BACKENDS: OPENGL: Activate framebuffer with a specific pipeline
This commit is contained in:
parent
29c25ed566
commit
9b951944bc
4 changed files with 18 additions and 14 deletions
|
@ -20,19 +20,20 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "backends/graphics/opengl/framebuffer.h"
|
#include "backends/graphics/opengl/framebuffer.h"
|
||||||
#include "backends/graphics/opengl/texture.h"
|
|
||||||
#include "backends/graphics/opengl/pipelines/pipeline.h"
|
#include "backends/graphics/opengl/pipelines/pipeline.h"
|
||||||
|
#include "backends/graphics/opengl/texture.h"
|
||||||
#include "graphics/opengl/debug.h"
|
#include "graphics/opengl/debug.h"
|
||||||
|
|
||||||
namespace OpenGL {
|
namespace OpenGL {
|
||||||
|
|
||||||
Framebuffer::Framebuffer()
|
Framebuffer::Framebuffer()
|
||||||
: _viewport(), _projectionMatrix(), _isActive(false), _clearColor(),
|
: _viewport(), _projectionMatrix(), _pipeline(nullptr), _clearColor(),
|
||||||
_blendState(kBlendModeDisabled), _scissorTestState(false), _scissorBox() {
|
_blendState(kBlendModeDisabled), _scissorTestState(false), _scissorBox() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Framebuffer::activate() {
|
void Framebuffer::activate(Pipeline *pipeline) {
|
||||||
_isActive = true;
|
assert(pipeline);
|
||||||
|
_pipeline = pipeline;
|
||||||
|
|
||||||
applyViewport();
|
applyViewport();
|
||||||
applyProjectionMatrix();
|
applyProjectionMatrix();
|
||||||
|
@ -45,9 +46,9 @@ void Framebuffer::activate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Framebuffer::deactivate() {
|
void Framebuffer::deactivate() {
|
||||||
_isActive = false;
|
|
||||||
|
|
||||||
deactivateInternal();
|
deactivateInternal();
|
||||||
|
|
||||||
|
_pipeline = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Framebuffer::setClearColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
|
void Framebuffer::setClearColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
|
||||||
|
@ -97,7 +98,8 @@ void Framebuffer::applyViewport() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Framebuffer::applyProjectionMatrix() {
|
void Framebuffer::applyProjectionMatrix() {
|
||||||
Pipeline::getActivePipeline()->setProjectionMatrix(_projectionMatrix);
|
assert(_pipeline);
|
||||||
|
_pipeline->setProjectionMatrix(_projectionMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Framebuffer::applyClearColor() {
|
void Framebuffer::applyClearColor() {
|
||||||
|
|
|
@ -28,11 +28,12 @@
|
||||||
|
|
||||||
namespace OpenGL {
|
namespace OpenGL {
|
||||||
|
|
||||||
|
class Pipeline;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object describing a framebuffer OpenGL can render to.
|
* Object describing a framebuffer OpenGL can render to.
|
||||||
*/
|
*/
|
||||||
class Framebuffer {
|
class Framebuffer {
|
||||||
friend class Pipeline;
|
|
||||||
public:
|
public:
|
||||||
Framebuffer();
|
Framebuffer();
|
||||||
virtual ~Framebuffer() {};
|
virtual ~Framebuffer() {};
|
||||||
|
@ -86,7 +87,7 @@ public:
|
||||||
*/
|
*/
|
||||||
const Math::Matrix4 &getProjectionMatrix() const { return _projectionMatrix; }
|
const Math::Matrix4 &getProjectionMatrix() const { return _projectionMatrix; }
|
||||||
protected:
|
protected:
|
||||||
bool isActive() const { return _isActive; }
|
bool isActive() const { return _pipeline != nullptr; }
|
||||||
|
|
||||||
GLint _viewport[4];
|
GLint _viewport[4];
|
||||||
void applyViewport();
|
void applyViewport();
|
||||||
|
@ -109,11 +110,11 @@ protected:
|
||||||
*/
|
*/
|
||||||
virtual void deactivateInternal() {}
|
virtual void deactivateInternal() {}
|
||||||
|
|
||||||
private:
|
public:
|
||||||
/**
|
/**
|
||||||
* Accessor to activate framebuffer for pipeline.
|
* Accessor to activate framebuffer for pipeline.
|
||||||
*/
|
*/
|
||||||
void activate();
|
void activate(Pipeline *pipeline);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accessor to deactivate framebuffer from pipeline.
|
* Accessor to deactivate framebuffer from pipeline.
|
||||||
|
@ -121,7 +122,7 @@ private:
|
||||||
void deactivate();
|
void deactivate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _isActive;
|
Pipeline *_pipeline;
|
||||||
|
|
||||||
GLfloat _clearColor[4];
|
GLfloat _clearColor[4];
|
||||||
void applyClearColor();
|
void applyClearColor();
|
||||||
|
|
|
@ -34,7 +34,7 @@ void Pipeline::activate() {
|
||||||
_isActive = true;
|
_isActive = true;
|
||||||
|
|
||||||
if (_activeFramebuffer) {
|
if (_activeFramebuffer) {
|
||||||
_activeFramebuffer->activate();
|
_activeFramebuffer->activate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
activateInternal();
|
activateInternal();
|
||||||
|
@ -58,7 +58,7 @@ Framebuffer *Pipeline::setFramebuffer(Framebuffer *framebuffer) {
|
||||||
|
|
||||||
_activeFramebuffer = framebuffer;
|
_activeFramebuffer = framebuffer;
|
||||||
if (_isActive && _activeFramebuffer) {
|
if (_isActive && _activeFramebuffer) {
|
||||||
_activeFramebuffer->activate();
|
_activeFramebuffer->activate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return oldFramebuffer;
|
return oldFramebuffer;
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include "graphics/opengl/system_headers.h"
|
#include "graphics/opengl/system_headers.h"
|
||||||
|
|
||||||
|
#include "backends/graphics/opengl/framebuffer.h"
|
||||||
#include "backends/graphics/opengl/texture.h"
|
#include "backends/graphics/opengl/texture.h"
|
||||||
|
|
||||||
#include "math/matrix4.h"
|
#include "math/matrix4.h"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue