18#ifndef HEADER_SP_DYNAMIC_DRAW_CALL_HPP
19#define HEADER_SP_DYNAMIC_DRAW_CALL_HPP
21#include "graphics/sp/sp_mesh_buffer.hpp"
23#include <IMeshBuffer.h>
24#include <ISceneNode.h>
30#include <unordered_map>
44 core::matrix4 m_trans;
46 scene::ISceneNode* m_parent = NULL;
48 core::vector2df m_texture_trans;
50 scene::E_PRIMITIVE_TYPE m_primitive_type;
52 unsigned m_gl_vbo_size = 4;
54 int m_update_offset = 0;
56 bool m_visible =
true;
58 bool m_update_trans =
false;
60 bool m_removing =
false;
63 bool initTextureDyDc();
67 std::shared_ptr<SPShader> shader,
Material* m);
71 virtual void draw(DrawCallType dct = DCT_NORMAL,
72 int material_id = -1)
const
75 glBindVertexArray(m_vao[0]);
76 glDrawArraysInstanced(
77 m_primitive_type == EPT_TRIANGLES ? GL_TRIANGLES :
78 m_primitive_type == EPT_TRIANGLE_STRIP ? GL_TRIANGLE_STRIP :
79 GL_TRIANGLE_FAN, 0, getVertexCount(), 1);
83 virtual void uploadInstanceData()
86 if (m_texture_trans.X != 0.0f || m_texture_trans.Y != 0.0f ||
87 m_update_trans || m_parent != NULL)
89 m_update_trans =
false;
91 m_texture_trans.X, m_texture_trans.Y, 0.0f, 0);
92 glBindBuffer(GL_ARRAY_BUFFER, m_ibo);
93 glBufferSubData(GL_ARRAY_BUFFER, 0, 44,
id.getData());
94 glBindBuffer(GL_ARRAY_BUFFER, 0);
96 if (m_update_offset >= 0 && !m_vertices.empty())
98 glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
99 unsigned new_size = m_gl_vbo_size;
100 while (m_vertices.size() > new_size)
105 if (new_size != m_gl_vbo_size)
108 m_gl_vbo_size = new_size;
109 m_vertices.reserve(m_gl_vbo_size);
110 glBufferData(GL_ARRAY_BUFFER, m_gl_vbo_size * 48,
111 m_vertices.data(), GL_DYNAMIC_DRAW);
116 ((int)m_vertices.size() - m_update_offset) * 48;
118 glBufferSubData(GL_ARRAY_BUFFER, m_update_offset * 48, length,
119 m_vertices.data() + m_update_offset);
121 glBindBuffer(GL_ARRAY_BUFFER, 0);
122 m_update_offset = -1;
127 virtual void uploadGLMesh() {}
129 virtual void enableTextureMatrix(
unsigned mat_id) {}
131 std::vector<video::S3DVertexSkinnedMesh>& getVerticesVector()
132 {
return m_vertices; }
134 core::vector2df& getTextureTrans()
136 m_update_trans =
true;
137 return m_texture_trans;
140 void setUpdateOffset(
int offset)
144 if (m_update_offset != -1 && offset > m_update_offset)
146 m_update_offset = offset;
149 bool isVisible()
const {
return m_visible; }
151 void setVisible(
bool val) { m_visible = val; }
153 core::matrix4 getAbsoluteTransformation()
const
155 core::matrix4 trans = m_trans;
156 if (m_parent != NULL)
158 trans = m_parent->getAbsoluteTransformation() * trans;
163 void removeFromSP() { m_removing =
true; }
165 bool isRemoving()
const {
return m_removing; }
167 bool notReadyFromDrawing()
const {
return m_vertices.size() < 3; }
169 void setTransformation(
const core::matrix4& mat)
172 m_update_trans =
true;
175 void setPosition(
const core::vector3df pos)
177 m_trans.setTranslation(pos);
178 m_update_trans =
true;
181 void setRotationRadians(
const core::vector3df rot)
183 m_trans.setRotationRadians(rot);
184 m_update_trans =
true;
187 void setRotationDegrees(
const core::vector3df rot)
189 m_trans.setRotationDegrees(rot);
190 m_update_trans =
true;
193 void setScale(
const core::vector3df scale)
195 m_trans.setScale(scale);
196 m_update_trans =
true;
199 void setParent(scene::ISceneNode* parent) { m_parent = parent; }
Definition: material.hpp:48
Definition: sp_dynamic_draw_call.hpp:42
Definition: sp_instanced_data.hpp:32
Definition: sp_mesh_buffer.hpp:48