mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-21 22:59:19 +02:00
merge tmj
This commit is contained in:
127
Texture.h
127
Texture.h
@@ -12,49 +12,90 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include <string>
|
||||
#include "GL/glew.h"
|
||||
|
||||
enum class resource_state {
|
||||
none,
|
||||
loading,
|
||||
good,
|
||||
failed
|
||||
};
|
||||
|
||||
struct opengl_texture {
|
||||
|
||||
// methods
|
||||
void load();
|
||||
void create();
|
||||
// members
|
||||
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 traits; // requested texture attributes: wrapping modes etc
|
||||
std::string name; // name of the texture source file
|
||||
|
||||
private:
|
||||
// methods
|
||||
void load_BMP();
|
||||
void load_DDS();
|
||||
void load_TEX();
|
||||
void load_TGA();
|
||||
void set_filtering();
|
||||
|
||||
// members
|
||||
std::vector<char> data; // texture data
|
||||
resource_state data_state{ resource_state::none }; // current state of texture data
|
||||
int data_width{ 0 },
|
||||
data_height{ 0 },
|
||||
data_mapcount{ 0 };
|
||||
GLuint data_format{ 0 },
|
||||
data_components{ 0 };
|
||||
/*
|
||||
//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;
|
||||
};
|
||||
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
|
||||
*/
|
||||
|
||||
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;
|
||||
};
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class texture_manager {
|
||||
|
||||
private:
|
||||
typedef std::vector<opengl_texture> opengltexture_array;
|
||||
|
||||
public:
|
||||
// typedef opengltexture_array::size_type size_type;
|
||||
typedef int size_type;
|
||||
|
||||
texture_manager();
|
||||
~texture_manager() { Free(); }
|
||||
|
||||
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 ); }
|
||||
void Init();
|
||||
void Free();
|
||||
|
||||
private:
|
||||
typedef std::unordered_map<std::string, size_type> index_map;
|
||||
/*
|
||||
opengltexture_array::size_type LoadFromFile(std::string name, int filter = -1);
|
||||
*/
|
||||
/*
|
||||
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;
|
||||
size_type m_activetexture{ 0 }; // last i.e. currently bound texture
|
||||
};
|
||||
|
||||
extern texture_manager TextureManager;
|
||||
Reference in New Issue
Block a user