add Buffer API to create a Buffer with an initializer_list of GLfloats/GLdoubles
This commit is contained in:
parent
cf06b6a945
commit
09cb80327f
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "glcxx/gl.hpp"
|
#include "glcxx/gl.hpp"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <initializer_list>
|
||||||
|
|
||||||
namespace glcxx
|
namespace glcxx
|
||||||
{
|
{
|
||||||
@ -15,6 +16,18 @@ namespace glcxx
|
|||||||
|
|
||||||
void set_buffer_data(GLenum target, GLenum usage, const void * ptr, size_t size);
|
void set_buffer_data(GLenum target, GLenum usage, const void * ptr, size_t size);
|
||||||
|
|
||||||
|
void set_buffer_data(GLenum target, GLenum usage, std::initializer_list<GLfloat> data)
|
||||||
|
{
|
||||||
|
set_buffer_data(target, usage, &*data.begin(),
|
||||||
|
(uintptr_t)&*data.end() - (uintptr_t)&*data.begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_buffer_data_d(GLenum target, GLenum usage, std::initializer_list<GLdouble> data)
|
||||||
|
{
|
||||||
|
set_buffer_data(target, usage, &*data.begin(),
|
||||||
|
(uintptr_t)&*data.end() - (uintptr_t)&*data.begin());
|
||||||
|
}
|
||||||
|
|
||||||
GLuint id() const { return m_id; }
|
GLuint id() const { return m_id; }
|
||||||
|
|
||||||
void bind() const { glBindBuffer(m_target, m_id); }
|
void bind() const { glBindBuffer(m_target, m_id); }
|
||||||
@ -26,6 +39,22 @@ namespace glcxx
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::shared_ptr<Buffer> create(GLenum target, GLenum usage,
|
||||||
|
std::initializer_list<GLfloat> data)
|
||||||
|
{
|
||||||
|
std::shared_ptr<Buffer> buffer = std::make_shared<Buffer>();
|
||||||
|
buffer->set_buffer_data(target, usage, data);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::shared_ptr<Buffer> create_d(GLenum target, GLenum usage,
|
||||||
|
std::initializer_list<GLdouble> data)
|
||||||
|
{
|
||||||
|
std::shared_ptr<Buffer> buffer = std::make_shared<Buffer>();
|
||||||
|
buffer->set_buffer_data_d(target, usage, data);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GLuint m_id;
|
GLuint m_id;
|
||||||
|
|
||||||
|
@ -35,26 +35,20 @@ bool init(void)
|
|||||||
"position", 0,
|
"position", 0,
|
||||||
"color", 1);
|
"color", 1);
|
||||||
|
|
||||||
GLfloat coords[] = {
|
buffer = glcxx::Buffer::create(GL_ARRAY_BUFFER, GL_STATIC_DRAW,
|
||||||
-0.5, -0.5,
|
{-0.5, -0.5,
|
||||||
0.5, -0.5,
|
0.5, -0.5,
|
||||||
0.5, 0.5,
|
0.5, 0.5,
|
||||||
-0.5, 0.5,
|
-0.5, 0.5});
|
||||||
};
|
|
||||||
buffer = glcxx::Buffer::create(GL_ARRAY_BUFFER, GL_STATIC_DRAW, &coords, sizeof(coords));
|
|
||||||
|
|
||||||
GLfloat coords2[] = {
|
buffer2 = glcxx::Buffer::create(GL_ARRAY_BUFFER, GL_STATIC_DRAW,
|
||||||
0.2, 0.2,
|
{0.2, 0.2,
|
||||||
0.9, 0.2,
|
0.9, 0.2,
|
||||||
0.9, 0.9,
|
0.9, 0.9});
|
||||||
};
|
buffer3 = glcxx::Buffer::create(GL_ARRAY_BUFFER, GL_STATIC_DRAW,
|
||||||
buffer2 = glcxx::Buffer::create(GL_ARRAY_BUFFER, GL_STATIC_DRAW, &coords2, sizeof(coords2));
|
{1.0, 0.1, 0.1, 1.0,
|
||||||
GLfloat colors[] = {
|
|
||||||
1.0, 0.1, 0.1, 1.0,
|
|
||||||
0.1, 1.0, 0.1, 1.0,
|
0.1, 1.0, 0.1, 1.0,
|
||||||
0.1, 0.1, 1.0, 1.0,
|
0.1, 0.1, 1.0, 1.0});
|
||||||
};
|
|
||||||
buffer3 = glcxx::Buffer::create(GL_ARRAY_BUFFER, GL_STATIC_DRAW, &colors, sizeof(colors));
|
|
||||||
|
|
||||||
array1->bind();
|
array1->bind();
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user