mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-11-29 03:33:48 +00:00
use VBO to render tile borders
Also fix oversight in DynamicGPUBuffer::drawElements(); first wasn't used
This commit is contained in:
parent
cc78b300cc
commit
a111bfc17f
4 changed files with 18 additions and 17 deletions
|
@ -158,6 +158,8 @@ void Core::setup_opengl()
|
|||
TexCoordBox defaultTC;
|
||||
defaultTC.setStandard();
|
||||
defaultQuadGrid.init(2, 2, defaultTC);
|
||||
|
||||
defautQuadBorder.initQuadVertices(defaultTC, GPUACCESS_DEFAULT);
|
||||
}
|
||||
|
||||
void Core::resizeWindow(int w, int h, int full, int bpp, int vsync, int display, int hz)
|
||||
|
@ -281,7 +283,7 @@ static bool checkWritable(const std::string& path, bool warn, bool critical)
|
|||
|
||||
|
||||
Core::Core(const std::string &filesystem, const std::string& extraDataDir, int numRenderLayers, const std::string &appName, int particleSize, std::string userDataSubFolder)
|
||||
: ActionMapper(), StateManager(), appName(appName)
|
||||
: ActionMapper(), StateManager(), appName(appName), defautQuadBorder(GPUBUF_STATIC | GPUBUF_VERTEXBUF)
|
||||
{
|
||||
window = NULL;
|
||||
sound = NULL;
|
||||
|
@ -1922,6 +1924,7 @@ void Core::shutdown()
|
|||
debugLog("OK");
|
||||
|
||||
defaultQuadGrid.dropBuffers();
|
||||
defautQuadBorder.dropBuffer();
|
||||
|
||||
debugLog("Shutdown Graphics Library...");
|
||||
shutdownGraphicsLibrary();
|
||||
|
|
|
@ -413,6 +413,7 @@ public:
|
|||
TextureMgr texmgr;
|
||||
|
||||
inline const RenderGrid *getDefaultQuadGrid() const { return &defaultQuadGrid; }
|
||||
inline const DynamicGPUBuffer *getDefaultQuadBorderBuf() const { return &defautQuadBorder; }
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -492,6 +493,7 @@ protected:
|
|||
void clearActionButtons();
|
||||
|
||||
RenderGrid defaultQuadGrid;
|
||||
DynamicGPUBuffer defautQuadBorder;
|
||||
|
||||
public:
|
||||
// inclusive!
|
||||
|
|
|
@ -62,6 +62,7 @@ void TileRender::onRender(const RenderState& rs) const
|
|||
unsigned lastTexId = 0;
|
||||
|
||||
const bool renderExtras = renderBorders || RenderObject::renderCollisionShape;
|
||||
|
||||
const TileEffectData *prevEff = ((TileEffectData*)NULL)+1; // initial value is different from anything else
|
||||
|
||||
for(size_t i = 0; i < storage.tiles.size(); ++i)
|
||||
|
@ -183,20 +184,11 @@ void TileRender::onRender(const RenderState& rs) const
|
|||
color *= getTagColor(tile.tag);
|
||||
|
||||
glColor4f(color.x, color.y, color.z, 1.0f);
|
||||
core->getDefaultQuadBorderBuf()->apply();
|
||||
glPointSize(16);
|
||||
glBegin(GL_POINTS);
|
||||
glVertex2f(0,0);
|
||||
glEnd();
|
||||
|
||||
// TODO: move this to the IBO
|
||||
glDrawArrays(GL_POINTS, 4, 1);
|
||||
glLineWidth(2);
|
||||
glBegin(GL_LINE_STRIP);
|
||||
glVertex2f(0.5f, 0.5f);
|
||||
glVertex2f(0.5f, -0.5f);
|
||||
glVertex2f(-0.5f, -0.5f);
|
||||
glVertex2f(-0.5f, 0.5f);
|
||||
glVertex2f(0.5f, 0.5f);
|
||||
glEnd();
|
||||
glDrawArrays(GL_LINE_LOOP, 0, 4);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -279,17 +279,17 @@ void DynamicGPUBuffer::drawElements(unsigned glmode, size_t n, size_t first) con
|
|||
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, id);
|
||||
//}
|
||||
|
||||
void *p = id ? NULL : _h_data;
|
||||
const unsigned short *p = (unsigned short*)(id ? NULL : _h_data);
|
||||
assert(p || id);
|
||||
|
||||
glDrawElements(glmode, n, GL_UNSIGNED_SHORT, p);
|
||||
glDrawElements(glmode, n, GL_UNSIGNED_SHORT, p + first);
|
||||
}
|
||||
|
||||
void DynamicGPUBuffer::initQuadVertices(const TexCoordBox& tc, unsigned access)
|
||||
{
|
||||
do
|
||||
{
|
||||
float *p = (float*)beginWrite(GPUBUFTYPE_VEC2_TC, (4*4) * sizeof(float), access);
|
||||
float *p = (float*)beginWrite(GPUBUFTYPE_VEC2_TC, (4*4 + 4) * sizeof(float), access);
|
||||
*p++ = -0.5f; *p++ = +0.5f; // xy
|
||||
*p++ = tc.u1; *p++ = tc.v1; // uv
|
||||
*p++ = +0.5f; *p++ = +0.5f; // xy
|
||||
|
@ -298,6 +298,9 @@ void DynamicGPUBuffer::initQuadVertices(const TexCoordBox& tc, unsigned access)
|
|||
*p++ = tc.u2; *p++ = tc.v2; // uv
|
||||
*p++ = -0.5f; *p++ = -0.5f; // xy
|
||||
*p++ = tc.u1; *p++ = tc.v2; // uv
|
||||
|
||||
for(size_t i = 0; i < 4; ++i)
|
||||
*p++ = 0; // zero/center xy uv (uv isn't used)
|
||||
}
|
||||
while(!commitWrite());
|
||||
}
|
||||
|
@ -318,9 +321,10 @@ size_t DynamicGPUBuffer::initGridIndices_Triangles(size_t w, size_t h, bool inve
|
|||
const size_t quadsx = w - 1;
|
||||
const size_t quadsy = h - 1;
|
||||
const size_t quads = quadsx * quadsy;
|
||||
const size_t border = 4; // for GL_LINE_LOOP
|
||||
do
|
||||
{
|
||||
unsigned short *p = (unsigned short*)beginWrite(GPUBUFTYPE_U16, 6*quads * sizeof(short), access);
|
||||
unsigned short *p = (unsigned short*)beginWrite(GPUBUFTYPE_U16, (6*quads + border) * sizeof(short), access);
|
||||
|
||||
if(!invert)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue