mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-21 17:09:19 +02:00
reformat: remove redundant qualifiers
This commit is contained in:
@@ -169,7 +169,7 @@ cFrustum::cube_inside( float const X, float const Y, float const Z, float const
|
||||
return true;
|
||||
}
|
||||
|
||||
void cFrustum::normalize_plane( cFrustum::side const Side ) {
|
||||
void cFrustum::normalize_plane( side const Side ) {
|
||||
|
||||
const float magnitude =
|
||||
std::sqrt(
|
||||
|
||||
@@ -79,7 +79,7 @@ private:
|
||||
|
||||
// methods:
|
||||
void
|
||||
normalize_plane( cFrustum::side const Side ); // normalizes a plane (A side) from the frustum
|
||||
normalize_plane( side const Side ); // normalizes a plane (A side) from the frustum
|
||||
|
||||
// members:
|
||||
float m_frustum[6][4]; // holds the A B C and D values (normal & distance) for each side of the frustum.
|
||||
|
||||
@@ -251,14 +251,14 @@ void calculate_indices( index_array &Indices, vertex_array &Vertices, userdata_a
|
||||
// generic geometry bank class, allows storage, update and drawing of geometry chunks
|
||||
|
||||
// creates a new geometry chunk of specified type from supplied data. returns: handle to the chunk or NULL
|
||||
gfx::geometry_handle
|
||||
geometry_bank::create( gfx::vertex_array &Vertices, userdata_array &Userdata, unsigned int const Type ) {
|
||||
geometry_handle
|
||||
geometry_bank::create( vertex_array &Vertices, userdata_array &Userdata, unsigned int const Type ) {
|
||||
|
||||
if(Vertices.empty()) { return { 0, 0 }; }
|
||||
|
||||
m_chunks.emplace_back( Vertices, Userdata, Type );
|
||||
// NOTE: handle is effectively (index into chunk array + 1) this leaves value of 0 to serve as error/empty handle indication
|
||||
const gfx::geometry_handle chunkhandle { 0, static_cast<std::uint32_t>(m_chunks.size()) };
|
||||
const geometry_handle chunkhandle { 0, static_cast<std::uint32_t>(m_chunks.size()) };
|
||||
// template method implementation
|
||||
create_( chunkhandle );
|
||||
// all done
|
||||
@@ -266,14 +266,14 @@ geometry_bank::create( gfx::vertex_array &Vertices, userdata_array &Userdata, un
|
||||
}
|
||||
|
||||
// creates a new indexed geometry chunk of specified type from supplied data. returns: handle to the chunk or NULL
|
||||
gfx::geometry_handle
|
||||
geometry_bank::create( gfx::index_array &Indices, gfx::vertex_array &Vertices, userdata_array &Userdata, unsigned int const Type ) {
|
||||
geometry_handle
|
||||
geometry_bank::create( index_array &Indices, vertex_array &Vertices, userdata_array &Userdata, unsigned int const Type ) {
|
||||
|
||||
if(Vertices.empty()) { return { 0, 0 }; }
|
||||
|
||||
m_chunks.emplace_back( Indices, Vertices, Userdata, Type );
|
||||
// NOTE: handle is effectively (index into chunk array + 1) this leaves value of 0 to serve as error/empty handle indication
|
||||
const gfx::geometry_handle chunkhandle { 0, static_cast<std::uint32_t>(m_chunks.size()) };
|
||||
const geometry_handle chunkhandle { 0, static_cast<std::uint32_t>(m_chunks.size()) };
|
||||
// template method implementation
|
||||
create_( chunkhandle );
|
||||
// all done
|
||||
@@ -282,11 +282,11 @@ geometry_bank::create( gfx::index_array &Indices, gfx::vertex_array &Vertices, u
|
||||
|
||||
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
|
||||
bool
|
||||
geometry_bank::replace( gfx::vertex_array &Vertices, userdata_array &Userdata, gfx::geometry_handle const &Geometry, std::size_t const Offset ) {
|
||||
geometry_bank::replace( vertex_array &Vertices, userdata_array &Userdata, 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 );
|
||||
auto &chunk = geometry_bank::chunk( Geometry );
|
||||
|
||||
if( ( Offset == 0 )
|
||||
&& ( Vertices.size() == chunk.vertices.size() ) ) {
|
||||
@@ -298,8 +298,8 @@ geometry_bank::replace( gfx::vertex_array &Vertices, userdata_array &Userdata, g
|
||||
// ...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.userdata.resize( Offset + Userdata.size(), gfx::vertex_userdata() );
|
||||
chunk.vertices.resize( Offset + Vertices.size(), basic_vertex() );
|
||||
chunk.userdata.resize( Offset + Userdata.size(), vertex_userdata() );
|
||||
chunk.vertices.insert( std::end( chunk.vertices ), std::begin( Vertices ), std::end( Vertices ) );
|
||||
chunk.userdata.insert( std::end( chunk.userdata ), std::begin( Userdata ), std::end( Userdata ) );
|
||||
}
|
||||
@@ -311,23 +311,23 @@ geometry_bank::replace( gfx::vertex_array &Vertices, userdata_array &Userdata, g
|
||||
|
||||
// adds supplied vertex data at the end of specified chunk
|
||||
bool
|
||||
geometry_bank::append( gfx::vertex_array &Vertices, userdata_array &Userdata, gfx::geometry_handle const &Geometry ) {
|
||||
geometry_bank::append( vertex_array &Vertices, userdata_array &Userdata, geometry_handle const &Geometry ) {
|
||||
|
||||
if( ( Geometry.chunk == 0 ) || ( Geometry.chunk > m_chunks.size() ) ) { return false; }
|
||||
|
||||
return replace( Vertices, Userdata, Geometry, gfx::geometry_bank::chunk( Geometry ).vertices.size() );
|
||||
return replace( Vertices, Userdata, Geometry, chunk( Geometry ).vertices.size() );
|
||||
}
|
||||
|
||||
// draws geometry stored in specified chunk
|
||||
std::size_t
|
||||
geometry_bank::draw( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) {
|
||||
geometry_bank::draw( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams ) {
|
||||
// template method implementation
|
||||
return draw_( Geometry, Units, Streams );
|
||||
}
|
||||
|
||||
// draws geometry stored in specified chunk InstanceCount times via instanced draw call
|
||||
std::size_t
|
||||
geometry_bank::draw_instanced( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, std::size_t const InstanceCount, unsigned int const Streams ) {
|
||||
geometry_bank::draw_instanced( geometry_handle const &Geometry, stream_units const &Units, std::size_t const InstanceCount, unsigned int const Streams ) {
|
||||
if( InstanceCount == 0 ) { return 0; }
|
||||
return draw_instanced_( Geometry, Units, InstanceCount, Streams );
|
||||
}
|
||||
@@ -341,23 +341,23 @@ geometry_bank::release() {
|
||||
|
||||
// provides direct access to indexdata of specfied chunk
|
||||
index_array const &
|
||||
geometry_bank::indices( gfx::geometry_handle const &Geometry ) const {
|
||||
geometry_bank::indices( geometry_handle const &Geometry ) const {
|
||||
|
||||
return geometry_bank::chunk( Geometry ).indices;
|
||||
return chunk( Geometry ).indices;
|
||||
}
|
||||
|
||||
// provides direct access to vertex data of specfied chunk
|
||||
vertex_array const &
|
||||
geometry_bank::vertices( gfx::geometry_handle const &Geometry ) const {
|
||||
geometry_bank::vertices( geometry_handle const &Geometry ) const {
|
||||
|
||||
return geometry_bank::chunk( Geometry ).vertices;
|
||||
return chunk( Geometry ).vertices;
|
||||
}
|
||||
|
||||
// provides direct access to vertex user data of specfied chunk
|
||||
userdata_array const &
|
||||
geometry_bank::userdata( gfx::geometry_handle const &Geometry ) const {
|
||||
geometry_bank::userdata( geometry_handle const &Geometry ) const {
|
||||
|
||||
return geometry_bank::chunk( Geometry ).userdata;
|
||||
return chunk( Geometry ).userdata;
|
||||
}
|
||||
|
||||
// geometry bank manager, holds collection of geometry banks
|
||||
@@ -370,7 +370,7 @@ geometrybank_manager::update() {
|
||||
}
|
||||
|
||||
// creates a new geometry bank. returns: handle to the bank or NULL
|
||||
gfx::geometrybank_handle
|
||||
geometrybank_handle
|
||||
geometrybank_manager::register_bank(std::unique_ptr<geometry_bank> bank) {
|
||||
m_geometrybanks.emplace_back(std::move(bank), std::chrono::steady_clock::time_point() );
|
||||
|
||||
@@ -379,8 +379,8 @@ geometrybank_manager::register_bank(std::unique_ptr<geometry_bank> bank) {
|
||||
}
|
||||
|
||||
// creates a new geometry chunk of specified type from supplied data, in specified bank. returns: handle to the chunk or NULL
|
||||
gfx::geometry_handle
|
||||
geometrybank_manager::create_chunk(vertex_array &Vertices, userdata_array &Userdata, gfx::geometrybank_handle const &Geometry, int const Type ) {
|
||||
geometry_handle
|
||||
geometrybank_manager::create_chunk(vertex_array &Vertices, userdata_array &Userdata, geometrybank_handle const &Geometry, int const Type ) {
|
||||
|
||||
auto const newchunkhandle = bank( Geometry ).first->create( Vertices, Userdata, Type );
|
||||
|
||||
@@ -389,8 +389,8 @@ geometrybank_manager::create_chunk(vertex_array &Vertices, userdata_array &Userd
|
||||
}
|
||||
|
||||
// creates a new indexed geometry chunk of specified type from supplied data, in specified bank. returns: handle to the chunk or NULL
|
||||
gfx::geometry_handle
|
||||
geometrybank_manager::create_chunk( gfx::index_array &Indices, gfx::vertex_array &Vertices, userdata_array &Userdata, gfx::geometrybank_handle const &Geometry, unsigned int const Type ) {
|
||||
geometry_handle
|
||||
geometrybank_manager::create_chunk( index_array &Indices, vertex_array &Vertices, userdata_array &Userdata, geometrybank_handle const &Geometry, unsigned int const Type ) {
|
||||
|
||||
auto const newchunkhandle = bank( Geometry ).first->create( Indices, Vertices, Userdata, Type );
|
||||
|
||||
@@ -400,20 +400,20 @@ geometrybank_manager::create_chunk( gfx::index_array &Indices, gfx::vertex_array
|
||||
|
||||
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
|
||||
bool
|
||||
geometrybank_manager::replace( gfx::vertex_array &Vertices, userdata_array &Userdata, gfx::geometry_handle const &Geometry, std::size_t const Offset ) {
|
||||
geometrybank_manager::replace( vertex_array &Vertices, userdata_array &Userdata, geometry_handle const &Geometry, std::size_t const Offset ) {
|
||||
|
||||
return bank( Geometry ).first->replace( Vertices, Userdata, Geometry, Offset );
|
||||
}
|
||||
|
||||
// adds supplied vertex data at the end of specified chunk
|
||||
bool
|
||||
geometrybank_manager::append( gfx::vertex_array &Vertices, userdata_array &Userdata, gfx::geometry_handle const &Geometry ) {
|
||||
geometrybank_manager::append( vertex_array &Vertices, userdata_array &Userdata, geometry_handle const &Geometry ) {
|
||||
|
||||
return bank( Geometry ).first->append( Vertices, Userdata, Geometry );
|
||||
}
|
||||
// draws geometry stored in specified chunk
|
||||
void
|
||||
geometrybank_manager::draw( gfx::geometry_handle const &Geometry, unsigned int const Streams ) {
|
||||
geometrybank_manager::draw( geometry_handle const &Geometry, unsigned int const Streams ) {
|
||||
|
||||
if( Geometry == null_handle ) { return; }
|
||||
|
||||
@@ -425,7 +425,7 @@ geometrybank_manager::draw( gfx::geometry_handle const &Geometry, unsigned int c
|
||||
|
||||
// draws geometry stored in specified chunk InstanceCount times via instanced draw call
|
||||
void
|
||||
geometrybank_manager::draw_instanced( gfx::geometry_handle const &Geometry, std::size_t const InstanceCount, unsigned int const Streams ) {
|
||||
geometrybank_manager::draw_instanced( geometry_handle const &Geometry, std::size_t const InstanceCount, unsigned int const Streams ) {
|
||||
|
||||
if( Geometry == null_handle ) { return; }
|
||||
if( InstanceCount == 0 ) { return; }
|
||||
@@ -437,22 +437,22 @@ geometrybank_manager::draw_instanced( gfx::geometry_handle const &Geometry, std:
|
||||
}
|
||||
|
||||
// provides direct access to index data of specfied chunk
|
||||
gfx::index_array const &
|
||||
geometrybank_manager::indices( gfx::geometry_handle const &Geometry ) const {
|
||||
index_array const &
|
||||
geometrybank_manager::indices( geometry_handle const &Geometry ) const {
|
||||
|
||||
return bank( Geometry ).first->indices( Geometry );
|
||||
}
|
||||
|
||||
// provides direct access to vertex data of specfied chunk
|
||||
gfx::vertex_array const &
|
||||
geometrybank_manager::vertices( gfx::geometry_handle const &Geometry ) const {
|
||||
vertex_array const &
|
||||
geometrybank_manager::vertices( geometry_handle const &Geometry ) const {
|
||||
|
||||
return bank( Geometry ).first->vertices( Geometry );
|
||||
}
|
||||
|
||||
// provides direct access to vertex user data of specfied chunk
|
||||
gfx::userdata_array const &
|
||||
geometrybank_manager::userdata( gfx::geometry_handle const &Geometry ) const {
|
||||
userdata_array const &
|
||||
geometrybank_manager::userdata( geometry_handle const &Geometry ) const {
|
||||
|
||||
return bank( Geometry ).first->userdata( Geometry );
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ enum stream {
|
||||
texture = 0x8
|
||||
};
|
||||
|
||||
unsigned int const basic_streams { stream::position | stream::normal | stream::texture };
|
||||
unsigned int const color_streams { stream::position | stream::color | stream::texture };
|
||||
unsigned int const basic_streams { position | normal | texture };
|
||||
unsigned int const color_streams { position | color | texture };
|
||||
|
||||
struct stream_units {
|
||||
|
||||
@@ -110,20 +110,20 @@ public:
|
||||
|
||||
// methods:
|
||||
// creates a new geometry chunk of specified type from supplied data. returns: handle to the chunk or NULL
|
||||
auto create( gfx::vertex_array &Vertices, gfx::userdata_array& Userdata, unsigned int const Type ) -> gfx::geometry_handle;
|
||||
auto create( vertex_array &Vertices, userdata_array& Userdata, unsigned int const Type ) -> geometry_handle;
|
||||
// creates a new indexed geometry chunk of specified type from supplied data. returns: handle to the chunk or NULL
|
||||
auto create( gfx::index_array &Indices, gfx::vertex_array &Vertices, gfx::userdata_array& Userdata, unsigned int const Type ) -> gfx::geometry_handle;
|
||||
auto create( index_array &Indices, vertex_array &Vertices, userdata_array& Userdata, unsigned int const Type ) -> geometry_handle;
|
||||
// replaces vertex data of specified chunk with the supplied data, starting from specified offset
|
||||
auto replace( gfx::vertex_array &Vertices, gfx::userdata_array& Userdata, gfx::geometry_handle const &Geometry, std::size_t const Offset = 0 ) -> bool;
|
||||
auto replace( vertex_array &Vertices, userdata_array& Userdata, 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::userdata_array& Userdata, gfx::geometry_handle const &Geometry ) -> bool;
|
||||
auto append( vertex_array &Vertices, userdata_array& Userdata, geometry_handle const &Geometry ) -> bool;
|
||||
// draws geometry stored in specified chunk
|
||||
auto draw( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams = basic_streams ) -> std::size_t;
|
||||
auto draw( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams = basic_streams ) -> std::size_t;
|
||||
// draws geometry stored in specified chunk N times via glDrawElementsInstanced*
|
||||
auto draw_instanced( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, std::size_t const InstanceCount, unsigned int const Streams = basic_streams ) -> std::size_t;
|
||||
auto draw_instanced( geometry_handle const &Geometry, stream_units const &Units, std::size_t const InstanceCount, unsigned int const Streams = basic_streams ) -> std::size_t;
|
||||
// draws geometry stored in supplied list of chunks
|
||||
template <typename Iterator_>
|
||||
auto draw( Iterator_ First, Iterator_ Last, gfx::stream_units const &Units, unsigned int const Streams = basic_streams ) ->std::size_t {
|
||||
auto draw( Iterator_ First, Iterator_ Last, stream_units const &Units, unsigned int const Streams = basic_streams ) ->std::size_t {
|
||||
std::size_t count { 0 };
|
||||
while( First != Last ) {
|
||||
count += draw( *First, Units, Streams ); ++First; }
|
||||
@@ -131,28 +131,28 @@ public:
|
||||
// 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 index data of specfied chunk
|
||||
auto indices( gfx::geometry_handle const &Geometry ) const -> gfx::index_array const &;
|
||||
auto indices( geometry_handle const &Geometry ) const -> index_array const &;
|
||||
// provides direct access to vertex data of specfied chunk
|
||||
auto vertices( gfx::geometry_handle const &Geometry ) const -> gfx::vertex_array const &;
|
||||
auto vertices( geometry_handle const &Geometry ) const -> vertex_array const &;
|
||||
// provides direct access to vertex user data of specfied chunk
|
||||
auto userdata( gfx::geometry_handle const &Geometry ) const -> gfx::userdata_array const &;
|
||||
auto userdata( geometry_handle const &Geometry ) const -> userdata_array const &;
|
||||
|
||||
protected:
|
||||
// types:
|
||||
struct geometry_chunk {
|
||||
unsigned int type; // kind of geometry used by the chunk
|
||||
gfx::vertex_array vertices; // geometry data
|
||||
gfx::index_array indices; // index data
|
||||
gfx::userdata_array userdata;
|
||||
vertex_array vertices; // geometry data
|
||||
index_array indices; // index data
|
||||
userdata_array userdata;
|
||||
// NOTE: constructor doesn't copy provided geometry data, but moves it
|
||||
geometry_chunk( gfx::vertex_array &Vertices, gfx::userdata_array& Userdata, unsigned int Type ) :
|
||||
geometry_chunk( vertex_array &Vertices, userdata_array& Userdata, unsigned int Type ) :
|
||||
type( Type )
|
||||
{
|
||||
vertices.swap( Vertices );
|
||||
userdata.swap( Userdata );
|
||||
}
|
||||
// NOTE: constructor doesn't copy provided geometry data, but moves it
|
||||
geometry_chunk( gfx::index_array &Indices, gfx::vertex_array &Vertices, gfx::userdata_array& Userdata, unsigned int Type ) :
|
||||
geometry_chunk( index_array &Indices, vertex_array &Vertices, userdata_array& Userdata, unsigned int Type ) :
|
||||
type( Type )
|
||||
{
|
||||
vertices.swap( Vertices );
|
||||
@@ -165,10 +165,10 @@ protected:
|
||||
|
||||
// methods
|
||||
inline
|
||||
auto chunk( gfx::geometry_handle const Geometry ) -> geometry_chunk & {
|
||||
auto chunk( geometry_handle const Geometry ) -> geometry_chunk & {
|
||||
return m_chunks[ Geometry.chunk - 1 ]; }
|
||||
inline
|
||||
auto chunk( gfx::geometry_handle const Geometry ) const -> geometry_chunk const & {
|
||||
auto chunk( geometry_handle const Geometry ) const -> geometry_chunk const & {
|
||||
return m_chunks[ Geometry.chunk - 1 ]; }
|
||||
|
||||
// members:
|
||||
@@ -177,13 +177,13 @@ protected:
|
||||
private:
|
||||
// methods:
|
||||
// create() subclass details
|
||||
virtual void create_( gfx::geometry_handle const &Geometry ) = 0;
|
||||
virtual void create_( geometry_handle const &Geometry ) = 0;
|
||||
// replace() subclass details
|
||||
virtual void replace_( gfx::geometry_handle const &Geometry ) = 0;
|
||||
virtual void replace_( geometry_handle const &Geometry ) = 0;
|
||||
// draw() subclass details
|
||||
virtual auto draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) -> std::size_t = 0;
|
||||
virtual auto draw_( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams ) -> std::size_t = 0;
|
||||
// draw_instanced() subclass details. Default implementation falls back to N regular draws.
|
||||
virtual auto draw_instanced_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, std::size_t const InstanceCount, unsigned int const Streams ) -> std::size_t {
|
||||
virtual auto draw_instanced_( geometry_handle const &Geometry, stream_units const &Units, std::size_t const InstanceCount, unsigned int const Streams ) -> std::size_t {
|
||||
std::size_t count { 0 };
|
||||
for( std::size_t i = 0; i < InstanceCount; ++i ) { count += draw_( Geometry, Units, Streams ); }
|
||||
return count; }
|
||||
@@ -204,33 +204,33 @@ public:
|
||||
// performs a resource sweep
|
||||
void update();
|
||||
// registers a new geometry bank. returns: handle to the bank
|
||||
auto register_bank(std::unique_ptr<geometry_bank> bank) -> gfx::geometrybank_handle;
|
||||
auto register_bank(std::unique_ptr<geometry_bank> bank) -> geometrybank_handle;
|
||||
// creates a new geometry chunk of specified type from supplied data, in specified bank. returns: handle to the chunk or NULL
|
||||
auto create_chunk( gfx::vertex_array &Vertices, gfx::userdata_array &Userdata, gfx::geometrybank_handle const &Geometry, int const Type ) -> gfx::geometry_handle;
|
||||
auto create_chunk( vertex_array &Vertices, userdata_array &Userdata, geometrybank_handle const &Geometry, int const Type ) -> geometry_handle;
|
||||
// creates a new indexed geometry chunk of specified type from supplied data, in specified bank. returns: handle to the chunk or NULL
|
||||
auto create_chunk( gfx::index_array &Indices, gfx::vertex_array &Vertices, gfx::userdata_array &Userdata, gfx::geometrybank_handle const &Geometry, unsigned int const Type ) -> gfx::geometry_handle;
|
||||
auto create_chunk( index_array &Indices, vertex_array &Vertices, userdata_array &Userdata, geometrybank_handle const &Geometry, unsigned int const Type ) -> geometry_handle;
|
||||
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
|
||||
auto replace( gfx::vertex_array &Vertices, gfx::userdata_array &Userdata, gfx::geometry_handle const &Geometry, std::size_t const Offset = 0 ) -> bool;
|
||||
auto replace( vertex_array &Vertices, userdata_array &Userdata, 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::userdata_array &Userdata, gfx::geometry_handle const &Geometry ) -> bool;
|
||||
auto append( vertex_array &Vertices, userdata_array &Userdata, geometry_handle const &Geometry ) -> bool;
|
||||
// draws geometry stored in specified chunk
|
||||
void draw( gfx::geometry_handle const &Geometry, unsigned int const Streams = basic_streams );
|
||||
void draw( geometry_handle const &Geometry, unsigned int const Streams = basic_streams );
|
||||
// draws geometry stored in specified chunk InstanceCount times via GPU instancing.
|
||||
// The shader reads per-instance modelview matrices from instance_ubo[gl_InstanceID].
|
||||
void draw_instanced( gfx::geometry_handle const &Geometry, std::size_t const InstanceCount, unsigned int const Streams = basic_streams );
|
||||
void draw_instanced( geometry_handle const &Geometry, std::size_t const InstanceCount, 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 index data of specfied chunk
|
||||
auto indices( gfx::geometry_handle const &Geometry ) const -> gfx::index_array const &;
|
||||
auto indices( geometry_handle const &Geometry ) const -> index_array const &;
|
||||
// provides direct access to vertex data of specfied chunk
|
||||
auto vertices( gfx::geometry_handle const &Geometry ) const -> gfx::vertex_array const &;
|
||||
auto vertices( geometry_handle const &Geometry ) const -> vertex_array const &;
|
||||
// provides direct access to vertex data of specfied chunk
|
||||
auto userdata( gfx::geometry_handle const &Geometry ) const -> gfx::userdata_array const &;
|
||||
auto userdata( geometry_handle const &Geometry ) const -> userdata_array const &;
|
||||
// sets target texture unit for the texture data stream
|
||||
auto units() -> gfx::stream_units & { return m_units; }
|
||||
auto units() -> stream_units & { return m_units; }
|
||||
// provides access to primitives count
|
||||
auto primitives_count() const -> std::size_t const & { return m_primitivecount; }
|
||||
auto primitives_count() -> std::size_t & { return m_primitivecount; }
|
||||
@@ -243,18 +243,18 @@ private:
|
||||
// members:
|
||||
geometrybanktimepointpair_sequence m_geometrybanks;
|
||||
garbage_collector<geometrybanktimepointpair_sequence> m_garbagecollector { m_geometrybanks, 60, 120, "geometry buffer" };
|
||||
gfx::stream_units m_units;
|
||||
stream_units m_units;
|
||||
|
||||
// methods
|
||||
inline
|
||||
auto valid( gfx::geometry_handle const &Geometry ) const -> bool {
|
||||
auto valid( 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 & {
|
||||
auto bank( 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 & {
|
||||
auto bank( geometry_handle const Geometry ) const -> geometrybanktimepointpair_sequence::value_type const & {
|
||||
return m_geometrybanks[ Geometry.bank - 1 ]; }
|
||||
|
||||
// members:
|
||||
|
||||
@@ -22,8 +22,8 @@ light_array::insert( TDynamicObject const *Owner ) {
|
||||
|
||||
// we're only storing lights for locos, which have two sets of lights, front and rear
|
||||
// for a more generic role this function would have to be tweaked to add vehicle type-specific light combinations
|
||||
data.emplace_back( Owner, end::front );
|
||||
data.emplace_back( Owner, end::rear );
|
||||
data.emplace_back( Owner, front );
|
||||
data.emplace_back( Owner, rear );
|
||||
}
|
||||
|
||||
void
|
||||
@@ -43,7 +43,7 @@ light_array::update() {
|
||||
|
||||
for( auto &light : data ) {
|
||||
// update light parameters to match current data of the owner
|
||||
if( light.index == end::front ) {
|
||||
if( light.index == front ) {
|
||||
// front light set
|
||||
light.position = light.owner->GetPosition() + ( light.owner->VectorFront() * ( std::max( 0.0, light.owner->GetLength() * 0.5 - 2.0 ) ) );// +( light.owner->VectorUp() * 0.25 );
|
||||
light.direction = glm::make_vec3( glm::value_ptr(light.owner->VectorFront()) ); // TODO: It is needed to get value_ptr and then make_vec3?
|
||||
@@ -63,15 +63,15 @@ light_array::update() {
|
||||
auto const lights { light.owner->MoverParameters->iLights[ light.index ] & light.owner->LightList( static_cast<end>( light.index ) ) };
|
||||
// ...then check their individual state
|
||||
light.count = 0
|
||||
+ ( ( lights & light::headlight_left ) ? 1 : 0 )
|
||||
+ ( ( lights & light::headlight_right ) ? 1 : 0 )
|
||||
+ ( ( lights & light::headlight_upper ) ? 1 : 0 )
|
||||
+ ( ( lights & light::highbeamlight_left ) ? 1: 0)
|
||||
+ ( ( lights & light::highbeamlight_right ) ? 1 : 0);
|
||||
+ ( ( lights & headlight_left ) ? 1 : 0 )
|
||||
+ ( ( lights & headlight_right ) ? 1 : 0 )
|
||||
+ ( ( lights & headlight_upper ) ? 1 : 0 )
|
||||
+ ( ( lights & highbeamlight_left ) ? 1: 0)
|
||||
+ ( ( lights & highbeamlight_right ) ? 1 : 0);
|
||||
|
||||
// set intensity
|
||||
if( light.count > 0 ) {
|
||||
const bool isEnabled = light.index == end::front ? !light.owner->HeadlightsAoff : !light.owner->HeadlightsBoff;
|
||||
const bool isEnabled = light.index == front ? !light.owner->HeadlightsAoff : !light.owner->HeadlightsBoff;
|
||||
|
||||
light.intensity = std::max(0.0f, std::log((float)light.count + 1.0f));
|
||||
if (light.owner->DimHeadlights && !light.owner->HighBeamLights && isEnabled) // tylko przyciemnione
|
||||
@@ -89,9 +89,9 @@ light_array::update() {
|
||||
|
||||
// TBD, TODO: intensity can be affected further by other factors
|
||||
light.state = {
|
||||
( ( lights & light::headlight_left | light::highbeamlight_left ) ? 1.f : 0.f ),
|
||||
( ( lights & light::headlight_upper ) ? 1.f : 0.f ),
|
||||
( ( lights & light::headlight_right | light::highbeamlight_right) ? 1.f : 0.f ) };
|
||||
( ( lights & headlight_left | highbeamlight_left ) ? 1.f : 0.f ),
|
||||
( ( lights & headlight_upper ) ? 1.f : 0.f ),
|
||||
( ( lights & headlight_right | highbeamlight_right) ? 1.f : 0.f ) };
|
||||
|
||||
light.color = {
|
||||
static_cast<float>(light.owner->MoverParameters->refR) / 255.0f,
|
||||
|
||||
@@ -6,4 +6,4 @@ std::unique_ptr<gfx_renderer> null_renderer::create_func()
|
||||
return std::unique_ptr<null_renderer>(new null_renderer());
|
||||
}
|
||||
|
||||
bool null_renderer::renderer_register = gfx_renderer_factory::get_instance()->register_backend("null", null_renderer::create_func);
|
||||
bool null_renderer::renderer_register = gfx_renderer_factory::get_instance()->register_backend("null", create_func);
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace gfx {
|
||||
|
||||
// create() subclass details
|
||||
void
|
||||
opengl33_vaogeometrybank::create_( gfx::geometry_handle const &Geometry ) {
|
||||
opengl33_vaogeometrybank::create_( geometry_handle const &Geometry ) {
|
||||
// adding a chunk means we'll be (re)building the buffer, which will fill the chunk records, amongst other things.
|
||||
// thus we don't need to initialize the values here
|
||||
m_chunkrecords.emplace_back( chunk_record() );
|
||||
@@ -28,12 +28,12 @@ opengl33_vaogeometrybank::create_( gfx::geometry_handle const &Geometry ) {
|
||||
|
||||
// replace() subclass details
|
||||
void
|
||||
opengl33_vaogeometrybank::replace_( gfx::geometry_handle const &Geometry ) {
|
||||
opengl33_vaogeometrybank::replace_( geometry_handle const &Geometry ) {
|
||||
|
||||
auto &chunkrecord = m_chunkrecords[ Geometry.chunk - 1 ];
|
||||
chunkrecord.is_good = false;
|
||||
// if the overall length of the chunk didn't change we can get away with reusing the old buffer...
|
||||
if( geometry_bank::chunk( Geometry ).vertices.size() != chunkrecord.vertex_count ) {
|
||||
if( chunk( Geometry ).vertices.size() != chunkrecord.vertex_count ) {
|
||||
// ...but otherwise we'll need to allocate a new one
|
||||
// TBD: we could keep and reuse the old buffer also if the new chunk is smaller than the old one,
|
||||
// but it'd require some extra tracking and work to keep all chunks up to date; also wasting vram; may be not worth it?
|
||||
@@ -78,7 +78,7 @@ void opengl33_vaogeometrybank::setup_buffer()
|
||||
// optional index buffer...
|
||||
if( indexcount > 0 ) {
|
||||
m_indexbuffer.emplace();
|
||||
m_indexbuffer->allocate( gl::buffer::ELEMENT_ARRAY_BUFFER, indexcount * sizeof( gfx::basic_index ), GL_STATIC_DRAW );
|
||||
m_indexbuffer->allocate( gl::buffer::ELEMENT_ARRAY_BUFFER, indexcount * sizeof( basic_index ), GL_STATIC_DRAW );
|
||||
if( ::glGetError() == GL_OUT_OF_MEMORY ) {
|
||||
ErrorLog( "openGL error: out of memory; failed to create a geometry index buffer" );
|
||||
throw std::bad_alloc();
|
||||
@@ -92,7 +92,7 @@ void opengl33_vaogeometrybank::setup_buffer()
|
||||
m_vertexbuffer.emplace();
|
||||
// NOTE: we're using static_draw since it's generally true for all we have implemented at the moment
|
||||
// TODO: allow to specify usage hint at the object creation, and pass it here
|
||||
const int vertex_size = has_userdata ? sizeof( gfx::basic_vertex ) + sizeof(gfx::vertex_userdata) : sizeof(gfx::basic_vertex);
|
||||
const int vertex_size = has_userdata ? sizeof( basic_vertex ) + sizeof(vertex_userdata) : sizeof(basic_vertex);
|
||||
m_vertexbuffer->allocate( gl::buffer::ARRAY_BUFFER, static_cast<int>(vertexcount * vertex_size), GL_STATIC_DRAW );
|
||||
if( ::glGetError() == GL_OUT_OF_MEMORY ) {
|
||||
ErrorLog( "openGL error: out of memory; failed to create a geometry buffer" );
|
||||
@@ -123,7 +123,7 @@ void opengl33_vaogeometrybank::setup_userdata(size_t offset) {
|
||||
// NOTE: units and stream parameters are unused, but they're part of (legacy) interface
|
||||
// TBD: specialized bank/manager pair without the cruft?
|
||||
std::size_t
|
||||
opengl33_vaogeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams )
|
||||
opengl33_vaogeometrybank::draw_( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams )
|
||||
{
|
||||
setup_buffer();
|
||||
|
||||
@@ -132,18 +132,18 @@ opengl33_vaogeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stre
|
||||
if( chunkrecord.vertex_count == 0 )
|
||||
return 0;
|
||||
|
||||
auto const &chunk = gfx::geometry_bank::chunk( Geometry );
|
||||
auto const &chunk = geometry_bank::chunk( Geometry );
|
||||
if( !chunkrecord.is_good ) {
|
||||
m_vao->bind();
|
||||
// we may potentially need to upload new buffer data before we can draw it
|
||||
if( chunkrecord.index_count > 0 ) {
|
||||
m_indexbuffer->upload( gl::buffer::ELEMENT_ARRAY_BUFFER, chunk.indices.data(), chunkrecord.index_offset * sizeof( gfx::basic_index ), chunkrecord.index_count * sizeof( gfx::basic_index ) );
|
||||
m_indexbuffer->upload( gl::buffer::ELEMENT_ARRAY_BUFFER, chunk.indices.data(), chunkrecord.index_offset * sizeof( basic_index ), chunkrecord.index_count * sizeof( basic_index ) );
|
||||
}
|
||||
m_vertexbuffer->upload( gl::buffer::ARRAY_BUFFER, chunk.vertices.data(), chunkrecord.vertex_offset * sizeof( gfx::basic_vertex ), chunkrecord.vertex_count * sizeof( gfx::basic_vertex ) );
|
||||
m_vertexbuffer->upload( gl::buffer::ARRAY_BUFFER, chunk.vertices.data(), chunkrecord.vertex_offset * sizeof( basic_vertex ), chunkrecord.vertex_count * sizeof( basic_vertex ) );
|
||||
if(chunkrecord.has_userdata)
|
||||
m_vertexbuffer->upload(gl::buffer::ARRAY_BUFFER, chunk.userdata.data(),
|
||||
static_cast<int>(m_vertex_count * sizeof(gfx::basic_vertex) + chunkrecord.vertex_offset * sizeof(gfx::vertex_userdata)),
|
||||
static_cast<int>(chunkrecord.vertex_count * sizeof(gfx::vertex_userdata)));
|
||||
static_cast<int>(m_vertex_count * sizeof(basic_vertex) + chunkrecord.vertex_offset * sizeof(vertex_userdata)),
|
||||
static_cast<int>(chunkrecord.vertex_count * sizeof(vertex_userdata)));
|
||||
chunkrecord.is_good = true;
|
||||
}
|
||||
// render
|
||||
@@ -153,14 +153,14 @@ opengl33_vaogeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stre
|
||||
::glDrawRangeElementsBaseVertex(
|
||||
chunk.type,
|
||||
0, chunkrecord.vertex_count,
|
||||
chunkrecord.index_count, GL_UNSIGNED_INT, reinterpret_cast<void const *>( chunkrecord.index_offset * sizeof( gfx::basic_index ) ),
|
||||
chunkrecord.index_count, GL_UNSIGNED_INT, reinterpret_cast<void const *>( chunkrecord.index_offset * sizeof( basic_index ) ),
|
||||
chunkrecord.vertex_offset );
|
||||
}
|
||||
else if (glDrawElementsBaseVertexOES) {
|
||||
m_vao->bind();
|
||||
::glDrawElementsBaseVertexOES(
|
||||
chunk.type,
|
||||
chunkrecord.index_count, GL_UNSIGNED_INT, reinterpret_cast<void const *>( chunkrecord.index_offset * sizeof( gfx::basic_index ) ),
|
||||
chunkrecord.index_count, GL_UNSIGNED_INT, reinterpret_cast<void const *>( chunkrecord.index_offset * sizeof( basic_index ) ),
|
||||
chunkrecord.vertex_offset );
|
||||
}
|
||||
else {
|
||||
@@ -169,7 +169,7 @@ opengl33_vaogeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stre
|
||||
::glDrawRangeElements(
|
||||
chunk.type,
|
||||
0, chunkrecord.vertex_count,
|
||||
chunkrecord.index_count, GL_UNSIGNED_INT, reinterpret_cast<void const *>( chunkrecord.index_offset * sizeof( gfx::basic_index ) ) );
|
||||
chunkrecord.index_count, GL_UNSIGNED_INT, reinterpret_cast<void const *>( chunkrecord.index_offset * sizeof( basic_index ) ) );
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -190,24 +190,24 @@ opengl33_vaogeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stre
|
||||
// draw_instanced() subclass details — single GL instanced draw for InstanceCount instances.
|
||||
// The vertex shader reads per-instance modelview from instance_ubo[gl_InstanceID].
|
||||
std::size_t
|
||||
opengl33_vaogeometrybank::draw_instanced_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, std::size_t const InstanceCount, unsigned int const Streams )
|
||||
opengl33_vaogeometrybank::draw_instanced_( geometry_handle const &Geometry, stream_units const &Units, std::size_t const InstanceCount, unsigned int const Streams )
|
||||
{
|
||||
setup_buffer();
|
||||
|
||||
auto &chunkrecord = m_chunkrecords.at(Geometry.chunk - 1);
|
||||
if( chunkrecord.vertex_count == 0 ) { return 0; }
|
||||
|
||||
auto const &chunk = gfx::geometry_bank::chunk( Geometry );
|
||||
auto const &chunk = geometry_bank::chunk( Geometry );
|
||||
if( !chunkrecord.is_good ) {
|
||||
m_vao->bind();
|
||||
if( chunkrecord.index_count > 0 ) {
|
||||
m_indexbuffer->upload( gl::buffer::ELEMENT_ARRAY_BUFFER, chunk.indices.data(), chunkrecord.index_offset * sizeof( gfx::basic_index ), chunkrecord.index_count * sizeof( gfx::basic_index ) );
|
||||
m_indexbuffer->upload( gl::buffer::ELEMENT_ARRAY_BUFFER, chunk.indices.data(), chunkrecord.index_offset * sizeof( basic_index ), chunkrecord.index_count * sizeof( basic_index ) );
|
||||
}
|
||||
m_vertexbuffer->upload( gl::buffer::ARRAY_BUFFER, chunk.vertices.data(), chunkrecord.vertex_offset * sizeof( gfx::basic_vertex ), chunkrecord.vertex_count * sizeof( gfx::basic_vertex ) );
|
||||
m_vertexbuffer->upload( gl::buffer::ARRAY_BUFFER, chunk.vertices.data(), chunkrecord.vertex_offset * sizeof( basic_vertex ), chunkrecord.vertex_count * sizeof( basic_vertex ) );
|
||||
if( chunkrecord.has_userdata ) {
|
||||
m_vertexbuffer->upload( gl::buffer::ARRAY_BUFFER, chunk.userdata.data(),
|
||||
static_cast<int>(m_vertex_count * sizeof(gfx::basic_vertex) + chunkrecord.vertex_offset * sizeof(gfx::vertex_userdata)),
|
||||
static_cast<int>(chunkrecord.vertex_count * sizeof(gfx::vertex_userdata)) );
|
||||
static_cast<int>(m_vertex_count * sizeof(basic_vertex) + chunkrecord.vertex_offset * sizeof(vertex_userdata)),
|
||||
static_cast<int>(chunkrecord.vertex_count * sizeof(vertex_userdata)) );
|
||||
}
|
||||
chunkrecord.is_good = true;
|
||||
}
|
||||
@@ -219,7 +219,7 @@ opengl33_vaogeometrybank::draw_instanced_( gfx::geometry_handle const &Geometry,
|
||||
::glDrawElementsInstancedBaseVertex(
|
||||
chunk.type,
|
||||
chunkrecord.index_count, GL_UNSIGNED_INT,
|
||||
reinterpret_cast<void const *>( chunkrecord.index_offset * sizeof( gfx::basic_index ) ),
|
||||
reinterpret_cast<void const *>( chunkrecord.index_offset * sizeof( basic_index ) ),
|
||||
inst_count,
|
||||
chunkrecord.vertex_offset );
|
||||
}
|
||||
|
||||
@@ -46,16 +46,16 @@ private:
|
||||
// methods:
|
||||
// create() subclass details
|
||||
void
|
||||
create_( gfx::geometry_handle const &Geometry ) override;
|
||||
create_( geometry_handle const &Geometry ) override;
|
||||
// replace() subclass details
|
||||
void
|
||||
replace_( gfx::geometry_handle const &Geometry ) override;
|
||||
replace_( geometry_handle const &Geometry ) override;
|
||||
// draw() subclass details
|
||||
auto
|
||||
draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) -> std::size_t override;
|
||||
draw_( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams ) -> std::size_t override;
|
||||
// draw_instanced() subclass details — issues glDrawElementsInstancedBaseVertex
|
||||
auto
|
||||
draw_instanced_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, std::size_t const InstanceCount, unsigned int const Streams ) -> std::size_t override;
|
||||
draw_instanced_( geometry_handle const &Geometry, stream_units const &Units, std::size_t const InstanceCount, unsigned int const Streams ) -> std::size_t override;
|
||||
// release() subclass details
|
||||
void
|
||||
release_() override;
|
||||
|
||||
@@ -85,7 +85,7 @@ bool opengl33_renderer::Init(GLFWwindow *Window)
|
||||
Global.DayLight.diffuse[1] = 242.0f / 255.0f;
|
||||
Global.DayLight.diffuse[2] = 231.0f / 255.0f;
|
||||
Global.DayLight.is_directional = true;
|
||||
m_sunlight.id = opengl33_renderer::sunlight;
|
||||
m_sunlight.id = sunlight;
|
||||
|
||||
// create dynamic light pool
|
||||
for (int idx = 0; idx < Global.DynamicLightCount; ++idx)
|
||||
@@ -1254,16 +1254,16 @@ bool opengl33_renderer::Render_interior( bool const Alpha ) {
|
||||
glm::dvec3 const originoffset { dynamic->vPosition - m_renderpass.pass_camera.position() };
|
||||
float const squaredistance{ glm::length2( glm::vec3{ originoffset } / Global.ZoomFactor ) };
|
||||
dynamics.emplace_back( squaredistance, dynamic );
|
||||
dynamic = dynamic->Next( coupling::permanent );
|
||||
dynamic = dynamic->Next( permanent );
|
||||
}
|
||||
// draw also interiors of permanently coupled vehicles in front, if there's any
|
||||
dynamic = simulation::Train->Dynamic()->Prev( coupling::permanent );
|
||||
dynamic = simulation::Train->Dynamic()->Prev( permanent );
|
||||
while( dynamic != nullptr ) {
|
||||
|
||||
glm::dvec3 const originoffset { dynamic->vPosition - m_renderpass.pass_camera.position() };
|
||||
float const squaredistance{ glm::length2( glm::vec3{ originoffset } / Global.ZoomFactor ) };
|
||||
dynamics.emplace_back( squaredistance, dynamic );
|
||||
dynamic = dynamic->Prev( coupling::permanent );
|
||||
dynamic = dynamic->Prev( permanent );
|
||||
}
|
||||
if( Alpha ) {
|
||||
std::sort(
|
||||
@@ -1360,11 +1360,11 @@ bool opengl33_renderer::Render_coupler_adapter( TDynamicObject *Dynamic, float c
|
||||
auto const position { glm::dvec3 {
|
||||
0.f,
|
||||
Dynamic->MoverParameters->Couplers[ End ].adapter_height,
|
||||
( Dynamic->MoverParameters->Couplers[ End ].adapter_length + Dynamic->MoverParameters->Dim.L * 0.5 ) * ( End == end::front ? 1 : -1 ) } };
|
||||
( Dynamic->MoverParameters->Couplers[ End ].adapter_length + Dynamic->MoverParameters->Dim.L * 0.5 ) * ( End == front ? 1 : -1 ) } };
|
||||
|
||||
auto const angle { glm::vec3{
|
||||
0,
|
||||
( End == end::front ? 0 : 180 ),
|
||||
( End == front ? 0 : 180 ),
|
||||
0 } };
|
||||
|
||||
if( Alpha ) {
|
||||
@@ -3449,8 +3449,8 @@ bool opengl33_renderer::Render(TDynamicObject *Dynamic)
|
||||
Render( attachment, Dynamic->Material(), squaredistance );
|
||||
}
|
||||
// optional coupling adapters
|
||||
Render_coupler_adapter( Dynamic, squaredistance, end::front );
|
||||
Render_coupler_adapter( Dynamic, squaredistance, end::rear );
|
||||
Render_coupler_adapter( Dynamic, squaredistance, front );
|
||||
Render_coupler_adapter( Dynamic, squaredistance, rear );
|
||||
|
||||
// post-render cleanup
|
||||
if (Dynamic->fShade > 0.0f)
|
||||
@@ -3475,8 +3475,8 @@ bool opengl33_renderer::Render(TDynamicObject *Dynamic)
|
||||
Render( attachment, Dynamic->Material(), squaredistance );
|
||||
}
|
||||
// optional coupling adapters
|
||||
Render_coupler_adapter( Dynamic, squaredistance, end::front );
|
||||
Render_coupler_adapter( Dynamic, squaredistance, end::rear );
|
||||
Render_coupler_adapter( Dynamic, squaredistance, front );
|
||||
Render_coupler_adapter( Dynamic, squaredistance, rear );
|
||||
if( Dynamic->mdLoad ) {
|
||||
// renderowanie nieprzezroczystego ładunku
|
||||
Render( Dynamic->mdLoad, Dynamic->Material(), squaredistance, { 0.f, Dynamic->LoadOffset, 0.f }, {} );
|
||||
@@ -4489,8 +4489,8 @@ bool opengl33_renderer::Render_Alpha(TDynamicObject *Dynamic)
|
||||
Render_Alpha( attachment, Dynamic->Material(), squaredistance );
|
||||
}
|
||||
// optional coupling adapters
|
||||
Render_coupler_adapter( Dynamic, squaredistance, end::front, true );
|
||||
Render_coupler_adapter( Dynamic, squaredistance, end::rear, true );
|
||||
Render_coupler_adapter( Dynamic, squaredistance, front, true );
|
||||
Render_coupler_adapter( Dynamic, squaredistance, rear, true );
|
||||
if( Dynamic->mdLoad ) {
|
||||
// renderowanie nieprzezroczystego ładunku
|
||||
Render_Alpha( Dynamic->mdLoad, Dynamic->Material(), squaredistance, { 0.f, Dynamic->LoadOffset, 0.f }, {} );
|
||||
@@ -5423,7 +5423,7 @@ std::unique_ptr<gfx_renderer> opengl33_renderer::create_func()
|
||||
return std::unique_ptr<gfx_renderer>(new opengl33_renderer());
|
||||
}
|
||||
|
||||
bool opengl33_renderer::renderer_register = gfx_renderer_factory::get_instance()->register_backend("modern", opengl33_renderer::create_func);
|
||||
bool opengl33_renderer::renderer_register = gfx_renderer_factory::get_instance()->register_backend("modern", create_func);
|
||||
|
||||
bool opengl33_renderer::opengl33_imgui_renderer::Init()
|
||||
{
|
||||
|
||||
@@ -18,12 +18,12 @@ namespace gfx {
|
||||
// opengl vbo-based variant of the geometry bank
|
||||
|
||||
GLuint opengl_vbogeometrybank::m_activevertexbuffer { 0 }; // buffer bound currently on the opengl end, if any
|
||||
unsigned int opengl_vbogeometrybank::m_activestreams { gfx::stream::none }; // currently enabled data type pointers
|
||||
unsigned int opengl_vbogeometrybank::m_activestreams { none }; // currently enabled data type pointers
|
||||
std::vector<GLint> opengl_vbogeometrybank::m_activetexturearrays; // currently enabled texture coord arrays
|
||||
|
||||
// create() subclass details
|
||||
void
|
||||
opengl_vbogeometrybank::create_( gfx::geometry_handle const &Geometry ) {
|
||||
opengl_vbogeometrybank::create_( geometry_handle const &Geometry ) {
|
||||
// adding a chunk means we'll be (re)building the buffer, which will fill the chunk records, amongst other things.
|
||||
// thus we don't need to initialize the values here
|
||||
m_chunkrecords.emplace_back( chunk_record() );
|
||||
@@ -33,12 +33,12 @@ opengl_vbogeometrybank::create_( gfx::geometry_handle const &Geometry ) {
|
||||
|
||||
// replace() subclass details
|
||||
void
|
||||
opengl_vbogeometrybank::replace_( gfx::geometry_handle const &Geometry ) {
|
||||
opengl_vbogeometrybank::replace_( geometry_handle const &Geometry ) {
|
||||
|
||||
auto &chunkrecord = m_chunkrecords[ Geometry.chunk - 1 ];
|
||||
chunkrecord.is_good = false;
|
||||
// if the overall length of the chunk didn't change we can get away with reusing the old buffer...
|
||||
if( geometry_bank::chunk( Geometry ).vertices.size() != chunkrecord.vertex_count ) {
|
||||
if( chunk( Geometry ).vertices.size() != chunkrecord.vertex_count ) {
|
||||
// ...but otherwise we'll need to allocate a new one
|
||||
// TBD: we could keep and reuse the old buffer also if the new chunk is smaller than the old one,
|
||||
// but it'd require some extra tracking and work to keep all chunks up to date; also wasting vram; may be not worth it?
|
||||
@@ -48,7 +48,7 @@ opengl_vbogeometrybank::replace_( gfx::geometry_handle const &Geometry ) {
|
||||
|
||||
// draw() subclass details
|
||||
std::size_t
|
||||
opengl_vbogeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) {
|
||||
opengl_vbogeometrybank::draw_( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams ) {
|
||||
|
||||
setup_buffer();
|
||||
|
||||
@@ -59,20 +59,20 @@ opengl_vbogeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stream
|
||||
if( m_activevertexbuffer != m_vertexbuffer ) {
|
||||
bind_buffer();
|
||||
}
|
||||
auto const &chunk = gfx::geometry_bank::chunk( Geometry );
|
||||
auto const &chunk = geometry_bank::chunk( Geometry );
|
||||
if( false == chunkrecord.is_good ) {
|
||||
// we may potentially need to upload new buffer data before we can draw it
|
||||
if( chunkrecord.index_count > 0 ) {
|
||||
::glBufferSubData(
|
||||
GL_ELEMENT_ARRAY_BUFFER,
|
||||
chunkrecord.index_offset * sizeof( gfx::basic_index ),
|
||||
chunkrecord.index_count * sizeof( gfx::basic_index ),
|
||||
chunkrecord.index_offset * sizeof( basic_index ),
|
||||
chunkrecord.index_count * sizeof( basic_index ),
|
||||
chunk.indices.data() );
|
||||
}
|
||||
::glBufferSubData(
|
||||
GL_ARRAY_BUFFER,
|
||||
chunkrecord.vertex_offset * sizeof( gfx::basic_vertex ),
|
||||
chunkrecord.vertex_count * sizeof( gfx::basic_vertex ),
|
||||
chunkrecord.vertex_offset * sizeof( basic_vertex ),
|
||||
chunkrecord.vertex_count * sizeof( basic_vertex ),
|
||||
chunk.vertices.data() );
|
||||
chunkrecord.is_good = true;
|
||||
}
|
||||
@@ -91,7 +91,7 @@ opengl_vbogeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stream
|
||||
::glDrawRangeElementsBaseVertex(
|
||||
chunk.type,
|
||||
0, chunkrecord.vertex_count,
|
||||
chunkrecord.index_count, GL_UNSIGNED_INT, reinterpret_cast<void const *>( chunkrecord.index_offset * sizeof( gfx::basic_index ) ),
|
||||
chunkrecord.index_count, GL_UNSIGNED_INT, reinterpret_cast<void const *>( chunkrecord.index_offset * sizeof( basic_index ) ),
|
||||
chunkrecord.vertex_offset );
|
||||
}
|
||||
else {
|
||||
@@ -99,7 +99,7 @@ opengl_vbogeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stream
|
||||
::glDrawRangeElements(
|
||||
chunk.type,
|
||||
0, chunkrecord.vertex_count,
|
||||
chunkrecord.index_count, GL_UNSIGNED_INT, reinterpret_cast<void const *>( chunkrecord.index_offset * sizeof( gfx::basic_index ) ) );
|
||||
chunkrecord.index_count, GL_UNSIGNED_INT, reinterpret_cast<void const *>( chunkrecord.index_offset * sizeof( basic_index ) ) );
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -171,7 +171,7 @@ opengl_vbogeometrybank::setup_buffer() {
|
||||
if( indexcount > 0 ) {
|
||||
::glBufferData(
|
||||
GL_ELEMENT_ARRAY_BUFFER,
|
||||
indexcount * sizeof( gfx::basic_index ),
|
||||
indexcount * sizeof( basic_index ),
|
||||
nullptr,
|
||||
GL_STATIC_DRAW );
|
||||
if( ::glGetError() == GL_OUT_OF_MEMORY ) {
|
||||
@@ -183,7 +183,7 @@ opengl_vbogeometrybank::setup_buffer() {
|
||||
}
|
||||
::glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
vertexcount * sizeof( gfx::basic_vertex ),
|
||||
vertexcount * sizeof( basic_vertex ),
|
||||
nullptr,
|
||||
GL_STATIC_DRAW );
|
||||
if( ::glGetError() == GL_OUT_OF_MEMORY ) {
|
||||
@@ -200,7 +200,7 @@ opengl_vbogeometrybank::bind_buffer() {
|
||||
::glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_indexbuffer );
|
||||
::glBindBuffer( GL_ARRAY_BUFFER, m_vertexbuffer );
|
||||
m_activevertexbuffer = m_vertexbuffer;
|
||||
m_activestreams = gfx::stream::none;
|
||||
m_activestreams = none;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -224,34 +224,34 @@ opengl_vbogeometrybank::delete_buffer() {
|
||||
}
|
||||
|
||||
void
|
||||
opengl_vbogeometrybank::bind_streams( gfx::stream_units const &Units, unsigned int const Streams, size_t offset ) {
|
||||
opengl_vbogeometrybank::bind_streams( stream_units const &Units, unsigned int const Streams, size_t offset ) {
|
||||
|
||||
if( Streams & gfx::stream::position ) {
|
||||
::glVertexPointer( 3, GL_FLOAT, sizeof( gfx::basic_vertex ), reinterpret_cast<void const *>( offsetof(gfx::basic_vertex, position) + sizeof( gfx::basic_vertex ) * offset ) );
|
||||
if( Streams & position ) {
|
||||
::glVertexPointer( 3, GL_FLOAT, sizeof( basic_vertex ), reinterpret_cast<void const *>( offsetof(gfx::basic_vertex, position) + sizeof( basic_vertex ) * offset ) );
|
||||
::glEnableClientState( GL_VERTEX_ARRAY );
|
||||
}
|
||||
else {
|
||||
::glDisableClientState( GL_VERTEX_ARRAY );
|
||||
}
|
||||
// NOTE: normal and color streams share the data, making them effectively mutually exclusive
|
||||
if( Streams & gfx::stream::normal ) {
|
||||
::glNormalPointer( GL_FLOAT, sizeof( gfx::basic_vertex ), reinterpret_cast<void const *>( offsetof(gfx::basic_vertex, normal) + sizeof( gfx::basic_vertex ) * offset ) );
|
||||
if( Streams & normal ) {
|
||||
::glNormalPointer( GL_FLOAT, sizeof( basic_vertex ), reinterpret_cast<void const *>( offsetof(gfx::basic_vertex, normal) + sizeof( basic_vertex ) * offset ) );
|
||||
::glEnableClientState( GL_NORMAL_ARRAY );
|
||||
}
|
||||
else {
|
||||
::glDisableClientState( GL_NORMAL_ARRAY );
|
||||
}
|
||||
if( Streams & gfx::stream::color ) {
|
||||
::glColorPointer( 3, GL_FLOAT, sizeof( gfx::basic_vertex ), reinterpret_cast<void const *>( offsetof(gfx::basic_vertex, normal) + sizeof( gfx::basic_vertex ) * offset ) );
|
||||
if( Streams & color ) {
|
||||
::glColorPointer( 3, GL_FLOAT, sizeof( basic_vertex ), reinterpret_cast<void const *>( offsetof(gfx::basic_vertex, normal) + sizeof( basic_vertex ) * offset ) );
|
||||
::glEnableClientState( GL_COLOR_ARRAY );
|
||||
}
|
||||
else {
|
||||
::glDisableClientState( GL_COLOR_ARRAY );
|
||||
}
|
||||
if( Streams & gfx::stream::texture ) {
|
||||
if( Streams & texture ) {
|
||||
for (const auto unit : Units.texture ) {
|
||||
::glClientActiveTexture( GL_TEXTURE0 + unit );
|
||||
::glTexCoordPointer( 2, GL_FLOAT, sizeof( gfx::basic_vertex ), reinterpret_cast<void const *>( offsetof(gfx::basic_vertex, texture) + sizeof( gfx::basic_vertex ) * offset ) );
|
||||
::glTexCoordPointer( 2, GL_FLOAT, sizeof( basic_vertex ), reinterpret_cast<void const *>( offsetof(gfx::basic_vertex, texture) + sizeof( basic_vertex ) * offset ) );
|
||||
::glEnableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
}
|
||||
m_activetexturearrays = Units.texture;
|
||||
@@ -278,7 +278,7 @@ opengl_vbogeometrybank::release_streams() {
|
||||
::glDisableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
}
|
||||
|
||||
m_activestreams = gfx::stream::none;
|
||||
m_activestreams = none;
|
||||
m_activetexturearrays.clear();
|
||||
}
|
||||
|
||||
@@ -286,21 +286,21 @@ opengl_vbogeometrybank::release_streams() {
|
||||
|
||||
// create() subclass details
|
||||
void
|
||||
opengl_dlgeometrybank::create_( gfx::geometry_handle const &Geometry ) {
|
||||
opengl_dlgeometrybank::create_( geometry_handle const &Geometry ) {
|
||||
|
||||
m_chunkrecords.emplace_back( chunk_record() );
|
||||
}
|
||||
|
||||
// replace() subclass details
|
||||
void
|
||||
opengl_dlgeometrybank::replace_( gfx::geometry_handle const &Geometry ) {
|
||||
opengl_dlgeometrybank::replace_( geometry_handle const &Geometry ) {
|
||||
|
||||
delete_list( Geometry );
|
||||
}
|
||||
|
||||
// draw() subclass details
|
||||
std::size_t
|
||||
opengl_dlgeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) {
|
||||
opengl_dlgeometrybank::draw_( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams ) {
|
||||
|
||||
auto &chunkrecord = m_chunkrecords[ Geometry.chunk - 1 ];
|
||||
if( chunkrecord.streams != Streams ) {
|
||||
@@ -311,7 +311,7 @@ opengl_dlgeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stream_
|
||||
// we don't have a list ready, so compile one
|
||||
chunkrecord.streams = Streams;
|
||||
chunkrecord.list = ::glGenLists( 1 );
|
||||
auto const &chunk = gfx::geometry_bank::chunk( Geometry );
|
||||
auto const &chunk = geometry_bank::chunk( Geometry );
|
||||
::glNewList( chunkrecord.list, GL_COMPILE );
|
||||
|
||||
::glBegin( chunk.type );
|
||||
@@ -319,19 +319,19 @@ opengl_dlgeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stream_
|
||||
// indexed geometry
|
||||
for( auto const &index : chunk.indices ) {
|
||||
auto const &vertex { chunk.vertices[ index ] };
|
||||
if( Streams & gfx::stream::normal ) { ::glNormal3fv( glm::value_ptr( vertex.normal ) ); }
|
||||
else if( Streams & gfx::stream::color ) { ::glColor3fv( glm::value_ptr( vertex.normal ) ); }
|
||||
if( Streams & gfx::stream::texture ) { for (const auto unit : Units.texture ) { ::glMultiTexCoord2fv( unit, glm::value_ptr( vertex.texture ) ); } }
|
||||
if( Streams & gfx::stream::position ) { ::glVertex3fv( glm::value_ptr( vertex.position ) ); }
|
||||
if( Streams & normal ) { ::glNormal3fv( glm::value_ptr( vertex.normal ) ); }
|
||||
else if( Streams & color ) { ::glColor3fv( glm::value_ptr( vertex.normal ) ); }
|
||||
if( Streams & texture ) { for (const auto unit : Units.texture ) { ::glMultiTexCoord2fv( unit, glm::value_ptr( vertex.texture ) ); } }
|
||||
if( Streams & position ) { ::glVertex3fv( glm::value_ptr( vertex.position ) ); }
|
||||
}
|
||||
}
|
||||
else {
|
||||
// raw geometry
|
||||
for( auto const &vertex : chunk.vertices ) {
|
||||
if( Streams & gfx::stream::normal ) { ::glNormal3fv( glm::value_ptr( vertex.normal ) ); }
|
||||
else if( Streams & gfx::stream::color ) { ::glColor3fv( glm::value_ptr( vertex.normal ) ); }
|
||||
if( Streams & gfx::stream::texture ) { for (const auto unit : Units.texture ) { ::glMultiTexCoord2fv( unit, glm::value_ptr( vertex.texture ) ); } }
|
||||
if( Streams & gfx::stream::position ) { ::glVertex3fv( glm::value_ptr( vertex.position ) ); }
|
||||
if( Streams & normal ) { ::glNormal3fv( glm::value_ptr( vertex.normal ) ); }
|
||||
else if( Streams & color ) { ::glColor3fv( glm::value_ptr( vertex.normal ) ); }
|
||||
if( Streams & texture ) { for (const auto unit : Units.texture ) { ::glMultiTexCoord2fv( unit, glm::value_ptr( vertex.texture ) ); } }
|
||||
if( Streams & position ) { ::glVertex3fv( glm::value_ptr( vertex.position ) ); }
|
||||
}
|
||||
}
|
||||
::glEnd();
|
||||
@@ -358,19 +358,19 @@ opengl_dlgeometrybank::release_() {
|
||||
::glDeleteLists( chunkrecord.list, 1 );
|
||||
chunkrecord.list = 0;
|
||||
}
|
||||
chunkrecord.streams = gfx::stream::none;
|
||||
chunkrecord.streams = none;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
opengl_dlgeometrybank::delete_list( gfx::geometry_handle const &Geometry ) {
|
||||
opengl_dlgeometrybank::delete_list( geometry_handle const &Geometry ) {
|
||||
// NOTE: given it's our own internal method we trust it to be called with valid parameters
|
||||
auto &chunkrecord = m_chunkrecords[ Geometry.chunk - 1 ];
|
||||
if( chunkrecord.list != 0 ) {
|
||||
::glDeleteLists( chunkrecord.list, 1 );
|
||||
chunkrecord.list = 0;
|
||||
}
|
||||
chunkrecord.streams = gfx::stream::none;
|
||||
chunkrecord.streams = none;
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
void
|
||||
reset() {
|
||||
m_activevertexbuffer = 0;
|
||||
m_activestreams = gfx::stream::none; }
|
||||
m_activestreams = none; }
|
||||
|
||||
private:
|
||||
// types:
|
||||
@@ -45,13 +45,13 @@ private:
|
||||
// methods:
|
||||
// create() subclass details
|
||||
void
|
||||
create_( gfx::geometry_handle const &Geometry ) override;
|
||||
create_( geometry_handle const &Geometry ) override;
|
||||
// replace() subclass details
|
||||
void
|
||||
replace_( gfx::geometry_handle const &Geometry ) override;
|
||||
replace_( geometry_handle const &Geometry ) override;
|
||||
// draw() subclass details
|
||||
auto
|
||||
draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) -> std::size_t override;
|
||||
draw_( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams ) -> std::size_t override;
|
||||
// release() subclass details
|
||||
void
|
||||
release_() override;
|
||||
@@ -63,7 +63,7 @@ private:
|
||||
delete_buffer();
|
||||
static
|
||||
void
|
||||
bind_streams(gfx::stream_units const &Units, unsigned int const Streams , size_t offset = 0);
|
||||
bind_streams(stream_units const &Units, unsigned int const Streams , size_t offset = 0);
|
||||
static
|
||||
void
|
||||
release_streams();
|
||||
@@ -103,18 +103,18 @@ private:
|
||||
// methods:
|
||||
// create() subclass details
|
||||
void
|
||||
create_( gfx::geometry_handle const &Geometry ) override;
|
||||
create_( geometry_handle const &Geometry ) override;
|
||||
// replace() subclass details
|
||||
void
|
||||
replace_( gfx::geometry_handle const &Geometry ) override;
|
||||
replace_( geometry_handle const &Geometry ) override;
|
||||
// draw() subclass details
|
||||
auto
|
||||
draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) -> std::size_t override;
|
||||
draw_( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams ) -> std::size_t override;
|
||||
// release () subclass details
|
||||
void
|
||||
release_() override;
|
||||
void
|
||||
delete_list( gfx::geometry_handle const &Geometry );
|
||||
delete_list( geometry_handle const &Geometry );
|
||||
|
||||
// members:
|
||||
chunkrecord_sequence m_chunkrecords; // helper data for all stored geometry chunks, in matching order
|
||||
|
||||
@@ -107,17 +107,17 @@ public:
|
||||
void
|
||||
mode( GLuint const Mode ) {
|
||||
switch( Mode ) {
|
||||
case GL_MODELVIEW: { m_mode = stack_mode::gl_modelview; break; }
|
||||
case GL_PROJECTION: { m_mode = stack_mode::gl_projection; break; }
|
||||
case GL_TEXTURE: { m_mode = stack_mode::gl_texture; break; }
|
||||
case GL_MODELVIEW: { m_mode = gl_modelview; break; }
|
||||
case GL_PROJECTION: { m_mode = gl_projection; break; }
|
||||
case GL_TEXTURE: { m_mode = gl_texture; break; }
|
||||
default: { break; } }
|
||||
if( m_upload ) {::glMatrixMode( Mode ); } }
|
||||
glm::mat4 const &
|
||||
data( GLuint const Mode = -1 ) const {
|
||||
switch( Mode ) {
|
||||
case GL_MODELVIEW: { return m_stacks[ stack_mode::gl_modelview ].data(); }
|
||||
case GL_PROJECTION: { return m_stacks[ stack_mode::gl_projection ].data(); }
|
||||
case GL_TEXTURE: { return m_stacks[ stack_mode::gl_texture ].data(); }
|
||||
case GL_MODELVIEW: { return m_stacks[ gl_modelview ].data(); }
|
||||
case GL_PROJECTION: { return m_stacks[ gl_projection ].data(); }
|
||||
case GL_TEXTURE: { return m_stacks[ gl_texture ].data(); }
|
||||
default: { return m_stacks[ m_mode ].data(); } } }
|
||||
float const *
|
||||
data_array( GLuint const Mode = -1 ) const {
|
||||
@@ -207,7 +207,7 @@ public:
|
||||
|
||||
private:
|
||||
// members:
|
||||
stack_mode m_mode{ stack_mode::gl_projection };
|
||||
stack_mode m_mode{ gl_projection };
|
||||
openglstack_array m_stacks;
|
||||
bool m_upload { true };
|
||||
};
|
||||
|
||||
@@ -85,14 +85,14 @@ opengl_renderer::Init( GLFWwindow *Window ) {
|
||||
// setup lighting
|
||||
::glLightModelfv( GL_LIGHT_MODEL_AMBIENT, glm::value_ptr(m_baseambient) );
|
||||
::glEnable( GL_LIGHTING );
|
||||
::glEnable( opengl_renderer::sunlight );
|
||||
::glEnable( sunlight );
|
||||
|
||||
// rgb value for 5780 kelvin
|
||||
Global.DayLight.diffuse[ 0 ] = 255.0f / 255.0f;
|
||||
Global.DayLight.diffuse[ 1 ] = 242.0f / 255.0f;
|
||||
Global.DayLight.diffuse[ 2 ] = 231.0f / 255.0f;
|
||||
Global.DayLight.is_directional = true;
|
||||
m_sunlight.id = opengl_renderer::sunlight;
|
||||
m_sunlight.id = sunlight;
|
||||
// ::glLightf( opengl_renderer::sunlight, GL_SPOT_CUTOFF, 90.0f );
|
||||
|
||||
// create dynamic light pool
|
||||
@@ -767,16 +767,16 @@ bool opengl_renderer::Render_interior( bool const Alpha ) {
|
||||
glm::dvec3 const originoffset { dynamic->vPosition - m_renderpass.camera.position() };
|
||||
float const squaredistance{ glm::length2( glm::vec3{ originoffset } / Global.ZoomFactor ) };
|
||||
dynamics.emplace_back( squaredistance, dynamic );
|
||||
dynamic = dynamic->Next( coupling::permanent );
|
||||
dynamic = dynamic->Next( permanent );
|
||||
}
|
||||
// draw also interiors of permanently coupled vehicles in front, if there's any
|
||||
dynamic = simulation::Train->Dynamic()->Prev( coupling::permanent );
|
||||
dynamic = simulation::Train->Dynamic()->Prev( permanent );
|
||||
while( dynamic != nullptr ) {
|
||||
|
||||
glm::dvec3 const originoffset { dynamic->vPosition - m_renderpass.camera.position() };
|
||||
float const squaredistance{ glm::length2( glm::vec3{ originoffset } / Global.ZoomFactor ) };
|
||||
dynamics.emplace_back( squaredistance, dynamic );
|
||||
dynamic = dynamic->Prev( coupling::permanent );
|
||||
dynamic = dynamic->Prev( permanent );
|
||||
}
|
||||
if( Alpha ) {
|
||||
std::sort(
|
||||
@@ -869,9 +869,9 @@ bool opengl_renderer::Render_coupler_adapter( TDynamicObject *Dynamic, float con
|
||||
auto const position { glm::dvec3 {
|
||||
0.f,
|
||||
Dynamic->MoverParameters->Couplers[ End ].adapter_height,
|
||||
( Dynamic->MoverParameters->Couplers[ End ].adapter_length + Dynamic->MoverParameters->Dim.L * 0.5 ) * ( End == end::front ? 1 : -1 ) } };
|
||||
( Dynamic->MoverParameters->Couplers[ End ].adapter_length + Dynamic->MoverParameters->Dim.L * 0.5 ) * ( End == front ? 1 : -1 ) } };
|
||||
|
||||
auto const angle{ glm::vec3{ 0, ( End == end::front ? 0 : 180 ), 0 } };
|
||||
auto const angle{ glm::vec3{ 0, ( End == front ? 0 : 180 ), 0 } };
|
||||
|
||||
if( Alpha ) {
|
||||
Render_Alpha( Dynamic->m_coupleradapters[ End ], Dynamic->Material(), Squaredistance, position, angle );
|
||||
@@ -1203,7 +1203,7 @@ opengl_renderer::setup_units( bool const Diffuse, bool const Shadows, bool const
|
||||
}
|
||||
else {
|
||||
// ...otherwise fallback on static spherical image
|
||||
m_textures.bind( textureunit::helper, m_reflectiontexture );
|
||||
m_textures.bind( helper, m_reflectiontexture );
|
||||
::glEnable( GL_TEXTURE_2D );
|
||||
}
|
||||
}
|
||||
@@ -2509,8 +2509,8 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) {
|
||||
Render( attachment, Dynamic->Material(), squaredistance );
|
||||
}
|
||||
// optional coupling adapters
|
||||
Render_coupler_adapter( Dynamic, squaredistance, end::front );
|
||||
Render_coupler_adapter( Dynamic, squaredistance, end::rear );
|
||||
Render_coupler_adapter( Dynamic, squaredistance, front );
|
||||
Render_coupler_adapter( Dynamic, squaredistance, rear );
|
||||
// post-render cleanup
|
||||
m_renderspecular = false;
|
||||
if( Dynamic->fShade > 0.0f ) {
|
||||
@@ -2536,8 +2536,8 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) {
|
||||
Render( attachment, Dynamic->Material(), squaredistance );
|
||||
}
|
||||
// optional coupling adapters
|
||||
Render_coupler_adapter( Dynamic, squaredistance, end::front );
|
||||
Render_coupler_adapter( Dynamic, squaredistance, end::rear );
|
||||
Render_coupler_adapter( Dynamic, squaredistance, front );
|
||||
Render_coupler_adapter( Dynamic, squaredistance, rear );
|
||||
if( Dynamic->mdLoad ) {
|
||||
// renderowanie nieprzezroczystego ładunku
|
||||
Render( Dynamic->mdLoad, Dynamic->Material(), squaredistance, { 0.f, Dynamic->LoadOffset, 0.f }, {} );
|
||||
@@ -3713,8 +3713,8 @@ opengl_renderer::Render_Alpha( TDynamicObject *Dynamic ) {
|
||||
Render_Alpha( attachment, Dynamic->Material(), squaredistance );
|
||||
}
|
||||
// optional coupling adapters
|
||||
Render_coupler_adapter( Dynamic, squaredistance, end::front, true );
|
||||
Render_coupler_adapter( Dynamic, squaredistance, end::rear, true );
|
||||
Render_coupler_adapter( Dynamic, squaredistance, front, true );
|
||||
Render_coupler_adapter( Dynamic, squaredistance, rear, true );
|
||||
if( Dynamic->mdLoad ) {
|
||||
// renderowanie nieprzezroczystego ładunku
|
||||
Render_Alpha( Dynamic->mdLoad, Dynamic->Material(), squaredistance, { 0.f, Dynamic->LoadOffset, 0.f }, {} );
|
||||
@@ -4522,7 +4522,7 @@ std::unique_ptr<gfx_renderer> opengl_renderer::create_func()
|
||||
return std::unique_ptr<gfx_renderer>(new opengl_renderer());
|
||||
}
|
||||
|
||||
bool opengl_renderer::renderer_register = gfx_renderer_factory::get_instance()->register_backend("legacy", opengl_renderer::create_func);
|
||||
bool opengl_renderer::renderer_register = gfx_renderer_factory::get_instance()->register_backend("legacy", create_func);
|
||||
|
||||
bool opengl_renderer::opengl_imgui_renderer::Init()
|
||||
{
|
||||
|
||||
@@ -23,14 +23,14 @@ smoke_source::particle_emitter::deserialize( cParser &Input ) {
|
||||
if( Input.getToken<std::string>() != "{" ) { return; }
|
||||
|
||||
std::unordered_map<std::string, float &> const variablemap {
|
||||
{ "min_inclination:", inclination[ value_limit::min ] },
|
||||
{ "max_inclination:", inclination[ value_limit::max ] },
|
||||
{ "min_velocity:", velocity[ value_limit::min ] },
|
||||
{ "max_velocity:", velocity[ value_limit::max ] },
|
||||
{ "min_size:", size[ value_limit::min ] },
|
||||
{ "max_size:", size[ value_limit::max ] },
|
||||
{ "min_opacity:", opacity[ value_limit::min ] },
|
||||
{ "max_opacity:", opacity[ value_limit::max ] } };
|
||||
{ "min_inclination:", inclination[ min ] },
|
||||
{ "max_inclination:", inclination[ max ] },
|
||||
{ "min_velocity:", velocity[ min ] },
|
||||
{ "max_velocity:", velocity[ max ] },
|
||||
{ "min_size:", size[ min ] },
|
||||
{ "max_size:", size[ max ] },
|
||||
{ "min_opacity:", opacity[ min ] },
|
||||
{ "max_opacity:", opacity[ max ] } };
|
||||
std::string key;
|
||||
|
||||
while( ( false == ( ( key = Input.getToken<std::string>( true, "\n\r\t ,;[]" ) ).empty() ) )
|
||||
@@ -58,20 +58,20 @@ smoke_source::particle_emitter::deserialize( cParser &Input ) {
|
||||
void
|
||||
smoke_source::particle_emitter::initialize( smoke_particle &Particle ) {
|
||||
|
||||
auto const polarangle { glm::radians( LocalRandom( inclination[ value_limit::min ], inclination[ value_limit::max ] ) ) }; // theta
|
||||
auto const polarangle { glm::radians( LocalRandom( inclination[ min ], inclination[ max ] ) ) }; // theta
|
||||
auto const azimuthalangle { glm::radians( LocalRandom( -180, 180 ) ) }; // phi
|
||||
// convert spherical coordinates to opengl coordinates
|
||||
auto const launchvector { glm::vec3(
|
||||
std::sin( polarangle ) * std::sin( azimuthalangle ) * -1,
|
||||
std::cos( polarangle ),
|
||||
std::sin( polarangle ) * std::cos( azimuthalangle ) ) };
|
||||
auto const launchvelocity { static_cast<float>( LocalRandom( velocity[ value_limit::min ], velocity[ value_limit::max ] ) ) };
|
||||
auto const launchvelocity { static_cast<float>( LocalRandom( velocity[ min ], velocity[ max ] ) ) };
|
||||
|
||||
Particle.velocity = launchvector * launchvelocity;
|
||||
|
||||
Particle.rotation = glm::radians( LocalRandom( 0, 360 ) );
|
||||
Particle.size = LocalRandom( size[ value_limit::min ], size[ value_limit::max ] );
|
||||
Particle.opacity = LocalRandom( opacity[ value_limit::min ], opacity[ value_limit::max ] ) / Global.SmokeFidelity;
|
||||
Particle.size = LocalRandom( size[ min ], size[ max ] );
|
||||
Particle.opacity = LocalRandom( opacity[ min ], opacity[ max ] ) / Global.SmokeFidelity;
|
||||
Particle.age = 0;
|
||||
}
|
||||
|
||||
@@ -282,8 +282,8 @@ smoke_source::update( double const Timedelta, bool const Onlydespawn ) {
|
||||
}
|
||||
// determine bounding area from calculated bounding box
|
||||
if( false == m_particles.empty() ) {
|
||||
m_area.center = glm::mix(boundingbox[value_limit::min], boundingbox[value_limit::max], 0.5);
|
||||
m_area.radius = 0.5 * ( glm::length( boundingbox[ value_limit::max ] - boundingbox[ value_limit::min ] ) );
|
||||
m_area.center = glm::mix(boundingbox[min], boundingbox[max], 0.5);
|
||||
m_area.radius = 0.5 * ( glm::length( boundingbox[ max ] - boundingbox[ min ] ) );
|
||||
}
|
||||
else {
|
||||
m_area.center = location();
|
||||
@@ -392,8 +392,8 @@ smoke_source::update( smoke_particle &Particle, bounding_box &Boundingbox, doubl
|
||||
Particle.age += Timedelta;
|
||||
|
||||
// update bounding box
|
||||
Boundingbox[ value_limit::min ] = glm::min( Boundingbox[ value_limit::min ], Particle.position - glm::dvec3{ Particle.size } );
|
||||
Boundingbox[ value_limit::max ] = glm::max( Boundingbox[ value_limit::max ], Particle.position + glm::dvec3{ Particle.size } );
|
||||
Boundingbox[ min ] = glm::min( Boundingbox[ min ], Particle.position - glm::dvec3{ Particle.size } );
|
||||
Boundingbox[ max ] = glm::max( Boundingbox[ max ], Particle.position + glm::dvec3{ Particle.size } );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -215,8 +215,8 @@ fixedstep_modifier<Type_>::update( Type_ &Variable, double const Timedelta ) con
|
||||
m_valuechange / *( m_valuechangemodifier ) ) };
|
||||
Variable += ( valuechange * static_cast<float>( Timedelta ) );
|
||||
// clamp down to allowed value range
|
||||
Variable = glm::max( Variable, m_valuelimits[ value_limit::min ] );
|
||||
Variable = glm::min( Variable, m_valuelimits[ value_limit::max ] );
|
||||
Variable = glm::max( Variable, m_valuelimits[ min ] );
|
||||
Variable = glm::min( Variable, m_valuelimits[ max ] );
|
||||
}
|
||||
|
||||
template <typename Type_>
|
||||
@@ -227,8 +227,8 @@ fixedstep_modifier<Type_>::deserialize( cParser &Input ) {
|
||||
|
||||
std::unordered_map<std::string, Type_ &> const variablemap {
|
||||
{ "step:", m_valuechange },
|
||||
{ "min:", m_valuelimits[ value_limit::min ] },
|
||||
{ "max:", m_valuelimits[ value_limit::max ] } };
|
||||
{ "min:", m_valuelimits[ min ] },
|
||||
{ "max:", m_valuelimits[ max ] } };
|
||||
|
||||
std::string key;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
std::unique_ptr<gfx_renderer> GfxRenderer;
|
||||
|
||||
bool gfx_renderer_factory::register_backend(const std::string &backend, gfx_renderer_factory::create_method func)
|
||||
bool gfx_renderer_factory::register_backend(const std::string &backend, create_method func)
|
||||
{
|
||||
backends[backend] = func;
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user