From 12a8f590f8f1300780ca2e8e3e46316a3cb4321b Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Thu, 25 Aug 2011 04:02:11 -0500 Subject: [PATCH 01/28] Remove immediate mode from the Texture converter, probably need to redo this for texcache rewrite :/ --- .../Plugin_VideoOGL/Src/TextureConverter.cpp | 48 ++++++++++++++----- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp index c715775194..ad457996b2 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp @@ -213,13 +213,24 @@ void EncodeToRamUsingShader(FRAGMENTSHADER& shader, GLuint srcTexture, const Tar PixelShaderCache::SetCurrentShader(shader.glprogid); - // Draw... - glBegin(GL_QUADS); - glTexCoord2f((float)sourceRc.left, (float)sourceRc.top); glVertex2f(-1,-1); - glTexCoord2f((float)sourceRc.left, (float)sourceRc.bottom); glVertex2f(-1,1); - glTexCoord2f((float)sourceRc.right, (float)sourceRc.bottom); glVertex2f(1,1); - glTexCoord2f((float)sourceRc.right, (float)sourceRc.top); glVertex2f(1,-1); - glEnd(); + GL_REPORT_ERRORD(); + + GLfloat tex1[] = { + (float)sourceRc.left, (float)sourceRc.top, + (float)sourceRc.left, (float)sourceRc.bottom, + (float)sourceRc.right, (float)sourceRc.bottom, + (float)sourceRc.right, (float)sourceRc.top + }; + GLfloat vtx1[] = { + -1, -1, 1, + -1, 1, 1, + 1, 1, 1, + 1, -1, 1 + }; + glTexCoordPointer(2, GL_FLOAT, 0, tex1); + glVertexPointer(3, GL_FLOAT, 0, vtx1); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + GL_REPORT_ERRORD(); // .. and then read back the results. @@ -458,12 +469,23 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur GL_REPORT_ERRORD(); - glBegin(GL_QUADS); - glTexCoord2f((float)srcFmtWidth, (float)srcHeight); glVertex2f(1,-1); - glTexCoord2f((float)srcFmtWidth, 0); glVertex2f(1,1); - glTexCoord2f(0, 0); glVertex2f(-1,1); - glTexCoord2f(0, (float)srcHeight); glVertex2f(-1,-1); - glEnd(); + GLfloat tex1[] = { + (float)srcFmtWidth, (float)srcHeight, + (float)srcFmtWidth, 0, + 0, 0, + 0, (float)srcHeight + }; + GLfloat vtx1[] = { + 1, -1, 1, + 1, 1, 1, + -1, 1, 1, + -1, -1, 1 + }; + glTexCoordPointer(2, GL_FLOAT, 0, tex1); + glVertexPointer(3, GL_FLOAT, 0, vtx1); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + GL_REPORT_ERRORD(); // reset state glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); From d021f9e3b65f507273d0a9b8bea2db46db9f062c Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Thu, 25 Aug 2011 04:28:29 -0500 Subject: [PATCH 02/28] Here we go with the texture cache --- .../Plugin_VideoOGL/Src/TextureCache.cpp | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp index 4a9431a563..55e20c0b05 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp @@ -302,12 +302,24 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo TargetRectangle targetSource = g_renderer->ConvertEFBRectangle(srcRect); - glBegin(GL_QUADS); - glTexCoord2f((GLfloat)targetSource.left, (GLfloat)targetSource.bottom); glVertex2f(-1, 1); - glTexCoord2f((GLfloat)targetSource.left, (GLfloat)targetSource.top ); glVertex2f(-1, -1); - glTexCoord2f((GLfloat)targetSource.right, (GLfloat)targetSource.top ); glVertex2f( 1, -1); - glTexCoord2f((GLfloat)targetSource.right, (GLfloat)targetSource.bottom); glVertex2f( 1, 1); - glEnd(); + GL_REPORT_ERRORD(); + + GLfloat tex1[] = { + (GLfloat)targetSource.left, (GLfloat)targetSource.bottom, + (GLfloat)targetSource.left, (GLfloat)targetSource.top, + (GLfloat)targetSource.right, (GLfloat)targetSource.top, + (GLfloat)targetSource.right, (GLfloat)targetSource.bottom + }; + GLfloat vtx1[] = { + -1, 1, 1, + -1, -1, 1, + 1, -1, 1, + 1, 1, 1 + }; + glTexCoordPointer(2, GL_FLOAT, 0, tex1); + glVertexPointer(3, GL_FLOAT, 0, vtx1); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + GL_REPORT_ERRORD(); From 31fd25bf6138fae81af19d7c264cdefe3c5086a2 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Thu, 25 Aug 2011 04:41:45 -0500 Subject: [PATCH 03/28] Move on to XFB drawing --- .../Src/FramebufferManager.cpp | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp index 0e37c3adb6..79189d4309 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp @@ -305,23 +305,30 @@ void XFBSource::Draw(const MathUtil::Rectangle &sourcerc, glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture); - glBegin(GL_QUADS); - glTexCoord2f(sourcerc.left, sourcerc.bottom); + GLfloat vtx1[] = { + drawrc.left, drawrc.bottom, 1, + drawrc.left, drawrc.top, 1, + drawrc.right, drawrc.top, 1, + drawrc.right, drawrc.bottom, 1 + }; + GLfloat tex1[] = { // For TEXTURE0 + sourcerc.left, sourcerc.bottom, + sourcerc.left, sourcerc.top, + sourcerc.right, sourcerc.top, + sourcerc.right, sourcerc.bottom + }; + + glClientActiveTexture(GL_TEXTURE0); + glTexCoordPointer(2, GL_FLOAT, 0, tex1); + + // Is this correct? glMultiTexCoord2fARB(GL_TEXTURE1, 0, 0); - glVertex2f(drawrc.left, drawrc.bottom); - - glTexCoord2f(sourcerc.left, sourcerc.top); glMultiTexCoord2fARB(GL_TEXTURE1, 0, 1); - glVertex2f(drawrc.left, drawrc.top); - - glTexCoord2f(sourcerc.right, sourcerc.top); glMultiTexCoord2fARB(GL_TEXTURE1, 1, 1); - glVertex2f(drawrc.right, drawrc.top); - - glTexCoord2f(sourcerc.right, sourcerc.bottom); glMultiTexCoord2fARB(GL_TEXTURE1, 1, 0); - glVertex2f(drawrc.right, drawrc.bottom); - glEnd(); + + glVertexPointer(3, GL_FLOAT, 0, vtx1); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); GL_REPORT_ERRORD(); } From 5a6a2b2bec29e71efd8dda61bf6fb5aad4a45020 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Thu, 25 Aug 2011 05:20:41 -0500 Subject: [PATCH 04/28] Do clearscreen and swap, probably won't do debug text nonsense since it looks like trash anyway. maybe later. --- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 95 +++++++++++-------- 1 file changed, 55 insertions(+), 40 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 0c9d904cad..a0640d7294 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -888,16 +888,39 @@ void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaE glViewport(targetRc.left, targetRc.bottom, targetRc.GetWidth(), targetRc.GetHeight()); glDepthRange(0.0, (float)(z & 0xFFFFFF) / float(0xFFFFFF)); - glColor4f((float)((color >> 16) & 0xFF) / 255.0f, - (float)((color >> 8) & 0xFF) / 255.0f, - (float)(color & 0xFF) / 255.0f, - (float)((color >> 24) & 0xFF) / 255.0f); - glBegin(GL_QUADS); - glVertex3f(-1.f, -1.f, 1.f); - glVertex3f(-1.f, 1.f, 1.f); - glVertex3f( 1.f, 1.f, 1.f); - glVertex3f( 1.f, -1.f, 1.f); - glEnd(); + GLfloat vtx1[] = { + -1, -1, 1, + -1, 1, 1, + 1, 1, 1, + 1, -1, 1 + }; + GLfloat col1[] = { // This looks terrible + (float)((color >> 16) & 0xFF) / 255.0f, + (float)((color >> 8) & 0xFF) / 255.0f, + (float)(color & 0xFF) / 255.0f, + (float)((color >> 24) & 0xFF) / 255.0f, + + (float)((color >> 16) & 0xFF) / 255.0f, + (float)((color >> 8) & 0xFF) / 255.0f, + (float)(color & 0xFF) / 255.0f, + (float)((color >> 24) & 0xFF) / 255.0f, + + (float)((color >> 16) & 0xFF) / 255.0f, + (float)((color >> 8) & 0xFF) / 255.0f, + (float)(color & 0xFF) / 255.0f, + (float)((color >> 24) & 0xFF) / 255.0f, + + (float)((color >> 16) & 0xFF) / 255.0f, + (float)((color >> 8) & 0xFF) / 255.0f, + (float)(color & 0xFF) / 255.0f, + (float)((color >> 24) & 0xFF) / 255.0f + }; + glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); // Only need this to not overwrite the GL_COLOR_ARRAY state + glEnableClientState(GL_COLOR_ARRAY); + glColorPointer(4, GL_FLOAT, 0 ,col1); + glVertexPointer(3, GL_FLOAT, 0, vtx1); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + glPopClientAttrib(); RestoreAPIState(); } @@ -1115,43 +1138,35 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons // Render to the real buffer now. glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // switch to the window backbuffer glBindTexture(GL_TEXTURE_RECTANGLE_ARB, read_texture); + + GLfloat vtx1[] = { + -1, -1, 1, + -1, 1, 1, + 1, 1, 1, + 1, -1, 1 + }; + GLfloat tex1[] = { // For TEXTURE0 + targetRc.left, targetRc.bottom, + targetRc.left, targetRc.top, + targetRc.right, targetRc.top, + targetRc.right, targetRc.bottom + }; + + glClientActiveTexture(GL_TEXTURE0); + glTexCoordPointer(2, GL_FLOAT, 0, tex1); + if (applyShader) { - glBegin(GL_QUADS); - glTexCoord2f(targetRc.left, targetRc.bottom); glMultiTexCoord2fARB(GL_TEXTURE1, 0, 0); - glVertex2f(-1, -1); - - glTexCoord2f(targetRc.left, targetRc.top); glMultiTexCoord2fARB(GL_TEXTURE1, 0, 1); - glVertex2f(-1, 1); - - glTexCoord2f(targetRc.right, targetRc.top); glMultiTexCoord2fARB(GL_TEXTURE1, 1, 1); - glVertex2f( 1, 1); - - glTexCoord2f(targetRc.right, targetRc.bottom); glMultiTexCoord2fARB(GL_TEXTURE1, 1, 0); - glVertex2f( 1, -1); - glEnd(); + } + + glVertexPointer(3, GL_FLOAT, 0, vtx1); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + if(applyShader) PixelShaderCache::DisableShader(); - } - else - { - glBegin(GL_QUADS); - glTexCoord2f(targetRc.left, targetRc.bottom); - glVertex2f(-1, -1); - - glTexCoord2f(targetRc.left, targetRc.top); - glVertex2f(-1, 1); - - glTexCoord2f(targetRc.right, targetRc.top); - glVertex2f( 1, 1); - - glTexCoord2f(targetRc.right, targetRc.bottom); - glVertex2f( 1, -1); - glEnd(); - } } glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); From 8c1d104ca36f1dba5e0b347940fe5ebc465e7758 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Sat, 27 Oct 2012 18:10:31 -0500 Subject: [PATCH 05/28] Change EFB copy location rectangles over to a Vertex array --- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 52 +++++++++++++------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 1a9f02c37e..fa3c3ed5c5 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -543,11 +543,13 @@ void Renderer::DrawDebugInfo() // Set Line Size glLineWidth(3.0f); - glBegin(GL_LINES); + GLfloat *RectPoints = new GLfloat[stats.efb_regions.size() * 16]; + GLfloat *Colours = new GLfloat[stats.efb_regions.size() * 3]; // Draw EFB copy regions rectangles + int a = 0; for (std::vector::const_iterator it = stats.efb_regions.begin(); - it != stats.efb_regions.end(); ++it) + it != stats.efb_regions.end(); ++it, ++a) { GLfloat halfWidth = EFB_WIDTH / 2.0f; GLfloat halfHeight = EFB_HEIGHT / 2.0f; @@ -556,22 +558,40 @@ void Renderer::DrawDebugInfo() GLfloat x2 = (GLfloat) -1.0f + ((GLfloat)it->right / halfWidth); GLfloat y2 = (GLfloat) 1.0f - ((GLfloat)it->bottom / halfHeight); - // Draw shadow of rect - glColor3f(0.0f, 0.0f, 0.0f); - glVertex2f(x, y - 0.01); glVertex2f(x2, y - 0.01); - glVertex2f(x, y2 - 0.01); glVertex2f(x2, y2 - 0.01); - glVertex2f(x + 0.005, y); glVertex2f(x + 0.005, y2); - glVertex2f(x2 + 0.005, y); glVertex2f(x2 + 0.005, y2); + Colours[a * 3] = 0.0f; + Colours[a * 3 + 1] = 1.0f; + Colours[a * 3 + 2] = 1.0f; - // Draw rect - glColor3f(0.0f, 1.0f, 1.0f); - glVertex2f(x, y); glVertex2f(x2, y); - glVertex2f(x, y2); glVertex2f(x2, y2); - glVertex2f(x, y); glVertex2f(x, y2); - glVertex2f(x2, y); glVertex2f(x2, y2); + RectPoints[a * 16] = x; + RectPoints[a * 16 + 1] = y; + + RectPoints[a * 16 + 2] = x2; + RectPoints[a * 16 + 3] = y; + + RectPoints[a * 16 + 4] = x; + RectPoints[a * 16 + 5] = y2; + + RectPoints[a * 16 + 6] = x2; + RectPoints[a * 16 + 7] = y2; + + RectPoints[a * 16 + 8] = x; + RectPoints[a * 16 + 9] = y; + + RectPoints[a * 16 + 10] = x; + RectPoints[a * 16 + 11] = y2; + + RectPoints[a * 16 + 12] = x2; + RectPoints[a * 16 + 13] = y; + + RectPoints[a * 16 + 14] = x2; + RectPoints[a * 16 + 15] = y2; } - - glEnd(); + + glColorPointer (3, GL_FLOAT, 0, Colours); + glVertexPointer(2, GL_FLOAT, 0, RectPoints); + glDrawArrays(GL_LINE_STRIP, 0, stats.efb_regions.size() * 8); + delete[] RectPoints; + delete[] Colours; // Restore Line Size glLineWidth(lSize); From dfb3c44d1a9b641f71ac4a93cd871b8d69dde542 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Sat, 27 Oct 2012 18:27:16 -0500 Subject: [PATCH 06/28] Remove glMatrixMode and glLoadIdentity calls in Render.cpp which do absolutely nothing. --- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index fa3c3ed5c5..12f38f89f3 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -458,11 +458,6 @@ Renderer::Renderer() glViewport(0, 0, GetTargetWidth(), GetTargetHeight()); // Reset The Current Viewport - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClearDepth(1.0f); @@ -479,11 +474,6 @@ Renderer::Renderer() glBlendColorEXT(0, 0, 0, 0.5f); glClearDepth(1.0f); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - // legacy multitexturing: select texture channel only. glActiveTexture(GL_TEXTURE0); glClientActiveTexture(GL_TEXTURE0); From fb92c338af83a56edaabaea13168696e3cf1c7c7 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Sat, 27 Oct 2012 22:50:06 -0500 Subject: [PATCH 07/28] Bit of cleanup and fixing of one issue that was noticeable in SMS with Mario's shadow. --- .../Src/FramebufferManager.cpp | 24 +++++++-------- .../Src/NativeVertexFormat.cpp | 4 --- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 14 +++++---- .../Plugin_VideoOGL/Src/TextureCache.cpp | 21 +++++++------- .../Plugin_VideoOGL/Src/TextureConverter.cpp | 29 ++++++++++--------- 5 files changed, 46 insertions(+), 46 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp index 79189d4309..76e4b8156b 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp @@ -306,10 +306,10 @@ void XFBSource::Draw(const MathUtil::Rectangle &sourcerc, glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture); GLfloat vtx1[] = { - drawrc.left, drawrc.bottom, 1, - drawrc.left, drawrc.top, 1, - drawrc.right, drawrc.top, 1, - drawrc.right, drawrc.bottom, 1 + drawrc.left, drawrc.bottom, + drawrc.left, drawrc.top, + drawrc.right, drawrc.top, + drawrc.right, drawrc.bottom, }; GLfloat tex1[] = { // For TEXTURE0 sourcerc.left, sourcerc.bottom, @@ -319,17 +319,17 @@ void XFBSource::Draw(const MathUtil::Rectangle &sourcerc, }; glClientActiveTexture(GL_TEXTURE0); - glTexCoordPointer(2, GL_FLOAT, 0, tex1); - // Is this correct? - glMultiTexCoord2fARB(GL_TEXTURE1, 0, 0); - glMultiTexCoord2fARB(GL_TEXTURE1, 0, 1); - glMultiTexCoord2fARB(GL_TEXTURE1, 1, 1); - glMultiTexCoord2fARB(GL_TEXTURE1, 1, 0); - - glVertexPointer(3, GL_FLOAT, 0, vtx1); + glMultiTexCoord2f(GL_TEXTURE1, 0, 0); + glMultiTexCoord2f(GL_TEXTURE1, 0, 1); + glMultiTexCoord2f(GL_TEXTURE1, 1, 1); + glMultiTexCoord2f(GL_TEXTURE1, 1, 0); + + glVertexPointer(2, GL_FLOAT, 0, vtx1); + glTexCoordPointer(2, GL_FLOAT, 0, tex1); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + GL_REPORT_ERRORD(); } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp b/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp index ae20649433..0cbf878799 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp @@ -274,10 +274,6 @@ void GLVertexFormat::EnableComponents(u32 components) if ((components & (VB_HAS_UV0 << i)) != (s_prevcomponents & (VB_HAS_UV0 << i))) { glClientActiveTexture(GL_TEXTURE0 + i); - if (components & (VB_HAS_UV0 << i)) - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - else - glDisableClientState(GL_TEXTURE_COORD_ARRAY); } } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 12f38f89f3..00f971a31b 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -474,6 +474,7 @@ Renderer::Renderer() glBlendColorEXT(0, 0, 0, 0.5f); glClearDepth(1.0f); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); // legacy multitexturing: select texture channel only. glActiveTexture(GL_TEXTURE0); glClientActiveTexture(GL_TEXTURE0); @@ -1154,18 +1155,19 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons }; glClientActiveTexture(GL_TEXTURE0); - glTexCoordPointer(2, GL_FLOAT, 0, tex1); if (applyShader) { - glMultiTexCoord2fARB(GL_TEXTURE1, 0, 0); - glMultiTexCoord2fARB(GL_TEXTURE1, 0, 1); - glMultiTexCoord2fARB(GL_TEXTURE1, 1, 1); - glMultiTexCoord2fARB(GL_TEXTURE1, 1, 0); + glMultiTexCoord2f(GL_TEXTURE1, 0, 0); + glMultiTexCoord2f(GL_TEXTURE1, 0, 1); + glMultiTexCoord2f(GL_TEXTURE1, 1, 1); + glMultiTexCoord2f(GL_TEXTURE1, 1, 0); } - + glVertexPointer(3, GL_FLOAT, 0, vtx1); + glTexCoordPointer(2, GL_FLOAT, 0, tex1); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + if(applyShader) PixelShaderCache::DisableShader(); } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp index 052727e1b0..797ba39c10 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp @@ -306,23 +306,22 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo TargetRectangle targetSource = g_renderer->ConvertEFBRectangle(srcRect); GL_REPORT_ERRORD(); - GLfloat tex1[] = { - (GLfloat)targetSource.left, (GLfloat)targetSource.bottom, - (GLfloat)targetSource.left, (GLfloat)targetSource.top, - (GLfloat)targetSource.right, (GLfloat)targetSource.top, - (GLfloat)targetSource.right, (GLfloat)targetSource.bottom + (GLfloat)targetSource.left, (GLfloat)targetSource.bottom, + (GLfloat)targetSource.left, (GLfloat)targetSource.top, + (GLfloat)targetSource.right, (GLfloat)targetSource.top, + (GLfloat)targetSource.right, (GLfloat)targetSource.bottom }; GLfloat vtx1[] = { - -1, 1, 1, - -1, -1, 1, - 1, -1, 1, - 1, 1, 1 + -1.f, 1.f, + -1.f, -1.f, + 1.f, -1.f, + 1.f, 1.f }; + glTexCoordPointer(2, GL_FLOAT, 0, tex1); - glVertexPointer(3, GL_FLOAT, 0, vtx1); + glVertexPointer(2, GL_FLOAT, 0, vtx1); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - GL_REPORT_ERRORD(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp index 64ac6ba888..306fa5e298 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp @@ -222,13 +222,14 @@ void EncodeToRamUsingShader(FRAGMENTSHADER& shader, GLuint srcTexture, const Tar (float)sourceRc.right, (float)sourceRc.top }; GLfloat vtx1[] = { - -1, -1, 1, - -1, 1, 1, - 1, 1, 1, - 1, -1, 1 + -1.f, -1.f, + -1.f, 1.f, + 1.f, 1.f, + 1.f, -1.f }; + glTexCoordPointer(2, GL_FLOAT, 0, tex1); - glVertexPointer(3, GL_FLOAT, 0, vtx1); + glVertexPointer(2, GL_FLOAT, 0, vtx1); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); GL_REPORT_ERRORD(); @@ -389,20 +390,22 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur GLfloat tex1[] = { (float)srcFmtWidth, (float)srcHeight, - (float)srcFmtWidth, 0, - 0, 0, - 0, (float)srcHeight + (float)srcFmtWidth, 0.f, + 0.f, 0.f, + 0.f, (float)srcHeight }; GLfloat vtx1[] = { - 1, -1, 1, - 1, 1, 1, - -1, 1, 1, - -1, -1, 1 + 1.f, -1.f, + 1.f, 1.f, + -1.f, 1.f, + -1.f, -1.f }; + glTexCoordPointer(2, GL_FLOAT, 0, tex1); - glVertexPointer(3, GL_FLOAT, 0, vtx1); + glVertexPointer(2, GL_FLOAT, 0, vtx1); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + GL_REPORT_ERRORD(); // reset state From 888b5fb061363d6ce644d7ebacb76b82778801c4 Mon Sep 17 00:00:00 2001 From: degasus Date: Fri, 7 Dec 2012 14:40:52 +0100 Subject: [PATCH 08/28] remove usage of glMultiTexCoord2f Signed-off-by: Ryan Houdek --- .../Plugin_VideoOGL/Src/FramebufferManager.cpp | 15 +++++++++------ Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 14 +++++++++----- .../Plugins/Plugin_VideoOGL/Src/TextureCache.cpp | 1 + .../Plugin_VideoOGL/Src/TextureConverter.cpp | 2 ++ 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp index 76e4b8156b..7e3244f634 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp @@ -317,16 +317,19 @@ void XFBSource::Draw(const MathUtil::Rectangle &sourcerc, sourcerc.right, sourcerc.top, sourcerc.right, sourcerc.bottom }; + GLfloat tex2[] = { // For TEXTURE1 + 0.0f, 0.0f, + 0.0f, 1.0f, + 1.0f, 1.0f, + 1.0f, 0.0f + }; - glClientActiveTexture(GL_TEXTURE0); - - glMultiTexCoord2f(GL_TEXTURE1, 0, 0); - glMultiTexCoord2f(GL_TEXTURE1, 0, 1); - glMultiTexCoord2f(GL_TEXTURE1, 1, 1); - glMultiTexCoord2f(GL_TEXTURE1, 1, 0); glVertexPointer(2, GL_FLOAT, 0, vtx1); + glClientActiveTexture(GL_TEXTURE0); glTexCoordPointer(2, GL_FLOAT, 0, tex1); + glClientActiveTexture(GL_TEXTURE1); + glTexCoordPointer(2, GL_FLOAT, 0, tex2); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 00f971a31b..d912277150 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -1153,18 +1153,22 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons right, top, right, bottom }; + GLfloat tex2[] = { // For TEXTURE1 + 0.0f, 0.0f, + 0.0f, 1.0f, + 1.0f, 1.0f, + 1.0f, 0.0f + }; - glClientActiveTexture(GL_TEXTURE0); if (applyShader) { - glMultiTexCoord2f(GL_TEXTURE1, 0, 0); - glMultiTexCoord2f(GL_TEXTURE1, 0, 1); - glMultiTexCoord2f(GL_TEXTURE1, 1, 1); - glMultiTexCoord2f(GL_TEXTURE1, 1, 0); + glClientActiveTexture(GL_TEXTURE1); + glTexCoordPointer(2, GL_FLOAT, 0, tex2); } glVertexPointer(3, GL_FLOAT, 0, vtx1); + glClientActiveTexture(GL_TEXTURE0); glTexCoordPointer(2, GL_FLOAT, 0, tex1); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp index 797ba39c10..6827539ce8 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp @@ -319,6 +319,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo 1.f, 1.f }; + glClientActiveTexture(GL_TEXTURE0); glTexCoordPointer(2, GL_FLOAT, 0, tex1); glVertexPointer(2, GL_FLOAT, 0, vtx1); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp index 306fa5e298..86e4d09301 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp @@ -228,6 +228,7 @@ void EncodeToRamUsingShader(FRAGMENTSHADER& shader, GLuint srcTexture, const Tar 1.f, -1.f }; + glClientActiveTexture(GL_TEXTURE0); glTexCoordPointer(2, GL_FLOAT, 0, tex1); glVertexPointer(2, GL_FLOAT, 0, vtx1); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); @@ -401,6 +402,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur -1.f, -1.f }; + glClientActiveTexture(GL_TEXTURE0); glTexCoordPointer(2, GL_FLOAT, 0, tex1); glVertexPointer(2, GL_FLOAT, 0, vtx1); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); From 6864b40e26354f6b366e8fe8c2ff4f6680f09189 Mon Sep 17 00:00:00 2001 From: degasus Date: Fri, 7 Dec 2012 21:09:48 +0100 Subject: [PATCH 09/28] reset glEnableClientState befor every draw should be done with VAO, but atm, this is not possible :-( this also partial revert the fix in fb92c338af83 (activating texture0 globally). Signed-off-by: Ryan Houdek --- .../Src/FramebufferManager.cpp | 17 +++++++++ .../Src/NativeVertexFormat.cpp | 38 ++++++++++--------- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 33 ++++++++++++++-- .../Plugin_VideoOGL/Src/TextureCache.cpp | 15 ++++++++ .../Plugin_VideoOGL/Src/TextureConverter.cpp | 15 ++++++++ .../Plugin_VideoOGL/Src/VertexManager.cpp | 3 -- 6 files changed, 97 insertions(+), 24 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp index 7e3244f634..8c3c3f3fca 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp @@ -17,6 +17,7 @@ #include "Globals.h" #include "FramebufferManager.h" +#include "VertexShaderGen.h" #include "TextureConverter.h" #include "Render.h" @@ -324,6 +325,22 @@ void XFBSource::Draw(const MathUtil::Rectangle &sourcerc, 1.0f, 0.0f }; + // disable all pointer, TODO: use VAO + glEnableClientState(GL_VERTEX_ARRAY); + glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB); + glDisableClientState(GL_NORMAL_ARRAY); + glDisableVertexAttribArray(SHADER_NORM1_ATTRIB); + glDisableVertexAttribArray(SHADER_NORM2_ATTRIB); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_SECONDARY_COLOR_ARRAY); + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glClientActiveTexture(GL_TEXTURE1); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + for(int i=2; i<8; i++) { + glClientActiveTexture(GL_TEXTURE0 + i); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } glVertexPointer(2, GL_FLOAT, 0, vtx1); glClientActiveTexture(GL_TEXTURE0); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp b/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp index 0cbf878799..14035c0634 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp @@ -27,8 +27,9 @@ #define COMPILED_CODE_SIZE 4096 -// TODO: this guy is never initialized -u32 s_prevcomponents; // previous state set +// TODO: Use this again for performance, but without VAO we never know exactly the last configuration +static u32 s_prevcomponents; // previous state set + /* #ifdef _WIN32 #ifdef _M_IX86 @@ -64,7 +65,6 @@ public: virtual void Initialize(const PortableVertexDeclaration &_vtx_decl); virtual void SetupVertexPointers(); - virtual void EnableComponents(u32 components); }; namespace OGL @@ -219,34 +219,32 @@ void GLVertexFormat::SetupVertexPointers() { glVertexAttribPointer(SHADER_POSMTX_ATTRIB, 4, GL_UNSIGNED_BYTE, GL_FALSE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.posmtx_offset)); } #endif -} -void GLVertexFormat::EnableComponents(u32 components) -{ - if (s_prevcomponents != components) +// if (s_prevcomponents != m_components) { - VertexManager::Flush(); + // vertices + glEnableClientState(GL_VERTEX_ARRAY); // matrices - if ((components & VB_HAS_POSMTXIDX) != (s_prevcomponents & VB_HAS_POSMTXIDX)) +// if ((m_components & VB_HAS_POSMTXIDX) != (s_prevcomponents & VB_HAS_POSMTXIDX)) { - if (components & VB_HAS_POSMTXIDX) + if (m_components & VB_HAS_POSMTXIDX) glEnableVertexAttribArray(SHADER_POSMTX_ATTRIB); else glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB); } // normals - if ((components & VB_HAS_NRM0) != (s_prevcomponents & VB_HAS_NRM0)) +// if ((m_components & VB_HAS_NRM0) != (s_prevcomponents & VB_HAS_NRM0)) { - if (components & VB_HAS_NRM0) + if (m_components & VB_HAS_NRM0) glEnableClientState(GL_NORMAL_ARRAY); else glDisableClientState(GL_NORMAL_ARRAY); } - if ((components & VB_HAS_NRM1) != (s_prevcomponents & VB_HAS_NRM1)) +// if ((m_components & VB_HAS_NRM1) != (s_prevcomponents & VB_HAS_NRM1)) { - if (components & VB_HAS_NRM1) { + if (m_components & VB_HAS_NRM1) { glEnableVertexAttribArray(SHADER_NORM1_ATTRIB); glEnableVertexAttribArray(SHADER_NORM2_ATTRIB); } @@ -259,9 +257,9 @@ void GLVertexFormat::EnableComponents(u32 components) // color for (int i = 0; i < 2; ++i) { - if ((components & (VB_HAS_COL0 << i)) != (s_prevcomponents & (VB_HAS_COL0 << i))) +// if ((m_components & (VB_HAS_COL0 << i)) != (s_prevcomponents & (VB_HAS_COL0 << i))) { - if (components & (VB_HAS_COL0 << i)) + if (m_components & (VB_HAS_COL0 << i)) glEnableClientState(i ? GL_SECONDARY_COLOR_ARRAY : GL_COLOR_ARRAY); else glDisableClientState(i ? GL_SECONDARY_COLOR_ARRAY : GL_COLOR_ARRAY); @@ -271,12 +269,16 @@ void GLVertexFormat::EnableComponents(u32 components) // tex for (int i = 0; i < 8; ++i) { - if ((components & (VB_HAS_UV0 << i)) != (s_prevcomponents & (VB_HAS_UV0 << i))) +// if ((m_components & (VB_HAS_UV0 << i)) != (s_prevcomponents & (VB_HAS_UV0 << i))) { glClientActiveTexture(GL_TEXTURE0 + i); + if (m_components & (VB_HAS_UV0 << i)) + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + else + glDisableClientState(GL_TEXTURE_COORD_ARRAY); } } - s_prevcomponents = components; + s_prevcomponents = m_components; } } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index d912277150..3b7205867d 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -474,7 +474,6 @@ Renderer::Renderer() glBlendColorEXT(0, 0, 0, 0.5f); glClearDepth(1.0f); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); // legacy multitexturing: select texture channel only. glActiveTexture(GL_TEXTURE0); glClientActiveTexture(GL_TEXTURE0); @@ -578,6 +577,19 @@ void Renderer::DrawDebugInfo() RectPoints[a * 16 + 15] = y2; } + // disable all pointer, TODO: use VAO + glEnableClientState(GL_VERTEX_ARRAY); + glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB); + glDisableClientState(GL_NORMAL_ARRAY); + glDisableVertexAttribArray(SHADER_NORM1_ATTRIB); + glDisableVertexAttribArray(SHADER_NORM2_ATTRIB); + glEnableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_SECONDARY_COLOR_ARRAY); + for(int i=0; i<8; i++) { + glClientActiveTexture(GL_TEXTURE0 + i); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } + glColorPointer (3, GL_FLOAT, 0, Colours); glVertexPointer(2, GL_FLOAT, 0, RectPoints); glDrawArrays(GL_LINE_STRIP, 0, stats.efb_regions.size() * 8); @@ -1159,14 +1171,29 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons 1.0f, 1.0f, 1.0f, 0.0f }; - + + // disable all pointer, TODO: use VAO + glEnableClientState(GL_VERTEX_ARRAY); + glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB); + glDisableClientState(GL_NORMAL_ARRAY); + glDisableVertexAttribArray(SHADER_NORM1_ATTRIB); + glDisableVertexAttribArray(SHADER_NORM2_ATTRIB); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_SECONDARY_COLOR_ARRAY); + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + for(int i=1; i<8; i++) { + glClientActiveTexture(GL_TEXTURE0 + i); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } if (applyShader) { glClientActiveTexture(GL_TEXTURE1); glTexCoordPointer(2, GL_FLOAT, 0, tex2); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); } - + glVertexPointer(3, GL_FLOAT, 0, vtx1); glClientActiveTexture(GL_TEXTURE0); glTexCoordPointer(2, GL_FLOAT, 0, tex1); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp index 6827539ce8..5441a65901 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp @@ -319,6 +319,21 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo 1.f, 1.f }; + // disable all pointer, TODO: use VAO + glEnableClientState(GL_VERTEX_ARRAY); + glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB); + glDisableClientState(GL_NORMAL_ARRAY); + glDisableVertexAttribArray(SHADER_NORM1_ATTRIB); + glDisableVertexAttribArray(SHADER_NORM2_ATTRIB); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_SECONDARY_COLOR_ARRAY); + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + for(int i=1; i<8; i++) { + glClientActiveTexture(GL_TEXTURE0 + i); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } + glClientActiveTexture(GL_TEXTURE0); glTexCoordPointer(2, GL_FLOAT, 0, tex1); glVertexPointer(2, GL_FLOAT, 0, vtx1); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp index 86e4d09301..3159909789 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp @@ -228,6 +228,21 @@ void EncodeToRamUsingShader(FRAGMENTSHADER& shader, GLuint srcTexture, const Tar 1.f, -1.f }; + // disable all pointer, TODO: use VAO + glEnableClientState(GL_VERTEX_ARRAY); + glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB); + glDisableClientState(GL_NORMAL_ARRAY); + glDisableVertexAttribArray(SHADER_NORM1_ATTRIB); + glDisableVertexAttribArray(SHADER_NORM2_ATTRIB); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_SECONDARY_COLOR_ARRAY); + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + for(int i=1; i<8; i++) { + glClientActiveTexture(GL_TEXTURE0 + i); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } + glClientActiveTexture(GL_TEXTURE0); glTexCoordPointer(2, GL_FLOAT, 0, tex1); glVertexPointer(2, GL_FLOAT, 0, vtx1); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp index 501c4969e5..3725d87add 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp @@ -64,9 +64,6 @@ VertexManager::VertexManager() // max_Index_size = MAXIBUFFERSIZE; // //GL_REPORT_ERRORD(); - - glEnableClientState(GL_VERTEX_ARRAY); - GL_REPORT_ERRORD(); } void VertexManager::CreateDeviceObjects() From 8b62be20253a282edc8308cd3ce541be5ecbbb70 Mon Sep 17 00:00:00 2001 From: degasus Date: Fri, 7 Dec 2012 22:49:18 +0100 Subject: [PATCH 10/28] fix ShowEFBCopyRegions those fancy colors were the result of the usage of non-allocated heap Signed-off-by: Ryan Houdek --- Source/Core/VideoCommon/Src/BPFunctions.cpp | 2 +- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 122 +++++++++++++----- 2 files changed, 90 insertions(+), 34 deletions(-) diff --git a/Source/Core/VideoCommon/Src/BPFunctions.cpp b/Source/Core/VideoCommon/Src/BPFunctions.cpp index cddeae3000..b9a76ba7b6 100644 --- a/Source/Core/VideoCommon/Src/BPFunctions.cpp +++ b/Source/Core/VideoCommon/Src/BPFunctions.cpp @@ -236,7 +236,7 @@ bool GetConfig(const int &type) case CONFIG_DISABLEFOG: return g_ActiveConfig.bDisableFog; case CONFIG_SHOWEFBREGIONS: - return false; + return g_ActiveConfig.bShowEFBCopyRegions; default: PanicAlert("GetConfig Error: Unknown Config Type!"); return false; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 3b7205867d..56991457e1 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -533,13 +533,15 @@ void Renderer::DrawDebugInfo() // Set Line Size glLineWidth(3.0f); - GLfloat *RectPoints = new GLfloat[stats.efb_regions.size() * 16]; - GLfloat *Colours = new GLfloat[stats.efb_regions.size() * 3]; + // 2*Coords + 3*Color + GLfloat *Vertices = new GLfloat[stats.efb_regions.size() * (2+3)*2*6]; // Draw EFB copy regions rectangles int a = 0; + GLfloat color[3] = {0.0f, 1.0f, 1.0f}; + for (std::vector::const_iterator it = stats.efb_regions.begin(); - it != stats.efb_regions.end(); ++it, ++a) + it != stats.efb_regions.end(); ++it) { GLfloat halfWidth = EFB_WIDTH / 2.0f; GLfloat halfHeight = EFB_HEIGHT / 2.0f; @@ -548,33 +550,88 @@ void Renderer::DrawDebugInfo() GLfloat x2 = (GLfloat) -1.0f + ((GLfloat)it->right / halfWidth); GLfloat y2 = (GLfloat) 1.0f - ((GLfloat)it->bottom / halfHeight); - Colours[a * 3] = 0.0f; - Colours[a * 3 + 1] = 1.0f; - Colours[a * 3 + 2] = 1.0f; - - RectPoints[a * 16] = x; - RectPoints[a * 16 + 1] = y; + Vertices[a++] = x; + Vertices[a++] = y; + Vertices[a++] = color[0]; + Vertices[a++] = color[1]; + Vertices[a++] = color[2]; - RectPoints[a * 16 + 2] = x2; - RectPoints[a * 16 + 3] = y; + Vertices[a++] = x2; + Vertices[a++] = y; + Vertices[a++] = color[0]; + Vertices[a++] = color[1]; + Vertices[a++] = color[2]; - RectPoints[a * 16 + 4] = x; - RectPoints[a * 16 + 5] = y2; - - RectPoints[a * 16 + 6] = x2; - RectPoints[a * 16 + 7] = y2; - - RectPoints[a * 16 + 8] = x; - RectPoints[a * 16 + 9] = y; - - RectPoints[a * 16 + 10] = x; - RectPoints[a * 16 + 11] = y2; - - RectPoints[a * 16 + 12] = x2; - RectPoints[a * 16 + 13] = y; - - RectPoints[a * 16 + 14] = x2; - RectPoints[a * 16 + 15] = y2; + + Vertices[a++] = x2; + Vertices[a++] = y; + Vertices[a++] = color[0]; + Vertices[a++] = color[1]; + Vertices[a++] = color[2]; + + Vertices[a++] = x2; + Vertices[a++] = y2; + Vertices[a++] = color[0]; + Vertices[a++] = color[1]; + Vertices[a++] = color[2]; + + + Vertices[a++] = x2; + Vertices[a++] = y2; + Vertices[a++] = color[0]; + Vertices[a++] = color[1]; + Vertices[a++] = color[2]; + + Vertices[a++] = x; + Vertices[a++] = y2; + Vertices[a++] = color[0]; + Vertices[a++] = color[1]; + Vertices[a++] = color[2]; + + + Vertices[a++] = x; + Vertices[a++] = y2; + Vertices[a++] = color[0]; + Vertices[a++] = color[1]; + Vertices[a++] = color[2]; + + Vertices[a++] = x; + Vertices[a++] = y; + Vertices[a++] = color[0]; + Vertices[a++] = color[1]; + Vertices[a++] = color[2]; + + + Vertices[a++] = x; + Vertices[a++] = y; + Vertices[a++] = color[0]; + Vertices[a++] = color[1]; + Vertices[a++] = color[2]; + + Vertices[a++] = x2; + Vertices[a++] = y2; + Vertices[a++] = color[0]; + Vertices[a++] = color[1]; + Vertices[a++] = color[2]; + + + Vertices[a++] = x2; + Vertices[a++] = y; + Vertices[a++] = color[0]; + Vertices[a++] = color[1]; + Vertices[a++] = color[2]; + + Vertices[a++] = x; + Vertices[a++] = y2; + Vertices[a++] = color[0]; + Vertices[a++] = color[1]; + Vertices[a++] = color[2]; + + // TO DO: build something nicer here + GLfloat temp = color[0]; + color[0] = color[1]; + color[1] = color[2]; + color[2] = temp; } // disable all pointer, TODO: use VAO @@ -590,11 +647,10 @@ void Renderer::DrawDebugInfo() glDisableClientState(GL_TEXTURE_COORD_ARRAY); } - glColorPointer (3, GL_FLOAT, 0, Colours); - glVertexPointer(2, GL_FLOAT, 0, RectPoints); - glDrawArrays(GL_LINE_STRIP, 0, stats.efb_regions.size() * 8); - delete[] RectPoints; - delete[] Colours; + glColorPointer (3, GL_FLOAT, sizeof(GLfloat)*5, Vertices+2); + glVertexPointer(2, GL_FLOAT, sizeof(GLfloat)*5, Vertices); + glDrawArrays(GL_LINES, 0, stats.efb_regions.size() * 2*6); + delete[] Vertices; // Restore Line Size glLineWidth(lSize); From 6b3125728be4041e44cc2805e561737ac0d28375 Mon Sep 17 00:00:00 2001 From: degasus Date: Fri, 7 Dec 2012 23:34:38 +0100 Subject: [PATCH 11/28] use vbo for ShowEFBCopyRegions Signed-off-by: Ryan Houdek --- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 56991457e1..a282939dfb 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -106,10 +106,10 @@ namespace OGL // Declarations and definitions // ---------------------------- -int s_fps=0; +static int s_fps = 0; +static GLuint s_ShowEFBCopyRegions_VBO = 0; - -RasterFont* s_pfont = NULL; +static RasterFont* s_pfont = NULL; // 1 for no MSAA. Use s_MSAASamples > 1 to check for MSAA. static int s_MSAASamples = 1; @@ -125,9 +125,9 @@ static std::thread scrshotThread; #endif // EFB cache related -const u32 EFB_CACHE_RECT_SIZE = 64; // Cache 64x64 blocks. -const u32 EFB_CACHE_WIDTH = (EFB_WIDTH + EFB_CACHE_RECT_SIZE - 1) / EFB_CACHE_RECT_SIZE; // round up -const u32 EFB_CACHE_HEIGHT = (EFB_HEIGHT + EFB_CACHE_RECT_SIZE - 1) / EFB_CACHE_RECT_SIZE; +static const u32 EFB_CACHE_RECT_SIZE = 64; // Cache 64x64 blocks. +static const u32 EFB_CACHE_WIDTH = (EFB_WIDTH + EFB_CACHE_RECT_SIZE - 1) / EFB_CACHE_RECT_SIZE; // round up +static const u32 EFB_CACHE_HEIGHT = (EFB_HEIGHT + EFB_CACHE_RECT_SIZE - 1) / EFB_CACHE_RECT_SIZE; static bool s_efbCacheValid[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT]; static std::vector s_efbCache[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT]; // 2 for PEEK_Z and PEEK_COLOR @@ -250,6 +250,7 @@ Renderer::Renderer() OSDInternalH = 0; s_fps=0; + s_ShowEFBCopyRegions_VBO = 0; s_blendMode = 0; InitFPSCounter(); @@ -452,6 +453,9 @@ Renderer::Renderer() cgGLSetDebugMode(GL_FALSE); #endif #endif + + // creating buffers + glGenBuffers(1, &s_ShowEFBCopyRegions_VBO); glStencilFunc(GL_ALWAYS, 0, 0); glBlendFunc(GL_ONE, GL_ONE); @@ -489,6 +493,10 @@ Renderer::~Renderer() { g_Config.bRunning = false; UpdateActiveConfig(); + + glDeleteBuffers(1, &s_ShowEFBCopyRegions_VBO); + s_ShowEFBCopyRegions_VBO = 0; + delete s_pfont; s_pfont = 0; @@ -534,7 +542,9 @@ void Renderer::DrawDebugInfo() glLineWidth(3.0f); // 2*Coords + 3*Color - GLfloat *Vertices = new GLfloat[stats.efb_regions.size() * (2+3)*2*6]; + glBindBuffer(GL_ARRAY_BUFFER, s_ShowEFBCopyRegions_VBO); + glBufferData(GL_ARRAY_BUFFER, stats.efb_regions.size() * sizeof(GLfloat) * (2+3)*2*6, NULL, GL_STREAM_DRAW); + GLfloat *Vertices = (GLfloat*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); // Draw EFB copy regions rectangles int a = 0; @@ -633,6 +643,7 @@ void Renderer::DrawDebugInfo() color[1] = color[2]; color[2] = temp; } + glUnmapBuffer(GL_ARRAY_BUFFER); // disable all pointer, TODO: use VAO glEnableClientState(GL_VERTEX_ARRAY); @@ -647,13 +658,15 @@ void Renderer::DrawDebugInfo() glDisableClientState(GL_TEXTURE_COORD_ARRAY); } - glColorPointer (3, GL_FLOAT, sizeof(GLfloat)*5, Vertices+2); - glVertexPointer(2, GL_FLOAT, sizeof(GLfloat)*5, Vertices); + glColorPointer (3, GL_FLOAT, sizeof(GLfloat)*5, (GLfloat*)NULL+2); + glVertexPointer(2, GL_FLOAT, sizeof(GLfloat)*5, NULL); glDrawArrays(GL_LINES, 0, stats.efb_regions.size() * 2*6); - delete[] Vertices; // Restore Line Size glLineWidth(lSize); + + // disable buffer TODO: remove this, after everting is in vbo + glBindBuffer(GL_ARRAY_BUFFER, 0); // Clear stored regions stats.efb_regions.clear(); From d44228f1b7ec13db032ff558a6e3bc87e5789216 Mon Sep 17 00:00:00 2001 From: degasus Date: Sat, 8 Dec 2012 00:54:38 +0100 Subject: [PATCH 12/28] TextureCache::TCacheEntry::FromRenderTarget as vbo Signed-off-by: Ryan Houdek --- .../Plugin_VideoOGL/Src/TextureCache.cpp | 47 ++++++++++++------- .../Plugin_VideoOGL/Src/TextureCache.h | 1 + 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp index 5441a65901..30b67119df 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp @@ -57,6 +57,7 @@ namespace OGL { static u32 s_TempFramebuffer = 0; +static GLuint s_VBO = 0; static const GLint c_MinLinearFilter[8] = { GL_NEAREST, @@ -306,19 +307,20 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo TargetRectangle targetSource = g_renderer->ConvertEFBRectangle(srcRect); GL_REPORT_ERRORD(); - GLfloat tex1[] = { - (GLfloat)targetSource.left, (GLfloat)targetSource.bottom, - (GLfloat)targetSource.left, (GLfloat)targetSource.top, - (GLfloat)targetSource.right, (GLfloat)targetSource.top, - (GLfloat)targetSource.right, (GLfloat)targetSource.bottom - }; - GLfloat vtx1[] = { - -1.f, 1.f, - -1.f, -1.f, - 1.f, -1.f, - 1.f, 1.f + GLfloat vertices[] = { + -1.f, 1.f, + (GLfloat)targetSource.left, (GLfloat)targetSource.bottom, + -1.f, -1.f, + (GLfloat)targetSource.left, (GLfloat)targetSource.top, + 1.f, -1.f, + (GLfloat)targetSource.right, (GLfloat)targetSource.top, + 1.f, 1.f, + (GLfloat)targetSource.right, (GLfloat)targetSource.bottom }; + glBindBuffer(GL_ARRAY_BUFFER, s_VBO); + glBufferData(GL_ARRAY_BUFFER, 4*4*sizeof(GLfloat), vertices, GL_STREAM_DRAW); + // disable all pointer, TODO: use VAO glEnableClientState(GL_VERTEX_ARRAY); glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB); @@ -335,9 +337,12 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo } glClientActiveTexture(GL_TEXTURE0); - glTexCoordPointer(2, GL_FLOAT, 0, tex1); - glVertexPointer(2, GL_FLOAT, 0, vtx1); + glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat)*4, (GLfloat*)NULL + 2); + glVertexPointer(2, GL_FLOAT, sizeof(GLfloat)*4, 0); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + // TODO: this should be removed if we use vbo everywhere + glBindBuffer(GL_ARRAY_BUFFER, 0); GL_REPORT_ERRORD(); @@ -415,13 +420,21 @@ void TextureCache::TCacheEntry::SetTextureParameters(const TexMode0 &newmode, co (float)(1 << g_ActiveConfig.iMaxAnisotropy)); } +TextureCache::TextureCache() +{ + glGenBuffers(1, &s_VBO); +} + + TextureCache::~TextureCache() { - if (s_TempFramebuffer) + glDeleteBuffers(1, &s_VBO); + + if (s_TempFramebuffer) { - glDeleteFramebuffersEXT(1, (GLuint*)&s_TempFramebuffer); - s_TempFramebuffer = 0; - } + glDeleteFramebuffersEXT(1, (GLuint*)&s_TempFramebuffer); + s_TempFramebuffer = 0; + } } void TextureCache::DisableStage(unsigned int stage) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.h b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.h index 30f44b797d..91245237d9 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.h @@ -32,6 +32,7 @@ namespace OGL class TextureCache : public ::TextureCache { public: + TextureCache(); static void DisableStage(unsigned int stage); private: From 8ea2ddbc5056bc25ba67329dc9b6be192fddafda Mon Sep 17 00:00:00 2001 From: degasus Date: Sat, 8 Dec 2012 01:32:58 +0100 Subject: [PATCH 13/28] XFBSource::Draw in vbo Signed-off-by: Ryan Houdek --- .../Src/FramebufferManager.cpp | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp index 8c3c3f3fca..1f70c75d69 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp @@ -28,6 +28,8 @@ namespace OGL extern bool s_bHaveFramebufferBlit; // comes from Render.cpp. ugly. +static GLuint s_VBO = 0; + int FramebufferManager::m_targetWidth; int FramebufferManager::m_targetHeight; int FramebufferManager::m_msaaSamples; @@ -170,6 +172,8 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms // Create XFB framebuffer; targets will be created elsewhere. glGenFramebuffersEXT(1, &m_xfbFramebuffer); + + glGenBuffers(1, &s_VBO); // EFB framebuffer is currently bound, make sure to clear its alpha value to 1.f glViewport(0, 0, m_targetWidth, m_targetHeight); @@ -182,6 +186,7 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms FramebufferManager::~FramebufferManager() { glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + glDeleteBuffers(1, &s_VBO); GLuint glObj[3]; @@ -306,25 +311,24 @@ void XFBSource::Draw(const MathUtil::Rectangle &sourcerc, glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture); - GLfloat vtx1[] = { + GLfloat vertices[] = { drawrc.left, drawrc.bottom, - drawrc.left, drawrc.top, - drawrc.right, drawrc.top, - drawrc.right, drawrc.bottom, - }; - GLfloat tex1[] = { // For TEXTURE0 sourcerc.left, sourcerc.bottom, - sourcerc.left, sourcerc.top, - sourcerc.right, sourcerc.top, - sourcerc.right, sourcerc.bottom - }; - GLfloat tex2[] = { // For TEXTURE1 0.0f, 0.0f, + drawrc.left, drawrc.top, + sourcerc.left, sourcerc.top, 0.0f, 1.0f, + drawrc.right, drawrc.top, + sourcerc.right, sourcerc.top, 1.0f, 1.0f, + drawrc.right, drawrc.bottom, + sourcerc.right, sourcerc.bottom, 1.0f, 0.0f }; + glBindBuffer(GL_ARRAY_BUFFER, s_VBO); + glBufferData(GL_ARRAY_BUFFER, 2*4*3*sizeof(GLfloat), vertices, GL_STREAM_DRAW); + // disable all pointer, TODO: use VAO glEnableClientState(GL_VERTEX_ARRAY); glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB); @@ -342,13 +346,15 @@ void XFBSource::Draw(const MathUtil::Rectangle &sourcerc, glDisableClientState(GL_TEXTURE_COORD_ARRAY); } - glVertexPointer(2, GL_FLOAT, 0, vtx1); + glVertexPointer(2, GL_FLOAT, 6*sizeof(GLfloat), NULL); glClientActiveTexture(GL_TEXTURE0); - glTexCoordPointer(2, GL_FLOAT, 0, tex1); + glTexCoordPointer(2, GL_FLOAT, 6*sizeof(GLfloat), (GLfloat*)NULL+2); glClientActiveTexture(GL_TEXTURE1); - glTexCoordPointer(2, GL_FLOAT, 0, tex2); + glTexCoordPointer(2, GL_FLOAT, 6*sizeof(GLfloat), (GLfloat*)NULL+4); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + // TODO: this need to be removed in future + glBindBuffer(GL_ARRAY_BUFFER, 0); GL_REPORT_ERRORD(); } From b41c06a9aca4c280af3bb81f3fb0a2f20a3ed6a7 Mon Sep 17 00:00:00 2001 From: degasus Date: Sat, 8 Dec 2012 01:48:15 +0100 Subject: [PATCH 14/28] EncodeToRamUsingShader in vbo Signed-off-by: Ryan Houdek --- .../Plugin_VideoOGL/Src/TextureConverter.cpp | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp index 3159909789..02ddd8d42d 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp @@ -57,6 +57,8 @@ static FRAGMENTSHADER s_yuyvToRgbProgram; const u32 NUM_ENCODING_PROGRAMS = 64; static FRAGMENTSHADER s_encodingPrograms[NUM_ENCODING_PROGRAMS]; +static GLuint s_VBO = 0; + void CreateRgbToYuyvProgram() { // Output is BGRA because that is slightly faster than RGBA. @@ -140,6 +142,8 @@ FRAGMENTSHADER &GetOrCreateEncodingShader(u32 format) void Init() { glGenFramebuffersEXT(1, &s_texConvFrameBuffer); + + glGenBuffers(1, &s_VBO); glGenRenderbuffersEXT(1, &s_dstRenderBuffer); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, s_dstRenderBuffer); @@ -162,6 +166,7 @@ void Shutdown() glDeleteTextures(1, &s_srcTexture); glDeleteRenderbuffersEXT(1, &s_dstRenderBuffer); glDeleteFramebuffersEXT(1, &s_texConvFrameBuffer); + glDeleteBuffers(1, &s_VBO); s_rgbToYuyvProgram.Destroy(); s_yuyvToRgbProgram.Destroy(); @@ -215,18 +220,19 @@ void EncodeToRamUsingShader(FRAGMENTSHADER& shader, GLuint srcTexture, const Tar GL_REPORT_ERRORD(); - GLfloat tex1[] = { + GLfloat vertices[] = { + -1.f, -1.f, (float)sourceRc.left, (float)sourceRc.top, + -1.f, 1.f, (float)sourceRc.left, (float)sourceRc.bottom, + 1.f, 1.f, (float)sourceRc.right, (float)sourceRc.bottom, + 1.f, -1.f, (float)sourceRc.right, (float)sourceRc.top }; - GLfloat vtx1[] = { - -1.f, -1.f, - -1.f, 1.f, - 1.f, 1.f, - 1.f, -1.f - }; + + glBindBuffer(GL_ARRAY_BUFFER, s_VBO); + glBufferData(GL_ARRAY_BUFFER, 4*4*sizeof(GLfloat), vertices, GL_STREAM_DRAW); // disable all pointer, TODO: use VAO glEnableClientState(GL_VERTEX_ARRAY); @@ -244,10 +250,13 @@ void EncodeToRamUsingShader(FRAGMENTSHADER& shader, GLuint srcTexture, const Tar } glClientActiveTexture(GL_TEXTURE0); - glTexCoordPointer(2, GL_FLOAT, 0, tex1); - glVertexPointer(2, GL_FLOAT, 0, vtx1); + glTexCoordPointer(2, GL_FLOAT, 4*sizeof(GLfloat), (GLfloat*)NULL + 2); + glVertexPointer(2, GL_FLOAT, 4*sizeof(GLfloat), NULL); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + // TODO: remove this + glBindBuffer(GL_ARRAY_BUFFER, 0); + GL_REPORT_ERRORD(); // .. and then read back the results. From bbcb442983857d79d318b9bf8e5019602734361f Mon Sep 17 00:00:00 2001 From: degasus Date: Sat, 8 Dec 2012 02:01:35 +0100 Subject: [PATCH 15/28] in the end, also Renderer::Swap in vbo two last draw-calls are missing: VertexManager::Draw (see Graphic_Update branch) RasterFont::printString (perhaps reimplement with an texture) Signed-off-by: Ryan Houdek --- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index a282939dfb..9350b4ca46 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -108,6 +108,7 @@ namespace OGL // ---------------------------- static int s_fps = 0; static GLuint s_ShowEFBCopyRegions_VBO = 0; +static GLuint s_Swap_VBO = 0; static RasterFont* s_pfont = NULL; @@ -251,6 +252,7 @@ Renderer::Renderer() s_fps=0; s_ShowEFBCopyRegions_VBO = 0; + s_Swap_VBO = 0; s_blendMode = 0; InitFPSCounter(); @@ -456,6 +458,7 @@ Renderer::Renderer() // creating buffers glGenBuffers(1, &s_ShowEFBCopyRegions_VBO); + glGenBuffers(1, &s_Swap_VBO); glStencilFunc(GL_ALWAYS, 0, 0); glBlendFunc(GL_ONE, GL_ONE); @@ -495,6 +498,7 @@ Renderer::~Renderer() UpdateActiveConfig(); glDeleteBuffers(1, &s_ShowEFBCopyRegions_VBO); + glDeleteBuffers(1, &s_Swap_VBO); s_ShowEFBCopyRegions_VBO = 0; delete s_pfont; @@ -1217,29 +1221,26 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // switch to the window backbuffer glBindTexture(GL_TEXTURE_RECTANGLE_ARB, read_texture); - GLfloat vtx1[] = { - -1, -1, 1, - -1, 1, 1, - 1, 1, 1, - 1, -1, 1 - }; - GLfloat top = (GLfloat)targetRc.top; - GLfloat right = (GLfloat)targetRc.right; - GLfloat bottom = (GLfloat)targetRc.bottom; - GLfloat left = (GLfloat)targetRc.left; - - GLfloat tex1[] = { // For TEXTURE0 - left, bottom, - left, top, - right, top, - right, bottom - }; - GLfloat tex2[] = { // For TEXTURE1 + GLfloat vertices[] = { + -1.0f, -1.0f, 1.0f, + (GLfloat)targetRc.left, (GLfloat)targetRc.bottom, 0.0f, 0.0f, + + -1.0f, 1.0f, 1.0f, + (GLfloat)targetRc.left, (GLfloat)targetRc.top, 0.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + (GLfloat)targetRc.right, (GLfloat)targetRc.top, 1.0f, 1.0f, + + 1.0f, -1.0f, 1.0f, + (GLfloat)targetRc.right, (GLfloat)targetRc.bottom, 1.0f, 0.0f }; + + glBindBuffer(GL_ARRAY_BUFFER, s_Swap_VBO); + glBufferData(GL_ARRAY_BUFFER, 4*7*sizeof(GLfloat), vertices, GL_STREAM_DRAW); // disable all pointer, TODO: use VAO glEnableClientState(GL_VERTEX_ARRAY); @@ -1259,14 +1260,18 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons if (applyShader) { glClientActiveTexture(GL_TEXTURE1); - glTexCoordPointer(2, GL_FLOAT, 0, tex2); glEnableClientState(GL_TEXTURE_COORD_ARRAY); } - glVertexPointer(3, GL_FLOAT, 0, vtx1); + glVertexPointer(3, GL_FLOAT, 7*sizeof(GLfloat), NULL); glClientActiveTexture(GL_TEXTURE0); - glTexCoordPointer(2, GL_FLOAT, 0, tex1); + glTexCoordPointer(2, GL_FLOAT, 7*sizeof(GLfloat), (GLfloat*)NULL+3); + glClientActiveTexture(GL_TEXTURE1); + glTexCoordPointer(2, GL_FLOAT, 7*sizeof(GLfloat), (GLfloat*)NULL+5); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + // TODO: also remove this + glBindBuffer(GL_ARRAY_BUFFER, 0); if(applyShader) PixelShaderCache::DisableShader(); From d0c4332d99b77d0869f4f9dc23a77452d0cbb381 Mon Sep 17 00:00:00 2001 From: degasus Date: Sun, 9 Dec 2012 19:22:21 +0100 Subject: [PATCH 16/28] don't update vbo, if there are no changes in Renderer::Swap Signed-off-by: Ryan Houdek --- Source/Core/Common/Src/MathUtil.h | 2 + Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 51 ++++++++++++------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/Source/Core/Common/Src/MathUtil.h b/Source/Core/Common/Src/MathUtil.h index a6290ff602..c5f613ada1 100644 --- a/Source/Core/Common/Src/MathUtil.h +++ b/Source/Core/Common/Src/MathUtil.h @@ -117,6 +117,8 @@ struct Rectangle Rectangle(T theLeft, T theTop, T theRight, T theBottom) : left(theLeft), top(theTop), right(theRight), bottom(theBottom) { } + + bool operator==(const Rectangle& r) { return left==r.left && top==r.top && right==r.right && bottom==r.bottom; } T GetWidth() const { return abs(right - left); } T GetHeight() const { return abs(bottom - top); } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 9350b4ca46..8df239700e 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -109,6 +109,7 @@ namespace OGL static int s_fps = 0; static GLuint s_ShowEFBCopyRegions_VBO = 0; static GLuint s_Swap_VBO = 0; +static TargetRectangle s_old_targetRc; static RasterFont* s_pfont = NULL; @@ -254,6 +255,13 @@ Renderer::Renderer() s_ShowEFBCopyRegions_VBO = 0; s_Swap_VBO = 0; s_blendMode = 0; + + // should be invalid, so there will be an upload on the first call + s_old_targetRc.bottom = -1; + s_old_targetRc.top = -1; + s_old_targetRc.left = -1; + s_old_targetRc.right = -1; + InitFPSCounter(); @@ -1221,26 +1229,33 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // switch to the window backbuffer glBindTexture(GL_TEXTURE_RECTANGLE_ARB, read_texture); - GLfloat vertices[] = { - -1.0f, -1.0f, 1.0f, - (GLfloat)targetRc.left, (GLfloat)targetRc.bottom, - 0.0f, 0.0f, + if(!(s_old_targetRc == targetRc)) { + GLfloat vertices[] = { + -1.0f, -1.0f, 1.0f, + (GLfloat)targetRc.left, (GLfloat)targetRc.bottom, + 0.0f, 0.0f, + + -1.0f, 1.0f, 1.0f, + (GLfloat)targetRc.left, (GLfloat)targetRc.top, + 0.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + (GLfloat)targetRc.right, (GLfloat)targetRc.top, + 1.0f, 1.0f, + + 1.0f, -1.0f, 1.0f, + (GLfloat)targetRc.right, (GLfloat)targetRc.bottom, + 1.0f, 0.0f + }; - -1.0f, 1.0f, 1.0f, - (GLfloat)targetRc.left, (GLfloat)targetRc.top, - 0.0f, 1.0f, + glBindBuffer(GL_ARRAY_BUFFER, s_Swap_VBO); + glBufferData(GL_ARRAY_BUFFER, 4*7*sizeof(GLfloat), vertices, GL_STREAM_DRAW); - 1.0f, 1.0f, 1.0f, - (GLfloat)targetRc.right, (GLfloat)targetRc.top, - 1.0f, 1.0f, - - 1.0f, -1.0f, 1.0f, - (GLfloat)targetRc.right, (GLfloat)targetRc.bottom, - 1.0f, 0.0f - }; - - glBindBuffer(GL_ARRAY_BUFFER, s_Swap_VBO); - glBufferData(GL_ARRAY_BUFFER, 4*7*sizeof(GLfloat), vertices, GL_STREAM_DRAW); + s_old_targetRc = targetRc; + } else { + // TODO: remove this after switch to VAO + glBindBuffer(GL_ARRAY_BUFFER, s_Swap_VBO); + } // disable all pointer, TODO: use VAO glEnableClientState(GL_VERTEX_ARRAY); From 34b1451fbea2798f943be7c84f0677f95a81ed84 Mon Sep 17 00:00:00 2001 From: degasus Date: Sun, 9 Dec 2012 20:30:29 +0100 Subject: [PATCH 17/28] cache vbos in TextureCache::TCacheEntry::FromRenderTarget Signed-off-by: Ryan Houdek --- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 14 ++--- .../Plugin_VideoOGL/Src/TextureCache.cpp | 58 ++++++++++++++----- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 8df239700e..30907bde8b 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -109,7 +109,7 @@ namespace OGL static int s_fps = 0; static GLuint s_ShowEFBCopyRegions_VBO = 0; static GLuint s_Swap_VBO = 0; -static TargetRectangle s_old_targetRc; +static TargetRectangle s_cached_targetRc; static RasterFont* s_pfont = NULL; @@ -257,10 +257,10 @@ Renderer::Renderer() s_blendMode = 0; // should be invalid, so there will be an upload on the first call - s_old_targetRc.bottom = -1; - s_old_targetRc.top = -1; - s_old_targetRc.left = -1; - s_old_targetRc.right = -1; + s_cached_targetRc.bottom = -1; + s_cached_targetRc.top = -1; + s_cached_targetRc.left = -1; + s_cached_targetRc.right = -1; InitFPSCounter(); @@ -1229,7 +1229,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // switch to the window backbuffer glBindTexture(GL_TEXTURE_RECTANGLE_ARB, read_texture); - if(!(s_old_targetRc == targetRc)) { + if(!( s_cached_targetRc == targetRc)) { GLfloat vertices[] = { -1.0f, -1.0f, 1.0f, (GLfloat)targetRc.left, (GLfloat)targetRc.bottom, @@ -1251,7 +1251,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons glBindBuffer(GL_ARRAY_BUFFER, s_Swap_VBO); glBufferData(GL_ARRAY_BUFFER, 4*7*sizeof(GLfloat), vertices, GL_STREAM_DRAW); - s_old_targetRc = targetRc; + s_cached_targetRc = targetRc; } else { // TODO: remove this after switch to VAO glBindBuffer(GL_ARRAY_BUFFER, s_Swap_VBO); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp index 30b67119df..6685d8a176 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp @@ -56,8 +56,13 @@ namespace OGL { +struct VBOCache { + GLuint vbo; + TargetRectangle targetSource; +}; +static std::map s_VBO; + static u32 s_TempFramebuffer = 0; -static GLuint s_VBO = 0; static const GLint c_MinLinearFilter[8] = { GL_NEAREST, @@ -305,21 +310,41 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo GL_REPORT_ERRORD(); TargetRectangle targetSource = g_renderer->ConvertEFBRectangle(srcRect); - GL_REPORT_ERRORD(); - GLfloat vertices[] = { - -1.f, 1.f, - (GLfloat)targetSource.left, (GLfloat)targetSource.bottom, - -1.f, -1.f, - (GLfloat)targetSource.left, (GLfloat)targetSource.top, - 1.f, -1.f, - (GLfloat)targetSource.right, (GLfloat)targetSource.top, - 1.f, 1.f, - (GLfloat)targetSource.right, (GLfloat)targetSource.bottom - }; - glBindBuffer(GL_ARRAY_BUFFER, s_VBO); - glBufferData(GL_ARRAY_BUFFER, 4*4*sizeof(GLfloat), vertices, GL_STREAM_DRAW); + // should be unique enough, if not, vbo will "only" be uploaded to much + u32 targetSourceHash = targetSource.left<<24 | targetSource.top<<16 | targetSource.right<<8 | targetSource.bottom; + std::map::iterator vbo_it = s_VBO.find(targetSourceHash); + + if(vbo_it == s_VBO.end()) { + VBOCache item; + item.targetSource.bottom = -1; + item.targetSource.top = -1; + item.targetSource.left = -1; + item.targetSource.right = -1; + glGenBuffers(1, &item.vbo); + vbo_it = s_VBO.insert(std::pair(targetSourceHash, item)).first; + } + if(!(vbo_it->second.targetSource == targetSource)) { + GLfloat vertices[] = { + -1.f, 1.f, + (GLfloat)targetSource.left, (GLfloat)targetSource.bottom, + -1.f, -1.f, + (GLfloat)targetSource.left, (GLfloat)targetSource.top, + 1.f, -1.f, + (GLfloat)targetSource.right, (GLfloat)targetSource.top, + 1.f, 1.f, + (GLfloat)targetSource.right, (GLfloat)targetSource.bottom + }; + + glBindBuffer(GL_ARRAY_BUFFER, vbo_it->second.vbo); + glBufferData(GL_ARRAY_BUFFER, 4*4*sizeof(GLfloat), vertices, GL_STREAM_DRAW); + + vbo_it->second.targetSource = targetSource; + } else { + // TODO: remove after switched to VAO + glBindBuffer(GL_ARRAY_BUFFER, vbo_it->second.vbo); + } // disable all pointer, TODO: use VAO glEnableClientState(GL_VERTEX_ARRAY); @@ -422,13 +447,14 @@ void TextureCache::TCacheEntry::SetTextureParameters(const TexMode0 &newmode, co TextureCache::TextureCache() { - glGenBuffers(1, &s_VBO); } TextureCache::~TextureCache() { - glDeleteBuffers(1, &s_VBO); + for(std::map::iterator it = s_VBO.begin(); it != s_VBO.end(); it++) { + glGenBuffers(1, &it->second.vbo); + } if (s_TempFramebuffer) { From 1f1b32b663a93838a5560ba49e8ff4a2153be56e Mon Sep 17 00:00:00 2001 From: degasus Date: Sun, 9 Dec 2012 20:44:13 +0100 Subject: [PATCH 18/28] only update vbo on changes in XFBSource::Draw Signed-off-by: Ryan Houdek --- .../Src/FramebufferManager.cpp | 54 +++++++++++++------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp index 1f70c75d69..7452e12a97 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp @@ -29,6 +29,8 @@ namespace OGL extern bool s_bHaveFramebufferBlit; // comes from Render.cpp. ugly. static GLuint s_VBO = 0; +static MathUtil::Rectangle s_cached_sourcerc; +static MathUtil::Rectangle s_cached_drawrc; int FramebufferManager::m_targetWidth; int FramebufferManager::m_targetHeight; @@ -56,6 +58,15 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms m_resolvedDepthTexture = 0; m_xfbFramebuffer = 0; + s_cached_sourcerc.bottom = -1; + s_cached_sourcerc.left = -1; + s_cached_sourcerc.right = -1; + s_cached_sourcerc.top = -1; + s_cached_drawrc.bottom = -1; + s_cached_drawrc.left = -1; + s_cached_drawrc.right = -1; + s_cached_drawrc.top = -1; + m_targetWidth = targetWidth; m_targetHeight = targetHeight; @@ -311,23 +322,32 @@ void XFBSource::Draw(const MathUtil::Rectangle &sourcerc, glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture); - GLfloat vertices[] = { - drawrc.left, drawrc.bottom, - sourcerc.left, sourcerc.bottom, - 0.0f, 0.0f, - drawrc.left, drawrc.top, - sourcerc.left, sourcerc.top, - 0.0f, 1.0f, - drawrc.right, drawrc.top, - sourcerc.right, sourcerc.top, - 1.0f, 1.0f, - drawrc.right, drawrc.bottom, - sourcerc.right, sourcerc.bottom, - 1.0f, 0.0f - }; - - glBindBuffer(GL_ARRAY_BUFFER, s_VBO); - glBufferData(GL_ARRAY_BUFFER, 2*4*3*sizeof(GLfloat), vertices, GL_STREAM_DRAW); + if(!(s_cached_sourcerc == sourcerc) || !(s_cached_drawrc == drawrc)) { + GLfloat vertices[] = { + drawrc.left, drawrc.bottom, + sourcerc.left, sourcerc.bottom, + 0.0f, 0.0f, + drawrc.left, drawrc.top, + sourcerc.left, sourcerc.top, + 0.0f, 1.0f, + drawrc.right, drawrc.top, + sourcerc.right, sourcerc.top, + 1.0f, 1.0f, + drawrc.right, drawrc.bottom, + sourcerc.right, sourcerc.bottom, + 1.0f, 0.0f + }; + glBindBuffer(GL_ARRAY_BUFFER, s_VBO); + glBufferData(GL_ARRAY_BUFFER, 2*4*3*sizeof(GLfloat), vertices, GL_STREAM_DRAW); + + s_cached_sourcerc = sourcerc; + s_cached_drawrc = drawrc; + } + else + { + // TODO: remove on VAO + glBindBuffer(GL_ARRAY_BUFFER, s_VBO); + } // disable all pointer, TODO: use VAO glEnableClientState(GL_VERTEX_ARRAY); From 5c8800968a0f8f08229ce4a59365ff9c66bc5a19 Mon Sep 17 00:00:00 2001 From: degasus Date: Sun, 9 Dec 2012 20:56:58 +0100 Subject: [PATCH 19/28] also check for vbo updates in EncodeToRamUsingShader Signed-off-by: Ryan Houdek --- .../Plugin_VideoOGL/Src/TextureCache.cpp | 1 + .../Plugin_VideoOGL/Src/TextureConverter.cpp | 38 ++++++++++++------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp index 6685d8a176..95ddd80e94 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp @@ -455,6 +455,7 @@ TextureCache::~TextureCache() for(std::map::iterator it = s_VBO.begin(); it != s_VBO.end(); it++) { glGenBuffers(1, &it->second.vbo); } + s_VBO.clear(); if (s_TempFramebuffer) { diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp index 02ddd8d42d..4dab390d09 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp @@ -58,6 +58,7 @@ const u32 NUM_ENCODING_PROGRAMS = 64; static FRAGMENTSHADER s_encodingPrograms[NUM_ENCODING_PROGRAMS]; static GLuint s_VBO = 0; +static TargetRectangle s_cached_sourceRc; void CreateRgbToYuyvProgram() { @@ -144,6 +145,10 @@ void Init() glGenFramebuffersEXT(1, &s_texConvFrameBuffer); glGenBuffers(1, &s_VBO); + s_cached_sourceRc.top = -1; + s_cached_sourceRc.bottom = -1; + s_cached_sourceRc.left = -1; + s_cached_sourceRc.right = -1; glGenRenderbuffersEXT(1, &s_dstRenderBuffer); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, s_dstRenderBuffer); @@ -219,20 +224,25 @@ void EncodeToRamUsingShader(FRAGMENTSHADER& shader, GLuint srcTexture, const Tar PixelShaderCache::SetCurrentShader(shader.glprogid); GL_REPORT_ERRORD(); - - GLfloat vertices[] = { - -1.f, -1.f, - (float)sourceRc.left, (float)sourceRc.top, - -1.f, 1.f, - (float)sourceRc.left, (float)sourceRc.bottom, - 1.f, 1.f, - (float)sourceRc.right, (float)sourceRc.bottom, - 1.f, -1.f, - (float)sourceRc.right, (float)sourceRc.top - }; - - glBindBuffer(GL_ARRAY_BUFFER, s_VBO); - glBufferData(GL_ARRAY_BUFFER, 4*4*sizeof(GLfloat), vertices, GL_STREAM_DRAW); + if(!(s_cached_sourceRc == sourceRc)) { + GLfloat vertices[] = { + -1.f, -1.f, + (float)sourceRc.left, (float)sourceRc.top, + -1.f, 1.f, + (float)sourceRc.left, (float)sourceRc.bottom, + 1.f, 1.f, + (float)sourceRc.right, (float)sourceRc.bottom, + 1.f, -1.f, + (float)sourceRc.right, (float)sourceRc.top + }; + glBindBuffer(GL_ARRAY_BUFFER, s_VBO); + glBufferData(GL_ARRAY_BUFFER, 4*4*sizeof(GLfloat), vertices, GL_STREAM_DRAW); + + s_cached_sourceRc = sourceRc; + } else { + // TODO: remove + glBindBuffer(GL_ARRAY_BUFFER, s_VBO); + } // disable all pointer, TODO: use VAO glEnableClientState(GL_VERTEX_ARRAY); From c207422987a3f39032ee348fed4bde1b67a21fcc Mon Sep 17 00:00:00 2001 From: degasus Date: Sun, 9 Dec 2012 22:49:58 +0100 Subject: [PATCH 20/28] using of vao, warning: ARB_vertex_array_object is needed Signed-off-by: Ryan Houdek --- .gitignore | 1 + .../Src/FramebufferManager.cpp | 50 ++++----- .../Src/NativeVertexFormat.cpp | 4 + Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 93 +++++++--------- .../Plugin_VideoOGL/Src/TextureCache.cpp | 45 +++----- .../Plugin_VideoOGL/Src/TextureConverter.cpp | 105 ++++++++++-------- 6 files changed, 141 insertions(+), 157 deletions(-) diff --git a/.gitignore b/.gitignore index 3cc8a1d8a4..6eaaaf119a 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ Source/Core/Common/Src/scmrev.h *.ipch .sconsign.dblite Externals/scons-local/* +*~ diff --git a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp index 7452e12a97..9c66396226 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp @@ -29,6 +29,7 @@ namespace OGL extern bool s_bHaveFramebufferBlit; // comes from Render.cpp. ugly. static GLuint s_VBO = 0; +static GLuint s_VAO = 0; static MathUtil::Rectangle s_cached_sourcerc; static MathUtil::Rectangle s_cached_drawrc; @@ -184,7 +185,22 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms glGenFramebuffersEXT(1, &m_xfbFramebuffer); + // Generate VBO & VAO - and initialize the VAO for "Draw" glGenBuffers(1, &s_VBO); + glGenVertexArrays(1, &s_VAO); + glBindBuffer(GL_ARRAY_BUFFER, s_VBO); + glBindVertexArray(s_VAO); + + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(2, GL_FLOAT, 6*sizeof(GLfloat), NULL); + + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, 6*sizeof(GLfloat), (GLfloat*)NULL+2); + + glClientActiveTexture(GL_TEXTURE1); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, 6*sizeof(GLfloat), (GLfloat*)NULL+4); // EFB framebuffer is currently bound, make sure to clear its alpha value to 1.f glViewport(0, 0, m_targetWidth, m_targetHeight); @@ -198,6 +214,7 @@ FramebufferManager::~FramebufferManager() { glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glDeleteBuffers(1, &s_VBO); + glDeleteVertexArrays(1, &s_VAO); GLuint glObj[3]; @@ -339,42 +356,13 @@ void XFBSource::Draw(const MathUtil::Rectangle &sourcerc, }; glBindBuffer(GL_ARRAY_BUFFER, s_VBO); glBufferData(GL_ARRAY_BUFFER, 2*4*3*sizeof(GLfloat), vertices, GL_STREAM_DRAW); - + s_cached_sourcerc = sourcerc; s_cached_drawrc = drawrc; } - else - { - // TODO: remove on VAO - glBindBuffer(GL_ARRAY_BUFFER, s_VBO); - } - - // disable all pointer, TODO: use VAO - glEnableClientState(GL_VERTEX_ARRAY); - glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableVertexAttribArray(SHADER_NORM1_ATTRIB); - glDisableVertexAttribArray(SHADER_NORM2_ATTRIB); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_SECONDARY_COLOR_ARRAY); - glClientActiveTexture(GL_TEXTURE0); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glClientActiveTexture(GL_TEXTURE1); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - for(int i=2; i<8; i++) { - glClientActiveTexture(GL_TEXTURE0 + i); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } - glVertexPointer(2, GL_FLOAT, 6*sizeof(GLfloat), NULL); - glClientActiveTexture(GL_TEXTURE0); - glTexCoordPointer(2, GL_FLOAT, 6*sizeof(GLfloat), (GLfloat*)NULL+2); - glClientActiveTexture(GL_TEXTURE1); - glTexCoordPointer(2, GL_FLOAT, 6*sizeof(GLfloat), (GLfloat*)NULL+4); + glBindVertexArray(s_VAO); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - - // TODO: this need to be removed in future - glBindBuffer(GL_ARRAY_BUFFER, 0); GL_REPORT_ERRORD(); } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp b/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp index 14035c0634..724212d208 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp @@ -187,6 +187,10 @@ void GLVertexFormat::SetupVertexPointers() { #ifdef USE_JIT ((void (*)())(void*)m_compiledCode)(); #else + // TODO: use this :-) + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindVertexArray(0); + glVertexPointer(3, GL_FLOAT, vtx_decl.stride, VertexManager::s_pBaseBufferPointer); if (vtx_decl.num_normals >= 1) { glNormalPointer(VarToGL(vtx_decl.normal_gl_type), vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.normal_offset[0])); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 30907bde8b..d19cdfd41e 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -108,7 +108,9 @@ namespace OGL // ---------------------------- static int s_fps = 0; static GLuint s_ShowEFBCopyRegions_VBO = 0; +static GLuint s_ShowEFBCopyRegions_VAO = 0; static GLuint s_Swap_VBO = 0; +static GLuint s_Swap_VAO[2]; static TargetRectangle s_cached_targetRc; static RasterFont* s_pfont = NULL; @@ -322,6 +324,13 @@ Renderer::Renderer() bSuccess = false; } + if (!GLEW_ARB_vertex_array_object) + { + ERROR_LOG(VIDEO, "GPU: OGL ERROR: Need GL_ARB_vertex_array_object.\n" + "GPU: Does your video card support OpenGL 3.0?"); + bSuccess = false; + } + s_bHaveFramebufferBlit = strstr(ptoken, "GL_EXT_framebuffer_blit") != NULL; s_bHaveCoverageMSAA = strstr(ptoken, "GL_NV_framebuffer_multisample_coverage") != NULL; @@ -466,7 +475,33 @@ Renderer::Renderer() // creating buffers glGenBuffers(1, &s_ShowEFBCopyRegions_VBO); + glGenVertexArrays(1, &s_ShowEFBCopyRegions_VAO); + glBindBuffer(GL_ARRAY_BUFFER, s_ShowEFBCopyRegions_VBO); + glBindVertexArray( s_ShowEFBCopyRegions_VAO ); + glEnableClientState(GL_COLOR_ARRAY); + glColorPointer (3, GL_FLOAT, sizeof(GLfloat)*5, (GLfloat*)NULL+2); + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(2, GL_FLOAT, sizeof(GLfloat)*5, NULL); + glGenBuffers(1, &s_Swap_VBO); + glGenVertexArrays(2, s_Swap_VAO); + glBindBuffer(GL_ARRAY_BUFFER, s_Swap_VBO); + glBindVertexArray(s_Swap_VAO[0]); + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_FLOAT, 7*sizeof(GLfloat), NULL); + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, 7*sizeof(GLfloat), (GLfloat*)NULL+3); + + glBindVertexArray(s_Swap_VAO[1]); + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_FLOAT, 7*sizeof(GLfloat), NULL); + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, 7*sizeof(GLfloat), (GLfloat*)NULL+3); + glClientActiveTexture(GL_TEXTURE1); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, 7*sizeof(GLfloat), (GLfloat*)NULL+5); glStencilFunc(GL_ALWAYS, 0, 0); glBlendFunc(GL_ONE, GL_ONE); @@ -506,7 +541,9 @@ Renderer::~Renderer() UpdateActiveConfig(); glDeleteBuffers(1, &s_ShowEFBCopyRegions_VBO); + glDeleteVertexArrays(1, &s_ShowEFBCopyRegions_VAO); glDeleteBuffers(1, &s_Swap_VBO); + glDeleteVertexArrays(2, s_Swap_VAO); s_ShowEFBCopyRegions_VBO = 0; delete s_pfont; @@ -657,28 +694,11 @@ void Renderer::DrawDebugInfo() } glUnmapBuffer(GL_ARRAY_BUFFER); - // disable all pointer, TODO: use VAO - glEnableClientState(GL_VERTEX_ARRAY); - glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableVertexAttribArray(SHADER_NORM1_ATTRIB); - glDisableVertexAttribArray(SHADER_NORM2_ATTRIB); - glEnableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_SECONDARY_COLOR_ARRAY); - for(int i=0; i<8; i++) { - glClientActiveTexture(GL_TEXTURE0 + i); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } - - glColorPointer (3, GL_FLOAT, sizeof(GLfloat)*5, (GLfloat*)NULL+2); - glVertexPointer(2, GL_FLOAT, sizeof(GLfloat)*5, NULL); + glBindVertexArray( s_ShowEFBCopyRegions_VAO ); glDrawArrays(GL_LINES, 0, stats.efb_regions.size() * 2*6); // Restore Line Size glLineWidth(lSize); - - // disable buffer TODO: remove this, after everting is in vbo - glBindBuffer(GL_ARRAY_BUFFER, 0); // Clear stored regions stats.efb_regions.clear(); @@ -1252,41 +1272,10 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons glBufferData(GL_ARRAY_BUFFER, 4*7*sizeof(GLfloat), vertices, GL_STREAM_DRAW); s_cached_targetRc = targetRc; - } else { - // TODO: remove this after switch to VAO - glBindBuffer(GL_ARRAY_BUFFER, s_Swap_VBO); - } - - // disable all pointer, TODO: use VAO - glEnableClientState(GL_VERTEX_ARRAY); - glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableVertexAttribArray(SHADER_NORM1_ATTRIB); - glDisableVertexAttribArray(SHADER_NORM2_ATTRIB); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_SECONDARY_COLOR_ARRAY); - glClientActiveTexture(GL_TEXTURE0); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - for(int i=1; i<8; i++) { - glClientActiveTexture(GL_TEXTURE0 + i); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } - - if (applyShader) - { - glClientActiveTexture(GL_TEXTURE1); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - } - - glVertexPointer(3, GL_FLOAT, 7*sizeof(GLfloat), NULL); - glClientActiveTexture(GL_TEXTURE0); - glTexCoordPointer(2, GL_FLOAT, 7*sizeof(GLfloat), (GLfloat*)NULL+3); - glClientActiveTexture(GL_TEXTURE1); - glTexCoordPointer(2, GL_FLOAT, 7*sizeof(GLfloat), (GLfloat*)NULL+5); - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + } - // TODO: also remove this - glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindVertexArray(s_Swap_VAO[applyShader]); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); if(applyShader) PixelShaderCache::DisableShader(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp index 95ddd80e94..046ab4bcf2 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp @@ -58,6 +58,7 @@ namespace OGL struct VBOCache { GLuint vbo; + GLuint vao; TargetRectangle targetSource; }; static std::map s_VBO; @@ -323,6 +324,18 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo item.targetSource.left = -1; item.targetSource.right = -1; glGenBuffers(1, &item.vbo); + glGenVertexArrays(1, &item.vao); + + glBindBuffer(GL_ARRAY_BUFFER, item.vbo); + glBindVertexArray(item.vao); + + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(2, GL_FLOAT, sizeof(GLfloat)*4, 0); + + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat)*4, (GLfloat*)NULL + 2); + vbo_it = s_VBO.insert(std::pair(targetSourceHash, item)).first; } if(!(vbo_it->second.targetSource == targetSource)) { @@ -336,38 +349,15 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo 1.f, 1.f, (GLfloat)targetSource.right, (GLfloat)targetSource.bottom }; - + glBindBuffer(GL_ARRAY_BUFFER, vbo_it->second.vbo); glBufferData(GL_ARRAY_BUFFER, 4*4*sizeof(GLfloat), vertices, GL_STREAM_DRAW); vbo_it->second.targetSource = targetSource; - } else { - // TODO: remove after switched to VAO - glBindBuffer(GL_ARRAY_BUFFER, vbo_it->second.vbo); - } - - // disable all pointer, TODO: use VAO - glEnableClientState(GL_VERTEX_ARRAY); - glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableVertexAttribArray(SHADER_NORM1_ATTRIB); - glDisableVertexAttribArray(SHADER_NORM2_ATTRIB); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_SECONDARY_COLOR_ARRAY); - glClientActiveTexture(GL_TEXTURE0); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - for(int i=1; i<8; i++) { - glClientActiveTexture(GL_TEXTURE0 + i); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } + } - glClientActiveTexture(GL_TEXTURE0); - glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat)*4, (GLfloat*)NULL + 2); - glVertexPointer(2, GL_FLOAT, sizeof(GLfloat)*4, 0); + glBindVertexArray(vbo_it->second.vao); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - - // TODO: this should be removed if we use vbo everywhere - glBindBuffer(GL_ARRAY_BUFFER, 0); GL_REPORT_ERRORD(); @@ -453,7 +443,8 @@ TextureCache::TextureCache() TextureCache::~TextureCache() { for(std::map::iterator it = s_VBO.begin(); it != s_VBO.end(); it++) { - glGenBuffers(1, &it->second.vbo); + glDeleteBuffers(1, &it->second.vbo); + glDeleteVertexArrays(1, &it->second.vao); } s_VBO.clear(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp index 4dab390d09..e2ebe65581 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp @@ -57,8 +57,13 @@ static FRAGMENTSHADER s_yuyvToRgbProgram; const u32 NUM_ENCODING_PROGRAMS = 64; static FRAGMENTSHADER s_encodingPrograms[NUM_ENCODING_PROGRAMS]; -static GLuint s_VBO = 0; +static GLuint s_encode_VBO = 0; +static GLuint s_encode_VAO = 0; +static GLuint s_decode_VBO = 0; +static GLuint s_decode_VAO = 0; static TargetRectangle s_cached_sourceRc; +static int s_cached_srcWidth = 0; +static int s_cached_srcHeight = 0; void CreateRgbToYuyvProgram() { @@ -144,14 +149,37 @@ void Init() { glGenFramebuffersEXT(1, &s_texConvFrameBuffer); - glGenBuffers(1, &s_VBO); + glGenBuffers(1, &s_encode_VBO ); + glGenVertexArrays(1, &s_encode_VAO ); + glBindBuffer(GL_ARRAY_BUFFER, s_encode_VBO ); + glBindVertexArray( s_encode_VAO ); + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(2, GL_FLOAT, 4*sizeof(GLfloat), NULL); + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, 4*sizeof(GLfloat), (GLfloat*)NULL + 2); s_cached_sourceRc.top = -1; s_cached_sourceRc.bottom = -1; s_cached_sourceRc.left = -1; s_cached_sourceRc.right = -1; + + glGenBuffers(1, &s_decode_VBO ); + glGenVertexArrays(1, &s_decode_VAO ); + glBindBuffer(GL_ARRAY_BUFFER, s_decode_VBO ); + glBindVertexArray( s_decode_VAO ); + s_cached_srcWidth = -1; + s_cached_srcHeight = -1; + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(2, GL_FLOAT, sizeof(GLfloat)*4, NULL); + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat)*4, (GLfloat*)NULL+2); + + glGenRenderbuffersEXT(1, &s_dstRenderBuffer); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, s_dstRenderBuffer); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA, renderBufferWidth, renderBufferHeight); s_srcTextureWidth = 0; @@ -171,7 +199,10 @@ void Shutdown() glDeleteTextures(1, &s_srcTexture); glDeleteRenderbuffersEXT(1, &s_dstRenderBuffer); glDeleteFramebuffersEXT(1, &s_texConvFrameBuffer); - glDeleteBuffers(1, &s_VBO); + glDeleteBuffers(1, &s_encode_VBO ); + glDeleteVertexArrays(1, &s_encode_VAO ); + glDeleteBuffers(1, &s_decode_VBO ); + glDeleteVertexArrays(1, &s_decode_VAO ); s_rgbToYuyvProgram.Destroy(); s_yuyvToRgbProgram.Destroy(); @@ -235,38 +266,15 @@ void EncodeToRamUsingShader(FRAGMENTSHADER& shader, GLuint srcTexture, const Tar 1.f, -1.f, (float)sourceRc.right, (float)sourceRc.top }; - glBindBuffer(GL_ARRAY_BUFFER, s_VBO); + glBindBuffer(GL_ARRAY_BUFFER, s_encode_VBO ); glBufferData(GL_ARRAY_BUFFER, 4*4*sizeof(GLfloat), vertices, GL_STREAM_DRAW); s_cached_sourceRc = sourceRc; - } else { - // TODO: remove - glBindBuffer(GL_ARRAY_BUFFER, s_VBO); - } + } - // disable all pointer, TODO: use VAO - glEnableClientState(GL_VERTEX_ARRAY); - glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableVertexAttribArray(SHADER_NORM1_ATTRIB); - glDisableVertexAttribArray(SHADER_NORM2_ATTRIB); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_SECONDARY_COLOR_ARRAY); - glClientActiveTexture(GL_TEXTURE0); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - for(int i=1; i<8; i++) { - glClientActiveTexture(GL_TEXTURE0 + i); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } - - glClientActiveTexture(GL_TEXTURE0); - glTexCoordPointer(2, GL_FLOAT, 4*sizeof(GLfloat), (GLfloat*)NULL + 2); - glVertexPointer(2, GL_FLOAT, 4*sizeof(GLfloat), NULL); + glBindVertexArray( s_encode_VAO ); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - // TODO: remove this - glBindBuffer(GL_ARRAY_BUFFER, 0); - GL_REPORT_ERRORD(); // .. and then read back the results. @@ -422,32 +430,35 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur PixelShaderCache::SetCurrentShader(s_yuyvToRgbProgram.glprogid); GL_REPORT_ERRORD(); - - GLfloat tex1[] = { - (float)srcFmtWidth, (float)srcHeight, - (float)srcFmtWidth, 0.f, - 0.f, 0.f, - 0.f, (float)srcHeight - }; - GLfloat vtx1[] = { - 1.f, -1.f, - 1.f, 1.f, - -1.f, 1.f, - -1.f, -1.f - }; - glClientActiveTexture(GL_TEXTURE0); - glTexCoordPointer(2, GL_FLOAT, 0, tex1); - glVertexPointer(2, GL_FLOAT, 0, vtx1); + if(s_cached_srcHeight != srcHeight || s_cached_srcWidth != srcWidth) { + GLfloat vertices[] = { + 1.f, -1.f, + (float)srcFmtWidth, (float)srcHeight, + 1.f, 1.f, + (float)srcFmtWidth, 0.f, + -1.f, 1.f, + 0.f, 0.f, + -1.f, -1.f, + 0.f, (float)srcHeight + }; + + glBindBuffer(GL_ARRAY_BUFFER, s_decode_VBO ); + glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*4*4, vertices, GL_STREAM_DRAW); + + s_cached_srcHeight = srcHeight; + s_cached_srcWidth = srcWidth; + } + + glBindVertexArray( s_decode_VAO ); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - GL_REPORT_ERRORD(); // reset state glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, 0, 0); - TextureCache::DisableStage(0); + TextureCache::DisableStage(0); VertexShaderManager::SetViewportChanged(); From 75dd48247f908aca7f3dbd945a7411edadbd318c Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 11 Dec 2012 12:37:08 +0100 Subject: [PATCH 21/28] initial release of new RasterFont without color support this new design will once create a texture for all chars. while rendering a string, a list of polygons (position on screen + texture) for this string is generated on the fly and print at once by glDrawArrays. atm, there is no support for colors, so everything will display white. Signed-off-by: Ryan Houdek --- .../Plugin_VideoOGL/Src/RasterFont.cpp | 196 ++++++++++-------- .../Plugins/Plugin_VideoOGL/Src/RasterFont.h | 17 +- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 7 +- .../Plugin_VideoSoftware/Src/SWRenderer.cpp | 5 +- 4 files changed, 120 insertions(+), 105 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp index da53fae6d5..a5467c6e6a 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp @@ -22,7 +22,13 @@ #include "RasterFont.h" // globals -const GLubyte rasters[][13] = { + +static const u32 char_width = 8; +static const u32 char_height = 13; +static const u32 char_offset = 32; +static const u32 char_count = 95; + +const u8 rasters[char_count][char_height] = { {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36}, @@ -122,102 +128,122 @@ const GLubyte rasters[][13] = { RasterFont::RasterFont() { - // set GL modes - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - // create the raster font - fontOffset = glGenLists(128); - for (int i = 32; i < 127; i++) { - glNewList(i + fontOffset, GL_COMPILE); - glBitmap(8, 13, 0.0f, 2.0f, 10.0f, 0.0f, rasters[i - 32]); - glEndList(); + // generate the texture + glEnable(GL_TEXTURE_RECTANGLE); + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_RECTANGLE, texture); + u32* texture_data = new u32[char_width*char_count*char_height]; + for(u32 y=0; y= TEMP_BUFFER_SIZE) - length = TEMP_BUFFER_SIZE - 1; - - // Sanitize string to avoid GL errors. - char *s2 = temp_buffer; - memcpy(s2, s, length); - s2[length] = 0; - for (int i = 0; i < length; i++) { - if (s2[i] < 32 || s2[i] > 126) - s2[i] = '!'; - } - - // go to the right spot - glRasterPos3d(x, y, z); - GL_REPORT_ERRORD(); - - glPushAttrib (GL_LIST_BIT); - glListBase(fontOffset); - glCallLists((GLsizei)strlen(s2), GL_UNSIGNED_BYTE, (GLubyte *) s2); - GL_REPORT_ERRORD(); - glPopAttrib(); - GL_REPORT_ERRORD(); -} - -void RasterFont::printCenteredString(const char *s, double y, int screen_width, double z) -{ - int length = (int)strlen(s); - int x = (int)(screen_width/2.0 - (length/2.0)*char_width); - printString(s, x, y, z); -} - -void RasterFont::printMultilineText(const char *text, double start_x, double start_y, double z, int bbWidth, int bbHeight) -{ - double x = start_x; - double y = start_y; - char temp[1024]; - char *t = temp; - while (*text) - { - if (*text == '\n') - { - *t = 0; - printString(temp, x, y, z); - y -= char_height * 2.0f / bbHeight; + return; // nothing to do + + glBindVertexArray(VAO); + glBindBuffer(GL_ARRAY_BUFFER, VBO); + glBufferData(GL_ARRAY_BUFFER, length*4*6*sizeof(GLfloat), NULL, GL_STREAM_DRAW); + GLfloat *vertices = (GLfloat*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); + + int usage = 0; + GLfloat delta_x = 2*char_width/GLfloat(bbWidth); + GLfloat delta_y = 2*char_height/GLfloat(bbHeight); + GLfloat border_x = 1*2/GLfloat(bbWidth); + GLfloat border_y = 2*2/GLfloat(bbHeight); + + GLfloat x = start_x; + GLfloat y = start_y; + + for(int i=0; i= char_count+char_offset) continue; + + vertices[usage++] = x; + vertices[usage++] = y; + vertices[usage++] = (c-char_offset)*char_width; + vertices[usage++] = 0; + + vertices[usage++] = x+delta_x; + vertices[usage++] = y; + vertices[usage++] = (c-char_offset+1)*char_width; + vertices[usage++] = 0; + + vertices[usage++] = x+delta_x; + vertices[usage++] = y+delta_y; + vertices[usage++] = (c-char_offset+1)*char_width; + vertices[usage++] = char_height; + + vertices[usage++] = x; + vertices[usage++] = y; + vertices[usage++] = (c-char_offset)*char_width; + vertices[usage++] = 0; + + vertices[usage++] = x+delta_x; + vertices[usage++] = y+delta_y; + vertices[usage++] = (c-char_offset+1)*char_width; + vertices[usage++] = char_height; + + vertices[usage++] = x; + vertices[usage++] = y+delta_y; + vertices[usage++] = (c-char_offset)*char_width; + vertices[usage++] = char_height; + + x += delta_x + border_x; } + glUnmapBuffer(GL_ARRAY_BUFFER); + + // no printable char, so also nothing to do + if(!usage) return; - // ???? - if (t != text) - { - *t = 0; - printString(temp, x, y, z); - } + glEnable(GL_BLEND); + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_RECTANGLE, texture); + glEnable(GL_TEXTURE_RECTANGLE); + glDrawArrays(GL_TRIANGLES, 0, usage/4); } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.h b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.h index 3ebc684dd0..e1cd8b87b9 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.h @@ -23,20 +23,13 @@ public: RasterFont(); ~RasterFont(void); static int debug; - - // some useful constants - enum {char_width = 10}; - enum {char_height = 15}; - - // and the happy helper functions - void printString(const char *s, double x, double y, double z=0.0); - void printCenteredString(const char *s, double y, int screen_width, double z=0.0); - void printMultilineText(const char *text, double x, double y, double z, int bbWidth, int bbHeight); + void printMultilineText(const char *text, double x, double y, double z, int bbWidth, int bbHeight, u32 color); private: - int fontOffset; - char *temp_buffer; - enum {TEMP_BUFFER_SIZE = 64 * 1024}; + + u32 VBO; + u32 VAO; + u32 texture; }; #endif // _RASTERFONT_H_ diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index d19cdfd41e..b1191e383c 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -722,14 +722,11 @@ void Renderer::RenderText(const char *text, int left, int top, u32 color) { const int nBackbufferWidth = (int)OpenGL_GetBackbufferWidth(); const int nBackbufferHeight = (int)OpenGL_GetBackbufferHeight(); - - glColor4f(((color>>16) & 0xff)/255.0f, ((color>> 8) & 0xff)/255.0f, - ((color>> 0) & 0xff)/255.0f, ((color>>24) & 0xFF)/255.0f); - + s_pfont->printMultilineText(text, left * 2.0f / (float)nBackbufferWidth - 1, 1 - top * 2.0f / (float)nBackbufferHeight, - 0, nBackbufferWidth, nBackbufferHeight); + 0, nBackbufferWidth, nBackbufferHeight, color); GL_REPORT_ERRORD(); } diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/SWRenderer.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/SWRenderer.cpp index 3923ed0840..0fefa16a93 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/SWRenderer.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/SWRenderer.cpp @@ -101,12 +101,11 @@ void SWRenderer::RenderText(const char* pstr, int left, int top, u32 color) { int nBackbufferWidth = (int)OpenGL_GetBackbufferWidth(); int nBackbufferHeight = (int)OpenGL_GetBackbufferHeight(); - glColor4f(((color>>16) & 0xff)/255.0f, ((color>> 8) & 0xff)/255.0f, - ((color>> 0) & 0xff)/255.0f, ((color>>24) & 0xFF)/255.0f); + s_pfont->printMultilineText(pstr, left * 2.0f / (float)nBackbufferWidth - 1, 1 - top * 2.0f / (float)nBackbufferHeight, - 0, nBackbufferWidth, nBackbufferHeight); + 0, nBackbufferWidth, nBackbufferHeight, color); } void SWRenderer::DrawDebugText() From 23a3336f9a545e88dd7e5f2b96d363c61f9004be Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 11 Dec 2012 17:25:53 +0100 Subject: [PATCH 22/28] increase hash size to u64 Signed-off-by: Ryan Houdek --- Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp index 046ab4bcf2..94304f9c44 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp @@ -61,7 +61,7 @@ struct VBOCache { GLuint vao; TargetRectangle targetSource; }; -static std::map s_VBO; +static std::map s_VBO; static u32 s_TempFramebuffer = 0; @@ -314,8 +314,8 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo GL_REPORT_ERRORD(); // should be unique enough, if not, vbo will "only" be uploaded to much - u32 targetSourceHash = targetSource.left<<24 | targetSource.top<<16 | targetSource.right<<8 | targetSource.bottom; - std::map::iterator vbo_it = s_VBO.find(targetSourceHash); + u64 targetSourceHash = u64(targetSource.left)<<48 | u64(targetSource.top)<<32 | u64(targetSource.right)<<16 | u64(targetSource.bottom); + std::map::iterator vbo_it = s_VBO.find(targetSourceHash); if(vbo_it == s_VBO.end()) { VBOCache item; @@ -336,7 +336,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat)*4, (GLfloat*)NULL + 2); - vbo_it = s_VBO.insert(std::pair(targetSourceHash, item)).first; + vbo_it = s_VBO.insert(std::pair(targetSourceHash, item)).first; } if(!(vbo_it->second.targetSource == targetSource)) { GLfloat vertices[] = { @@ -442,7 +442,7 @@ TextureCache::TextureCache() TextureCache::~TextureCache() { - for(std::map::iterator it = s_VBO.begin(); it != s_VBO.end(); it++) { + for(std::map::iterator it = s_VBO.begin(); it != s_VBO.end(); it++) { glDeleteBuffers(1, &it->second.vbo); glDeleteVertexArrays(1, &it->second.vao); } From 1bd21f44b28858d5d891b386e6bfb47df9c885a4 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 11 Dec 2012 22:08:53 +0100 Subject: [PATCH 23/28] custom shader for RasterFont, fix color support OpenGL2.0 compatible Signed-off-by: Ryan Houdek --- .../Plugin_VideoOGL/Src/RasterFont.cpp | 65 ++++++++++++++++--- .../Plugins/Plugin_VideoOGL/Src/RasterFont.h | 3 + 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp index a5467c6e6a..ba0135146f 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp @@ -126,6 +126,23 @@ const u8 rasters[char_count][char_height] = { {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x8f, 0xf1, 0x60, 0x00, 0x00, 0x00} }; +static const char *s_vertex_shader = + "attribute vec2 vertexPosition;\n" + "attribute vec2 texturePosition;\n" + "varying vec2 tpos;\n" + "void main(void) {\n" + " gl_Position = vec4(vertexPosition,0,1);\n" + " tpos = texturePosition;\n" + "}\n"; + +static const char *s_fragment_shader = + "uniform sampler2DRect textureSampler;\n" + "uniform vec4 color;\n" + "varying vec2 tpos;\n" + "void main(void) {\n" + " gl_FragColor = texture2DRect(textureSampler,tpos) * color;\n" + "}\n"; + RasterFont::RasterFont() { // generate the texture @@ -149,12 +166,35 @@ RasterFont::RasterFont() glGenVertexArrays(1, &VAO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBindVertexArray(VAO); - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, sizeof(GLfloat)*4, NULL); - glEnable(GL_TEXTURE_RECTANGLE); - glClientActiveTexture(GL_TEXTURE0); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat)*4, (GLfloat*)NULL+2); + glEnableVertexAttribArray(0); // vertexPosition + glVertexAttribPointer(0, 2, GL_FLOAT, 0, sizeof(GLfloat)*4, NULL); + glEnableVertexAttribArray(1); // texturePosition + glVertexAttribPointer(1, 2, GL_FLOAT, 0, sizeof(GLfloat)*4, (GLfloat*)NULL+2); + + // generate shader + GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER); + GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); + shader_program = glCreateProgram(); + + glShaderSource(vertex_shader, 1, &s_vertex_shader, NULL); + glCompileShader(vertex_shader); + glShaderSource(fragment_shader, 1, &s_fragment_shader, NULL); + glCompileShader(fragment_shader); + glAttachShader(shader_program, vertex_shader); + glAttachShader(shader_program, fragment_shader); + glBindAttribLocation(shader_program, 0, "vertexPosition"); + glBindAttribLocation(shader_program, 1, "texturePosition"); + glLinkProgram(shader_program); + glDeleteShader(vertex_shader); + glDeleteShader(fragment_shader); + + // bound uniforms + glUseProgram(shader_program); + glUniform1i(glGetUniformLocation(shader_program,"textureSampler"), 0); // GL_TEXTURE0 + uniform_color_id = glGetUniformLocation(shader_program,"color"); + glUniform4f(uniform_color_id, 1, 1, 1, 1); + cached_color = -1; + glUseProgram(0); } RasterFont::~RasterFont() @@ -162,12 +202,11 @@ RasterFont::~RasterFont() glDeleteTextures(1, &texture); glDeleteBuffers(1, &VBO); glDeleteVertexArrays(1, &VAO); + glDeleteProgram(shader_program); } void RasterFont::printMultilineText(const char *text, double start_x, double start_y, double z, int bbWidth, int bbHeight, u32 color) { - if(!(color & 0xffffff)) return; // color are not supported atm, so do not draw black shadows - int length = (int)strlen(text); if (!length) return; // nothing to do @@ -240,10 +279,20 @@ void RasterFont::printMultilineText(const char *text, double start_x, double sta // no printable char, so also nothing to do if(!usage) return; + glUseProgram(shader_program); + + if(color != cached_color) { + glUniform4f(uniform_color_id, ((color>>0)&0xff)/255.f,((color>>8)&0xff)/255.f,((color>>16)&0xff)/255.f,((color>>24)&0xff)/255.f); + cached_color = color; + } + + glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_RECTANGLE, texture); glEnable(GL_TEXTURE_RECTANGLE); glDrawArrays(GL_TRIANGLES, 0, usage/4); + + glUseProgram(0); } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.h b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.h index e1cd8b87b9..fcbfdfff61 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.h @@ -30,6 +30,9 @@ private: u32 VBO; u32 VAO; u32 texture; + u32 shader_program; + u32 uniform_color_id; + u32 cached_color; }; #endif // _RASTERFONT_H_ From 48812f7bf7defc334a9fb2c9503a589a250b5603 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 11 Dec 2012 22:46:02 +0100 Subject: [PATCH 24/28] update the rasterfont shader to GLSL3.3 - so OGL 3.3 is needed Signed-off-by: Ryan Houdek --- Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp index ba0135146f..6c98824341 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp @@ -127,18 +127,22 @@ const u8 rasters[char_count][char_height] = { }; static const char *s_vertex_shader = - "attribute vec2 vertexPosition;\n" - "attribute vec2 texturePosition;\n" - "varying vec2 tpos;\n" + "#version 330 core\n" + "layout(location = 0) in vec2 vertexPosition;\n" + "layout(location = 1) in vec2 texturePosition;\n" + "out vec2 tpos;\n" "void main(void) {\n" " gl_Position = vec4(vertexPosition,0,1);\n" " tpos = texturePosition;\n" "}\n"; static const char *s_fragment_shader = + "#version 330 core\n" + "#extension GL_ARB_texture_rectangle : enable\n" "uniform sampler2DRect textureSampler;\n" "uniform vec4 color;\n" - "varying vec2 tpos;\n" + "in vec2 tpos;\n" + "out vec4 gl_FragColor;\n" "void main(void) {\n" " gl_FragColor = texture2DRect(textureSampler,tpos) * color;\n" "}\n"; @@ -182,8 +186,6 @@ RasterFont::RasterFont() glCompileShader(fragment_shader); glAttachShader(shader_program, vertex_shader); glAttachShader(shader_program, fragment_shader); - glBindAttribLocation(shader_program, 0, "vertexPosition"); - glBindAttribLocation(shader_program, 1, "texturePosition"); glLinkProgram(shader_program); glDeleteShader(vertex_shader); glDeleteShader(fragment_shader); From 61836f8c51e84083a98c3d852f572e6f03d28e8b Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 12 Dec 2012 10:40:03 +0100 Subject: [PATCH 25/28] helper for compiling glsl Signed-off-by: Ryan Houdek --- Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp | 64 +++++++++++++++++++ Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h | 6 ++ .../Plugin_VideoOGL/Src/RasterFont.cpp | 14 +--- 3 files changed, 71 insertions(+), 13 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp index 5110023ee3..574ca33a05 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp @@ -629,6 +629,70 @@ void OpenGL_Shutdown() #endif } +GLuint OpenGL_CompileProgram ( const char* vertexShader, const char* fragmentShader ) +{ + // generate objects + GLuint vertexShaderID = glCreateShader(GL_VERTEX_SHADER); + GLuint fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER); + GLuint programID = glCreateProgram(); + GLint Result = GL_FALSE; + char stringBuffer[1024]; + GLsizei stringBufferUsage = 0; + + // compile vertex shader + glShaderSource(vertexShaderID, 1, &vertexShader, NULL); + glCompileShader(vertexShaderID); +#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL) + glGetShaderiv(vertexShaderID, GL_COMPILE_STATUS, &Result); + glGetShaderInfoLog(vertexShaderID, 1024, &stringBufferUsage, stringBuffer); + if(Result && stringBufferUsage) { + ERROR_LOG(VIDEO, "GLSL vertex shader warnings:\n%s%s", stringBuffer, vertexShader); + } else if(!Result) { + ERROR_LOG(VIDEO, "GLSL vertex shader error:\n%s%s", stringBuffer, vertexShader); + } else { + DEBUG_LOG(VIDEO, "GLSL vertex shader compiled:\n%s", vertexShader); + } + bool shader_errors = !Result; +#endif + + // compile fragment shader + glShaderSource(fragmentShaderID, 1, &fragmentShader, NULL); + glCompileShader(fragmentShaderID); +#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL) + glGetShaderiv(fragmentShaderID, GL_COMPILE_STATUS, &Result); + glGetShaderInfoLog(fragmentShaderID, 1024, &stringBufferUsage, stringBuffer); + if(Result && stringBufferUsage) { + ERROR_LOG(VIDEO, "GLSL fragment shader warnings:\n%s%s", stringBuffer, fragmentShader); + } else if(!Result) { + ERROR_LOG(VIDEO, "GLSL fragment shader error:\n%s%s", stringBuffer, fragmentShader); + } else { + DEBUG_LOG(VIDEO, "GLSL fragment shader compiled:\n%s", fragmentShader); + } + shader_errors |= !Result; +#endif + + // link them + glAttachShader(programID, vertexShaderID); + glAttachShader(programID, fragmentShaderID); + glLinkProgram(programID); +#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL) + glGetProgramiv(programID, GL_LINK_STATUS, &Result); + glGetProgramInfoLog(programID, 1024, &stringBufferUsage, stringBuffer); + if(Result && stringBufferUsage) { + ERROR_LOG(VIDEO, "GLSL linker warnings:\n%s%s%s", stringBuffer, vertexShader, fragmentShader); + } else if(!Result && !shader_errors) { + ERROR_LOG(VIDEO, "GLSL linker error:\n%s%s%s", stringBuffer, vertexShader, fragmentShader); + } +#endif + + // cleanup + glDeleteShader(vertexShaderID); + glDeleteShader(fragmentShaderID); + + return programID; +} + + GLuint OpenGL_ReportGLError(const char *function, const char *file, int line) { GLint err = glGetError(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h index 23c31a1bb7..61f3ef6085 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h @@ -96,6 +96,9 @@ u32 OpenGL_GetBackbufferHeight(); // Set things void OpenGL_SetWindowText(const char *text); +// Helpers +GLuint OpenGL_CompileProgram(const char *vertexShader, const char *fragmentShader); + // Error reporting - use the convenient macros. void OpenGL_ReportARBProgramError(); GLuint OpenGL_ReportGLError(const char *function, const char *file, int line); @@ -126,4 +129,7 @@ extern CGprofile g_cgvProf, g_cgfProf; // use GLSL shaders across the whole pipeline. Yikes! //#define USE_DUAL_SOURCE_BLEND +// TODO: should be removed if we use glsl a lot +#define DEBUG_GLSL + #endif // _GLINIT_H_ diff --git a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp index 6c98824341..29166e4bc0 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp @@ -176,19 +176,7 @@ RasterFont::RasterFont() glVertexAttribPointer(1, 2, GL_FLOAT, 0, sizeof(GLfloat)*4, (GLfloat*)NULL+2); // generate shader - GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER); - GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); - shader_program = glCreateProgram(); - - glShaderSource(vertex_shader, 1, &s_vertex_shader, NULL); - glCompileShader(vertex_shader); - glShaderSource(fragment_shader, 1, &s_fragment_shader, NULL); - glCompileShader(fragment_shader); - glAttachShader(shader_program, vertex_shader); - glAttachShader(shader_program, fragment_shader); - glLinkProgram(shader_program); - glDeleteShader(vertex_shader); - glDeleteShader(fragment_shader); + shader_program = OpenGL_CompileProgram(s_vertex_shader, s_fragment_shader); // bound uniforms glUseProgram(shader_program); From 09274e2483abd7ea0ae26daa32f9cf3f7a3e2b16 Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 12 Dec 2012 16:57:00 +0100 Subject: [PATCH 26/28] Check texture params before updateing them Signed-off-by: Ryan Houdek --- Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp | 4 ---- Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp | 9 ++++++++- Source/Plugins/Plugin_VideoOGL/Src/TextureCache.h | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp index 29166e4bc0..e3575eef4e 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp @@ -17,8 +17,6 @@ #include "GLUtil.h" -#include - #include "RasterFont.h" // globals @@ -150,7 +148,6 @@ static const char *s_fragment_shader = RasterFont::RasterFont() { // generate the texture - glEnable(GL_TEXTURE_RECTANGLE); glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_RECTANGLE, texture); u32* texture_data = new u32[char_width*char_count*char_height]; @@ -281,7 +278,6 @@ void RasterFont::printMultilineText(const char *text, double start_x, double sta glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_RECTANGLE, texture); - glEnable(GL_TEXTURE_RECTANGLE); glDrawArrays(GL_TRIANGLES, 0, usage/4); glUseProgram(0); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp index 94304f9c44..4f05ccb777 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp @@ -113,6 +113,8 @@ TextureCache::TCacheEntry::~TCacheEntry() TextureCache::TCacheEntry::TCacheEntry() { glGenTextures(1, &texture); + currmode.hex = 0; + currmode1.hex = 0; GL_REPORT_ERRORD(); } @@ -125,7 +127,9 @@ void TextureCache::TCacheEntry::Bind(unsigned int stage) // TODO: is this already done somewhere else? TexMode0 &tm0 = bpmem.tex[stage >> 2].texMode0[stage & 3]; TexMode1 &tm1 = bpmem.tex[stage >> 2].texMode1[stage & 3]; - SetTextureParameters(tm0, tm1); + + if(currmode.hex != tm0.hex || currmode1.hex != tm1.hex) + SetTextureParameters(tm0, tm1); } bool TextureCache::TCacheEntry::Save(const char filename[], unsigned int level) @@ -404,6 +408,9 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo void TextureCache::TCacheEntry::SetTextureParameters(const TexMode0 &newmode, const TexMode1 &newmode1) { + currmode = newmode; + currmode1 = newmode1; + // TODO: not used anywhere TexMode0 mode = newmode; //mode1 = newmode1; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.h b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.h index 91245237d9..dc560e098b 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.h @@ -67,6 +67,8 @@ private: private: void SetTextureParameters(const TexMode0 &newmode, const TexMode1 &newmode1); + TexMode0 currmode; + TexMode1 currmode1; }; ~TextureCache(); From 79a7ce4827de774bc0d454ad2e679f99e1da96fe Mon Sep 17 00:00:00 2001 From: degasus Date: Thu, 13 Dec 2012 15:48:42 +0100 Subject: [PATCH 27/28] move glBindBuffer and glBindVertexArray out of VertexManager Signed-off-by: Ryan Houdek --- .../Plugin_VideoOGL/Src/FramebufferManager.cpp | 12 +++++++++++- .../Plugin_VideoOGL/Src/NativeVertexFormat.cpp | 15 ++++++--------- .../Plugins/Plugin_VideoOGL/Src/RasterFont.cpp | 8 ++++++++ Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 15 +++++++++++++++ .../Plugin_VideoOGL/Src/TextureCache.cpp | 6 ++++++ .../Plugin_VideoOGL/Src/TextureConverter.cpp | 18 ++++++++++++++++-- 6 files changed, 62 insertions(+), 12 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp index 9c66396226..0220e54806 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp @@ -201,7 +201,11 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms glClientActiveTexture(GL_TEXTURE1); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 6*sizeof(GLfloat), (GLfloat*)NULL+4); - + + // TODO: this after merging with graphic_update + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindVertexArray(0); + // EFB framebuffer is currently bound, make sure to clear its alpha value to 1.f glViewport(0, 0, m_targetWidth, m_targetHeight); glScissor(0, 0, m_targetWidth, m_targetHeight); @@ -356,6 +360,9 @@ void XFBSource::Draw(const MathUtil::Rectangle &sourcerc, }; glBindBuffer(GL_ARRAY_BUFFER, s_VBO); glBufferData(GL_ARRAY_BUFFER, 2*4*3*sizeof(GLfloat), vertices, GL_STREAM_DRAW); + + // TODO: this after merging with graphic_update + glBindBuffer(GL_ARRAY_BUFFER, 0); s_cached_sourcerc = sourcerc; s_cached_drawrc = drawrc; @@ -363,6 +370,9 @@ void XFBSource::Draw(const MathUtil::Rectangle &sourcerc, glBindVertexArray(s_VAO); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + // TODO: this after merging with graphic_update + glBindVertexArray(0); GL_REPORT_ERRORD(); } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp b/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp index 724212d208..a435be0dca 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp @@ -187,9 +187,6 @@ void GLVertexFormat::SetupVertexPointers() { #ifdef USE_JIT ((void (*)())(void*)m_compiledCode)(); #else - // TODO: use this :-) - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindVertexArray(0); glVertexPointer(3, GL_FLOAT, vtx_decl.stride, VertexManager::s_pBaseBufferPointer); if (vtx_decl.num_normals >= 1) { @@ -224,13 +221,13 @@ void GLVertexFormat::SetupVertexPointers() { } #endif -// if (s_prevcomponents != m_components) + if (s_prevcomponents != m_components) { // vertices glEnableClientState(GL_VERTEX_ARRAY); // matrices -// if ((m_components & VB_HAS_POSMTXIDX) != (s_prevcomponents & VB_HAS_POSMTXIDX)) + if ((m_components & VB_HAS_POSMTXIDX) != (s_prevcomponents & VB_HAS_POSMTXIDX)) { if (m_components & VB_HAS_POSMTXIDX) glEnableVertexAttribArray(SHADER_POSMTX_ATTRIB); @@ -239,14 +236,14 @@ void GLVertexFormat::SetupVertexPointers() { } // normals -// if ((m_components & VB_HAS_NRM0) != (s_prevcomponents & VB_HAS_NRM0)) + if ((m_components & VB_HAS_NRM0) != (s_prevcomponents & VB_HAS_NRM0)) { if (m_components & VB_HAS_NRM0) glEnableClientState(GL_NORMAL_ARRAY); else glDisableClientState(GL_NORMAL_ARRAY); } -// if ((m_components & VB_HAS_NRM1) != (s_prevcomponents & VB_HAS_NRM1)) + if ((m_components & VB_HAS_NRM1) != (s_prevcomponents & VB_HAS_NRM1)) { if (m_components & VB_HAS_NRM1) { glEnableVertexAttribArray(SHADER_NORM1_ATTRIB); @@ -261,7 +258,7 @@ void GLVertexFormat::SetupVertexPointers() { // color for (int i = 0; i < 2; ++i) { -// if ((m_components & (VB_HAS_COL0 << i)) != (s_prevcomponents & (VB_HAS_COL0 << i))) + if ((m_components & (VB_HAS_COL0 << i)) != (s_prevcomponents & (VB_HAS_COL0 << i))) { if (m_components & (VB_HAS_COL0 << i)) glEnableClientState(i ? GL_SECONDARY_COLOR_ARRAY : GL_COLOR_ARRAY); @@ -273,7 +270,7 @@ void GLVertexFormat::SetupVertexPointers() { // tex for (int i = 0; i < 8; ++i) { -// if ((m_components & (VB_HAS_UV0 << i)) != (s_prevcomponents & (VB_HAS_UV0 << i))) + if ((m_components & (VB_HAS_UV0 << i)) != (s_prevcomponents & (VB_HAS_UV0 << i))) { glClientActiveTexture(GL_TEXTURE0 + i); if (m_components & (VB_HAS_UV0 << i)) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp index e3575eef4e..13e0cb6210 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp @@ -182,6 +182,10 @@ RasterFont::RasterFont() glUniform4f(uniform_color_id, 1, 1, 1, 1); cached_color = -1; glUseProgram(0); + + // TODO: this after merging with graphic_update + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindVertexArray(0); } RasterFont::~RasterFont() @@ -280,5 +284,9 @@ void RasterFont::printMultilineText(const char *text, double start_x, double sta glBindTexture(GL_TEXTURE_RECTANGLE, texture); glDrawArrays(GL_TRIANGLES, 0, usage/4); + // TODO: this after merging with graphic_update + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindVertexArray(0); + glUseProgram(0); } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index b1191e383c..59f61b6a60 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -503,6 +503,10 @@ Renderer::Renderer() glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 7*sizeof(GLfloat), (GLfloat*)NULL+5); + // TODO: this after merging with graphic_update + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindVertexArray(0); + glStencilFunc(GL_ALWAYS, 0, 0); glBlendFunc(GL_ONE, GL_ONE); @@ -696,6 +700,10 @@ void Renderer::DrawDebugInfo() glBindVertexArray( s_ShowEFBCopyRegions_VAO ); glDrawArrays(GL_LINES, 0, stats.efb_regions.size() * 2*6); + + // TODO: this after merging with graphic_update + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindVertexArray(0); // Restore Line Size glLineWidth(lSize); @@ -1268,12 +1276,19 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons glBindBuffer(GL_ARRAY_BUFFER, s_Swap_VBO); glBufferData(GL_ARRAY_BUFFER, 4*7*sizeof(GLfloat), vertices, GL_STREAM_DRAW); + // TODO: this after merging with graphic_update + glBindBuffer(GL_ARRAY_BUFFER, 0); + s_cached_targetRc = targetRc; } glBindVertexArray(s_Swap_VAO[applyShader]); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + // TODO: this after merging with graphic_update + glBindVertexArray(0); + if(applyShader) PixelShaderCache::DisableShader(); } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp index 4f05ccb777..40dac17df6 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp @@ -357,11 +357,17 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo glBindBuffer(GL_ARRAY_BUFFER, vbo_it->second.vbo); glBufferData(GL_ARRAY_BUFFER, 4*4*sizeof(GLfloat), vertices, GL_STREAM_DRAW); + // TODO: this after merging with graphic_update + glBindBuffer(GL_ARRAY_BUFFER, 0); + vbo_it->second.targetSource = targetSource; } glBindVertexArray(vbo_it->second.vao); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + // TODO: this after merging with graphic_update + glBindVertexArray(0); GL_REPORT_ERRORD(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp index e2ebe65581..f45277f759 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp @@ -175,7 +175,9 @@ void Init() glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat)*4, (GLfloat*)NULL+2); - + // TODO: this after merging with graphic_update + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindVertexArray(0); glGenRenderbuffersEXT(1, &s_dstRenderBuffer); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, s_dstRenderBuffer); @@ -269,12 +271,18 @@ void EncodeToRamUsingShader(FRAGMENTSHADER& shader, GLuint srcTexture, const Tar glBindBuffer(GL_ARRAY_BUFFER, s_encode_VBO ); glBufferData(GL_ARRAY_BUFFER, 4*4*sizeof(GLfloat), vertices, GL_STREAM_DRAW); + // TODO: this after merging with graphic_update + glBindBuffer(GL_ARRAY_BUFFER, 0); + s_cached_sourceRc = sourceRc; } glBindVertexArray( s_encode_VAO ); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + // TODO: this after merging with graphic_update + glBindVertexArray(0); + GL_REPORT_ERRORD(); // .. and then read back the results. @@ -446,13 +454,19 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur glBindBuffer(GL_ARRAY_BUFFER, s_decode_VBO ); glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*4*4, vertices, GL_STREAM_DRAW); + // TODO: this after merging with graphic_update + glBindBuffer(GL_ARRAY_BUFFER, 0); + s_cached_srcHeight = srcHeight; s_cached_srcWidth = srcWidth; } glBindVertexArray( s_decode_VAO ); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - + + // TODO: this after merging with graphic_update + glBindVertexArray(0); + GL_REPORT_ERRORD(); // reset state From 399a6af66de69ffaf54d779441b57b05aa2b24e0 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 25 Dec 2012 12:22:02 +0100 Subject: [PATCH 28/28] revert update the rasterfont shader to GLSL3.3 - OGL 2.0 should be enough --- .../Plugin_VideoOGL/Src/RasterFont.cpp | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp index 13e0cb6210..bf3681483b 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp @@ -125,22 +125,19 @@ const u8 rasters[char_count][char_height] = { }; static const char *s_vertex_shader = - "#version 330 core\n" - "layout(location = 0) in vec2 vertexPosition;\n" - "layout(location = 1) in vec2 texturePosition;\n" - "out vec2 tpos;\n" + "attribute vec2 vertexPosition;\n" + "attribute vec2 texturePosition;\n" + "varying vec2 tpos;\n" "void main(void) {\n" " gl_Position = vec4(vertexPosition,0,1);\n" " tpos = texturePosition;\n" "}\n"; static const char *s_fragment_shader = - "#version 330 core\n" "#extension GL_ARB_texture_rectangle : enable\n" "uniform sampler2DRect textureSampler;\n" "uniform vec4 color;\n" - "in vec2 tpos;\n" - "out vec4 gl_FragColor;\n" + "varying vec2 tpos;\n" "void main(void) {\n" " gl_FragColor = texture2DRect(textureSampler,tpos) * color;\n" "}\n"; @@ -162,16 +159,6 @@ RasterFont::RasterFont() glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, char_width*char_count, char_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture_data); delete [] texture_data; - // generate VBO & VAO - glGenBuffers(1, &VBO); - glGenVertexArrays(1, &VAO); - glBindBuffer(GL_ARRAY_BUFFER, VBO); - glBindVertexArray(VAO); - glEnableVertexAttribArray(0); // vertexPosition - glVertexAttribPointer(0, 2, GL_FLOAT, 0, sizeof(GLfloat)*4, NULL); - glEnableVertexAttribArray(1); // texturePosition - glVertexAttribPointer(1, 2, GL_FLOAT, 0, sizeof(GLfloat)*4, (GLfloat*)NULL+2); - // generate shader shader_program = OpenGL_CompileProgram(s_vertex_shader, s_fragment_shader); @@ -183,6 +170,16 @@ RasterFont::RasterFont() cached_color = -1; glUseProgram(0); + // generate VBO & VAO + glGenBuffers(1, &VBO); + glGenVertexArrays(1, &VAO); + glBindBuffer(GL_ARRAY_BUFFER, VBO); + glBindVertexArray(VAO); + glEnableVertexAttribArray(glGetAttribLocation(shader_program, "vertexPosition")); + glVertexAttribPointer(glGetAttribLocation(shader_program, "vertexPosition"), 2, GL_FLOAT, 0, sizeof(GLfloat)*4, NULL); + glEnableVertexAttribArray(glGetAttribLocation(shader_program, "texturePosition")); + glVertexAttribPointer(glGetAttribLocation(shader_program, "texturePosition"), 2, GL_FLOAT, 0, sizeof(GLfloat)*4, (GLfloat*)NULL+2); + // TODO: this after merging with graphic_update glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0);