mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-19 17:59:18 +02:00
completed basic separation of visual renderer from simulation
This commit is contained in:
@@ -445,7 +445,7 @@ bool TAnimModel::Init(std::string const &asName, std::string const &asReplacable
|
||||
asText = asReplacableTexture.substr(1, asReplacableTexture.length() - 1); // zapamiętanie tekstu
|
||||
else if (asReplacableTexture != "none")
|
||||
m_materialdata.replacable_skins[1] =
|
||||
GfxRenderer.GetTextureId( asReplacableTexture, "" );
|
||||
GfxRenderer.Fetch_Texture( asReplacableTexture, "" );
|
||||
if( ( m_materialdata.replacable_skins[ 1 ] != 0 )
|
||||
&& ( GfxRenderer.Texture( m_materialdata.replacable_skins[ 1 ] ).has_alpha ) ) {
|
||||
// tekstura z kanałem alfa - nie renderować w cyklu nieprzezroczystych
|
||||
@@ -606,6 +606,7 @@ int TAnimModel::Flags()
|
||||
//-----------------------------------------------------------------------------
|
||||
// 2011-03-16 funkcje renderowania z możliwością pochylania obiektów
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef EU07_USE_OLD_RENDERCODE
|
||||
void TAnimModel::Render( vector3 const &Position ) {
|
||||
RaAnimate(); // jednorazowe przeliczenie animacji
|
||||
RaPrepare();
|
||||
@@ -617,7 +618,7 @@ void TAnimModel::RenderAlpha( vector3 const &Position ) {
|
||||
if( pModel ) // renderowanie rekurencyjne submodeli
|
||||
GfxRenderer.Render_Alpha( pModel, Material(), Position, vAngle );
|
||||
};
|
||||
|
||||
#endif
|
||||
//---------------------------------------------------------------------------
|
||||
bool TAnimModel::TerrainLoaded()
|
||||
{ // zliczanie kwadratów kilometrowych (główna linia po Next) do tworznia tablicy
|
||||
|
||||
@@ -164,8 +164,10 @@ class TAnimModel {
|
||||
bool Load(cParser *parser, bool ter = false);
|
||||
TAnimContainer * AddContainer(char *pName);
|
||||
TAnimContainer * GetContainer(char *pName);
|
||||
#ifdef EU07_USE_OLD_RENDERCODE
|
||||
void Render( vector3 const &Position );
|
||||
void RenderAlpha( vector3 const &Position );
|
||||
#endif
|
||||
int Flags();
|
||||
void RaAnglesSet(double a, double b, double c)
|
||||
{
|
||||
|
||||
20
DynObj.cpp
20
DynObj.cpp
@@ -4064,7 +4064,7 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
|
||||
{
|
||||
std::string nowheretexture = TextureTest(Global::asCurrentTexturePath + "nowhere"); // na razie prymitywnie
|
||||
if( false == nowheretexture.empty() ) {
|
||||
m_materialdata.replacable_skins[ 4 ] = GfxRenderer.GetTextureId( nowheretexture, "", 9 );
|
||||
m_materialdata.replacable_skins[ 4 ] = GfxRenderer.Fetch_Texture( nowheretexture, "", 9 );
|
||||
}
|
||||
|
||||
if (m_materialdata.multi_textures > 0) {
|
||||
@@ -4076,7 +4076,7 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
|
||||
int skinindex = 0;
|
||||
std::string texturename; nameparser >> texturename;
|
||||
while( ( texturename != "" ) && ( skinindex < 4 ) ) {
|
||||
m_materialdata.replacable_skins[ skinindex + 1 ] = GfxRenderer.GetTextureId( Global::asCurrentTexturePath + texturename, "" );
|
||||
m_materialdata.replacable_skins[ skinindex + 1 ] = GfxRenderer.Fetch_Texture( Global::asCurrentTexturePath + texturename, "" );
|
||||
++skinindex;
|
||||
texturename = ""; nameparser >> texturename;
|
||||
}
|
||||
@@ -4086,7 +4086,7 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
|
||||
// otherwise try the basic approach
|
||||
int skinindex = 0;
|
||||
do {
|
||||
texture_handle texture = GfxRenderer.GetTextureId( Global::asCurrentTexturePath + ReplacableSkin + "," + std::to_string( skinindex + 1 ), "", Global::iDynamicFiltering, true );
|
||||
texture_handle texture = GfxRenderer.Fetch_Texture( Global::asCurrentTexturePath + ReplacableSkin + "," + std::to_string( skinindex + 1 ), "", Global::iDynamicFiltering, true );
|
||||
if( texture == NULL ) {
|
||||
break;
|
||||
}
|
||||
@@ -4096,12 +4096,12 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
|
||||
m_materialdata.multi_textures = skinindex;
|
||||
if( m_materialdata.multi_textures == 0 ) {
|
||||
// zestaw nie zadziałał, próbujemy normanie
|
||||
m_materialdata.replacable_skins[ 1 ] = GfxRenderer.GetTextureId( Global::asCurrentTexturePath + ReplacableSkin, "", Global::iDynamicFiltering );
|
||||
m_materialdata.replacable_skins[ 1 ] = GfxRenderer.Fetch_Texture( Global::asCurrentTexturePath + ReplacableSkin, "", Global::iDynamicFiltering );
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_materialdata.replacable_skins[ 1 ] = GfxRenderer.GetTextureId( Global::asCurrentTexturePath + ReplacableSkin, "", Global::iDynamicFiltering );
|
||||
m_materialdata.replacable_skins[ 1 ] = GfxRenderer.Fetch_Texture( Global::asCurrentTexturePath + ReplacableSkin, "", Global::iDynamicFiltering );
|
||||
}
|
||||
if( GfxRenderer.Texture( m_materialdata.replacable_skins[ 1 ] ).has_alpha ) {
|
||||
// tekstura -1 z kanałem alfa - nie renderować w cyklu nieprzezroczystych
|
||||
@@ -5424,13 +5424,13 @@ void TDynamicObject::DestinationSet(std::string to, std::string numer)
|
||||
std::string x = TextureTest(asBaseDir + numer + "@" + MoverParameters->TypeName);
|
||||
if (!x.empty())
|
||||
{
|
||||
m_materialdata.replacable_skins[ 4 ] = GfxRenderer.GetTextureId( x, "", 9 ); // rozmywania 0,1,4,5 nie nadają się
|
||||
m_materialdata.replacable_skins[ 4 ] = GfxRenderer.Fetch_Texture( x, "", 9 ); // rozmywania 0,1,4,5 nie nadają się
|
||||
return;
|
||||
}
|
||||
x = TextureTest(asBaseDir + numer );
|
||||
if (!x.empty())
|
||||
{
|
||||
m_materialdata.replacable_skins[ 4 ] = GfxRenderer.GetTextureId( x, "", 9 ); // rozmywania 0,1,4,5 nie nadają się
|
||||
m_materialdata.replacable_skins[ 4 ] = GfxRenderer.Fetch_Texture( x, "", 9 ); // rozmywania 0,1,4,5 nie nadają się
|
||||
return;
|
||||
}
|
||||
if (to.empty())
|
||||
@@ -5438,17 +5438,17 @@ void TDynamicObject::DestinationSet(std::string to, std::string numer)
|
||||
x = TextureTest(asBaseDir + to + "@" + MoverParameters->TypeName); // w pierwszej kolejności z nazwą FIZ/MMD
|
||||
if (!x.empty())
|
||||
{
|
||||
m_materialdata.replacable_skins[ 4 ] = GfxRenderer.GetTextureId( x, "", 9 ); // rozmywania 0,1,4,5 nie nadają się
|
||||
m_materialdata.replacable_skins[ 4 ] = GfxRenderer.Fetch_Texture( x, "", 9 ); // rozmywania 0,1,4,5 nie nadają się
|
||||
return;
|
||||
}
|
||||
x = TextureTest(asBaseDir + to); // na razie prymitywnie
|
||||
if (!x.empty())
|
||||
m_materialdata.replacable_skins[ 4 ] = GfxRenderer.GetTextureId( x, "", 9 ); // rozmywania 0,1,4,5 nie nadają się
|
||||
m_materialdata.replacable_skins[ 4 ] = GfxRenderer.Fetch_Texture( x, "", 9 ); // rozmywania 0,1,4,5 nie nadają się
|
||||
else
|
||||
{
|
||||
x = TextureTest(asBaseDir + "nowhere"); // jak nie znalazł dedykowanej, to niech daje nowhere
|
||||
if (!x.empty())
|
||||
m_materialdata.replacable_skins[ 4 ] = GfxRenderer.GetTextureId( x, "", 9 );
|
||||
m_materialdata.replacable_skins[ 4 ] = GfxRenderer.Fetch_Texture( x, "", 9 );
|
||||
}
|
||||
// Ra 2015-01: żeby zalogować błąd, trzeba by mieć pewność, że model używa tekstury nr 4
|
||||
};
|
||||
|
||||
@@ -53,9 +53,8 @@ std::string LogComment;
|
||||
bool
|
||||
degenerate( glm::dvec3 const &Vertex1, glm::dvec3 const &Vertex2, glm::dvec3 const &Vertex3 ) {
|
||||
|
||||
return ( ( Vertex1 == Vertex2 )
|
||||
|| ( Vertex2 == Vertex3 )
|
||||
|| ( Vertex3 == Vertex1 ) );
|
||||
// degenerate( A, B, C, minarea ) = ( ( B - A ).cross( C - A ) ).lengthSquared() < ( 4.0f * minarea * minarea );
|
||||
return glm::length2( glm::cross( Vertex2 - Vertex1, Vertex3 - Vertex1 ) ) < std::numeric_limits<double>::epsilon();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -1330,7 +1329,7 @@ TGroundNode * TGround::AddGroundNode(cParser *parser)
|
||||
*parser >> token;
|
||||
}
|
||||
str = token;
|
||||
tmp->TextureID = GfxRenderer.GetTextureId( str, szTexturePath );
|
||||
tmp->TextureID = GfxRenderer.Fetch_Texture( str );
|
||||
bool const clamps = (
|
||||
tmp->TextureID ?
|
||||
GfxRenderer.Texture( tmp->TextureID ).traits.find( 's' ) != std::string::npos :
|
||||
|
||||
@@ -341,7 +341,7 @@ int TSubModel::Load( cParser &parser, TModel3d *Model, /*int Pos,*/ bool dynamic
|
||||
if( texture.find_first_of( "/\\" ) == texture.npos ) {
|
||||
texture.insert( 0, Global::asCurrentTexturePath );
|
||||
}
|
||||
TextureID = GfxRenderer.GetTextureId( texture, szTexturePath );
|
||||
TextureID = GfxRenderer.Fetch_Texture( texture );
|
||||
// renderowanie w cyklu przezroczystych tylko jeśli:
|
||||
// 1. Opacity=0 (przejściowo <1, czy tam <100) oraz
|
||||
// 2. tekstura ma przezroczystość
|
||||
@@ -1670,7 +1670,7 @@ void TSubModel::BinInit(TSubModel *s, float4x4 *m, std::vector<std::string> *t,
|
||||
pTexture = t->at(iTexture);
|
||||
if (pTexture.find_last_of("/\\") == std::string::npos)
|
||||
pTexture.insert(0, Global::asCurrentTexturePath);
|
||||
TextureID = GfxRenderer.GetTextureId(pTexture, szTexturePath);
|
||||
TextureID = GfxRenderer.Fetch_Texture(pTexture);
|
||||
if( ( iFlags & 0x30 ) == 0 ) {
|
||||
// texture-alpha based fallback if for some reason we don't have opacity flag set yet
|
||||
iFlags |=
|
||||
|
||||
32
Track.cpp
32
Track.cpp
@@ -483,20 +483,20 @@ void TTrack::Load(cParser *parser, vector3 pOrigin, std::string name)
|
||||
{
|
||||
parser->getTokens();
|
||||
*parser >> str; // railtex
|
||||
TextureID1 = (str == "none" ? 0 : GfxRenderer.GetTextureId(
|
||||
str, szTexturePath,
|
||||
(iCategoryFlag & 1) ? Global::iRailProFiltering :
|
||||
Global::iBallastFiltering));
|
||||
TextureID1 = (
|
||||
str == "none" ?
|
||||
NULL :
|
||||
GfxRenderer.Fetch_Texture( str ) );
|
||||
parser->getTokens();
|
||||
*parser >> fTexLength; // tex tile length
|
||||
if (fTexLength < 0.01)
|
||||
fTexLength = 4; // Ra: zabezpiecznie przed zawieszeniem
|
||||
parser->getTokens();
|
||||
*parser >> str; // sub || railtex
|
||||
TextureID2 = (str == "none" ? 0 : GfxRenderer.GetTextureId(
|
||||
str, szTexturePath,
|
||||
(eType == tt_Normal) ? Global::iBallastFiltering :
|
||||
Global::iRailProFiltering));
|
||||
TextureID2 = (
|
||||
str == "none" ?
|
||||
NULL :
|
||||
GfxRenderer.Fetch_Texture( str ) );
|
||||
parser->getTokens(3);
|
||||
*parser >> fTexHeight1 >> fTexWidth >> fTexSlope;
|
||||
if (iCategoryFlag & 4)
|
||||
@@ -1866,22 +1866,6 @@ void TTrack::EnvironmentReset()
|
||||
}
|
||||
};
|
||||
|
||||
void TTrack::RenderDyn()
|
||||
{ // renderowanie nieprzezroczystych fragmentów pojazdów
|
||||
for( auto dynamic : Dynamics ) {
|
||||
// sam sprawdza, czy VBO; zmienia kontekst VBO!
|
||||
GfxRenderer.Render( dynamic );
|
||||
}
|
||||
};
|
||||
|
||||
void TTrack::RenderDynAlpha()
|
||||
{ // renderowanie przezroczystych fragmentów pojazdów
|
||||
for( auto dynamic : Dynamics ) {
|
||||
// sam sprawdza, czy VBO; zmienia kontekst VBO!
|
||||
GfxRenderer.Render_Alpha( dynamic );
|
||||
}
|
||||
};
|
||||
|
||||
void TTrack::RenderDynSounds()
|
||||
{ // odtwarzanie dźwięków pojazdów jest niezależne od ich wyświetlania
|
||||
for( auto dynamic : Dynamics ) {
|
||||
|
||||
2
Track.h
2
Track.h
@@ -236,8 +236,6 @@ public:
|
||||
/*
|
||||
void RaRenderVBO(int iPtr); // renderowanie z VBO sektora
|
||||
*/
|
||||
void RenderDyn(); // renderowanie nieprzezroczystych pojazdów (oba tryby)
|
||||
void RenderDynAlpha(); // renderowanie przezroczystych pojazdów (oba tryby)
|
||||
void RenderDynSounds(); // odtwarzanie dźwięków pojazdów jest niezależne od ich wyświetlania
|
||||
|
||||
void RaOwnerSet(TSubRect *o) {
|
||||
|
||||
171
renderer.cpp
171
renderer.cpp
@@ -190,9 +190,9 @@ opengl_renderer::Init( GLFWwindow *Window ) {
|
||||
::glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
|
||||
// preload some common textures
|
||||
WriteLog( "Loading common gfx data..." );
|
||||
m_glaretexture = GetTextureId( "fx\\lightglare", szTexturePath );
|
||||
m_suntexture = GetTextureId( "fx\\sun", szTexturePath );
|
||||
m_moontexture = GetTextureId( "fx\\moon", szTexturePath );
|
||||
m_glaretexture = Fetch_Texture( "fx\\lightglare" );
|
||||
m_suntexture = Fetch_Texture( "fx\\sun" );
|
||||
m_moontexture = Fetch_Texture( "fx\\moon" );
|
||||
WriteLog( "...gfx data pre-loading done" );
|
||||
// prepare basic geometry chunks
|
||||
auto const geometrybank = m_geometry.create_bank();
|
||||
@@ -236,15 +236,27 @@ opengl_renderer::Render_pass( rendermode const Mode ) {
|
||||
|
||||
case rendermode::color: {
|
||||
|
||||
// TODO: run shadowmap pass before color
|
||||
if( Global::RenderShadows && World.InitPerformed() ) {
|
||||
// run shadowmap pass before color
|
||||
::glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_shadowframebuffer );
|
||||
::glDrawBuffer( GL_NONE ); // we won't be rendering colour data, so can skip the colour attachment
|
||||
|
||||
Render_pass( rendermode::shadows );
|
||||
m_renderpass.draw_mode = rendermode::color; // restore draw mode. TODO: render mode stack
|
||||
|
||||
::glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); // switch back to primary render target
|
||||
::glDrawBuffer( GL_BACK );
|
||||
}
|
||||
|
||||
#ifdef EU07_USE_PICKING_FRAMEBUFFER
|
||||
::glViewport( 0, 0, Global::ScreenWidth, Global::ScreenHeight );
|
||||
#endif
|
||||
|
||||
if( World.InitPerformed() ) {
|
||||
auto const skydomecolour = World.Environment.m_skydome.GetAverageColor();
|
||||
::glClearColor( skydomecolour.x, skydomecolour.y, skydomecolour.z, 0.0f ); // kolor nieba
|
||||
}
|
||||
else {
|
||||
::glClearColor( 51.0f / 255.0f, 102.0f / 255.0f, 85.0f / 255.0f, 1.0f ); // initial background Color
|
||||
}
|
||||
::glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
|
||||
if( World.InitPerformed() ) {
|
||||
@@ -271,15 +283,14 @@ opengl_renderer::Render_pass( rendermode const Mode ) {
|
||||
|
||||
case rendermode::shadows: {
|
||||
|
||||
#ifdef EU07_USE_PICKING_FRAMEBUFFER
|
||||
::glViewport( 0, 0, m_pickbuffersize, m_pickbuffersize ); // TODO: separate shadow buffer
|
||||
#endif
|
||||
::glViewport( 0, 0, m_shadowbuffersize, m_shadowbuffersize );
|
||||
|
||||
::glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
|
||||
::glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
::glClear( GL_DEPTH_BUFFER_BIT );
|
||||
|
||||
if( World.InitPerformed() ) {
|
||||
// setup
|
||||
m_renderpass.draw_range = 500.0f; // 1.5km square centered around camera
|
||||
m_renderpass.draw_range = 500.0f; // 1.0km square centered around camera
|
||||
Render_projection();
|
||||
Render_camera();
|
||||
::glDepthFunc( GL_LEQUAL );
|
||||
@@ -355,9 +366,11 @@ opengl_renderer::Render_projection() {
|
||||
|
||||
switch( m_renderpass.draw_mode ) {
|
||||
|
||||
case rendermode::color:
|
||||
#ifndef EU07_USE_PICKING_FRAMEBUFFER
|
||||
case rendermode::pickcontrols:
|
||||
case rendermode::pickscenery: {
|
||||
case rendermode::pickscenery:
|
||||
#endif
|
||||
case rendermode::color: {
|
||||
::gluPerspective(
|
||||
Global::FieldOfView / Global::ZoomFactor,
|
||||
std::max( 1.0f, (float)Global::ScreenWidth ) / std::max( 1.0f, (float)Global::ScreenHeight ),
|
||||
@@ -365,19 +378,20 @@ opengl_renderer::Render_projection() {
|
||||
m_renderpass.draw_range * Global::fDistanceFactor );
|
||||
break;
|
||||
}
|
||||
/*
|
||||
// version for the smaller pickbuffer. ultimately scratched because resolution isn't comfortable/reliable enough for the user
|
||||
#ifdef EU07_USE_PICKING_FRAMEBUFFER
|
||||
case rendermode::pickcontrols:
|
||||
case rendermode::pickscenery: {
|
||||
// TODO: render to buffer and scissor test for pick modes
|
||||
// TODO: scissor test for pick modes
|
||||
auto const angle = Global::FieldOfView / Global::ZoomFactor;
|
||||
auto const height = std::max( 1.0f, (float)Global::ScreenWidth ) / std::max( 1.0f, (float)Global::ScreenHeight ) / ( Global::ScreenWidth / m_pickbuffersize );
|
||||
::gluPerspective(
|
||||
Global::FieldOfView / Global::ZoomFactor,
|
||||
std::max( 1.0f, (float)Global::ScreenWidth ) / std::max( 1.0f, (float)Global::ScreenHeight ) / ( Global::ScreenWidth / 1024.0f ),
|
||||
std::max( 1.0f, (float)Global::ScreenWidth ) / std::max( 1.0f, (float)Global::ScreenHeight ) / ( Global::ScreenWidth / m_pickbuffersize ),
|
||||
0.1f * Global::ZoomFactor,
|
||||
m_renderpass.draw_range * Global::fDistanceFactor );
|
||||
break;
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
case rendermode::shadows: {
|
||||
// TODO: set parallel projection
|
||||
::gluPerspective(
|
||||
@@ -447,6 +461,9 @@ opengl_renderer::Render_setup( bool const Alpha ) {
|
||||
case rendermode::color: {
|
||||
::glEnable( GL_LIGHTING );
|
||||
::glShadeModel( GL_SMOOTH );
|
||||
if( Global::iMultisampling ) {
|
||||
::glEnable( GL_MULTISAMPLE );
|
||||
}
|
||||
// setup fog
|
||||
if( Global::fFogEnd > 0 ) {
|
||||
// fog setup
|
||||
@@ -474,9 +491,12 @@ opengl_renderer::Render_setup( bool const Alpha ) {
|
||||
case rendermode::shadows:
|
||||
case rendermode::pickcontrols:
|
||||
case rendermode::pickscenery: {
|
||||
::glDisable( GL_FOG );
|
||||
::glDisable( GL_LIGHTING );
|
||||
::glShadeModel( GL_FLAT );
|
||||
if( Global::iMultisampling ) {
|
||||
::glDisable( GL_MULTISAMPLE );
|
||||
}
|
||||
::glDisable( GL_FOG );
|
||||
|
||||
if( m_texenvmode != m_renderpass.draw_mode ) {
|
||||
// solid colour with texture alpha
|
||||
@@ -508,19 +528,32 @@ opengl_renderer::Render( world_environment *Environment ) {
|
||||
}
|
||||
|
||||
Bind( NULL );
|
||||
|
||||
::glDisable( GL_LIGHTING );
|
||||
::glDisable( GL_DEPTH_TEST );
|
||||
::glDepthMask( GL_FALSE );
|
||||
::glPushMatrix();
|
||||
|
||||
// skydome
|
||||
Environment->m_skydome.Render();
|
||||
if( true == Global::bUseVBO ) {
|
||||
// skydome uses a custom vbo which could potentially confuse the main geometry system. hardly elegant but, eh
|
||||
opengl_vbogeometrybank::reset();
|
||||
}
|
||||
Environment->m_stars.render();
|
||||
// stars
|
||||
if( Environment->m_stars.m_stars != nullptr ) {
|
||||
// setup
|
||||
::glPushMatrix();
|
||||
::glRotatef( Environment->m_stars.m_latitude, 1.f, 0.f, 0.f ); // ustawienie osi OY na północ
|
||||
::glRotatef( -std::fmod( (float)Global::fTimeAngleDeg, 360.f ), 0.f, 1.f, 0.f ); // obrót dobowy osi OX
|
||||
::glPointSize( 2.f );
|
||||
// render
|
||||
GfxRenderer.Render( Environment->m_stars.m_stars, nullptr, 1.0 );
|
||||
// post-render cleanup
|
||||
::glPointSize( 3.f );
|
||||
::glPopMatrix();
|
||||
}
|
||||
|
||||
// celestial bodies
|
||||
float const duskfactor = 1.0f - clamp( std::abs( Environment->m_sun.getAngle() ), 0.0f, 12.0f ) / 12.0f;
|
||||
glm::vec3 suncolor = interpolate(
|
||||
glm::vec3( 255.0f / 255.0f, 242.0f / 255.0f, 231.0f / 255.0f ),
|
||||
@@ -601,10 +634,26 @@ opengl_renderer::Render( world_environment *Environment ) {
|
||||
::glPopAttrib();
|
||||
|
||||
// clouds
|
||||
Environment->m_clouds.Render(
|
||||
interpolate( Environment->m_skydome.GetAverageColor(), suncolor, duskfactor * 0.25f )
|
||||
* ( 1.0f - Global::Overcast * 0.5f ) // overcast darkens the clouds
|
||||
* 2.5f ); // arbitrary adjustment factor
|
||||
if( Environment->m_clouds.mdCloud ) {
|
||||
// setup
|
||||
Disable_Lights();
|
||||
::glEnable( GL_LIGHTING );
|
||||
::glLightModelfv(
|
||||
GL_LIGHT_MODEL_AMBIENT,
|
||||
glm::value_ptr(
|
||||
interpolate( Environment->m_skydome.GetAverageColor(), suncolor, duskfactor * 0.25f )
|
||||
* ( 1.0f - Global::Overcast * 0.5f ) // overcast darkens the clouds
|
||||
* 2.5f // arbitrary adjustment factor
|
||||
) );
|
||||
// render
|
||||
Render( Environment->m_clouds.mdCloud, nullptr, 100.0 );
|
||||
Render_Alpha( Environment->m_clouds.mdCloud, nullptr, 100.0 );
|
||||
// post-render cleanup
|
||||
GLfloat noambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||
::glLightModelfv( GL_LIGHT_MODEL_AMBIENT, noambient );
|
||||
::glEnable( GL_LIGHT0 ); // other lights will be enabled during lights update
|
||||
::glDisable( GL_LIGHTING );
|
||||
}
|
||||
|
||||
Global::DayLight.apply_angle();
|
||||
Global::DayLight.apply_intensity();
|
||||
@@ -655,7 +704,7 @@ opengl_renderer::Vertices( geometry_handle const &Geometry ) const {
|
||||
|
||||
// texture methods
|
||||
texture_handle
|
||||
opengl_renderer::GetTextureId( std::string Filename, std::string const &Dir, int const Filter, bool const Loadnow ) {
|
||||
opengl_renderer::Fetch_Texture( std::string const &Filename, std::string const &Dir, int const Filter, bool const Loadnow ) {
|
||||
|
||||
return m_textures.create( Filename, Dir, Filter, Loadnow );
|
||||
}
|
||||
@@ -854,7 +903,7 @@ opengl_renderer::Render( TSubRect *Groundsubcell ) {
|
||||
#ifdef EU07_SCENERY_EDITOR
|
||||
// memcells
|
||||
if( EditorModeFlag ) {
|
||||
for( auto const memcell : m_memcells ) {
|
||||
for( auto const memcell : Groundsubcell->m_memcells ) {
|
||||
Render( memcell );
|
||||
}
|
||||
}
|
||||
@@ -888,7 +937,7 @@ opengl_renderer::Render( TSubRect *Groundsubcell ) {
|
||||
#ifdef EU07_SCENERY_EDITOR
|
||||
// memcells
|
||||
if( EditorModeFlag ) {
|
||||
for( auto const memcell : m_memcells ) {
|
||||
for( auto const memcell : Groundsubcell->m_memcells ) {
|
||||
::glColor3fv( glm::value_ptr( pick_color( m_picksceneryitems.size() + 1 ) ) );
|
||||
Render( memcell );
|
||||
}
|
||||
@@ -961,7 +1010,14 @@ opengl_renderer::Render( TGroundNode *Node ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#ifdef EU07_USE_OLD_RENDERCODE
|
||||
Node->Model->Render( Node->pCenter - m_renderpass.camera.position() );
|
||||
#else
|
||||
Node->Model->RaAnimate(); // jednorazowe przeliczenie animacji
|
||||
Node->Model->RaPrepare();
|
||||
if( Node->Model->pModel ) // renderowanie rekurencyjne submodeli
|
||||
Render( Node->Model->pModel, Node->Model->Material(), Node->pCenter - m_renderpass.camera.position(), Node->Model->vAngle );
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1559,19 +1615,35 @@ opengl_renderer::Render( TTrack *Track ) {
|
||||
void
|
||||
opengl_renderer::Render( TMemCell *Memcell ) {
|
||||
|
||||
::glPushAttrib( GL_ENABLE_BIT );
|
||||
// ::glDisable( GL_LIGHTING );
|
||||
::glDisable( GL_TEXTURE_2D );
|
||||
// ::glEnable( GL_BLEND );
|
||||
::glPushMatrix();
|
||||
|
||||
auto const position = Memcell->Position();
|
||||
auto const position = Memcell->Position() - m_renderpass.camera.position();
|
||||
::glTranslated( position.x, position.y + 0.5, position.z );
|
||||
::glColor3f( 0.36f, 0.75f, 0.35f );
|
||||
::gluSphere( m_quadric, 0.35, 4, 2 );
|
||||
|
||||
switch( m_renderpass.draw_mode ) {
|
||||
case rendermode::color: {
|
||||
::glPushAttrib( GL_ENABLE_BIT );
|
||||
::glDisable( GL_TEXTURE_2D );
|
||||
::glColor3f( 0.36f, 0.75f, 0.35f );
|
||||
|
||||
::gluSphere( m_quadric, 0.35, 4, 2 );
|
||||
|
||||
::glPopAttrib();
|
||||
break;
|
||||
}
|
||||
case rendermode::pickscenery:
|
||||
case rendermode::shadows: {
|
||||
::gluSphere( m_quadric, 0.35, 4, 2 );
|
||||
break;
|
||||
}
|
||||
case rendermode::pickcontrols: {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
::glPopMatrix();
|
||||
::glPopAttrib();
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -1615,8 +1687,11 @@ opengl_renderer::Render_Alpha( TSubRect *Groundsubcell ) {
|
||||
Render_Alpha( node ); // przezroczyste z mieszanych modeli
|
||||
for( node = Groundsubcell->nRenderAlpha; node; node = node->nNext3 )
|
||||
Render_Alpha( node ); // przezroczyste modele
|
||||
for( int j = 0; j < Groundsubcell->iTracks; ++j )
|
||||
Groundsubcell->tTracks[ j ]->RenderDynAlpha(); // przezroczyste fragmenty pojazdów na torach
|
||||
for( int trackidx = 0; trackidx < Groundsubcell->iTracks; ++trackidx ) {
|
||||
for( auto dynamic : Groundsubcell->tTracks[ trackidx ]->Dynamics ) {
|
||||
Render_Alpha( dynamic ); // przezroczyste fragmenty pojazdów na torach
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1677,7 +1752,13 @@ opengl_renderer::Render_Alpha( TGroundNode *Node ) {
|
||||
}
|
||||
}
|
||||
case TP_MODEL: {
|
||||
#ifdef EU07_USE_OLD_RENDERCODE
|
||||
Node->Model->RenderAlpha( Node->pCenter - m_renderpass.camera.position() );
|
||||
#else
|
||||
Node->Model->RaPrepare();
|
||||
if( Node->Model->pModel ) // renderowanie rekurencyjne submodeli
|
||||
Render_Alpha( Node->Model->pModel, Node->Model->Material(), Node->pCenter - m_renderpass.camera.position(), Node->Model->vAngle );
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2137,15 +2218,11 @@ opengl_renderer::Update( double const Deltatime ) {
|
||||
// adjust draw ranges etc, based on recent performance
|
||||
auto const framerate = 1000.0f / (m_drawtime / 20.0f);
|
||||
|
||||
// NOTE: until we have quadtree in place we have to rely on the legacy rendering
|
||||
// once this is resolved we should be able to simply adjust draw range
|
||||
int targetsegments;
|
||||
float targetfactor;
|
||||
|
||||
if( framerate > 90.0 ) { targetsegments = 400; targetfactor = 3.0f; }
|
||||
else if( framerate > 60.0 ) { targetsegments = 225; targetfactor = 1.5f; }
|
||||
else if( framerate > 30.0 ) { targetsegments = 90; targetfactor = Global::ScreenHeight / 768.0f; }
|
||||
else { targetsegments = 9; targetfactor = Global::ScreenHeight / 768.0f * 0.75f; }
|
||||
if( framerate > 90.0 ) { targetfactor = 3.0f; }
|
||||
else if( framerate > 60.0 ) { targetfactor = 1.5f; }
|
||||
else if( framerate > 30.0 ) { targetfactor = Global::ScreenHeight / 768.0f; }
|
||||
else { targetfactor = Global::ScreenHeight / 768.0f * 0.75f; }
|
||||
|
||||
if( targetfactor > Global::fDistanceFactor ) {
|
||||
|
||||
|
||||
32
renderer.h
32
renderer.h
@@ -119,21 +119,6 @@ public:
|
||||
// main draw call. returns false on error
|
||||
bool
|
||||
Render();
|
||||
// render sub-methods, temporarily exposed until we complete migrating render code to the renderer
|
||||
bool
|
||||
Render( TDynamicObject *Dynamic );
|
||||
bool
|
||||
Render( TModel3d *Model, material_data const *Material, Math3D::vector3 const &Position, Math3D::vector3 const &Angle );
|
||||
bool
|
||||
Render( TModel3d *Model, material_data const *Material, double const Squaredistance );
|
||||
void
|
||||
Render( TSubModel *Submodel );
|
||||
bool
|
||||
Render_Alpha( TDynamicObject *Dynamic );
|
||||
bool
|
||||
Render_Alpha( TModel3d *Model, material_data const *Material, Math3D::vector3 const &Position, Math3D::vector3 const &Angle );
|
||||
bool
|
||||
Render_Alpha( TModel3d *Model, material_data const *Material, double const Squaredistance );
|
||||
// geometry methods
|
||||
// NOTE: hands-on geometry management is exposed as a temporary measure; ultimately all visualization data should be generated/handled automatically by the renderer itself
|
||||
// creates a new geometry bank. returns: handle to the bank or NULL
|
||||
@@ -153,7 +138,7 @@ public:
|
||||
Vertices( geometry_handle const &Geometry ) const;
|
||||
// texture methods
|
||||
texture_handle
|
||||
GetTextureId( std::string Filename, std::string const &Dir, int const Filter = -1, bool const Loadnow = true );
|
||||
Fetch_Texture( std::string const &Filename, std::string const &Dir = szTexturePath, int const Filter = -1, bool const Loadnow = true );
|
||||
void
|
||||
Bind( texture_handle const Texture );
|
||||
opengl_texture const &
|
||||
@@ -225,6 +210,14 @@ private:
|
||||
Render( TSubRect *Groundsubcell );
|
||||
bool
|
||||
Render( TGroundNode *Node );
|
||||
bool
|
||||
Render( TDynamicObject *Dynamic );
|
||||
bool
|
||||
Render( TModel3d *Model, material_data const *Material, Math3D::vector3 const &Position, Math3D::vector3 const &Angle );
|
||||
bool
|
||||
Render( TModel3d *Model, material_data const *Material, double const Squaredistance );
|
||||
void
|
||||
Render( TSubModel *Submodel );
|
||||
void
|
||||
Render( TTrack *Track );
|
||||
bool
|
||||
@@ -237,6 +230,12 @@ private:
|
||||
Render_Alpha( TSubRect *Groundsubcell );
|
||||
bool
|
||||
Render_Alpha( TGroundNode *Node );
|
||||
bool
|
||||
Render_Alpha( TDynamicObject *Dynamic );
|
||||
bool
|
||||
Render_Alpha( TModel3d *Model, material_data const *Material, Math3D::vector3 const &Position, Math3D::vector3 const &Angle );
|
||||
bool
|
||||
Render_Alpha( TModel3d *Model, material_data const *Material, double const Squaredistance );
|
||||
void
|
||||
Render_Alpha( TSubModel *Submodel );
|
||||
void
|
||||
@@ -277,6 +276,7 @@ private:
|
||||
bool m_framebuffersupport { false };
|
||||
rendermode m_texenvmode { rendermode::color }; // last configured texture environment
|
||||
renderpass_config m_renderpass;
|
||||
// std::stack<renderpass_config> m_renderpasses;
|
||||
bool m_renderspecular { false }; // controls whether to include specular component in the calculations
|
||||
std::vector<TGroundNode const *> m_picksceneryitems;
|
||||
std::vector<TSubModel const *> m_pickcontrolsitems;
|
||||
|
||||
15
sky.cpp
15
sky.cpp
@@ -9,24 +9,22 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "sky.h"
|
||||
#include "Logs.h"
|
||||
#include "Globals.h"
|
||||
#include "MdlMngr.h"
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
GLfloat lightPos[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
//GLfloat lightPos[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
TSky::~TSky(){};
|
||||
void TSky::Init() {
|
||||
|
||||
TSky::TSky(){};
|
||||
if( ( Global::asSky != "1" )
|
||||
&& ( Global::asSky != "0" ) ) {
|
||||
|
||||
void TSky::Init()
|
||||
{
|
||||
WriteLog( "Clouds init" );
|
||||
if ((Global::asSky != "1") && (Global::asSky != "0"))
|
||||
mdCloud = TModelsManager::GetModel( Global::asSky );
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef EU07_USE_OLD_RENDERCODE
|
||||
void TSky::Render( glm::vec3 const &Tint )
|
||||
{
|
||||
if (mdCloud)
|
||||
@@ -45,5 +43,6 @@ void TSky::Render( glm::vec3 const &Tint )
|
||||
::glDisable( GL_LIGHTING );
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
16
sky.h
16
sky.h
@@ -12,16 +12,18 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include "Model3d.h"
|
||||
|
||||
class TSky
|
||||
{
|
||||
private:
|
||||
TModel3d *mdCloud;
|
||||
class TSky {
|
||||
|
||||
public:
|
||||
TSky();
|
||||
~TSky();
|
||||
friend class opengl_renderer;
|
||||
|
||||
private:
|
||||
TModel3d *mdCloud { nullptr };
|
||||
|
||||
public:
|
||||
void Init();
|
||||
#ifdef EU07_USE_OLD_RENDERCODE
|
||||
void Render( glm::vec3 const &Tint = glm::vec3(1.0f, 1.0f, 1.0f) );
|
||||
#endif
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "stars.h"
|
||||
#include "globals.h"
|
||||
#include "MdlMngr.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cStars -- simple starfield model, simulating appearance of starry sky
|
||||
@@ -9,9 +10,9 @@
|
||||
void
|
||||
cStars::init() {
|
||||
|
||||
m_stars.LoadFromFile( "models\\skydome_stars.t3d", false );
|
||||
m_stars = TModelsManager::GetModel( "models\\skydome_stars.t3d", false );
|
||||
}
|
||||
|
||||
#ifdef EU07_USE_OLD_RENDERCODE
|
||||
void
|
||||
cStars::render() {
|
||||
// setup
|
||||
@@ -27,4 +28,5 @@ cStars::render() {
|
||||
::glPointSize( 3.0f );
|
||||
|
||||
::glPopMatrix();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
9
stars.h
9
stars.h
@@ -8,13 +8,16 @@
|
||||
|
||||
class cStars {
|
||||
|
||||
friend class opengl_renderer;
|
||||
|
||||
public:
|
||||
// types:
|
||||
|
||||
// methods:
|
||||
void init();
|
||||
void render();
|
||||
|
||||
#ifdef EU07_USE_OLD_RENDERCODE
|
||||
void render();
|
||||
#endif
|
||||
// constructors:
|
||||
|
||||
// deconstructor:
|
||||
@@ -29,5 +32,5 @@ private:
|
||||
// members:
|
||||
float m_longitude{ 19.0f }; // geograpic coordinates hardcoded roughly to Poland location, for the time being
|
||||
float m_latitude{ 52.0f };
|
||||
TModel3d m_stars;
|
||||
TModel3d *m_stars { nullptr };
|
||||
};
|
||||
|
||||
2
stdafx.h
2
stdafx.h
@@ -91,4 +91,4 @@
|
||||
#include <glm/gtx/rotate_vector.hpp>
|
||||
#include <glm/gtx/norm.hpp>
|
||||
|
||||
#include "openglmatrixstack.h"
|
||||
#include "openglmatrixstack.h"
|
||||
|
||||
@@ -96,7 +96,7 @@ void
|
||||
ui_layer::set_background( std::string const &Filename ) {
|
||||
|
||||
if( false == Filename.empty() ) {
|
||||
m_background = GfxRenderer.GetTextureId( Filename, szTexturePath );
|
||||
m_background = GfxRenderer.Fetch_Texture( Filename );
|
||||
}
|
||||
else {
|
||||
m_background = NULL;
|
||||
|
||||
Reference in New Issue
Block a user