Skip to content

Commit

Permalink
Cleanup: Move utility classes away from rendersystem.cpp/h
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Oct 13, 2015
1 parent 32f1a0a commit fa76127
Show file tree
Hide file tree
Showing 11 changed files with 441 additions and 296 deletions.
50 changes: 50 additions & 0 deletions doomsday/apps/client/include/render/projectionlist.h
@@ -0,0 +1,50 @@
/** @file projectionlist.h Projection list.
*
* @authors Copyright © 2006-2015 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, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef DENG_CLIENT_RENDER_PROJECTIONLIST_H
#define DENG_CLIENT_RENDER_PROJECTIONLIST_H

#include "projectedtexturedata.h"

struct ProjectionList
{
struct Node
{
Node *next, *nextUsed;
ProjectedTextureData projection;
};

Node *head = nullptr;
bool sortByLuma; ///< @c true= Sort from brightest to darkest.

static void init();
static void rewind();

inline ProjectionList &operator << (ProjectedTextureData &texp) { return add(texp); }

ProjectionList &add(ProjectedTextureData &texp);

private:
static Node *firstNode;
static Node *cursorNode;

static Node *newNode();
};

#endif // DENG_CLIENT_RENDER_PROJECTIONLIST_H

80 changes: 3 additions & 77 deletions doomsday/apps/client/include/render/rendersystem.h
Expand Up @@ -13,7 +13,7 @@
* 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, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#ifndef CLIENT_RENDERSYSTEM_H
Expand All @@ -28,87 +28,13 @@
#include "settingsregister.h"
#include "projectedtexturedata.h"
#include "vectorlightdata.h"
#include "projectionlist.h"
#include "vectorlightlist.h"

class AngleClipper;
class ModelRenderer;
class SkyDrawable;

/**
* Geometry backing store (arrays).
* @todo Replace with GLBuffer -ds
*/
struct Store
{
de::Vector3f *posCoords = nullptr;
de::Vector4ub *colorCoords = nullptr;
de::Vector2f *texCoords[2];
de::Vector2f *modCoords = nullptr;

Store();
~Store();

void rewind();

void clear();

de::duint allocateVertices(de::duint count);

private:
de::duint _vertCount = 0;
de::duint _vertMax = 0;
};

/// @todo make private to RenderSystem
struct ProjectionList
{
struct Node
{
Node *next, *nextUsed;
ProjectedTextureData projection;
};

Node *head = nullptr;
bool sortByLuma; ///< @c true= Sort from brightest to darkest.

static void init();
static void rewind();

inline ProjectionList &operator << (ProjectedTextureData &texp) { return add(texp); }

ProjectionList &add(ProjectedTextureData &texp);

private:
static Node *firstNode;
static Node *cursorNode;

static Node *newNode();
};

/// @todo make private to RenderSystem
struct VectorLightList
{
struct Node
{
Node *next, *nextUsed;
VectorLightData vlight;
};

Node *head = nullptr;

static void init();
static void rewind();

inline VectorLightList &operator << (VectorLightData &texp) { return add(texp); }

VectorLightList &add(VectorLightData &texp);

private:
static Node *firstNode;
static Node *cursorNode;

static Node *newNode();
};

/**
* Renderer subsystems, draw lists, etc... @ingroup render
*/
Expand Down
50 changes: 50 additions & 0 deletions doomsday/apps/client/include/render/store.h
@@ -0,0 +1,50 @@
/** @file store.h Store.
*
* @authors Copyright © 2003-2014 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2015 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, see:
* http://www.gnu.org/licenses</small>
*/
#ifndef DENG_CLIENT_RENDER_STORE_H
#define DENG_CLIENT_RENDER_STORE_H

#include <de/Vector>

/**
* Geometry backing store (arrays).
* @todo Replace with GLBuffer -ds
*/
struct Store
{
de::Vector3f *posCoords = nullptr;
de::Vector4ub *colorCoords = nullptr;
de::Vector2f *texCoords[2];
de::Vector2f *modCoords = nullptr;

Store();
~Store();

void rewind();

void clear();

de::duint allocateVertices(de::duint count);

private:
de::duint _vertCount = 0;
de::duint _vertMax = 0;
};

#endif // DENG_CLIENT_RENDER_STORE_H

49 changes: 49 additions & 0 deletions doomsday/apps/client/include/render/vectorlightlist.h
@@ -0,0 +1,49 @@
/** @file vectorlightlist.h Vector light list.
*
* @authors Copyright © 2006-2015 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, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef DENG_CLIENT_RENDER_VECTORLIGHTLIST_H
#define DENG_CLIENT_RENDER_VECTORLIGHTLIST_H

#include "render/vectorlightdata.h"

struct VectorLightList
{
struct Node
{
Node *next, *nextUsed;
VectorLightData vlight;
};

Node *head = nullptr;

static void init();
static void rewind();

inline VectorLightList &operator << (VectorLightData &texp) { return add(texp); }

VectorLightList &add(VectorLightData &texp);

private:
static Node *firstNode;
static Node *cursorNode;

static Node *newNode();
};

#endif // DENG_CLIENT_RENDER_VECTORLIGHTLIST_H

1 change: 1 addition & 0 deletions doomsday/apps/client/src/render/drawlist.cpp
Expand Up @@ -26,6 +26,7 @@
#include "clientapp.h"
#include "gl/gl_main.h"
#include "render/rend_main.h"
#include "render/store.h"

using namespace de;

Expand Down
104 changes: 104 additions & 0 deletions doomsday/apps/client/src/render/projectionlist.cpp
@@ -0,0 +1,104 @@
/** @file projectionlist.cpp Projection list.
*
* @authors Copyright © 2006-2015 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, see:
* http://www.gnu.org/licenses</small>
*/

#include "render/projectionlist.h"

#include <de/memoryzone.h>

ProjectionList::Node *ProjectionList::firstNode = nullptr;
ProjectionList::Node *ProjectionList::cursorNode = nullptr;

void ProjectionList::init() // static
{
static bool firstTime = true;
if(firstTime)
{
firstNode = 0;
cursorNode = 0;
firstTime = false;
}
}

void ProjectionList::rewind() // static
{
// Start reusing nodes.
cursorNode = firstNode;
}

/// Averaged-color * alpha.
static dfloat luminosity(ProjectedTextureData const &pt) // static
{
return (pt.color.x + pt.color.y + pt.color.z) / 3 * pt.color.w;
}

ProjectionList &ProjectionList::add(ProjectedTextureData &texp)
{
Node *node = newNode();
node->projection = texp;

if(head && sortByLuma)
{
dfloat luma = luminosity(node->projection);
Node *iter = head;
Node *last = iter;
do
{
// Is this brighter than that being added?
if(luminosity(iter->projection) > luma)
{
last = iter;
iter = iter->next;
}
else
{
// Insert it here.
node->next = last->next;
last->next = node;
return *this;
}
} while(iter);
}

node->next = head;
head = node;

return *this;
}

ProjectionList::Node *ProjectionList::newNode() // static
{
Node *node;

// Do we need to allocate more nodes?
if(!cursorNode)
{
node = (Node *) Z_Malloc(sizeof(*node), PU_APPSTATIC, nullptr);

// Link the new node to the list.
node->nextUsed = firstNode;
firstNode = node;
}
else
{
node = cursorNode;
cursorNode = cursorNode->nextUsed;
}

node->next = nullptr;
return node;
}
1 change: 1 addition & 0 deletions doomsday/apps/client/src/render/rend_fakeradio.cpp
Expand Up @@ -42,6 +42,7 @@
#include "render/r_main.h" // levelFullBright
#include "render/shadowedge.h"
#include "render/viewports.h" // R_FrameCount()
#include "render/store.h"

using namespace de;

Expand Down
3 changes: 2 additions & 1 deletion doomsday/apps/client/src/render/rend_main.cpp
Expand Up @@ -91,6 +91,7 @@
#include "render/rend_particle.h"
#include "render/rendpoly.h"
#include "render/skydrawable.h"
#include "render/store.h"
#include "render/viewports.h"
#include "render/vissprite.h"
#include "render/vr.h"
Expand Down Expand Up @@ -806,7 +807,7 @@ static void lightVertex(Vector4f &color, Vector3f const &vtx, dfloat lightLevel,
*
* @param verts Geometry to be illuminated.
*
* Surface geometry:
* Surface geometry:
* @param numVertices Total number of map-space surface geometry vertices.
* @param posCoords Position coordinates for the map-space surface geometry.
* @param mapElement Source MapElement for the map-space surface geometry.
Expand Down

0 comments on commit fa76127

Please sign in to comment.