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

introduced opengl texture object

This commit is contained in:
tmj-fstate
2017-02-11 21:02:21 +01:00
parent 1b6339e482
commit 22245a8801
17 changed files with 272 additions and 262 deletions

View File

@@ -12,49 +12,56 @@ http://mozilla.org/MPL/2.0/.
#include <string>
#include "opengl/glew.h"
struct opengl_texture {
GLuint id{ -1 }; // associated GL resource
bool has_alpha{ false }; // indicates the texture has alpha channel
bool is_ready{ false }; // indicates the texture was processed and is ready for use
std::string name; // name of the texture source file
std::vector<char> data; // texture data
/*std::atomic<bool>*/ bool is_loaded{ false }; // indicates the texture data was loaded and can be processed
/*std::atomic<bool>*/ bool is_good{ false }; // indicates the texture data was retrieved without errors
};
class texture_manager {
private:
typedef std::vector<opengl_texture> opengltexture_array;
public:
typedef opengltexture_array::size_type size_type;
~texture_manager() { Free(); }
size_type GetTextureId( std::string Filename, std::string const &Dir, int const Filter = -1 );
opengl_texture &Texture( size_type const Id ) { return m_textures.at( Id ); }
void Init();
void Free();
private:
typedef std::unordered_map<std::string, size_type> index_map;
/*
//Ra: miejsce umieszczenia tego jest deczko bezsensowne
void glDebug()
{//logowanie błędów OpenGL
GLenum err;
if (Global::iErorrCounter==326) //tu wpisz o 1 mniej niz wartość, przy której się wyłożyło
Global::iErorrCounter=Global::iErorrCounter+0; //do zastawiania pułapki przed błędnym kodem
while ((err=glGetError())!=GL_NO_ERROR) //dalej jest pułapka po wykonaniu błędnego kodu
WriteLog("OpenGL error found: "+AnsiString(err)+", step:"+AnsiString(Global::iErorrCounter));
++Global::iErorrCounter;
};
opengltexture_array::size_type LoadFromFile(std::string name, int filter = -1);
*/
class TTexturesManager
{
public:
static void Init();
static void Free();
static GLuint GetTextureID(char *dir, char *where, std::string name, int filter = -1);
static bool GetAlpha(GLuint ID); // McZapkie-141203: czy tekstura ma polprzeroczystosc
static std::string GetName(GLuint id);
private:
typedef std::pair<GLuint, bool> AlphaValue;
typedef std::map<std::string, GLuint> Names;
typedef std::map<GLuint, bool> Alphas;
static Names::iterator LoadFromFile(std::string name, int filter = -1);
static AlphaValue LoadBMP(std::string const &fileName);
static AlphaValue LoadTEX(std::string fileName);
static AlphaValue LoadTGA(std::string fileName, int filter = -1);
static AlphaValue LoadDDS(std::string fileName, int filter = -1);
static void SetFiltering(int filter);
static void SetFiltering(bool alpha, bool hash);
static GLuint CreateTexture(GLubyte *buff, GLint bpp, int width, int height, bool bHasAlpha,
bool bHash, bool bDollar = true, int filter = -1);
static Names _names;
static Alphas _alphas;
// std::list<TTexture> Textures;
/*
bool LoadBMP( std::string const &fileName);
bool LoadTEX( std::string fileName );
bool LoadTGA( std::string fileName, int filter = -1 );
bool LoadDDS( std::string fileName, int filter = -1 );
*/
// checks whether specified texture is in the texture bank. returns texture id, or npos.
size_type find_in_databank( std::string const &Texturename );
// checks whether specified file exists. returns name of the located file, or empty string.
std::string find_on_disk( std::string const &Texturename );
/*
void SetFiltering(int filter);
void SetFiltering(bool alpha, bool hash);
GLuint CreateTexture(GLubyte *buff, GLint bpp, int width, int height, bool bHasAlpha,
bool bHash, bool bDollar = true, int filter = -1);
*/
static const size_type npos{ 0 }; // should be -1, but the rest of the code uses -1 for something else
opengltexture_array m_textures;
index_map m_texturemappings;
};
//---------------------------------------------------------------------------
extern texture_manager TTexturesManager;