Updated examples to new vertex layout API

This commit is contained in:
vurtun 2016-09-04 10:02:28 +02:00
parent 7f5d808809
commit 7279f0f0cc
5 changed files with 102 additions and 40 deletions

View File

@ -1,4 +1,6 @@
# Changelog # Changelog
- 2016/09/03 (1.131)- Fixed gaps inside combo boxes in OpenGL
- 2016/09/02 (1.13) - Changed nuklear to not have any default vertex layout and - 2016/09/02 (1.13) - Changed nuklear to not have any default vertex layout and
instead made it user provided. The range of types to convert instead made it user provided. The range of types to convert
to is quite limited at the moment, but I would be more than to is quite limited at the moment, but I would be more than

View File

@ -45,6 +45,12 @@
* DEVICE * DEVICE
* *
* ===============================================================*/ * ===============================================================*/
struct nk_glfw_vertex {
float position[2];
float uv[2];
nk_byte col[4];
};
struct device { struct device {
struct nk_buffer cmds; struct nk_buffer cmds;
struct nk_draw_null_texture null; struct nk_draw_null_texture null;
@ -145,10 +151,10 @@ device_init(struct device *dev)
{ {
/* buffer setup */ /* buffer setup */
GLsizei vs = sizeof(struct nk_draw_vertex); GLsizei vs = sizeof(struct nk_glfw_vertex);
size_t vp = offsetof(struct nk_draw_vertex, position); size_t vp = offsetof(struct nk_glfw_vertex, position);
size_t vt = offsetof(struct nk_draw_vertex, uv); size_t vt = offsetof(struct nk_glfw_vertex, uv);
size_t vc = offsetof(struct nk_draw_vertex, col); size_t vc = offsetof(struct nk_glfw_vertex, col);
glGenBuffers(1, &dev->vbo); glGenBuffers(1, &dev->vbo);
glGenBuffers(1, &dev->ebo); glGenBuffers(1, &dev->ebo);
@ -242,16 +248,25 @@ device_draw(struct device *dev, struct nk_context *ctx, int width, int height,
vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
{ {
/* fill converting configuration */ /* fill convert configuration */
struct nk_convert_config config; struct nk_convert_config config;
memset(&config, 0, sizeof(config)); static const struct nk_draw_vertex_layout_element vertex_layout[] = {
config.global_alpha = 1.0f; {NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_glfw_vertex, position)},
config.shape_AA = AA; {NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_glfw_vertex, uv)},
config.line_AA = AA; {NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct nk_glfw_vertex, col)},
{NK_VERTEX_LAYOUT_END}
};
NK_MEMSET(&config, 0, sizeof(config));
config.vertex_layout = vertex_layout;
config.vertex_size = sizeof(struct nk_glfw_vertex);
config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex);
config.null = dev->null;
config.circle_segment_count = 22; config.circle_segment_count = 22;
config.curve_segment_count = 22; config.curve_segment_count = 22;
config.arc_segment_count = 22; config.arc_segment_count = 22;
config.null = dev->null; config.global_alpha = 1.0f;
config.shape_AA = AA;
config.line_AA = AA;
/* setup buffers to load vertices and elements */ /* setup buffers to load vertices and elements */
{struct nk_buffer vbuf, ebuf; {struct nk_buffer vbuf, ebuf;

View File

@ -480,6 +480,12 @@ basic_demo(struct nk_context *ctx, struct media *media)
* DEVICE * DEVICE
* *
* ===============================================================*/ * ===============================================================*/
struct nk_glfw_vertex {
float position[2];
float uv[2];
nk_byte col[4];
};
struct device { struct device {
struct nk_buffer cmds; struct nk_buffer cmds;
struct nk_draw_null_texture null; struct nk_draw_null_texture null;
@ -580,10 +586,10 @@ device_init(struct device *dev)
{ {
/* buffer setup */ /* buffer setup */
GLsizei vs = sizeof(struct nk_draw_vertex); GLsizei vs = sizeof(struct nk_glfw_vertex);
size_t vp = offsetof(struct nk_draw_vertex, position); size_t vp = offsetof(struct nk_glfw_vertex, position);
size_t vt = offsetof(struct nk_draw_vertex, uv); size_t vt = offsetof(struct nk_glfw_vertex, uv);
size_t vc = offsetof(struct nk_draw_vertex, col); size_t vc = offsetof(struct nk_glfw_vertex, col);
glGenBuffers(1, &dev->vbo); glGenBuffers(1, &dev->vbo);
glGenBuffers(1, &dev->ebo); glGenBuffers(1, &dev->ebo);
@ -677,16 +683,25 @@ device_draw(struct device *dev, struct nk_context *ctx, int width, int height,
vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
{ {
/* fill converting configuration */ /* fill convert configuration */
struct nk_convert_config config; struct nk_convert_config config;
memset(&config, 0, sizeof(config)); static const struct nk_draw_vertex_layout_element vertex_layout[] = {
config.global_alpha = 1.0f; {NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_glfw_vertex, position)},
config.shape_AA = AA; {NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_glfw_vertex, uv)},
config.line_AA = AA; {NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct nk_glfw_vertex, col)},
{NK_VERTEX_LAYOUT_END}
};
NK_MEMSET(&config, 0, sizeof(config));
config.vertex_layout = vertex_layout;
config.vertex_size = sizeof(struct nk_glfw_vertex);
config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex);
config.null = dev->null;
config.circle_segment_count = 22; config.circle_segment_count = 22;
config.curve_segment_count = 22; config.curve_segment_count = 22;
config.arc_segment_count = 22; config.arc_segment_count = 22;
config.null = dev->null; config.global_alpha = 1.0f;
config.shape_AA = AA;
config.line_AA = AA;
/* setup buffers to load vertices and elements */ /* setup buffers to load vertices and elements */
{struct nk_buffer vbuf, ebuf; {struct nk_buffer vbuf, ebuf;

View File

@ -518,6 +518,12 @@ file_browser_run(struct file_browser *browser, struct nk_context *ctx)
* DEVICE * DEVICE
* *
* ===============================================================*/ * ===============================================================*/
struct nk_glfw_vertex {
float position[2];
float uv[2];
nk_byte col[4];
};
struct device { struct device {
struct nk_buffer cmds; struct nk_buffer cmds;
struct nk_draw_null_texture null; struct nk_draw_null_texture null;
@ -606,10 +612,10 @@ device_init(struct device *dev)
{ {
/* buffer setup */ /* buffer setup */
GLsizei vs = sizeof(struct nk_draw_vertex); GLsizei vs = sizeof(struct nk_glfw_vertex);
size_t vp = offsetof(struct nk_draw_vertex, position); size_t vp = offsetof(struct nk_glfw_vertex, position);
size_t vt = offsetof(struct nk_draw_vertex, uv); size_t vt = offsetof(struct nk_glfw_vertex, uv);
size_t vc = offsetof(struct nk_draw_vertex, col); size_t vc = offsetof(struct nk_glfw_vertex, col);
glGenBuffers(1, &dev->vbo); glGenBuffers(1, &dev->vbo);
glGenBuffers(1, &dev->ebo); glGenBuffers(1, &dev->ebo);
@ -703,16 +709,25 @@ device_draw(struct device *dev, struct nk_context *ctx, int width, int height,
vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
{ {
/* fill converting configuration */ /* fill convert configuration */
struct nk_convert_config config; struct nk_convert_config config;
memset(&config, 0, sizeof(config)); static const struct nk_draw_vertex_layout_element vertex_layout[] = {
config.global_alpha = 1.0f; {NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_glfw_vertex, position)},
config.shape_AA = AA; {NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_glfw_vertex, uv)},
config.line_AA = AA; {NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct nk_glfw_vertex, col)},
{NK_VERTEX_LAYOUT_END}
};
NK_MEMSET(&config, 0, sizeof(config));
config.vertex_layout = vertex_layout;
config.vertex_size = sizeof(struct nk_glfw_vertex);
config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex);
config.null = dev->null;
config.circle_segment_count = 22; config.circle_segment_count = 22;
config.curve_segment_count = 22; config.curve_segment_count = 22;
config.arc_segment_count = 22; config.arc_segment_count = 22;
config.null = dev->null; config.global_alpha = 1.0f;
config.shape_AA = AA;
config.line_AA = AA;
/* setup buffers to load vertices and elements */ /* setup buffers to load vertices and elements */
{struct nk_buffer vbuf, ebuf; {struct nk_buffer vbuf, ebuf;

View File

@ -72,6 +72,12 @@ struct media {
* DEVICE * DEVICE
* *
* ===============================================================*/ * ===============================================================*/
struct nk_glfw_vertex {
float position[2];
float uv[2];
nk_byte col[4];
};
struct device { struct device {
struct nk_buffer cmds; struct nk_buffer cmds;
struct nk_draw_null_texture null; struct nk_draw_null_texture null;
@ -172,10 +178,10 @@ device_init(struct device *dev)
{ {
/* buffer setup */ /* buffer setup */
GLsizei vs = sizeof(struct nk_draw_vertex); GLsizei vs = sizeof(struct nk_glfw_vertex);
size_t vp = offsetof(struct nk_draw_vertex, position); size_t vp = offsetof(struct nk_glfw_vertex, position);
size_t vt = offsetof(struct nk_draw_vertex, uv); size_t vt = offsetof(struct nk_glfw_vertex, uv);
size_t vc = offsetof(struct nk_draw_vertex, col); size_t vc = offsetof(struct nk_glfw_vertex, col);
glGenBuffers(1, &dev->vbo); glGenBuffers(1, &dev->vbo);
glGenBuffers(1, &dev->ebo); glGenBuffers(1, &dev->ebo);
@ -269,16 +275,25 @@ device_draw(struct device *dev, struct nk_context *ctx, int width, int height,
vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
{ {
/* fill converting configuration */ /* fill convert configuration */
struct nk_convert_config config; struct nk_convert_config config;
memset(&config, 0, sizeof(config)); static const struct nk_draw_vertex_layout_element vertex_layout[] = {
config.global_alpha = 1.0f; {NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_glfw_vertex, position)},
config.shape_AA = AA; {NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_glfw_vertex, uv)},
config.line_AA = AA; {NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct nk_glfw_vertex, col)},
{NK_VERTEX_LAYOUT_END}
};
NK_MEMSET(&config, 0, sizeof(config));
config.vertex_layout = vertex_layout;
config.vertex_size = sizeof(struct nk_glfw_vertex);
config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex);
config.null = dev->null;
config.circle_segment_count = 22; config.circle_segment_count = 22;
config.curve_segment_count = 22; config.curve_segment_count = 22;
config.arc_segment_count = 22; config.arc_segment_count = 22;
config.null = dev->null; config.global_alpha = 1.0f;
config.shape_AA = AA;
config.line_AA = AA;
/* setup buffers to load vertices and elements */ /* setup buffers to load vertices and elements */
{struct nk_buffer vbuf, ebuf; {struct nk_buffer vbuf, ebuf;