diff --git a/bootstrap/vita/sbrk.c b/bootstrap/vita/sbrk.c index 471b56ccd4..5159623c73 100644 --- a/bootstrap/vita/sbrk.c +++ b/bootstrap/vita/sbrk.c @@ -4,7 +4,7 @@ #include #include -#define RAM_THRESHOLD 0xA00000 // Memory left to the system for threads and other internal stuffs +#define RAM_THRESHOLD 0x1000000 // Memory left to the system for threads and other internal stuffs int _newlib_heap_memblock; unsigned _newlib_heap_size; diff --git a/gfx/drivers/gl1.c b/gfx/drivers/gl1.c index dc11972c2c..f693319ff9 100644 --- a/gfx/drivers/gl1.c +++ b/gfx/drivers/gl1.c @@ -286,7 +286,7 @@ static void *gl1_gfx_init(const video_info_t *video, mode.width = 0; mode.height = 0; #ifdef VITA - vglInitExtended(0x1400000, full_x, full_y, 0x1000000, SCE_GXM_MULTISAMPLE_4X); + vglInitExtended(0x1400000, full_x, full_y, 0x100000, SCE_GXM_MULTISAMPLE_4X); vglUseVram(GL_TRUE); vglStartRendering(); #endif @@ -574,11 +574,6 @@ static void draw_tex(gl1_t *gl1, int pot_width, int pot_height, int width, int h #endif glBindTexture(GL_TEXTURE_2D, tex); - - /* For whatever reason you can't send NULL in GLDirect, - so we send the frame as dummy data */ - glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, pot_width, pot_height, 0, format, type, frame_to_copy); - frame = (uint8_t*)frame_to_copy; if (!gl1->supports_bgra) { @@ -600,9 +595,10 @@ static void draw_tex(gl1_t *gl1, int pot_width, int pot_height, int width, int h frame = frame_rgba; } } - - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, frame); - free(frame_rgba); + RARCH_LOG("draw_tex\n"); + glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, pot_width, pot_height, 0, format, type, frame); + if (frame_rgba) + free(frame_rgba); if (tex == gl1->tex) { @@ -643,45 +639,44 @@ static void draw_tex(gl1_t *gl1, int pot_width, int pot_height, int width, int h if (gl1->rotation && tex == gl1->tex) glRotatef(gl1->rotation, 0.0f, 0.0f, 1.0f); + + float vertices[] = { + -1.0f, -1.0f, 0.0f, + -1.0f, 1.0f, 0.0f, + 1.0f, 1.0f, 0.0f, + 1.0f, -1.0f, 0.0f + }; + + float colors[] = { + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f + }; + + float norm_width = (1.0f / (float)pot_width) * (float)width; + float norm_height = (1.0f / (float)pot_height) * (float)height; + + float texcoords[] = { + 0.0f, norm_height, + 0.0f, 0.0f, + norm_width, 1.0f, + norm_width, norm_height + }; + + glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + + glColorPointer(4, GL_FLOAT, 0, colors); + glVertexPointer(3, GL_FLOAT, 0, vertices); + glTexCoordPointer(2, GL_FLOAT, 0, texcoords); - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - - glBegin(GL_QUADS); - - { - float tex_BL[2] = {0.0f, 0.0f}; - float tex_BR[2] = {1.0f, 0.0f}; - float tex_TL[2] = {0.0f, 1.0f}; - float tex_TR[2] = {1.0f, 1.0f}; - float *tex_mirror_BL = tex_TL; - float *tex_mirror_BR = tex_TR; - float *tex_mirror_TL = tex_BL; - float *tex_mirror_TR = tex_BR; - float norm_width = (1.0f / (float)pot_width) * (float)width; - float norm_height = (1.0f / (float)pot_height) * (float)height; - - /* remove extra POT padding */ - tex_mirror_BR[0] = norm_width; - tex_mirror_TR[0] = norm_width; - - /* normally this would be 1.0 - height, but we're drawing upside-down */ - tex_mirror_BL[1] = norm_height; - tex_mirror_BR[1] = norm_height; - - glTexCoord2f(tex_mirror_BL[0], tex_mirror_BL[1]); - glVertex2f(-1.0f, -1.0f); - - glTexCoord2f(tex_mirror_TL[0], tex_mirror_TL[1]); - glVertex2f(-1.0f, 1.0f); - - glTexCoord2f(tex_mirror_TR[0], tex_mirror_TR[1]); - glVertex2f(1.0f, 1.0f); - - glTexCoord2f(tex_mirror_BR[0], tex_mirror_BR[1]); - glVertex2f(1.0f, -1.0f); - } - - glEnd(); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); glMatrixMode(GL_MODELVIEW); glPopMatrix(); @@ -1275,6 +1270,7 @@ static void gl1_load_texture_data( #ifndef VITA glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); #endif + RARCH_LOG("gl1_load_texture_data\n"); glTexImage2D(GL_TEXTURE_2D, 0, (use_rgba || !rgb32) ? GL_RGBA : RARCH_GL1_INTERNAL_FORMAT32, diff --git a/gfx/drivers_context/vita_ctx.c b/gfx/drivers_context/vita_ctx.c new file mode 100644 index 0000000000..a795297e2b --- /dev/null +++ b/gfx/drivers_context/vita_ctx.c @@ -0,0 +1,321 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2018 - M4xw + * + * 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 . + */ + +#include + +#include + +#ifdef HAVE_CONFIG_H +#include "../../config.h" +#endif + +#include "../common/orbis_common.h" +#include "../../frontend/frontend_driver.h" +#include "../../configuration.h" + +static enum gfx_ctx_api ctx_orbis_api = GFX_CTX_OPENGL_API; + +orbis_ctx_data_t *nx_ctx_ptr = NULL; + +extern bool platform_orbis_has_focus; + +void orbis_ctx_destroy(void *data) +{ + orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data; + + if (ctx_orbis) + { +#ifdef HAVE_EGL + egl_destroy(&ctx_orbis->egl); +#endif + ctx_orbis->resize = false; + free(ctx_orbis); + } +} + +static void orbis_ctx_get_video_size(void *data, + unsigned *width, unsigned *height) +{ + orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data; + + *width = ATTR_ORBISGL_WIDTH; + *height = ATTR_ORBISGL_HEIGHT; +} + +static void *orbis_ctx_init(video_frame_info_t *video_info, void *video_driver) +{ +#ifdef HAVE_EGL + int ret; + EGLint n; + EGLint major, minor; + static const EGLint attribs[] = { + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, 8, + EGL_DEPTH_SIZE, 16, + EGL_STENCIL_SIZE, 0, + EGL_SAMPLE_BUFFERS, 0, + EGL_SAMPLES, 0, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_NONE}; +#endif + + orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)calloc(1, sizeof(*ctx_orbis)); + + if (!ctx_orbis) + return NULL; + + nx_ctx_ptr = ctx_orbis; + +#ifdef HAVE_EGL + + memset(&ctx_orbis->pgl_config, 0, sizeof(ctx_orbis->pgl_config)); + { + ctx_orbis->pgl_config.size=sizeof(ctx_orbis->pgl_config); + ctx_orbis->pgl_config.flags=SCE_PGL_FLAGS_USE_COMPOSITE_EXT | SCE_PGL_FLAGS_USE_FLEXIBLE_MEMORY | 0x60; + ctx_orbis->pgl_config.processOrder=1; + ctx_orbis->pgl_config.systemSharedMemorySize=0x200000; + ctx_orbis->pgl_config.videoSharedMemorySize=0x2400000; + ctx_orbis->pgl_config.maxMappedFlexibleMemory=0xAA00000; + ctx_orbis->pgl_config.drawCommandBufferSize=0xC0000; + ctx_orbis->pgl_config.lcueResourceBufferSize=0x10000; + ctx_orbis->pgl_config.dbgPosCmd_0x40=ATTR_ORBISGL_WIDTH; + ctx_orbis->pgl_config.dbgPosCmd_0x44=ATTR_ORBISGL_HEIGHT; + ctx_orbis->pgl_config.dbgPosCmd_0x48=0; + ctx_orbis->pgl_config.dbgPosCmd_0x4C=0; + ctx_orbis->pgl_config.unk_0x5C=2; + } + ret = scePigletSetConfigurationVSH(&ctx_orbis->pgl_config); + if (!ret) + { + printf("[ORBISGL] scePigletSetConfigurationVSH failed 0x%08X.\n",ret); + goto error; + } + + if (!egl_init_context(&ctx_orbis->egl, EGL_NONE, EGL_DEFAULT_DISPLAY, + &major, &minor, &n, attribs, NULL)) + { + egl_report_error(); + printf("[ORBIS]: EGL error: %d.\n", eglGetError()); + goto error; + } +#endif + + return ctx_orbis; + +error: + orbis_ctx_destroy(video_driver); + return NULL; +} + +static void orbis_ctx_check_window(void *data, bool *quit, + bool *resize, unsigned *width, unsigned *height, bool is_shutdown) +{ + unsigned new_width, new_height; + + orbis_ctx_get_video_size(data, &new_width, &new_height); + + if (new_width != *width || new_height != *height) + { + *width = new_width; + *height = new_height; + *resize = true; + } + + *quit = (bool)false; +} + +static bool orbis_ctx_set_video_mode(void *data, + video_frame_info_t *video_info, + unsigned width, unsigned height, + bool fullscreen) +{ + /* Create an EGL rendering context */ + static const EGLint contextAttributeList[] = + { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE}; + + orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data; + + ctx_orbis->width = ATTR_ORBISGL_WIDTH; + ctx_orbis->height = ATTR_ORBISGL_HEIGHT; + + ctx_orbis->native_window.width = ctx_orbis->width; + ctx_orbis->native_window.height = ctx_orbis->height; + + ctx_orbis->refresh_rate = 60; + +#ifdef HAVE_EGL + if (!egl_create_context(&ctx_orbis->egl, contextAttributeList)) + { + egl_report_error(); + goto error; + } +#endif + +#ifdef HAVE_EGL + if (!egl_create_surface(&ctx_orbis->egl, &ctx_orbis->native_window)) + goto error; +#endif + + return true; + +error: + printf("[ctx_orbis]: EGL error: %d.\n", eglGetError()); + orbis_ctx_destroy(data); + + return false; +} + +static void orbis_ctx_input_driver(void *data, + const char *name, + input_driver_t **input, void **input_data) +{ + *input = NULL; + *input_data = NULL; +} + +static enum gfx_ctx_api orbis_ctx_get_api(void *data) +{ + return ctx_orbis_api; +} + +static bool orbis_ctx_bind_api(void *data, + enum gfx_ctx_api api, unsigned major, unsigned minor) +{ + (void)data; + ctx_orbis_api = api; + + if (api == GFX_CTX_OPENGL_ES_API) + if (eglBindAPI(EGL_OPENGL_ES_API) != EGL_FALSE) + return true; + + return false; +} + +static bool orbis_ctx_has_focus(void *data) +{ + (void)data; + return true; +} + +static bool orbis_ctx_suppress_screensaver(void *data, bool enable) +{ + (void)data; + (void)enable; + return false; +} + +static void orbis_ctx_set_swap_interval(void *data, + int swap_interval) +{ + orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data; + +#ifdef HAVE_EGL + egl_set_swap_interval(&ctx_orbis->egl, 0); +#endif +} + +static void orbis_ctx_swap_buffers(void *data, void *data2) +{ + orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data; + +#ifdef HAVE_EGL + egl_swap_buffers(&ctx_orbis->egl); +#endif +} + +static gfx_ctx_proc_t orbis_ctx_get_proc_address(const char *symbol) +{ +#ifdef HAVE_EGL + return egl_get_proc_address(symbol); +#endif +} + +static void orbis_ctx_bind_hw_render(void *data, bool enable) +{ + orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data; + +#ifdef HAVE_EGL + egl_bind_hw_render(&ctx_orbis->egl, enable); +#endif +} + +static uint32_t orbis_ctx_get_flags(void *data) +{ + uint32_t flags = 0; + + if (string_is_equal(video_driver_get_ident(), "glcore")) + { +#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS) + BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG); +#endif + } + else + { + BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL); + } + + return flags; +} + +static void orbis_ctx_set_flags(void *data, uint32_t flags) +{ + (void)data; +} + +static float orbis_ctx_get_refresh_rate(void *data) +{ + orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data; + + return ctx_orbis->refresh_rate; +} + +const gfx_ctx_driver_t orbis_ctx = { + orbis_ctx_init, + orbis_ctx_destroy, + orbis_ctx_get_api, + orbis_ctx_bind_api, + orbis_ctx_set_swap_interval, + orbis_ctx_set_video_mode, + orbis_ctx_get_video_size, + orbis_ctx_get_refresh_rate, + NULL, /* get_video_output_size */ + NULL, /* get_video_output_prev */ + NULL, /* get_video_output_next */ + NULL, /* get_metrics */ + NULL, + NULL, /* update_title */ + orbis_ctx_check_window, + NULL, /* set_resize */ + orbis_ctx_has_focus, + orbis_ctx_suppress_screensaver, + false, /* has_windowed */ + orbis_ctx_swap_buffers, + orbis_ctx_input_driver, + orbis_ctx_get_proc_address, + NULL, + NULL, + NULL, + "orbis", + orbis_ctx_get_flags, + orbis_ctx_set_flags, + orbis_ctx_bind_hw_render, + NULL, + NULL}; diff --git a/gfx/drivers_font/gl1_raster_font.c b/gfx/drivers_font/gl1_raster_font.c index dbd13a50b7..6272b3ce47 100644 --- a/gfx/drivers_font/gl1_raster_font.c +++ b/gfx/drivers_font/gl1_raster_font.c @@ -43,6 +43,10 @@ #define MAX_MSG_LEN_CHUNK 64 +#ifdef VITA +static float *vertices3 = NULL; +#endif + typedef struct { gl1_t *gl; @@ -78,8 +82,8 @@ static void gl1_raster_font_free_font(void *data, free(font); } -#if 0 -static bool gl1_raster_font_upload_atlas_components_4(gl1_raster_t *font) +#ifdef VITA +static bool gl1_raster_font_upload_atlas(gl1_raster_t *font) { unsigned i, j; GLint gl_internal = GL_RGBA; @@ -111,8 +115,7 @@ static bool gl1_raster_font_upload_atlas_components_4(gl1_raster_t *font) return true; } -#endif - +#else static bool gl1_raster_font_upload_atlas(gl1_raster_t *font) { unsigned i, j; @@ -156,7 +159,7 @@ static bool gl1_raster_font_upload_atlas(gl1_raster_t *font) return true; } - +#endif static void *gl1_raster_font_init_font(void *data, const char *font_path, float font_size, bool is_threaded) @@ -263,8 +266,21 @@ static void gl1_raster_font_draw_vertices(gl1_raster_t *font, glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glColorPointer(4, GL_FLOAT, 0, coords->color); +#ifdef VITA + if (vertices3) + free(vertices3); + vertices3 = (float*)malloc(sizeof(float) * 3 * coords->vertices); + int i; + for (i = 0; i < coords->vertices; i++) { + memcpy(&vertices3[i*3], &coords->vertex[i*2], sizeof(float) * 2); + vertices3[i*3+2] = 0.0f; + } + glVertexPointer(3, GL_FLOAT, 0, vertices3); +#else glVertexPointer(2, GL_FLOAT, 0, coords->vertex); +#endif + + glColorPointer(4, GL_FLOAT, 0, coords->color); glTexCoordPointer(2, GL_FLOAT, 0, coords->tex_coord); glDrawArrays(GL_TRIANGLES, 0, coords->vertices); diff --git a/menu/drivers_display/menu_display_gl1.c b/menu/drivers_display/menu_display_gl1.c index f27e5b7ba7..77c292082d 100644 --- a/menu/drivers_display/menu_display_gl1.c +++ b/menu/drivers_display/menu_display_gl1.c @@ -26,6 +26,10 @@ #include "../menu_driver.h" +#ifdef VITA +static float *vertices3 = NULL; +#endif + static const GLfloat gl1_menu_vertexes[] = { 0, 0, 1, 0, @@ -133,8 +137,21 @@ static void menu_display_gl1_draw(menu_display_ctx_draw_t *draw, glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glColorPointer(4, GL_FLOAT, 0, draw->coords->color); +#ifdef VITA + if (vertices3) + free(vertices3); + vertices3 = (float*)malloc(sizeof(float) * 3 * draw->coords->vertices); + int i; + for (i = 0; i < draw->coords->vertices; i++) { + memcpy(&vertices3[i*3], &draw->coords->vertex[i*2], sizeof(float) * 2); + vertices3[i*3+2] = 0.0f; + } + glVertexPointer(3, GL_FLOAT, 0, vertices3); +#else glVertexPointer(2, GL_FLOAT, 0, draw->coords->vertex); +#endif + + glColorPointer(4, GL_FLOAT, 0, draw->coords->color); glTexCoordPointer(2, GL_FLOAT, 0, draw->coords->tex_coord); glDrawArrays(menu_display_prim_to_gl1_enum(