From 911fd6c4e9d20799ec22ef9cd33e5ffc2b906508 Mon Sep 17 00:00:00 2001 From: pradeep Date: Tue, 6 Dec 2016 16:59:39 +0530 Subject: [PATCH 1/7] fix indentation in surface impl file --- src/backend/opengl/surface_impl.cpp | 77 +++++++++++++++-------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/src/backend/opengl/surface_impl.cpp b/src/backend/opengl/surface_impl.cpp index 9e484e4d..6ffcfcb8 100644 --- a/src/backend/opengl/surface_impl.cpp +++ b/src/backend/opengl/surface_impl.cpp @@ -25,24 +25,25 @@ using namespace std; void generateGridIndices(unsigned short rows, unsigned short cols, unsigned short *indices) { -unsigned short idx = 0; -for(unsigned short r = 0; r < rows-1; ++r){ - for(unsigned short c = 0; c < cols*2; ++c){ - unsigned short i = c + (r * (cols*2)); - - if(c == cols * 2 - 1) { - *indices++ = idx; - }else{ - *indices++ = idx; - if(i%2 == 0){ - idx += cols; + unsigned short idx = 0; + + for(unsigned short r = 0; r < rows-1; ++r) { + for(unsigned short c = 0; c < cols*2; ++c) { + unsigned short i = c + (r * (cols*2)); + + if (c == cols * 2 - 1) { + *indices++ = idx; } else { - idx -= (r%2 == 0) ? (cols-1) : (cols+1); + *indices++ = idx; + if (i%2 == 0) { + idx += cols; + } else { + idx -= (r%2 == 0) ? (cols-1) : (cols+1); + } } } } } -} namespace forge { @@ -51,36 +52,36 @@ namespace opengl void surface_impl::bindResources(const int pWindowId) { -if (mVAOMap.find(pWindowId) == mVAOMap.end()) { - GLuint vao = 0; - /* create a vertex array object - * with appropriate bindings */ - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - // attach plot vertices - glEnableVertexAttribArray(mSurfPointIndex); - glBindBuffer(GL_ARRAY_BUFFER, mVBO); - glVertexAttribPointer(mSurfPointIndex, 3, mDataType, GL_FALSE, 0, 0); - glEnableVertexAttribArray(mSurfColorIndex); - glBindBuffer(GL_ARRAY_BUFFER, mCBO); - glVertexAttribPointer(mSurfColorIndex, 3, GL_FLOAT, GL_FALSE, 0, 0); - glEnableVertexAttribArray(mSurfAlphaIndex); - glBindBuffer(GL_ARRAY_BUFFER, mABO); - glVertexAttribPointer(mSurfAlphaIndex, 1, GL_FLOAT, GL_FALSE, 0, 0); - //attach indices - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIBO); - glBindVertexArray(0); - /* store the vertex array object corresponding to - * the window instance in the map */ - mVAOMap[pWindowId] = vao; -} + if (mVAOMap.find(pWindowId) == mVAOMap.end()) { + GLuint vao = 0; + /* create a vertex array object + * with appropriate bindings */ + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + // attach plot vertices + glEnableVertexAttribArray(mSurfPointIndex); + glBindBuffer(GL_ARRAY_BUFFER, mVBO); + glVertexAttribPointer(mSurfPointIndex, 3, mDataType, GL_FALSE, 0, 0); + glEnableVertexAttribArray(mSurfColorIndex); + glBindBuffer(GL_ARRAY_BUFFER, mCBO); + glVertexAttribPointer(mSurfColorIndex, 3, GL_FLOAT, GL_FALSE, 0, 0); + glEnableVertexAttribArray(mSurfAlphaIndex); + glBindBuffer(GL_ARRAY_BUFFER, mABO); + glVertexAttribPointer(mSurfAlphaIndex, 1, GL_FLOAT, GL_FALSE, 0, 0); + //attach indices + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIBO); + glBindVertexArray(0); + /* store the vertex array object corresponding to + * the window instance in the map */ + mVAOMap[pWindowId] = vao; + } -glBindVertexArray(mVAOMap[pWindowId]); + glBindVertexArray(mVAOMap[pWindowId]); } void surface_impl::unbindResources() const { -glBindVertexArray(0); + glBindVertexArray(0); } glm::mat4 surface_impl::computeTransformMat(const glm::mat4& pView, const glm::mat4& pOrient) From 4df785c7b26917b2c138e9001b3a2512949cf95a Mon Sep 17 00:00:00 2001 From: pradeep Date: Wed, 7 Dec 2016 13:42:59 +0530 Subject: [PATCH 2/7] fix index buffer for surface's triangular strip --- src/backend/opengl/surface_impl.cpp | 43 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/backend/opengl/surface_impl.cpp b/src/backend/opengl/surface_impl.cpp index 6ffcfcb8..5d9f386b 100644 --- a/src/backend/opengl/surface_impl.cpp +++ b/src/backend/opengl/surface_impl.cpp @@ -23,24 +23,24 @@ using namespace gl; using namespace std; -void generateGridIndices(unsigned short rows, unsigned short cols, unsigned short *indices) +void generateGridIndices(unsigned short rows, unsigned short cols, + std::vector& indices) { - unsigned short idx = 0; - - for(unsigned short r = 0; r < rows-1; ++r) { - for(unsigned short c = 0; c < cols*2; ++c) { - unsigned short i = c + (r * (cols*2)); - - if (c == cols * 2 - 1) { - *indices++ = idx; - } else { - *indices++ = idx; - if (i%2 == 0) { - idx += cols; - } else { - idx -= (r%2 == 0) ? (cols-1) : (cols+1); - } - } + for (unsigned short r = 0; r < (rows-1); ++r) { + if (r > 0) { + // repeat first vertex for degenerate triangle + indices.push_back(r*rows); + } + + for (unsigned short c = 0; c < cols; ++c) { + // One part of the strip + indices.push_back(r*rows + c); + indices.push_back((r+1)*rows + c); + } + + if (r < (rows-2)) { + // repeat last vertex for degenerate triangle + indices.push_back(((r + 1) * rows) + (cols - 1)); } } } @@ -202,9 +202,12 @@ surface_impl::surface_impl(unsigned pNumXPoints, unsigned pNumYPoints, #undef SURF_CREATE_BUFFERS - mIBOSize = (2 * mNumYPoints) * (mNumXPoints - 1); - std::vector indices(mIBOSize); - generateGridIndices(mNumXPoints, mNumYPoints, indices.data()); + std::vector indices; + + generateGridIndices(mNumXPoints, mNumYPoints, indices); + + mIBOSize = indices.size(); + mIBO = createBuffer(GL_ELEMENT_ARRAY_BUFFER, mIBOSize, indices.data(), GL_STATIC_DRAW); CheckGL("End surface_impl::surface_impl"); From a23f095fc83e94f8a4b0cbc148cdd0bc9cce3d84 Mon Sep 17 00:00:00 2001 From: pradeep Date: Fri, 9 Dec 2016 11:54:58 +0530 Subject: [PATCH 3/7] fix index buffer type in surface --- examples/cpu/surface.cpp | 16 ++++++++-------- src/backend/opengl/surface_impl.cpp | 18 +++++++++--------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/examples/cpu/surface.cpp b/examples/cpu/surface.cpp index 0d0135e5..8e16ca29 100644 --- a/examples/cpu/surface.cpp +++ b/examples/cpu/surface.cpp @@ -17,20 +17,20 @@ using namespace std; -static const float XMIN = -8.0f; -static const float XMAX = 8.f; -static const float YMIN = -8.0f; -static const float YMAX = 8.f; +static const float XMIN = -32.0f; +static const float XMAX = 32.f; +static const float YMIN = -32.0f; +static const float YMAX = 32.f; -const float DX = 0.5; +const float DX = 0.25; const size_t XSIZE = (XMAX-XMIN)/DX; const size_t YSIZE = (YMAX-YMIN)/DX; void genSurface(float dx, std::vector &vec ) { vec.clear(); - for(float x=XMIN; x < XMAX; x+=dx){ - for(float y=YMIN; y < YMAX; y+=dx){ + for(float x=XMIN; x < XMAX; x+=dx) { + for(float y=YMIN; y < YMAX; y+=dx) { vec.push_back(x); vec.push_back(y); float z = sqrt(x*x+y*y) + 2.2204e-16; @@ -50,7 +50,7 @@ int main(void) wnd.makeCurrent(); forge::Chart chart(FG_CHART_3D); - chart.setAxesLimits(-10.f, 10.f, -10.f, 10.f, -0.5f, 1.f); + chart.setAxesLimits(XMIN-2.0f, XMAX+2.0f, YMIN-2.0f, YMAX+2.0f, -0.5f, 1.f); chart.setAxesTitles("x-axis", "y-axis", "z-axis"); forge::Surface surf = chart.surface(XSIZE, YSIZE, forge::f32); diff --git a/src/backend/opengl/surface_impl.cpp b/src/backend/opengl/surface_impl.cpp index 5d9f386b..c6807420 100644 --- a/src/backend/opengl/surface_impl.cpp +++ b/src/backend/opengl/surface_impl.cpp @@ -24,15 +24,15 @@ using namespace gl; using namespace std; void generateGridIndices(unsigned short rows, unsigned short cols, - std::vector& indices) + std::vector& indices) { - for (unsigned short r = 0; r < (rows-1); ++r) { + for (int r = 0; r < (rows-1); ++r) { if (r > 0) { // repeat first vertex for degenerate triangle indices.push_back(r*rows); } - for (unsigned short c = 0; c < cols; ++c) { + for (int c = 0; c < cols; ++c) { // One part of the strip indices.push_back(r*rows + c); indices.push_back((r+1)*rows + c); @@ -121,11 +121,11 @@ void surface_impl::renderGraph(const int pWindowId, const glm::mat4& transform) glUniform1i(mSurfPVAIndex, mIsPVAOn); bindResources(pWindowId); - glDrawElements(GL_TRIANGLE_STRIP, mIBOSize, GL_UNSIGNED_SHORT, (void*)0 ); + glDrawElements(GL_TRIANGLE_STRIP, mIBOSize, GL_UNSIGNED_INT, (void*)0); unbindResources(); mSurfProgram.unbind(); - if(mMarkerType != FG_MARKER_NONE) { + if (mMarkerType != FG_MARKER_NONE) { glEnable(GL_PROGRAM_POINT_SIZE); mMarkerProgram.bind(); @@ -136,7 +136,7 @@ void surface_impl::renderGraph(const int pWindowId, const glm::mat4& transform) glUniform4fv(mMarkerColIndex, 1, mColor); bindResources(pWindowId); - glDrawElements(GL_POINTS, mIBOSize, GL_UNSIGNED_SHORT, (void*)0); + glDrawElements(GL_POINTS, mIBOSize, GL_UNSIGNED_INT, (void*)0); unbindResources(); mMarkerProgram.unbind(); @@ -202,13 +202,13 @@ surface_impl::surface_impl(unsigned pNumXPoints, unsigned pNumYPoints, #undef SURF_CREATE_BUFFERS - std::vector indices; + std::vector indices; generateGridIndices(mNumXPoints, mNumYPoints, indices); mIBOSize = indices.size(); - mIBO = createBuffer(GL_ELEMENT_ARRAY_BUFFER, mIBOSize, indices.data(), GL_STATIC_DRAW); + mIBO = createBuffer(GL_ELEMENT_ARRAY_BUFFER, mIBOSize, indices.data(), GL_STATIC_DRAW); CheckGL("End surface_impl::surface_impl"); } @@ -260,7 +260,7 @@ void scatter3_impl::renderGraph(const int pWindowId, const glm::mat4& transform) glUniform4fv(mMarkerColIndex, 1, mColor); bindResources(pWindowId); - glDrawElements(GL_POINTS, mIBOSize, GL_UNSIGNED_SHORT, (void*)0); + glDrawElements(GL_POINTS, mIBOSize, GL_UNSIGNED_INT, (void*)0); unbindResources(); mMarkerProgram.unbind(); From 4aa16cc58fb578d2479ac897d7c6d3d4484bb696 Mon Sep 17 00:00:00 2001 From: pradeep Date: Mon, 19 Dec 2016 23:51:46 +0530 Subject: [PATCH 4/7] fix style in surface example --- examples/cpu/surface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/cpu/surface.cpp b/examples/cpu/surface.cpp index 8e16ca29..86a266e0 100644 --- a/examples/cpu/surface.cpp +++ b/examples/cpu/surface.cpp @@ -18,9 +18,9 @@ using namespace std; static const float XMIN = -32.0f; -static const float XMAX = 32.f; +static const float XMAX = 32.0f; static const float YMIN = -32.0f; -static const float YMAX = 32.f; +static const float YMAX = 32.0f; const float DX = 0.25; const size_t XSIZE = (XMAX-XMIN)/DX; From de4968a6304f72647a2205e85ebb15ba34643e13 Mon Sep 17 00:00:00 2001 From: pradeep Date: Mon, 19 Dec 2016 23:58:28 +0530 Subject: [PATCH 5/7] reserve vector memory for surface's index buffer --- src/backend/opengl/surface_impl.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/backend/opengl/surface_impl.cpp b/src/backend/opengl/surface_impl.cpp index c6807420..9c9e62a1 100644 --- a/src/backend/opengl/surface_impl.cpp +++ b/src/backend/opengl/surface_impl.cpp @@ -26,6 +26,12 @@ using namespace std; void generateGridIndices(unsigned short rows, unsigned short cols, std::vector& indices) { + const int numDegens = 2 * (rows - 2); + const int verticesPerStrip = 2 * cols; + + //reserve the size of vector + indices.reserve(verticesPerStrip + numDegens); + for (int r = 0; r < (rows-1); ++r) { if (r > 0) { // repeat first vertex for degenerate triangle From 7d045e4ac2ac144fc7688c38cc68ab78371616a9 Mon Sep 17 00:00:00 2001 From: pradeep Date: Tue, 20 Dec 2016 00:05:49 +0530 Subject: [PATCH 6/7] fix function signature style --- src/backend/opengl/surface_impl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/opengl/surface_impl.cpp b/src/backend/opengl/surface_impl.cpp index 9c9e62a1..580e2112 100644 --- a/src/backend/opengl/surface_impl.cpp +++ b/src/backend/opengl/surface_impl.cpp @@ -23,8 +23,8 @@ using namespace gl; using namespace std; -void generateGridIndices(unsigned short rows, unsigned short cols, - std::vector& indices) +void generateGridIndices(std::vector& indices, + unsigned short rows, unsigned short cols) { const int numDegens = 2 * (rows - 2); const int verticesPerStrip = 2 * cols; @@ -210,7 +210,7 @@ surface_impl::surface_impl(unsigned pNumXPoints, unsigned pNumYPoints, std::vector indices; - generateGridIndices(mNumXPoints, mNumYPoints, indices); + generateGridIndices(indices, mNumXPoints, mNumYPoints); mIBOSize = indices.size(); From c57384dc0aa5f48e43906bd1a5ae2bc189aadee1 Mon Sep 17 00:00:00 2001 From: pradeep Date: Tue, 20 Dec 2016 00:09:55 +0530 Subject: [PATCH 7/7] bump version to 0.9.2 --- CMakeModules/Version.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeModules/Version.cmake b/CMakeModules/Version.cmake index b1293cb8..da010809 100644 --- a/CMakeModules/Version.cmake +++ b/CMakeModules/Version.cmake @@ -9,7 +9,7 @@ ENDIF() SET(FG_VERSION_MAJOR "0") SET(FG_VERSION_MINOR "9") -SET(FG_VERSION_PATCH "1") +SET(FG_VERSION_PATCH "2") SET(FG_VERSION "${FG_VERSION_MAJOR}.${FG_VERSION_MINOR}.${FG_VERSION_PATCH}") SET(FG_API_VERSION_CURRENT ${FG_VERSION_MAJOR}${FG_VERSION_MINOR})