mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
multi texturing support for display list mode
This commit is contained in:
@@ -963,8 +963,6 @@ void TWorld::FollowView(bool wycisz) {
|
||||
+ Train->GetDirection() * 5.0 * Train->Dynamic()->MoverParameters->ActiveCab;
|
||||
}
|
||||
Train->pMechOffset = Train->pMechSittingPosition;
|
||||
|
||||
Global::SetCameraPosition( Train->Dynamic() ->GetPosition()); // tu ustawić nową, bo od niej liczą się odległości
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -98,9 +98,9 @@ geometry_bank::append( vertex_array &Vertices, geometry_handle const &Geometry )
|
||||
|
||||
// draws geometry stored in specified chunk
|
||||
void
|
||||
geometry_bank::draw( geometry_handle const &Geometry, unsigned int const Streams ) {
|
||||
geometry_bank::draw( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams ) {
|
||||
// template method implementation
|
||||
draw_( Geometry, Streams );
|
||||
draw_( Geometry, Units, Streams );
|
||||
}
|
||||
|
||||
// frees subclass-specific resources associated with the bank, typically called when the bank wasn't in use for a period of time
|
||||
@@ -148,7 +148,7 @@ opengl_vbogeometrybank::replace_( geometry_handle const &Geometry ) {
|
||||
|
||||
// draw() subclass details
|
||||
void
|
||||
opengl_vbogeometrybank::draw_( geometry_handle const &Geometry, unsigned int const Streams ) {
|
||||
opengl_vbogeometrybank::draw_( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams ) {
|
||||
|
||||
if( m_buffer == NULL ) {
|
||||
// if there's no buffer, we'll have to make one
|
||||
@@ -203,7 +203,7 @@ opengl_vbogeometrybank::draw_( geometry_handle const &Geometry, unsigned int con
|
||||
chunkrecord.is_good = true;
|
||||
}
|
||||
if( m_activestreams != Streams ) {
|
||||
bind_streams( Streams );
|
||||
bind_streams( Units, Streams );
|
||||
}
|
||||
// ...render...
|
||||
::glDrawArrays( chunk.type, chunkrecord.offset, chunkrecord.size );
|
||||
@@ -239,7 +239,7 @@ opengl_vbogeometrybank::delete_buffer() {
|
||||
::glDeleteBuffers( 1, &m_buffer );
|
||||
if( m_activebuffer == m_buffer ) {
|
||||
m_activebuffer = NULL;
|
||||
bind_streams( stream::none );
|
||||
release_streams();
|
||||
}
|
||||
m_buffer = NULL;
|
||||
m_buffercapacity = 0;
|
||||
@@ -249,7 +249,7 @@ opengl_vbogeometrybank::delete_buffer() {
|
||||
}
|
||||
|
||||
void
|
||||
opengl_vbogeometrybank::bind_streams( unsigned int const Streams ) {
|
||||
opengl_vbogeometrybank::bind_streams( stream_units const &Units, unsigned int const Streams ) {
|
||||
|
||||
if( Streams & stream::position ) {
|
||||
::glVertexPointer( 3, GL_FLOAT, sizeof( basic_vertex ), static_cast<char *>( nullptr ) );
|
||||
@@ -274,6 +274,7 @@ opengl_vbogeometrybank::bind_streams( unsigned int const Streams ) {
|
||||
::glDisableClientState( GL_COLOR_ARRAY );
|
||||
}
|
||||
if( Streams & stream::texture ) {
|
||||
::glClientActiveTexture( Units.texture );
|
||||
::glTexCoordPointer( 2, GL_FLOAT, sizeof( basic_vertex ), static_cast<char *>( nullptr ) + 24 );
|
||||
::glEnableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
}
|
||||
@@ -284,6 +285,17 @@ opengl_vbogeometrybank::bind_streams( unsigned int const Streams ) {
|
||||
m_activestreams = Streams;
|
||||
}
|
||||
|
||||
void
|
||||
opengl_vbogeometrybank::release_streams() {
|
||||
|
||||
::glDisableClientState( GL_VERTEX_ARRAY );
|
||||
::glDisableClientState( GL_NORMAL_ARRAY );
|
||||
::glDisableClientState( GL_COLOR_ARRAY );
|
||||
::glDisableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
|
||||
m_activestreams = stream::none;
|
||||
}
|
||||
|
||||
// opengl display list based variant of the geometry bank
|
||||
|
||||
// create() subclass details
|
||||
@@ -302,7 +314,7 @@ opengl_dlgeometrybank::replace_( geometry_handle const &Geometry ) {
|
||||
|
||||
// draw() subclass details
|
||||
void
|
||||
opengl_dlgeometrybank::draw_( geometry_handle const &Geometry, 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 ) {
|
||||
@@ -319,7 +331,7 @@ opengl_dlgeometrybank::draw_( geometry_handle const &Geometry, unsigned int cons
|
||||
for( auto const &vertex : chunk.vertices ) {
|
||||
if( Streams & stream::normal ) { ::glNormal3fv( glm::value_ptr( vertex.normal ) ); }
|
||||
else if( Streams & stream::color ) { ::glColor3fv( glm::value_ptr( vertex.normal ) ); }
|
||||
if( Streams & stream::texture ) { ::glTexCoord2fv( glm::value_ptr( vertex.texture ) ); }
|
||||
if( Streams & stream::texture ) { ::glMultiTexCoord2fv( Units.texture, glm::value_ptr( vertex.texture ) ); }
|
||||
if( Streams & stream::position ) { ::glVertex3fv( glm::value_ptr( vertex.position ) ); }
|
||||
}
|
||||
::glEnd();
|
||||
@@ -404,7 +416,7 @@ geometrybank_manager::draw( geometry_handle const &Geometry, unsigned int const
|
||||
auto &bankrecord = bank( Geometry );
|
||||
|
||||
bankrecord.second = m_garbagecollector.timestamp();
|
||||
bankrecord.first->draw( Geometry, Streams );
|
||||
bankrecord.first->draw( Geometry, m_units, Streams );
|
||||
}
|
||||
|
||||
// provides direct access to vertex data of specfied chunk
|
||||
|
||||
@@ -42,7 +42,12 @@ enum stream {
|
||||
};
|
||||
|
||||
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 {
|
||||
|
||||
GLint texture { GL_TEXTURE0 }; // unit associated with main texture data stream. TODO: allow multiple units per stream
|
||||
};
|
||||
|
||||
typedef std::vector<basic_vertex> vertex_array;
|
||||
|
||||
@@ -98,11 +103,11 @@ public:
|
||||
append( vertex_array &Vertices, geometry_handle const &Geometry );
|
||||
// draws geometry stored in specified chunk
|
||||
void
|
||||
draw( geometry_handle const &Geometry, unsigned int const Streams = basic_streams );
|
||||
draw( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams = basic_streams );
|
||||
// draws geometry stored in supplied list of chunks
|
||||
template <typename Iterator_>
|
||||
void
|
||||
draw( Iterator_ First, Iterator_ Last, unsigned int const Streams = basic_streams ) { while( First != Last ) { draw( *First, Streams ); ++First; } }
|
||||
draw( Iterator_ First, Iterator_ Last, stream_units const &Units, unsigned int const Streams = basic_streams ) { while( First != Last ) { draw( *First, Units, Streams ); ++First; } }
|
||||
// frees subclass-specific resources associated with the bank, typically called when the bank wasn't in use for a period of time
|
||||
void
|
||||
release();
|
||||
@@ -145,7 +150,7 @@ private:
|
||||
// replace() subclass details
|
||||
virtual void replace_( geometry_handle const &Geometry ) = 0;
|
||||
// draw() subclass details
|
||||
virtual void draw_( geometry_handle const &Geometry, unsigned int const Streams ) = 0;
|
||||
virtual void draw_( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams ) = 0;
|
||||
// resource release subclass details
|
||||
virtual void release_() = 0;
|
||||
};
|
||||
@@ -186,8 +191,8 @@ private:
|
||||
replace_( geometry_handle const &Geometry );
|
||||
// draw() subclass details
|
||||
void
|
||||
draw_( geometry_handle const &Geometry, unsigned int const Streams );
|
||||
// release () subclass details
|
||||
draw_( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams );
|
||||
// release() subclass details
|
||||
void
|
||||
release_();
|
||||
void
|
||||
@@ -195,7 +200,9 @@ private:
|
||||
void
|
||||
delete_buffer();
|
||||
void
|
||||
bind_streams( unsigned int const Streams );
|
||||
bind_streams( stream_units const &Units, unsigned int const Streams );
|
||||
void
|
||||
release_streams();
|
||||
|
||||
// members:
|
||||
static GLuint m_activebuffer; // buffer bound currently on the opengl end, if any
|
||||
@@ -236,7 +243,7 @@ private:
|
||||
replace_( geometry_handle const &Geometry );
|
||||
// draw() subclass details
|
||||
void
|
||||
draw_( geometry_handle const &Geometry, unsigned int const Streams );
|
||||
draw_( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams );
|
||||
// release () subclass details
|
||||
void
|
||||
release_();
|
||||
@@ -282,6 +289,9 @@ public:
|
||||
// provides direct access to vertex data of specfied chunk
|
||||
vertex_array const &
|
||||
vertices( geometry_handle const &Geometry ) const;
|
||||
// sets target texture unit for the texture data stream
|
||||
stream_units &
|
||||
units() { return m_units; }
|
||||
|
||||
private:
|
||||
// types:
|
||||
@@ -294,6 +304,7 @@ private:
|
||||
// members:
|
||||
geometrybanktimepointpair_sequence m_geometrybanks;
|
||||
garbage_collector<geometrybanktimepointpair_sequence> m_garbagecollector { m_geometrybanks, 60, 120, "geometry buffer" };
|
||||
stream_units m_units;
|
||||
|
||||
// methods
|
||||
inline
|
||||
|
||||
@@ -71,7 +71,7 @@ opengl_renderer::Init( GLFWwindow *Window ) {
|
||||
glShadeModel( GL_SMOOTH ); // Enable Smooth Shading
|
||||
|
||||
glActiveTexture( m_diffusetextureunit );
|
||||
glClientActiveTexture( m_diffusetextureunit );
|
||||
m_geometry.units().texture = m_diffusetextureunit;
|
||||
UILayer.set_unit( m_diffusetextureunit );
|
||||
|
||||
glEnable( GL_DEPTH_TEST );
|
||||
@@ -566,7 +566,7 @@ void
|
||||
opengl_renderer::setup_camera_light_perspective( glm::dmat4 &Viewmatrix ) {
|
||||
|
||||
m_renderpass.camera.position() = Global::pCameraPosition - glm::dvec3{ Global::DayLight.direction * m_renderpass.draw_range * 0.5f };
|
||||
m_renderpass.camera.position().y = std::max( 75.0, m_renderpass.camera.position().y ); // prevent shadow source from dipping too low
|
||||
m_renderpass.camera.position().y = std::max<float>( m_renderpass.draw_range * 0.5f * 0.1f, m_renderpass.camera.position().y ); // prevent shadow source from dipping too low
|
||||
Viewmatrix = glm::lookAt(
|
||||
m_renderpass.camera.position(),
|
||||
glm::dvec3{ Global::pCameraPosition.x, 0.0, Global::pCameraPosition.z },
|
||||
|
||||
@@ -65,7 +65,7 @@ ui_layer::render() {
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho( 0, Global::ScreenWidth, Global::ScreenHeight, 0, -1, 1 );
|
||||
glOrtho( 0, std::max( 1, Global::ScreenWidth ), std::max( 1, Global::ScreenHeight ), 0, -1, 1 );
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
Reference in New Issue
Block a user