Currently job artifacts in CI/CD pipelines on LRZ GitLab never expire. Starting from Wed 26.1.2022 the default expiration time will be 30 days (GitLab default). Currently existing artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

Commit 35c0f343 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Two improvements:

* MultiIndexedGeometry supports instanced rendering
* FontAtlas supports writing picking information
parent 35531771
...@@ -59,8 +59,6 @@ namespace campvis { ...@@ -59,8 +59,6 @@ namespace campvis {
MultiIndexedGeometry::MultiIndexedGeometry(const MultiIndexedGeometry& rhs) MultiIndexedGeometry::MultiIndexedGeometry(const MultiIndexedGeometry& rhs)
: GeometryData(rhs) : GeometryData(rhs)
, _indices(rhs._indices) , _indices(rhs._indices)
, _offsets(rhs._offsets)
, _counts(rhs._counts)
, _vertices(rhs._vertices) , _vertices(rhs._vertices)
, _textureCoordinates(rhs._textureCoordinates) , _textureCoordinates(rhs._textureCoordinates)
, _colors(rhs._colors) , _colors(rhs._colors)
...@@ -80,8 +78,6 @@ namespace campvis { ...@@ -80,8 +78,6 @@ namespace campvis {
GeometryData::operator=(rhs); GeometryData::operator=(rhs);
_indices = rhs._indices; _indices = rhs._indices;
_offsets = rhs._offsets;
_counts = rhs._counts;
_vertices = rhs._vertices; _vertices = rhs._vertices;
_textureCoordinates = rhs._textureCoordinates; _textureCoordinates = rhs._textureCoordinates;
...@@ -97,8 +93,6 @@ namespace campvis { ...@@ -97,8 +93,6 @@ namespace campvis {
MultiIndexedGeometry* MultiIndexedGeometry::clone() const { MultiIndexedGeometry* MultiIndexedGeometry::clone() const {
MultiIndexedGeometry* toReturn = new MultiIndexedGeometry(_vertices, _textureCoordinates, _colors, _normals); MultiIndexedGeometry* toReturn = new MultiIndexedGeometry(_vertices, _textureCoordinates, _colors, _normals);
toReturn->_indices = _indices; toReturn->_indices = _indices;
toReturn->_offsets = _offsets;
toReturn->_counts = _counts;
return toReturn; return toReturn;
} }
...@@ -121,12 +115,11 @@ namespace campvis { ...@@ -121,12 +115,11 @@ namespace campvis {
} }
void MultiIndexedGeometry::addPrimitive(const std::vector<uint16_t>& indices) { void MultiIndexedGeometry::addPrimitive(const std::vector<uint16_t>& indices) {
_offsets.push_back(reinterpret_cast<void*>(_indices.size() * 2)); if (! _indices.empty())
_counts.push_back(static_cast<GLsizei>(indices.size())); _indices.push_back(65535);
_indices.insert(_indices.end(), indices.begin(), indices.end());
_indices.insert(_indices.end(), indices.begin(), indices.end());
_buffersDirty = true; _buffersDirty = true;
} }
const std::vector<cgt::col4>& MultiIndexedGeometry::getPickingInformation() const { const std::vector<cgt::col4>& MultiIndexedGeometry::getPickingInformation() const {
...@@ -140,7 +133,38 @@ namespace campvis { ...@@ -140,7 +133,38 @@ namespace campvis {
} }
void MultiIndexedGeometry::render(GLenum mode) const { void MultiIndexedGeometry::render(GLenum mode) const {
if (_counts.empty()) if (_indices.empty())
return;
createGLBuffers();
if (_buffersDirty) {
LERROR("Cannot render without initialized OpenGL buffers.");
return;
}
cgt::VertexArrayObject vao;
if (_verticesBuffer)
vao.setVertexAttributePointer(0, _verticesBuffer);
if (_texCoordsBuffer)
vao.setVertexAttributePointer(1, _texCoordsBuffer);
if (_colorsBuffer)
vao.setVertexAttributePointer(2, _colorsBuffer);
if (_normalsBuffer)
vao.setVertexAttributePointer(3, _normalsBuffer);
if (_pickingBuffer)
vao.setVertexAttributePointer(4, _pickingBuffer);
vao.bindIndexBuffer(_indicesBuffer);
glEnable(GL_PRIMITIVE_RESTART);
glPrimitiveRestartIndex(65535);
glDrawElements(mode, static_cast<GLsizei>(_indices.size()), GL_UNSIGNED_SHORT, 0);
glDisable(GL_PRIMITIVE_RESTART);
LGL_ERROR;
}
void MultiIndexedGeometry::renderInstanced(GLsizei count, GLenum mode /*= GL_TRIANGLE_FAN*/) const {
if (_indices.empty())
return; return;
createGLBuffers(); createGLBuffers();
...@@ -162,8 +186,10 @@ namespace campvis { ...@@ -162,8 +186,10 @@ namespace campvis {
vao.setVertexAttributePointer(4, _pickingBuffer); vao.setVertexAttributePointer(4, _pickingBuffer);
vao.bindIndexBuffer(_indicesBuffer); vao.bindIndexBuffer(_indicesBuffer);
const GLvoid** ptr = (const GLvoid**)(&_offsets.front()); // <- hidden reinterpret_cast<const GLvoid**> here, ugly OpenGL... glEnable(GL_PRIMITIVE_RESTART);
glMultiDrawElements(mode, &_counts.front(), GL_UNSIGNED_SHORT, ptr, static_cast<GLsizei>(_offsets.size())); glPrimitiveRestartIndex(65535);
glDrawElementsInstanced(mode, static_cast<GLsizei>(_indices.size()), GL_UNSIGNED_SHORT, 0, count);
glDisable(GL_PRIMITIVE_RESTART);
LGL_ERROR; LGL_ERROR;
} }
......
...@@ -110,6 +110,14 @@ namespace campvis { ...@@ -110,6 +110,14 @@ namespace campvis {
*/ */
virtual void render(GLenum mode) const; virtual void render(GLenum mode) const;
/**
* Renders multiple instances of this GeometryData.
* Must be called from a valid OpenGL context.
* \param count Number of instances
* \param mode OpenGL rendering mode
*/
virtual void renderInstanced(GLsizei count, GLenum mode = GL_TRIANGLE_FAN) const;
/// \see GeometryData::getWorldBounds /// \see GeometryData::getWorldBounds
virtual cgt::Bounds getWorldBounds() const; virtual cgt::Bounds getWorldBounds() const;
/// \see GeometryData::hasTextureCoordinates /// \see GeometryData::hasTextureCoordinates
...@@ -130,8 +138,6 @@ namespace campvis { ...@@ -130,8 +138,6 @@ namespace campvis {
void deleteIndicesBuffer() const; void deleteIndicesBuffer() const;
std::vector<uint16_t> _indices; ///< Index list defining the faces std::vector<uint16_t> _indices; ///< Index list defining the faces
std::vector<void*> _offsets; ///< Byte offsets for each primitive to render
std::vector<GLsizei> _counts; ///< Numer of vertices for each primitive to render
std::vector<cgt::vec3> _vertices; ///< The list of the vertex positions of the face. std::vector<cgt::vec3> _vertices; ///< The list of the vertex positions of the face.
std::vector<cgt::vec3> _textureCoordinates; ///< The list of vertex texture coordinates, may be empty. std::vector<cgt::vec3> _textureCoordinates; ///< The list of vertex texture coordinates, may be empty.
......
...@@ -25,11 +25,17 @@ IF(${ModuleEnabled}) ...@@ -25,11 +25,17 @@ IF(${ModuleEnabled})
# Header files (including GLSL files so that they'll appear in VS projects) # Header files (including GLSL files so that they'll appear in VS projects)
FILE(GLOB ThisModHeaders RELATIVE ${ModulesDir} FILE(GLOB ThisModHeaders RELATIVE ${ModulesDir}
modules/fontrendering/glsl/*.frag
modules/fontrendering/glsl/*.geom
modules/fontrendering/glsl/*.vert
modules/fontrendering/pipelines/*.h modules/fontrendering/pipelines/*.h
modules/fontrendering/processors/*.h modules/fontrendering/processors/*.h
modules/fontrendering/tools/*.h modules/fontrendering/tools/*.h
) )
LIST (APPEND ThisModShaderDirectories "modules/fontrendering/fonts")
LIST (APPEND ThisModShaderDirectories "modules/fontrendering/glsl")
SET(ThisModDependencies base) SET(ThisModDependencies base)
ENDIF(${ModuleEnabled}) ENDIF(${ModuleEnabled})
......
...@@ -23,11 +23,15 @@ ...@@ -23,11 +23,15 @@
// ================================================================================================ // ================================================================================================
in vec3 ex_TexCoord; in vec3 ex_TexCoord;
out vec4 out_Color;
layout(location = 0) out vec4 out_Color;
layout(location = 1) out vec4 out_Picking;
uniform sampler2D _fontTexture; uniform sampler2D _fontTexture;
uniform vec4 _color = vec4(1.0, 1.0, 1.0, 1.0); uniform vec4 _color = vec4(1.0, 1.0, 1.0, 1.0);
uniform vec4 _pickingColor = vec4(0.0);
void main() { void main() {
out_Color = vec4(texture2D(_fontTexture, ex_TexCoord.xy).r) * _color; out_Color = vec4(texture2D(_fontTexture, ex_TexCoord.xy).r) * _color;
out_Picking = _pickingColor;
} }
...@@ -196,5 +196,13 @@ namespace campvis { ...@@ -196,5 +196,13 @@ namespace campvis {
LGL_ERROR; LGL_ERROR;
} }
void FontAtlas::renderTextWithPickingInformation(const std::string& text, const cgt::vec2& position, const cgt::vec4& color, const cgt::vec4& pickingInfo, const cgt::mat4& transformationMatrix /*= cgt::mat4::identity*/) {
_shader->activate();
_shader->setUniform("_pickingColor", pickingInfo);
_shader->deactivate();
renderText(text, position, color, transformationMatrix);
}
} }
} }
...@@ -82,6 +82,18 @@ namespace fontrendering { ...@@ -82,6 +82,18 @@ namespace fontrendering {
*/ */
void renderText(const std::string& text, const cgt::vec2& position, const cgt::vec4& color, const cgt::mat4& transformationMatrix = cgt::mat4::identity); void renderText(const std::string& text, const cgt::vec2& position, const cgt::vec4& color, const cgt::mat4& transformationMatrix = cgt::mat4::identity);
/**
* Renders the given text with the given parameters into the current framebuffer.
* \param text The text to render (currently only ASCII-256 support).
* \param position Position where to start rendering the text (in normalized [-1, 1] coordinates).
* \param color Color of the text to render.
* \param pickingInformation Color to render into the picking info texture (second FBO color attachment).
* \param transformationMatrix Additional transformation matrix that is applied to each rendered vertex.
*/
void renderTextWithPickingInformation(const std::string& text, const cgt::vec2& position, const cgt::vec4& color, const cgt::vec4& pickingInfo, const cgt::mat4& transformationMatrix = cgt::mat4::identity);
private: private:
/// Struct storing glyph parameters of each printable ASCII character /// Struct storing glyph parameters of each printable ASCII character
struct { struct {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment