Skip to content

Commit

Permalink
Refactor|Client|GL: GLTextureUnit uses GL2 filter/wrap identifiers; r…
Browse files Browse the repository at this point in the history
…elocated
  • Loading branch information
danij-deng committed Nov 8, 2013
1 parent ecb5eb3 commit d9b9cd3
Show file tree
Hide file tree
Showing 16 changed files with 293 additions and 226 deletions.
1 change: 1 addition & 0 deletions doomsday/client/client.pro
Expand Up @@ -259,6 +259,7 @@ DENG_HEADERS += \
include/gl/gl_model.h \
include/gl/gl_tex.h \
include/gl/gl_texmanager.h \
include/gl/gltextureunit.h \
include/gl/svg.h \
include/gl/sys_opengl.h \
include/gl/texturecontent.h \
Expand Down
110 changes: 3 additions & 107 deletions doomsday/client/include/gl/gl_main.h
Expand Up @@ -33,6 +33,7 @@
#include "api_gl.h"
#include "sys_opengl.h"

#include "gl/gltextureunit.h"
#include "render/r_main.h"
#include "Texture"

Expand All @@ -43,8 +44,6 @@ struct texturevariant_s;

class Material;

#define MAX_TEX_UNITS 2 // More aren't currently used.

DENG_EXTERN_C int numTexUnits;
DENG_EXTERN_C boolean envModAdd;
DENG_EXTERN_C int defResX, defResY, defBPP, defFullscreen;
Expand All @@ -69,109 +68,6 @@ DENG_EXTERN_C int r_detail;
# define LIBDENG_ASSERT_GL_TEXTURE_ISBOUND(tex)
#endif

/**
* GL Texture unit config.
*/
struct GLTextureUnit
{
de::TextureVariant *textureVariant;

/// Properties used only with @em unmanged GL textures.
DGLuint textureGLName;
int textureGLMagMode;
int textureGLWrapS;
int textureGLWrapT;

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

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

GLTextureUnit()
: textureVariant(0)
, textureGLName(0)
, textureGLMagMode(GL_LINEAR)
, textureGLWrapS(GL_REPEAT)
, textureGLWrapT(GL_REPEAT)
, opacity(1)
, scale(1, 1)
{}
GLTextureUnit(de::TextureVariant &textureVariant,
de::Vector2f const &scale = de::Vector2f(1, 1),
de::Vector2f const &offset = de::Vector2f(0, 0),
float opacity = 1)
: textureVariant(&textureVariant)
, textureGLName(0)
, textureGLMagMode(GL_LINEAR)
, textureGLWrapS(GL_REPEAT)
, textureGLWrapT(GL_REPEAT)
, opacity(opacity)
, scale(scale)
, offset(offset)
{}
GLTextureUnit(DGLuint textureGLName, int textureGLWrapS = GL_REPEAT,
int textureGLWrapT = GL_REPEAT)
: textureVariant(0)
, textureGLName(textureGLName)
, textureGLMagMode(GL_LINEAR)
, textureGLWrapS(textureGLWrapS)
, textureGLWrapT(textureGLWrapT)
, opacity(1)
, scale(1, 1)
{}
GLTextureUnit(GLTextureUnit const &other)
: textureVariant(other.textureVariant)
, textureGLName(other.textureGLName)
, textureGLMagMode(other.textureGLMagMode)
, textureGLWrapS(other.textureGLWrapS)
, textureGLWrapT(other.textureGLWrapT)
, opacity(other.opacity)
, scale(other.scale)
, offset(other.offset)
{}

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

bool operator == (GLTextureUnit const &other) const {
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(!de::fequal(opacity, other.opacity)) return false;
if(scale != other.scale) return false;
if(offset != other.offset) return false;
return true;
}
bool operator != (GLTextureUnit const other) const {
return !(*this == other);
}

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

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

void GL_AssertContextActive();

/// Register the console commands, variables, etc..., of this module.
Expand Down Expand Up @@ -315,14 +211,14 @@ void GL_BindTextureUnmanaged(DGLuint texname, int wrapS = GL_REPEAT, int wrapT =
* the @em active GL texture unit. If no texture is associated then nothing
* will happen.
*/
void GL_Bind(GLTextureUnit const &glTU);
void GL_Bind(de::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_BindTo(de::GLTextureUnit const &glTU, int unit);

void GL_SetNoTexture();

Expand Down
166 changes: 166 additions & 0 deletions doomsday/client/include/gl/gltextureunit.h
@@ -0,0 +1,166 @@
/** @file gltextureunit.h GL texture unit.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#ifndef DENG_CLIENT_GLTEXTUREUNIT_H
#define DENG_CLIENT_GLTEXTUREUNIT_H

#include "Texture"
#include <de/GLTexture>
#include <de/Vector>

/**
* Of the available GL texture units, only this many will be utilized.
*
* @todo Find a more suitable home (here because all other GL-domain headers
* also include system headers, which aren't needed in components whose API(s)
* do not depend on them (and pollute on Windows)).
*/
#define MAX_TEX_UNITS 2 // More aren't currently used.

namespace de {

/**
* GL Texture unit config.
*
* @ingroup gl
*/
class GLTextureUnit
{
public:
/// Managed GL textures encapsulate filter and wrapping management.
TextureVariant *texture;

/// Unmanged GL textures have an independent state.
struct Unmanaged {
GLuint glName;
gl::Wrapping wrapS;
gl::Wrapping wrapT;
gl::Filter filter;

Unmanaged(GLuint glName = 0,
gl::Wrapping wrapS = gl::Repeat,
gl::Wrapping wrapT = gl::Repeat,
gl::Filter filter = gl::Linear)
: glName(glName)
, wrapS(wrapS)
, wrapT(wrapT)
, filter(filter)
{}
Unmanaged(Unmanaged const &other)
: glName(other.glName)
, wrapS(other.wrapS)
, wrapT(other.wrapT)
, filter(other.filter)
{}

Unmanaged &operator = (Unmanaged const &other) {
glName = other.glName;
wrapS = other.wrapS;
wrapT = other.wrapT;
filter = other.filter;
return *this;
}

bool operator == (Unmanaged const &other) const {
if(glName != other.glName) return false;
if(wrapS != other.wrapS) return false;
if(wrapT != other.wrapT) return false;
if(filter != other.filter) return false;
return true;
}

bool operator != (Unmanaged const &other) const {
return !(*this == other);
}
} unmanaged;

/// Shared properties:
float opacity;
Vector2f scale;
Vector2f offset;

GLTextureUnit()
: texture(0)
, opacity(1)
, scale(1, 1)
{}
GLTextureUnit(TextureVariant &textureVariant,
Vector2f const &scale = Vector2f(1, 1),
Vector2f const &offset = Vector2f(0, 0),
float opacity = 1)
: texture(&textureVariant)
, opacity(opacity)
, scale(scale)
, offset(offset)
{}
GLTextureUnit(GLuint textureGLName, gl::Wrapping textureGLWrapS = gl::Repeat,
gl::Wrapping textureGLWrapT = gl::Repeat)
: texture(0)
, unmanaged(textureGLName, textureGLWrapS, textureGLWrapT)
, opacity(1)
, scale(1, 1)
{}
GLTextureUnit(GLTextureUnit const &other)
: texture(other.texture)
, unmanaged(other.unmanaged)
, opacity(other.opacity)
, scale(other.scale)
, offset(other.offset)
{}

GLTextureUnit &operator = (GLTextureUnit const &other) {
texture = other.texture;
unmanaged = other.unmanaged;
opacity = other.opacity;
scale = other.scale;
offset = other.offset;
return *this;
}

bool operator == (GLTextureUnit const &other) const {
if(texture)
{
if(texture != other.texture) return false;
}
else
{
if(unmanaged != other.unmanaged) return false;
}
if(!de::fequal(opacity, other.opacity)) return false;
if(scale != other.scale) return false;
if(offset != other.offset) return false;
return true;
}
bool operator != (GLTextureUnit const other) const {
return !(*this == other);
}

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

GLuint getTextureGLName() const {
return texture? texture->glName() : unmanaged.glName;
}
};

} // namespace de

#endif // DENG_CLIENT_GLTEXTUREUNIT_H
15 changes: 8 additions & 7 deletions doomsday/client/include/render/drawlist.h
Expand Up @@ -21,12 +21,13 @@
#ifndef DENG_CLIENT_RENDER_DRAWLIST_H
#define DENG_CLIENT_RENDER_DRAWLIST_H

#include "de_platform.h"
#include "gl/gl_main.h"
#include "gl/gltextureunit.h"
#include <de/GLBuffer>
#include <de/Vector>
#include <QFlags>

enum blendmode_e;

/// Semantic geometry group identifiers.
enum GeomGroup
{
Expand Down Expand Up @@ -85,17 +86,17 @@ class DrawList
struct Spec
{
GeomGroup group;
GLTextureUnit texunits[NUM_TEXTURE_UNITS];
de::GLTextureUnit texunits[NUM_TEXTURE_UNITS];

Spec(GeomGroup group = UnlitGeom) : group(group)
{}

inline GLTextureUnit &unit(int index) {
inline de::GLTextureUnit &unit(int index) {
DENG2_ASSERT(index >= 0 && index < NUM_TEXTURE_UNITS);
return texunits[index];
}

inline GLTextureUnit const &unit(int index) const {
inline de::GLTextureUnit const &unit(int index) const {
DENG2_ASSERT(index >= 0 && index < NUM_TEXTURE_UNITS);
return texunits[index];
}
Expand Down Expand Up @@ -123,13 +124,13 @@ class DrawList
* @param modColor Modulation color (if any).
* @param modTexCoords Modulation texture coordinates for each vertex (if any).
*/
DrawList &write(de::gl::Primitive primitive, blendmode_t blendMode,
DrawList &write(de::gl::Primitive primitive, blendmode_e 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,
GLuint modTexture = 0, de::Vector3f const *modColor = 0,
de::Vector2f const *modTexCoords = 0);

void draw(DrawMode mode, TexUnitMap const &texUnitMap) const;
Expand Down

0 comments on commit d9b9cd3

Please sign in to comment.