Skip to content

Commit

Permalink
Fixed loading of detail textures. The correct level of gray mipmap co…
Browse files Browse the repository at this point in the history
…ntrast is saved as flags in the texturecontent_t, to be applied when the texture is really uploaded.
  • Loading branch information
skyjake committed Aug 6, 2007
1 parent 2e9caaf commit 8d770da
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
4 changes: 3 additions & 1 deletion doomsday/engine/portable/include/gl_defer.h
Expand Up @@ -51,13 +51,15 @@ typedef struct texturecontent_s {
// Flags for texture content.
#define TXCF_NO_COMPRESSION 0x1
#define TXCF_MIPMAP 0x2
#define TXCF_GET_GRAY_MIPMAP 0x4
#define TXCF_GRAY_MIPMAP 0x4
#define TXCF_EASY_UPLOAD 0x8
#define TXCF_UPLOAD_ARG_ALPHACHANNEL 0x10
#define TXCF_UPLOAD_ARG_RGBDATA 0x20
#define TXCF_UPLOAD_ARG_NOSTRETCH 0x40
#define TXCF_UPLOAD_ARG_NOSMARTFILTER 0x80
#define TXCF_NEVER_DEFER 0x100
#define TXCF_GRAY_MIPMAP_LEVEL_SHIFT 24
#define TXCF_GRAY_MIPMAP_LEVEL_MASK 0xff000000

void GL_InitDeferred(void);
void GL_ShutdownDeferred(void);
Expand Down
3 changes: 2 additions & 1 deletion doomsday/engine/portable/include/gl_texmanager.h
Expand Up @@ -141,7 +141,8 @@ void GL_DestroyImage(image_t *img);
byte *GL_LoadTexture(image_t *img, char *name);
DGLuint GL_LoadGraphics(const char *name, gfxmode_t mode);
DGLuint GL_LoadGraphics2(resourceclass_t resClass, const char *name,
gfxmode_t mode, int useMipmap, boolean clamped);
gfxmode_t mode, int useMipmap, boolean clamped,
int otherFlags);
DGLuint GL_LoadGraphics3(const char *name, gfxmode_t mode,
int minFilter, int magFilter, int anisoFilter,
int wrapS, int wrapT, int otherFlags);
Expand Down
6 changes: 3 additions & 3 deletions doomsday/engine/portable/src/gl_defer.c
Expand Up @@ -282,10 +282,10 @@ DGLuint GL_NewTexture(texturecontent_t *content)
content->bufferSize = content->width * content->height * bytesPerPixel;
}

if(content->flags & TXCF_GET_GRAY_MIPMAP)
if(content->flags & TXCF_GRAY_MIPMAP)
{
// Use the current level of gray mipmap.
content->grayMipmap = gl.GetInteger(DGL_GRAY_MIPMAP);
content->grayMipmap = ((content->flags & TXCF_GRAY_MIPMAP_LEVEL_MASK)
>> TXCF_GRAY_MIPMAP_LEVEL_SHIFT);
}

content->name = GL_GetReservedName();
Expand Down
28 changes: 17 additions & 11 deletions doomsday/engine/portable/src/gl_texmanager.c
Expand Up @@ -577,7 +577,7 @@ boolean GL_LoadReflectionMap(ded_reflection_t *loading_ref)
{
// Need to load the shiny texture.
ref->shiny_tex = GL_LoadGraphics2(RC_LIGHTMAP, ref->shiny_map.path,
LGM_NORMAL, DGL_FALSE, true);
LGM_NORMAL, DGL_FALSE, true, 0);
if(ref->shiny_tex == 0)
{
VERBOSE(Con_Printf("GL_LoadReflectionMap: %s not found!\n",
Expand All @@ -594,7 +594,7 @@ boolean GL_LoadReflectionMap(ded_reflection_t *loading_ref)
{
ref->mask_tex = GL_LoadGraphics2(RC_LIGHTMAP,
ref->mask_map.path,
LGM_NORMAL, DGL_TRUE, true);
LGM_NORMAL, DGL_TRUE, true, 0);
if(ref->mask_tex == 0)
{
VERBOSE(Con_Printf("GL_LoadReflectionMap: %s not found!\n",
Expand Down Expand Up @@ -1174,20 +1174,24 @@ DGLuint GL_LoadDetailTexture(int num, float contrast, const char *external)
// Detail textures are faded to gray depending on the contrast factor.
// The texture is also progressively faded towards gray when each
// mipmap level is loaded.
content.grayMipmap = contrast * 255;
gl.SetInteger(DGL_GRAY_MIPMAP, content.grayMipmap);
content.grayMipmap = MINMAX_OF(0, contrast * 255, 255);

// Try external first.
if(external != NULL)
{
inst->tex = GL_LoadGraphics2(RC_TEXTURE, external, LGM_NORMAL,
DGL_GRAY_MIPMAP, true);
//inst->tex = GL_LoadGraphics2(RC_TEXTURE, external, LGM_NORMAL,
// DGL_GRAY_MIPMAP, true, (content.grayMipmap << TXCF_GRAY_MIPMAP_LEVEL_SHIFT));
inst->tex = GL_LoadGraphics4(RC_TEXTURE, external, LGM_NORMAL,
DGL_GRAY_MIPMAP, DGL_LINEAR_MIPMAP_LINEAR,
DGL_LINEAR, -1, DGL_REPEAT, DGL_REPEAT,
(content.grayMipmap << TXCF_GRAY_MIPMAP_LEVEL_SHIFT));

if(inst->tex == 0)
{
VERBOSE(Con_Message("GL_LoadDetailTexture: "
"Failed to load: %s\n", external));
}
return inst->tex; // We're done.
}
else
{
Expand Down Expand Up @@ -1238,6 +1242,7 @@ DGLuint GL_LoadDetailTexture(int num, float contrast, const char *external)
content.magFilter = DGL_LINEAR;
content.anisoFilter = -1; // Best
content.wrap[0] = content.wrap[1] = DGL_REPEAT;
content.flags |= TXCF_GRAY_MIPMAP | (content.grayMipmap << TXCF_GRAY_MIPMAP_LEVEL_SHIFT);

inst->tex = GL_NewTexture(&content);

Expand Down Expand Up @@ -1431,7 +1436,7 @@ DGLuint GL_PrepareDDTexture(ddtextureid_t which, texinfo_t **texinfo)
{
ddTextures[which].tex =
GL_LoadGraphics2(RC_GRAPHICS, ddTexNames[which], LGM_NORMAL,
DGL_TRUE, false);
DGL_TRUE, false, 0);

if(!ddTextures[which].tex)
Con_Error("GL_PrepareDDTexture: \"%s\" not found!\n",
Expand Down Expand Up @@ -1655,16 +1660,17 @@ byte *GL_LoadHighResPatch(image_t *img, char *name)

DGLuint GL_LoadGraphics(const char *name, gfxmode_t mode)
{
return GL_LoadGraphics2(RC_GRAPHICS, name, mode, DGL_FALSE, true);
return GL_LoadGraphics2(RC_GRAPHICS, name, mode, DGL_FALSE, true, 0);
}

DGLuint GL_LoadGraphics2(resourceclass_t resClass, const char *name,
gfxmode_t mode, int useMipmap, boolean clamped)
gfxmode_t mode, int useMipmap, boolean clamped,
int otherFlags)
{
return GL_LoadGraphics4(resClass, name, mode, useMipmap,
DGL_LINEAR, glmode[texMagMode], 0 /*no anisotropy*/,
clamped? DGL_CLAMP : DGL_REPEAT,
clamped? DGL_CLAMP : DGL_REPEAT, 0);
clamped? DGL_CLAMP : DGL_REPEAT, otherFlags);
}

DGLuint GL_LoadGraphics3(const char *name, gfxmode_t mode,
Expand Down Expand Up @@ -1745,7 +1751,7 @@ DGLuint GL_LoadGraphics4(resourceclass_t resClass, const char *name,
image.pixelSize == 4 ? DGL_RGBA : DGL_LUMINANCE ),
image.width, image.height, image.pixels,
( otherFlags | (useMipmap? TXCF_MIPMAP : 0) |
(useMipmap == DGL_GRAY_MIPMAP? TXCF_GET_GRAY_MIPMAP : 0) |
(useMipmap == DGL_GRAY_MIPMAP? TXCF_GRAY_MIPMAP : 0) |
(image.width < 128 && image.height < 128? TXCF_NO_COMPRESSION : 0) ),
(useMipmap ? glmode[mipmapping] : DGL_LINEAR),
glmode[texMagMode], texAniso,
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/rend_particle.c
Expand Up @@ -129,7 +129,7 @@ void PG_InitTextures(void)

// Load the zeroth texture (the default: a blurred point).
ptctexname[0] =
GL_LoadGraphics2(RC_GRAPHICS, "Zeroth", LGM_WHITE_ALPHA, DGL_TRUE, true);
GL_LoadGraphics2(RC_GRAPHICS, "Zeroth", LGM_WHITE_ALPHA, DGL_TRUE, true, 0);

if(ptctexname[0] == 0)
{
Expand Down

0 comments on commit 8d770da

Please sign in to comment.