Skip to content

Commit

Permalink
Client|Map Renderer: Began dismantling of the old render lists module
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 5, 2013
1 parent 9c2ee90 commit 39ac6fb
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 164 deletions.
164 changes: 121 additions & 43 deletions doomsday/client/include/gl/gl_main.h
Expand Up @@ -83,62 +83,135 @@ typedef enum {
} rtexmapunitid_t;

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

struct rtexmapunit_texture_t
struct GLTextureUnit
{
union {
struct {
DGLuint name; ///< Texture used on this layer (if any).
int magMode; ///< GL texture magnification filter.
int wrapS; ///< GL texture S axis wrap mode.
int wrapT; ///< GL texture T axis wrap mode.
} gl;
struct TextureState
{
de::TextureVariant *variant;
};
/// @ref textureUnitFlags
int flags;

rtexmapunit_texture_t() : flags(0)
{
gl.name = 0;
gl.magMode = GL_LINEAR;
gl.wrapS = GL_REPEAT;
gl.wrapT = GL_REPEAT;
}
/// 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;
}

inline bool hasTexture() const
{
if(flags & TUF_TEXTURE_IS_MANAGED)
{
return variant && variant->glName() != 0;
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);
}
return gl.name != 0;
}
};

/**
* GL Texture unit config.
*/
struct rtexmapunit_t
{
rtexmapunit_texture_t texture; ///< Info about the bound texture for this unit.
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).
bool hasTexture() const {
return (variant && variant->glName() != 0) || glName != 0;
}

rtexmapunit_t() : blendMode(BM_NORMAL), opacity(1), scale(1, 1)
DGLuint textureGLName() const {
return variant? variant->glName() : glName;
}
};
TextureState texture; ///< Info about the bound texture for this unit.

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(GLTextureUnit const &other)
: texture(other.texture),
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;
return *this;
}

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

bool hasTexture() const {
return texture.hasTexture();
}

DGLuint textureGLName() const {
return texture.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 @@ -200,6 +273,11 @@ void GL_Restore2DState(int step, viewport_t const *port, viewdata_t const *viewD

void GL_ProjectionMatrix();

/**
* The first selected unit is active after this call.
*/
void GL_SelectTexUnits(int count);

/**
* Swaps buffers / blits the back buffer to the front.
*/
Expand Down
124 changes: 28 additions & 96 deletions doomsday/client/include/render/rend_list.h
@@ -1,4 +1,4 @@
/** @file rend_list.h Rendering Lists.
/** @file rend_list.h Rendering draw lists.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
Expand All @@ -17,52 +17,11 @@
* http://www.gnu.org/licenses</small>
*/

#ifndef CLIENT_RENDER_LIST_H
#define CLIENT_RENDER_LIST_H
#ifndef DENG_CLIENT_RENDER_DRAWLIST_RENDERER_H
#define DENG_CLIENT_RENDER_DRAWLIST_RENDERER_H

#include <de/Vector>

#include "render/rendpoly.h"

// Multiplicative blending for dynamic lights?
#define IS_MUL (dynlightBlend != 1 && !usingFog)

struct rtexmapunit_t;

/**
* Types of render primitive supported by this module (polygons only).
*/
typedef enum primtype_e {
PT_FIRST = 0,
PT_TRIANGLE_STRIP = PT_FIRST, // Used for most stuff.
PT_FAN,
NUM_PRIM_TYPES
} primtype_t;

/**
* @defgroup rendpolyFlags Rendpoly Flags
* @ingroup flags
* @{
*/
#define RPF_SKYMASK 0x1 /// This primitive is to be added to the sky mask.
#define RPF_LIGHT 0x2 /// This primitive is to be added to the special lists for lights.
#define RPF_SHADOW 0x4 /// This primitive is to be added to the special lists for shadows (either object or fakeradio edge shadow).
#define RPF_HAS_DYNLIGHTS 0x8 /// Dynamic light primitives are to be drawn on top of this.

/// Default rendpolyFlags
#define RPF_DEFAULT 0
/**@}*/

DENG_EXTERN_C int renderTextures; /// @c 0= no textures, @c 1= normal mode, @c 2= lighting debug
DENG_EXTERN_C int renderWireframe;
DENG_EXTERN_C int useMultiTexLights;
DENG_EXTERN_C int useMultiTexDetails;

DENG_EXTERN_C int dynlightBlend;

DENG_EXTERN_C int torchAdditive;
DENG_EXTERN_C de::Vector3f torchColor;

/// Register the console commands, variables, etc..., of this module.
void RL_Register(void);

Expand All @@ -81,64 +40,36 @@ boolean RL_IsMTexDetails(void);
void RL_ClearLists(void);

void RL_DeleteLists(void);

/**
* Reset the texture unit write state back to the initial default values.
* Any mappings between logical units and preconfigured RTU states are
* cleared at this time.
*/
void RL_LoadDefaultRtus(void);

/**
* Map the texture unit write state for the identified @a idx unit to
* @a rtu. This creates a reference to @a rtu which MUST continue to
* remain accessible until the mapping is subsequently cleared or
* changed (explicitly by call to RL_MapRtu/RL_LoadDefaultRtus, or,
* implicitly by customizing the unit configuration through one of the
* RL_RTU* family of functions (at which point a copy will be performed).
*/
void RL_MapRtu(uint idx, rtexmapunit_t const *rtu);

/**
* Copy the configuration for the identified @a idx texture unit of
* the primitive writer's internal state from @a rtu.
*
* @param idx Logical index of the texture unit being configured.
* @param rtu Configured RTU state to copy the configuration from.
* Geometry backing store (arrays).
*/
void RL_CopyRtu(uint idx, rtexmapunit_t const *rtu);

/// @todo Avoid modifying the RTU write state for the purposes of primitive
/// specific translations by implementing these as arguments to the
/// RL_Add* family of functions.

/// Change the scale property of the identified @a idx texture unit.
void RL_Rtu_SetScale(uint idx, de::Vector2f const &st);

inline void RL_Rtu_SetScale(uint idx, float s, float t) {
RL_Rtu_SetScale(idx, de::Vector2f(s, t));
}
struct Store
{
/// Texture coordinate array indices.
enum
{
TCA_MAIN, // Main texture.
TCA_BLEND, // Blendtarget texture.
TCA_LIGHT, // Dynlight texture.
NUM_TEXCOORD_ARRAYS
};

/// Scale the offset and scale properties of the identified @a idx texture unit.
void RL_Rtu_Scale(uint idx, float scalar);
void RL_Rtu_ScaleST(uint idx, de::Vector2f const &st);
de::Vector3f *posCoords;
de::Vector2f *texCoords[NUM_TEXCOORD_ARRAYS];
de::Vector4ub *colorCoords;

/// Change the offset property of the identified @a idx texture unit.
void RL_Rtu_SetOffset(uint idx, de::Vector2f const &st);
Store();
~Store();

inline void RL_Rtu_SetOffset(uint idx, float s, float t) {
RL_Rtu_SetOffset(idx, de::Vector2f(s, t));
}
void rewind();

/// Translate the offset property of the identified @a idx texture unit.
void RL_Rtu_TranslateOffset(uint idx, de::Vector2f const &st);
void clear();

inline void RL_Rtu_TranslateOffset(uint idx, float s, float t) {
RL_Rtu_TranslateOffset(idx, de::Vector2f(s, t));
}
uint allocateVertices(uint count);

/// Change the texture assigned to the identified @a idx texture unit.
void RL_Rtu_SetTextureUnmanaged(uint idx, DGLuint glName, int wrapS, int wrapT);
private:
uint vertCount, vertMax;
};

/**
* @param primType Type of primitive being written.
Expand Down Expand Up @@ -197,7 +128,8 @@ void RL_AddPolyWithModulation(primtype_t primType, int flags, uint numElements,
*/
void RL_AddPoly(primtype_t primType, int flags, uint numElements,
const de::Vector3f* vertices, const de::Vector4f* colors);
Store &RL_Store();

void RL_RenderAllLists(void);
void RL_RenderAllLists();

#endif // CLIENT_RENDER_LIST_H
#endif // DENG_CLIENT_RENDER_DRAWLIST_RENDERER_H

0 comments on commit 39ac6fb

Please sign in to comment.