2015-05-06 17:35:14 +00:00
|
|
|
#ifndef NO_OPENGL3
|
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
|
|
|
|
|
|
|
|
///todo: make this configurable in the gui
|
2018-09-23 21:17:31 +00:00
|
|
|
bool useShadowMap = true; // true;//false;//true;
|
|
|
|
int shadowMapWidth = 4096;
|
|
|
|
int shadowMapHeight = 4096;
|
|
|
|
float shadowMapWorldSize = 10;
|
2018-09-30 14:10:40 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
struct caster2
|
|
|
|
{
|
|
|
|
void setInt(int v)
|
|
|
|
{
|
|
|
|
i = v;
|
|
|
|
}
|
|
|
|
float getFloat()
|
|
|
|
{
|
|
|
|
float v = ((float)i) + .25;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
union {
|
|
|
|
int i;
|
|
|
|
float f;
|
|
|
|
};
|
|
|
|
};
|
2015-04-16 22:16:13 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
#define MAX_POINTS_IN_BATCH 1024
|
|
|
|
#define MAX_LINES_IN_BATCH 1024
|
2017-05-24 20:05:16 +00:00
|
|
|
#define MAX_TRIANGLES_IN_BATCH 8192
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
#include "OpenGLInclude.h"
|
2015-04-16 22:16:13 +00:00
|
|
|
#include "../CommonInterfaces/CommonWindowInterface.h"
|
2015-04-16 16:55:32 +00:00
|
|
|
//#include "Bullet3Common/b3MinMax.h"
|
2017-09-20 04:10:54 +00:00
|
|
|
#ifdef B3_USE_GLFW
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2017-09-20 04:10:54 +00:00
|
|
|
#else
|
2015-04-16 16:55:32 +00:00
|
|
|
#ifndef __APPLE__
|
|
|
|
#ifndef glVertexAttribDivisor
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2017-02-07 00:22:17 +00:00
|
|
|
#ifndef NO_GLEW
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
#define glVertexAttribDivisor glVertexAttribDivisorARB
|
2018-09-23 21:17:31 +00:00
|
|
|
#endif //NO_GLEW
|
|
|
|
#endif //glVertexAttribDivisor
|
2015-04-16 16:55:32 +00:00
|
|
|
#ifndef GL_COMPARE_REF_TO_TEXTURE
|
|
|
|
#define GL_COMPARE_REF_TO_TEXTURE GL_COMPARE_R_TO_TEXTURE
|
2018-09-23 21:17:31 +00:00
|
|
|
#endif //GL_COMPARE_REF_TO_TEXTURE
|
2015-04-16 16:55:32 +00:00
|
|
|
#ifndef glDrawElementsInstanced
|
2017-02-07 00:22:17 +00:00
|
|
|
#ifndef NO_GLEW
|
2015-04-16 16:55:32 +00:00
|
|
|
#define glDrawElementsInstanced glDrawElementsInstancedARB
|
2018-09-23 21:17:31 +00:00
|
|
|
#endif //NO_GLEW
|
2015-04-16 16:55:32 +00:00
|
|
|
#endif
|
2018-09-23 21:17:31 +00:00
|
|
|
#endif //__APPLE__
|
|
|
|
#endif //B3_USE_GLFW
|
2015-04-16 16:55:32 +00:00
|
|
|
#include "GLInstancingRenderer.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
//#include "DemoSettings.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "Bullet3Common/b3Vector3.h"
|
|
|
|
#include "Bullet3Common/b3Quaternion.h"
|
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
|
|
|
#include "Bullet3Common/b3Transform.h"
|
2015-04-16 16:55:32 +00:00
|
|
|
#include "Bullet3Common/b3Matrix3x3.h"
|
2017-05-04 00:05:05 +00:00
|
|
|
#include "Bullet3Common/b3ResizablePool.h"
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
#include "LoadShader.h"
|
|
|
|
|
|
|
|
#include "GLInstanceRendererInternalData.h"
|
|
|
|
|
|
|
|
//GLSL shader strings, embedded using build3/stringify
|
|
|
|
#include "Shaders/pointSpriteVS.h"
|
|
|
|
#include "Shaders/pointSpritePS.h"
|
|
|
|
#include "Shaders/instancingVS.h"
|
|
|
|
#include "Shaders/instancingPS.h"
|
|
|
|
#include "Shaders/createShadowMapInstancingVS.h"
|
|
|
|
#include "Shaders/createShadowMapInstancingPS.h"
|
|
|
|
#include "Shaders/useShadowMapInstancingVS.h"
|
|
|
|
#include "Shaders/useShadowMapInstancingPS.h"
|
2018-02-12 05:29:02 +00:00
|
|
|
#include "Shaders/projectiveTextureInstancingVS.h"
|
|
|
|
#include "Shaders/projectiveTextureInstancingPS.h"
|
2018-09-30 14:10:40 +00:00
|
|
|
|
|
|
|
#include "Shaders/segmentationMaskInstancingVS.h"
|
|
|
|
#include "Shaders/segmentationMaskInstancingPS.h"
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
#include "Shaders/linesPS.h"
|
|
|
|
#include "Shaders/linesVS.h"
|
|
|
|
|
|
|
|
#include "GLRenderToTexture.h"
|
2018-09-11 06:18:34 +00:00
|
|
|
#include "stb_image/stb_image_write.h"
|
2015-04-16 16:55:32 +00:00
|
|
|
|
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
|
|
|
static const char* triangleVertexShaderText =
|
2018-09-23 21:17:31 +00:00
|
|
|
"#version 330\n"
|
|
|
|
"precision highp float;"
|
|
|
|
"uniform mat4 MVP;\n"
|
|
|
|
"uniform vec3 vCol;\n"
|
|
|
|
"layout (location = 0) in vec3 vPos;\n"
|
|
|
|
"layout (location = 1) in vec2 vUV;\n"
|
|
|
|
|
|
|
|
"out vec3 clr;\n"
|
|
|
|
"out vec2 uv0;\n"
|
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
|
|
|
" gl_Position = MVP * vec4(vPos,1);\n"
|
|
|
|
" clr = vCol;\n"
|
|
|
|
" uv0 = vUV;\n"
|
|
|
|
"}\n";
|
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
|
|
|
|
|
|
|
static const char* triangleFragmentShader =
|
2018-09-23 21:17:31 +00:00
|
|
|
"#version 330\n"
|
|
|
|
"precision highp float;"
|
|
|
|
"in vec3 clr;\n"
|
|
|
|
"in vec2 uv0;"
|
|
|
|
"out vec4 color;"
|
|
|
|
"uniform sampler2D Diffuse;"
|
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
|
|
|
" vec4 texel = texture(Diffuse,uv0);\n"
|
|
|
|
" color = vec4(clr,texel.r)*texel;\n"
|
|
|
|
"}\n";
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
//#include "../../opencl/gpu_rigidbody_pipeline/b3GpuNarrowphaseAndSolver.h"//for m_maxNumObjectCapacity
|
|
|
|
|
|
|
|
static InternalDataRenderer* sData2;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
GLint lineWidthRange[2] = {1, 1};
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2017-06-24 20:41:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
eGfxTransparency = 1,
|
2017-07-01 16:15:00 +00:00
|
|
|
eGfxHasTexture = 2,
|
2017-06-24 20:41:33 +00:00
|
|
|
};
|
2017-07-01 02:11:43 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
struct b3GraphicsInstance
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
GLuint m_cube_vao;
|
|
|
|
GLuint m_index_vbo;
|
|
|
|
GLuint m_textureIndex;
|
2015-04-16 16:55:32 +00:00
|
|
|
int m_numIndices;
|
|
|
|
int m_numVertices;
|
|
|
|
|
|
|
|
int m_numGraphicsInstances;
|
2017-05-04 00:05:05 +00:00
|
|
|
b3AlignedObjectArray<int> m_tempObjectUids;
|
2015-04-16 16:55:32 +00:00
|
|
|
int m_instanceOffset;
|
|
|
|
int m_vertexArrayOffset;
|
2018-09-23 21:17:31 +00:00
|
|
|
int m_primitiveType;
|
2017-06-01 03:32:45 +00:00
|
|
|
float m_materialShinyNess;
|
|
|
|
b3Vector3 m_materialSpecularColor;
|
2018-09-23 21:17:31 +00:00
|
|
|
int m_flags; //transparency etc
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
b3GraphicsInstance()
|
2018-09-23 21:17:31 +00:00
|
|
|
: m_cube_vao(-1),
|
|
|
|
m_index_vbo(-1),
|
|
|
|
m_textureIndex(-1),
|
|
|
|
m_numIndices(-1),
|
|
|
|
m_numVertices(-1),
|
|
|
|
m_numGraphicsInstances(0),
|
|
|
|
m_instanceOffset(0),
|
|
|
|
m_vertexArrayOffset(0),
|
|
|
|
m_primitiveType(B3_GL_TRIANGLES),
|
|
|
|
m_materialShinyNess(41),
|
|
|
|
m_materialSpecularColor(b3MakeVector3(.5, .5, .5)),
|
|
|
|
m_flags(0)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool m_ortho = false;
|
|
|
|
|
|
|
|
//static GLfloat depthLightModelviewMatrix[16];
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
static void checkError(const char* functionName)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
GLenum error;
|
|
|
|
while ((error = glGetError()) != GL_NO_ERROR)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "GL error 0x%X detected in %s\n", error, functionName);
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern int gShapeIndex;
|
|
|
|
|
2016-04-20 19:55:21 +00:00
|
|
|
struct InternalTextureHandle
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
GLuint m_glTexture;
|
|
|
|
int m_width;
|
|
|
|
int m_height;
|
2017-07-01 02:11:43 +00:00
|
|
|
int m_enableFiltering;
|
2016-04-20 19:55:21 +00:00
|
|
|
};
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2017-05-04 00:05:05 +00:00
|
|
|
struct b3PublicGraphicsInstanceData
|
|
|
|
{
|
|
|
|
int m_shapeIndex;
|
|
|
|
int m_internalInstanceIndex;
|
|
|
|
GLfloat m_position[4];
|
|
|
|
GLfloat m_orientation[4];
|
|
|
|
GLfloat m_color[4];
|
|
|
|
GLfloat m_scale[4];
|
|
|
|
|
2017-05-04 04:53:29 +00:00
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
}
|
2017-05-04 00:05:05 +00:00
|
|
|
};
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2017-05-04 00:05:05 +00:00
|
|
|
typedef b3PoolBodyHandle<b3PublicGraphicsInstanceData> b3PublicGraphicsInstance;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
struct InternalDataRenderer : public GLInstanceRendererInternalData
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
SimpleCamera m_defaultCamera1;
|
|
|
|
CommonCameraInterface* m_activeCamera;
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
GLfloat m_projectionMatrix[16];
|
|
|
|
GLfloat m_viewMatrix[16];
|
2018-03-19 01:45:54 +00:00
|
|
|
GLfloat m_projectiveTextureProjectionMatrix[16];
|
|
|
|
GLfloat m_projectiveTextureViewMatrix[16];
|
2017-06-01 03:32:45 +00:00
|
|
|
GLfloat m_viewMatrixInverse[16];
|
2018-03-21 04:28:47 +00:00
|
|
|
bool m_useProjectiveTexture;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2017-04-23 14:35:13 +00:00
|
|
|
b3Vector3 m_lightPos;
|
2017-06-01 03:32:45 +00:00
|
|
|
b3Vector3 m_lightSpecularIntensity;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
GLuint m_defaultTexturehandle;
|
|
|
|
b3AlignedObjectArray<InternalTextureHandle> m_textureHandles;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
GLRenderToTexture* m_shadowMap;
|
|
|
|
GLuint m_shadowTexture;
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
GLuint m_renderFrameBuffer;
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3ResizablePool<b3PublicGraphicsInstance> m_publicGraphicsInstances;
|
2017-05-04 00:05:05 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
InternalDataRenderer() : m_activeCamera(&m_defaultCamera1),
|
|
|
|
m_shadowMap(0),
|
|
|
|
m_shadowTexture(0),
|
|
|
|
m_renderFrameBuffer(0)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
m_lightPos = b3MakeVector3(-50, 30, 40);
|
|
|
|
m_lightSpecularIntensity.setValue(1, 1, 1);
|
2017-04-23 14:35:13 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
//clear to zero to make it obvious if the matrix is used uninitialized
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < 16; i++)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
m_projectionMatrix[i] = 0;
|
|
|
|
m_viewMatrix[i] = 0;
|
|
|
|
m_viewMatrixInverse[i] = 0;
|
|
|
|
m_projectiveTextureProjectionMatrix[i] = 0;
|
|
|
|
m_projectiveTextureViewMatrix[i] = 0;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2018-03-21 04:28:47 +00:00
|
|
|
m_useProjectiveTexture = false;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
struct GLInstanceRendererInternalData* GLInstancingRenderer::getInternalData()
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
return m_data;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
static GLuint triangleShaderProgram;
|
|
|
|
static GLint triangle_mvp_location = -1;
|
|
|
|
static GLint triangle_vpos_location = -1;
|
|
|
|
static GLint triangle_vUV_location = -1;
|
|
|
|
static GLint triangle_vcol_location = -1;
|
|
|
|
static GLuint triangleVertexBufferObject = 0;
|
|
|
|
static GLuint triangleVertexArrayObject = 0;
|
|
|
|
static GLuint triangleIndexVbo = 0;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
static GLuint linesShader; // The line renderer
|
|
|
|
static GLuint useShadowMapInstancingShader; // The shadow instancing renderer
|
|
|
|
static GLuint createShadowMapInstancingShader; // The shadow instancing renderer
|
|
|
|
static GLuint projectiveTextureInstancingShader; // The projective texture instancing renderer
|
2018-09-30 14:10:40 +00:00
|
|
|
static GLuint segmentationMaskInstancingShader; // The segmentation mask instancing renderer
|
|
|
|
|
|
|
|
static GLuint instancingShader; // The instancing renderer
|
|
|
|
static GLuint instancingShaderPointSprite; // The point sprite instancing renderer
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
//static bool done = false;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
static GLint lines_ModelViewMatrix = 0;
|
|
|
|
static GLint lines_ProjectionMatrix = 0;
|
|
|
|
static GLint lines_position = 0;
|
|
|
|
static GLint lines_colour = 0;
|
|
|
|
GLuint lineVertexBufferObject = 0;
|
|
|
|
GLuint lineVertexArrayObject = 0;
|
2015-04-16 16:55:32 +00:00
|
|
|
GLuint lineIndexVbo = 0;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
GLuint linesVertexBufferObject = 0;
|
|
|
|
GLuint linesVertexArrayObject = 0;
|
2015-04-16 16:55:32 +00:00
|
|
|
GLuint linesIndexVbo = 0;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
static GLint useShadow_ViewMatrixInverse = 0;
|
|
|
|
static GLint useShadow_ModelViewMatrix = 0;
|
|
|
|
static GLint useShadow_lightSpecularIntensity = 0;
|
|
|
|
static GLint useShadow_materialSpecularColor = 0;
|
|
|
|
static GLint useShadow_MVP = 0;
|
|
|
|
static GLint useShadow_lightPosIn = 0;
|
|
|
|
static GLint useShadow_cameraPositionIn = 0;
|
|
|
|
static GLint useShadow_materialShininessIn = 0;
|
|
|
|
|
|
|
|
static GLint useShadow_ProjectionMatrix = 0;
|
|
|
|
static GLint useShadow_DepthBiasModelViewMatrix = 0;
|
|
|
|
static GLint useShadow_uniform_texture_diffuse = 0;
|
|
|
|
static GLint useShadow_shadowMap = 0;
|
|
|
|
|
|
|
|
static GLint createShadow_depthMVP = 0;
|
|
|
|
|
|
|
|
static GLint projectiveTexture_ViewMatrixInverse = 0;
|
|
|
|
static GLint projectiveTexture_ModelViewMatrix = 0;
|
|
|
|
static GLint projectiveTexture_lightSpecularIntensity = 0;
|
|
|
|
static GLint projectiveTexture_materialSpecularColor = 0;
|
|
|
|
static GLint projectiveTexture_MVP = 0;
|
|
|
|
static GLint projectiveTexture_lightPosIn = 0;
|
|
|
|
static GLint projectiveTexture_cameraPositionIn = 0;
|
|
|
|
static GLint projectiveTexture_materialShininessIn = 0;
|
|
|
|
|
|
|
|
static GLint projectiveTexture_ProjectionMatrix = 0;
|
|
|
|
static GLint projectiveTexture_TextureMVP = 0;
|
|
|
|
static GLint projectiveTexture_uniform_texture_diffuse = 0;
|
|
|
|
static GLint projectiveTexture_shadowMap = 0;
|
|
|
|
|
|
|
|
static GLint ModelViewMatrix = 0;
|
|
|
|
static GLint ProjectionMatrix = 0;
|
|
|
|
static GLint regularLightDirIn = 0;
|
|
|
|
|
2018-09-30 14:10:40 +00:00
|
|
|
static GLint segmentationMaskModelViewMatrix = 0;
|
|
|
|
static GLint segmentationMaskProjectionMatrix = 0;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
static GLint uniform_texture_diffuse = 0;
|
|
|
|
|
|
|
|
static GLint screenWidthPointSprite = 0;
|
|
|
|
static GLint ModelViewMatrixPointSprite = 0;
|
|
|
|
static GLint ProjectionMatrixPointSprite = 0;
|
2015-04-16 16:55:32 +00:00
|
|
|
//static GLint uniform_texture_diffusePointSprite= 0;
|
|
|
|
|
|
|
|
GLInstancingRenderer::GLInstancingRenderer(int maxNumObjectCapacity, int maxShapeCapacityInBytes)
|
2018-09-23 21:17:31 +00:00
|
|
|
: m_textureenabled(true),
|
|
|
|
m_textureinitialized(false),
|
|
|
|
m_screenWidth(0),
|
|
|
|
m_screenHeight(0),
|
|
|
|
m_upAxis(1),
|
|
|
|
m_planeReflectionShapeIndex(-1)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
m_data = new InternalDataRenderer;
|
2015-05-01 18:42:14 +00:00
|
|
|
m_data->m_maxNumObjectCapacity = maxNumObjectCapacity;
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_maxShapeCapacityInBytes = maxShapeCapacityInBytes;
|
2015-05-01 18:42:14 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
m_data->m_totalNumInstances = 0;
|
|
|
|
|
|
|
|
sData2 = m_data;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_instance_positions_ptr.resize(m_data->m_maxNumObjectCapacity * 4);
|
|
|
|
m_data->m_instance_quaternion_ptr.resize(m_data->m_maxNumObjectCapacity * 4);
|
|
|
|
m_data->m_instance_colors_ptr.resize(m_data->m_maxNumObjectCapacity * 4);
|
2018-09-30 14:10:40 +00:00
|
|
|
m_data->m_instance_scale_ptr.resize(m_data->m_maxNumObjectCapacity * 4);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLInstancingRenderer::removeAllInstances()
|
|
|
|
{
|
2016-07-09 22:09:09 +00:00
|
|
|
m_data->m_totalNumInstances = 0;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < m_graphicsInstances.size(); i++)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
if (m_graphicsInstances[i]->m_index_vbo)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
glDeleteBuffers(1, &m_graphicsInstances[i]->m_index_vbo);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
if (m_graphicsInstances[i]->m_cube_vao)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
glDeleteVertexArrays(1, &m_graphicsInstances[i]->m_cube_vao);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
delete m_graphicsInstances[i];
|
|
|
|
}
|
|
|
|
m_graphicsInstances.clear();
|
2017-05-04 00:05:05 +00:00
|
|
|
m_data->m_publicGraphicsInstances.exitHandles();
|
|
|
|
m_data->m_publicGraphicsInstances.initHandles();
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLInstancingRenderer::~GLInstancingRenderer()
|
|
|
|
{
|
|
|
|
delete m_data->m_shadowMap;
|
2018-09-23 21:17:31 +00:00
|
|
|
glDeleteTextures(1, &m_data->m_shadowTexture);
|
|
|
|
glDeleteTextures(1, &m_data->m_defaultTexturehandle);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
removeAllInstances();
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
sData2 = 0;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
if (m_data)
|
|
|
|
{
|
|
|
|
if (m_data->m_vbo)
|
2018-09-23 21:17:31 +00:00
|
|
|
glDeleteBuffers(1, &m_data->m_vbo);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
delete m_data;
|
|
|
|
}
|
|
|
|
|
2017-06-30 20:35:07 +00:00
|
|
|
int GLInstancingRenderer::getShapeIndexFromInstance(int srcIndex)
|
|
|
|
{
|
|
|
|
b3PublicGraphicsInstance* pg = m_data->m_publicGraphicsInstances.getHandle(srcIndex);
|
|
|
|
if (pg)
|
|
|
|
{
|
|
|
|
return pg->m_shapeIndex;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
|
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
|
|
|
bool GLInstancingRenderer::readSingleInstanceTransformToCPU(float* position, float* orientation, int shapeIndex)
|
|
|
|
{
|
|
|
|
b3PublicGraphicsInstance* pg = m_data->m_publicGraphicsInstances.getHandle(shapeIndex);
|
|
|
|
if (pg)
|
|
|
|
{
|
|
|
|
int srcIndex = pg->m_internalInstanceIndex;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if ((srcIndex < m_data->m_totalNumInstances) && (srcIndex >= 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
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
position[0] = m_data->m_instance_positions_ptr[srcIndex * 4 + 0];
|
|
|
|
position[1] = m_data->m_instance_positions_ptr[srcIndex * 4 + 1];
|
|
|
|
position[2] = m_data->m_instance_positions_ptr[srcIndex * 4 + 2];
|
|
|
|
|
|
|
|
orientation[0] = m_data->m_instance_quaternion_ptr[srcIndex * 4 + 0];
|
|
|
|
orientation[1] = m_data->m_instance_quaternion_ptr[srcIndex * 4 + 1];
|
|
|
|
orientation[2] = m_data->m_instance_quaternion_ptr[srcIndex * 4 + 2];
|
|
|
|
orientation[3] = m_data->m_instance_quaternion_ptr[srcIndex * 4 + 3];
|
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
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2017-06-01 23:48:07 +00:00
|
|
|
void GLInstancingRenderer::writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex2)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2017-06-01 23:48:07 +00:00
|
|
|
b3PublicGraphicsInstance* pg = m_data->m_publicGraphicsInstances.getHandle(srcIndex2);
|
2017-05-04 00:05:05 +00:00
|
|
|
b3Assert(pg);
|
2017-05-30 04:55:58 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (pg == 0)
|
2017-05-30 04:55:58 +00:00
|
|
|
return;
|
|
|
|
|
2017-05-04 00:05:05 +00:00
|
|
|
int srcIndex = pg->m_internalInstanceIndex;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(srcIndex < m_data->m_totalNumInstances);
|
|
|
|
b3Assert(srcIndex >= 0);
|
|
|
|
m_data->m_instance_positions_ptr[srcIndex * 4 + 0] = position[0];
|
|
|
|
m_data->m_instance_positions_ptr[srcIndex * 4 + 1] = position[1];
|
|
|
|
m_data->m_instance_positions_ptr[srcIndex * 4 + 2] = position[2];
|
|
|
|
m_data->m_instance_positions_ptr[srcIndex * 4 + 3] = 1;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_instance_quaternion_ptr[srcIndex * 4 + 0] = orientation[0];
|
|
|
|
m_data->m_instance_quaternion_ptr[srcIndex * 4 + 1] = orientation[1];
|
|
|
|
m_data->m_instance_quaternion_ptr[srcIndex * 4 + 2] = orientation[2];
|
|
|
|
m_data->m_instance_quaternion_ptr[srcIndex * 4 + 3] = orientation[3];
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2017-06-01 23:48:07 +00:00
|
|
|
void GLInstancingRenderer::readSingleInstanceTransformFromCPU(int srcIndex2, float* position, float* orientation)
|
2016-09-08 22:15:58 +00:00
|
|
|
{
|
2017-06-01 23:48:07 +00:00
|
|
|
b3PublicGraphicsInstance* pg = m_data->m_publicGraphicsInstances.getHandle(srcIndex2);
|
2017-05-04 00:05:05 +00:00
|
|
|
b3Assert(pg);
|
|
|
|
int srcIndex = pg->m_internalInstanceIndex;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(srcIndex < m_data->m_totalNumInstances);
|
|
|
|
b3Assert(srcIndex >= 0);
|
|
|
|
position[0] = m_data->m_instance_positions_ptr[srcIndex * 4 + 0];
|
|
|
|
position[1] = m_data->m_instance_positions_ptr[srcIndex * 4 + 1];
|
|
|
|
position[2] = m_data->m_instance_positions_ptr[srcIndex * 4 + 2];
|
2017-05-04 00:05:05 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
orientation[0] = m_data->m_instance_quaternion_ptr[srcIndex * 4 + 0];
|
|
|
|
orientation[1] = m_data->m_instance_quaternion_ptr[srcIndex * 4 + 1];
|
|
|
|
orientation[2] = m_data->m_instance_quaternion_ptr[srcIndex * 4 + 2];
|
|
|
|
orientation[3] = m_data->m_instance_quaternion_ptr[srcIndex * 4 + 3];
|
2016-09-08 22:15:58 +00:00
|
|
|
}
|
2017-06-01 23:48:07 +00:00
|
|
|
void GLInstancingRenderer::writeSingleInstanceColorToCPU(const double* color, int srcIndex2)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2017-06-01 23:48:07 +00:00
|
|
|
b3PublicGraphicsInstance* pg = m_data->m_publicGraphicsInstances.getHandle(srcIndex2);
|
2017-05-04 00:05:05 +00:00
|
|
|
b3Assert(pg);
|
|
|
|
int srcIndex = pg->m_internalInstanceIndex;
|
|
|
|
|
2018-04-11 15:50:29 +00:00
|
|
|
int shapeIndex = pg->m_shapeIndex;
|
|
|
|
b3GraphicsInstance* gfxObj = m_graphicsInstances[shapeIndex];
|
2018-09-23 21:17:31 +00:00
|
|
|
if (color[3] < 1)
|
2018-04-11 15:50:29 +00:00
|
|
|
{
|
|
|
|
gfxObj->m_flags |= eGfxTransparency;
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2018-04-11 15:50:29 +00:00
|
|
|
{
|
|
|
|
gfxObj->m_flags &= ~eGfxTransparency;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
m_data->m_instance_colors_ptr[srcIndex * 4 + 0] = float(color[0]);
|
|
|
|
m_data->m_instance_colors_ptr[srcIndex * 4 + 1] = float(color[1]);
|
|
|
|
m_data->m_instance_colors_ptr[srcIndex * 4 + 2] = float(color[2]);
|
|
|
|
m_data->m_instance_colors_ptr[srcIndex * 4 + 3] = float(color[3]);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2017-06-01 23:48:07 +00:00
|
|
|
void GLInstancingRenderer::writeSingleInstanceColorToCPU(const float* color, int srcIndex2)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2017-06-01 23:48:07 +00:00
|
|
|
b3PublicGraphicsInstance* pg = m_data->m_publicGraphicsInstances.getHandle(srcIndex2);
|
2017-05-04 00:05:05 +00:00
|
|
|
b3Assert(pg);
|
|
|
|
int srcIndex = pg->m_internalInstanceIndex;
|
2018-04-11 15:50:29 +00:00
|
|
|
int shapeIndex = pg->m_shapeIndex;
|
|
|
|
b3GraphicsInstance* gfxObj = m_graphicsInstances[shapeIndex];
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (color[3] < 1)
|
2018-04-11 15:50:29 +00:00
|
|
|
{
|
|
|
|
gfxObj->m_flags |= eGfxTransparency;
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2018-04-11 15:50:29 +00:00
|
|
|
{
|
|
|
|
gfxObj->m_flags &= ~eGfxTransparency;
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_instance_colors_ptr[srcIndex * 4 + 0] = color[0];
|
|
|
|
m_data->m_instance_colors_ptr[srcIndex * 4 + 1] = color[1];
|
|
|
|
m_data->m_instance_colors_ptr[srcIndex * 4 + 2] = color[2];
|
|
|
|
m_data->m_instance_colors_ptr[srcIndex * 4 + 3] = color[3];
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2017-06-01 23:48:07 +00:00
|
|
|
void GLInstancingRenderer::writeSingleInstanceScaleToCPU(const float* scale, int srcIndex2)
|
2016-07-09 22:09:09 +00:00
|
|
|
{
|
2017-06-01 23:48:07 +00:00
|
|
|
b3PublicGraphicsInstance* pg = m_data->m_publicGraphicsInstances.getHandle(srcIndex2);
|
2017-05-04 00:05:05 +00:00
|
|
|
b3Assert(pg);
|
|
|
|
int srcIndex = pg->m_internalInstanceIndex;
|
|
|
|
|
2018-09-30 14:10:40 +00:00
|
|
|
m_data->m_instance_scale_ptr[srcIndex * 4 + 0] = scale[0];
|
|
|
|
m_data->m_instance_scale_ptr[srcIndex * 4 + 1] = scale[1];
|
|
|
|
m_data->m_instance_scale_ptr[srcIndex * 4 + 2] = scale[2];
|
|
|
|
caster2 c;
|
|
|
|
c.setInt(srcIndex2);
|
|
|
|
m_data->m_instance_scale_ptr[srcIndex * 4 + 3] = c.getFloat();
|
2016-07-09 22:09:09 +00:00
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2017-06-01 23:48:07 +00:00
|
|
|
void GLInstancingRenderer::writeSingleInstanceSpecularColorToCPU(const double* specular, int srcIndex2)
|
2017-06-01 19:32:44 +00:00
|
|
|
{
|
2017-06-01 23:48:07 +00:00
|
|
|
b3PublicGraphicsInstance* pg = m_data->m_publicGraphicsInstances.getHandle(srcIndex2);
|
2017-06-01 19:32:44 +00:00
|
|
|
b3Assert(pg);
|
2017-06-01 23:48:07 +00:00
|
|
|
int graphicsIndex = pg->m_internalInstanceIndex;
|
2017-06-01 19:32:44 +00:00
|
|
|
|
|
|
|
int totalNumInstances = 0;
|
|
|
|
|
|
|
|
int gfxObjIndex = -1;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < m_graphicsInstances.size(); i++)
|
2017-06-01 19:32:44 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
totalNumInstances += m_graphicsInstances[i]->m_numGraphicsInstances;
|
|
|
|
if (srcIndex2 < totalNumInstances)
|
2017-06-01 19:32:44 +00:00
|
|
|
{
|
|
|
|
gfxObjIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (gfxObjIndex > 0)
|
2017-06-01 19:32:44 +00:00
|
|
|
{
|
|
|
|
m_graphicsInstances[gfxObjIndex]->m_materialSpecularColor[0] = specular[0];
|
|
|
|
m_graphicsInstances[gfxObjIndex]->m_materialSpecularColor[1] = specular[1];
|
|
|
|
m_graphicsInstances[gfxObjIndex]->m_materialSpecularColor[2] = specular[2];
|
|
|
|
}
|
|
|
|
}
|
2017-06-01 23:48:07 +00:00
|
|
|
void GLInstancingRenderer::writeSingleInstanceSpecularColorToCPU(const float* specular, int srcIndex2)
|
2017-06-01 19:32:44 +00:00
|
|
|
{
|
2017-06-01 23:48:07 +00:00
|
|
|
b3PublicGraphicsInstance* pg = m_data->m_publicGraphicsInstances.getHandle(srcIndex2);
|
2017-06-01 19:32:44 +00:00
|
|
|
b3Assert(pg);
|
|
|
|
int srcIndex = pg->m_internalInstanceIndex;
|
|
|
|
|
|
|
|
int totalNumInstances = 0;
|
|
|
|
|
|
|
|
int gfxObjIndex = -1;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < m_graphicsInstances.size(); i++)
|
2017-06-01 19:32:44 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
totalNumInstances += m_graphicsInstances[i]->m_numGraphicsInstances;
|
|
|
|
if (srcIndex2 < totalNumInstances)
|
2017-06-01 19:32:44 +00:00
|
|
|
{
|
|
|
|
gfxObjIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (gfxObjIndex > 0)
|
2017-06-01 19:32:44 +00:00
|
|
|
{
|
|
|
|
m_graphicsInstances[gfxObjIndex]->m_materialSpecularColor[0] = specular[0];
|
|
|
|
m_graphicsInstances[gfxObjIndex]->m_materialSpecularColor[1] = specular[1];
|
|
|
|
m_graphicsInstances[gfxObjIndex]->m_materialSpecularColor[2] = specular[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-01 23:48:07 +00:00
|
|
|
void GLInstancingRenderer::writeSingleInstanceScaleToCPU(const double* scale, int srcIndex2)
|
2016-07-09 22:09:09 +00:00
|
|
|
{
|
2017-06-01 23:48:07 +00:00
|
|
|
b3PublicGraphicsInstance* pg = m_data->m_publicGraphicsInstances.getHandle(srcIndex2);
|
2017-05-04 00:05:05 +00:00
|
|
|
b3Assert(pg);
|
|
|
|
int srcIndex = pg->m_internalInstanceIndex;
|
|
|
|
|
2018-09-30 14:10:40 +00:00
|
|
|
m_data->m_instance_scale_ptr[srcIndex * 4 + 0] = scale[0];
|
|
|
|
m_data->m_instance_scale_ptr[srcIndex * 4 + 1] = scale[1];
|
|
|
|
m_data->m_instance_scale_ptr[srcIndex * 4 + 2] = scale[2];
|
|
|
|
caster2 c;
|
|
|
|
c.setInt(srcIndex2);
|
|
|
|
m_data->m_instance_scale_ptr[srcIndex * 4 + 3] = c.getFloat();
|
2016-07-09 22:09:09 +00:00
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2017-05-04 00:05:05 +00:00
|
|
|
void GLInstancingRenderer::writeSingleInstanceTransformToGPU(float* position, float* orientation, int objectUniqueId)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
|
2016-07-18 06:50:11 +00:00
|
|
|
//glFlush();
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2017-05-04 00:05:05 +00:00
|
|
|
b3PublicGraphicsInstance* pg = m_data->m_publicGraphicsInstances.getHandle(objectUniqueId);
|
|
|
|
b3Assert(pg);
|
|
|
|
int objectIndex = pg->m_internalInstanceIndex;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
char* orgBase = (char*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
|
2015-04-16 16:55:32 +00:00
|
|
|
//b3GraphicsInstance* gfxObj = m_graphicsInstances[k];
|
2018-09-23 21:17:31 +00:00
|
|
|
int totalNumInstances = 0;
|
|
|
|
for (int k = 0; k < m_graphicsInstances.size(); k++)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
b3GraphicsInstance* gfxObj = m_graphicsInstances[k];
|
2018-09-23 21:17:31 +00:00
|
|
|
totalNumInstances += gfxObj->m_numGraphicsInstances;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int POSITION_BUFFER_SIZE = (totalNumInstances * sizeof(float) * 4);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
char* base = orgBase;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
float* positions = (float*)(base + m_data->m_maxShapeCapacityInBytes);
|
|
|
|
float* orientations = (float*)(base + m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
positions[objectIndex * 4] = position[0];
|
|
|
|
positions[objectIndex * 4 + 1] = position[1];
|
|
|
|
positions[objectIndex * 4 + 2] = position[2];
|
|
|
|
positions[objectIndex * 4 + 3] = position[3];
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
orientations[objectIndex * 4] = orientation[0];
|
|
|
|
orientations[objectIndex * 4 + 1] = orientation[1];
|
|
|
|
orientations[objectIndex * 4 + 2] = orientation[2];
|
|
|
|
orientations[objectIndex * 4 + 3] = orientation[3];
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glUnmapBuffer(GL_ARRAY_BUFFER);
|
2016-07-18 06:50:11 +00:00
|
|
|
//glFlush();
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLInstancingRenderer::writeTransforms()
|
|
|
|
{
|
2016-10-14 22:06:09 +00:00
|
|
|
{
|
2017-09-29 14:50:48 +00:00
|
|
|
//B3_PROFILE("b3Assert(glGetError() 1");
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2016-10-14 22:06:09 +00:00
|
|
|
}
|
|
|
|
{
|
2017-09-29 14:50:48 +00:00
|
|
|
//B3_PROFILE("glBindBuffer");
|
2016-10-14 22:06:09 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2016-10-14 22:06:09 +00:00
|
|
|
{
|
2017-09-29 14:50:48 +00:00
|
|
|
//B3_PROFILE("glFlush()");
|
2016-10-14 22:06:09 +00:00
|
|
|
//without the flush, the glBufferSubData can spike to really slow (seconds slow)
|
|
|
|
glFlush();
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2016-10-14 22:06:09 +00:00
|
|
|
{
|
2017-09-29 14:50:48 +00:00
|
|
|
//B3_PROFILE("b3Assert(glGetError() 2");
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2016-10-14 22:06:09 +00:00
|
|
|
}
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2016-07-09 22:09:09 +00:00
|
|
|
#ifdef B3_DEBUG
|
2016-07-08 02:24:44 +00:00
|
|
|
{
|
2016-10-14 22:06:09 +00:00
|
|
|
//B3_PROFILE("m_data->m_totalNumInstances == totalNumInstances");
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int totalNumInstances = 0;
|
|
|
|
for (int k = 0; k < m_graphicsInstances.size(); k++)
|
2016-07-09 22:09:09 +00:00
|
|
|
{
|
|
|
|
b3GraphicsInstance* gfxObj = m_graphicsInstances[k];
|
2018-09-23 21:17:31 +00:00
|
|
|
totalNumInstances += gfxObj->m_numGraphicsInstances;
|
2016-07-09 22:09:09 +00:00
|
|
|
}
|
|
|
|
b3Assert(m_data->m_totalNumInstances == totalNumInstances);
|
2016-07-08 02:24:44 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
#endif //B3_DEBUG
|
2016-07-08 02:24:44 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int POSITION_BUFFER_SIZE = (m_data->m_totalNumInstances * sizeof(float) * 4);
|
|
|
|
int ORIENTATION_BUFFER_SIZE = (m_data->m_totalNumInstances * sizeof(float) * 4);
|
|
|
|
int COLOR_BUFFER_SIZE = (m_data->m_totalNumInstances * sizeof(float) * 4);
|
2018-10-01 03:02:12 +00:00
|
|
|
// int SCALE_BUFFER_SIZE = (totalNumInstances*sizeof(float)*4);
|
2016-07-08 02:24:44 +00:00
|
|
|
|
|
|
|
#if 1
|
2016-10-14 22:06:09 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
// printf("m_data->m_totalNumInstances = %d\n", m_data->m_totalNumInstances);
|
2016-10-14 22:06:09 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
//B3_PROFILE("glBufferSubData pos");
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, m_data->m_maxShapeCapacityInBytes, m_data->m_totalNumInstances * sizeof(float) * 4,
|
|
|
|
&m_data->m_instance_positions_ptr[0]);
|
2016-10-14 22:06:09 +00:00
|
|
|
}
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
// B3_PROFILE("glBufferSubData orn");
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE, m_data->m_totalNumInstances * sizeof(float) * 4,
|
|
|
|
&m_data->m_instance_quaternion_ptr[0]);
|
2016-10-14 22:06:09 +00:00
|
|
|
}
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
// B3_PROFILE("glBufferSubData color");
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE + ORIENTATION_BUFFER_SIZE, m_data->m_totalNumInstances * sizeof(float) * 4,
|
|
|
|
&m_data->m_instance_colors_ptr[0]);
|
2016-10-14 22:06:09 +00:00
|
|
|
}
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
// B3_PROFILE("glBufferSubData scale");
|
2018-09-30 14:10:40 +00:00
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE + ORIENTATION_BUFFER_SIZE + COLOR_BUFFER_SIZE, m_data->m_totalNumInstances * sizeof(float) * 4,
|
2018-09-23 21:17:31 +00:00
|
|
|
&m_data->m_instance_scale_ptr[0]);
|
2016-10-14 22:06:09 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-08 02:24:44 +00:00
|
|
|
#else
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
char* orgBase = (char*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
|
2015-04-16 16:55:32 +00:00
|
|
|
if (orgBase)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int k = 0; k < m_graphicsInstances.size(); k++)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
//int k=0;
|
|
|
|
b3GraphicsInstance* gfxObj = m_graphicsInstances[k];
|
|
|
|
|
|
|
|
char* base = orgBase;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
float* positions = (float*)(base + m_data->m_maxShapeCapacityInBytes);
|
|
|
|
float* orientations = (float*)(base + m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE);
|
|
|
|
float* colors = (float*)(base + m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE + ORIENTATION_BUFFER_SIZE);
|
|
|
|
float* scaling = (float*)(base + m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE + ORIENTATION_BUFFER_SIZE + COLOR_BUFFER_SIZE);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
//static int offset=0;
|
|
|
|
//offset++;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < gfxObj->m_numGraphicsInstances; i++)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int srcIndex = i + gfxObj->m_instanceOffset;
|
|
|
|
|
|
|
|
positions[srcIndex * 4] = m_data->m_instance_positions_ptr[srcIndex * 4];
|
|
|
|
positions[srcIndex * 4 + 1] = m_data->m_instance_positions_ptr[srcIndex * 4 + 1];
|
|
|
|
positions[srcIndex * 4 + 2] = m_data->m_instance_positions_ptr[srcIndex * 4 + 2];
|
|
|
|
positions[srcIndex * 4 + 3] = m_data->m_instance_positions_ptr[srcIndex * 4 + 3];
|
|
|
|
|
|
|
|
orientations[srcIndex * 4] = m_data->m_instance_quaternion_ptr[srcIndex * 4];
|
|
|
|
orientations[srcIndex * 4 + 1] = m_data->m_instance_quaternion_ptr[srcIndex * 4 + 1];
|
|
|
|
orientations[srcIndex * 4 + 2] = m_data->m_instance_quaternion_ptr[srcIndex * 4 + 2];
|
|
|
|
orientations[srcIndex * 4 + 3] = m_data->m_instance_quaternion_ptr[srcIndex * 4 + 3];
|
|
|
|
|
|
|
|
colors[srcIndex * 4] = m_data->m_instance_colors_ptr[srcIndex * 4];
|
|
|
|
colors[srcIndex * 4 + 1] = m_data->m_instance_colors_ptr[srcIndex * 4 + 1];
|
|
|
|
colors[srcIndex * 4 + 2] = m_data->m_instance_colors_ptr[srcIndex * 4 + 2];
|
|
|
|
colors[srcIndex * 4 + 3] = m_data->m_instance_colors_ptr[srcIndex * 4 + 3];
|
|
|
|
|
2018-09-30 14:10:40 +00:00
|
|
|
scaling[srcIndex * 4] = m_data->m_instance_scale_ptr[srcIndex * 4];
|
|
|
|
scaling[srcIndex * 4 + 1] = m_data->m_instance_scale_ptr[srcIndex * 4 + 1];
|
|
|
|
scaling[srcIndex * 4 + 2] = m_data->m_instance_scale_ptr[srcIndex * 4 + 2];
|
|
|
|
scaling[srcIndex * 4 + 3] = m_data->m_instance_scale_ptr[srcIndex * 4 + 3];
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
b3Error("ERROR glMapBuffer failed\n");
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glUnmapBuffer(GL_ARRAY_BUFFER);
|
2015-04-16 16:55:32 +00:00
|
|
|
//if this glFinish is removed, the animation is not always working/blocks
|
|
|
|
//@todo: figure out why
|
2016-07-18 06:50:11 +00:00
|
|
|
//glFlush();
|
2016-07-08 02:24:44 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2016-10-14 22:06:09 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
// B3_PROFILE("glBindBuffer 2");
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0); //m_data->m_vbo);
|
2016-10-14 22:06:09 +00:00
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2016-10-14 22:06:09 +00:00
|
|
|
{
|
2017-09-29 14:50:48 +00:00
|
|
|
// B3_PROFILE("b3Assert(glGetError() 4");
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2016-10-14 22:06:09 +00:00
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int GLInstancingRenderer::registerGraphicsInstance(int shapeIndex, const double* pos1, const double* orn1, const double* color1, const double* scaling1)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
float pos[4] = {(float)pos1[0], (float)pos1[1], (float)pos1[2], (float)pos1[3]};
|
|
|
|
float orn[4] = {(float)orn1[0], (float)orn1[1], (float)orn1[2], (float)orn1[3]};
|
|
|
|
float color[4] = {(float)color1[0], (float)color1[1], (float)color1[2], (float)color1[3]};
|
|
|
|
float scaling[4] = {(float)scaling1[0], (float)scaling1[1], (float)scaling1[2], (float)scaling1[3]};
|
|
|
|
return registerGraphicsInstance(shapeIndex, pos, orn, color, scaling);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2017-05-04 00:05:05 +00:00
|
|
|
void GLInstancingRenderer::rebuildGraphicsInstances()
|
|
|
|
{
|
|
|
|
m_data->m_totalNumInstances = 0;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2017-05-04 00:05:05 +00:00
|
|
|
b3AlignedObjectArray<int> usedObjects;
|
|
|
|
m_data->m_publicGraphicsInstances.getUsedHandles(usedObjects);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < usedObjects.size(); i++)
|
2017-05-04 00:05:05 +00:00
|
|
|
{
|
2017-06-01 23:48:07 +00:00
|
|
|
int srcIndex2 = usedObjects[i];
|
|
|
|
b3PublicGraphicsInstance* pg = m_data->m_publicGraphicsInstances.getHandle(srcIndex2);
|
2017-05-04 00:05:05 +00:00
|
|
|
b3Assert(pg);
|
|
|
|
int srcIndex = pg->m_internalInstanceIndex;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
pg->m_position[0] = m_data->m_instance_positions_ptr[srcIndex * 4 + 0];
|
|
|
|
pg->m_position[1] = m_data->m_instance_positions_ptr[srcIndex * 4 + 1];
|
|
|
|
pg->m_position[2] = m_data->m_instance_positions_ptr[srcIndex * 4 + 2];
|
|
|
|
pg->m_orientation[0] = m_data->m_instance_quaternion_ptr[srcIndex * 4 + 0];
|
|
|
|
pg->m_orientation[1] = m_data->m_instance_quaternion_ptr[srcIndex * 4 + 1];
|
|
|
|
pg->m_orientation[2] = m_data->m_instance_quaternion_ptr[srcIndex * 4 + 2];
|
|
|
|
pg->m_orientation[3] = m_data->m_instance_quaternion_ptr[srcIndex * 4 + 3];
|
|
|
|
pg->m_color[0] = m_data->m_instance_colors_ptr[srcIndex * 4 + 0];
|
|
|
|
pg->m_color[1] = m_data->m_instance_colors_ptr[srcIndex * 4 + 1];
|
|
|
|
pg->m_color[2] = m_data->m_instance_colors_ptr[srcIndex * 4 + 2];
|
|
|
|
pg->m_color[3] = m_data->m_instance_colors_ptr[srcIndex * 4 + 3];
|
2018-09-30 14:10:40 +00:00
|
|
|
pg->m_scale[0] = m_data->m_instance_scale_ptr[srcIndex * 4 + 0];
|
|
|
|
pg->m_scale[1] = m_data->m_instance_scale_ptr[srcIndex * 4 + 1];
|
|
|
|
pg->m_scale[2] = m_data->m_instance_scale_ptr[srcIndex * 4 + 2];
|
|
|
|
pg->m_scale[3] = m_data->m_instance_scale_ptr[srcIndex * 4 + 3];
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i < m_graphicsInstances.size(); i++)
|
2017-05-04 00:05:05 +00:00
|
|
|
{
|
|
|
|
m_graphicsInstances[i]->m_numGraphicsInstances = 0;
|
|
|
|
m_graphicsInstances[i]->m_instanceOffset = 0;
|
|
|
|
m_graphicsInstances[i]->m_tempObjectUids.clear();
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < usedObjects.size(); i++)
|
2017-05-04 00:05:05 +00:00
|
|
|
{
|
2017-06-01 23:48:07 +00:00
|
|
|
int srcIndex2 = usedObjects[i];
|
|
|
|
b3PublicGraphicsInstance* pg = m_data->m_publicGraphicsInstances.getHandle(srcIndex2);
|
2018-09-23 21:17:31 +00:00
|
|
|
if (pg && pg->m_shapeIndex < m_graphicsInstances.size() && pg->m_shapeIndex >= 0)
|
2018-05-23 03:26:00 +00:00
|
|
|
{
|
|
|
|
m_graphicsInstances[pg->m_shapeIndex]->m_tempObjectUids.push_back(srcIndex2);
|
|
|
|
}
|
2017-05-04 00:05:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int curOffset = 0;
|
|
|
|
m_data->m_totalNumInstances = 0;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < m_graphicsInstances.size(); i++)
|
2017-05-04 00:05:05 +00:00
|
|
|
{
|
|
|
|
m_graphicsInstances[i]->m_instanceOffset = curOffset;
|
|
|
|
m_graphicsInstances[i]->m_numGraphicsInstances = 0;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int g = 0; g < m_graphicsInstances[i]->m_tempObjectUids.size(); g++)
|
2017-05-04 00:05:05 +00:00
|
|
|
{
|
|
|
|
curOffset++;
|
|
|
|
int objectUniqueId = m_graphicsInstances[i]->m_tempObjectUids[g];
|
|
|
|
b3PublicGraphicsInstance* pg = m_data->m_publicGraphicsInstances.getHandle(objectUniqueId);
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
registerGraphicsInstanceInternal(objectUniqueId, pg->m_position, pg->m_orientation, pg->m_color, pg->m_scale);
|
2017-05-04 00:05:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLInstancingRenderer::removeGraphicsInstance(int instanceUid)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2017-05-04 00:05:05 +00:00
|
|
|
b3PublicGraphicsInstance* pg = m_data->m_publicGraphicsInstances.getHandle(instanceUid);
|
|
|
|
b3Assert(pg);
|
|
|
|
if (pg)
|
|
|
|
{
|
|
|
|
m_data->m_publicGraphicsInstances.freeHandle(instanceUid);
|
|
|
|
rebuildGraphicsInstances();
|
|
|
|
}
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2017-05-04 00:05:05 +00:00
|
|
|
int GLInstancingRenderer::registerGraphicsInstanceInternal(int newUid, const float* position, const float* quaternion, const float* color, const float* scaling)
|
|
|
|
{
|
|
|
|
b3PublicGraphicsInstance* pg = m_data->m_publicGraphicsInstances.getHandle(newUid);
|
|
|
|
int shapeIndex = pg->m_shapeIndex;
|
2018-09-23 21:17:31 +00:00
|
|
|
// b3Assert(pg);
|
|
|
|
// int objectIndex = pg->m_internalInstanceIndex;
|
2017-05-04 00:05:05 +00:00
|
|
|
|
|
|
|
b3GraphicsInstance* gfxObj = m_graphicsInstances[shapeIndex];
|
2015-04-16 16:55:32 +00:00
|
|
|
int index = gfxObj->m_numGraphicsInstances + gfxObj->m_instanceOffset;
|
2017-05-04 00:05:05 +00:00
|
|
|
pg->m_internalInstanceIndex = index;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
int maxElements = m_data->m_instance_positions_ptr.size();
|
2018-09-23 21:17:31 +00:00
|
|
|
if (index * 4 < maxElements)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_instance_positions_ptr[index * 4] = position[0];
|
|
|
|
m_data->m_instance_positions_ptr[index * 4 + 1] = position[1];
|
|
|
|
m_data->m_instance_positions_ptr[index * 4 + 2] = position[2];
|
|
|
|
m_data->m_instance_positions_ptr[index * 4 + 3] = 1;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_instance_quaternion_ptr[index * 4] = quaternion[0];
|
|
|
|
m_data->m_instance_quaternion_ptr[index * 4 + 1] = quaternion[1];
|
|
|
|
m_data->m_instance_quaternion_ptr[index * 4 + 2] = quaternion[2];
|
|
|
|
m_data->m_instance_quaternion_ptr[index * 4 + 3] = quaternion[3];
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_instance_colors_ptr[index * 4] = color[0];
|
|
|
|
m_data->m_instance_colors_ptr[index * 4 + 1] = color[1];
|
|
|
|
m_data->m_instance_colors_ptr[index * 4 + 2] = color[2];
|
|
|
|
m_data->m_instance_colors_ptr[index * 4 + 3] = color[3];
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-30 14:10:40 +00:00
|
|
|
m_data->m_instance_scale_ptr[index * 4] = scaling[0];
|
|
|
|
m_data->m_instance_scale_ptr[index * 4 + 1] = scaling[1];
|
|
|
|
m_data->m_instance_scale_ptr[index * 4 + 2] = scaling[2];
|
|
|
|
caster2 c;
|
|
|
|
c.setInt(newUid);
|
|
|
|
m_data->m_instance_scale_ptr[index * 4 + 3] = c.getFloat();
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (color[3] < 1 && color[3] > 0)
|
2017-06-24 20:41:33 +00:00
|
|
|
{
|
|
|
|
gfxObj->m_flags |= eGfxTransparency;
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
gfxObj->m_numGraphicsInstances++;
|
|
|
|
m_data->m_totalNumInstances++;
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
b3Error("registerGraphicsInstance out of range, %d\n", maxElements);
|
|
|
|
return -1;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
return newUid; //gfxObj->m_numGraphicsInstances;
|
2017-05-04 00:05:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int GLInstancingRenderer::registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling)
|
|
|
|
{
|
|
|
|
int newUid = m_data->m_publicGraphicsInstances.allocHandle();
|
|
|
|
b3PublicGraphicsInstance* pg = m_data->m_publicGraphicsInstances.getHandle(newUid);
|
|
|
|
pg->m_shapeIndex = shapeIndex;
|
|
|
|
|
|
|
|
//b3Assert(shapeIndex == (m_graphicsInstances.size()-1));
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(m_graphicsInstances.size() < m_data->m_maxNumObjectCapacity - 1);
|
|
|
|
if (shapeIndex == (m_graphicsInstances.size() - 1))
|
2017-05-04 00:05:05 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
registerGraphicsInstanceInternal(newUid, position, quaternion, color, scaling);
|
|
|
|
}
|
|
|
|
else
|
2017-05-04 00:05:05 +00:00
|
|
|
{
|
|
|
|
int srcIndex = m_data->m_totalNumInstances++;
|
|
|
|
pg->m_internalInstanceIndex = srcIndex;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_instance_positions_ptr[srcIndex * 4 + 0] = position[0];
|
|
|
|
m_data->m_instance_positions_ptr[srcIndex * 4 + 1] = position[1];
|
|
|
|
m_data->m_instance_positions_ptr[srcIndex * 4 + 2] = position[2];
|
|
|
|
m_data->m_instance_positions_ptr[srcIndex * 4 + 3] = 1.;
|
2017-05-04 00:05:05 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_instance_quaternion_ptr[srcIndex * 4 + 0] = quaternion[0];
|
|
|
|
m_data->m_instance_quaternion_ptr[srcIndex * 4 + 1] = quaternion[1];
|
|
|
|
m_data->m_instance_quaternion_ptr[srcIndex * 4 + 2] = quaternion[2];
|
|
|
|
m_data->m_instance_quaternion_ptr[srcIndex * 4 + 3] = quaternion[3];
|
2017-05-04 00:05:05 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_instance_colors_ptr[srcIndex * 4 + 0] = color[0];
|
|
|
|
m_data->m_instance_colors_ptr[srcIndex * 4 + 1] = color[1];
|
|
|
|
m_data->m_instance_colors_ptr[srcIndex * 4 + 2] = color[2];
|
|
|
|
m_data->m_instance_colors_ptr[srcIndex * 4 + 3] = color[3];
|
2017-05-04 00:05:05 +00:00
|
|
|
|
2018-09-30 14:10:40 +00:00
|
|
|
m_data->m_instance_scale_ptr[srcIndex * 4 + 0] = scaling[0];
|
|
|
|
m_data->m_instance_scale_ptr[srcIndex * 4 + 1] = scaling[1];
|
|
|
|
m_data->m_instance_scale_ptr[srcIndex * 4 + 2] = scaling[2];
|
|
|
|
caster2 c;
|
|
|
|
c.setInt(newUid);
|
|
|
|
m_data->m_instance_scale_ptr[srcIndex * 4 + 3] = c.getFloat();
|
2017-05-04 00:05:05 +00:00
|
|
|
|
|
|
|
rebuildGraphicsInstances();
|
|
|
|
}
|
|
|
|
|
|
|
|
return newUid;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 07:22:16 +00:00
|
|
|
void GLInstancingRenderer::removeTexture(int textureIndex)
|
|
|
|
{
|
|
|
|
if ((textureIndex >= 0) && (textureIndex < m_data->m_textureHandles.size()))
|
|
|
|
{
|
|
|
|
InternalTextureHandle& h = m_data->m_textureHandles[textureIndex];
|
|
|
|
glDeleteTextures(1, &h.m_glTexture);
|
|
|
|
}
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int GLInstancingRenderer::registerTexture(const unsigned char* texels, int width, int height, bool flipPixelsY)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2017-10-06 20:46:24 +00:00
|
|
|
B3_PROFILE("GLInstancingRenderer::registerTexture");
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2016-04-20 19:55:21 +00:00
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2015-04-16 16:55:32 +00:00
|
|
|
int textureIndex = m_data->m_textureHandles.size();
|
2018-09-23 21:17:31 +00:00
|
|
|
// const GLubyte* image= (const GLubyte*)texels;
|
2015-04-16 16:55:32 +00:00
|
|
|
GLuint textureHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
glGenTextures(1, (GLuint*)&textureHandle);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, textureHandle);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2016-04-27 03:52:52 +00:00
|
|
|
InternalTextureHandle h;
|
2018-09-23 21:17:31 +00:00
|
|
|
h.m_glTexture = textureHandle;
|
|
|
|
h.m_width = width;
|
|
|
|
h.m_height = height;
|
2017-07-01 02:11:43 +00:00
|
|
|
h.m_enableFiltering = true;
|
2016-04-20 19:55:21 +00:00
|
|
|
m_data->m_textureHandles.push_back(h);
|
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
|
|
|
if (texels)
|
|
|
|
{
|
2017-10-06 20:46:24 +00:00
|
|
|
B3_PROFILE("updateTexture");
|
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
|
|
|
updateTexture(textureIndex, texels, flipPixelsY);
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
return textureIndex;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void GLInstancingRenderer::replaceTexture(int shapeIndex, int textureId)
|
2017-06-30 20:35:07 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if ((shapeIndex >= 0) && (shapeIndex < m_graphicsInstances.size()))
|
2017-06-30 20:35:07 +00:00
|
|
|
{
|
|
|
|
b3GraphicsInstance* gfxObj = m_graphicsInstances[shapeIndex];
|
2018-09-23 21:17:31 +00:00
|
|
|
if (textureId >= 0 && textureId < m_data->m_textureHandles.size())
|
2017-06-30 20:35:07 +00:00
|
|
|
{
|
2017-07-01 02:11:43 +00:00
|
|
|
gfxObj->m_textureIndex = textureId;
|
2017-07-01 16:15:00 +00:00
|
|
|
gfxObj->m_flags |= eGfxHasTexture;
|
2018-10-20 22:56:56 +00:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
gfxObj->m_textureIndex = -1;
|
|
|
|
gfxObj->m_flags &= ~eGfxHasTexture;
|
2017-06-30 20:35:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void GLInstancingRenderer::updateTexture(int textureIndex, const unsigned char* texels, bool flipPixelsY)
|
2016-04-20 19:55:21 +00:00
|
|
|
{
|
2017-10-06 20:46:24 +00:00
|
|
|
B3_PROFILE("updateTexture");
|
2018-09-23 21:17:31 +00:00
|
|
|
if ((textureIndex >= 0) && (textureIndex < m_data->m_textureHandles.size()))
|
|
|
|
{
|
|
|
|
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);
|
2016-04-27 03:52:52 +00:00
|
|
|
|
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
|
|
|
if (flipPixelsY)
|
2016-04-27 03:52:52 +00:00
|
|
|
{
|
2017-10-06 20:46:24 +00:00
|
|
|
B3_PROFILE("flipPixelsY");
|
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
|
|
|
//textures need to be flipped for OpenGL...
|
|
|
|
b3AlignedObjectArray<unsigned char> flippedTexels;
|
2018-09-23 21:17:31 +00:00
|
|
|
flippedTexels.resize(h.m_width * h.m_height * 3);
|
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
|
|
|
|
2017-10-06 20:46:24 +00:00
|
|
|
for (int j = 0; j < h.m_height; j++)
|
2016-04-27 03:52:52 +00:00
|
|
|
{
|
2017-10-06 20:46:24 +00:00
|
|
|
for (int i = 0; i < h.m_width; i++)
|
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
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
flippedTexels[(i + j * h.m_width) * 3] = texels[(i + (h.m_height - 1 - j) * h.m_width) * 3];
|
|
|
|
flippedTexels[(i + j * h.m_width) * 3 + 1] = texels[(i + (h.m_height - 1 - j) * h.m_width) * 3 + 1];
|
|
|
|
flippedTexels[(i + j * h.m_width) * 3 + 2] = texels[(i + (h.m_height - 1 - j) * h.m_width) * 3 + 2];
|
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
|
|
|
}
|
2016-04-27 03:52:52 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, h.m_width, h.m_height, 0, GL_RGB, GL_UNSIGNED_BYTE, &flippedTexels[0]);
|
|
|
|
}
|
|
|
|
else
|
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
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, h.m_width, h.m_height, 0, GL_RGB, GL_UNSIGNED_BYTE, &texels[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
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2017-07-01 02:11:43 +00:00
|
|
|
if (h.m_enableFiltering)
|
|
|
|
{
|
2017-10-06 20:46:24 +00:00
|
|
|
B3_PROFILE("glGenerateMipmap");
|
2018-09-23 21:17:31 +00:00
|
|
|
glGenerateMipmap(GL_TEXTURE_2D);
|
2017-07-01 02:11:43 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
|
|
|
}
|
2016-04-20 19:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLInstancingRenderer::activateTexture(int textureIndex)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (textureIndex >= 0 && textureIndex < m_data->m_textureHandles.size())
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, m_data->m_textureHandles[textureIndex].m_glTexture);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
}
|
2016-04-20 19:55:21 +00:00
|
|
|
}
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
void GLInstancingRenderer::updateShape(int shapeIndex, const float* vertices)
|
|
|
|
{
|
|
|
|
b3GraphicsInstance* gfxObj = m_graphicsInstances[shapeIndex];
|
|
|
|
int numvertices = gfxObj->m_numVertices;
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
|
2018-09-23 21:17:31 +00:00
|
|
|
int vertexStrideInBytes = 9 * sizeof(float);
|
|
|
|
int sz = numvertices * vertexStrideInBytes;
|
2018-02-18 19:09:42 +00:00
|
|
|
#if 0
|
|
|
|
char* dest= (char*)glMapBuffer( GL_ARRAY_BUFFER,GL_WRITE_ONLY);//GL_WRITE_ONLY
|
2015-04-16 16:55:32 +00:00
|
|
|
memcpy(dest+vertexStrideInBytes*gfxObj->m_vertexArrayOffset,vertices,sz);
|
|
|
|
glUnmapBuffer( GL_ARRAY_BUFFER);
|
2018-02-18 19:09:42 +00:00
|
|
|
#else
|
2018-09-23 21:17:31 +00:00
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, vertexStrideInBytes * gfxObj->m_vertexArrayOffset, sz,
|
|
|
|
vertices);
|
2018-02-18 19:09:42 +00:00
|
|
|
#endif
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int GLInstancingRenderer::registerShape(const float* vertices, int numvertices, const int* indices, int numIndices, int primitiveType, int textureId)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
b3GraphicsInstance* gfxObj = new b3GraphicsInstance;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (textureId >= 0)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2017-07-01 02:11:43 +00:00
|
|
|
gfxObj->m_textureIndex = textureId;
|
2017-07-01 16:15:00 +00:00
|
|
|
gfxObj->m_flags |= eGfxHasTexture;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxObj->m_primitiveType = primitiveType;
|
|
|
|
|
|
|
|
if (m_graphicsInstances.size())
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3GraphicsInstance* prevObj = m_graphicsInstances[m_graphicsInstances.size() - 1];
|
2015-04-16 16:55:32 +00:00
|
|
|
gfxObj->m_instanceOffset = prevObj->m_instanceOffset + prevObj->m_numGraphicsInstances;
|
|
|
|
gfxObj->m_vertexArrayOffset = prevObj->m_vertexArrayOffset + prevObj->m_numVertices;
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
gfxObj->m_instanceOffset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_graphicsInstances.push_back(gfxObj);
|
|
|
|
gfxObj->m_numIndices = numIndices;
|
|
|
|
gfxObj->m_numVertices = numvertices;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int vertexStrideInBytes = 9 * sizeof(float);
|
|
|
|
int sz = numvertices * vertexStrideInBytes;
|
|
|
|
int totalUsed = vertexStrideInBytes * gfxObj->m_vertexArrayOffset + sz;
|
|
|
|
b3Assert(totalUsed < m_data->m_maxShapeCapacityInBytes);
|
|
|
|
if (totalUsed >= m_data->m_maxShapeCapacityInBytes)
|
2017-05-15 16:02:49 +00:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
|
|
|
|
|
2016-10-14 22:06:09 +00:00
|
|
|
#if 0
|
|
|
|
|
|
|
|
char* dest= (char*)glMapBuffer( GL_ARRAY_BUFFER,GL_WRITE_ONLY);//GL_WRITE_ONLY
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
#ifdef B3_DEBUG
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
#endif //B3_DEBUG
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
memcpy(dest+vertexStrideInBytes*gfxObj->m_vertexArrayOffset,vertices,sz);
|
|
|
|
glUnmapBuffer( GL_ARRAY_BUFFER);
|
2016-10-14 22:06:09 +00:00
|
|
|
#else
|
2018-09-23 21:17:31 +00:00
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, vertexStrideInBytes * gfxObj->m_vertexArrayOffset, sz,
|
|
|
|
vertices);
|
2016-10-14 22:06:09 +00:00
|
|
|
#endif
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
glGenBuffers(1, &gfxObj->m_index_vbo);
|
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gfxObj->m_index_vbo);
|
2018-09-23 21:17:31 +00:00
|
|
|
int indexBufferSizeInBytes = gfxObj->m_numIndices * sizeof(int);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexBufferSizeInBytes, NULL, GL_STATIC_DRAW);
|
2018-09-23 21:17:31 +00:00
|
|
|
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, indexBufferSizeInBytes, indices);
|
2015-04-16 16:55:32 +00:00
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
|
|
|
|
glGenVertexArrays(1, &gfxObj->m_cube_vao);
|
|
|
|
glBindVertexArray(gfxObj->m_cube_vao);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
|
|
|
|
glBindVertexArray(0);
|
2018-09-23 21:17:31 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
2015-04-16 16:55:32 +00:00
|
|
|
glBindVertexArray(0);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
return m_graphicsInstances.size() - 1;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLInstancingRenderer::InitShaders()
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int POSITION_BUFFER_SIZE = (m_data->m_maxNumObjectCapacity * sizeof(float) * 4);
|
|
|
|
int ORIENTATION_BUFFER_SIZE = (m_data->m_maxNumObjectCapacity * sizeof(float) * 4);
|
|
|
|
int COLOR_BUFFER_SIZE = (m_data->m_maxNumObjectCapacity * sizeof(float) * 4);
|
2018-09-30 14:10:40 +00:00
|
|
|
int SCALE_BUFFER_SIZE = (m_data->m_maxNumObjectCapacity * sizeof(float) * 4);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
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
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
triangleShaderProgram = gltLoadShaderPair(triangleVertexShaderText, triangleFragmentShader);
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2017-05-24 20:05:16 +00:00
|
|
|
//triangle_vpos_location = glGetAttribLocation(triangleShaderProgram, "vPos");
|
|
|
|
//triangle_vUV_location = glGetAttribLocation(triangleShaderProgram, "vUV");
|
|
|
|
|
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
|
|
|
triangle_mvp_location = glGetUniformLocation(triangleShaderProgram, "MVP");
|
|
|
|
triangle_vcol_location = glGetUniformLocation(triangleShaderProgram, "vCol");
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2017-05-24 20:05:16 +00:00
|
|
|
glLinkProgram(triangleShaderProgram);
|
|
|
|
glUseProgram(triangleShaderProgram);
|
|
|
|
|
|
|
|
glGenVertexArrays(1, &triangleVertexArrayObject);
|
|
|
|
glBindVertexArray(triangleVertexArrayObject);
|
|
|
|
|
|
|
|
glGenBuffers(1, &triangleVertexBufferObject);
|
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
|
|
|
glGenBuffers(1, &triangleIndexVbo);
|
2017-05-24 20:05:16 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int sz = MAX_TRIANGLES_IN_BATCH * sizeof(GfxVertexFormat0);
|
2017-05-24 20:05:16 +00:00
|
|
|
glBindVertexArray(triangleVertexArrayObject);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, triangleVertexBufferObject);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, sz, 0, GL_DYNAMIC_DRAW);
|
|
|
|
|
|
|
|
glBindVertexArray(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
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
linesShader = gltLoadShaderPair(linesVertexShader, linesFragmentShader);
|
2015-04-16 16:55:32 +00:00
|
|
|
lines_ModelViewMatrix = glGetUniformLocation(linesShader, "ModelViewMatrix");
|
|
|
|
lines_ProjectionMatrix = glGetUniformLocation(linesShader, "ProjectionMatrix");
|
2018-09-23 21:17:31 +00:00
|
|
|
lines_colour = glGetUniformLocation(linesShader, "colour");
|
|
|
|
lines_position = glGetAttribLocation(linesShader, "position");
|
2015-04-16 16:55:32 +00:00
|
|
|
glLinkProgram(linesShader);
|
|
|
|
glUseProgram(linesShader);
|
|
|
|
|
|
|
|
{
|
|
|
|
glGenVertexArrays(1, &linesVertexArrayObject);
|
|
|
|
glBindVertexArray(linesVertexArrayObject);
|
|
|
|
|
|
|
|
glGenBuffers(1, &linesVertexBufferObject);
|
|
|
|
glGenBuffers(1, &linesIndexVbo);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int sz = MAX_LINES_IN_BATCH * sizeof(b3Vector3);
|
2015-04-16 16:55:32 +00:00
|
|
|
glBindVertexArray(linesVertexArrayObject);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, linesVertexBufferObject);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, sz, 0, GL_DYNAMIC_DRAW);
|
|
|
|
|
|
|
|
glBindVertexArray(0);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
glGenVertexArrays(1, &lineVertexArrayObject);
|
|
|
|
glBindVertexArray(lineVertexArrayObject);
|
|
|
|
|
|
|
|
glGenBuffers(1, &lineVertexBufferObject);
|
|
|
|
glGenBuffers(1, &lineIndexVbo);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int sz = MAX_POINTS_IN_BATCH * sizeof(b3Vector3);
|
2015-04-16 16:55:32 +00:00
|
|
|
glBindVertexArray(lineVertexArrayObject);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, sz, 0, GL_DYNAMIC_DRAW);
|
|
|
|
|
|
|
|
glBindVertexArray(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//glGetIntegerv(GL_ALIASED_LINE_WIDTH_RANGE, range);
|
|
|
|
glGetIntegerv(GL_SMOOTH_LINE_WIDTH_RANGE, lineWidthRange);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
projectiveTextureInstancingShader = gltLoadShaderPair(projectiveTextureInstancingVertexShader, projectiveTextureInstancingFragmentShader);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-02-12 05:29:02 +00:00
|
|
|
glLinkProgram(projectiveTextureInstancingShader);
|
|
|
|
glUseProgram(projectiveTextureInstancingShader);
|
|
|
|
projectiveTexture_ViewMatrixInverse = glGetUniformLocation(projectiveTextureInstancingShader, "ViewMatrixInverse");
|
|
|
|
projectiveTexture_ModelViewMatrix = glGetUniformLocation(projectiveTextureInstancingShader, "ModelViewMatrix");
|
|
|
|
projectiveTexture_lightSpecularIntensity = glGetUniformLocation(projectiveTextureInstancingShader, "lightSpecularIntensityIn");
|
|
|
|
projectiveTexture_materialSpecularColor = glGetUniformLocation(projectiveTextureInstancingShader, "materialSpecularColorIn");
|
2018-09-23 21:17:31 +00:00
|
|
|
projectiveTexture_MVP = glGetUniformLocation(projectiveTextureInstancingShader, "MVP");
|
2018-02-12 05:29:02 +00:00
|
|
|
projectiveTexture_ProjectionMatrix = glGetUniformLocation(projectiveTextureInstancingShader, "ProjectionMatrix");
|
2018-02-21 02:32:09 +00:00
|
|
|
projectiveTexture_TextureMVP = glGetUniformLocation(projectiveTextureInstancingShader, "TextureMVP");
|
2018-02-12 05:29:02 +00:00
|
|
|
projectiveTexture_uniform_texture_diffuse = glGetUniformLocation(projectiveTextureInstancingShader, "Diffuse");
|
2018-09-23 21:17:31 +00:00
|
|
|
projectiveTexture_shadowMap = glGetUniformLocation(projectiveTextureInstancingShader, "shadowMap");
|
|
|
|
projectiveTexture_lightPosIn = glGetUniformLocation(projectiveTextureInstancingShader, "lightPosIn");
|
|
|
|
projectiveTexture_cameraPositionIn = glGetUniformLocation(projectiveTextureInstancingShader, "cameraPositionIn");
|
|
|
|
projectiveTexture_materialShininessIn = glGetUniformLocation(projectiveTextureInstancingShader, "materialShininessIn");
|
|
|
|
|
2018-02-12 05:29:02 +00:00
|
|
|
glUseProgram(0);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
useShadowMapInstancingShader = gltLoadShaderPair(useShadowMapInstancingVertexShader, useShadowMapInstancingFragmentShader);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
glLinkProgram(useShadowMapInstancingShader);
|
|
|
|
glUseProgram(useShadowMapInstancingShader);
|
2017-06-01 03:32:45 +00:00
|
|
|
useShadow_ViewMatrixInverse = glGetUniformLocation(useShadowMapInstancingShader, "ViewMatrixInverse");
|
2015-04-16 16:55:32 +00:00
|
|
|
useShadow_ModelViewMatrix = glGetUniformLocation(useShadowMapInstancingShader, "ModelViewMatrix");
|
2017-06-01 03:32:45 +00:00
|
|
|
useShadow_lightSpecularIntensity = glGetUniformLocation(useShadowMapInstancingShader, "lightSpecularIntensityIn");
|
|
|
|
useShadow_materialSpecularColor = glGetUniformLocation(useShadowMapInstancingShader, "materialSpecularColorIn");
|
2018-09-23 21:17:31 +00:00
|
|
|
useShadow_MVP = glGetUniformLocation(useShadowMapInstancingShader, "MVP");
|
2015-04-16 16:55:32 +00:00
|
|
|
useShadow_ProjectionMatrix = glGetUniformLocation(useShadowMapInstancingShader, "ProjectionMatrix");
|
|
|
|
useShadow_DepthBiasModelViewMatrix = glGetUniformLocation(useShadowMapInstancingShader, "DepthBiasModelViewProjectionMatrix");
|
|
|
|
useShadow_uniform_texture_diffuse = glGetUniformLocation(useShadowMapInstancingShader, "Diffuse");
|
2018-09-23 21:17:31 +00:00
|
|
|
useShadow_shadowMap = glGetUniformLocation(useShadowMapInstancingShader, "shadowMap");
|
|
|
|
useShadow_lightPosIn = glGetUniformLocation(useShadowMapInstancingShader, "lightPosIn");
|
|
|
|
useShadow_cameraPositionIn = glGetUniformLocation(useShadowMapInstancingShader, "cameraPositionIn");
|
|
|
|
useShadow_materialShininessIn = glGetUniformLocation(useShadowMapInstancingShader, "materialShininessIn");
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
createShadowMapInstancingShader = gltLoadShaderPair(createShadowMapInstancingVertexShader, createShadowMapInstancingFragmentShader);
|
2015-04-16 16:55:32 +00:00
|
|
|
glLinkProgram(createShadowMapInstancingShader);
|
|
|
|
glUseProgram(createShadowMapInstancingShader);
|
|
|
|
createShadow_depthMVP = glGetUniformLocation(createShadowMapInstancingShader, "depthMVP");
|
|
|
|
|
|
|
|
glUseProgram(0);
|
|
|
|
|
2018-09-30 14:10:40 +00:00
|
|
|
segmentationMaskInstancingShader = gltLoadShaderPair(segmentationMaskInstancingVertexShader, segmentationMaskInstancingFragmentShader);
|
|
|
|
glLinkProgram(segmentationMaskInstancingShader);
|
|
|
|
glUseProgram(segmentationMaskInstancingShader);
|
|
|
|
|
|
|
|
segmentationMaskModelViewMatrix = glGetUniformLocation(segmentationMaskInstancingShader, "ModelViewMatrix");
|
|
|
|
segmentationMaskProjectionMatrix = glGetUniformLocation(segmentationMaskInstancingShader, "ProjectionMatrix");
|
|
|
|
|
|
|
|
glUseProgram(0);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
instancingShader = gltLoadShaderPair(instancingVertexShader, instancingFragmentShader);
|
2015-04-16 16:55:32 +00:00
|
|
|
glLinkProgram(instancingShader);
|
|
|
|
glUseProgram(instancingShader);
|
|
|
|
ModelViewMatrix = glGetUniformLocation(instancingShader, "ModelViewMatrix");
|
|
|
|
ProjectionMatrix = glGetUniformLocation(instancingShader, "ProjectionMatrix");
|
|
|
|
uniform_texture_diffuse = glGetUniformLocation(instancingShader, "Diffuse");
|
2018-09-23 21:17:31 +00:00
|
|
|
regularLightDirIn = glGetUniformLocation(instancingShader, "lightDirIn");
|
2015-08-06 02:03:27 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
glUseProgram(0);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
instancingShaderPointSprite = gltLoadShaderPair(pointSpriteVertexShader, pointSpriteFragmentShader);
|
2015-04-16 16:55:32 +00:00
|
|
|
glUseProgram(instancingShaderPointSprite);
|
|
|
|
ModelViewMatrixPointSprite = glGetUniformLocation(instancingShaderPointSprite, "ModelViewMatrix");
|
|
|
|
ProjectionMatrixPointSprite = glGetUniformLocation(instancingShaderPointSprite, "ProjectionMatrix");
|
|
|
|
screenWidthPointSprite = glGetUniformLocation(instancingShaderPointSprite, "screenWidth");
|
|
|
|
|
|
|
|
glUseProgram(0);
|
|
|
|
|
|
|
|
//GLuint offset = 0;
|
|
|
|
|
|
|
|
glGenBuffers(1, &m_data->m_vbo);
|
2018-09-23 21:17:31 +00:00
|
|
|
checkError("glGenBuffers");
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int size = m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE + ORIENTATION_BUFFER_SIZE + COLOR_BUFFER_SIZE + SCALE_BUFFER_SIZE;
|
2015-04-16 16:55:32 +00:00
|
|
|
m_data->m_vboSize = size;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glBufferData(GL_ARRAY_BUFFER, size, 0, GL_DYNAMIC_DRAW); //GL_STATIC_DRAW);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
2015-04-16 16:55:32 +00:00
|
|
|
glBindVertexArray(0);
|
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLInstancingRenderer::init()
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthFunc(GL_LESS);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
// glClearColor(float(0.),float(0.),float(0.4),float(0));
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
B3_PROFILE("texture");
|
2018-09-23 21:17:31 +00:00
|
|
|
if (m_textureenabled)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (!m_textureinitialized)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
GLubyte* image = new GLubyte[256 * 256 * 3];
|
|
|
|
for (int y = 0; y < 256; ++y)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
// const int t=y>>5;
|
|
|
|
GLubyte* pi = image + y * 256 * 3;
|
|
|
|
for (int x = 0; x < 256; ++x)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (x < 2 || y < 2 || x > 253 || y > 253)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
pi[0] = 255; //0;
|
|
|
|
pi[1] = 255; //0;
|
|
|
|
pi[2] = 255; //0;
|
|
|
|
}
|
|
|
|
else
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
pi[0] = 255;
|
|
|
|
pi[1] = 255;
|
|
|
|
pi[2] = 255;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
const int s=x>>5;
|
|
|
|
const GLubyte b=180;
|
|
|
|
GLubyte c=b+((s+t&1)&1)*(255-b);
|
|
|
|
pi[0]=c;
|
|
|
|
pi[1]=c;
|
|
|
|
pi[2]=c;
|
|
|
|
*/
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
pi += 3;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glGenTextures(1, (GLuint*)&m_data->m_defaultTexturehandle);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, m_data->m_defaultTexturehandle);
|
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
|
2015-04-16 16:55:32 +00:00
|
|
|
glGenerateMipmap(GL_TEXTURE_2D);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
delete[] image;
|
2018-09-23 21:17:31 +00:00
|
|
|
m_textureinitialized = true;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, m_data->m_defaultTexturehandle);
|
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
|
|
|
}
|
|
|
|
else
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//glEnable(GL_COLOR_MATERIAL);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
// glEnable(GL_CULL_FACE);
|
|
|
|
// glCullFace(GL_BACK);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void GLInstancingRenderer::resize(int width, int height)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2015-04-16 22:16:13 +00:00
|
|
|
m_screenWidth = width;
|
|
|
|
m_screenHeight = height;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2015-04-16 22:16:13 +00:00
|
|
|
const CommonCameraInterface* GLInstancingRenderer::getActiveCamera() const
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2016-07-13 01:16:13 +00:00
|
|
|
return m_data->m_activeCamera;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2015-04-16 22:16:13 +00:00
|
|
|
CommonCameraInterface* GLInstancingRenderer::getActiveCamera()
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2016-07-13 01:16:13 +00:00
|
|
|
return m_data->m_activeCamera;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2015-04-16 22:16:13 +00:00
|
|
|
void GLInstancingRenderer::setActiveCamera(CommonCameraInterface* cam)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2016-07-13 01:16:13 +00:00
|
|
|
m_data->m_activeCamera = cam;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2017-06-01 03:32:45 +00:00
|
|
|
void GLInstancingRenderer::setLightSpecularIntensity(const float lightSpecularIntensity[3])
|
|
|
|
{
|
|
|
|
m_data->m_lightSpecularIntensity[0] = lightSpecularIntensity[0];
|
|
|
|
m_data->m_lightSpecularIntensity[1] = lightSpecularIntensity[1];
|
|
|
|
m_data->m_lightSpecularIntensity[2] = lightSpecularIntensity[2];
|
|
|
|
}
|
|
|
|
|
2017-04-23 14:35:13 +00:00
|
|
|
void GLInstancingRenderer::setLightPosition(const float lightPos[3])
|
|
|
|
{
|
|
|
|
m_data->m_lightPos[0] = lightPos[0];
|
|
|
|
m_data->m_lightPos[1] = lightPos[1];
|
|
|
|
m_data->m_lightPos[2] = lightPos[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLInstancingRenderer::setLightPosition(const double lightPos[3])
|
|
|
|
{
|
|
|
|
m_data->m_lightPos[0] = lightPos[0];
|
|
|
|
m_data->m_lightPos[1] = lightPos[1];
|
|
|
|
m_data->m_lightPos[2] = lightPos[2];
|
|
|
|
}
|
|
|
|
|
2018-03-19 01:45:54 +00:00
|
|
|
void GLInstancingRenderer::setProjectiveTextureMatrices(const float viewMatrix[16], const float projectionMatrix[16])
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
m_data->m_projectiveTextureViewMatrix[i] = viewMatrix[i];
|
|
|
|
m_data->m_projectiveTextureProjectionMatrix[i] = projectionMatrix[i];
|
|
|
|
}
|
|
|
|
}
|
2015-04-16 22:16:13 +00:00
|
|
|
|
2018-03-21 04:28:47 +00:00
|
|
|
void GLInstancingRenderer::setProjectiveTexture(bool useProjectiveTexture)
|
|
|
|
{
|
|
|
|
m_data->m_useProjectiveTexture = useProjectiveTexture;
|
|
|
|
}
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
void GLInstancingRenderer::updateCamera(int upAxis)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
m_upAxis = upAxis;
|
|
|
|
|
2016-07-13 01:16:13 +00:00
|
|
|
m_data->m_activeCamera->setCameraUpAxis(upAxis);
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_activeCamera->setAspectRatio((float)m_screenWidth / (float)m_screenHeight);
|
2016-07-13 01:16:13 +00:00
|
|
|
m_data->m_defaultCamera1.update();
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_activeCamera->getCameraProjectionMatrix(m_data->m_projectionMatrix);
|
|
|
|
m_data->m_activeCamera->getCameraViewMatrix(m_data->m_viewMatrix);
|
2017-06-01 03:32:45 +00:00
|
|
|
b3Scalar viewMat[16];
|
|
|
|
b3Scalar viewMatInverse[16];
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < 16; i++)
|
2017-06-01 03:32:45 +00:00
|
|
|
{
|
|
|
|
viewMat[i] = m_data->m_viewMatrix[i];
|
|
|
|
}
|
|
|
|
b3Transform tr;
|
|
|
|
tr.setFromOpenGLMatrix(viewMat);
|
|
|
|
tr = tr.inverse();
|
|
|
|
tr.getOpenGLMatrix(viewMatInverse);
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < 16; i++)
|
2017-06-01 03:32:45 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_viewMatrixInverse[i] = viewMatInverse[i];
|
2017-06-01 03:32:45 +00:00
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void writeTextureToPng(int textureWidth, int textureHeight, const char* fileName, int numComponents)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
|
|
|
glPixelStorei(GL_PACK_ALIGNMENT, 4);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
glReadBuffer(GL_NONE);
|
2018-09-23 21:17:31 +00:00
|
|
|
float* orgPixels = (float*)malloc(textureWidth * textureHeight * numComponents * 4);
|
|
|
|
char* pixels = (char*)malloc(textureWidth * textureHeight * numComponents * 4);
|
|
|
|
glReadPixels(0, 0, textureWidth, textureHeight, GL_DEPTH_COMPONENT, GL_FLOAT, orgPixels);
|
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
|
|
|
for (int j = 0; j < textureHeight; j++)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < textureWidth; i++)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
float val = orgPixels[(j * textureWidth + i)];
|
|
|
|
if (val != 1.f)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
//printf("val[%d,%d]=%f\n", i,j,val);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
pixels[(j * textureWidth + i) * numComponents] = char(orgPixels[(j * textureWidth + i)] * 255.f);
|
|
|
|
pixels[(j * textureWidth + i) * numComponents + 1] = 0; //255.f;
|
|
|
|
pixels[(j * textureWidth + i) * numComponents + 2] = 0; //255.f;
|
|
|
|
pixels[(j * textureWidth + i) * numComponents + 3] = 127;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
//pixels[(j*textureWidth+i)*+1]=val;
|
|
|
|
//pixels[(j*textureWidth+i)*numComponents+2]=val;
|
|
|
|
//pixels[(j*textureWidth+i)*numComponents+3]=255;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pixels[(j*textureWidth+j)*numComponents]=255;
|
|
|
|
pixels[(j*textureWidth+j)*numComponents+1]=0;
|
|
|
|
pixels[(j*textureWidth+j)*numComponents+2]=0;
|
|
|
|
pixels[(j*textureWidth+j)*numComponents+3]=255;
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
//swap the pixels
|
|
|
|
unsigned char tmp;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int j = 0; j < textureHeight / 2; j++)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < textureWidth; i++)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int c = 0; c < numComponents; c++)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
tmp = pixels[(j * textureWidth + i) * numComponents + c];
|
|
|
|
pixels[(j * textureWidth + i) * numComponents + c] =
|
|
|
|
pixels[((textureHeight - j - 1) * textureWidth + i) * numComponents + c];
|
|
|
|
pixels[((textureHeight - j - 1) * textureWidth + i) * numComponents + c] = tmp;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
stbi_write_png(fileName, textureWidth, textureHeight, numComponents, pixels, textureWidth * numComponents);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
free(pixels);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLInstancingRenderer::renderScene()
|
|
|
|
{
|
|
|
|
//avoid some Intel driver on a Macbook Pro to lock-up
|
|
|
|
//todo: figure out what is going on on that machine
|
|
|
|
|
2016-07-18 06:50:11 +00:00
|
|
|
//glFlush();
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-30 14:10:40 +00:00
|
|
|
if (m_data->m_useProjectiveTexture)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-30 14:10:40 +00:00
|
|
|
renderSceneInternal(B3_USE_PROJECTIVE_TEXTURE_RENDERMODE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (useShadowMap)
|
2018-04-11 08:03:36 +00:00
|
|
|
{
|
2018-09-30 14:10:40 +00:00
|
|
|
renderSceneInternal(B3_CREATE_SHADOWMAP_RENDERMODE);
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2018-09-30 14:10:40 +00:00
|
|
|
if (m_planeReflectionShapeIndex >= 0)
|
|
|
|
{
|
|
|
|
/* Don't update color or depth. */
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
2018-04-11 08:03:36 +00:00
|
|
|
|
2018-09-30 14:10:40 +00:00
|
|
|
/* Draw 1 into the stencil buffer. */
|
|
|
|
glEnable(GL_STENCIL_TEST);
|
|
|
|
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
|
|
|
|
glStencilFunc(GL_ALWAYS, 1, 0xffffffff);
|
2018-04-11 08:03:36 +00:00
|
|
|
|
2018-09-30 14:10:40 +00:00
|
|
|
/* Now render floor; floor pixels just get their stencil set to 1. */
|
|
|
|
renderSceneInternal(B3_USE_SHADOWMAP_RENDERMODE_REFLECTION_PLANE);
|
2018-04-11 08:03:36 +00:00
|
|
|
|
2018-09-30 14:10:40 +00:00
|
|
|
/* Re-enable update of color and depth. */
|
|
|
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2018-09-30 14:10:40 +00:00
|
|
|
/* Now, only render where stencil is set to 1. */
|
|
|
|
glStencilFunc(GL_EQUAL, 1, 0xffffffff); /* draw if ==1 */
|
|
|
|
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2018-09-30 14:10:40 +00:00
|
|
|
//draw the reflection objects
|
|
|
|
renderSceneInternal(B3_USE_SHADOWMAP_RENDERMODE_REFLECTION);
|
2018-04-11 08:03:36 +00:00
|
|
|
|
2018-09-30 14:10:40 +00:00
|
|
|
glDisable(GL_STENCIL_TEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderSceneInternal(B3_USE_SHADOWMAP_RENDERMODE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
renderSceneInternal();
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
struct PointerCaster
|
|
|
|
{
|
|
|
|
union {
|
|
|
|
int m_baseIndex;
|
|
|
|
GLvoid* m_pointer;
|
|
|
|
};
|
|
|
|
|
|
|
|
PointerCaster()
|
2018-09-23 21:17:31 +00:00
|
|
|
: m_pointer(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
|
|
|
};
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static void b3CreateFrustum(
|
|
|
|
float left,
|
|
|
|
float right,
|
|
|
|
float bottom,
|
|
|
|
float top,
|
|
|
|
float nearVal,
|
|
|
|
float farVal,
|
|
|
|
float frustum[16])
|
|
|
|
{
|
|
|
|
|
|
|
|
frustum[0*4+0] = (float(2) * nearVal) / (right - left);
|
|
|
|
frustum[0*4+1] = float(0);
|
|
|
|
frustum[0*4+2] = float(0);
|
|
|
|
frustum[0*4+3] = float(0);
|
|
|
|
|
|
|
|
frustum[1*4+0] = float(0);
|
|
|
|
frustum[1*4+1] = (float(2) * nearVal) / (top - bottom);
|
|
|
|
frustum[1*4+2] = float(0);
|
|
|
|
frustum[1*4+3] = float(0);
|
|
|
|
|
|
|
|
frustum[2*4+0] = (right + left) / (right - left);
|
|
|
|
frustum[2*4+1] = (top + bottom) / (top - bottom);
|
|
|
|
frustum[2*4+2] = -(farVal + nearVal) / (farVal - nearVal);
|
|
|
|
frustum[2*4+3] = float(-1);
|
|
|
|
|
|
|
|
frustum[3*4+0] = float(0);
|
|
|
|
frustum[3*4+1] = float(0);
|
|
|
|
frustum[3*4+2] = -(float(2) * farVal * nearVal) / (farVal - nearVal);
|
|
|
|
frustum[3*4+3] = float(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void b3Matrix4x4Mul(GLfloat aIn[4][4], GLfloat bIn[4][4], GLfloat result[4][4])
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int j = 0; j < 4; j++)
|
|
|
|
for (int i = 0; i < 4; i++)
|
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
|
|
|
result[j][i] = aIn[0][i] * bIn[j][0] + aIn[1][i] * bIn[j][1] + aIn[2][i] * bIn[j][2] + aIn[3][i] * bIn[j][3];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void b3Matrix4x4Mul16(GLfloat aIn[16], GLfloat bIn[16], GLfloat result[16])
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int j = 0; j < 4; j++)
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
result[j * 4 + i] = aIn[0 * 4 + i] * bIn[j * 4 + 0] + aIn[1 * 4 + i] * bIn[j * 4 + 1] + aIn[2 * 4 + i] * bIn[j * 4 + 2] + aIn[3 * 4 + i] * bIn[j * 4 + 3];
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void b3CreateDiagonalMatrix(GLfloat value, GLfloat result[4][4])
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < 4; i++)
|
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
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int j = 0; j < 4; j++)
|
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
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (i == j)
|
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
|
|
|
{
|
|
|
|
result[i][j] = value;
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
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
|
|
|
{
|
|
|
|
result[i][j] = 0.f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void b3CreateOrtho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar, GLfloat result[4][4])
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3CreateDiagonalMatrix(1.f, result);
|
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
|
|
|
|
|
|
|
result[0][0] = 2.f / (right - left);
|
|
|
|
result[1][1] = 2.f / (top - bottom);
|
2018-09-23 21:17:31 +00:00
|
|
|
result[2][2] = -2.f / (zFar - zNear);
|
|
|
|
result[3][0] = -(right + left) / (right - left);
|
|
|
|
result[3][1] = -(top + bottom) / (top - bottom);
|
|
|
|
result[3][2] = -(zFar + zNear) / (zFar - zNear);
|
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
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
static void b3CreateLookAt(const b3Vector3& eye, const b3Vector3& center, const b3Vector3& up, GLfloat result[16])
|
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
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 f = (center - eye).normalized();
|
|
|
|
b3Vector3 u = up.normalized();
|
|
|
|
b3Vector3 s = (f.cross(u)).normalized();
|
|
|
|
u = s.cross(f);
|
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
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
result[0 * 4 + 0] = s.x;
|
|
|
|
result[1 * 4 + 0] = s.y;
|
|
|
|
result[2 * 4 + 0] = s.z;
|
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
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
result[0 * 4 + 1] = u.x;
|
|
|
|
result[1 * 4 + 1] = u.y;
|
|
|
|
result[2 * 4 + 1] = u.z;
|
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
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
result[0 * 4 + 2] = -f.x;
|
|
|
|
result[1 * 4 + 2] = -f.y;
|
|
|
|
result[2 * 4 + 2] = -f.z;
|
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
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
result[0 * 4 + 3] = 0.f;
|
|
|
|
result[1 * 4 + 3] = 0.f;
|
|
|
|
result[2 * 4 + 3] = 0.f;
|
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
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
result[3 * 4 + 0] = -s.dot(eye);
|
|
|
|
result[3 * 4 + 1] = -u.dot(eye);
|
|
|
|
result[3 * 4 + 2] = f.dot(eye);
|
|
|
|
result[3 * 4 + 3] = 1.f;
|
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
|
|
|
}
|
|
|
|
|
2017-05-24 20:05:16 +00:00
|
|
|
void GLInstancingRenderer::drawTexturedTriangleMesh(float worldPosition[3], float worldOrientation[4], const float* vertices, int numvertices, const unsigned int* indices, int numIndices, float colorRGBA[4], int textureIndex, int vertexLayout)
|
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
|
|
|
{
|
2017-05-24 20:05:16 +00:00
|
|
|
int sz = sizeof(GfxVertexFormat0);
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
activateTexture(textureIndex);
|
|
|
|
checkError("activateTexture");
|
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
glUseProgram(triangleShaderProgram);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Quaternion orn(worldOrientation[0], worldOrientation[1], worldOrientation[2], worldOrientation[3]);
|
|
|
|
b3Vector3 pos = b3MakeVector3(worldPosition[0], worldPosition[1], worldPosition[2]);
|
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
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Transform worldTrans(orn, pos);
|
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
|
|
|
b3Scalar worldMatUnk[16];
|
|
|
|
worldTrans.getOpenGLMatrix(worldMatUnk);
|
|
|
|
float modelMat[16];
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < 16; i++)
|
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
|
|
|
{
|
|
|
|
modelMat[i] = worldMatUnk[i];
|
|
|
|
}
|
2017-05-24 20:05:16 +00:00
|
|
|
float viewProjection[16];
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Matrix4x4Mul16(m_data->m_projectionMatrix, m_data->m_viewMatrix, viewProjection);
|
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
|
|
|
float MVP[16];
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Matrix4x4Mul16(viewProjection, modelMat, MVP);
|
|
|
|
glUniformMatrix4fv(triangle_mvp_location, 1, GL_FALSE, (const GLfloat*)MVP);
|
2017-05-24 20:05:16 +00:00
|
|
|
checkError("glUniformMatrix4fv");
|
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
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glUniform3f(triangle_vcol_location, colorRGBA[0], colorRGBA[1], colorRGBA[2]);
|
2017-05-24 20:05:16 +00:00
|
|
|
checkError("glUniform3f");
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2017-05-24 20:05:16 +00:00
|
|
|
glBindVertexArray(triangleVertexArrayObject);
|
|
|
|
checkError("glBindVertexArray");
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, triangleVertexBufferObject);
|
|
|
|
checkError("glBindBuffer");
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glBufferData(GL_ARRAY_BUFFER, sizeof(GfxVertexFormat0) * numvertices, 0, GL_DYNAMIC_DRAW);
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GfxVertexFormat0) * numvertices, vertices);
|
2017-05-24 20:05:16 +00:00
|
|
|
|
|
|
|
PointerCaster posCast;
|
|
|
|
posCast.m_baseIndex = 0;
|
|
|
|
PointerCaster uvCast;
|
2018-09-23 21:17:31 +00:00
|
|
|
uvCast.m_baseIndex = 8 * sizeof(float);
|
2017-05-24 20:05:16 +00:00
|
|
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(GfxVertexFormat0), posCast.m_pointer);
|
2018-02-21 03:44:02 +00:00
|
|
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GfxVertexFormat0), uvCast.m_pointer);
|
2017-05-24 20:05:16 +00:00
|
|
|
checkError("glVertexAttribPointer");
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
glEnableVertexAttribArray(1);
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glVertexAttribDivisor(0, 0);
|
|
|
|
glVertexAttribDivisor(1, 0);
|
2017-05-24 20:05:16 +00:00
|
|
|
checkError("glVertexAttribDivisor");
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2017-05-24 20:05:16 +00:00
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, triangleIndexVbo);
|
2018-09-23 21:17:31 +00:00
|
|
|
int indexBufferSizeInBytes = numIndices * sizeof(int);
|
2017-05-24 20:05:16 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices * sizeof(int), NULL, GL_DYNAMIC_DRAW);
|
|
|
|
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, numIndices * sizeof(int), indices);
|
2017-05-24 20:05:16 +00:00
|
|
|
|
|
|
|
glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, 0);
|
|
|
|
|
|
|
|
//glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT,indices);
|
|
|
|
checkError("glDrawElements");
|
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
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2018-09-23 21:17:31 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 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
|
|
|
glUseProgram(0);
|
2017-05-24 20:05:16 +00:00
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
2018-09-23 21:17:31 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
2017-05-24 20:05:16 +00:00
|
|
|
glBindVertexArray(0);
|
|
|
|
checkError("glBindVertexArray");
|
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
|
|
|
void GLInstancingRenderer::drawPoint(const double* position, const double color[4], double pointDrawSize)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
float pos[4] = {(float)position[0], (float)position[1], (float)position[2], 0};
|
|
|
|
float clr[4] = {(float)color[0], (float)color[1], (float)color[2], (float)color[3]};
|
|
|
|
drawPoints(pos, clr, 1, 3 * sizeof(float), float(pointDrawSize));
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLInstancingRenderer::drawPoint(const float* positions, const float color[4], float pointDrawSize)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
drawPoints(positions, color, 1, 3 * sizeof(float), pointDrawSize);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
void GLInstancingRenderer::drawPoints(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, float pointDrawSize)
|
|
|
|
{
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2018-09-23 21:17:31 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
glUseProgram(linesShader);
|
|
|
|
glUniformMatrix4fv(lines_ProjectionMatrix, 1, false, &m_data->m_projectionMatrix[0]);
|
|
|
|
glUniformMatrix4fv(lines_ModelViewMatrix, 1, false, &m_data->m_viewMatrix[0]);
|
2018-09-23 21:17:31 +00:00
|
|
|
glUniform4f(lines_colour, color[0], color[1], color[2], color[3]);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
glPointSize(pointDrawSize);
|
|
|
|
glBindVertexArray(lineVertexArrayObject);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
int maxPointsInBatch = MAX_POINTS_IN_BATCH;
|
|
|
|
int remainingPoints = numPoints;
|
2018-09-23 21:17:31 +00:00
|
|
|
int offsetNumPoints = 0;
|
2015-04-16 16:55:32 +00:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int curPointsInBatch = b3Min(maxPointsInBatch, remainingPoints);
|
|
|
|
if (curPointsInBatch)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, curPointsInBatch * pointStrideInBytes, positions + offsetNumPoints * (pointStrideInBytes / sizeof(float)));
|
2015-04-16 16:55:32 +00:00
|
|
|
glEnableVertexAttribArray(0);
|
2018-09-23 21:17:31 +00:00
|
|
|
int numFloats = 3; // pointStrideInBytes / sizeof(float);
|
2015-04-16 16:55:32 +00:00
|
|
|
glVertexAttribPointer(0, numFloats, GL_FLOAT, GL_FALSE, pointStrideInBytes, 0);
|
|
|
|
glDrawArrays(GL_POINTS, 0, curPointsInBatch);
|
|
|
|
remainingPoints -= curPointsInBatch;
|
|
|
|
offsetNumPoints += curPointsInBatch;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
2018-10-01 03:02:12 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
glBindVertexArray(0);
|
|
|
|
glPointSize(1);
|
|
|
|
glUseProgram(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLInstancingRenderer::drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float lineWidthIn)
|
|
|
|
{
|
2016-07-08 02:24:44 +00:00
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2018-09-23 21:17:31 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2016-07-08 02:24:44 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
float lineWidth = lineWidthIn;
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Clamp(lineWidth, (float)lineWidthRange[0], (float)lineWidthRange[1]);
|
2015-04-16 16:55:32 +00:00
|
|
|
glLineWidth(lineWidth);
|
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2018-09-23 21:17:31 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
glUseProgram(linesShader);
|
|
|
|
glUniformMatrix4fv(lines_ProjectionMatrix, 1, false, &m_data->m_projectionMatrix[0]);
|
|
|
|
glUniformMatrix4fv(lines_ModelViewMatrix, 1, false, &m_data->m_viewMatrix[0]);
|
2018-09-23 21:17:31 +00:00
|
|
|
glUniform4f(lines_colour, color[0], color[1], color[2], color[3]);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
// glPointSize(pointDrawSize);
|
2015-04-16 16:55:32 +00:00
|
|
|
glBindVertexArray(linesVertexArrayObject);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, linesVertexBufferObject);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
glBufferData(GL_ARRAY_BUFFER, numPoints * pointStrideInBytes, 0, GL_DYNAMIC_DRAW);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, numPoints * pointStrideInBytes, positions);
|
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, linesVertexBufferObject);
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
int numFloats = 3;
|
|
|
|
glVertexAttribPointer(0, numFloats, GL_FLOAT, GL_FALSE, pointStrideInBytes, 0);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, linesIndexVbo);
|
2018-09-23 21:17:31 +00:00
|
|
|
int indexBufferSizeInBytes = numIndices * sizeof(int);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexBufferSizeInBytes, NULL, GL_DYNAMIC_DRAW);
|
|
|
|
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, indexBufferSizeInBytes, indices);
|
|
|
|
|
|
|
|
glDrawElements(GL_LINES, numIndices, GL_UNSIGNED_INT, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
2018-09-23 21:17:31 +00:00
|
|
|
// for (int i=0;i<numIndices;i++)
|
|
|
|
// printf("indicec[i]=%d]\n",indices[i]);
|
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
glBindVertexArray(0);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
glPointSize(1);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
glUseProgram(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLInstancingRenderer::drawLine(const double fromIn[4], const double toIn[4], const double colorIn[4], double lineWidthIn)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
float from[4] = {float(fromIn[0]), float(fromIn[1]), float(fromIn[2]), float(fromIn[3])};
|
|
|
|
float to[4] = {float(toIn[0]), float(toIn[1]), float(toIn[2]), float(toIn[3])};
|
|
|
|
float color[4] = {float(colorIn[0]), float(colorIn[1]), float(colorIn[2]), float(colorIn[3])};
|
|
|
|
float lineWidth = float(lineWidthIn);
|
|
|
|
drawLine(from, to, color, lineWidth);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
void GLInstancingRenderer::drawLine(const float from[4], const float to[4], const float color[4], float lineWidth)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2018-09-23 21:17:31 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
glUseProgram(linesShader);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
glUniformMatrix4fv(lines_ProjectionMatrix, 1, false, &m_data->m_projectionMatrix[0]);
|
|
|
|
glUniformMatrix4fv(lines_ModelViewMatrix, 1, false, &m_data->m_viewMatrix[0]);
|
2018-09-23 21:17:31 +00:00
|
|
|
glUniform4f(lines_colour, color[0], color[1], color[2], color[3]);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
const float vertexPositions[] = {
|
2018-09-23 21:17:31 +00:00
|
|
|
from[0], from[1], from[2], 1,
|
|
|
|
to[0], to[1], to[2], 1};
|
2015-04-16 16:55:32 +00:00
|
|
|
int sz = sizeof(vertexPositions);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Clamp(lineWidth, (float)lineWidthRange[0], (float)lineWidthRange[1]);
|
2015-04-16 16:55:32 +00:00
|
|
|
glLineWidth(lineWidth);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
glBindVertexArray(lineVertexArrayObject);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, sz, vertexPositions);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
2015-04-16 16:55:32 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
glDrawArrays(GL_LINES, 0, 2);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
glBindVertexArray(0);
|
|
|
|
glLineWidth(1);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
glUseProgram(0);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
B3_ATTRIBUTE_ALIGNED16(struct)
|
|
|
|
SortableTransparentInstance
|
2017-06-24 20:41:33 +00:00
|
|
|
{
|
2018-02-06 07:48:39 +00:00
|
|
|
b3Scalar m_projection;
|
|
|
|
|
2017-06-24 20:41:33 +00:00
|
|
|
int m_shapeIndex;
|
|
|
|
int m_instanceId;
|
|
|
|
};
|
2015-04-16 22:16:13 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
B3_ATTRIBUTE_ALIGNED16(struct)
|
|
|
|
TransparentDistanceSortPredicate{
|
2017-06-24 20:41:33 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
inline bool operator()(const SortableTransparentInstance& a, const SortableTransparentInstance& b) const {
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2018-02-06 07:48:39 +00:00
|
|
|
return (a.m_projection > b.m_projection);
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
;
|
2015-04-16 22:16:13 +00:00
|
|
|
|
2018-01-08 20:25:56 +00:00
|
|
|
void GLInstancingRenderer::renderSceneInternal(int orgRenderMode)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int renderMode = orgRenderMode;
|
2018-01-08 20:25:56 +00:00
|
|
|
bool reflectionPass = false;
|
2018-04-11 08:03:36 +00:00
|
|
|
bool reflectionPlanePass = false;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (orgRenderMode == B3_USE_SHADOWMAP_RENDERMODE_REFLECTION_PLANE)
|
2018-04-11 08:03:36 +00:00
|
|
|
{
|
|
|
|
reflectionPlanePass = true;
|
|
|
|
renderMode = B3_USE_SHADOWMAP_RENDERMODE;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (orgRenderMode == B3_USE_SHADOWMAP_RENDERMODE_REFLECTION)
|
2018-01-08 20:25:56 +00:00
|
|
|
{
|
|
|
|
reflectionPass = true;
|
|
|
|
renderMode = B3_USE_SHADOWMAP_RENDERMODE;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2017-05-16 19:19:03 +00:00
|
|
|
if (!useShadowMap)
|
|
|
|
{
|
2018-09-30 14:10:40 +00:00
|
|
|
renderMode = orgRenderMode;
|
2017-05-16 19:19:03 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
if (orgRenderMode == B3_USE_PROJECTIVE_TEXTURE_RENDERMODE)
|
2018-02-11 21:50:45 +00:00
|
|
|
{
|
|
|
|
renderMode = B3_USE_PROJECTIVE_TEXTURE_RENDERMODE;
|
|
|
|
}
|
2017-05-16 19:19:03 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
// glEnable(GL_DEPTH_TEST);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
GLint dims[4];
|
2018-09-23 21:17:31 +00:00
|
|
|
glGetIntegerv(GL_VIEWPORT, dims);
|
2015-04-16 16:55:32 +00:00
|
|
|
//we need to get the viewport dims, because on Apple Retina the viewport dimension is different from screenWidth
|
|
|
|
//printf("dims=%d,%d,%d,%d\n",dims[0],dims[1],dims[2],dims[3]);
|
|
|
|
// Accept fragment if it closer to the camera than the former one
|
|
|
|
//glDepthFunc(GL_LESS);
|
|
|
|
|
|
|
|
// Cull triangles which normal is not towards the camera
|
2015-08-10 21:30:00 +00:00
|
|
|
glEnable(GL_CULL_FACE);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
B3_PROFILE("GLInstancingRenderer::RenderScene");
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
{
|
2015-04-16 16:55:32 +00:00
|
|
|
B3_PROFILE("init");
|
|
|
|
init();
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
float depthProjectionMatrix[4][4];
|
|
|
|
GLfloat depthModelViewMatrix[4][4];
|
|
|
|
//GLfloat depthModelViewMatrix2[4][4];
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2018-02-11 21:50:45 +00:00
|
|
|
// For projective texture mapping
|
2018-04-11 08:03:36 +00:00
|
|
|
//float textureProjectionMatrix[4][4];
|
|
|
|
//GLfloat textureModelViewMatrix[4][4];
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
// Compute the MVP matrix from the light's point of view
|
2018-09-23 21:17:31 +00:00
|
|
|
if (renderMode == B3_CREATE_SHADOWMAP_RENDERMODE)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
glCullFace(GL_FRONT);
|
|
|
|
|
|
|
|
if (!m_data->m_shadowMap)
|
|
|
|
{
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glGenTextures(1, &m_data->m_shadowTexture);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, m_data->m_shadowTexture);
|
2015-04-16 16:55:32 +00:00
|
|
|
//glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT16,m_screenWidth,m_screenHeight,0,GL_DEPTH_COMPONENT,GL_FLOAT,0);
|
|
|
|
//glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT32,m_screenWidth,m_screenHeight,0,GL_DEPTH_COMPONENT,GL_FLOAT,0);
|
2015-07-11 05:20:06 +00:00
|
|
|
|
|
|
|
#ifdef OLD_SHADOWMAP_INIT
|
2018-09-23 21:17:31 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, shadowMapWidth, shadowMapHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
|
|
|
|
#else //OLD_SHADOWMAP_INIT \
|
|
|
|
//Reduce size of shadowMap if glTexImage2D call fails as may happen in some cases \
|
|
|
|
//https://github.com/bulletphysics/bullet3/issues/40
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2015-07-11 05:20:06 +00:00
|
|
|
int size;
|
|
|
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size);
|
2018-09-23 21:17:31 +00:00
|
|
|
if (size < shadowMapWidth)
|
|
|
|
{
|
2015-07-11 05:20:06 +00:00
|
|
|
shadowMapWidth = size;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (size < shadowMapHeight)
|
|
|
|
{
|
2015-07-11 05:20:06 +00:00
|
|
|
shadowMapHeight = size;
|
|
|
|
}
|
|
|
|
GLuint err;
|
2018-09-23 21:17:31 +00:00
|
|
|
do
|
|
|
|
{
|
2018-02-21 03:44:02 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16,
|
2018-09-23 21:17:31 +00:00
|
|
|
shadowMapWidth, shadowMapHeight,
|
|
|
|
0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
|
2015-07-11 05:20:06 +00:00
|
|
|
err = glGetError();
|
2018-09-23 21:17:31 +00:00
|
|
|
if (err != GL_NO_ERROR)
|
|
|
|
{
|
2015-07-11 05:20:06 +00:00
|
|
|
shadowMapHeight >>= 1;
|
|
|
|
shadowMapWidth >>= 1;
|
|
|
|
}
|
|
|
|
} while (err != GL_NO_ERROR && shadowMapWidth > 0);
|
2018-09-23 21:17:31 +00:00
|
|
|
#endif //OLD_SHADOWMAP_INIT
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
2016-10-14 22:06:09 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
2016-10-13 06:03:36 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
float l_ClampColor[] = {1.0, 1.0, 1.0, 1.0};
|
|
|
|
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, l_ClampColor);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
2018-09-23 21:17:31 +00:00
|
|
|
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2015-04-16 16:55:32 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_shadowMap = new GLRenderToTexture();
|
|
|
|
m_data->m_shadowMap->init(shadowMapWidth, shadowMapHeight, m_data->m_shadowTexture, RENDERTEXTURE_DEPTH);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
m_data->m_shadowMap->enable();
|
2018-09-23 21:17:31 +00:00
|
|
|
glViewport(0, 0, shadowMapWidth, shadowMapHeight);
|
2015-04-16 16:55:32 +00:00
|
|
|
//glClearColor(1,1,1,1);
|
|
|
|
glClear(GL_DEPTH_BUFFER_BIT);
|
|
|
|
//glClearColor(0.3,0.3,0.3,1);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
// m_data->m_shadowMap->disable();
|
|
|
|
// return;
|
2015-04-16 16:55:32 +00:00
|
|
|
glEnable(GL_CULL_FACE);
|
2018-09-23 21:17:31 +00:00
|
|
|
glCullFace(GL_FRONT); // Cull back-facing triangles -> draw only front-facing triangles
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
|
|
|
}
|
|
|
|
else
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2016-11-04 20:15:10 +00:00
|
|
|
glEnable(GL_CULL_FACE);
|
2015-04-16 16:55:32 +00:00
|
|
|
glCullFace(GL_BACK);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3CreateOrtho(-shadowMapWorldSize, shadowMapWorldSize, -shadowMapWorldSize, shadowMapWorldSize, 1, 300, depthProjectionMatrix); //-14,14,-14,14,1,200, depthProjectionMatrix);
|
2015-04-16 16:55:32 +00:00
|
|
|
float depthViewMatrix[4][4];
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 center = b3MakeVector3(0, 0, 0);
|
2018-02-01 06:17:15 +00:00
|
|
|
m_data->m_activeCamera->getCameraTargetPosition(center);
|
2017-04-10 18:03:41 +00:00
|
|
|
//float upf[3];
|
|
|
|
//m_data->m_activeCamera->getCameraUpVector(upf);
|
2017-06-25 02:38:31 +00:00
|
|
|
b3Vector3 up, lightFwd;
|
2017-04-23 14:35:13 +00:00
|
|
|
b3Vector3 lightDir = m_data->m_lightPos.normalized();
|
2018-09-23 21:17:31 +00:00
|
|
|
b3PlaneSpace1(lightDir, up, lightFwd);
|
|
|
|
// b3Vector3 up = b3MakeVector3(upf[0],upf[1],upf[2]);
|
|
|
|
b3CreateLookAt(m_data->m_lightPos + center, center, up, &depthViewMatrix[0][0]);
|
2015-04-16 16:55:32 +00:00
|
|
|
//b3CreateLookAt(lightPos,m_data->m_cameraTargetPosition,b3Vector3(0,1,0),(float*)depthModelViewMatrix2);
|
|
|
|
|
|
|
|
GLfloat depthModelMatrix[4][4];
|
2018-09-23 21:17:31 +00:00
|
|
|
b3CreateDiagonalMatrix(1.f, depthModelMatrix);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
b3Matrix4x4Mul(depthViewMatrix, depthModelMatrix, depthModelViewMatrix);
|
|
|
|
|
|
|
|
GLfloat depthMVP[4][4];
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Matrix4x4Mul(depthProjectionMatrix, depthModelViewMatrix, depthMVP);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
GLfloat biasMatrix[4][4] = {
|
|
|
|
{0.5, 0.0, 0.0, 0.0},
|
|
|
|
{0.0, 0.5, 0.0, 0.0},
|
|
|
|
{0.0, 0.0, 0.5, 0.0},
|
|
|
|
{0.5, 0.5, 0.5, 1.0}};
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
GLfloat depthBiasMVP[4][4];
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Matrix4x4Mul(biasMatrix, depthMVP, depthBiasMVP);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-02-21 02:32:09 +00:00
|
|
|
// TODO: Expose the projective texture matrix setup. Temporarily set it to be the same as camera view projection matrix.
|
|
|
|
GLfloat textureMVP[16];
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Matrix4x4Mul16(m_data->m_projectiveTextureProjectionMatrix, m_data->m_projectiveTextureViewMatrix, textureMVP);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
//float m_frustumZNear=0.1;
|
2018-09-23 21:17:31 +00:00
|
|
|
//float m_frustumZFar=100.f;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
//b3CreateFrustum(-m_frustumZNear, m_frustumZNear, -m_frustumZNear, m_frustumZNear, m_frustumZNear, m_frustumZFar,(float*)depthProjectionMatrix);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
//b3CreateLookAt(lightPos,m_data->m_cameraTargetPosition,b3Vector3(0,0,1),(float*)depthModelViewMatrix);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
B3_PROFILE("updateCamera");
|
2018-09-23 21:17:31 +00:00
|
|
|
// updateCamera();
|
2016-07-13 01:16:13 +00:00
|
|
|
m_data->m_activeCamera->getCameraProjectionMatrix(m_data->m_projectionMatrix);
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_activeCamera->getCameraViewMatrix(m_data->m_viewMatrix);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
// glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
{
|
|
|
|
B3_PROFILE("glFlush2");
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
|
2016-07-18 06:50:11 +00:00
|
|
|
//glFlush();
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
int totalNumInstances = 0;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < m_graphicsInstances.size(); i++)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
totalNumInstances += m_graphicsInstances[i]->m_numGraphicsInstances;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
b3AlignedObjectArray<SortableTransparentInstance> transparentInstances;
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2017-06-25 02:38:31 +00:00
|
|
|
int curOffset = 0;
|
|
|
|
//GLuint lastBindTexture = 0;
|
|
|
|
|
|
|
|
transparentInstances.reserve(totalNumInstances);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-02-06 07:48:39 +00:00
|
|
|
float fwd[3];
|
|
|
|
m_data->m_activeCamera->getCameraForwardVector(fwd);
|
|
|
|
b3Vector3 camForwardVec;
|
2018-09-23 21:17:31 +00:00
|
|
|
camForwardVec.setValue(fwd[0], fwd[1], fwd[2]);
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int obj = 0; obj < m_graphicsInstances.size(); obj++)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2017-06-25 02:38:31 +00:00
|
|
|
b3GraphicsInstance* gfxObj = m_graphicsInstances[obj];
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
if (gfxObj->m_numGraphicsInstances)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2017-06-25 02:38:31 +00:00
|
|
|
SortableTransparentInstance inst;
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
inst.m_shapeIndex = obj;
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if ((gfxObj->m_flags & eGfxTransparency) == 0)
|
2017-06-25 02:38:31 +00:00
|
|
|
{
|
|
|
|
inst.m_instanceId = curOffset;
|
2018-02-06 07:48:39 +00:00
|
|
|
b3Vector3 centerPosition;
|
2018-09-23 21:17:31 +00:00
|
|
|
centerPosition.setValue(m_data->m_instance_positions_ptr[inst.m_instanceId * 4 + 0],
|
|
|
|
m_data->m_instance_positions_ptr[inst.m_instanceId * 4 + 1],
|
|
|
|
m_data->m_instance_positions_ptr[inst.m_instanceId * 4 + 2]);
|
|
|
|
centerPosition *= -1; //reverse sort opaque instances
|
2018-02-06 07:48:39 +00:00
|
|
|
inst.m_projection = centerPosition.dot(camForwardVec);
|
2017-06-25 02:38:31 +00:00
|
|
|
transparentInstances.push_back(inst);
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2017-06-25 02:38:31 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < gfxObj->m_numGraphicsInstances; i++)
|
2017-06-25 02:38:31 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
inst.m_instanceId = curOffset + i;
|
2018-02-06 07:48:39 +00:00
|
|
|
b3Vector3 centerPosition;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
centerPosition.setValue(m_data->m_instance_positions_ptr[inst.m_instanceId * 4 + 0],
|
|
|
|
m_data->m_instance_positions_ptr[inst.m_instanceId * 4 + 1],
|
|
|
|
m_data->m_instance_positions_ptr[inst.m_instanceId * 4 + 2]);
|
2018-02-06 07:48:39 +00:00
|
|
|
inst.m_projection = centerPosition.dot(camForwardVec);
|
2017-06-25 02:38:31 +00:00
|
|
|
transparentInstances.push_back(inst);
|
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
curOffset += gfxObj->m_numGraphicsInstances;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
2017-06-25 02:38:31 +00:00
|
|
|
}
|
|
|
|
TransparentDistanceSortPredicate sorter;
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
transparentInstances.quickSort(sorter);
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
//two passes: first for opaque instances, second for transparent ones.
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int pass = 0; pass < 2; pass++)
|
2017-06-25 02:38:31 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < transparentInstances.size(); i++)
|
2017-06-25 02:38:31 +00:00
|
|
|
{
|
|
|
|
int shapeIndex = transparentInstances[i].m_shapeIndex;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-04-11 08:03:36 +00:00
|
|
|
//during a reflectionPlanePass, only draw the plane, nothing else
|
2018-04-11 15:50:29 +00:00
|
|
|
if (reflectionPlanePass)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (shapeIndex != m_planeReflectionShapeIndex)
|
2018-04-11 15:50:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-04-11 08:03:36 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
b3GraphicsInstance* gfxObj = m_graphicsInstances[shapeIndex];
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
//only draw stuff (opaque/transparent) if it is the right pass
|
2018-09-23 21:17:31 +00:00
|
|
|
int drawThisPass = (pass == 0) == ((gfxObj->m_flags & eGfxTransparency) == 0);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
//transparent objects don't cast shadows (to simplify things)
|
2018-09-23 21:17:31 +00:00
|
|
|
if (gfxObj->m_flags & eGfxTransparency)
|
2017-06-25 02:38:31 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (renderMode == B3_CREATE_SHADOWMAP_RENDERMODE)
|
2017-06-25 02:38:31 +00:00
|
|
|
drawThisPass = 0;
|
|
|
|
}
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
if (drawThisPass && gfxObj->m_numGraphicsInstances)
|
|
|
|
{
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
GLuint curBindTexture = 0;
|
2017-07-01 16:15:00 +00:00
|
|
|
if (gfxObj->m_flags & eGfxHasTexture)
|
2017-07-01 02:11:43 +00:00
|
|
|
{
|
|
|
|
curBindTexture = m_data->m_textureHandles[gfxObj->m_textureIndex].m_glTexture;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
|
2017-07-01 02:11:43 +00:00
|
|
|
|
|
|
|
if (m_data->m_textureHandles[gfxObj->m_textureIndex].m_enableFiltering)
|
|
|
|
{
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2017-07-01 02:11:43 +00:00
|
|
|
{
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
}
|
|
|
|
}
|
2017-06-25 02:38:31 +00:00
|
|
|
else
|
2017-07-01 02:11:43 +00:00
|
|
|
{
|
2017-06-25 02:38:31 +00:00
|
|
|
curBindTexture = m_data->m_defaultTexturehandle;
|
2017-07-01 02:11:43 +00:00
|
|
|
}
|
2017-06-25 02:38:31 +00:00
|
|
|
|
2018-04-11 08:03:36 +00:00
|
|
|
//disable lazy evaluation, it just leads to bugs
|
2017-06-25 02:38:31 +00:00
|
|
|
//if (lastBindTexture != curBindTexture)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, curBindTexture);
|
2017-06-25 02:38:31 +00:00
|
|
|
}
|
|
|
|
//lastBindTexture = curBindTexture;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
|
|
|
// int myOffset = gfxObj->m_instanceOffset*4*sizeof(float);
|
|
|
|
|
|
|
|
int POSITION_BUFFER_SIZE = (totalNumInstances * sizeof(float) * 4);
|
|
|
|
int ORIENTATION_BUFFER_SIZE = (totalNumInstances * sizeof(float) * 4);
|
|
|
|
int COLOR_BUFFER_SIZE = (totalNumInstances * sizeof(float) * 4);
|
|
|
|
// int SCALE_BUFFER_SIZE = (totalNumInstances*sizeof(float)*3);
|
|
|
|
|
|
|
|
glBindVertexArray(gfxObj->m_cube_vao);
|
|
|
|
|
|
|
|
int vertexStride = 9 * sizeof(float);
|
|
|
|
PointerCaster vertex;
|
|
|
|
vertex.m_baseIndex = gfxObj->m_vertexArrayOffset * vertexStride;
|
|
|
|
|
2018-09-30 14:10:40 +00:00
|
|
|
//vertex position
|
2018-09-23 21:17:31 +00:00
|
|
|
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 9 * sizeof(float), vertex.m_pointer);
|
2018-09-30 14:10:40 +00:00
|
|
|
//instance_position
|
2018-09-23 21:17:31 +00:00
|
|
|
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(transparentInstances[i].m_instanceId * 4 * sizeof(float) + m_data->m_maxShapeCapacityInBytes));
|
2018-09-30 14:10:40 +00:00
|
|
|
//instance_quaternion
|
2018-09-23 21:17:31 +00:00
|
|
|
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(transparentInstances[i].m_instanceId * 4 * sizeof(float) + m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE));
|
|
|
|
|
|
|
|
PointerCaster uv;
|
|
|
|
uv.m_baseIndex = 7 * sizeof(float) + vertex.m_baseIndex;
|
|
|
|
|
|
|
|
PointerCaster normal;
|
|
|
|
normal.m_baseIndex = 4 * sizeof(float) + vertex.m_baseIndex;
|
|
|
|
|
|
|
|
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 9 * sizeof(float), uv.m_pointer);
|
|
|
|
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), normal.m_pointer);
|
2018-09-30 14:10:40 +00:00
|
|
|
//instance_color
|
2018-09-23 21:17:31 +00:00
|
|
|
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(transparentInstances[i].m_instanceId * 4 * sizeof(float) + m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE + ORIENTATION_BUFFER_SIZE));
|
2018-09-30 14:10:40 +00:00
|
|
|
//instance_scale
|
|
|
|
glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(transparentInstances[i].m_instanceId * 4 * sizeof(float) + m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE + ORIENTATION_BUFFER_SIZE + COLOR_BUFFER_SIZE));
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
glEnableVertexAttribArray(1);
|
|
|
|
glEnableVertexAttribArray(2);
|
|
|
|
glEnableVertexAttribArray(3);
|
|
|
|
glEnableVertexAttribArray(4);
|
|
|
|
glEnableVertexAttribArray(5);
|
|
|
|
glEnableVertexAttribArray(6);
|
|
|
|
glVertexAttribDivisor(0, 0);
|
|
|
|
glVertexAttribDivisor(1, 1);
|
|
|
|
glVertexAttribDivisor(2, 1);
|
|
|
|
glVertexAttribDivisor(3, 0);
|
|
|
|
glVertexAttribDivisor(4, 0);
|
|
|
|
glVertexAttribDivisor(5, 1);
|
|
|
|
glVertexAttribDivisor(6, 1);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
int indexCount = gfxObj->m_numIndices;
|
|
|
|
GLvoid* indexOffset = 0;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gfxObj->m_index_vbo);
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2017-06-25 02:38:31 +00:00
|
|
|
B3_PROFILE("glDrawElementsInstanced");
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (gfxObj->m_primitiveType == B3_GL_POINTS)
|
2017-06-25 02:38:31 +00:00
|
|
|
{
|
|
|
|
glUseProgram(instancingShaderPointSprite);
|
|
|
|
glUniformMatrix4fv(ProjectionMatrixPointSprite, 1, false, &m_data->m_projectionMatrix[0]);
|
|
|
|
glUniformMatrix4fv(ModelViewMatrixPointSprite, 1, false, &m_data->m_viewMatrix[0]);
|
2018-09-23 21:17:31 +00:00
|
|
|
glUniform1f(screenWidthPointSprite, float(m_screenWidth));
|
2017-06-25 02:38:31 +00:00
|
|
|
|
|
|
|
//glUniform1i(uniform_texture_diffusePointSprite, 0);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
|
|
|
glPointSize(20);
|
2017-06-25 02:38:31 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
#ifndef __APPLE__
|
2017-06-25 02:38:31 +00:00
|
|
|
glEnable(GL_POINT_SPRITE_ARB);
|
2018-09-23 21:17:31 +00:00
|
|
|
// glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
|
|
|
|
#endif
|
2017-06-25 02:38:31 +00:00
|
|
|
|
|
|
|
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
|
|
|
glDrawElementsInstanced(GL_POINTS, indexCount, GL_UNSIGNED_INT, indexOffset, gfxObj->m_numGraphicsInstances);
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2017-06-25 02:38:31 +00:00
|
|
|
{
|
|
|
|
switch (renderMode)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-30 14:10:40 +00:00
|
|
|
case B3_SEGMENTATION_MASK_RENDERMODE:
|
|
|
|
{
|
|
|
|
glUseProgram(segmentationMaskInstancingShader);
|
|
|
|
glUniformMatrix4fv(segmentationMaskProjectionMatrix, 1, false, &m_data->m_projectionMatrix[0]);
|
|
|
|
glUniformMatrix4fv(segmentationMaskModelViewMatrix, 1, false, &m_data->m_viewMatrix[0]);
|
|
|
|
glDrawElementsInstanced(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, indexOffset, gfxObj->m_numGraphicsInstances);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case B3_DEFAULT_RENDERMODE:
|
2017-06-25 02:38:31 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (gfxObj->m_flags & eGfxTransparency)
|
2017-06-25 02:38:31 +00:00
|
|
|
{
|
|
|
|
glDepthMask(false);
|
2018-09-23 21:17:31 +00:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2017-06-25 02:38:31 +00:00
|
|
|
}
|
2017-06-01 03:32:45 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
glUseProgram(instancingShader);
|
|
|
|
glUniformMatrix4fv(ProjectionMatrix, 1, false, &m_data->m_projectionMatrix[0]);
|
|
|
|
glUniformMatrix4fv(ModelViewMatrix, 1, false, &m_data->m_viewMatrix[0]);
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
b3Vector3 gLightDir = m_data->m_lightPos;
|
|
|
|
gLightDir.normalize();
|
2018-09-23 21:17:31 +00:00
|
|
|
glUniform3f(regularLightDirIn, gLightDir[0], gLightDir[1], gLightDir[2]);
|
2017-06-01 03:32:45 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
glUniform1i(uniform_texture_diffuse, 0);
|
2017-06-24 20:41:33 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (gfxObj->m_flags & eGfxTransparency)
|
2017-06-24 20:41:33 +00:00
|
|
|
{
|
2017-06-25 02:38:31 +00:00
|
|
|
int instanceId = transparentInstances[i].m_instanceId;
|
2018-09-23 21:17:31 +00:00
|
|
|
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)((instanceId)*4 * sizeof(float) + m_data->m_maxShapeCapacityInBytes));
|
|
|
|
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)((instanceId)*4 * sizeof(float) + m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE));
|
|
|
|
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)((instanceId)*4 * sizeof(float) + m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE + ORIENTATION_BUFFER_SIZE));
|
2018-10-01 03:02:12 +00:00
|
|
|
glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)((instanceId)*4 * sizeof(float) + m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE + ORIENTATION_BUFFER_SIZE + COLOR_BUFFER_SIZE));
|
2017-06-25 02:38:31 +00:00
|
|
|
|
|
|
|
glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, 0);
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2017-06-25 02:38:31 +00:00
|
|
|
{
|
|
|
|
glDrawElementsInstanced(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, indexOffset, gfxObj->m_numGraphicsInstances);
|
|
|
|
}
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (gfxObj->m_flags & eGfxTransparency)
|
2017-06-25 02:38:31 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
glDisable(GL_BLEND);
|
2017-06-25 02:38:31 +00:00
|
|
|
glDepthMask(true);
|
|
|
|
}
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case B3_CREATE_SHADOWMAP_RENDERMODE:
|
|
|
|
{
|
|
|
|
glUseProgram(createShadowMapInstancingShader);
|
|
|
|
glUniformMatrix4fv(createShadow_depthMVP, 1, false, &depthMVP[0][0]);
|
|
|
|
glDrawElementsInstanced(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, indexOffset, gfxObj->m_numGraphicsInstances);
|
|
|
|
break;
|
|
|
|
}
|
2017-06-24 20:41:33 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case B3_USE_SHADOWMAP_RENDERMODE:
|
2017-06-25 02:38:31 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (gfxObj->m_flags & eGfxTransparency)
|
2017-06-25 02:38:31 +00:00
|
|
|
{
|
|
|
|
glDepthMask(false);
|
2018-09-23 21:17:31 +00:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2017-06-24 20:41:33 +00:00
|
|
|
}
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
glUseProgram(useShadowMapInstancingShader);
|
|
|
|
glUniformMatrix4fv(useShadow_ProjectionMatrix, 1, false, &m_data->m_projectionMatrix[0]);
|
2018-01-08 20:25:56 +00:00
|
|
|
//glUniformMatrix4fv(useShadow_ModelViewMatrix, 1, false, &m_data->m_viewMatrix[0]);
|
|
|
|
//glUniformMatrix4fv(useShadow_ViewMatrixInverse, 1, false, &m_data->m_viewMatrix[0]);
|
|
|
|
//glUniformMatrix4fv(useShadow_ViewMatrixInverse, 1, false, &m_data->m_viewMatrixInverse[0]);
|
|
|
|
//glUniformMatrix4fv(useShadow_ModelViewMatrix, 1, false, &m_data->m_viewMatrix[0]);
|
2017-06-24 20:41:33 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glUniform3f(useShadow_lightSpecularIntensity, m_data->m_lightSpecularIntensity[0], m_data->m_lightSpecularIntensity[1], m_data->m_lightSpecularIntensity[2]);
|
|
|
|
glUniform3f(useShadow_materialSpecularColor, gfxObj->m_materialSpecularColor[0], gfxObj->m_materialSpecularColor[1], gfxObj->m_materialSpecularColor[2]);
|
2017-06-25 02:38:31 +00:00
|
|
|
|
|
|
|
float MVP[16];
|
2018-01-08 20:25:56 +00:00
|
|
|
if (reflectionPass)
|
|
|
|
{
|
2018-04-11 08:03:36 +00:00
|
|
|
//todo: create an API to select this reflection matrix, to allow
|
|
|
|
//reflection planes different from Z-axis up through (0,0,0)
|
2018-01-08 20:25:56 +00:00
|
|
|
float tmp[16];
|
2018-09-23 21:17:31 +00:00
|
|
|
float reflectionMatrix[16] = {1, 0, 0, 0,
|
|
|
|
0, 1, 0, 0,
|
|
|
|
0, 0, -1, 0,
|
|
|
|
0, 0, 0, 1};
|
2018-01-08 20:25:56 +00:00
|
|
|
glCullFace(GL_FRONT);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Matrix4x4Mul16(m_data->m_viewMatrix, reflectionMatrix, tmp);
|
|
|
|
b3Matrix4x4Mul16(m_data->m_projectionMatrix, tmp, MVP);
|
|
|
|
}
|
|
|
|
else
|
2018-01-08 20:25:56 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Matrix4x4Mul16(m_data->m_projectionMatrix, m_data->m_viewMatrix, MVP);
|
2018-01-08 20:25:56 +00:00
|
|
|
glCullFace(GL_BACK);
|
|
|
|
}
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
glUniformMatrix4fv(useShadow_MVP, 1, false, &MVP[0]);
|
|
|
|
//gLightDir.normalize();
|
2018-09-23 21:17:31 +00:00
|
|
|
glUniform3f(useShadow_lightPosIn, m_data->m_lightPos[0], m_data->m_lightPos[1], m_data->m_lightPos[2]);
|
2017-06-25 02:38:31 +00:00
|
|
|
float camPos[3];
|
|
|
|
m_data->m_activeCamera->getCameraPosition(camPos);
|
2018-09-23 21:17:31 +00:00
|
|
|
glUniform3f(useShadow_cameraPositionIn, camPos[0], camPos[1], camPos[2]);
|
|
|
|
glUniform1f(useShadow_materialShininessIn, gfxObj->m_materialShinyNess);
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
glUniformMatrix4fv(useShadow_DepthBiasModelViewMatrix, 1, false, &depthBiasMVP[0][0]);
|
|
|
|
glActiveTexture(GL_TEXTURE1);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, m_data->m_shadowTexture);
|
2018-09-23 21:17:31 +00:00
|
|
|
glUniform1i(useShadow_shadowMap, 1);
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
//sort transparent objects
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
//gfxObj->m_instanceOffset
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (gfxObj->m_flags & eGfxTransparency)
|
2017-06-24 20:41:33 +00:00
|
|
|
{
|
|
|
|
int instanceId = transparentInstances[i].m_instanceId;
|
2018-09-23 21:17:31 +00:00
|
|
|
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)((instanceId)*4 * sizeof(float) + m_data->m_maxShapeCapacityInBytes));
|
|
|
|
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)((instanceId)*4 * sizeof(float) + m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE));
|
|
|
|
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)((instanceId)*4 * sizeof(float) + m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE + ORIENTATION_BUFFER_SIZE));
|
2018-10-01 03:02:12 +00:00
|
|
|
glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)((instanceId)*4 * sizeof(float) + m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE + ORIENTATION_BUFFER_SIZE + COLOR_BUFFER_SIZE));
|
2017-06-24 20:41:33 +00:00
|
|
|
glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, 0);
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2017-06-25 02:38:31 +00:00
|
|
|
{
|
|
|
|
glDrawElementsInstanced(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, indexOffset, gfxObj->m_numGraphicsInstances);
|
2017-06-24 20:41:33 +00:00
|
|
|
}
|
2018-02-21 03:44:02 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (gfxObj->m_flags & eGfxTransparency)
|
2017-06-25 02:38:31 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
glDisable(GL_BLEND);
|
2017-06-25 02:38:31 +00:00
|
|
|
glDepthMask(true);
|
|
|
|
}
|
|
|
|
glActiveTexture(GL_TEXTURE1);
|
2018-09-23 21:17:31 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2017-06-25 02:38:31 +00:00
|
|
|
|
2018-02-11 21:50:45 +00:00
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2018-09-23 21:17:31 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2018-02-11 21:50:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case B3_USE_PROJECTIVE_TEXTURE_RENDERMODE:
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (gfxObj->m_flags & eGfxTransparency)
|
2018-02-11 21:50:45 +00:00
|
|
|
{
|
|
|
|
glDepthMask(false);
|
2018-09-23 21:17:31 +00:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2018-02-11 21:50:45 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2018-02-12 05:29:02 +00:00
|
|
|
glUseProgram(projectiveTextureInstancingShader);
|
|
|
|
glUniformMatrix4fv(projectiveTexture_ProjectionMatrix, 1, false, &m_data->m_projectionMatrix[0]);
|
2018-09-23 21:17:31 +00:00
|
|
|
glUniform3f(projectiveTexture_lightSpecularIntensity, m_data->m_lightSpecularIntensity[0], m_data->m_lightSpecularIntensity[1], m_data->m_lightSpecularIntensity[2]);
|
|
|
|
glUniform3f(projectiveTexture_materialSpecularColor, gfxObj->m_materialSpecularColor[0], gfxObj->m_materialSpecularColor[1], gfxObj->m_materialSpecularColor[2]);
|
|
|
|
|
2018-02-11 21:50:45 +00:00
|
|
|
float MVP[16];
|
|
|
|
if (reflectionPass)
|
|
|
|
{
|
|
|
|
float tmp[16];
|
2018-09-23 21:17:31 +00:00
|
|
|
float reflectionMatrix[16] = {1, 0, 0, 0,
|
|
|
|
0, 1, 0, 0,
|
|
|
|
0, 0, -1, 0,
|
|
|
|
0, 0, 0, 1};
|
2018-02-11 21:50:45 +00:00
|
|
|
glCullFace(GL_FRONT);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Matrix4x4Mul16(m_data->m_viewMatrix, reflectionMatrix, tmp);
|
|
|
|
b3Matrix4x4Mul16(m_data->m_projectionMatrix, tmp, MVP);
|
|
|
|
}
|
|
|
|
else
|
2018-02-11 21:50:45 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Matrix4x4Mul16(m_data->m_projectionMatrix, m_data->m_viewMatrix, MVP);
|
2018-02-11 21:50:45 +00:00
|
|
|
glCullFace(GL_BACK);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2018-02-12 05:29:02 +00:00
|
|
|
glUniformMatrix4fv(projectiveTexture_MVP, 1, false, &MVP[0]);
|
2018-09-23 21:17:31 +00:00
|
|
|
glUniform3f(projectiveTexture_lightPosIn, m_data->m_lightPos[0], m_data->m_lightPos[1], m_data->m_lightPos[2]);
|
2018-02-11 21:50:45 +00:00
|
|
|
float camPos[3];
|
|
|
|
m_data->m_activeCamera->getCameraPosition(camPos);
|
2018-09-23 21:17:31 +00:00
|
|
|
glUniform3f(projectiveTexture_cameraPositionIn, camPos[0], camPos[1], camPos[2]);
|
|
|
|
glUniform1f(projectiveTexture_materialShininessIn, gfxObj->m_materialShinyNess);
|
|
|
|
|
2018-02-21 02:32:09 +00:00
|
|
|
glUniformMatrix4fv(projectiveTexture_TextureMVP, 1, false, &textureMVP[0]);
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2018-02-11 21:50:45 +00:00
|
|
|
//sort transparent objects
|
2018-09-23 21:17:31 +00:00
|
|
|
if (gfxObj->m_flags & eGfxTransparency)
|
2018-02-11 21:50:45 +00:00
|
|
|
{
|
|
|
|
int instanceId = transparentInstances[i].m_instanceId;
|
2018-09-23 21:17:31 +00:00
|
|
|
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)((instanceId)*4 * sizeof(float) + m_data->m_maxShapeCapacityInBytes));
|
|
|
|
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)((instanceId)*4 * sizeof(float) + m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE));
|
|
|
|
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)((instanceId)*4 * sizeof(float) + m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE + ORIENTATION_BUFFER_SIZE));
|
2018-10-01 03:02:12 +00:00
|
|
|
glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)((instanceId)*4 * sizeof(float) + m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE + ORIENTATION_BUFFER_SIZE + COLOR_BUFFER_SIZE));
|
2018-02-11 21:50:45 +00:00
|
|
|
glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, 0);
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2018-02-11 21:50:45 +00:00
|
|
|
{
|
|
|
|
glDrawElementsInstanced(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, indexOffset, gfxObj->m_numGraphicsInstances);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
if (gfxObj->m_flags & eGfxTransparency)
|
2018-02-11 21:50:45 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
glDisable(GL_BLEND);
|
2018-02-11 21:50:45 +00:00
|
|
|
glDepthMask(true);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2018-09-23 21:17:31 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2017-06-25 02:38:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
default:
|
2017-06-24 20:41:33 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
// b3Assert(0);
|
2017-06-24 20:41:33 +00:00
|
|
|
}
|
2017-06-25 02:38:31 +00:00
|
|
|
};
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2017-06-25 02:38:31 +00:00
|
|
|
//glDrawElementsInstanced(GL_LINE_LOOP, indexCount, GL_UNSIGNED_INT, (void*)indexOffset, gfxObj->m_numGraphicsInstances);
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
B3_PROFILE("glFlush");
|
|
|
|
//glFlush();
|
|
|
|
}
|
|
|
|
if (renderMode == B3_CREATE_SHADOWMAP_RENDERMODE)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
// writeTextureToPng(shadowMapWidth,shadowMapHeight,"shadowmap.png",4);
|
2015-04-16 16:55:32 +00:00
|
|
|
m_data->m_shadowMap->disable();
|
2018-09-23 21:17:31 +00:00
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, m_data->m_renderFrameBuffer);
|
|
|
|
glViewport(dims[0], dims[1], dims[2], dims[3]);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
B3_PROFILE("glUseProgram(0);");
|
|
|
|
glUseProgram(0);
|
2018-09-23 21:17:31 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
2015-04-16 16:55:32 +00:00
|
|
|
glBindVertexArray(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
glDisable(GL_CULL_FACE);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(glGetError() == GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLInstancingRenderer::CleanupShaders()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-04-11 08:03:36 +00:00
|
|
|
void GLInstancingRenderer::setPlaneReflectionShapeIndex(int index)
|
|
|
|
{
|
|
|
|
m_planeReflectionShapeIndex = index;
|
|
|
|
}
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
void GLInstancingRenderer::enableShadowMap()
|
|
|
|
{
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
//glEnable(GL_TEXTURE_2D);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, m_data->m_shadowTexture);
|
|
|
|
//glBindTexture(GL_TEXTURE_2D, m_data->m_defaultTexturehandle);
|
|
|
|
}
|
|
|
|
|
2015-10-18 21:01:25 +00:00
|
|
|
void GLInstancingRenderer::clearZBuffer()
|
|
|
|
{
|
|
|
|
glClear(GL_DEPTH_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
|
2015-05-01 18:42:14 +00:00
|
|
|
int GLInstancingRenderer::getMaxShapeCapacity() const
|
|
|
|
{
|
|
|
|
return m_data->m_maxShapeCapacityInBytes;
|
|
|
|
}
|
|
|
|
int GLInstancingRenderer::getInstanceCapacity() const
|
|
|
|
{
|
|
|
|
return m_data->m_maxNumObjectCapacity;
|
|
|
|
}
|
2016-06-30 23:03:38 +00:00
|
|
|
|
|
|
|
void GLInstancingRenderer::setRenderFrameBuffer(unsigned int renderFrameBuffer)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_renderFrameBuffer = (GLuint)renderFrameBuffer;
|
2016-06-30 23:03:38 +00:00
|
|
|
}
|
|
|
|
|
2016-07-08 02:24:44 +00:00
|
|
|
int GLInstancingRenderer::getTotalNumInstances() const
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
return m_data->m_totalNumInstances;
|
2016-07-08 02:24:44 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
#endif //NO_OPENGL3
|