summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/shader.cpp2
-rw-r--r--gfx/image.cpp6
-rw-r--r--gfx/image.h2
-rw-r--r--gfx/manualCameraController.cpp6
-rw-r--r--gfx/models/mesh.cpp11
-rw-r--r--gfx/models/obj.h2
-rw-r--r--gfx/models/obj.impl.cpp6
-rw-r--r--gfx/models/texture.cpp3
-rw-r--r--gfx/window.cpp5
9 files changed, 25 insertions, 18 deletions
diff --git a/gfx/gl/shader.cpp b/gfx/gl/shader.cpp
index b97d6fc..14cf404 100644
--- a/gfx/gl/shader.cpp
+++ b/gfx/gl/shader.cpp
@@ -76,7 +76,7 @@ Shader::setUniform(const GLchar * uniform, glm::vec3 v) const
void
Shader::setModel(const Location & loc, Program pid) const
{
- auto & prog = programs[(int)pid];
+ auto & prog = programs[static_cast<std::size_t>(pid)];
glUseProgram(prog.m_program);
if (prog.model_uniform >= 0) {
const auto model {glm::translate(loc.pos) * rotate_ypr(loc.rot)};
diff --git a/gfx/image.cpp b/gfx/image.cpp
index 41c59a2..e3e3b01 100644
--- a/gfx/image.cpp
+++ b/gfx/image.cpp
@@ -6,7 +6,11 @@
Image::Image(const char * fileName, int flags) : width {}, height {}, numComponents {}
{
stbi_set_flip_vertically_on_load(1);
- unsigned char * bytes = stbi_load(fileName, &width, &height, &numComponents, flags);
+ int w, h, nc;
+ unsigned char * bytes = stbi_load(fileName, &w, &h, &nc, flags);
+ width = static_cast<unsigned int>(w);
+ height = static_cast<unsigned int>(h);
+ numComponents = static_cast<unsigned int>(nc);
if (!bytes) {
throw std::runtime_error {std::string {"Unable to load image: "} + fileName};
diff --git a/gfx/image.h b/gfx/image.h
index d43737f..23e9a9b 100644
--- a/gfx/image.h
+++ b/gfx/image.h
@@ -14,7 +14,7 @@ public:
NO_COPY(Image);
NO_MOVE(Image);
- int width, height, numComponents;
+ unsigned int width, height, numComponents;
std::span<unsigned char> data;
};
diff --git a/gfx/manualCameraController.cpp b/gfx/manualCameraController.cpp
index 022fb72..cacf6ac 100644
--- a/gfx/manualCameraController.cpp
+++ b/gfx/manualCameraController.cpp
@@ -43,8 +43,8 @@ ManualCameraController::handleInput(SDL_Event & e)
case SDL_MOUSEMOTION:
if (mrb) {
if (ctrl) {
- direction -= 0.01F * (float)e.motion.xrel;
- pitch = std::clamp(pitch - 0.01F * (float)e.motion.yrel, 0.1F, half_pi);
+ direction -= 0.01F * static_cast<float>(e.motion.xrel);
+ pitch = std::clamp(pitch - 0.01F * static_cast<float>(e.motion.yrel), 0.1F, half_pi);
}
else {
focus += rotate_flat(-direction) * glm::vec2 {-e.motion.xrel, e.motion.yrel};
@@ -52,7 +52,7 @@ ManualCameraController::handleInput(SDL_Event & e)
}
return true;
case SDL_MOUSEWHEEL:
- dist = std::clamp(dist - (float)e.wheel.y * 4.F, 5.F, 200.F);
+ dist = std::clamp(dist - static_cast<float>(e.wheel.y) * 4.F, 5.F, 200.F);
break;
}
return false;
diff --git a/gfx/models/mesh.cpp b/gfx/models/mesh.cpp
index 52ce6bb..82eafbc 100644
--- a/gfx/models/mesh.cpp
+++ b/gfx/models/mesh.cpp
@@ -2,10 +2,10 @@
#include "vertex.hpp"
#include <cstddef>
-#define offset_ptr(T, m) (((char *)1) + offsetof(T, m) - 1)
+#define offset_ptr(T, m) ((reinterpret_cast<char *>(1)) + offsetof(T, m) - 1)
Mesh::Mesh(const std::span<const Vertex> vertices, const std::span<const unsigned int> indices, GLenum m) :
- m_vertexArrayObject {}, m_vertexArrayBuffers {}, m_numIndices {(GLsizei)indices.size()}, mode {m}
+ m_vertexArrayObject {}, m_vertexArrayBuffers {}, m_numIndices {static_cast<GLsizei>(indices.size())}, mode {m}
{
glGenVertexArrays(1, &m_vertexArrayObject);
glBindVertexArray(m_vertexArrayObject);
@@ -13,7 +13,8 @@ Mesh::Mesh(const std::span<const Vertex> vertices, const std::span<const unsigne
glGenBuffers(2, m_vertexArrayBuffers.data());
glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffers[0]);
- glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)(sizeof(Vertex) * vertices.size()), vertices.data(), GL_STATIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, static_cast<GLsizeiptr>(sizeof(Vertex) * vertices.size()), vertices.data(),
+ GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), offset_ptr(Vertex, pos));
@@ -25,8 +26,8 @@ Mesh::Mesh(const std::span<const Vertex> vertices, const std::span<const unsigne
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), offset_ptr(Vertex, normal));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vertexArrayBuffers[1]);
- glBufferData(
- GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)(sizeof(indices[0]) * indices.size()), indices.data(), GL_STATIC_DRAW);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, static_cast<GLsizeiptr>(sizeof(indices[0]) * indices.size()), indices.data(),
+ GL_STATIC_DRAW);
glBindVertexArray(0);
}
diff --git a/gfx/models/obj.h b/gfx/models/obj.h
index 9a2a30e..6db16c0 100644
--- a/gfx/models/obj.h
+++ b/gfx/models/obj.h
@@ -25,7 +25,7 @@ public:
std::vector<glm::vec4> vertices;
std::vector<glm::vec3> texCoords;
std::vector<glm::vec3> normals;
- using FaceElement = glm::vec<3, int>;
+ using FaceElement = glm::vec<3, unsigned int>;
using Face = std::vector<FaceElement>;
using Faces = std::vector<Face>;
using Object = std::pair<std::string, Faces>;
diff --git a/gfx/models/obj.impl.cpp b/gfx/models/obj.impl.cpp
index 02996da..745689e 100644
--- a/gfx/models/obj.impl.cpp
+++ b/gfx/models/obj.impl.cpp
@@ -52,15 +52,15 @@ ObjParser::createMeshData() const
const auto & fe {face[idx]};
if (const auto existing = std::find(vertexOrder.begin(), vertexOrder.end(), fe);
existing != vertexOrder.end()) {
- indices.push_back(std::distance(vertexOrder.begin(), existing));
+ indices.push_back(static_cast<unsigned int>(std::distance(vertexOrder.begin(), existing)));
}
else {
- indices.push_back(overtices.size());
+ indices.push_back(static_cast<unsigned int>(overtices.size()));
overtices.emplace_back(vertices[fe.x - 1], texCoords[fe.y - 1], -normals[fe.z - 1]);
vertexOrder.emplace_back(fe);
}
};
- f(0);
+ f(0U);
f(idx);
f(idx - 1);
}
diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp
index 898f495..cd275e8 100644
--- a/gfx/models/texture.cpp
+++ b/gfx/models/texture.cpp
@@ -18,7 +18,8 @@ Texture::Texture(const std::filesystem::path & fileName) : m_texture {}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width, tex.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.data.data());
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, static_cast<GLsizei>(tex.width), static_cast<GLsizei>(tex.height), 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, tex.data.data());
}
Texture::~Texture()
diff --git a/gfx/window.cpp b/gfx/window.cpp
index f7bb125..2e3c843 100644
--- a/gfx/window.cpp
+++ b/gfx/window.cpp
@@ -3,8 +3,9 @@
#include <stdexcept>
Window::Window(int width, int height, const std::string & title) :
- m_window {m_window.create(SDL_CreateWindow, SDL_DestroyWindow, title.c_str(), SDL_WINDOWPOS_CENTERED,
- SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL)},
+ m_window {m_window.create(SDL_CreateWindow, SDL_DestroyWindow, title.c_str(),
+ static_cast<int>(SDL_WINDOWPOS_CENTERED), static_cast<int>(SDL_WINDOWPOS_CENTERED), width, height,
+ static_cast<Uint32>(SDL_WINDOW_OPENGL))},
m_glContext {m_glContext.create(SDL_GL_CreateContext, SDL_GL_DeleteContext, m_window)}
{
if (glewInit() != GLEW_OK) {