]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - dpsoftrast.h
fix bug in last patch, fix RF_USEAXIS handling
[xonotic/darkplaces.git] / dpsoftrast.h
1
2 #ifndef DPSOFTRAST_H
3 #define DPSOFTRAST_H
4
5 #include <stdlib.h>
6
7 #define DPSOFTRAST_MAXMIPMAPS 16
8 #define DPSOFTRAST_TEXTURE_MAXSIZE (1<<(DPSOFTRAST_MAXMIPMAPS - 1))
9 #define DPSOFTRAST_MAXTEXTUREUNITS 16
10 #define DPSOFTRAST_MAXTEXCOORDARRAYS 8
11
12 // type of pixels in texture (some of these are converted to BGRA8 on update)
13 #define DPSOFTRAST_TEXTURE_FORMAT_BGRA8 0
14 #define DPSOFTRAST_TEXTURE_FORMAT_DEPTH 1
15 #define DPSOFTRAST_TEXTURE_FORMAT_RGBA8 2
16 #define DPSOFTRAST_TEXTURE_FORMAT_ALPHA8 3
17 #define DPSOFTRAST_TEXTURE_FORMAT_RGBA16F 4
18 #define DPSOFTRAST_TEXTURE_FORMAT_RGBA32F 5
19 #define DPSOFTRAST_TEXTURE_FORMAT_COMPAREMASK 0x0F
20
21 // modifier flags for texture (can not be changed after creation)
22 #define DPSOFTRAST_TEXTURE_FLAG_MIPMAP 0x10
23 #define DPSOFTRAST_TEXTURE_FLAG_CUBEMAP 0x20
24 #define DPSOFTRAST_TEXTURE_FLAG_USEALPHA 0x40
25 #define DPSOFTRAST_TEXTURE_FLAG_CLAMPTOEDGE 0x80
26
27 typedef enum DPSOFTRAST_TEXTURE_FILTER_e
28 {
29         DPSOFTRAST_TEXTURE_FILTER_NEAREST = 0,
30         DPSOFTRAST_TEXTURE_FILTER_LINEAR = 1,
31         DPSOFTRAST_TEXTURE_FILTER_NEAREST_MIPMAP_TRIANGLE = 2,
32         DPSOFTRAST_TEXTURE_FILTER_LINEAR_MIPMAP_TRIANGLE = 3,
33 }
34 DPSOFTRAST_TEXTURE_FILTER;
35
36 int DPSOFTRAST_Init(int width, int height, int numthreads, int interlace, unsigned int *colorpixels, unsigned int *depthpixels);
37 void DPSOFTRAST_Shutdown(void);
38 void DPSOFTRAST_Flush(void);
39 void DPSOFTRAST_Finish(void);
40
41 int DPSOFTRAST_Texture_New(int flags, int width, int height, int depth);
42 void DPSOFTRAST_Texture_Free(int index);
43 void DPSOFTRAST_Texture_UpdatePartial(int index, int mip, const unsigned char *pixels, int blockx, int blocky, int blockwidth, int blockheight);
44 void DPSOFTRAST_Texture_UpdateFull(int index, const unsigned char *pixels);
45 int DPSOFTRAST_Texture_GetWidth(int index, int mip);
46 int DPSOFTRAST_Texture_GetHeight(int index, int mip);
47 int DPSOFTRAST_Texture_GetDepth(int index, int mip);
48 unsigned char *DPSOFTRAST_Texture_GetPixelPointer(int index, int mip);
49 void DPSOFTRAST_Texture_Filter(int index, DPSOFTRAST_TEXTURE_FILTER filter);
50
51 void DPSOFTRAST_SetRenderTargets(int width, int height, unsigned int *depthpixels, unsigned int *colorpixels0, unsigned int *colorpixels1, unsigned int *colorpixels2, unsigned int *colorpixels3);
52 void DPSOFTRAST_Viewport(int x, int y, int width, int height);
53 void DPSOFTRAST_ClearColor(float r, float g, float b, float a);
54 void DPSOFTRAST_ClearDepth(float d);
55 void DPSOFTRAST_ColorMask(int r, int g, int b, int a);
56 void DPSOFTRAST_DepthTest(int enable);
57 void DPSOFTRAST_ScissorTest(int enable);
58 void DPSOFTRAST_Scissor(float x, float y, float width, float height);
59 void DPSOFTRAST_ClipPlane(float x, float y, float z, float w);
60
61 void DPSOFTRAST_BlendFunc(int smodulate, int dmodulate);
62 void DPSOFTRAST_BlendSubtract(int enable);
63 void DPSOFTRAST_DepthMask(int enable);
64 void DPSOFTRAST_DepthFunc(int comparemode);
65 void DPSOFTRAST_DepthRange(float range0, float range1);
66 void DPSOFTRAST_PolygonOffset(float alongnormal, float intoview);
67 void DPSOFTRAST_CullFace(int mode);
68 void DPSOFTRAST_AlphaTest(int enable);
69 void DPSOFTRAST_AlphaFunc(int alphafunc, float alphavalue);
70 void DPSOFTRAST_Color4f(float r, float g, float b, float a);
71 void DPSOFTRAST_GetPixelsBGRA(int blockx, int blocky, int blockwidth, int blockheight, unsigned char *outpixels);
72 void DPSOFTRAST_CopyRectangleToTexture(int index, int mip, int tx, int ty, int sx, int sy, int width, int height);
73 void DPSOFTRAST_SetTexture(int unitnum, int index);
74
75 void DPSOFTRAST_SetVertexPointer(const float *vertex3f, size_t stride);
76 void DPSOFTRAST_SetColorPointer(const float *color4f, size_t stride);
77 void DPSOFTRAST_SetColorPointer4ub(const unsigned char *color4ub, size_t stride);
78 void DPSOFTRAST_SetTexCoordPointer(int unitnum, int numcomponents, size_t stride, const float *texcoordf);
79
80 typedef enum gl20_texunit_e
81 {
82         // postprocess shaders, and generic shaders:
83         GL20TU_FIRST = 0,
84         GL20TU_SECOND = 1,
85         GL20TU_GAMMARAMPS = 2,
86         // standard material properties
87         GL20TU_NORMAL = 0,
88         GL20TU_COLOR = 1,
89         GL20TU_GLOSS = 2,
90         GL20TU_GLOW = 3,
91         // material properties for a second material
92         GL20TU_SECONDARY_NORMAL = 4,
93         GL20TU_SECONDARY_COLOR = 5,
94         GL20TU_SECONDARY_GLOSS = 6,
95         GL20TU_SECONDARY_GLOW = 7,
96         // material properties for a colormapped material
97         // conflicts with secondary material
98         GL20TU_PANTS = 4,
99         GL20TU_SHIRT = 7,
100         // fog fade in the distance
101         GL20TU_FOGMASK = 8,
102         // compiled ambient lightmap and deluxemap
103         GL20TU_LIGHTMAP = 9,
104         GL20TU_DELUXEMAP = 10,
105         // refraction, used by water shaders
106         GL20TU_REFRACTION = 3,
107         // reflection, used by water shaders, also with normal material rendering
108         // conflicts with secondary material
109         GL20TU_REFLECTION = 7,
110         // rtlight attenuation (distance fade) and cubemap filter (projection texturing)
111         // conflicts with lightmap/deluxemap
112         GL20TU_ATTENUATION = 9,
113         GL20TU_CUBE = 10,
114         GL20TU_SHADOWMAP2D = 15,
115         GL20TU_CUBEPROJECTION = 12,
116         // rtlight prepass data (screenspace depth and normalmap)
117         GL20TU_SCREENDEPTH = 13,
118         GL20TU_SCREENNORMALMAP = 14,
119         // lightmap prepass data (screenspace diffuse and specular from lights)
120         GL20TU_SCREENDIFFUSE = 11,
121         GL20TU_SCREENSPECULAR = 12,
122         // fake reflections
123         GL20TU_REFLECTMASK = 5,
124         GL20TU_REFLECTCUBE = 6,
125         GL20TU_FOGHEIGHTTEXTURE = 14
126 }
127 gl20_texunit;
128
129 typedef enum glsl_attrib_e
130 {
131         GLSLATTRIB_POSITION = 0,
132         GLSLATTRIB_COLOR = 1,
133         GLSLATTRIB_TEXCOORD0 = 2,
134         GLSLATTRIB_TEXCOORD1 = 3,
135         GLSLATTRIB_TEXCOORD2 = 4,
136         GLSLATTRIB_TEXCOORD3 = 5,
137         GLSLATTRIB_TEXCOORD4 = 6,
138         GLSLATTRIB_TEXCOORD5 = 7,
139         GLSLATTRIB_TEXCOORD6 = 8,
140         GLSLATTRIB_TEXCOORD7 = 9,
141 }
142 glsl_attrib;
143
144 // this enum selects which of the glslshadermodeinfo entries should be used
145 typedef enum shadermode_e
146 {
147         SHADERMODE_GENERIC, ///< (particles/HUD/etc) vertex color, optionally multiplied by one texture
148         SHADERMODE_POSTPROCESS, ///< postprocessing shader (r_glsl_postprocess)
149         SHADERMODE_DEPTH_OR_SHADOW, ///< (depthfirst/shadows) vertex shader only
150         SHADERMODE_FLATCOLOR, ///< (lightmap) modulate texture by uniform color (q1bsp, q3bsp)
151         SHADERMODE_VERTEXCOLOR, ///< (lightmap) modulate texture by vertex colors (q3bsp)
152         SHADERMODE_LIGHTMAP, ///< (lightmap) modulate texture by lightmap texture (q1bsp, q3bsp)
153         SHADERMODE_FAKELIGHT, ///< (fakelight) modulate texture by "fake" lighting (no lightmaps, no nothing)
154         SHADERMODE_LIGHTDIRECTIONMAP_MODELSPACE, ///< (lightmap) use directional pixel shading from texture containing modelspace light directions (q3bsp deluxemap)
155         SHADERMODE_LIGHTDIRECTIONMAP_TANGENTSPACE, ///< (lightmap) use directional pixel shading from texture containing tangentspace light directions (q1bsp deluxemap)
156         SHADERMODE_LIGHTDIRECTION, ///< (lightmap) use directional pixel shading from fixed light direction (q3bsp)
157         SHADERMODE_LIGHTSOURCE, ///< (lightsource) use directional pixel shading from light source (rtlight)
158         SHADERMODE_REFRACTION, ///< refract background (the material is rendered normally after this pass)
159         SHADERMODE_WATER, ///< refract background and reflection (the material is rendered normally after this pass)
160         SHADERMODE_SHOWDEPTH, ///< (debugging) renders depth as color
161         SHADERMODE_DEFERREDGEOMETRY, ///< (deferred) render material properties to screenspace geometry buffers
162         SHADERMODE_DEFERREDLIGHTSOURCE, ///< (deferred) use directional pixel shading from light source (rtlight) on screenspace geometry buffers
163         SHADERMODE_COUNT
164 }
165 shadermode_t;
166
167 typedef enum shaderpermutation_e
168 {
169         SHADERPERMUTATION_DIFFUSE = 1<<0, ///< (lightsource) whether to use directional shading
170         SHADERPERMUTATION_VERTEXTEXTUREBLEND = 1<<1, ///< indicates this is a two-layer material blend based on vertex alpha (q3bsp)
171         SHADERPERMUTATION_VIEWTINT = 1<<2, ///< view tint (postprocessing only), use vertex colors (generic only)
172         SHADERPERMUTATION_COLORMAPPING = 1<<3, ///< indicates this is a colormapped skin
173         SHADERPERMUTATION_SATURATION = 1<<4, ///< saturation (postprocessing only)
174         SHADERPERMUTATION_FOGINSIDE = 1<<5, ///< tint the color by fog color or black if using additive blend mode
175         SHADERPERMUTATION_FOGOUTSIDE = 1<<6, ///< tint the color by fog color or black if using additive blend mode
176         SHADERPERMUTATION_FOGHEIGHTTEXTURE = 1<<7, ///< fog color and density determined by texture mapped on vertical axis
177         SHADERPERMUTATION_FOGALPHAHACK = 1<<8, ///< fog color and density determined by texture mapped on vertical axis
178         SHADERPERMUTATION_GAMMARAMPS = 1<<9, ///< gamma (postprocessing only)
179         SHADERPERMUTATION_CUBEFILTER = 1<<10, ///< (lightsource) use cubemap light filter
180         SHADERPERMUTATION_GLOW = 1<<11, ///< (lightmap) blend in an additive glow texture
181         SHADERPERMUTATION_BLOOM = 1<<12, ///< bloom (postprocessing only)
182         SHADERPERMUTATION_SPECULAR = 1<<13, ///< (lightsource or deluxemapping) render specular effects
183         SHADERPERMUTATION_POSTPROCESSING = 1<<14, ///< user defined postprocessing (postprocessing only)
184         SHADERPERMUTATION_REFLECTION = 1<<15, ///< normalmap-perturbed reflection of the scene infront of the surface, preformed as an overlay on the surface
185         SHADERPERMUTATION_OFFSETMAPPING = 1<<16, ///< adjust texcoords to roughly simulate a displacement mapped surface
186         SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING = 1<<17, ///< adjust texcoords to accurately simulate a displacement mapped surface (requires OFFSETMAPPING to also be set!)
187         SHADERPERMUTATION_SHADOWMAP2D = 1<<18, ///< (lightsource) use shadowmap texture as light filter
188         SHADERPERMUTATION_SHADOWMAPPCF = 1<<19, ///< (lightsource) use percentage closer filtering on shadowmap test results
189         SHADERPERMUTATION_SHADOWMAPPCF2 = 1<<20, ///< (lightsource) use higher quality percentage closer filtering on shadowmap test results
190         SHADERPERMUTATION_SHADOWSAMPLER = 1<<21, ///< (lightsource) use hardware shadowmap test
191         SHADERPERMUTATION_SHADOWMAPVSDCT = 1<<22, ///< (lightsource) use virtual shadow depth cube texture for shadowmap indexing
192         SHADERPERMUTATION_SHADOWMAPORTHO = 1<<23, ///< (lightsource) use orthographic shadowmap projection
193         SHADERPERMUTATION_DEFERREDLIGHTMAP = 1<<24, ///< (lightmap) read Texture_ScreenDiffuse/Specular textures and add them on top of lightmapping
194         SHADERPERMUTATION_ALPHAKILL = 1<<25, ///< (deferredgeometry) discard pixel if diffuse texture alpha below 0.5
195         SHADERPERMUTATION_REFLECTCUBE = 1<<26, ///< fake reflections using global cubemap (not HDRI light probe)
196         SHADERPERMUTATION_NORMALMAPSCROLLBLEND = 1<<27, ///< (water) counter-direction normalmaps scrolling
197         SHADERPERMUTATION_BOUNCEGRID = 1<<28, ///< (lightmap) use Texture_BounceGrid as an additional source of ambient light
198         SHADERPERMUTATION_BOUNCEGRIDDIRECTIONAL = 1<<29, ///< (lightmap) use 16-component pixels in bouncegrid texture for directional lighting rather than standard 4-component
199         SHADERPERMUTATION_LIMIT = 1<<30, ///< size of permutations array
200         SHADERPERMUTATION_COUNT = 30 ///< size of shaderpermutationinfo array
201 }
202 shaderpermutation_t;
203
204 typedef enum DPSOFTRAST_UNIFORM_e
205 {
206         DPSOFTRAST_UNIFORM_Texture_First,
207         DPSOFTRAST_UNIFORM_Texture_Second,
208         DPSOFTRAST_UNIFORM_Texture_GammaRamps,
209         DPSOFTRAST_UNIFORM_Texture_Normal,
210         DPSOFTRAST_UNIFORM_Texture_Color,
211         DPSOFTRAST_UNIFORM_Texture_Gloss,
212         DPSOFTRAST_UNIFORM_Texture_Glow,
213         DPSOFTRAST_UNIFORM_Texture_SecondaryNormal,
214         DPSOFTRAST_UNIFORM_Texture_SecondaryColor,
215         DPSOFTRAST_UNIFORM_Texture_SecondaryGloss,
216         DPSOFTRAST_UNIFORM_Texture_SecondaryGlow,
217         DPSOFTRAST_UNIFORM_Texture_Pants,
218         DPSOFTRAST_UNIFORM_Texture_Shirt,
219         DPSOFTRAST_UNIFORM_Texture_FogHeightTexture,
220         DPSOFTRAST_UNIFORM_Texture_FogMask,
221         DPSOFTRAST_UNIFORM_Texture_Lightmap,
222         DPSOFTRAST_UNIFORM_Texture_Deluxemap,
223         DPSOFTRAST_UNIFORM_Texture_Attenuation,
224         DPSOFTRAST_UNIFORM_Texture_Cube,
225         DPSOFTRAST_UNIFORM_Texture_Refraction,
226         DPSOFTRAST_UNIFORM_Texture_Reflection,
227         DPSOFTRAST_UNIFORM_Texture_ShadowMap2D,
228         DPSOFTRAST_UNIFORM_Texture_CubeProjection,
229         DPSOFTRAST_UNIFORM_Texture_ScreenDepth,
230         DPSOFTRAST_UNIFORM_Texture_ScreenNormalMap,
231         DPSOFTRAST_UNIFORM_Texture_ScreenDiffuse,
232         DPSOFTRAST_UNIFORM_Texture_ScreenSpecular,
233         DPSOFTRAST_UNIFORM_Texture_ReflectMask,
234         DPSOFTRAST_UNIFORM_Texture_ReflectCube,
235         DPSOFTRAST_UNIFORM_Alpha,
236         DPSOFTRAST_UNIFORM_BloomBlur_Parameters,
237         DPSOFTRAST_UNIFORM_ClientTime,
238         DPSOFTRAST_UNIFORM_Color_Ambient,
239         DPSOFTRAST_UNIFORM_Color_Diffuse,
240         DPSOFTRAST_UNIFORM_Color_Specular,
241         DPSOFTRAST_UNIFORM_Color_Glow,
242         DPSOFTRAST_UNIFORM_Color_Pants,
243         DPSOFTRAST_UNIFORM_Color_Shirt,
244         DPSOFTRAST_UNIFORM_DeferredColor_Ambient,
245         DPSOFTRAST_UNIFORM_DeferredColor_Diffuse,
246         DPSOFTRAST_UNIFORM_DeferredColor_Specular,
247         DPSOFTRAST_UNIFORM_DeferredMod_Diffuse,
248         DPSOFTRAST_UNIFORM_DeferredMod_Specular,
249         DPSOFTRAST_UNIFORM_DistortScaleRefractReflect,
250         DPSOFTRAST_UNIFORM_EyePosition,
251         DPSOFTRAST_UNIFORM_FogColor,
252         DPSOFTRAST_UNIFORM_FogHeightFade,
253         DPSOFTRAST_UNIFORM_FogPlane,
254         DPSOFTRAST_UNIFORM_FogPlaneViewDist,
255         DPSOFTRAST_UNIFORM_FogRangeRecip,
256         DPSOFTRAST_UNIFORM_LightColor,
257         DPSOFTRAST_UNIFORM_LightDir,
258         DPSOFTRAST_UNIFORM_LightPosition,
259         DPSOFTRAST_UNIFORM_OffsetMapping_ScaleSteps,
260         DPSOFTRAST_UNIFORM_PixelSize,
261         DPSOFTRAST_UNIFORM_ReflectColor,
262         DPSOFTRAST_UNIFORM_ReflectFactor,
263         DPSOFTRAST_UNIFORM_ReflectOffset,
264         DPSOFTRAST_UNIFORM_RefractColor,
265         DPSOFTRAST_UNIFORM_Saturation,
266         DPSOFTRAST_UNIFORM_ScreenCenterRefractReflect,
267         DPSOFTRAST_UNIFORM_ScreenScaleRefractReflect,
268         DPSOFTRAST_UNIFORM_ScreenToDepth,
269         DPSOFTRAST_UNIFORM_ShadowMap_Parameters,
270         DPSOFTRAST_UNIFORM_ShadowMap_TextureScale,
271         DPSOFTRAST_UNIFORM_SpecularPower,
272         DPSOFTRAST_UNIFORM_UserVec1,
273         DPSOFTRAST_UNIFORM_UserVec2,
274         DPSOFTRAST_UNIFORM_UserVec3,
275         DPSOFTRAST_UNIFORM_UserVec4,
276         DPSOFTRAST_UNIFORM_ViewTintColor,
277         DPSOFTRAST_UNIFORM_ViewToLightM1,
278         DPSOFTRAST_UNIFORM_ViewToLightM2,
279         DPSOFTRAST_UNIFORM_ViewToLightM3,
280         DPSOFTRAST_UNIFORM_ViewToLightM4,
281         DPSOFTRAST_UNIFORM_ModelToLightM1,
282         DPSOFTRAST_UNIFORM_ModelToLightM2,
283         DPSOFTRAST_UNIFORM_ModelToLightM3,
284         DPSOFTRAST_UNIFORM_ModelToLightM4,
285         DPSOFTRAST_UNIFORM_TexMatrixM1,
286         DPSOFTRAST_UNIFORM_TexMatrixM2,
287         DPSOFTRAST_UNIFORM_TexMatrixM3,
288         DPSOFTRAST_UNIFORM_TexMatrixM4,
289         DPSOFTRAST_UNIFORM_BackgroundTexMatrixM1,
290         DPSOFTRAST_UNIFORM_BackgroundTexMatrixM2,
291         DPSOFTRAST_UNIFORM_BackgroundTexMatrixM3,
292         DPSOFTRAST_UNIFORM_BackgroundTexMatrixM4,
293         DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1,
294         DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM2,
295         DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM3,
296         DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM4,
297         DPSOFTRAST_UNIFORM_ModelViewMatrixM1,
298         DPSOFTRAST_UNIFORM_ModelViewMatrixM2,
299         DPSOFTRAST_UNIFORM_ModelViewMatrixM3,
300         DPSOFTRAST_UNIFORM_ModelViewMatrixM4,
301         DPSOFTRAST_UNIFORM_PixelToScreenTexCoord,
302         DPSOFTRAST_UNIFORM_ModelToReflectCubeM1,
303         DPSOFTRAST_UNIFORM_ModelToReflectCubeM2,
304         DPSOFTRAST_UNIFORM_ModelToReflectCubeM3,
305         DPSOFTRAST_UNIFORM_ModelToReflectCubeM4,
306         DPSOFTRAST_UNIFORM_ShadowMapMatrixM1,
307         DPSOFTRAST_UNIFORM_ShadowMapMatrixM2,
308         DPSOFTRAST_UNIFORM_ShadowMapMatrixM3,
309         DPSOFTRAST_UNIFORM_ShadowMapMatrixM4,
310         DPSOFTRAST_UNIFORM_BloomColorSubtract,
311         DPSOFTRAST_UNIFORM_NormalmapScrollBlend,
312         DPSOFTRAST_UNIFORM_TOTAL
313 }
314 DPSOFTRAST_UNIFORM;
315
316 void DPSOFTRAST_SetShader(int mode, int permutation, int exactspecularmath);
317 #define DPSOFTRAST_Uniform1f(index, v0) DPSOFTRAST_Uniform4f(index, v0, 0, 0, 0)
318 #define DPSOFTRAST_Uniform2f(index, v0, v1) DPSOFTRAST_Uniform4f(index, v0, v1, 0, 0)
319 #define DPSOFTRAST_Uniform3f(index, v0, v1, v2) DPSOFTRAST_Uniform4f(index, v0, v1, v2, 0)
320 void DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM index, float v0, float v1, float v2, float v3);
321 void DPSOFTRAST_Uniform4fv(DPSOFTRAST_UNIFORM index, const float *v);
322 void DPSOFTRAST_UniformMatrix4fv(DPSOFTRAST_UNIFORM index, int arraysize, int transpose, const float *v);
323 void DPSOFTRAST_Uniform1i(DPSOFTRAST_UNIFORM index, int i0);
324
325 void DPSOFTRAST_DrawTriangles(int firstvertex, int numvertices, int numtriangles, const int *element3i, const unsigned short *element3s);
326
327 #endif // DPSOFTRAST_H