23 #include <flw/flc/buffers/IBuffer.h> 24 #include <flw/flc/pipeline/Attribute.h> 26 #include <flw/flf/models/shapes/Shape.h> 28 #include <flw/cmn/Containers.h> 54 :
IBuffer(GL_ARRAY_BUFFER, dataStoreModification) {
58 TVertexBuffer(
const std::vector<T> &vertices, GLuint dataStoreModification = GL_STATIC_DRAW)
59 :
IBuffer(GL_ARRAY_BUFFER, dataStoreModification) {
60 mDataVertices = vertices;
61 mTotalElements = mDataVertices.size();
62 mData = mDataVertices.data();
63 mSize = mTotalElements *
sizeof(T);
67 :
IBuffer(GL_ARRAY_BUFFER, dataStoreModification) {
68 mDataVertices = shape.getVertices();
69 mSize = mTotalElements *
sizeof(T);
70 mData = mDataVertices.data();
73 ~TVertexBuffer()
override =
default;
75 void load(T element) {
76 mDataVertices.push_back(element);
78 mSize = mTotalElements *
sizeof(T);
79 mData = mDataVertices.data();
82 void initAttributes(GLint programHandle) {
83 if (mAttributes.empty()) {
84 getAttributes(programHandle);
88 void attributesSetForVAO() {
89 std::for_each(mAttributes.begin(), mAttributes.end(), [](
Attribute &a) {
92 std::for_each(mAttributes.begin(), mAttributes.end(), [](
Attribute &a) {
97 void attributesEnable() {
98 std::for_each(mAttributes.begin(), mAttributes.end(), [](
Attribute &a) {
107 void attributesSetPointer() {
108 std::for_each(mAttributes.begin(), mAttributes.end(), [](
Attribute &a) {
113 T *getDataInternal() {
114 if (mDataVertices.empty()) {
115 std::cout <<
"Not cpu data in this buffer" << std::endl;
118 return mDataVertices.data();
121 void emptyCPU()
override {
122 mDataVertices.clear();
127 void emptyGPU()
override {
128 std::cout <<
"Not gpu data clear is possible in this buffer" << std::endl;
131 virtual void log()
const = 0;
134 std::vector<T> mDataVertices;
136 inline void getAttributes(GLint programHandle) {
138 glGetProgramiv(programHandle, GL_ACTIVE_ATTRIBUTES, &howMany);
139 mAttributes.reserve(howMany);
140 for (
int i = 0; i < howMany; ++i) {
141 int name_len = -1, num = -1;
142 GLenum type = GL_ZERO;
144 glGetActiveAttrib(programHandle, GLuint(i),
sizeof(name) - 1, &name_len, &num, &type, name);
146 GLuint location = glGetAttribLocation(programHandle, name);
149 case GL_UNSIGNED_INT:
177 #if defined(FILLWAVE_BACKEND_OPENGL_ES_20) || defined(FILLWAVE_BACKEND_OPENGL_ES_30) 179 case GL_UNSIGNED_INT_VEC3:
182 case GL_UNSIGNED_INT_VEC2:
185 case GL_UNSIGNED_INT_VEC4:
190 std::cout <<
"Not supported type of attribute" << std::endl;
195 Attribute a(name, location, size,
sizeof(T), type);
196 mAttributes.push_back(a);
199 unsigned long long pointer = 0;
200 for (GLuint i = 0; i < mAttributes.size(); i++) {
201 for (
auto &it : mAttributes) {
202 if (it.getIndex() == i) {
203 it.setOffsetPointer((GLvoid *) pointer);
204 pointer += it.getSize() * it.getTypeSize();
210 inline void attributesBind(GLint programHandle) {
211 std::for_each(mAttributes.begin(), mAttributes.end(), [programHandle](
Attribute &a) {
212 a.bindLocation(programHandle);
217 vecStack<Attribute> mAttributes;
Template for all vertex buffers.
Definition: TVertexBuffer.h:42
VertexAttribute to be kept within the VertexBuffer.
Definition: Attribute.h:33
Base for all buffer types.
Definition: IBuffer.h:33
Base class for every shape. Specialized with Vertex data structure.
Definition: Shape.h:37