5 #include <ThirdParty/glew-2.1.0/include/GL/glew.h> 9 OpenGLTexture::OpenGLTexture(
const eastl::string& filename,
int desiredChannels) : Texture(filename, desiredChannels)
11 eastl::string baseLocation =
"Resources/Textures/";
12 baseLocation.append(filename);
13 stbi_uc* textureData = stbi_load(
15 baseLocation.c_str() :
16 "Resources/Textures/default.png", &width, &height, &channels, STBI_rgb_alpha);
17 OpenGLTexture::CreateTextureWithData(textureData,
true);
18 stbi_image_free(textureData);
21 OpenGLTexture::OpenGLTexture(
int width,
int height) : Texture(width, height)
25 OpenGLTexture::~OpenGLTexture()
27 GLuint textureReference = GLuint(texture);
30 glDeleteTextures(1, &textureReference);
33 void OpenGLTexture::CreateTextureWithData(stbi_uc* data,
bool genMipMaps,
TextureDataSize bytes,
bool storage)
35 this->dataSize = bytes;
36 GLuint textureReference = GLuint(texture);
38 glDeleteTextures(1, &textureReference);
40 glGenTextures(1, &textureReference);
43 glBindTexture(GL_TEXTURE_2D, textureReference);
48 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
50 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
53 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
56 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
57 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
64 type = GL_UNSIGNED_BYTE;
67 type = GL_UNSIGNED_BYTE;
70 type = GL_UNSIGNED_SHORT;
73 type = GL_UNSIGNED_SHORT;
76 type = GL_UNSIGNED_INT;
79 type = GL_UNSIGNED_INT;
82 type = GL_UNSIGNED_BYTE;
99 glGenerateMipmap(GL_TEXTURE_2D);
103 texture = uint64_t(textureReference);
static bool FileExists(const eastl::string &fileName)