mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-23 23:49:17 +02:00
removed direct texture binding. binding is now done through texture manager
This commit is contained in:
@@ -449,9 +449,9 @@ bool TAnimModel::Init(std::string const &asName, std::string const &asReplacable
|
|||||||
asText = asReplacableTexture.substr(1, asReplacableTexture.length() - 1); // zapamiętanie tekstu
|
asText = asReplacableTexture.substr(1, asReplacableTexture.length() - 1); // zapamiętanie tekstu
|
||||||
else if (asReplacableTexture != "none")
|
else if (asReplacableTexture != "none")
|
||||||
ReplacableSkinId[1] =
|
ReplacableSkinId[1] =
|
||||||
TTexturesManager.GetTextureId( asReplacableTexture, "" );
|
TextureManager.GetTextureId( asReplacableTexture, "" );
|
||||||
if( ( ReplacableSkinId[ 1 ] != 0 )
|
if( ( ReplacableSkinId[ 1 ] != 0 )
|
||||||
&& ( TTexturesManager.Texture( ReplacableSkinId[ 1 ] ).has_alpha ) ) {
|
&& ( TextureManager.Texture( ReplacableSkinId[ 1 ] ).has_alpha ) ) {
|
||||||
// tekstura z kanałem alfa - nie renderować w cyklu nieprzezroczystych
|
// tekstura z kanałem alfa - nie renderować w cyklu nieprzezroczystych
|
||||||
iTexAlpha = 0x31310031;
|
iTexAlpha = 0x31310031;
|
||||||
}
|
}
|
||||||
|
|||||||
32
DynObj.cpp
32
DynObj.cpp
@@ -4417,7 +4417,7 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
|
|||||||
Global::asCurrentTexturePath + ReplacableSkin; // skory tez z dynamic/...
|
Global::asCurrentTexturePath + ReplacableSkin; // skory tez z dynamic/...
|
||||||
std::string x = TextureTest(Global::asCurrentTexturePath + "nowhere"); // na razie prymitywnie
|
std::string x = TextureTest(Global::asCurrentTexturePath + "nowhere"); // na razie prymitywnie
|
||||||
if (!x.empty())
|
if (!x.empty())
|
||||||
ReplacableSkinID[4] = TTexturesManager.GetTextureId( Global::asCurrentTexturePath + "nowhere", "", 9);
|
ReplacableSkinID[4] = TextureManager.GetTextureId( Global::asCurrentTexturePath + "nowhere", "", 9);
|
||||||
/*
|
/*
|
||||||
if ((i = ReplacableSkin.Pos("|")) > 0) // replacable dzielone
|
if ((i = ReplacableSkin.Pos("|")) > 0) // replacable dzielone
|
||||||
{
|
{
|
||||||
@@ -4480,21 +4480,21 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
|
|||||||
*/
|
*/
|
||||||
if (iMultiTex > 0)
|
if (iMultiTex > 0)
|
||||||
{ // jeśli model ma 4 tekstury
|
{ // jeśli model ma 4 tekstury
|
||||||
ReplacableSkinID[1] = TTexturesManager.GetTextureId(
|
ReplacableSkinID[1] = TextureManager.GetTextureId(
|
||||||
ReplacableSkin + ",1", "", Global::iDynamicFiltering);
|
ReplacableSkin + ",1", "", Global::iDynamicFiltering);
|
||||||
if (ReplacableSkinID[1])
|
if (ReplacableSkinID[1])
|
||||||
{ // pierwsza z zestawu znaleziona
|
{ // pierwsza z zestawu znaleziona
|
||||||
ReplacableSkinID[2] = TTexturesManager.GetTextureId(
|
ReplacableSkinID[2] = TextureManager.GetTextureId(
|
||||||
ReplacableSkin + ",2", "", Global::iDynamicFiltering);
|
ReplacableSkin + ",2", "", Global::iDynamicFiltering);
|
||||||
if (ReplacableSkinID[2])
|
if (ReplacableSkinID[2])
|
||||||
{
|
{
|
||||||
iMultiTex = 2; // już są dwie
|
iMultiTex = 2; // już są dwie
|
||||||
ReplacableSkinID[3] = TTexturesManager.GetTextureId(
|
ReplacableSkinID[3] = TextureManager.GetTextureId(
|
||||||
ReplacableSkin + ",3", "", Global::iDynamicFiltering);
|
ReplacableSkin + ",3", "", Global::iDynamicFiltering);
|
||||||
if (ReplacableSkinID[3])
|
if (ReplacableSkinID[3])
|
||||||
{
|
{
|
||||||
iMultiTex = 3; // a teraz nawet trzy
|
iMultiTex = 3; // a teraz nawet trzy
|
||||||
ReplacableSkinID[4] = TTexturesManager.GetTextureId(
|
ReplacableSkinID[4] = TextureManager.GetTextureId(
|
||||||
ReplacableSkin + ",4", "", Global::iDynamicFiltering);
|
ReplacableSkin + ",4", "", Global::iDynamicFiltering);
|
||||||
if (ReplacableSkinID[4])
|
if (ReplacableSkinID[4])
|
||||||
iMultiTex = 4; // jak są cztery, to blokujemy podmianę tekstury
|
iMultiTex = 4; // jak są cztery, to blokujemy podmianę tekstury
|
||||||
@@ -4505,14 +4505,14 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
|
|||||||
else
|
else
|
||||||
{ // zestaw nie zadziałał, próbujemy normanie
|
{ // zestaw nie zadziałał, próbujemy normanie
|
||||||
iMultiTex = 0;
|
iMultiTex = 0;
|
||||||
ReplacableSkinID[1] = TTexturesManager.GetTextureId(
|
ReplacableSkinID[1] = TextureManager.GetTextureId(
|
||||||
ReplacableSkin, "", Global::iDynamicFiltering);
|
ReplacableSkin, "", Global::iDynamicFiltering);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ReplacableSkinID[1] = TTexturesManager.GetTextureId(
|
ReplacableSkinID[1] = TextureManager.GetTextureId(
|
||||||
ReplacableSkin, "", Global::iDynamicFiltering);
|
ReplacableSkin, "", Global::iDynamicFiltering);
|
||||||
if (TTexturesManager.Texture(ReplacableSkinID[1]).has_alpha)
|
if (TextureManager.Texture(ReplacableSkinID[1]).has_alpha)
|
||||||
iAlpha = 0x31310031; // tekstura -1 z kanałem alfa - nie renderować w cyklu
|
iAlpha = 0x31310031; // tekstura -1 z kanałem alfa - nie renderować w cyklu
|
||||||
// nieprzezroczystych
|
// nieprzezroczystych
|
||||||
else
|
else
|
||||||
@@ -4520,17 +4520,17 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
|
|||||||
// renderować w
|
// renderować w
|
||||||
// cyklu przezroczystych
|
// cyklu przezroczystych
|
||||||
if (ReplacableSkinID[2])
|
if (ReplacableSkinID[2])
|
||||||
if (TTexturesManager.Texture(ReplacableSkinID[2]).has_alpha)
|
if (TextureManager.Texture(ReplacableSkinID[2]).has_alpha)
|
||||||
iAlpha |= 0x02020002; // tekstura -2 z kanałem alfa - nie renderować
|
iAlpha |= 0x02020002; // tekstura -2 z kanałem alfa - nie renderować
|
||||||
// w cyklu
|
// w cyklu
|
||||||
// nieprzezroczystych
|
// nieprzezroczystych
|
||||||
if (ReplacableSkinID[3])
|
if (ReplacableSkinID[3])
|
||||||
if (TTexturesManager.Texture(ReplacableSkinID[3]).has_alpha)
|
if (TextureManager.Texture(ReplacableSkinID[3]).has_alpha)
|
||||||
iAlpha |= 0x04040004; // tekstura -3 z kanałem alfa - nie renderować
|
iAlpha |= 0x04040004; // tekstura -3 z kanałem alfa - nie renderować
|
||||||
// w cyklu
|
// w cyklu
|
||||||
// nieprzezroczystych
|
// nieprzezroczystych
|
||||||
if (ReplacableSkinID[4])
|
if (ReplacableSkinID[4])
|
||||||
if (TTexturesManager.Texture(ReplacableSkinID[4]).has_alpha)
|
if (TextureManager.Texture(ReplacableSkinID[4]).has_alpha)
|
||||||
iAlpha |= 0x08080008; // tekstura -4 z kanałem alfa - nie renderować
|
iAlpha |= 0x08080008; // tekstura -4 z kanałem alfa - nie renderować
|
||||||
// w cyklu
|
// w cyklu
|
||||||
// nieprzezroczystych
|
// nieprzezroczystych
|
||||||
@@ -5849,13 +5849,13 @@ void TDynamicObject::DestinationSet(std::string to, std::string numer)
|
|||||||
std::string x = TextureTest(asBaseDir + numer + "@" + MoverParameters->TypeName);
|
std::string x = TextureTest(asBaseDir + numer + "@" + MoverParameters->TypeName);
|
||||||
if (!x.empty())
|
if (!x.empty())
|
||||||
{
|
{
|
||||||
ReplacableSkinID[4] = TTexturesManager.GetTextureId( x, "", 9); // rozmywania 0,1,4,5 nie nadają się
|
ReplacableSkinID[4] = TextureManager.GetTextureId( x, "", 9); // rozmywania 0,1,4,5 nie nadają się
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
x = TextureTest(asBaseDir + numer );
|
x = TextureTest(asBaseDir + numer );
|
||||||
if (!x.empty())
|
if (!x.empty())
|
||||||
{
|
{
|
||||||
ReplacableSkinID[4] = TTexturesManager.GetTextureId( x, "", 9); // rozmywania 0,1,4,5 nie nadają się
|
ReplacableSkinID[4] = TextureManager.GetTextureId( x, "", 9); // rozmywania 0,1,4,5 nie nadają się
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (to.empty())
|
if (to.empty())
|
||||||
@@ -5863,17 +5863,17 @@ void TDynamicObject::DestinationSet(std::string to, std::string numer)
|
|||||||
x = TextureTest(asBaseDir + to + "@" + MoverParameters->TypeName); // w pierwszej kolejności z nazwą FIZ/MMD
|
x = TextureTest(asBaseDir + to + "@" + MoverParameters->TypeName); // w pierwszej kolejności z nazwą FIZ/MMD
|
||||||
if (!x.empty())
|
if (!x.empty())
|
||||||
{
|
{
|
||||||
ReplacableSkinID[4] = TTexturesManager.GetTextureId( x, "", 9); // rozmywania 0,1,4,5 nie nadają się
|
ReplacableSkinID[4] = TextureManager.GetTextureId( x, "", 9); // rozmywania 0,1,4,5 nie nadają się
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
x = TextureTest(asBaseDir + to); // na razie prymitywnie
|
x = TextureTest(asBaseDir + to); // na razie prymitywnie
|
||||||
if (!x.empty())
|
if (!x.empty())
|
||||||
ReplacableSkinID[4] = TTexturesManager.GetTextureId( x, "", 9); // rozmywania 0,1,4,5 nie nadają się
|
ReplacableSkinID[4] = TextureManager.GetTextureId( x, "", 9); // rozmywania 0,1,4,5 nie nadają się
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
x = TextureTest(asBaseDir + "nowhere"); // jak nie znalazł dedykowanej, to niech daje nowhere
|
x = TextureTest(asBaseDir + "nowhere"); // jak nie znalazł dedykowanej, to niech daje nowhere
|
||||||
if (!x.empty())
|
if (!x.empty())
|
||||||
ReplacableSkinID[4] = TTexturesManager.GetTextureId( x, "", 9);
|
ReplacableSkinID[4] = TextureManager.GetTextureId( x, "", 9);
|
||||||
}
|
}
|
||||||
// Ra 2015-01: żeby zalogować błąd, trzeba by mieć pewność, że model używa
|
// Ra 2015-01: żeby zalogować błąd, trzeba by mieć pewność, że model używa
|
||||||
// tekstury nr 4
|
// tekstury nr 4
|
||||||
|
|||||||
12
Ground.cpp
12
Ground.cpp
@@ -276,7 +276,7 @@ void TGroundNode::RaRenderVBO()
|
|||||||
{ // renderowanie z domyslnego bufora VBO
|
{ // renderowanie z domyslnego bufora VBO
|
||||||
glColor3ub(Diffuse[0], Diffuse[1], Diffuse[2]);
|
glColor3ub(Diffuse[0], Diffuse[1], Diffuse[2]);
|
||||||
if (TextureID)
|
if (TextureID)
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID); // Ustaw aktywną teksturę
|
TextureManager.Bind(TextureID); // Ustaw aktywną teksturę
|
||||||
glDrawArrays(iType, iVboPtr, iNumVerts); // Narysuj naraz wszystkie trójkąty
|
glDrawArrays(iType, iVboPtr, iNumVerts); // Narysuj naraz wszystkie trójkąty
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,7 +445,7 @@ void TGroundNode::Compile(bool many)
|
|||||||
#ifdef USE_VERTEX_ARRAYS
|
#ifdef USE_VERTEX_ARRAYS
|
||||||
glVertexPointer(3, GL_DOUBLE, sizeof(vector3), &Points[0].x);
|
glVertexPointer(3, GL_DOUBLE, sizeof(vector3), &Points[0].x);
|
||||||
#endif
|
#endif
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
TextureManager.Bind(0);
|
||||||
#ifdef USE_VERTEX_ARRAYS
|
#ifdef USE_VERTEX_ARRAYS
|
||||||
glDrawArrays(iType, 0, iNumPts);
|
glDrawArrays(iType, 0, iNumPts);
|
||||||
#else
|
#else
|
||||||
@@ -466,7 +466,7 @@ void TGroundNode::Compile(bool many)
|
|||||||
glTexCoordPointer(2, GL_FLOAT, sizeof(TGroundVertex), &tri->Vertices[0].tu);
|
glTexCoordPointer(2, GL_FLOAT, sizeof(TGroundVertex), &tri->Vertices[0].tu);
|
||||||
#endif
|
#endif
|
||||||
glColor3ub(tri->Diffuse[0], tri->Diffuse[1], tri->Diffuse[2]);
|
glColor3ub(tri->Diffuse[0], tri->Diffuse[1], tri->Diffuse[2]);
|
||||||
glBindTexture(GL_TEXTURE_2D, Global::bWireFrame ? 0 : tri->TextureID);
|
TextureManager.Bind(Global::bWireFrame ? 0 : tri->TextureID);
|
||||||
#ifdef USE_VERTEX_ARRAYS
|
#ifdef USE_VERTEX_ARRAYS
|
||||||
glDrawArrays(Global::bWireFrame ? GL_LINE_LOOP : tri->iType, 0, tri->iNumVerts);
|
glDrawArrays(Global::bWireFrame ? GL_LINE_LOOP : tri->iType, 0, tri->iNumVerts);
|
||||||
#else
|
#else
|
||||||
@@ -494,7 +494,7 @@ void TGroundNode::Compile(bool many)
|
|||||||
else if (iType == TP_MESH)
|
else if (iType == TP_MESH)
|
||||||
{ // grupa ze wspólną teksturą - wrzucanie do wspólnego Display List
|
{ // grupa ze wspólną teksturą - wrzucanie do wspólnego Display List
|
||||||
if (TextureID)
|
if (TextureID)
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID); // Ustaw aktywną teksturę
|
TextureManager.Bind(TextureID); // Ustaw aktywną teksturę
|
||||||
TGroundNode *n = nNode;
|
TGroundNode *n = nNode;
|
||||||
while (n ? n->TextureID == TextureID : false)
|
while (n ? n->TextureID == TextureID : false)
|
||||||
{ // wszystkie obiekty o tej samej testurze
|
{ // wszystkie obiekty o tej samej testurze
|
||||||
@@ -2109,8 +2109,8 @@ TGroundNode * TGround::AddGroundNode(cParser *parser)
|
|||||||
tmp->PROBLEND = false;
|
tmp->PROBLEND = false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
tmp->TextureID = TTexturesManager.GetTextureId( str, szTexturePath );
|
tmp->TextureID = TextureManager.GetTextureId( str, szTexturePath );
|
||||||
tmp->iFlags = TTexturesManager.Texture(tmp->TextureID).has_alpha ? 0x220 : 0x210; // z usuwaniem
|
tmp->iFlags = TextureManager.Texture(tmp->TextureID).has_alpha ? 0x220 : 0x210; // z usuwaniem
|
||||||
if (((tmp->iType == GL_TRIANGLES) && (tmp->iFlags & 0x10)) ?
|
if (((tmp->iType == GL_TRIANGLES) && (tmp->iFlags & 0x10)) ?
|
||||||
Global::pTerrainCompact->TerrainLoaded() :
|
Global::pTerrainCompact->TerrainLoaded() :
|
||||||
false)
|
false)
|
||||||
|
|||||||
52
Model3d.cpp
52
Model3d.cpp
@@ -28,7 +28,7 @@ using namespace Mtable;
|
|||||||
|
|
||||||
double TSubModel::fSquareDist = 0;
|
double TSubModel::fSquareDist = 0;
|
||||||
int TSubModel::iInstance; // numer renderowanego egzemplarza obiektu
|
int TSubModel::iInstance; // numer renderowanego egzemplarza obiektu
|
||||||
GLuint *TSubModel::ReplacableSkinId = NULL;
|
texture_manager::size_type *TSubModel::ReplacableSkinId = NULL;
|
||||||
int TSubModel::iAlpha = 0x30300030; // maska do testowania flag tekstur wymiennych
|
int TSubModel::iAlpha = 0x30300030; // maska do testowania flag tekstur wymiennych
|
||||||
TModel3d *TSubModel::pRoot; // Ra: tymczasowo wskaźnik na model widoczny z submodelu
|
TModel3d *TSubModel::pRoot; // Ra: tymczasowo wskaźnik na model widoczny z submodelu
|
||||||
std::string *TSubModel::pasText;
|
std::string *TSubModel::pasText;
|
||||||
@@ -411,12 +411,12 @@ int TSubModel::Load(cParser &parser, TModel3d *Model, int Pos, bool dynamic)
|
|||||||
TextureNameSet(texture.c_str());
|
TextureNameSet(texture.c_str());
|
||||||
if (texture.find_first_of("/\\") == texture.npos)
|
if (texture.find_first_of("/\\") == texture.npos)
|
||||||
texture.insert(0, Global::asCurrentTexturePath.c_str());
|
texture.insert(0, Global::asCurrentTexturePath.c_str());
|
||||||
TextureID = TTexturesManager.GetTextureId( texture, szTexturePath );
|
TextureID = TextureManager.GetTextureId( texture, szTexturePath );
|
||||||
// TexAlpha=TTexturesManager::GetAlpha(TextureID);
|
// TexAlpha=TTexturesManager::GetAlpha(TextureID);
|
||||||
// iFlags|=TexAlpha?0x20:0x10; //0x10-nieprzezroczysta, 0x20-przezroczysta
|
// iFlags|=TexAlpha?0x20:0x10; //0x10-nieprzezroczysta, 0x20-przezroczysta
|
||||||
if (Opacity < 1.0) // przezroczystość z tekstury brana tylko dla Opacity
|
if (Opacity < 1.0) // przezroczystość z tekstury brana tylko dla Opacity
|
||||||
// 0!
|
// 0!
|
||||||
iFlags |= TTexturesManager.Texture(TextureID).has_alpha ?
|
iFlags |= TextureManager.Texture(TextureID).has_alpha ?
|
||||||
0x20 :
|
0x20 :
|
||||||
0x10; // 0x10-nieprzezroczysta, 0x20-przezroczysta
|
0x10; // 0x10-nieprzezroczysta, 0x20-przezroczysta
|
||||||
else
|
else
|
||||||
@@ -636,7 +636,7 @@ int TSubModel::TriangleAdd(TModel3d *m, texture_manager::size_type tex, int tri)
|
|||||||
m->AddTo(this, s);
|
m->AddTo(this, s);
|
||||||
}
|
}
|
||||||
// s->asTexture=AnsiString(TTexturesManager::GetName(tex).c_str());
|
// s->asTexture=AnsiString(TTexturesManager::GetName(tex).c_str());
|
||||||
s->TextureNameSet(TTexturesManager.Texture(tex).name.c_str());
|
s->TextureNameSet(TextureManager.Texture(tex).name.c_str());
|
||||||
s->TextureID = tex;
|
s->TextureID = tex;
|
||||||
s->eType = GL_TRIANGLES;
|
s->eType = GL_TRIANGLES;
|
||||||
// iAnimOwner=0; //roboczy wskaźnik na wierzchołek
|
// iAnimOwner=0; //roboczy wskaźnik na wierzchołek
|
||||||
@@ -714,7 +714,7 @@ void TSubModel::DisplayLists()
|
|||||||
{
|
{
|
||||||
uiDisplayList = glGenLists(1);
|
uiDisplayList = glGenLists(1);
|
||||||
glNewList(uiDisplayList, GL_COMPILE);
|
glNewList(uiDisplayList, GL_COMPILE);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
TextureManager.Bind(0);
|
||||||
// if (eType==smt_FreeSpotLight)
|
// if (eType==smt_FreeSpotLight)
|
||||||
// {
|
// {
|
||||||
// if (iFarAttenDecay==0)
|
// if (iFarAttenDecay==0)
|
||||||
@@ -737,7 +737,7 @@ void TSubModel::DisplayLists()
|
|||||||
{ // punkty świecące dookólnie
|
{ // punkty świecące dookólnie
|
||||||
uiDisplayList = glGenLists(1);
|
uiDisplayList = glGenLists(1);
|
||||||
glNewList(uiDisplayList, GL_COMPILE);
|
glNewList(uiDisplayList, GL_COMPILE);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0); // tekstury nie ma
|
TextureManager.Bind(0); // tekstury nie ma
|
||||||
glColorMaterial(GL_FRONT, GL_EMISSION);
|
glColorMaterial(GL_FRONT, GL_EMISSION);
|
||||||
glDisable(GL_LIGHTING); // Tolaris-030603: bo mu punkty swiecace sie blendowaly
|
glDisable(GL_LIGHTING); // Tolaris-030603: bo mu punkty swiecace sie blendowaly
|
||||||
glBegin(GL_POINTS);
|
glBegin(GL_POINTS);
|
||||||
@@ -1100,11 +1100,11 @@ void TSubModel::RenderDL()
|
|||||||
{
|
{
|
||||||
if (TextureID < 0) // && (ReplacableSkinId!=0))
|
if (TextureID < 0) // && (ReplacableSkinId!=0))
|
||||||
{ // zmienialne skóry
|
{ // zmienialne skóry
|
||||||
glBindTexture(GL_TEXTURE_2D, ReplacableSkinId[-TextureID]);
|
TextureManager.Bind(ReplacableSkinId[-TextureID]);
|
||||||
// TexAlpha=!(iAlpha&1); //zmiana tylko w przypadku wymienej tekstury
|
// TexAlpha=!(iAlpha&1); //zmiana tylko w przypadku wymienej tekstury
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID); // również 0
|
TextureManager.Bind(TextureID); // również 0
|
||||||
if (Global::fLuminance < fLight)
|
if (Global::fLuminance < fLight)
|
||||||
{
|
{
|
||||||
glMaterialfv(GL_FRONT, GL_EMISSION, f4Diffuse); // zeby swiecilo na kolorowo
|
glMaterialfv(GL_FRONT, GL_EMISSION, f4Diffuse); // zeby swiecilo na kolorowo
|
||||||
@@ -1197,11 +1197,11 @@ void TSubModel::RenderAlphaDL()
|
|||||||
{
|
{
|
||||||
if (TextureID < 0) // && (ReplacableSkinId!=0))
|
if (TextureID < 0) // && (ReplacableSkinId!=0))
|
||||||
{ // zmienialne skóry
|
{ // zmienialne skóry
|
||||||
glBindTexture(GL_TEXTURE_2D, ReplacableSkinId[-TextureID]);
|
TextureManager.Bind(ReplacableSkinId[-TextureID]);
|
||||||
// TexAlpha=iAlpha&1; //zmiana tylko w przypadku wymienej tekstury
|
// TexAlpha=iAlpha&1; //zmiana tylko w przypadku wymienej tekstury
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID); // również 0
|
TextureManager.Bind(TextureID); // również 0
|
||||||
if (Global::fLuminance < fLight)
|
if (Global::fLuminance < fLight)
|
||||||
{
|
{
|
||||||
glMaterialfv(GL_FRONT, GL_EMISSION, f4Diffuse); // zeby swiecilo na kolorowo
|
glMaterialfv(GL_FRONT, GL_EMISSION, f4Diffuse); // zeby swiecilo na kolorowo
|
||||||
@@ -1278,11 +1278,11 @@ void TSubModel::RenderVBO()
|
|||||||
{
|
{
|
||||||
if (TextureID < 0) // && (ReplacableSkinId!=0))
|
if (TextureID < 0) // && (ReplacableSkinId!=0))
|
||||||
{ // zmienialne skóry
|
{ // zmienialne skóry
|
||||||
glBindTexture(GL_TEXTURE_2D, ReplacableSkinId[-TextureID]);
|
TextureManager.Bind(ReplacableSkinId[-TextureID]);
|
||||||
// TexAlpha=!(iAlpha&1); //zmiana tylko w przypadku wymienej tekstury
|
// TexAlpha=!(iAlpha&1); //zmiana tylko w przypadku wymienej tekstury
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID); // również 0
|
TextureManager.Bind(TextureID); // również 0
|
||||||
glColor3fv(f4Diffuse); // McZapkie-240702: zamiast ub
|
glColor3fv(f4Diffuse); // McZapkie-240702: zamiast ub
|
||||||
// glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,f4Diffuse); //to samo,
|
// glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,f4Diffuse); //to samo,
|
||||||
// co glColor
|
// co glColor
|
||||||
@@ -1349,7 +1349,7 @@ void TSubModel::RenderVBO()
|
|||||||
Distdimm=1;
|
Distdimm=1;
|
||||||
|
|
||||||
*/
|
*/
|
||||||
glBindTexture(GL_TEXTURE_2D, 0); // nie teksturować
|
TextureManager.Bind(0); // nie teksturować
|
||||||
// glColor3f(f4Diffuse[0],f4Diffuse[1],f4Diffuse[2]);
|
// glColor3f(f4Diffuse[0],f4Diffuse[1],f4Diffuse[2]);
|
||||||
// glColorMaterial(GL_FRONT,GL_EMISSION);
|
// glColorMaterial(GL_FRONT,GL_EMISSION);
|
||||||
float color[4] = {f4Diffuse[0] * Distdimm, f4Diffuse[1] * Distdimm,
|
float color[4] = {f4Diffuse[0] * Distdimm, f4Diffuse[1] * Distdimm,
|
||||||
@@ -1378,7 +1378,7 @@ void TSubModel::RenderVBO()
|
|||||||
if (pRoot->StartColorVBO())
|
if (pRoot->StartColorVBO())
|
||||||
{ // wyświetlanie kolorowych punktów zamiast
|
{ // wyświetlanie kolorowych punktów zamiast
|
||||||
// trójkątów
|
// trójkątów
|
||||||
glBindTexture(GL_TEXTURE_2D, 0); // tekstury nie ma
|
TextureManager.Bind(0); // tekstury nie ma
|
||||||
glColorMaterial(GL_FRONT, GL_EMISSION);
|
glColorMaterial(GL_FRONT, GL_EMISSION);
|
||||||
glDisable(GL_LIGHTING); // Tolaris-030603: bo mu punkty swiecace sie
|
glDisable(GL_LIGHTING); // Tolaris-030603: bo mu punkty swiecace sie
|
||||||
// blendowaly
|
// blendowaly
|
||||||
@@ -1452,11 +1452,11 @@ void TSubModel::RenderAlphaVBO()
|
|||||||
{
|
{
|
||||||
if (TextureID < 0) // && (ReplacableSkinId!=0))
|
if (TextureID < 0) // && (ReplacableSkinId!=0))
|
||||||
{ // zmienialne skory
|
{ // zmienialne skory
|
||||||
glBindTexture(GL_TEXTURE_2D, ReplacableSkinId[-TextureID]);
|
TextureManager.Bind(ReplacableSkinId[-TextureID]);
|
||||||
// TexAlpha=iAlpha&1; //zmiana tylko w przypadku wymienej tekstury
|
// TexAlpha=iAlpha&1; //zmiana tylko w przypadku wymienej tekstury
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID); // również 0
|
TextureManager.Bind(TextureID); // również 0
|
||||||
if (Global::fLuminance < fLight)
|
if (Global::fLuminance < fLight)
|
||||||
{
|
{
|
||||||
glMaterialfv(GL_FRONT, GL_EMISSION, f4Diffuse); // zeby swiecilo na kolorowo
|
glMaterialfv(GL_FRONT, GL_EMISSION, f4Diffuse); // zeby swiecilo na kolorowo
|
||||||
@@ -1624,14 +1624,14 @@ void TSubModel::BinInit(TSubModel *s, float4x4 *m, float8 *v, TStringPack *t, TS
|
|||||||
std::string tex = pTexture;
|
std::string tex = pTexture;
|
||||||
if (tex.find_last_of("/\\") == std::string::npos)
|
if (tex.find_last_of("/\\") == std::string::npos)
|
||||||
tex.insert(0, Global::asCurrentTexturePath);
|
tex.insert(0, Global::asCurrentTexturePath);
|
||||||
TextureID = TTexturesManager.GetTextureId( tex, szTexturePath );
|
TextureID = TextureManager.GetTextureId( tex, szTexturePath );
|
||||||
// TexAlpha=TTexturesManager::GetAlpha(TextureID); //zmienna robocza
|
// TexAlpha=TTexturesManager::GetAlpha(TextureID); //zmienna robocza
|
||||||
// ustawienie cyklu przezroczyste/nieprzezroczyste zależnie od własności
|
// ustawienie cyklu przezroczyste/nieprzezroczyste zależnie od własności
|
||||||
// stałej tekstury
|
// stałej tekstury
|
||||||
// iFlags=(iFlags&~0x30)|(TTexturesManager::GetAlpha(TextureID)?0x20:0x10);
|
// iFlags=(iFlags&~0x30)|(TTexturesManager::GetAlpha(TextureID)?0x20:0x10);
|
||||||
// //0x10-nieprzezroczysta, 0x20-przezroczysta
|
// //0x10-nieprzezroczysta, 0x20-przezroczysta
|
||||||
if (Opacity < 1.0) // przezroczystość z tekstury brana tylko dla Opacity 0!
|
if (Opacity < 1.0) // przezroczystość z tekstury brana tylko dla Opacity 0!
|
||||||
iFlags |= TTexturesManager.Texture(TextureID).has_alpha ?
|
iFlags |= TextureManager.Texture(TextureID).has_alpha ?
|
||||||
0x20 :
|
0x20 :
|
||||||
0x10; // 0x10-nieprzezroczysta, 0x20-przezroczysta
|
0x10; // 0x10-nieprzezroczysta, 0x20-przezroczysta
|
||||||
else
|
else
|
||||||
@@ -2175,7 +2175,7 @@ ReplacableSkinId,int iAlpha)
|
|||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void TModel3d::Render(double fSquareDistance, GLuint *ReplacableSkinId, int iAlpha)
|
void TModel3d::Render(double fSquareDistance, texture_manager::size_type *ReplacableSkinId, int iAlpha)
|
||||||
{
|
{
|
||||||
iAlpha ^= 0x0F0F000F; // odwrócenie flag tekstur, aby wyłapać nieprzezroczyste
|
iAlpha ^= 0x0F0F000F; // odwrócenie flag tekstur, aby wyłapać nieprzezroczyste
|
||||||
if (iAlpha & iFlags & 0x1F1F001F) // czy w ogóle jest co robić w tym cyklu?
|
if (iAlpha & iFlags & 0x1F1F001F) // czy w ogóle jest co robić w tym cyklu?
|
||||||
@@ -2186,7 +2186,7 @@ void TModel3d::Render(double fSquareDistance, GLuint *ReplacableSkinId, int iAlp
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void TModel3d::RenderAlpha(double fSquareDistance, GLuint *ReplacableSkinId, int iAlpha)
|
void TModel3d::RenderAlpha(double fSquareDistance, texture_manager::size_type *ReplacableSkinId, int iAlpha)
|
||||||
{
|
{
|
||||||
if (iAlpha & iFlags & 0x2F2F002F)
|
if (iAlpha & iFlags & 0x2F2F002F)
|
||||||
{
|
{
|
||||||
@@ -2230,7 +2230,7 @@ globalna!
|
|||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void TModel3d::RaRender(double fSquareDistance, GLuint *ReplacableSkinId, int iAlpha)
|
void TModel3d::RaRender( double fSquareDistance, texture_manager::size_type *ReplacableSkinId, int iAlpha )
|
||||||
{ // renderowanie specjalne, np. kabiny
|
{ // renderowanie specjalne, np. kabiny
|
||||||
iAlpha ^= 0x0F0F000F; // odwrócenie flag tekstur, aby wyłapać nieprzezroczyste
|
iAlpha ^= 0x0F0F000F; // odwrócenie flag tekstur, aby wyłapać nieprzezroczyste
|
||||||
if (iAlpha & iFlags & 0x1F1F001F) // czy w ogóle jest co robić w tym cyklu?
|
if (iAlpha & iFlags & 0x1F1F001F) // czy w ogóle jest co robić w tym cyklu?
|
||||||
@@ -2246,7 +2246,7 @@ void TModel3d::RaRender(double fSquareDistance, GLuint *ReplacableSkinId, int iA
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void TModel3d::RaRenderAlpha(double fSquareDistance, GLuint *ReplacableSkinId, int iAlpha)
|
void TModel3d::RaRenderAlpha(double fSquareDistance, texture_manager::size_type *ReplacableSkinId, int iAlpha)
|
||||||
{ // renderowanie specjalne, np. kabiny
|
{ // renderowanie specjalne, np. kabiny
|
||||||
if (iAlpha & iFlags & 0x2F2F002F) // czy w ogóle jest co robić w tym cyklu?
|
if (iAlpha & iFlags & 0x2F2F002F) // czy w ogóle jest co robić w tym cyklu?
|
||||||
{
|
{
|
||||||
@@ -2284,7 +2284,7 @@ globalna!
|
|||||||
// 2011-03-16 cztery nowe funkcje renderowania z możliwością pochylania obiektów
|
// 2011-03-16 cztery nowe funkcje renderowania z możliwością pochylania obiektów
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
void TModel3d::Render(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableSkinId, int iAlpha)
|
void TModel3d::Render(vector3 *vPosition, vector3 *vAngle, texture_manager::size_type *ReplacableSkinId, int iAlpha)
|
||||||
{ // nieprzezroczyste, Display List
|
{ // nieprzezroczyste, Display List
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslated(vPosition->x, vPosition->y, vPosition->z);
|
glTranslated(vPosition->x, vPosition->y, vPosition->z);
|
||||||
@@ -2301,7 +2301,7 @@ void TModel3d::Render(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableSki
|
|||||||
Root->RenderDL();
|
Root->RenderDL();
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
};
|
};
|
||||||
void TModel3d::RenderAlpha(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableSkinId,
|
void TModel3d::RenderAlpha(vector3 *vPosition, vector3 *vAngle, texture_manager::size_type *ReplacableSkinId,
|
||||||
int iAlpha)
|
int iAlpha)
|
||||||
{ // przezroczyste, Display List
|
{ // przezroczyste, Display List
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
@@ -2318,7 +2318,7 @@ void TModel3d::RenderAlpha(vector3 *vPosition, vector3 *vAngle, GLuint *Replacab
|
|||||||
Root->RenderAlphaDL();
|
Root->RenderAlphaDL();
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
};
|
};
|
||||||
void TModel3d::RaRender(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableSkinId, int iAlpha)
|
void TModel3d::RaRender( vector3 *vPosition, vector3 *vAngle, texture_manager::size_type *ReplacableSkinId, int iAlpha )
|
||||||
{ // nieprzezroczyste, VBO
|
{ // nieprzezroczyste, VBO
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslated(vPosition->x, vPosition->y, vPosition->z);
|
glTranslated(vPosition->x, vPosition->y, vPosition->z);
|
||||||
@@ -2338,7 +2338,7 @@ void TModel3d::RaRender(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableS
|
|||||||
}
|
}
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
};
|
};
|
||||||
void TModel3d::RaRenderAlpha(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableSkinId,
|
void TModel3d::RaRenderAlpha(vector3 *vPosition, vector3 *vAngle, texture_manager::size_type *ReplacableSkinId,
|
||||||
int iAlpha)
|
int iAlpha)
|
||||||
{ // przezroczyste, VBO
|
{ // przezroczyste, VBO
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|||||||
28
Model3d.h
28
Model3d.h
@@ -253,7 +253,7 @@ class TSubModel
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
static int iInstance; // identyfikator egzemplarza, który aktualnie renderuje model
|
static int iInstance; // identyfikator egzemplarza, który aktualnie renderuje model
|
||||||
static GLuint *ReplacableSkinId;
|
static texture_manager::size_type *ReplacableSkinId;
|
||||||
static int iAlpha; // maska bitowa dla danego przebiegu
|
static int iAlpha; // maska bitowa dla danego przebiegu
|
||||||
static double fSquareDist;
|
static double fSquareDist;
|
||||||
static TModel3d *pRoot;
|
static TModel3d *pRoot;
|
||||||
@@ -312,7 +312,7 @@ class TSubModel
|
|||||||
void InfoSet(TSubModelInfo *info);
|
void InfoSet(TSubModelInfo *info);
|
||||||
void BinInit(TSubModel *s, float4x4 *m, float8 *v, TStringPack *t, TStringPack *n = NULL,
|
void BinInit(TSubModel *s, float4x4 *m, float8 *v, TStringPack *t, TStringPack *n = NULL,
|
||||||
bool dynamic = false);
|
bool dynamic = false);
|
||||||
void ReplacableSet(GLuint *r, int a)
|
void ReplacableSet(texture_manager::size_type *r, int a)
|
||||||
{
|
{
|
||||||
ReplacableSkinId = r;
|
ReplacableSkinId = r;
|
||||||
iAlpha = a;
|
iAlpha = a;
|
||||||
@@ -410,29 +410,29 @@ class TModel3d : public CMesh
|
|||||||
void SaveToBinFile(char const *FileName);
|
void SaveToBinFile(char const *FileName);
|
||||||
void BreakHierarhy();
|
void BreakHierarhy();
|
||||||
// renderowanie specjalne
|
// renderowanie specjalne
|
||||||
void Render(double fSquareDistance, GLuint *ReplacableSkinId = NULL, int iAlpha = 0x30300030);
|
void Render(double fSquareDistance, texture_manager::size_type *ReplacableSkinId = NULL, int iAlpha = 0x30300030);
|
||||||
void RenderAlpha(double fSquareDistance, GLuint *ReplacableSkinId = NULL,
|
void RenderAlpha(double fSquareDistance, texture_manager::size_type *ReplacableSkinId = NULL,
|
||||||
int iAlpha = 0x30300030);
|
int iAlpha = 0x30300030);
|
||||||
void RaRender(double fSquareDistance, GLuint *ReplacableSkinId = NULL, int iAlpha = 0x30300030);
|
void RaRender(double fSquareDistance, texture_manager::size_type *ReplacableSkinId = NULL, int iAlpha = 0x30300030);
|
||||||
void RaRenderAlpha(double fSquareDistance, GLuint *ReplacableSkinId = NULL,
|
void RaRenderAlpha(double fSquareDistance, texture_manager::size_type *ReplacableSkinId = NULL,
|
||||||
int iAlpha = 0x30300030);
|
int iAlpha = 0x30300030);
|
||||||
// jeden kąt obrotu
|
// jeden kąt obrotu
|
||||||
void Render(vector3 pPosition, double fAngle = 0, GLuint *ReplacableSkinId = NULL,
|
void Render(vector3 pPosition, double fAngle = 0, texture_manager::size_type *ReplacableSkinId = NULL,
|
||||||
int iAlpha = 0x30300030);
|
int iAlpha = 0x30300030);
|
||||||
void RenderAlpha(vector3 pPosition, double fAngle = 0, GLuint *ReplacableSkinId = NULL,
|
void RenderAlpha(vector3 pPosition, double fAngle = 0, texture_manager::size_type *ReplacableSkinId = NULL,
|
||||||
int iAlpha = 0x30300030);
|
int iAlpha = 0x30300030);
|
||||||
void RaRender(vector3 pPosition, double fAngle = 0, GLuint *ReplacableSkinId = NULL,
|
void RaRender(vector3 pPosition, double fAngle = 0, texture_manager::size_type *ReplacableSkinId = NULL,
|
||||||
int iAlpha = 0x30300030);
|
int iAlpha = 0x30300030);
|
||||||
void RaRenderAlpha(vector3 pPosition, double fAngle = 0, GLuint *ReplacableSkinId = NULL,
|
void RaRenderAlpha(vector3 pPosition, double fAngle = 0, texture_manager::size_type *ReplacableSkinId = NULL,
|
||||||
int iAlpha = 0x30300030);
|
int iAlpha = 0x30300030);
|
||||||
// trzy kąty obrotu
|
// trzy kąty obrotu
|
||||||
void Render(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableSkinId = NULL,
|
void Render( vector3 *vPosition, vector3 *vAngle, texture_manager::size_type *ReplacableSkinId = NULL,
|
||||||
int iAlpha = 0x30300030);
|
int iAlpha = 0x30300030);
|
||||||
void RenderAlpha(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableSkinId = NULL,
|
void RenderAlpha( vector3 *vPosition, vector3 *vAngle, texture_manager::size_type *ReplacableSkinId = NULL,
|
||||||
int iAlpha = 0x30300030);
|
int iAlpha = 0x30300030);
|
||||||
void RaRender(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableSkinId = NULL,
|
void RaRender( vector3 *vPosition, vector3 *vAngle, texture_manager::size_type *ReplacableSkinId = NULL,
|
||||||
int iAlpha = 0x30300030);
|
int iAlpha = 0x30300030);
|
||||||
void RaRenderAlpha(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableSkinId = NULL,
|
void RaRenderAlpha( vector3 *vPosition, vector3 *vAngle, texture_manager::size_type *ReplacableSkinId = NULL,
|
||||||
int iAlpha = 0x30300030);
|
int iAlpha = 0x30300030);
|
||||||
// inline int GetSubModelsCount() { return (SubModelsCount); };
|
// inline int GetSubModelsCount() { return (SubModelsCount); };
|
||||||
int Flags()
|
int Flags()
|
||||||
|
|||||||
@@ -447,7 +447,7 @@ void TPythonScreens::init(cParser &parser, TModel3d *model, std::string const &n
|
|||||||
free(pyClassName);
|
free(pyClassName);
|
||||||
return; // nie ma takiego sub modelu w danej kabinie pomijamy
|
return; // nie ma takiego sub modelu w danej kabinie pomijamy
|
||||||
}
|
}
|
||||||
int textureId = subModel->GetTextureId();
|
int textureId = TextureManager.Texture(subModel->GetTextureId()).id;
|
||||||
if (textureId <= 0)
|
if (textureId <= 0)
|
||||||
{
|
{
|
||||||
sprintf(buff, "Python Screen: invalid texture id %d - Ignoring screen", textureId);
|
sprintf(buff, "Python Screen: invalid texture id %d - Ignoring screen", textureId);
|
||||||
|
|||||||
@@ -641,7 +641,7 @@ void TSegment::RenderSwitchRail(const vector6 *ShapePoints1, const vector6 *Shap
|
|||||||
void TSegment::Render()
|
void TSegment::Render()
|
||||||
{
|
{
|
||||||
vector3 pt;
|
vector3 pt;
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
TextureManager.Bind(0);
|
||||||
int i;
|
int i;
|
||||||
if (bCurve)
|
if (bCurve)
|
||||||
{
|
{
|
||||||
|
|||||||
276
Texture.cpp
276
Texture.cpp
@@ -26,19 +26,248 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "Usefull.h"
|
#include "Usefull.h"
|
||||||
#include "TextureDDS.h"
|
#include "TextureDDS.h"
|
||||||
|
|
||||||
texture_manager TTexturesManager;
|
texture_manager TextureManager;
|
||||||
|
|
||||||
/*
|
texture_manager::texture_manager() {
|
||||||
TTexturesManager::Alphas TTexturesManager::_alphas;
|
|
||||||
TTexturesManager::Names TTexturesManager::_names;
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
texture_manager::Init() {
|
|
||||||
|
|
||||||
// since index 0 is used to indicate no texture, we put a blank entry in the first texture slot
|
// since index 0 is used to indicate no texture, we put a blank entry in the first texture slot
|
||||||
m_textures.emplace_back( opengl_texture() );
|
m_textures.emplace_back( opengl_texture() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// loads texture data from specified file
|
||||||
|
// TODO: wrap it in a workitem class, for the job system deferred loading
|
||||||
|
void
|
||||||
|
opengl_texture::load() {
|
||||||
|
|
||||||
|
if( name.size() < 3 ) { goto fail; }
|
||||||
|
|
||||||
|
WriteLog( "Loading texture data from \"" + name + "\"" );
|
||||||
|
|
||||||
|
data_state = resource_state::loading;
|
||||||
|
{
|
||||||
|
std::string const extension = name.substr( name.size() - 3, 3 );
|
||||||
|
|
||||||
|
if( extension == "dds" ) { load_DDS(); }
|
||||||
|
/*
|
||||||
|
else if( extension == "tga" ) { load_TGA(); }
|
||||||
|
else if( extension == "tex" ) { load_TEX(); }
|
||||||
|
else if( extension == "bmp" ) { load_BMP(); }
|
||||||
|
*/
|
||||||
|
else { goto fail; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// data state will be set by called loader, so we're all done here
|
||||||
|
if( data_state == resource_state::good ) {
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fail:
|
||||||
|
data_state = resource_state::failed;
|
||||||
|
ErrorLog( "Failed to load texture \"" + name + "\"" );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
opengl_texture::load_DDS() {
|
||||||
|
|
||||||
|
std::ifstream file( name, std::ios::binary | std::ios::ate ); file.unsetf( std::ios::skipws );
|
||||||
|
std::size_t filesize = static_cast<size_t>(file.tellg()); // ios::ate already positioned us at the end of the file
|
||||||
|
file.seekg( 0, std::ios::beg ); // rewind the caret afterwards
|
||||||
|
|
||||||
|
char filecode[5];
|
||||||
|
file.read(filecode, 4);
|
||||||
|
filesize -= 4;
|
||||||
|
filecode[4] = 0;
|
||||||
|
|
||||||
|
if( filecode != std::string( "DDS " ) )
|
||||||
|
{
|
||||||
|
data_state = resource_state::failed;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DDSURFACEDESC2 ddsd;
|
||||||
|
file.read((char *)&ddsd, sizeof(ddsd));
|
||||||
|
filesize -= sizeof( ddsd );
|
||||||
|
|
||||||
|
//
|
||||||
|
// This .dds loader supports the loading of compressed formats DXT1, DXT3
|
||||||
|
// and DXT5.
|
||||||
|
//
|
||||||
|
|
||||||
|
switch (ddsd.ddpfPixelFormat.dwFourCC)
|
||||||
|
{
|
||||||
|
case FOURCC_DXT1:
|
||||||
|
// DXT1's compression ratio is 8:1
|
||||||
|
data_format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FOURCC_DXT3:
|
||||||
|
// DXT3's compression ratio is 4:1
|
||||||
|
data_format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FOURCC_DXT5:
|
||||||
|
// DXT5's compression ratio is 4:1
|
||||||
|
data_format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
data_state = resource_state::failed;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
data_width = ddsd.dwWidth;
|
||||||
|
data_height = ddsd.dwHeight;
|
||||||
|
data_mapcount = 1;// ddsd.dwMipMapCount;
|
||||||
|
|
||||||
|
int blockSize = ( data_format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ? 8 : 16 );
|
||||||
|
int offset = 0;
|
||||||
|
|
||||||
|
while( ( data_width > Global::iMaxTextureSize ) || ( data_height > Global::iMaxTextureSize ) ) {
|
||||||
|
// pomijanie zbyt dużych mipmap, jeśli wymagane jest ograniczenie rozmiaru
|
||||||
|
offset += ( ( data_width + 3 ) / 4 ) * ( ( data_height + 3 ) / 4 ) * blockSize;
|
||||||
|
data_width /= 2;
|
||||||
|
data_height /= 2;
|
||||||
|
--data_mapcount;
|
||||||
|
};
|
||||||
|
|
||||||
|
if( data_mapcount <= 0 ) {
|
||||||
|
// there's a chance we've discarded the provided mipmap(s) as too large
|
||||||
|
WriteLog( "Texture \"" + name + "\" has no mipmaps which can fit currently set texture size limits." );
|
||||||
|
data_state = resource_state::failed;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int datasize = filesize - offset;
|
||||||
|
// int datasize = ( ( data_width + 3 ) / 4 ) * ( ( data_height + 3 ) / 4 ) * blockSize;
|
||||||
|
/*
|
||||||
|
// calculate size of accepted data
|
||||||
|
// NOTE: this is a fallback, as we should be able to just move the file caret by calculated offset and read the rest
|
||||||
|
int datasize = 0;
|
||||||
|
int mapcount = data_mapcount,
|
||||||
|
width = data_width,
|
||||||
|
height = data_height;
|
||||||
|
while( mapcount ) {
|
||||||
|
|
||||||
|
datasize += ( ( width + 3 ) / 4 ) * ( ( height + 3 ) / 4 ) * blockSize;
|
||||||
|
width = std::max( width / 2, 4 );
|
||||||
|
height = std::max( height / 2, 4 );
|
||||||
|
--mapcount;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
// reserve space and load texture data
|
||||||
|
data.resize( datasize );
|
||||||
|
if( offset != 0 ) {
|
||||||
|
// skip data for mipmaps we don't need
|
||||||
|
file.seekg( offset, std::ios_base::cur );
|
||||||
|
filesize -= offset;
|
||||||
|
}
|
||||||
|
file.read((char *)&data[0], datasize);
|
||||||
|
filesize -= datasize;
|
||||||
|
|
||||||
|
data_components =
|
||||||
|
( ddsd.ddpfPixelFormat.dwFourCC == FOURCC_DXT1 ?
|
||||||
|
GL_RGB :
|
||||||
|
GL_RGBA );
|
||||||
|
|
||||||
|
data_state = resource_state::good;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
opengl_texture::create() {
|
||||||
|
|
||||||
|
if( data_state != resource_state::good ) {
|
||||||
|
// don't bother until we have useful texture data
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
glGenTextures( 1, &id );
|
||||||
|
glBindTexture( GL_TEXTURE_2D, id );
|
||||||
|
|
||||||
|
// TODO: set wrapping according to supplied parameters
|
||||||
|
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
|
||||||
|
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
|
||||||
|
|
||||||
|
set_filtering();
|
||||||
|
|
||||||
|
if( GLEW_VERSION_1_4 ) {
|
||||||
|
|
||||||
|
if( data_mapcount == 1 ) {
|
||||||
|
// fill missing mipmaps if needed
|
||||||
|
glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE );
|
||||||
|
}
|
||||||
|
// upload texture data
|
||||||
|
// TBD, TODO: handle mipmaps other than base manually, or let the card take care of it?
|
||||||
|
int dataoffset = 0,
|
||||||
|
datasize = 0,
|
||||||
|
datawidth = data_width,
|
||||||
|
dataheight = data_height;
|
||||||
|
for( int maplevel = 0; maplevel < data_mapcount; ++maplevel ) {
|
||||||
|
|
||||||
|
if( ( data_format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT )
|
||||||
|
|| ( data_format == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT )
|
||||||
|
|| ( data_format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT ) ) {
|
||||||
|
// compressed dds formats
|
||||||
|
if( false == Global::bDecompressDDS ) {
|
||||||
|
// let the openGL handle this
|
||||||
|
int const datablocksize =
|
||||||
|
( data_format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ?
|
||||||
|
8 :
|
||||||
|
16 );
|
||||||
|
|
||||||
|
datasize = ( ( std::max(datawidth, 4) + 3 ) / 4 ) * ( ( std::max(dataheight, 4) + 3 ) / 4 ) * datablocksize;
|
||||||
|
|
||||||
|
glCompressedTexImage2D(
|
||||||
|
GL_TEXTURE_2D, maplevel,
|
||||||
|
data_format, datawidth, dataheight, 0, datasize,
|
||||||
|
(GLubyte *)&data[0] + dataoffset );
|
||||||
|
|
||||||
|
dataoffset += datasize;
|
||||||
|
datawidth = std::max( datawidth / 2, 1 );
|
||||||
|
dataheight = std::max( dataheight / 2, 1 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
is_ready = true;
|
||||||
|
has_alpha = (
|
||||||
|
data_components == GL_RGBA ?
|
||||||
|
true :
|
||||||
|
false );
|
||||||
|
|
||||||
|
data.resize( 0 ); // TBD, TODO: keep the texture data if we start doing some gpu data cleaning down the road
|
||||||
|
data_state = resource_state::none;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
opengl_texture::set_filtering() {
|
||||||
|
|
||||||
|
bool hash = ( name.find( '#' ) != std::string::npos );
|
||||||
|
|
||||||
|
if( GLEW_VERSION_1_4 ) {
|
||||||
|
|
||||||
|
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
||||||
|
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
|
||||||
|
|
||||||
|
if( true == hash ) {
|
||||||
|
// #: sharpen more
|
||||||
|
glTexEnvf( GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, -2.0 );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// regular texture sharpening
|
||||||
|
glTexEnvf( GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, -1.0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
texture_manager::Init() {
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TTexturesManager::Names::iterator TTexturesManager::LoadFromFile(std::string fileName, int filter)
|
TTexturesManager::Names::iterator TTexturesManager::LoadFromFile(std::string fileName, int filter)
|
||||||
{
|
{
|
||||||
@@ -100,9 +329,9 @@ struct ReplaceSlash
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
// ustalenie numeru tekstury, wczytanie jeśli nie jeszcze takiej nie było
|
// ustalenie numeru tekstury, wczytanie jeśli jeszcze takiej nie było
|
||||||
texture_manager::size_type
|
texture_manager::size_type
|
||||||
texture_manager::GetTextureId( std::string Filename, std::string const &Dir, int const Filter ) {
|
texture_manager::GetTextureId( std::string Filename, std::string const &Dir, int const Filter, bool const Loadnow ) {
|
||||||
|
|
||||||
if( Filename.find( ':' ) != std::string::npos )
|
if( Filename.find( ':' ) != std::string::npos )
|
||||||
Filename.erase( Filename.find( ':' ) ); // po dwukropku mogą być podane dodatkowe informacje niebędące nazwą tekstury
|
Filename.erase( Filename.find( ':' ) ); // po dwukropku mogą być podane dodatkowe informacje niebędące nazwą tekstury
|
||||||
@@ -112,6 +341,8 @@ texture_manager::GetTextureId( std::string Filename, std::string const &Dir, int
|
|||||||
// change forward slashes to windows ones. NOTE: probably not strictly necessary, but eh
|
// change forward slashes to windows ones. NOTE: probably not strictly necessary, but eh
|
||||||
c = ( c == '/' ? '\\' : c );
|
c = ( c == '/' ? '\\' : c );
|
||||||
}
|
}
|
||||||
|
if( Filename.rfind('.')!= std::string::npos )
|
||||||
|
Filename.erase( Filename.find( '.' ) ); // trim extension if there's one
|
||||||
/*
|
/*
|
||||||
std::transform(
|
std::transform(
|
||||||
Filename.begin(), Filename.end(),
|
Filename.begin(), Filename.end(),
|
||||||
@@ -171,15 +402,38 @@ texture_manager::GetTextureId( std::string Filename, std::string const &Dir, int
|
|||||||
|
|
||||||
opengl_texture texture;
|
opengl_texture texture;
|
||||||
texture.name = filename;
|
texture.name = filename;
|
||||||
|
texture.attributes = std::to_string( Filter ); // temporary. TODO, TBD: check how it's used and possibly get rid of it
|
||||||
|
auto const textureindex = m_textures.size();
|
||||||
m_textures.emplace_back( texture );
|
m_textures.emplace_back( texture );
|
||||||
auto const textureindex = m_textures.size() - 1;
|
|
||||||
m_texturemappings.emplace( filename, textureindex );
|
m_texturemappings.emplace( filename, textureindex );
|
||||||
|
|
||||||
WriteLog( "Created texture object for file \"" + filename + "\"" );
|
WriteLog( "Created texture object for \"" + filename + "\"" );
|
||||||
|
|
||||||
|
if( true == Loadnow ) {
|
||||||
|
|
||||||
|
Texture( textureindex ).load();
|
||||||
|
Texture( textureindex ).create();
|
||||||
|
}
|
||||||
|
|
||||||
return textureindex;
|
return textureindex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
texture_manager::Bind( texture_manager::size_type const Id ) {
|
||||||
|
|
||||||
|
// TODO: keep track of what's currently bound and don't do it twice
|
||||||
|
// TODO: do binding in texture object, add support for other types
|
||||||
|
if( Id != 0 ) {
|
||||||
|
|
||||||
|
auto const &texture = Texture( Id );
|
||||||
|
if( true == texture.is_ready ) {
|
||||||
|
glBindTexture( GL_TEXTURE_2D, texture.id );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
glBindTexture( GL_TEXTURE_2D, 0 );
|
||||||
|
}
|
||||||
// checks whether specified texture is in the texture bank. returns texture id, or npos.
|
// checks whether specified texture is in the texture bank. returns texture id, or npos.
|
||||||
texture_manager::size_type
|
texture_manager::size_type
|
||||||
texture_manager::find_in_databank( std::string const &Texturename ) {
|
texture_manager::find_in_databank( std::string const &Texturename ) {
|
||||||
|
|||||||
38
Texture.h
38
Texture.h
@@ -12,15 +12,40 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "opengl/glew.h"
|
#include "opengl/glew.h"
|
||||||
|
|
||||||
|
enum resource_state {
|
||||||
|
none,
|
||||||
|
loading,
|
||||||
|
good,
|
||||||
|
failed
|
||||||
|
};
|
||||||
|
|
||||||
struct opengl_texture {
|
struct opengl_texture {
|
||||||
|
|
||||||
GLuint id{ -1 }; // associated GL resource
|
GLuint id{ -1 }; // associated GL resource
|
||||||
bool has_alpha{ false }; // indicates the texture has alpha channel
|
bool has_alpha{ false }; // indicates the texture has alpha channel
|
||||||
bool is_ready{ false }; // indicates the texture was processed and is ready for use
|
bool is_ready{ false }; // indicates the texture was processed and is ready for use
|
||||||
|
std::string attributes; // requested texture attributes: wrapping modes etc
|
||||||
std::string name; // name of the texture source file
|
std::string name; // name of the texture source file
|
||||||
std::vector<char> data; // texture data
|
std::vector<char> data; // texture data
|
||||||
/*std::atomic<bool>*/ bool is_loaded{ false }; // indicates the texture data was loaded and can be processed
|
resource_state data_state{ none }; // current state of texture data
|
||||||
/*std::atomic<bool>*/ bool is_good{ false }; // indicates the texture data was retrieved without errors
|
int data_width{ 0 },
|
||||||
|
data_height{ 0 },
|
||||||
|
data_mapcount{ 0 };
|
||||||
|
GLuint data_format{ 0 },
|
||||||
|
data_components{ 0 };
|
||||||
|
/*
|
||||||
|
std::atomic<bool> is_loaded{ false }; // indicates the texture data was loaded and can be processed
|
||||||
|
std::atomic<bool> is_good{ false }; // indicates the texture data was retrieved without errors
|
||||||
|
*/
|
||||||
|
void load();
|
||||||
|
void create();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// void load_BMP();
|
||||||
|
void load_DDS();
|
||||||
|
// void load_TEX();
|
||||||
|
// void load_TGA();
|
||||||
|
void set_filtering();
|
||||||
};
|
};
|
||||||
|
|
||||||
class texture_manager {
|
class texture_manager {
|
||||||
@@ -29,11 +54,14 @@ private:
|
|||||||
typedef std::vector<opengl_texture> opengltexture_array;
|
typedef std::vector<opengl_texture> opengltexture_array;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef opengltexture_array::size_type size_type;
|
// typedef opengltexture_array::size_type size_type;
|
||||||
|
typedef int size_type;
|
||||||
|
|
||||||
|
texture_manager();
|
||||||
~texture_manager() { Free(); }
|
~texture_manager() { Free(); }
|
||||||
|
|
||||||
size_type GetTextureId( std::string Filename, std::string const &Dir, int const Filter = -1 );
|
size_type GetTextureId( std::string Filename, std::string const &Dir, int const Filter = -1, bool const Loadnow = true );
|
||||||
|
void Bind( size_type const Id );
|
||||||
opengl_texture &Texture( size_type const Id ) { return m_textures.at( Id ); }
|
opengl_texture &Texture( size_type const Id ) { return m_textures.at( Id ); }
|
||||||
void Init();
|
void Init();
|
||||||
void Free();
|
void Free();
|
||||||
@@ -64,4 +92,4 @@ private:
|
|||||||
index_map m_texturemappings;
|
index_map m_texturemappings;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern texture_manager TTexturesManager;
|
extern texture_manager TextureManager;
|
||||||
48
Track.cpp
48
Track.cpp
@@ -508,7 +508,7 @@ void TTrack::Load(cParser *parser, vector3 pOrigin, std::string name)
|
|||||||
parser->getTokens();
|
parser->getTokens();
|
||||||
*parser >> token;
|
*parser >> token;
|
||||||
str = token; // railtex
|
str = token; // railtex
|
||||||
TextureID1 = (str == "none" ? 0 : TTexturesManager.GetTextureId(
|
TextureID1 = (str == "none" ? 0 : TextureManager.GetTextureId(
|
||||||
str, szTexturePath,
|
str, szTexturePath,
|
||||||
(iCategoryFlag & 1) ? Global::iRailProFiltering :
|
(iCategoryFlag & 1) ? Global::iRailProFiltering :
|
||||||
Global::iBallastFiltering));
|
Global::iBallastFiltering));
|
||||||
@@ -519,7 +519,7 @@ void TTrack::Load(cParser *parser, vector3 pOrigin, std::string name)
|
|||||||
parser->getTokens();
|
parser->getTokens();
|
||||||
*parser >> token;
|
*parser >> token;
|
||||||
str = token; // sub || railtex
|
str = token; // sub || railtex
|
||||||
TextureID2 = (str == "none" ? 0 : TTexturesManager.GetTextureId(
|
TextureID2 = (str == "none" ? 0 : TextureManager.GetTextureId(
|
||||||
str, szTexturePath,
|
str, szTexturePath,
|
||||||
(eType == tt_Normal) ? Global::iBallastFiltering :
|
(eType == tt_Normal) ? Global::iBallastFiltering :
|
||||||
Global::iRailProFiltering));
|
Global::iRailProFiltering));
|
||||||
@@ -579,12 +579,12 @@ void TTrack::Load(cParser *parser, vector3 pOrigin, std::string name)
|
|||||||
if (TextureID1 && fTexLength)
|
if (TextureID1 && fTexLength)
|
||||||
{ // dla drogi trzeba ustalić proporcje boków nawierzchni
|
{ // dla drogi trzeba ustalić proporcje boków nawierzchni
|
||||||
float w, h;
|
float w, h;
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID1);
|
TextureManager.Bind(TextureID1);
|
||||||
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
||||||
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
||||||
if (h != 0.0)
|
if (h != 0.0)
|
||||||
fTexRatio1 = w / h; // proporcja boków
|
fTexRatio1 = w / h; // proporcja boków
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID2);
|
TextureManager.Bind(TextureID2);
|
||||||
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
||||||
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
||||||
if (h != 0.0)
|
if (h != 0.0)
|
||||||
@@ -1299,14 +1299,14 @@ void TTrack::Compile(GLuint tex)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!tex)
|
if (!tex)
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID2);
|
TextureManager.Bind( TextureID2 );
|
||||||
Segment->RenderLoft(bpts1, iTrapezoid ? -4 : 4, fTexLength);
|
Segment->RenderLoft(bpts1, iTrapezoid ? -4 : 4, fTexLength);
|
||||||
}
|
}
|
||||||
if (TextureID1)
|
if (TextureID1)
|
||||||
if (tex ? TextureID1 == tex : true) // jeśli pasuje do grupy (tex)
|
if (tex ? TextureID1 == tex : true) // jeśli pasuje do grupy (tex)
|
||||||
{ // szyny
|
{ // szyny
|
||||||
if (!tex)
|
if (!tex)
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID1);
|
TextureManager.Bind( TextureID1 );
|
||||||
Segment->RenderLoft(rpts1, iTrapezoid ? -nnumPts : nnumPts, fTexLength);
|
Segment->RenderLoft(rpts1, iTrapezoid ? -nnumPts : nnumPts, fTexLength);
|
||||||
Segment->RenderLoft(rpts2, iTrapezoid ? -nnumPts : nnumPts, fTexLength);
|
Segment->RenderLoft(rpts2, iTrapezoid ? -nnumPts : nnumPts, fTexLength);
|
||||||
}
|
}
|
||||||
@@ -1345,7 +1345,7 @@ void TTrack::Compile(GLuint tex)
|
|||||||
// McZapkie-130302 - poprawione rysowanie szyn
|
// McZapkie-130302 - poprawione rysowanie szyn
|
||||||
if (SwitchExtension->RightSwitch)
|
if (SwitchExtension->RightSwitch)
|
||||||
{ // zwrotnica prawa
|
{ // zwrotnica prawa
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID1);
|
TextureManager.Bind( TextureID1 );
|
||||||
SwitchExtension->Segments[0]->RenderLoft(rpts1, nnumPts, fTexLength,
|
SwitchExtension->Segments[0]->RenderLoft(rpts1, nnumPts, fTexLength,
|
||||||
2); // prawa szyna za iglicą
|
2); // prawa szyna za iglicą
|
||||||
SwitchExtension->Segments[0]->RenderSwitchRail(
|
SwitchExtension->Segments[0]->RenderSwitchRail(
|
||||||
@@ -1354,7 +1354,7 @@ void TTrack::Compile(GLuint tex)
|
|||||||
SwitchExtension->Segments[0]->RenderLoft(
|
SwitchExtension->Segments[0]->RenderLoft(
|
||||||
rpts2, nnumPts, fTexLength); // lewa szyna normalnie cała
|
rpts2, nnumPts, fTexLength); // lewa szyna normalnie cała
|
||||||
if (TextureID2 != TextureID1) // nie wiadomo, czy OpenGL to optymalizuje
|
if (TextureID2 != TextureID1) // nie wiadomo, czy OpenGL to optymalizuje
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID2);
|
TextureManager.Bind( TextureID2 );
|
||||||
SwitchExtension->Segments[1]->RenderLoft(
|
SwitchExtension->Segments[1]->RenderLoft(
|
||||||
rpts1, nnumPts, fTexLength); // prawa szyna normalna cała
|
rpts1, nnumPts, fTexLength); // prawa szyna normalna cała
|
||||||
SwitchExtension->Segments[1]->RenderLoft(rpts2, nnumPts, fTexLength,
|
SwitchExtension->Segments[1]->RenderLoft(rpts2, nnumPts, fTexLength,
|
||||||
@@ -1365,7 +1365,7 @@ void TTrack::Compile(GLuint tex)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // lewa kiedyś działała lepiej niż prawa
|
{ // lewa kiedyś działała lepiej niż prawa
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID1);
|
TextureManager.Bind( TextureID1 );
|
||||||
SwitchExtension->Segments[0]->RenderLoft(
|
SwitchExtension->Segments[0]->RenderLoft(
|
||||||
rpts1, nnumPts, fTexLength); // prawa szyna normalna cała
|
rpts1, nnumPts, fTexLength); // prawa szyna normalna cała
|
||||||
SwitchExtension->Segments[0]->RenderLoft(rpts2, nnumPts, fTexLength,
|
SwitchExtension->Segments[0]->RenderLoft(rpts2, nnumPts, fTexLength,
|
||||||
@@ -1374,7 +1374,7 @@ void TTrack::Compile(GLuint tex)
|
|||||||
rpts2, rpts4, nnumPts, fTexLength, 2,
|
rpts2, rpts4, nnumPts, fTexLength, 2,
|
||||||
-SwitchExtension->fOffset2); // lewa iglica
|
-SwitchExtension->fOffset2); // lewa iglica
|
||||||
if (TextureID2 != TextureID1) // nie wiadomo, czy OpenGL to optymalizuje
|
if (TextureID2 != TextureID1) // nie wiadomo, czy OpenGL to optymalizuje
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID2);
|
TextureManager.Bind( TextureID2 );
|
||||||
SwitchExtension->Segments[1]->RenderLoft(rpts1, nnumPts, fTexLength,
|
SwitchExtension->Segments[1]->RenderLoft(rpts1, nnumPts, fTexLength,
|
||||||
2); // prawa szyna za iglicą
|
2); // prawa szyna za iglicą
|
||||||
SwitchExtension->Segments[1]->RenderSwitchRail(
|
SwitchExtension->Segments[1]->RenderSwitchRail(
|
||||||
@@ -1422,7 +1422,7 @@ void TTrack::Compile(GLuint tex)
|
|||||||
if (tex ? TextureID1 == tex : true) // jeśli pasuje do grupy (tex)
|
if (tex ? TextureID1 == tex : true) // jeśli pasuje do grupy (tex)
|
||||||
{ // tworzenie trójkątów nawierzchni szosy
|
{ // tworzenie trójkątów nawierzchni szosy
|
||||||
if (!tex)
|
if (!tex)
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID1);
|
TextureManager.Bind( TextureID1 );
|
||||||
Segment->RenderLoft(bpts1, iTrapezoid ? -2 : 2, fTexLength);
|
Segment->RenderLoft(bpts1, iTrapezoid ? -2 : 2, fTexLength);
|
||||||
}
|
}
|
||||||
if (TextureID2)
|
if (TextureID2)
|
||||||
@@ -1430,7 +1430,7 @@ void TTrack::Compile(GLuint tex)
|
|||||||
{ // pobocze drogi - poziome przy przechyłce (a może krawężnik i chodnik zrobić jak
|
{ // pobocze drogi - poziome przy przechyłce (a może krawężnik i chodnik zrobić jak
|
||||||
// w Midtown Madness 2?)
|
// w Midtown Madness 2?)
|
||||||
if (!tex)
|
if (!tex)
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID2);
|
TextureManager.Bind( TextureID2 );
|
||||||
vector6 rpts1[6],
|
vector6 rpts1[6],
|
||||||
rpts2[6]; // współrzędne przekroju i mapowania dla prawej i lewej strony
|
rpts2[6]; // współrzędne przekroju i mapowania dla prawej i lewej strony
|
||||||
if (fTexHeight1 >= 0.0)
|
if (fTexHeight1 >= 0.0)
|
||||||
@@ -1610,7 +1610,7 @@ void TTrack::Compile(GLuint tex)
|
|||||||
// Midtown Madness 2?)
|
// Midtown Madness 2?)
|
||||||
if (TextureID2)
|
if (TextureID2)
|
||||||
if (!tex)
|
if (!tex)
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID2);
|
TextureManager.Bind( TextureID2 );
|
||||||
vector6 rpts1[6],
|
vector6 rpts1[6],
|
||||||
rpts2[6]; // współrzędne przekroju i mapowania dla prawej i lewej strony
|
rpts2[6]; // współrzędne przekroju i mapowania dla prawej i lewej strony
|
||||||
// Ra 2014-07: trzeba to przerobić na pętlę i pobierać profile (przynajmniej 2..4) z
|
// Ra 2014-07: trzeba to przerobić na pętlę i pobierać profile (przynajmniej 2..4) z
|
||||||
@@ -1755,7 +1755,7 @@ void TTrack::Compile(GLuint tex)
|
|||||||
if (tex ? TextureID1 == tex : true) // jeśli pasuje do grupy (tex)
|
if (tex ? TextureID1 == tex : true) // jeśli pasuje do grupy (tex)
|
||||||
{
|
{
|
||||||
if (!tex)
|
if (!tex)
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID1);
|
TextureManager.Bind( TextureID1 );
|
||||||
glBegin(GL_TRIANGLE_FAN); // takie kółeczko będzie
|
glBegin(GL_TRIANGLE_FAN); // takie kółeczko będzie
|
||||||
glNormal3f(0, 1, 0);
|
glNormal3f(0, 1, 0);
|
||||||
glTexCoord2f(0.5, 0.5); //środek tekstury na środku skrzyżowania
|
glTexCoord2f(0.5, 0.5); //środek tekstury na środku skrzyżowania
|
||||||
@@ -1787,7 +1787,7 @@ void TTrack::Compile(GLuint tex)
|
|||||||
if (tex ? TextureID1 == tex : true) // jeśli pasuje do grupy (tex)
|
if (tex ? TextureID1 == tex : true) // jeśli pasuje do grupy (tex)
|
||||||
{
|
{
|
||||||
if (!tex)
|
if (!tex)
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID1);
|
TextureManager.Bind( TextureID1 );
|
||||||
Segment->RenderLoft(bpts1, numPts, fTexLength);
|
Segment->RenderLoft(bpts1, numPts, fTexLength);
|
||||||
}
|
}
|
||||||
if (TextureID2)
|
if (TextureID2)
|
||||||
@@ -1799,7 +1799,7 @@ void TTrack::Compile(GLuint tex)
|
|||||||
vector6 rpts2[3] = {vector6(-fHTW, 0.0, 1.0), vector6(-fHTW - side, 0.0, 0.5),
|
vector6 rpts2[3] = {vector6(-fHTW, 0.0, 1.0), vector6(-fHTW - side, 0.0, 0.5),
|
||||||
vector6(-rozp, -fTexHeight1, 0.0)}; // Ra: po kiego 0.1?
|
vector6(-rozp, -fTexHeight1, 0.0)}; // Ra: po kiego 0.1?
|
||||||
if (!tex)
|
if (!tex)
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID2); // brzeg rzeki
|
TextureManager.Bind( TextureID2 ); // brzeg rzeki
|
||||||
Segment->RenderLoft(rpts1, 3, fTexLength);
|
Segment->RenderLoft(rpts1, 3, fTexLength);
|
||||||
Segment->RenderLoft(rpts2, 3, fTexLength);
|
Segment->RenderLoft(rpts2, 3, fTexLength);
|
||||||
}
|
}
|
||||||
@@ -2473,7 +2473,7 @@ void TTrack::RaRenderVBO(int iPtr)
|
|||||||
if (TextureID1)
|
if (TextureID1)
|
||||||
if ((seg = SwitchExtension->Segments[0]->RaSegCount()) > 0)
|
if ((seg = SwitchExtension->Segments[0]->RaSegCount()) > 0)
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID1); // szyny +
|
TextureManager.Bind( TextureID1 ); // szyny +
|
||||||
for (i = 0; i < seg; ++i)
|
for (i = 0; i < seg; ++i)
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, iPtr + 24 * i, 24);
|
glDrawArrays(GL_TRIANGLE_STRIP, iPtr + 24 * i, 24);
|
||||||
iPtr += 24 * seg; // pominięcie lewej szyny
|
iPtr += 24 * seg; // pominięcie lewej szyny
|
||||||
@@ -2484,7 +2484,7 @@ void TTrack::RaRenderVBO(int iPtr)
|
|||||||
if (TextureID2)
|
if (TextureID2)
|
||||||
if ((seg = SwitchExtension->Segments[1]->RaSegCount()) > 0)
|
if ((seg = SwitchExtension->Segments[1]->RaSegCount()) > 0)
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID2); // szyny -
|
TextureManager.Bind( TextureID2 ); // szyny -
|
||||||
for (i = 0; i < seg; ++i)
|
for (i = 0; i < seg; ++i)
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, iPtr + 24 * i, 24);
|
glDrawArrays(GL_TRIANGLE_STRIP, iPtr + 24 * i, 24);
|
||||||
iPtr += 24 * seg; // pominięcie lewej szyny
|
iPtr += 24 * seg; // pominięcie lewej szyny
|
||||||
@@ -2498,14 +2498,14 @@ void TTrack::RaRenderVBO(int iPtr)
|
|||||||
{
|
{
|
||||||
if (TextureID2)
|
if (TextureID2)
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID2); // podsypka
|
TextureManager.Bind( TextureID2 ); // podsypka
|
||||||
for (i = 0; i < seg; ++i)
|
for (i = 0; i < seg; ++i)
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, iPtr + 8 * i, 8);
|
glDrawArrays(GL_TRIANGLE_STRIP, iPtr + 8 * i, 8);
|
||||||
iPtr += 8 * seg; // pominięcie podsypki
|
iPtr += 8 * seg; // pominięcie podsypki
|
||||||
}
|
}
|
||||||
if (TextureID1)
|
if (TextureID1)
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID1); // szyny
|
TextureManager.Bind( TextureID1 ); // szyny
|
||||||
for (i = 0; i < seg; ++i)
|
for (i = 0; i < seg; ++i)
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, iPtr + 24 * i, 24);
|
glDrawArrays(GL_TRIANGLE_STRIP, iPtr + 24 * i, 24);
|
||||||
iPtr += 24 * seg; // pominięcie lewej szyny
|
iPtr += 24 * seg; // pominięcie lewej szyny
|
||||||
@@ -2520,7 +2520,7 @@ void TTrack::RaRenderVBO(int iPtr)
|
|||||||
{
|
{
|
||||||
if (TextureID1)
|
if (TextureID1)
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID1); // nawierzchnia
|
TextureManager.Bind( TextureID1 ); // nawierzchnia
|
||||||
for (i = 0; i < seg; ++i)
|
for (i = 0; i < seg; ++i)
|
||||||
{
|
{
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, iPtr, 4);
|
glDrawArrays(GL_TRIANGLE_STRIP, iPtr, 4);
|
||||||
@@ -2529,7 +2529,7 @@ void TTrack::RaRenderVBO(int iPtr)
|
|||||||
}
|
}
|
||||||
if (TextureID2)
|
if (TextureID2)
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID2); // pobocze
|
TextureManager.Bind( TextureID2 ); // pobocze
|
||||||
if (fTexHeight1 >= 0.0)
|
if (fTexHeight1 >= 0.0)
|
||||||
{ // normalna droga z poboczem
|
{ // normalna droga z poboczem
|
||||||
for (i = 0; i < seg; ++i)
|
for (i = 0; i < seg; ++i)
|
||||||
@@ -2558,7 +2558,7 @@ void TTrack::RaRenderVBO(int iPtr)
|
|||||||
{
|
{
|
||||||
if (TextureID1)
|
if (TextureID1)
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID1); // nawierzchnia
|
TextureManager.Bind( TextureID1 ); // nawierzchnia
|
||||||
for (i = 0; i < seg; ++i)
|
for (i = 0; i < seg; ++i)
|
||||||
{
|
{
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, iPtr, 4);
|
glDrawArrays(GL_TRIANGLE_STRIP, iPtr, 4);
|
||||||
@@ -2567,7 +2567,7 @@ void TTrack::RaRenderVBO(int iPtr)
|
|||||||
}
|
}
|
||||||
if (TextureID2)
|
if (TextureID2)
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, TextureID2); // pobocze
|
TextureManager.Bind( TextureID2 ); // pobocze
|
||||||
for (i = 0; i < seg; ++i)
|
for (i = 0; i < seg; ++i)
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, iPtr + 6 * i, 6);
|
glDrawArrays(GL_TRIANGLE_STRIP, iPtr + 6 * i, 6);
|
||||||
iPtr += 6 * seg; // pominięcie lewego pobocza
|
iPtr += 6 * seg; // pominięcie lewego pobocza
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "logs.h"
|
#include "logs.h"
|
||||||
#include "mctools.h"
|
#include "mctools.h"
|
||||||
#include "TractionPower.h"
|
#include "TractionPower.h"
|
||||||
|
#include "Texture.h"
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
/*
|
/*
|
||||||
@@ -115,7 +116,7 @@ void TTraction::Optimize()
|
|||||||
uiDisplayList = glGenLists(1);
|
uiDisplayList = glGenLists(1);
|
||||||
glNewList(uiDisplayList, GL_COMPILE);
|
glNewList(uiDisplayList, GL_COMPILE);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
TextureManager.Bind(0);
|
||||||
// glColor3ub(0,0,0); McZapkie: to do render
|
// glColor3ub(0,0,0); McZapkie: to do render
|
||||||
|
|
||||||
// glPushMatrix();
|
// glPushMatrix();
|
||||||
@@ -462,7 +463,7 @@ void TTraction::RenderVBO(float mgn, int iPtr)
|
|||||||
{ // renderowanie z użyciem VBO
|
{ // renderowanie z użyciem VBO
|
||||||
if (Wires != 0 && !TestFlag(DamageFlag, 128)) // rysuj jesli sa druty i nie zerwana
|
if (Wires != 0 && !TestFlag(DamageFlag, 128)) // rysuj jesli sa druty i nie zerwana
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
TextureManager.Bind(0);
|
||||||
glDisable(GL_LIGHTING); // aby nie używało wektorów normalnych do kolorowania
|
glDisable(GL_LIGHTING); // aby nie używało wektorów normalnych do kolorowania
|
||||||
glColor4f(0, 0, 0, 1); // jak nieznany kolor to czarne nieprzezroczyste
|
glColor4f(0, 0, 0, 1); // jak nieznany kolor to czarne nieprzezroczyste
|
||||||
if (!Global::bSmoothTraction)
|
if (!Global::bSmoothTraction)
|
||||||
|
|||||||
14
World.cpp
14
World.cpp
@@ -479,8 +479,8 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
|
|||||||
glDisable(GL_DEPTH_TEST); // Disables depth testing
|
glDisable(GL_DEPTH_TEST); // Disables depth testing
|
||||||
glColor3f(3.0f, 3.0f, 3.0f);
|
glColor3f(3.0f, 3.0f, 3.0f);
|
||||||
|
|
||||||
auto logo = TTexturesManager.GetTextureId( "logo", szTexturePath, 6 );
|
auto logo = TextureManager.GetTextureId( "logo", szTexturePath, 6 );
|
||||||
glBindTexture(GL_TEXTURE_2D, logo); // Select our texture
|
TextureManager.Bind(logo); // Select our texture
|
||||||
|
|
||||||
glBegin(GL_QUADS); // Drawing using triangles
|
glBegin(GL_QUADS); // Drawing using triangles
|
||||||
glTexCoord2f(0.0f, 0.0f);
|
glTexCoord2f(0.0f, 0.0f);
|
||||||
@@ -663,9 +663,9 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
|
|||||||
// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); //{Texture blends with object
|
// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); //{Texture blends with object
|
||||||
// background}
|
// background}
|
||||||
if (Global::bOldSmudge == true)
|
if (Global::bOldSmudge == true)
|
||||||
light = TTexturesManager.GetTextureId( "smuga.tga", szTexturePath );
|
light = TextureManager.GetTextureId( "smuga.tga", szTexturePath );
|
||||||
else
|
else
|
||||||
light = TTexturesManager.GetTextureId( "smuga2.tga", szTexturePath );
|
light = TextureManager.GetTextureId( "smuga2.tga", szTexturePath );
|
||||||
// Camera.Reset();
|
// Camera.Reset();
|
||||||
Timer::ResetTimers();
|
Timer::ResetTimers();
|
||||||
WriteLog( "Load time: " +
|
WriteLog( "Load time: " +
|
||||||
@@ -1584,7 +1584,7 @@ TWorld::Render_Cab() {
|
|||||||
glDisable( GL_LIGHTING );
|
glDisable( GL_LIGHTING );
|
||||||
glDisable( GL_FOG );
|
glDisable( GL_FOG );
|
||||||
glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||||
glBindTexture( GL_TEXTURE_2D, light ); // Select our texture
|
TextureManager.Bind( light ); // Select our texture
|
||||||
glBegin( GL_QUADS );
|
glBegin( GL_QUADS );
|
||||||
float fSmudge =
|
float fSmudge =
|
||||||
dynamic->MoverParameters->DimHalf.y + 7; // gdzie zaczynać smugę
|
dynamic->MoverParameters->DimHalf.y + 7; // gdzie zaczynać smugę
|
||||||
@@ -1623,7 +1623,7 @@ TWorld::Render_Cab() {
|
|||||||
glDisable( GL_LIGHTING );
|
glDisable( GL_LIGHTING );
|
||||||
glDisable( GL_FOG );
|
glDisable( GL_FOG );
|
||||||
//glColor4f(0.15f, 0.15f, 0.15f, 0.25f);
|
//glColor4f(0.15f, 0.15f, 0.15f, 0.25f);
|
||||||
glBindTexture( GL_TEXTURE_2D, light ); // Select our texture
|
TextureManager.Bind( light ); // Select our texture
|
||||||
//float ddl = (0.15*Global::diffuseDayLight[0]+0.295*Global::diffuseDayLight[1]+0.055*Global::diffuseDayLight[2]); //0.24:0
|
//float ddl = (0.15*Global::diffuseDayLight[0]+0.295*Global::diffuseDayLight[1]+0.055*Global::diffuseDayLight[2]); //0.24:0
|
||||||
glBegin( GL_QUADS );
|
glBegin( GL_QUADS );
|
||||||
float fSmudge = dynamic->MoverParameters->DimHalf.y + 7; // gdzie zaczynać smugę
|
float fSmudge = dynamic->MoverParameters->DimHalf.y + 7; // gdzie zaczynać smugę
|
||||||
@@ -1922,7 +1922,7 @@ TWorld::Render_UI() {
|
|||||||
SetWindowText( hWnd, Controlled->MoverParameters->Name.c_str() );
|
SetWindowText( hWnd, Controlled->MoverParameters->Name.c_str() );
|
||||||
else
|
else
|
||||||
SetWindowText( hWnd, Global::SceneryFile.c_str() ); // nazwa scenerii
|
SetWindowText( hWnd, Global::SceneryFile.c_str() ); // nazwa scenerii
|
||||||
glBindTexture( GL_TEXTURE_2D, 0 );
|
TextureManager.Bind( 0 );
|
||||||
glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
|
glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glTranslatef( 0.0f, 0.0f, -0.50f );
|
glTranslatef( 0.0f, 0.0f, -0.50f );
|
||||||
|
|||||||
Reference in New Issue
Block a user