Skip to content

Instantly share code, notes, and snippets.

@VirtuosoChris
Created April 23, 2019 21:05
Show Gist options
  • Save VirtuosoChris/1c9c811caf5e4d2b11ea716aaffa8210 to your computer and use it in GitHub Desktop.
Save VirtuosoChris/1c9c811caf5e4d2b11ea716aaffa8210 to your computer and use it in GitHub Desktop.
rendertargets.h
//
// RenderTargets.h
//
//
// Created by Chris Pugh on 2/2/16.
//
//
#ifndef RenderTargets_h
#define RenderTargets_h
struct RenderTarget
{
gl::Framebuffer fbo;
unsigned int frameWidth; ///< one half the allocated render target width, since we are using side by side stereo
unsigned int frameHeight;
unsigned int multisamples;
RenderTarget(unsigned int width, unsigned int height, unsigned int samples) :
frameWidth(width), frameHeight(height), multisamples(samples)
{
}
};
struct BasicRenderTarget : public RenderTarget
{
// *** experimental path. copying from side by side rendering to output textures*** /
gl::Renderbuffer depthTex;
void prime(GLuint tex)
{
fbo.Bind(GL_FRAMEBUFFER);
#if GL_ALT_API_NAME == GL_ALT_GLES_API
if (multisamples > 1)
{
glFramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
tex, 0, multisamples);
}
else
#endif
{
std::clog<<"fbo texture"<<std::endl;
fbo.Texture(GL_COLOR_ATTACHMENT0, tex, 0);
/// glFramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,tex, 0, multisamples);
///fbo.Texture2D(GL_COLOR_ATTACHMENT0, tex, 0);
}
/*try
{
checkFramebuffer();
}
catch (const std::runtime_error& ex)
{
std::clog<<ex.what()<<std::endl;
}*/
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
BasicRenderTarget(int multisamples, unsigned int width, unsigned int height) :
RenderTarget(width, height, multisamples)
{
const GLenum depthFormat = GL_DEPTH_COMPONENT16;
///\todo acknowledge settings for eg, samples, depth format
#if GL_ALT_API_NAME == GL_ALT_GLES_API
if (multisamples > 1)
{
std::clog<<"Side by side with multisamples : "<<multisamples<<std::endl;
depthTex.Bind();
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, multisamples, depthFormat, width, height);
///\todo this fails but renderbufferstoragemultisamplext directly does not
///depthTex.StorageMultisample(multisamples, depthFormat, width, height);
}
else
#endif
{
std::clog<<"Side by side without multisampling"<<std::endl;
depthTex.Storage(depthFormat, width,height);
}
fbo.Renderbuffer(GL_DEPTH_ATTACHMENT, depthTex); ///\todo was depthTex
static const GLenum draw_buffers[] = {GL_COLOR_ATTACHMENT0};
/**glDrawBuffers(1, draw_buffers);**/
///\todo checkFramebuffer();
glViewport(0, 0, frameWidth, frameHeight);
}
};
#endif /* RenderTargets_h */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment