Skip to content

Commit

Permalink
Refactor|Renderer: Cleaned up primitive writing in DrawList
Browse files Browse the repository at this point in the history
Removed excessive use of write() method parameters, particularly when
all the parameters are left to their default values.
  • Loading branch information
skyjake committed Oct 31, 2016
1 parent 6b6cdcf commit ffef952
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 241 deletions.
97 changes: 55 additions & 42 deletions doomsday/apps/client/include/render/drawlist.h
Expand Up @@ -124,6 +124,37 @@ class DrawList

typedef QVector<de::duint> Indices;

struct PrimitiveParams
{
de::gl::Primitive type;

// GL state and flags.
enum Flag {
Unlit = 0,
OneLight = 0x1000,
ManyLights = 0x2000
};
Q_DECLARE_FLAGS(Flags, Flag)

de::duint32 flags_blendMode;
de::Vector2f texScale;
de::Vector2f texOffset;
de::Vector2f detailTexScale;
de::Vector2f detailTexOffset;
DGLuint modTexture; ///< GL-name of the modulation texture; otherwise @c 0.
de::Vector3f modColor; ///< Modulation color.

PrimitiveParams(de::gl::Primitive type,
de::Vector2f texScale = de::Vector2f(1, 1),
de::Vector2f texOffset = de::Vector2f(0, 0),
de::Vector2f detailTexScale = de::Vector2f(1, 1),
de::Vector2f detailTexOffset = de::Vector2f(0, 0),
Flags flags = Unlit,
blendmode_t blendMode = BM_NORMAL,
DGLuint modTexture = 0,
de::Vector3f modColor = de::Vector3f());
};

public:
/**
* Construct a new draw list.
Expand All @@ -135,46 +166,25 @@ class DrawList
/**
* Write indices for a (buffered) geometry primitive to the list.
*
* Primitive geometry:
* @param buffer Geometry buffer containing the primitive to write. It is the caller's
* responsibility to ensure this data remains accessible and valid while
* this DrawList is used (i.e., until a @ref clear(), rewind() or the
* @param buffer Geometry buffer containing the primitive to write.
* It is the caller's responsibility to ensure this data
* remains accessible and valid while this DrawList is used
* (i.e., until a @ref clear(), rewind() or the
* list itself is destroyed).
* @param primitive Type identifier for the GL primitive being written.
* @param primParams GL primitive parameters.
* @param indices Indices for the vertex elements in @a buffer. A copy is made.
*
* Primitive-specific GL attribute/state to apply when drawing:
* @param blendMode
* @param oneLight
* @param manyLights
* @param texScale
* @param texOffset
* @param detailTexScale
* @param detailTexOffset
* @param modTexture GL-name of the modulation texture; otherwise @c 0.
* @param modColor Modulation color.
*/
DrawList &write(Store const &buffer, de::gl::Primitive primitive, de::duint const *indices, int indexCount,
blendmode_t blendMode = BM_NORMAL,
bool oneLight = false,
bool manyLights = false,
de::Vector2f const &texScale = de::Vector2f(1, 1),
de::Vector2f const &texOffset = de::Vector2f(0, 0),
de::Vector2f const &detailTexScale = de::Vector2f(1, 1),
de::Vector2f const &detailTexOffset = de::Vector2f(0, 0),
GLuint modTexture = 0,
de::Vector3f const &modColor = de::Vector3f());

DrawList &write(Store const &buffer, de::gl::Primitive primitive, Indices const &indices,
blendmode_t blendMode = BM_NORMAL,
bool oneLight = false,
bool manyLights = false,
de::Vector2f const &texScale = de::Vector2f(1, 1),
de::Vector2f const &texOffset = de::Vector2f(0, 0),
de::Vector2f const &detailTexScale = de::Vector2f(1, 1),
de::Vector2f const &detailTexOffset = de::Vector2f(0, 0),
GLuint modTexture = 0,
de::Vector3f const &modColor = de::Vector3f());
DrawList &write(Store const &buffer,
de::duint const *indices, int indexCount,
PrimitiveParams const &primParms);

DrawList &write(Store const &buffer,
Indices const &indices,
de::gl::Primitive primitiveType); // using default parameters

DrawList &write(Store const &buffer,
Indices const &indices,
PrimitiveParams const &primParms);

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

Expand All @@ -189,16 +199,17 @@ class DrawList
void clear();

/**
* Return the read/write cursor to the beginning of the list, retaining all allocated storage for
* buffered GL commands so that it can be reused.
* Return the read/write cursor to the beginning of the list, retaining all allocated
* storage for buffered GL commands so that it can be reused.
*
* To be called at the beginning of a new render frame before any geometry is written to the list.
* To be called at the beginning of a new render frame before any geometry is written
* to the list.
*/
void rewind();

/**
* Provides mutable access to the list's specification. Note that any changes to this configuration
* will affect @em all geometry in the list.
* Provides mutable access to the list's specification. Note that any changes to this
* configuration will affect @em all geometry in the list.
*/
Spec &spec();

Expand All @@ -213,4 +224,6 @@ class DrawList

typedef DrawList::Spec DrawListSpec;

Q_DECLARE_OPERATORS_FOR_FLAGS(DrawList::PrimitiveParams::Flags)

#endif // CLIENT_RENDER_DRAWLIST_H

0 comments on commit ffef952

Please sign in to comment.