]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
now uses hardware transforms
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 6 Sep 2002 09:45:51 +0000 (09:45 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 6 Sep 2002 09:45:51 +0000 (09:45 +0000)
fixed a bunch of bugs in matrixlib
view matrix is now calculated using Matrix4x4 functions instead of GL calls

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2339 d7cf8633-e32d-0410-b094-e92efae38249

gl_backend.c
glquake.h
matrixlib.c
matrixlib.h
vid_shared.c

index 16178e65f892c4ea9eed3e19848256c10792d879..8702cbf40eb0402d89fc797f61bdbc5048992087 100644 (file)
@@ -65,7 +65,7 @@ void GL_PrintError(int errornumber, char *filename, int linenumber)
 }
 #endif
 
-#define BACKENDACTIVECHECK if (!backendactive) Sys_Error(__func__ " called when backend is not active\n");
+#define BACKENDACTIVECHECK if (!backendactive) Sys_Error("GL backend function called when backend is not active\n");
 
 float r_mesh_farclip;
 
@@ -90,7 +90,10 @@ float *varray_texcoord[MAX_TEXTUREUNITS];
 int mesh_maxtris;
 int mesh_maxverts; // always mesh_maxtris * 3
 
-static matrix4x4_t backendmatrix;
+static matrix4x4_t backend_viewmatrix;
+static matrix4x4_t backend_modelmatrix;
+static matrix4x4_t backend_modelviewmatrix;
+static matrix4x4_t backend_glmodelviewmatrix;
 
 static int backendunits, backendactive;
 static qbyte *varray_bcolor;
@@ -273,9 +276,23 @@ static void GL_SetupFrame (void)
        qglFrustum(-xmax, xmax, -ymax, ymax, zNear, zFar);CHECKGLERROR
 
        qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
-       qglLoadIdentity ();CHECKGLERROR
 
+       Matrix4x4_CreateRotate(&backend_viewmatrix, -90, 1, 0, 0);
+       Matrix4x4_ConcatRotate(&backend_viewmatrix, 90, 0, 0, 1);
+       Matrix4x4_ConcatRotate(&backend_viewmatrix, -r_refdef.viewangles[2], 1, 0, 0);
+       Matrix4x4_ConcatRotate(&backend_viewmatrix, -r_refdef.viewangles[0], 0, 1, 0);
+       Matrix4x4_ConcatRotate(&backend_viewmatrix, -r_refdef.viewangles[1], 0, 0, 1);
+       Matrix4x4_ConcatTranslate(&backend_viewmatrix, -r_refdef.vieworg[0],  -r_refdef.vieworg[1],  -r_refdef.vieworg[2]);
+       //Con_Printf("Our Matrix:\n");
+       //Matrix4x4_Print(&backend_viewmatrix);
+
+       //Matrix4x4_Transpose(&backend_glmodelviewmatrix, &backend_viewmatrix);
+       //qglLoadMatrixf(&backend_glmodelviewmatrix.m[0][0]);CHECKGLERROR
+       memset(&backend_modelmatrix, 0, sizeof(backend_modelmatrix));
+
+       /*
        // put Z going up
+       qglLoadIdentity ();CHECKGLERROR
        qglRotatef (-90,  1, 0, 0);CHECKGLERROR
        qglRotatef (90,  0, 0, 1);CHECKGLERROR
        // camera rotation
@@ -284,6 +301,11 @@ static void GL_SetupFrame (void)
        qglRotatef (-r_refdef.viewangles[1],  0, 0, 1);CHECKGLERROR
        // camera location
        qglTranslatef (-r_refdef.vieworg[0],  -r_refdef.vieworg[1],  -r_refdef.vieworg[2]);CHECKGLERROR
+       qglGetFloatv (GL_MODELVIEW_MATRIX, &gl_viewmatrix.m[0][0]);
+       Matrix4x4_Transpose(&backend_viewmatrix, &gl_viewmatrix);
+       Con_Printf("GL Matrix:\n");
+       Matrix4x4_Print(&backend_viewmatrix);
+       */
 }
 
 static struct
@@ -495,6 +517,7 @@ void GL_ConvertColorsFloatToByte(int numverts)
        }
 }
 
+/*
 void GL_TransformVertices(int numverts)
 {
        int i;
@@ -519,6 +542,7 @@ void GL_TransformVertices(int numverts)
                v[2] = tempv[0] * m[8] + tempv[1] * m[9] + tempv[2] * m[10] + m[11];
        }
 }
+*/
 
 void GL_DrawRangeElements(int firstvert, int endvert, int indexcount, GLuint *index)
 {
@@ -619,7 +643,7 @@ void R_Mesh_Draw(int numverts, int numtriangles)
        // drawmode 0 always uses byte colors
        if (!gl_mesh_floatcolors.integer || gl_mesh_drawmode.integer <= 0)
                GL_ConvertColorsFloatToByte(numverts);
-       GL_TransformVertices(numverts);
+       //GL_TransformVertices(numverts);
        if (!r_render.integer)
                return;
        GL_DrawRangeElements(0, numverts, numtriangles * 3, varray_element);
@@ -703,7 +727,14 @@ void R_Mesh_State(const rmeshstate_t *m)
                GL_SetupTextureState();
        }
 
-       backendmatrix = m->matrix; // this copies the struct
+       //backendmatrix = m->matrix; // this copies the struct
+       if (memcmp(&m->matrix, &backend_modelmatrix, sizeof(matrix4x4_t)))
+       {
+               backend_modelmatrix = m->matrix;
+               Matrix4x4_Concat(&backend_modelviewmatrix, &backend_viewmatrix, &m->matrix);
+               Matrix4x4_Transpose(&backend_glmodelviewmatrix, &backend_modelviewmatrix);
+               qglLoadMatrixf(&backend_glmodelviewmatrix.m[0][0]);
+       }
 
        overbright = false;
        scaler = 1;
index 87d3278d3715f05b4803c22cf7550518955aea94..d945bc9dbfa1402f0c38507151034e1804d14cf4 100644 (file)
--- a/glquake.h
+++ b/glquake.h
@@ -92,6 +92,10 @@ typedef double GLclampd;
 #define GL_MODELVIEW                           0x1700
 #define GL_PROJECTION                          0x1701
 #define GL_TEXTURE                             0x1702
+#define GL_MATRIX_MODE                         0x0BA0
+#define GL_MODELVIEW_MATRIX                    0x0BA6
+#define GL_PROJECTION_MATRIX                   0x0BA7
+#define GL_TEXTURE_MATRIX                      0x0BA8
 
 #define GL_DEPTH_TEST                          0x0B71
 
@@ -305,9 +309,9 @@ extern void (GLAPIENTRY *qglDisable)(GLenum cap);
 extern void (GLAPIENTRY *qglEnableClientState)(GLenum cap);
 extern void (GLAPIENTRY *qglDisableClientState)(GLenum cap);
 
-//extern void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
-//extern void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
-//extern void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
+extern void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
+extern void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
+extern void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
 extern void (GLAPIENTRY *qglGetIntegerv)(GLenum pname, GLint *params);
 
 extern GLenum (GLAPIENTRY *qglGetError)(void);
@@ -342,8 +346,8 @@ extern void (GLAPIENTRY *qglViewport)(GLint x, GLint y, GLsizei width, GLsizei h
 //extern void (GLAPIENTRY *qglPushMatrix)(void);
 //extern void (GLAPIENTRY *qglPopMatrix)(void);
 extern void (GLAPIENTRY *qglLoadIdentity)(void);
-//extern void (GLAPIENTRY *qglLoadMatrixd)(const GLdouble *m);
-//extern void (GLAPIENTRY *qglLoadMatrixf)(const GLfloat *m);
+extern void (GLAPIENTRY *qglLoadMatrixd)(const GLdouble *m);
+extern void (GLAPIENTRY *qglLoadMatrixf)(const GLfloat *m);
 //extern void (GLAPIENTRY *qglMultMatrixd)(const GLdouble *m);
 //extern void (GLAPIENTRY *qglMultMatrixf)(const GLfloat *m);
 //extern void (GLAPIENTRY *qglRotated)(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
index 40798fdafae1227824df743318b626759e6fb5af..af5ec5ee5697ab7ff25e5cb668bc4769ff1a3e8d 100644 (file)
@@ -220,7 +220,7 @@ void Matrix4x4_CreateRotate (matrix4x4_t *out, float angle, float x, float y, fl
        y *= len;
        z *= len;
 
-       angle *= M_PI / 180.0;
+       angle *= -M_PI / 180.0;
        c = cos(angle);
        s = sin(angle);
 
@@ -381,7 +381,7 @@ void Matrix4x4_SimpleUntransform (const matrix4x4_t *in, const float v[3], float
 void Matrix4x4_ConcatTranslate (matrix4x4_t *out, float x, float y, float z)
 {
        matrix4x4_t base, temp;
-       Matrix4x4_Copy(out, &base);
+       base = *out;
        Matrix4x4_CreateTranslate(&temp, x, y, z);
        Matrix4x4_Concat(out, &base, &temp);
 }
@@ -390,7 +390,7 @@ void Matrix4x4_ConcatTranslate (matrix4x4_t *out, float x, float y, float z)
 void Matrix4x4_ConcatRotate (matrix4x4_t *out, float angle, float x, float y, float z)
 {
        matrix4x4_t base, temp;
-       Matrix4x4_Copy(out, &base);
+       base = *out;
        Matrix4x4_CreateRotate(&temp, angle, x, y, z);
        Matrix4x4_Concat(out, &base, &temp);
 }
@@ -399,7 +399,7 @@ void Matrix4x4_ConcatRotate (matrix4x4_t *out, float angle, float x, float y, fl
 void Matrix4x4_ConcatScale (matrix4x4_t *out, float x)
 {
        matrix4x4_t base, temp;
-       Matrix4x4_Copy(out, &base);
+       base = *out;
        Matrix4x4_CreateScale(&temp, x);
        Matrix4x4_Concat(out, &base, &temp);
 }
@@ -408,11 +408,19 @@ void Matrix4x4_ConcatScale (matrix4x4_t *out, float x)
 void Matrix4x4_ConcatScale3 (matrix4x4_t *out, float x, float y, float z)
 {
        matrix4x4_t base, temp;
-       Matrix4x4_Copy(out, &base);
+       base = *out;
        Matrix4x4_CreateScale3(&temp, x, y, z);
        Matrix4x4_Concat(out, &base, &temp);
 }
 
+void Matrix4x4_Print (const matrix4x4_t *in)
+{
+       Con_Printf("%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n"
+       , in->m[0][0], in->m[0][1], in->m[0][2], in->m[0][3]
+       , in->m[1][0], in->m[1][1], in->m[1][2], in->m[1][3]
+       , in->m[2][0], in->m[2][1], in->m[2][2], in->m[2][3]
+       , in->m[3][0], in->m[3][1], in->m[3][2], in->m[3][3]);
+}
 
 
 
@@ -714,7 +722,7 @@ void Matrix3x4_SimpleUntransform (const matrix3x4_t *in, const float v[3], float
 void Matrix3x4_ConcatTranslate (matrix3x4_t *out, float x, float y, float z)
 {
        matrix3x4_t base, temp;
-       Matrix3x4_Copy(out, &base);
+       base = *out;
        Matrix3x4_CreateTranslate(&temp, x, y, z);
        Matrix3x4_Concat(out, &base, &temp);
 }
@@ -723,7 +731,7 @@ void Matrix3x4_ConcatTranslate (matrix3x4_t *out, float x, float y, float z)
 void Matrix3x4_ConcatRotate (matrix3x4_t *out, float angle, float x, float y, float z)
 {
        matrix3x4_t base, temp;
-       Matrix3x4_Copy(out, &base);
+       base = *out;
        Matrix3x4_CreateRotate(&temp, angle, x, y, z);
        Matrix3x4_Concat(out, &base, &temp);
 }
@@ -732,7 +740,7 @@ void Matrix3x4_ConcatRotate (matrix3x4_t *out, float angle, float x, float y, fl
 void Matrix3x4_ConcatScale (matrix3x4_t *out, float x)
 {
        matrix3x4_t base, temp;
-       Matrix3x4_Copy(out, &base);
+       base = *out;
        Matrix3x4_CreateScale(&temp, x);
        Matrix3x4_Concat(out, &base, &temp);
 }
@@ -741,7 +749,16 @@ void Matrix3x4_ConcatScale (matrix3x4_t *out, float x)
 void Matrix3x4_ConcatScale3 (matrix3x4_t *out, float x, float y, float z)
 {
        matrix3x4_t base, temp;
-       Matrix3x4_Copy(out, &base);
+       base = *out;
        Matrix3x4_CreateScale3(&temp, x, y, z);
        Matrix3x4_Concat(out, &base, &temp);
 }
+
+void Matrix3x4_Print (const matrix3x4_t *in)
+{
+       Con_Printf("%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n"
+       , in->m[0][0], in->m[0][1], in->m[0][2], in->m[0][3]
+       , in->m[1][0], in->m[1][1], in->m[1][2], in->m[1][3]
+       , in->m[2][0], in->m[2][1], in->m[2][2], in->m[2][3]);
+}
+
index 62b8a3e1ff36c2942c235351dda9b36aa5c9e9d0..81364c68e2de344284f21b478a19c2ea5bc67af6 100644 (file)
@@ -84,6 +84,8 @@ void Matrix4x4_ConcatScale (matrix4x4_t *out, float x);
 // immediately applies a Scale3 to the matrix
 void Matrix4x4_ConcatScale3 (matrix4x4_t *out, float x, float y, float z);
 
+// print a matrix to the console
+void Matrix4x4_Print(const matrix4x4_t *in);
 
 
 // functions for manipulating 3x4 matrices
@@ -149,4 +151,7 @@ void Matrix3x4_ConcatScale (matrix3x4_t *out, float x);
 // immediately applies a Scale3 to the matrix
 void Matrix3x4_ConcatScale3 (matrix3x4_t *out, float x, float y, float z);
 
+// print a matrix to the console
+void Matrix3x4_Print(const matrix3x4_t *in);
+
 #endif
index a7932293a62e73437b1683afe929823a9fc56c4e..8ae15b81ea6741403bd724647a6a717cbef427f2 100644 (file)
@@ -62,9 +62,9 @@ void (GLAPIENTRY *qglDisable)(GLenum cap);
 void (GLAPIENTRY *qglEnableClientState)(GLenum cap);
 void (GLAPIENTRY *qglDisableClientState)(GLenum cap);
 
-//void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
-//void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
-//void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
+void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
+void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
+void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
 void (GLAPIENTRY *qglGetIntegerv)(GLenum pname, GLint *params);
 
 GLenum (GLAPIENTRY *qglGetError)(void);
@@ -99,8 +99,8 @@ void (GLAPIENTRY *qglViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
 //void (GLAPIENTRY *qglPushMatrix)(void);
 //void (GLAPIENTRY *qglPopMatrix)(void);
 void (GLAPIENTRY *qglLoadIdentity)(void);
-//void (GLAPIENTRY *qglLoadMatrixd)(const GLdouble *m);
-//void (GLAPIENTRY *qglLoadMatrixf)(const GLfloat *m);
+void (GLAPIENTRY *qglLoadMatrixd)(const GLdouble *m);
+void (GLAPIENTRY *qglLoadMatrixf)(const GLfloat *m);
 //void (GLAPIENTRY *qglMultMatrixd)(const GLdouble *m);
 //void (GLAPIENTRY *qglMultMatrixf)(const GLfloat *m);
 //void (GLAPIENTRY *qglRotated)(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
@@ -200,9 +200,9 @@ static gl_extensionfunctionlist_t opengl110funcs[] =
 //     {"glIsEnabled", (void **) &qglIsEnabled},
        {"glEnableClientState", (void **) &qglEnableClientState},
        {"glDisableClientState", (void **) &qglDisableClientState},
-//     {"glGetBooleanv", (void **) &qglGetBooleanv},
-//     {"glGetDoublev", (void **) &qglGetDoublev},
-//     {"glGetFloatv", (void **) &qglGetFloatv},
+       {"glGetBooleanv", (void **) &qglGetBooleanv},
+       {"glGetDoublev", (void **) &qglGetDoublev},
+       {"glGetFloatv", (void **) &qglGetFloatv},
        {"glGetIntegerv", (void **) &qglGetIntegerv},
        {"glGetError", (void **) &qglGetError},
        {"glGetString", (void **) &qglGetString},
@@ -231,8 +231,8 @@ static gl_extensionfunctionlist_t opengl110funcs[] =
 //     {"glPushMatrix", (void **) &qglPushMatrix},
 //     {"glPopMatrix", (void **) &qglPopMatrix},
        {"glLoadIdentity", (void **) &qglLoadIdentity},
-//     {"glLoadMatrixd", (void **) &qglLoadMatrixd},
-//     {"glLoadMatrixf", (void **) &qglLoadMatrixf},
+       {"glLoadMatrixd", (void **) &qglLoadMatrixd},
+       {"glLoadMatrixf", (void **) &qglLoadMatrixf},
 //     {"glMultMatrixd", (void **) &qglMultMatrixd},
 //     {"glMultMatrixf", (void **) &qglMultMatrixf},
 //     {"glRotated", (void **) &qglRotated},