added methods to glw framebuffer and program.

This commit is contained in:
Marco Di Benedetto 2012-06-01 16:57:42 +00:00
parent ddebef10db
commit e95721b5c4
2 changed files with 86 additions and 25 deletions

View File

@ -214,6 +214,16 @@ class Framebuffer : public Object
return true;
}
bool removeAllColorTargets(GLenum target, GLint unit)
{
(void)unit;
for (RenderTargetMapping::ConstIterator it=this->m_config.colorTargets.bindings.begin(); it!=this->m_config.colorTargets.bindings.end(); ++it)
{
glFramebufferRenderbuffer(target, GL_COLOR_ATTACHMENT0 + it->first, GL_RENDERBUFFER, 0);
}
this->m_config.colorTargets.clear();
}
bool setDepthTarget(GLenum target, GLint unit, const RenderTarget & renderTarget)
{
(void)unit;
@ -254,6 +264,23 @@ class Framebuffer : public Object
return true;
}
bool removeAllTargets(GLenum target, GLint unit)
{
this->removeAllColorTargets (target, unit);
this->removeDepthTarget (target, unit);
this->removeStencilTarget (target, unit);
return true;
}
bool setTargetInputs(GLenum target, GLint unit, const RenderTargetBinding & targetInputs)
{
(void)target;
(void)unit;
GLW_ASSERT(this->isValid());
this->configureTargetInputs(targetInputs);
return true;
}
bool readColorPixels(GLenum target, GLint unit, GLint index, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid * data)
{
(void)target;
@ -358,29 +385,7 @@ class Framebuffer : public Object
const bool stencilAttached = this->attachTarget(target, GL_STENCIL_ATTACHMENT, args.stencilTarget);
if (stencilAttached) this->m_config.stencilTarget = args.stencilTarget;
if (this->m_config.colorTargets.bindings.empty())
{
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
}
else
{
std::vector<GLenum> drawBuffers;
drawBuffers.reserve(args.targetInputs.bindings.size());
for (RenderTargetBinding::ConstIterator it=args.targetInputs.bindings.begin(); it!=args.targetInputs.bindings.end(); ++it)
{
const GLuint fragOutput = it->second;
const GLuint attachmentIndex = GL_COLOR_ATTACHMENT0 + it->first;
if (drawBuffers.size() <= size_t(fragOutput))
{
drawBuffers.resize(size_t(fragOutput + 1), GL_NONE);
}
drawBuffers[fragOutput] = attachmentIndex;
this->m_config.targetInputs[it->first] = fragOutput;
}
glDrawBuffers(GLsizei(drawBuffers.size()), &(drawBuffers[0]));
glReadBuffer(drawBuffers[0]);
}
this->configureTargetInputs(args.targetInputs);
}
bool attachTarget(GLenum target, GLenum attachment, const RenderTarget & renderTarget)
@ -402,6 +407,32 @@ class Framebuffer : public Object
return true;
}
void configureTargetInputs(const RenderTargetBinding & targetInputs)
{
if (this->m_config.colorTargets.bindings.empty() && targetInputs.bindings.empty())
{
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
return;
}
std::vector<GLenum> drawBuffers;
drawBuffers.reserve(targetInputs.bindings.size());
for (RenderTargetBinding::ConstIterator it=targetInputs.bindings.begin(); it!=targetInputs.bindings.end(); ++it)
{
const GLuint fragOutput = it->second;
const GLuint attachmentIndex = GL_COLOR_ATTACHMENT0 + it->first;
if (drawBuffers.size() <= size_t(fragOutput))
{
drawBuffers.resize(size_t(fragOutput + 1), GL_NONE);
}
drawBuffers[fragOutput] = attachmentIndex;
this->m_config.targetInputs[it->first] = fragOutput;
}
glDrawBuffers(GLsizei(drawBuffers.size()), &(drawBuffers[0]));
glReadBuffer(drawBuffers[0]);
}
};
namespace detail { template <> struct BaseOf <Framebuffer> { typedef Object Type; }; };
@ -511,6 +542,11 @@ class BoundFramebuffer : public BoundObject
return this->object()->removeColorTarget(this->m_target, this->m_unit, index);
}
bool removeAllColorTargets(void)
{
return this->object()->removeAllColorTargets(this->m_target, this->m_unit);
}
bool setDepthTarget(const RenderTarget & renderTarget)
{
return this->object()->setDepthTarget(this->m_target, this->m_unit, renderTarget);
@ -531,6 +567,16 @@ class BoundFramebuffer : public BoundObject
return this->object()->removeStencilTarget(this->m_target, this->m_unit);
}
bool removeAllTargets(void)
{
return this->object()->removeAllTargets(this->m_target, this->m_unit);
}
bool setTargetInputs(const RenderTargetBinding & targetInputs)
{
return this->object()->setTargetInputs(this->m_target, this->m_unit, targetInputs);
}
protected:
BoundFramebuffer(const FramebufferHandle & handle, const FramebufferBindingParams & params)

View File

@ -228,6 +228,11 @@ class Program : public Object
return this->m_log;
}
const std::string & fullLog(void) const
{
return this->m_fullLog;
}
bool isLinked(void) const
{
return this->m_linked;
@ -297,6 +302,7 @@ class Program : public Object
glGetIntegerv(GL_CURRENT_PROGRAM, &boundName);
this->m_name = glCreateProgram();
this->m_fullLog = "";
// shaders
{
@ -304,6 +310,7 @@ class Program : public Object
{
const ShaderHandle & shader = this->m_arguments.shaders[i];
if (!shader) continue;
this->m_fullLog += shader->log();
if (!shader->isCompiled()) continue;
glAttachShader(this->m_name, shader->name());
}
@ -356,8 +363,9 @@ class Program : public Object
GLint linkStatus = 0;
glGetProgramiv(this->m_name, GL_LINK_STATUS, &linkStatus);
this->m_log = ThisType::getInfoLog(this->m_name);
this->m_linked = (linkStatus != GL_FALSE);
this->m_log = ThisType::getInfoLog(this->m_name);
this->m_fullLog += this->m_log;
this->m_linked = (linkStatus != GL_FALSE);
#if GLW_PRINT_LOG_TO_STDERR
std::cerr << "---------------------------" << std::endl;
@ -381,6 +389,7 @@ class Program : public Object
glDeleteProgram(this->m_name);
this->m_arguments.clear();
this->m_log.clear();
this->m_fullLog.clear();
this->m_linked = false;
}
@ -420,6 +429,7 @@ class Program : public Object
ProgramArguments m_arguments;
UniformMap m_uniforms;
std::string m_log;
std::string m_fullLog;
bool m_linked;
static std::string getInfoLog(GLuint Program)
@ -499,6 +509,11 @@ class SafeProgram : public SafeObject
return this->object()->log();
}
const std::string & fullLog(void) const
{
return this->object()->fullLog();
}
bool isLinked(void) const
{
return this->object()->isLinked();