void glf_free_font(gl_tex_font_p glf) { if(glf != NULL) { if(glf->ft_face != NULL) { FT_Done_Face(glf->ft_face); } glf->ft_face = NULL; if(glf->glyphs != NULL) { free(glf->glyphs); glf->glyphs = NULL; } glf->glyphs_count = 0; glf->gl_real_tex_indexes_count = 0; if(glf->gl_tex_indexes != NULL) { if(glf->gl_tex_indexes_count > 0) { qglDeleteTextures(glf->gl_tex_indexes_count, glf->gl_tex_indexes); } free(glf->gl_tex_indexes); } glf->gl_tex_indexes_count = 0; glf->gl_tex_indexes = NULL; free(glf); } }
// e6y // The common function for cleaning textures and patches // gld_CleanTextures and gld_CleanPatchTextures are replaced with that static void gld_CleanTexItems(int count, GLTexture ***items) { int i, j; if (!(*items)) return; for (i=0; i<count; i++) { if ((*items)[i]) { int cm, n; for (j=0; j<(CR_LIMIT+MAXPLAYERS); j++) { for (n=0; n<PLAYERCOLORMAP_COUNT; n++) { for (cm=0; cm<numcolormaps; cm++) { if ((*items) && (*items)[i]->glTexExID[j][n][cm]) { qglDeleteTextures(1,&((*items)[i]->glTexExID[j][n][cm])); } } } } Z_Free((*items)[i]->glTexExID); (*items)[i]->glTexExID = NULL; Z_Free((*items)[i]); } } memset((*items),0,count*sizeof(GLTexture *)); }
int gld_wipe_exitMelt(int ticks) { if (wipe_scr_start_tex != 0) { qglDeleteTextures(1, &wipe_scr_start_tex); wipe_scr_start_tex = 0; } if (wipe_scr_end_tex != 0) { qglDeleteTextures(1, &wipe_scr_end_tex); wipe_scr_end_tex = 0; } gld_ResetLastTexture(); return 0; }
/* ======================== idImage::PurgeImage ======================== */ void idImage::PurgeImage() { if ( texnum != TEXTURE_NOT_LOADED ) { qglDeleteTextures( 1, (GLuint *)&texnum ); // this should be the ONLY place it is ever called! texnum = TEXTURE_NOT_LOADED; } // clear all the current binding caches, so the next bind will do a real one for ( int i = 0 ; i < MAX_MULTITEXTURE_UNITS ; i++ ) { backEnd.glState.tmu[i].current2DMap = TEXTURE_NOT_LOADED; backEnd.glState.tmu[i].currentCubeMap = TEXTURE_NOT_LOADED; } }
/* * RB_FreeTextureNum */ void RB_FreeTextureNum( image_t *tex ) { qglDeleteTextures( 1, &tex->texnum ); tex->texnum = 0; // Ensures that the RB_BindTexture call that may follow will work if( rb.gl.anyTexturesBound ) { rb.gl.anyTexturesBound = 0; memset( rb.gl.currentTextures, 0, sizeof( rb.gl.currentTextures ) ); } }
void Sky_ClearSkybox (void) { // purge old texture if (skyCubeTexture) { qglDeleteTextures (1, &skyCubeTexture); skyCubeTexture = 0; } skybox_name[0] = 0; }
void Gui_Destroy() { if(main_inventory_manager) { delete main_inventory_manager; main_inventory_manager = NULL; } qglDeleteTextures(1, &load_screen_tex); qglDeleteBuffersARB(1, &crosshairBuffer); qglDeleteBuffersARB(1, &backgroundBuffer); qglDeleteBuffersARB(1, &rectBuffer); }
/* =============== RE_Shutdown =============== */ void RE_Shutdown( qboolean destroyWindow ) { // Com_Printf ("RE_Shutdown( %i )\n", destroyWindow ); Cmd_RemoveCommand ("imagelist"); Cmd_RemoveCommand ("shaderlist"); Cmd_RemoveCommand ("skinlist"); Cmd_RemoveCommand ("fontlist"); Cmd_RemoveCommand ("screenshot"); Cmd_RemoveCommand ("screenshot_tga"); Cmd_RemoveCommand ("gfxinfo"); Cmd_RemoveCommand ("r_atihack"); Cmd_RemoveCommand ("r_we"); Cmd_RemoveCommand ("imagecacheinfo"); Cmd_RemoveCommand ("modellist"); Cmd_RemoveCommand ("modelist"); Cmd_RemoveCommand ("modelcacheinfo"); #ifndef DEDICATED if ( r_DynamicGlow && r_DynamicGlow->integer ) { // Release the Glow Vertex Shader. if ( tr.glowVShader ) { qglDeleteProgramsARB( 1, &tr.glowVShader ); } // Release Pixel Shader. if ( tr.glowPShader ) { if ( qglCombinerParameteriNV ) { // Release the Glow Regcom call list. qglDeleteLists( tr.glowPShader, 1 ); } else if ( qglGenProgramsARB ) { // Release the Glow Fragment Shader. qglDeleteProgramsARB( 1, &tr.glowPShader ); } } // Release the scene glow texture. qglDeleteTextures( 1, &tr.screenGlow ); // Release the scene texture. qglDeleteTextures( 1, &tr.sceneImage ); // Release the blur texture. qglDeleteTextures( 1, &tr.blurImage ); } R_TerrainShutdown(); //rwwRMG - added R_ShutdownFonts(); if ( tr.registered ) { R_SyncRenderThread(); R_ShutdownCommandBuffers(); if (destroyWindow) { R_DeleteTextures(); // only do this for vid_restart now, not during things like map load } } // shut down platform specific OpenGL stuff if ( destroyWindow ) { GLimp_Shutdown(); } #endif //!DEDICATED tr.registered = qfalse; }
// will free all GL binded qtextures and shaders // NOTE: doesn't make much sense out of Radiant exit or called during a reload void WINAPI QERApp_FreeShaders() { int i; brush_t *b; // store the shader names used by the patches for(i=0; i<PatchShaders.GetSize(); i++) delete PatchShaders.GetAt(i); PatchShaders.RemoveAll(); for (b=active_brushes.next ; b != NULL && b != &active_brushes ; b=b->next) { if (b->patchBrush) PushPatch(b->pPatch); } for (b=selected_brushes.next ; b != NULL && b != &selected_brushes ; b=b->next) { if (b->patchBrush) PushPatch(b->pPatch); } // reload shaders // empty the actives shaders list g_ActiveShaders.ReleaseAll(); g_Shaders.ReleaseAll(); // empty the main g_qeglobals.d_qtextures list // FIXME: when we reload later on, we need to have the shader names // for brushes it's stored in the texdef // but patches don't have texdef // see bug 104655 for details // so the solution, build an array of patchMesh_t* and their shader names #ifdef _DEBUG Sys_Printf("FIXME: bug 104655 workaround\n"); #endif // NOTE: maybe before we'd like to set all qtexture_t in the shaders list to notex? // NOTE: maybe there are some qtexture_t we don't want to erase? For plain color faces maybe? // NOTE: the GL textures are freed later on if (g_qeglobals.d_qtextures) { qtexture_t* pTex = g_qeglobals.d_qtextures->next; while (pTex != NULL && pTex != g_qeglobals.d_qtextures) { qtexture_t* pNextTex = pTex->next; if (g_qeglobals.bSurfacePropertiesPlugin) { // Timo // Surface properties plugin #ifdef _DEBUG if ( !pTex->pData ) Sys_Printf("WARNING: found a qtexture_t* with no IPluginQTexture\n"); #endif if ( pTex->pData ) GETPLUGINTEXDEF(pTex)->DecRef(); } free(pTex); pTex = pNextTex; } } // free GL bindings GLuint* pGln = new GLuint[texture_extension_number-1]; qglGenTextures(texture_extension_number-1, pGln); QE_CheckOpenGLForErrors(); qglDeleteTextures(texture_extension_number-1, pGln); QE_CheckOpenGLForErrors(); delete []pGln; texture_extension_number = 1; g_qeglobals.d_qtextures = NULL; // free the map g_qeglobals.d_qtexmap->RemoveAll(); }
void glf_resize(gl_tex_font_p glf, uint16_t font_size) { if((glf != NULL) && (glf->ft_face != NULL)) { const GLint padding = 2; GLubyte *buffer; GLint chars_in_row, chars_in_column; size_t buffer_size; int x, y, xx, yy; int i, ii, i0 = 0; // clear old atlas, if exists if(glf->gl_tex_indexes != NULL) { if(glf->gl_tex_indexes_count > 0) { qglDeleteTextures(glf->gl_tex_indexes_count, glf->gl_tex_indexes); } free(glf->gl_tex_indexes); } glf->gl_tex_indexes = NULL; glf->gl_real_tex_indexes_count = 0; // resize base font glf->font_size = font_size; FT_Set_Char_Size(glf->ft_face, font_size << 6, font_size << 6, 0, 0); // calculate texture atlas size chars_in_row = 1 + sqrt(glf->glyphs_count); glf->gl_tex_width = (font_size + padding) * chars_in_row; glf->gl_tex_width = NextPowerOf2(glf->gl_tex_width); if(glf->gl_tex_width > glf->gl_max_tex_width) { glf->gl_tex_width = glf->gl_max_tex_width; } // create new atlas chars_in_row = glf->gl_tex_width / (font_size + padding); chars_in_column = glf->glyphs_count / chars_in_row + 1; glf->gl_tex_indexes_count = (chars_in_column * (font_size + padding)) / glf->gl_tex_width + 1; glf->gl_tex_indexes = (GLuint*)malloc(glf->gl_tex_indexes_count * sizeof(GLuint)); qglGenTextures(glf->gl_tex_indexes_count, glf->gl_tex_indexes); buffer_size = glf->gl_tex_width * glf->gl_tex_width * sizeof(GLubyte); buffer = (GLubyte*)malloc(buffer_size); memset(buffer, 0x00, buffer_size); for(i = 0, x = 0, y = 0; i < glf->glyphs_count; i++) { FT_GlyphSlot g; glf->glyphs[i].tex_index = 0; /* load glyph image into the slot (erase previous one) */ if(FT_Load_Glyph(glf->ft_face, i, FT_LOAD_RENDER)) { continue; } /* convert to an anti-aliased bitmap */ if(FT_Render_Glyph(((FT_Face)glf->ft_face)->glyph, FT_RENDER_MODE_NORMAL)) { continue; } g = ((FT_Face)glf->ft_face)->glyph; glf->glyphs[i].width = g->bitmap.width; glf->glyphs[i].height = g->bitmap.rows; glf->glyphs[i].advance_x_pt = g->advance.x; glf->glyphs[i].advance_y_pt = g->advance.y; glf->glyphs[i].left = g->bitmap_left; glf->glyphs[i].top = g->bitmap_top; if((g->bitmap.width == 0) || (g->bitmap.rows == 0)) { continue; } if(x + g->bitmap.width > glf->gl_tex_width) { x = 0; y += glf->font_size + padding; if(y + glf->font_size > glf->gl_tex_width) { int ii; qglBindTexture(GL_TEXTURE_2D, glf->gl_tex_indexes[glf->gl_real_tex_indexes_count]); qglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); qglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); qglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, glf->gl_tex_width, glf->gl_tex_width, 0, GL_ALPHA, GL_UNSIGNED_BYTE, buffer); for(ii = i0; ii < i; ii++) { glf->glyphs[ii].tex_x0 /= (GLfloat)glf->gl_tex_width; glf->glyphs[ii].tex_x1 /= (GLfloat)glf->gl_tex_width; glf->glyphs[ii].tex_y0 /= (GLfloat)glf->gl_tex_width; glf->glyphs[ii].tex_y1 /= (GLfloat)glf->gl_tex_width; } memset(buffer, 0x00, buffer_size); y = 0; i0 = i; glf->gl_real_tex_indexes_count++; } } glf->glyphs[i].tex_x0 = (GLfloat)x; glf->glyphs[i].tex_y0 = (GLfloat)y; glf->glyphs[i].tex_x1 = (GLfloat)(x + g->bitmap.width); glf->glyphs[i].tex_y1 = (GLfloat)(y + g->bitmap.rows); glf->glyphs[i].tex_index = glf->gl_tex_indexes[glf->gl_real_tex_indexes_count]; for(xx = 0; xx < g->bitmap.width; xx++) { for(yy = 0; yy < g->bitmap.rows; yy++) { buffer[(y+yy)*glf->gl_tex_width + (x+xx)] = g->bitmap.buffer[yy * g->bitmap.width + xx]; } } x += (g->bitmap.width + padding); } qglBindTexture(GL_TEXTURE_2D, glf->gl_tex_indexes[glf->gl_real_tex_indexes_count]); qglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); qglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); chars_in_column = NextPowerOf2(y + font_size + padding); qglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, glf->gl_tex_width, chars_in_column, 0, GL_ALPHA, GL_UNSIGNED_BYTE, buffer); for(ii = i0; ii < glf->glyphs_count; ii++) { glf->glyphs[ii].tex_x0 /= (GLfloat)glf->gl_tex_width; glf->glyphs[ii].tex_x1 /= (GLfloat)glf->gl_tex_width; glf->glyphs[ii].tex_y0 /= (GLfloat)chars_in_column; glf->glyphs[ii].tex_y1 /= (GLfloat)chars_in_column; } free(buffer); glf->gl_real_tex_indexes_count++; } }
/* =============== RE_Shutdown =============== */ void RE_Shutdown( qboolean destroyWindow ) { ri.Printf( PRINT_ALL, "RE_Shutdown( %i )\n", destroyWindow ); ri.Cmd_RemoveCommand ("modellist"); ri.Cmd_RemoveCommand ("screenshotJPEG"); ri.Cmd_RemoveCommand ("screenshot"); ri.Cmd_RemoveCommand ("imagelist"); ri.Cmd_RemoveCommand ("shaderlist"); ri.Cmd_RemoveCommand ("skinlist"); ri.Cmd_RemoveCommand ("gfxinfo"); ri.Cmd_RemoveCommand ("modelist"); ri.Cmd_RemoveCommand ("shaderstate"); ri.Cmd_RemoveCommand ("r_we"); ri.Cmd_RemoveCommand ("modelcacheinfo"); ri.Cmd_RemoveCommand ("imagecacheinfo"); #ifndef DEDICATED if ( r_DynamicGlow && r_DynamicGlow->integer ) { // Release the Glow Vertex Shader. if ( tr.glowVShader ) { qglDeleteProgramsARB( 1, &tr.glowVShader ); } // Release Pixel Shader. if ( tr.glowPShader ) { if ( qglCombinerParameteriNV ) { // Release the Glow Regcom call list. qglDeleteLists( tr.glowPShader, 1 ); } else if ( qglGenProgramsARB ) { // Release the Glow Fragment Shader. qglDeleteProgramsARB( 1, &tr.glowPShader ); } } // Release the scene glow texture. qglDeleteTextures( 1, &tr.screenGlow ); // Release the scene texture. qglDeleteTextures( 1, &tr.sceneImage ); // Release the blur texture. qglDeleteTextures( 1, &tr.blurImage ); } // gamma correction if (tr.gammaPixelShader) { qglDeleteProgramsARB(1, &tr.gammaPixelShader); } if (tr.gammaVertexShader) { qglDeleteProgramsARB(1, &tr.gammaVertexShader); } if (tr.gammaLUTImage) { qglDeleteTextures(1, &tr.gammaLUTImage); } // -------- R_ShutdownFonts(); if ( tr.registered ) { R_SyncRenderThread(); R_ShutdownCommandBuffers(); if (destroyWindow) { R_DeleteTextures(); // only do this for vid_restart now, not during things like map load } } // shut down platform specific OpenGL stuff if ( destroyWindow ) { GLimp_Shutdown(); } #endif //!DEDICATED tr.registered = qfalse; #ifdef G2_COLLISION_ENABLED if (G2VertSpaceServer) { delete G2VertSpaceServer; G2VertSpaceServer = 0; } #endif }
/********* SP_DrawTexture *********/ void SP_DrawTexture(void* pixels, float width, float height, float vShift) { if (!pixels) { // Ug. We were not even able to load the error message texture. return; } // Create a texture from the buffered file GLuint texid; qglGenTextures(1, &texid); qglBindTexture(GL_TEXTURE_2D, texid); qglTexImage2D(GL_TEXTURE_2D, 0, GL_DDS1_EXT, width, height, 0, GL_DDS1_EXT, GL_UNSIGNED_BYTE, pixels); qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); // Reset every GL state we've got. Who knows what state // the renderer could be in when this function gets called. qglColor3f(1.f, 1.f, 1.f); qglViewport(0, 0, 640, 480); GLboolean alpha = qglIsEnabled(GL_ALPHA_TEST); qglDisable(GL_ALPHA_TEST); GLboolean blend = qglIsEnabled(GL_BLEND); qglDisable(GL_BLEND); GLboolean cull = qglIsEnabled(GL_CULL_FACE); qglDisable(GL_CULL_FACE); GLboolean depth = qglIsEnabled(GL_DEPTH_TEST); qglDisable(GL_DEPTH_TEST); GLboolean fog = qglIsEnabled(GL_FOG); qglDisable(GL_FOG); GLboolean lighting = qglIsEnabled(GL_LIGHTING); qglDisable(GL_LIGHTING); GLboolean offset = qglIsEnabled(GL_POLYGON_OFFSET_FILL); qglDisable(GL_POLYGON_OFFSET_FILL); GLboolean scissor = qglIsEnabled(GL_SCISSOR_TEST); qglDisable(GL_SCISSOR_TEST); GLboolean stencil = qglIsEnabled(GL_STENCIL_TEST); qglDisable(GL_STENCIL_TEST); GLboolean texture = qglIsEnabled(GL_TEXTURE_2D); qglEnable(GL_TEXTURE_2D); qglMatrixMode(GL_MODELVIEW); qglLoadIdentity(); qglMatrixMode(GL_PROJECTION); qglLoadIdentity(); qglOrtho(0, 640, 0, 480, 0, 1); qglMatrixMode(GL_TEXTURE0); qglLoadIdentity(); qglMatrixMode(GL_TEXTURE1); qglLoadIdentity(); qglActiveTextureARB(GL_TEXTURE0_ARB); qglClientActiveTextureARB(GL_TEXTURE0_ARB); memset(&tess, 0, sizeof(tess)); // Draw the error message qglBeginFrame(); if (!SP_LicenseDone) { // clear the screen if we haven't done the // license yet... qglClearColor(0, 0, 0, 1); qglClear(GL_COLOR_BUFFER_BIT); } float x1 = 320 - width / 2; float x2 = 320 + width / 2; float y1 = 240 - height / 2; float y2 = 240 + height / 2; y1 += vShift; y2 += vShift; qglBeginEXT (GL_TRIANGLE_STRIP, 4, 0, 0, 4, 0); qglTexCoord2f( 0, 0 ); qglVertex2f(x1, y1); qglTexCoord2f( 1 , 0 ); qglVertex2f(x2, y1); qglTexCoord2f( 0, 1 ); qglVertex2f(x1, y2); qglTexCoord2f( 1, 1 ); qglVertex2f(x2, y2); qglEnd(); qglEndFrame(); qglFlush(); // Restore (most) of the render states we reset if (alpha) qglEnable(GL_ALPHA_TEST); else qglDisable(GL_ALPHA_TEST); if (blend) qglEnable(GL_BLEND); else qglDisable(GL_BLEND); if (cull) qglEnable(GL_CULL_FACE); else qglDisable(GL_CULL_FACE); if (depth) qglEnable(GL_DEPTH_TEST); else qglDisable(GL_DEPTH_TEST); if (fog) qglEnable(GL_FOG); else qglDisable(GL_FOG); if (lighting) qglEnable(GL_LIGHTING); else qglDisable(GL_LIGHTING); if (offset) qglEnable(GL_POLYGON_OFFSET_FILL); else qglDisable(GL_POLYGON_OFFSET_FILL); if (scissor) qglEnable(GL_SCISSOR_TEST); else qglDisable(GL_SCISSOR_TEST); if (stencil) qglEnable(GL_STENCIL_TEST); else qglDisable(GL_STENCIL_TEST); if (texture) qglEnable(GL_TEXTURE_2D); else qglDisable(GL_TEXTURE_2D); // Kill the texture qglDeleteTextures(1, &texid); }