mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 04:20:28 +00:00
81403e2751 Fix error requiring HAVE_SHARK to be enabled to build. (#45) 58551e1f52 Added possibility to change runtime shader compiler optimization flags. 77ab50a7b1 Added GL_BGR and GL_BGRA texture formats support. 0ac2793bcf Fix error in texture wrapping options. (#42) 0d2110ac7b Improvements to GL buffer support. (#41) cf86149a85 Added proper compressed texture support. (#40) 8b0a0f735a Unbinded textures and texture units concepts. 1b04851efc Added glUniform2i and glUniform2f implementations. 9a65397ef6 Properly checking for uniform locations existence. 91c557f35d Added support for GL_SHORT attribute types for shaders. 3237fd3fe3 Added vglTexImageDepthBuffer function. f58b3818f2 Typo fix on mag filter setting. ee11f7e1d0 Added vglHasRuntimeShaderCompiler function. 3596242f73 Add PowerVR texture compression (PVRTC) support (#39) 2ae694df4b Added support for mipmaps filtering. af7804b44c Added vglGetGxmTexture implementation. 54b1df4ca2 Removed unused arguments. 7c2ed742ee Allow to call vglBind*Location funcs with wrong param names. 8be84ff698 Fixed RGB565 color conversion. 234ff57f65 Properly setting a single stream with packed attributes. d3b28a5e32 Fix for correct vglBindAttribLocation behaviour. 46e72d3564 Use a single stream for packed attributes. 72a39315e9 Properly dealing with missing attrs in glGetUniformLocation. a6269ce574 Added TEXUNIT1 support for custom shaders. 824d43073e Resetting custom shaders uniforms only when invalidated. d242570161 Minor fix in glShaderSource. bc28bd946d Added glGetShaderInfoLog implementation. git-subtree-dir: deps/vitaGL git-subtree-split: 81403e2751c4dc28cf17cc89a5ab053eb2c5af67
206 lines
5.6 KiB
C
206 lines
5.6 KiB
C
/*
|
|
* This file is part of vitaGL
|
|
* Copyright 2017, 2018, 2019, 2020 Rinnegatamante
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published
|
|
* by the Free Software Foundation, version 3 of the License, or (at your
|
|
* option) any later version.
|
|
*
|
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/*
|
|
* framebuffers.c:
|
|
* Implementation for framebuffers related functions
|
|
*/
|
|
|
|
#include "shared.h"
|
|
|
|
static framebuffer framebuffers[BUFFERS_NUM]; // Framebuffers array
|
|
|
|
framebuffer *active_read_fb = NULL; // Current readback framebuffer in use
|
|
framebuffer *active_write_fb = NULL; // Current write framebuffer in use
|
|
|
|
uint32_t get_color_from_texture(uint32_t type) {
|
|
uint32_t res = 0;
|
|
switch (type) {
|
|
case GL_RGB:
|
|
res = SCE_GXM_COLOR_FORMAT_U8U8U8_BGR;
|
|
break;
|
|
case GL_RGBA:
|
|
res = SCE_GXM_COLOR_FORMAT_U8U8U8U8_ABGR;
|
|
break;
|
|
case GL_LUMINANCE:
|
|
res = SCE_GXM_COLOR_FORMAT_U8_R;
|
|
break;
|
|
case GL_LUMINANCE_ALPHA:
|
|
res = SCE_GXM_COLOR_FORMAT_U8U8_GR;
|
|
break;
|
|
case GL_INTENSITY:
|
|
res = SCE_GXM_COLOR_FORMAT_U8_R;
|
|
break;
|
|
case GL_ALPHA:
|
|
res = SCE_GXM_COLOR_FORMAT_U8_A;
|
|
break;
|
|
default:
|
|
vgl_error = GL_INVALID_ENUM;
|
|
break;
|
|
}
|
|
return res;
|
|
}
|
|
|
|
/*
|
|
* ------------------------------
|
|
* - IMPLEMENTATION STARTS HERE -
|
|
* ------------------------------
|
|
*/
|
|
|
|
void glGenFramebuffers(GLsizei n, GLuint *ids) {
|
|
int i = 0, j = 0;
|
|
#ifndef SKIP_ERROR_HANDLING
|
|
if (n < 0) {
|
|
SET_GL_ERROR(GL_INVALID_VALUE)
|
|
}
|
|
#endif
|
|
for (i = 0; i < BUFFERS_NUM; i++) {
|
|
if (!framebuffers[i].active) {
|
|
ids[j++] = (GLuint)&framebuffers[i];
|
|
framebuffers[i].active = 1;
|
|
framebuffers[i].depth_buffer_addr = NULL;
|
|
framebuffers[i].stencil_buffer_addr = NULL;
|
|
}
|
|
if (j >= n)
|
|
break;
|
|
}
|
|
}
|
|
|
|
void glDeleteFramebuffers(GLsizei n, GLuint *framebuffers) {
|
|
#ifndef SKIP_ERROR_HANDLING
|
|
if (n < 0) {
|
|
SET_GL_ERROR(GL_INVALID_VALUE)
|
|
}
|
|
#endif
|
|
while (n > 0) {
|
|
framebuffer *fb = (framebuffer *)framebuffers[n--];
|
|
fb->active = 0;
|
|
if (fb->target) {
|
|
sceGxmDestroyRenderTarget(fb->target);
|
|
fb->target = NULL;
|
|
}
|
|
if (fb->depth_buffer_addr) {
|
|
mempool_free(fb->depth_buffer_addr, fb->depth_buffer_mem_type);
|
|
mempool_free(fb->stencil_buffer_addr, fb->stencil_buffer_mem_type);
|
|
fb->depth_buffer_addr = NULL;
|
|
fb->stencil_buffer_addr = NULL;
|
|
}
|
|
}
|
|
}
|
|
|
|
void glBindFramebuffer(GLenum target, GLuint fb) {
|
|
switch (target) {
|
|
case GL_DRAW_FRAMEBUFFER:
|
|
active_write_fb = (framebuffer *)fb;
|
|
break;
|
|
case GL_READ_FRAMEBUFFER:
|
|
active_read_fb = (framebuffer *)fb;
|
|
break;
|
|
case GL_FRAMEBUFFER:
|
|
active_write_fb = active_read_fb = (framebuffer *)fb;
|
|
break;
|
|
default:
|
|
SET_GL_ERROR(GL_INVALID_ENUM)
|
|
break;
|
|
}
|
|
}
|
|
|
|
void glFramebufferTexture(GLenum target, GLenum attachment, GLuint tex_id, GLint level) {
|
|
// Detecting requested framebuffer
|
|
framebuffer *fb = NULL;
|
|
switch (target) {
|
|
case GL_DRAW_FRAMEBUFFER:
|
|
case GL_FRAMEBUFFER:
|
|
fb = active_write_fb;
|
|
break;
|
|
case GL_READ_FRAMEBUFFER:
|
|
fb = active_read_fb;
|
|
break;
|
|
default:
|
|
SET_GL_ERROR(GL_INVALID_ENUM)
|
|
break;
|
|
}
|
|
|
|
// Aliasing to make code more readable
|
|
texture *tex = &textures[tex_id];
|
|
|
|
// Extracting texture sizes
|
|
fb->width = sceGxmTextureGetWidth(&tex->gxm_tex);
|
|
fb->height = sceGxmTextureGetHeight(&tex->gxm_tex);
|
|
|
|
// Detecting requested attachment
|
|
switch (attachment) {
|
|
case GL_COLOR_ATTACHMENT0:
|
|
|
|
// Allocating colorbuffer
|
|
sceGxmColorSurfaceInit(
|
|
&fb->colorbuffer,
|
|
get_color_from_texture(tex->type),
|
|
SCE_GXM_COLOR_SURFACE_LINEAR,
|
|
msaa_mode == SCE_GXM_MULTISAMPLE_NONE ? SCE_GXM_COLOR_SURFACE_SCALE_NONE : SCE_GXM_COLOR_SURFACE_SCALE_MSAA_DOWNSCALE,
|
|
SCE_GXM_OUTPUT_REGISTER_SIZE_32BIT,
|
|
fb->width,
|
|
fb->height,
|
|
fb->width,
|
|
sceGxmTextureGetData(&tex->gxm_tex));
|
|
|
|
// Allocating depth and stencil buffer (FIXME: This probably shouldn't be here)
|
|
initDepthStencilBuffer(fb->width, fb->height, &fb->depthbuffer, &fb->depth_buffer_addr, &fb->stencil_buffer_addr, &fb->depth_buffer_mem_type, &fb->stencil_buffer_mem_type);
|
|
|
|
// Creating rendertarget
|
|
SceGxmRenderTargetParams renderTargetParams;
|
|
memset(&renderTargetParams, 0, sizeof(SceGxmRenderTargetParams));
|
|
renderTargetParams.flags = 0;
|
|
renderTargetParams.width = sceGxmTextureGetWidth(&tex->gxm_tex);
|
|
renderTargetParams.height = sceGxmTextureGetHeight(&tex->gxm_tex);
|
|
renderTargetParams.scenesPerFrame = 1;
|
|
renderTargetParams.multisampleMode = msaa_mode;
|
|
renderTargetParams.multisampleLocations = 0;
|
|
renderTargetParams.driverMemBlock = -1;
|
|
sceGxmCreateRenderTarget(&renderTargetParams, &fb->target);
|
|
break;
|
|
default:
|
|
SET_GL_ERROR(GL_INVALID_ENUM)
|
|
break;
|
|
}
|
|
}
|
|
|
|
/* vgl* */
|
|
|
|
void vglTexImageDepthBuffer(GLenum target) {
|
|
// Setting some aliases to make code more readable
|
|
texture_unit *tex_unit = &texture_units[server_texture_unit];
|
|
int texture2d_idx = tex_unit->tex_id;
|
|
texture *tex = &textures[texture2d_idx];
|
|
|
|
switch (target) {
|
|
case GL_TEXTURE_2D:
|
|
{
|
|
if (active_read_fb)
|
|
sceGxmTextureInitLinear(&tex->gxm_tex, active_read_fb->depth_buffer_addr, SCE_GXM_TEXTURE_FORMAT_DF32M, active_read_fb->width, active_read_fb->height, 0);
|
|
else
|
|
sceGxmTextureInitLinear(&tex->gxm_tex, gxm_depth_surface_addr, SCE_GXM_TEXTURE_FORMAT_DF32M, DISPLAY_WIDTH, DISPLAY_HEIGHT, 0);
|
|
tex->valid = 1;
|
|
}
|
|
break;
|
|
default:
|
|
SET_GL_ERROR(GL_INVALID_ENUM)
|
|
break;
|
|
}
|
|
}
|