summaryrefslogtreecommitdiff
path: root/src/render
diff options
context:
space:
mode:
Diffstat (limited to 'src/render')
-rw-r--r--src/render/graphics.h7
-rw-r--r--src/render/mgl.cpp1
-rw-r--r--src/render/mgl.h1
-rw-r--r--src/render/mgltypes.h1
-rw-r--r--src/render/modernopenglgraphics.cpp77
-rw-r--r--src/render/modernopenglgraphics.h5
-rw-r--r--src/render/normalopenglgraphics.cpp56
-rw-r--r--src/render/normalopenglgraphics.h2
-rw-r--r--src/render/safeopenglgraphics.cpp26
-rw-r--r--src/render/safeopenglgraphics.h2
10 files changed, 178 insertions, 0 deletions
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"