move shaders to .glsl files and stringify to .h file.
add crude screenshot facility (using F1 key), it can also be used for debugging start with shadows using shadowmap, not working yet add experimental 'ignore' body index in raycast, using b3HitInfo.m_m_hitResult2
This commit is contained in:
@@ -2,37 +2,47 @@
|
||||
///See http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-14-render-to-texture/
|
||||
|
||||
#include "GLRenderToTexture.h"
|
||||
|
||||
#include "Bullet3Common/b3Scalar.h" // for b3Assert
|
||||
GLRenderToTexture::GLRenderToTexture()
|
||||
:m_framebufferName(0)
|
||||
{
|
||||
}
|
||||
|
||||
void GLRenderToTexture::init(int width, int height)
|
||||
void GLRenderToTexture::init(int width, int height, GLuint textureId, int renderTextureType)
|
||||
{
|
||||
m_renderTextureType = renderTextureType;
|
||||
|
||||
glGenFramebuffers(1, &m_framebufferName);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_framebufferName);
|
||||
|
||||
GLuint m_renderedTexture;
|
||||
glGenTextures(1, &m_renderedTexture);
|
||||
|
||||
// "Bind" the newly created texture : all future texture functions will modify this texture
|
||||
glBindTexture(GL_TEXTURE_2D, m_renderedTexture);
|
||||
|
||||
// Give an empty image to OpenGL ( the last "0" )
|
||||
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, width, height, 0,GL_RGB, GL_UNSIGNED_BYTE, 0);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
|
||||
switch (m_renderTextureType)
|
||||
{
|
||||
case RENDERTEXTURE_COLOR:
|
||||
{
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureId, 0);
|
||||
break;
|
||||
}
|
||||
case RENDERTEXTURE_DEPTH:
|
||||
{
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, textureId, 0);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
b3Assert(0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// The depth buffer
|
||||
glGenRenderbuffers(1, &m_depthrenderbuffer);
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_depthrenderbuffer);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthrenderbuffer);
|
||||
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_renderedTexture, 0);
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -40,9 +50,29 @@ bool GLRenderToTexture::enable()
|
||||
{
|
||||
bool status = false;
|
||||
|
||||
// Set the list of draw buffers.
|
||||
GLenum drawBuffers[2] = {GL_COLOR_ATTACHMENT0,0};
|
||||
glDrawBuffers(1, drawBuffers);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_framebufferName);
|
||||
|
||||
|
||||
switch (m_renderTextureType)
|
||||
{
|
||||
case RENDERTEXTURE_COLOR:
|
||||
{
|
||||
// Set the list of draw buffers.
|
||||
GLenum drawBuffers[2] = {GL_COLOR_ATTACHMENT0,0};
|
||||
glDrawBuffers(1, drawBuffers);
|
||||
break;
|
||||
}
|
||||
case RENDERTEXTURE_DEPTH:
|
||||
{
|
||||
glDrawBuffer(GL_NONE);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
b3Assert(0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Always check that our framebuffer is ok
|
||||
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE)
|
||||
@@ -50,6 +80,7 @@ bool GLRenderToTexture::enable()
|
||||
status = true;
|
||||
}
|
||||
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
@@ -57,7 +88,6 @@ bool GLRenderToTexture::enable()
|
||||
void GLRenderToTexture::disable()
|
||||
{
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
GLRenderToTexture::~GLRenderToTexture()
|
||||
@@ -65,10 +95,10 @@ GLRenderToTexture::~GLRenderToTexture()
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
|
||||
|
||||
if (m_depthrenderbuffer)
|
||||
{
|
||||
glDeleteRenderbuffers(1,&m_depthrenderbuffer);
|
||||
}
|
||||
|
||||
if(m_renderedTexture)
|
||||
glDeleteTextures(1, &m_renderedTexture);
|
||||
|
||||
if( m_framebufferName)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user