Skip to content

Commit

Permalink
Refactor|Client|Map Renderer: Began dismantling/remodeling GLTextureUnit
Browse files Browse the repository at this point in the history
This component does not make sense in its current form.
  • Loading branch information
danij-deng committed Nov 7, 2013
1 parent e6f1c34 commit 8527700
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 94 deletions.
45 changes: 14 additions & 31 deletions doomsday/client/include/gl/gl_main.h
Expand Up @@ -69,19 +69,6 @@ DENG_EXTERN_C int r_detail;
# define LIBDENG_ASSERT_GL_TEXTURE_ISBOUND(tex)
#endif

/**
* Symbolic identifiers for (virtual) texture units.
*/
typedef enum {
RTU_PRIMARY = 0,
RTU_PRIMARY_DETAIL,
RTU_INTER,
RTU_INTER_DETAIL,
RTU_REFLECTION,
RTU_REFLECTION_MASK,
NUM_TEXMAP_UNITS
} rtexmapunitid_t;

/**
* GL Texture unit config.
*/
Expand Down Expand Up @@ -170,24 +157,6 @@ struct GLTextureUnit
DGLuint getTextureGLName() const {
return textureVariant? textureVariant->glName() : textureGLName;
}

/**
* Bind the associated texture and apply the texture unit configuration to
* the @em active GL texture unit. If no texture is associated then nothing
* will happen.
*
* @see bindTo()
*/
void bind() const;

/**
* Bind the associated texture and apply the texture unit configuration to
* the specified GL texture @a unit, which, is made active during this call.
* If no texture is associated then nothing will happen.
*
* @see bind()
*/
void bindTo(int unit) const;
};

void GL_AssertContextActive();
Expand Down Expand Up @@ -328,6 +297,20 @@ void GL_BindTexture(de::Texture::Variant *tex);
void GL_BindTextureUnmanaged(DGLuint texname, int wrapS = GL_REPEAT, int wrapT = GL_REPEAT,
int magMode = GL_LINEAR);

/**
* Bind the associated texture and apply the texture unit configuration to
* the @em active GL texture unit. If no texture is associated then nothing
* will happen.
*/
void GL_Bind(GLTextureUnit const &glTU);

/**
* Bind the associated texture and apply the texture unit configuration to
* the specified GL texture @a unit, which, is made active during this call.
* If no texture is associated then nothing will happen.
*/
void GL_BindTo(GLTextureUnit const &glTU, int unit);

void GL_SetNoTexture();

/**
Expand Down
20 changes: 16 additions & 4 deletions doomsday/client/include/resource/materialsnapshot.h
Expand Up @@ -17,8 +17,8 @@
* 02110-1301 USA</small>
*/

#ifndef DENG_RESOURCE_MATERIALSNAPSHOT_H
#define DENG_RESOURCE_MATERIALSNAPSHOT_H
#ifndef DENG_CLIENT_RESOURCE_MATERIALSNAPSHOT_H
#define DENG_CLIENT_RESOURCE_MATERIALSNAPSHOT_H

#ifndef __CLIENT__
# error "resource/materialsnapshot.h only exists in the Client"
Expand All @@ -29,7 +29,6 @@

#include "Material"
#include "Texture"
#include "render/rendpoly.h"

// Material texture unit idents:
enum {
Expand All @@ -42,6 +41,19 @@ enum {

struct GLTextureUnit;

/**
* Symbolic identifiers for (virtual) texture units.
*/
typedef enum {
RTU_PRIMARY = 0,
RTU_PRIMARY_DETAIL,
RTU_INTER,
RTU_INTER_DETAIL,
RTU_REFLECTION,
RTU_REFLECTION_MASK,
NUM_TEXMAP_UNITS
} rtexmapunitid_t;

namespace de {

/**
Expand Down Expand Up @@ -160,4 +172,4 @@ typedef MaterialSnapshot::Decoration MaterialSnapshotDecoration;

} // namespace de

#endif // DENG_RESOURCE_MATERIALSNAPSHOT_H
#endif // DENG_CLIENT_RESOURCE_MATERIALSNAPSHOT_H
64 changes: 33 additions & 31 deletions doomsday/client/src/gl/gl_main.cpp
Expand Up @@ -868,7 +868,40 @@ void GL_BindTextureUnmanaged(DGLuint glName, int wrapS, int wrapT, int magMode)
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));
}
}

void GL_Bind(GLTextureUnit const &glTU)
{
if(!glTU.hasTexture()) return;

if(!renderTextures)
{
GL_SetNoTexture();
return;
}

if(glTU.textureVariant)
{
GL_BindTexture(glTU.textureVariant);
}
else
{
GL_BindTextureUnmanaged(glTU.textureGLName, glTU.textureGLWrapS,
glTU.textureGLWrapT, glTU.textureGLMagMode);
}
}

void GL_BindTo(GLTextureUnit const &glTU, int unit)
{
if(!glTU.hasTexture()) return;

DENG_ASSERT_IN_MAIN_THREAD();
DENG_ASSERT_GL_CONTEXT_ACTIVE();
glActiveTexture(GL_TEXTURE0 + byte(unit));
GL_Bind(glTU);
}

void GL_SetNoTexture()
Expand Down Expand Up @@ -1180,37 +1213,6 @@ void GL_CalcLuminance(uint8_t const *buffer, int width, int height, int pixelSiz
*/
}

void GLTextureUnit::bind() const
{
if(!hasTexture()) return;

if(!renderTextures)
{
GL_SetNoTexture();
return;
}

if(textureVariant)
{
GL_BindTexture(textureVariant);
}
else
{
GL_BindTextureUnmanaged(textureGLName, textureGLWrapS,
textureGLWrapT, textureGLMagMode);
}
}

void GLTextureUnit::bindTo(int unit) const
{
if(!hasTexture()) return;

DENG_ASSERT_IN_MAIN_THREAD();
DENG_ASSERT_GL_CONTEXT_ACTIVE();
glActiveTexture(GL_TEXTURE0 + byte(unit));
bind();
}

D_CMD(SetRes)
{
DENG2_UNUSED3(src, argc, argv);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/drawlist.cpp
Expand Up @@ -20,7 +20,7 @@

#include "render/drawlist.h"

#include "DrawLists"
#include "gl/gl_main.h"
#include "render/rend_main.h"
#include "clientapp.h"
#include <de/concurrency.h>
Expand Down
50 changes: 23 additions & 27 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -2885,8 +2885,8 @@ static DrawConditions pushGLStateForList(DrawList const &list, DrawMode mode)
DENG2_ASSERT(numTexUnits >= 2);
GL_SelectTexUnits(2);

listSpec.unit(TU_PRIMARY).bindTo(0);
listSpec.unit(TU_INTER).bindTo(1);
GL_BindTo(listSpec.unit(TU_PRIMARY), 0);
GL_BindTo(listSpec.unit(TU_INTER), 1);
GL_ModulateTexture(2);

float color[4] = { 0, 0, 0, listSpec.unit(TU_INTER).opacity };
Expand All @@ -2901,7 +2901,7 @@ static DrawConditions pushGLStateForList(DrawList const &list, DrawMode mode)
{
// Normal modulation.
GL_SelectTexUnits(1);
listSpec.unit(TU_PRIMARY).bind();
GL_Bind(listSpec.unit(TU_PRIMARY));
GL_ModulateTexture(1);
}

Expand All @@ -2913,11 +2913,11 @@ static DrawConditions pushGLStateForList(DrawList const &list, DrawMode mode)

case DM_LIGHT_MOD_TEXTURE:
// Modulate sector light, dynamic light and regular texture.
listSpec.unit(TU_PRIMARY).bindTo(1);
GL_BindTo(listSpec.unit(TU_PRIMARY), 1);
return SetMatrixTexture1 | SetLightEnv0 | JustOneLight | NoBlend;

case DM_TEXTURE_PLUS_LIGHT:
listSpec.unit(TU_PRIMARY).bindTo(0);
GL_BindTo(listSpec.unit(TU_PRIMARY), 0);
return SetMatrixTexture0 | SetLightEnv1 | NoBlend;

case DM_FIRST_LIGHT:
Expand All @@ -2934,10 +2934,8 @@ static DrawConditions pushGLStateForList(DrawList const &list, DrawMode mode)

DENG2_ASSERT(numTexUnits >= 2);
GL_SelectTexUnits(2);

listSpec.unit(TU_PRIMARY).bindTo(0);
listSpec.unit(TU_INTER).bindTo(1);

GL_BindTo(listSpec.unit(TU_PRIMARY), 0);
GL_BindTo(listSpec.unit(TU_INTER), 1);
GL_ModulateTexture(2);

float color[4] = { 0, 0, 0, listSpec.unit(TU_INTER).opacity };
Expand All @@ -2958,7 +2956,7 @@ static DrawConditions pushGLStateForList(DrawList const &list, DrawMode mode)

case DM_LIGHTS:
// These lists only contain light geometries.
listSpec.unit(TU_PRIMARY).bind();
GL_Bind(listSpec.unit(TU_PRIMARY));
return 0;

case DM_BLENDED_MOD_TEXTURE:
Expand All @@ -2980,10 +2978,8 @@ static DrawConditions pushGLStateForList(DrawList const &list, DrawMode mode)
// which would modulate with primary color.
DENG2_ASSERT(numTexUnits >= 2);
GL_SelectTexUnits(2);

listSpec.unit(TU_PRIMARY).bindTo(0);
listSpec.unit(TU_INTER).bindTo(1);

GL_BindTo(listSpec.unit(TU_PRIMARY), 0);
GL_BindTo(listSpec.unit(TU_INTER), 1);
GL_ModulateTexture(3);

float color[4] = { 0, 0, 0, listSpec.unit(TU_INTER).opacity };
Expand All @@ -2993,7 +2989,7 @@ static DrawConditions pushGLStateForList(DrawList const &list, DrawMode mode)
}
// No modulation at all.
GL_SelectTexUnits(1);
listSpec.unit(TU_PRIMARY).bind();
GL_Bind(listSpec.unit(TU_PRIMARY));
GL_ModulateTexture(0);
if(mode == DM_MOD_TEXTURE_MANY_LIGHTS)
{
Expand All @@ -3012,23 +3008,23 @@ static DrawConditions pushGLStateForList(DrawList const &list, DrawMode mode)
{
GL_SelectTexUnits(2);
GL_ModulateTexture(9); // Tex+Detail, no color.
listSpec.unit(TU_PRIMARY).bindTo(0);
listSpec.unit(TU_PRIMARY_DETAIL).bindTo(1);
GL_BindTo(listSpec.unit(TU_PRIMARY), 0);
GL_BindTo(listSpec.unit(TU_PRIMARY_DETAIL), 1);
return SetMatrixTexture0 | SetMatrixDTexture1;
}
else
{
GL_SelectTexUnits(1);
GL_ModulateTexture(0);
listSpec.unit(TU_PRIMARY).bind();
GL_Bind(listSpec.unit(TU_PRIMARY));
return SetMatrixTexture0;
}
break;

case DM_ALL_DETAILS:
if(listSpec.unit(TU_PRIMARY_DETAIL).hasTexture())
{
listSpec.unit(TU_PRIMARY_DETAIL).bind();
GL_Bind(listSpec.unit(TU_PRIMARY_DETAIL));
return SetMatrixDTexture0;
}
break;
Expand All @@ -3044,16 +3040,16 @@ static DrawConditions pushGLStateForList(DrawList const &list, DrawMode mode)
{
GL_SelectTexUnits(2);
GL_ModulateTexture(8);
listSpec.unit(TU_PRIMARY).bindTo(0);
listSpec.unit(TU_PRIMARY_DETAIL).bindTo(1);
GL_BindTo(listSpec.unit(TU_PRIMARY), 0);
GL_BindTo(listSpec.unit(TU_PRIMARY_DETAIL), 1);
return SetMatrixTexture0 | SetMatrixDTexture1;
}
else
{
// Normal modulation.
GL_SelectTexUnits(1);
GL_ModulateTexture(1);
listSpec.unit(TU_PRIMARY).bind();
GL_Bind(listSpec.unit(TU_PRIMARY));
return SetMatrixTexture0;
}
break;
Expand All @@ -3071,8 +3067,8 @@ static DrawConditions pushGLStateForList(DrawList const &list, DrawMode mode)
break;
}

listSpec.unit(TU_PRIMARY_DETAIL).bindTo(0);
listSpec.unit(TU_INTER_DETAIL).bindTo(1);
GL_BindTo(listSpec.unit(TU_PRIMARY_DETAIL), 0);
GL_BindTo(listSpec.unit(TU_INTER_DETAIL), 1);

float color[4] = { 0, 0, 0, listSpec.unit(TU_INTER_DETAIL).opacity };
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);
Expand All @@ -3081,7 +3077,7 @@ static DrawConditions pushGLStateForList(DrawList const &list, DrawMode mode)
case DM_SHADOW:
if(listSpec.unit(TU_PRIMARY).hasTexture())
{
listSpec.unit(TU_PRIMARY).bind();
GL_Bind(listSpec.unit(TU_PRIMARY));
}
else
{
Expand All @@ -3106,7 +3102,7 @@ static DrawConditions pushGLStateForList(DrawList const &list, DrawMode mode)
{
GL_SelectTexUnits(2);
// The intertex holds the info for the mask texture.
listSpec.unit(TU_INTER).bindTo(1);
GL_BindTo(listSpec.unit(TU_INTER), 1);
float color[4] = { 0, 0, 0, 1 };
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);
}
Expand All @@ -3115,7 +3111,7 @@ static DrawConditions pushGLStateForList(DrawList const &list, DrawMode mode)

case DM_ALL_SHINY:
case DM_SHINY:
listSpec.unit(TU_PRIMARY).bindTo(0);
GL_BindTo(listSpec.unit(TU_PRIMARY), 0);
if(!listSpec.unit(TU_INTER).hasTexture())
{
GL_SelectTexUnits(1);
Expand Down

0 comments on commit 8527700

Please sign in to comment.