25 #ifdef E3D_BACKEND_OPENGL
28 #elif defined E3D_BACKEND_GLES
29 # include <GLES3/gl3.h>
30 #elif defined E3D_BACKEND_RGX
34 #include "eng3d/mesh.hpp"
35 #include "eng3d/string.hpp"
44 glGenVertexArrays(1, &
id);
48 glDeleteVertexArrays(1, &
id);
63 glBindVertexArray(
id);
81 glDeleteBuffers(1, &
id);
96 glBindBuffer(GL_ARRAY_BUFFER,
id);
110 glGenBuffers(1, &
id);
114 glDeleteBuffers(1, &
id);
129 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
id);
137 #if defined E3D_BACKEND_OPENGL || defined E3D_BACKEND_GLES
141 i_mode = GL_TRIANGLE_FAN;
144 i_mode = GL_TRIANGLE_STRIP;
147 i_mode = GL_TRIANGLES;
153 i_mode = GL_LINE_STRIP;
163 glDrawElementsInstanced(i_mode, n_indices, GL_UNSIGNED_INT,
nullptr, instances);
165 glDrawArraysInstanced(i_mode, 0, n_buffer, instances);
169 glDrawElements(i_mode, n_indices, GL_UNSIGNED_INT,
nullptr);
171 glDrawArrays(i_mode, 0, n_buffer);
176 void Eng3D::upload(
const Eng3D::OpenGL::VAO& vao,
const Eng3D::OpenGL::VBO& vbo,
const Eng3D::OpenGL::EBO& ebo,
const void *buffer,
size_t n_buffer,
size_t sz_buffer,
size_t sz_buffer_vert,
size_t sz_buffer_tex,
size_t v_len,
size_t t_len,
size_t c_len,
const void *indices,
size_t n_indices,
size_t sz_indices,
bool has_color) {
177 #if defined E3D_BACKEND_OPENGL || defined E3D_BACKEND_GLES
180 glBufferData(GL_ARRAY_BUFFER, n_buffer * sz_buffer, buffer, GL_STATIC_DRAW);
182 glBufferData(GL_ELEMENT_ARRAY_BUFFER, n_indices * sz_indices, indices, GL_STATIC_DRAW);
185 glVertexAttribPointer(0, v_len, GL_FLOAT, GL_FALSE, sz_buffer,
nullptr);
186 glEnableVertexAttribArray(0);
189 size_t tex_stride = sz_buffer_vert;
190 glVertexAttribPointer(1, t_len, GL_FLOAT, GL_FALSE, sz_buffer, (
void*)((uintptr_t)tex_stride));
191 glEnableVertexAttribArray(1);
195 size_t color_stride = tex_stride + sz_buffer_tex;
196 glVertexAttribPointer(2, c_len, GL_FLOAT, GL_FALSE, sz_buffer, (
void*)((uintptr_t)color_stride));
197 glEnableVertexAttribArray(2);
203 #if defined E3D_BACKEND_OPENGL || defined E3D_BACKEND_GLES
204 if(!instances)
return;
208 glBufferData(GL_ARRAY_BUFFER, index_size * instances, buffer, GL_STATIC_DRAW);
209 glBindBuffer(GL_ARRAY_BUFFER, 0);
211 glEnableVertexAttribArray(2);
213 glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, index_size,
nullptr);
214 glBindBuffer(GL_ARRAY_BUFFER, 0);
215 glVertexAttribDivisor(2, 1);
EBO & operator=(EBO &rhs)
unsigned int get_id() const
VAO & operator=(VAO &rhs)
unsigned int get_id() const
VBO & operator=(VBO &rhs)
unsigned int get_id() const
void upload(const Eng3D::OpenGL::VAO &vao, const Eng3D::OpenGL::VBO &vbo, const Eng3D::OpenGL::EBO &ebo, const void *buffer, size_t n_buffer, size_t sz_buffer, size_t sz_buffer_vert, size_t sz_buffer_tex, size_t v_len, size_t t_len, size_t c_len, const void *indices, size_t n_indices, size_t sz_indices, bool has_color)
void draw(const Eng3D::OpenGL::VAO &vao, MeshMode mode, const void *indices, size_t n_indices, const void *buffer, size_t n_buffer, int instances)
void instancing(const Eng3D::OpenGL::VAO &vao, const Eng3D::OpenGL::VBO &i_vbo, const void *buffer, size_t index_size, int instances)
std::string translate_format(const std::string_view format, Args &&... args)
String formatter, with translation.
#define CXX_THROW(class,...)