mirror of
https://github.com/libretro/RetroArch
synced 2025-02-02 23:54:06 +00:00
Create video_common.c
This commit is contained in:
parent
38fd0592f5
commit
c697923eb6
@ -141,6 +141,7 @@ OBJ += frontend/frontend.o \
|
|||||||
audio/audio_driver.o \
|
audio/audio_driver.o \
|
||||||
input/input_driver.o \
|
input/input_driver.o \
|
||||||
input/input_hid_driver.o \
|
input/input_hid_driver.o \
|
||||||
|
gfx/video_common.o \
|
||||||
gfx/video_driver.o \
|
gfx/video_driver.o \
|
||||||
gfx/video_pixel_converter.o \
|
gfx/video_pixel_converter.o \
|
||||||
gfx/video_viewport.o \
|
gfx/video_viewport.o \
|
||||||
|
@ -157,87 +157,3 @@ bool gl_load_luts(const struct video_shader *shader,
|
|||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE bool realloc_checked(void **ptr, size_t size)
|
|
||||||
{
|
|
||||||
void *nptr;
|
|
||||||
|
|
||||||
if (*ptr)
|
|
||||||
nptr = realloc(*ptr, size);
|
|
||||||
else
|
|
||||||
nptr = malloc(size);
|
|
||||||
|
|
||||||
if (nptr)
|
|
||||||
*ptr = nptr;
|
|
||||||
|
|
||||||
return *ptr == nptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool gl_coord_array_add(gfx_coord_array_t *ca, const gfx_coords_t *coords, unsigned count)
|
|
||||||
{
|
|
||||||
size_t base_size, offset;
|
|
||||||
bool success = false;
|
|
||||||
|
|
||||||
count = min(count, coords->vertices);
|
|
||||||
|
|
||||||
if (ca->coords.vertices + count >= ca->allocated)
|
|
||||||
{
|
|
||||||
unsigned alloc_size = next_pow2(ca->coords.vertices + count);
|
|
||||||
size_t base_size = sizeof(GLfloat) * alloc_size;
|
|
||||||
|
|
||||||
bool vert_ok = realloc_checked((void**)&ca->coords.vertex, 2 * base_size);
|
|
||||||
bool color_ok = realloc_checked((void**)&ca->coords.color, 4 * base_size);
|
|
||||||
bool tex_ok = realloc_checked((void**)&ca->coords.tex_coord, 2 * base_size);
|
|
||||||
bool lut_ok = realloc_checked((void**)&ca->coords.lut_tex_coord, 2 * base_size);
|
|
||||||
|
|
||||||
if (vert_ok && color_ok && tex_ok && lut_ok)
|
|
||||||
{
|
|
||||||
ca->allocated = alloc_size;
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
success = true;
|
|
||||||
|
|
||||||
if (!success)
|
|
||||||
{
|
|
||||||
RARCH_WARN("Allocation failed.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
base_size = count * sizeof(GLfloat);
|
|
||||||
offset = ca->coords.vertices;
|
|
||||||
|
|
||||||
/* XXX: i wish we used interlaced arrays so we could call memcpy only once */
|
|
||||||
memcpy(ca->coords.vertex + offset * 2, coords->vertex, base_size * 2);
|
|
||||||
memcpy(ca->coords.color + offset * 4, coords->color, base_size * 4);
|
|
||||||
memcpy(ca->coords.tex_coord + offset * 2, coords->tex_coord, base_size * 2);
|
|
||||||
memcpy(ca->coords.lut_tex_coord + offset * 2, coords->lut_tex_coord, base_size * 2);
|
|
||||||
|
|
||||||
ca->coords.vertices += count;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void gl_coord_array_free(gfx_coord_array_t *ca)
|
|
||||||
{
|
|
||||||
if (!ca->allocated)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (ca->coords.vertex)
|
|
||||||
free(ca->coords.vertex);
|
|
||||||
if (ca->coords.color)
|
|
||||||
free(ca->coords.color);
|
|
||||||
if (ca->coords.tex_coord)
|
|
||||||
free(ca->coords.tex_coord);
|
|
||||||
if (ca->coords.lut_tex_coord)
|
|
||||||
free(ca->coords.lut_tex_coord);
|
|
||||||
|
|
||||||
ca->coords.vertex = NULL;
|
|
||||||
ca->coords.color = NULL;
|
|
||||||
ca->coords.tex_coord = NULL;
|
|
||||||
ca->coords.lut_tex_coord = NULL;
|
|
||||||
|
|
||||||
ca->coords.vertices = 0;
|
|
||||||
ca->allocated = 0;
|
|
||||||
}
|
|
||||||
|
@ -360,9 +360,6 @@ static INLINE unsigned gl_wrap_type_to_enum(enum gfx_wrap_type type)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gl_coord_array_add(gfx_coord_array_t *ca, const gfx_coords_t *coords, unsigned count);
|
|
||||||
void gl_coord_array_free(gfx_coord_array_t *ca);
|
|
||||||
|
|
||||||
void gl_ff_vertex(const void *data);
|
void gl_ff_vertex(const void *data);
|
||||||
void gl_ff_matrix(const void *data);
|
void gl_ff_matrix(const void *data);
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ static void gl_raster_font_render_line(
|
|||||||
coords.lut_tex_coord = font_lut_tex_coord;
|
coords.lut_tex_coord = font_lut_tex_coord;
|
||||||
|
|
||||||
if (font->block)
|
if (font->block)
|
||||||
gl_coord_array_add(&font->block->carr, &coords, coords.vertices);
|
gfx_coord_array_add(&font->block->carr, &coords, coords.vertices);
|
||||||
else
|
else
|
||||||
gl_raster_font_draw_vertices(gl, &coords);
|
gl_raster_font_draw_vertices(gl, &coords);
|
||||||
|
|
||||||
|
103
gfx/video_common.c
Normal file
103
gfx/video_common.c
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
/* RetroArch - A frontend for libretro.
|
||||||
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
||||||
|
* Copyright (C) 2011-2015 - Daniel De Matteis
|
||||||
|
*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
|
||||||
|
#include <retro_inline.h>
|
||||||
|
#include <retro_miscellaneous.h>
|
||||||
|
|
||||||
|
#include "video_common.h"
|
||||||
|
|
||||||
|
static INLINE bool realloc_checked(void **ptr, size_t size)
|
||||||
|
{
|
||||||
|
void *nptr;
|
||||||
|
|
||||||
|
if (*ptr)
|
||||||
|
nptr = realloc(*ptr, size);
|
||||||
|
else
|
||||||
|
nptr = malloc(size);
|
||||||
|
|
||||||
|
if (nptr)
|
||||||
|
*ptr = nptr;
|
||||||
|
|
||||||
|
return *ptr == nptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gfx_coord_array_add(gfx_coord_array_t *ca, const gfx_coords_t *coords, unsigned count)
|
||||||
|
{
|
||||||
|
size_t base_size, offset;
|
||||||
|
bool success = false;
|
||||||
|
|
||||||
|
count = min(count, coords->vertices);
|
||||||
|
|
||||||
|
if (ca->coords.vertices + count >= ca->allocated)
|
||||||
|
{
|
||||||
|
unsigned alloc_size = next_pow2(ca->coords.vertices + count);
|
||||||
|
size_t base_size = sizeof(float) * alloc_size;
|
||||||
|
|
||||||
|
bool vert_ok = realloc_checked((void**)&ca->coords.vertex, 2 * base_size);
|
||||||
|
bool color_ok = realloc_checked((void**)&ca->coords.color, 4 * base_size);
|
||||||
|
bool tex_ok = realloc_checked((void**)&ca->coords.tex_coord, 2 * base_size);
|
||||||
|
bool lut_ok = realloc_checked((void**)&ca->coords.lut_tex_coord, 2 * base_size);
|
||||||
|
|
||||||
|
if (vert_ok && color_ok && tex_ok && lut_ok)
|
||||||
|
{
|
||||||
|
ca->allocated = alloc_size;
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
success = true;
|
||||||
|
|
||||||
|
if (!success) /* Allocation failed. */
|
||||||
|
return false;
|
||||||
|
|
||||||
|
base_size = count * sizeof(float);
|
||||||
|
offset = ca->coords.vertices;
|
||||||
|
|
||||||
|
/* XXX: i wish we used interlaced arrays so we could call memcpy only once */
|
||||||
|
memcpy(ca->coords.vertex + offset * 2, coords->vertex, base_size * 2);
|
||||||
|
memcpy(ca->coords.color + offset * 4, coords->color, base_size * 4);
|
||||||
|
memcpy(ca->coords.tex_coord + offset * 2, coords->tex_coord, base_size * 2);
|
||||||
|
memcpy(ca->coords.lut_tex_coord + offset * 2, coords->lut_tex_coord, base_size * 2);
|
||||||
|
|
||||||
|
ca->coords.vertices += count;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gfx_coord_array_free(gfx_coord_array_t *ca)
|
||||||
|
{
|
||||||
|
if (!ca->allocated)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (ca->coords.vertex)
|
||||||
|
free(ca->coords.vertex);
|
||||||
|
if (ca->coords.color)
|
||||||
|
free(ca->coords.color);
|
||||||
|
if (ca->coords.tex_coord)
|
||||||
|
free(ca->coords.tex_coord);
|
||||||
|
if (ca->coords.lut_tex_coord)
|
||||||
|
free(ca->coords.lut_tex_coord);
|
||||||
|
|
||||||
|
ca->coords.vertex = NULL;
|
||||||
|
ca->coords.color = NULL;
|
||||||
|
ca->coords.tex_coord = NULL;
|
||||||
|
ca->coords.lut_tex_coord = NULL;
|
||||||
|
|
||||||
|
ca->coords.vertices = 0;
|
||||||
|
ca->allocated = 0;
|
||||||
|
}
|
@ -20,6 +20,8 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <boolean.h>
|
||||||
|
|
||||||
struct gfx_fbo_rect
|
struct gfx_fbo_rect
|
||||||
{
|
{
|
||||||
unsigned img_width;
|
unsigned img_width;
|
||||||
@ -78,4 +80,9 @@ typedef struct gfx_raster_block
|
|||||||
gfx_coord_array_t carr;
|
gfx_coord_array_t carr;
|
||||||
} gfx_font_raster_block_t;
|
} gfx_font_raster_block_t;
|
||||||
|
|
||||||
|
bool gfx_coord_array_add(gfx_coord_array_t *ca,
|
||||||
|
const gfx_coords_t *coords, unsigned count);
|
||||||
|
|
||||||
|
void gfx_coord_array_free(gfx_coord_array_t *ca);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -505,6 +505,7 @@ AUDIO
|
|||||||
DRIVERS
|
DRIVERS
|
||||||
============================================================ */
|
============================================================ */
|
||||||
#include "../gfx/video_driver.c"
|
#include "../gfx/video_driver.c"
|
||||||
|
#include "../gfx/video_common.c"
|
||||||
#include "../gfx/video_pixel_converter.c"
|
#include "../gfx/video_pixel_converter.c"
|
||||||
#include "../gfx/video_viewport.c"
|
#include "../gfx/video_viewport.c"
|
||||||
#include "../input/input_driver.c"
|
#include "../input/input_driver.c"
|
||||||
|
@ -577,7 +577,7 @@ static void glui_free(void *data)
|
|||||||
if (!glui || !menu)
|
if (!glui || !menu)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
gl_coord_array_free(&glui->list_block.carr);
|
gfx_coord_array_free(&glui->list_block.carr);
|
||||||
|
|
||||||
gl = (gl_t*)video_driver_get_ptr(NULL);
|
gl = (gl_t*)video_driver_get_ptr(NULL);
|
||||||
|
|
||||||
|
@ -1937,7 +1937,7 @@ static void xmb_free(void *data)
|
|||||||
file_list_free(xmb->horizontal_list);
|
file_list_free(xmb->horizontal_list);
|
||||||
xmb->horizontal_list = NULL;
|
xmb->horizontal_list = NULL;
|
||||||
|
|
||||||
gl_coord_array_free(&xmb->raster_block.carr);
|
gfx_coord_array_free(&xmb->raster_block.carr);
|
||||||
|
|
||||||
if (menu->userdata)
|
if (menu->userdata)
|
||||||
free(menu->userdata);
|
free(menu->userdata);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user