mirror of
https://github.com/libretro/RetroArch
synced 2025-02-08 15:40:14 +00:00
move more C functions over to gl_core.c
This commit is contained in:
parent
90874b434e
commit
376ad6d61d
@ -143,6 +143,24 @@ GLuint gl_core_compile_shader(GLenum stage, const char *source);
|
||||
|
||||
void gl_core_framebuffer_clear(GLuint id);
|
||||
|
||||
void gl_core_framebuffer_copy(
|
||||
GLuint fb_id,
|
||||
GLuint quad_program,
|
||||
GLuint quad_vbo,
|
||||
GLint flat_ubo_vertex,
|
||||
struct Size2D size,
|
||||
GLuint image);
|
||||
|
||||
void gl_core_framebuffer_copy_partial(
|
||||
GLuint fb_id,
|
||||
GLuint quad_program,
|
||||
GLint flat_ubo_vertex,
|
||||
struct Size2D size,
|
||||
GLuint image,
|
||||
float rx, float ry);
|
||||
|
||||
void gl_core_build_default_matrix(float *data);
|
||||
|
||||
uint32_t gl_core_get_cross_compiler_target_version(void);
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
@ -53,6 +53,131 @@
|
||||
|
||||
static const struct video_ortho gl_core_default_ortho = {0, 1, 0, 1, -1, 1};
|
||||
|
||||
void gl_core_build_default_matrix(float *data)
|
||||
{
|
||||
data[0] = 2.0f;
|
||||
data[1] = 0.0f;
|
||||
data[2] = 0.0f;
|
||||
data[3] = 0.0f;
|
||||
data[4] = 0.0f;
|
||||
data[5] = 2.0f;
|
||||
data[6] = 0.0f;
|
||||
data[7] = 0.0f;
|
||||
data[8] = 0.0f;
|
||||
data[9] = 0.0f;
|
||||
data[10] = 2.0f;
|
||||
data[11] = 0.0f;
|
||||
data[12] = -1.0f;
|
||||
data[13] = -1.0f;
|
||||
data[14] = 0.0f;
|
||||
data[15] = 1.0f;
|
||||
}
|
||||
|
||||
void gl_core_framebuffer_copy(
|
||||
GLuint fb_id,
|
||||
GLuint quad_program,
|
||||
GLuint quad_vbo,
|
||||
GLint flat_ubo_vertex,
|
||||
struct Size2D size,
|
||||
GLuint image)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb_id);
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, image);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glViewport(0, 0, size.width, size.height);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glUseProgram(quad_program);
|
||||
if (flat_ubo_vertex >= 0)
|
||||
{
|
||||
float mvp[16];
|
||||
gl_core_build_default_matrix(mvp);
|
||||
glUniform4fv(flat_ubo_vertex, 4, mvp);
|
||||
}
|
||||
|
||||
/* Draw quad */
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, quad_vbo);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
|
||||
(void *)((uintptr_t)(0)));
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
|
||||
(void *)((uintptr_t)(2 * sizeof(float))));
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glDisableVertexAttribArray(0);
|
||||
glDisableVertexAttribArray(1);
|
||||
|
||||
glUseProgram(0);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
void gl_core_framebuffer_copy_partial(
|
||||
GLuint fb_id,
|
||||
GLuint quad_program,
|
||||
GLint flat_ubo_vertex,
|
||||
struct Size2D size,
|
||||
GLuint image,
|
||||
float rx, float ry)
|
||||
{
|
||||
GLuint vbo;
|
||||
const float quad_data[] = {
|
||||
0.0f, 0.0f, 0.0f, 0.0f,
|
||||
1.0f, 0.0f, rx, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, ry,
|
||||
1.0f, 1.0f, rx, ry,
|
||||
};
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb_id);
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, image);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glViewport(0, 0, size.width, size.height);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glUseProgram(quad_program);
|
||||
if (flat_ubo_vertex >= 0)
|
||||
{
|
||||
float mvp[16];
|
||||
gl_core_build_default_matrix(mvp);
|
||||
glUniform4fv(flat_ubo_vertex, 4, mvp);
|
||||
}
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
/* A bit crude, but heeeey. */
|
||||
glGenBuffers(1, &vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(quad_data), quad_data, GL_STREAM_DRAW);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
|
||||
(void *)((uintptr_t)(0)));
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
|
||||
(void *)((uintptr_t)(2 * sizeof(float))));
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glDeleteBuffers(1, &vbo);
|
||||
glDisableVertexAttribArray(0);
|
||||
glDisableVertexAttribArray(1);
|
||||
glUseProgram(0);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
static void gl_core_deinit_fences(gl_core_t *gl)
|
||||
{
|
||||
unsigned i;
|
||||
|
@ -293,25 +293,6 @@ static unsigned num_miplevels(unsigned width, unsigned height)
|
||||
return levels;
|
||||
}
|
||||
|
||||
static void build_default_matrix(float *data)
|
||||
{
|
||||
data[0] = 2.0f;
|
||||
data[1] = 0.0f;
|
||||
data[2] = 0.0f;
|
||||
data[3] = 0.0f;
|
||||
data[4] = 0.0f;
|
||||
data[5] = 2.0f;
|
||||
data[6] = 0.0f;
|
||||
data[7] = 0.0f;
|
||||
data[8] = 0.0f;
|
||||
data[9] = 0.0f;
|
||||
data[10] = 2.0f;
|
||||
data[11] = 0.0f;
|
||||
data[12] = -1.0f;
|
||||
data[13] = -1.0f;
|
||||
data[14] = 0.0f;
|
||||
data[15] = 1.0f;
|
||||
}
|
||||
|
||||
static void build_vec4(float *data, unsigned width, unsigned height)
|
||||
{
|
||||
@ -560,8 +541,6 @@ public:
|
||||
GLuint get_image() const { return image; }
|
||||
GLuint get_framebuffer() const { return framebuffer; }
|
||||
|
||||
void copy(const CommonResources &common, GLuint image);
|
||||
void copy_partial(const CommonResources &common, GLuint image, float rx, float ry);
|
||||
bool is_complete() const { return complete; }
|
||||
|
||||
unsigned get_levels() const { return levels; }
|
||||
@ -679,100 +658,6 @@ void Framebuffer::init()
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
void Framebuffer::copy(const CommonResources &common, GLuint image)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, image);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glViewport(0, 0, size.width, size.height);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glUseProgram(common.quad_program);
|
||||
if (common.quad_loc.flat_ubo_vertex >= 0)
|
||||
{
|
||||
float mvp[16];
|
||||
build_default_matrix(mvp);
|
||||
glUniform4fv(common.quad_loc.flat_ubo_vertex, 4, mvp);
|
||||
}
|
||||
|
||||
/* Draw quad */
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, common.quad_vbo);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
|
||||
reinterpret_cast<void *>(uintptr_t(0)));
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
|
||||
reinterpret_cast<void *>(uintptr_t(2 * sizeof(float))));
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glDisableVertexAttribArray(0);
|
||||
glDisableVertexAttribArray(1);
|
||||
|
||||
glUseProgram(0);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
void Framebuffer::copy_partial(const CommonResources &common, GLuint image, float rx, float ry)
|
||||
{
|
||||
GLuint vbo;
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, image);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glViewport(0, 0, size.width, size.height);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glUseProgram(common.quad_program);
|
||||
if (common.quad_loc.flat_ubo_vertex >= 0)
|
||||
{
|
||||
float mvp[16];
|
||||
build_default_matrix(mvp);
|
||||
glUniform4fv(common.quad_loc.flat_ubo_vertex, 4, mvp);
|
||||
}
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
/* A bit crude, but heeeey. */
|
||||
glGenBuffers(1, &vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
|
||||
const float quad_data[] = {
|
||||
0.0f, 0.0f, 0.0f, 0.0f,
|
||||
1.0f, 0.0f, rx, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, ry,
|
||||
1.0f, 1.0f, rx, ry,
|
||||
};
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(quad_data), quad_data, GL_STREAM_DRAW);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
|
||||
reinterpret_cast<void *>(uintptr_t(0)));
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
|
||||
reinterpret_cast<void *>(uintptr_t(2 * sizeof(float))));
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glDeleteBuffers(1, &vbo);
|
||||
glDisableVertexAttribArray(0);
|
||||
glDisableVertexAttribArray(1);
|
||||
glUseProgram(0);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
Framebuffer::~Framebuffer()
|
||||
{
|
||||
if (framebuffer != 0)
|
||||
@ -1505,7 +1390,7 @@ void Pass::build_semantics(uint8_t *buffer,
|
||||
memcpy(buffer + offset,
|
||||
mvp, sizeof(float) * 16);
|
||||
else
|
||||
build_default_matrix(reinterpret_cast<float *>(
|
||||
gl_core_build_default_matrix(reinterpret_cast<float *>(
|
||||
buffer + offset));
|
||||
}
|
||||
|
||||
@ -1518,7 +1403,7 @@ void Pass::build_semantics(uint8_t *buffer,
|
||||
memcpy(push_constant_buffer.data() + offset,
|
||||
mvp, sizeof(float) * 16);
|
||||
else
|
||||
build_default_matrix(reinterpret_cast<float *>(
|
||||
gl_core_build_default_matrix(reinterpret_cast<float *>(
|
||||
push_constant_buffer.data() + offset));
|
||||
}
|
||||
|
||||
@ -1860,7 +1745,13 @@ void gl_core_filter_chain::update_history()
|
||||
tmp->set_size({ input_texture.width, input_texture.height }, input_texture.format);
|
||||
|
||||
if (tmp->is_complete())
|
||||
tmp->copy(common, input_texture.image);
|
||||
gl_core_framebuffer_copy(
|
||||
tmp->get_framebuffer(),
|
||||
common.quad_program,
|
||||
common.quad_vbo,
|
||||
common.quad_loc.flat_ubo_vertex,
|
||||
tmp->get_size(),
|
||||
input_texture.image);
|
||||
|
||||
/* Should ring buffer, but we don't have *that* many passes. */
|
||||
move_backward(begin(original_history), end(original_history) - 1, end(original_history));
|
||||
@ -2154,7 +2045,12 @@ void gl_core_filter_chain::set_input_texture(
|
||||
copy_framebuffer->set_size({ input_texture.width, input_texture.height }, input_texture.format);
|
||||
|
||||
if (copy_framebuffer->is_complete())
|
||||
copy_framebuffer->copy_partial(common, input_texture.image,
|
||||
gl_core_framebuffer_copy_partial(
|
||||
copy_framebuffer->get_framebuffer(),
|
||||
common.quad_program,
|
||||
common.quad_loc.flat_ubo_vertex,
|
||||
copy_framebuffer->get_size(),
|
||||
input_texture.image,
|
||||
float(input_texture.width)
|
||||
/ input_texture.padded_width,
|
||||
float(input_texture.height)
|
||||
|
@ -2265,7 +2265,9 @@ void Pass::build_commands(
|
||||
build_semantics(sets[sync_index], u, mvp, original, source);
|
||||
|
||||
if (reflection.ubo_stage_mask)
|
||||
vulkan_set_uniform_buffer(device, sets[sync_index], reflection.ubo_binding,
|
||||
vulkan_set_uniform_buffer(device,
|
||||
sets[sync_index],
|
||||
reflection.ubo_binding,
|
||||
common->ubo->get_buffer(),
|
||||
ubo_offset + sync_index * common->ubo_sync_index_stride,
|
||||
reflection.ubo_size);
|
||||
@ -2285,7 +2287,8 @@ void Pass::build_commands(
|
||||
VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
0,
|
||||
VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||
VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
|
||||
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,
|
||||
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
|
||||
|
||||
@ -2371,7 +2374,8 @@ void Pass::build_commands(
|
||||
/* Barrier to sync with next pass. */
|
||||
vulkan_image_layout_transition_levels(
|
||||
cmd,
|
||||
framebuffer->get_image(),VK_REMAINING_MIP_LEVELS,
|
||||
framebuffer->get_image(),
|
||||
VK_REMAINING_MIP_LEVELS,
|
||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||
|
Loading…
x
Reference in New Issue
Block a user