diff options
Diffstat (limited to 'gfx')
-rw-r--r-- | gfx/manualCameraController.cpp | 6 | ||||
-rw-r--r-- | gfx/models/mesh.cpp | 16 | ||||
-rw-r--r-- | gfx/models/mesh.h | 3 |
3 files changed, 14 insertions, 11 deletions
diff --git a/gfx/manualCameraController.cpp b/gfx/manualCameraController.cpp index 21eefc8..268920a 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 * e.motion.xrel; - pitch = std::clamp(pitch - 0.01F * e.motion.yrel, 0.1F, half_pi); + direction -= 0.01F * (float)e.motion.xrel; + pitch = std::clamp(pitch - 0.01F * (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 - e.wheel.y * 4.F, 5.F, 200.F); + dist = std::clamp(dist - (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 0834394..52ce6bb 100644 --- a/gfx/models/mesh.cpp +++ b/gfx/models/mesh.cpp @@ -1,8 +1,11 @@ #include "mesh.h"
#include "vertex.hpp"
+#include <cstddef>
+
+#define offset_ptr(T, m) (((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 {indices.size()}, mode {m}
+ m_vertexArrayObject {}, m_vertexArrayBuffers {}, m_numIndices {(GLsizei)indices.size()}, mode {m}
{
glGenVertexArrays(1, &m_vertexArrayObject);
glBindVertexArray(m_vertexArrayObject);
@@ -10,19 +13,20 @@ 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, sizeof(Vertex) * vertices.size(), vertices.data(), GL_STATIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)(sizeof(Vertex) * vertices.size()), vertices.data(), GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, pos));
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), offset_ptr(Vertex, pos));
glEnableVertexAttribArray(1);
- glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, texCoord));
+ glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), offset_ptr(Vertex, texCoord));
glEnableVertexAttribArray(2);
- glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, normal));
+ 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, sizeof(indices[0]) * indices.size(), indices.data(), GL_STATIC_DRAW);
+ glBufferData(
+ GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)(sizeof(indices[0]) * indices.size()), indices.data(), GL_STATIC_DRAW);
glBindVertexArray(0);
}
diff --git a/gfx/models/mesh.h b/gfx/models/mesh.h index 8825aa2..c9f1204 100644 --- a/gfx/models/mesh.h +++ b/gfx/models/mesh.h @@ -3,7 +3,6 @@ #include <GL/glew.h>
#include <array>
-#include <cstddef>
#include <memory>
#include <span>
#include <special_members.hpp>
@@ -27,7 +26,7 @@ private: GLuint m_vertexArrayObject;
std::array<GLuint, NUM_BUFFERS> m_vertexArrayBuffers;
- size_t m_numIndices;
+ GLsizei m_numIndices;
GLenum mode;
};
using MeshPtr = std::shared_ptr<const Mesh>;
|