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 = {0, "gl_vbo", "1", "make use of GL_ARB_vertex_buffer_object extension to store static geometry in video memory for faster rendering"};
+cvar_t gl_vbo = {CVAR_SAVE, "gl_vbo", "1", "make use of GL_ARB_vertex_buffer_object extension to store static geometry in video memory for faster rendering"};
cvar_t v_flipped = {0, "v_flipped", "0", "mirror the screen (poor man's left handed mode)"};
qboolean v_flipped_state = false;
void GL_SetupView_Orientation_FromEntity(const matrix4x4_t *matrix)
{
matrix4x4_t tempmatrix, basematrix;
- Matrix4x4_Invert_Simple(&tempmatrix, matrix);
+ 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);
CHECKGLERROR
}
+void GL_SetupView_ApplyCustomNearClipPlane(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.
+
+ VectorSet(normal, normalx, normaly, normalz);
+ Matrix4x4_Transform3x3(&backend_viewmatrix, normal, clipPlane);
+ VectorScale(normal, dist, v3);
+ Matrix4x4_Transform(&backend_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);
+
+#if 0
+{
+ // testing code for comparing results
+ float clipPlane2[4];
+ VectorCopy4(clipPlane, clipPlane2);
+ R_Mesh_Matrix(&identitymatrix);
+ VectorSet(q, normal[0], normal[1], normal[2], -dist);
+ qglClipPlane(GL_CLIP_PLANE0, q);
+ qglGetClipPlane(GL_CLIP_PLANE0, q);
+ VectorCopy4(q, clipPlane);
+}
+#endif
+
+ // Calculate the clip-space corner point opposite the clipping plane
+ // 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[2] = -1.0f;
+ q[3] = (1.0f + matrix[10]) / matrix[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;
+
+ // Load it back into OpenGL
+ qglMatrixMode(GL_PROJECTION);CHECKGLERROR
+ qglLoadMatrixd(matrix);CHECKGLERROR
+ qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
+ CHECKGLERROR
+ Matrix4x4_FromArrayDoubleGL(&backend_projectmatrix, matrix);
+}
+
typedef struct gltextureunit_s
{
const void *pointer_texcoord;