Skip to content

Commit

Permalink
Refactor|Client|GL: Use GL2 filter/wrap identifiers with unmanaged te…
Browse files Browse the repository at this point in the history
…xtures
  • Loading branch information
danij-deng committed Nov 9, 2013
1 parent e8d4e8c commit f343501
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 60 deletions.
8 changes: 4 additions & 4 deletions doomsday/client/include/gl/gl_main.h
Expand Up @@ -187,12 +187,12 @@ void GL_CallList(DGLuint list);

void GL_DeleteLists(DGLuint list, int range);

void GL_SetMaterialUI2(Material *mat, int wrapS, int wrapT);
void GL_SetMaterialUI2(Material *mat, de::gl::Wrapping wrapS, de::gl::Wrapping wrapT);
void GL_SetMaterialUI(Material *mat);

void GL_SetPSprite(Material *mat, int tclass, int tmap);

void GL_SetRawImage(lumpnum_t lumpNum, int wrapS, int wrapT);
void GL_SetRawImage(lumpnum_t lumpNum, de::gl::Wrapping wrapS, de::gl::Wrapping wrapT);

/**
* Bind this texture to the currently active texture unit.
Expand All @@ -203,8 +203,8 @@ void GL_SetRawImage(lumpnum_t lumpNum, int wrapS, int wrapT);
*/
void GL_BindTexture(de::Texture::Variant *tex);

void GL_BindTextureUnmanaged(DGLuint texname, int wrapS = GL_REPEAT, int wrapT = GL_REPEAT,
int magMode = GL_LINEAR);
void GL_BindTextureUnmanaged(GLuint texname, de::gl::Wrapping wrapS = de::gl::Repeat,
de::gl::Wrapping wrapT = de::gl::Repeat, de::gl::Filter = de::gl::Linear);

/**
* Bind the associated texture and apply the texture unit configuration to
Expand Down
9 changes: 5 additions & 4 deletions doomsday/client/src/gl/dgl_common.cpp
Expand Up @@ -722,13 +722,14 @@ void DGL_SetNoMaterial(void)
GL_SetNoTexture();
}

static int DGL_ToGLWrapCap(DGLint cap)
static gl::Wrapping DGL_ToGLWrapCap(DGLint cap)
{
switch(cap)
{
case DGL_CLAMP: return GL_CLAMP;
case DGL_CLAMP_TO_EDGE: return GL_CLAMP_TO_EDGE;
case DGL_REPEAT: return GL_REPEAT;
case DGL_CLAMP:
case DGL_CLAMP_TO_EDGE: return gl::ClampToEdge;

case DGL_REPEAT: return gl::Repeat;
default:
Con_Error("DGL_ToGLWrapCap: Unknown cap value %i.", (int)cap);
exit(1); // Unreachable.
Expand Down
74 changes: 38 additions & 36 deletions doomsday/client/src/gl/gl_main.cpp
Expand Up @@ -743,6 +743,27 @@ void GL_BlendMode(blendmode_t mode)
}
}

static GLenum glFilter(gl::Filter f)
{
switch(f)
{
case gl::Nearest: return GL_NEAREST;
case gl::Linear: return GL_LINEAR;
}
return GL_REPEAT;
}

static GLenum glWrap(gl::Wrapping w)
{
switch(w)
{
case gl::Repeat: return GL_REPEAT;
case gl::RepeatMirrored: return GL_MIRRORED_REPEAT;
case gl::ClampToEdge: return GL_CLAMP_TO_EDGE;
}
return GL_REPEAT;
}

int GL_NumMipmapLevels(int width, int height)
{
int numLevels = 0;
Expand Down Expand Up @@ -791,36 +812,39 @@ int GL_GetTexAnisoMul(int level)
return mul;
}

void GL_SetMaterialUI2(Material *mat, int wrapS, int wrapT)
void GL_SetMaterialUI2(Material *mat, gl::Wrapping wrapS, gl::Wrapping wrapT)
{
if(!mat) return; // @todo we need a "NULL material".

MaterialVariantSpec const &spec =
App_Materials().variantSpec(UiContext, 0, 1, 0, 0, wrapS, wrapT,
App_Materials().variantSpec(UiContext, 0, 1, 0, 0,
glWrap(wrapS), glWrap(wrapT),
0, 1, 0, false, false, false, false);
GL_BindTexture(&mat->prepare(spec).texture(MTU_PRIMARY));
}

void GL_SetMaterialUI(Material* mat)
void GL_SetMaterialUI(Material *mat)
{
GL_SetMaterialUI2(mat, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
GL_SetMaterialUI2(mat, gl::ClampToEdge, gl::ClampToEdge);
}

void GL_SetPSprite(Material *mat, int tClass, int tMap)
{
if(!mat) return; // @todo we need a "NULL material".

MaterialVariantSpec const &spec =
App_Materials().variantSpec(PSpriteContext, 0, 1, tClass, tMap, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
App_Materials().variantSpec(PSpriteContext, 0, 1, tClass, tMap,
GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
0, 1, 0, false, true, true, false);
GL_BindTexture(&mat->prepare(spec).texture(MTU_PRIMARY));
}

void GL_SetRawImage(lumpnum_t lumpNum, int wrapS, int wrapT)
void GL_SetRawImage(lumpnum_t lumpNum, gl::Wrapping wrapS, gl::Wrapping wrapT)
{
if(rawtex_t *rawTex = R_GetRawTex(lumpNum))
{
GL_BindTextureUnmanaged(GL_PrepareRawTexture(*rawTex), wrapS, wrapT, (filterUI ? GL_LINEAR : GL_NEAREST));
GL_BindTextureUnmanaged(GL_PrepareRawTexture(*rawTex), wrapS, wrapT,
(filterUI ? gl::Linear : gl::Nearest));
}
}

Expand Down Expand Up @@ -858,7 +882,8 @@ void GL_BindTexture(TextureVariant *vtexture)
}
}

void GL_BindTextureUnmanaged(DGLuint glName, int wrapS, int wrapT, int magMode)
void GL_BindTextureUnmanaged(GLuint glName, gl::Wrapping wrapS, gl::Wrapping wrapT,
gl::Filter filter)
{
if(BusyMode_InWorkerThread()) return;

Expand All @@ -874,36 +899,15 @@ void GL_BindTextureUnmanaged(DGLuint glName, int wrapS, int wrapT, 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);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, glWrap(wrapS));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, glWrap(wrapT));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, glFilter(filter));
if(GL_state.features.texFilterAniso)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, GL_GetTexAnisoMul(texAniso));
}
}

static GLenum glFilter(gl::Filter f)
{
switch(f)
{
case gl::Nearest: return GL_NEAREST;
case gl::Linear: return GL_LINEAR;
}
return GL_REPEAT;
}

static GLenum glWrap(gl::Wrapping w)
{
switch(w)
{
case gl::Repeat: return GL_REPEAT;
case gl::RepeatMirrored: return GL_MIRRORED_REPEAT;
case gl::ClampToEdge: return GL_CLAMP_TO_EDGE;
}
return GL_REPEAT;
}

void GL_Bind(GLTextureUnit const &glTU)
{
if(!glTU.hasTexture()) return;
Expand All @@ -920,10 +924,8 @@ void GL_Bind(GLTextureUnit const &glTU)
}
else
{
GL_BindTextureUnmanaged(DGLuint(glTU.unmanaged.glName),
glWrap(glTU.unmanaged.wrapS),
glWrap(glTU.unmanaged.wrapT),
glFilter(glTU.unmanaged.filter));
GL_BindTextureUnmanaged(glTU.unmanaged.glName, glTU.unmanaged.wrapS,
glTU.unmanaged.wrapT, glTU.unmanaged.filter);
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/drawlist.cpp
Expand Up @@ -101,7 +101,7 @@ DENG2_PIMPL(DrawList)
// Use the correct texture and color for the light.
glActiveTexture((conditions & SetLightEnv0)? GL_TEXTURE0 : GL_TEXTURE1);
GL_BindTextureUnmanaged(!renderTextures? 0 : modTexture,
GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
gl::ClampToEdge, gl::ClampToEdge);

float modColorV[4] = { modColor.x, modColor.y, modColor.z, 0 };
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, modColorV);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/rend_fakeradio.cpp
Expand Up @@ -1426,7 +1426,7 @@ void Rend_DrawShadowOffsetVerts()
glDisable(GL_DEPTH_TEST);

GL_BindTextureUnmanaged(GL_PrepareLSTexture(LST_DYNAMIC),
GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
gl::ClampToEdge, gl::ClampToEdge);
glEnable(GL_TEXTURE_2D);

/// @todo fixme: Should use the visual plane heights of sector clusters.
Expand Down
10 changes: 5 additions & 5 deletions doomsday/client/src/render/rend_font.cpp
Expand Up @@ -550,8 +550,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), GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
filterUI? GL_LINEAR : GL_NEAREST);
GL_BindTextureUnmanaged(BitmapFont_GLTextureName(font), gl::ClampToEdge,
gl::ClampToEdge, filterUI? gl::Linear : gl::Nearest);

glMatrixMode(GL_TEXTURE);
glPushMatrix();
Expand Down Expand Up @@ -740,8 +740,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), GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
filterUI? GL_LINEAR : GL_NEAREST);
GL_BindTextureUnmanaged(BitmapFont_GLTextureName(font), gl::ClampToEdge,
gl::ClampToEdge, filterUI? gl::Linear : gl::Nearest);

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

GL_BindTextureUnmanaged(GL_PrepareLSTexture(LST_DYNAMIC),
GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
gl::ClampToEdge, gl::ClampToEdge);

GLState::top().setBlendFunc(bright? gl::SrcAlpha : gl::Zero,
bright? gl::One : gl::OneMinusSrcAlpha)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/rend_halo.cpp
Expand Up @@ -302,7 +302,7 @@ bool H_RenderHalo(Vector3d const &origin, float size, DGLuint tex,
pos += mirror * fl->offset;
}

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

float const radX = radius * fl->size;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/rend_particle.cpp
Expand Up @@ -563,7 +563,7 @@ static void renderParticles(int rtype, boolean withBlend)
glDepthMask(GL_FALSE);
glDisable(GL_CULL_FACE);

GL_BindTextureUnmanaged(tex, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
GL_BindTextureUnmanaged(tex, gl::ClampToEdge, gl::ClampToEdge);
glEnable(GL_TEXTURE_2D);

glDepthFunc(GL_LEQUAL);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/sprite.cpp
Expand Up @@ -473,7 +473,7 @@ void Rend_RenderMaskedWall(rendmaskedwallparams_t const *p)
glActiveTexture(IS_MUL ? GL_TEXTURE0 : GL_TEXTURE1);
/// @todo modTex may be the name of a "managed" texture.
GL_BindTextureUnmanaged(renderTextures ? p->modTex : 0,
GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
gl::ClampToEdge, gl::ClampToEdge);

glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, p->modColor);

Expand Down
5 changes: 4 additions & 1 deletion doomsday/client/src/render/vignette.cpp
Expand Up @@ -26,6 +26,8 @@

#include "render/vignette.h"

using namespace de;

static byte vignetteEnabled = true;
static float vignetteDarkness = 1.0f;
static float vignetteWidth = 1.0f;
Expand Down Expand Up @@ -73,7 +75,8 @@ void Vignette_Render(const RectRaw* viewRect, float fov)
alpha *= fov/100.f;
}

GL_BindTextureUnmanaged(GL_PrepareLSTexture(LST_CAMERA_VIGNETTE), GL_REPEAT, GL_CLAMP_TO_EDGE);
GL_BindTextureUnmanaged(GL_PrepareLSTexture(LST_CAMERA_VIGNETTE), gl::Repeat,
gl::ClampToEdge);
glEnable(GL_TEXTURE_2D);

glBegin(GL_TRIANGLE_STRIP);
Expand Down
4 changes: 3 additions & 1 deletion doomsday/client/src/ui/busyvisual.cpp
Expand Up @@ -113,6 +113,8 @@ void BusyVisual_Render(void)
*/
#include "de_misc.h"

using namespace de;

#define DOOMWIPESINE_NUMSAMPLES 320

static void seedDoomWipeSine(void);
Expand Down Expand Up @@ -226,7 +228,7 @@ void Con_DrawTransition(void)

GLuint const texScreenshot = ClientWindow::main().busy().transitionScreenshot()->glName();

GL_BindTextureUnmanaged(texScreenshot, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
GL_BindTextureUnmanaged(texScreenshot, gl::ClampToEdge, gl::ClampToEdge);
glEnable(GL_TEXTURE_2D);

switch(transition.style)
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/ui/ui2_main.cpp
Expand Up @@ -1007,8 +1007,8 @@ 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, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
(filterUI ? GL_LINEAR : GL_NEAREST));
GL_BindTextureUnmanaged(glName, gl::ClampToEdge, gl::ClampToEdge,
(filterUI ? gl::Linear : gl::Nearest));
if(glName)
{
glEnable(GL_TEXTURE_2D);
Expand All @@ -1021,8 +1021,8 @@ 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, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
(filterUI ? GL_LINEAR : GL_NEAREST));
GL_BindTextureUnmanaged(f->texRef.tex, gl::ClampToEdge, gl::ClampToEdge,
(filterUI ? gl::Linear : gl::Nearest));
if(f->texRef.tex)
{
glEnable(GL_TEXTURE_2D);
Expand Down

0 comments on commit f343501

Please sign in to comment.