Skip to content

Commit

Permalink
Refactor|GL|Client: Updated use of GL_DrawRect()
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 13, 2013
1 parent cd53124 commit 5fdd9d1
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 62 deletions.
1 change: 0 additions & 1 deletion doomsday/client/include/dd_main.h
Expand Up @@ -35,7 +35,6 @@
#include "api_plugin.h"
#include "api_gameexport.h"
#include "Materials"
#include "resource/textures.h"
#include "filesys/sys_direc.h"
#include <de/c_wrapper.h>
#include <de/LibraryFile>
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/include/resource/resourcesystem.h
Expand Up @@ -19,13 +19,13 @@
#ifndef DENG_RESOURCESYSTEM_H
#define DENG_RESOURCESYSTEM_H

#include <de/System>
#include <de/Error>
#include "resourceclass.h"
#include "Textures"
#ifdef __CLIENT__
# include "Fonts"
#endif
#include <de/System>
#include <de/Error>

/**
* Logical resources; materials, packages, textures, etc... @ingroup resource
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/include/resourceclass.h
Expand Up @@ -27,11 +27,11 @@
#include "api_resourceclass.h"

#ifdef __cplusplus
//#ifndef DENG2_C_API_ONLY
#ifndef DENG2_C_API_ONLY

#include <QList>
#include <de/String>
#include "filetype.h"
#include <de/String>
#include <QList>

namespace de
{
Expand Down Expand Up @@ -129,7 +129,7 @@ namespace de

} // namespace de

//#endif // DENG2_C_API_ONLY
#endif // DENG2_C_API_ONLY
#endif // __cplusplus

#endif /* LIBDENG_RESOURCECLASS_H */
2 changes: 1 addition & 1 deletion doomsday/client/src/render/biassource.cpp
Expand Up @@ -17,7 +17,7 @@
* http://www.gnu.org/licenses</small>
*/

#include "dd_main.h"
#include "de_base.h"
#include "def_data.h"

#include "world/world.h"
Expand Down
7 changes: 3 additions & 4 deletions doomsday/client/src/render/biastracker.cpp
Expand Up @@ -17,15 +17,14 @@
* http://www.gnu.org/licenses</small>
*/

#include <de/Observers>
#include "de_platform.h"
#include "render/biastracker.h"

#include "dd_main.h"

#include "world/map.h"
#include "BiasDigest"
#include "BiasSource"

#include "render/biastracker.h"
#include <de/Observers>

using namespace de;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/skyfixedge.cpp
Expand Up @@ -17,7 +17,7 @@
* 02110-1301 USA</small>
*/

#include "dd_main.h"
#include "de_base.h"

#include "Face"

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/resource/api_resource.cpp
@@ -1,6 +1,6 @@
#define DENG_NO_API_MACROS_RESOURCE
#include "de_base.h"
#include "api_resource.h"
#include "dd_main.h"
#include "Textures"

#undef Textures_UniqueId2
Expand Down
27 changes: 15 additions & 12 deletions doomsday/client/src/ui/dd_input.cpp
Expand Up @@ -41,6 +41,8 @@
# include "de_graphics.h"
#endif

using namespace de;

#define DEFAULT_JOYSTICK_DEADZONE .05f // 5%

#define MAX_AXIS_FILTER 40
Expand Down Expand Up @@ -1629,7 +1631,6 @@ void Rend_RenderKeyStateVisual(inputdev_t* device, uint keyID, const Point2Raw*
const inputdevkey_t* key;
char keyLabelBuf[2];
Point2Raw origin;
RectRaw textGeom;
ddstring_t label;

if(geometry)
Expand Down Expand Up @@ -1679,16 +1680,17 @@ void Rend_RenderKeyStateVisual(inputdev_t* device, uint keyID, const Point2Raw*
initDrawStateForVisual(&origin);

// Calculate the size of the visual according to the dimensions of the text.
textGeom.origin.x = textGeom.origin.y = 0;
FR_TextSize(&textGeom.size, Str_Text(&label));
Size2Raw textSize;
FR_TextSize(&textSize, Str_Text(&label));

// Enlarge by BORDER pixels.
textGeom.size.width += BORDER * 2;
textGeom.size.height += BORDER * 2;
Rectanglei textGeom = Rectanglei::fromSize(Vector2i(0, 0),
Vector2ui(textSize.width + BORDER * 2,
textSize.height + BORDER * 2));

// Draw a background.
glColor4fv(key->isDown? downColor : upColor);
GL_DrawRect(&textGeom);
GL_DrawRect(textGeom);

// Draw the text.
glEnable(GL_TEXTURE_2D);
Expand All @@ -1698,20 +1700,20 @@ void Rend_RenderKeyStateVisual(inputdev_t* device, uint keyID, const Point2Raw*
// Mark expired?
if(key->assoc.flags & IDAF_EXPIRED)
{
const int markSize = .5f + MIN_OF(textGeom.size.width, textGeom.size.height) / 3.f;
int const markSize = .5f + de::min(textGeom.width(), textGeom.height()) / 3.f;

glColor3fv(expiredMarkColor);
glBegin(GL_TRIANGLES);
glVertex2i(textGeom.size.width, 0);
glVertex2i(textGeom.size.width, markSize);
glVertex2i(textGeom.size.width-markSize, 0);
glVertex2i(textGeom.width(), 0);
glVertex2i(textGeom.width(), markSize);
glVertex2i(textGeom.width() - markSize, 0);
glEnd();
}

// Mark triggered?
if(key->assoc.flags & IDAF_TRIGGERED)
{
const int markSize = .5f + MIN_OF(textGeom.size.width, textGeom.size.height) / 3.f;
int const markSize = .5f + de::min(textGeom.width(), textGeom.height()) / 3.f;

glColor3fv(triggeredMarkColor);
glBegin(GL_TRIANGLES);
Expand All @@ -1728,7 +1730,8 @@ void Rend_RenderKeyStateVisual(inputdev_t* device, uint keyID, const Point2Raw*
if(geometry)
{
memcpy(&geometry->origin, &origin, sizeof(geometry->origin));
memcpy(&geometry->size, &textGeom.size, sizeof(geometry->size));
geometry->size.width = textGeom.width();
geometry->size.height = textGeom.height();
}

#undef BORDER
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/ui/ui_main.cpp
Expand Up @@ -2427,8 +2427,8 @@ void UI_DrawLogo(Point2Raw const *origin, Size2Raw const *size)

glColor4f(1, 1, 1, uiAlpha);
glEnable(GL_TEXTURE_2D);
RectRaw rect(origin->x, origin->y, size->width, size->height);
GL_DrawRect(&rect);
GL_DrawRect(Rectanglei::fromSize(Vector2i(origin->xy),
Vector2ui(size->width, size->height)));
glDisable(GL_TEXTURE_2D);
}

Expand Down
70 changes: 37 additions & 33 deletions doomsday/client/src/ui/zonedebug.cpp
Expand Up @@ -22,33 +22,38 @@
* 02110-1301 USA</small>
*/

#ifdef _DEBUG

#include "de_base.h"
#include "de_graphics.h"

#include <math.h>
#include <de/Rectangle>
#include <de/Vector>
#include <de/concurrency.h>

#ifdef _DEBUG
#include <math.h>

/// @todo Find a better way to access the private data of the zone
/// (e.g., move this into the library and use an abstract graphics interface).
#include "../../libdeng1/src/memoryzone_private.h"

void Z_DrawRegion(memvolume_t* volume, RectRaw* rect, size_t start, size_t size, const float* color)
using namespace de;

static void drawRegion(memvolume_t &volume, Rectanglei &rect, size_t start,
size_t size, float const color[4])
{
const int bytesPerRow = (volume->size - sizeof(memzone_t)) / rect->size.height;
const float toPixelScale = (float)rect->size.width / (float)bytesPerRow;
const size_t edge = rect->origin.x + rect->size.width;
int x = (start % bytesPerRow)*toPixelScale + rect->origin.x;
int y = start / bytesPerRow + rect->origin.y;
int pixels = MAX_OF(1, ceil(size * toPixelScale));
DENG2_ASSERT(start + size <= volume.size);

assert(start + size <= volume->size);
int const bytesPerRow = (volume.size - sizeof(memzone_t)) / rect.height();
float const toPixelScale = (float)rect.width() / (float)bytesPerRow;
size_t const edge = rect.topLeft.x + rect.width();
int x = (start % bytesPerRow) * toPixelScale + rect.topLeft.x;
int y = start / bytesPerRow + rect.topLeft.y;
int pixels = de::max<dint>(1, std::ceil(size * toPixelScale));

while(pixels > 0)
{
const int availPixels = edge - x;
const int usedPixels = MIN_OF(availPixels, pixels);
int const availPixels = edge - x;
int const usedPixels = de::min(availPixels, pixels);

glColor4fv(color);
glVertex2i(x, y);
Expand All @@ -58,21 +63,21 @@ void Z_DrawRegion(memvolume_t* volume, RectRaw* rect, size_t start, size_t size,

// Move to the next row.
y++;
x = rect->origin.x;
x = rect.topLeft.x;
}
}

void Z_DebugDrawVolume(MemoryZonePrivateData* pd, memvolume_t* volume, RectRaw* rect)
void Z_DebugDrawVolume(MemoryZonePrivateData *pd, memvolume_t *volume, Rectanglei &rect)
{
memblock_t* block;
char* base = ((char*)volume->zone) + sizeof(memzone_t);
float opacity = .85f;
float colAppStatic[4] = { 1, 1, 1, .65f };
float colGameStatic[4] = { 1, 0, 0, .65f };
float colMap[4] = { 0, 1, 0, .65f };
float colMapStatic[4] = { 0, .5f, 0, .65f };
float colCache[4] = { 1, 0, 1, .65f };
float colOther[4] = { 0, 0, 1, .65f };
float const opacity = .85f;
float const colAppStatic[4] = { 1, 1, 1, .65f };
float const colGameStatic[4] = { 1, 0, 0, .65f };
float const colMap[4] = { 0, 1, 0, .65f };
float const colMapStatic[4] = { 0, .5f, 0, .65f };
float const colCache[4] = { 1, 0, 1, .65f };
float const colOther[4] = { 0, 0, 1, .65f };

char *base = ((char *)volume->zone) + sizeof(memzone_t);

// Clear the background.
glColor4f(0, 0, 0, opacity);
Expand All @@ -88,11 +93,11 @@ void Z_DebugDrawVolume(MemoryZonePrivateData* pd, memvolume_t* volume, RectRaw*
glBegin(GL_LINES);

// Visualize each block.
for(block = volume->zone->blockList.next;
for(memblock_t *block = volume->zone->blockList.next;
block != &volume->zone->blockList;
block = block->next)
{
const float* color = colOther;
float const *color = colOther;
if(!block->user) continue; // Free is black.

// Choose the color for this block.
Expand All @@ -108,7 +113,7 @@ void Z_DebugDrawVolume(MemoryZonePrivateData* pd, memvolume_t* volume, RectRaw*
break;
}

Z_DrawRegion(volume, rect, (char*)block - base, block->size, color);
drawRegion(*volume, rect, (char *)block - base, block->size, color);
}

glEnd();
Expand Down Expand Up @@ -163,12 +168,11 @@ void Z_DebugDrawer(void)
i = 0;
for(volume = pd.volumeRoot; volume; volume = volume->next, ++i)
{
RectRaw rect;
rect.size.width = MIN_OF(400, DENG_GAMEVIEW_WIDTH);
rect.size.height = h;
rect.origin.x = DENG_GAMEVIEW_WIDTH - rect.size.width - 1;
rect.origin.y = DENG_GAMEVIEW_HEIGHT - rect.size.height*(i+1) - 10*i - 1;
Z_DebugDrawVolume(&pd, volume, &rect);
int size = de::min(400, DENG_GAMEVIEW_WIDTH);
Z_DebugDrawVolume(&pd, volume,
Rectanglei::fromSize(Vector2i(DENG_GAMEVIEW_WIDTH - size - 1,
DENG_GAMEVIEW_HEIGHT - size * (i+1) - 10*i - 1),
Vector2ui(size, size)));
}

pd.unlock();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/server/src/shelluser.cpp
Expand Up @@ -24,8 +24,8 @@
#include <de/Log>
#include <de/LogBuffer>

#include "de_base.h"
#include "con_main.h"
#include "dd_main.h"
#include "games.h"
#include "Game"
#include "network/net_main.h"
Expand Down

0 comments on commit 5fdd9d1

Please sign in to comment.