libkwineffects: align variable naming to the rest of KWin

This commit is contained in:
Xaver Hugl 2023-09-07 00:07:13 +02:00
parent 27f90476b4
commit f2dd1b3471
4 changed files with 114 additions and 120 deletions

View file

@ -19,22 +19,16 @@
namespace KWin
{
bool GLFramebuffer::sSupported = false;
bool GLFramebuffer::sSupportsPackedDepthStencil = false;
bool GLFramebuffer::sSupportsDepth24 = false;
bool GLFramebuffer::s_blitSupported = false;
QStack<GLFramebuffer *> GLFramebuffer::s_fbos = QStack<GLFramebuffer *>();
void GLFramebuffer::initStatic()
{
if (GLPlatform::instance()->isGLES()) {
sSupported = true;
sSupportsPackedDepthStencil = hasGLVersion(3, 0) || hasGLExtension(QByteArrayLiteral("GL_OES_packed_depth_stencil"));
sSupportsDepth24 = hasGLVersion(3, 0) || hasGLExtension(QByteArrayLiteral("GL_OES_depth24"));
s_supported = true;
s_supportsPackedDepthStencil = hasGLVersion(3, 0) || hasGLExtension(QByteArrayLiteral("GL_OES_packed_depth_stencil"));
s_supportsDepth24 = hasGLVersion(3, 0) || hasGLExtension(QByteArrayLiteral("GL_OES_depth24"));
s_blitSupported = hasGLVersion(3, 0);
} else {
sSupported = hasGLVersion(3, 0) || hasGLExtension(QByteArrayLiteral("GL_ARB_framebuffer_object")) || hasGLExtension(QByteArrayLiteral("GL_EXT_framebuffer_object"));
sSupportsPackedDepthStencil = hasGLVersion(3, 0) || hasGLExtension(QByteArrayLiteral("GL_ARB_framebuffer_object")) || hasGLExtension(QByteArrayLiteral("GL_EXT_packed_depth_stencil"));
s_supported = hasGLVersion(3, 0) || hasGLExtension(QByteArrayLiteral("GL_ARB_framebuffer_object")) || hasGLExtension(QByteArrayLiteral("GL_EXT_framebuffer_object"));
s_supportsPackedDepthStencil = hasGLVersion(3, 0) || hasGLExtension(QByteArrayLiteral("GL_ARB_framebuffer_object")) || hasGLExtension(QByteArrayLiteral("GL_EXT_packed_depth_stencil"));
s_blitSupported = hasGLVersion(3, 0) || hasGLExtension(QByteArrayLiteral("GL_ARB_framebuffer_object")) || hasGLExtension(QByteArrayLiteral("GL_EXT_framebuffer_blit"));
}
}
@ -42,7 +36,7 @@ void GLFramebuffer::initStatic()
void GLFramebuffer::cleanup()
{
Q_ASSERT(s_fbos.isEmpty());
sSupported = false;
s_supported = false;
s_blitSupported = false;
}
@ -112,10 +106,10 @@ static QString formatFramebufferStatus(GLenum status)
}
GLFramebuffer::GLFramebuffer(GLTexture *colorAttachment, Attachment attachment)
: mSize(colorAttachment->size())
: m_size(colorAttachment->size())
, m_colorAttachment(colorAttachment)
{
if (!sSupported) {
if (!s_supported) {
qCCritical(LIBKWINGLUTILS) << "Framebuffer objects aren't supported!";
return;
}
@ -125,8 +119,8 @@ GLFramebuffer::GLFramebuffer(GLTexture *colorAttachment, Attachment attachment)
prevFbo = current->handle();
}
glGenFramebuffers(1, &mFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
glGenFramebuffers(1, &m_handle);
glBindFramebuffer(GL_FRAMEBUFFER, m_handle);
initColorAttachment(colorAttachment);
if (attachment == Attachment::CombinedDepthStencil) {
@ -139,32 +133,32 @@ GLFramebuffer::GLFramebuffer(GLTexture *colorAttachment, Attachment attachment)
if (status != GL_FRAMEBUFFER_COMPLETE) {
// We have an incomplete framebuffer, consider it invalid
qCCritical(LIBKWINGLUTILS) << "Invalid framebuffer status: " << formatFramebufferStatus(status);
glDeleteFramebuffers(1, &mFramebuffer);
glDeleteFramebuffers(1, &m_handle);
return;
}
mValid = true;
m_valid = true;
}
GLFramebuffer::GLFramebuffer(GLuint handle, const QSize &size)
: mFramebuffer(handle)
, mSize(size)
, mValid(true)
, mForeign(true)
: m_handle(handle)
, m_size(size)
, m_valid(true)
, m_foreign(true)
, m_colorAttachment(nullptr)
{
}
GLFramebuffer::~GLFramebuffer()
{
if (!mForeign && mValid) {
glDeleteFramebuffers(1, &mFramebuffer);
if (!m_foreign && m_valid) {
glDeleteFramebuffers(1, &m_handle);
}
if (mDepthBuffer) {
glDeleteRenderbuffers(1, &mDepthBuffer);
if (m_depthBuffer) {
glDeleteRenderbuffers(1, &m_depthBuffer);
}
if (mStencilBuffer && mStencilBuffer != mDepthBuffer) {
glDeleteRenderbuffers(1, &mStencilBuffer);
if (m_stencilBuffer && m_stencilBuffer != m_depthBuffer) {
glDeleteRenderbuffers(1, &m_stencilBuffer);
}
}
@ -176,7 +170,7 @@ bool GLFramebuffer::bind()
}
glBindFramebuffer(GL_FRAMEBUFFER, handle());
glViewport(0, 0, mSize.width(), mSize.height());
glViewport(0, 0, m_size.width(), m_size.height());
return true;
}
@ -192,18 +186,18 @@ void GLFramebuffer::initDepthStencilAttachment()
GLuint buffer = 0;
// Try to attach a depth/stencil combined attachment.
if (sSupportsPackedDepthStencil) {
if (s_supportsPackedDepthStencil) {
glGenRenderbuffers(1, &buffer);
glBindRenderbuffer(GL_RENDERBUFFER, buffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, mSize.width(), mSize.height());
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, m_size.width(), m_size.height());
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, buffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, buffer);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
glDeleteRenderbuffers(1, &buffer);
} else {
mDepthBuffer = buffer;
mStencilBuffer = buffer;
m_depthBuffer = buffer;
m_stencilBuffer = buffer;
return;
}
}
@ -211,7 +205,7 @@ void GLFramebuffer::initDepthStencilAttachment()
// Try to attach a depth attachment separately.
GLenum depthFormat;
if (GLPlatform::instance()->isGLES()) {
if (sSupportsDepth24) {
if (s_supportsDepth24) {
depthFormat = GL_DEPTH_COMPONENT24;
} else {
depthFormat = GL_DEPTH_COMPONENT16;
@ -222,12 +216,12 @@ void GLFramebuffer::initDepthStencilAttachment()
glGenRenderbuffers(1, &buffer);
glBindRenderbuffer(GL_RENDERBUFFER, buffer);
glRenderbufferStorage(GL_RENDERBUFFER, depthFormat, mSize.width(), mSize.height());
glRenderbufferStorage(GL_RENDERBUFFER, depthFormat, m_size.width(), m_size.height());
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, buffer);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
glDeleteRenderbuffers(1, &buffer);
} else {
mDepthBuffer = buffer;
m_depthBuffer = buffer;
}
// Try to attach a stencil attachment separately.
@ -240,12 +234,12 @@ void GLFramebuffer::initDepthStencilAttachment()
glGenRenderbuffers(1, &buffer);
glBindRenderbuffer(GL_RENDERBUFFER, buffer);
glRenderbufferStorage(GL_RENDERBUFFER, stencilFormat, mSize.width(), mSize.height());
glRenderbufferStorage(GL_RENDERBUFFER, stencilFormat, m_size.width(), m_size.height());
glFramebufferRenderbuffer(GL_RENDERBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, buffer);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
glDeleteRenderbuffers(1, &buffer);
} else {
mStencilBuffer = buffer;
m_stencilBuffer = buffer;
}
}
@ -276,9 +270,9 @@ void GLFramebuffer::blitFromFramebuffer(const QRect &source, const QRect &destin
}
const GLuint dstX0 = d.x();
const GLuint dstY0 = mSize.height() - (d.y() + d.height());
const GLuint dstY0 = m_size.height() - (d.y() + d.height());
const GLuint dstX1 = d.x() + d.width();
const GLuint dstY1 = mSize.height() - d.y();
const GLuint dstY1 = m_size.height() - d.y();
glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, GL_COLOR_BUFFER_BIT, filter);

View file

@ -67,24 +67,24 @@ public:
*/
GLuint handle() const
{
return mFramebuffer;
return m_handle;
}
/**
* Returns the size of the color attachment to this framebuffer object.
*/
QSize size() const
{
return mSize;
return m_size;
}
bool valid() const
{
return mValid;
return m_valid;
}
static void initStatic();
static bool supported()
{
return sSupported;
return s_supported;
}
/**
@ -138,18 +138,18 @@ private:
friend void KWin::cleanupGL();
static void cleanup();
static bool sSupported;
static bool sSupportsPackedDepthStencil;
static bool sSupportsDepth24;
static bool s_blitSupported;
static QStack<GLFramebuffer *> s_fbos;
inline static bool s_supported = false;
inline static bool s_supportsPackedDepthStencil = false;
inline static bool s_supportsDepth24 = false;
inline static bool s_blitSupported = false;
inline static QStack<GLFramebuffer *> s_fbos;
GLuint mFramebuffer = 0;
GLuint mDepthBuffer = 0;
GLuint mStencilBuffer = 0;
QSize mSize;
bool mValid = false;
bool mForeign = false;
GLuint m_handle = 0;
GLuint m_depthBuffer = 0;
GLuint m_stencilBuffer = 0;
QSize m_size;
bool m_valid = false;
bool m_foreign = false;
GLTexture *const m_colorAttachment;
};

View file

@ -19,26 +19,26 @@ namespace KWin
{
GLShader::GLShader(unsigned int flags)
: mValid(false)
, mLocationsResolved(false)
, mExplicitLinking(flags & ExplicitLinking)
: m_valid(false)
, m_locationsResolved(false)
, m_explicitLinking(flags & ExplicitLinking)
{
mProgram = glCreateProgram();
m_program = glCreateProgram();
}
GLShader::GLShader(const QString &vertexfile, const QString &fragmentfile, unsigned int flags)
: mValid(false)
, mLocationsResolved(false)
, mExplicitLinking(flags & ExplicitLinking)
: m_valid(false)
, m_locationsResolved(false)
, m_explicitLinking(flags & ExplicitLinking)
{
mProgram = glCreateProgram();
m_program = glCreateProgram();
loadFromFiles(vertexfile, fragmentfile);
}
GLShader::~GLShader()
{
if (mProgram) {
glDeleteProgram(mProgram);
if (m_program) {
glDeleteProgram(m_program);
}
}
@ -64,31 +64,31 @@ bool GLShader::loadFromFiles(const QString &vertexFile, const QString &fragmentF
bool GLShader::link()
{
// Be optimistic
mValid = true;
m_valid = true;
glLinkProgram(mProgram);
glLinkProgram(m_program);
// Get the program info log
int maxLength, length;
glGetProgramiv(mProgram, GL_INFO_LOG_LENGTH, &maxLength);
glGetProgramiv(m_program, GL_INFO_LOG_LENGTH, &maxLength);
QByteArray log(maxLength, 0);
glGetProgramInfoLog(mProgram, maxLength, &length, log.data());
glGetProgramInfoLog(m_program, maxLength, &length, log.data());
// Make sure the program linked successfully
int status;
glGetProgramiv(mProgram, GL_LINK_STATUS, &status);
glGetProgramiv(m_program, GL_LINK_STATUS, &status);
if (status == 0) {
qCCritical(LIBKWINGLUTILS) << "Failed to link shader:"
<< "\n"
<< log;
mValid = false;
m_valid = false;
} else if (length > 0) {
qCDebug(LIBKWINGLUTILS) << "Shader link log:" << log;
}
return mValid;
return m_valid;
}
const QByteArray GLShader::prepareSource(GLenum shaderType, const QByteArray &source) const
@ -155,11 +155,11 @@ bool GLShader::load(const QByteArray &vertexSource, const QByteArray &fragmentSo
return false;
}
mValid = false;
m_valid = false;
// Compile the vertex shader
if (!vertexSource.isEmpty()) {
bool success = compile(mProgram, GL_VERTEX_SHADER, vertexSource);
bool success = compile(m_program, GL_VERTEX_SHADER, vertexSource);
if (!success) {
return false;
@ -168,14 +168,14 @@ bool GLShader::load(const QByteArray &vertexSource, const QByteArray &fragmentSo
// Compile the fragment shader
if (!fragmentSource.isEmpty()) {
bool success = compile(mProgram, GL_FRAGMENT_SHADER, fragmentSource);
bool success = compile(m_program, GL_FRAGMENT_SHADER, fragmentSource);
if (!success) {
return false;
}
}
if (mExplicitLinking) {
if (m_explicitLinking) {
return true;
}
@ -185,19 +185,19 @@ bool GLShader::load(const QByteArray &vertexSource, const QByteArray &fragmentSo
void GLShader::bindAttributeLocation(const char *name, int index)
{
glBindAttribLocation(mProgram, index, name);
glBindAttribLocation(m_program, index, name);
}
void GLShader::bindFragDataLocation(const char *name, int index)
{
if (!GLPlatform::instance()->isGLES() && (hasGLVersion(3, 0) || hasGLExtension(QByteArrayLiteral("GL_EXT_gpu_shader4")))) {
glBindFragDataLocation(mProgram, index, name);
glBindFragDataLocation(m_program, index, name);
}
}
void GLShader::bind()
{
glUseProgram(mProgram);
glUseProgram(m_program);
}
void GLShader::unbind()
@ -207,60 +207,60 @@ void GLShader::unbind()
void GLShader::resolveLocations()
{
if (mLocationsResolved) {
if (m_locationsResolved) {
return;
}
mMatrixLocation[TextureMatrix] = uniformLocation("textureMatrix");
mMatrixLocation[ProjectionMatrix] = uniformLocation("projection");
mMatrixLocation[ModelViewMatrix] = uniformLocation("modelview");
mMatrixLocation[ModelViewProjectionMatrix] = uniformLocation("modelViewProjectionMatrix");
mMatrixLocation[WindowTransformation] = uniformLocation("windowTransformation");
mMatrixLocation[ScreenTransformation] = uniformLocation("screenTransformation");
mMatrixLocation[ColorimetryTransformation] = uniformLocation("colorimetryTransform");
m_matrixLocation[TextureMatrix] = uniformLocation("textureMatrix");
m_matrixLocation[ProjectionMatrix] = uniformLocation("projection");
m_matrixLocation[ModelViewMatrix] = uniformLocation("modelview");
m_matrixLocation[ModelViewProjectionMatrix] = uniformLocation("modelViewProjectionMatrix");
m_matrixLocation[WindowTransformation] = uniformLocation("windowTransformation");
m_matrixLocation[ScreenTransformation] = uniformLocation("screenTransformation");
m_matrixLocation[ColorimetryTransformation] = uniformLocation("colorimetryTransform");
mVec2Location[Offset] = uniformLocation("offset");
m_vec2Location[Offset] = uniformLocation("offset");
m_vec3Locations[Vec3Uniform::PrimaryBrightness] = uniformLocation("primaryBrightness");
mVec4Location[ModulationConstant] = uniformLocation("modulation");
m_vec4Location[ModulationConstant] = uniformLocation("modulation");
mFloatLocation[Saturation] = uniformLocation("saturation");
mFloatLocation[MaxHdrBrightness] = uniformLocation("maxHdrBrightness");
m_floatLocation[Saturation] = uniformLocation("saturation");
m_floatLocation[MaxHdrBrightness] = uniformLocation("maxHdrBrightness");
mColorLocation[Color] = uniformLocation("geometryColor");
m_colorLocation[Color] = uniformLocation("geometryColor");
mIntLocation[TextureWidth] = uniformLocation("textureWidth");
mIntLocation[TextureHeight] = uniformLocation("textureHeight");
mIntLocation[SourceNamedTransferFunction] = uniformLocation("sourceNamedTransferFunction");
mIntLocation[DestinationNamedTransferFunction] = uniformLocation("destinationNamedTransferFunction");
mIntLocation[SdrBrightness] = uniformLocation("sdrBrightness");
m_intLocation[TextureWidth] = uniformLocation("textureWidth");
m_intLocation[TextureHeight] = uniformLocation("textureHeight");
m_intLocation[SourceNamedTransferFunction] = uniformLocation("sourceNamedTransferFunction");
m_intLocation[DestinationNamedTransferFunction] = uniformLocation("destinationNamedTransferFunction");
m_intLocation[SdrBrightness] = uniformLocation("sdrBrightness");
mLocationsResolved = true;
m_locationsResolved = true;
}
int GLShader::uniformLocation(const char *name)
{
const int location = glGetUniformLocation(mProgram, name);
const int location = glGetUniformLocation(m_program, name);
return location;
}
bool GLShader::setUniform(MatrixUniform uniform, const QMatrix3x3 &value)
{
resolveLocations();
return setUniform(mMatrixLocation[uniform], value);
return setUniform(m_matrixLocation[uniform], value);
}
bool GLShader::setUniform(GLShader::MatrixUniform uniform, const QMatrix4x4 &matrix)
{
resolveLocations();
return setUniform(mMatrixLocation[uniform], matrix);
return setUniform(m_matrixLocation[uniform], matrix);
}
bool GLShader::setUniform(GLShader::Vec2Uniform uniform, const QVector2D &value)
{
resolveLocations();
return setUniform(mVec2Location[uniform], value);
return setUniform(m_vec2Location[uniform], value);
}
bool GLShader::setUniform(Vec3Uniform uniform, const QVector3D &value)
@ -272,31 +272,31 @@ bool GLShader::setUniform(Vec3Uniform uniform, const QVector3D &value)
bool GLShader::setUniform(GLShader::Vec4Uniform uniform, const QVector4D &value)
{
resolveLocations();
return setUniform(mVec4Location[uniform], value);
return setUniform(m_vec4Location[uniform], value);
}
bool GLShader::setUniform(GLShader::FloatUniform uniform, float value)
{
resolveLocations();
return setUniform(mFloatLocation[uniform], value);
return setUniform(m_floatLocation[uniform], value);
}
bool GLShader::setUniform(GLShader::IntUniform uniform, int value)
{
resolveLocations();
return setUniform(mIntLocation[uniform], value);
return setUniform(m_intLocation[uniform], value);
}
bool GLShader::setUniform(GLShader::ColorUniform uniform, const QVector4D &value)
{
resolveLocations();
return setUniform(mColorLocation[uniform], value);
return setUniform(m_colorLocation[uniform], value);
}
bool GLShader::setUniform(GLShader::ColorUniform uniform, const QColor &value)
{
resolveLocations();
return setUniform(mColorLocation[uniform], value);
return setUniform(m_colorLocation[uniform], value);
}
bool GLShader::setUniform(const char *name, float value)
@ -407,7 +407,7 @@ bool GLShader::setUniform(int location, const QColor &color)
int GLShader::attributeLocation(const char *name)
{
int location = glGetAttribLocation(mProgram, name);
int location = glGetAttribLocation(m_program, name);
return location;
}
@ -425,7 +425,7 @@ QMatrix4x4 GLShader::getUniformMatrix4x4(const char *name)
int location = uniformLocation(name);
if (location >= 0) {
GLfloat m[16];
glGetnUniformfv(mProgram, location, sizeof(m), m);
glGetnUniformfv(m_program, location, sizeof(m), m);
QMatrix4x4 matrix(m[0], m[4], m[8], m[12],
m[1], m[5], m[9], m[13],
m[2], m[6], m[10], m[14],

View file

@ -36,7 +36,7 @@ public:
bool isValid() const
{
return mValid;
return m_valid;
}
void bindAttributeLocation(const char *name, int index);
@ -142,17 +142,17 @@ protected:
void resolveLocations();
private:
unsigned int mProgram;
bool mValid : 1;
bool mLocationsResolved : 1;
bool mExplicitLinking : 1;
int mMatrixLocation[MatrixCount];
int mVec2Location[Vec2UniformCount];
unsigned int m_program;
bool m_valid : 1;
bool m_locationsResolved : 1;
bool m_explicitLinking : 1;
int m_matrixLocation[MatrixCount];
int m_vec2Location[Vec2UniformCount];
QHash<Vec3Uniform, int> m_vec3Locations;
int mVec4Location[Vec4UniformCount];
int mFloatLocation[FloatUniformCount];
int mIntLocation[IntUniformCount];
int mColorLocation[ColorUniformCount];
int m_vec4Location[Vec4UniformCount];
int m_floatLocation[FloatUniformCount];
int m_intLocation[IntUniformCount];
int m_colorLocation[ColorUniformCount];
friend class ShaderManager;
};