Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
glimBatchData.cpp
Go to the documentation of this file.
1/*
2** GLIM - OpenGL Immediate Mode
3** Copyright Jan Krassnigg (Jan@Krassnigg.de)
4** For more details, see the included Readme.txt.
5*/
6
7
8
9#include "glimBatchData.h"
10
15
16#define BUFFER_OFFSET(i) ((char*)NULL + (i))
17
18namespace NS_GLIM {
19
21
24 m_ArrayData.clear();
25
26 m_CurrentValue[0].Int = 0;
27 m_CurrentValue[1].Int = 0;
28 m_CurrentValue[2].Int = 0;
29 m_CurrentValue[3].Int = 0;
30}
31
33 switch (m_DataType) {
34 // 4 byte data
38 m_ArrayData.push_back(m_CurrentValue[0]);
39 return;
40
41 // 8 byte data
44 m_ArrayData.push_back(m_CurrentValue[0]);
45 m_ArrayData.push_back(m_CurrentValue[1]);
46 return;
47
48 // 12 byte data
51 m_ArrayData.push_back(m_CurrentValue[0]);
52 m_ArrayData.push_back(m_CurrentValue[1]);
53 m_ArrayData.push_back(m_CurrentValue[2]);
54 return;
55
56 // 16 byte data
59 m_ArrayData.push_back(m_CurrentValue[0]);
60 m_ArrayData.push_back(m_CurrentValue[1]);
61 m_ArrayData.push_back(m_CurrentValue[2]);
62 m_ArrayData.push_back(m_CurrentValue[3]);
63 return;
64
65 default:
66 // throws an exception
67 GLIM_CHECK(false,
68 "GlimArrayData::PushElement: Data-Type is invalid.");
69 return;
70 }
71}
72
74{
75 Reset();
76}
77
79{
80 Reset();
81}
82
83void glimBatchData::Reset(bool reserveBuffers, unsigned int vertexCount, unsigned int attributeCount) {
85
86 m_Attributes.clear();
87 m_Attributes.reserve(attributeCount);
89
91 m_IndexBuffer_Lines.clear();
94
95 if (reserveBuffers) {
96 vertexCount *= 3;
97 m_PositionData.reserve(vertexCount);
98 m_IndexBuffer_Points.reserve(std::max(vertexCount / 4, 1u));
99 m_IndexBuffer_Lines.reserve(std::max(vertexCount / 2, 1u));
100 m_IndexBuffer_Triangles.reserve(vertexCount * 2u);
101 m_IndexBuffer_Wireframe.reserve(vertexCount * 2u);
102 }
103}
104
105unsigned int glimBatchData::AddVertex(float x, float y, float z) {
106 m_PositionData.emplace_back(x);
107 m_PositionData.emplace_back(y);
108 m_PositionData.emplace_back(z);
109
110 for (auto&[_, data] : m_Attributes) {
111 data.PushElement();
112 }
113
114 return (unsigned int)(m_PositionData.size() / 3) - 1;
115}
116
117}
void efficient_clear(eastl::fixed_vector< T, nodeCount, bEnableOverflow, OverflowAllocator > &fixed_vector)
Definition: Vector.h:52
void GLIM_CHECK(bool bCondition, const char *szErrorMsg) noexcept
Assert Macro used internally.
Definition: Declarations.h:66
Divide::vector< Glim4ByteData > m_ArrayData
Definition: glimBatchData.h:42
Glim4ByteData m_CurrentValue[4]
Definition: glimBatchData.h:40
Divide::vector< unsigned int > m_IndexBuffer_Triangles
Definition: glimBatchData.h:82
void Reset(bool reserveBuffers=false, unsigned int vertexCount=64 *3, unsigned int attributeCount=1)
unsigned int AddVertex(float x, float y, float z)
Divide::vector< unsigned int > m_IndexBuffer_Lines
Definition: glimBatchData.h:80
Divide::vector< unsigned int > m_IndexBuffer_Wireframe
Definition: glimBatchData.h:84
Divide::vector< Glim4ByteData > m_PositionData
Definition: glimBatchData.h:75
Divide::hashMap< unsigned int, GlimArrayData > m_Attributes
Definition: glimBatchData.h:72
Divide::vector< unsigned int > m_IndexBuffer_Points
Definition: glimBatchData.h:78
GLIM_BATCH_STATE m_State
Definition: glimBatchData.h:69