Skip to content

Commit

Permalink
Refactor: Added texture wrap args for GL_BindTextureUnmanaged()
Browse files Browse the repository at this point in the history
This function now mimics the behavior of GL_BindTexture() in that
the GL texture parameters are configured at texture bind time.

This means there should be virtually no need to manipulate the GL
texture parameters manually elsewhere (the GL texture manager being
the one exception).
  • Loading branch information
danij-deng committed Feb 28, 2013
1 parent fb39c10 commit 9c3e359
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 60 deletions.
35 changes: 18 additions & 17 deletions doomsday/client/include/gl/gl_main.h
Expand Up @@ -69,62 +69,62 @@ DENG_EXTERN_C int r_detail;
# define LIBDENG_ASSERT_GL_TEXTURE_ISBOUND(tex)
#endif

void GL_AssertContextActive(void);
void GL_AssertContextActive();

/// Register the console commands, variables, etc..., of this module.
void GL_Register(void);
void GL_Register();

/**
* One-time initialization of GL and the renderer. This is done very early
* on during engine startup and is supposed to be fast. All subsystems
* cannot yet be initialized, such as the texture management, so any rendering
* occuring before GL_Init() must be done with manually prepared textures.
*/
boolean GL_EarlyInit(void);
boolean GL_EarlyInit();

/**
* Finishes GL initialization. This can be called once the virtual file
* system has been fully loaded up, and the console variables have been
* read from the config file.
*/
void GL_Init(void);
void GL_Init();

/**
* Kills the graphics library for good.
*/
void GL_Shutdown(void);
void GL_Shutdown();

/**
* Returns @c true iff the graphics library is currently initialized.
*/
boolean GL_IsInited(void);
boolean GL_IsInited();

/**
* GL is reset back to the state it was right after initialization.
* Use GL_TotalRestore to bring back online.
*/
void GL_TotalReset(void);
void GL_TotalReset();

/**
* To be called after a GL_TotalReset to bring GL back online.
*/
void GL_TotalRestore(void);
void GL_TotalRestore();

/**
* Initializes the renderer to 2D state.
*/
void GL_Init2DState(void);
void GL_Init2DState();

void GL_SwitchTo3DState(boolean push_state, viewport_t const *port, viewdata_t const *viewData);

void GL_Restore2DState(int step, viewport_t const *port, viewdata_t const *viewData);

void GL_ProjectionMatrix(void);
void GL_ProjectionMatrix();

/**
* Swaps buffers / blits the back buffer to the front.
*/
void GL_DoUpdate(void);
void GL_DoUpdate();

/**
* Set the current GL blending mode.
Expand All @@ -134,14 +134,14 @@ void GL_BlendMode(blendmode_t mode);
/**
* Initializes the graphics library for refresh. Also called at update.
*/
void GL_InitRefresh(void);
void GL_InitRefresh();

/**
* To be called once at final shutdown.
*/
void GL_ShutdownRefresh(void);
void GL_ShutdownRefresh();

void GL_LowRes(void);
void GL_LowRes();

/**
* Configure the GL state for the specified texture modulation mode.
Expand Down Expand Up @@ -172,7 +172,7 @@ void GL_BlendOp(int op);

boolean GL_NewList(DGLuint list, int mode);

DGLuint GL_EndList(void);
DGLuint GL_EndList();

void GL_CallList(DGLuint list);

Expand All @@ -194,9 +194,10 @@ void GL_SetRawImage(lumpnum_t lumpNum, int wrapS, int wrapT);
*/
void GL_BindTexture(de::Texture::Variant *tex);

void GL_BindTextureUnmanaged(DGLuint texname, int magMode = GL_LINEAR);
void GL_BindTextureUnmanaged(DGLuint texname, int wrapS = GL_REPEAT, int wrapT = GL_REPEAT,
int magMode = GL_LINEAR);

void GL_SetNoTexture(void);
void GL_SetNoTexture();

/**
* Given a logical anisotropic filtering level return an appropriate multiplier
Expand Down
14 changes: 5 additions & 9 deletions doomsday/client/src/gl/gl_main.cpp
Expand Up @@ -775,15 +775,9 @@ void GL_SetPSprite(Material *mat, int tClass, int tMap)

void GL_SetRawImage(lumpnum_t lumpNum, int wrapS, int wrapT)
{
rawtex_t* rawTex = R_GetRawTex(lumpNum);
if(rawTex)
if(rawtex_t *rawTex = R_GetRawTex(lumpNum))
{
LIBDENG_ASSERT_IN_MAIN_THREAD();
LIBDENG_ASSERT_GL_CONTEXT_ACTIVE();

GL_BindTextureUnmanaged(GL_PrepareRawTexture(*rawTex), (filterUI ? GL_LINEAR : GL_NEAREST));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT);
GL_BindTextureUnmanaged(GL_PrepareRawTexture(*rawTex), wrapS, wrapT, (filterUI ? GL_LINEAR : GL_NEAREST));
}
}

Expand Down Expand Up @@ -820,7 +814,7 @@ void GL_BindTexture(Texture::Variant *tex)
}
}

void GL_BindTextureUnmanaged(DGLuint glName, int magMode)
void GL_BindTextureUnmanaged(DGLuint glName, int wrapS, int wrapT, int magMode)
{
if(BusyMode_InWorkerThread()) return;

Expand All @@ -836,6 +830,8 @@ void GL_BindTextureUnmanaged(DGLuint glName, int magMode)
glBindTexture(GL_TEXTURE_2D, glName);
Sys_GLCheckError();

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magMode);
if(GL_state.features.texFilterAniso)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, GL_GetTexAnisoMul(texAniso));
Expand Down
17 changes: 8 additions & 9 deletions doomsday/client/src/gl/gl_texmanager.cpp
Expand Up @@ -2057,15 +2057,14 @@ DGLuint GL_PrepareLSTexture(lightingtexid_t which)
static const struct TexDef {
char const *name;
gfxmode_t mode;
int wrapS, wrapT;
} texDefs[NUM_LIGHTING_TEXTURES] = {
/* LST_DYNAMIC */ { "dlight", LGM_WHITE_ALPHA, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE },
/* LST_GRADIENT */ { "wallglow", LGM_WHITE_ALPHA, GL_REPEAT, GL_CLAMP_TO_EDGE },
/* LST_RADIO_CO */ { "radioco", LGM_WHITE_ALPHA, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE },
/* LST_RADIO_CC */ { "radiocc", LGM_WHITE_ALPHA, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE },
/* LST_RADIO_OO */ { "radiooo", LGM_WHITE_ALPHA, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE },
/* LST_RADIO_OE */ { "radiooe", LGM_WHITE_ALPHA, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE },
/* LST_CAMERA_VIGNETTE */ { "vignette", LGM_NORMAL, GL_REPEAT, GL_CLAMP_TO_EDGE }
/* LST_DYNAMIC */ { "dlight", LGM_WHITE_ALPHA },
/* LST_GRADIENT */ { "wallglow", LGM_WHITE_ALPHA },
/* LST_RADIO_CO */ { "radioco", LGM_WHITE_ALPHA },
/* LST_RADIO_CC */ { "radiocc", LGM_WHITE_ALPHA },
/* LST_RADIO_OO */ { "radiooo", LGM_WHITE_ALPHA },
/* LST_RADIO_OE */ { "radiooe", LGM_WHITE_ALPHA },
/* LST_CAMERA_VIGNETTE */ { "vignette", LGM_NORMAL }
};
struct TexDef const &def = texDefs[which];

Expand All @@ -2083,7 +2082,7 @@ DGLuint GL_PrepareLSTexture(lightingtexid_t which)
image.pixelSize == 4 ? DGL_RGBA : DGL_LUMINANCE ),
image.size.width, image.size.height, image.pixels,
TXCF_NO_COMPRESSION, 0, GL_LINEAR, GL_LINEAR, -1 /*best anisotropy*/,
def.wrapS, def.wrapT);
( which == LST_GRADIENT? GL_REPEAT : GL_CLAMP_TO_EDGE ), GL_CLAMP_TO_EDGE);

lightingTextures[which] = glName;
}
Expand Down
3 changes: 2 additions & 1 deletion doomsday/client/src/render/rend_fakeradio.cpp
Expand Up @@ -1590,7 +1590,8 @@ void Rend_DrawShadowOffsetVerts()
glDepthMask(GL_FALSE);
glDisable(GL_DEPTH_TEST);

GL_BindTextureUnmanaged(GL_PrepareLSTexture(LST_DYNAMIC));
GL_BindTextureUnmanaged(GL_PrepareLSTexture(LST_DYNAMIC),
GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
glEnable(GL_TEXTURE_2D);

for(uint i = 0; i < NUM_LINEDEFS; ++i)
Expand Down
9 changes: 6 additions & 3 deletions doomsday/client/src/render/rend_font.cpp
Expand Up @@ -548,7 +548,8 @@ static void textFragmentDrawer(const char* fragment, int x, int y, int alignFlag
}
if(Font_Type(font) == FT_BITMAP && 0 != BitmapFont_GLTextureName(font))
{
GL_BindTextureUnmanaged(BitmapFont_GLTextureName(font), filterUI? GL_LINEAR : GL_NEAREST);
GL_BindTextureUnmanaged(BitmapFont_GLTextureName(font), GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
filterUI? GL_LINEAR : GL_NEAREST);

glMatrixMode(GL_TEXTURE);
glPushMatrix();
Expand Down Expand Up @@ -737,7 +738,8 @@ static void drawChar(unsigned char ch, int posX, int posY, font_t* font,
case FT_BITMAP:
/// @todo Filtering should be determined at a higher level.
/// @todo We should not need to re-bind this texture here.
GL_BindTextureUnmanaged(BitmapFont_GLTextureName(font), filterUI? GL_LINEAR : GL_NEAREST);
GL_BindTextureUnmanaged(BitmapFont_GLTextureName(font), GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
filterUI? GL_LINEAR : GL_NEAREST);

std::memcpy(&geometry, BitmapFont_CharGeometry(font, ch), sizeof(geometry));
BitmapFont_CharCoords(font, ch, coords);
Expand Down Expand Up @@ -801,7 +803,8 @@ static void drawFlash(const Point2Raw* origin, const Size2Raw* size, int bright)
w = (int) fw;
h = (int) fh;

GL_BindTextureUnmanaged(GL_PrepareLSTexture(LST_DYNAMIC));
GL_BindTextureUnmanaged(GL_PrepareLSTexture(LST_DYNAMIC),
GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);

if(bright)
GL_BlendMode(BM_ADD);
Expand Down
8 changes: 1 addition & 7 deletions doomsday/client/src/render/rend_halo.cpp
Expand Up @@ -345,15 +345,9 @@ boolean H_RenderHalo(coord_t x, coord_t y, coord_t z, float size, DGLuint tex,
haloPos[k] += mirror[k] * fl->offset;
}

GL_BindTextureUnmanaged(renderTextures? tex : 0);
GL_BindTextureUnmanaged(renderTextures? tex : 0, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
glEnable(GL_TEXTURE_2D);

// Don't wrap the texture. Evidently some drivers can't just
// take a hint... (or then something's changing the wrapping
// mode inadvertently)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glColor4fv(rgba);

glBegin(GL_QUADS);
Expand Down
6 changes: 2 additions & 4 deletions doomsday/client/src/render/rend_particle.cpp
Expand Up @@ -505,15 +505,13 @@ static void renderParticles(int rtype, boolean withBlend)
LIBDENG_ASSERT_IN_MAIN_THREAD();
LIBDENG_ASSERT_GL_CONTEXT_ACTIVE();

{
const viewdata_t* viewData = R_ViewData(viewPlayer - ddPlayers);
viewdata_t const *viewData = R_ViewData(viewPlayer - ddPlayers);
// viewSideVec points to the left.
for(c = 0; c < 3; ++c)
{
leftoff[c] = viewData->upVec[c] + viewData->sideVec[c];
rightoff[c] = viewData->upVec[c] - viewData->sideVec[c];
}
}

// Should we use a texture?
if(rtype == PTC_POINT ||
Expand All @@ -538,7 +536,7 @@ static void renderParticles(int rtype, boolean withBlend)
glDepthMask(GL_FALSE);
glDisable(GL_CULL_FACE);

GL_BindTextureUnmanaged(tex);
GL_BindTextureUnmanaged(tex, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
glEnable(GL_TEXTURE_2D);

glDepthFunc(GL_LEQUAL);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/vignette.cpp
Expand Up @@ -73,7 +73,7 @@ void Vignette_Render(const RectRaw* viewRect, float fov)
alpha *= fov/100.f;
}

GL_BindTextureUnmanaged(GL_PrepareLSTexture(LST_CAMERA_VIGNETTE));
GL_BindTextureUnmanaged(GL_PrepareLSTexture(LST_CAMERA_VIGNETTE), GL_REPEAT, GL_CLAMP_TO_EDGE);
glEnable(GL_TEXTURE_2D);

glBegin(GL_TRIANGLE_STRIP);
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/ui/busyvisual.cpp
Expand Up @@ -241,7 +241,7 @@ static void drawPositionIndicator(float x, float y, float radius, float pos,
// Draw the frame.
glEnable(GL_TEXTURE_2D);

GL_BindTextureUnmanaged(texLoading[0]);
GL_BindTextureUnmanaged(texLoading[0], GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
LIBDENG_ASSERT_GL_TEXTURE_ISBOUND(texLoading[0]);
glColor4fv(col);
GL_DrawRectf2(x - radius, y - radius, radius*2, radius*2);
Expand All @@ -257,7 +257,7 @@ static void drawPositionIndicator(float x, float y, float radius, float pos,
// Draw a fan.
glColor4f(col[0], col[1], col[2], .5f);
LIBDENG_ASSERT_GL_TEXTURE_ISBOUND(texLoading[0]);
GL_BindTextureUnmanaged(texLoading[1]);
GL_BindTextureUnmanaged(texLoading[1], GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
LIBDENG_ASSERT_GL_TEXTURE_ISBOUND(texLoading[1]);
glBegin(GL_TRIANGLE_FAN);
// Center.
Expand Down Expand Up @@ -586,7 +586,7 @@ void Con_DrawTransition(void)
glLoadIdentity();
glOrtho(0, SCREENWIDTH, SCREENHEIGHT, 0, -1, 1);

GL_BindTextureUnmanaged(texScreenshot);
GL_BindTextureUnmanaged(texScreenshot, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
glEnable(GL_TEXTURE_2D);

switch(transition.style)
Expand Down
10 changes: 4 additions & 6 deletions doomsday/client/src/ui/ui2_main.cpp
Expand Up @@ -997,12 +997,11 @@ static void drawPicFrame(fidata_pic_t *p, uint frame, float const _origin[3],
V3f_Set(dimensions, 320 /*rawTex->width*/, 200 /*rawTex->height*/, 0);
// Rotation occurs around the center of the screen.
V2f_Set(rotateCenter, 160, 100);
GL_BindTextureUnmanaged(glName, (filterUI ? GL_LINEAR : GL_NEAREST));
GL_BindTextureUnmanaged(glName, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
(filterUI ? GL_LINEAR : GL_NEAREST));
if(glName)
{
glEnable(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
textureEnabled = true;
}
}
Expand All @@ -1012,12 +1011,11 @@ static void drawPicFrame(fidata_pic_t *p, uint frame, float const _origin[3],
V3f_Set(offset, 0, 0, 0);
V3f_Set(dimensions, 1, 1, 0);
V2f_Set(rotateCenter, .5f, .5f);
GL_BindTextureUnmanaged(f->texRef.tex, (filterUI ? GL_LINEAR : GL_NEAREST));
GL_BindTextureUnmanaged(f->texRef.tex, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
(filterUI ? GL_LINEAR : GL_NEAREST));
if(f->texRef.tex)
{
glEnable(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
textureEnabled = true;
}
break;
Expand Down

0 comments on commit 9c3e359

Please sign in to comment.