Skip to content

Commit

Permalink
Merge branch 'renderer' into renderer2, based on latest master
Browse files Browse the repository at this point in the history
# Conflicts:
#	radiantcore/brush/Face.cpp
#	radiantcore/brush/Face.h
#	radiantcore/entity/doom3group/Doom3Group.cpp
#	radiantcore/entity/doom3group/Doom3Group.h
#	radiantcore/entity/doom3group/Doom3GroupNode.cpp
#	radiantcore/patch/Patch.h
#	test/Entity.cpp
  • Loading branch information
codereader committed Nov 27, 2021
2 parents a9ed8c3 + e9b256c commit e14ad68
Show file tree
Hide file tree
Showing 127 changed files with 3,620 additions and 794 deletions.
4 changes: 2 additions & 2 deletions include/imanipulator.h
Expand Up @@ -11,7 +11,7 @@ typedef BasicVector2<double> Vector2;
class Matrix4;
class VolumeTest;
class SelectionTest;
class RenderableCollector;
class IRenderableCollector;

namespace selection
{
Expand Down Expand Up @@ -118,7 +118,7 @@ class ISceneManipulator :
virtual ~ISceneManipulator() {}

// Renders the manipulator's visual representation to the scene
virtual void render(RenderableCollector& collector, const VolumeTest& volume) = 0;
virtual void render(IRenderableCollector& collector, const VolumeTest& volume) = 0;

// Manipulators should indicate whether component editing is supported or not
virtual bool supportsComponentManipulation() const = 0;
Expand Down
4 changes: 2 additions & 2 deletions include/imousetool.h
Expand Up @@ -6,7 +6,7 @@
#include "imousetoolevent.h"

class RenderSystem;
class RenderableCollector;
class IRenderableCollector;
class VolumeTest;

namespace ui
Expand Down Expand Up @@ -128,7 +128,7 @@ class MouseTool
// For in-scene rendering of active mousetools they need implement this method.
// Any needed shaders should be acquired on-demand from the attached rendersystem.
// Renderable objects need to be submitted to the given RenderableCollector.
virtual void render(RenderSystem& renderSystem, RenderableCollector& collector, const VolumeTest& volume)
virtual void render(RenderSystem& renderSystem, IRenderableCollector& collector, const VolumeTest& volume)
{}
};
typedef std::shared_ptr<MouseTool> MouseToolPtr;
Expand Down
25 changes: 23 additions & 2 deletions include/irender.h
@@ -1,10 +1,14 @@
#pragma once

#include "imodule.h"
#include "iwindingrenderer.h"
#include "isurfacerenderer.h"
#include <functional>
#include <vector>

#include "math/Vector3.h"
#include "math/AABB.h"
#include "render/ArbitraryMeshVertex.h"

#include "ishaderlayer.h"
#include <sigc++/signal.h>
Expand Down Expand Up @@ -117,6 +121,8 @@ typedef BasicVector3<double> Vector3;
class Shader;
typedef std::shared_ptr<Shader> ShaderPtr;

struct RenderableGeometry;

/**
* A RenderEntity represents a map entity as seen by the renderer.
* It provides up to 12 numbered parameters to the renderer:
Expand Down Expand Up @@ -384,7 +390,9 @@ typedef std::shared_ptr<Material> MaterialPtr;
* which use it -- the actual rendering is performed by traversing a list of
* Shaders and rendering the geometry attached to each one.
*/
class Shader
class Shader :
public render::IWindingRenderer,
public render::ISurfaceRenderer
{
public:
// Observer interface to get notified on (un-)realisation
Expand Down Expand Up @@ -423,6 +431,10 @@ class Shader
const LightSources* lights = nullptr,
const IRenderEntity* entity = nullptr) = 0;

#ifdef RENDERABLE_GEOMETRY
virtual void addGeometry(RenderableGeometry& geometry) = 0;
#endif

/**
* \brief
* Control the visibility of this shader.
Expand Down Expand Up @@ -467,6 +479,14 @@ typedef std::shared_ptr<Shader> ShaderPtr;

const char* const MODULE_RENDERSYSTEM("ShaderCache");

// Render view type enumeration, is used to select (or leave out)
// Shader objects during rendering
enum class RenderViewType
{
Camera = 1 << 0,
OrthoView = 1 << 1,
};

/**
* \brief
* The main interface for the backend renderer.
Expand Down Expand Up @@ -514,7 +534,8 @@ class RenderSystem
* \param viewer
* Location of the viewer in world space.
*/
virtual void render(RenderStateFlags globalFlagsMask,
virtual void render(RenderViewType renderViewType,
RenderStateFlags globalFlagsMask,
const Matrix4& modelview,
const Matrix4& projection,
const Vector3& viewer) = 0;
Expand Down
80 changes: 69 additions & 11 deletions include/irenderable.h
@@ -1,7 +1,9 @@
#pragma once

#include <memory>
#include "math/Vector3.h"

class ArbitraryMeshVertex;
class Shader;
typedef std::shared_ptr<Shader> ShaderPtr;

Expand All @@ -14,22 +16,50 @@ class Matrix4;
class IRenderEntity;
class RendererLight;
class LitObject;
class Renderable;
class VolumeTest;

#ifdef RENDERABLE_GEOMETRY
// Contains the vertex and index data to render geometry of the given type
struct RenderableGeometry
{
enum class Type
{
Triangles,
Quads,
Polygons,
};

// The primitive type which will be translated to openGL enums
virtual Type getType() const = 0;

// Data as needed by glDrawArrays

virtual const Vector3& getFirstVertex() = 0;
virtual std::size_t getVertexStride() = 0;
virtual const unsigned int& getFirstIndex() = 0;
virtual std::size_t getNumIndices() = 0;
};
#endif

/**
* \brief Class which accepts OpenGLRenderable objects during the first pass of
* rendering.
*
* Each Renderable in the scenegraph is passed a reference to a
* RenderableCollector, to which the Renderable submits its OpenGLRenderable(s)
* Each Renderable in the scenegraph is passed a reference to an
* IRenderableCollector, to which the Renderable submits its OpenGLRenderable(s)
* for later rendering. A single Renderable may submit more than one
* OpenGLRenderable, with different options each time -- for instance a
* Renderable model class may submit each of its material surfaces separately
* with different shaders.
*/
class RenderableCollector
class IRenderableCollector
{
public:
virtual ~RenderableCollector() {}
virtual ~IRenderableCollector() {}

// Process the given renderable object
virtual void processRenderable(const Renderable& renderable, const VolumeTest& volume) = 0;

/**
* \brief Submit a renderable object.
Expand Down Expand Up @@ -71,6 +101,13 @@ class RenderableCollector
const LitObject* litObject = nullptr,
const IRenderEntity* entity = nullptr) = 0;

/**
* Submits a renderable object that is used for highlighting an object.
* Depending on the view, this might be a coloured, transparent overlay
* or a wireframe outline.
*/
virtual void addHighlightRenderable(const OpenGLRenderable& renderable, const Matrix4& localToWorld) = 0;

/**
* \brief Submit a light source for the render operation.
*
Expand Down Expand Up @@ -108,9 +145,17 @@ class RenderableCollector
};

virtual void setHighlightFlag(Highlight::Flags flags, bool enabled) = 0;
};

class VolumeTest;
// Returns true if the current set of highlight flags is not empty
virtual bool hasHighlightFlags() const = 0;

#ifdef RENDERABLE_GEOMETRY
// Submits renderable geometry to the collector, it will only rendered in the current frame
// Flags are a combination of Highlight::Flags
virtual void addGeometry(RenderableGeometry& geometry, std::size_t flags)
{}
#endif
};

/**
* \brief
Expand All @@ -133,18 +178,31 @@ class Renderable
*/
virtual void setRenderSystem(const RenderSystemPtr& renderSystem) = 0;

// Called in preparation of rendering this node
virtual void onPreRender(const VolumeTest& volume)
{}

// Returns true if this renderable makes use of a non-identity model matrix,
// or submit their geometry in final world coordinates.
// Geometry of renderables returning true will not be streamlined into a larger buffer
virtual bool isOriented() const
{
return false; // by default, renderables render in world coordinates
}

/// Submit renderable geometry when rendering in Solid mode.
virtual void renderSolid(RenderableCollector& collector,
virtual void renderSolid(IRenderableCollector& collector,
const VolumeTest& volume) const = 0;

/// Submit renderable geometry when rendering in Wireframe mode.
virtual void renderWireframe(RenderableCollector& collector,
virtual void renderWireframe(IRenderableCollector& collector,
const VolumeTest& volume) const = 0;

virtual void renderComponents(RenderableCollector&, const VolumeTest&) const
{ }
// Submit renderable geometry for highlighting the object
virtual void renderHighlights(IRenderableCollector& collector,
const VolumeTest& volume) = 0;

virtual void viewChanged() const
virtual void renderComponents(IRenderableCollector&, const VolumeTest&) const
{ }

struct Highlight
Expand Down
51 changes: 51 additions & 0 deletions include/isurfacerenderer.h
@@ -0,0 +1,51 @@
#pragma once

#include <vector>
#include <limits>
#include <cstdint>
#include "render/ArbitraryMeshVertex.h"

namespace render
{

enum class SurfaceIndexingType
{
Triangles,
Quads,
};

/**
* A surface renderer accepts a variable number of indexed surfaces and arranges
* them into one or more continuous blocks of vertices for efficient rendering.
*
* The internal arrangement has the goal of reducing the amount of draw calls for
* suraces sharing a single material. Allocating a surface slot yields a handle which
* allows for later update or deallocation of the slot.
*/
class ISurfaceRenderer
{
public:
virtual ~ISurfaceRenderer() {}

using Slot = std::uint64_t;
static constexpr Slot InvalidSlot = std::numeric_limits<Slot>::max();

// Allocate a slot to hold the given surface data of the given size
// Returns the handle which can be used to update or deallocate the data later
// The indexType determines the primitive GLenum that is chosen to render this surface
virtual Slot addSurface(SurfaceIndexingType indexType,
const std::vector<ArbitraryMeshVertex>& vertices,
const std::vector<unsigned int>& indices) = 0;

// Releases a previously allocated slot. This invalidates the handle.
virtual void removeSurface(Slot slot) = 0;

// 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;
};

}
51 changes: 51 additions & 0 deletions include/iwindingrenderer.h
@@ -0,0 +1,51 @@
#pragma once

#include <vector>
#include <limits>
#include <cstdint>
#include "render/ArbitraryMeshVertex.h"

namespace render
{

/**
* A winding renderer accepts a variable number of windings and arranges them into
* one or more continuous blocks of vertices for efficient rendering.
*
* The internal arrangement has the goal of reducing the amount of draw calls for
* winding sharing a single material. Allocating a winding slot yields a handle which
* allows for later update or deallocation of the slot.
*
* Only the vertex data (XYZ, UV, Normals, Colour) needs to be submitted,
* the render indices of each winding slot are handled internally.
*/
class IWindingRenderer
{
public:
virtual ~IWindingRenderer() {}

using Slot = std::uint64_t;
static constexpr Slot InvalidSlot = std::numeric_limits<Slot>::max();

// Allocate a slot to hold the vertex data of a winding of the given size
// Returns the handle which can be used to update or deallocate the data later
virtual Slot addWinding(const std::vector<ArbitraryMeshVertex>& vertices) = 0;

// Releases a previously allocated winding slot. This invalidates the handle.
virtual void removeWinding(Slot slot) = 0;

// Sets the winding data
virtual void updateWinding(Slot slot, const std::vector<ArbitraryMeshVertex>& vertices) = 0;

// Mode used to specify how to render a single winding
enum class RenderMode
{
Triangles,
Polygon,
};

// Submits a single winding to GL
virtual void renderWinding(RenderMode mode, Slot slot) = 0;
};

}
4 changes: 0 additions & 4 deletions libs/debugging/ScopedDebugTimer.h
Expand Up @@ -91,18 +91,15 @@ class ScopedDebugTimer
ScopedDebugTimer(const std::string& name, bool showFps = false)
: _op(name), _fps(showFps)
{
#ifndef NDEBUG
// Save start time
gettimeofday(&_s, NULL);
#endif
}

/**
* Destructor. Prints out the time of the operation.
*/
~ScopedDebugTimer()
{
#ifndef NDEBUG
// Get the current time
timeval end;
gettimeofday(&end, NULL);
Expand All @@ -121,6 +118,5 @@ class ScopedDebugTimer
}

stream << std::endl;
#endif
}
};
6 changes: 6 additions & 0 deletions libs/render.h
Expand Up @@ -281,6 +281,12 @@ class RenderablePointVector :
void push_back(const VertexCb& point) {
_vector.push_back(point);
}

template<class... Args>
VertexCb& emplace_back(Args&&... args)
{
return _vector.emplace_back(std::forward<Args>(args)...);
}
};


Expand Down

0 comments on commit e14ad68

Please sign in to comment.