Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -38,7 +38,7 @@
|
||||
|
||||
#include "OpenGLInclude.h"
|
||||
|
||||
#include "third_party/GL/EGL/egl.h"
|
||||
#include "third_party/GL/gl/include/EGL/egl.h"
|
||||
#include "third_party/GL/gl/include/EGL/eglext.h"
|
||||
#include "third_party/GL/gl/include/GL/gl.h"
|
||||
|
||||
|
||||
@@ -361,7 +361,8 @@ GLInstancingRenderer::GLInstancingRenderer(int maxNumObjectCapacity, int maxShap
|
||||
m_textureinitialized(false),
|
||||
m_screenWidth(0),
|
||||
m_screenHeight(0),
|
||||
m_upAxis(1)
|
||||
m_upAxis(1),
|
||||
m_planeReflectionShapeIndex(-1)
|
||||
{
|
||||
|
||||
m_data = new InternalDataRenderer;
|
||||
@@ -508,6 +509,16 @@ void GLInstancingRenderer::writeSingleInstanceColorToCPU(const double* color, in
|
||||
b3Assert(pg);
|
||||
int srcIndex = pg->m_internalInstanceIndex;
|
||||
|
||||
int shapeIndex = pg->m_shapeIndex;
|
||||
b3GraphicsInstance* gfxObj = m_graphicsInstances[shapeIndex];
|
||||
if (color[3]<1)
|
||||
{
|
||||
gfxObj->m_flags |= eGfxTransparency;
|
||||
} else
|
||||
{
|
||||
gfxObj->m_flags &= ~eGfxTransparency;
|
||||
}
|
||||
|
||||
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]);
|
||||
@@ -519,6 +530,16 @@ void GLInstancingRenderer::writeSingleInstanceColorToCPU(const float* color, int
|
||||
b3PublicGraphicsInstance* pg = m_data->m_publicGraphicsInstances.getHandle(srcIndex2);
|
||||
b3Assert(pg);
|
||||
int srcIndex = pg->m_internalInstanceIndex;
|
||||
int shapeIndex = pg->m_shapeIndex;
|
||||
b3GraphicsInstance* gfxObj = m_graphicsInstances[shapeIndex];
|
||||
|
||||
if (color[3]<1)
|
||||
{
|
||||
gfxObj->m_flags |= eGfxTransparency;
|
||||
} else
|
||||
{
|
||||
gfxObj->m_flags &= ~eGfxTransparency;
|
||||
}
|
||||
|
||||
m_data->m_instance_colors_ptr[srcIndex*4+0]=color[0];
|
||||
m_data->m_instance_colors_ptr[srcIndex*4+1]=color[1];
|
||||
@@ -1597,13 +1618,44 @@ void GLInstancingRenderer::renderScene()
|
||||
{
|
||||
|
||||
renderSceneInternal(B3_CREATE_SHADOWMAP_RENDERMODE);
|
||||
//glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
||||
//renderSceneInternal(B3_USE_SHADOWMAP_RENDERMODE_REFLECTION);
|
||||
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
if (m_planeReflectionShapeIndex>=0)
|
||||
{
|
||||
/* Don't update color or depth. */
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||
|
||||
/* Draw 1 into the stencil buffer. */
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
|
||||
glStencilFunc(GL_ALWAYS, 1, 0xffffffff);
|
||||
|
||||
/* Now render floor; floor pixels just get their stencil set to 1. */
|
||||
renderSceneInternal(B3_USE_SHADOWMAP_RENDERMODE_REFLECTION_PLANE);
|
||||
|
||||
/* Re-enable update of color and depth. */
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
/* Now, only render where stencil is set to 1. */
|
||||
glStencilFunc(GL_EQUAL, 1, 0xffffffff); /* draw if ==1 */
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
||||
|
||||
//draw the reflection objects
|
||||
renderSceneInternal(B3_USE_SHADOWMAP_RENDERMODE_REFLECTION);
|
||||
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
}
|
||||
|
||||
renderSceneInternal(B3_USE_SHADOWMAP_RENDERMODE);
|
||||
|
||||
|
||||
|
||||
}
|
||||
else if (m_data->m_useProjectiveTexture)
|
||||
{
|
||||
|
||||
renderSceneInternal(B3_USE_PROJECTIVE_TEXTURE_RENDERMODE);
|
||||
}
|
||||
else
|
||||
@@ -2040,6 +2092,13 @@ void GLInstancingRenderer::renderSceneInternal(int orgRenderMode)
|
||||
{
|
||||
int renderMode=orgRenderMode;
|
||||
bool reflectionPass = false;
|
||||
bool reflectionPlanePass = false;
|
||||
|
||||
if (orgRenderMode==B3_USE_SHADOWMAP_RENDERMODE_REFLECTION_PLANE)
|
||||
{
|
||||
reflectionPlanePass = true;
|
||||
renderMode = B3_USE_SHADOWMAP_RENDERMODE;
|
||||
}
|
||||
if (orgRenderMode==B3_USE_SHADOWMAP_RENDERMODE_REFLECTION)
|
||||
{
|
||||
reflectionPass = true;
|
||||
@@ -2085,8 +2144,8 @@ void GLInstancingRenderer::renderSceneInternal(int orgRenderMode)
|
||||
//GLfloat depthModelViewMatrix2[4][4];
|
||||
|
||||
// For projective texture mapping
|
||||
float textureProjectionMatrix[4][4];
|
||||
GLfloat textureModelViewMatrix[4][4];
|
||||
//float textureProjectionMatrix[4][4];
|
||||
//GLfloat textureModelViewMatrix[4][4];
|
||||
|
||||
// Compute the MVP matrix from the light's point of view
|
||||
if (renderMode==B3_CREATE_SHADOWMAP_RENDERMODE)
|
||||
@@ -2254,6 +2313,7 @@ b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
for (int obj=0;obj<m_graphicsInstances.size();obj++)
|
||||
{
|
||||
b3GraphicsInstance* gfxObj = m_graphicsInstances[obj];
|
||||
|
||||
if (gfxObj->m_numGraphicsInstances)
|
||||
{
|
||||
SortableTransparentInstance inst;
|
||||
@@ -2300,9 +2360,16 @@ b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
{
|
||||
for (int i=0;i<transparentInstances.size();i++)
|
||||
{
|
||||
|
||||
|
||||
int shapeIndex = transparentInstances[i].m_shapeIndex;
|
||||
|
||||
//during a reflectionPlanePass, only draw the plane, nothing else
|
||||
if (reflectionPlanePass)
|
||||
{
|
||||
if (shapeIndex!=m_planeReflectionShapeIndex)
|
||||
continue;
|
||||
}
|
||||
|
||||
b3GraphicsInstance* gfxObj = m_graphicsInstances[shapeIndex];
|
||||
|
||||
//only draw stuff (opaque/transparent) if it is the right pass
|
||||
@@ -2340,7 +2407,7 @@ b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
curBindTexture = m_data->m_defaultTexturehandle;
|
||||
}
|
||||
|
||||
//disable lazy evaluation, it just leads to bugs
|
||||
//disable lazy evaluation, it just leads to bugs
|
||||
//if (lastBindTexture != curBindTexture)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D,curBindTexture);
|
||||
@@ -2503,6 +2570,8 @@ b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
float MVP[16];
|
||||
if (reflectionPass)
|
||||
{
|
||||
//todo: create an API to select this reflection matrix, to allow
|
||||
//reflection planes different from Z-axis up through (0,0,0)
|
||||
float tmp[16];
|
||||
float reflectionMatrix[16] = {1,0,0,0,
|
||||
0,1,0,0,
|
||||
@@ -2669,6 +2738,11 @@ void GLInstancingRenderer::CleanupShaders()
|
||||
{
|
||||
}
|
||||
|
||||
void GLInstancingRenderer::setPlaneReflectionShapeIndex(int index)
|
||||
{
|
||||
m_planeReflectionShapeIndex = index;
|
||||
}
|
||||
|
||||
void GLInstancingRenderer::enableShadowMap()
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
@@ -39,6 +39,8 @@ class GLInstancingRenderer : public CommonRenderInterface
|
||||
int m_screenHeight;
|
||||
|
||||
int m_upAxis;
|
||||
|
||||
int m_planeReflectionShapeIndex;
|
||||
|
||||
|
||||
int registerGraphicsInstanceInternal(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling);
|
||||
@@ -151,6 +153,8 @@ public:
|
||||
virtual int getTotalNumInstances() const;
|
||||
|
||||
virtual void enableShadowMap();
|
||||
|
||||
virtual void setPlaneReflectionShapeIndex(int index);
|
||||
|
||||
virtual void clearZBuffer();
|
||||
|
||||
|
||||
@@ -17,12 +17,20 @@ subject to the following restrictions:
|
||||
#ifndef __OPENGL_INCLUDE_H
|
||||
#define __OPENGL_INCLUDE_H
|
||||
|
||||
#ifdef BT_NO_GLAD
|
||||
#include "third_party/GL/gl/include/EGL/egl.h"
|
||||
#include "third_party/GL/gl/include/EGL/eglext.h"
|
||||
#include "third_party/GL/gl/include/GL/gl.h"
|
||||
#else
|
||||
|
||||
#ifdef B3_USE_GLFW
|
||||
#include "glad/glad.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
#else
|
||||
#include "glad/glad.h"
|
||||
#endif //B3_USE_GLFW
|
||||
#endif //BT_NO_GLAD
|
||||
|
||||
//disable glGetError
|
||||
//#undef glGetError
|
||||
//#define glGetError MyGetError
|
||||
|
||||
@@ -17,12 +17,17 @@ subject to the following restrictions:
|
||||
#ifndef __OPENGL_INCLUDE_H
|
||||
#define __OPENGL_INCLUDE_H
|
||||
|
||||
#ifdef BT_NO_GLAD
|
||||
#include "third_party/GL/gl/include/EGL/egl.h"
|
||||
#include "third_party/GL/gl/include/EGL/eglext.h"
|
||||
#include "third_party/GL/gl/include/GL/gl.h"
|
||||
#else
|
||||
#ifdef B3_USE_GLFW
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#else
|
||||
#include "glad/glad.h"
|
||||
#endif //B3_USE_GLFW
|
||||
|
||||
#endif //BT_NO_GLAD
|
||||
#endif //__OPENGL_INCLUDE_H
|
||||
|
||||
|
||||
@@ -295,7 +295,7 @@ static void printGLString(const char *name, GLenum s) {
|
||||
bool sOpenGLVerbose = true;
|
||||
|
||||
|
||||
SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height, bool allowRetina)
|
||||
SimpleOpenGL3App::SimpleOpenGL3App(const char* title, int width, int height, bool allowRetina, int maxNumObjectCapacity, int maxShapeCapacityInBytes)
|
||||
{
|
||||
gApp = this;
|
||||
|
||||
@@ -369,7 +369,7 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height, boo
|
||||
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
|
||||
m_instancingRenderer = new GLInstancingRenderer(128*1024,128*1024*1024);
|
||||
m_instancingRenderer = new GLInstancingRenderer(maxNumObjectCapacity, maxShapeCapacityInBytes);
|
||||
|
||||
m_primRenderer = new GLPrimitiveRenderer(width,height);
|
||||
|
||||
|
||||
@@ -16,7 +16,8 @@ struct SimpleOpenGL3App : public CommonGraphicsApp
|
||||
class GLInstancingRenderer* m_instancingRenderer;
|
||||
virtual void setBackgroundColor(float red, float green, float blue);
|
||||
|
||||
SimpleOpenGL3App(const char* title, int width,int height, bool allowRetina=true);
|
||||
SimpleOpenGL3App(const char* title, int width,int height, bool allowRetina=true, int maxNumObjectCapacity = 128 * 1024, int maxShapeCapacityInBytes = 128 * 1024 * 1024);
|
||||
|
||||
virtual ~SimpleOpenGL3App();
|
||||
|
||||
virtual int registerCubeShape(float halfExtentsX=1.f,float halfExtentsY=1.f, float halfExtentsZ = 1.f, int textureIndex = -1, float textureScaling = 1);
|
||||
|
||||
@@ -6,11 +6,6 @@
|
||||
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#ifdef GLEW_STATIC
|
||||
#include "glad/glad.h"
|
||||
#else
|
||||
#include <GL/glew.h>
|
||||
#endif//GLEW_STATIC
|
||||
|
||||
#ifdef GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
|
||||
#include "glad/glad_glx.h"
|
||||
|
||||
Reference in New Issue
Block a user