mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-14 17:40:26 -05: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
|
||||
Reference in New Issue
Block a user