cvar_t gl_paranoid = {0, "gl_paranoid", "0", "enables OpenGL error checking and other tests"};
cvar_t gl_printcheckerror = {0, "gl_printcheckerror", "0", "prints all OpenGL error checks, useful to identify location of driver crashes"};
-cvar_t r_render = {0, "r_render", "1", "enables rendering calls (you want this on!)"};
+cvar_t r_render = {0, "r_render", "1", "enables rendering 3D views (you want this on!)"};
+cvar_t r_renderview = {0, "r_renderview", "1", "enables rendering 3D views (you want this on!)"};
cvar_t r_waterwarp = {CVAR_SAVE, "r_waterwarp", "1", "warp view while underwater"};
cvar_t gl_polyblend = {CVAR_SAVE, "gl_polyblend", "1", "tints view while underwater, hurt, etc"};
cvar_t gl_dither = {CVAR_SAVE, "gl_dither", "1", "enables OpenGL dithering (16bit looks bad with this off)"};
cvar_t gl_lockarrays = {0, "gl_lockarrays", "0", "enables use of glLockArraysEXT, may cause glitches with some broken drivers, and may be slower than normal"};
cvar_t gl_lockarrays_minimumvertices = {0, "gl_lockarrays_minimumvertices", "1", "minimum number of vertices required for use of glLockArraysEXT, setting this too low may reduce performance"};
cvar_t gl_vbo = {CVAR_SAVE, "gl_vbo", "3", "make use of GL_ARB_vertex_buffer_object extension to store static geometry in video memory for faster rendering, 0 disables VBO allocation or use, 1 enables VBOs for vertex and triangle data, 2 only for vertex data, 3 for vertex data and triangle data of simple meshes (ones with only one surface)"};
+cvar_t gl_fbo = {CVAR_SAVE, "gl_fbo", "1", "make use of GL_ARB_framebuffer_object extension to enable shadowmaps and other features using pixel formats different from the framebuffer"};
cvar_t v_flipped = {0, "v_flipped", "0", "mirror the screen (poor man's left handed mode)"};
qboolean v_flipped_state = false;
case GL_TABLE_TOO_LARGE:
Con_Printf("GL_TABLE_TOO_LARGE at %s:%i\n", filename, linenumber);
break;
+#endif
+#ifdef GL_INVALID_FRAMEBUFFER_OPERATION_EXT
+ case GL_INVALID_FRAMEBUFFER_OPERATION_EXT:
+ Con_Printf("GL_INVALID_FRAMEBUFFER_OPERATION at %s:%i\n", filename, linenumber);
+ break;
#endif
default:
Con_Printf("GL UNKNOWN (%i) at %s:%i\n", errornumber, filename, linenumber);
void SCR_ScreenShot_f (void);
-static matrix4x4_t backend_viewmatrix;
+typedef struct gl_bufferobjectinfo_s
+{
+ int target;
+ int object;
+ size_t size;
+ char name[MAX_QPATH];
+}
+gl_bufferobjectinfo_t;
+
+typedef struct gltextureunit_s
+{
+ const void *pointer_texcoord;
+ size_t pointer_texcoord_offset;
+ int pointer_texcoord_buffer;
+ int t2d, t3d, tcubemap, trectangle;
+ int arrayenabled;
+ unsigned int arraycomponents;
+ int rgbscale, alphascale;
+ int combinergb, combinealpha;
+ // texmatrixenabled exists only to avoid unnecessary texmatrix compares
+ int texmatrixenabled;
+ matrix4x4_t matrix;
+}
+gltextureunit_t;
+
+typedef struct gl_state_s
+{
+ int cullface;
+ int cullfaceenable;
+ int blendfunc1;
+ int blendfunc2;
+ int blend;
+ GLboolean depthmask;
+ int colormask; // stored as bottom 4 bits: r g b a (3 2 1 0 order)
+ int depthtest;
+ float depthrange[2];
+ float polygonoffset[2];
+ int alphatest;
+ int scissortest;
+ unsigned int unit;
+ unsigned int clientunit;
+ gltextureunit_t units[MAX_TEXTUREUNITS];
+ float color4f[4];
+ int lockrange_first;
+ int lockrange_count;
+ int vertexbufferobject;
+ int elementbufferobject;
+ qboolean pointer_color_enabled;
+ const void *pointer_vertex;
+ const void *pointer_color;
+ size_t pointer_vertex_offset;
+ size_t pointer_color_offset;
+ int pointer_vertex_buffer;
+ int pointer_color_buffer;
+}
+gl_state_t;
+
+static gl_state_t gl_state;
+
+static memexpandablearray_t gl_bufferobjectinfoarray;
+
+static r_viewport_t backend_viewport;
static matrix4x4_t backend_modelmatrix;
static matrix4x4_t backend_modelviewmatrix;
-static matrix4x4_t backend_projectmatrix;
-static unsigned int backendunits, backendimageunits, backendarrayunits, backendactive;
+static unsigned int backendactive;
/*
note: here's strip order for a terrain row:
}
*/
-unsigned short polygonelements[(POLYGONELEMENTS_MAXPOINTS-2)*3];
-unsigned short quadelements[QUADELEMENTS_MAXQUADS*6];
-
-void GL_Backend_AllocArrays(void)
-{
-}
-
-void GL_Backend_FreeArrays(void)
-{
-}
+int polygonelement3i[(POLYGONELEMENTS_MAXPOINTS-2)*3];
+unsigned short polygonelement3s[(POLYGONELEMENTS_MAXPOINTS-2)*3];
+int quadelement3i[QUADELEMENTS_MAXQUADS*6];
+unsigned short quadelement3s[QUADELEMENTS_MAXQUADS*6];
void GL_VBOStats_f(void)
{
GL_Mesh_ListVBOs(true);
}
-typedef struct gl_bufferobjectinfo_s
-{
- int target;
- int object;
- size_t size;
- char name[MAX_QPATH];
-}
-gl_bufferobjectinfo_t;
-
-memexpandablearray_t gl_bufferobjectinfoarray;
-
static void gl_backend_start(void)
{
CHECKGLERROR
Con_DPrintf("GL_MAX_ELEMENTS_VERTICES = %i\nGL_MAX_ELEMENTS_INDICES = %i\n", gl_maxdrawrangeelementsvertices, gl_maxdrawrangeelementsindices);
}
- backendunits = bound(1, gl_textureunits, MAX_TEXTUREUNITS);
- backendimageunits = backendunits;
- backendarrayunits = backendunits;
- if (gl_support_fragment_shader)
+ if (vid.support.arb_fragment_shader)
{
- CHECKGLERROR
- qglGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, (int *)&backendimageunits);
- CHECKGLERROR
- qglGetIntegerv(GL_MAX_TEXTURE_COORDS_ARB, (int *)&backendarrayunits);
- CHECKGLERROR
- Con_DPrintf("GLSL shader support detected: texture units = %i texenv, %i image, %i array\n", backendunits, backendimageunits, backendarrayunits);
- backendimageunits = bound(1, backendimageunits, MAX_TEXTUREUNITS);
- backendarrayunits = bound(1, backendarrayunits, MAX_TEXTUREUNITS);
+ Con_DPrintf("GLSL shader support detected: texture units = %i texenv, %i image, %i array\n", vid.texunits, vid.teximageunits, vid.texarrayunits);
+ vid.teximageunits = bound(1, vid.teximageunits, MAX_TEXTUREUNITS);
+ vid.texarrayunits = bound(1, vid.texarrayunits, MAX_TEXTUREUNITS);
}
else
- Con_DPrintf("GL_MAX_TEXTUREUNITS = %i\n", backendunits);
-
- GL_Backend_AllocArrays();
+ Con_DPrintf("GL_MAX_TEXTUREUNITS = %i\n", vid.texunits);
Mem_ExpandableArray_NewArray(&gl_bufferobjectinfoarray, r_main_mempool, sizeof(gl_bufferobjectinfo_t), 128);
static void gl_backend_shutdown(void)
{
- backendunits = 0;
- backendimageunits = 0;
- backendarrayunits = 0;
backendactive = false;
Con_DPrint("OpenGL Backend shutting down\n");
Mem_ExpandableArray_FreeArray(&gl_bufferobjectinfoarray);
-
- GL_Backend_FreeArrays();
}
static void gl_backend_newmap(void)
for (i = 0;i < POLYGONELEMENTS_MAXPOINTS - 2;i++)
{
- polygonelements[i * 3 + 0] = 0;
- polygonelements[i * 3 + 1] = i + 1;
- polygonelements[i * 3 + 2] = i + 2;
+ polygonelement3s[i * 3 + 0] = 0;
+ polygonelement3s[i * 3 + 1] = i + 1;
+ polygonelement3s[i * 3 + 2] = i + 2;
}
// elements for rendering a series of quads as triangles
for (i = 0;i < QUADELEMENTS_MAXQUADS;i++)
{
- quadelements[i * 6 + 0] = i * 4;
- quadelements[i * 6 + 1] = i * 4 + 1;
- quadelements[i * 6 + 2] = i * 4 + 2;
- quadelements[i * 6 + 3] = i * 4;
- quadelements[i * 6 + 4] = i * 4 + 2;
- quadelements[i * 6 + 5] = i * 4 + 3;
+ quadelement3s[i * 6 + 0] = i * 4;
+ quadelement3s[i * 6 + 1] = i * 4 + 1;
+ quadelement3s[i * 6 + 2] = i * 4 + 2;
+ quadelement3s[i * 6 + 3] = i * 4;
+ quadelement3s[i * 6 + 4] = i * 4 + 2;
+ quadelement3s[i * 6 + 5] = i * 4 + 3;
}
+ for (i = 0;i < (POLYGONELEMENTS_MAXPOINTS - 2)*3;i++)
+ polygonelement3i[i] = polygonelement3s[i];
+ for (i = 0;i < QUADELEMENTS_MAXQUADS*3;i++)
+ quadelement3i[i] = quadelement3s[i];
+
Cvar_RegisterVariable(&r_render);
+ Cvar_RegisterVariable(&r_renderview);
Cvar_RegisterVariable(&r_waterwarp);
Cvar_RegisterVariable(&gl_polyblend);
Cvar_RegisterVariable(&v_flipped);
Cvar_RegisterVariable(&gl_vbo);
Cvar_RegisterVariable(&gl_paranoid);
Cvar_RegisterVariable(&gl_printcheckerror);
-#ifdef NORENDER
- Cvar_SetValue("r_render", 0);
-#endif
Cvar_RegisterVariable(&gl_mesh_drawrangeelements);
Cvar_RegisterVariable(&gl_mesh_testarrayelement);
void GL_SetMirrorState(qboolean state);
-void GL_SetupView_Orientation_Identity (void)
-{
- backend_viewmatrix = identitymatrix;
- GL_SetMirrorState(false);
- memset(&backend_modelmatrix, 0, sizeof(backend_modelmatrix));
-}
-
-void GL_SetupView_Orientation_FromEntity(const matrix4x4_t *matrix)
-{
- matrix4x4_t tempmatrix, basematrix;
- Matrix4x4_Invert_Full(&tempmatrix, matrix);
- Matrix4x4_CreateRotate(&basematrix, -90, 1, 0, 0);
- Matrix4x4_ConcatRotate(&basematrix, 90, 0, 0, 1);
- Matrix4x4_Concat(&backend_viewmatrix, &basematrix, &tempmatrix);
-
- GL_SetMirrorState(v_flipped.integer);
- if(v_flipped_state)
- {
- Matrix4x4_Transpose(&basematrix, &backend_viewmatrix);
- Matrix4x4_ConcatScale3(&basematrix, -1, 1, 1);
- Matrix4x4_Transpose(&backend_viewmatrix, &basematrix);
- }
-
- //Matrix4x4_ConcatRotate(&backend_viewmatrix, -angles[2], 1, 0, 0);
- //Matrix4x4_ConcatRotate(&backend_viewmatrix, -angles[0], 0, 1, 0);
- //Matrix4x4_ConcatRotate(&backend_viewmatrix, -angles[1], 0, 0, 1);
- //Matrix4x4_ConcatTranslate(&backend_viewmatrix, -origin[0], -origin[1], -origin[2]);
-
- // force an update of the model matrix by copying it off, resetting it, and then calling the R_Mesh_Matrix function with it
- tempmatrix = backend_modelmatrix;
- memset(&backend_modelmatrix, 0, sizeof(backend_modelmatrix));
- R_Mesh_Matrix(&tempmatrix);
-}
-
-static void GL_BuildFrustum(double m[16], double left, double right, double bottom, double top, double nearVal, double farVal)
-{
- m[0] = 2 * nearVal / (right - left);
- m[1] = 0;
- m[2] = 0;
- m[3] = 0;
-
- m[4] = 0;
- m[5] = 2 * nearVal / (top - bottom);
- m[6] = 0;
- m[7] = 0;
-
- m[8] = (right + left) / (right - left);
- m[9] = (top + bottom) / (top - bottom);
- m[10] = - (farVal + nearVal) / (farVal - nearVal);
- m[11] = -1;
-
- m[12] = 0;
- m[13] = 0;
- m[14] = - 2 * farVal * nearVal / (farVal - nearVal);
- m[15] = 0;
-}
-
-void GL_SetupView_Mode_Perspective (double frustumx, double frustumy, double zNear, double zFar)
-{
- double m[16];
-
- // set up viewpoint
- CHECKGLERROR
- qglMatrixMode(GL_PROJECTION);CHECKGLERROR
- // set view pyramid
-#if 1
- // avoid glGetDoublev whenever possible, it may stall the render pipeline
- // in the tested cases (nvidia) no measurable fps difference, but it sure
- // makes a difference over a network line with GLX
- GL_BuildFrustum(m, -frustumx * zNear, frustumx * zNear, -frustumy * zNear, frustumy * zNear, zNear, zFar);
- qglLoadMatrixd(m);CHECKGLERROR
-#else
- qglLoadIdentity();CHECKGLERROR
- qglFrustum(-frustumx * zNear, frustumx * zNear, -frustumy * zNear, frustumy * zNear, zNear, zFar);CHECKGLERROR
- qglGetDoublev(GL_PROJECTION_MATRIX, m);CHECKGLERROR
-#endif
- Matrix4x4_FromArrayDoubleGL(&backend_projectmatrix, m);
- qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
- GL_SetupView_Orientation_Identity();
- CHECKGLERROR
-}
-
-void GL_SetupView_Mode_PerspectiveInfiniteFarClip (double frustumx, double frustumy, double zNear)
-{
- double nudge, m[16];
-
- // set up viewpoint
- CHECKGLERROR
- qglMatrixMode(GL_PROJECTION);CHECKGLERROR
- qglLoadIdentity();CHECKGLERROR
- // set view pyramid
- nudge = 1.0 - 1.0 / (1<<23);
- m[ 0] = 1.0 / frustumx;
- m[ 1] = 0;
- m[ 2] = 0;
- m[ 3] = 0;
- m[ 4] = 0;
- m[ 5] = 1.0 / frustumy;
- m[ 6] = 0;
- m[ 7] = 0;
- m[ 8] = 0;
- m[ 9] = 0;
- m[10] = -nudge;
- m[11] = -1;
- m[12] = 0;
- m[13] = 0;
- m[14] = -2 * zNear * nudge;
- m[15] = 0;
- qglLoadMatrixd(m);CHECKGLERROR
- qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
- GL_SetupView_Orientation_Identity();
- CHECKGLERROR
- Matrix4x4_FromArrayDoubleGL(&backend_projectmatrix, m);
-}
-
-static void GL_BuildOrtho(double m[16], double left, double right, double bottom, double top, double zNear, double zFar)
+void R_Viewport_TransformToScreen(const r_viewport_t *v, const vec4_t in, vec4_t out)
{
- m[0] = 2/(right - left);
- m[1] = 0;
- m[2] = 0;
- m[3] = 0;
-
- m[4] = 0;
- m[5] = 2/(top - bottom);
- m[6] = 0;
- m[7] = 0;
-
- m[8] = 0;
- m[9] = 0;
- m[10] = -2/(zFar - zNear);
- m[11] = 0;
-
- m[12] = - (right + left)/(right - left);
- m[13] = - (top + bottom)/(top - bottom);
- m[14] = - (zFar + zNear)/(zFar - zNear);
- m[15] = 1;
-}
-
-void GL_SetupView_Mode_Ortho (double x1, double y1, double x2, double y2, double zNear, double zFar)
-{
- double m[16];
-
- // set up viewpoint
- CHECKGLERROR
- qglMatrixMode(GL_PROJECTION);CHECKGLERROR
-#if 1
- // avoid glGetDoublev whenever possible, it may stall the render pipeline
- // in the tested cases (nvidia) no measurable fps difference, but it sure
- // makes a difference over a network line with GLX
- GL_BuildOrtho(m, x1, x2, y2, y1, zNear, zFar);
- qglLoadMatrixd(m);CHECKGLERROR
-#else
- qglLoadIdentity();CHECKGLERROR
- qglOrtho(x1, x2, y2, y1, zNear, zFar);CHECKGLERROR
- qglGetDoublev(GL_PROJECTION_MATRIX, m);CHECKGLERROR
-#endif
- Matrix4x4_FromArrayDoubleGL(&backend_projectmatrix, m);
- qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
- GL_SetupView_Orientation_Identity();
- CHECKGLERROR
+ vec4_t temp;
+ float iw;
+ Matrix4x4_Transform4 (&v->viewmatrix, in, temp);
+ Matrix4x4_Transform4 (&v->projectmatrix, temp, out);
+ iw = 1.0f / out[3];
+ out[0] = v->x + (out[0] * iw + 1.0f) * v->width * 0.5f;
+ out[1] = v->y + v->height - (out[1] * iw + 1.0f) * v->height * 0.5f;
+ out[2] = v->z + (out[2] * iw + 1.0f) * v->depth * 0.5f;
}
-void GL_SetupView_ApplyCustomNearClipPlane(double normalx, double normaly, double normalz, double dist)
+static void R_Viewport_ApplyNearClipPlane(r_viewport_t *v, double normalx, double normaly, double normalz, double dist)
{
- double matrix[16];
double q[4];
double d;
float clipPlane[4], v3[3], v4[3];
float normal[3];
- // This is Olique Depth Projection from http://www.terathon.com/code/oblique.php
- // modified to fit in this codebase.
+ // This is inspired by Oblique Depth Projection from http://www.terathon.com/code/oblique.php
VectorSet(normal, normalx, normaly, normalz);
- Matrix4x4_Transform3x3(&backend_viewmatrix, normal, clipPlane);
+ Matrix4x4_Transform3x3(&v->viewmatrix, normal, clipPlane);
VectorScale(normal, dist, v3);
- Matrix4x4_Transform(&backend_viewmatrix, v3, v4);
+ Matrix4x4_Transform(&v->viewmatrix, v3, v4);
// FIXME: LordHavoc: I think this can be done more efficiently somehow but I can't remember the technique
clipPlane[3] = -DotProduct(v4, clipPlane);
// as (sgn(clipPlane.x), sgn(clipPlane.y), 1, 1) and
// transform it into camera space by multiplying it
// by the inverse of the projection matrix
- Matrix4x4_ToArrayDoubleGL(&backend_projectmatrix, matrix);
-
- q[0] = ((clipPlane[0] < 0.0f ? -1.0f : clipPlane[0] > 0.0f ? 1.0f : 0.0f) + matrix[8]) / matrix[0];
- q[1] = ((clipPlane[1] < 0.0f ? -1.0f : clipPlane[1] > 0.0f ? 1.0f : 0.0f) + matrix[9]) / matrix[5];
+ q[0] = ((clipPlane[0] < 0.0f ? -1.0f : clipPlane[0] > 0.0f ? 1.0f : 0.0f) + v->m[8]) / v->m[0];
+ q[1] = ((clipPlane[1] < 0.0f ? -1.0f : clipPlane[1] > 0.0f ? 1.0f : 0.0f) + v->m[9]) / v->m[5];
q[2] = -1.0f;
- q[3] = (1.0f + matrix[10]) / matrix[14];
+ q[3] = (1.0f + v->m[10]) / v->m[14];
// Calculate the scaled plane vector
d = 2.0f / DotProduct4(clipPlane, q);
// Replace the third row of the projection matrix
- matrix[2] = clipPlane[0] * d;
- matrix[6] = clipPlane[1] * d;
- matrix[10] = clipPlane[2] * d + 1.0f;
- matrix[14] = clipPlane[3] * d;
+ v->m[2] = clipPlane[0] * d;
+ v->m[6] = clipPlane[1] * d;
+ v->m[10] = clipPlane[2] * d + 1.0f;
+ 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)
+{
+ float left = x1, right = x2, bottom = y2, top = y1, zNear = nearclip, zFar = farclip;
+ memset(v, 0, sizeof(*v));
+ v->type = R_VIEWPORTTYPE_ORTHO;
+ v->cameramatrix = *cameramatrix;
+ v->x = x;
+ v->y = y;
+ v->z = 0;
+ v->width = width;
+ v->height = height;
+ v->depth = 1;
+ v->m[0] = 2/(right - left);
+ v->m[5] = 2/(top - bottom);
+ v->m[10] = -2/(zFar - zNear);
+ v->m[12] = - (right + left)/(right - left);
+ v->m[13] = - (top + bottom)/(top - bottom);
+ v->m[14] = - (zFar + zNear)/(zFar - zNear);
+ v->m[15] = 1;
+
+ Matrix4x4_Invert_Full(&v->viewmatrix, &v->cameramatrix);
+ Matrix4x4_FromArrayDoubleGL(&v->projectmatrix, v->m);
+
+ if (nearplane)
+ R_Viewport_ApplyNearClipPlane(v, nearplane[0], nearplane[1], nearplane[2], nearplane[3]);
- // Load it back into OpenGL
- qglMatrixMode(GL_PROJECTION);CHECKGLERROR
- qglLoadMatrixd(matrix);CHECKGLERROR
- qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
- CHECKGLERROR
- Matrix4x4_FromArrayDoubleGL(&backend_projectmatrix, matrix);
+#if 0
+ {
+ vec4_t test1;
+ vec4_t test2;
+ Vector4Set(test1, (x1+x2)*0.5f, (y1+y2)*0.5f, 0.0f, 1.0f);
+ R_Viewport_TransformToScreen(v, test1, test2);
+ Con_Printf("%f %f %f -> %f %f %f\n", test1[0], test1[1], test1[2], test2[0], test2[1], test2[2]);
+ }
+#endif
}
-typedef struct gltextureunit_s
+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)
{
- const void *pointer_texcoord;
- size_t pointer_texcoord_offset;
- int pointer_texcoord_buffer;
- int t1d, t2d, t3d, tcubemap;
- int arrayenabled;
- unsigned int arraycomponents;
- int rgbscale, alphascale;
- int combinergb, combinealpha;
- // FIXME: add more combine stuff
- // texmatrixenabled exists only to avoid unnecessary texmatrix compares
- int texmatrixenabled;
- matrix4x4_t matrix;
+ matrix4x4_t tempmatrix, basematrix;
+ memset(v, 0, sizeof(*v));
+
+ if(v_flipped.integer)
+ frustumx = -frustumx;
+
+ v->type = R_VIEWPORTTYPE_PERSPECTIVE;
+ v->cameramatrix = *cameramatrix;
+ v->x = x;
+ v->y = y;
+ v->z = 0;
+ v->width = width;
+ v->height = height;
+ v->depth = 1;
+ v->m[0] = 1.0 / frustumx;
+ v->m[5] = 1.0 / frustumy;
+ v->m[10] = -(farclip + nearclip) / (farclip - nearclip);
+ v->m[11] = -1;
+ v->m[14] = -2 * nearclip * farclip / (farclip - nearclip);
+
+ Matrix4x4_Invert_Full(&tempmatrix, &v->cameramatrix);
+ Matrix4x4_CreateRotate(&basematrix, -90, 1, 0, 0);
+ Matrix4x4_ConcatRotate(&basematrix, 90, 0, 0, 1);
+ Matrix4x4_Concat(&v->viewmatrix, &basematrix, &tempmatrix);
+
+ Matrix4x4_FromArrayDoubleGL(&v->projectmatrix, v->m);
+
+ if (nearplane)
+ R_Viewport_ApplyNearClipPlane(v, nearplane[0], nearplane[1], nearplane[2], nearplane[3]);
}
-gltextureunit_t;
-static struct gl_state_s
+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)
{
- int cullface;
- int cullfaceenable;
- int blendfunc1;
- int blendfunc2;
- int blend;
- GLboolean depthmask;
- int colormask; // stored as bottom 4 bits: r g b a (3 2 1 0 order)
- int depthtest;
- float depthrange[2];
- float polygonoffset[2];
- int alphatest;
- int scissortest;
- unsigned int unit;
- unsigned int clientunit;
- gltextureunit_t units[MAX_TEXTUREUNITS];
- float color4f[4];
- int lockrange_first;
- int lockrange_count;
- int vertexbufferobject;
- int elementbufferobject;
- qboolean pointer_color_enabled;
- const void *pointer_vertex;
- const void *pointer_color;
- size_t pointer_vertex_offset;
- size_t pointer_color_offset;
- int pointer_vertex_buffer;
- int pointer_color_buffer;
+ matrix4x4_t tempmatrix, basematrix;
+ const double nudge = 1.0 - 1.0 / (1<<23);
+ memset(v, 0, sizeof(*v));
+
+ if(v_flipped.integer)
+ frustumx = -frustumx;
+
+ v->type = R_VIEWPORTTYPE_PERSPECTIVE_INFINITEFARCLIP;
+ v->cameramatrix = *cameramatrix;
+ v->x = x;
+ v->y = y;
+ v->z = 0;
+ v->width = width;
+ v->height = height;
+ v->depth = 1;
+ v->m[ 0] = 1.0 / frustumx;
+ v->m[ 5] = 1.0 / frustumy;
+ v->m[10] = -nudge;
+ v->m[11] = -1;
+ v->m[14] = -2 * nearclip * nudge;
+
+ Matrix4x4_Invert_Full(&tempmatrix, &v->cameramatrix);
+ Matrix4x4_CreateRotate(&basematrix, -90, 1, 0, 0);
+ Matrix4x4_ConcatRotate(&basematrix, 90, 0, 0, 1);
+ Matrix4x4_Concat(&v->viewmatrix, &basematrix, &tempmatrix);
+
+ Matrix4x4_FromArrayDoubleGL(&v->projectmatrix, v->m);
+
+ if (nearplane)
+ R_Viewport_ApplyNearClipPlane(v, nearplane[0], nearplane[1], nearplane[2], nearplane[3]);
+}
+
+float cubeviewmatrix[6][16] =
+{
+ // standard cubemap projections
+ { // +X
+ 0, 0,-1, 0,
+ 0,-1, 0, 0,
+ -1, 0, 0, 0,
+ 0, 0, 0, 1,
+ },
+ { // -X
+ 0, 0, 1, 0,
+ 0,-1, 0, 0,
+ 1, 0, 0, 0,
+ 0, 0, 0, 1,
+ },
+ { // +Y
+ 1, 0, 0, 0,
+ 0, 0,-1, 0,
+ 0, 1, 0, 0,
+ 0, 0, 0, 1,
+ },
+ { // -Y
+ 1, 0, 0, 0,
+ 0, 0, 1, 0,
+ 0,-1, 0, 0,
+ 0, 0, 0, 1,
+ },
+ { // +Z
+ 1, 0, 0, 0,
+ 0,-1, 0, 0,
+ 0, 0,-1, 0,
+ 0, 0, 0, 1,
+ },
+ { // -Z
+ -1, 0, 0, 0,
+ 0,-1, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1,
+ },
+};
+float rectviewmatrix[6][16] =
+{
+ // sign-preserving cubemap projections
+ { // +X
+ 0, 0,-1, 0,
+ 0, 1, 0, 0,
+ 1, 0, 0, 0,
+ 0, 0, 0, 1,
+ },
+ { // -X
+ 0, 0, 1, 0,
+ 0, 1, 0, 0,
+ 1, 0, 0, 0,
+ 0, 0, 0, 1,
+ },
+ { // +Y
+ 1, 0, 0, 0,
+ 0, 0,-1, 0,
+ 0, 1, 0, 0,
+ 0, 0, 0, 1,
+ },
+ { // -Y
+ 1, 0, 0, 0,
+ 0, 0, 1, 0,
+ 0, 1, 0, 0,
+ 0, 0, 0, 1,
+ },
+ { // +Z
+ 1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0,-1, 0,
+ 0, 0, 0, 1,
+ },
+ { // -Z
+ 1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1,
+ },
+};
+
+void R_Viewport_InitCubeSideView(r_viewport_t *v, const matrix4x4_t *cameramatrix, int side, int size, float nearclip, float farclip, const float *nearplane)
+{
+ matrix4x4_t tempmatrix, basematrix;
+ memset(v, 0, sizeof(*v));
+ v->type = R_VIEWPORTTYPE_PERSPECTIVECUBESIDE;
+ v->cameramatrix = *cameramatrix;
+ v->width = size;
+ v->height = size;
+ v->depth = 1;
+ v->m[0] = v->m[5] = 1.0f;
+ v->m[10] = -(farclip + nearclip) / (farclip - nearclip);
+ v->m[11] = -1;
+ v->m[14] = -2 * nearclip * farclip / (farclip - nearclip);
+
+ Matrix4x4_FromArrayFloatGL(&basematrix, cubeviewmatrix[side]);
+ Matrix4x4_Invert_Simple(&tempmatrix, &v->cameramatrix);
+ Matrix4x4_Concat(&v->viewmatrix, &basematrix, &tempmatrix);
+ Matrix4x4_FromArrayDoubleGL(&v->projectmatrix, v->m);
+
+ if (nearplane)
+ R_Viewport_ApplyNearClipPlane(v, nearplane[0], nearplane[1], nearplane[2], nearplane[3]);
+}
+
+void R_Viewport_InitRectSideView(r_viewport_t *v, const matrix4x4_t *cameramatrix, int side, int size, int border, float nearclip, float farclip, const float *nearplane)
+{
+ matrix4x4_t tempmatrix, basematrix;
+ memset(v, 0, sizeof(*v));
+ v->type = R_VIEWPORTTYPE_PERSPECTIVECUBESIDE;
+ v->cameramatrix = *cameramatrix;
+ v->x = (side & 1) * size;
+ v->y = (side >> 1) * size;
+ v->width = size;
+ v->height = size;
+ v->depth = 1;
+ v->m[0] = v->m[5] = 1.0f * ((float)size - border) / size;
+ v->m[10] = -(farclip + nearclip) / (farclip - nearclip);
+ v->m[11] = -1;
+ v->m[14] = -2 * nearclip * farclip / (farclip - nearclip);
+
+ Matrix4x4_FromArrayFloatGL(&basematrix, rectviewmatrix[side]);
+ Matrix4x4_Invert_Simple(&tempmatrix, &v->cameramatrix);
+ Matrix4x4_Concat(&v->viewmatrix, &basematrix, &tempmatrix);
+ Matrix4x4_FromArrayDoubleGL(&v->projectmatrix, v->m);
+
+ if (nearplane)
+ R_Viewport_ApplyNearClipPlane(v, nearplane[0], nearplane[1], nearplane[2], nearplane[3]);
+}
+
+void R_SetViewport(const r_viewport_t *v)
+{
+ float glmatrix[16];
+ backend_viewport = *v;
+
+ CHECKGLERROR
+ qglViewport(v->x, v->y, v->width, v->height);CHECKGLERROR
+
+ // Load the projection matrix into OpenGL
+ qglMatrixMode(GL_PROJECTION);CHECKGLERROR
+ qglLoadMatrixd(backend_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(&backend_modelviewmatrix, &backend_viewport.viewmatrix, &backend_modelmatrix);
+ Matrix4x4_ToArrayFloatGL(&backend_modelviewmatrix, glmatrix);
+ qglLoadMatrixf(glmatrix);CHECKGLERROR
+}
+
+void R_GetViewport(r_viewport_t *v)
+{
+ *v = backend_viewport;
}
-gl_state;
static void GL_BindVBO(int bufferobject)
{
for (i = 0;i < MAX_TEXTUREUNITS;i++)
{
unit = gl_state.units + i;
- unit->t1d = 0;
unit->t2d = 0;
unit->t3d = 0;
unit->tcubemap = 0;
unit->matrix = identitymatrix;
}
- for (i = 0;i < backendimageunits;i++)
+ for (i = 0;i < vid.teximageunits;i++)
{
GL_ActiveTexture(i);
- qglBindTexture(GL_TEXTURE_1D, 0);CHECKGLERROR
qglBindTexture(GL_TEXTURE_2D, 0);CHECKGLERROR
- if (gl_texture3d)
+ if (vid.support.ext_texture_3d)
{
qglBindTexture(GL_TEXTURE_3D, 0);CHECKGLERROR
}
- if (gl_texturecubemap)
+ if (vid.support.arb_texture_cube_map)
{
qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, 0);CHECKGLERROR
}
+ if (vid.support.arb_texture_rectangle)
+ {
+ qglBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);CHECKGLERROR
+ }
}
- for (i = 0;i < backendarrayunits;i++)
+ for (i = 0;i < vid.texarrayunits;i++)
{
GL_ClientActiveTexture(i);
GL_BindVBO(0);
qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
}
- for (i = 0;i < backendunits;i++)
+ for (i = 0;i < vid.texunits;i++)
{
GL_ActiveTexture(i);
- qglDisable(GL_TEXTURE_1D);CHECKGLERROR
qglDisable(GL_TEXTURE_2D);CHECKGLERROR
- if (gl_texture3d)
+ if (vid.support.ext_texture_3d)
{
qglDisable(GL_TEXTURE_3D);CHECKGLERROR
}
- if (gl_texturecubemap)
+ if (vid.support.arb_texture_cube_map)
{
qglDisable(GL_TEXTURE_CUBE_MAP_ARB);CHECKGLERROR
}
+ if (vid.support.arb_texture_rectangle)
+ {
+ qglDisable(GL_TEXTURE_RECTANGLE_ARB);CHECKGLERROR
+ }
qglMatrixMode(GL_TEXTURE);CHECKGLERROR
qglLoadIdentity();CHECKGLERROR
qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
qglDepthMask(gl_state.depthmask);CHECKGLERROR
qglPolygonOffset(gl_state.polygonoffset[0], gl_state.polygonoffset[1]);
- if (gl_support_arb_vertex_buffer_object)
+ if (vid.support.arb_vertex_buffer_object)
{
qglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
qglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
}
+ if (vid.support.ext_framebuffer_object)
+ {
+ qglBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
+ qglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ }
+
qglVertexPointer(3, GL_FLOAT, sizeof(float[3]), NULL);CHECKGLERROR
qglEnableClientState(GL_VERTEX_ARRAY);CHECKGLERROR
qglUnlockArraysEXT();
CHECKGLERROR
}
- if (count && gl_supportslockarrays && gl_lockarrays.integer && r_render.integer)
+ if (count && vid.support.ext_compiled_vertex_array && gl_lockarrays.integer)
{
gl_state.lockrange_first = first;
gl_state.lockrange_count = count;
void GL_Scissor (int x, int y, int width, int height)
{
CHECKGLERROR
- qglScissor(x, vid.height - (y + height),width,height);
+ qglScissor(x, y,width,height);
CHECKGLERROR
}
qglClear(mask);CHECKGLERROR
}
-void GL_TransformToScreen(const vec4_t in, vec4_t out)
-{
- vec4_t temp;
- float iw;
- Matrix4x4_Transform4 (&backend_viewmatrix, in, temp);
- Matrix4x4_Transform4 (&backend_projectmatrix, temp, out);
- iw = 1.0f / out[3];
- out[0] = r_refdef.view.x + (out[0] * iw + 1.0f) * r_refdef.view.width * 0.5f;
- out[1] = r_refdef.view.y + r_refdef.view.height - (out[1] * iw + 1.0f) * r_refdef.view.height * 0.5f;
- out[2] = r_refdef.view.z + (out[2] * iw + 1.0f) * r_refdef.view.depth * 0.5f;
-}
-
// called at beginning of frame
void R_Mesh_Start(void)
{
CHECKGLERROR
}
-int gl_backend_rebindtextures;
-
void GL_Backend_RenumberElements(int *out, int count, const int *in, int offset)
{
int i;
for (j = 0, size = numvertices * 4, p = (int *)((float *)gl_state.pointer_color + firstvertex * 4);j < size;j++, p++)
paranoidblah += *p;
}
- for (i = 0;i < backendarrayunits;i++)
+ for (i = 0;i < vid.texarrayunits;i++)
{
if (gl_state.units[i].arrayenabled)
{
}
CHECKGLERROR
}
- if (r_render.integer)
+ if (r_render.integer || r_refdef.draw2dstage)
{
CHECKGLERROR
if (gl_mesh_testmanualfeeding.integer)
for (i = 0;i < (unsigned int) numtriangles * 3;i++)
{
element = element3i ? element3i[i] : element3s[i];
- for (j = 0;j < backendarrayunits;j++)
+ for (j = 0;j < vid.texarrayunits;j++)
{
if (gl_state.units[j].pointer_texcoord && gl_state.units[j].arrayenabled)
{
- if (backendarrayunits > 1)
+ if (vid.texarrayunits > 1)
{
if (gl_state.units[j].arraycomponents == 4)
{
GL_BindEBO(bufferobject3s);
if (gl_mesh_drawrangeelements.integer && qglDrawRangeElements != NULL)
{
- qglDrawRangeElements(GL_TRIANGLES, firstvertex, firstvertex + numvertices, numelements, GL_UNSIGNED_SHORT, (void *)(firsttriangle * sizeof(unsigned short[3])));
+ qglDrawRangeElements(GL_TRIANGLES, firstvertex, firstvertex + numvertices - 1, numelements, GL_UNSIGNED_SHORT, (void *)(firsttriangle * sizeof(unsigned short[3])));
CHECKGLERROR
}
else
GL_BindEBO(bufferobject3i);
if (gl_mesh_drawrangeelements.integer && qglDrawRangeElements != NULL)
{
- qglDrawRangeElements(GL_TRIANGLES, firstvertex, firstvertex + numvertices, numelements, GL_UNSIGNED_INT, (void *)(firsttriangle * sizeof(unsigned int[3])));
+ qglDrawRangeElements(GL_TRIANGLES, firstvertex, firstvertex + numvertices - 1, numelements, GL_UNSIGNED_INT, (void *)(firsttriangle * sizeof(unsigned int[3])));
CHECKGLERROR
}
else
GL_BindEBO(0);
if (gl_mesh_drawrangeelements.integer && qglDrawRangeElements != NULL)
{
- qglDrawRangeElements(GL_TRIANGLES, firstvertex, firstvertex + numvertices, numelements, GL_UNSIGNED_SHORT, element3s);
+ qglDrawRangeElements(GL_TRIANGLES, firstvertex, firstvertex + numvertices - 1, numelements, GL_UNSIGNED_SHORT, element3s);
CHECKGLERROR
}
else
GL_BindEBO(0);
if (gl_mesh_drawrangeelements.integer && qglDrawRangeElements != NULL)
{
- qglDrawRangeElements(GL_TRIANGLES, firstvertex, firstvertex + numvertices, numelements, GL_UNSIGNED_INT, element3i);
+ qglDrawRangeElements(GL_TRIANGLES, firstvertex, firstvertex + numvertices - 1, numelements, GL_UNSIGNED_INT, element3i);
CHECKGLERROR
}
else
GL_LockArrays(0, 0);
CHECKGLERROR
- for (i = 0;i < backendimageunits;i++)
+ for (i = 0;i < vid.teximageunits;i++)
{
GL_ActiveTexture(i);
- qglBindTexture(GL_TEXTURE_1D, 0);CHECKGLERROR
qglBindTexture(GL_TEXTURE_2D, 0);CHECKGLERROR
- if (gl_texture3d)
+ if (vid.support.ext_texture_3d)
{
qglBindTexture(GL_TEXTURE_3D, 0);CHECKGLERROR
}
- if (gl_texturecubemap)
+ if (vid.support.arb_texture_cube_map)
{
qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, 0);CHECKGLERROR
}
+ if (vid.support.arb_texture_rectangle)
+ {
+ qglBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);CHECKGLERROR
+ }
}
- for (i = 0;i < backendarrayunits;i++)
+ for (i = 0;i < vid.texarrayunits;i++)
{
- GL_ActiveTexture(backendarrayunits - 1 - i);
+ GL_ActiveTexture(vid.texarrayunits - 1 - i);
qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
}
- for (i = 0;i < backendunits;i++)
+ for (i = 0;i < vid.texunits;i++)
{
- GL_ActiveTexture(backendunits - 1 - i);
- qglDisable(GL_TEXTURE_1D);CHECKGLERROR
+ GL_ActiveTexture(vid.texunits - 1 - i);
qglDisable(GL_TEXTURE_2D);CHECKGLERROR
- if (gl_texture3d)
+ if (vid.support.ext_texture_3d)
{
qglDisable(GL_TEXTURE_3D);CHECKGLERROR
}
- if (gl_texturecubemap)
+ if (vid.support.arb_texture_cube_map)
{
qglDisable(GL_TEXTURE_CUBE_MAP_ARB);CHECKGLERROR
}
+ if (vid.support.arb_texture_rectangle)
+ {
+ qglDisable(GL_TEXTURE_RECTANGLE_ARB);CHECKGLERROR
+ }
qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);CHECKGLERROR
if (gl_combine.integer)
{
{
if (memcmp(matrix, &backend_modelmatrix, sizeof(matrix4x4_t)))
{
- double glmatrix[16];
+ float glmatrix[16];
backend_modelmatrix = *matrix;
- Matrix4x4_Concat(&backend_modelviewmatrix, &backend_viewmatrix, matrix);
- Matrix4x4_ToArrayDoubleGL(&backend_modelviewmatrix, glmatrix);
+ Matrix4x4_Concat(&backend_modelviewmatrix, &backend_viewport.viewmatrix, &backend_modelmatrix);
+ Matrix4x4_ToArrayFloatGL(&backend_modelviewmatrix, glmatrix);
CHECKGLERROR
- qglLoadMatrixd(glmatrix);CHECKGLERROR
+ qglLoadMatrixf(glmatrix);CHECKGLERROR
}
}
void R_Mesh_VertexPointer(const float *vertex3f, int bufferobject, size_t bufferoffset)
{
- if (!gl_vbo.integer)
+ if (!gl_vbo.integer || gl_mesh_testarrayelement.integer)
bufferobject = 0;
if (gl_state.pointer_vertex != vertex3f || gl_state.pointer_vertex_buffer != bufferobject || gl_state.pointer_vertex_offset != bufferoffset)
{
// means that a valid vbo may be supplied even if there is no color array.
if (color4f)
{
- if (!gl_vbo.integer)
+ if (!gl_vbo.integer || gl_mesh_testarrayelement.integer)
bufferobject = 0;
// caller wants color array enabled
if (!gl_state.pointer_color_enabled)
// that involve a valid bufferobject also supply a texcoord array
if (texcoord)
{
- if (!gl_vbo.integer)
+ if (!gl_vbo.integer || gl_mesh_testarrayelement.integer)
bufferobject = 0;
// texture array unit is enabled, enable the array
if (!unit->arrayenabled)
}
}
-void R_Mesh_TexBindAll(unsigned int unitnum, int tex1d, int tex2d, int tex3d, int texcubemap)
+void R_Mesh_TexBindAll(unsigned int unitnum, int tex2d, int tex3d, int texcubemap, int texrectangle)
{
gltextureunit_t *unit = gl_state.units + unitnum;
- if (unitnum >= backendimageunits)
+ if (unitnum >= vid.teximageunits)
return;
- // update 1d texture binding
- if (unit->t1d != tex1d)
- {
- GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
- {
- if (tex1d)
- {
- if (unit->t1d == 0)
- {
- qglEnable(GL_TEXTURE_1D);CHECKGLERROR
- }
- }
- else
- {
- if (unit->t1d)
- {
- qglDisable(GL_TEXTURE_1D);CHECKGLERROR
- }
- }
- }
- unit->t1d = tex1d;
- qglBindTexture(GL_TEXTURE_1D, unit->t1d);CHECKGLERROR
- }
// update 2d texture binding
if (unit->t2d != tex2d)
{
GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
+ if (unitnum < vid.texunits)
{
if (tex2d)
{
if (unit->t3d != tex3d)
{
GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
+ if (unitnum < vid.texunits)
{
if (tex3d)
{
if (unit->tcubemap != texcubemap)
{
GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
+ if (unitnum < vid.texunits)
{
if (texcubemap)
{
unit->tcubemap = texcubemap;
qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);CHECKGLERROR
}
-}
-
-void R_Mesh_TexBind1D(unsigned int unitnum, int texnum)
-{
- gltextureunit_t *unit = gl_state.units + unitnum;
- if (unitnum >= backendimageunits)
- return;
- // update 1d texture binding
- if (unit->t1d != texnum)
+ // update rectangle texture binding
+ if (unit->trectangle != texrectangle)
{
GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
+ if (unitnum < vid.texunits)
{
- if (texnum)
+ if (texrectangle)
{
- if (unit->t1d == 0)
+ if (unit->trectangle == 0)
{
- qglEnable(GL_TEXTURE_1D);CHECKGLERROR
+ qglEnable(GL_TEXTURE_RECTANGLE_ARB);CHECKGLERROR
}
}
else
{
- if (unit->t1d)
+ if (unit->trectangle)
{
- qglDisable(GL_TEXTURE_1D);CHECKGLERROR
+ qglDisable(GL_TEXTURE_RECTANGLE_ARB);CHECKGLERROR
}
}
}
- unit->t1d = texnum;
- qglBindTexture(GL_TEXTURE_1D, unit->t1d);CHECKGLERROR
- }
- // update 2d texture binding
- if (unit->t2d)
- {
- GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
- {
- if (unit->t2d)
- {
- qglDisable(GL_TEXTURE_2D);CHECKGLERROR
- }
- }
- unit->t2d = 0;
- qglBindTexture(GL_TEXTURE_2D, unit->t2d);CHECKGLERROR
- }
- // update 3d texture binding
- if (unit->t3d)
- {
- GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
- {
- 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)
- {
- GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
- {
- if (unit->tcubemap)
- {
- qglDisable(GL_TEXTURE_CUBE_MAP_ARB);CHECKGLERROR
- }
- }
- unit->tcubemap = 0;
- qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);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 >= backendimageunits)
+ if (unitnum >= vid.teximageunits)
return;
- // update 1d texture binding
- if (unit->t1d)
- {
- GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
- {
- if (unit->t1d)
- {
- qglDisable(GL_TEXTURE_1D);CHECKGLERROR
- }
- }
- unit->t1d = 0;
- qglBindTexture(GL_TEXTURE_1D, unit->t1d);CHECKGLERROR
- }
// update 2d texture binding
if (unit->t2d != texnum)
{
GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
+ if (unitnum < vid.texunits)
{
if (texnum)
{
if (unit->t3d)
{
GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
+ if (unitnum < vid.texunits)
{
if (unit->t3d)
{
if (unit->tcubemap != 0)
{
GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
+ if (unitnum < vid.texunits)
{
if (unit->tcubemap)
{
unit->tcubemap = 0;
qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);CHECKGLERROR
}
-}
-
-void R_Mesh_TexBind3D(unsigned int unitnum, int texnum)
-{
- gltextureunit_t *unit = gl_state.units + unitnum;
- if (unitnum >= backendimageunits)
- return;
- // update 1d texture binding
- if (unit->t1d)
+ // update rectangle texture binding
+ if (unit->trectangle != 0)
{
GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
+ if (unitnum < vid.texunits)
{
- if (unit->t1d)
+ if (unit->trectangle)
{
- qglDisable(GL_TEXTURE_1D);CHECKGLERROR
+ qglDisable(GL_TEXTURE_RECTANGLE_ARB);CHECKGLERROR
}
}
- unit->t1d = 0;
- qglBindTexture(GL_TEXTURE_1D, unit->t1d);CHECKGLERROR
+ unit->trectangle = 0;
+ qglBindTexture(GL_TEXTURE_RECTANGLE_ARB, unit->trectangle);CHECKGLERROR
}
+}
+
+void R_Mesh_TexBind3D(unsigned int unitnum, int texnum)
+{
+ gltextureunit_t *unit = gl_state.units + unitnum;
+ if (unitnum >= vid.teximageunits)
+ return;
// update 2d texture binding
if (unit->t2d)
{
GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
+ if (unitnum < vid.texunits)
{
if (unit->t2d)
{
if (unit->t3d != texnum)
{
GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
+ if (unitnum < vid.texunits)
{
if (texnum)
{
if (unit->tcubemap != 0)
{
GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
+ if (unitnum < vid.texunits)
{
if (unit->tcubemap)
{
unit->tcubemap = 0;
qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);CHECKGLERROR
}
-}
-
-void R_Mesh_TexBindCubeMap(unsigned int unitnum, int texnum)
-{
- gltextureunit_t *unit = gl_state.units + unitnum;
- if (unitnum >= backendimageunits)
- return;
- // update 1d texture binding
- if (unit->t1d)
+ // update rectangle texture binding
+ if (unit->trectangle != 0)
{
GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
+ if (unitnum < vid.texunits)
{
- if (unit->t1d)
+ if (unit->trectangle)
{
- qglDisable(GL_TEXTURE_1D);CHECKGLERROR
+ qglDisable(GL_TEXTURE_RECTANGLE_ARB);CHECKGLERROR
}
}
- unit->t1d = 0;
- qglBindTexture(GL_TEXTURE_1D, unit->t1d);CHECKGLERROR
+ unit->trectangle = 0;
+ qglBindTexture(GL_TEXTURE_RECTANGLE_ARB, unit->trectangle);CHECKGLERROR
}
+}
+
+void R_Mesh_TexBindCubeMap(unsigned int unitnum, int texnum)
+{
+ gltextureunit_t *unit = gl_state.units + unitnum;
+ if (unitnum >= vid.teximageunits)
+ return;
// update 2d texture binding
if (unit->t2d)
{
GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
+ if (unitnum < vid.texunits)
{
if (unit->t2d)
{
if (unit->t3d)
{
GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
+ if (unitnum < vid.texunits)
{
if (unit->t3d)
{
if (unit->tcubemap != texnum)
{
GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
+ if (unitnum < vid.texunits)
{
if (texnum)
{
unit->tcubemap = texnum;
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
+ }
}
-static const double gl_identitymatrix[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};
+void R_Mesh_TexBindRectangle(unsigned int unitnum, int texnum)
+{
+ gltextureunit_t *unit = gl_state.units + unitnum;
+ if (unitnum >= vid.teximageunits)
+ return;
+ // update 2d texture binding
+ if (unit->t2d)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < vid.texunits)
+ {
+ if (unit->t2d)
+ {
+ qglDisable(GL_TEXTURE_2D);CHECKGLERROR
+ }
+ }
+ unit->t2d = 0;
+ 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 != texnum)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < vid.texunits)
+ {
+ if (texnum)
+ {
+ if (unit->trectangle == 0)
+ {
+ qglEnable(GL_TEXTURE_RECTANGLE_ARB);CHECKGLERROR
+ }
+ }
+ else
+ {
+ if (unit->trectangle)
+ {
+ qglDisable(GL_TEXTURE_RECTANGLE_ARB);CHECKGLERROR
+ }
+ }
+ }
+ unit->trectangle = texnum;
+ qglBindTexture(GL_TEXTURE_RECTANGLE_ARB, unit->trectangle);CHECKGLERROR
+ }
+}
+
+static const float gl_identitymatrix[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};
void R_Mesh_TexMatrix(unsigned int unitnum, const matrix4x4_t *matrix)
{
// texmatrix specified, check if it is different
if (!unit->texmatrixenabled || memcmp(&unit->matrix, matrix, sizeof(matrix4x4_t)))
{
- double glmatrix[16];
+ float glmatrix[16];
unit->texmatrixenabled = true;
unit->matrix = *matrix;
CHECKGLERROR
- Matrix4x4_ToArrayDoubleGL(&unit->matrix, glmatrix);
+ Matrix4x4_ToArrayFloatGL(&unit->matrix, glmatrix);
GL_ActiveTexture(unitnum);
qglMatrixMode(GL_TEXTURE);CHECKGLERROR
- qglLoadMatrixd(glmatrix);CHECKGLERROR
+ qglLoadMatrixf(glmatrix);CHECKGLERROR
qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
}
}
BACKENDACTIVECHECK
CHECKGLERROR
- if (gl_backend_rebindtextures)
- {
- gl_backend_rebindtextures = false;
- GL_SetupTextureState();
- CHECKGLERROR
- }
-
- for (i = 0;i < backendimageunits;i++)
- R_Mesh_TexBindAll(i, m->tex1d[i], m->tex[i], m->tex3d[i], m->texcubemap[i]);
- for (i = 0;i < backendarrayunits;i++)
+ for (i = 0;i < vid.teximageunits;i++)
+ R_Mesh_TexBindAll(i, m->tex[i], m->tex3d[i], m->texcubemap[i], m->texrectangle[i]);
+ for (i = 0;i < vid.texarrayunits;i++)
{
if (m->pointer_texcoord3f[i])
R_Mesh_TexCoordPointer(i, 3, m->pointer_texcoord3f[i], m->pointer_texcoord_bufferobject[i], m->pointer_texcoord_bufferoffset[i]);
else
R_Mesh_TexCoordPointer(i, 2, m->pointer_texcoord[i], m->pointer_texcoord_bufferobject[i], m->pointer_texcoord_bufferoffset[i]);
}
- for (i = 0;i < backendunits;i++)
+ for (i = 0;i < vid.texunits;i++)
{
R_Mesh_TexMatrix(i, &m->texmatrix[i]);
R_Mesh_TexCombine(i, m->texcombinergb[i], m->texcombinealpha[i], m->texrgbscale[i], m->texalphascale[i]);
BACKENDACTIVECHECK
CHECKGLERROR
- if (gl_backend_rebindtextures)
- {
- gl_backend_rebindtextures = false;
- GL_SetupTextureState();
- CHECKGLERROR
- }
-
- for (unitnum = 0;unitnum < backendimageunits;unitnum++)
+ for (unitnum = 0;unitnum < vid.teximageunits;unitnum++)
{
gltextureunit_t *unit = gl_state.units + unitnum;
- // update 1d texture binding
- if (unit->t1d)
- {
- GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
- {
- qglDisable(GL_TEXTURE_1D);CHECKGLERROR
- }
- unit->t1d = 0;
- qglBindTexture(GL_TEXTURE_1D, unit->t1d);CHECKGLERROR
- }
// update 2d texture binding
if (unit->t2d)
{
GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
+ if (unitnum < vid.texunits)
{
qglDisable(GL_TEXTURE_2D);CHECKGLERROR
}
if (unit->t3d)
{
GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
+ if (unitnum < vid.texunits)
{
qglDisable(GL_TEXTURE_3D);CHECKGLERROR
}
if (unit->tcubemap)
{
GL_ActiveTexture(unitnum);
- if (unitnum < backendunits)
+ if (unitnum < vid.texunits)
{
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)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < vid.texunits)
+ {
+ qglDisable(GL_TEXTURE_RECTANGLE_ARB);CHECKGLERROR
+ }
+ unit->trectangle = 0;
+ qglBindTexture(GL_TEXTURE_RECTANGLE_ARB, unit->trectangle);CHECKGLERROR
+ }
}
- for (unitnum = 0;unitnum < backendarrayunits;unitnum++)
+ for (unitnum = 0;unitnum < vid.texarrayunits;unitnum++)
{
gltextureunit_t *unit = gl_state.units + unitnum;
// texture array unit is disabled, disable the array
qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
}
}
- for (unitnum = 0;unitnum < backendunits;unitnum++)
+ for (unitnum = 0;unitnum < vid.texunits;unitnum++)
{
gltextureunit_t *unit = gl_state.units + unitnum;
// no texmatrix specified, revert to identity