]> icculus.org git repositories - divverent/darkplaces.git/blob - gl_backend.h
added tracking of memory usage of VBO/EBO buffers
[divverent/darkplaces.git] / gl_backend.h
1
2 #ifndef GL_BACKEND_H
3 #define GL_BACKEND_H
4
5 // how many texture units to track state on (backendunits/backendimageunits/backendarrayunits are limited to this value)
6 #define MAX_TEXTUREUNITS 64
7
8 #define POLYGONELEMENTS_MAXPOINTS 258
9 extern int polygonelements[(POLYGONELEMENTS_MAXPOINTS-2)*3];
10 #define QUADELEMENTS_MAXQUADS 128
11 extern int quadelements[QUADELEMENTS_MAXQUADS*6];
12
13 void GL_SetupView_Orientation_Identity(void);
14 void GL_SetupView_Orientation_FromEntity(const matrix4x4_t *matrix);
15 void GL_SetupView_Mode_Perspective(double frustumx, double frustumy, double zNear, double zFar);
16 void GL_SetupView_Mode_PerspectiveInfiniteFarClip(double frustumx, double frustumy, double zNear);
17 void GL_SetupView_Mode_Ortho(double x1, double y1, double x2, double y2, double zNear, double zFar);
18 void GL_BlendFunc(int blendfunc1, int blendfunc2);
19 void GL_DepthMask(int state);
20 void GL_DepthTest(int state);
21 void GL_DepthRange(float nearfrac, float farfrac);
22 void GL_CullFace(int state);
23 void GL_AlphaTest(int state);
24 void GL_ColorMask(int r, int g, int b, int a);
25 void GL_Color(float cr, float cg, float cb, float ca);
26 void GL_TransformToScreen(const vec4_t in, vec4_t out);
27 void GL_LockArrays(int first, int count);
28 void GL_ActiveTexture(unsigned int num);
29 void GL_ClientActiveTexture(unsigned int num);
30 void GL_Scissor(int x, int y, int width, int height);
31 void GL_ScissorTest(int state);
32 void GL_Clear(int mask);
33
34 unsigned int GL_Backend_CompileProgram(int vertexstrings_count, const char **vertexstrings_list, int geometrystrings_count, const char **geometrystrings_list, int fragmentstrings_count, const char **fragmentstrings_list);
35 void GL_Backend_FreeProgram(unsigned int prog);
36
37 extern cvar_t gl_lockarrays;
38 extern cvar_t gl_mesh_copyarrays;
39 extern cvar_t gl_paranoid;
40 extern cvar_t gl_printcheckerror;
41
42 //input to R_Mesh_TextureState
43 typedef struct rmeshstate_s
44 {
45         // textures
46         int tex1d[MAX_TEXTUREUNITS];
47         int tex[MAX_TEXTUREUNITS];
48         int tex3d[MAX_TEXTUREUNITS];
49         int texcubemap[MAX_TEXTUREUNITS];
50         // texture combine settings
51         int texrgbscale[MAX_TEXTUREUNITS]; // used only if COMBINE is present
52         int texalphascale[MAX_TEXTUREUNITS]; // used only if COMBINE is present
53         int texcombinergb[MAX_TEXTUREUNITS]; // works with or without combine for some operations
54         int texcombinealpha[MAX_TEXTUREUNITS]; // does nothing without combine
55         // matrices
56         matrix4x4_t texmatrix[MAX_TEXTUREUNITS];
57         // pointers
58         const float *pointer_texcoord[MAX_TEXTUREUNITS]; // 2D
59         const float *pointer_texcoord3f[MAX_TEXTUREUNITS]; // 3D
60         int pointer_texcoord_bufferobject[MAX_TEXTUREUNITS]; // 2D and 3D
61         size_t pointer_texcoord_bufferoffset[MAX_TEXTUREUNITS]; // 2D and 3D
62 }
63 rmeshstate_t;
64
65 // adds console variables and registers the render module (only call from GL_Init)
66 void gl_backend_init(void);
67
68 // starts mesh rendering for the frame
69 void R_Mesh_Start(void);
70
71 // ends mesh rendering for the frame
72 // (only valid after R_Mesh_Start)
73 void R_Mesh_Finish(void);
74
75 // allocates a static element array buffer object
76 // (storing triangle data in video memory)
77 int R_Mesh_CreateStaticEBO(void *data, size_t size);
78 // frees an element array buffer object
79 void R_Mesh_DestroyEBO(int bufferobject);
80 // allocates a static vertex/element array buffer object
81 // (storing vertex or element data in video memory)
82 // target is GL_ELEMENT_ARRAY_BUFFER_ARB (triangle elements)
83 // or GL_ARRAY_BUFFER_ARB (vertex data)
84 int R_Mesh_CreateStaticBufferObject(unsigned int target, void *data, size_t size, const char *name);
85 // frees a vertex/element array buffer object
86 void R_Mesh_DestroyBufferObject(int bufferobject);
87 void GL_Mesh_ListVBOs(qboolean printeach);
88
89 // sets up the requested vertex transform matrix
90 void R_Mesh_Matrix(const matrix4x4_t *matrix);
91 // sets the vertex array pointer
92 void R_Mesh_VertexPointer(const float *vertex3f, int bufferobject, size_t bufferoffset);
93 // sets the color array pointer (GL_Color only works when this is NULL)
94 void R_Mesh_ColorPointer(const float *color4f, int bufferobject, size_t bufferoffset);
95 // sets the texcoord array pointer for an array unit
96 void R_Mesh_TexCoordPointer(unsigned int unitnum, unsigned int numcomponents, const float *texcoord, int bufferobject, size_t bufferoffset);
97 // sets all textures bound to an image unit (multiple can be non-zero at once, according to OpenGL rules the highest one overrides the others)
98 void R_Mesh_TexBindAll(unsigned int unitnum, int tex1d, int tex2d, int tex3d, int texcubemap);
99 // sets these are like TexBindAll with only one of the texture indices non-zero
100 // (binds one texture type and unbinds all other types)
101 void R_Mesh_TexBind1D(unsigned int unitnum, int texnum);
102 void R_Mesh_TexBind(unsigned int unitnum, int texnum);
103 void R_Mesh_TexBind3D(unsigned int unitnum, int texnum);
104 void R_Mesh_TexBindCubeMap(unsigned int unitnum, int texnum);
105 // sets the texcoord matrix for a texenv unit
106 void R_Mesh_TexMatrix(unsigned int unitnum, const matrix4x4_t *matrix);
107 // sets the combine state for a texenv unit
108 void R_Mesh_TexCombine(unsigned int unitnum, int combinergb, int combinealpha, int rgbscale, int alphascale);
109 // set up the requested texture state
110 void R_Mesh_TextureState(const rmeshstate_t *m);
111 // set up a blank texture state (faster/easier specialized version of R_Mesh_TextureState)
112 void R_Mesh_ResetTextureState(void);
113
114 // renders a mesh
115 void R_Mesh_Draw(int firstvertex, int numvertices, int numtriangles, const int *elements, int bufferobject, size_t bufferoffset);
116 // renders a mesh as lines
117 void R_Mesh_Draw_ShowTris(int firstvertex, int numvertices, int numtriangles, const int *elements);
118
119 // saves a section of the rendered frame to a .tga or .jpg file
120 qboolean SCR_ScreenShot(char *filename, unsigned char *buffer1, unsigned char *buffer2, unsigned char *buffer3, int x, int y, int width, int height, qboolean flipx, qboolean flipy, qboolean flipdiagonal, qboolean jpeg, qboolean gammacorrect);
121 // used by R_Envmap_f and internally in backend, clears the frame
122 void R_ClearScreen(void);
123 // invoke refresh of loading plaque (nothing else seen)
124 void SCR_UpdateLoadingScreen(qboolean clear);
125
126 #endif
127