Skip to content

Commit

Permalink
#5584: Add ability to render a single slot/partition of the surface v…
Browse files Browse the repository at this point in the history
…ertex buffer. This allows us to render the patch highlight overlay using the same buffered data in the shader. We can now get rid of the RenderablePatchSolid helper.
  • Loading branch information
codereader committed Nov 19, 2021
1 parent 8b4fbb7 commit 9bd6664
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 16 deletions.
3 changes: 3 additions & 0 deletions include/isurfacerenderer.h
Expand Up @@ -43,6 +43,9 @@ class ISurfaceRenderer
// Sets the surface data
virtual void updateSurface(Slot slot, const std::vector<ArbitraryMeshVertex>& vertices,
const std::vector<unsigned int>& indices) = 0;

// Submits the geometry of a single surface slot to GL
virtual void renderSurface(Slot slot) = 0;
};

}
3 changes: 0 additions & 3 deletions radiantcore/patch/Patch.cpp
Expand Up @@ -48,7 +48,6 @@ inline bool double_valid(double f) {
Patch::Patch(PatchNode& node) :
_node(node),
_undoStateSaver(nullptr),
_solidRenderable(_mesh),
_renderableNTBVectors(_mesh),
_renderableCtrlPoints(GL_POINTS, _ctrl_vertices),
_renderableLattice(GL_LINES, _latticeIndices, _ctrl_vertices),
Expand All @@ -67,7 +66,6 @@ Patch::Patch(const Patch& other, PatchNode& node) :
IUndoable(other),
_node(node),
_undoStateSaver(nullptr),
_solidRenderable(_mesh),
_renderableNTBVectors(_mesh),
_renderableCtrlPoints(GL_POINTS, _ctrl_vertices),
_renderableLattice(GL_LINES, _latticeIndices, _ctrl_vertices),
Expand Down Expand Up @@ -571,7 +569,6 @@ void Patch::updateTesselation(bool force)
}

_node.onTesselationChanged();
_solidRenderable.queueUpdate();
}

void Patch::invertMatrix()
Expand Down
2 changes: 0 additions & 2 deletions radiantcore/patch/Patch.h
Expand Up @@ -56,8 +56,6 @@ class Patch :
// The tesselation for this patch
PatchTesselation _mesh;

// The OpenGL renderables for three rendering modes
RenderablePatchSolid _solidRenderable;
RenderablePatchVectorsNTB _renderableNTBVectors;

// The shader states for the control points and the lattice
Expand Down
3 changes: 2 additions & 1 deletion radiantcore/patch/PatchNode.cpp
Expand Up @@ -383,7 +383,8 @@ void PatchNode::renderWireframe(IRenderableCollector& collector, const VolumeTes

void PatchNode::renderHighlights(IRenderableCollector& collector, const VolumeTest& volume)
{
collector.addHighlightRenderable(m_patch._solidRenderable, localToWorld());
// Overlay the selected node with the quadrangulated wireframe
collector.addHighlightRenderable(_renderableSurfaceWireframe, localToWorld());

// Render the selected components
renderComponentsSelected(collector, volume);
Expand Down
1 change: 0 additions & 1 deletion radiantcore/patch/PatchNode.h
Expand Up @@ -54,7 +54,6 @@ class PatchNode final :
RenderablePatchTesselation<TesselationIndexer_Quads> _renderableSurfaceWireframe;

public:
// Construct a PatchNode with no arguments
PatchNode(patch::PatchDefType type);

// Copy Constructor
Expand Down
4 changes: 4 additions & 0 deletions radiantcore/patch/PatchRenderables.cpp
@@ -1,5 +1,6 @@
#include "PatchRenderables.h"

#if 0
RenderablePatchSolid::RenderablePatchSolid(PatchTesselation& tess) :
_tess(tess),
_needsUpdate(true)
Expand Down Expand Up @@ -55,6 +56,8 @@ void RenderablePatchSolid::queueUpdate()
{
_needsUpdate = true;
}
#endif

#ifdef RENDERABLE_GEOMETRY
RenderableGeometry::Type RenderablePatchSolid::getType() const
{
Expand Down Expand Up @@ -114,6 +117,7 @@ void RenderablePatchSolid::updateIndices()
}
}
#endif

const ShaderPtr& RenderablePatchVectorsNTB::getShader() const
{
return _shader;
Expand Down
17 changes: 14 additions & 3 deletions radiantcore/patch/PatchRenderables.h
Expand Up @@ -14,6 +14,7 @@
#include "render/VertexBuffer.h"
#include "render/IndexedVertexBuffer.h"

#if 0
/// Helper class to render a PatchTesselation in solid mode
class RenderablePatchSolid :
public OpenGLRenderable
Expand Down Expand Up @@ -51,6 +52,7 @@ class RenderablePatchSolid :
void updateIndices();
#endif
};
#endif

// Renders a vertex' normal/tangent/bitangent vector (for debugging purposes)
class RenderablePatchVectorsNTB :
Expand Down Expand Up @@ -146,16 +148,17 @@ class TesselationIndexer_Quads :
for (std::size_t w = 0; w < tess.width - 1; ++w)
{
outputIt = static_cast<unsigned int>(rowOffset + w);
outputIt = static_cast<unsigned int>(rowOffset + w + 1);
outputIt = static_cast<unsigned int>(rowOffset + w + tess.width + 1);
outputIt = static_cast<unsigned int>(rowOffset + w + tess.width);
outputIt = static_cast<unsigned int>(rowOffset + w + tess.width + 1);
outputIt = static_cast<unsigned int>(rowOffset + w + 1);
}
}
}
};

template<typename TesselationIndexerT>
class RenderablePatchTesselation
class RenderablePatchTesselation :
public OpenGLRenderable
{
private:
static_assert(std::is_base_of_v<ITesselationIndexer, TesselationIndexerT>, "Indexer must implement ITesselationIndexer");
Expand Down Expand Up @@ -224,4 +227,12 @@ class RenderablePatchTesselation
shader->updateSurface(_surfaceSlot, _tess.vertices, indices);
}
}

void render(const RenderInfo& info) const override
{
if (_surfaceSlot != render::ISurfaceRenderer::InvalidSlot && _shader)
{
_shader->renderSurface(_surfaceSlot);
}
}
};
5 changes: 5 additions & 0 deletions radiantcore/rendersystem/backend/OpenGLShader.cpp
Expand Up @@ -225,6 +225,11 @@ void OpenGLShader::updateSurface(ISurfaceRenderer::Slot slot, const std::vector<
SurfaceRenderer::updateSurface(slot, vertices, indices);
}

void OpenGLShader::renderSurface(ISurfaceRenderer::Slot slot)
{
SurfaceRenderer::renderSurface(slot);
}

IWindingRenderer::Slot OpenGLShader::addWinding(const std::vector<ArbitraryMeshVertex>& vertices)
{
return _windingRenderer->addWinding(vertices);
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/rendersystem/backend/OpenGLShader.h
Expand Up @@ -120,7 +120,7 @@ class OpenGLShader final :
void removeSurface(ISurfaceRenderer::Slot slot) override;
void updateSurface(ISurfaceRenderer::Slot slot, const std::vector<ArbitraryMeshVertex>& vertices,
const std::vector<unsigned int>& indices) override;

void renderSurface(ISurfaceRenderer::Slot slot) override;
#ifdef RENDERABLE_GEOMETRY
void addGeometry(RenderableGeometry& geometry) override;
bool hasGeometry() const;
Expand Down
26 changes: 21 additions & 5 deletions radiantcore/rendersystem/backend/SurfaceRenderer.h
Expand Up @@ -11,6 +11,7 @@ class SurfaceRenderer :
private:
struct VertexBuffer
{
GLenum mode;
std::vector<ArbitraryMeshVertex> vertices;
std::vector<unsigned int> indices;
};
Expand All @@ -36,7 +37,10 @@ class SurfaceRenderer :
public:
SurfaceRenderer() :
_freeSlotMappingHint(InvalidSlotMapping)
{}
{
_triangleBuffer.mode = GL_TRIANGLES;
_quadBuffer.mode = GL_QUADS;
}

bool empty() const
{
Expand Down Expand Up @@ -140,21 +144,33 @@ class SurfaceRenderer :

void render()
{
renderBuffer(_triangleBuffer, GL_TRIANGLES);
renderBuffer(_quadBuffer, GL_QUADS);
renderBuffer(_triangleBuffer);
renderBuffer(_quadBuffer);
}

void renderSurface(Slot slot) override
{
auto& slotInfo = _slots.at(slot);
auto& buffer = getBucketByIndex(slotInfo.bucketIndex);

glVertexPointer(3, GL_DOUBLE, sizeof(ArbitraryMeshVertex), &buffer.vertices.at(slotInfo.firstVertex).vertex);
glTexCoordPointer(2, GL_DOUBLE, sizeof(ArbitraryMeshVertex), &buffer.vertices.at(slotInfo.firstVertex).texcoord);
glNormalPointer(GL_DOUBLE, sizeof(ArbitraryMeshVertex), &buffer.vertices.at(slotInfo.firstVertex).normal);

glDrawElements(buffer.mode, static_cast<GLsizei>(buffer.indices.size()), GL_UNSIGNED_INT, &buffer.indices.at(slotInfo.firstIndex));
}

private:

void renderBuffer(const VertexBuffer& buffer, GLenum mode)
void renderBuffer(const VertexBuffer& buffer)
{
if (!buffer.indices.empty())
{
glVertexPointer(3, GL_DOUBLE, sizeof(ArbitraryMeshVertex), &buffer.vertices.front().vertex);
glTexCoordPointer(2, GL_DOUBLE, sizeof(ArbitraryMeshVertex), &buffer.vertices.front().texcoord);
glNormalPointer(GL_DOUBLE, sizeof(ArbitraryMeshVertex), &buffer.vertices.front().normal);

glDrawElements(mode, static_cast<GLsizei>(buffer.indices.size()), GL_UNSIGNED_INT, &buffer.indices.front());
glDrawElements(buffer.mode, static_cast<GLsizei>(buffer.indices.size()), GL_UNSIGNED_INT, &buffer.indices.front());
}
}

Expand Down

0 comments on commit 9bd6664

Please sign in to comment.