Raise clang-format column size, make std::span support in opengl.hpp version-dependent

This commit is contained in:
wheremyfoodat 2023-06-16 22:06:59 +03:00
parent 553d23974a
commit 936302da2a
4 changed files with 42 additions and 20 deletions

View file

@ -1,6 +1,6 @@
BasedOnStyle: Google BasedOnStyle: Google
IndentWidth: 4 IndentWidth: 4
ColumnLimit: 120 ColumnLimit: 150
AccessModifierOffset: -2 AccessModifierOffset: -2
TabWidth: 4 TabWidth: 4
NamespaceIndentation: All NamespaceIndentation: All

View file

@ -23,7 +23,6 @@
#include <functional> #include <functional>
#include <initializer_list> #include <initializer_list>
#include <iostream> #include <iostream>
#include <span>
#include <stdexcept> #include <stdexcept>
#include <string_view> #include <string_view>
#include <type_traits> #include <type_traits>
@ -31,6 +30,19 @@
#include "gl3w.h" #include "gl3w.h"
// Check if we have C++20. If yes, we can add C++20 std::span support
#ifdef _MSVC_LANG // MSVC does not properly define __cplusplus without a compiler flag...
#if _MSVC_LANG >= 202002L
#define OPENGL_HAVE_CPP20
#endif
#elif __cplusplus >= 202002L
#define OPENGL_HAVE_CPP20
#endif // MSVC_LANG
#ifdef OPENGL_HAVE_CPP20
#include <span>
#endif
// Uncomment the following define if you want GL objects to automatically free themselves when their lifetime ends // Uncomment the following define if you want GL objects to automatically free themselves when their lifetime ends
// #define OPENGL_DESTRUCTORS // #define OPENGL_DESTRUCTORS
@ -391,15 +403,28 @@ namespace OpenGL {
// Reallocates the buffer on every call. Prefer the sub version if possible. // Reallocates the buffer on every call. Prefer the sub version if possible.
template <typename VertType> template <typename VertType>
void bufferVerts(std::span<const VertType> vertices, GLenum usage = GL_DYNAMIC_DRAW) { void bufferVerts(VertType* vertices, int vertCount, GLenum usage = GL_DYNAMIC_DRAW) {
glBufferData(GL_ARRAY_BUFFER, sizeof(VertType) * vertices.size(), vertices.data(), usage); glBufferData(GL_ARRAY_BUFFER, sizeof(VertType) * vertCount, vertices, usage);
} }
// Only use if you used createFixedSize // Only use if you used createFixedSize
template <typename VertType>
void bufferVertsSub(VertType* vertices, int vertCount, GLintptr offset = 0) {
glBufferSubData(GL_ARRAY_BUFFER, offset, sizeof(VertType) * vertCount, vertices);
}
// If C++20 is available, add overloads that take std::span instead of raw pointers
#ifdef OPENGL_HAVE_CPP20
template <typename VertType>
void bufferVerts(std::span<const VertType> vertices, GLenum usage = GL_DYNAMIC_DRAW) {
glBufferData(GL_ARRAY_BUFFER, sizeof(VertType) * vertices.size(), vertices.data(), usage);
}
template <typename VertType> template <typename VertType>
void bufferVertsSub(std::span<const VertType> vertices, GLintptr offset = 0) { void bufferVertsSub(std::span<const VertType> vertices, GLintptr offset = 0) {
glBufferSubData(GL_ARRAY_BUFFER, offset, sizeof(VertType) * vertices.size(), vertices.data()); glBufferSubData(GL_ARRAY_BUFFER, offset, sizeof(VertType) * vertices.size(), vertices.data());
} }
#endif
}; };
enum DepthFunc { enum DepthFunc {

View file

@ -66,7 +66,7 @@ class Renderer {
void setupBlending(); void setupBlending();
void bindDepthBuffer(); void bindDepthBuffer();
public: public:
Renderer(GPU& gpu, const std::array<u32, regNum>& internalRegs) : gpu(gpu), regs(internalRegs) {} Renderer(GPU& gpu, const std::array<u32, regNum>& internalRegs) : gpu(gpu), regs(internalRegs) {}
void reset(); void reset();
@ -74,9 +74,7 @@ public:
void initGraphicsContext(); // Initialize graphics context void initGraphicsContext(); // Initialize graphics context
void getGraphicsContext(); // Set up graphics context for rendering void getGraphicsContext(); // Set up graphics context for rendering
void clearBuffer(u32 startAddress, u32 endAddress, u32 value, u32 control); // Clear a GPU buffer in VRAM void clearBuffer(u32 startAddress, u32 endAddress, u32 value, u32 control); // Clear a GPU buffer in VRAM
void displayTransfer( void displayTransfer(u32 inputAddr, u32 outputAddr, u32 inputSize, u32 outputSize, u32 flags); // Perform display transfer
u32 inputAddr, u32 outputAddr, u32 inputSize, u32 outputSize, u32 flags
); // Perform display transfer
void drawVertices(OpenGL::Primitives primType, std::span<const Vertex> vertices); // Draw the given vertices void drawVertices(OpenGL::Primitives primType, std::span<const Vertex> vertices); // Draw the given vertices
void setFBSize(u32 width, u32 height) { void setFBSize(u32 width, u32 height) {

View file

@ -213,7 +213,6 @@ void Renderer::initGraphicsContext() {
void Renderer::getGraphicsContext() { void Renderer::getGraphicsContext() {
OpenGL::disableScissor(); OpenGL::disableScissor();
OpenGL::setViewport(400, 240);
vbo.bind(); vbo.bind();
vao.bind(); vao.bind();