//--------------------------------------------------------------------------- int R_NumPatchWidth(int lump) { const rpatch_t *patch = R_CachePatchNum(lump); int width = patch->width; R_UnlockPatchNum(lump); return width; }
//--------------------------------------------------------------------------- int R_NumPatchHeight(int lump) { const rpatch_t *patch = R_CachePatchNum(lump); int height = patch->height; R_UnlockPatchNum(lump); return height; }
void R_SetSpriteByNum(patchnum_t *patchnum, int lump) { const rpatch_t *patch = R_CachePatchNum(lump); patchnum->width = patch->width; patchnum->height = patch->height; patchnum->leftoffset = patch->leftoffset; patchnum->topoffset = patch->topoffset; patchnum->lumpnum = lump; R_UnlockPatchNum(lump); }
GLTexture *gld_RegisterPatch(int lump, int cm) { const rpatch_t *patch; GLTexture *gltexture; gltexture=gld_AddNewGLPatchTexture(lump); if (!gltexture) return NULL; if (gltexture->textype==GLDT_UNREGISTERED) { patch=R_CachePatchNum(lump); if (!patch) return NULL; gltexture->textype=GLDT_BROKEN; gltexture->index=lump; gltexture->mipmap=false; gltexture->realtexwidth=patch->width; gltexture->realtexheight=patch->height; gltexture->leftoffset=patch->leftoffset; gltexture->topoffset=patch->topoffset; gltexture->tex_width=gld_GetTexDimension(gltexture->realtexwidth); gltexture->tex_height=gld_GetTexDimension(gltexture->realtexheight); gltexture->width=MIN(gltexture->realtexwidth, gltexture->tex_width); gltexture->height=MIN(gltexture->realtexheight, gltexture->tex_height); gltexture->buffer_width=gltexture->tex_width; gltexture->buffer_height=gltexture->tex_height; #ifdef USE_GLU_IMAGESCALE gltexture->width=MIN(gltexture->realtexwidth, gltexture->tex_width); gltexture->height=MIN(gltexture->realtexheight, gltexture->tex_height); gltexture->buffer_width=MAX(gltexture->realtexwidth, gltexture->tex_width); gltexture->buffer_height=MAX(gltexture->realtexheight, gltexture->tex_height); #endif gltexture->buffer_size=gltexture->buffer_width*gltexture->buffer_height*4; R_UnlockPatchNum(lump); if (gltexture->realtexwidth>gltexture->buffer_width) return gltexture; if (gltexture->realtexheight>gltexture->buffer_height) return gltexture; gltexture->textype=GLDT_PATCH; } return gltexture; }
void gld_BindPatch(GLTexture *gltexture, int cm) { const rpatch_t *patch; unsigned char *buffer; int w, h; if (!gltexture || gltexture->textype != GLDT_PATCH) { qglBindTexture(GL_TEXTURE_2D, 0); last_glTexID = NULL; return; } #ifdef HAVE_LIBSDL_IMAGE if (gld_LoadHiresTex(gltexture, cm)) { gld_SetTexClamp(gltexture, GLTEXTURE_CLAMPXY); last_glTexID = gltexture->texid_p; return; } #endif gld_GetTextureTexID(gltexture, cm); if (last_glTexID == gltexture->texid_p) { gld_SetTexClamp(gltexture, GLTEXTURE_CLAMPXY); return; } last_glTexID = gltexture->texid_p; if (*gltexture->texid_p != 0) { qglBindTexture(GL_TEXTURE_2D, *gltexture->texid_p); gld_SetTexClamp(gltexture, GLTEXTURE_CLAMPXY); return; } patch=R_CachePatchNum(gltexture->index); buffer=(unsigned char*)Z_Malloc(gltexture->buffer_size,PU_STATIC,0); if (gl_paletted_texture) memset(buffer,transparent_pal_index,gltexture->buffer_size); else memset(buffer,0,gltexture->buffer_size); gld_AddPatchToTexture(gltexture, buffer, patch, 0, 0, cm, gl_paletted_texture); // e6y // Post-process the texture data after the buffer has been created. // Smooth the edges of transparent fields in the texture. // // It is a workaround to set the color of all transparent pixels // that border on a non-transparent pixel to the color // of one bordering non-transparent pixel. // It is necessary for textures that are not power of two // to avoid the lines (boxes) around the elements that change // on the intermission screens in Doom1 (E2, E3) // if ((gltexture->flags & (GLTEXTURE_HASHOLES | GLTEXTURE_SPRITE)) == // (GLTEXTURE_HASHOLES | GLTEXTURE_SPRITE)) if ((gltexture->flags & GLTEXTURE_HASHOLES)) { SmoothEdges(buffer, gltexture->buffer_width, gltexture->buffer_height); } if (*gltexture->texid_p == 0) qglGenTextures(1, gltexture->texid_p); qglBindTexture(GL_TEXTURE_2D, *gltexture->texid_p); buffer = gld_HQResize(gltexture, buffer, gltexture->buffer_width, gltexture->buffer_height, &w, &h); gld_BuildTexture(gltexture, buffer, false, w, h); gld_SetTexClamp(gltexture, GLTEXTURE_CLAMPXY); R_UnlockPatchNum(gltexture->index); }
GLTexture *gld_RegisterPatch(int lump, int cm) { const rpatch_t *patch; GLTexture *gltexture; gltexture=gld_AddNewGLPatchTexture(lump); if (!gltexture) return NULL; if (gltexture->textype==GLDT_UNREGISTERED) { patch=R_CachePatchNum(lump); if (!patch) return NULL; gltexture->textype=GLDT_BROKEN; gltexture->index=lump; //e6y gltexture->flags = 0; if (lump >= firstspritelump && lump > (firstspritelump + numsprites)) { gltexture->flags |= GLTEXTURE_SPRITE; if (tex_filter[MIP_SPRITE].mipmap) gltexture->flags |= GLTEXTURE_MIPMAP; } else { if (tex_filter[MIP_PATCH].mipmap) gltexture->flags |= GLTEXTURE_MIPMAP; } //gltexture->wrap_mode = (patch->flags & PATCH_REPEAT ? GL_REPEAT : GLEXT_CLAMP_TO_EDGE); gltexture->realtexwidth=patch->width; gltexture->realtexheight=patch->height; gltexture->leftoffset=patch->leftoffset; gltexture->topoffset=patch->topoffset; gltexture->tex_width=gld_GetTexDimension(gltexture->realtexwidth); gltexture->tex_height=gld_GetTexDimension(gltexture->realtexheight); gltexture->width=MIN(gltexture->realtexwidth, gltexture->tex_width); gltexture->height=MIN(gltexture->realtexheight, gltexture->tex_height); gltexture->buffer_width=gltexture->tex_width; gltexture->buffer_height=gltexture->tex_height; #ifdef USE_GLU_IMAGESCALE gltexture->width=MIN(gltexture->realtexwidth, gltexture->tex_width); gltexture->height=MIN(gltexture->realtexheight, gltexture->tex_height); gltexture->buffer_width=MAX(gltexture->realtexwidth, gltexture->tex_width); gltexture->buffer_height=MAX(gltexture->realtexheight, gltexture->tex_height); #endif if (gltexture->flags & GLTEXTURE_MIPMAP) { gltexture->width=gltexture->tex_width; gltexture->height=gltexture->tex_height; gltexture->buffer_width=gltexture->realtexwidth; gltexture->buffer_height=gltexture->realtexheight; } //e6y: right/bottom UV coordinates for patch drawing gltexture->scalexfac=(float)gltexture->width/(float)gltexture->tex_width; gltexture->scaleyfac=(float)gltexture->height/(float)gltexture->tex_height; gltexture->buffer_size=gltexture->buffer_width*gltexture->buffer_height*4; R_UnlockPatchNum(lump); if (gltexture->realtexwidth>gltexture->buffer_width) return gltexture; if (gltexture->realtexheight>gltexture->buffer_height) return gltexture; gltexture->textype=GLDT_PATCH; } return gltexture; }
void gld_BindPatch(GLTexture *gltexture, int cm) { const rpatch_t *patch; int i; unsigned char *buffer; if ((gltexture==last_gltexture) && (cm==last_cm)) return; last_gltexture=gltexture; last_cm=cm; if (!gltexture) return; if (gltexture->textype!=GLDT_PATCH) { glBindTexture(GL_TEXTURE_2D, 0); last_gltexture = NULL; last_cm = -1; return; } if (gltexture->glTexID[cm]!=0) { glBindTexture(GL_TEXTURE_2D, gltexture->glTexID[cm]); glGetTexParameteriv(GL_TEXTURE_2D,GL_TEXTURE_RESIDENT,&i); #ifdef _DEBUG if (i!=GL_TRUE) lprintf(LO_INFO, "glGetTexParam: %i\n", i); #endif if (i==GL_TRUE) return; } patch=R_CachePatchNum(gltexture->index); buffer=(unsigned char*)Z_Malloc(gltexture->buffer_size,PU_STATIC,0); if (gl_paletted_texture) memset(buffer,transparent_pal_index,gltexture->buffer_size); else memset(buffer,0,gltexture->buffer_size); gld_AddPatchToTexture(gltexture, buffer, patch, 0, 0, cm, gl_paletted_texture); if (gltexture->glTexID[cm]==0) glGenTextures(1,&gltexture->glTexID[cm]); glBindTexture(GL_TEXTURE_2D, gltexture->glTexID[cm]); #ifdef USE_GLU_IMAGESCALE if ((gltexture->buffer_width>gltexture->tex_width) || (gltexture->buffer_height>gltexture->tex_height) ) { unsigned char *scaledbuffer; scaledbuffer=(unsigned char*)Z_Malloc(gltexture->tex_width*gltexture->tex_height*4,PU_STATIC,0); if (scaledbuffer) { gluScaleImage(GL_RGBA, gltexture->buffer_width, gltexture->buffer_height, GL_UNSIGNED_BYTE,buffer, gltexture->tex_width, gltexture->tex_height, GL_UNSIGNED_BYTE,scaledbuffer); Z_Free(buffer); buffer=scaledbuffer; glTexImage2D( GL_TEXTURE_2D, 0, gl_tex_format, gltexture->tex_width, gltexture->tex_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); } } else #endif /* USE_GLU_IMAGESCALE */ { if (gl_paletted_texture) { I_Error("Paletted textures not supported"); /* gld_SetTexturePalette(GL_TEXTURE_2D); glTexImage2D( GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, gltexture->buffer_width, gltexture->buffer_height, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, buffer); */ } else { glTexImage2D( GL_TEXTURE_2D, 0, gl_tex_format, gltexture->buffer_width, gltexture->buffer_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); } } // Vladimir i ->x glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_tex_filter); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_tex_filter); Z_Free(buffer); R_UnlockPatchNum(gltexture->index); }