From 72f88856cd224c85ba190b5af660c2eb2521fa45 Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Sat, 19 Mar 2011 19:45:24 +0000 Subject: [PATCH] only use VBO's and USE_GPU_COPY -> OpenCL/OpenGL interop under Windows, so that stuff compiles/runs on Mac OSX and Linux See Issue 495 --- Demos/OpenCLClothDemo/cl_cloth_demo.cpp | 5 +-- Demos/OpenCLClothDemo/cloth.h | 41 ++++++++++++++++--------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/Demos/OpenCLClothDemo/cl_cloth_demo.cpp b/Demos/OpenCLClothDemo/cl_cloth_demo.cpp index 762f67364..021c70015 100644 --- a/Demos/OpenCLClothDemo/cl_cloth_demo.cpp +++ b/Demos/OpenCLClothDemo/cl_cloth_demo.cpp @@ -17,11 +17,12 @@ subject to the following restrictions: #include #endif + #ifndef USE_MINICL #define USE_SIMDAWARE_SOLVER #define USE_GPU_SOLVER -#ifdef _WIN32 -#define USE_GPU_COPY //only tested on Windows, may work under Linux +#if defined (_WIN32) + #define USE_GPU_COPY //only tested on Windows #endif //_WIN32 #endif //USE_MINICL diff --git a/Demos/OpenCLClothDemo/cloth.h b/Demos/OpenCLClothDemo/cloth.h index dd2ddd7a9..9fd741ff3 100644 --- a/Demos/OpenCLClothDemo/cloth.h +++ b/Demos/OpenCLClothDemo/cloth.h @@ -20,7 +20,7 @@ subject to the following restrictions: #include #include #include "LinearMath/btScalar.h" -#include //sprintf + struct vertex_struct { @@ -49,7 +49,9 @@ class piece_of_cloth created = false; cpu_buffer = NULL; m_vertexBufferDescriptor = NULL; +#ifdef USE_GPU_COPY clothVBO = 0; +#endif } bool created; @@ -64,6 +66,7 @@ class piece_of_cloth int height; GLuint m_texture; +#ifdef USE_GPU_COPY GLuint clothVBO; @@ -71,6 +74,7 @@ class piece_of_cloth { return clothVBO; } +#endif //USE_GPU_COPY void draw(void) { @@ -80,26 +84,25 @@ class piece_of_cloth glEnable(GL_DEPTH_TEST); glColor3f(0.0f, 1.0f, 1.0f); - +#ifdef USE_GPU_COPY int error = 0; - glBindBuffer(GL_ARRAY_BUFFER, clothVBO); #ifndef USE_GPU_COPY // Upload data to VBO // Needed while we're not doing interop glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_struct)*width*height, &(cpu_buffer[0]), GL_DYNAMIC_DRAW); #endif - - +#endif glEnableClientState(GL_VERTEX_ARRAY); +#ifdef USE_GPU_COPY glEnableClientState(GL_NORMAL_ARRAY); +#endif glEnableClientState(GL_TEXTURE_COORD_ARRAY); - - glBindTexture(GL_TEXTURE_2D, m_texture); + glBindTexture(GL_TEXTURE_2D, m_texture); +#ifdef USE_GPU_COPY error = glGetError(); - // VBO version glVertexPointer( 3, GL_FLOAT, sizeof(vertex_struct), (const GLvoid *)0 ); error = glGetError(); @@ -107,15 +110,25 @@ class piece_of_cloth error = glGetError(); glTexCoordPointer( 2, GL_FLOAT, sizeof(vertex_struct), (const GLvoid *)(sizeof(float)*6) ); error = glGetError(); - + + +#else + glVertexPointer( 3, GL_FLOAT, sizeof(vertex_struct), reinterpret_cast< GLvoid* >(&(cpu_buffer[0].pos[0])) ); + //glNormalPointer( 3, sizeof(vertex_struct), reinterpret_cast< GLvoid* >(&(cpu_buffer[0].normal[0])) ); + glTexCoordPointer( 2, GL_FLOAT, sizeof(vertex_struct), reinterpret_cast< GLvoid* >(&(cpu_buffer[0].texcoord[0])) ); +#endif + glDrawElements(GL_TRIANGLES, (height-1 )*(width-1)*3*2, GL_UNSIGNED_INT, indices); - glDisableClientState(GL_NORMAL_ARRAY); +// glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); - error = glGetError(); glBindTexture(GL_TEXTURE_2D, 0); +#ifdef USE_GPU_COPY + error = glGetError(); glBindBuffer(GL_ARRAY_BUFFER, 0); error = glGetError(); +#endif + } void create_texture(std::string filename) @@ -248,7 +261,7 @@ class piece_of_cloth indices[baseIndex+5] = x+width + y*width; } } - +#ifdef USE_GPU_COPY // Construct VBO glGenBuffers(1, &clothVBO); glBindBuffer(GL_ARRAY_BUFFER, clothVBO); @@ -256,8 +269,6 @@ class piece_of_cloth glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_struct)*width*height, &(cpu_buffer[0]), GL_DYNAMIC_DRAW); int error = glGetError(); glBindBuffer(GL_ARRAY_BUFFER, 0); - - - +#endif } };