From 239b3ab10b460da34c490a7e06a21c984e21ffb6 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 26 Nov 2021 20:21:12 +0000 Subject: Enable all Jason Turner recommended warnings --- gfx/gl/shader.cpp | 2 +- gfx/image.cpp | 6 +++++- gfx/image.h | 2 +- gfx/manualCameraController.cpp | 6 +++--- gfx/models/mesh.cpp | 11 ++++++----- gfx/models/obj.h | 2 +- gfx/models/obj.impl.cpp | 6 +++--- gfx/models/texture.cpp | 3 ++- gfx/window.cpp | 5 +++-- 9 files changed, 25 insertions(+), 18 deletions(-) (limited to 'gfx') 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(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(w); + height = static_cast(h); + numComponents = static_cast(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 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(e.motion.xrel); + pitch = std::clamp(pitch - 0.01F * static_cast(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(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 -#define offset_ptr(T, m) (((char *)1) + offsetof(T, m) - 1) +#define offset_ptr(T, m) ((reinterpret_cast(1)) + offsetof(T, m) - 1) Mesh::Mesh(const std::span vertices, const std::span indices, GLenum m) : - m_vertexArrayObject {}, m_vertexArrayBuffers {}, m_numIndices {(GLsizei)indices.size()}, mode {m} + m_vertexArrayObject {}, m_vertexArrayBuffers {}, m_numIndices {static_cast(indices.size())}, mode {m} { glGenVertexArrays(1, &m_vertexArrayObject); glBindVertexArray(m_vertexArrayObject); @@ -13,7 +13,8 @@ Mesh::Mesh(const std::span vertices, const std::span(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 vertices, const std::span(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 vertices; std::vector texCoords; std::vector normals; - using FaceElement = glm::vec<3, int>; + using FaceElement = glm::vec<3, unsigned int>; using Face = std::vector; using Faces = std::vector; using Object = std::pair; 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(std::distance(vertexOrder.begin(), existing))); } else { - indices.push_back(overtices.size()); + indices.push_back(static_cast(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(tex.width), static_cast(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 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(SDL_WINDOWPOS_CENTERED), static_cast(SDL_WINDOWPOS_CENTERED), width, height, + static_cast(SDL_WINDOW_OPENGL))}, m_glContext {m_glContext.create(SDL_GL_CreateContext, SDL_GL_DeleteContext, m_window)} { if (glewInit() != GLEW_OK) { -- cgit v1.2.3