Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

Commit

Permalink
make the size of nk_draw_index an option, also make the documentation…
Browse files Browse the repository at this point in the history
… a bit more clear.
  • Loading branch information
FredrikHson committed Aug 27, 2018
1 parent 5cea113 commit 2b03f44
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
8 changes: 8 additions & 0 deletions doc/nuklear.html
Expand Up @@ -96,6 +96,7 @@
NK_INCLUDE_COMMAND_USERDATA | Defining this adds a userdata pointer into each command. Can be useful for example if you want to provide custom shaders depending on the used widget. Can be combined with the style structures.
NK_BUTTON_TRIGGER_ON_RELEASE | Different platforms require button clicks occurring either on buttons being pressed (up to down) or released (down to up). By default this library will react on buttons being pressed, but if you define this it will only trigger if a button is released.
NK_ZERO_COMMAND_MEMORY | Defining this will zero out memory for each drawing command added to a drawing queue (inside nk_command_buffer_push). Zeroing command memory is very useful for fast checking (using memcmp) if command buffers are equal and avoid drawing frames when nothing on screen has changed since previous frame.
NK_UINT_DRAW_INDEX | Defining this will set the size of vertex index elements when using NK_VERTEX_BUFFER_OUTPUT to 32bit instead of the default of 16bit
!!! WARNING
The following flags will pull in the standard C library:
- NK_INCLUDE_DEFAULT_ALLOCATOR
Expand All @@ -111,6 +112,7 @@
- NK_INCLUDE_DEFAULT_FONT
- NK_INCLUDE_STANDARD_VARARGS
- NK_INCLUDE_COMMAND_USERDATA
- NK_UINT_DRAW_INDEX
### Constants
Define | Description
--------------------------------|---------------------------------------
Expand Down Expand Up @@ -611,6 +613,12 @@
vertex draw commands:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
// fill configuration
struct your_vertex
{
float pos[2]; // important to keep it to 2 floats
float uv[2];
unsigned char col[4];
};
struct nk_convert_config cfg = {};
static const struct nk_draw_vertex_layout_element vertex_layout[] = {
{NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct your_vertex, pos)},
Expand Down
20 changes: 14 additions & 6 deletions nuklear.h
Expand Up @@ -105,6 +105,7 @@
/// NK_INCLUDE_COMMAND_USERDATA | Defining this adds a userdata pointer into each command. Can be useful for example if you want to provide custom shaders depending on the used widget. Can be combined with the style structures.
/// NK_BUTTON_TRIGGER_ON_RELEASE | Different platforms require button clicks occurring either on buttons being pressed (up to down) or released (down to up). By default this library will react on buttons being pressed, but if you define this it will only trigger if a button is released.
/// NK_ZERO_COMMAND_MEMORY | Defining this will zero out memory for each drawing command added to a drawing queue (inside nk_command_buffer_push). Zeroing command memory is very useful for fast checking (using memcmp) if command buffers are equal and avoid drawing frames when nothing on screen has changed since previous frame.
/// NK_UINT_DRAW_INDEX | Defining this will set the size of vertex index elements when using NK_VERTEX_BUFFER_OUTPUT to 32bit instead of the default of 16bit
///
/// !!! WARNING
/// The following flags will pull in the standard C library:
Expand All @@ -122,6 +123,7 @@
/// - NK_INCLUDE_DEFAULT_FONT
/// - NK_INCLUDE_STANDARD_VARARGS
/// - NK_INCLUDE_COMMAND_USERDATA
/// - NK_UINT_DRAW_INDEX
///
/// ### Constants
/// Define | Description
Expand Down Expand Up @@ -1083,12 +1085,12 @@ NK_API void nk_input_end(struct nk_context*);
///
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
/// // fill configuration
// struct your_vertex
// {
// float pos[2]; // important to keep it to 2 floats
// float uv[2];
// unsigned char col[4];
// };
/// struct your_vertex
/// {
/// float pos[2]; // important to keep it to 2 floats
/// float uv[2];
/// unsigned char col[4];
/// };
/// struct nk_convert_config cfg = {};
/// static const struct nk_draw_vertex_layout_element vertex_layout[] = {
/// {NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct your_vertex, pos)},
Expand Down Expand Up @@ -4593,7 +4595,11 @@ NK_API int nk_input_is_key_down(const struct nk_input*, enum nk_keys);
In fact it is probably more powerful than needed but allows even more crazy
things than this library provides by default.
*/
#ifdef NK_UINT_DRAW_INDEX
typedef nk_uint nk_draw_index;
#else
typedef nk_ushort nk_draw_index;
#endif
enum nk_draw_list_stroke {
NK_STROKE_OPEN = nk_false,
/* build up path has no connection back to the beginning */
Expand Down Expand Up @@ -9364,8 +9370,10 @@ nk_draw_list_alloc_vertices(struct nk_draw_list *list, nk_size count)
* backend (OpenGL, DirectX, ...). For example in OpenGL for `glDrawElements`
* instead of specifing `GL_UNSIGNED_SHORT` you have to define `GL_UNSIGNED_INT`.
* Sorry for the inconvenience. */
#ifndef NK_UINT_DRAW_INDEX
NK_ASSERT((sizeof(nk_draw_index) == 2 && list->vertex_count < NK_USHORT_MAX &&
"To many verticies for 16-bit vertex indicies. Please read comment above on how to solve this problem"));
#endif
return vtx;
}
NK_INTERN nk_draw_index*
Expand Down
2 changes: 2 additions & 0 deletions src/HEADER
Expand Up @@ -104,6 +104,7 @@
/// NK_INCLUDE_COMMAND_USERDATA | Defining this adds a userdata pointer into each command. Can be useful for example if you want to provide custom shaders depending on the used widget. Can be combined with the style structures.
/// NK_BUTTON_TRIGGER_ON_RELEASE | Different platforms require button clicks occurring either on buttons being pressed (up to down) or released (down to up). By default this library will react on buttons being pressed, but if you define this it will only trigger if a button is released.
/// NK_ZERO_COMMAND_MEMORY | Defining this will zero out memory for each drawing command added to a drawing queue (inside nk_command_buffer_push). Zeroing command memory is very useful for fast checking (using memcmp) if command buffers are equal and avoid drawing frames when nothing on screen has changed since previous frame.
/// NK_UINT_DRAW_INDEX | Defining this will set the size of vertex index elements when using NK_VERTEX_BUFFER_OUTPUT to 32bit instead of the default of 16bit
///
/// !!! WARNING
/// The following flags will pull in the standard C library:
Expand All @@ -121,6 +122,7 @@
/// - NK_INCLUDE_DEFAULT_FONT
/// - NK_INCLUDE_STANDARD_VARARGS
/// - NK_INCLUDE_COMMAND_USERDATA
/// - NK_UINT_DRAW_INDEX
///
/// ### Constants
/// Define | Description
Expand Down
10 changes: 10 additions & 0 deletions src/nuklear.h
Expand Up @@ -867,6 +867,12 @@ NK_API void nk_input_end(struct nk_context*);
///
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
/// // fill configuration
/// struct your_vertex
/// {
/// float pos[2]; // important to keep it to 2 floats
/// float uv[2];
/// unsigned char col[4];
/// };
/// struct nk_convert_config cfg = {};
/// static const struct nk_draw_vertex_layout_element vertex_layout[] = {
/// {NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct your_vertex, pos)},
Expand Down Expand Up @@ -4371,7 +4377,11 @@ NK_API int nk_input_is_key_down(const struct nk_input*, enum nk_keys);
In fact it is probably more powerful than needed but allows even more crazy
things than this library provides by default.
*/
#ifdef NK_UINT_DRAW_INDEX
typedef nk_uint nk_draw_index;
#else
typedef nk_ushort nk_draw_index;
#endif
enum nk_draw_list_stroke {
NK_STROKE_OPEN = nk_false,
/* build up path has no connection back to the beginning */
Expand Down
2 changes: 2 additions & 0 deletions src/nuklear_vertex.c
Expand Up @@ -233,8 +233,10 @@ nk_draw_list_alloc_vertices(struct nk_draw_list *list, nk_size count)
* backend (OpenGL, DirectX, ...). For example in OpenGL for `glDrawElements`
* instead of specifing `GL_UNSIGNED_SHORT` you have to define `GL_UNSIGNED_INT`.
* Sorry for the inconvenience. */
#ifndef NK_UINT_DRAW_INDEX
NK_ASSERT((sizeof(nk_draw_index) == 2 && list->vertex_count < NK_USHORT_MAX &&
"To many verticies for 16-bit vertex indicies. Please read comment above on how to solve this problem"));
#endif
return vtx;
}
NK_INTERN nk_draw_index*
Expand Down

0 comments on commit 2b03f44

Please sign in to comment.