16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 16:19:19 +02:00

Merge remote-tracking branch 'refs/remotes/TMJ/mover_in_c++'

This commit is contained in:
Królik Uszasty
2017-07-31 17:32:23 +02:00
29 changed files with 995 additions and 326 deletions

View File

@@ -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

View File

@@ -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)
{

View File

@@ -14,13 +14,6 @@ http://mozilla.org/MPL/2.0/.
#include "Console.h"
#include "logs.h"
TButton::TButton()
{
iFeedbackBit = 0;
bData = NULL;
Clear();
};
void TButton::Clear(int i)
{
pModelOn = nullptr;

View File

@@ -36,7 +36,7 @@ class TButton
play( PSound Sound );
public:
TButton();
TButton() = default;
void Clear(int const i = -1);
inline void FeedbackBitSet(int const i) {
iFeedbackBit = 1 << i; };

View File

@@ -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
};

View File

@@ -139,8 +139,8 @@ TGauge::Load_mapping( cParser &Input ) {
}
else if( key.find( "sound" ) == 0 ) {
// sounds assigned to specific gauge values, defined by key soundFoo: where Foo = value
auto const indexstart = key.find_first_of( "1234567890" );
auto const indexend = key.find_first_not_of( "1234567890", indexstart );
auto const indexstart = key.find_first_of( "-1234567890" );
auto const indexend = key.find_first_not_of( "-1234567890", indexstart );
if( indexstart != std::string::npos ) {
m_soundfxvalues.emplace(
std::stoi( key.substr( indexstart, indexend - indexstart ) ),
@@ -180,18 +180,21 @@ void TGauge::DecValue(double fNewDesired)
void
TGauge::UpdateValue( double fNewDesired, PSound Fallbacksound ) {
if( static_cast<int>( std::round( ( fDesiredValue - fOffset ) / fScale ) ) == static_cast<int>( fNewDesired ) ) {
auto const desiredtimes100 = static_cast<int>( 100.0 * fNewDesired );
if( static_cast<int>( std::round( 100.0 * ( fDesiredValue - fOffset ) / fScale ) ) == desiredtimes100 ) {
return;
}
fDesiredValue = fNewDesired * fScale + fOffset;
// if there's any sound associated with new requested value, play it
// check value-specific table first...
auto const desiredvalue = static_cast<int>( std::round( fNewDesired ) );
auto const lookup = m_soundfxvalues.find( desiredvalue );
if( desiredtimes100 % 100 == 0 ) {
// filter out values other than full integers
auto const lookup = m_soundfxvalues.find( desiredtimes100 / 100 );
if( lookup != m_soundfxvalues.end() ) {
play( lookup->second );
return;
}
}
// ...and if there isn't any, fall back on the basic set...
auto const currentvalue = GetValue();
if( ( currentvalue < fNewDesired ) && ( m_soundfxincrease != nullptr ) ) {

View File

@@ -87,6 +87,8 @@ float Global::Overcast { 0.1f }; // NOTE: all this weather stuff should be moved
opengl_light Global::DayLight;
int Global::DynamicLightCount { 3 };
bool Global::ScaleSpecularValues { true };
bool Global::RenderShadows { false };
Global::shadowtune_t Global::shadowtune = { 2048, 200.0f, 150.0f, 100.0f };
bool Global::bRollFix = true; // czy wykonać przeliczanie przechyłki
bool Global::bJoinEvents = false; // czy grupować eventy o tych samych nazwach
int Global::iHiddenEvents = 1; // czy łączyć eventy z torami poprzez nazwę toru
@@ -544,6 +546,19 @@ void Global::ConfigParse(cParser &Parser)
Parser.getTokens();
Parser >> Global::ScaleSpecularValues;
}
else if( token == "shadows" ) {
// shadow render toggle
Parser.getTokens();
Parser >> Global::RenderShadows;
}
else if( token == "shadowtune" ) {
Parser.getTokens( 4, false );
Parser
>> Global::shadowtune.map_size
>> Global::shadowtune.width
>> Global::shadowtune.depth
>> Global::shadowtune.distance;
}
else if (token == "smoothtraction")
{
// podwójna jasność ambient

View File

@@ -226,6 +226,13 @@ class Global
static opengl_light DayLight;
static int DynamicLightCount;
static bool ScaleSpecularValues;
static bool RenderShadows;
static struct shadowtune_t {
unsigned int map_size;
float width;
float depth;
float distance;
} shadowtune;
static int iSlowMotion;
static TDynamicObject *changeDynObj;

View File

@@ -49,15 +49,6 @@ extern "C"
bool bCondition; // McZapkie: do testowania warunku na event multiple
std::string LogComment;
// tests whether provided points form a degenerate triangle
bool
degenerate( glm::dvec3 const &Vertex1, glm::dvec3 const &Vertex2, glm::dvec3 const &Vertex3 ) {
return ( ( Vertex1 == Vertex2 )
|| ( Vertex2 == Vertex3 )
|| ( Vertex3 == Vertex1 ) );
}
//---------------------------------------------------------------------------
// Obiekt renderujący siatkę jest sztucznie tworzonym obiektem pomocniczym,
// grupującym siatki obiektów dla danej tekstury. Obiektami składowymi mogą
@@ -1330,7 +1321,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 :

View File

@@ -98,6 +98,11 @@ std::string to_string( glm::tvec3<Type_, Precision_> const &Value ) {
return to_string( Value.x, 2 ) + ", " + to_string( Value.y, 2 ) + ", " + to_string( Value.z, 2 );
}
template <typename Type_, glm::precision Precision_ = glm::defaultp>
std::string to_string( glm::tvec4<Type_, Precision_> const &Value, int const Width = 2 ) {
return to_string( Value.x, Width ) + ", " + to_string( Value.y, Width ) + ", " + to_string( Value.z, Width ) + ", " + to_string( Value.w, Width );
}
int stol_def(const std::string & str, const int & DefaultValue);
std::string ToLower(std::string const &text);

View File

@@ -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ść
@@ -460,10 +460,8 @@ int TSubModel::Load( cParser &parser, TModel3d *Model, /*int Pos,*/ bool dynamic
>> Vertices[i].texture.t;
if (i % 3 == 2) {
// jeżeli wczytano 3 punkty
if (Vertices[i ].position == Vertices[i - 1].position
|| Vertices[i - 1].position == Vertices[i - 2].position
|| Vertices[i - 2].position == Vertices[i ].position)
{ // jeżeli punkty się nakładają na siebie
if( true == degenerate( Vertices[ i ].position, Vertices[ i - 1 ].position, Vertices[ i - 2 ].position ) ) {
// jeżeli punkty się nakładają na siebie
--facecount; // o jeden trójkąt mniej
iNumVerts -= 3; // czyli o 3 wierzchołki
i -= 3; // wczytanie kolejnego w to miejsce
@@ -1670,7 +1668,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 |=

View File

@@ -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)
@@ -1267,31 +1267,32 @@ void TTrack::create_geometry( geometrybank_handle const &Bank ) {
}
vertex_array vertices;
Segment->RenderLoft(vertices, origin, bpts1, iTrapezoid ? -4 : 4, fTexLength);
if( ( Bank != 0 ) && ( true == Geometry2.empty() ) ) {
Geometry2.emplace_back( GfxRenderer.Insert( vertices, Bank, GL_TRIANGLE_STRIP ) );
}
if( ( Bank == 0 ) && ( false == Geometry2.empty() ) ) {
// special variant, replace existing data for a turntable track
GfxRenderer.Replace( vertices, Geometry2[ 0 ] );
}
else {
Geometry2.emplace_back( GfxRenderer.Insert( vertices, Bank, GL_TRIANGLE_STRIP ) );
}
}
if (TextureID1)
{ // szyny - generujemy dwie, najwyżej rysować się będzie jedną
vertex_array vertices;
if( ( Bank != 0 ) && ( true == Geometry1.empty() ) ) {
Segment->RenderLoft( vertices, origin, rpts1, iTrapezoid ? -nnumPts : nnumPts, fTexLength );
Geometry1.emplace_back( GfxRenderer.Insert( vertices, Bank, GL_TRIANGLE_STRIP ) );
vertices.clear(); // reuse the scratchpad
Segment->RenderLoft( vertices, origin, rpts2, iTrapezoid ? -nnumPts : nnumPts, fTexLength );
Geometry1.emplace_back( GfxRenderer.Insert( vertices, Bank, GL_TRIANGLE_STRIP ) );
}
if( ( Bank == 0 ) && ( false == Geometry1.empty() ) ) {
// special variant, replace existing data for a turntable track
Segment->RenderLoft( vertices, origin, rpts1, iTrapezoid ? -nnumPts : nnumPts, fTexLength );
GfxRenderer.Replace( vertices, Geometry1[ 0 ] );
vertices.clear(); // reuse the scratchpad
Segment->RenderLoft( vertices, origin, rpts2, iTrapezoid ? -nnumPts : nnumPts, fTexLength );
GfxRenderer.Replace( vertices, Geometry1[ 1 ] );
}
else {
Segment->RenderLoft( vertices, origin, rpts1, iTrapezoid ? -nnumPts : nnumPts, fTexLength );
Geometry1.emplace_back( GfxRenderer.Insert( vertices, Bank, GL_TRIANGLE_STRIP ) );
vertices.clear(); // reuse the scratchpad
Segment->RenderLoft( vertices, origin, rpts2, iTrapezoid ? -nnumPts : nnumPts, fTexLength );
Geometry1.emplace_back( GfxRenderer.Insert( vertices, Bank, GL_TRIANGLE_STRIP ) );
}
}
break;
case tt_Switch: // dla zwrotnicy dwa razy szyny
@@ -1865,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 ) {

View File

@@ -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) {

View File

@@ -32,6 +32,8 @@ http://mozilla.org/MPL/2.0/.
#include "uilayer.h"
#include "translation.h"
//#define EU07_USE_DEBUG_SHADOWMAP
//---------------------------------------------------------------------------
TDynamicObject *Controlled = NULL; // pojazd, który prowadzimy
@@ -632,8 +634,13 @@ void TWorld::OnKeyDown(int cKey)
break;
}
case GLFW_KEY_F8: {
#ifdef EU07_USE_DEBUG_SHADOWMAP
if( Global::iTextMode == cKey ) { ++Global::iScreenMode[ cKey - GLFW_KEY_F1 ]; }
if( Global::iScreenMode[ cKey - GLFW_KEY_F1 ] > 1 ) {
Global::iScreenMode[ cKey - GLFW_KEY_F1 ] = 0;
}
#endif
Global::iTextMode = cKey;
// FPS
break;
}
case GLFW_KEY_F9: {
@@ -956,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
@@ -1696,7 +1701,7 @@ TWorld::Update_UI() {
std::to_string( int( tmp->MoverParameters->Im ) ) )
+ "; U=" + to_string( int( tmp->MoverParameters->RunningTraction.TractionVoltage + 0.5 ) )
+ "; R=" +
( tmp->MoverParameters->RunningShape.R > 100000.0 ?
( std::abs( tmp->MoverParameters->RunningShape.R ) > 10000.0 ?
"~0.0" :
to_string( tmp->MoverParameters->RunningShape.R, 1 ) )
+ " An=" + to_string( tmp->MoverParameters->AccN, 2 ); // przyspieszenie poprzeczne

View File

@@ -125,9 +125,11 @@ mouse_input::button( int const Button, int const Action ) {
// TODO: pass correct entity id once the missing systems are in place
m_relay.post( mousecommand, 0, 0, Action, 0 );
m_updateaccumulator = 0.0; // prevent potential command repeat right after issuing one
/*
if( mousecommand == user_command::mastercontrollerincrease ) {
m_updateaccumulator -= 0.15; // extra pause on first increase of master controller
}
*/
switch( mousecommand ) {
case user_command::mastercontrollerincrease:
case user_command::mastercontrollerdecrease:

View File

@@ -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

View File

@@ -44,6 +44,11 @@ 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 {
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
@@ -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,7 +191,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_();
@@ -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

View File

@@ -55,6 +55,10 @@ public:
multiply( glm::mat4 const &Matrix ) {
m_stack.top() *= Matrix;
upload(); }
void
ortho( float const Left, float const Right, float const Bottom, float const Top, float const Znear, float const Zfar ) {
m_stack.top() *= glm::ortho( Left, Right, Bottom, Top, Znear, Zfar );
upload(); }
void
perspective( float const Fovy, float const Aspect, float const Znear, float const Zfar ) {
m_stack.top() *= glm::perspective( Fovy, Aspect, Znear, Zfar );
@@ -132,10 +136,20 @@ public:
m_stacks[ m_mode ].multiply(
glm::make_mat4( Matrix ) ); }
template <typename Type_>
void
ortho( Type_ const Left, Type_ const Right, Type_ const Bottom, Type_ const Top, Type_ const Znear, Type_ const Zfar ) {
m_stacks[ m_mode ].ortho(
static_cast<float>( Left ),
static_cast<float>( Right ),
static_cast<float>( Bottom ),
static_cast<float>( Top ),
static_cast<float>( Znear ),
static_cast<float>( Zfar ) ); }
template <typename Type_>
void
perspective( Type_ const Fovy, Type_ const Aspect, Type_ const Znear, Type_ const Zfar ) {
m_stacks[ m_mode ].perspective(
static_cast<float>(Fovy) * 0.0174532925f, // deg2rad
static_cast<float>( glm::radians( Fovy ) ),
static_cast<float>( Aspect ),
static_cast<float>( Znear ),
static_cast<float>( Zfar ) ); }
@@ -177,6 +191,7 @@ extern opengl_matrices OpenGLMatrices;
// NOTE: no scale override as we aren't using it anywhere
#define glMultMatrixd OpenGLMatrices.multiply
#define glMultMatrixf OpenGLMatrices.multiply
#define glOrtho OpenGLMatrices.ortho
#define gluPerspective OpenGLMatrices.perspective
#define gluLookAt OpenGLMatrices.look_at

File diff suppressed because it is too large Load Diff

View File

@@ -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 &
@@ -174,7 +159,7 @@ public:
TGroundNode const *
Update_Pick_Node();
// debug performance string
std::string const &
std::string
Info() const;
// members
@@ -184,6 +169,7 @@ public:
private:
// types
enum class rendermode {
none,
color,
shadows,
pickcontrols,
@@ -209,12 +195,30 @@ private:
Render_pass( rendermode const Mode );
// configures projection matrix for the current render pass
void
Render_projection();
setup_projection();
void
setup_projection_world();
void
setup_projection_light_ortho();
void
setup_projection_light_perspective();
// configures camera for the current render pass
void
Render_camera();
setup_camera();
void
Render_setup( bool const Alpha = false );
setup_camera_world( glm::dmat4 &Viewmatrix );
void
setup_camera_light_ortho( glm::dmat4 &Viewmatrix );
void
setup_camera_light_perspective( glm::dmat4 &Viewmatrix );
void
setup_drawing( bool const Alpha = false );
void
setup_units( bool const Diffuse, bool const Shadows, bool const Reflections );
void
setup_shadow_color( glm::vec4 const &Shadowcolor );
void
toggle_units( bool const Diffuse, bool const Shadows, bool const Reflections );
bool
Render( world_environment *Environment );
bool
@@ -225,6 +229,14 @@ private:
Render( TSubRect *Groundsubcell );
bool
Render( TGroundNode *Node );
bool
Render( TDynamicObject *Dynamic );
bool
Render( TModel3d *Model, material_data const *Material, double const Squaredistance, 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 +249,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, double const Squaredistance, 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
@@ -254,13 +272,23 @@ private:
GLuint m_pickframebuffer { 0 }; // TODO: refactor pick framebuffer stuff into an object
GLuint m_picktexture { 0 };
GLuint m_pickdepthbuffer { 0 };
int m_pickbuffersize { 1024 }; // size of (square) textures bound with the pick framebuffer
#endif
GLuint m_shadowframebuffer { 0 };
GLuint m_shadowtexture { 0 };
int m_shadowbuffersize { 4096 };
glm::mat4 m_shadowtexturematrix;
glm::vec4 m_shadowcolor{ 0.5f, 0.5f, 0.5f, 1.f };
GLUquadricObj *m_quadric { nullptr }; // helper object for drawing debug mode scene elements
int m_shadowtextureunit { GL_TEXTURE1 };
int m_helpertextureunit { GL_TEXTURE0 };
int m_diffusetextureunit { GL_TEXTURE2 };
geometry_handle m_billboardgeometry { 0, 0 };
texture_handle m_glaretexture { -1 };
texture_handle m_suntexture { -1 };
texture_handle m_moontexture { -1 };
texture_handle m_reflectiontexture { -1 };
float m_drawtime { 1000.0f / 30.0f * 20.0f }; // start with presumed 'neutral' average of 30 fps
double m_updateaccumulator { 0.0 };
@@ -271,7 +299,6 @@ private:
float m_speculartranslucentscalefactor { 1.0f };
bool m_framebuffersupport { false };
rendermode m_texenvmode { rendermode::color }; // last configured texture environment
renderpass_config m_renderpass;
bool m_renderspecular { false }; // controls whether to include specular component in the calculations
std::vector<TGroundNode const *> m_picksceneryitems;

15
sky.cpp
View File

@@ -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
//---------------------------------------------------------------------------

12
sky.h
View File

@@ -12,16 +12,18 @@ http://mozilla.org/MPL/2.0/.
#include "Model3d.h"
class TSky
{
class TSky {
friend class opengl_renderer;
private:
TModel3d *mdCloud;
TModel3d *mdCloud { nullptr };
public:
TSky();
~TSky();
void Init();
#ifdef EU07_USE_OLD_RENDERCODE
void Render( glm::vec3 const &Tint = glm::vec3(1.0f, 1.0f, 1.0f) );
#endif
};
//---------------------------------------------------------------------------

View File

@@ -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
@@ -28,3 +29,4 @@ cStars::render() {
::glPopMatrix();
}
#endif

View File

@@ -8,13 +8,16 @@
class cStars {
friend class opengl_renderer;
public:
// types:
// methods:
void init();
#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 };
};

View File

@@ -65,7 +65,7 @@ ui_layer::render() {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho( 0.f, Global::ScreenWidth, Global::ScreenHeight, 0.f, -1.f, 1.f );
glOrtho( 0, std::max( 1, Global::ScreenWidth ), std::max( 1, Global::ScreenHeight ), 0, -1, 1 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@@ -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;
@@ -272,10 +272,10 @@ ui_layer::quad( float4 const &Coordinates, float4 const &Color ) {
glBegin( GL_TRIANGLE_STRIP );
glTexCoord2f( 0.f, 1.f ); glVertex2f( 0.5f * ( Global::iWindowWidth - width ) + Coordinates.x * heightratio, 0.5f * ( Global::iWindowHeight - height ) + Coordinates.y * heightratio );
glTexCoord2f( 0.f, 0.f ); glVertex2f( 0.5f * ( Global::iWindowWidth - width ) + Coordinates.x * heightratio, 0.5f * ( Global::iWindowHeight - height ) + Coordinates.w * heightratio );
glTexCoord2f( 1.f, 1.f ); glVertex2f( 0.5f * ( Global::iWindowWidth - width ) + Coordinates.z * heightratio, 0.5f * ( Global::iWindowHeight - height ) + Coordinates.y * heightratio );
glTexCoord2f( 1.f, 0.f ); glVertex2f( 0.5f * ( Global::iWindowWidth - width ) + Coordinates.z * heightratio, 0.5f * ( Global::iWindowHeight - height ) + Coordinates.w * heightratio );
glMultiTexCoord2f( m_textureunit, 0.f, 1.f ); glVertex2f( 0.5f * ( Global::iWindowWidth - width ) + Coordinates.x * heightratio, 0.5f * ( Global::iWindowHeight - height ) + Coordinates.y * heightratio );
glMultiTexCoord2f( m_textureunit, 0.f, 0.f ); glVertex2f( 0.5f * ( Global::iWindowWidth - width ) + Coordinates.x * heightratio, 0.5f * ( Global::iWindowHeight - height ) + Coordinates.w * heightratio );
glMultiTexCoord2f( m_textureunit, 1.f, 1.f ); glVertex2f( 0.5f * ( Global::iWindowWidth - width ) + Coordinates.z * heightratio, 0.5f * ( Global::iWindowHeight - height ) + Coordinates.y * heightratio );
glMultiTexCoord2f( m_textureunit, 1.f, 0.f ); glVertex2f( 0.5f * ( Global::iWindowWidth - width ) + Coordinates.z * heightratio, 0.5f * ( Global::iWindowHeight - height ) + Coordinates.w * heightratio );
glEnd();
}

View File

@@ -41,6 +41,8 @@ public:
// methods:
bool
init( GLFWwindow *Window );
void
set_unit( GLint const Textureunit ) { m_textureunit = Textureunit; }
// draws requested UI elements
void
render();
@@ -83,6 +85,7 @@ private:
// members:
GLFWwindow *m_window { nullptr };
GLint m_textureunit{ GL_TEXTURE0 };
GLuint m_fontbase { (GLuint)-1 }; // numer DL dla znaków w napisach
// progress bar config. TODO: put these together into an object

View File

@@ -71,4 +71,13 @@ interpolate( Type_ const &First, Type_ const &Second, double const Factor ) {
return ( First * ( 1.0 - Factor ) ) + ( Second * Factor );
}
// tests whether provided points form a degenerate triangle
template <typename VecType_>
bool
degenerate( VecType_ const &Vertex1, VecType_ const &Vertex2, VecType_ const &Vertex3 ) {
// 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<VecType_::value_type>::epsilon();
}
//---------------------------------------------------------------------------

View File

@@ -1,5 +1,5 @@
#pragma once
#define VERSION_MAJOR 17
#define VERSION_MINOR 715
#define VERSION_MINOR 725
#define VERSION_REVISION 0