Merge pull request #8231 from bparker06/gl1_squash_merge

OpenGL 1.1 video driver (gl1)
This commit is contained in:
Twinaphex 2019-02-08 22:48:18 +01:00 committed by GitHub
commit 6b8f18676c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 2223 additions and 3 deletions

View File

@ -1060,8 +1060,17 @@ ifeq ($(HAVE_GL_CONTEXT), 1)
gfx/drivers_font/gl_raster_font.o \
$(LIBRETRO_COMM_DIR)/glsym/rglgen.o
ifeq ($(HAVE_OPENGL1), 1)
OBJ += gfx/drivers/gl1.o \
gfx/drivers_font/gl1_raster_font.o
endif
ifeq ($(HAVE_MENU_COMMON), 1)
OBJ += menu/drivers_display/menu_display_gl.o
ifeq ($(HAVE_OPENGL1), 1)
OBJ += menu/drivers_display/menu_display_gl1.o
endif
endif
ifeq ($(HAVE_VIDEOCORE), 1)

View File

@ -2485,6 +2485,7 @@ static bool check_menu_driver_compatibility(void)
string_is_equal(video_driver, "d3d12") ||
string_is_equal(video_driver, "gdi") ||
string_is_equal(video_driver, "gl") ||
/*string_is_equal(video_driver, "gl1") ||*/
string_is_equal(video_driver, "gx2") ||
string_is_equal(video_driver, "vulkan") ||
string_is_equal(video_driver, "metal") ||

97
gfx/common/gl1_common.h Normal file
View File

@ -0,0 +1,97 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* copyright (c) 2011-2017 - Daniel De Matteis
* copyright (c) 2016-2019 - Brad Parker
*
* 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/>.
*/
#ifndef __GL1_COMMON_H
#define __GL1_COMMON_H
#include <retro_environment.h>
#include <retro_inline.h>
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
#else
#if defined(_WIN32) && !defined(_XBOX)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include <GL/gl.h>
#include <GL/glext.h>
#endif
#include "../video_driver.h"
struct string_list;
typedef struct gl1
{
unsigned video_width;
unsigned video_height;
unsigned screen_width;
unsigned screen_height;
int version_major;
int version_minor;
void *ctx_data;
const gfx_ctx_driver_t *ctx_driver;
GLuint tex;
GLuint menu_tex;
struct string_list *extensions;
bool supports_bgra;
struct video_viewport vp;
bool keep_aspect;
unsigned vp_out_width;
unsigned vp_out_height;
bool should_resize;
struct video_coords coords;
GLuint texture[GFX_MAX_TEXTURES];
unsigned tex_index; /* For use with PREV. */
unsigned textures;
math_matrix_4x4 mvp, mvp_no_rot;
struct video_tex_info tex_info;
const float *vertex_ptr;
const float *white_color_ptr;
unsigned rotation;
bool menu_texture_enable;
bool menu_texture_full_screen;
bool have_sync;
bool smooth;
bool menu_smooth;
void *readback_buffer_screenshot;
} gl1_t;
typedef struct gl1_texture
{
int width;
int height;
int active_width;
int active_height;
enum texture_filter_type type;
void* data;
} gl1_texture_t;
static INLINE void gl1_bind_texture(GLuint id, GLint wrap_mode, GLint mag_filter,
GLint min_filter)
{
glBindTexture(GL_TEXTURE_2D, id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_mode);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_mode);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
}
#endif

1248
gfx/drivers/gl1.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,581 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2016-2017 - Brad Parker
*
* 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 <encodings/utf.h>
#include <string/stdstring.h>
#include <retro_math.h>
#include "../common/gl1_common.h"
#include "../font_driver.h"
#include "../video_driver.h"
#include "../../verbosity.h"
/* TODO: Move viewport side effects to the caller: it's a source of bugs. */
#define gl1_raster_font_emit(c, vx, vy) do { \
font_vertex[ 2 * (6 * i + c) + 0] = (x + (delta_x + off_x + vx * width) * scale) * inv_win_width; \
font_vertex[ 2 * (6 * i + c) + 1] = (y + (delta_y - off_y - vy * height) * scale) * inv_win_height; \
font_tex_coords[ 2 * (6 * i + c) + 0] = (tex_x + vx * width) * inv_tex_size_x; \
font_tex_coords[ 2 * (6 * i + c) + 1] = (tex_y + vy * height) * inv_tex_size_y; \
font_color[ 4 * (6 * i + c) + 0] = color[0]; \
font_color[ 4 * (6 * i + c) + 1] = color[1]; \
font_color[ 4 * (6 * i + c) + 2] = color[2]; \
font_color[ 4 * (6 * i + c) + 3] = color[3]; \
font_lut_tex_coord[ 2 * (6 * i + c) + 0] = gl->coords.lut_tex_coord[0]; \
font_lut_tex_coord[ 2 * (6 * i + c) + 1] = gl->coords.lut_tex_coord[1]; \
} while(0)
#define MAX_MSG_LEN_CHUNK 64
typedef struct
{
gl1_t *gl;
GLuint tex;
unsigned tex_width, tex_height;
const font_renderer_driver_t *font_driver;
void *font_data;
struct font_atlas *atlas;
video_font_raster_block_t *block;
} gl1_raster_t;
static void gl1_raster_font_free_font(void *data,
bool is_threaded)
{
gl1_raster_t *font = (gl1_raster_t*)data;
if (!font)
return;
if (font->font_driver && font->font_data)
font->font_driver->free(font->font_data);
if (is_threaded)
video_context_driver_make_current(true);
glDeleteTextures(1, &font->tex);
free(font);
}
#if 0
static bool gl1_raster_font_upload_atlas_components_4(gl1_raster_t *font)
{
unsigned i, j;
GLint gl_internal = GL_RGBA;
GLenum gl_format = GL_RGBA;
size_t ncomponents = 4;
uint8_t *tmp = NULL;
tmp = (uint8_t*)calloc(font->tex_height, font->tex_width * ncomponents);
for (i = 0; i < font->atlas->height; ++i)
{
const uint8_t *src = &font->atlas->buffer[i * font->atlas->width];
uint8_t *dst = &tmp[i * font->tex_width * ncomponents];
for (j = 0; j < font->atlas->width; ++j)
{
*dst++ = 0xff;
*dst++ = 0xff;
*dst++ = 0xff;
*dst++ = *src++;
}
break;
}
glTexImage2D(GL_TEXTURE_2D, 0, gl_internal, font->tex_width, font->tex_height,
0, gl_format, GL_UNSIGNED_BYTE, tmp);
free(tmp);
return true;
}
#endif
static bool gl1_raster_font_upload_atlas(gl1_raster_t *font)
{
unsigned i, j;
GLint gl_internal = GL_LUMINANCE_ALPHA;
GLenum gl_format = GL_LUMINANCE_ALPHA;
size_t ncomponents = 2;
uint8_t *tmp = NULL;
tmp = (uint8_t*)calloc(font->tex_height, font->tex_width * ncomponents);
switch (ncomponents)
{
case 1:
for (i = 0; i < font->atlas->height; ++i)
{
const uint8_t *src = &font->atlas->buffer[i * font->atlas->width];
uint8_t *dst = &tmp[i * font->tex_width * ncomponents];
memcpy(dst, src, font->atlas->width);
}
break;
case 2:
for (i = 0; i < font->atlas->height; ++i)
{
const uint8_t *src = &font->atlas->buffer[i * font->atlas->width];
uint8_t *dst = &tmp[i * font->tex_width * ncomponents];
for (j = 0; j < font->atlas->width; ++j)
{
*dst++ = 0xff;
*dst++ = *src++;
}
}
break;
}
glTexImage2D(GL_TEXTURE_2D, 0, gl_internal, font->tex_width, font->tex_height,
0, gl_format, GL_UNSIGNED_BYTE, tmp);
free(tmp);
return true;
}
static void *gl1_raster_font_init_font(void *data,
const char *font_path, float font_size,
bool is_threaded)
{
gl1_raster_t *font = (gl1_raster_t*)calloc(1, sizeof(*font));
if (!font)
return NULL;
font->gl = (gl1_t*)data;
if (!font_renderer_create_default(
&font->font_driver,
&font->font_data, font_path, font_size))
{
RARCH_WARN("Couldn't initialize font renderer.\n");
free(font);
return NULL;
}
RARCH_LOG("[Font]: Using font driver GL1\n");
if (is_threaded)
video_context_driver_make_current(false);
glGenTextures(1, &font->tex);
gl1_bind_texture(font->tex, GL_CLAMP, GL_LINEAR, GL_LINEAR);
font->atlas = font->font_driver->get_atlas(font->font_data);
font->tex_width = next_pow2(font->atlas->width);
font->tex_height = next_pow2(font->atlas->height);
if (!gl1_raster_font_upload_atlas(font))
goto error;
font->atlas->dirty = false;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, font->gl->texture[font->gl->tex_index]);
return font;
error:
gl1_raster_font_free_font(font, is_threaded);
font = NULL;
return NULL;
}
static int gl1_get_message_width(void *data, const char *msg,
unsigned msg_len, float scale)
{
gl1_raster_t *font = (gl1_raster_t*)data;
const char* msg_end = msg + msg_len;
int delta_x = 0;
if ( !font
|| !font->font_driver
|| !font->font_driver->get_glyph
|| !font->font_data )
return 0;
while (msg < msg_end)
{
unsigned code = utf8_walk(&msg);
const struct font_glyph *glyph = font->font_driver->get_glyph(
font->font_data, code);
if (!glyph) /* Do something smarter here ... */
glyph = font->font_driver->get_glyph(font->font_data, '?');
if (!glyph)
continue;
delta_x += glyph->advance_x;
}
return delta_x * scale;
}
static void gl1_raster_font_draw_vertices(gl1_raster_t *font,
const video_coords_t *coords,
video_frame_info_t *video_info)
{
video_shader_ctx_coords_t coords_data;
if (font->atlas->dirty)
{
gl1_raster_font_upload_atlas(font);
font->atlas->dirty = false;
}
coords_data.handle_data = NULL;
coords_data.data = coords;
video_driver_set_coords(&coords_data);
/*video_info->cb_set_mvp(font->gl,
video_info->shader_data, &font->gl->mvp_no_rot);*/
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadMatrixf(font->gl->mvp.data);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glColorPointer(4, GL_FLOAT, 0, coords->color);
glVertexPointer(2, GL_FLOAT, 0, coords->vertex);
glTexCoordPointer(2, GL_FLOAT, 0, coords->tex_coord);
glDrawArrays(GL_TRIANGLES, 0, coords->vertices);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
}
static void gl1_raster_font_render_line(
gl1_raster_t *font, const char *msg, unsigned msg_len,
GLfloat scale, const GLfloat color[4], GLfloat pos_x,
GLfloat pos_y, unsigned text_align,
video_frame_info_t *video_info)
{
unsigned i;
struct video_coords coords;
GLfloat font_tex_coords[2 * 6 * MAX_MSG_LEN_CHUNK];
GLfloat font_vertex[2 * 6 * MAX_MSG_LEN_CHUNK];
GLfloat font_color[4 * 6 * MAX_MSG_LEN_CHUNK];
GLfloat font_lut_tex_coord[2 * 6 * MAX_MSG_LEN_CHUNK];
gl1_t *gl = font->gl;
const char* msg_end = msg + msg_len;
int x = roundf(pos_x * gl->vp.width);
int y = roundf(pos_y * gl->vp.height);
int delta_x = 0;
int delta_y = 0;
float inv_tex_size_x = 1.0f / font->tex_width;
float inv_tex_size_y = 1.0f / font->tex_height;
float inv_win_width = 1.0f / font->gl->vp.width;
float inv_win_height = 1.0f / font->gl->vp.height;
switch (text_align)
{
case TEXT_ALIGN_RIGHT:
x -= gl1_get_message_width(font, msg, msg_len, scale);
break;
case TEXT_ALIGN_CENTER:
x -= gl1_get_message_width(font, msg, msg_len, scale) / 2.0;
break;
}
while (msg < msg_end)
{
i = 0;
while ((i < MAX_MSG_LEN_CHUNK) && (msg < msg_end))
{
int off_x, off_y, tex_x, tex_y, width, height;
unsigned code = utf8_walk(&msg);
const struct font_glyph *glyph = font->font_driver->get_glyph(
font->font_data, code);
if (!glyph) /* Do something smarter here ... */
glyph = font->font_driver->get_glyph(font->font_data, '?');
if (!glyph)
continue;
off_x = glyph->draw_offset_x;
off_y = glyph->draw_offset_y;
tex_x = glyph->atlas_offset_x;
tex_y = glyph->atlas_offset_y;
width = glyph->width;
height = glyph->height;
gl1_raster_font_emit(0, 0, 1); /* Bottom-left */
gl1_raster_font_emit(1, 1, 1); /* Bottom-right */
gl1_raster_font_emit(2, 0, 0); /* Top-left */
gl1_raster_font_emit(3, 1, 0); /* Top-right */
gl1_raster_font_emit(4, 0, 0); /* Top-left */
gl1_raster_font_emit(5, 1, 1); /* Bottom-right */
i++;
delta_x += glyph->advance_x;
delta_y -= glyph->advance_y;
}
coords.tex_coord = font_tex_coords;
coords.vertex = font_vertex;
coords.color = font_color;
coords.vertices = i * 6;
coords.lut_tex_coord = font_lut_tex_coord;
if (font->block)
video_coord_array_append(&font->block->carr, &coords, coords.vertices);
else
gl1_raster_font_draw_vertices(font, &coords, video_info);
}
}
static void gl1_raster_font_render_message(
gl1_raster_t *font, const char *msg, GLfloat scale,
const GLfloat color[4], GLfloat pos_x, GLfloat pos_y,
unsigned text_align,
video_frame_info_t *video_info)
{
float line_height;
int lines = 0;
/* If the font height is not supported just draw as usual */
if (!font->font_driver->get_line_height)
{
gl1_raster_font_render_line(font,
msg, (unsigned)strlen(msg), scale, color, pos_x,
pos_y, text_align,
video_info);
return;
}
line_height = (float) font->font_driver->get_line_height(font->font_data) *
scale / font->gl->vp.height;
for (;;)
{
const char *delim = strchr(msg, '\n');
unsigned msg_len = delim
? (unsigned)(delim - msg) : (unsigned)strlen(msg);
/* Draw the line */
gl1_raster_font_render_line(font,
msg, msg_len, scale, color, pos_x,
pos_y - (float)lines*line_height, text_align,
video_info);
if (!delim)
break;
msg += msg_len + 1;
lines++;
}
}
static void gl1_raster_font_setup_viewport(unsigned width, unsigned height,
gl1_raster_t *font, bool full_screen)
{
video_shader_ctx_info_t shader_info;
video_driver_set_viewport(width, height, full_screen, false);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
/*glBlendEquation(GL_FUNC_ADD);*/
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, font->tex);
/*shader_info.data = NULL;
shader_info.idx = VIDEO_SHADER_STOCK_BLEND;
shader_info.set_active = true;
video_shader_driver_use(&shader_info);*/
}
static void gl1_raster_font_render_msg(
video_frame_info_t *video_info,
void *data, const char *msg,
const struct font_params *params)
{
GLfloat color[4];
int drop_x, drop_y;
GLfloat x, y, scale, drop_mod, drop_alpha;
enum text_alignment text_align = TEXT_ALIGN_LEFT;
bool full_screen = false ;
gl1_raster_t *font = (gl1_raster_t*)data;
unsigned width = video_info->width;
unsigned height = video_info->height;
if (!font || string_is_empty(msg))
return;
if (params)
{
x = params->x;
y = params->y;
scale = params->scale;
full_screen = params->full_screen;
text_align = params->text_align;
drop_x = params->drop_x;
drop_y = params->drop_y;
drop_mod = params->drop_mod;
drop_alpha = params->drop_alpha;
color[0] = FONT_COLOR_GET_RED(params->color) / 255.0f;
color[1] = FONT_COLOR_GET_GREEN(params->color) / 255.0f;
color[2] = FONT_COLOR_GET_BLUE(params->color) / 255.0f;
color[3] = FONT_COLOR_GET_ALPHA(params->color) / 255.0f;
/* If alpha is 0.0f, turn it into default 1.0f */
if (color[3] <= 0.0f)
color[3] = 1.0f;
}
else
{
x = video_info->font_msg_pos_x;
y = video_info->font_msg_pos_y;
scale = 1.0f;
full_screen = true;
text_align = TEXT_ALIGN_LEFT;
color[0] = video_info->font_msg_color_r;
color[1] = video_info->font_msg_color_g;
color[2] = video_info->font_msg_color_b;
color[3] = 1.0f;
drop_x = -2;
drop_y = -2;
drop_mod = 0.3f;
drop_alpha = 1.0f;
}
if (font->block)
font->block->fullscreen = full_screen;
else
gl1_raster_font_setup_viewport(width, height, font, full_screen);
if (!string_is_empty(msg) && font->gl
&& font->font_data && font->font_driver)
{
if (drop_x || drop_y)
{
GLfloat color_dark[4];
color_dark[0] = color[0] * drop_mod;
color_dark[1] = color[1] * drop_mod;
color_dark[2] = color[2] * drop_mod;
color_dark[3] = color[3] * drop_alpha;
if (font->gl)
gl1_raster_font_render_message(font, msg, scale, color_dark,
x + scale * drop_x / font->gl->vp.width, y +
scale * drop_y / font->gl->vp.height, text_align,
video_info);
}
if (font->gl)
gl1_raster_font_render_message(font, msg, scale, color,
x, y, text_align, video_info);
}
if (!font->block && font->gl)
{
/* restore viewport */
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, font->gl->texture[font->gl->tex_index]);
glDisable(GL_BLEND);
video_driver_set_viewport(width, height, false, true);
}
}
static const struct font_glyph *gl1_raster_font_get_glyph(
void *data, uint32_t code)
{
gl1_raster_t *font = (gl1_raster_t*)data;
if (!font || !font->font_driver)
return NULL;
if (!font->font_driver->ident)
return NULL;
return font->font_driver->get_glyph((void*)font->font_driver, code);
}
static void gl1_raster_font_flush_block(unsigned width, unsigned height,
void *data, video_frame_info_t *video_info)
{
gl1_raster_t *font = (gl1_raster_t*)data;
video_font_raster_block_t *block = font ? font->block : NULL;
if (!font || !block || !block->carr.coords.vertices)
return;
gl1_raster_font_setup_viewport(width, height, font, block->fullscreen);
gl1_raster_font_draw_vertices(font, (video_coords_t*)&block->carr.coords,
video_info);
if (font->gl)
{
/* restore viewport */
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, font->gl->texture[font->gl->tex_index]);
glDisable(GL_BLEND);
video_driver_set_viewport(width, height, block->fullscreen, true);
}
}
static void gl1_raster_font_bind_block(void *data, void *userdata)
{
gl1_raster_t *font = (gl1_raster_t*)data;
video_font_raster_block_t *block = (video_font_raster_block_t*)userdata;
if (font)
font->block = block;
}
font_renderer_t gl1_raster_font = {
gl1_raster_font_init_font,
gl1_raster_font_free_font,
gl1_raster_font_render_msg,
"GL1 raster",
gl1_raster_font_get_glyph,
gl1_raster_font_bind_block,
gl1_raster_font_flush_block,
gl1_get_message_width
};

View File

@ -183,6 +183,37 @@ static bool gl_font_init_first(
return false;
}
#ifdef HAVE_OPENGL1
static const font_renderer_t *gl1_font_backends[] = {
&gl1_raster_font,
NULL,
};
static bool gl1_font_init_first(
const void **font_driver, void **font_handle,
void *video_data, const char *font_path,
float font_size, bool is_threaded)
{
unsigned i;
for (i = 0; gl1_font_backends[i]; i++)
{
void *data = gl1_font_backends[i]->init(
video_data, font_path, font_size,
is_threaded);
if (!data)
continue;
*font_driver = gl1_font_backends[i];
*font_handle = data;
return true;
}
return false;
}
#endif
#endif
#ifdef HAVE_CACA
@ -630,6 +661,11 @@ static bool font_init_first(
case FONT_DRIVER_RENDER_OPENGL_API:
return gl_font_init_first(font_driver, font_handle,
video_data, font_path, font_size, is_threaded);
#ifdef HAVE_OPENGL1
case FONT_DRIVER_RENDER_OPENGL1_API:
return gl1_font_init_first(font_driver, font_handle,
video_data, font_path, font_size, is_threaded);
#endif
#endif
#ifdef HAVE_VULKAN
case FONT_DRIVER_RENDER_VULKAN_API:

View File

@ -157,6 +157,7 @@ void font_driver_init_osd(
void font_driver_free_osd(void);
extern font_renderer_t gl_raster_font;
extern font_renderer_t gl1_raster_font;
extern font_renderer_t libdbg_font;
extern font_renderer_t d3d_xbox360_font;
extern font_renderer_t d3d_xdk1_font;

View File

@ -83,6 +83,7 @@ enum font_driver_render_api
{
FONT_DRIVER_RENDER_DONT_CARE,
FONT_DRIVER_RENDER_OPENGL_API,
FONT_DRIVER_RENDER_OPENGL1_API,
FONT_DRIVER_RENDER_D3D8_API,
FONT_DRIVER_RENDER_D3D9_API,
FONT_DRIVER_RENDER_D3D10_API,

View File

@ -260,6 +260,9 @@ struct aspect_ratio_elem aspectratio_lut[ASPECT_RATIO_END] = {
static const video_driver_t *video_drivers[] = {
#ifdef HAVE_OPENGL
&video_gl2,
#ifdef HAVE_OPENGL1
&video_gl1,
#endif
#endif
#ifdef HAVE_VULKAN
&video_vulkan,
@ -425,7 +428,6 @@ static const gfx_ctx_driver_t *gfx_ctx_drivers[] = {
NULL
};
bool video_driver_started_fullscreen(void)
{
return video_started_fullscreen;

View File

@ -1209,6 +1209,7 @@ bool video_driver_get_all_flags(gfx_ctx_flags_t *flags,
enum display_flags flag);
extern video_driver_t video_gl2;
extern video_driver_t video_gl1;
extern video_driver_t video_vulkan;
extern video_driver_t video_metal;
extern video_driver_t video_psp1;

View File

@ -411,6 +411,9 @@ VIDEO DRIVER
#ifdef HAVE_OPENGL
#include "../gfx/drivers/gl.c"
#ifdef HAVE_OPENGL1
#include "../gfx/drivers/gl1.c"
#endif
#include "../libretro-common/gfx/gl_capabilities.c"
#ifndef HAVE_PSGL
@ -488,6 +491,9 @@ FONTS
#if defined(HAVE_OPENGL)
#include "../gfx/drivers_font/gl_raster_font.c"
#ifdef HAVE_OPENGL1
#include "../gfx/drivers_font/gl1_raster_font.c"
#endif
#endif
#if defined(_XBOX1)
@ -1248,6 +1254,9 @@ MENU
#ifdef HAVE_OPENGL
#include "../menu/drivers_display/menu_display_gl.c"
#ifdef HAVE_OPENGL1
#include "../menu/drivers_display/menu_display_gl1.c"
#endif
#endif
#ifdef HAVE_VULKAN

View File

@ -0,0 +1,223 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2017 - 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 <retro_miscellaneous.h>
#ifdef HAVE_CONFIG_H
#include "../../config.h"
#endif
#include "../../retroarch.h"
#include "../../gfx/font_driver.h"
#include "../../gfx/video_driver.h"
#include "../../gfx/common/gl1_common.h"
#include "../menu_driver.h"
static const GLfloat gl1_menu_vertexes[] = {
0, 0,
1, 0,
0, 1,
1, 1
};
static const GLfloat gl1_menu_tex_coords[] = {
0, 1,
1, 1,
0, 0,
1, 0
};
static const float *menu_display_gl1_get_default_vertices(void)
{
return &gl1_menu_vertexes[0];
}
static const float *menu_display_gl1_get_default_tex_coords(void)
{
return &gl1_menu_tex_coords[0];
}
static void *menu_display_gl1_get_default_mvp(video_frame_info_t *video_info)
{
gl1_t *gl1 = video_info ? (gl1_t*)video_info->userdata : NULL;
if (!gl1)
return NULL;
return &gl1->mvp_no_rot;
}
static GLenum menu_display_prim_to_gl1_enum(
enum menu_display_prim_type type)
{
switch (type)
{
case MENU_DISPLAY_PRIM_TRIANGLESTRIP:
return GL_TRIANGLE_STRIP;
case MENU_DISPLAY_PRIM_TRIANGLES:
return GL_TRIANGLES;
case MENU_DISPLAY_PRIM_NONE:
default:
break;
}
return 0;
}
static void menu_display_gl1_blend_begin(video_frame_info_t *video_info)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
static void menu_display_gl1_blend_end(video_frame_info_t *video_info)
{
glDisable(GL_BLEND);
}
static void menu_display_gl1_viewport(menu_display_ctx_draw_t *draw,
video_frame_info_t *video_info)
{
if (draw)
glViewport(draw->x, draw->y, draw->width, draw->height);
}
static void menu_display_gl1_draw(menu_display_ctx_draw_t *draw,
video_frame_info_t *video_info)
{
video_shader_ctx_mvp_t mvp;
video_shader_ctx_coords_t coords;
gl1_t *gl1 = video_info ?
(gl1_t*)video_info->userdata : NULL;
if (!gl1 || !draw)
return;
if (!draw->coords->vertex)
draw->coords->vertex = menu_display_gl1_get_default_vertices();
if (!draw->coords->tex_coord)
draw->coords->tex_coord = menu_display_gl1_get_default_tex_coords();
if (!draw->coords->lut_tex_coord)
draw->coords->lut_tex_coord = menu_display_gl1_get_default_tex_coords();
menu_display_gl1_viewport(draw, video_info);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, (GLuint)draw->texture);
coords.handle_data = gl1;
coords.data = draw->coords;
video_driver_set_coords(&coords);
mvp.data = gl1;
mvp.matrix = draw->matrix_data ? (math_matrix_4x4*)draw->matrix_data
: (math_matrix_4x4*)menu_display_gl1_get_default_mvp(video_info);
video_driver_set_mvp(&mvp);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadMatrixf(((math_matrix_4x4*)mvp.matrix)->data);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glColorPointer(4, GL_FLOAT, 0, draw->coords->color);
glVertexPointer(2, GL_FLOAT, 0, draw->coords->vertex);
glTexCoordPointer(2, GL_FLOAT, 0, draw->coords->tex_coord);
glDrawArrays(menu_display_prim_to_gl1_enum(
draw->prim_type), 0, draw->coords->vertices);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
gl1->coords.color = gl1->white_color_ptr;
}
static void menu_display_gl1_restore_clear_color(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
static void menu_display_gl1_clear_color(
menu_display_ctx_clearcolor_t *clearcolor,
video_frame_info_t *video_info)
{
if (!clearcolor)
return;
glClearColor(clearcolor->r,
clearcolor->g, clearcolor->b, clearcolor->a);
glClear(GL_COLOR_BUFFER_BIT);
}
static bool menu_display_gl1_font_init_first(
void **font_handle, void *video_data,
const char *font_path, float menu_font_size,
bool is_threaded)
{
font_data_t **handle = (font_data_t**)font_handle;
if (!(*handle = font_driver_init_first(video_data,
font_path, menu_font_size, true,
is_threaded,
FONT_DRIVER_RENDER_OPENGL1_API)))
return false;
return true;
}
static void menu_display_gl1_scissor_begin(video_frame_info_t *video_info, int x, int y,
unsigned width, unsigned height)
{
glScissor(x, video_info->height - y - height, width, height);
glEnable(GL_SCISSOR_TEST);
}
static void menu_display_gl1_scissor_end(video_frame_info_t *video_info)
{
glDisable(GL_SCISSOR_TEST);
}
menu_display_ctx_driver_t menu_display_ctx_gl1 = {
menu_display_gl1_draw,
NULL,
menu_display_gl1_viewport,
menu_display_gl1_blend_begin,
menu_display_gl1_blend_end,
menu_display_gl1_restore_clear_color,
menu_display_gl1_clear_color,
menu_display_gl1_get_default_mvp,
menu_display_gl1_get_default_vertices,
menu_display_gl1_get_default_tex_coords,
menu_display_gl1_font_init_first,
MENU_VIDEO_DRIVER_OPENGL1,
"gl1",
false,
menu_display_gl1_scissor_begin,
menu_display_gl1_scissor_end
};

View File

@ -200,6 +200,7 @@ enum menu_display_driver_type
{
MENU_VIDEO_DRIVER_GENERIC = 0,
MENU_VIDEO_DRIVER_OPENGL,
MENU_VIDEO_DRIVER_OPENGL1,
MENU_VIDEO_DRIVER_VULKAN,
MENU_VIDEO_DRIVER_METAL,
MENU_VIDEO_DRIVER_DIRECT3D8,

View File

@ -126,6 +126,9 @@ static menu_display_ctx_driver_t *menu_display_ctx_drivers[] = {
#endif
#ifdef HAVE_OPENGL
&menu_display_ctx_gl,
#ifdef HAVE_OPENGL1
&menu_display_ctx_gl1,
#endif
#endif
#ifdef HAVE_VULKAN
&menu_display_ctx_vulkan,
@ -274,6 +277,10 @@ static bool menu_display_check_compatibility(
if (string_is_equal(video_driver, "gl"))
return true;
break;
case MENU_VIDEO_DRIVER_OPENGL1:
if (string_is_equal(video_driver, "gl1"))
return true;
break;
case MENU_VIDEO_DRIVER_VULKAN:
if (string_is_equal(video_driver, "vulkan"))
return true;
@ -781,7 +788,8 @@ void menu_display_draw_bg(menu_display_ctx_draw_t *draw,
if (!draw->texture)
draw->texture = menu_display_white_texture;
draw->matrix_data = (math_matrix_4x4*)menu_disp->get_default_mvp(video_info);
if (menu_disp && menu_disp->get_default_mvp)
draw->matrix_data = (math_matrix_4x4*)menu_disp->get_default_mvp(video_info);
}
void menu_display_draw_gradient(menu_display_ctx_draw_t *draw,

View File

@ -692,6 +692,7 @@ void menu_subsystem_populate(const struct retro_subsystem_info* subsystem, menu_
extern uintptr_t menu_display_white_texture;
extern menu_display_ctx_driver_t menu_display_ctx_gl;
extern menu_display_ctx_driver_t menu_display_ctx_gl1;
extern menu_display_ctx_driver_t menu_display_ctx_vulkan;
extern menu_display_ctx_driver_t menu_display_ctx_metal;
extern menu_display_ctx_driver_t menu_display_ctx_d3d8;

View File

@ -56,7 +56,8 @@ C89_D3D11=no
HAVE_D3D12=yes # Direct3D 12 support
C89_D3D12=no
HAVE_D3DX=yes # Direct3DX support
HAVE_OPENGL=auto # OpenGL support
HAVE_OPENGL=auto # OpenGL 2.0 support
HAVE_OPENGL1=no # OpenGL 1.1 support
HAVE_MALI_FBDEV=no # Mali fbdev context support
HAVE_VIVANTE_FBDEV=no # Vivante fbdev context support
HAVE_OPENDINGUX_FBDEV=no # Opendingux fbdev context support