]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - gl_backend.h
fixed realtime lighting bugs with gl_mesh_batching 1 (... by not using batching while...
[xonotic/darkplaces.git] / gl_backend.h
1
2 #ifndef GL_BACKEND_H
3 #define GL_BACKEND_H
4
5 #define MAX_TEXTUREUNITS 8
6
7 #define POLYGONELEMENTS_MAXPOINTS 258
8 extern int polygonelements[768];
9
10 void GL_SetupView_ViewPort (int x, int y, int width, int height);
11 void GL_SetupView_Orientation_Identity (void);
12 void GL_SetupView_Orientation_FromEntity (vec3_t origin, vec3_t angles);
13 void GL_SetupView_Mode_Perspective (double fovx, double fovy, double zNear, double zFar);
14 void GL_SetupView_Mode_PerspectiveInfiniteFarClip (double fovx, double fovy, double zNear);
15 void GL_SetupView_Mode_Ortho (double x1, double y1, double x2, double y2, double zNear, double zFar);
16 void GL_UseColorArray(void);
17 void GL_Color(float cr, float cg, float cb, float ca);
18 void GL_TransformToScreen(const vec4_t in, vec4_t out);
19 void GL_LockArrays(int first, int count);
20
21 extern cvar_t gl_lockarrays;
22 extern cvar_t gl_mesh_copyarrays;
23
24 extern int c_meshelements, c_meshs;
25
26 //input to R_Mesh_State
27 typedef struct
28 {
29         int depthwrite; // force depth writing enabled even if polygon is not opaque
30         int depthdisable; // disable depth read/write entirely
31         int blendfunc1;
32         int blendfunc2;
33         //int wantoverbright;
34         int tex1d[MAX_TEXTUREUNITS];
35         int tex[MAX_TEXTUREUNITS];
36         int tex3d[MAX_TEXTUREUNITS];
37         int texcubemap[MAX_TEXTUREUNITS];
38         int texrgbscale[MAX_TEXTUREUNITS]; // used only if COMBINE is present
39         int texalphascale[MAX_TEXTUREUNITS]; // used only if COMBINE is present
40         int texcombinergb[MAX_TEXTUREUNITS]; // works with or without combine for some operations
41         int texcombinealpha[MAX_TEXTUREUNITS]; // does nothing without combine
42         int pointervertexcount;
43         float *pointer_vertex;
44         float *pointer_color;
45         float *pointer_texcoord[MAX_TEXTUREUNITS];
46 }
47 rmeshstate_t;
48
49 // overbright rendering scale for the current state
50 extern int r_lightmapscalebit;
51 extern float r_colorscale;
52 extern float *varray_vertex3f;
53 extern float *varray_color4f;
54 extern float *varray_texcoord3f[MAX_TEXTUREUNITS];
55 extern float *varray_texcoord2f[MAX_TEXTUREUNITS];
56 extern int mesh_maxverts;
57
58 // adds console variables and registers the render module (only call from GL_Init)
59 void gl_backend_init(void);
60
61 // starts mesh rendering for the frame
62 void R_Mesh_Start(void);
63
64 // ends mesh rendering for the frame
65 // (only valid after R_Mesh_Start)
66 void R_Mesh_Finish(void);
67
68 // sets up the requested transform matrix
69 void R_Mesh_Matrix(const matrix4x4_t *matrix);
70
71 // sets up the requested state
72 void R_Mesh_State(const rmeshstate_t *m);
73
74 // sets up the requested main state
75 void R_Mesh_MainState(const rmeshstate_t *m);
76
77 // sets up the requested texture state
78 void R_Mesh_TextureState(const rmeshstate_t *m);
79
80 // forcefully ends a batch (do this before calling any gl functions directly)
81 void R_Mesh_EndBatch(void);
82 // prepares varray_* buffers for rendering a mesh
83 void R_Mesh_GetSpace(int numverts);
84 // renders a mesh (optionally with batching)
85 void R_Mesh_Draw(int numverts, int numtriangles, const int *elements);
86 // renders a mesh without affecting batching
87 void R_Mesh_Draw_NoBatching(int numverts, int numtriangles, const int *elements);
88
89 // copies a vertex3f array into varray_vertex3f
90 void R_Mesh_CopyVertex3f(const float *vertex3f, int numverts);
91 // copies a texcoord2f array into varray_texcoord[tmu]
92 void R_Mesh_CopyTexCoord2f(int tmu, const float *texcoord2f, int numverts);
93 // copies a color4f array into varray_color4f
94 void R_Mesh_CopyColor4f(const float *color4f, int numverts);
95
96 // saves a section of the rendered frame to a .tga or .jpg file
97 qboolean SCR_ScreenShot(char *filename, int x, int y, int width, int height, qboolean jpeg);
98 // used by R_Envmap_f and internally in backend, clears the frame
99 void R_ClearScreen(void);
100 // invoke refresh of frame
101 void SCR_UpdateScreen (void);
102
103 // public structure
104 typedef struct rcachearrayrequest_s
105 {
106         // for use by the code that is requesting the array, these are not
107         // directly used but merely compared to determine if cache items are
108         // identical
109         const void *id_pointer1;
110         const void *id_pointer2;
111         const void *id_pointer3;
112         int id_number1;
113         int id_number2;
114         int id_number3;
115         // size of array data
116         int data_size;
117         // array data pointer
118         void *data;
119 }
120 rcachearrayrequest_t;
121
122 int R_Mesh_CacheArray(rcachearrayrequest_t *r);
123
124 #endif
125