]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_backend.c
remove superfluous newline after gl_vbostats text
[xonotic/darkplaces.git] / gl_backend.c
index 8d3a8c3fdad82b981086048e1844b89e1360de60..9d4ff32515cb845a43563b72d095091f2731f303 100644 (file)
@@ -265,7 +265,7 @@ void gl_backend_init(void)
        Cvar_RegisterVariable(&gl_mesh_testarrayelement);
        Cvar_RegisterVariable(&gl_mesh_testmanualfeeding);
 
-       Cmd_AddCommand("gl_vbostats", GL_VBOStats_f, "prints a list of all buffer objects (vertex data and triangle elements) and total video memory used by them\n");
+       Cmd_AddCommand("gl_vbostats", GL_VBOStats_f, "prints a list of all buffer objects (vertex data and triangle elements) and total video memory used by them");
 
        R_RegisterModule("GL_Backend", gl_backend_start, gl_backend_shutdown, gl_backend_newmap);
 }
@@ -282,7 +282,7 @@ void GL_SetupView_Orientation_Identity (void)
 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);
@@ -299,7 +299,11 @@ void GL_SetupView_Orientation_FromEntity(const matrix4x4_t *matrix)
        //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);
 }
 
 void GL_SetupView_Mode_Perspective (double frustumx, double frustumy, double zNear, double zFar)
@@ -368,6 +372,65 @@ void GL_SetupView_Mode_Ortho (double x1, double y1, double x2, double y2, double
        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;
@@ -844,9 +907,9 @@ void GL_TransformToScreen(const vec4_t in, vec4_t out)
        Matrix4x4_Transform4 (&backend_viewmatrix, in, temp);
        Matrix4x4_Transform4 (&backend_projectmatrix, temp, out);
        iw = 1.0f / out[3];
-       out[0] = r_view.x + (out[0] * iw + 1.0f) * r_view.width * 0.5f;
-       out[1] = r_view.y + r_view.height - (out[1] * iw + 1.0f) * r_view.height * 0.5f;
-       out[2] = r_view.z + (out[2] * iw + 1.0f) * r_view.depth * 0.5f;
+       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
@@ -874,8 +937,15 @@ qboolean GL_Backend_CompileShader(int programobject, GLenum shadertypeenum, cons
        qglCompileShaderARB(shaderobject);CHECKGLERROR
        qglGetObjectParameterivARB(shaderobject, GL_OBJECT_COMPILE_STATUS_ARB, &shadercompiled);CHECKGLERROR
        qglGetInfoLogARB(shaderobject, sizeof(compilelog), NULL, compilelog);CHECKGLERROR
-       if (compilelog[0])
-               Con_DPrintf("%s shader compile log:\n%s\n", shadertype, compilelog);
+       if (compilelog[0] && developer.integer > 0)
+       {
+               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);
+       }
        if (!shadercompiled)
        {
                qglDeleteObjectARB(shaderobject);CHECKGLERROR
@@ -962,7 +1032,7 @@ void R_Mesh_Draw(int firstvertex, int numvertices, int numtriangles, const int *
                Con_Printf("R_Mesh_Draw(%d, %d, %d, %8p, %i, %p);\n", firstvertex, numvertices, numtriangles, elements, bufferobject, (void *)bufferoffset);
                return;
        }
-       if (!gl_vbo.integer)
+       if (gl_vbo.integer != 1)
                bufferobject = 0;
        CHECKGLERROR
        r_refdef.stats.meshes++;