cvar_t v_flipped = {0, "v_flipped", "0", "mirror the screen (poor man's left handed mode)"};
qboolean v_flipped_state = false;
+r_viewport_t gl_viewport;
+matrix4x4_t gl_modelmatrix;
+matrix4x4_t gl_viewmatrix;
+matrix4x4_t gl_modelviewmatrix;
+matrix4x4_t gl_projectionmatrix;
+matrix4x4_t gl_modelviewprojectionmatrix;
+float gl_modelview16f[16];
+float gl_modelviewprojection16f[16];
+qboolean gl_modelmatrixchanged;
+
int gl_maxdrawrangeelementsvertices;
int gl_maxdrawrangeelementsindices;
memexpandablearray_t bufferobjectinfoarray;
- r_viewport_t viewport;
- matrix4x4_t modelmatrix;
- matrix4x4_t modelviewmatrix;
-
qboolean active;
}
gl_state_t;
out[2] = v->z + (out[2] * iw + 1.0f) * v->depth * 0.5f;
}
-static void R_Viewport_ApplyNearClipPlane(r_viewport_t *v, double normalx, double normaly, double normalz, double dist)
+static void R_Viewport_ApplyNearClipPlane(r_viewport_t *v, float normalx, float normaly, float normalz, float dist)
{
- double q[4];
- double d;
+ float q[4];
+ float d;
float clipPlane[4], v3[3], v4[3];
float normal[3];
// testing code for comparing results
float clipPlane2[4];
VectorCopy4(clipPlane, clipPlane2);
- R_Mesh_Matrix(&identitymatrix);
+ R_EntityMatrix(&identitymatrix);
VectorSet(q, normal[0], normal[1], normal[2], -dist);
qglClipPlane(GL_CLIP_PLANE0, q);
qglGetClipPlane(GL_CLIP_PLANE0, q);
v->m[14] = clipPlane[3] * d;
}
-void R_Viewport_InitOrtho(r_viewport_t *v, const matrix4x4_t *cameramatrix, int x, int y, int width, int height, double x1, double y1, double x2, double y2, double nearclip, double farclip, const double *nearplane)
+void R_Viewport_InitOrtho(r_viewport_t *v, const matrix4x4_t *cameramatrix, int x, int y, int width, int height, float x1, float y1, float x2, float y2, float nearclip, float farclip, const float *nearplane)
{
float left = x1, right = x2, bottom = y2, top = y1, zNear = nearclip, zFar = farclip;
memset(v, 0, sizeof(*v));
#endif
}
-void R_Viewport_InitPerspective(r_viewport_t *v, const matrix4x4_t *cameramatrix, int x, int y, int width, int height, double frustumx, double frustumy, double nearclip, double farclip, const double *nearplane)
+void R_Viewport_InitPerspective(r_viewport_t *v, const matrix4x4_t *cameramatrix, int x, int y, int width, int height, float frustumx, float frustumy, float nearclip, float farclip, const float *nearplane)
{
matrix4x4_t tempmatrix, basematrix;
memset(v, 0, sizeof(*v));
R_Viewport_ApplyNearClipPlane(v, nearplane[0], nearplane[1], nearplane[2], nearplane[3]);
}
-void R_Viewport_InitPerspectiveInfinite(r_viewport_t *v, const matrix4x4_t *cameramatrix, int x, int y, int width, int height, double frustumx, double frustumy, double nearclip, const double *nearplane)
+void R_Viewport_InitPerspectiveInfinite(r_viewport_t *v, const matrix4x4_t *cameramatrix, int x, int y, int width, int height, float frustumx, float frustumy, float nearclip, const float *nearplane)
{
matrix4x4_t tempmatrix, basematrix;
- const double nudge = 1.0 - 1.0 / (1<<23);
+ const float nudge = 1.0 - 1.0 / (1<<23);
memset(v, 0, sizeof(*v));
if(v_flipped.integer)
void R_SetViewport(const r_viewport_t *v)
{
- float glmatrix[16];
- gl_state.viewport = *v;
+ gl_viewport = *v;
CHECKGLERROR
qglViewport(v->x, v->y, v->width, v->height);CHECKGLERROR
- // Load the projection matrix into OpenGL
- qglMatrixMode(GL_PROJECTION);CHECKGLERROR
- qglLoadMatrixf(gl_state.viewport.m);CHECKGLERROR
- qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
-
// FIXME: v_flipped_state is evil, this probably breaks somewhere
GL_SetMirrorState(v_flipped.integer && (v->type == R_VIEWPORTTYPE_PERSPECTIVE || v->type == R_VIEWPORTTYPE_PERSPECTIVE_INFINITEFARCLIP));
- // directly force an update of the modelview matrix
- Matrix4x4_Concat(&gl_state.modelviewmatrix, &gl_state.viewport.viewmatrix, &gl_state.modelmatrix);
- Matrix4x4_ToArrayFloatGL(&gl_state.modelviewmatrix, glmatrix);
- qglLoadMatrixf(glmatrix);CHECKGLERROR
+ // copy over the matrices to our state
+ gl_viewmatrix = v->viewmatrix;
+ gl_projectionmatrix = v->projectmatrix;
+
+ switch(vid.renderpath)
+ {
+ case RENDERPATH_GL20:
+ case RENDERPATH_CGGL:
+// break;
+ case RENDERPATH_GL13:
+ case RENDERPATH_GL11:
+ // Load the projection matrix into OpenGL
+ qglMatrixMode(GL_PROJECTION);CHECKGLERROR
+ qglLoadMatrixf(gl_viewport.m);CHECKGLERROR
+ qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
+ break;
+ }
+
+ // force an update of the derived matrices
+ gl_modelmatrixchanged = true;
+ R_EntityMatrix(&gl_modelmatrix);
}
void R_GetViewport(r_viewport_t *v)
{
- *v = gl_state.viewport;
+ *v = gl_viewport;
}
static void GL_BindVBO(int bufferobject)
qglCompileShaderARB(shaderobject);CHECKGLERROR
qglGetObjectParameterivARB(shaderobject, GL_OBJECT_COMPILE_STATUS_ARB, &shadercompiled);CHECKGLERROR
qglGetInfoLogARB(shaderobject, sizeof(compilelog), NULL, compilelog);CHECKGLERROR
- if (compilelog[0] && developer.integer > 0 && (strstr(compilelog, "error") || strstr(compilelog, "ERROR") || strstr(compilelog, "Error") || strstr(compilelog, "WARNING") || strstr(compilelog, "warning") || strstr(compilelog, "Warning")))
+ if (compilelog[0] && (strstr(compilelog, "error") || strstr(compilelog, "ERROR") || strstr(compilelog, "Error") || strstr(compilelog, "WARNING") || strstr(compilelog, "warning") || strstr(compilelog, "Warning")))
{
int i, j, pretextlines = 0;
for (i = 0;i < numstrings - 1;i++)
for (j = 0;strings[i][j];j++)
if (strings[i][j] == '\n')
pretextlines++;
- Con_DPrintf("%s shader compile log:\n%s\n(line offset for any above warnings/errors: %i)\n", shadertype, compilelog, pretextlines);
+ Con_Printf("%s shader compile log:\n%s\n(line offset for any above warnings/errors: %i)\n", shadertype, compilelog, pretextlines);
}
if (!shadercompiled)
{
unsigned int numelements = numtriangles * 3;
if (numvertices < 3 || numtriangles < 1)
{
- if (numvertices < 0 || numtriangles < 0 || developer.integer >= 100)
- Con_Printf("R_Mesh_Draw(%d, %d, %d, %d, %8p, %8p, %i, %i);\n", firstvertex, numvertices, firsttriangle, numtriangles, (void *)element3i, (void *)element3s, bufferobject3i, bufferobject3s);
+ if (numvertices < 0 || numtriangles < 0 || developer_extra.integer)
+ Con_DPrintf("R_Mesh_Draw(%d, %d, %d, %d, %8p, %8p, %i, %i);\n", firstvertex, numvertices, firsttriangle, numtriangles, (void *)element3i, (void *)element3s, bufferobject3i, bufferobject3s);
return;
}
if (!gl_mesh_prefer_short_elements.integer)
Con_Printf("vertex buffers: %i element buffers totalling %i bytes (%.3f MB), %i vertex buffers totalling %i bytes (%.3f MB), combined %i bytes (%.3fMB)\n", (int)ebocount, (int)ebomemory, ebomemory / 1048576.0, (int)vbocount, (int)vbomemory, vbomemory / 1048576.0, (int)(ebomemory + vbomemory), (ebomemory + vbomemory) / 1048576.0);
}
-void R_Mesh_Matrix(const matrix4x4_t *matrix)
-{
- if (memcmp(matrix, &gl_state.modelmatrix, sizeof(matrix4x4_t)))
- {
- float glmatrix[16];
- gl_state.modelmatrix = *matrix;
- Matrix4x4_Concat(&gl_state.modelviewmatrix, &gl_state.viewport.viewmatrix, &gl_state.modelmatrix);
- Matrix4x4_ToArrayFloatGL(&gl_state.modelviewmatrix, glmatrix);
- CHECKGLERROR
- qglLoadMatrixf(glmatrix);CHECKGLERROR
- }
-}
-
void R_Mesh_VertexPointer(const float *vertex3f, int bufferobject, size_t bufferoffset)
{
if (!gl_vbo.integer || gl_mesh_testarrayelement.integer)
}
}
-void R_Mesh_TexBindAll(unsigned int unitnum, int tex2d, int tex3d, int texcubemap, int texrectangle)
+int R_Mesh_TexBound(unsigned int unitnum, int id)
+{
+ gltextureunit_t *unit = gl_state.units + unitnum;
+ if (unitnum >= vid.teximageunits)
+ return 0;
+ if (id == GL_TEXTURE_2D)
+ return unit->t2d;
+ if (id == GL_TEXTURE_3D)
+ return unit->t3d;
+ if (id == GL_TEXTURE_CUBE_MAP_ARB)
+ return unit->tcubemap;
+ if (id == GL_TEXTURE_RECTANGLE_ARB)
+ return unit->trectangle;
+ return 0;
+}
+
+void R_Mesh_CopyToTexture(rtexture_t *tex, int tx, int ty, int sx, int sy, int width, int height)
+{
+ R_Mesh_TexBind(0, tex);
+ GL_ActiveTexture(0);CHECKGLERROR
+ qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, tx, ty, sx, sy, width, height);CHECKGLERROR
+}
+
+void R_Mesh_TexBind(unsigned int unitnum, rtexture_t *tex)
{
gltextureunit_t *unit = gl_state.units + unitnum;
+ int tex2d, tex3d, texcubemap, texnum;
if (unitnum >= vid.teximageunits)
return;
- // update 2d texture binding
- if (unit->t2d != tex2d)
+ switch(vid.renderpath)
{
- GL_ActiveTexture(unitnum);
- if (unitnum < vid.texunits)
+ case RENDERPATH_GL20:
+ case RENDERPATH_CGGL:
+ if (!tex)
+ tex = r_texture_white;
+ texnum = R_GetTexture(tex);
+ switch(tex->gltexturetypeenum)
+ {
+ case GL_TEXTURE_2D: if (unit->t2d != texnum) {GL_ActiveTexture(unitnum);unit->t2d = texnum;qglBindTexture(GL_TEXTURE_2D, unit->t2d);CHECKGLERROR}break;
+ case GL_TEXTURE_3D: if (unit->t3d != texnum) {GL_ActiveTexture(unitnum);unit->t3d = texnum;qglBindTexture(GL_TEXTURE_3D, unit->t3d);CHECKGLERROR}break;
+ case GL_TEXTURE_CUBE_MAP_ARB: if (unit->tcubemap != texnum) {GL_ActiveTexture(unitnum);unit->tcubemap = texnum;qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);CHECKGLERROR}break;
+ case GL_TEXTURE_RECTANGLE_ARB: if (unit->trectangle != texnum) {GL_ActiveTexture(unitnum);unit->trectangle = texnum;qglBindTexture(GL_TEXTURE_RECTANGLE_ARB, unit->trectangle);CHECKGLERROR}break;
+ }
+ break;
+ case RENDERPATH_GL13:
+ case RENDERPATH_GL11:
+ tex2d = 0;
+ tex3d = 0;
+ texcubemap = 0;
+ if (tex)
{
+ texnum = R_GetTexture(tex);
+ switch(tex->gltexturetypeenum)
+ {
+ case GL_TEXTURE_2D:
+ tex2d = texnum;
+ break;
+ case GL_TEXTURE_3D:
+ tex3d = texnum;
+ break;
+ case GL_TEXTURE_CUBE_MAP_ARB:
+ texcubemap = texnum;
+ break;
+ }
+ }
+ // update 2d texture binding
+ if (unit->t2d != tex2d)
+ {
+ GL_ActiveTexture(unitnum);
if (tex2d)
{
if (unit->t2d == 0)
qglDisable(GL_TEXTURE_2D);CHECKGLERROR
}
}
+ unit->t2d = tex2d;
+ qglBindTexture(GL_TEXTURE_2D, unit->t2d);CHECKGLERROR
}
- unit->t2d = tex2d;
- qglBindTexture(GL_TEXTURE_2D, unit->t2d);CHECKGLERROR
- }
- // update 3d texture binding
- if (unit->t3d != tex3d)
- {
- GL_ActiveTexture(unitnum);
- if (unitnum < vid.texunits)
+ // update 3d texture binding
+ if (unit->t3d != tex3d)
{
+ GL_ActiveTexture(unitnum);
if (tex3d)
{
if (unit->t3d == 0)
qglDisable(GL_TEXTURE_3D);CHECKGLERROR
}
}
+ unit->t3d = tex3d;
+ qglBindTexture(GL_TEXTURE_3D, unit->t3d);CHECKGLERROR
}
- unit->t3d = tex3d;
- qglBindTexture(GL_TEXTURE_3D, unit->t3d);CHECKGLERROR
- }
- // update cubemap texture binding
- if (unit->tcubemap != texcubemap)
- {
- GL_ActiveTexture(unitnum);
- if (unitnum < vid.texunits)
+ // update cubemap texture binding
+ if (unit->tcubemap != texcubemap)
{
+ GL_ActiveTexture(unitnum);
if (texcubemap)
{
if (unit->tcubemap == 0)
qglDisable(GL_TEXTURE_CUBE_MAP_ARB);CHECKGLERROR
}
}
+ unit->tcubemap = texcubemap;
+ qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);CHECKGLERROR
}
- unit->tcubemap = texcubemap;
- qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);CHECKGLERROR
- }
- // update rectangle texture binding
- if (unit->trectangle != texrectangle)
- {
- GL_ActiveTexture(unitnum);
- if (unitnum < vid.texunits)
- {
- if (texrectangle)
- {
- if (unit->trectangle == 0)
- {
- qglEnable(GL_TEXTURE_RECTANGLE_ARB);CHECKGLERROR
- }
- }
- else
- {
- if (unit->trectangle)
- {
- qglDisable(GL_TEXTURE_RECTANGLE_ARB);CHECKGLERROR
- }
- }
- }
- unit->trectangle = texrectangle;
- qglBindTexture(GL_TEXTURE_RECTANGLE_ARB, unit->trectangle);CHECKGLERROR
- }
-}
-
-void R_Mesh_TexBind(unsigned int unitnum, int texnum)
-{
- gltextureunit_t *unit = gl_state.units + unitnum;
- if (unitnum >= vid.teximageunits)
- return;
- // update 2d texture binding
- if (unit->t2d != texnum)
- {
- GL_ActiveTexture(unitnum);
- if (unitnum < vid.texunits)
- {
- if (texnum)
- {
- if (unit->t2d == 0)
- {
- qglEnable(GL_TEXTURE_2D);CHECKGLERROR
- }
- }
- else
- {
- if (unit->t2d)
- {
- qglDisable(GL_TEXTURE_2D);CHECKGLERROR
- }
- }
- }
- unit->t2d = texnum;
- qglBindTexture(GL_TEXTURE_2D, unit->t2d);CHECKGLERROR
- }
- // update 3d texture binding
- if (unit->t3d)
- {
- GL_ActiveTexture(unitnum);
- if (unitnum < vid.texunits)
- {
- if (unit->t3d)
- {
- qglDisable(GL_TEXTURE_3D);CHECKGLERROR
- }
- }
- unit->t3d = 0;
- qglBindTexture(GL_TEXTURE_3D, unit->t3d);CHECKGLERROR
- }
- // update cubemap texture binding
- if (unit->tcubemap != 0)
- {
- GL_ActiveTexture(unitnum);
- if (unitnum < vid.texunits)
- {
- if (unit->tcubemap)
- {
- qglDisable(GL_TEXTURE_CUBE_MAP_ARB);CHECKGLERROR
- }
- }
- unit->tcubemap = 0;
- qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);CHECKGLERROR
- }
- // update rectangle texture binding
- if (unit->trectangle != 0)
- {
- GL_ActiveTexture(unitnum);
- if (unitnum < vid.texunits)
- {
- if (unit->trectangle)
- {
- qglDisable(GL_TEXTURE_RECTANGLE_ARB);CHECKGLERROR
- }
- }
- unit->trectangle = 0;
- qglBindTexture(GL_TEXTURE_RECTANGLE_ARB, unit->trectangle);CHECKGLERROR
+ break;
}
}
switch(vid.renderpath)
{
case RENDERPATH_GL20:
+ case RENDERPATH_CGGL:
// do nothing
break;
case RENDERPATH_GL13:
switch(vid.renderpath)
{
case RENDERPATH_GL20:
+ case RENDERPATH_CGGL:
for (unitnum = 0;unitnum < vid.teximageunits;unitnum++)
{
gltextureunit_t *unit = gl_state.units + unitnum;