Skip to content

Commit

Permalink
#5893: Ongoing work on connecting the geometry store to the renderabl…
Browse files Browse the repository at this point in the history
…e surfaces and geometry.
  • Loading branch information
codereader committed Jan 30, 2022
1 parent 50dcb0a commit 7cb1e03
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/igeometryrenderer.h
Expand Up @@ -53,7 +53,7 @@ class IGeometryRenderer
virtual void renderGeometry(Slot slot) = 0;

// Returns the storage handle to enable the backend renderer to get hold of the indexed vertex data
virtual IGeometryStore::Slot getStorageLocation(Slot slot) = 0;
virtual IGeometryStore::Slot getGeometryStorageLocation(Slot slot) = 0;
};

}
4 changes: 4 additions & 0 deletions include/irenderableobject.h
Expand Up @@ -2,6 +2,7 @@

#include <memory>
#include <sigc++/signal.h>
#include "igeometrystore.h"
#include "math/AABB.h"
#include "math/Matrix4.h"

Expand All @@ -27,6 +28,9 @@ class IRenderableObject
// Emitted when the object bounds have changed,
// because it has been either moved or resized.
virtual sigc::signal<void>& signal_boundsChanged() = 0;

// Returns the key to access the vertex data in the renderer's geometry store
virtual IGeometryStore::Slot getStorageLocation() = 0;
};

}
4 changes: 4 additions & 0 deletions include/isurfacerenderer.h
@@ -1,6 +1,7 @@
#pragma once

#include "irenderableobject.h"
#include "igeometrystore.h"

#include <vector>
#include <limits>
Expand Down Expand Up @@ -61,6 +62,9 @@ class ISurfaceRenderer

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

// Get the key to access the vertex data of this surface within the renderer's backend geometry store
virtual IGeometryStore::Slot getSurfaceStorageLocation(ISurfaceRenderer::Slot slot) = 0;
};

}
10 changes: 10 additions & 0 deletions libs/render/RenderableGeometry.h
Expand Up @@ -66,6 +66,16 @@ class RenderableGeometry :
_bounds = bounds;
signal_boundsChanged().emit();
}

IGeometryStore::Slot getStorageLocation() override
{
if (_owner._surfaceSlot == IGeometryRenderer::InvalidSlot)
{
throw std::logic_error("Cannot access storage of unattached RenderableGeometry");
}

return _owner._shader->getGeometryStorageLocation(_owner._surfaceSlot);
}
};

// Adapater suitable to be attached to an IRenderEntity
Expand Down
52 changes: 50 additions & 2 deletions libs/render/RenderableSurface.h
Expand Up @@ -18,16 +18,25 @@ namespace render
*/
class RenderableSurface :
public IRenderableSurface,
public OpenGLRenderable
public OpenGLRenderable,
public std::enable_shared_from_this<RenderableSurface>
{
private:
using ShaderMapping = std::map<ShaderPtr, ISurfaceRenderer::Slot>;
ShaderMapping _shaders;

sigc::signal<void> _sigBoundsChanged;

// The render entity the adapter is attached to
IRenderEntity* _renderEntity;

// When attached to an entity, this is the backend storage handle
IGeometryStore::Slot _storageLocation;

protected:
RenderableSurface()
RenderableSurface() :
_renderEntity(nullptr),
_storageLocation(std::numeric_limits<IGeometryStore::Slot>::max())
{}

public:
Expand Down Expand Up @@ -73,12 +82,34 @@ class RenderableSurface :
// Removes the surface from all shaders
void detach()
{
// Detach from the render entity when being cleared
detachFromEntity();

while (!_shaders.empty())
{
detachFromShader(_shaders.begin());
}
}

// Attach this geometry to the given render entity.
// This call is only valid if this instance has been attached to the shader first
// Does nothing if already attached to the given render entity.
void attachToEntity(IRenderEntity* entity, const ShaderPtr& shader)
{
assert(_shaders.count(shader) > 0);

if (_renderEntity == entity) return; // nothing to do

if (_renderEntity && entity != _renderEntity)
{
detachFromEntity();
}

_renderEntity = entity;
_renderEntity->addRenderable(shared_from_this(), shader);
_storageLocation = shader->getSurfaceStorageLocation(_shaders[shader]);
}

// Renders the surface stored in our single slot
void render(const RenderInfo& info) const override
{
Expand All @@ -93,7 +124,24 @@ class RenderableSurface :
return _sigBoundsChanged;
}

IGeometryStore::Slot getStorageLocation() override
{
assert(_storageLocation != std::numeric_limits<IGeometryStore::Slot>::max());
return _storageLocation;
}

private:
void detachFromEntity()
{
if (_renderEntity)
{
_renderEntity->removeRenderable(shared_from_this());
_renderEntity = nullptr;
}

_storageLocation = std::numeric_limits<IGeometryStore::Slot>::max();
}

void detachFromShader(const ShaderMapping::iterator& iter)
{
iter->first->removeSurface(iter->second);
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/rendersystem/backend/GeometryRenderer.h
Expand Up @@ -297,7 +297,7 @@ class GeometryRenderer :
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}

IGeometryStore::Slot getStorageLocation(Slot slot) override
IGeometryStore::Slot getGeometryStorageLocation(Slot slot) override
{
return _slots.at(slot).storageHandle;
}
Expand Down
9 changes: 7 additions & 2 deletions radiantcore/rendersystem/backend/OpenGLShader.cpp
Expand Up @@ -167,9 +167,9 @@ void OpenGLShader::renderGeometry(IGeometryRenderer::Slot slot)
_geometryRenderer.renderGeometry(slot);
}

IGeometryStore::Slot OpenGLShader::getStorageLocation(IGeometryRenderer::Slot slot)
IGeometryStore::Slot OpenGLShader::getGeometryStorageLocation(IGeometryRenderer::Slot slot)
{
return _geometryRenderer.getStorageLocation(slot);
return _geometryRenderer.getGeometryStorageLocation(slot);
}

ISurfaceRenderer::Slot OpenGLShader::addSurface(IRenderableSurface& surface)
Expand All @@ -192,6 +192,11 @@ void OpenGLShader::renderSurface(ISurfaceRenderer::Slot slot)
_surfaceRenderer.renderSurface(slot);
}

IGeometryStore::Slot OpenGLShader::getSurfaceStorageLocation(ISurfaceRenderer::Slot slot)
{
return _surfaceRenderer.getSurfaceStorageLocation(slot);
}

IWindingRenderer::Slot OpenGLShader::addWinding(const std::vector<ArbitraryMeshVertex>& vertices)
{
return _windingRenderer->addWinding(vertices);
Expand Down
3 changes: 2 additions & 1 deletion radiantcore/rendersystem/backend/OpenGLShader.h
Expand Up @@ -115,12 +115,13 @@ class OpenGLShader :
void updateGeometry(IGeometryRenderer::Slot slot, const std::vector<ArbitraryMeshVertex>& vertices,
const std::vector<unsigned int>& indices) override;
void renderGeometry(IGeometryRenderer::Slot slot) override;
IGeometryStore::Slot getStorageLocation(IGeometryRenderer::Slot slot) override;
IGeometryStore::Slot getGeometryStorageLocation(IGeometryRenderer::Slot slot) override;

ISurfaceRenderer::Slot addSurface(IRenderableSurface& surface) override;
void removeSurface(ISurfaceRenderer::Slot slot) override;
void updateSurface(ISurfaceRenderer::Slot slot) override;
void renderSurface(ISurfaceRenderer::Slot slot) override;
IGeometryStore::Slot getSurfaceStorageLocation(ISurfaceRenderer::Slot slot) override;

IWindingRenderer::Slot addWinding(const std::vector<ArbitraryMeshVertex>& vertices) override;
void removeWinding(IWindingRenderer::Slot slot) override;
Expand Down
9 changes: 8 additions & 1 deletion radiantcore/rendersystem/backend/SurfaceRenderer.h
Expand Up @@ -128,11 +128,13 @@ class SurfaceRenderer :
std::reference_wrapper<IRenderableSurface> surface;
bool surfaceDataChanged;
VertexBuffer buffer;
IGeometryStore::Slot storageHandle;

SurfaceInfo(IRenderableSurface& surface_) :
surface(surface_),
buffer(GL_TRIANGLES),
surfaceDataChanged(true)
surfaceDataChanged(true),
storageHandle(std::numeric_limits<IGeometryStore::Slot>::max())
{}
};
std::map<Slot, SurfaceInfo> _surfaces;
Expand Down Expand Up @@ -212,6 +214,11 @@ class SurfaceRenderer :
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}

IGeometryStore::Slot getSurfaceStorageLocation(ISurfaceRenderer::Slot slot) override
{
return _surfaces.at(slot).storageHandle;
}

private:
void renderSlot(SurfaceInfo& slot, const VolumeTest* view = nullptr, bool renderBump = false)
{
Expand Down

0 comments on commit 7cb1e03

Please sign in to comment.