mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-23 05:19:18 -06:00
Add DebugRenderer enabling easy screen space point rendering
This commit is contained in:
119
modules/debugging/rendering/debugrenderer.cpp
Normal file
119
modules/debugging/rendering/debugrenderer.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/debugging/rendering/debugrenderer.h>
|
||||
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
|
||||
#include <ghoul/misc/assert.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "DebugRenderer";
|
||||
}
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
std::shared_ptr<DebugRenderer> DebugRenderer::_singleton = nullptr;
|
||||
|
||||
|
||||
DebugRenderer::DebugRenderer() {
|
||||
_programObject = OsEng.renderEngine().buildRenderProgram(
|
||||
"BasicDebugShader",
|
||||
"${MODULE_DEBUGGING}/rendering/debugshader_vs.glsl",
|
||||
"${MODULE_DEBUGGING}/rendering/debugshader_fs.glsl"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<DebugRenderer> DebugRenderer::ref() {
|
||||
if (_singleton == nullptr) {
|
||||
try {
|
||||
_singleton = std::make_shared<DebugRenderer>();
|
||||
}
|
||||
catch (const ShaderObject::ShaderCompileError& e) {
|
||||
LERROR(e.what());
|
||||
}
|
||||
}
|
||||
return _singleton;
|
||||
}
|
||||
|
||||
void DebugRenderer::renderScreenSpace(const std::vector<glm::vec3>& clippingSpacePoints, GLenum mode, glm::vec4 rgba) const {
|
||||
if (clippingSpacePoints.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
GLuint _vaoID;
|
||||
glGenVertexArrays(1, &_vaoID);
|
||||
ghoul_assert(_vaoID != 0, "Could not generate vertex arrays");
|
||||
|
||||
GLuint _vertexBufferID;
|
||||
glGenBuffers(1, &_vertexBufferID);
|
||||
ghoul_assert(_vertexBufferID != 0, "Could not create vertex buffer");
|
||||
|
||||
_programObject->activate();
|
||||
_programObject->setUniform("color", rgba);
|
||||
|
||||
|
||||
glBindVertexArray(_vaoID);
|
||||
|
||||
|
||||
// Vertex buffer
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferID);
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
clippingSpacePoints.size() * sizeof(clippingSpacePoints[0]),
|
||||
&clippingSpacePoints[0],
|
||||
GL_STATIC_DRAW);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(clippingSpacePoints[0]), 0);
|
||||
|
||||
// uniforms
|
||||
|
||||
|
||||
|
||||
glDrawArrays(mode, 0, clippingSpacePoints.size());
|
||||
GLenum error = glGetError();
|
||||
if (error != GL_NO_ERROR) {
|
||||
LERROR(error);
|
||||
}
|
||||
|
||||
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
glDeleteVertexArrays(1, &_vaoID);
|
||||
glDeleteBuffers(1, &_vertexBufferID);
|
||||
_programObject->deactivate();
|
||||
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
69
modules/debugging/rendering/debugrenderer.h
Normal file
69
modules/debugging/rendering/debugrenderer.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __DEBUG_RENDERER_H__
|
||||
#define __DEBUG_RENDERER_H__
|
||||
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
|
||||
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
namespace openspace {
|
||||
using namespace ghoul::opengl;
|
||||
|
||||
|
||||
class DebugRenderer {
|
||||
public:
|
||||
DebugRenderer();
|
||||
|
||||
static std::shared_ptr<DebugRenderer> ref();
|
||||
|
||||
|
||||
void renderScreenSpace(const std::vector<glm::vec3>& clippingSpacePoints, GLenum mode, glm::vec4 rgb = {1,0,0,1}) const;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
std::unique_ptr<ProgramObject> _programObject;
|
||||
|
||||
|
||||
static std::shared_ptr<DebugRenderer> _singleton;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
|
||||
#endif // __DEBUG_RENDERER_H__
|
||||
38
modules/debugging/rendering/debugshader_fs.glsl
Normal file
38
modules/debugging/rendering/debugshader_fs.glsl
Normal file
@@ -0,0 +1,38 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include "fragment.glsl"
|
||||
#include "PowerScaling/powerScalingMath.hglsl"
|
||||
|
||||
in vec3 fs_vertexPosition;
|
||||
|
||||
uniform vec4 color;
|
||||
|
||||
Fragment getFragment(){
|
||||
Fragment frag;
|
||||
frag.color = color;
|
||||
vec4 p = z_normalization(vec4(fs_vertexPosition, 1));
|
||||
frag.depth = p.z;
|
||||
return frag;
|
||||
}
|
||||
33
modules/debugging/rendering/debugshader_vs.glsl
Normal file
33
modules/debugging/rendering/debugshader_vs.glsl
Normal file
@@ -0,0 +1,33 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
#version __CONTEXT__
|
||||
|
||||
layout(location = 0) in vec3 vertexPosition;
|
||||
|
||||
out vec3 fs_vertexPosition;
|
||||
|
||||
void main(){
|
||||
fs_vertexPosition = vertexPosition;
|
||||
gl_Position = vec4(vertexPosition, 1);
|
||||
}
|
||||
Reference in New Issue
Block a user