mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-21 12:29:18 +02:00
refactoring: selectable gfx renderer groundwork
This commit is contained in:
103
renderer.h
103
renderer.h
@@ -29,6 +29,52 @@ http://mozilla.org/MPL/2.0/.
|
||||
//#define EU07_USEIMGUIIMPLOPENGL2
|
||||
//#define EU07_DISABLECABREFLECTIONS
|
||||
|
||||
class gfx_renderer {
|
||||
|
||||
public:
|
||||
// types
|
||||
// constructors
|
||||
// destructor
|
||||
virtual ~gfx_renderer() {}
|
||||
// methods
|
||||
virtual auto Init( GLFWwindow *Window ) -> bool = 0;
|
||||
// main draw call. returns false on error
|
||||
virtual auto Render() -> bool = 0;
|
||||
virtual auto Framerate() -> float = 0;
|
||||
// geometry methods
|
||||
// NOTE: hands-on geometry management is exposed as a temporary measure; ultimately all visualization data should be generated/handled automatically by the renderer itself
|
||||
// creates a new geometry bank. returns: handle to the bank or NULL
|
||||
virtual auto Create_Bank() -> gfx::geometrybank_handle = 0;
|
||||
// creates a new geometry chunk of specified type from supplied vertex data, in specified bank. returns: handle to the chunk or NULL
|
||||
virtual auto Insert( gfx::vertex_array &Vertices, gfx::geometrybank_handle const &Geometry, int const Type ) -> gfx::geometry_handle = 0;
|
||||
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
|
||||
virtual auto Replace( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, std::size_t const Offset = 0 ) -> bool = 0;
|
||||
// adds supplied vertex data at the end of specified chunk
|
||||
virtual auto Append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry ) -> bool = 0;
|
||||
// provides direct access to vertex data of specfied chunk
|
||||
virtual auto Vertices( gfx::geometry_handle const &Geometry ) const ->gfx::vertex_array const & = 0;
|
||||
// material methods
|
||||
virtual auto Fetch_Material( std::string const &Filename, bool const Loadnow = true ) -> material_handle = 0;
|
||||
virtual void Bind_Material( material_handle const Material ) = 0;
|
||||
virtual auto Material( material_handle const Material ) const -> opengl_material const & = 0;
|
||||
// texture methods
|
||||
virtual auto Fetch_Texture( std::string const &Filename, bool const Loadnow = true ) -> texture_handle = 0;
|
||||
virtual void Bind_Texture( texture_handle const Texture ) = 0;
|
||||
virtual auto Texture( texture_handle const Texture ) const -> opengl_texture const & = 0;
|
||||
// utility methods
|
||||
virtual auto Pick_Control() const -> TSubModel const * = 0;
|
||||
virtual auto Pick_Node() const -> scene::basic_node const * = 0;
|
||||
virtual auto Mouse_Position() const -> glm::dvec3 = 0;
|
||||
// maintenance methods
|
||||
virtual void Update( double const Deltatime ) = 0;
|
||||
virtual auto Update_Pick_Control() -> TSubModel * = 0;
|
||||
virtual auto Update_Pick_Node() -> scene::basic_node * = 0;
|
||||
virtual auto Update_Mouse_Position() -> glm::dvec3 = 0;
|
||||
// debug methods
|
||||
virtual auto info_times() const -> std::string const & = 0;
|
||||
virtual auto info_stats() const -> std::string const & = 0;
|
||||
};
|
||||
|
||||
struct opengl_light : public basic_light {
|
||||
|
||||
GLuint id { (GLuint)-1 };
|
||||
@@ -158,7 +204,7 @@ private:
|
||||
|
||||
|
||||
// bare-bones render controller, in lack of anything better yet
|
||||
class opengl_renderer {
|
||||
class opengl_renderer : public gfx_renderer {
|
||||
|
||||
public:
|
||||
// types
|
||||
@@ -168,68 +214,65 @@ public:
|
||||
~opengl_renderer() { gluDeleteQuadric( m_quadric ); }
|
||||
// methods
|
||||
bool
|
||||
Init( GLFWwindow *Window );
|
||||
Init( GLFWwindow *Window ) override;
|
||||
// main draw call. returns false on error
|
||||
bool
|
||||
Render();
|
||||
Render() override;
|
||||
inline
|
||||
float
|
||||
Framerate() { return m_framerate; }
|
||||
Framerate() override { return m_framerate; }
|
||||
// geometry methods
|
||||
// NOTE: hands-on geometry management is exposed as a temporary measure; ultimately all visualization data should be generated/handled automatically by the renderer itself
|
||||
// creates a new geometry bank. returns: handle to the bank or NULL
|
||||
gfx::geometrybank_handle
|
||||
Create_Bank();
|
||||
Create_Bank() override;
|
||||
// creates a new geometry chunk of specified type from supplied vertex data, in specified bank. returns: handle to the chunk or NULL
|
||||
gfx::geometry_handle
|
||||
Insert( gfx::vertex_array &Vertices, gfx::geometrybank_handle const &Geometry, int const Type );
|
||||
Insert( gfx::vertex_array &Vertices, gfx::geometrybank_handle const &Geometry, int const Type ) override;
|
||||
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
|
||||
bool
|
||||
Replace( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, std::size_t const Offset = 0 );
|
||||
Replace( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, std::size_t const Offset = 0 ) override;
|
||||
// adds supplied vertex data at the end of specified chunk
|
||||
bool
|
||||
Append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry );
|
||||
Append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry ) override;
|
||||
// provides direct access to vertex data of specfied chunk
|
||||
gfx::vertex_array const &
|
||||
Vertices( gfx::geometry_handle const &Geometry ) const;
|
||||
Vertices( gfx::geometry_handle const &Geometry ) const override;
|
||||
// material methods
|
||||
material_handle
|
||||
Fetch_Material( std::string const &Filename, bool const Loadnow = true );
|
||||
Fetch_Material( std::string const &Filename, bool const Loadnow = true ) override;
|
||||
void
|
||||
Bind_Material( material_handle const Material );
|
||||
Bind_Material( material_handle const Material ) override;
|
||||
opengl_material const &
|
||||
Material( material_handle const Material ) const;
|
||||
Material( material_handle const Material ) const override;
|
||||
// texture methods
|
||||
texture_handle
|
||||
Fetch_Texture( std::string const &Filename, bool const Loadnow = true );
|
||||
Fetch_Texture( std::string const &Filename, bool const Loadnow = true ) override;
|
||||
void
|
||||
Bind_Texture( texture_handle const Texture );
|
||||
opengl_texture const &
|
||||
Texture( texture_handle const Texture ) const;
|
||||
// light methods
|
||||
void
|
||||
Disable_Lights();
|
||||
Texture( texture_handle const Texture ) const override;
|
||||
// utility methods
|
||||
TSubModel const *
|
||||
Pick_Control() const { return m_pickcontrolitem; }
|
||||
Pick_Control() const override { return m_pickcontrolitem; }
|
||||
scene::basic_node const *
|
||||
Pick_Node() const { return m_picksceneryitem; }
|
||||
Pick_Node() const override { return m_picksceneryitem; }
|
||||
glm::dvec3
|
||||
Mouse_Position() const { return m_worldmousecoordinates; }
|
||||
Mouse_Position() const override { return m_worldmousecoordinates; }
|
||||
// maintenance methods
|
||||
void
|
||||
Update( double const Deltatime );
|
||||
Update( double const Deltatime ) override;
|
||||
TSubModel *
|
||||
Update_Pick_Control();
|
||||
Update_Pick_Control() override;
|
||||
scene::basic_node *
|
||||
Update_Pick_Node();
|
||||
Update_Pick_Node() override;
|
||||
glm::dvec3
|
||||
Update_Mouse_Position();
|
||||
Update_Mouse_Position() override;
|
||||
// debug methods
|
||||
std::string const &
|
||||
info_times() const;
|
||||
info_times() const override;
|
||||
std::string const &
|
||||
info_stats() const;
|
||||
info_stats() const override;
|
||||
|
||||
// members
|
||||
GLenum static const sunlight { GL_LIGHT0 };
|
||||
@@ -286,8 +329,8 @@ private:
|
||||
typedef std::vector<opengl_light> opengllight_array;
|
||||
|
||||
// methods
|
||||
bool
|
||||
Init_caps();
|
||||
void
|
||||
Disable_Lights();
|
||||
void
|
||||
setup_pass( renderpass_config &Config, rendermode const Mode, float const Znear = 0.f, float const Zfar = 1.f, bool const Ignoredebug = false );
|
||||
void
|
||||
@@ -365,6 +408,8 @@ private:
|
||||
Render_Alpha( TSubModel *Submodel );
|
||||
void
|
||||
Update_Lights( light_array &Lights );
|
||||
bool
|
||||
Init_caps();
|
||||
glm::vec3
|
||||
pick_color( std::size_t const Index );
|
||||
std::size_t
|
||||
@@ -459,6 +504,6 @@ private:
|
||||
#endif
|
||||
};
|
||||
|
||||
extern opengl_renderer GfxRenderer;
|
||||
extern std::unique_ptr<gfx_renderer> GfxRenderer;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user