summaryrefslogtreecommitdiff
path: root/gfx/models
diff options
context:
space:
mode:
authorDan Goodliffe <dan.goodliffe@octal.co.uk>2026-03-02 13:17:28 +0000
committerDan Goodliffe <dan.goodliffe@octal.co.uk>2026-03-02 13:17:28 +0000
commit64ede41ebaade64ad6705f7f55ca4a778a156481 (patch)
tree6d2fbc64cd28d272fe3f5bbf79ddd41ecc5e2626 /gfx/models
parentRefactor glArrays to better expose underlying types (diff)
downloadilt-64ede41ebaade64ad6705f7f55ca4a778a156481.tar.bz2
ilt-64ede41ebaade64ad6705f7f55ca4a778a156481.tar.xz
ilt-64ede41ebaade64ad6705f7f55ca4a778a156481.zip
Wrap up some low level texture operations in glTexture classHEADmain
Fixes previously hard coded billboard texture size.
Diffstat (limited to 'gfx/models')
-rw-r--r--gfx/models/texture.cpp23
-rw-r--r--gfx/models/texture.h3
2 files changed, 6 insertions, 20 deletions
diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp
index 3457fb5..46bdff8 100644
--- a/gfx/models/texture.cpp
+++ b/gfx/models/texture.cpp
@@ -1,6 +1,5 @@
#include "texture.h"
#include "config/types.h"
-#include "glArrays.h"
#include "tga.h"
#include <fcntl.h>
#include <filesystem.h>
@@ -41,7 +40,7 @@ Texture::Texture(GLsizei width, GLsizei height, TextureOptions to) : Texture {wi
Texture::Texture(GLsizei width, GLsizei height, const void * data, TextureOptions to) : type {to.type}
{
- glBindTexture(type, m_texture);
+ m_texture.bind(type);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameter(type, GL_TEXTURE_WRAP_S, TextureOptions::glMapMode(to.wrapU));
@@ -65,25 +64,14 @@ Texture::Texture(GLsizei width, GLsizei height, const void * data, TextureOption
void
Texture::bind(GLenum unit) const
{
- glActiveTexture(unit);
- glBindTexture(type, m_texture);
-}
-
-TextureDimensions
-Texture::getSize(const glTexture & texture)
-{
- TextureDimensions size {};
- glGetTextureLevelParameteriv(texture, 0, GL_TEXTURE_WIDTH, &size.x);
- glGetTextureLevelParameteriv(texture, 0, GL_TEXTURE_HEIGHT, &size.y);
- glGetTextureLevelParameteriv(texture, 0, GL_TEXTURE_DEPTH, &size.z);
- return size;
+ m_texture.bind(type, unit);
}
void
Texture::save(
const glTexture & texture, GLenum format, GLenum type, uint8_t channels, const char * path, uint8_t tgaFormat)
{
- const auto size = getSize(texture);
+ const auto size = texture.getSize();
const size_t dataSize = (static_cast<size_t>(size.x * size.y * size.z * channels));
const size_t fileSize = dataSize + sizeof(TGAHead);
@@ -132,7 +120,7 @@ Texture::saveNormal(const glTexture & texture, const char * path)
TextureAtlas::TextureAtlas(GLsizei width, GLsizei height, GLuint count) : Texture(width, height, nullptr, {})
{
- glBindTexture(GL_TEXTURE_RECTANGLE, m_atlas);
+ m_atlas.bind(GL_TEXTURE_RECTANGLE);
glTexParameter(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameter(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
@@ -147,8 +135,7 @@ void
TextureAtlas::bind(GLenum unit) const
{
Texture::bind(unit);
- glActiveTexture(unit + 1);
- glBindTexture(GL_TEXTURE_RECTANGLE, m_atlas);
+ m_atlas.bind(GL_TEXTURE_RECTANGLE, unit + 1);
}
GLuint
diff --git a/gfx/models/texture.h b/gfx/models/texture.h
index d8c3b29..03d296a 100644
--- a/gfx/models/texture.h
+++ b/gfx/models/texture.h
@@ -1,7 +1,7 @@
#pragma once
#include "config/types.h"
-#include "glArrays.h"
+#include "gfx/gl/glTexture.h"
#include "stdTypeDefs.h"
#include <filesystem>
#include <glm/fwd.hpp>
@@ -38,7 +38,6 @@ public:
static void saveDepth(const glTexture &, const char * path);
static void saveNormal(const glTexture &, const char * path);
static void savePosition(const glTexture &, const char * path);
- static TextureDimensions getSize(const glTexture &);
protected:
static void save(const glTexture &, GLenum, GLenum, uint8_t channels, const char * path, uint8_t tgaFormat);