Skip to content

Commit

Permalink
Renderer: Render lists module is now aware of "managed" textures
Browse files Browse the repository at this point in the history
The interface mechanics are little clunky due to the texture unit map
needing to support unmanaged textures also. Once unmanaged textures
are refactored away, the lists will no longer contain references to
GL textures; meaning the hashes and lists will not need to be cleared
following a texture reset.

This commit fixes the issue of the GL magnification filter for "world"
class textures not being updated when this option is changed.
  • Loading branch information
danij-deng committed Jan 27, 2012
1 parent 90b5975 commit e639076
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 144 deletions.
30 changes: 24 additions & 6 deletions doomsday/engine/portable/include/r_data.h
Expand Up @@ -54,23 +54,39 @@ struct font_s;
#define DTLF_PWAD 0x2 // Can use if from PWAD.
#define DTLF_EXTERNAL 0x4 // Can use if from external resource.

/**
* @defgroup textureUnitFlags Texture Unit Flags
*/
///{
#define TUF_TEXTURE_IS_MANAGED 0x1 ///< A managed texture is bound to this unit.
///}

typedef struct rtexmapunit_texture_s {
union {
struct unmanaged {
DGLuint glName; ///< Texture used on this layer (if any).
int magMode; ///< GL texture magnification filter.
};
struct texturevariant_s* variant;
};
/// @ref textureUnitFlags
int flags;
} rtexmapunit_texture_t;

/**
* Texture unit state. POD.
*
* A simple Record data structure for storing properties used for
* configuring a GL texture unit during render.
*/
typedef struct rtexmapuint_s {
/// Texture used on this layer (if any).
DGLuint tex;

/// GL texture magnification filter.
int magMode;
/// Info about the bound texture for this unit.
rtexmapunit_texture_t texture;

/// Currently used only with reflection.
blendmode_t blendMode;

/// Opacity of this layer [0...1].
/// Opacity of this layer [0..1].
float opacity;

/// Texture-space scale multiplier.
Expand All @@ -83,6 +99,8 @@ typedef struct rtexmapuint_s {
/// Manipulators, for convenience.
void Rtu_Init(rtexmapunit_t* rtu);

boolean Rtu_HasTexture(const rtexmapunit_t* rtu);

/// Change the scale property.
void Rtu_SetScale(rtexmapunit_t* rtu, float s, float t);
void Rtu_SetScalev(rtexmapunit_t* rtu, float const st[2]);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/rend_list.h
Expand Up @@ -131,7 +131,7 @@ void RL_Rtu_TranslateOffset(uint idx, float s, float t);
void RL_Rtu_TranslateOffsetv(uint idx, float const st[2]);

/// Change the texture assigned to the identified @idx texture unit.
void RL_Rtu_SetTexture(uint idx, DGLuint glName);
void RL_Rtu_SetTextureUnmanaged(uint idx, DGLuint glName);

/**
* @param primType Type of primitive being written.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/gl_texmanager.c
Expand Up @@ -1235,7 +1235,7 @@ void GL_PrintTextureVariantSpecification(const texturevariantspecification_t* ba
" minFilter:(%s|%s) magFilter:(%s|%s) anisoFilter:%i",
textureUsageContextNames[tc-TEXTUREVARIANTUSAGECONTEXT_FIRST + 1],
(spec->flags & ~TSF_INTERNAL_MASK), spec->border,
filterModeNames[2 + MINMAX_OF(-1, spec->minFilter, 0)],
filterModeNames[3 + MINMAX_OF(-1, spec->minFilter, 0)],
glFilterNames[glMinFilterNameIdx],
filterModeNames[3 + MINMAX_OF(-3, spec->magFilter, 0)],
glFilterNames[glMagFilterNameIdx],
Expand Down
12 changes: 5 additions & 7 deletions doomsday/engine/portable/src/materials.c
Expand Up @@ -1134,17 +1134,17 @@ static void updateMaterialTextureLinks(materialbind_t* mb)
}

static void setTexUnit(materialsnapshot_t* ms, byte unit, TextureVariant* texture,
blendmode_t blendMode, int magMode, float sScale, float tScale, float sOffset,
blendmode_t blendMode, float sScale, float tScale, float sOffset,
float tOffset, float opacity)
{
rtexmapunit_t* tu;
assert(ms && unit < NUM_MATERIAL_TEXTURE_UNITS);

ms->textures[unit] = texture;
tu = &ms->units[unit];
tu->tex = (texture? TextureVariant_GLName(texture) : 0);
tu->texture.variant = texture;
tu->texture.flags = TUF_TEXTURE_IS_MANAGED;
tu->blendMode = blendMode;
tu->magMode = magMode;
V2_Set(tu->scale, sScale, tScale);
V2_Set(tu->offset, sOffset, tOffset);
tu->opacity = MINMAX_OF(0, opacity, 1);
Expand Down Expand Up @@ -1266,7 +1266,6 @@ const materialsnapshot_t* updateMaterialSnapshot(materialvariant_t* variant,
const float tScale = 1.f / snapshot->size.height;

setTexUnit(snapshot, MTU_PRIMARY, tex, BM_NORMAL,
snapshot->units[MTU_PRIMARY].magMode,
sScale, tScale, MaterialVariant_Layer(variant, 0)->texOrigin[0],
MaterialVariant_Layer(variant, 0)->texOrigin[1], 1);
}
Expand All @@ -1291,7 +1290,7 @@ const materialsnapshot_t* updateMaterialSnapshot(materialvariant_t* variant,
scale *= detailScale;

setTexUnit(snapshot, MTU_DETAIL, tex, BM_NORMAL,
texMagMode?GL_LINEAR:GL_NEAREST, 1.f / width * scale, 1.f / height * scale, 0, 0, 1);
1.f / width * scale, 1.f / height * scale, 0, 0, 1);
}

// Setup the shiny texture units?
Expand All @@ -1301,15 +1300,14 @@ const materialsnapshot_t* updateMaterialSnapshot(materialvariant_t* variant,
const blendmode_t blendmode = Material_ShinyBlendmode(mat);
const float strength = Material_ShinyStrength(mat);

setTexUnit(snapshot, MTU_REFLECTION, tex, blendmode, GL_LINEAR, 1, 1, 0, 0, strength);
setTexUnit(snapshot, MTU_REFLECTION, tex, blendmode, 1, 1, 0, 0, strength);
}

if(texUnits[MTU_REFLECTION_MASK].tex)
{
TextureVariant* tex = texUnits[MTU_REFLECTION_MASK].tex;

setTexUnit(snapshot, MTU_REFLECTION_MASK, tex, BM_NORMAL,
snapshot->units[MTU_PRIMARY].magMode,
1.f / (snapshot->size.width * Texture_Width(TextureVariant_GeneralCase(tex))),
1.f / (snapshot->size.height * Texture_Height(TextureVariant_GeneralCase(tex))),
snapshot->units[MTU_PRIMARY].offset[0], snapshot->units[MTU_PRIMARY].offset[1], 1);
Expand Down
28 changes: 17 additions & 11 deletions doomsday/engine/portable/src/r_data.c
Expand Up @@ -44,6 +44,7 @@
#include "colorpalette.h"
#include "texture.h"
#include "materialvariant.h"
#include "texturevariant.h"
#include "font.h"

// MACROS ------------------------------------------------------------------
Expand Down Expand Up @@ -752,10 +753,9 @@ rtexcoord_t* R_AllocRendTexCoords(uint num)
*/
void R_FreeRendVertices(rvertex_t* rvertices)
{
uint i;
uint i;

if(!rvertices)
return;
if(!rvertices) return;

for(i = 0; i < numrendpolys; ++i)
{
Expand All @@ -778,10 +778,9 @@ void R_FreeRendVertices(rvertex_t* rvertices)
*/
void R_FreeRendColors(ColorRawf* rcolors)
{
uint i;
uint i;

if(!rcolors)
return;
if(!rcolors) return;

for(i = 0; i < numrendpolys; ++i)
{
Expand All @@ -804,10 +803,9 @@ void R_FreeRendColors(ColorRawf* rcolors)
*/
void R_FreeRendTexCoords(rtexcoord_t* rtexcoords)
{
uint i;
uint i;

if(!rtexcoords)
return;
if(!rtexcoords) return;

for(i = 0; i < numrendpolys; ++i)
{
Expand All @@ -825,14 +823,22 @@ void R_FreeRendTexCoords(rtexcoord_t* rtexcoords)
void Rtu_Init(rtexmapunit_t* rtu)
{
assert(rtu);
rtu->tex = 0;
rtu->magMode = GL_LINEAR;
rtu->texture.glName = 0;
rtu->texture.magMode = GL_LINEAR;
rtu->texture.flags = 0;
rtu->blendMode = BM_NORMAL;
rtu->opacity = 1;
rtu->scale[0] = rtu->scale[1] = 1;
rtu->offset[0] = rtu->offset[1] = 0;
}

boolean Rtu_HasTexture(const rtexmapunit_t* rtu)
{
if(rtu->texture.flags & TUF_TEXTURE_IS_MANAGED)
return TextureVariant_GLName(rtu->texture.variant) != 0;
return rtu->texture.glName != 0;
}

void Rtu_SetScale(rtexmapunit_t* rtu, float s, float t)
{
assert(rtu);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/rend_dynlight.c
Expand Up @@ -112,7 +112,7 @@ int RIT_RenderLightProjectionIterator(const dynlight_t* dyn, void* paramaters)
}

RL_LoadDefaultRtus();
RL_Rtu_SetTexture(RTU_PRIMARY, dyn->texture);
RL_Rtu_SetTextureUnmanaged(RTU_PRIMARY, dyn->texture);

if(p->isWall && p->divs)
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/rend_fakeradio.c
Expand Up @@ -991,7 +991,7 @@ static void renderShadowSeg(const rvertex_t* origVertices, const walldiv_t* divs
{
// Write multiple polys depending on rend params.
RL_LoadDefaultRtus();
RL_Rtu_SetTexture(RTU_PRIMARY, GL_PrepareLSTexture(p->texture));
RL_Rtu_SetTextureUnmanaged(RTU_PRIMARY, GL_PrepareLSTexture(p->texture));

if(divs)
{
Expand Down

0 comments on commit e639076

Please sign in to comment.