mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 08:09:19 +02:00
maintenance: opengl and generic gfx class source files split
This commit is contained in:
@@ -16,6 +16,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "DynObj.h"
|
#include "DynObj.h"
|
||||||
|
|
||||||
#include "simulation.h"
|
#include "simulation.h"
|
||||||
|
#include "lightarray.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
#include "Train.h"
|
#include "Train.h"
|
||||||
#include "Driver.h"
|
#include "Driver.h"
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
|
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
#include "Logs.h"
|
#include "Logs.h"
|
||||||
|
#include "parser.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
#include "Track.h"
|
#include "Track.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "simulation.h"
|
#include "simulation.h"
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
#include "MemCell.h"
|
||||||
#include "messaging.h"
|
#include "messaging.h"
|
||||||
#include "DynObj.h"
|
#include "DynObj.h"
|
||||||
#include "AnimModel.h"
|
#include "AnimModel.h"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "Train.h"
|
#include "Train.h"
|
||||||
#include "dictionary.h"
|
#include "dictionary.h"
|
||||||
#include "sceneeditor.h"
|
#include "sceneeditor.h"
|
||||||
#include "renderer.h"
|
#include "openglrenderer.h"
|
||||||
#include "uilayer.h"
|
#include "uilayer.h"
|
||||||
#include "translation.h"
|
#include "translation.h"
|
||||||
#include "Logs.h"
|
#include "Logs.h"
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "translation.h"
|
#include "translation.h"
|
||||||
#include "simulation.h"
|
#include "simulation.h"
|
||||||
#include "simulationtime.h"
|
#include "simulationtime.h"
|
||||||
|
#include "simulationenvironment.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
#include "TractionPower.h"
|
#include "TractionPower.h"
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "editoruilayer.h"
|
#include "editoruilayer.h"
|
||||||
|
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
|
#include "scenenode.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
|
||||||
editor_ui::editor_ui() {
|
editor_ui::editor_ui() {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "AnimModel.h"
|
#include "AnimModel.h"
|
||||||
#include "Track.h"
|
#include "Track.h"
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
#include "MemCell.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
#include "scenenodegroups.h"
|
#include "scenenodegroups.h"
|
||||||
|
|||||||
183
geometrybank.cpp
Normal file
183
geometrybank.cpp
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
/*
|
||||||
|
This Source Code Form is subject to the
|
||||||
|
terms of the Mozilla Public License, v.
|
||||||
|
2.0. If a copy of the MPL was not
|
||||||
|
distributed with this file, You can
|
||||||
|
obtain one at
|
||||||
|
http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "stdafx.h"
|
||||||
|
#include "geometrybank.h"
|
||||||
|
#include "openglgeometrybank.h"
|
||||||
|
|
||||||
|
#include "sn_utils.h"
|
||||||
|
#include "Logs.h"
|
||||||
|
#include "Globals.h"
|
||||||
|
|
||||||
|
namespace gfx {
|
||||||
|
|
||||||
|
void
|
||||||
|
basic_vertex::serialize( std::ostream &s ) const {
|
||||||
|
|
||||||
|
sn_utils::ls_float32( s, position.x );
|
||||||
|
sn_utils::ls_float32( s, position.y );
|
||||||
|
sn_utils::ls_float32( s, position.z );
|
||||||
|
|
||||||
|
sn_utils::ls_float32( s, normal.x );
|
||||||
|
sn_utils::ls_float32( s, normal.y );
|
||||||
|
sn_utils::ls_float32( s, normal.z );
|
||||||
|
|
||||||
|
sn_utils::ls_float32( s, texture.x );
|
||||||
|
sn_utils::ls_float32( s, texture.y );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
basic_vertex::deserialize( std::istream &s ) {
|
||||||
|
|
||||||
|
position.x = sn_utils::ld_float32( s );
|
||||||
|
position.y = sn_utils::ld_float32( s );
|
||||||
|
position.z = sn_utils::ld_float32( s );
|
||||||
|
|
||||||
|
normal.x = sn_utils::ld_float32( s );
|
||||||
|
normal.y = sn_utils::ld_float32( s );
|
||||||
|
normal.z = sn_utils::ld_float32( s );
|
||||||
|
|
||||||
|
texture.x = sn_utils::ld_float32( s );
|
||||||
|
texture.y = sn_utils::ld_float32( s );
|
||||||
|
}
|
||||||
|
|
||||||
|
// generic geometry bank class, allows storage, update and drawing of geometry chunks
|
||||||
|
|
||||||
|
// creates a new geometry chunk of specified type from supplied vertex data. returns: handle to the chunk
|
||||||
|
gfx::geometry_handle
|
||||||
|
geometry_bank::create( gfx::vertex_array &Vertices, unsigned int const Type ) {
|
||||||
|
|
||||||
|
if( true == Vertices.empty() ) { return { 0, 0 }; }
|
||||||
|
|
||||||
|
m_chunks.emplace_back( Vertices, Type );
|
||||||
|
// NOTE: handle is effectively (index into chunk array + 1) this leaves value of 0 to serve as error/empty handle indication
|
||||||
|
gfx::geometry_handle chunkhandle { 0, static_cast<std::uint32_t>(m_chunks.size()) };
|
||||||
|
// template method implementation
|
||||||
|
create_( chunkhandle );
|
||||||
|
// all done
|
||||||
|
return chunkhandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
|
||||||
|
bool
|
||||||
|
geometry_bank::replace( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, std::size_t const Offset ) {
|
||||||
|
|
||||||
|
if( ( Geometry.chunk == 0 ) || ( Geometry.chunk > m_chunks.size() ) ) { return false; }
|
||||||
|
|
||||||
|
auto &chunk = gfx::geometry_bank::chunk( Geometry );
|
||||||
|
|
||||||
|
if( ( Offset == 0 )
|
||||||
|
&& ( Vertices.size() == chunk.vertices.size() ) ) {
|
||||||
|
// check first if we can get away with a simple swap...
|
||||||
|
chunk.vertices.swap( Vertices );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// ...otherwise we need to do some legwork
|
||||||
|
// NOTE: if the offset is larger than existing size of the chunk, it'll bridge the gap with 'blank' vertices
|
||||||
|
// TBD: we could bail out with an error instead if such request occurs
|
||||||
|
chunk.vertices.resize( Offset + Vertices.size(), gfx::basic_vertex() );
|
||||||
|
chunk.vertices.insert( std::end( chunk.vertices ), std::begin( Vertices ), std::end( Vertices ) );
|
||||||
|
}
|
||||||
|
// template method implementation
|
||||||
|
replace_( Geometry );
|
||||||
|
// all done
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// adds supplied vertex data at the end of specified chunk
|
||||||
|
bool
|
||||||
|
geometry_bank::append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry ) {
|
||||||
|
|
||||||
|
if( ( Geometry.chunk == 0 ) || ( Geometry.chunk > m_chunks.size() ) ) { return false; }
|
||||||
|
|
||||||
|
return replace( Vertices, Geometry, gfx::geometry_bank::chunk( Geometry ).vertices.size() );
|
||||||
|
}
|
||||||
|
|
||||||
|
// draws geometry stored in specified chunk
|
||||||
|
void
|
||||||
|
geometry_bank::draw( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) {
|
||||||
|
// template method implementation
|
||||||
|
draw_( Geometry, Units, Streams );
|
||||||
|
}
|
||||||
|
|
||||||
|
// frees subclass-specific resources associated with the bank, typically called when the bank wasn't in use for a period of time
|
||||||
|
void
|
||||||
|
geometry_bank::release() {
|
||||||
|
// template method implementation
|
||||||
|
release_();
|
||||||
|
}
|
||||||
|
|
||||||
|
vertex_array const &
|
||||||
|
geometry_bank::vertices( gfx::geometry_handle const &Geometry ) const {
|
||||||
|
|
||||||
|
return geometry_bank::chunk( Geometry ).vertices;
|
||||||
|
}
|
||||||
|
|
||||||
|
// geometry bank manager, holds collection of geometry banks
|
||||||
|
|
||||||
|
// performs a resource sweep
|
||||||
|
void
|
||||||
|
geometrybank_manager::update() {
|
||||||
|
|
||||||
|
m_garbagecollector.sweep();
|
||||||
|
}
|
||||||
|
|
||||||
|
// creates a new geometry bank. returns: handle to the bank or NULL
|
||||||
|
gfx::geometrybank_handle
|
||||||
|
geometrybank_manager::create_bank() {
|
||||||
|
|
||||||
|
if( true == Global.bUseVBO ) { m_geometrybanks.emplace_back( std::make_shared<opengl_vbogeometrybank>(), std::chrono::steady_clock::time_point() ); }
|
||||||
|
else { m_geometrybanks.emplace_back( std::make_shared<opengl_dlgeometrybank>(), std::chrono::steady_clock::time_point() ); }
|
||||||
|
// NOTE: handle is effectively (index into chunk array + 1) this leaves value of 0 to serve as error/empty handle indication
|
||||||
|
return { static_cast<std::uint32_t>( m_geometrybanks.size() ), 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
geometrybank_manager::create_chunk( gfx::vertex_array &Vertices, gfx::geometrybank_handle const &Geometry, int const Type ) {
|
||||||
|
|
||||||
|
auto const newchunkhandle = bank( Geometry ).first->create( Vertices, Type );
|
||||||
|
|
||||||
|
if( newchunkhandle.chunk != 0 ) { return { Geometry.bank, newchunkhandle.chunk }; }
|
||||||
|
else { return { 0, 0 }; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
|
||||||
|
bool
|
||||||
|
geometrybank_manager::replace( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, std::size_t const Offset ) {
|
||||||
|
|
||||||
|
return bank( Geometry ).first->replace( Vertices, Geometry, Offset );
|
||||||
|
}
|
||||||
|
|
||||||
|
// adds supplied vertex data at the end of specified chunk
|
||||||
|
bool
|
||||||
|
geometrybank_manager::append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry ) {
|
||||||
|
|
||||||
|
return bank( Geometry ).first->append( Vertices, Geometry );
|
||||||
|
}
|
||||||
|
// draws geometry stored in specified chunk
|
||||||
|
void
|
||||||
|
geometrybank_manager::draw( gfx::geometry_handle const &Geometry, unsigned int const Streams ) {
|
||||||
|
|
||||||
|
if( Geometry == null_handle ) { return; }
|
||||||
|
|
||||||
|
auto &bankrecord = bank( Geometry );
|
||||||
|
|
||||||
|
bankrecord.second = m_garbagecollector.timestamp();
|
||||||
|
bankrecord.first->draw( Geometry, m_units, Streams );
|
||||||
|
}
|
||||||
|
|
||||||
|
// provides direct access to vertex data of specfied chunk
|
||||||
|
gfx::vertex_array const &
|
||||||
|
geometrybank_manager::vertices( gfx::geometry_handle const &Geometry ) const {
|
||||||
|
|
||||||
|
return bank( Geometry ).first->vertices( Geometry );
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace gfx
|
||||||
209
geometrybank.h
Normal file
209
geometrybank.h
Normal file
@@ -0,0 +1,209 @@
|
|||||||
|
/*
|
||||||
|
This Source Code Form is subject to the
|
||||||
|
terms of the Mozilla Public License, v.
|
||||||
|
2.0. If a copy of the MPL was not
|
||||||
|
distributed with this file, You can
|
||||||
|
obtain one at
|
||||||
|
http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
#include "GL/glew.h"
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include "GL/wglew.h"
|
||||||
|
#endif
|
||||||
|
#include "ResourceManager.h"
|
||||||
|
|
||||||
|
namespace gfx {
|
||||||
|
|
||||||
|
struct basic_vertex {
|
||||||
|
|
||||||
|
glm::vec3 position; // 3d space
|
||||||
|
glm::vec3 normal; // 3d space
|
||||||
|
glm::vec2 texture; // uv space
|
||||||
|
|
||||||
|
basic_vertex() = default;
|
||||||
|
basic_vertex( glm::vec3 Position, glm::vec3 Normal, glm::vec2 Texture ) :
|
||||||
|
position( Position ), normal( Normal ), texture( Texture )
|
||||||
|
{}
|
||||||
|
void serialize( std::ostream& ) const;
|
||||||
|
void deserialize( std::istream& );
|
||||||
|
};
|
||||||
|
|
||||||
|
// data streams carried in a vertex
|
||||||
|
enum stream {
|
||||||
|
none = 0x0,
|
||||||
|
position = 0x1,
|
||||||
|
normal = 0x2,
|
||||||
|
color = 0x4, // currently normal and colour streams are stored in the same slot, and mutually exclusive
|
||||||
|
texture = 0x8
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned int const basic_streams { stream::position | stream::normal | stream::texture };
|
||||||
|
unsigned int const color_streams { stream::position | stream::color | stream::texture };
|
||||||
|
|
||||||
|
struct stream_units {
|
||||||
|
|
||||||
|
std::vector<GLint> texture { GL_TEXTURE0 }; // unit associated with main texture data stream. TODO: allow multiple units per stream
|
||||||
|
};
|
||||||
|
|
||||||
|
using vertex_array = std::vector<basic_vertex>;
|
||||||
|
|
||||||
|
// generic geometry bank class, allows storage, update and drawing of geometry chunks
|
||||||
|
|
||||||
|
struct geometry_handle {
|
||||||
|
// constructors
|
||||||
|
geometry_handle() :
|
||||||
|
bank( 0 ), chunk( 0 )
|
||||||
|
{}
|
||||||
|
geometry_handle( std::uint32_t Bank, std::uint32_t Chunk ) :
|
||||||
|
bank( Bank ), chunk( Chunk )
|
||||||
|
{}
|
||||||
|
// methods
|
||||||
|
inline
|
||||||
|
operator std::uint64_t() const {
|
||||||
|
/*
|
||||||
|
return bank << 14 | chunk; }
|
||||||
|
*/
|
||||||
|
return ( std::uint64_t { bank } << 32 | chunk );
|
||||||
|
}
|
||||||
|
|
||||||
|
// members
|
||||||
|
/*
|
||||||
|
std::uint32_t
|
||||||
|
bank : 18, // 250k banks
|
||||||
|
chunk : 14; // 16k chunks per bank
|
||||||
|
*/
|
||||||
|
std::uint32_t bank;
|
||||||
|
std::uint32_t chunk;
|
||||||
|
};
|
||||||
|
|
||||||
|
class geometry_bank {
|
||||||
|
|
||||||
|
public:
|
||||||
|
// types:
|
||||||
|
|
||||||
|
// constructors:
|
||||||
|
|
||||||
|
// destructor:
|
||||||
|
virtual
|
||||||
|
~geometry_bank() {}
|
||||||
|
|
||||||
|
// methods:
|
||||||
|
// creates a new geometry chunk of specified type from supplied vertex data. returns: handle to the chunk or NULL
|
||||||
|
auto create( gfx::vertex_array &Vertices, unsigned int const Type ) -> gfx::geometry_handle;
|
||||||
|
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
|
||||||
|
auto replace( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, std::size_t const Offset = 0 ) -> bool;
|
||||||
|
// adds supplied vertex data at the end of specified chunk
|
||||||
|
auto append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry ) -> bool;
|
||||||
|
// draws geometry stored in specified chunk
|
||||||
|
void draw( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams = basic_streams );
|
||||||
|
// draws geometry stored in supplied list of chunks
|
||||||
|
template <typename Iterator_>
|
||||||
|
void draw( Iterator_ First, Iterator_ Last, gfx::stream_units const &Units, unsigned int const Streams = basic_streams ) {
|
||||||
|
while( First != Last ) {
|
||||||
|
draw( *First, Units, Streams ); ++First; } }
|
||||||
|
// frees subclass-specific resources associated with the bank, typically called when the bank wasn't in use for a period of time
|
||||||
|
void release();
|
||||||
|
// provides direct access to vertex data of specfied chunk
|
||||||
|
auto vertices( gfx::geometry_handle const &Geometry ) const -> gfx::vertex_array const &;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// types:
|
||||||
|
struct geometry_chunk {
|
||||||
|
unsigned int type; // kind of geometry used by the chunk
|
||||||
|
gfx::vertex_array vertices; // geometry data
|
||||||
|
// NOTE: constructor doesn't copy provided vertex data, but moves it
|
||||||
|
geometry_chunk( gfx::vertex_array &Vertices, unsigned int Type ) :
|
||||||
|
type( Type )
|
||||||
|
{
|
||||||
|
vertices.swap( Vertices );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
using geometrychunk_sequence = std::vector<geometry_chunk>;
|
||||||
|
|
||||||
|
// methods
|
||||||
|
inline
|
||||||
|
auto chunk( gfx::geometry_handle const Geometry ) -> geometry_chunk & {
|
||||||
|
return m_chunks[ Geometry.chunk - 1 ]; }
|
||||||
|
inline
|
||||||
|
auto chunk( gfx::geometry_handle const Geometry ) const -> geometry_chunk const & {
|
||||||
|
return m_chunks[ Geometry.chunk - 1 ]; }
|
||||||
|
|
||||||
|
// members:
|
||||||
|
geometrychunk_sequence m_chunks;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// methods:
|
||||||
|
// create() subclass details
|
||||||
|
virtual void create_( gfx::geometry_handle const &Geometry ) = 0;
|
||||||
|
// replace() subclass details
|
||||||
|
virtual void replace_( gfx::geometry_handle const &Geometry ) = 0;
|
||||||
|
// draw() subclass details
|
||||||
|
virtual void draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) = 0;
|
||||||
|
// resource release subclass details
|
||||||
|
virtual void release_() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// geometry bank manager, holds collection of geometry banks
|
||||||
|
|
||||||
|
using geometrybank_handle = geometry_handle;
|
||||||
|
|
||||||
|
class geometrybank_manager {
|
||||||
|
|
||||||
|
public:
|
||||||
|
// constructors
|
||||||
|
geometrybank_manager() = default;
|
||||||
|
// methods:
|
||||||
|
// performs a resource sweep
|
||||||
|
void update();
|
||||||
|
// creates a new geometry bank. returns: handle to the bank or NULL
|
||||||
|
auto create_bank() -> gfx::geometrybank_handle;
|
||||||
|
// creates a new geometry chunk of specified type from supplied vertex data, in specified bank. returns: handle to the chunk or NULL
|
||||||
|
auto create_chunk( gfx::vertex_array &Vertices, gfx::geometrybank_handle const &Geometry, int const Type ) -> gfx::geometry_handle;
|
||||||
|
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
|
||||||
|
auto replace( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, std::size_t const Offset = 0 ) -> bool;
|
||||||
|
// adds supplied vertex data at the end of specified chunk
|
||||||
|
auto append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry ) -> bool;
|
||||||
|
// draws geometry stored in specified chunk
|
||||||
|
void draw( gfx::geometry_handle const &Geometry, unsigned int const Streams = basic_streams );
|
||||||
|
template <typename Iterator_>
|
||||||
|
void draw( Iterator_ First, Iterator_ Last, unsigned int const Streams = basic_streams ) {
|
||||||
|
while( First != Last ) {
|
||||||
|
draw( *First, Streams );
|
||||||
|
++First; } }
|
||||||
|
// provides direct access to vertex data of specfied chunk
|
||||||
|
auto vertices( gfx::geometry_handle const &Geometry ) const -> gfx::vertex_array const &;
|
||||||
|
// sets target texture unit for the texture data stream
|
||||||
|
auto units() -> gfx::stream_units & { return m_units; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
// types:
|
||||||
|
using geometrybanktimepoint_pair = std::pair< std::shared_ptr<geometry_bank>, resource_timestamp >;
|
||||||
|
using geometrybanktimepointpair_sequence = std::deque< geometrybanktimepoint_pair >;
|
||||||
|
|
||||||
|
// members:
|
||||||
|
geometrybanktimepointpair_sequence m_geometrybanks;
|
||||||
|
garbage_collector<geometrybanktimepointpair_sequence> m_garbagecollector { m_geometrybanks, 60, 120, "geometry buffer" };
|
||||||
|
gfx::stream_units m_units;
|
||||||
|
|
||||||
|
// methods
|
||||||
|
inline
|
||||||
|
auto valid( gfx::geometry_handle const &Geometry ) const -> bool {
|
||||||
|
return ( ( Geometry.bank != 0 )
|
||||||
|
&& ( Geometry.bank <= m_geometrybanks.size() ) ); }
|
||||||
|
inline
|
||||||
|
auto bank( gfx::geometry_handle const Geometry ) -> geometrybanktimepointpair_sequence::value_type & {
|
||||||
|
return m_geometrybanks[ Geometry.bank - 1 ]; }
|
||||||
|
inline
|
||||||
|
auto bank( gfx::geometry_handle const Geometry ) const -> geometrybanktimepointpair_sequence::value_type const & {
|
||||||
|
return m_geometrybanks[ Geometry.bank - 1 ]; }
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace gfx
|
||||||
@@ -52,6 +52,12 @@
|
|||||||
<Filter Include="Source Files\imgui">
|
<Filter Include="Source Files\imgui">
|
||||||
<UniqueIdentifier>{33f7f4ae-692b-4989-a71a-004e0d48ed4f}</UniqueIdentifier>
|
<UniqueIdentifier>{33f7f4ae-692b-4989-a71a-004e0d48ed4f}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="Header Files\gfx">
|
||||||
|
<UniqueIdentifier>{66a7bd41-ffd6-47cc-af2f-15c36e811142}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Header Files\math">
|
||||||
|
<UniqueIdentifier>{77356e25-abc5-4f1c-9caf-6cf554a65770}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="AirCoupler.cpp">
|
<ClCompile Include="AirCoupler.cpp">
|
||||||
@@ -342,6 +348,24 @@
|
|||||||
<ClCompile Include="dictionary.cpp">
|
<ClCompile Include="dictionary.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="particles.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="geometrybank.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="openglrenderer.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="opengllight.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="openglcamera.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="openglparticles.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Globals.h">
|
<ClInclude Include="Globals.h">
|
||||||
@@ -356,36 +380,21 @@
|
|||||||
<ClInclude Include="McZapkie\mover.h">
|
<ClInclude Include="McZapkie\mover.h">
|
||||||
<Filter>Header Files\mczapkie</Filter>
|
<Filter>Header Files\mczapkie</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="dumb3d.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="PyInt.h">
|
<ClInclude Include="PyInt.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Classes.h">
|
<ClInclude Include="Classes.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Texture.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Camera.h">
|
<ClInclude Include="Camera.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="MdlMngr.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="sky.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="parser.h">
|
<ClInclude Include="parser.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="resource.h">
|
<ClInclude Include="resource.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Float3d.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="stdafx.h">
|
<ClInclude Include="stdafx.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -428,15 +437,9 @@
|
|||||||
<ClInclude Include="Names.h">
|
<ClInclude Include="Names.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Model3d.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Event.h">
|
<ClInclude Include="Event.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="AnimModel.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Track.h">
|
<ClInclude Include="Track.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -467,33 +470,15 @@
|
|||||||
<ClInclude Include="sun.h">
|
<ClInclude Include="sun.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="renderer.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="skydome.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="color.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="stars.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="lightarray.h">
|
<ClInclude Include="lightarray.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="sn_utils.h">
|
<ClInclude Include="sn_utils.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="frustum.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="uilayer.h">
|
<ClInclude Include="uilayer.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="openglmatrixstack.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="moon.h">
|
<ClInclude Include="moon.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -503,15 +488,9 @@
|
|||||||
<ClInclude Include="version.h">
|
<ClInclude Include="version.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="openglgeometrybank.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="translation.h">
|
<ClInclude Include="translation.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="material.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="vertex.h">
|
<ClInclude Include="vertex.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -539,9 +518,6 @@
|
|||||||
<ClInclude Include="uitranscripts.h">
|
<ClInclude Include="uitranscripts.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="light.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="utilities.h">
|
<ClInclude Include="utilities.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -620,15 +596,81 @@
|
|||||||
<ClInclude Include="editoruipanels.h">
|
<ClInclude Include="editoruipanels.h">
|
||||||
<Filter>Header Files\application\mode_editor</Filter>
|
<Filter>Header Files\application\mode_editor</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="precipitation.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="openglcolor.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="dictionary.h">
|
<ClInclude Include="dictionary.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="particles.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="geometrybank.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="color.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="light.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="material.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="openglcolor.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="openglgeometrybank.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="openglmatrixstack.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="renderer.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="sky.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="skydome.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Texture.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="stars.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="precipitation.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="AnimModel.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="MdlMngr.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Model3d.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="openglrenderer.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Float3d.h">
|
||||||
|
<Filter>Header Files\math</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="frustum.h">
|
||||||
|
<Filter>Header Files\math</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="dumb3d.h">
|
||||||
|
<Filter>Header Files\math</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="opengllight.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="openglcamera.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="openglparticles.h">
|
||||||
|
<Filter>Header Files\gfx</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="maszyna.rc">
|
<ResourceCompile Include="maszyna.rc">
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
|
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
#include "parser.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
#include "sn_utils.h"
|
#include "sn_utils.h"
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
|
|||||||
61
openglcamera.cpp
Normal file
61
openglcamera.cpp
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
This Source Code Form is subject to the
|
||||||
|
terms of the Mozilla Public License, v.
|
||||||
|
2.0. If a copy of the MPL was not
|
||||||
|
distributed with this file, You can
|
||||||
|
obtain one at
|
||||||
|
http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "stdafx.h"
|
||||||
|
#include "openglcamera.h"
|
||||||
|
|
||||||
|
#include "DynObj.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
opengl_camera::update_frustum( glm::mat4 const &Projection, glm::mat4 const &Modelview ) {
|
||||||
|
|
||||||
|
m_frustum.calculate( Projection, Modelview );
|
||||||
|
// cache inverse tranformation matrix
|
||||||
|
// NOTE: transformation is done only to camera-centric space
|
||||||
|
m_inversetransformation = glm::inverse( Projection * glm::mat4{ glm::mat3{ Modelview } } );
|
||||||
|
// calculate frustum corners
|
||||||
|
m_frustumpoints = ndcfrustumshapepoints;
|
||||||
|
transform_to_world(
|
||||||
|
std::begin( m_frustumpoints ),
|
||||||
|
std::end( m_frustumpoints ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true if specified object is within camera frustum, false otherwise
|
||||||
|
bool
|
||||||
|
opengl_camera::visible( scene::bounding_area const &Area ) const {
|
||||||
|
|
||||||
|
return ( m_frustum.sphere_inside( Area.center, Area.radius ) > 0.f );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
opengl_camera::visible( TDynamicObject const *Dynamic ) const {
|
||||||
|
|
||||||
|
// sphere test is faster than AABB, so we'll use it here
|
||||||
|
glm::vec3 diagonal(
|
||||||
|
static_cast<float>( Dynamic->MoverParameters->Dim.L ),
|
||||||
|
static_cast<float>( Dynamic->MoverParameters->Dim.H ),
|
||||||
|
static_cast<float>( Dynamic->MoverParameters->Dim.W ) );
|
||||||
|
// we're giving vehicles some extra padding, to allow for things like shared bogeys extending past the main body
|
||||||
|
float const radius = glm::length( diagonal ) * 0.65f;
|
||||||
|
|
||||||
|
return ( m_frustum.sphere_inside( Dynamic->GetPosition(), radius ) > 0.0f );
|
||||||
|
}
|
||||||
|
|
||||||
|
// debug helper, draws shape of frustum in world space
|
||||||
|
void
|
||||||
|
opengl_camera::draw( glm::vec3 const &Offset ) const {
|
||||||
|
|
||||||
|
::glBegin( GL_LINES );
|
||||||
|
for( auto const pointindex : frustumshapepoinstorder ) {
|
||||||
|
::glVertex3fv( glm::value_ptr( glm::vec3{ m_frustumpoints[ pointindex ] } - Offset ) );
|
||||||
|
}
|
||||||
|
::glEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
78
openglcamera.h
Normal file
78
openglcamera.h
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
This Source Code Form is subject to the
|
||||||
|
terms of the Mozilla Public License, v.
|
||||||
|
2.0. If a copy of the MPL was not
|
||||||
|
distributed with this file, You can
|
||||||
|
obtain one at
|
||||||
|
http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "GL/glew.h"
|
||||||
|
#include "frustum.h"
|
||||||
|
#include "scene.h"
|
||||||
|
|
||||||
|
// simple camera object. paired with 'virtual camera' in the scene
|
||||||
|
class opengl_camera {
|
||||||
|
|
||||||
|
public:
|
||||||
|
// constructors
|
||||||
|
opengl_camera() = default;
|
||||||
|
// methods:
|
||||||
|
inline
|
||||||
|
void
|
||||||
|
update_frustum() { update_frustum( m_projection, m_modelview ); }
|
||||||
|
void
|
||||||
|
update_frustum( glm::mat4 const &Projection, glm::mat4 const &Modelview );
|
||||||
|
bool
|
||||||
|
visible( scene::bounding_area const &Area ) const;
|
||||||
|
bool
|
||||||
|
visible( TDynamicObject const *Dynamic ) const;
|
||||||
|
inline
|
||||||
|
glm::dvec3 const &
|
||||||
|
position() const { return m_position; }
|
||||||
|
inline
|
||||||
|
glm::dvec3 &
|
||||||
|
position() { return m_position; }
|
||||||
|
inline
|
||||||
|
glm::mat4 const &
|
||||||
|
projection() const { return m_projection; }
|
||||||
|
inline
|
||||||
|
glm::mat4 &
|
||||||
|
projection() { return m_projection; }
|
||||||
|
inline
|
||||||
|
glm::mat4 const &
|
||||||
|
modelview() const { return m_modelview; }
|
||||||
|
inline
|
||||||
|
glm::mat4 &
|
||||||
|
modelview() { return m_modelview; }
|
||||||
|
inline
|
||||||
|
std::vector<glm::vec4> &
|
||||||
|
frustum_points() { return m_frustumpoints; }
|
||||||
|
// transforms provided set of clip space points to world space
|
||||||
|
template <class Iterator_>
|
||||||
|
void
|
||||||
|
transform_to_world( Iterator_ First, Iterator_ Last ) const {
|
||||||
|
std::for_each(
|
||||||
|
First, Last,
|
||||||
|
[this]( glm::vec4 &point ) {
|
||||||
|
// transform each point using the cached matrix...
|
||||||
|
point = this->m_inversetransformation * point;
|
||||||
|
// ...and scale by transformed w
|
||||||
|
point = glm::vec4{ glm::vec3{ point } / point.w, 1.f }; } ); }
|
||||||
|
// debug helper, draws shape of frustum in world space
|
||||||
|
void
|
||||||
|
draw( glm::vec3 const &Offset ) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// members:
|
||||||
|
cFrustum m_frustum;
|
||||||
|
std::vector<glm::vec4> m_frustumpoints; // visualization helper; corners of defined frustum, in world space
|
||||||
|
glm::dvec3 m_position;
|
||||||
|
glm::mat4 m_projection;
|
||||||
|
glm::mat4 m_modelview;
|
||||||
|
glm::mat4 m_inversetransformation; // cached transformation to world space
|
||||||
|
};
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
@@ -10,114 +10,10 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "openglgeometrybank.h"
|
#include "openglgeometrybank.h"
|
||||||
|
|
||||||
#include "sn_utils.h"
|
|
||||||
#include "Logs.h"
|
#include "Logs.h"
|
||||||
#include "Globals.h"
|
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
|
||||||
void
|
|
||||||
basic_vertex::serialize( std::ostream &s ) const {
|
|
||||||
|
|
||||||
sn_utils::ls_float32( s, position.x );
|
|
||||||
sn_utils::ls_float32( s, position.y );
|
|
||||||
sn_utils::ls_float32( s, position.z );
|
|
||||||
|
|
||||||
sn_utils::ls_float32( s, normal.x );
|
|
||||||
sn_utils::ls_float32( s, normal.y );
|
|
||||||
sn_utils::ls_float32( s, normal.z );
|
|
||||||
|
|
||||||
sn_utils::ls_float32( s, texture.x );
|
|
||||||
sn_utils::ls_float32( s, texture.y );
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
basic_vertex::deserialize( std::istream &s ) {
|
|
||||||
|
|
||||||
position.x = sn_utils::ld_float32( s );
|
|
||||||
position.y = sn_utils::ld_float32( s );
|
|
||||||
position.z = sn_utils::ld_float32( s );
|
|
||||||
|
|
||||||
normal.x = sn_utils::ld_float32( s );
|
|
||||||
normal.y = sn_utils::ld_float32( s );
|
|
||||||
normal.z = sn_utils::ld_float32( s );
|
|
||||||
|
|
||||||
texture.x = sn_utils::ld_float32( s );
|
|
||||||
texture.y = sn_utils::ld_float32( s );
|
|
||||||
}
|
|
||||||
|
|
||||||
// generic geometry bank class, allows storage, update and drawing of geometry chunks
|
|
||||||
|
|
||||||
// creates a new geometry chunk of specified type from supplied vertex data. returns: handle to the chunk
|
|
||||||
gfx::geometry_handle
|
|
||||||
geometry_bank::create( gfx::vertex_array &Vertices, unsigned int const Type ) {
|
|
||||||
|
|
||||||
if( true == Vertices.empty() ) { return { 0, 0 }; }
|
|
||||||
|
|
||||||
m_chunks.emplace_back( Vertices, Type );
|
|
||||||
// NOTE: handle is effectively (index into chunk array + 1) this leaves value of 0 to serve as error/empty handle indication
|
|
||||||
gfx::geometry_handle chunkhandle { 0, static_cast<std::uint32_t>(m_chunks.size()) };
|
|
||||||
// template method implementation
|
|
||||||
create_( chunkhandle );
|
|
||||||
// all done
|
|
||||||
return chunkhandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
|
|
||||||
bool
|
|
||||||
geometry_bank::replace( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, std::size_t const Offset ) {
|
|
||||||
|
|
||||||
if( ( Geometry.chunk == 0 ) || ( Geometry.chunk > m_chunks.size() ) ) { return false; }
|
|
||||||
|
|
||||||
auto &chunk = gfx::geometry_bank::chunk( Geometry );
|
|
||||||
|
|
||||||
if( ( Offset == 0 )
|
|
||||||
&& ( Vertices.size() == chunk.vertices.size() ) ) {
|
|
||||||
// check first if we can get away with a simple swap...
|
|
||||||
chunk.vertices.swap( Vertices );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// ...otherwise we need to do some legwork
|
|
||||||
// NOTE: if the offset is larger than existing size of the chunk, it'll bridge the gap with 'blank' vertices
|
|
||||||
// TBD: we could bail out with an error instead if such request occurs
|
|
||||||
chunk.vertices.resize( Offset + Vertices.size(), gfx::basic_vertex() );
|
|
||||||
chunk.vertices.insert( std::end( chunk.vertices ), std::begin( Vertices ), std::end( Vertices ) );
|
|
||||||
}
|
|
||||||
// template method implementation
|
|
||||||
replace_( Geometry );
|
|
||||||
// all done
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// adds supplied vertex data at the end of specified chunk
|
|
||||||
bool
|
|
||||||
geometry_bank::append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry ) {
|
|
||||||
|
|
||||||
if( ( Geometry.chunk == 0 ) || ( Geometry.chunk > m_chunks.size() ) ) { return false; }
|
|
||||||
|
|
||||||
return replace( Vertices, Geometry, gfx::geometry_bank::chunk( Geometry ).vertices.size() );
|
|
||||||
}
|
|
||||||
|
|
||||||
// draws geometry stored in specified chunk
|
|
||||||
void
|
|
||||||
geometry_bank::draw( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) {
|
|
||||||
// template method implementation
|
|
||||||
draw_( Geometry, Units, Streams );
|
|
||||||
}
|
|
||||||
|
|
||||||
// frees subclass-specific resources associated with the bank, typically called when the bank wasn't in use for a period of time
|
|
||||||
void
|
|
||||||
geometry_bank::release() {
|
|
||||||
// template method implementation
|
|
||||||
release_();
|
|
||||||
}
|
|
||||||
|
|
||||||
vertex_array const &
|
|
||||||
geometry_bank::vertices( gfx::geometry_handle const &Geometry ) const {
|
|
||||||
|
|
||||||
return geometry_bank::chunk( Geometry ).vertices;
|
|
||||||
}
|
|
||||||
|
|
||||||
// opengl vbo-based variant of the geometry bank
|
// opengl vbo-based variant of the geometry bank
|
||||||
|
|
||||||
GLuint opengl_vbogeometrybank::m_activebuffer { 0 }; // buffer bound currently on the opengl end, if any
|
GLuint opengl_vbogeometrybank::m_activebuffer { 0 }; // buffer bound currently on the opengl end, if any
|
||||||
@@ -382,65 +278,4 @@ opengl_dlgeometrybank::delete_list( gfx::geometry_handle const &Geometry ) {
|
|||||||
chunkrecord.streams = gfx::stream::none;
|
chunkrecord.streams = gfx::stream::none;
|
||||||
}
|
}
|
||||||
|
|
||||||
// geometry bank manager, holds collection of geometry banks
|
|
||||||
|
|
||||||
// performs a resource sweep
|
|
||||||
void
|
|
||||||
geometrybank_manager::update() {
|
|
||||||
|
|
||||||
m_garbagecollector.sweep();
|
|
||||||
}
|
|
||||||
|
|
||||||
// creates a new geometry bank. returns: handle to the bank or NULL
|
|
||||||
gfx::geometrybank_handle
|
|
||||||
geometrybank_manager::create_bank() {
|
|
||||||
|
|
||||||
if( true == Global.bUseVBO ) { m_geometrybanks.emplace_back( std::make_shared<opengl_vbogeometrybank>(), std::chrono::steady_clock::time_point() ); }
|
|
||||||
else { m_geometrybanks.emplace_back( std::make_shared<opengl_dlgeometrybank>(), std::chrono::steady_clock::time_point() ); }
|
|
||||||
// NOTE: handle is effectively (index into chunk array + 1) this leaves value of 0 to serve as error/empty handle indication
|
|
||||||
return { static_cast<std::uint32_t>( m_geometrybanks.size() ), 0 };
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
|
||||||
geometrybank_manager::create_chunk( gfx::vertex_array &Vertices, gfx::geometrybank_handle const &Geometry, int const Type ) {
|
|
||||||
|
|
||||||
auto const newchunkhandle = bank( Geometry ).first->create( Vertices, Type );
|
|
||||||
|
|
||||||
if( newchunkhandle.chunk != 0 ) { return { Geometry.bank, newchunkhandle.chunk }; }
|
|
||||||
else { return { 0, 0 }; }
|
|
||||||
}
|
|
||||||
|
|
||||||
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
|
|
||||||
bool
|
|
||||||
geometrybank_manager::replace( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, std::size_t const Offset ) {
|
|
||||||
|
|
||||||
return bank( Geometry ).first->replace( Vertices, Geometry, Offset );
|
|
||||||
}
|
|
||||||
|
|
||||||
// adds supplied vertex data at the end of specified chunk
|
|
||||||
bool
|
|
||||||
geometrybank_manager::append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry ) {
|
|
||||||
|
|
||||||
return bank( Geometry ).first->append( Vertices, Geometry );
|
|
||||||
}
|
|
||||||
// draws geometry stored in specified chunk
|
|
||||||
void
|
|
||||||
geometrybank_manager::draw( gfx::geometry_handle const &Geometry, unsigned int const Streams ) {
|
|
||||||
|
|
||||||
if( Geometry == null_handle ) { return; }
|
|
||||||
|
|
||||||
auto &bankrecord = bank( Geometry );
|
|
||||||
|
|
||||||
bankrecord.second = m_garbagecollector.timestamp();
|
|
||||||
bankrecord.first->draw( Geometry, m_units, Streams );
|
|
||||||
}
|
|
||||||
|
|
||||||
// provides direct access to vertex data of specfied chunk
|
|
||||||
gfx::vertex_array const &
|
|
||||||
geometrybank_manager::vertices( gfx::geometry_handle const &Geometry ) const {
|
|
||||||
|
|
||||||
return bank( Geometry ).first->vertices( Geometry );
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace gfx
|
} // namespace gfx
|
||||||
|
|||||||
@@ -9,154 +9,10 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <vector>
|
#include "geometrybank.h"
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
|
||||||
#include "GL/glew.h"
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include "GL/wglew.h"
|
|
||||||
#endif
|
|
||||||
#include "ResourceManager.h"
|
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
|
||||||
struct basic_vertex {
|
|
||||||
|
|
||||||
glm::vec3 position; // 3d space
|
|
||||||
glm::vec3 normal; // 3d space
|
|
||||||
glm::vec2 texture; // uv space
|
|
||||||
|
|
||||||
basic_vertex() = default;
|
|
||||||
basic_vertex( glm::vec3 Position, glm::vec3 Normal, glm::vec2 Texture ) :
|
|
||||||
position( Position ), normal( Normal ), texture( Texture )
|
|
||||||
{}
|
|
||||||
void serialize( std::ostream& ) const;
|
|
||||||
void deserialize( std::istream& );
|
|
||||||
};
|
|
||||||
|
|
||||||
// data streams carried in a vertex
|
|
||||||
enum stream {
|
|
||||||
none = 0x0,
|
|
||||||
position = 0x1,
|
|
||||||
normal = 0x2,
|
|
||||||
color = 0x4, // currently normal and colour streams are stored in the same slot, and mutually exclusive
|
|
||||||
texture = 0x8
|
|
||||||
};
|
|
||||||
|
|
||||||
unsigned int const basic_streams { stream::position | stream::normal | stream::texture };
|
|
||||||
unsigned int const color_streams { stream::position | stream::color | stream::texture };
|
|
||||||
|
|
||||||
struct stream_units {
|
|
||||||
|
|
||||||
std::vector<GLint> texture { GL_TEXTURE0 }; // unit associated with main texture data stream. TODO: allow multiple units per stream
|
|
||||||
};
|
|
||||||
|
|
||||||
using vertex_array = std::vector<basic_vertex>;
|
|
||||||
|
|
||||||
// generic geometry bank class, allows storage, update and drawing of geometry chunks
|
|
||||||
|
|
||||||
struct geometry_handle {
|
|
||||||
// constructors
|
|
||||||
geometry_handle() :
|
|
||||||
bank( 0 ), chunk( 0 )
|
|
||||||
{}
|
|
||||||
geometry_handle( std::uint32_t Bank, std::uint32_t Chunk ) :
|
|
||||||
bank( Bank ), chunk( Chunk )
|
|
||||||
{}
|
|
||||||
// methods
|
|
||||||
inline
|
|
||||||
operator std::uint64_t() const {
|
|
||||||
/*
|
|
||||||
return bank << 14 | chunk; }
|
|
||||||
*/
|
|
||||||
return ( std::uint64_t { bank } << 32 | chunk );
|
|
||||||
}
|
|
||||||
|
|
||||||
// members
|
|
||||||
/*
|
|
||||||
std::uint32_t
|
|
||||||
bank : 18, // 250k banks
|
|
||||||
chunk : 14; // 16k chunks per bank
|
|
||||||
*/
|
|
||||||
std::uint32_t bank;
|
|
||||||
std::uint32_t chunk;
|
|
||||||
};
|
|
||||||
|
|
||||||
class geometry_bank {
|
|
||||||
|
|
||||||
public:
|
|
||||||
// types:
|
|
||||||
|
|
||||||
// constructors:
|
|
||||||
|
|
||||||
// destructor:
|
|
||||||
virtual
|
|
||||||
~geometry_bank() {}
|
|
||||||
|
|
||||||
// methods:
|
|
||||||
// creates a new geometry chunk of specified type from supplied vertex data. returns: handle to the chunk or NULL
|
|
||||||
gfx::geometry_handle
|
|
||||||
create( gfx::vertex_array &Vertices, unsigned int const Type );
|
|
||||||
// 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 );
|
|
||||||
// adds supplied vertex data at the end of specified chunk
|
|
||||||
bool
|
|
||||||
append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry );
|
|
||||||
// draws geometry stored in specified chunk
|
|
||||||
void
|
|
||||||
draw( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams = basic_streams );
|
|
||||||
// draws geometry stored in supplied list of chunks
|
|
||||||
template <typename Iterator_>
|
|
||||||
void
|
|
||||||
draw( Iterator_ First, Iterator_ Last, gfx::stream_units const &Units, unsigned int const Streams = basic_streams ) { while( First != Last ) { draw( *First, Units, Streams ); ++First; } }
|
|
||||||
// frees subclass-specific resources associated with the bank, typically called when the bank wasn't in use for a period of time
|
|
||||||
void
|
|
||||||
release();
|
|
||||||
// provides direct access to vertex data of specfied chunk
|
|
||||||
gfx::vertex_array const &
|
|
||||||
vertices( gfx::geometry_handle const &Geometry ) const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
// types:
|
|
||||||
struct geometry_chunk {
|
|
||||||
unsigned int type; // kind of geometry used by the chunk
|
|
||||||
gfx::vertex_array vertices; // geometry data
|
|
||||||
// NOTE: constructor doesn't copy provided vertex data, but moves it
|
|
||||||
geometry_chunk( gfx::vertex_array &Vertices, unsigned int Type ) :
|
|
||||||
type( Type )
|
|
||||||
{
|
|
||||||
vertices.swap( Vertices );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
using geometrychunk_sequence = std::vector<geometry_chunk>;
|
|
||||||
|
|
||||||
// methods
|
|
||||||
inline
|
|
||||||
geometry_chunk &
|
|
||||||
chunk( gfx::geometry_handle const Geometry ) {
|
|
||||||
return m_chunks[ Geometry.chunk - 1 ]; }
|
|
||||||
inline
|
|
||||||
geometry_chunk const &
|
|
||||||
chunk( gfx::geometry_handle const Geometry ) const {
|
|
||||||
return m_chunks[ Geometry.chunk - 1 ]; }
|
|
||||||
|
|
||||||
// members:
|
|
||||||
geometrychunk_sequence m_chunks;
|
|
||||||
|
|
||||||
private:
|
|
||||||
// methods:
|
|
||||||
// create() subclass details
|
|
||||||
virtual void create_( gfx::geometry_handle const &Geometry ) = 0;
|
|
||||||
// replace() subclass details
|
|
||||||
virtual void replace_( gfx::geometry_handle const &Geometry ) = 0;
|
|
||||||
// draw() subclass details
|
|
||||||
virtual void draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) = 0;
|
|
||||||
// resource release subclass details
|
|
||||||
virtual void release_() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
// opengl vbo-based variant of the geometry bank
|
// opengl vbo-based variant of the geometry bank
|
||||||
|
|
||||||
class opengl_vbogeometrybank : public geometry_bank {
|
class opengl_vbogeometrybank : public geometry_bank {
|
||||||
@@ -260,71 +116,4 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// geometry bank manager, holds collection of geometry banks
|
|
||||||
|
|
||||||
using geometrybank_handle = geometry_handle;
|
|
||||||
|
|
||||||
class geometrybank_manager {
|
|
||||||
|
|
||||||
public:
|
|
||||||
// constructors
|
|
||||||
geometrybank_manager() = default;
|
|
||||||
// methods:
|
|
||||||
// performs a resource sweep
|
|
||||||
void update();
|
|
||||||
// creates a new geometry bank. returns: handle to the bank or NULL
|
|
||||||
gfx::geometrybank_handle
|
|
||||||
create_bank();
|
|
||||||
// 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
|
|
||||||
create_chunk( gfx::vertex_array &Vertices, gfx::geometrybank_handle const &Geometry, int const Type );
|
|
||||||
// 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 );
|
|
||||||
// adds supplied vertex data at the end of specified chunk
|
|
||||||
bool
|
|
||||||
append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry );
|
|
||||||
// draws geometry stored in specified chunk
|
|
||||||
void
|
|
||||||
draw( gfx::geometry_handle const &Geometry, unsigned int const Streams = basic_streams );
|
|
||||||
template <typename Iterator_>
|
|
||||||
void
|
|
||||||
draw( Iterator_ First, Iterator_ Last, unsigned int const Streams = basic_streams ) {
|
|
||||||
while( First != Last ) {
|
|
||||||
draw( *First, Streams );
|
|
||||||
++First; } }
|
|
||||||
// provides direct access to vertex data of specfied chunk
|
|
||||||
gfx::vertex_array const &
|
|
||||||
vertices( gfx::geometry_handle const &Geometry ) const;
|
|
||||||
// sets target texture unit for the texture data stream
|
|
||||||
gfx::stream_units &
|
|
||||||
units() { return m_units; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
// types:
|
|
||||||
using geometrybanktimepoint_pair = std::pair< std::shared_ptr<geometry_bank>, resource_timestamp >;
|
|
||||||
using geometrybanktimepointpair_sequence = std::deque< geometrybanktimepoint_pair >;
|
|
||||||
|
|
||||||
// members:
|
|
||||||
geometrybanktimepointpair_sequence m_geometrybanks;
|
|
||||||
garbage_collector<geometrybanktimepointpair_sequence> m_garbagecollector { m_geometrybanks, 60, 120, "geometry buffer" };
|
|
||||||
gfx::stream_units m_units;
|
|
||||||
|
|
||||||
// methods
|
|
||||||
inline
|
|
||||||
bool
|
|
||||||
valid( gfx::geometry_handle const &Geometry ) const {
|
|
||||||
return ( ( Geometry.bank != 0 )
|
|
||||||
&& ( Geometry.bank <= m_geometrybanks.size() ) ); }
|
|
||||||
inline
|
|
||||||
geometrybanktimepointpair_sequence::value_type &
|
|
||||||
bank( gfx::geometry_handle const Geometry ) {
|
|
||||||
return m_geometrybanks[ Geometry.bank - 1 ]; }
|
|
||||||
inline
|
|
||||||
geometrybanktimepointpair_sequence::value_type const &
|
|
||||||
bank( gfx::geometry_handle const Geometry ) const {
|
|
||||||
return m_geometrybanks[ Geometry.bank - 1 ]; }
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace gfx
|
} // namespace gfx
|
||||||
44
opengllight.cpp
Normal file
44
opengllight.cpp
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
This Source Code Form is subject to the
|
||||||
|
terms of the Mozilla Public License, v.
|
||||||
|
2.0. If a copy of the MPL was not
|
||||||
|
distributed with this file, You can
|
||||||
|
obtain one at
|
||||||
|
http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "stdafx.h"
|
||||||
|
|
||||||
|
#include "opengllight.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
opengl_light::apply_intensity( float const Factor ) {
|
||||||
|
|
||||||
|
if( Factor == 1.f ) {
|
||||||
|
|
||||||
|
::glLightfv( id, GL_AMBIENT, glm::value_ptr( ambient ) );
|
||||||
|
::glLightfv( id, GL_DIFFUSE, glm::value_ptr( diffuse ) );
|
||||||
|
::glLightfv( id, GL_SPECULAR, glm::value_ptr( specular ) );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
auto const factor{ clamp( Factor, 0.05f, 1.f ) };
|
||||||
|
// temporary light scaling mechanics (ultimately this work will be left to the shaders
|
||||||
|
glm::vec4 scaledambient( ambient.r * factor, ambient.g * factor, ambient.b * factor, ambient.a );
|
||||||
|
glm::vec4 scaleddiffuse( diffuse.r * factor, diffuse.g * factor, diffuse.b * factor, diffuse.a );
|
||||||
|
glm::vec4 scaledspecular( specular.r * factor, specular.g * factor, specular.b * factor, specular.a );
|
||||||
|
glLightfv( id, GL_AMBIENT, glm::value_ptr( scaledambient ) );
|
||||||
|
glLightfv( id, GL_DIFFUSE, glm::value_ptr( scaleddiffuse ) );
|
||||||
|
glLightfv( id, GL_SPECULAR, glm::value_ptr( scaledspecular ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
opengl_light::apply_angle() {
|
||||||
|
|
||||||
|
::glLightfv( id, GL_POSITION, glm::value_ptr( glm::vec4{ position, ( is_directional ? 0.f : 1.f ) } ) );
|
||||||
|
if( false == is_directional ) {
|
||||||
|
::glLightfv( id, GL_SPOT_DIRECTION, glm::value_ptr( direction ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
30
opengllight.h
Normal file
30
opengllight.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
This Source Code Form is subject to the
|
||||||
|
terms of the Mozilla Public License, v.
|
||||||
|
2.0. If a copy of the MPL was not
|
||||||
|
distributed with this file, You can
|
||||||
|
obtain one at
|
||||||
|
http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "GL/glew.h"
|
||||||
|
#include "light.h"
|
||||||
|
|
||||||
|
struct opengl_light : public basic_light {
|
||||||
|
|
||||||
|
GLuint id { (GLuint)-1 };
|
||||||
|
|
||||||
|
void
|
||||||
|
apply_intensity( float const Factor = 1.0f );
|
||||||
|
void
|
||||||
|
apply_angle();
|
||||||
|
|
||||||
|
opengl_light &
|
||||||
|
operator=( basic_light const &Right ) {
|
||||||
|
basic_light::operator=( Right );
|
||||||
|
return *this; }
|
||||||
|
};
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
158
openglparticles.cpp
Normal file
158
openglparticles.cpp
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
/*
|
||||||
|
This Source Code Form is subject to the
|
||||||
|
terms of the Mozilla Public License, v.
|
||||||
|
2.0. If a copy of the MPL was not
|
||||||
|
distributed with this file, You can
|
||||||
|
obtain one at
|
||||||
|
http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "stdafx.h"
|
||||||
|
#include "openglparticles.h"
|
||||||
|
|
||||||
|
#include "particles.h"
|
||||||
|
#include "openglcamera.h"
|
||||||
|
#include "simulation.h"
|
||||||
|
#include "Logs.h"
|
||||||
|
|
||||||
|
std::vector<std::pair<glm::vec3, glm::vec2>> const billboard_vertices {
|
||||||
|
|
||||||
|
{ { -0.5f, -0.5f, 0.f }, { 0.f, 0.f } },
|
||||||
|
{ { 0.5f, -0.5f, 0.f }, { 1.f, 0.f } },
|
||||||
|
{ { 0.5f, 0.5f, 0.f }, { 1.f, 1.f } },
|
||||||
|
{ { -0.5f, 0.5f, 0.f }, { 0.f, 1.f } }
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
opengl_particles::update( opengl_camera const &Camera ) {
|
||||||
|
|
||||||
|
m_particlevertices.clear();
|
||||||
|
|
||||||
|
if( false == Global.Smoke ) { return; }
|
||||||
|
|
||||||
|
// build a list of visible smoke sources
|
||||||
|
// NOTE: arranged by distance to camera, if we ever need sorting and/or total amount cap-based culling
|
||||||
|
std::multimap<float, smoke_source const &> sources;
|
||||||
|
|
||||||
|
for( auto const &source : simulation::Particles.sequence() ) {
|
||||||
|
if( false == Camera.visible( source.area() ) ) { continue; }
|
||||||
|
// NOTE: the distance is negative when the camera is inside the source's bounding area
|
||||||
|
sources.emplace(
|
||||||
|
static_cast<float>( glm::length( Camera.position() - source.area().center ) - source.area().radius ),
|
||||||
|
source );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( true == sources.empty() ) { return; }
|
||||||
|
|
||||||
|
// build billboard data for particles from visible sources
|
||||||
|
auto const camerarotation { glm::mat3( Camera.modelview() ) };
|
||||||
|
particle_vertex vertex;
|
||||||
|
for( auto const &source : sources ) {
|
||||||
|
|
||||||
|
auto const particlecolor {
|
||||||
|
glm::clamp(
|
||||||
|
source.second.color()
|
||||||
|
* ( glm::vec3 { Global.DayLight.ambient } + 0.35f * glm::vec3{ Global.DayLight.diffuse } )
|
||||||
|
* 255.f,
|
||||||
|
glm::vec3{ 0.f }, glm::vec3{ 255.f } ) };
|
||||||
|
auto const &particles { source.second.sequence() };
|
||||||
|
// TODO: put sanity cap on the overall amount of particles that can be drawn
|
||||||
|
auto const sizestep { 256.0 * billboard_vertices.size() };
|
||||||
|
m_particlevertices.reserve(
|
||||||
|
sizestep * std::ceil( m_particlevertices.size() + ( particles.size() * billboard_vertices.size() ) / sizestep ) );
|
||||||
|
for( auto const &particle : particles ) {
|
||||||
|
// TODO: particle color support
|
||||||
|
vertex.color[ 0 ] = static_cast<std::uint_fast8_t>( particlecolor.r );
|
||||||
|
vertex.color[ 1 ] = static_cast<std::uint_fast8_t>( particlecolor.g );
|
||||||
|
vertex.color[ 2 ] = static_cast<std::uint_fast8_t>( particlecolor.b );
|
||||||
|
vertex.color[ 3 ] = clamp<std::uint8_t>( particle.opacity * 255, 0, 255 );
|
||||||
|
|
||||||
|
auto const offset { glm::vec3{ particle.position - Camera.position() } };
|
||||||
|
auto const rotation { glm::angleAxis( particle.rotation, glm::vec3{ 0.f, 0.f, 1.f } ) };
|
||||||
|
|
||||||
|
for( auto const &billboardvertex : billboard_vertices ) {
|
||||||
|
vertex.position = offset + ( rotation * billboardvertex.first * particle.size ) * camerarotation;
|
||||||
|
vertex.texture = billboardvertex.second;
|
||||||
|
|
||||||
|
m_particlevertices.emplace_back( vertex );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ship the billboard data to the gpu:
|
||||||
|
// setup...
|
||||||
|
::glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT );
|
||||||
|
// ...make sure we have enough room...
|
||||||
|
if( m_buffercapacity < m_particlevertices.size() ) {
|
||||||
|
// allocate gpu side buffer big enough to hold the data
|
||||||
|
m_buffercapacity = 0;
|
||||||
|
if( m_buffer != (GLuint)-1 ) {
|
||||||
|
// get rid of the old buffer
|
||||||
|
::glDeleteBuffers( 1, &m_buffer );
|
||||||
|
m_buffer = (GLuint)-1;
|
||||||
|
}
|
||||||
|
::glGenBuffers( 1, &m_buffer );
|
||||||
|
if( ( m_buffer > 0 ) && ( m_buffer != (GLuint)-1 ) ) {
|
||||||
|
// if we didn't get a buffer we'll try again during the next draw call
|
||||||
|
// NOTE: we match capacity instead of current size to reduce number of re-allocations
|
||||||
|
auto const particlecount { m_particlevertices.capacity() };
|
||||||
|
::glBindBuffer( GL_ARRAY_BUFFER, m_buffer );
|
||||||
|
::glBufferData(
|
||||||
|
GL_ARRAY_BUFFER,
|
||||||
|
particlecount * sizeof( particle_vertex ),
|
||||||
|
nullptr,
|
||||||
|
GL_DYNAMIC_DRAW );
|
||||||
|
if( ::glGetError() == GL_OUT_OF_MEMORY ) {
|
||||||
|
// TBD: throw a bad_alloc?
|
||||||
|
ErrorLog( "openGL error: out of memory; failed to create a geometry buffer" );
|
||||||
|
::glDeleteBuffers( 1, &m_buffer );
|
||||||
|
m_buffer = (GLuint)-1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_buffercapacity = particlecount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ...send the data...
|
||||||
|
if( ( m_buffer > 0 ) && ( m_buffer != (GLuint)-1 ) ) {
|
||||||
|
// if the buffer exists at this point it's guaranteed to be big enough to hold our data
|
||||||
|
::glBindBuffer( GL_ARRAY_BUFFER, m_buffer );
|
||||||
|
::glBufferSubData(
|
||||||
|
GL_ARRAY_BUFFER,
|
||||||
|
0,
|
||||||
|
m_particlevertices.size() * sizeof( particle_vertex ),
|
||||||
|
m_particlevertices.data() );
|
||||||
|
}
|
||||||
|
// ...and cleanup
|
||||||
|
::glPopClientAttrib();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
opengl_particles::render( int const Textureunit ) {
|
||||||
|
|
||||||
|
if( false == Global.Smoke ) { return; }
|
||||||
|
if( m_buffercapacity == 0 ) { return; }
|
||||||
|
if( m_particlevertices.empty() ) { return; }
|
||||||
|
if( ( m_buffer == 0 ) || ( m_buffer == (GLuint)-1 ) ) { return; }
|
||||||
|
|
||||||
|
// setup...
|
||||||
|
::glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT );
|
||||||
|
::glBindBuffer( GL_ARRAY_BUFFER, m_buffer );
|
||||||
|
::glVertexPointer( 3, GL_FLOAT, sizeof( particle_vertex ), static_cast<char *>( nullptr ) );
|
||||||
|
::glEnableClientState( GL_VERTEX_ARRAY );
|
||||||
|
::glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof( particle_vertex ), static_cast<char *>( nullptr ) + sizeof( float ) * 3 );
|
||||||
|
::glEnableClientState( GL_COLOR_ARRAY );
|
||||||
|
::glClientActiveTexture( Textureunit );
|
||||||
|
::glTexCoordPointer( 2, GL_FLOAT, sizeof( particle_vertex ), static_cast<char *>( nullptr ) + sizeof( float ) * 3 + sizeof( std::uint8_t ) * 4 );
|
||||||
|
::glEnableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||||
|
// ...draw...
|
||||||
|
::glDrawArrays( GL_QUADS, 0, m_particlevertices.size() );
|
||||||
|
// ...and cleanup
|
||||||
|
::glBindBuffer( GL_ARRAY_BUFFER, 0 );
|
||||||
|
if( Global.bUseVBO ) {
|
||||||
|
gfx::opengl_vbogeometrybank::reset();
|
||||||
|
}
|
||||||
|
::glPopClientAttrib();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
53
openglparticles.h
Normal file
53
openglparticles.h
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
This Source Code Form is subject to the
|
||||||
|
terms of the Mozilla Public License, v.
|
||||||
|
2.0. If a copy of the MPL was not
|
||||||
|
distributed with this file, You can
|
||||||
|
obtain one at
|
||||||
|
http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "GL/glew.h"
|
||||||
|
|
||||||
|
class opengl_camera;
|
||||||
|
|
||||||
|
// particle data visualizer
|
||||||
|
class opengl_particles {
|
||||||
|
public:
|
||||||
|
// constructors
|
||||||
|
opengl_particles() = default;
|
||||||
|
// destructor
|
||||||
|
~opengl_particles() {
|
||||||
|
if( m_buffer != 0 ) {
|
||||||
|
::glDeleteBuffers( 1, &m_buffer ); } }
|
||||||
|
// methods
|
||||||
|
void
|
||||||
|
update( opengl_camera const &Camera );
|
||||||
|
void
|
||||||
|
render( int const Textureunit );
|
||||||
|
private:
|
||||||
|
// types
|
||||||
|
struct particle_vertex {
|
||||||
|
glm::vec3 position; // 3d space
|
||||||
|
std::uint8_t color[ 4 ]; // rgba, unsigned byte format
|
||||||
|
glm::vec2 texture; // uv space
|
||||||
|
float padding[ 2 ]; // experimental, some gfx hardware allegedly works better with 32-bit aligned data blocks
|
||||||
|
};
|
||||||
|
/*
|
||||||
|
using sourcedistance_pair = std::pair<smoke_source *, float>;
|
||||||
|
using source_sequence = std::vector<sourcedistance_pair>;
|
||||||
|
*/
|
||||||
|
using particlevertex_sequence = std::vector<particle_vertex>;
|
||||||
|
// methods
|
||||||
|
// members
|
||||||
|
/*
|
||||||
|
source_sequence m_sources; // list of particle sources visible in current render pass, with their respective distances to the camera
|
||||||
|
*/
|
||||||
|
particlevertex_sequence m_particlevertices; // geometry data of visible particles, generated on the cpu end
|
||||||
|
GLuint m_buffer{ (GLuint)-1 }; // id of the buffer holding geometry data on the opengl end
|
||||||
|
std::size_t m_buffercapacity{ 0 }; // total capacity of the last established buffer
|
||||||
|
};
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
4088
openglrenderer.cpp
Normal file
4088
openglrenderer.cpp
Normal file
File diff suppressed because it is too large
Load Diff
331
openglrenderer.h
Normal file
331
openglrenderer.h
Normal file
@@ -0,0 +1,331 @@
|
|||||||
|
/*
|
||||||
|
This Source Code Form is subject to the
|
||||||
|
terms of the Mozilla Public License, v.
|
||||||
|
2.0. If a copy of the MPL was not
|
||||||
|
distributed with this file, You can
|
||||||
|
obtain one at
|
||||||
|
http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "GL/glew.h"
|
||||||
|
#include "renderer.h"
|
||||||
|
#include "opengllight.h"
|
||||||
|
#include "openglcamera.h"
|
||||||
|
#include "openglparticles.h"
|
||||||
|
#include "lightarray.h"
|
||||||
|
#include "scene.h"
|
||||||
|
#include "simulationenvironment.h"
|
||||||
|
#include "MemCell.h"
|
||||||
|
|
||||||
|
#define EU07_USE_PICKING_FRAMEBUFFER
|
||||||
|
//#define EU07_USE_DEBUG_SHADOWMAP
|
||||||
|
//#define EU07_USE_DEBUG_CABSHADOWMAP
|
||||||
|
//#define EU07_USE_DEBUG_CAMERA
|
||||||
|
//#define EU07_USE_DEBUG_SOUNDEMITTERS
|
||||||
|
//#define EU07_USEIMGUIIMPLOPENGL2
|
||||||
|
//#define EU07_DISABLECABREFLECTIONS
|
||||||
|
|
||||||
|
// bare-bones render controller, in lack of anything better yet
|
||||||
|
class opengl_renderer : public gfx_renderer {
|
||||||
|
|
||||||
|
public:
|
||||||
|
// types
|
||||||
|
// constructors
|
||||||
|
opengl_renderer() = default;
|
||||||
|
// destructor
|
||||||
|
~opengl_renderer() { gluDeleteQuadric( m_quadric ); }
|
||||||
|
// methods
|
||||||
|
bool
|
||||||
|
Init( GLFWwindow *Window ) override;
|
||||||
|
// main draw call. returns false on error
|
||||||
|
bool
|
||||||
|
Render() override;
|
||||||
|
inline
|
||||||
|
float
|
||||||
|
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() 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 ) 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 ) override;
|
||||||
|
// adds supplied vertex data at the end of specified chunk
|
||||||
|
bool
|
||||||
|
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 override;
|
||||||
|
// material methods
|
||||||
|
material_handle
|
||||||
|
Fetch_Material( std::string const &Filename, bool const Loadnow = true ) override;
|
||||||
|
void
|
||||||
|
Bind_Material( material_handle const Material ) override;
|
||||||
|
opengl_material const &
|
||||||
|
Material( material_handle const Material ) const override;
|
||||||
|
// texture methods
|
||||||
|
texture_handle
|
||||||
|
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 override;
|
||||||
|
// utility methods
|
||||||
|
TSubModel const *
|
||||||
|
Pick_Control() const override { return m_pickcontrolitem; }
|
||||||
|
scene::basic_node const *
|
||||||
|
Pick_Node() const override { return m_picksceneryitem; }
|
||||||
|
glm::dvec3
|
||||||
|
Mouse_Position() const override { return m_worldmousecoordinates; }
|
||||||
|
// maintenance methods
|
||||||
|
void
|
||||||
|
Update( double const Deltatime ) override;
|
||||||
|
TSubModel *
|
||||||
|
Update_Pick_Control() override;
|
||||||
|
scene::basic_node *
|
||||||
|
Update_Pick_Node() override;
|
||||||
|
glm::dvec3
|
||||||
|
Update_Mouse_Position() override;
|
||||||
|
// debug methods
|
||||||
|
std::string const &
|
||||||
|
info_times() const override;
|
||||||
|
std::string const &
|
||||||
|
info_stats() const override;
|
||||||
|
|
||||||
|
// members
|
||||||
|
GLenum static const sunlight { GL_LIGHT0 };
|
||||||
|
std::size_t m_drawcount { 0 };
|
||||||
|
|
||||||
|
private:
|
||||||
|
// types
|
||||||
|
enum class rendermode {
|
||||||
|
none,
|
||||||
|
color,
|
||||||
|
shadows,
|
||||||
|
cabshadows,
|
||||||
|
reflections,
|
||||||
|
pickcontrols,
|
||||||
|
pickscenery
|
||||||
|
};
|
||||||
|
|
||||||
|
enum textureunit {
|
||||||
|
helper = 0,
|
||||||
|
shadows,
|
||||||
|
normals,
|
||||||
|
diffuse
|
||||||
|
};
|
||||||
|
|
||||||
|
struct debug_stats {
|
||||||
|
int dynamics { 0 };
|
||||||
|
int models { 0 };
|
||||||
|
int submodels { 0 };
|
||||||
|
int paths { 0 };
|
||||||
|
int traction { 0 };
|
||||||
|
int shapes { 0 };
|
||||||
|
int lines { 0 };
|
||||||
|
int drawcalls { 0 };
|
||||||
|
};
|
||||||
|
|
||||||
|
using section_sequence = std::vector<scene::basic_section *>;
|
||||||
|
using distancecell_pair = std::pair<double, scene::basic_cell *>;
|
||||||
|
using cell_sequence = std::vector<distancecell_pair>;
|
||||||
|
|
||||||
|
struct renderpass_config {
|
||||||
|
|
||||||
|
opengl_camera camera;
|
||||||
|
rendermode draw_mode { rendermode::none };
|
||||||
|
float draw_range { 0.0f };
|
||||||
|
};
|
||||||
|
|
||||||
|
struct units_state {
|
||||||
|
|
||||||
|
bool diffuse { false };
|
||||||
|
bool shadows { false };
|
||||||
|
bool reflections { false };
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::vector<opengl_light> opengllight_array;
|
||||||
|
|
||||||
|
// methods
|
||||||
|
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
|
||||||
|
setup_matrices();
|
||||||
|
void
|
||||||
|
setup_drawing( bool const Alpha = false );
|
||||||
|
void
|
||||||
|
setup_units( bool const Diffuse, bool const Shadows, bool const Reflections );
|
||||||
|
void
|
||||||
|
setup_shadow_map( GLuint const Texture, glm::mat4 const &Transformation );
|
||||||
|
void
|
||||||
|
setup_shadow_color( glm::vec4 const &Shadowcolor );
|
||||||
|
void
|
||||||
|
setup_environment_light( TEnvironmentType const Environment = e_flat );
|
||||||
|
void
|
||||||
|
switch_units( bool const Diffuse, bool const Shadows, bool const Reflections );
|
||||||
|
// helper, texture manager method; activates specified texture unit
|
||||||
|
void
|
||||||
|
select_unit( GLint const Textureunit );
|
||||||
|
// runs jobs needed to generate graphics for specified render pass
|
||||||
|
void
|
||||||
|
Render_pass( rendermode const Mode );
|
||||||
|
// creates dynamic environment cubemap
|
||||||
|
bool
|
||||||
|
Render_reflections();
|
||||||
|
bool
|
||||||
|
Render( world_environment *Environment );
|
||||||
|
void
|
||||||
|
Render( scene::basic_region *Region );
|
||||||
|
void
|
||||||
|
Render( section_sequence::iterator First, section_sequence::iterator Last );
|
||||||
|
void
|
||||||
|
Render( cell_sequence::iterator First, cell_sequence::iterator Last );
|
||||||
|
void
|
||||||
|
Render( scene::shape_node const &Shape, bool const Ignorerange );
|
||||||
|
void
|
||||||
|
Render( TAnimModel *Instance );
|
||||||
|
bool
|
||||||
|
Render( TDynamicObject *Dynamic );
|
||||||
|
bool
|
||||||
|
Render( TModel3d *Model, material_data const *Material, float const Squaredistance, Math3D::vector3 const &Position, glm::vec3 const &Angle );
|
||||||
|
bool
|
||||||
|
Render( TModel3d *Model, material_data const *Material, float const Squaredistance );
|
||||||
|
void
|
||||||
|
Render( TSubModel *Submodel );
|
||||||
|
void
|
||||||
|
Render( TTrack *Track );
|
||||||
|
void
|
||||||
|
Render( scene::basic_cell::path_sequence::const_iterator First, scene::basic_cell::path_sequence::const_iterator Last );
|
||||||
|
bool
|
||||||
|
Render_cab( TDynamicObject const *Dynamic, float const Lightlevel, bool const Alpha = false );
|
||||||
|
void
|
||||||
|
Render( TMemCell *Memcell );
|
||||||
|
void
|
||||||
|
Render_particles();
|
||||||
|
void
|
||||||
|
Render_precipitation();
|
||||||
|
void
|
||||||
|
Render_Alpha( scene::basic_region *Region );
|
||||||
|
void
|
||||||
|
Render_Alpha( cell_sequence::reverse_iterator First, cell_sequence::reverse_iterator Last );
|
||||||
|
void
|
||||||
|
Render_Alpha( TAnimModel *Instance );
|
||||||
|
void
|
||||||
|
Render_Alpha( TTraction *Traction );
|
||||||
|
void
|
||||||
|
Render_Alpha( scene::lines_node const &Lines );
|
||||||
|
bool
|
||||||
|
Render_Alpha( TDynamicObject *Dynamic );
|
||||||
|
bool
|
||||||
|
Render_Alpha( TModel3d *Model, material_data const *Material, float const Squaredistance, Math3D::vector3 const &Position, glm::vec3 const &Angle );
|
||||||
|
bool
|
||||||
|
Render_Alpha( TModel3d *Model, material_data const *Material, float const Squaredistance );
|
||||||
|
void
|
||||||
|
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
|
||||||
|
pick_index( glm::ivec3 const &Color );
|
||||||
|
|
||||||
|
// members
|
||||||
|
GLFWwindow *m_window { nullptr };
|
||||||
|
gfx::geometrybank_manager m_geometry;
|
||||||
|
material_manager m_materials;
|
||||||
|
texture_manager m_textures;
|
||||||
|
opengl_light m_sunlight;
|
||||||
|
opengllight_array m_lights;
|
||||||
|
/*
|
||||||
|
float m_sunandviewangle; // cached dot product of sunlight and camera vectors
|
||||||
|
*/
|
||||||
|
gfx::geometry_handle m_billboardgeometry { 0, 0 };
|
||||||
|
texture_handle m_glaretexture { -1 };
|
||||||
|
texture_handle m_suntexture { -1 };
|
||||||
|
texture_handle m_moontexture { -1 };
|
||||||
|
texture_handle m_reflectiontexture { -1 };
|
||||||
|
texture_handle m_smoketexture { -1 };
|
||||||
|
GLUquadricObj *m_quadric { nullptr }; // helper object for drawing debug mode scene elements
|
||||||
|
// TODO: refactor framebuffer stuff into an object
|
||||||
|
bool m_framebuffersupport { false };
|
||||||
|
#ifdef EU07_USE_PICKING_FRAMEBUFFER
|
||||||
|
GLuint m_pickframebuffer { 0 };
|
||||||
|
GLuint m_picktexture { 0 };
|
||||||
|
GLuint m_pickdepthbuffer { 0 };
|
||||||
|
#endif
|
||||||
|
// main shadowmap resources
|
||||||
|
int m_shadowbuffersize { 2048 };
|
||||||
|
GLuint m_shadowframebuffer { 0 };
|
||||||
|
GLuint m_shadowtexture { 0 };
|
||||||
|
#ifdef EU07_USE_DEBUG_SHADOWMAP
|
||||||
|
GLuint m_shadowdebugtexture{ 0 };
|
||||||
|
#endif
|
||||||
|
#ifdef EU07_USE_DEBUG_CABSHADOWMAP
|
||||||
|
GLuint m_cabshadowdebugtexture{ 0 };
|
||||||
|
#endif
|
||||||
|
glm::mat4 m_shadowtexturematrix; // conversion from camera-centric world space to light-centric clip space
|
||||||
|
// cab shadowmap resources
|
||||||
|
GLuint m_cabshadowframebuffer { 0 };
|
||||||
|
GLuint m_cabshadowtexture { 0 };
|
||||||
|
glm::mat4 m_cabshadowtexturematrix; // conversion from cab-centric world space to light-centric clip space
|
||||||
|
// environment map resources
|
||||||
|
GLuint m_environmentframebuffer { 0 };
|
||||||
|
GLuint m_environmentcubetexture { 0 };
|
||||||
|
GLuint m_environmentdepthbuffer { 0 };
|
||||||
|
bool m_environmentcubetexturesupport { false }; // indicates whether we can use the dynamic environment cube map
|
||||||
|
int m_environmentcubetextureface { 0 }; // helper, currently processed cube map face
|
||||||
|
int m_environmentupdatetime { 0 }; // time of the most recent environment map update
|
||||||
|
glm::dvec3 m_environmentupdatelocation; // coordinates of most recent environment map update
|
||||||
|
// particle visualization subsystem
|
||||||
|
opengl_particles m_particlerenderer;
|
||||||
|
|
||||||
|
int m_helpertextureunit { GL_TEXTURE0 };
|
||||||
|
int m_shadowtextureunit { GL_TEXTURE1 };
|
||||||
|
int m_normaltextureunit { GL_TEXTURE2 };
|
||||||
|
int m_diffusetextureunit{ GL_TEXTURE3 };
|
||||||
|
units_state m_unitstate;
|
||||||
|
|
||||||
|
unsigned int m_framestamp; // id of currently rendered gfx frame
|
||||||
|
float m_framerate;
|
||||||
|
double m_updateaccumulator { 0.0 };
|
||||||
|
// double m_pickupdateaccumulator { 0.0 };
|
||||||
|
std::string m_debugtimestext;
|
||||||
|
std::string m_pickdebuginfo;
|
||||||
|
debug_stats m_debugstats;
|
||||||
|
std::string m_debugstatstext;
|
||||||
|
|
||||||
|
glm::vec4 m_baseambient { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||||
|
glm::vec4 m_shadowcolor { colors::shadow };
|
||||||
|
float m_fogrange { 2000.f };
|
||||||
|
// TEnvironmentType m_environment { e_flat };
|
||||||
|
float m_specularopaquescalefactor { 1.f };
|
||||||
|
float m_speculartranslucentscalefactor { 1.f };
|
||||||
|
bool m_renderspecular{ false }; // controls whether to include specular component in the calculations
|
||||||
|
|
||||||
|
renderpass_config m_renderpass; // parameters for current render pass
|
||||||
|
section_sequence m_sectionqueue; // list of sections in current render pass
|
||||||
|
cell_sequence m_cellqueue;
|
||||||
|
renderpass_config m_colorpass; // parametrs of most recent color pass
|
||||||
|
renderpass_config m_shadowpass; // parametrs of most recent shadowmap pass
|
||||||
|
renderpass_config m_cabshadowpass; // parameters of most recent cab shadowmap pass
|
||||||
|
std::vector<TSubModel *> m_pickcontrolsitems;
|
||||||
|
TSubModel *m_pickcontrolitem { nullptr };
|
||||||
|
std::vector<scene::basic_node *> m_picksceneryitems;
|
||||||
|
scene::basic_node *m_picksceneryitem { nullptr };
|
||||||
|
glm::vec3 m_worldmousecoordinates { 0.f };
|
||||||
|
#ifdef EU07_USE_DEBUG_CAMERA
|
||||||
|
renderpass_config m_worldcamera; // debug item
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
4296
renderer.cpp
4296
renderer.cpp
File diff suppressed because it is too large
Load Diff
448
renderer.h
448
renderer.h
@@ -9,25 +9,8 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "GL/glew.h"
|
#include "geometrybank.h"
|
||||||
#include "openglgeometrybank.h"
|
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
#include "light.h"
|
|
||||||
#include "lightarray.h"
|
|
||||||
#include "dumb3d.h"
|
|
||||||
#include "frustum.h"
|
|
||||||
#include "scene.h"
|
|
||||||
#include "simulationenvironment.h"
|
|
||||||
#include "particles.h"
|
|
||||||
#include "MemCell.h"
|
|
||||||
|
|
||||||
#define EU07_USE_PICKING_FRAMEBUFFER
|
|
||||||
//#define EU07_USE_DEBUG_SHADOWMAP
|
|
||||||
//#define EU07_USE_DEBUG_CABSHADOWMAP
|
|
||||||
//#define EU07_USE_DEBUG_CAMERA
|
|
||||||
//#define EU07_USE_DEBUG_SOUNDEMITTERS
|
|
||||||
//#define EU07_USEIMGUIIMPLOPENGL2
|
|
||||||
//#define EU07_DISABLECABREFLECTIONS
|
|
||||||
|
|
||||||
class gfx_renderer {
|
class gfx_renderer {
|
||||||
|
|
||||||
@@ -75,435 +58,6 @@ public:
|
|||||||
virtual auto info_stats() const -> std::string const & = 0;
|
virtual auto info_stats() const -> std::string const & = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct opengl_light : public basic_light {
|
|
||||||
|
|
||||||
GLuint id { (GLuint)-1 };
|
|
||||||
|
|
||||||
void
|
|
||||||
apply_intensity( float const Factor = 1.0f );
|
|
||||||
void
|
|
||||||
apply_angle();
|
|
||||||
|
|
||||||
opengl_light &
|
|
||||||
operator=( basic_light const &Right ) {
|
|
||||||
basic_light::operator=( Right );
|
|
||||||
return *this; }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// encapsulates basic rendering setup.
|
|
||||||
// for modern opengl this translates to a specific collection of glsl shaders,
|
|
||||||
// for legacy opengl this is combination of blending modes, active texture units etc
|
|
||||||
struct opengl_technique {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// simple camera object. paired with 'virtual camera' in the scene
|
|
||||||
class opengl_camera {
|
|
||||||
|
|
||||||
public:
|
|
||||||
// constructors
|
|
||||||
opengl_camera() = default;
|
|
||||||
// methods:
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
update_frustum() { update_frustum( m_projection, m_modelview ); }
|
|
||||||
void
|
|
||||||
update_frustum( glm::mat4 const &Projection, glm::mat4 const &Modelview );
|
|
||||||
bool
|
|
||||||
visible( scene::bounding_area const &Area ) const;
|
|
||||||
bool
|
|
||||||
visible( TDynamicObject const *Dynamic ) const;
|
|
||||||
inline
|
|
||||||
glm::dvec3 const &
|
|
||||||
position() const { return m_position; }
|
|
||||||
inline
|
|
||||||
glm::dvec3 &
|
|
||||||
position() { return m_position; }
|
|
||||||
inline
|
|
||||||
glm::mat4 const &
|
|
||||||
projection() const { return m_projection; }
|
|
||||||
inline
|
|
||||||
glm::mat4 &
|
|
||||||
projection() { return m_projection; }
|
|
||||||
inline
|
|
||||||
glm::mat4 const &
|
|
||||||
modelview() const { return m_modelview; }
|
|
||||||
inline
|
|
||||||
glm::mat4 &
|
|
||||||
modelview() { return m_modelview; }
|
|
||||||
inline
|
|
||||||
std::vector<glm::vec4> &
|
|
||||||
frustum_points() { return m_frustumpoints; }
|
|
||||||
// transforms provided set of clip space points to world space
|
|
||||||
template <class Iterator_>
|
|
||||||
void
|
|
||||||
transform_to_world( Iterator_ First, Iterator_ Last ) const {
|
|
||||||
std::for_each(
|
|
||||||
First, Last,
|
|
||||||
[this]( glm::vec4 &point ) {
|
|
||||||
// transform each point using the cached matrix...
|
|
||||||
point = this->m_inversetransformation * point;
|
|
||||||
// ...and scale by transformed w
|
|
||||||
point = glm::vec4{ glm::vec3{ point } / point.w, 1.f }; } ); }
|
|
||||||
// debug helper, draws shape of frustum in world space
|
|
||||||
void
|
|
||||||
draw( glm::vec3 const &Offset ) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
// members:
|
|
||||||
cFrustum m_frustum;
|
|
||||||
std::vector<glm::vec4> m_frustumpoints; // visualization helper; corners of defined frustum, in world space
|
|
||||||
glm::dvec3 m_position;
|
|
||||||
glm::mat4 m_projection;
|
|
||||||
glm::mat4 m_modelview;
|
|
||||||
glm::mat4 m_inversetransformation; // cached transformation to world space
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// particle data visualizer
|
|
||||||
class opengl_particles {
|
|
||||||
public:
|
|
||||||
// constructors
|
|
||||||
opengl_particles() = default;
|
|
||||||
// destructor
|
|
||||||
~opengl_particles() {
|
|
||||||
if( m_buffer != 0 ) {
|
|
||||||
::glDeleteBuffers( 1, &m_buffer ); } }
|
|
||||||
// methods
|
|
||||||
void
|
|
||||||
update( opengl_camera const &Camera );
|
|
||||||
void
|
|
||||||
render( int const Textureunit );
|
|
||||||
private:
|
|
||||||
// types
|
|
||||||
struct particle_vertex {
|
|
||||||
glm::vec3 position; // 3d space
|
|
||||||
std::uint8_t color[ 4 ]; // rgba, unsigned byte format
|
|
||||||
glm::vec2 texture; // uv space
|
|
||||||
float padding[ 2 ]; // experimental, some gfx hardware allegedly works better with 32-bit aligned data blocks
|
|
||||||
};
|
|
||||||
/*
|
|
||||||
using sourcedistance_pair = std::pair<smoke_source *, float>;
|
|
||||||
using source_sequence = std::vector<sourcedistance_pair>;
|
|
||||||
*/
|
|
||||||
using particlevertex_sequence = std::vector<particle_vertex>;
|
|
||||||
// methods
|
|
||||||
// members
|
|
||||||
/*
|
|
||||||
source_sequence m_sources; // list of particle sources visible in current render pass, with their respective distances to the camera
|
|
||||||
*/
|
|
||||||
particlevertex_sequence m_particlevertices; // geometry data of visible particles, generated on the cpu end
|
|
||||||
GLuint m_buffer{ (GLuint)-1 }; // id of the buffer holding geometry data on the opengl end
|
|
||||||
std::size_t m_buffercapacity{ 0 }; // total capacity of the last established buffer
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// bare-bones render controller, in lack of anything better yet
|
|
||||||
class opengl_renderer : public gfx_renderer {
|
|
||||||
|
|
||||||
public:
|
|
||||||
// types
|
|
||||||
// constructors
|
|
||||||
opengl_renderer() = default;
|
|
||||||
// destructor
|
|
||||||
~opengl_renderer() { gluDeleteQuadric( m_quadric ); }
|
|
||||||
// methods
|
|
||||||
bool
|
|
||||||
Init( GLFWwindow *Window ) override;
|
|
||||||
// main draw call. returns false on error
|
|
||||||
bool
|
|
||||||
Render() override;
|
|
||||||
inline
|
|
||||||
float
|
|
||||||
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() 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 ) 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 ) override;
|
|
||||||
// adds supplied vertex data at the end of specified chunk
|
|
||||||
bool
|
|
||||||
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 override;
|
|
||||||
// material methods
|
|
||||||
material_handle
|
|
||||||
Fetch_Material( std::string const &Filename, bool const Loadnow = true ) override;
|
|
||||||
void
|
|
||||||
Bind_Material( material_handle const Material ) override;
|
|
||||||
opengl_material const &
|
|
||||||
Material( material_handle const Material ) const override;
|
|
||||||
// texture methods
|
|
||||||
texture_handle
|
|
||||||
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 override;
|
|
||||||
// utility methods
|
|
||||||
TSubModel const *
|
|
||||||
Pick_Control() const override { return m_pickcontrolitem; }
|
|
||||||
scene::basic_node const *
|
|
||||||
Pick_Node() const override { return m_picksceneryitem; }
|
|
||||||
glm::dvec3
|
|
||||||
Mouse_Position() const override { return m_worldmousecoordinates; }
|
|
||||||
// maintenance methods
|
|
||||||
void
|
|
||||||
Update( double const Deltatime ) override;
|
|
||||||
TSubModel *
|
|
||||||
Update_Pick_Control() override;
|
|
||||||
scene::basic_node *
|
|
||||||
Update_Pick_Node() override;
|
|
||||||
glm::dvec3
|
|
||||||
Update_Mouse_Position() override;
|
|
||||||
// debug methods
|
|
||||||
std::string const &
|
|
||||||
info_times() const override;
|
|
||||||
std::string const &
|
|
||||||
info_stats() const override;
|
|
||||||
|
|
||||||
// members
|
|
||||||
GLenum static const sunlight { GL_LIGHT0 };
|
|
||||||
std::size_t m_drawcount { 0 };
|
|
||||||
|
|
||||||
private:
|
|
||||||
// types
|
|
||||||
enum class rendermode {
|
|
||||||
none,
|
|
||||||
color,
|
|
||||||
shadows,
|
|
||||||
cabshadows,
|
|
||||||
reflections,
|
|
||||||
pickcontrols,
|
|
||||||
pickscenery
|
|
||||||
};
|
|
||||||
|
|
||||||
enum textureunit {
|
|
||||||
helper = 0,
|
|
||||||
shadows,
|
|
||||||
normals,
|
|
||||||
diffuse
|
|
||||||
};
|
|
||||||
|
|
||||||
struct debug_stats {
|
|
||||||
int dynamics { 0 };
|
|
||||||
int models { 0 };
|
|
||||||
int submodels { 0 };
|
|
||||||
int paths { 0 };
|
|
||||||
int traction { 0 };
|
|
||||||
int shapes { 0 };
|
|
||||||
int lines { 0 };
|
|
||||||
int drawcalls { 0 };
|
|
||||||
};
|
|
||||||
|
|
||||||
using section_sequence = std::vector<scene::basic_section *>;
|
|
||||||
using distancecell_pair = std::pair<double, scene::basic_cell *>;
|
|
||||||
using cell_sequence = std::vector<distancecell_pair>;
|
|
||||||
|
|
||||||
struct renderpass_config {
|
|
||||||
|
|
||||||
opengl_camera camera;
|
|
||||||
rendermode draw_mode { rendermode::none };
|
|
||||||
float draw_range { 0.0f };
|
|
||||||
};
|
|
||||||
|
|
||||||
struct units_state {
|
|
||||||
|
|
||||||
bool diffuse { false };
|
|
||||||
bool shadows { false };
|
|
||||||
bool reflections { false };
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::vector<opengl_light> opengllight_array;
|
|
||||||
|
|
||||||
// methods
|
|
||||||
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
|
|
||||||
setup_matrices();
|
|
||||||
void
|
|
||||||
setup_drawing( bool const Alpha = false );
|
|
||||||
void
|
|
||||||
setup_units( bool const Diffuse, bool const Shadows, bool const Reflections );
|
|
||||||
void
|
|
||||||
setup_shadow_map( GLuint const Texture, glm::mat4 const &Transformation );
|
|
||||||
void
|
|
||||||
setup_shadow_color( glm::vec4 const &Shadowcolor );
|
|
||||||
void
|
|
||||||
setup_environment_light( TEnvironmentType const Environment = e_flat );
|
|
||||||
void
|
|
||||||
switch_units( bool const Diffuse, bool const Shadows, bool const Reflections );
|
|
||||||
// helper, texture manager method; activates specified texture unit
|
|
||||||
void
|
|
||||||
select_unit( GLint const Textureunit );
|
|
||||||
// runs jobs needed to generate graphics for specified render pass
|
|
||||||
void
|
|
||||||
Render_pass( rendermode const Mode );
|
|
||||||
// creates dynamic environment cubemap
|
|
||||||
bool
|
|
||||||
Render_reflections();
|
|
||||||
bool
|
|
||||||
Render( world_environment *Environment );
|
|
||||||
void
|
|
||||||
Render( scene::basic_region *Region );
|
|
||||||
void
|
|
||||||
Render( section_sequence::iterator First, section_sequence::iterator Last );
|
|
||||||
void
|
|
||||||
Render( cell_sequence::iterator First, cell_sequence::iterator Last );
|
|
||||||
void
|
|
||||||
Render( scene::shape_node const &Shape, bool const Ignorerange );
|
|
||||||
void
|
|
||||||
Render( TAnimModel *Instance );
|
|
||||||
bool
|
|
||||||
Render( TDynamicObject *Dynamic );
|
|
||||||
bool
|
|
||||||
Render( TModel3d *Model, material_data const *Material, float const Squaredistance, Math3D::vector3 const &Position, glm::vec3 const &Angle );
|
|
||||||
bool
|
|
||||||
Render( TModel3d *Model, material_data const *Material, float const Squaredistance );
|
|
||||||
void
|
|
||||||
Render( TSubModel *Submodel );
|
|
||||||
void
|
|
||||||
Render( TTrack *Track );
|
|
||||||
void
|
|
||||||
Render( scene::basic_cell::path_sequence::const_iterator First, scene::basic_cell::path_sequence::const_iterator Last );
|
|
||||||
bool
|
|
||||||
Render_cab( TDynamicObject const *Dynamic, float const Lightlevel, bool const Alpha = false );
|
|
||||||
void
|
|
||||||
Render( TMemCell *Memcell );
|
|
||||||
void
|
|
||||||
Render_particles();
|
|
||||||
void
|
|
||||||
Render_precipitation();
|
|
||||||
void
|
|
||||||
Render_Alpha( scene::basic_region *Region );
|
|
||||||
void
|
|
||||||
Render_Alpha( cell_sequence::reverse_iterator First, cell_sequence::reverse_iterator Last );
|
|
||||||
void
|
|
||||||
Render_Alpha( TAnimModel *Instance );
|
|
||||||
void
|
|
||||||
Render_Alpha( TTraction *Traction );
|
|
||||||
void
|
|
||||||
Render_Alpha( scene::lines_node const &Lines );
|
|
||||||
bool
|
|
||||||
Render_Alpha( TDynamicObject *Dynamic );
|
|
||||||
bool
|
|
||||||
Render_Alpha( TModel3d *Model, material_data const *Material, float const Squaredistance, Math3D::vector3 const &Position, glm::vec3 const &Angle );
|
|
||||||
bool
|
|
||||||
Render_Alpha( TModel3d *Model, material_data const *Material, float const Squaredistance );
|
|
||||||
void
|
|
||||||
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
|
|
||||||
pick_index( glm::ivec3 const &Color );
|
|
||||||
|
|
||||||
// members
|
|
||||||
GLFWwindow *m_window { nullptr };
|
|
||||||
gfx::geometrybank_manager m_geometry;
|
|
||||||
material_manager m_materials;
|
|
||||||
texture_manager m_textures;
|
|
||||||
opengl_light m_sunlight;
|
|
||||||
opengllight_array m_lights;
|
|
||||||
/*
|
|
||||||
float m_sunandviewangle; // cached dot product of sunlight and camera vectors
|
|
||||||
*/
|
|
||||||
gfx::geometry_handle m_billboardgeometry { 0, 0 };
|
|
||||||
texture_handle m_glaretexture { -1 };
|
|
||||||
texture_handle m_suntexture { -1 };
|
|
||||||
texture_handle m_moontexture { -1 };
|
|
||||||
texture_handle m_reflectiontexture { -1 };
|
|
||||||
texture_handle m_smoketexture { -1 };
|
|
||||||
GLUquadricObj *m_quadric { nullptr }; // helper object for drawing debug mode scene elements
|
|
||||||
// TODO: refactor framebuffer stuff into an object
|
|
||||||
bool m_framebuffersupport { false };
|
|
||||||
#ifdef EU07_USE_PICKING_FRAMEBUFFER
|
|
||||||
GLuint m_pickframebuffer { 0 };
|
|
||||||
GLuint m_picktexture { 0 };
|
|
||||||
GLuint m_pickdepthbuffer { 0 };
|
|
||||||
#endif
|
|
||||||
// main shadowmap resources
|
|
||||||
int m_shadowbuffersize { 2048 };
|
|
||||||
GLuint m_shadowframebuffer { 0 };
|
|
||||||
GLuint m_shadowtexture { 0 };
|
|
||||||
#ifdef EU07_USE_DEBUG_SHADOWMAP
|
|
||||||
GLuint m_shadowdebugtexture{ 0 };
|
|
||||||
#endif
|
|
||||||
#ifdef EU07_USE_DEBUG_CABSHADOWMAP
|
|
||||||
GLuint m_cabshadowdebugtexture{ 0 };
|
|
||||||
#endif
|
|
||||||
glm::mat4 m_shadowtexturematrix; // conversion from camera-centric world space to light-centric clip space
|
|
||||||
// cab shadowmap resources
|
|
||||||
GLuint m_cabshadowframebuffer { 0 };
|
|
||||||
GLuint m_cabshadowtexture { 0 };
|
|
||||||
glm::mat4 m_cabshadowtexturematrix; // conversion from cab-centric world space to light-centric clip space
|
|
||||||
// environment map resources
|
|
||||||
GLuint m_environmentframebuffer { 0 };
|
|
||||||
GLuint m_environmentcubetexture { 0 };
|
|
||||||
GLuint m_environmentdepthbuffer { 0 };
|
|
||||||
bool m_environmentcubetexturesupport { false }; // indicates whether we can use the dynamic environment cube map
|
|
||||||
int m_environmentcubetextureface { 0 }; // helper, currently processed cube map face
|
|
||||||
int m_environmentupdatetime { 0 }; // time of the most recent environment map update
|
|
||||||
glm::dvec3 m_environmentupdatelocation; // coordinates of most recent environment map update
|
|
||||||
// particle visualization subsystem
|
|
||||||
opengl_particles m_particlerenderer;
|
|
||||||
|
|
||||||
int m_helpertextureunit { GL_TEXTURE0 };
|
|
||||||
int m_shadowtextureunit { GL_TEXTURE1 };
|
|
||||||
int m_normaltextureunit { GL_TEXTURE2 };
|
|
||||||
int m_diffusetextureunit{ GL_TEXTURE3 };
|
|
||||||
units_state m_unitstate;
|
|
||||||
|
|
||||||
unsigned int m_framestamp; // id of currently rendered gfx frame
|
|
||||||
float m_framerate;
|
|
||||||
double m_updateaccumulator { 0.0 };
|
|
||||||
// double m_pickupdateaccumulator { 0.0 };
|
|
||||||
std::string m_debugtimestext;
|
|
||||||
std::string m_pickdebuginfo;
|
|
||||||
debug_stats m_debugstats;
|
|
||||||
std::string m_debugstatstext;
|
|
||||||
|
|
||||||
glm::vec4 m_baseambient { 0.0f, 0.0f, 0.0f, 1.0f };
|
|
||||||
glm::vec4 m_shadowcolor { colors::shadow };
|
|
||||||
float m_fogrange { 2000.f };
|
|
||||||
// TEnvironmentType m_environment { e_flat };
|
|
||||||
float m_specularopaquescalefactor { 1.f };
|
|
||||||
float m_speculartranslucentscalefactor { 1.f };
|
|
||||||
bool m_renderspecular{ false }; // controls whether to include specular component in the calculations
|
|
||||||
|
|
||||||
renderpass_config m_renderpass; // parameters for current render pass
|
|
||||||
section_sequence m_sectionqueue; // list of sections in current render pass
|
|
||||||
cell_sequence m_cellqueue;
|
|
||||||
renderpass_config m_colorpass; // parametrs of most recent color pass
|
|
||||||
renderpass_config m_shadowpass; // parametrs of most recent shadowmap pass
|
|
||||||
renderpass_config m_cabshadowpass; // parameters of most recent cab shadowmap pass
|
|
||||||
std::vector<TSubModel *> m_pickcontrolsitems;
|
|
||||||
TSubModel *m_pickcontrolitem { nullptr };
|
|
||||||
std::vector<scene::basic_node *> m_picksceneryitems;
|
|
||||||
scene::basic_node *m_picksceneryitem { nullptr };
|
|
||||||
glm::vec3 m_worldmousecoordinates { 0.f };
|
|
||||||
#ifdef EU07_USE_DEBUG_CAMERA
|
|
||||||
renderpass_config m_worldcamera; // debug item
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
extern std::unique_ptr<gfx_renderer> GfxRenderer;
|
extern std::unique_ptr<gfx_renderer> GfxRenderer;
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
#include "simulation.h"
|
#include "simulation.h"
|
||||||
#include "simulationtime.h"
|
#include "simulationtime.h"
|
||||||
|
#include "simulationenvironment.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
#include "scenarioloaderuilayer.h"
|
#include "scenarioloaderuilayer.h"
|
||||||
|
|||||||
2
scene.h
2
scene.h
@@ -16,7 +16,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "openglgeometrybank.h"
|
#include "geometrybank.h"
|
||||||
#include "scenenode.h"
|
#include "scenenode.h"
|
||||||
#include "Track.h"
|
#include "Track.h"
|
||||||
#include "Traction.h"
|
#include "Traction.h"
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
#include "simulation.h"
|
#include "simulation.h"
|
||||||
|
#include "MemCell.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
#include "AnimModel.h"
|
#include "AnimModel.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
@@ -149,8 +150,8 @@ basic_editor::rotate( scene::basic_node *Node, glm::vec3 const &Angle, float con
|
|||||||
// rotate entire group
|
// rotate entire group
|
||||||
// TODO: contextual switch between group and item rotation
|
// TODO: contextual switch between group and item rotation
|
||||||
// TODO: translation of affected/relevant events
|
// TODO: translation of affected/relevant events
|
||||||
auto const rotationcenter { Node->location() };
|
auto const &rotationcenter { Node->location() };
|
||||||
auto &nodegroup { scene::Groups.group( Node->group() ).nodes };
|
auto const &nodegroup { scene::Groups.group( Node->group() ).nodes };
|
||||||
std::for_each(
|
std::for_each(
|
||||||
std::begin( nodegroup ), std::end( nodegroup ),
|
std::begin( nodegroup ), std::end( nodegroup ),
|
||||||
[&]( auto *node ) {
|
[&]( auto *node ) {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
|
|
||||||
#include "Model3d.h"
|
#include "Model3d.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
#include "parser.h"
|
||||||
#include "Logs.h"
|
#include "Logs.h"
|
||||||
#include "sn_utils.h"
|
#include "sn_utils.h"
|
||||||
|
|
||||||
|
|||||||
@@ -15,12 +15,15 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
#include "simulation.h"
|
#include "simulation.h"
|
||||||
#include "simulationtime.h"
|
#include "simulationtime.h"
|
||||||
|
#include "simulationenvironment.h"
|
||||||
#include "scenenodegroups.h"
|
#include "scenenodegroups.h"
|
||||||
#include "particles.h"
|
#include "particles.h"
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
#include "MemCell.h"
|
||||||
#include "Driver.h"
|
#include "Driver.h"
|
||||||
#include "DynObj.h"
|
#include "DynObj.h"
|
||||||
#include "AnimModel.h"
|
#include "AnimModel.h"
|
||||||
|
#include "lightarray.h"
|
||||||
#include "TractionPower.h"
|
#include "TractionPower.h"
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user