| TGX 1.0.8 A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.

Loading...
Searching...
No Matches
ShaderParams.h
Go to the documentation of this file.
1
5//
6// Copyright 2020 Arvind Singh
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Lesser General Public
10// License as published by the Free Software Foundation; either
11// version 2.1 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
16// Lesser General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public
19// License along with this library; If not, see <http://www.gnu.org/licenses/>.
20#ifndef _TGX_SHADERSPARAMS_H_
21#define _TGX_SHADERSPARAMS_H_
22
23
24// only C++, no plain C
25#ifdef __cplusplus
26
27
28#include "Misc.h"
29#include "Vec2.h"
30#include "Vec3.h"
31#include "Vec4.h"
32#include "Box2.h"
33#include "Color.h"
34
35#include <stdint.h>
36
37 namespace tgx
38{
39
43 enum Shader
44 {
45 // Shaders for projection type : Perspective or ortho.
46 SHADER_PERSPECTIVE = (1 << 0),
47 SHADER_ORTHO = (1 << 1),
48
49 // Shaders for depth buffer : Zbuffer or no-Zbuffer
50 SHADER_NOZBUFFER = (1 << 2),
51 SHADER_ZBUFFER = (1 << 3),
52
53 // Shaders for shading algorithm: flat, gouraud or phong
54 SHADER_FLAT = (1 << 4),
55 SHADER_GOURAUD = (1 << 5),
56
57 // Shaders for texturing mode: no-texture, texture-wrap, texture-clamp
58 SHADER_NOTEXTURE = (1 << 7),
59 SHADER_TEXTURE = (1 << 8),
60
61 // Shaders for texture quality: nearest, bilinear
62 SHADER_TEXTURE_NEAREST = (1 << 11),
63 SHADER_TEXTURE_BILINEAR = (1 << 12),
64
65 // Shaders for texture wrapping mode: wrap , clamp
66 SHADER_TEXTURE_WRAP_POW2 = (1 << 13),
67 SHADER_TEXTURE_CLAMP = (1 << 14)
68 };
69
70
72 inline constexpr Shader operator|(Shader a1, Shader a2) { return ((Shader)((int)a1 | (int)a2)); }
73
75 inline Shader& operator|=(Shader& a1, Shader a2) { a1 = a1 | a2; return a1; }
76
78 inline constexpr Shader operator&(Shader a1, Shader a2) { return ((Shader)((int)a1 & (int)a2)); }
79
81 inline Shader& operator&=(Shader& a1, Shader a2) { a1 = a1 & a2; return a1; }
82
84 inline constexpr Shader operator~(Shader a) { return (Shader)(~((int)a)); }
85
86
87
88 #define TGX_SHADER_MASK_PROJECTION (SHADER_PERSPECTIVE | SHADER_ORTHO)
89 #define TGX_SHADER_MASK_ZBUFFER (SHADER_NOZBUFFER | SHADER_ZBUFFER)
90 #define TGX_SHADER_MASK_SHADING (SHADER_FLAT | SHADER_GOURAUD)
91 #define TGX_SHADER_MASK_TEXTURE (SHADER_NOTEXTURE | SHADER_TEXTURE)
92 #define TGX_SHADER_MASK_TEXTURE_QUALITY (SHADER_TEXTURE_BILINEAR | SHADER_TEXTURE_NEAREST)
93 #define TGX_SHADER_MASK_TEXTURE_MODE (SHADER_TEXTURE_WRAP_POW2 | SHADER_TEXTURE_CLAMP)
94 #define TGX_SHADER_MASK_ALL (TGX_SHADER_MASK_PROJECTION | TGX_SHADER_MASK_ZBUFFER | TGX_SHADER_MASK_SHADING | TGX_SHADER_MASK_TEXTURE | TGX_SHADER_MASK_TEXTURE_QUALITY | TGX_SHADER_MASK_TEXTURE_MODE)
95
96 #define TGX_SHADER_SET_FLAGS(shader_type, flags) { shader_type = (flags); }
97 #define TGX_SHADER_ADD_FLAGS(shader_type, flags) { shader_type |= (flags);}
98 #define TGX_SHADER_REMOVE_FLAGS(shader_type, flags) { shader_type &= ~(flags); }
99 #define TGX_SHADER_HAS_ONE_FLAG(shader_type, flags) (shader_type & (flags))
100 #define TGX_SHADER_HAS_ALL_FLAGS(shader_type, flags) ((shader_type & (flags)) == flags)
101
102 #define TGX_SHADER_HAS_PERSPECTIVE(shader_type) (TGX_SHADER_HAS_ONE_FLAG(shader_type , SHADER_PERSPECTIVE))
103 #define TGX_SHADER_HAS_ORTHO(shader_type) (TGX_SHADER_HAS_ONE_FLAG(shader_type , SHADER_ORTHO))
104 #define TGX_SHADER_HAS_NOZBUFFER(shader_type) (TGX_SHADER_HAS_ONE_FLAG(shader_type , SHADER_NOZBUFFER))
105 #define TGX_SHADER_HAS_ZBUFFER(shader_type) (TGX_SHADER_HAS_ONE_FLAG(shader_type , SHADER_ZBUFFER))
106 #define TGX_SHADER_HAS_FLAT(shader_type) (TGX_SHADER_HAS_ONE_FLAG(shader_type , SHADER_FLAT))
107 #define TGX_SHADER_HAS_GOURAUD(shader_type) (TGX_SHADER_HAS_ONE_FLAG(shader_type , SHADER_GOURAUD))
108 #define TGX_SHADER_HAS_NOTEXTURE(shader_type) (TGX_SHADER_HAS_ONE_FLAG(shader_type , SHADER_NOTEXTURE))
109 #define TGX_SHADER_HAS_TEXTURE(shader_type) (TGX_SHADER_HAS_ONE_FLAG(shader_type , SHADER_TEXTURE))
110 #define TGX_SHADER_HAS_TEXTURE_NEAREST(shader_type) (TGX_SHADER_HAS_ONE_FLAG(shader_type , SHADER_TEXTURE_NEAREST))
111 #define TGX_SHADER_HAS_TEXTURE_BILINEAR(shader_type) (TGX_SHADER_HAS_ONE_FLAG(shader_type , SHADER_TEXTURE_BILINEAR))
112 #define TGX_SHADER_HAS_TEXTURE_WRAP_POW2(shader_type) (TGX_SHADER_HAS_ONE_FLAG(shader_type , SHADER_TEXTURE_WRAP_POW2))
113 #define TGX_SHADER_HAS_TEXTURE_CLAMP(shader_type) (TGX_SHADER_HAS_ONE_FLAG(shader_type , SHADER_TEXTURE_CLAMP))
114
115 #define TGX_SHADER_REMOVE_PERSPECTIVE(shader_type) TGX_SHADER_REMOVE_FLAGS(shader_type , SHADER_PERSPECTIVE)
116 #define TGX_SHADER_REMOVE_ORTHO(shader_type) TGX_SHADER_REMOVE_FLAGS(shader_type , SHADER_ORTHO)
117 #define TGX_SHADER_REMOVE_NOZBUFFER(shader_type) TGX_SHADER_REMOVE_FLAGS(shader_type , SHADER_NOZBUFFER)
118 #define TGX_SHADER_REMOVE_ZBUFFER(shader_type) TGX_SHADER_REMOVE_FLAGS(shader_type , SHADER_ZBUFFER)
119 #define TGX_SHADER_REMOVE_FLAT(shader_type) TGX_SHADER_REMOVE_FLAGS(shader_type , SHADER_FLAT)
120 #define TGX_SHADER_REMOVE_GOURAUD(shader_type) TGX_SHADER_REMOVE_FLAGS(shader_type , SHADER_GOURAUD)
121 #define TGX_SHADER_REMOVE_NOTEXTURE(shader_type) TGX_SHADER_REMOVE_FLAGS(shader_type , SHADER_NOTEXTURE)
122 #define TGX_SHADER_REMOVE_TEXTURE(shader_type) TGX_SHADER_REMOVE_FLAGS(shader_type , SHADER_TEXTURE)
123 #define TGX_SHADER_REMOVE_TEXTURE_NEAREST(shader_type) TGX_SHADER_REMOVE_FLAGS(shader_type , SHADER_TEXTURE_NEAREST)
124 #define TGX_SHADER_REMOVE_TEXTURE_BILINEAR(shader_type) TGX_SHADER_REMOVE_FLAGS(shader_type , SHADER_TEXTURE_BILINEAR)
125 #define TGX_SHADER_REMOVE_TEXTURE_WRAP_POW2(shader_type) TGX_SHADER_REMOVE_FLAGS(shader_type , SHADER_TEXTURE_WRAP_POW2)
126 #define TGX_SHADER_REMOVE_TEXTURE_CLAMP(shader_type) TGX_SHADER_REMOVE_FLAGS(shader_type , SHADER_TEXTURE_CLAMP)
127
128 #define TGX_SHADER_ADD_PERSPECTIVE(shader_type) TGX_SHADER_ADD_FLAGS(shader_type , SHADER_PERSPECTIVE)
129 #define TGX_SHADER_ADD_ORTHO(shader_type) TGX_SHADER_ADD_FLAGS(shader_type , SHADER_ORTHO)
130 #define TGX_SHADER_ADD_NOZBUFFER(shader_type) TGX_SHADER_ADD_FLAGS(shader_type , SHADER_NOZBUFFER)
131 #define TGX_SHADER_ADD_ZBUFFER(shader_type) TGX_SHADER_ADD_FLAGS(shader_type , SHADER_ZBUFFER)
132 #define TGX_SHADER_ADD_FLAT(shader_type) TGX_SHADER_ADD_FLAGS(shader_type , SHADER_FLAT)
133 #define TGX_SHADER_ADD_GOURAUD(shader_type) TGX_SHADER_ADD_FLAGS(shader_type , SHADER_GOURAUD)
134 #define TGX_SHADER_ADD_NOTEXTURE(shader_type) TGX_SHADER_ADD_FLAGS(shader_type , SHADER_NOTEXTURE)
135 #define TGX_SHADER_ADD_TEXTURE(shader_type) TGX_SHADER_ADD_FLAGS(shader_type , SHADER_TEXTURE)
136 #define TGX_SHADER_ADD_TEXTURE_NEAREST(shader_type) TGX_SHADER_ADD_FLAGS(shader_type , SHADER_TEXTURE_NEAREST)
137 #define TGX_SHADER_ADD_TEXTURE_BILINEAR(shader_type) TGX_SHADER_ADD_FLAGS(shader_type , SHADER_TEXTURE_BILINEAR)
138 #define TGX_SHADER_ADD_TEXTURE_WRAP_POW2(shader_type) TGX_SHADER_ADD_FLAGS(shader_type , SHADER_TEXTURE_WRAP_POW2)
139 #define TGX_SHADER_ADD_TEXTURE_CLAMP(shader_type) TGX_SHADER_ADD_FLAGS(shader_type , SHADER_TEXTURE_CLAMP)
140
141
142 //forward declaration
143 template<typename color_t> class Image;
144
145
152 struct RasterizerVec4 : public tgx::fVec4
153 {
154 tgx::RGBf color;
155 tgx::fVec2 T;
156 float A;
157 };
158
159
160
167 template<typename color_t_im, typename color_t_tex, typename ZBUFFER_t, typename BLEND_OP = void> struct RasterizerParams
168 {
169 RGBf facecolor;
170 float opacity;
171 Image<color_t_im> * im;
172 ZBUFFER_t * zbuf;
173 const Image<color_t_tex>* tex;
174 color_t_tex mask_color;
175 int shader_type;
176 float wa;
177 float wb;
178 const BLEND_OP * p_blend_op;
179 };
180
181
182
183}
184
185
186#endif
187
188#endif
189
190
Box2.h
2D box class
tgx::operator|=
Anchor & operator|=(Anchor &a1, Anchor a2)
Enable bitwise |= operator for enum Anchor.
Definition: Box2.h:97
tgx::operator|
constexpr Anchor operator|(Anchor a1, Anchor a2)
Enable bitwise | operator for enum Anchor.
Definition: Box2.h:94
tgx::operator&
constexpr Anchor operator&(Anchor a1, Anchor a2)
Enable bitwise & operator for enum Anchor.
Definition: Box2.h:100
tgx::operator&=
Anchor & operator&=(Anchor &a1, Anchor a2)
Enable bitwise &= operator for enum Anchor.
Definition: Box2.h:103
Color.h
Color classes [RGB565, RGB24, RGB32, RGB64, RGBf, HSV].
Misc.h
Utility/miscellaneous functions used throughout the library.
tgx::operator~
constexpr Shader operator~(Shader a)
Enable bitwise ~ operator for enum.
Definition: ShaderParams.h:84
tgx::Shader
Shader
List of shaders available for 3D graphics.
Definition: ShaderParams.h:44
tgx::SHADER_NOZBUFFER
@ SHADER_NOZBUFFER
disable Z-buffer testing
Definition: ShaderParams.h:50
tgx::SHADER_FLAT
@ SHADER_FLAT
enable flat shading
Definition: ShaderParams.h:54
tgx::SHADER_TEXTURE_NEAREST
@ SHADER_TEXTURE_NEAREST
use point sampling texture mapping
Definition: ShaderParams.h:62
tgx::SHADER_NOTEXTURE
@ SHADER_NOTEXTURE
disable texture mapping
Definition: ShaderParams.h:58
tgx::SHADER_TEXTURE_WRAP_POW2
@ SHADER_TEXTURE_WRAP_POW2
texture has power of 2 dimensions and use wrapping at edges
Definition: ShaderParams.h:66
tgx::SHADER_PERSPECTIVE
@ SHADER_PERSPECTIVE
enable Perspective projection
Definition: ShaderParams.h:46
Vec2.h
2D vector.
Vec3.h
3D vector.
Vec4.h
4D vector.
tgx::RGBf
Color in R,G,B float format.
Definition: Color.h:2407
tgx::Vec2< float >
tgx::Vec4< float >