OpenGL: Implement VAOs

This commit is contained in:
Lynix
2020-05-11 14:10:36 +02:00
parent 332278dded
commit fe5b70ae1c
8 changed files with 422 additions and 33 deletions

View File

@@ -0,0 +1,73 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - OpenGL Renderer"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_OPENGLRENDERER_OPENGLVAOCACHE_HPP
#define NAZARA_OPENGLRENDERER_OPENGLVAOCACHE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/OpenGLRenderer/Config.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp>
#include <array>
#include <memory>
#include <optional>
#include <unordered_map>
namespace Nz::GL
{
struct OpenGLVaoSetup
{
struct Attribs
{
GLuint vertexBuffer;
GLint size;
GLenum type;
GLboolean normalized;
GLsizei stride;
const void* pointer;
};
GLuint indexBuffer = 0;
std::array<std::optional<Attribs>, 16> vertexAttribs;
inline friend bool operator==(const OpenGLVaoSetup& lhs, const OpenGLVaoSetup& rhs);
};
struct OpenGLVaoSetupHasher
{
inline std::size_t operator()(const OpenGLVaoSetup& setup) const;
};
class Context;
class VertexArray;
class NAZARA_OPENGLRENDERER_API OpenGLVaoCache
{
friend Context;
public:
OpenGLVaoCache(Context& owner);
OpenGLVaoCache(const OpenGLVaoCache&) = delete;
OpenGLVaoCache(OpenGLVaoCache&&) = delete;
~OpenGLVaoCache();
void Clear();
const VertexArray& Get(const OpenGLVaoSetup& setup) const;
OpenGLVaoCache& operator=(const OpenGLVaoCache&) = delete;
OpenGLVaoCache& operator=(OpenGLVaoCache&&) = delete;
private:
void NotifyBufferDestruction(GLuint buffer);
mutable std::unordered_map<OpenGLVaoSetup, std::unique_ptr<VertexArray>, OpenGLVaoSetupHasher> m_vertexArrays;
Context& m_context;
};
}
#include <Nazara/OpenGLRenderer/OpenGLVaoCache.inl>
#endif