Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
OpenGLMemoryPoolBuffer.cpp
1/*
2Copyright (C) 2019,2021,2025,2026 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#include <fstream>
17#include <ostream>
18#include <regex>
19#include <array>
20#include <utility>
21#include <cassert>
22#include "aeongames/AeonEngine.hpp"
23#include "aeongames/CRC.hpp"
24#include "aeongames/Material.hpp"
25#include "aeongames/Vector2.hpp"
26#include "aeongames/Vector3.hpp"
27#include "aeongames/Vector4.hpp"
28#include "OpenGLMemoryPoolBuffer.hpp"
29#include "OpenGLRenderer.hpp"
30
31namespace AeonGames
32{
33 static GLint GetUniformBufferOffsetAlignment()
34 {
35 GLint alignment{};
36 glGetIntegerv ( GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &alignment );
37 return alignment;
38 }
39
40 OpenGLMemoryPoolBuffer::OpenGLMemoryPoolBuffer ( const OpenGLRenderer& aOpenGLRenderer, GLsizei aStackSize ) :
41 mOpenGLRenderer { aOpenGLRenderer },
42 mUniformBuffer { ( ( aStackSize - 1 ) | ( GetUniformBufferOffsetAlignment() - 1 ) ) + 1, GL_DYNAMIC_DRAW }
43 {
44 }
45
47 mOpenGLRenderer { aOpenGLRenderer },
48 mUniformBuffer {}
49 {
50 }
51
53 mOpenGLRenderer { aOpenGLMemoryPoolBuffer.mOpenGLRenderer },
54 mUniformBuffer { std::move ( aOpenGLMemoryPoolBuffer.mUniformBuffer ) }
55 {
56 std::swap ( mOffset, aOpenGLMemoryPoolBuffer.mOffset );
57 }
58
59 OpenGLMemoryPoolBuffer::~OpenGLMemoryPoolBuffer()
60 {
61 Finalize();
62 }
63
65 {
66 size_t offset = mOffset;
67 mOffset += ( ( aSize - 1 ) | ( GetUniformBufferOffsetAlignment() - 1 ) ) + 1;
68 if ( mOffset > mUniformBuffer.GetSize() )
69 {
70 mOffset = offset;
71 std::cout << LogLevel::Error << "Memory Pool Buffer cannot fulfill allocation request." << std::endl;
72 throw std::runtime_error ( "Memory Pool Buffer cannot fulfill allocation request." );
73 }
74 return BufferAccessor{this, offset, aSize};
75 }
76
78 {
79 mOffset = 0;
80 }
82 {
83 return mUniformBuffer;
84 }
85
86 void OpenGLMemoryPoolBuffer::Initialize ( GLsizei aStackSize )
87 {
88 mUniformBuffer.Initialize ( ( ( aStackSize - 1 ) | ( GetUniformBufferOffsetAlignment() - 1 ) ) + 1, GL_DYNAMIC_DRAW );
89 }
91 {
92 mUniformBuffer.Finalize();
93 }
94}
Header for the 3D vector class.
Header for the 4D vector class.
Provides access to a region within a memory pool buffer.
Abstract interface for GPU/memory buffer operations.
Definition Buffer.hpp:24
void Reset() final
Reset the pool, freeing all previous allocations.
void Initialize(GLsizei aStackSize)
Initialize the pool buffer with the given size.
const Buffer & GetBuffer() const final
Get a reference to the underlying Buffer.
BufferAccessor Allocate(size_t aSize) final
Allocate a sub-region from the memory pool.
void Finalize()
Release pool buffer resources.
OpenGLMemoryPoolBuffer(const OpenGLRenderer &aOpenGLRenderer, GLsizei aStackSize)
Construct with a renderer and initial pool size.
OpenGL rendering backend implementing the Renderer interface.
<- This is here just for the literals
Definition AABB.hpp:31
@ Error
Error conditions.
Definition LogLevel.hpp:33
STL namespace.