libkwineffects: add a lookup table class
This commit is contained in:
parent
b200a3180f
commit
1f8a1a0788
3 changed files with 112 additions and 3 deletions
|
@ -109,6 +109,7 @@ target_sources(kwin PRIVATE
|
|||
libkwineffects/colorspace.cpp
|
||||
libkwineffects/effecttogglablestate.cpp
|
||||
libkwineffects/glframebuffer.cpp
|
||||
libkwineffects/gllut.cpp
|
||||
libkwineffects/glplatform.cpp
|
||||
libkwineffects/glshader.cpp
|
||||
libkwineffects/glshadermanager.cpp
|
||||
|
@ -122,11 +123,8 @@ target_sources(kwin PRIVATE
|
|||
libkwineffects/kwinoffscreenquickview.cpp
|
||||
libkwineffects/kwinquickeffect.cpp
|
||||
libkwineffects/logging.cpp
|
||||
libkwineffects/logging.cpp
|
||||
libkwineffects/openglcontext.cpp
|
||||
libkwineffects/rendertarget.cpp
|
||||
libkwineffects/rendertarget.cpp
|
||||
libkwineffects/renderviewport.cpp
|
||||
libkwineffects/renderviewport.cpp
|
||||
libkwineffects/version.cpp
|
||||
lidswitchtracker.cpp
|
||||
|
@ -433,6 +431,7 @@ install(FILES
|
|||
install(FILES
|
||||
libkwineffects/colorspace.h
|
||||
libkwineffects/glframebuffer.h
|
||||
libkwineffects/gllut.h
|
||||
libkwineffects/glplatform.h
|
||||
libkwineffects/glshader.h
|
||||
libkwineffects/glshadermanager.h
|
||||
|
|
70
src/libkwineffects/gllut.cpp
Normal file
70
src/libkwineffects/gllut.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
SPDX-FileCopyrightText: 2023 Xaver Hugl <xaver.hugl@gmail.com>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
#include "gllut.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
GlLookUpTable::GlLookUpTable(GLuint handle, size_t size)
|
||||
: m_handle(handle)
|
||||
, m_size(size)
|
||||
{
|
||||
}
|
||||
|
||||
GlLookUpTable::~GlLookUpTable()
|
||||
{
|
||||
glDeleteTextures(1, &m_handle);
|
||||
}
|
||||
|
||||
GLuint GlLookUpTable::handle() const
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
size_t GlLookUpTable::size() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
void GlLookUpTable::bind()
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_1D, m_handle);
|
||||
}
|
||||
|
||||
std::unique_ptr<GlLookUpTable> GlLookUpTable::create(const std::function<QVector3D(size_t value)> &func, size_t size)
|
||||
{
|
||||
GLuint handle = 0;
|
||||
glGenTextures(1, &handle);
|
||||
if (!handle) {
|
||||
return nullptr;
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_1D, handle);
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAX_LEVEL, 0);
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_LOD, 0);
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAX_LOD, 0);
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
std::vector<float> data;
|
||||
data.reserve(4 * size);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
const auto color = func(i);
|
||||
data.push_back(color.x());
|
||||
data.push_back(color.y());
|
||||
data.push_back(color.z());
|
||||
data.push_back(1);
|
||||
}
|
||||
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA16F, size, 0, GL_RGBA, GL_FLOAT, data.data());
|
||||
glBindTexture(GL_TEXTURE_1D, 0);
|
||||
return std::make_unique<GlLookUpTable>(handle, size);
|
||||
}
|
||||
|
||||
}
|
40
src/libkwineffects/gllut.h
Normal file
40
src/libkwineffects/gllut.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
SPDX-FileCopyrightText: 2023 Xaver Hugl <xaver.hugl@gmail.com>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "kwin_export.h"
|
||||
|
||||
#include <QVector3D>
|
||||
#include <QVector>
|
||||
#include <epoxy/gl.h>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
class KWIN_EXPORT GlLookUpTable
|
||||
{
|
||||
public:
|
||||
explicit GlLookUpTable(GLuint handle, size_t size);
|
||||
~GlLookUpTable();
|
||||
|
||||
GLuint handle() const;
|
||||
size_t size() const;
|
||||
|
||||
void bind();
|
||||
|
||||
static std::unique_ptr<GlLookUpTable> create(const std::function<QVector3D(size_t value)> &func, size_t size);
|
||||
|
||||
private:
|
||||
const GLuint m_handle;
|
||||
const size_t m_size;
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in a new issue