diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-06-14 02:17:38 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-06-14 11:41:50 +0300 |
commit | eecd33fff488d54d038d84d8676000fad826e940 (patch) | |
tree | 9eb6c12810579d52c8df16e43d294852ba5613bb | |
parent | 4b8a6d93c5a785c673ec6c9f8a09880c48dee065 (diff) | |
download | plus-eecd33fff488d54d038d84d8676000fad826e940.tar.gz plus-eecd33fff488d54d038d84d8676000fad826e940.tar.bz2 plus-eecd33fff488d54d038d84d8676000fad826e940.tar.xz plus-eecd33fff488d54d038d84d8676000fad826e940.zip |
fix modernoepngl drawing.
Add simple draw test in most renders.
-rw-r--r-- | src/graphicsmanager.cpp | 1 | ||||
-rw-r--r-- | src/graphicsvertexes.cpp | 15 | ||||
-rw-r--r-- | src/render/graphics.h | 7 | ||||
-rw-r--r-- | src/render/mgl.cpp | 1 | ||||
-rw-r--r-- | src/render/mgl.h | 1 | ||||
-rw-r--r-- | src/render/mgltypes.h | 1 | ||||
-rw-r--r-- | src/render/modernopenglgraphics.cpp | 77 | ||||
-rw-r--r-- | src/render/modernopenglgraphics.h | 5 | ||||
-rw-r--r-- | src/render/normalopenglgraphics.cpp | 56 | ||||
-rw-r--r-- | src/render/normalopenglgraphics.h | 2 | ||||
-rw-r--r-- | src/render/safeopenglgraphics.cpp | 26 | ||||
-rw-r--r-- | src/render/safeopenglgraphics.h | 2 | ||||
-rw-r--r-- | src/resources/map/maplayer.cpp | 15 | ||||
-rw-r--r-- | src/test/testlauncher.cpp | 35 | ||||
-rw-r--r-- | src/test/testlauncher.h | 2 |
15 files changed, 236 insertions, 10 deletions
diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp index cfed98cb1..5bd8f55b8 100644 --- a/src/graphicsmanager.cpp +++ b/src/graphicsmanager.cpp @@ -972,6 +972,7 @@ void GraphicsManager::initOpenGLFunctions() assignFunction(glDeleteBuffers, "glDeleteBuffers"); assignFunction(glBindBuffer, "glBindBuffer"); assignFunction(glBufferData, "glBufferData"); + assignFunction(glIsBuffer, "glIsBuffer"); } else { diff --git a/src/graphicsvertexes.cpp b/src/graphicsvertexes.cpp index c632952ee..102512274 100644 --- a/src/graphicsvertexes.cpp +++ b/src/graphicsvertexes.cpp @@ -20,7 +20,9 @@ #include "graphicsvertexes.h" -#include "render/mgl.h" +#include "logger.h" + +#include "render/graphics.h" #include "utils/dtor.h" @@ -97,14 +99,11 @@ void OpenGLGraphicsVertexes::clear() } mIntTexPool.clear(); - if (mglDeleteBuffers) + const int sz = mVbo.size(); + if (sz > 0) { - const int sz = mVbo.size(); - if (sz > 0) - { - mglDeleteBuffers(sz, &mVbo[0]); - mVbo.clear(); - } + mainGraphics->removeArray(sz, &mVbo[0]); + mVbo.clear(); } mVp.clear(); diff --git a/src/render/graphics.h b/src/render/graphics.h index a779ee1bb..3100971fc 100644 --- a/src/render/graphics.h +++ b/src/render/graphics.h @@ -460,6 +460,13 @@ class Graphics notfinal virtual void finalize(ImageVertexes *const vert A_UNUSED) { } + virtual void testDraw() + { } + + virtual void removeArray(const uint32_t sz A_UNUSED, + uint32_t *const arr A_UNUSED) + { } + int mWidth; int mHeight; int mActualWidth; diff --git a/src/render/mgl.cpp b/src/render/mgl.cpp index 88f413ea2..f8fed2b32 100644 --- a/src/render/mgl.cpp +++ b/src/render/mgl.cpp @@ -92,6 +92,7 @@ defName(glBindVertexBuffer); defName(glVertexAttribBinding); defName(glVertexAttribFormat); defName(glBindVertexBuffers); +defName(glIsBuffer); #ifdef WIN32 defName(wglGetExtensionsString); diff --git a/src/render/mgl.h b/src/render/mgl.h index 0f918ff02..d36950ca9 100644 --- a/src/render/mgl.h +++ b/src/render/mgl.h @@ -95,6 +95,7 @@ defNameE(glBindVertexBuffer); defNameE(glVertexAttribBinding); defNameE(glVertexAttribFormat); defNameE(glBindVertexBuffers); +defNameE(glIsBuffer); #ifdef WIN32 defNameE(wglGetExtensionsString); diff --git a/src/render/mgltypes.h b/src/render/mgltypes.h index 3b481e586..f4d23990f 100644 --- a/src/render/mgltypes.h +++ b/src/render/mgltypes.h @@ -139,6 +139,7 @@ typedef void (APIENTRY *glVertexAttribFormat_t) (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); typedef void (APIENTRY *glBindVertexBuffers_t) (GLuint first, GLsizei count, const GLuint *buffers, const GLuint *offsets, const GLsizei *strides); +typedef GLboolean (APIENTRY *glIsBuffer_t) (GLuint buffer); // callback typedef void (APIENTRY *GLDEBUGPROC_t) (GLenum source, GLenum type, GLuint id, diff --git a/src/render/modernopenglgraphics.cpp b/src/render/modernopenglgraphics.cpp index 6ab804e2b..fde4ff6cb 100644 --- a/src/render/modernopenglgraphics.cpp +++ b/src/render/modernopenglgraphics.cpp @@ -118,7 +118,10 @@ ModernOpenGLGraphics::~ModernOpenGLGraphics() if (mProgram) mProgram->decRef(); if (mVbo) + { +// logger->log("delete buffer: %u", mVbo); mglDeleteBuffers(1, &mVbo); + } if (mVao) mglDeleteVertexArrays(1, &mVao); } @@ -145,6 +148,7 @@ void ModernOpenGLGraphics::postInit() mglGenVertexArrays(1, &mVao); mglBindVertexArray(mVao); mglGenBuffers(1, &mVbo); + //logger->log("gen buffer: %u", mVbo); bindArrayBuffer(mVbo); logger->log("Compiling shaders"); @@ -263,6 +267,7 @@ void ModernOpenGLGraphics::drawQuad(const Image *const image, x2, y2, texX2, texY2 }; + //logger->log("allocate: %d, %ld", mVboCached, sizeof(vertices)); mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STREAM_DRAW); #ifdef DEBUG_DRAW_CALLS @@ -299,6 +304,7 @@ void ModernOpenGLGraphics::drawRescaledQuad(const Image *const image, x2, y2, texX2, texY2 }; + //logger->log("allocate: %d, %ld", mVboCached, sizeof(vertices)); mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STREAM_DRAW); #ifdef DEBUG_DRAW_CALLS @@ -337,6 +343,25 @@ bool ModernOpenGLGraphics::drawImageInline(const Image *const image, return true; } +void ModernOpenGLGraphics::testDraw() +{ + GLfloat vertices[] = + { + 0.0f, 0.0f, 0.0f, 0.0f, + 800.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 600.0f, 0.0f, 1.0f, + 800.0f, 600.0f, 1.0f, 1.0f + }; + + //logger->log("allocate: %d, %ld", mVboCached, sizeof(vertices)); + mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), + vertices, GL_STREAM_DRAW); +#ifdef DEBUG_DRAW_CALLS + mDrawCalls ++; +#endif + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); +} + void ModernOpenGLGraphics::drawImageCached(const Image *const image A_UNUSED, int A_UNUSED x, int y A_UNUSED) { @@ -545,6 +570,11 @@ inline void ModernOpenGLGraphics::drawVertexes(const std::vector<GLuint>::const_iterator ivbo; const std::vector<int>::const_iterator ivp_end = vp.end(); +/* + if (vp.size() != vbos.size()) + logger->log("different size in vp and vbos"); +*/ + for (ivp = vp.begin(), ivbo = vbos.begin(); ivp != ivp_end; ++ ivp, ++ ivbo) @@ -553,6 +583,7 @@ inline void ModernOpenGLGraphics::drawVertexes(const #ifdef DEBUG_DRAW_CALLS mDrawCalls ++; #endif + //logger->log("draw from array: %u", *ivbo); glDrawArrays(GL_TRIANGLES, 0, *ivp / 4); } } @@ -649,6 +680,13 @@ void ModernOpenGLGraphics::drawTileCollection(const ImageCollection { setTexturingAndBlending(true); // bindArrayBuffer(vbo); +/* + if (!vertCol) + { + logger->log("ModernOpenGLGraphics::drawTileCollection" + " vertCol is nullptr"); + } +*/ const ImageVertexesVector &draws = vertCol->draws; const ImageCollectionCIter it_end = draws.end(); for (ImageCollectionCIter it = draws.begin(); it != it_end; ++ it) @@ -929,6 +967,7 @@ void ModernOpenGLGraphics::drawPoint(int x, int y) { x + clipArea.xOffset, y + clipArea.yOffset, 0.0f, 0.0f }; + //logger->log("allocate: %d, %ld", mVboCached, sizeof(vertices)); mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STREAM_DRAW); #ifdef DEBUG_DRAW_CALLS @@ -947,6 +986,7 @@ void ModernOpenGLGraphics::drawLine(int x1, int y1, int x2, int y2) x1 + clipArea.xOffset, y1 + clipArea.yOffset, 0.0f, 0.0f, x2 + clipArea.xOffset, y2 + clipArea.yOffset, 0.0f, 0.0f }; + //logger->log("allocate: %d, %ld", mVboCached, sizeof(vertices)); mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STREAM_DRAW); #ifdef DEBUG_DRAW_CALLS @@ -972,6 +1012,7 @@ void ModernOpenGLGraphics::drawRectangle(const Rect& rect) x2, y1, 0.0f, 0.0f }; + //logger->log("allocate: %d, %ld", mVboCached, sizeof(vertices)); mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STREAM_DRAW); #ifdef DEBUG_DRAW_CALLS @@ -997,6 +1038,7 @@ void ModernOpenGLGraphics::fillRectangle(const Rect& rect) x2, y2, 0.0f, 0.0f }; + //logger->log("allocate: %d, %ld", mVboCached, sizeof(vertices)); mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STREAM_DRAW); #ifdef DEBUG_DRAW_CALLS @@ -1119,12 +1161,29 @@ void ModernOpenGLGraphics::bindTexture(const GLenum target, } } +void ModernOpenGLGraphics::removeArray(const uint32_t sz, + uint32_t *const arr) +{ + mglDeleteBuffers(sz, arr); + for (int f = 0; f < sz; f ++) + { + if (arr[f] == mVboCached) + mVboCached = 0; + //logger->log("delete buffers: %u", arr[f]); + } +} + void ModernOpenGLGraphics::bindArrayBuffer(const GLuint vbo) { if (mVboCached != vbo) { mVboCached = vbo; + //logger->log("bind array: %u", vbo); mglBindBuffer(GL_ARRAY_BUFFER, vbo); +/* + if (mglIsBuffer(vbo) != GL_TRUE) + logger->log("bind wrong buffer: %u", vbo); +*/ mAttributesCached = 0U; } } @@ -1134,15 +1193,22 @@ void ModernOpenGLGraphics::bindArrayBufferAndAttributes(const GLuint vbo) if (mVboCached != vbo) { mVboCached = vbo; +// logger->log("bind array: %u", vbo); mglBindBuffer(GL_ARRAY_BUFFER, vbo); +/* + if (mglIsBuffer(vbo) != GL_TRUE) + logger->log("bind wrong buffer: %u", vbo); +*/ mAttributesCached = mVboCached; +// logger->log("bind vertex buffer: %u", mVboCached); mglBindVertexBuffer(0, mVboCached, 0, 4 * sizeof(GLfloat)); // mglVertexAttribBinding(mPosAttrib, 0); } else if (mAttributesCached != mVboCached) { mAttributesCached = mVboCached; +// logger->log("bind vertex buffer: %u", mVboCached); mglBindVertexBuffer(0, mVboCached, 0, 4 * sizeof(GLfloat)); // mglVertexAttribBinding(mPosAttrib, 0); } @@ -1221,12 +1287,20 @@ void ModernOpenGLGraphics::finalize(ImageVertexes *const vert) const int sz = floatTexPool.size(); vbos.resize(sz); mglGenBuffers(sz, &vbos[0]); +/* + for (int f = 0; f < sz; f ++) + logger->log("gen buffers: %u", vbos[f]); +*/ for (ft = floatTexPool.begin(), ivp = vp.begin(), ivbo = vbos.begin(); ft != ft_end && ivp != ivp_end; ++ ft, ++ ivp, ++ ivbo) { bindArrayBuffer(*ivbo); +/* + logger->log("allocate: %d, %ld", mVboCached, + (*ivp) * sizeof(GLfloat)); +*/ mglBufferData(GL_ARRAY_BUFFER, (*ivp) * sizeof(GLfloat), *ft, GL_STATIC_DRAW); } @@ -1241,6 +1315,7 @@ void ModernOpenGLGraphics::finalize(ImageVertexes *const vert) void ModernOpenGLGraphics::drawTriangleArray(const int size) { + //logger->log("allocate: %d, %ld", mVboCached, size * sizeof(GLfloat)); mglBufferData(GL_ARRAY_BUFFER, size * sizeof(GLfloat), mFloatArray, GL_STREAM_DRAW); #ifdef DEBUG_DRAW_CALLS @@ -1252,6 +1327,7 @@ void ModernOpenGLGraphics::drawTriangleArray(const int size) void ModernOpenGLGraphics::drawTriangleArray(const GLfloat *const array, const int size) { + //logger->log("allocate: %d, %ld", mVboCached, size * sizeof(GLfloat)); mglBufferData(GL_ARRAY_BUFFER, size * sizeof(GLfloat), array, GL_STREAM_DRAW); #ifdef DEBUG_DRAW_CALLS @@ -1262,6 +1338,7 @@ void ModernOpenGLGraphics::drawTriangleArray(const GLfloat *const array, void ModernOpenGLGraphics::drawLineArrays(const int size) { + //logger->log("allocate: %d, %ld", mVboCached, size * sizeof(GLfloat)); mglBufferData(GL_ARRAY_BUFFER, size * sizeof(GLfloat), mFloatArray, GL_STREAM_DRAW); #ifdef DEBUG_DRAW_CALLS diff --git a/src/render/modernopenglgraphics.h b/src/render/modernopenglgraphics.h index d3523ea65..4ee663544 100644 --- a/src/render/modernopenglgraphics.h +++ b/src/render/modernopenglgraphics.h @@ -70,6 +70,11 @@ class ModernOpenGLGraphics final : public Graphics void finalize(ImageVertexes *const vert) override final; + void testDraw() override final; + + void removeArray(const uint32_t id, + uint32_t *const arr) override final; + #include "render/graphicsdef.hpp" #include "render/openglgraphicsdef.hpp" diff --git a/src/render/normalopenglgraphics.cpp b/src/render/normalopenglgraphics.cpp index 2348fa22b..3dd5392ae 100644 --- a/src/render/normalopenglgraphics.cpp +++ b/src/render/normalopenglgraphics.cpp @@ -339,6 +339,62 @@ bool NormalOpenGLGraphics::drawImageInline(const Image *const image, return true; } +void NormalOpenGLGraphics::testDraw() +{ + if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) + { + GLfloat tex[] = + { + 0.0f, 0.0f, + 1.0f, 0.0f, + 1.0f, 1.0f, + 0.0f, 1.0f + }; + + GLint vert[] = + { + 0, 0, + 800, 0, + 800, 600, + 0, 600 + }; + + glVertexPointer(2, GL_INT, 0, &vert); + glTexCoordPointer(2, GL_FLOAT, 0, &tex); + +#ifdef DEBUG_DRAW_CALLS + NormalOpenGLGraphics::mDrawCalls ++; +#endif + glDrawArrays(GL_QUADS, 0, 4); + } + else + { + GLint tex[] = + { + 0, 0, + 800, 0, + 800, 600, + 0, 600 + }; + + GLint vert[] = + { + 0, 0, + 800, 0, + 800, 600, + 0, 600 + }; + + glVertexPointer(2, GL_INT, 0, &vert); + glTexCoordPointer(2, GL_INT, 0, &tex); + +#ifdef DEBUG_DRAW_CALLS + NormalOpenGLGraphics::mDrawCalls ++; +#endif + glDrawArrays(GL_QUADS, 0, 4); + } +} + void NormalOpenGLGraphics::drawImageCached(const Image *const image, int x, int y) { diff --git a/src/render/normalopenglgraphics.h b/src/render/normalopenglgraphics.h index 361093183..2e258c238 100644 --- a/src/render/normalopenglgraphics.h +++ b/src/render/normalopenglgraphics.h @@ -76,6 +76,8 @@ class NormalOpenGLGraphics final : public Graphics inline void drawLineArrayf(const int size); + void testDraw() override final; + #include "render/graphicsdef.hpp" #include "render/openglgraphicsdef.hpp" diff --git a/src/render/safeopenglgraphics.cpp b/src/render/safeopenglgraphics.cpp index 2fdc55e87..2027128ec 100644 --- a/src/render/safeopenglgraphics.cpp +++ b/src/render/safeopenglgraphics.cpp @@ -176,6 +176,32 @@ bool SafeOpenGLGraphics::drawImageInline(const Image *const image, return true; } +void SafeOpenGLGraphics::testDraw() +{ + if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) + { + glTexCoord2f(0.0f, 0.0f); + glVertex2i(0, 0); + glTexCoord2f(1.0f, 0.0f); + glVertex2i(800, 0); + glTexCoord2f(1.0f, 1.0f); + glVertex2i(800, 600); + glTexCoord2f(0.0f, 1.0f); + glVertex2i(0, 600); + } + else + { + glTexCoord2i(0, 0); + glVertex2i(0, 0); + glTexCoord2i(800, 0); + glVertex2i(800, 0); + glTexCoord2i(800, 600); + glVertex2i(800, 600); + glTexCoord2i(0, 600); + glVertex2i(0, 600); + } +} + void SafeOpenGLGraphics::drawImageCached(const Image *const image, int x, int y) { diff --git a/src/render/safeopenglgraphics.h b/src/render/safeopenglgraphics.h index d8b37a0d6..e5292538e 100644 --- a/src/render/safeopenglgraphics.h +++ b/src/render/safeopenglgraphics.h @@ -50,6 +50,8 @@ class SafeOpenGLGraphics final : public Graphics ~SafeOpenGLGraphics(); + void testDraw(); + #include "render/graphicsdef.hpp" #include "render/openglgraphicsdef.hpp" diff --git a/src/resources/map/maplayer.cpp b/src/resources/map/maplayer.cpp index c1f1f2d7a..746d547fd 100644 --- a/src/resources/map/maplayer.cpp +++ b/src/resources/map/maplayer.cpp @@ -276,10 +276,12 @@ void MapLayer::updateOGL(Graphics *const graphics, && debugFlags != MapType::SPECIAL2); MapRowVertexes *const row = new MapRowVertexes(); + logger->log("mTempRows size: %u", (int)mTempRows.size()); mTempRows.push_back(row); Image *lastImage = nullptr; ImageVertexes *imgVert = nullptr; - std::map<int, ImageVertexes*> imgSet; + typedef std::map<int, ImageVertexes*> ImageVertexesMap; + ImageVertexesMap imgSet; for (int y = startY; y < endY; y++) { @@ -323,7 +325,16 @@ void MapLayer::updateOGL(Graphics *const graphics, } } } - graphics->finalize(imgVert); + FOR_EACH (MapRowImages::iterator, it, row->images) + { + graphics->finalize(*it); + } +/* + FOR_EACH (ImageVertexesMap::iterator, it, imgSet) + { + graphics->finalize((*it).second); + } +*/ BLOCK_END("MapLayer::updateOGL") } diff --git a/src/test/testlauncher.cpp b/src/test/testlauncher.cpp index 7072e292d..84283ee6e 100644 --- a/src/test/testlauncher.cpp +++ b/src/test/testlauncher.cpp @@ -90,6 +90,8 @@ int TestLauncher::exec() return testDye(); else if (mTest == "102") return testDraw(); + else if (mTest == "103") + return testFps2(); return -1; } @@ -184,6 +186,39 @@ int TestLauncher::testFps() return 0; } +int TestLauncher::testFps2() +{ + timeval start; + timeval end; + + Wallpaper::loadWallpapers(); + Wallpaper::getWallpaper(800, 600); + Image *img[1]; + const int sz = 4; + + img[0] = Theme::getImageFromTheme("graphics/images/login_wallpaper.png"); + mainGraphics->drawImage(img[0], 0, 0); + int idx = 0; + + const int cnt = 500; + + gettimeofday(&start, nullptr); + for (int k = 0; k < cnt; k ++) + { + for (int f = 0; f < 300; f ++) + mainGraphics->testDraw(); + mainGraphics->updateScreen(); + } + + gettimeofday(&end, nullptr); + const int tFps = calcFps(&start, &end, cnt); + file << mTest << std::endl; + file << tFps << std::endl; + + sleep(1); + return 0; +} + int TestLauncher::testBatches() { int batches = 512; diff --git a/src/test/testlauncher.h b/src/test/testlauncher.h index ed2b9251f..bc5d93ea8 100644 --- a/src/test/testlauncher.h +++ b/src/test/testlauncher.h @@ -56,6 +56,8 @@ class TestLauncher final int testFps(); + int testFps2(); + int testInternal(); int testDye(); |