add ability to render textures to Screen quad for dbg

This commit is contained in:
Joakim Kilby
2023-10-12 07:58:01 +02:00
parent 8e0a79bc56
commit 43d8ec2298
4 changed files with 81 additions and 0 deletions

View File

@@ -151,6 +151,8 @@ public:
*/
static scripting::LuaLibrary luaLibrary();
void setDebugTextureRendering(GLuint texture);
glm::ivec2 renderingResolution() const;
glm::ivec2 fontResolution() const;
@@ -176,6 +178,8 @@ private:
ghoul::Dictionary _resolveData;
ScreenLog* _log = nullptr;
GLuint _debugTextureRender = 0;
ghoul::opengl::OpenGLStateCache* _openglStateCache = nullptr;
properties::BoolProperty _showOverlayOnClients;

View File

@@ -0,0 +1,12 @@
#include "fragment.glsl"
uniform sampler2D tex;
in vec2 uv;
Fragment getFragment() {
Fragment frag;
frag.disableLDR2HDR = true;
frag.color = texture(tex, uv).rrrr;
return frag;
}

View File

@@ -0,0 +1,11 @@
#version __CONTEXT__
layout(location=0) in vec2 vertex_position;
out vec2 uv;
void main()
{
uv = 2 * (vertex_position - 0.5);
gl_Position = vec4(vertex_position, 0.0, 1.0);
}

View File

@@ -710,6 +710,56 @@ void RenderEngine::render(const glm::mat4& sceneMatrix, const glm::mat4& viewMat
}
glDisable(GL_BLEND);
}
if (_debugTextureRender > 0) {
static constexpr GLfloat vertices[] = {
0.5f, 0.5f,
1.f, 0.5f,
0.5f, 1.f,
0.5f, 1.f,
1.f, 0.5f,
1.f, 1.f,
};
static GLuint vao = 0, vbo;
static std::unique_ptr<ghoul::opengl::ProgramObject> prog;
if (vao == 0) {
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(
0,
2,
GL_FLOAT,
GL_FALSE,
2 * sizeof(GL_FLOAT),
reinterpret_cast<void*>(0)
);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
prog = buildRenderProgram(
"PlanetaryTrailBlurProgram",
absPath("${MODULE_BASE}/shaders/dbg_tex_vs.glsl"),
absPath("${MODULE_BASE}/shaders/dbg_tex_fs.glsl")
);
}
prog->activate();
prog->setUniform("tex", 0);
glBindTexture(GL_TEXTURE_2D, _debugTextureRender);
glBindVertexArray(vao);
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0);
glBindTexture(GL_TEXTURE_2D, 0);
}
LTRACE("RenderEngine::render(end)");
}
@@ -1032,6 +1082,10 @@ scripting::LuaLibrary RenderEngine::luaLibrary() {
};
}
void RenderEngine::setDebugTextureRendering(GLuint texture) {
_debugTextureRender = texture;
}
void RenderEngine::addScreenSpaceRenderable(std::unique_ptr<ScreenSpaceRenderable> s) {
const std::string identifier = s->identifier();