mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-28 10:40:39 +00:00
More fixes for menu_display_ctl.
Grep shows nothing now.
This commit is contained in:
parent
66c4f608e6
commit
8870e85395
@ -413,9 +413,9 @@ static void gx_set_video_mode(void *data, unsigned fbWidth, unsigned lines,
|
||||
|
||||
new_fb_pitch = new_fb_width * 2;
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_WIDTH, &new_fb_width);
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_HEIGHT, &new_fb_height);
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_FB_PITCH, &new_fb_pitch);
|
||||
menu_display_set_width(new_fb_width);
|
||||
menu_display_set_height(new_fb_height);
|
||||
menu_display_set_framebuffer_pitch(new_fb_pitch);
|
||||
|
||||
GX_SetViewportJitter(0, 0, gx_mode.fbWidth, gx_mode.efbHeight, 0, 1, 1);
|
||||
GX_SetDispCopySrc(0, 0, gx_mode.fbWidth, gx_mode.efbHeight);
|
||||
@ -551,8 +551,8 @@ static void init_texture(void *data, unsigned width, unsigned height)
|
||||
menu_w = 320;
|
||||
menu_h = 240;
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_WIDTH, &menu_w);
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_HEIGHT, &menu_h);
|
||||
menu_w = menu_display_get_width();
|
||||
menu_h = menu_display_get_height();
|
||||
|
||||
GX_InitTexObj(fb_ptr, g_tex.data, width, height,
|
||||
(gx->rgb32) ? GX_TF_RGBA8 : gx->menu_texture_enable ?
|
||||
@ -1492,9 +1492,9 @@ static bool gx_frame(void *data, const void *frame,
|
||||
size_t fb_pitch;
|
||||
unsigned fb_width, fb_height;
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_WIDTH, &fb_width);
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_HEIGHT, &fb_height);
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_FB_PITCH, &fb_pitch);
|
||||
fb_width = menu_display_get_width();
|
||||
fb_height = menu_display_get_height();
|
||||
fb_pitch = menu_display_get_framebuffer_pitch();
|
||||
|
||||
convert_texture16(
|
||||
gx->menu_data,
|
||||
|
@ -340,7 +340,6 @@ static void android_input_poll_main_cmd(void)
|
||||
runloop_ctl(RUNLOOP_CTL_SET_PAUSED, &boolean);
|
||||
runloop_ctl(RUNLOOP_CTL_SET_IDLE, &boolean);
|
||||
#ifdef HAVE_MENU
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_UNSET_STUB_DRAW_FRAME, NULL);
|
||||
video_driver_unset_stub_frame();
|
||||
#endif
|
||||
|
||||
@ -363,7 +362,6 @@ static void android_input_poll_main_cmd(void)
|
||||
runloop_ctl(RUNLOOP_CTL_SET_PAUSED, &boolean);
|
||||
runloop_ctl(RUNLOOP_CTL_SET_IDLE, &boolean);
|
||||
#ifdef HAVE_MENU
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_STUB_DRAW_FRAME, NULL);
|
||||
video_driver_set_stub_frame();
|
||||
#endif
|
||||
|
||||
|
@ -1,279 +1,279 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2011-2016 - Daniel De Matteis
|
||||
* Copyright (C) 2014-2015 - Jean-Andr<EFBFBD> Santoni
|
||||
* Copyright (C) 2016 - Andr<EFBFBD>s Su<EFBFBD>rez
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <streams/file_stream.h>
|
||||
|
||||
#define NK_INCLUDE_FIXED_TYPES
|
||||
#define NK_INCLUDE_STANDARD_IO
|
||||
#define NK_INCLUDE_DEFAULT_ALLOCATOR
|
||||
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
|
||||
#define NK_INCLUDE_FONT_BAKING
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2011-2016 - Daniel De Matteis
|
||||
* Copyright (C) 2014-2015 - Jean-Andr<EFBFBD> Santoni
|
||||
* Copyright (C) 2016 - Andr<EFBFBD>s Su<EFBFBD>rez
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <streams/file_stream.h>
|
||||
|
||||
#define NK_INCLUDE_FIXED_TYPES
|
||||
#define NK_INCLUDE_STANDARD_IO
|
||||
#define NK_INCLUDE_DEFAULT_ALLOCATOR
|
||||
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
|
||||
#define NK_INCLUDE_FONT_BAKING
|
||||
#define NK_INCLUDE_DEFAULT_FONT
|
||||
#define NK_IMPLEMENTATION
|
||||
|
||||
#include "nk_common.h"
|
||||
|
||||
#include "../menu_display.h"
|
||||
#include "../../gfx/video_shader_driver.h"
|
||||
|
||||
#include "../../gfx/drivers/gl_shaders/pipeline_zahnrad.glsl.vert.h"
|
||||
#include "../../gfx/drivers/gl_shaders/pipeline_zahnrad.glsl.frag.h"
|
||||
|
||||
struct nk_font *font;
|
||||
struct nk_font_atlas atlas;
|
||||
struct nk_user_font usrfnt;
|
||||
struct nk_allocator nk_alloc;
|
||||
struct nk_device device;
|
||||
|
||||
struct nk_image nk_common_image_load(const char *filename)
|
||||
{
|
||||
int x,y,n;
|
||||
GLuint tex;
|
||||
unsigned char *data = stbi_load(filename, &x, &y, &n, 0);
|
||||
if (!data) printf("Failed to load image: %s\n", filename);
|
||||
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
glGenTextures(1, &tex);
|
||||
glBindTexture(GL_TEXTURE_2D, tex);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
#endif
|
||||
|
||||
stbi_image_free(data);
|
||||
return nk_image_id((int)tex);
|
||||
}
|
||||
|
||||
char* nk_common_file_load(const char* path, size_t* size)
|
||||
{
|
||||
void *buf;
|
||||
ssize_t *length = (ssize_t*)size;
|
||||
filestream_read_file(path, &buf, length);
|
||||
return (char*)buf;
|
||||
}
|
||||
|
||||
NK_API void nk_common_device_init(struct nk_device *dev)
|
||||
{
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
GLint status;
|
||||
|
||||
dev->prog = glCreateProgram();
|
||||
dev->vert_shdr = glCreateShader(GL_VERTEX_SHADER);
|
||||
dev->frag_shdr = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(dev->vert_shdr, 1, &zahnrad_vertex_shader, 0);
|
||||
glShaderSource(dev->frag_shdr, 1, &zahnrad_fragment_shader, 0);
|
||||
glCompileShader(dev->vert_shdr);
|
||||
glCompileShader(dev->frag_shdr);
|
||||
glGetShaderiv(dev->vert_shdr, GL_COMPILE_STATUS, &status);
|
||||
glGetShaderiv(dev->frag_shdr, GL_COMPILE_STATUS, &status);
|
||||
glAttachShader(dev->prog, dev->vert_shdr);
|
||||
glAttachShader(dev->prog, dev->frag_shdr);
|
||||
glLinkProgram(dev->prog);
|
||||
glGetProgramiv(dev->prog, GL_LINK_STATUS, &status);
|
||||
|
||||
dev->uniform_proj = glGetUniformLocation(dev->prog, "ProjMtx");
|
||||
dev->attrib_pos = glGetAttribLocation(dev->prog, "Position");
|
||||
dev->attrib_uv = glGetAttribLocation(dev->prog, "TexCoord");
|
||||
dev->attrib_col = glGetAttribLocation(dev->prog, "Color");
|
||||
|
||||
{
|
||||
/* buffer setup */
|
||||
GLsizei vs = sizeof(struct nk_draw_vertex);
|
||||
size_t vp = offsetof(struct nk_draw_vertex, position);
|
||||
size_t vt = offsetof(struct nk_draw_vertex, uv);
|
||||
size_t vc = offsetof(struct nk_draw_vertex, col);
|
||||
|
||||
glGenBuffers(1, &dev->vbo);
|
||||
glGenBuffers(1, &dev->ebo);
|
||||
glGenVertexArrays(1, &dev->vao);
|
||||
|
||||
glBindVertexArray(dev->vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, dev->vbo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dev->ebo);
|
||||
|
||||
glEnableVertexAttribArray((GLuint)dev->attrib_pos);
|
||||
glEnableVertexAttribArray((GLuint)dev->attrib_uv);
|
||||
glEnableVertexAttribArray((GLuint)dev->attrib_col);
|
||||
|
||||
glVertexAttribPointer((GLuint)dev->attrib_pos, 2, GL_FLOAT, GL_FALSE, vs, (void*)vp);
|
||||
glVertexAttribPointer((GLuint)dev->attrib_uv, 2, GL_FLOAT, GL_FALSE, vs, (void*)vt);
|
||||
glVertexAttribPointer((GLuint)dev->attrib_col, 4, GL_UNSIGNED_BYTE, GL_TRUE, vs, (void*)vc);
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void device_upload_atlas(struct nk_device *dev, const void *image, int width, int height)
|
||||
{
|
||||
glGenTextures(1, &dev->font_tex);
|
||||
glBindTexture(GL_TEXTURE_2D, dev->font_tex);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 0,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, image);
|
||||
}
|
||||
|
||||
void nk_common_device_shutdown(struct nk_device *dev)
|
||||
{
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
glDetachShader(dev->prog, dev->vert_shdr);
|
||||
glDetachShader(dev->prog, dev->frag_shdr);
|
||||
glDeleteShader(dev->vert_shdr);
|
||||
glDeleteShader(dev->frag_shdr);
|
||||
glDeleteProgram(dev->prog);
|
||||
glDeleteTextures(1, &dev->font_tex);
|
||||
glDeleteBuffers(1, &dev->vbo);
|
||||
glDeleteBuffers(1, &dev->ebo);
|
||||
#endif
|
||||
}
|
||||
|
||||
void nk_common_device_draw(struct nk_device *dev,
|
||||
struct nk_context *ctx, int width, int height,
|
||||
enum nk_anti_aliasing AA)
|
||||
{
|
||||
video_shader_ctx_info_t shader_info;
|
||||
struct nk_buffer vbuf, ebuf;
|
||||
struct nk_convert_config config;
|
||||
uintptr_t last_prog;
|
||||
const struct nk_draw_command *cmd = NULL;
|
||||
void *vertices = NULL;
|
||||
void *elements = NULL;
|
||||
const nk_draw_index *offset = NULL;
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
GLint last_tex;
|
||||
GLint last_ebo, last_vbo, last_vao;
|
||||
GLfloat ortho[4][4] = {
|
||||
{2.0f, 0.0f, 0.0f, 0.0f},
|
||||
{0.0f,-2.0f, 0.0f, 0.0f},
|
||||
{0.0f, 0.0f,-1.0f, 0.0f},
|
||||
{-1.0f,1.0f, 0.0f, 1.0f},
|
||||
};
|
||||
ortho[0][0] /= (GLfloat)width;
|
||||
ortho[1][1] /= (GLfloat)height;
|
||||
|
||||
/* save previous opengl state */
|
||||
glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&last_prog);
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_tex);
|
||||
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_vao);
|
||||
glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_ebo);
|
||||
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vbo);
|
||||
#endif
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_BLEND_BEGIN, NULL);
|
||||
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
#endif
|
||||
|
||||
/* setup program */
|
||||
shader_info.data = NULL;
|
||||
shader_info.idx = dev->prog;
|
||||
shader_info.set_active = false;
|
||||
video_shader_driver_ctl(SHADER_CTL_USE, &shader_info);
|
||||
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
glUniformMatrix4fv(dev->uniform_proj, 1, GL_FALSE, &ortho[0][0]);
|
||||
|
||||
/* convert from command queue into draw list and draw to screen */
|
||||
|
||||
/* allocate vertex and element buffer */
|
||||
glBindVertexArray(dev->vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, dev->vbo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dev->ebo);
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, MAX_VERTEX_MEMORY, NULL, GL_STREAM_DRAW);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, MAX_ELEMENT_MEMORY, NULL, GL_STREAM_DRAW);
|
||||
|
||||
/* load draw vertices & elements directly into vertex + element buffer */
|
||||
vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
#endif
|
||||
|
||||
/* fill converting configuration */
|
||||
memset(&config, 0, sizeof(config));
|
||||
|
||||
config.global_alpha = 1.0f;
|
||||
config.shape_AA = AA;
|
||||
config.line_AA = AA;
|
||||
config.circle_segment_count = 22;
|
||||
//config.line_thickness = 1.0f;
|
||||
config.null = dev->null;
|
||||
|
||||
/* setup buffers to load vertices and elements */
|
||||
nk_buffer_init_fixed(&vbuf, vertices, MAX_VERTEX_MEMORY);
|
||||
nk_buffer_init_fixed(&ebuf, elements, MAX_ELEMENT_MEMORY);
|
||||
nk_convert(ctx, &dev->cmds, &vbuf, &ebuf, &config);
|
||||
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
|
||||
#endif
|
||||
|
||||
/* iterate over and execute each draw command */
|
||||
nk_draw_foreach(cmd, ctx, &dev->cmds)
|
||||
{
|
||||
if (!cmd->elem_count)
|
||||
continue;
|
||||
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)cmd->texture.id);
|
||||
glScissor((GLint)cmd->clip_rect.x,
|
||||
height - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h),
|
||||
(GLint)cmd->clip_rect.w, (GLint)cmd->clip_rect.h);
|
||||
glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count,
|
||||
GL_UNSIGNED_SHORT, offset);
|
||||
#endif
|
||||
|
||||
offset += cmd->elem_count;
|
||||
}
|
||||
nk_clear(ctx);
|
||||
|
||||
/* restore old state */
|
||||
shader_info.data = NULL;
|
||||
shader_info.idx = (GLint)last_prog;
|
||||
shader_info.set_active = false;
|
||||
video_shader_driver_ctl(SHADER_CTL_USE, &shader_info);
|
||||
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)last_tex);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, (GLuint)last_vbo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, (GLuint)last_ebo);
|
||||
glBindVertexArray((GLuint)last_vao);
|
||||
#endif
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_BLEND_END, NULL);
|
||||
}
|
||||
|
||||
//void nk_mem_alloc(nk_handle a, void *old, nk_size b);
|
||||
void* nk_common_mem_alloc(nk_handle a, void *old, nk_size b)
|
||||
{
|
||||
(void)a;
|
||||
return calloc(1, b);
|
||||
}
|
||||
|
||||
void nk_common_mem_free(nk_handle unused, void *ptr)
|
||||
{
|
||||
(void)unused;
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
#include "nk_common.h"
|
||||
|
||||
#include "../menu_display.h"
|
||||
#include "../../gfx/video_shader_driver.h"
|
||||
|
||||
#include "../../gfx/drivers/gl_shaders/pipeline_zahnrad.glsl.vert.h"
|
||||
#include "../../gfx/drivers/gl_shaders/pipeline_zahnrad.glsl.frag.h"
|
||||
|
||||
struct nk_font *font;
|
||||
struct nk_font_atlas atlas;
|
||||
struct nk_user_font usrfnt;
|
||||
struct nk_allocator nk_alloc;
|
||||
struct nk_device device;
|
||||
|
||||
struct nk_image nk_common_image_load(const char *filename)
|
||||
{
|
||||
int x,y,n;
|
||||
GLuint tex;
|
||||
unsigned char *data = stbi_load(filename, &x, &y, &n, 0);
|
||||
if (!data) printf("Failed to load image: %s\n", filename);
|
||||
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
glGenTextures(1, &tex);
|
||||
glBindTexture(GL_TEXTURE_2D, tex);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
#endif
|
||||
|
||||
stbi_image_free(data);
|
||||
return nk_image_id((int)tex);
|
||||
}
|
||||
|
||||
char* nk_common_file_load(const char* path, size_t* size)
|
||||
{
|
||||
void *buf;
|
||||
ssize_t *length = (ssize_t*)size;
|
||||
filestream_read_file(path, &buf, length);
|
||||
return (char*)buf;
|
||||
}
|
||||
|
||||
NK_API void nk_common_device_init(struct nk_device *dev)
|
||||
{
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
GLint status;
|
||||
|
||||
dev->prog = glCreateProgram();
|
||||
dev->vert_shdr = glCreateShader(GL_VERTEX_SHADER);
|
||||
dev->frag_shdr = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(dev->vert_shdr, 1, &zahnrad_vertex_shader, 0);
|
||||
glShaderSource(dev->frag_shdr, 1, &zahnrad_fragment_shader, 0);
|
||||
glCompileShader(dev->vert_shdr);
|
||||
glCompileShader(dev->frag_shdr);
|
||||
glGetShaderiv(dev->vert_shdr, GL_COMPILE_STATUS, &status);
|
||||
glGetShaderiv(dev->frag_shdr, GL_COMPILE_STATUS, &status);
|
||||
glAttachShader(dev->prog, dev->vert_shdr);
|
||||
glAttachShader(dev->prog, dev->frag_shdr);
|
||||
glLinkProgram(dev->prog);
|
||||
glGetProgramiv(dev->prog, GL_LINK_STATUS, &status);
|
||||
|
||||
dev->uniform_proj = glGetUniformLocation(dev->prog, "ProjMtx");
|
||||
dev->attrib_pos = glGetAttribLocation(dev->prog, "Position");
|
||||
dev->attrib_uv = glGetAttribLocation(dev->prog, "TexCoord");
|
||||
dev->attrib_col = glGetAttribLocation(dev->prog, "Color");
|
||||
|
||||
{
|
||||
/* buffer setup */
|
||||
GLsizei vs = sizeof(struct nk_draw_vertex);
|
||||
size_t vp = offsetof(struct nk_draw_vertex, position);
|
||||
size_t vt = offsetof(struct nk_draw_vertex, uv);
|
||||
size_t vc = offsetof(struct nk_draw_vertex, col);
|
||||
|
||||
glGenBuffers(1, &dev->vbo);
|
||||
glGenBuffers(1, &dev->ebo);
|
||||
glGenVertexArrays(1, &dev->vao);
|
||||
|
||||
glBindVertexArray(dev->vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, dev->vbo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dev->ebo);
|
||||
|
||||
glEnableVertexAttribArray((GLuint)dev->attrib_pos);
|
||||
glEnableVertexAttribArray((GLuint)dev->attrib_uv);
|
||||
glEnableVertexAttribArray((GLuint)dev->attrib_col);
|
||||
|
||||
glVertexAttribPointer((GLuint)dev->attrib_pos, 2, GL_FLOAT, GL_FALSE, vs, (void*)vp);
|
||||
glVertexAttribPointer((GLuint)dev->attrib_uv, 2, GL_FLOAT, GL_FALSE, vs, (void*)vt);
|
||||
glVertexAttribPointer((GLuint)dev->attrib_col, 4, GL_UNSIGNED_BYTE, GL_TRUE, vs, (void*)vc);
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void device_upload_atlas(struct nk_device *dev, const void *image, int width, int height)
|
||||
{
|
||||
glGenTextures(1, &dev->font_tex);
|
||||
glBindTexture(GL_TEXTURE_2D, dev->font_tex);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 0,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, image);
|
||||
}
|
||||
|
||||
void nk_common_device_shutdown(struct nk_device *dev)
|
||||
{
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
glDetachShader(dev->prog, dev->vert_shdr);
|
||||
glDetachShader(dev->prog, dev->frag_shdr);
|
||||
glDeleteShader(dev->vert_shdr);
|
||||
glDeleteShader(dev->frag_shdr);
|
||||
glDeleteProgram(dev->prog);
|
||||
glDeleteTextures(1, &dev->font_tex);
|
||||
glDeleteBuffers(1, &dev->vbo);
|
||||
glDeleteBuffers(1, &dev->ebo);
|
||||
#endif
|
||||
}
|
||||
|
||||
void nk_common_device_draw(struct nk_device *dev,
|
||||
struct nk_context *ctx, int width, int height,
|
||||
enum nk_anti_aliasing AA)
|
||||
{
|
||||
video_shader_ctx_info_t shader_info;
|
||||
struct nk_buffer vbuf, ebuf;
|
||||
struct nk_convert_config config;
|
||||
uintptr_t last_prog;
|
||||
const struct nk_draw_command *cmd = NULL;
|
||||
void *vertices = NULL;
|
||||
void *elements = NULL;
|
||||
const nk_draw_index *offset = NULL;
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
GLint last_tex;
|
||||
GLint last_ebo, last_vbo, last_vao;
|
||||
GLfloat ortho[4][4] = {
|
||||
{2.0f, 0.0f, 0.0f, 0.0f},
|
||||
{0.0f,-2.0f, 0.0f, 0.0f},
|
||||
{0.0f, 0.0f,-1.0f, 0.0f},
|
||||
{-1.0f,1.0f, 0.0f, 1.0f},
|
||||
};
|
||||
ortho[0][0] /= (GLfloat)width;
|
||||
ortho[1][1] /= (GLfloat)height;
|
||||
|
||||
/* save previous opengl state */
|
||||
glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&last_prog);
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_tex);
|
||||
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_vao);
|
||||
glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_ebo);
|
||||
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vbo);
|
||||
#endif
|
||||
|
||||
menu_display_blend_begin();
|
||||
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
#endif
|
||||
|
||||
/* setup program */
|
||||
shader_info.data = NULL;
|
||||
shader_info.idx = dev->prog;
|
||||
shader_info.set_active = false;
|
||||
video_shader_driver_ctl(SHADER_CTL_USE, &shader_info);
|
||||
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
glUniformMatrix4fv(dev->uniform_proj, 1, GL_FALSE, &ortho[0][0]);
|
||||
|
||||
/* convert from command queue into draw list and draw to screen */
|
||||
|
||||
/* allocate vertex and element buffer */
|
||||
glBindVertexArray(dev->vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, dev->vbo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dev->ebo);
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, MAX_VERTEX_MEMORY, NULL, GL_STREAM_DRAW);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, MAX_ELEMENT_MEMORY, NULL, GL_STREAM_DRAW);
|
||||
|
||||
/* load draw vertices & elements directly into vertex + element buffer */
|
||||
vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
#endif
|
||||
|
||||
/* fill converting configuration */
|
||||
memset(&config, 0, sizeof(config));
|
||||
|
||||
config.global_alpha = 1.0f;
|
||||
config.shape_AA = AA;
|
||||
config.line_AA = AA;
|
||||
config.circle_segment_count = 22;
|
||||
//config.line_thickness = 1.0f;
|
||||
config.null = dev->null;
|
||||
|
||||
/* setup buffers to load vertices and elements */
|
||||
nk_buffer_init_fixed(&vbuf, vertices, MAX_VERTEX_MEMORY);
|
||||
nk_buffer_init_fixed(&ebuf, elements, MAX_ELEMENT_MEMORY);
|
||||
nk_convert(ctx, &dev->cmds, &vbuf, &ebuf, &config);
|
||||
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
|
||||
#endif
|
||||
|
||||
/* iterate over and execute each draw command */
|
||||
nk_draw_foreach(cmd, ctx, &dev->cmds)
|
||||
{
|
||||
if (!cmd->elem_count)
|
||||
continue;
|
||||
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)cmd->texture.id);
|
||||
glScissor((GLint)cmd->clip_rect.x,
|
||||
height - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h),
|
||||
(GLint)cmd->clip_rect.w, (GLint)cmd->clip_rect.h);
|
||||
glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count,
|
||||
GL_UNSIGNED_SHORT, offset);
|
||||
#endif
|
||||
|
||||
offset += cmd->elem_count;
|
||||
}
|
||||
nk_clear(ctx);
|
||||
|
||||
/* restore old state */
|
||||
shader_info.data = NULL;
|
||||
shader_info.idx = (GLint)last_prog;
|
||||
shader_info.set_active = false;
|
||||
video_shader_driver_ctl(SHADER_CTL_USE, &shader_info);
|
||||
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)last_tex);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, (GLuint)last_vbo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, (GLuint)last_ebo);
|
||||
glBindVertexArray((GLuint)last_vao);
|
||||
#endif
|
||||
|
||||
menu_display_blend_end();
|
||||
}
|
||||
|
||||
//void nk_mem_alloc(nk_handle a, void *old, nk_size b);
|
||||
void* nk_common_mem_alloc(nk_handle a, void *old, nk_size b)
|
||||
{
|
||||
(void)a;
|
||||
return calloc(1, b);
|
||||
}
|
||||
|
||||
void nk_common_mem_free(nk_handle unused, void *ptr)
|
||||
{
|
||||
(void)unused;
|
||||
free(ptr);
|
||||
}
|
||||
|
@ -174,15 +174,14 @@ static void nk_menu_frame(void *data)
|
||||
nk_menu_handle_t *nk = (nk_menu_handle_t*)data;
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
bool libretro_running = menu_display_ctl(
|
||||
MENU_DISPLAY_CTL_LIBRETRO_RUNNING, NULL);
|
||||
bool libretro_running = menu_display_libretro_running();
|
||||
|
||||
if (!nk)
|
||||
return;
|
||||
|
||||
video_driver_get_size(&width, &height);
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_VIEWPORT, NULL);
|
||||
menu_display_set_viewport();
|
||||
|
||||
nk_input_begin(&nk->ctx);
|
||||
nk_menu_input_gamepad(nk);
|
||||
@ -212,22 +211,19 @@ static void nk_menu_frame(void *data)
|
||||
width,
|
||||
height);
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_RESTORE_CLEAR_COLOR, NULL);
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_UNSET_VIEWPORT, NULL);
|
||||
menu_display_restore_clear_color();
|
||||
menu_display_unset_viewport();
|
||||
}
|
||||
|
||||
static void nk_menu_layout(nk_menu_handle_t *nk)
|
||||
{
|
||||
void *fb_buf;
|
||||
float scale_factor;
|
||||
unsigned width, height, new_header_height;
|
||||
|
||||
video_driver_get_size(&width, &height);
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_GET_DPI, &scale_factor);
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_HEADER_HEIGHT,
|
||||
&new_header_height);
|
||||
|
||||
scale_factor = menu_display_get_dpi();
|
||||
menu_display_set_header_height(new_header_height);
|
||||
}
|
||||
|
||||
static void nk_menu_init_device(nk_menu_handle_t *nk)
|
||||
@ -285,7 +281,7 @@ static void *nk_menu_init(void **userdata)
|
||||
if (!menu)
|
||||
goto error;
|
||||
|
||||
if (!menu_display_ctl(MENU_DISPLAY_CTL_INIT_FIRST_DRIVER, NULL))
|
||||
if (!menu_display_init_first_driver())
|
||||
goto error;
|
||||
|
||||
nk = (nk_menu_handle_t*)calloc(1, sizeof(nk_menu_handle_t));
|
||||
@ -339,8 +335,7 @@ static void nk_menu_context_destroy(void *data)
|
||||
for (i = 0; i < NK_TEXTURE_LAST; i++)
|
||||
video_driver_texture_unload((uintptr_t*)&nk->textures.list[i]);
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_FONT_MAIN_DEINIT, NULL);
|
||||
|
||||
menu_display_font_main_deinit();
|
||||
wimp_context_bg_destroy(nk);
|
||||
}
|
||||
|
||||
|
@ -417,7 +417,7 @@ static void xui_frame(void *data)
|
||||
if (!d3dr)
|
||||
return;
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_VIEWPORT, NULL);
|
||||
menu_display_set_viewport();
|
||||
|
||||
app.RunFrame();
|
||||
XuiTimersRun();
|
||||
@ -445,7 +445,7 @@ static void xui_frame(void *data)
|
||||
|
||||
XuiRenderEnd( app.GetDC() );
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_UNSET_VIEWPORT, NULL);
|
||||
menu_display_unset_viewport();
|
||||
}
|
||||
|
||||
static void blit_line(int x, int y, const char *message, bool green)
|
||||
@ -454,7 +454,7 @@ static void blit_line(int x, int y, const char *message, bool green)
|
||||
|
||||
static void xui_render_background(void)
|
||||
{
|
||||
if (menu_display_ctl(MENU_DISPLAY_CTL_LIBRETRO_RUNNING, NULL))
|
||||
if (menu_display_libretro_running())
|
||||
XuiElementSetShow(m_background, FALSE);
|
||||
else
|
||||
XuiElementSetShow(m_background, TRUE);
|
||||
@ -536,8 +536,8 @@ static void xui_render(void *data)
|
||||
|
||||
frame_count = video_driver_get_frame_count_ptr();
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_WIDTH, &fb_width);
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_MSG_FORCE, &msg_force);
|
||||
fb_width = menu_display_get_width();
|
||||
msg_force = menu_display_get_msg_force();
|
||||
|
||||
if (
|
||||
menu_entries_ctl(MENU_ENTRIES_CTL_NEEDS_REFRESH, NULL)
|
||||
@ -546,7 +546,7 @@ static void xui_render(void *data)
|
||||
)
|
||||
return;
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_UNSET_FRAMEBUFFER_DIRTY_FLAG, NULL);
|
||||
menu_display_unset_framebuffer_dirty_flag();
|
||||
menu_animation_ctl(MENU_ANIMATION_CTL_CLEAR_ACTIVE, NULL);
|
||||
|
||||
xui_render_background();
|
||||
|
@ -186,7 +186,7 @@ static void menu_display_d3d_draw_pipeline(void *data)
|
||||
static float t = 0;
|
||||
gfx_coord_array_t *ca = NULL;
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_COORDS_ARRAY_GET, &ca);
|
||||
ca = menu_display_get_coords_array();
|
||||
|
||||
draw->x = 0;
|
||||
draw->y = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user