mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 13:59:19 +02:00
more pruning, remove texture units from geometrybank and remove dl
geometrybank
This commit is contained in:
@@ -100,9 +100,9 @@ geometry_bank::append( gfx::vertex_array &Vertices, gfx::geometry_handle const &
|
|||||||
|
|
||||||
// draws geometry stored in specified chunk
|
// draws geometry stored in specified chunk
|
||||||
void
|
void
|
||||||
geometry_bank::draw( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) {
|
geometry_bank::draw( gfx::geometry_handle const &Geometry, unsigned int const Streams ) {
|
||||||
// template method implementation
|
// template method implementation
|
||||||
draw_( Geometry, Units, Streams );
|
draw_( Geometry, Streams );
|
||||||
}
|
}
|
||||||
|
|
||||||
// frees subclass-specific resources associated with the bank, typically called when the bank wasn't in use for a period of time
|
// frees subclass-specific resources associated with the bank, typically called when the bank wasn't in use for a period of time
|
||||||
@@ -145,7 +145,7 @@ opengl_vbogeometrybank::replace_( gfx::geometry_handle const &Geometry ) {
|
|||||||
|
|
||||||
// draw() subclass details
|
// draw() subclass details
|
||||||
void
|
void
|
||||||
opengl_vbogeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) {
|
opengl_vbogeometrybank::draw_( gfx::geometry_handle const &Geometry, unsigned int const Streams ) {
|
||||||
|
|
||||||
if( m_buffer == 0 ) {
|
if( m_buffer == 0 ) {
|
||||||
// if there's no buffer, we'll have to make one
|
// if there's no buffer, we'll have to make one
|
||||||
@@ -206,6 +206,7 @@ opengl_vbogeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stream
|
|||||||
m_vao->setup_attrib(2, 2, GL_FLOAT, sizeof(basic_vertex), 6 * sizeof(GL_FLOAT));
|
m_vao->setup_attrib(2, 2, GL_FLOAT, sizeof(basic_vertex), 6 * sizeof(GL_FLOAT));
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
m_vao->unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
// actual draw procedure starts here
|
// actual draw procedure starts here
|
||||||
@@ -249,75 +250,6 @@ opengl_vbogeometrybank::delete_buffer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// opengl display list based variant of the geometry bank
|
|
||||||
|
|
||||||
// create() subclass details
|
|
||||||
void
|
|
||||||
opengl_dlgeometrybank::create_( gfx::geometry_handle const &Geometry ) {
|
|
||||||
|
|
||||||
m_chunkrecords.emplace_back( chunk_record() );
|
|
||||||
}
|
|
||||||
|
|
||||||
// replace() subclass details
|
|
||||||
void
|
|
||||||
opengl_dlgeometrybank::replace_( gfx::geometry_handle const &Geometry ) {
|
|
||||||
|
|
||||||
delete_list( Geometry );
|
|
||||||
}
|
|
||||||
|
|
||||||
// draw() subclass details
|
|
||||||
void
|
|
||||||
opengl_dlgeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) {
|
|
||||||
|
|
||||||
auto &chunkrecord = m_chunkrecords[ Geometry.chunk - 1 ];
|
|
||||||
if( chunkrecord.streams != Streams ) {
|
|
||||||
delete_list( Geometry );
|
|
||||||
}
|
|
||||||
if( chunkrecord.list == 0 ) {
|
|
||||||
// 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 );
|
|
||||||
::glNewList( chunkrecord.list, GL_COMPILE );
|
|
||||||
|
|
||||||
::glBegin( chunk.type );
|
|
||||||
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( auto unit : Units.texture ) { ::glMultiTexCoord2fv( unit, glm::value_ptr( vertex.texture ) ); } }
|
|
||||||
if( Streams & gfx::stream::position ) { ::glVertex3fv( glm::value_ptr( vertex.position ) ); }
|
|
||||||
}
|
|
||||||
::glEnd();
|
|
||||||
::glEndList();
|
|
||||||
}
|
|
||||||
// with the list done we can just play it
|
|
||||||
::glCallList( chunkrecord.list );
|
|
||||||
}
|
|
||||||
|
|
||||||
// release () subclass details
|
|
||||||
void
|
|
||||||
opengl_dlgeometrybank::release_() {
|
|
||||||
|
|
||||||
for( auto &chunkrecord : m_chunkrecords ) {
|
|
||||||
if( chunkrecord.list != 0 ) {
|
|
||||||
::glDeleteLists( chunkrecord.list, 1 );
|
|
||||||
chunkrecord.list = 0;
|
|
||||||
}
|
|
||||||
chunkrecord.streams = gfx::stream::none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
opengl_dlgeometrybank::delete_list( gfx::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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// geometry bank manager, holds collection of geometry banks
|
// geometry bank manager, holds collection of geometry banks
|
||||||
|
|
||||||
// performs a resource sweep
|
// performs a resource sweep
|
||||||
@@ -368,7 +300,7 @@ geometrybank_manager::draw( gfx::geometry_handle const &Geometry, unsigned int c
|
|||||||
auto &bankrecord = bank( Geometry );
|
auto &bankrecord = bank( Geometry );
|
||||||
|
|
||||||
bankrecord.second = m_garbagecollector.timestamp();
|
bankrecord.second = m_garbagecollector.timestamp();
|
||||||
bankrecord.first->draw( Geometry, m_units, Streams );
|
bankrecord.first->draw( Geometry, Streams );
|
||||||
}
|
}
|
||||||
|
|
||||||
// provides direct access to vertex data of specfied chunk
|
// provides direct access to vertex data of specfied chunk
|
||||||
|
|||||||
@@ -46,12 +46,6 @@ enum stream {
|
|||||||
|
|
||||||
unsigned int const basic_streams { stream::position | stream::normal | stream::texture };
|
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 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
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::vector<basic_vertex> vertex_array;
|
typedef std::vector<basic_vertex> vertex_array;
|
||||||
|
|
||||||
// generic geometry bank class, allows storage, update and drawing of geometry chunks
|
// generic geometry bank class, allows storage, update and drawing of geometry chunks
|
||||||
@@ -106,11 +100,11 @@ public:
|
|||||||
append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry );
|
append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry );
|
||||||
// draws geometry stored in specified chunk
|
// draws geometry stored in specified chunk
|
||||||
void
|
void
|
||||||
draw( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams = basic_streams );
|
draw( gfx::geometry_handle const &Geometry, unsigned int const Streams = basic_streams );
|
||||||
// draws geometry stored in supplied list of chunks
|
// draws geometry stored in supplied list of chunks
|
||||||
template <typename Iterator_>
|
template <typename Iterator_>
|
||||||
void
|
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; } }
|
draw( Iterator_ First, Iterator_ Last, unsigned int const Streams = basic_streams ) { while( First != Last ) { draw( *First, Streams ); ++First; } }
|
||||||
// frees subclass-specific resources associated with the bank, typically called when the bank wasn't in use for a period of time
|
// frees subclass-specific resources associated with the bank, typically called when the bank wasn't in use for a period of time
|
||||||
void
|
void
|
||||||
release();
|
release();
|
||||||
@@ -152,7 +146,7 @@ private:
|
|||||||
// replace() subclass details
|
// replace() subclass details
|
||||||
virtual void replace_( gfx::geometry_handle const &Geometry ) = 0;
|
virtual void replace_( gfx::geometry_handle const &Geometry ) = 0;
|
||||||
// draw() subclass details
|
// draw() subclass details
|
||||||
virtual void draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) = 0;
|
virtual void draw_( gfx::geometry_handle const &Geometry, unsigned int const Streams ) = 0;
|
||||||
// resource release subclass details
|
// resource release subclass details
|
||||||
virtual void release_() = 0;
|
virtual void release_() = 0;
|
||||||
};
|
};
|
||||||
@@ -191,7 +185,7 @@ private:
|
|||||||
replace_( gfx::geometry_handle const &Geometry );
|
replace_( gfx::geometry_handle const &Geometry );
|
||||||
// draw() subclass details
|
// draw() subclass details
|
||||||
void
|
void
|
||||||
draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams );
|
draw_( gfx::geometry_handle const &Geometry, unsigned int const Streams );
|
||||||
// release() subclass details
|
// release() subclass details
|
||||||
void
|
void
|
||||||
release_();
|
release_();
|
||||||
@@ -206,48 +200,6 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// opengl display list based variant of the geometry bank
|
|
||||||
|
|
||||||
class opengl_dlgeometrybank : public geometry_bank {
|
|
||||||
|
|
||||||
public:
|
|
||||||
// constructors:
|
|
||||||
opengl_dlgeometrybank() = default;
|
|
||||||
// destructor:
|
|
||||||
~opengl_dlgeometrybank() {
|
|
||||||
for( auto &chunkrecord : m_chunkrecords ) {
|
|
||||||
::glDeleteLists( chunkrecord.list, 1 ); } }
|
|
||||||
|
|
||||||
private:
|
|
||||||
// types:
|
|
||||||
struct chunk_record {
|
|
||||||
GLuint list { 0 }; // display list associated with the chunk
|
|
||||||
unsigned int streams { 0 }; // stream combination used to generate the display list
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::vector<chunk_record> chunkrecord_sequence;
|
|
||||||
|
|
||||||
// methods:
|
|
||||||
// create() subclass details
|
|
||||||
void
|
|
||||||
create_( gfx::geometry_handle const &Geometry );
|
|
||||||
// replace() subclass details
|
|
||||||
void
|
|
||||||
replace_( gfx::geometry_handle const &Geometry );
|
|
||||||
// draw() subclass details
|
|
||||||
void
|
|
||||||
draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams );
|
|
||||||
// release () subclass details
|
|
||||||
void
|
|
||||||
release_();
|
|
||||||
void
|
|
||||||
delete_list( gfx::geometry_handle const &Geometry );
|
|
||||||
|
|
||||||
// members:
|
|
||||||
chunkrecord_sequence m_chunkrecords; // helper data for all stored geometry chunks, in matching order
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// geometry bank manager, holds collection of geometry banks
|
// geometry bank manager, holds collection of geometry banks
|
||||||
|
|
||||||
typedef geometry_handle geometrybank_handle;
|
typedef geometry_handle geometrybank_handle;
|
||||||
@@ -282,9 +234,6 @@ public:
|
|||||||
// provides direct access to vertex data of specfied chunk
|
// provides direct access to vertex data of specfied chunk
|
||||||
gfx::vertex_array const &
|
gfx::vertex_array const &
|
||||||
vertices( gfx::geometry_handle const &Geometry ) 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:
|
private:
|
||||||
// types:
|
// types:
|
||||||
@@ -297,7 +246,6 @@ private:
|
|||||||
// members:
|
// members:
|
||||||
geometrybanktimepointpair_sequence m_geometrybanks;
|
geometrybanktimepointpair_sequence m_geometrybanks;
|
||||||
garbage_collector<geometrybanktimepointpair_sequence> m_garbagecollector { m_geometrybanks, 60, 120, "geometry buffer" };
|
garbage_collector<geometrybanktimepointpair_sequence> m_garbagecollector { m_geometrybanks, 60, 120, "geometry buffer" };
|
||||||
gfx::stream_units m_units;
|
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
inline
|
inline
|
||||||
|
|||||||
@@ -100,10 +100,6 @@ opengl_renderer::Init( GLFWwindow *Window ) {
|
|||||||
glFrontFace( GL_CCW );
|
glFrontFace( GL_CCW );
|
||||||
glEnable( GL_CULL_FACE );
|
glEnable( GL_CULL_FACE );
|
||||||
|
|
||||||
m_geometry.units().texture = (
|
|
||||||
Global.BasicRenderer ?
|
|
||||||
std::vector<GLint>{ m_diffusetextureunit } :
|
|
||||||
std::vector<GLint>{ m_normaltextureunit, m_diffusetextureunit } );
|
|
||||||
m_textures.assign_units( m_helpertextureunit, m_shadowtextureunit, m_normaltextureunit, m_diffusetextureunit ); // TODO: add reflections unit
|
m_textures.assign_units( m_helpertextureunit, m_shadowtextureunit, m_normaltextureunit, m_diffusetextureunit ); // TODO: add reflections unit
|
||||||
UILayer.set_unit( m_diffusetextureunit );
|
UILayer.set_unit( m_diffusetextureunit );
|
||||||
select_unit( m_diffusetextureunit );
|
select_unit( m_diffusetextureunit );
|
||||||
|
|||||||
@@ -143,13 +143,14 @@ void CSkyDome::Render() {
|
|||||||
::glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_indexbuffer );
|
::glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_indexbuffer );
|
||||||
::glBufferData( GL_ELEMENT_ARRAY_BUFFER, m_indices.size() * sizeof( unsigned short ), m_indices.data(), GL_STATIC_DRAW );
|
::glBufferData( GL_ELEMENT_ARRAY_BUFFER, m_indices.size() * sizeof( unsigned short ), m_indices.data(), GL_STATIC_DRAW );
|
||||||
// NOTE: vertex and index source data is superfluous past this point, but, eh
|
// NOTE: vertex and index source data is superfluous past this point, but, eh
|
||||||
|
|
||||||
|
m_vao->unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_shader->bind();
|
m_shader->bind();
|
||||||
m_shader->copy_gl_mvp();
|
m_shader->copy_gl_mvp();
|
||||||
m_vao->bind();
|
m_vao->bind();
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexbuffer);
|
|
||||||
glDrawElements( GL_TRIANGLES, static_cast<GLsizei>( m_indices.size() ), GL_UNSIGNED_SHORT, reinterpret_cast<void const*>( 0 ) );
|
glDrawElements( GL_TRIANGLES, static_cast<GLsizei>( m_indices.size() ), GL_UNSIGNED_SHORT, reinterpret_cast<void const*>( 0 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user