Skip to content

Commit

Permalink
Client|Map Renderer: Continued remodeling draw list specification/dra…
Browse files Browse the repository at this point in the history
…w-state management

Explicitly specify per-primitive GL draw state change properties at
DrawList::write() time, rather than copying them from the "RTU map".
  • Loading branch information
danij-deng committed Nov 7, 2013
1 parent 8e58d70 commit bdd6a90
Show file tree
Hide file tree
Showing 11 changed files with 303 additions and 294 deletions.
123 changes: 47 additions & 76 deletions doomsday/client/include/gl/gl_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,96 +87,67 @@ typedef enum {
*/
struct GLTextureUnit
{
struct TextureState
{
de::TextureVariant *variant;

/// Properties used only with @em unmanged GL textures.
DGLuint glName;
int glMagMode;
int glWrapS;
int glWrapT;

TextureState()
: variant(0),
glName(0),
glMagMode(GL_LINEAR),
glWrapS(GL_REPEAT),
glWrapT(GL_REPEAT)
{}

TextureState(TextureState const &other)
: variant(other.variant),
glName(other.glName),
glMagMode(other.glMagMode),
glWrapS(other.glWrapS),
glWrapT(other.glWrapT)
{}

TextureState &operator = (TextureState const &other) {
variant = other.variant;
glName = other.glName;
glMagMode = other.glMagMode;
glWrapS = other.glWrapS;
glWrapT = other.glWrapT;
return *this;
}
de::TextureVariant *textureVariant;

bool operator == (TextureState const &other) const {
if(variant)
{
if(variant != other.variant) return false;
}
else
{
if(glName != other.glName) return false;
if(glMagMode != other.glMagMode) return false;
if(glWrapS != other.glWrapS) return false;
if(glWrapT != other.glWrapT) return false;
}
return true;
}
bool operator != (TextureState const &other) const {
return !(*this == other);
}

bool hasTexture() const {
return (variant && variant->glName() != 0) || glName != 0;
}

DGLuint textureGLName() const {
return variant? variant->glName() : glName;
}
};
TextureState texture; ///< Info about the bound texture for this unit.
/// Properties used only with @em unmanged GL textures.
DGLuint textureGLName;
int textureGLMagMode;
int textureGLWrapS;
int textureGLWrapT;

blendmode_t blendMode; ///< Currently used only with reflection.
float opacity; ///< Opacity of this layer [0..1].

de::Vector2f scale; ///< Texture-space scale multiplier.
de::Vector2f offset; ///< Texture-space origin translation (unscaled).

GLTextureUnit() : blendMode(BM_NORMAL), opacity(1), scale(1, 1)
GLTextureUnit()
: textureVariant(0)
, textureGLName(0)
, textureGLMagMode(GL_LINEAR)
, textureGLWrapS(GL_REPEAT)
, textureGLWrapT(GL_REPEAT)
, blendMode(BM_NORMAL)
, opacity(1)
, scale(1, 1)
{}
GLTextureUnit(GLTextureUnit const &other)
: texture(other.texture),
blendMode(other.blendMode),
opacity(other.opacity),
scale(other.scale),
offset(other.offset)
: textureVariant(other.textureVariant)
, textureGLName(other.textureGLName)
, textureGLMagMode(other.textureGLMagMode)
, textureGLWrapS(other.textureGLWrapS)
, textureGLWrapT(other.textureGLWrapT)
, blendMode(other.blendMode)
, opacity(other.opacity)
, scale(other.scale)
, offset(other.offset)
{}

GLTextureUnit &operator = (GLTextureUnit const &other) {
texture = other.texture;
blendMode = other.blendMode;
opacity = other.opacity;
scale = other.scale;
offset = other.offset;
textureVariant = other.textureVariant;
textureGLName = other.textureGLName;
textureGLMagMode = other.textureGLMagMode;
textureGLWrapS = other.textureGLWrapS;
textureGLWrapT = other.textureGLWrapT;
blendMode = other.blendMode;
opacity = other.opacity;
scale = other.scale;
offset = other.offset;
return *this;
}

bool operator == (GLTextureUnit const &other) const {
if(texture != other.texture) return false;
if(textureVariant)
{
if(textureVariant != other.textureVariant) return false;
}
else
{
if(textureGLName != other.textureGLName) return false;
if(textureGLMagMode != other.textureGLMagMode) return false;
if(textureGLWrapS != other.textureGLWrapS) return false;
if(textureGLWrapT != other.textureGLWrapT) return false;
}
if(blendMode != other.blendMode) return false;
if(!de::fequal(opacity, other.opacity)) return false;
if(scale != other.scale) return false;
Expand All @@ -188,11 +159,11 @@ struct GLTextureUnit
}

bool hasTexture() const {
return texture.hasTexture();
return (textureVariant && textureVariant->glName() != 0) || textureGLName != 0;
}

DGLuint textureGLName() const {
return texture.textureGLName();
DGLuint getTextureGLName() const {
return textureVariant? textureVariant->glName() : textureGLName;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion doomsday/client/include/render/drawlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ class DrawList
* @param modColor Modulation color (if any).
* @param modTexCoords Modulation texture coordinates for each vertex (if any).
*/
DrawList &write(de::gl::Primitive primitive, bool isLit, uint vertCount,
DrawList &write(de::gl::Primitive primitive, blendmode_t blendMode,
de::Vector2f const &texScale, de::Vector2f const &texOffset,
de::Vector2f const &detailTexScale, de::Vector2f const &detailTexOffset,
bool isLit, uint vertCount,
de::Vector3f const *posCoords, de::Vector4f const *colorCoords = 0,
de::Vector2f const *texCoords = 0, de::Vector2f const *interTexCoords = 0,
DGLuint modTexture = 0, de::Vector3f const *modColor = 0,
Expand Down
10 changes: 4 additions & 6 deletions doomsday/client/include/render/drawlists.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ class DrawLists
DrawLists();

/**
* Locate an appropriate draw list for the specified geometry group and the
* currently configured, list texture unit write state. Collectively, these
* arguments comprise the "draw list specification".
* Locate an appropriate draw list for the given specification.
*
* @param group Logical geometry group identifier.
* @param spec Draw list specification.
*
* @return The chosen list.
*/
DrawList &find(GeomGroup group);
DrawList &find(DrawListSpec const &spec);

/**
* Finds all draw lists which match the given specification. Note that only
Expand Down Expand Up @@ -81,7 +79,7 @@ struct GLTextureUnit;
*/
void RL_LoadDefaultRtus();

DrawListSpec const &RL_CurrentListSpec();
DrawListSpec const &RL_ListSpec(GeomGroup group);

/**
* Map the texture unit write state for the identified @a idx unit to
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/gl/gl_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1190,14 +1190,14 @@ void GLTextureUnit::bind() const
return;
}

if(texture.variant)
if(textureVariant)
{
GL_BindTexture(texture.variant);
GL_BindTexture(textureVariant);
}
else
{
GL_BindTextureUnmanaged(texture.glName, texture.glWrapS,
texture.glWrapT, texture.glMagMode);
GL_BindTextureUnmanaged(textureGLName, textureGLWrapS,
textureGLWrapT, textureGLMagMode);
}
}

Expand Down
86 changes: 29 additions & 57 deletions doomsday/client/src/render/drawlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,11 @@ DENG2_PIMPL(DrawList)
DGLuint modTexture;
Vector3f modColor;

Vector2f ptexOffset;
Vector2f ptexScale;

Vector2f texOffset;
Vector2f texScale;

void setFromTexUnit(GLTextureUnit const &texUnit, bool p = false)
{
if(p)
{
ptexScale = texUnit.scale;
ptexOffset = texUnit.offset * texUnit.scale;
}
else
{
texScale = texUnit.scale;
texOffset = texUnit.offset * texUnit.scale;
}
}
Vector2f dtexOffset;
Vector2f dtexScale;

/**
* Draw the geometry for this element.
Expand All @@ -89,51 +75,51 @@ DENG2_PIMPL(DrawList)
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, modColorV);
}

if(conditions & SetMatrixDTexture)
if(conditions & SetMatrixTexture)
{
// Primitive-specific texture translation & scale.
if(conditions & SetMatrixDTexture0)
if(conditions & SetMatrixTexture0)
{
glActiveTexture(GL_TEXTURE0);
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
glTranslatef(texOffset.x, texOffset.y, 1);
glTranslatef(texOffset.x * texScale.x, texOffset.y * texScale.y, 1);
glScalef(texScale.x, texScale.y, 1);
}

if(conditions & SetMatrixDTexture1)
if(conditions & SetMatrixTexture1)
{
glActiveTexture(GL_TEXTURE1);
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
glTranslatef(texOffset.x, texOffset.y, 1);
glTranslatef(texOffset.x * texScale.x, texOffset.y * texScale.y, 1);
glScalef(texScale.x, texScale.y, 1);
}
}

if(conditions & SetMatrixTexture)
if(conditions & SetMatrixDTexture)
{
// Primitive-specific texture translation & scale.
if(conditions & SetMatrixTexture0)
if(conditions & SetMatrixDTexture0)
{
glActiveTexture(GL_TEXTURE0);
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
glTranslatef(ptexOffset.x, ptexOffset.y, 1);
glScalef(ptexScale.x, ptexScale.y, 1);
glTranslatef(dtexOffset.x * dtexScale.x, dtexOffset.y * dtexScale.y, 1);
glScalef(dtexScale.x, dtexScale.y, 1);
}

if(conditions & SetMatrixTexture1)
if(conditions & SetMatrixDTexture1)
{
glActiveTexture(GL_TEXTURE1);
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
glTranslatef(ptexOffset.x, ptexOffset.y, 1);
glScalef(ptexScale.x, ptexScale.y, 1);
glTranslatef(dtexOffset.x * dtexScale.x, dtexOffset.y * dtexScale.y, 1);
glScalef(dtexScale.x, dtexScale.y, 1);
}
}

Expand Down Expand Up @@ -169,31 +155,31 @@ DENG2_PIMPL(DrawList)
glEnd();

// Restore the texture matrix if changed.
if(conditions & SetMatrixTexture)
if(conditions & SetMatrixDTexture)
{
if(conditions & SetMatrixTexture0)
if(conditions & SetMatrixDTexture0)
{
glActiveTexture(GL_TEXTURE0);
glMatrixMode(GL_TEXTURE);
glPopMatrix();
}
if(conditions & SetMatrixTexture1)
if(conditions & SetMatrixDTexture1)
{
glActiveTexture(GL_TEXTURE1);
glMatrixMode(GL_TEXTURE);
glPopMatrix();
}
}

if(conditions & SetMatrixDTexture)
if(conditions & SetMatrixTexture)
{
if(conditions & SetMatrixDTexture0)
if(conditions & SetMatrixTexture0)
{
glActiveTexture(GL_TEXTURE0);
glMatrixMode(GL_TEXTURE);
glPopMatrix();
}
if(conditions & SetMatrixDTexture1)
if(conditions & SetMatrixTexture1)
{
glActiveTexture(GL_TEXTURE1);
glMatrixMode(GL_TEXTURE);
Expand Down Expand Up @@ -364,7 +350,9 @@ bool DrawList::isEmpty() const
return d->last == 0;
}

DrawList &DrawList::write(gl::Primitive primitive, bool isLit, uint vertCount,
DrawList &DrawList::write(gl::Primitive primitive, blendmode_t blendMode,
Vector2f const &texScale, Vector2f const &texOffset,
Vector2f const &detailTexScale, Vector2f const &detailTexOffset, bool isLit, uint vertCount,
Vector3f const *posCoords, Vector4f const *colorCoords, Vector2f const *texCoords,
Vector2f const *interTexCoords, DGLuint modTexture, Vector3f const *modColor,
Vector2f const *modTexCoords)
Expand Down Expand Up @@ -393,31 +381,15 @@ DrawList &DrawList::write(gl::Primitive primitive, bool isLit, uint vertCount,
}

// Configure the GL state to be applied when this geometry is drawn later.
Spec const &writeSpec = RL_CurrentListSpec();

elem->data.blendMode = writeSpec.unit(TU_PRIMARY).blendMode;
elem->data.blendMode = blendMode;
elem->data.modTexture = modTexture;
elem->data.modColor = modColor? *modColor : Vector3f();
elem->data.ptexOffset = Vector2f(0, 0);
elem->data.ptexScale = Vector2f(0, 0);
elem->data.texScale = Vector2f(1, 1);
elem->data.texOffset = Vector2f(1, 1);

// GL texture translation parameters come from the tex unit map and
// differ according to the (logical) type of primitive to be written.
if(spec().group == ShineGeom && writeSpec.unit(TU_INTER).hasTexture())
{
elem->data.setFromTexUnit(writeSpec.unit(TU_INTER), true);
}
else if(writeSpec.unit(TU_PRIMARY).hasTexture())
{
elem->data.setFromTexUnit(writeSpec.unit(TU_PRIMARY), true);
}

if(writeSpec.unit(TU_PRIMARY_DETAIL).hasTexture())
{
elem->data.setFromTexUnit(writeSpec.unit(TU_PRIMARY_DETAIL));
}
elem->data.texScale = texScale;
elem->data.texOffset = texOffset;

elem->data.dtexScale = detailTexScale;
elem->data.dtexOffset = detailTexOffset;

// Allocate geometry from the backing store.
uint base = elem->data.buffer->allocateVertices(vertCount);
Expand Down
Loading

0 comments on commit bdd6a90

Please sign in to comment.