more pruning, remove texture units from geometrybank and remove dl

geometrybank
This commit is contained in:
milek7
2018-06-25 13:31:58 +02:00
parent d8b3ddba8c
commit 48f2265c34
4 changed files with 11 additions and 134 deletions

View File

@@ -100,9 +100,9 @@ geometry_bank::append( gfx::vertex_array &Vertices, gfx::geometry_handle const &
// draws geometry stored in specified chunk
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
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
@@ -145,7 +145,7 @@ opengl_vbogeometrybank::replace_( gfx::geometry_handle const &Geometry ) {
// draw() subclass details
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 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));
glBindBuffer(GL_ARRAY_BUFFER, 0);
m_vao->unbind();
}
// 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
// performs a resource sweep
@@ -368,7 +300,7 @@ geometrybank_manager::draw( gfx::geometry_handle const &Geometry, unsigned int c
auto &bankrecord = bank( Geometry );
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

View File

@@ -46,12 +46,6 @@ enum stream {
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
};
typedef std::vector<basic_vertex> vertex_array;
// 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 );
// draws geometry stored in specified chunk
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
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; } }
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
void
release();
@@ -152,7 +146,7 @@ private:
// 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;
virtual void draw_( gfx::geometry_handle const &Geometry, unsigned int const Streams ) = 0;
// resource release subclass details
virtual void release_() = 0;
};
@@ -191,7 +185,7 @@ private:
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 );
draw_( gfx::geometry_handle const &Geometry, unsigned int const Streams );
// release() subclass details
void
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
typedef geometry_handle geometrybank_handle;
@@ -282,9 +234,6 @@ public:
// 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:
@@ -297,7 +246,6 @@ private:
// members:
geometrybanktimepointpair_sequence m_geometrybanks;
garbage_collector<geometrybanktimepointpair_sequence> m_garbagecollector { m_geometrybanks, 60, 120, "geometry buffer" };
gfx::stream_units m_units;
// methods
inline

View File

@@ -100,10 +100,6 @@ opengl_renderer::Init( GLFWwindow *Window ) {
glFrontFace( GL_CCW );
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
UILayer.set_unit( m_diffusetextureunit );
select_unit( m_diffusetextureunit );

View File

@@ -143,13 +143,14 @@ void CSkyDome::Render() {
::glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_indexbuffer );
::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
m_vao->unbind();
}
m_shader->bind();
m_shader->copy_gl_mvp();
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 ) );
}