]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
cleaned up GL_DepthTest and GL_CULL_FACE state management (by adding GL_CullFace...
[xonotic/darkplaces.git] / gl_rmain.c
index f760fa9d588461876c8dcc24e4ce994d256e1e81..b43d6656e043fe74e4d74e551e8782d8cbc35eee 100644 (file)
@@ -966,7 +966,7 @@ void gl_main_newmap(void)
                l = (int)strlen(entname) - 4;
                if (l >= 0 && !strcmp(entname + l, ".bsp"))
                {
-                       strcpy(entname + l, ".ent");
+                       memcpy(entname + l, ".ent", 5);
                        if ((entities = (char *)FS_LoadFile(entname, tempmempool, true, NULL)))
                        {
                                CL_ParseEntityLump(entities);
@@ -1138,7 +1138,11 @@ static void R_UpdateEntityLighting(entity_render_t *ent)
        VectorClear(ent->modellight_diffuse);
        VectorClear(ent->modellight_lightdir);
        if ((ent->flags & RENDER_LIGHT) && r_refdef.worldmodel && r_refdef.worldmodel->brush.LightPoint)
-               r_refdef.worldmodel->brush.LightPoint(r_refdef.worldmodel, ent->origin, ent->modellight_ambient, ent->modellight_diffuse, tempdiffusenormal);
+       {
+               vec3_t org;
+               Matrix4x4_OriginFromMatrix(&ent->matrix, org);
+               r_refdef.worldmodel->brush.LightPoint(r_refdef.worldmodel, org, ent->modellight_ambient, ent->modellight_diffuse, tempdiffusenormal);
+       }
        else // highly rare
                VectorSet(ent->modellight_ambient, 1, 1, 1);
        Matrix4x4_Transform3x3(&ent->inversematrix, tempdiffusenormal, ent->modellight_lightdir);
@@ -1175,7 +1179,7 @@ static void R_View_UpdateEntityVisible (void)
                for (i = 0;i < r_refdef.numentities;i++)
                {
                        ent = r_refdef.entities[i];
-                       r_viewcache.entityvisible[i] = !(ent->flags & renderimask) && !R_CullBox(ent->mins, ent->maxs) && (ent->effects & EF_NODEPTHTEST);
+                       r_viewcache.entityvisible[i] = !(ent->flags & renderimask) && !R_CullBox(ent->mins, ent->maxs);
                }
        }
 }
@@ -1780,10 +1784,6 @@ void R_UpdateVariables(void)
        for (i = 0;i < r_refdef.numentities;i++)
        {
                entity_render_t *ent = r_refdef.entities[i];
-               // some of the renderer still relies on origin...
-               Matrix4x4_OriginFromMatrix(&ent->matrix, ent->origin);
-               // some of the renderer still relies on scale...
-               ent->scale = Matrix4x4_ScaleFromMatrix(&ent->matrix);
                R_UpdateEntityLighting(ent);
        }
 }
@@ -1794,43 +1794,6 @@ R_RenderView
 ================
 */
 void R_RenderView(void)
-{
-       if (!r_refdef.entities/* || !r_refdef.worldmodel*/)
-               return; //Host_Error ("R_RenderView: NULL worldmodel");
-
-       CHECKGLERROR
-       if (r_timereport_active)
-               R_TimeReport("setup");
-
-       R_View_Update();
-       if (r_timereport_active)
-               R_TimeReport("visibility");
-
-       // GL is weird because it's bottom to top, r_view.y is top to bottom
-       R_ResetViewRendering();
-
-       R_ClearScreen();
-       if (r_timereport_active)
-               R_TimeReport("clear");
-
-       // this produces a bloom texture to be used in R_BlendView() later
-       if (r_hdr.integer)
-               R_HDR_RenderBloomTexture();
-
-       r_view.colorscale = r_hdr_scenebrightness.value;
-       R_RenderScene();
-
-       R_BlendView();
-       if (r_timereport_active)
-               R_TimeReport("blendview");
-
-       GL_Scissor(0, 0, vid.width, vid.height);
-       GL_ScissorTest(false);
-       CHECKGLERROR
-}
-
-//[515]: csqc
-void CSQC_R_ClearScreen (void)
 {
        if (!r_refdef.entities/* || !r_refdef.worldmodel*/)
                return; //Host_Error ("R_RenderView: NULL worldmodel");
@@ -1847,17 +1810,6 @@ void CSQC_R_ClearScreen (void)
 
        R_ResetViewRendering();
 
-       R_ClearScreen();
-       if (r_timereport_active)
-               R_TimeReport("clear");
-       CHECKGLERROR
-}
-
-//[515]: csqc
-void CSQC_R_RenderScene (void)
-{
-       R_ResetViewRendering();
-
        R_ClearScreen();
        if (r_timereport_active)
                R_TimeReport("clear");
@@ -1883,6 +1835,8 @@ extern void VM_AddPolygonsToMeshQueue (void);
 extern void R_DrawPortals (void);
 void R_RenderScene(void)
 {
+       DrawQ_Finish();
+
        // don't let sound skip if going slow
        if (r_refdef.extraupdate)
                S_ExtraUpdate ();
@@ -2115,9 +2069,11 @@ void R_DrawNoModel_TransparentCallback(const entity_render_t *ent, const rtlight
        R_Mesh_VertexPointer(nomodelvertex3f);
        if (r_refdef.fogenabled)
        {
+               vec3_t org;
                memcpy(color4f, nomodelcolor4f, sizeof(float[6*4]));
                R_Mesh_ColorPointer(color4f);
-               f2 = VERTEXFOGTABLE(VectorDistance(ent->origin, r_view.origin));
+               Matrix4x4_OriginFromMatrix(&ent->matrix, org);
+               f2 = VERTEXFOGTABLE(VectorDistance(org, r_view.origin));
                f1 = 1 - f2;
                for (i = 0, c = color4f;i < 6;i++, c += 4)
                {
@@ -2142,8 +2098,10 @@ void R_DrawNoModel_TransparentCallback(const entity_render_t *ent, const rtlight
 
 void R_DrawNoModel(entity_render_t *ent)
 {
+       vec3_t org;
+       Matrix4x4_OriginFromMatrix(&ent->matrix, org);
        //if ((ent->effects & EF_ADDITIVE) || (ent->alpha < 1))
-               R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_view.origin : ent->origin, R_DrawNoModel_TransparentCallback, ent, 0, r_shadow_rtlight);
+               R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_view.origin : org, R_DrawNoModel_TransparentCallback, ent, 0, r_shadow_rtlight);
        //else
        //      R_DrawNoModelCallback(ent, 0);
 }
@@ -2308,7 +2266,7 @@ void R_Mesh_AddBrushMeshFromPlanes(rmesh_t *mesh, int numplanes, mplane_t *plane
        {
                w = 0;
                tempnumpoints = 4;
-               PolygonD_QuadForPlane(temppoints[w], plane->normal[0], plane->normal[1], plane->normal[2], plane->normal[3], maxdist);
+               PolygonD_QuadForPlane(temppoints[w], plane->normal[0], plane->normal[1], plane->normal[2], plane->dist, maxdist);
                for (planenum2 = 0, plane2 = planes;planenum2 < numplanes && tempnumpoints >= 3;planenum2++, plane2++)
                {
                        if (planenum2 == planenum)
@@ -2657,6 +2615,7 @@ void RSurf_CleanUp(void)
 
 void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generatetangents, int texturenumsurfaces, msurface_t **texturesurfacelist)
 {
+       // if vertices are dynamic (animated models), generate them into the temporary rsurface_array_model* arrays and point rsurface_model* at them instead of the static data from the model itself
        if (rsurface_generatedvertex)
        {
                if (rsurface_texture->textureflags & (Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2))
@@ -2675,6 +2634,7 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta
                        Mod_BuildTextureVectorsFromNormals(0, rsurface_model->surfmesh.num_vertices, rsurface_model->surfmesh.num_triangles, rsurface_modelvertex3f, rsurface_model->surfmesh.data_texcoordtexture2f, rsurface_modelnormal3f, rsurface_model->surfmesh.data_element3i, rsurface_array_modelsvector3f, rsurface_array_modeltvector3f, r_smoothnormals_areaweighting.integer);
                }
        }
+       // if vertices are deformed (sprite flares and things in maps, possibly water waves, bulges and other deformations), generate them into rsurface_deform* arrays from whatever the rsurface_model* array pointers point to (may be static model data or generated data for an animated model)
        if (rsurface_texture->textureflags & (Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2))
        {
                int texturesurfaceindex;
@@ -2683,7 +2643,7 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta
                Matrix4x4_Transform(&rsurface_entity->inversematrix, r_view.forward, forward);
                Matrix4x4_Transform(&rsurface_entity->inversematrix, r_view.right, right);
                Matrix4x4_Transform(&rsurface_entity->inversematrix, r_view.up, up);
-               // make deformed versions of only the vertices used by the specified surfaces
+               // make deformed versions of only the model vertices used by the specified surfaces
                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                {
                        int i, j;
@@ -2693,7 +2653,7 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta
                        {
                                VectorClear(center);
                                for (i = 0;i < 4;i++)
-                                       VectorAdd(center, (rsurface_vertex3f + 3 * surface->num_firstvertex) + (j+i) * 3, center);
+                                       VectorAdd(center, (rsurface_modelvertex3f + 3 * surface->num_firstvertex) + (j+i) * 3, center);
                                VectorScale(center, 0.25f, center);
                                if (rsurface_texture->textureflags & Q3TEXTUREFLAG_AUTOSPRITE2)
                                {
@@ -2707,10 +2667,10 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta
                                        VectorSet(up, 0, 0, 1);
                                }
                                // FIXME: calculate vectors from triangle edges instead of using texture vectors as an easy way out?
-                               Matrix4x4_FromVectors(&matrix1, (rsurface_normal3f + 3 * surface->num_firstvertex) + j*3, (rsurface_svector3f + 3 * surface->num_firstvertex) + j*3, (rsurface_tvector3f + 3 * surface->num_firstvertex) + j*3, center);
+                               Matrix4x4_FromVectors(&matrix1, (rsurface_modelnormal3f + 3 * surface->num_firstvertex) + j*3, (rsurface_modelsvector3f + 3 * surface->num_firstvertex) + j*3, (rsurface_modeltvector3f + 3 * surface->num_firstvertex) + j*3, center);
                                Matrix4x4_Invert_Simple(&imatrix1, &matrix1);
                                for (i = 0;i < 4;i++)
-                                       Matrix4x4_Transform(&imatrix1, (rsurface_vertex3f + 3 * surface->num_firstvertex) + (j+i)*3, v[i]);
+                                       Matrix4x4_Transform(&imatrix1, (rsurface_modelvertex3f + 3 * surface->num_firstvertex) + (j+i)*3, v[i]);
                                for (i = 0;i < 4;i++)
                                        VectorMAMAMAM(1, center, v[i][0], forward, v[i][1], right, v[i][2], up, rsurface_array_deformedvertex3f + (surface->num_firstvertex+i+j) * 3);
                        }
@@ -3349,10 +3309,7 @@ static void R_DrawTextureSurfaceList(int texturenumsurfaces, msurface_t **textur
        r_refdef.stats.entities_surfaces += texturenumsurfaces;
        CHECKGLERROR
        GL_DepthTest(!(rsurface_texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST));
-       if ((rsurface_texture->textureflags & Q3TEXTUREFLAG_TWOSIDED) || (rsurface_entity->flags & RENDER_NOCULLFACE))
-       {
-               qglDisable(GL_CULL_FACE);CHECKGLERROR
-       }
+       GL_CullFace(((rsurface_texture->textureflags & Q3TEXTUREFLAG_TWOSIDED) || (rsurface_entity->flags & RENDER_NOCULLFACE)) ? GL_NONE : GL_FRONT); // quake is backwards, this culls back faces
        if (r_showsurfaces.integer)
                R_DrawTextureSurfaceList_ShowSurfaces(texturenumsurfaces, texturesurfacelist);
        else if (rsurface_texture->currentmaterialflags & MATERIALFLAG_SKY)
@@ -3368,10 +3325,6 @@ static void R_DrawTextureSurfaceList(int texturenumsurfaces, msurface_t **textur
        }
        CHECKGLERROR
        GL_LockArrays(0, 0);
-       if ((rsurface_texture->textureflags & Q3TEXTUREFLAG_TWOSIDED) || (rsurface_entity->flags & RENDER_NOCULLFACE))
-       {
-               qglEnable(GL_CULL_FACE);CHECKGLERROR
-       }
 }
 
 #define BATCHSIZE 256