Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Commit

Permalink
support renderbuffer based display (#52)
Browse files Browse the repository at this point in the history
* support renderbuffer based display

Add optional callback to Disp constructor to specify OS binding for renderbuffer storage during allocation.   If this is specified the renderbuffer will be used (via framebuffer) for rendering to the display, rather than framebuffer == 0 screen rendering.

* #include <functional>
  • Loading branch information
headupinclouds authored Sep 3, 2018
1 parent c9ff2a7 commit c1f1112
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ HunterGate(
LOCAL
)

project(ogles_gpgpu VERSION 0.3.3)
project(ogles_gpgpu VERSION 0.3.4)

hunter_add_package(check_ci_tag)
find_package(check_ci_tag CONFIG REQUIRED)
Expand Down
59 changes: 58 additions & 1 deletion ogles_gpgpu/common/proc/disp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,30 @@ void main()
);
// clang-format on

Disp::Disp() = default;

Disp::Disp(const Callback &renderbufferStorage)
: renderbufferStorage(renderbufferStorage)
{

}

Disp::~Disp()
{
if (renderbufferStorage)
{
glDeleteRenderbuffers(1, &renderbuffer);
}
}

int Disp::init(int inW, int inH, unsigned int order, bool prepareForExternalInput) {
OG_LOGINF(getProcName(), "initialize");

if(renderbufferStorage)
{
createFBO();
}

// ProcBase init - set defaults
baseInit(inW, inH, order, prepareForExternalInput, procParamOutW, procParamOutH, procParamOutScale);

Expand All @@ -50,12 +71,48 @@ int Disp::render(int position) {
filterRenderSetCoords();
Tools::checkGLErr(getProcName(), "render set coords");

//glBindBuffer(GL_FRAMEBUFFER, 0);
filterRenderDraw();
Tools::checkGLErr(getProcName(), "render draw");

if(renderbufferStorage)
{
glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
Tools::checkGLErr(getProcName(), "glBindRenderbuffer");
}

filterRenderCleanup();
Tools::checkGLErr(getProcName(), "render cleanup");

return 0;
}

void Disp::createFBO()
{
FilterProcBase::createFBO();

if (renderbufferStorage) {

fbo->bind();
Tools::checkGLErr(getProcName(), "glBindFramebuffer");

// Create a Renderbuffer
glGenRenderbuffers(1, &renderbuffer);
Tools::checkGLErr(getProcName(), "glGenRenderbuffers");

glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
Tools::checkGLErr(getProcName(), "glBindRenderbuffer");

renderbufferStorage();
Tools::checkGLErr(getProcName(), "renderbufferStorage");

glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer);
Tools::checkGLErr(getProcName(), "glFramebufferRenderbuffer");

auto fboStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (fboStatus != GL_FRAMEBUFFER_COMPLETE) {
std::stringstream ss;
ss << "Framebuffer incomplete :" << int(fboStatus);
throw std::runtime_error(ss.str());
}
}
}
30 changes: 30 additions & 0 deletions ogles_gpgpu/common/proc/disp.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include "base/filterprocbase.h"

#include <functional>

namespace ogles_gpgpu {

/**
Expand All @@ -25,6 +27,24 @@ namespace ogles_gpgpu {
*/
class Disp : public FilterProcBase {
public:

using Callback = std::function<void()>;

/**
* Default constructor
*/
Disp();

/**
* Constructor for renderbuffer based display
*/
Disp(const Callback &renderbufferStorage);

/**
* Destructor
*/
virtual ~Disp();

/**
* Output resolution of display.
*
Expand Down Expand Up @@ -87,13 +107,23 @@ class Disp : public FilterProcBase {
return NULL;
}

/**
* Create an FBO for this processor. This will contain the result after rendering in its attached texture.
*
* (optional) create renderbuffer if renderbufferStorage callback was specified in constructor.
*/
virtual void createFBO();

private:
float tx = 0.f;
float ty = 0.f;
float resolutionX = 1.f;
float resolutionY = 1.f;

static const char* fshaderDispSrc; // fragment shader source

GLuint renderbuffer; // (optional) renderbuffer based display
Callback renderbufferStorage;
};
}

Expand Down

0 comments on commit c1f1112

Please sign in to comment.