summaryrefslogtreecommitdiffstatsci
path: root/src/vkvg_internal.h
blob: 09ded36b9e21c2b694d6b8e92f4ca6b57c4c1cb9 (plain)
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
/*
 * Copyright (c) 2018 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.
 */
#ifndef VKVG_INTERNAL_H
#define VKVG_INTERNAL_H

 //disable warning on iostream functions on windows
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <float.h>

#define _USE_MATH_DEFINES
#include <math.h>

#define M_PIF               3.14159265358979323846f /* float pi */
#define M_PIF_2             1.57079632679489661923f
#define M_2_PIF             0.63661977236758134308f  // 2/pi
#ifndef M_PI
	#define M_PI		3.14159265358979323846	/* pi */
	#define M_2PI		6.28318530717958647692	/* 2 * pi */
	#define M_PI_2		1.57079632679489661923	/* pi/2 */
	#define M_PI_4		0.78539816339744830962	/* pi/4 */
	#define M_1_PI		0.31830988618379067154	/* 1/pi */
	#define M_2_PI		0.63661977236758134308	/* 2/pi */
	#define M_2_SQRTPI	1.12837916709551257390	/* 2/sqrt(pi) */
	#define M_SQRT2		1.41421356237309504880	/* sqrt(2) */
	#define M_SQRT1_2	0.70710678118654752440	/* 1/sqrt(2) */
#endif

#ifdef DEBUG
#define LOG(level,...) (vkvg_log_level & level) ? fprintf (stdout, __VA_ARGS__):true;
#else
#define LOG
#endif



#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_ELT_MASK       0x3FFFFFFF              /* Bit mask for fetching path element value */

#define ROUNDF(f, c) (((float)((int)((f) * (c))) / (c)))
#define ROUND_DOWNF(v,p) (floorf(v * p) / p)
#define ROUND_DOWN(v,p) (floor(v * p) / p)
#define EQUF(a, b) (fabsf(a-b)<=FLT_EPSILON)
#define EQU(a, b) (fabs(a-b)<=DBL_EPSILON)

#include "cross_os.h"
#include "vectors.h"
#include "cross_mutex.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_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|\
	VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_FORMAT_FEATURE_BLIT_SRC_BIT
#define VKVG_FENCE_TIMEOUT UINT64_MAX
#endif