]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
implemented occlusion query support on corona rendering, this enables
[xonotic/darkplaces.git] / gl_rmain.c
index b229b4b46501ed611d41ec646ad65a7e0b7bd065..9d83c1f1efc1c9575f3e7a775b68da84248278d4 100644 (file)
@@ -168,6 +168,10 @@ rtexture_t *r_texture_gammaramps;
 unsigned int r_texture_gammaramps_serial;
 //rtexture_t *r_texture_fogintensity;
 
+unsigned int r_queries[R_MAX_OCCLUSION_QUERIES];
+unsigned int r_numqueries;
+unsigned int r_maxqueries;
+
 char r_qwskincache[MAX_SCOREBOARD][MAX_QPATH];
 skinframe_t *r_qwskincache_skinframe[MAX_SCOREBOARD];
 
@@ -1243,13 +1247,13 @@ static char *R_GLSL_GetText(const char *filename, qboolean printfromdisknotice)
        }
        else if (!strcmp(filename, "glsl/default.glsl"))
        {
-               shaderstring = Mem_Alloc(r_main_mempool, strlen(builtinshaderstring) + 1);
+               shaderstring = (char *) Mem_Alloc(r_main_mempool, strlen(builtinshaderstring) + 1);
                memcpy(shaderstring, builtinshaderstring, strlen(builtinshaderstring) + 1);
        }
        return shaderstring;
 }
 
-static void R_GLSL_CompilePermutation(shadermode_t mode, shaderpermutation_t permutation)
+static void R_GLSL_CompilePermutation(unsigned int mode, unsigned int permutation)
 {
        int i;
        shadermodeinfo_t *modeinfo = shadermodeinfo + mode;
@@ -1420,8 +1424,8 @@ static void R_GLSL_CompilePermutation(shadermode_t mode, shaderpermutation_t per
 
 void R_GLSL_Restart_f(void)
 {
-       shadermode_t mode;
-       shaderpermutation_t permutation;
+       unsigned int mode;
+       unsigned int permutation;
        for (mode = 0;mode < SHADERMODE_COUNT;mode++)
                for (permutation = 0;permutation < SHADERPERMUTATION_LIMIT;permutation++)
                        if (r_glsl_permutations[mode][permutation].program)
@@ -1453,7 +1457,7 @@ void R_GLSL_DumpShader_f(void)
        Con_Printf("glsl/default.glsl written\n");
 }
 
-void R_SetupShader_SetPermutation(shadermode_t mode, unsigned int permutation)
+void R_SetupShader_SetPermutation(unsigned int mode, unsigned int permutation)
 {
        r_glsl_permutation_t *perm = &r_glsl_permutations[mode][permutation];
        if (r_glsl_permutation != perm)
@@ -1552,7 +1556,7 @@ void R_SetupSurfaceShader(const vec3_t lightcolorbase, qboolean modellighting, f
        // minimum features necessary to avoid wasting rendering time in the
        // fragment shader on features that are not being used
        unsigned int permutation = 0;
-       shadermode_t mode = 0;
+       unsigned int mode = 0;
        // TODO: implement geometry-shader based shadow volumes someday
        if (r_glsl_offsetmapping.integer)
        {
@@ -1734,7 +1738,7 @@ void R_SetupSurfaceShader(const vec3_t lightcolorbase, qboolean modellighting, f
                        if (r_glsl_permutation->loc_SpecularScale >= 0) qglUniform1fARB(r_glsl_permutation->loc_SpecularScale, r_refdef.lightmapintensity * specularscale);
                }
                if (r_glsl_permutation->loc_TintColor >= 0) qglUniform4fARB(r_glsl_permutation->loc_TintColor, rsurface.texture->lightmapcolor[0], rsurface.texture->lightmapcolor[1], rsurface.texture->lightmapcolor[2], rsurface.texture->lightmapcolor[3]);
-               if (r_glsl_permutation->loc_GlowScale     >= 0) qglUniform1fARB(r_glsl_permutation->loc_GlowScale, r_hdr_glowintensity.value);
+               if (r_glsl_permutation->loc_GlowScale >= 0) qglUniform1fARB(r_glsl_permutation->loc_GlowScale, r_hdr_glowintensity.value);
                // additive passes are only darkened by fog, not tinted
                if (r_glsl_permutation->loc_FogColor >= 0)
                {
@@ -1794,13 +1798,14 @@ void R_SetupSurfaceShader(const vec3_t lightcolorbase, qboolean modellighting, f
 
 #define SKINFRAME_HASH 1024
 
-struct
+typedef struct
 {
        int loadsequence; // incremented each level change
        memexpandablearray_t array;
        skinframe_t *hash[SKINFRAME_HASH];
 }
-r_skinframe;
+r_skinframe_t;
+r_skinframe_t r_skinframe;
 
 void R_SkinFrame_PrepareForPurge(void)
 {
@@ -2245,6 +2250,10 @@ skinframe_t *R_SkinFrame_LoadMissing(void)
 
 void gl_main_start(void)
 {
+       r_numqueries = 0;
+       r_maxqueries = 0;
+       memset(r_queries, 0, sizeof(r_queries));
+
        memset(r_qwskincache, 0, sizeof(r_qwskincache));
        memset(r_qwskincache_skinframe, 0, sizeof(r_qwskincache_skinframe));
 
@@ -2274,6 +2283,13 @@ void gl_main_start(void)
 
 void gl_main_shutdown(void)
 {
+       if (r_maxqueries)
+               qglDeleteQueriesARB(r_maxqueries, r_queries);
+
+       r_numqueries = 0;
+       r_maxqueries = 0;
+       memset(r_queries, 0, sizeof(r_queries));
+
        memset(r_qwskincache, 0, sizeof(r_qwskincache));
        memset(r_qwskincache_skinframe, 0, sizeof(r_qwskincache_skinframe));
 
@@ -2472,8 +2488,8 @@ void GL_Init (void)
        Con_Printf("GL_VENDOR: %s\n", gl_vendor);
        Con_Printf("GL_RENDERER: %s\n", gl_renderer);
        Con_Printf("GL_VERSION: %s\n", gl_version);
-       Con_Printf("GL_EXTENSIONS: %s\n", gl_extensions);
-       Con_Printf("%s_EXTENSIONS: %s\n", gl_platform, gl_platformextensions);
+       Con_DPrintf("GL_EXTENSIONS: %s\n", gl_extensions);
+       Con_DPrintf("%s_EXTENSIONS: %s\n", gl_platform, gl_platformextensions);
 
        VID_CheckExtensions();
 
@@ -4678,11 +4694,11 @@ void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t)
                        Matrix4x4_CreateTranslate(&matrix, tcmod->parms[0] * r_refdef.scene.time, tcmod->parms[1] * r_refdef.scene.time, 0);
                        break;
                case Q3TCMOD_PAGE: // poor man's animmap (to store animations into a single file, useful for HTTP downloaded textures)
-                       w = tcmod->parms[0];
-                       h = tcmod->parms[1];
+                       w = (int) tcmod->parms[0];
+                       h = (int) tcmod->parms[1];
                        f = r_refdef.scene.time / (tcmod->parms[2] * w * h);
                        f = f - floor(f);
-                       idx = floor(f * w * h);
+                       idx = (int) floor(f * w * h);
                        Matrix4x4_CreateTranslate(&matrix, (idx % w) / tcmod->parms[0], (idx / w) / tcmod->parms[1], 0);
                        break;
                case Q3TCMOD_STRETCH:
@@ -6942,7 +6958,7 @@ void R_DrawWorldSurfaces(qboolean skysurfaces, qboolean writedepth, qboolean dep
                r_maxsurfacelist = model->num_surfaces;
                if (r_surfacelist)
                        Mem_Free(r_surfacelist);
-               r_surfacelist = Mem_Alloc(r_main_mempool, r_maxsurfacelist * sizeof(*r_surfacelist));
+               r_surfacelist = (msurface_t **) Mem_Alloc(r_main_mempool, r_maxsurfacelist * sizeof(*r_surfacelist));
        }
 
        RSurf_ActiveWorldEntity();
@@ -7032,7 +7048,7 @@ void R_DrawModelSurfaces(entity_render_t *ent, qboolean skysurfaces, qboolean wr
                r_maxsurfacelist = model->num_surfaces;
                if (r_surfacelist)
                        Mem_Free(r_surfacelist);
-               r_surfacelist = Mem_Alloc(r_main_mempool, r_maxsurfacelist * sizeof(*r_surfacelist));
+               r_surfacelist = (msurface_t **) Mem_Alloc(r_main_mempool, r_maxsurfacelist * sizeof(*r_surfacelist));
        }
 
        // if the model is static it doesn't matter what value we give for