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
This commit is contained in:
@@ -17,11 +17,12 @@ subject to the following restrictions:
|
|||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef USE_MINICL
|
#ifndef USE_MINICL
|
||||||
#define USE_SIMDAWARE_SOLVER
|
#define USE_SIMDAWARE_SOLVER
|
||||||
#define USE_GPU_SOLVER
|
#define USE_GPU_SOLVER
|
||||||
#ifdef _WIN32
|
#if defined (_WIN32)
|
||||||
#define USE_GPU_COPY //only tested on Windows, may work under Linux
|
#define USE_GPU_COPY //only tested on Windows
|
||||||
#endif //_WIN32
|
#endif //_WIN32
|
||||||
#endif //USE_MINICL
|
#endif //USE_MINICL
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ subject to the following restrictions:
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "LinearMath/btScalar.h"
|
#include "LinearMath/btScalar.h"
|
||||||
#include <stdio.h> //sprintf
|
|
||||||
|
|
||||||
struct vertex_struct
|
struct vertex_struct
|
||||||
{
|
{
|
||||||
@@ -49,7 +49,9 @@ class piece_of_cloth
|
|||||||
created = false;
|
created = false;
|
||||||
cpu_buffer = NULL;
|
cpu_buffer = NULL;
|
||||||
m_vertexBufferDescriptor = NULL;
|
m_vertexBufferDescriptor = NULL;
|
||||||
|
#ifdef USE_GPU_COPY
|
||||||
clothVBO = 0;
|
clothVBO = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool created;
|
bool created;
|
||||||
@@ -64,6 +66,7 @@ class piece_of_cloth
|
|||||||
int height;
|
int height;
|
||||||
|
|
||||||
GLuint m_texture;
|
GLuint m_texture;
|
||||||
|
#ifdef USE_GPU_COPY
|
||||||
|
|
||||||
GLuint clothVBO;
|
GLuint clothVBO;
|
||||||
|
|
||||||
@@ -71,6 +74,7 @@ class piece_of_cloth
|
|||||||
{
|
{
|
||||||
return clothVBO;
|
return clothVBO;
|
||||||
}
|
}
|
||||||
|
#endif //USE_GPU_COPY
|
||||||
|
|
||||||
void draw(void)
|
void draw(void)
|
||||||
{
|
{
|
||||||
@@ -80,26 +84,25 @@ class piece_of_cloth
|
|||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
glColor3f(0.0f, 1.0f, 1.0f);
|
glColor3f(0.0f, 1.0f, 1.0f);
|
||||||
|
#ifdef USE_GPU_COPY
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, clothVBO);
|
glBindBuffer(GL_ARRAY_BUFFER, clothVBO);
|
||||||
#ifndef USE_GPU_COPY
|
#ifndef USE_GPU_COPY
|
||||||
// Upload data to VBO
|
// Upload data to VBO
|
||||||
// Needed while we're not doing interop
|
// Needed while we're not doing interop
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_struct)*width*height, &(cpu_buffer[0]), GL_DYNAMIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_struct)*width*height, &(cpu_buffer[0]), GL_DYNAMIC_DRAW);
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
|
#ifdef USE_GPU_COPY
|
||||||
glEnableClientState(GL_NORMAL_ARRAY);
|
glEnableClientState(GL_NORMAL_ARRAY);
|
||||||
|
#endif
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, m_texture);
|
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_texture);
|
||||||
|
#ifdef USE_GPU_COPY
|
||||||
error = glGetError();
|
error = glGetError();
|
||||||
|
|
||||||
|
|
||||||
// VBO version
|
// VBO version
|
||||||
glVertexPointer( 3, GL_FLOAT, sizeof(vertex_struct), (const GLvoid *)0 );
|
glVertexPointer( 3, GL_FLOAT, sizeof(vertex_struct), (const GLvoid *)0 );
|
||||||
error = glGetError();
|
error = glGetError();
|
||||||
@@ -107,15 +110,25 @@ class piece_of_cloth
|
|||||||
error = glGetError();
|
error = glGetError();
|
||||||
glTexCoordPointer( 2, GL_FLOAT, sizeof(vertex_struct), (const GLvoid *)(sizeof(float)*6) );
|
glTexCoordPointer( 2, GL_FLOAT, sizeof(vertex_struct), (const GLvoid *)(sizeof(float)*6) );
|
||||||
error = glGetError();
|
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);
|
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_VERTEX_ARRAY);
|
||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
error = glGetError();
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
#ifdef USE_GPU_COPY
|
||||||
|
error = glGetError();
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
error = glGetError();
|
error = glGetError();
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_texture(std::string filename)
|
void create_texture(std::string filename)
|
||||||
@@ -248,7 +261,7 @@ class piece_of_cloth
|
|||||||
indices[baseIndex+5] = x+width + y*width;
|
indices[baseIndex+5] = x+width + y*width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef USE_GPU_COPY
|
||||||
// Construct VBO
|
// Construct VBO
|
||||||
glGenBuffers(1, &clothVBO);
|
glGenBuffers(1, &clothVBO);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 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);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_struct)*width*height, &(cpu_buffer[0]), GL_DYNAMIC_DRAW);
|
||||||
int error = glGetError();
|
int error = glGetError();
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user