opengl/glframebuffer: move s_fbos to OpenGlContext
This commit is contained in:
parent
493797ff31
commit
179af074eb
4 changed files with 38 additions and 15 deletions
|
@ -21,25 +21,17 @@ namespace KWin
|
|||
|
||||
GLFramebuffer *GLFramebuffer::currentFramebuffer()
|
||||
{
|
||||
return s_fbos.isEmpty() ? nullptr : s_fbos.top();
|
||||
return OpenGlContext::currentContext()->currentFramebuffer();
|
||||
}
|
||||
|
||||
void GLFramebuffer::pushFramebuffer(GLFramebuffer *fbo)
|
||||
{
|
||||
fbo->bind();
|
||||
s_fbos.push(fbo);
|
||||
OpenGlContext::currentContext()->pushFramebuffer(fbo);
|
||||
}
|
||||
|
||||
GLFramebuffer *GLFramebuffer::popFramebuffer()
|
||||
{
|
||||
GLFramebuffer *ret = s_fbos.pop();
|
||||
if (!s_fbos.isEmpty()) {
|
||||
s_fbos.top()->bind();
|
||||
} else {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return OpenGlContext::currentContext()->popFramebuffer();
|
||||
}
|
||||
|
||||
GLFramebuffer::GLFramebuffer()
|
||||
|
|
|
@ -118,12 +118,8 @@ public:
|
|||
protected:
|
||||
void initColorAttachment(GLTexture *colorAttachment);
|
||||
void initDepthStencilAttachment();
|
||||
|
||||
private:
|
||||
bool bind();
|
||||
|
||||
inline static QStack<GLFramebuffer *> s_fbos;
|
||||
|
||||
GLuint m_handle = 0;
|
||||
GLuint m_depthBuffer = 0;
|
||||
GLuint m_stencilBuffer = 0;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
#include "openglcontext.h"
|
||||
#include "glframebuffer.h"
|
||||
#include "glplatform.h"
|
||||
#include "glvertexbuffer.h"
|
||||
#include "utils/common.h"
|
||||
|
@ -429,4 +430,32 @@ void OpenGlContext::glGetnUniformfv(GLuint program, GLint location, GLsizei bufS
|
|||
glGetUniformfv(program, location, params);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGlContext::pushFramebuffer(GLFramebuffer *fbo)
|
||||
{
|
||||
if (fbo != currentFramebuffer()) {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo->handle());
|
||||
glViewport(0, 0, fbo->size().width(), fbo->size().height());
|
||||
}
|
||||
m_fbos.push(fbo);
|
||||
}
|
||||
|
||||
GLFramebuffer *OpenGlContext::popFramebuffer()
|
||||
{
|
||||
const auto ret = m_fbos.pop();
|
||||
if (const auto fbo = currentFramebuffer(); fbo != ret) {
|
||||
if (fbo) {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo->handle());
|
||||
glViewport(0, 0, fbo->size().width(), fbo->size().height());
|
||||
} else {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
GLFramebuffer *OpenGlContext::currentFramebuffer()
|
||||
{
|
||||
return m_fbos.empty() ? nullptr : m_fbos.top();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include <QByteArray>
|
||||
#include <QSet>
|
||||
#include <QStack>
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
@ -77,6 +78,10 @@ public:
|
|||
void glReadnPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, GLvoid *data);
|
||||
void glGetnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params);
|
||||
|
||||
void pushFramebuffer(GLFramebuffer *fbo);
|
||||
GLFramebuffer *popFramebuffer();
|
||||
GLFramebuffer *currentFramebuffer();
|
||||
|
||||
static OpenGlContext *currentContext();
|
||||
|
||||
protected:
|
||||
|
@ -120,6 +125,7 @@ protected:
|
|||
ShaderManager *m_shaderManager = nullptr;
|
||||
GLVertexBuffer *m_streamingBuffer = nullptr;
|
||||
IndexBuffer *m_indexBuffer = nullptr;
|
||||
QStack<GLFramebuffer *> m_fbos;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue