summaryrefslogtreecommitdiff
path: root/gfx/models
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/models')
-rw-r--r--gfx/models/texture.cpp13
-rw-r--r--gfx/models/texture.h6
-rw-r--r--gfx/models/tga.h3
-rw-r--r--gfx/models/vertex.h17
4 files changed, 25 insertions, 14 deletions
diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp
index b7f1bee..35f8d35 100644
--- a/gfx/models/texture.cpp
+++ b/gfx/models/texture.cpp
@@ -1,4 +1,5 @@
#include "texture.h"
+#include "config/types.h"
#include "glArrays.h"
#include "tga.h"
#include <cache.h>
@@ -60,10 +61,10 @@ Texture::bind(GLenum unit) const
glBindTexture(type, m_texture);
}
-glm::ivec2
+TextureAbsCoord
Texture::getSize(const glTexture & texture)
{
- glm::ivec2 size;
+ TextureAbsCoord size;
glGetTextureLevelParameteriv(texture, 0, GL_TEXTURE_WIDTH, &size.x);
glGetTextureLevelParameteriv(texture, 0, GL_TEXTURE_HEIGHT, &size.y);
return size;
@@ -103,6 +104,12 @@ Texture::save(const glTexture & texture, const char * path)
}
void
+Texture::savePosition(const glTexture & texture, const char * path)
+{
+ save(texture, GL_BGR_INTEGER, GL_UNSIGNED_BYTE, 3, path, 2);
+}
+
+void
Texture::saveDepth(const glTexture & texture, const char * path)
{
save(texture, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 1, path, 3);
@@ -136,7 +143,7 @@ TextureAtlas::bind(GLenum unit) const
}
GLuint
-TextureAtlas::add(glm::ivec2 position, glm::ivec2 size, void * data, TextureOptions to)
+TextureAtlas::add(TextureAbsCoord position, TextureAbsCoord size, void * data, TextureOptions to)
{
glTextureSubImage2D(m_texture, 0, position.x, position.y, size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, data);
diff --git a/gfx/models/texture.h b/gfx/models/texture.h
index 1b66c64..5d40b39 100644
--- a/gfx/models/texture.h
+++ b/gfx/models/texture.h
@@ -1,5 +1,6 @@
#pragma once
+#include "config/types.h"
#include <cache.h>
#include <filesystem>
#include <glArrays.h>
@@ -39,10 +40,11 @@ public:
static void save(const glTexture &, const char * path);
static void saveDepth(const glTexture &, const char * path);
static void saveNormal(const glTexture &, const char * path);
+ static void savePosition(const glTexture &, const char * path);
protected:
static void save(const glTexture &, GLenum, GLenum, uint8_t channels, const char * path, uint8_t tgaFormat);
- static glm::ivec2 getSize(const glTexture &);
+ static TextureAbsCoord getSize(const glTexture &);
glTexture m_texture;
GLenum type;
@@ -53,7 +55,7 @@ public:
TextureAtlas(GLsizei width, GLsizei height, GLuint count);
void bind(GLenum unit = GL_TEXTURE0) const override;
- GLuint add(glm::ivec2 position, glm::ivec2 size, void * data, TextureOptions = {});
+ GLuint add(TextureAbsCoord position, TextureAbsCoord size, void * data, TextureOptions = {});
private:
glTexture m_atlas;
diff --git a/gfx/models/tga.h b/gfx/models/tga.h
index 52db220..3d072fb 100644
--- a/gfx/models/tga.h
+++ b/gfx/models/tga.h
@@ -4,10 +4,11 @@
#include <glm/vec2.hpp>
struct TGAHead {
+ using XY = glm::vec<2, uint16_t>;
uint8_t idLength {}, colorMapType {}, format {};
uint16_t __attribute__((packed)) colorMapFirst {}, colorMapLength {};
uint8_t colorMapEntrySize {};
- glm::vec<2, uint16_t> origin {}, size {};
+ XY origin {}, size {};
uint8_t pixelDepth {};
uint8_t descriptor {};
};
diff --git a/gfx/models/vertex.h b/gfx/models/vertex.h
index 0464ea7..3c6215f 100644
--- a/gfx/models/vertex.h
+++ b/gfx/models/vertex.h
@@ -1,23 +1,24 @@
#pragma once
+#include "config/types.h"
#include <glad/gl.h>
-#include <glm/glm.hpp>
class Vertex {
public:
#ifndef __cpp_aggregate_paren_init
- constexpr Vertex(glm::vec3 pos, glm::vec2 texCoord, glm::vec3 normal, glm::vec4 colour = {}, GLuint material = 0) :
- pos {std::move(pos)}, texCoord {std::move(texCoord)}, normal {std::move(normal)}, colour {std::move(colour)},
- material {material}
+ constexpr Vertex(
+ RelativePosition3D pos, TextureRelCoord texCoord, Normal3D normal, RGBA colour = {}, GLuint material = 0) :
+ pos {std::move(pos)},
+ texCoord {std::move(texCoord)}, normal {std::move(normal)}, colour {std::move(colour)}, material {material}
{
}
#endif
bool operator==(const Vertex &) const = default;
- glm::vec3 pos;
- glm::vec2 texCoord;
- glm::vec3 normal;
- glm::vec4 colour {};
+ RelativePosition3D pos {};
+ TextureRelCoord texCoord {};
+ Normal3D normal {};
+ RGBA colour {};
GLuint material {};
};