1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/*
* Copyright (c) 2018-2025 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
// disable warning on iostream functions on windows
#if defined(_WIN32)
# define _CRT_SECURE_NO_WARNINGS
# define WIN32_LEAN_AND_MEAN
# define NOMINMAX
#endif
#include <assert.h>
#include "vkh.h"
#include "vkvg.h"
#include <float.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h> // needed before stdarg.h on Windows
#include <stdarg.h>
// should be supported by c11
// #include <threads.h>
// #include <stdatomic.h>
#define _USE_MATH_DEFINES
#include <math.h>
#ifndef M_PIF
#define M_PIF 3.14159265358979323846f /* float pi */
#define M_PIF_2 1.57079632679489661923f
#define M_2_PIF 0.63661977236758134308f // 2/pi
#endif
/*#ifndef M_2_PI
#define M_2_PI 0.63661977236758134308 // 2/pi
#endif*/
/*#ifdef DEBUG
#define LOG(level, ...) \
{ \
if ((vkvg_log_level) & (level)) \
fprintf(stdout, __VA_ARGS__); \
}
#else
#define LOG
#endif*/
#define VK_CHECK_RESULT(f) \
{ \
VkResult res = (f); \
if (res != VK_SUCCESS) { \
LOG(VKH_LOG_ERR, "Fatal : VkResult is %d in %s at line %d\n", res, __FILE__, __LINE__); \
assert(res == VK_SUCCESS); \
} \
}
#define PATH_CLOSED_BIT 0x80000000 /* most significant bit of path elmts is closed/open path state */
#define PATH_HAS_CURVES_BIT \
0x40000000 /* 2rd most significant bit of path elmts is curved status \
* for main path, this indicate that curve datas are present. \
* For segments, this indicate that the segment is curved or not */
#define PATH_IS_CONVEX_BIT 0x20000000 /* simple rectangle or circle. */
#define PATH_ELT_MASK 0x1FFFFFFF /* Bit mask for fetching path element value */
#define ROUNDF(f, c) (((float)((int)((f) * (c))) / (c)))
#define ROUND_DOWN(v, p) (floorf(v * p) / p)
#define EQUF(a, b) (fabsf(a - (b)) <= FLT_EPSILON)
#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#include "deps/tinycthread.h"
#include "cross_os.h"
// width of the stencil buffer will determine the number of context saving/restore layers
// the two first bits of the stencil are the FILL and the CLIP bits, all other bits are
// used to store clipping bit on context saving. 8 bit stencil will allow 6 save/restore layer
#define FB_COLOR_FORMAT VK_FORMAT_B8G8R8A8_UNORM
#define VKVG_SURFACE_IMGS_REQUIREMENTS \
(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | \
VK_FORMAT_FEATURE_TRANSFER_DST_BIT | VK_FORMAT_FEATURE_TRANSFER_SRC_BIT | VK_FORMAT_FEATURE_BLIT_SRC_BIT)
#define VKVG_PNG_WRITE_IMG_REQUIREMENTS \
(VK_FORMAT_FEATURE_TRANSFER_SRC_BIT | VK_FORMAT_FEATURE_TRANSFER_DST_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT)
// 30 seconds fence timeout
#define VKVG_FENCE_TIMEOUT 30000000000
// #define VKVG_FENCE_TIMEOUT 10000
#include "vectors.h"
/*typedef struct {
vkvg_status_t status;
} _vkvg_no_mem_struct;*/
// static error value whose address is returned instead of vkvg object pointers to avoid null pointers.
static vkvg_status_t _vkvg_status_no_memory = VKVG_STATUS_NO_MEMORY;
static vkvg_status_t _vkvg_status_null_pointer = VKVG_STATUS_NULL_POINTER;
static vkvg_status_t _vkvg_status_invalid_dev_ci = VKVG_STATUS_INVALID_DEVICE_CREATE_INFO;
static vkvg_status_t _vkvg_status_device_error = VKVG_STATUS_DEVICE_ERROR;
static vkvg_status_t _vkvg_status_invalid_surface = VKVG_STATUS_INVALID_SURFACE;
|