mirror of
https://github.com/bulletphysics/bullet3
synced 2025-01-19 05:20:06 +00:00
Merge branch 'master' of https://github.com/erwincoumans/bullet3
This commit is contained in:
commit
16cbc191bd
@ -43,7 +43,11 @@ struct CommonRenderInterface
|
|||||||
virtual void drawPoint(const double* position, const double color[4], double pointDrawSize)=0;
|
virtual void drawPoint(const double* position, const double color[4], double pointDrawSize)=0;
|
||||||
virtual int registerShape(const float* vertices, int numvertices, const int* indices, int numIndices,int primitiveType=B3_GL_TRIANGLES, int textureIndex=-1)=0;
|
virtual int registerShape(const float* vertices, int numvertices, const int* indices, int numIndices,int primitiveType=B3_GL_TRIANGLES, int textureIndex=-1)=0;
|
||||||
virtual void updateShape(int shapeIndex, const float* vertices)=0;
|
virtual void updateShape(int shapeIndex, const float* vertices)=0;
|
||||||
|
|
||||||
virtual int registerTexture(const unsigned char* texels, int width, int height)=0;
|
virtual int registerTexture(const unsigned char* texels, int width, int height)=0;
|
||||||
|
virtual void updateTexture(int textureIndex, const unsigned char* texels)=0;
|
||||||
|
virtual void activateTexture(int textureIndex)=0;
|
||||||
|
|
||||||
virtual void writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex)=0;
|
virtual void writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex)=0;
|
||||||
virtual void writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex)=0;
|
virtual void writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex)=0;
|
||||||
virtual void writeSingleInstanceColorToCPU(float* color, int srcIndex)=0;
|
virtual void writeSingleInstanceColorToCPU(float* color, int srcIndex)=0;
|
||||||
|
@ -134,7 +134,12 @@ extern int gShapeIndex;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct InternalTextureHandle
|
||||||
|
{
|
||||||
|
GLuint m_glTexture;
|
||||||
|
int m_width;
|
||||||
|
int m_height;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -148,7 +153,7 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData
|
|||||||
|
|
||||||
|
|
||||||
GLuint m_defaultTexturehandle;
|
GLuint m_defaultTexturehandle;
|
||||||
b3AlignedObjectArray<GLuint> m_textureHandles;
|
b3AlignedObjectArray<InternalTextureHandle> m_textureHandles;
|
||||||
|
|
||||||
GLRenderToTexture* m_shadowMap;
|
GLRenderToTexture* m_shadowMap;
|
||||||
GLuint m_shadowTexture;
|
GLuint m_shadowTexture;
|
||||||
@ -518,7 +523,7 @@ int GLInstancingRenderer::registerGraphicsInstance(int shapeIndex, const float*
|
|||||||
int GLInstancingRenderer::registerTexture(const unsigned char* texels, int width, int height)
|
int GLInstancingRenderer::registerTexture(const unsigned char* texels, int width, int height)
|
||||||
{
|
{
|
||||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
int textureIndex = m_data->m_textureHandles.size();
|
int textureIndex = m_data->m_textureHandles.size();
|
||||||
const GLubyte* image= (const GLubyte*)texels;
|
const GLubyte* image= (const GLubyte*)texels;
|
||||||
GLuint textureHandle;
|
GLuint textureHandle;
|
||||||
@ -528,18 +533,51 @@ int GLInstancingRenderer::registerTexture(const unsigned char* texels, int width
|
|||||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width,height,0,GL_RGB,GL_UNSIGNED_BYTE,image);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width,height,0,GL_RGB,GL_UNSIGNED_BYTE,image);
|
||||||
|
|
||||||
|
|
||||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
|
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
|
|
||||||
|
InternalTextureHandle h;
|
||||||
|
h.m_glTexture = textureHandle;
|
||||||
|
h.m_width = width;
|
||||||
|
h.m_height = height;
|
||||||
|
|
||||||
m_data->m_textureHandles.push_back(textureHandle);
|
m_data->m_textureHandles.push_back(h);
|
||||||
return textureIndex;
|
return textureIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GLInstancingRenderer::updateTexture(int textureIndex, const unsigned char* texels)
|
||||||
|
{
|
||||||
|
if (textureIndex>=0)
|
||||||
|
{
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
|
InternalTextureHandle& h = m_data->m_textureHandles[textureIndex];
|
||||||
|
glBindTexture(GL_TEXTURE_2D,h.m_glTexture);
|
||||||
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
|
const GLubyte* image= (const GLubyte*)texels;
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, h.m_width,h.m_height,0,GL_RGB,GL_UNSIGNED_BYTE,image);
|
||||||
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLInstancingRenderer::activateTexture(int textureIndex)
|
||||||
|
{
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
|
||||||
|
if (textureIndex>=0)
|
||||||
|
{
|
||||||
|
glBindTexture(GL_TEXTURE_2D,m_data->m_textureHandles[textureIndex].m_glTexture);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
glBindTexture(GL_TEXTURE_2D,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GLInstancingRenderer::updateShape(int shapeIndex, const float* vertices)
|
void GLInstancingRenderer::updateShape(int shapeIndex, const float* vertices)
|
||||||
{
|
{
|
||||||
b3GraphicsInstance* gfxObj = m_graphicsInstances[shapeIndex];
|
b3GraphicsInstance* gfxObj = m_graphicsInstances[shapeIndex];
|
||||||
@ -559,7 +597,7 @@ int GLInstancingRenderer::registerShape(const float* vertices, int numvertices,
|
|||||||
|
|
||||||
if (textureId>=0)
|
if (textureId>=0)
|
||||||
{
|
{
|
||||||
gfxObj->m_texturehandle = m_data->m_textureHandles[textureId];
|
gfxObj->m_texturehandle = m_data->m_textureHandles[textureId].m_glTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
gfxObj->m_primitiveType = primitiveType;
|
gfxObj->m_primitiveType = primitiveType;
|
||||||
|
@ -63,6 +63,9 @@ public:
|
|||||||
virtual int registerShape(const float* vertices, int numvertices, const int* indices, int numIndices, int primitiveType=B3_GL_TRIANGLES, int textureIndex=-1);
|
virtual int registerShape(const float* vertices, int numvertices, const int* indices, int numIndices, int primitiveType=B3_GL_TRIANGLES, int textureIndex=-1);
|
||||||
|
|
||||||
virtual int registerTexture(const unsigned char* texels, int width, int height);
|
virtual int registerTexture(const unsigned char* texels, int width, int height);
|
||||||
|
virtual void updateTexture(int textureIndex, const unsigned char* texels);
|
||||||
|
virtual void activateTexture(int textureIndex);
|
||||||
|
|
||||||
|
|
||||||
///position x,y,z, quaternion x,y,z,w, color r,g,b,a, scaling x,y,z
|
///position x,y,z, quaternion x,y,z,w, color r,g,b,a, scaling x,y,z
|
||||||
virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling);
|
virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling);
|
||||||
|
@ -50,6 +50,10 @@ struct SimpleOpenGL2Renderer : public CommonRenderInterface
|
|||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
virtual void updateTexture(int textureIndex, const unsigned char* texels) {}
|
||||||
|
virtual void activateTexture(int textureIndex) {}
|
||||||
|
|
||||||
|
|
||||||
virtual int registerGraphicsInstance(int shapeIndex, const double* position, const double* quaternion, const double* color, const double* scaling);
|
virtual int registerGraphicsInstance(int shapeIndex, const double* position, const double* quaternion, const double* color, const double* scaling);
|
||||||
|
|
||||||
virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling);
|
virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling);
|
||||||
|
@ -44,17 +44,7 @@ void InternalOpenGL2RenderCallbacks::display2()
|
|||||||
PrimInternalData* data = getData();
|
PrimInternalData* data = getData();
|
||||||
|
|
||||||
glUseProgram(data->m_shaderProg);
|
glUseProgram(data->m_shaderProg);
|
||||||
|
|
||||||
float identity[16]={1,0,0,0,
|
|
||||||
0,1,0,0,
|
|
||||||
0,0,1,0,
|
|
||||||
0,0,0,1};
|
|
||||||
glUniformMatrix4fv(data->m_viewmatUniform, 1, false, identity);
|
|
||||||
glUniformMatrix4fv(data->m_projMatUniform, 1, false, identity);
|
|
||||||
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, s_vertexBuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, s_vertexBuffer);
|
||||||
|
|
||||||
glBindVertexArray(s_vertexArrayObject);
|
glBindVertexArray(s_vertexArrayObject);
|
||||||
|
|
||||||
assert(glGetError()==GL_NO_ERROR);
|
assert(glGetError()==GL_NO_ERROR);
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
#include "OpenGLWindow/SimpleOpenGL3App.h"
|
#include "OpenGLWindow/SimpleOpenGL3App.h"
|
||||||
|
|
||||||
#include "Bullet3Common/b3Vector3.h"
|
#include "Bullet3Common/b3Vector3.h"
|
||||||
#include "Bullet3Common/b3CommandLineArgs.h"
|
#include "Bullet3Common/b3CommandLineArgs.h"
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "OpenGLWindow/OpenGLInclude.h"
|
|
||||||
|
|
||||||
char* gVideoFileName = 0;
|
char* gVideoFileName = 0;
|
||||||
char* gPngFileName = 0;
|
char* gPngFileName = 0;
|
||||||
@ -16,6 +14,8 @@ static b3MouseButtonCallback sOldMouseButtonCB = 0;
|
|||||||
static b3KeyboardCallback sOldKeyboardCB = 0;
|
static b3KeyboardCallback sOldKeyboardCB = 0;
|
||||||
//static b3RenderCallback sOldRenderCB = 0;
|
//static b3RenderCallback sOldRenderCB = 0;
|
||||||
|
|
||||||
|
float gWidth = 0 ;
|
||||||
|
float gHeight = 0;
|
||||||
|
|
||||||
void MyWheelCallback(float deltax, float deltay)
|
void MyWheelCallback(float deltax, float deltay)
|
||||||
{
|
{
|
||||||
@ -24,6 +24,9 @@ void MyWheelCallback(float deltax, float deltay)
|
|||||||
}
|
}
|
||||||
void MyResizeCallback( float width, float height)
|
void MyResizeCallback( float width, float height)
|
||||||
{
|
{
|
||||||
|
gWidth = width;
|
||||||
|
gHeight = height;
|
||||||
|
|
||||||
if (sOldResizeCB)
|
if (sOldResizeCB)
|
||||||
sOldResizeCB(width,height);
|
sOldResizeCB(width,height);
|
||||||
}
|
}
|
||||||
@ -59,6 +62,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
|
|
||||||
SimpleOpenGL3App* app = new SimpleOpenGL3App("SimpleOpenGL3App",1024,768,true);
|
SimpleOpenGL3App* app = new SimpleOpenGL3App("SimpleOpenGL3App",1024,768,true);
|
||||||
|
|
||||||
app->m_instancingRenderer->getActiveCamera()->setCameraDistance(13);
|
app->m_instancingRenderer->getActiveCamera()->setCameraDistance(13);
|
||||||
app->m_instancingRenderer->getActiveCamera()->setCameraPitch(0);
|
app->m_instancingRenderer->getActiveCamera()->setCameraPitch(0);
|
||||||
app->m_instancingRenderer->getActiveCamera()->setCameraTargetPosition(0,0,0);
|
app->m_instancingRenderer->getActiveCamera()->setCameraTargetPosition(0,0,0);
|
||||||
@ -74,9 +78,6 @@ int main(int argc, char* argv[])
|
|||||||
app->m_window->setResizeCallback(MyResizeCallback);
|
app->m_window->setResizeCallback(MyResizeCallback);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
assert(glGetError()==GL_NO_ERROR);
|
|
||||||
|
|
||||||
myArgs.GetCmdLineArgument("mp4_file",gVideoFileName);
|
myArgs.GetCmdLineArgument("mp4_file",gVideoFileName);
|
||||||
if (gVideoFileName)
|
if (gVideoFileName)
|
||||||
app->dumpFramesToVideo(gVideoFileName);
|
app->dumpFramesToVideo(gVideoFileName);
|
||||||
@ -84,6 +85,15 @@ int main(int argc, char* argv[])
|
|||||||
myArgs.GetCmdLineArgument("png_file",gPngFileName);
|
myArgs.GetCmdLineArgument("png_file",gPngFileName);
|
||||||
char fileName[1024];
|
char fileName[1024];
|
||||||
|
|
||||||
|
int textureIndex = -1;
|
||||||
|
int textureWidth = 128;
|
||||||
|
int textureHeight = 128;
|
||||||
|
|
||||||
|
unsigned char* image=new unsigned char[textureWidth*textureHeight*4];
|
||||||
|
|
||||||
|
|
||||||
|
int textureHandle = app->m_renderer->registerTexture(image,textureWidth,textureHeight);
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
static int frameCount = 0;
|
static int frameCount = 0;
|
||||||
@ -96,7 +106,29 @@ int main(int argc, char* argv[])
|
|||||||
app->dumpNextFrameToPng(fileName);
|
app->dumpNextFrameToPng(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(glGetError()==GL_NO_ERROR);
|
|
||||||
|
|
||||||
|
//update the texels of the texture using a simple pattern, animated using frame index
|
||||||
|
for(int y=0;y<textureHeight;++y)
|
||||||
|
{
|
||||||
|
const int t=(y+frameCount)>>4;
|
||||||
|
unsigned char* pi=image+y*textureWidth*3;
|
||||||
|
for(int x=0;x<textureWidth;++x)
|
||||||
|
{
|
||||||
|
const int s=x>>4;
|
||||||
|
const unsigned char b=180;
|
||||||
|
unsigned char c=b+((s+(t&1))&1)*(255-b);
|
||||||
|
pi[0]=pi[1]=pi[2]=pi[3]=c;pi+=3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
app->m_renderer->activateTexture(textureHandle);
|
||||||
|
app->m_renderer->updateTexture(textureHandle,image);
|
||||||
|
|
||||||
|
float color[4] = {255,1,1,1};
|
||||||
|
app->m_primRenderer->drawTexturedRect(100,200,gWidth/2-50,gHeight/2-50,color,0,0,1,1,true);
|
||||||
|
|
||||||
|
|
||||||
app->m_instancingRenderer->init();
|
app->m_instancingRenderer->init();
|
||||||
app->m_instancingRenderer->updateCamera();
|
app->m_instancingRenderer->updateCamera();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user