-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuffers.cpp
78 lines (66 loc) · 3.03 KB
/
buffers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <algorithm>
#include "buffers.h"
using namespace std;
using namespace MaxLib;
namespace GLViewer {
// Create a new static buffer
// Example: GeometryBufferID buffer = buffers.CreateBuffer<StaticBuffer>([](StaticBuffer& buffer){ buffer.Addxxx() });
GeometryBufferID Buffers::CreateStaticBuffer(std::function<void(StaticBuffer&)> cb_AddData) {
return m_GeometryBuffers.Add<StaticBuffer>(cb_AddData).m_ID;
}
// Create a new dynamic buffer
// Example: GeometryBufferID buffer = buffers.CreateBuffer<DynamicBuffer>();
GeometryBufferID Buffers::CreateDynamicBuffer() {
return m_GeometryBuffers.Add<DynamicBuffer>().m_ID;
}
// Create a new Stream buffer
// Example: GeometryBufferID buffer = buffers.CreateBuffer<StreamBuffer>();
GeometryBufferID Buffers::CreateStreamBuffer() {
return m_GeometryBuffers.Add<StreamBuffer>().m_ID;
}
// Create a new Text buffer
TextBufferID Buffers::CreateTextBuffer() {
return m_TextBuffers.Add(m_Parent).m_ID;
}
// Create a new Image buffer
ImageBufferID Buffers::CreateImageBuffer() {
return m_ImageBuffers.Add(m_Parent).m_ID;
}
// Deletes a buffer, do not try to access this buffer after deletion
void Buffers::DeleteGeometryBuffer(GeometryBufferID bufferID) {
// Delete buffer if the ID matches. Go backwards through list so we always have correct index
for(int i = m_GeometryBuffers.Size()-1; i >= 0; i--) {
if(m_GeometryBuffers[(size_t)i].m_ID.id == bufferID.id) { m_GeometryBuffers.Remove((size_t)i); }
}
}
// Deletes a buffer, do not try to access this buffer after deletion
void Buffers::DeleteTextBuffer(TextBufferID bufferID) {
// Delete buffer if the ID matches. Go backwards through list so we always have correct index
for(int i = m_TextBuffers.Size()-1; i >= 0; i--) {
if(m_TextBuffers[(size_t)i].m_ID.id == bufferID.id) { m_TextBuffers.Remove((size_t)i); }
}
}
// Deletes a buffer, do not try to access this buffer after deletion
void Buffers::DeleteImageBuffer(ImageBufferID bufferID) {
// Delete buffer if the ID matches. Go backwards through list so we always have correct index
for(int i = m_ImageBuffers.Size()-1; i >= 0; i--) {
if(m_ImageBuffers[(size_t)i].m_ID.id == bufferID.id) { m_ImageBuffers.Remove((size_t)i); }
}
}
void Buffers::DeleteAllBuffers() {
// Delete each buffer. Go backwards through list so we always have correct index
while(m_GeometryBuffers.Size()) { m_GeometryBuffers.Remove(0); }
while(m_TextBuffers.Size()) { m_TextBuffers.Remove(0); }
while(m_ImageBuffers.Size()) { m_ImageBuffers.Remove(0); }
}
// Renders each of the buffers per frame
void Buffers::RenderBuffers(const glm::mat4& proj, const glm::mat4& view) {
// Render each of the GeometryBuffers
for(auto& buffer : m_GeometryBuffers) { buffer->Render(proj, view); }
// Render each of the TextBuffers
for(auto& buffer : m_TextBuffers) { buffer->Render(); }
// Render each of the ImageBuffers
for(auto& buffer : m_ImageBuffers) { buffer->Render(); }
}
} // End namespace GLViewer