comparison nuklear_ui/nuklear_sdl_gles2.h @ 1825:56a1171e29b9

Allow Nuklear UI to be used when OpenGL is disabled
author Michael Pavone <pavone@retrodev.com>
date Thu, 04 Apr 2019 23:08:45 -0700
parents fa9ae059e4d3
children e07fc3d473b2
comparison
equal deleted inserted replaced
1824:62dd62c83b05 1825:56a1171e29b9
45 */ 45 */
46 #ifdef NK_SDL_GLES2_IMPLEMENTATION 46 #ifdef NK_SDL_GLES2_IMPLEMENTATION
47 47
48 #include <string.h> 48 #include <string.h>
49 49
50 #ifndef DISABLE_OPENGL
50 struct nk_sdl_device { 51 struct nk_sdl_device {
51 struct nk_buffer cmds; 52 struct nk_buffer cmds;
52 struct nk_draw_null_texture null; 53 struct nk_draw_null_texture null;
53 GLuint vbo, ebo; 54 GLuint vbo, ebo;
54 GLuint prog; 55 GLuint prog;
67 struct nk_sdl_vertex { 68 struct nk_sdl_vertex {
68 GLfloat position[2]; 69 GLfloat position[2];
69 GLfloat uv[2]; 70 GLfloat uv[2];
70 nk_byte col[4]; 71 nk_byte col[4];
71 }; 72 };
73 #endif
72 74
73 static struct nk_sdl { 75 static struct nk_sdl {
74 SDL_Window *win; 76 SDL_Window *win;
77 #ifndef DISABLE_OPENGL
75 struct nk_sdl_device ogl; 78 struct nk_sdl_device ogl;
79 #endif
76 struct nk_context ctx; 80 struct nk_context ctx;
77 struct nk_font_atlas atlas; 81 struct nk_font_atlas atlas;
78 } sdl; 82 } sdl;
79 83
80 #ifdef USE_GLES 84 #ifdef USE_GLES
83 #else 87 #else
84 #define NK_SHADER_VERSION "#version 110\n" 88 #define NK_SHADER_VERSION "#version 110\n"
85 #define DECLARE_PRECISION 89 #define DECLARE_PRECISION
86 #endif 90 #endif
87 91
88 92 #ifndef DISABLE_OPENGL
89 NK_API void 93 NK_API void
90 nk_sdl_device_create(void) 94 nk_sdl_device_create(void)
91 { 95 {
92 GLint status; 96 GLint status;
93 static const GLchar *vertex_shader = 97 static const GLchar *vertex_shader =
294 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 298 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
295 299
296 glDisable(GL_BLEND); 300 glDisable(GL_BLEND);
297 glDisable(GL_SCISSOR_TEST); 301 glDisable(GL_SCISSOR_TEST);
298 } 302 }
303 #endif
299 304
300 static void 305 static void
301 nk_sdl_clipbard_paste(nk_handle usr, struct nk_text_edit *edit) 306 nk_sdl_clipbard_paste(nk_handle usr, struct nk_text_edit *edit)
302 { 307 {
303 const char *text = SDL_GetClipboardText(); 308 const char *text = SDL_GetClipboardText();
325 sdl.win = win; 330 sdl.win = win;
326 nk_init_default(&sdl.ctx, 0); 331 nk_init_default(&sdl.ctx, 0);
327 sdl.ctx.clip.copy = nk_sdl_clipbard_copy; 332 sdl.ctx.clip.copy = nk_sdl_clipbard_copy;
328 sdl.ctx.clip.paste = nk_sdl_clipbard_paste; 333 sdl.ctx.clip.paste = nk_sdl_clipbard_paste;
329 sdl.ctx.clip.userdata = nk_handle_ptr(0); 334 sdl.ctx.clip.userdata = nk_handle_ptr(0);
330 nk_sdl_device_create();
331 return &sdl.ctx; 335 return &sdl.ctx;
332 } 336 }
333 337
338 #ifndef DISABLE_OPENGL
334 NK_API void 339 NK_API void
335 nk_sdl_font_stash_begin(struct nk_font_atlas **atlas) 340 nk_sdl_font_stash_begin(struct nk_font_atlas **atlas)
336 { 341 {
337 nk_font_atlas_init_default(&sdl.atlas); 342 nk_font_atlas_init_default(&sdl.atlas);
338 nk_font_atlas_begin(&sdl.atlas); 343 nk_font_atlas_begin(&sdl.atlas);
348 nk_font_atlas_end(&sdl.atlas, nk_handle_id((int)sdl.ogl.font_tex), &sdl.ogl.null); 353 nk_font_atlas_end(&sdl.atlas, nk_handle_id((int)sdl.ogl.font_tex), &sdl.ogl.null);
349 if (sdl.atlas.default_font) 354 if (sdl.atlas.default_font)
350 nk_style_set_font(&sdl.ctx, &sdl.atlas.default_font->handle); 355 nk_style_set_font(&sdl.ctx, &sdl.atlas.default_font->handle);
351 356
352 } 357 }
358 #endif
353 359
354 NK_API int 360 NK_API int
355 nk_sdl_handle_event(SDL_Event *evt) 361 nk_sdl_handle_event(SDL_Event *evt)
356 { 362 {
357 struct nk_context *ctx = &sdl.ctx; 363 struct nk_context *ctx = &sdl.ctx;
445 NK_API 451 NK_API
446 void nk_sdl_shutdown(void) 452 void nk_sdl_shutdown(void)
447 { 453 {
448 nk_font_atlas_clear(&sdl.atlas); 454 nk_font_atlas_clear(&sdl.atlas);
449 nk_free(&sdl.ctx); 455 nk_free(&sdl.ctx);
456 #ifndef DISABLE_OPENGL
450 nk_sdl_device_destroy(); 457 nk_sdl_device_destroy();
458 #endif
451 memset(&sdl, 0, sizeof(sdl)); 459 memset(&sdl, 0, sizeof(sdl));
452 } 460 }
453 461
454 #endif 462 #endif