2015-04-16 16:55:32 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2012 Advanced Micro Devices, Inc.
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
In no event will the authors be held liable for any damages arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it freely,
|
|
|
|
subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
//Originally written by Erwin Coumans
|
|
|
|
|
|
|
|
#ifndef GL_INSTANCING_RENDERER_H
|
|
|
|
#define GL_INSTANCING_RENDERER_H
|
|
|
|
|
|
|
|
#include "Bullet3Common/b3AlignedObjectArray.h"
|
|
|
|
#include "../CommonInterfaces/CommonRenderInterface.h"
|
2015-04-16 22:16:13 +00:00
|
|
|
#include "SimpleCamera.h"
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GLInstancingRenderer : public CommonRenderInterface
|
|
|
|
{
|
|
|
|
|
|
|
|
b3AlignedObjectArray<struct b3GraphicsInstance*> m_graphicsInstances;
|
|
|
|
|
2015-05-01 18:42:14 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
struct InternalDataRenderer* m_data;
|
|
|
|
|
|
|
|
bool m_textureenabled;
|
|
|
|
bool m_textureinitialized;
|
|
|
|
|
|
|
|
int m_screenWidth;
|
|
|
|
int m_screenHeight;
|
|
|
|
|
|
|
|
int m_upAxis;
|
2018-04-11 08:03:36 +00:00
|
|
|
|
|
|
|
int m_planeReflectionShapeIndex;
|
2017-06-24 20:41:33 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2017-05-04 00:05:05 +00:00
|
|
|
int registerGraphicsInstanceInternal(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling);
|
|
|
|
void rebuildGraphicsInstances();
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
GLInstancingRenderer(int m_maxObjectCapacity, int maxShapeCapacityInBytes = 56*1024*1024);
|
|
|
|
virtual ~GLInstancingRenderer();
|
|
|
|
|
|
|
|
virtual void init();
|
|
|
|
|
|
|
|
virtual void renderScene();
|
2018-01-08 20:25:56 +00:00
|
|
|
virtual void renderSceneInternal(int orgRenderMode=B3_DEFAULT_RENDERMODE);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
void InitShaders();
|
|
|
|
void CleanupShaders();
|
2015-08-07 07:13:26 +00:00
|
|
|
virtual void removeAllInstances();
|
2017-05-04 00:05:05 +00:00
|
|
|
virtual void removeGraphicsInstance(int instanceUid);
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
virtual void updateShape(int shapeIndex, const float* vertices);
|
|
|
|
|
|
|
|
///vertices must be in the format x,y,z, nx,ny,nz, u,v
|
|
|
|
virtual int registerShape(const float* vertices, int numvertices, const int* indices, int numIndices, int primitiveType=B3_GL_TRIANGLES, int textureIndex=-1);
|
|
|
|
|
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
|
|
|
virtual int registerTexture(const unsigned char* texels, int width, int height, bool flipPixelsY=true);
|
|
|
|
virtual void updateTexture(int textureIndex, const unsigned char* texels, bool flipPixelsY=true);
|
2016-04-20 19:55:21 +00:00
|
|
|
virtual void activateTexture(int textureIndex);
|
2017-06-30 20:35:07 +00:00
|
|
|
virtual void replaceTexture(int shapeIndex, int textureId);
|
|
|
|
virtual int getShapeIndexFromInstance(int srcIndex);
|
2018-02-22 07:22:16 +00:00
|
|
|
virtual void removeTexture(int textureIndex);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
///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 double* position, const double* quaternion, const double* color, const double* scaling);
|
|
|
|
|
2017-05-04 00:05:05 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
void writeTransforms();
|
|
|
|
|
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
|
|
|
virtual bool readSingleInstanceTransformToCPU(float* position, float* orientation, int srcIndex);
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
virtual void writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex);
|
|
|
|
virtual void writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex)
|
|
|
|
{
|
|
|
|
float pos[4];
|
|
|
|
float orn[4];
|
|
|
|
pos[0] = (float)position[0];
|
|
|
|
pos[1] = (float)position[1];
|
|
|
|
pos[2] = (float)position[2];
|
|
|
|
pos[3] = (float)position[3];
|
|
|
|
orn[0] =(float)orientation[0];
|
|
|
|
orn[1] =(float)orientation[1];
|
|
|
|
orn[2] =(float)orientation[2];
|
|
|
|
orn[3] =(float)orientation[3];
|
|
|
|
writeSingleInstanceTransformToCPU(pos,orn,srcIndex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-06-01 19:32:44 +00:00
|
|
|
|
2016-09-08 22:15:58 +00:00
|
|
|
virtual void readSingleInstanceTransformFromCPU(int srcIndex, float* position, float* orientation);
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
virtual void writeSingleInstanceTransformToGPU(float* position, float* orientation, int srcIndex);
|
|
|
|
|
2017-05-13 16:18:36 +00:00
|
|
|
virtual void writeSingleInstanceColorToCPU(const float* color, int srcIndex);
|
|
|
|
virtual void writeSingleInstanceColorToCPU(const double* color, int srcIndex);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2017-06-01 23:48:07 +00:00
|
|
|
virtual void writeSingleInstanceSpecularColorToCPU(const double* specular, int srcIndex2);
|
|
|
|
virtual void writeSingleInstanceSpecularColorToCPU(const float* specular, int srcIndex2);
|
2017-06-01 19:32:44 +00:00
|
|
|
|
2017-05-13 16:18:36 +00:00
|
|
|
virtual void writeSingleInstanceScaleToCPU(const float* scale, int srcIndex);
|
|
|
|
virtual void writeSingleInstanceScaleToCPU(const double* scale, int srcIndex);
|
2016-07-09 22:09:09 +00:00
|
|
|
|
2015-04-16 22:16:13 +00:00
|
|
|
|
2015-05-01 18:42:14 +00:00
|
|
|
virtual struct GLInstanceRendererInternalData* getInternalData();
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
virtual void drawLine(const float from[4], const float to[4], const float color[4], float lineWidth=1);
|
|
|
|
virtual void drawLine(const double from[4], const double to[4], const double color[4], double lineWidth=1);
|
|
|
|
virtual void drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float pointDrawSize);
|
|
|
|
virtual void drawPoints(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, float pointDrawSize);
|
|
|
|
virtual void drawPoint(const float* position, const float color[4], float pointSize=1);
|
|
|
|
virtual void drawPoint(const double* position, const double color[4], double pointDrawSize=1);
|
2017-05-24 20:05:16 +00:00
|
|
|
virtual void drawTexturedTriangleMesh(float worldPosition[3], float worldOrientation[4], const float* vertices, int numvertices, const unsigned int* indices, int numIndices, float color[4], int textureIndex=-1, int vertexLayout=0);
|
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
virtual void updateCamera(int upAxis=1);
|
|
|
|
|
2015-04-16 22:16:13 +00:00
|
|
|
virtual const CommonCameraInterface* getActiveCamera() const;
|
|
|
|
virtual CommonCameraInterface* getActiveCamera();
|
|
|
|
virtual void setActiveCamera(CommonCameraInterface* cam);
|
|
|
|
|
2017-04-23 14:35:13 +00:00
|
|
|
virtual void setLightPosition(const float lightPos[3]);
|
|
|
|
virtual void setLightPosition(const double lightPos[3]);
|
2017-06-01 03:32:45 +00:00
|
|
|
void setLightSpecularIntensity(const float lightSpecularIntensity[3]);
|
2018-03-19 01:45:54 +00:00
|
|
|
virtual void setProjectiveTextureMatrices(const float viewMatrix[16], const float projectionMatrix[16]);
|
2018-03-21 04:28:47 +00:00
|
|
|
virtual void setProjectiveTexture(bool useProjectiveTexture);
|
2017-04-23 14:35:13 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
virtual void resize(int width, int height);
|
|
|
|
virtual int getScreenWidth()
|
|
|
|
{
|
|
|
|
return m_screenWidth;
|
|
|
|
}
|
|
|
|
virtual int getScreenHeight()
|
|
|
|
{
|
|
|
|
return m_screenHeight;
|
|
|
|
}
|
|
|
|
|
2015-05-01 18:42:14 +00:00
|
|
|
virtual int getMaxShapeCapacity() const;
|
|
|
|
|
|
|
|
virtual int getInstanceCapacity() const;
|
|
|
|
|
2016-07-08 02:24:44 +00:00
|
|
|
virtual int getTotalNumInstances() const;
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
virtual void enableShadowMap();
|
2018-04-11 08:03:36 +00:00
|
|
|
|
|
|
|
virtual void setPlaneReflectionShapeIndex(int index);
|
2017-06-24 20:41:33 +00:00
|
|
|
|
2015-10-18 21:01:25 +00:00
|
|
|
virtual void clearZBuffer();
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2016-06-30 23:03:38 +00:00
|
|
|
virtual void setRenderFrameBuffer(unsigned int renderFrameBuffer);
|
2015-04-16 16:55:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //GL_INSTANCING_RENDERER_H
|