mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-25 01:57:47 +01:00
allow custom amount of framebuffers
This commit is contained in:
parent
fdcf9a7d1a
commit
10f4d8b484
@ -5,6 +5,7 @@
|
|||||||
#include "opengl_utils.h"
|
#include "opengl_utils.h"
|
||||||
|
|
||||||
#define TEXTURE_COUNT 4
|
#define TEXTURE_COUNT 4
|
||||||
|
#define FBO_COUNT 1
|
||||||
|
|
||||||
typedef struct OGLRENDERER
|
typedef struct OGLRENDERER
|
||||||
{
|
{
|
||||||
@ -26,8 +27,8 @@ typedef struct OGLRENDERER
|
|||||||
GLuint main_vbos[3];
|
GLuint main_vbos[3];
|
||||||
GLuint main_vao;
|
GLuint main_vao;
|
||||||
GLint frame_count_uni_loc;
|
GLint frame_count_uni_loc;
|
||||||
GLuint frame_buffer_id;
|
GLuint frame_buffer_id[FBO_COUNT];
|
||||||
GLuint frame_buffer_tex_id;
|
GLuint frame_buffer_tex_id[FBO_COUNT];
|
||||||
GLint scale_tex_coord_attr_loc;
|
GLint scale_tex_coord_attr_loc;
|
||||||
GLuint scale_vbos[3];
|
GLuint scale_vbos[3];
|
||||||
GLuint scale_vao;
|
GLuint scale_vao;
|
||||||
|
138
src/render_ogl.c
138
src/render_ogl.c
@ -570,76 +570,82 @@ static void ogl_init_scale_program()
|
|||||||
};
|
};
|
||||||
glUniformMatrix4fv(glGetUniformLocation(g_ogl.scale_program, "MVPMatrix"), 1, GL_FALSE, mvp_matrix);
|
glUniformMatrix4fv(glGetUniformLocation(g_ogl.scale_program, "MVPMatrix"), 1, GL_FALSE, mvp_matrix);
|
||||||
|
|
||||||
glGenFramebuffers(1, &g_ogl.frame_buffer_id);
|
glGenFramebuffers(FBO_COUNT, g_ogl.frame_buffer_id);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, g_ogl.frame_buffer_id);
|
glGenTextures(FBO_COUNT, g_ogl.frame_buffer_tex_id);
|
||||||
|
|
||||||
glGenTextures(1, &g_ogl.frame_buffer_tex_id);
|
for (int i = 0; i < FBO_COUNT; i++)
|
||||||
glBindTexture(GL_TEXTURE_2D, g_ogl.frame_buffer_tex_id);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, g_ogl.filter_bilinear ? GL_LINEAR : GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, g_ogl.filter_bilinear ? GL_LINEAR : GL_NEAREST);
|
|
||||||
glTexImage2D(
|
|
||||||
GL_TEXTURE_2D,
|
|
||||||
0,
|
|
||||||
GL_RGBA8,
|
|
||||||
g_ogl.surface_tex_width,
|
|
||||||
g_ogl.surface_tex_height,
|
|
||||||
0,
|
|
||||||
GL_RGBA,
|
|
||||||
GL_UNSIGNED_BYTE,
|
|
||||||
g_ogl.surface_tex);
|
|
||||||
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, g_ogl.frame_buffer_tex_id, 0);
|
|
||||||
|
|
||||||
GLenum draw_buffers[1] = { GL_COLOR_ATTACHMENT0 };
|
|
||||||
glDrawBuffers(1, draw_buffers);
|
|
||||||
|
|
||||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
|
||||||
{
|
{
|
||||||
glDeleteTextures(1, &g_ogl.frame_buffer_tex_id);
|
glBindFramebuffer(GL_FRAMEBUFFER, g_ogl.frame_buffer_id[i]);
|
||||||
|
|
||||||
if (glDeleteFramebuffers)
|
glBindTexture(GL_TEXTURE_2D, g_ogl.frame_buffer_tex_id[i]);
|
||||||
glDeleteFramebuffers(1, &g_ogl.frame_buffer_id);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, g_ogl.filter_bilinear ? GL_LINEAR : GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, g_ogl.filter_bilinear ? GL_LINEAR : GL_NEAREST);
|
||||||
|
glTexImage2D(
|
||||||
|
GL_TEXTURE_2D,
|
||||||
|
0,
|
||||||
|
GL_RGBA8,
|
||||||
|
g_ogl.surface_tex_width,
|
||||||
|
g_ogl.surface_tex_height,
|
||||||
|
0,
|
||||||
|
GL_RGBA,
|
||||||
|
GL_UNSIGNED_BYTE,
|
||||||
|
g_ogl.surface_tex);
|
||||||
|
|
||||||
if (glDeleteProgram)
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, g_ogl.frame_buffer_tex_id[i], 0);
|
||||||
glDeleteProgram(g_ogl.scale_program);
|
|
||||||
|
|
||||||
g_ogl.scale_program = 0;
|
GLenum draw_buffers[1] = { GL_COLOR_ATTACHMENT0 };
|
||||||
|
glDrawBuffers(1, draw_buffers);
|
||||||
|
|
||||||
if (glDeleteBuffers)
|
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||||
glDeleteBuffers(3, g_ogl.scale_vbos);
|
|
||||||
|
|
||||||
if (glDeleteVertexArrays)
|
|
||||||
glDeleteVertexArrays(1, &g_ogl.scale_vao);
|
|
||||||
|
|
||||||
if (g_ogl.main_program)
|
|
||||||
{
|
{
|
||||||
glBindVertexArray(g_ogl.main_vao);
|
glDeleteTextures(FBO_COUNT, g_ogl.frame_buffer_tex_id);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, g_ogl.main_vbos[0]);
|
|
||||||
static const GLfloat vertex_coord_pal[] = {
|
|
||||||
-1.0f, 1.0f,
|
|
||||||
1.0f, 1.0f,
|
|
||||||
1.0f,-1.0f,
|
|
||||||
-1.0f,-1.0f,
|
|
||||||
};
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_coord_pal), vertex_coord_pal, GL_STATIC_DRAW);
|
|
||||||
glVertexAttribPointer(g_ogl.main_vertex_coord_attr_loc, 2, GL_FLOAT, GL_FALSE, 0, NULL);
|
|
||||||
glEnableVertexAttribArray(g_ogl.main_vertex_coord_attr_loc);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
glBindVertexArray(g_ogl.main_vao);
|
if (glDeleteFramebuffers)
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, g_ogl.main_vbos[1]);
|
glDeleteFramebuffers(FBO_COUNT, g_ogl.frame_buffer_id);
|
||||||
GLfloat tex_coord_pal[] = {
|
|
||||||
0.0f, 0.0f,
|
if (glDeleteProgram)
|
||||||
g_ogl.scale_w, 0.0f,
|
glDeleteProgram(g_ogl.scale_program);
|
||||||
g_ogl.scale_w, g_ogl.scale_h,
|
|
||||||
0.0f, g_ogl.scale_h,
|
g_ogl.scale_program = 0;
|
||||||
};
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(tex_coord_pal), tex_coord_pal, GL_STATIC_DRAW);
|
if (glDeleteBuffers)
|
||||||
glVertexAttribPointer(g_ogl.main_tex_coord_attr_loc, 2, GL_FLOAT, GL_FALSE, 0, NULL);
|
glDeleteBuffers(3, g_ogl.scale_vbos);
|
||||||
glEnableVertexAttribArray(g_ogl.main_tex_coord_attr_loc);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
if (glDeleteVertexArrays)
|
||||||
glBindVertexArray(0);
|
glDeleteVertexArrays(1, &g_ogl.scale_vao);
|
||||||
|
|
||||||
|
if (g_ogl.main_program)
|
||||||
|
{
|
||||||
|
glBindVertexArray(g_ogl.main_vao);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, g_ogl.main_vbos[0]);
|
||||||
|
static const GLfloat vertex_coord_pal[] = {
|
||||||
|
-1.0f, 1.0f,
|
||||||
|
1.0f, 1.0f,
|
||||||
|
1.0f,-1.0f,
|
||||||
|
-1.0f,-1.0f,
|
||||||
|
};
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_coord_pal), vertex_coord_pal, GL_STATIC_DRAW);
|
||||||
|
glVertexAttribPointer(g_ogl.main_vertex_coord_attr_loc, 2, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||||
|
glEnableVertexAttribArray(g_ogl.main_vertex_coord_attr_loc);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
glBindVertexArray(g_ogl.main_vao);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, g_ogl.main_vbos[1]);
|
||||||
|
GLfloat tex_coord_pal[] = {
|
||||||
|
0.0f, 0.0f,
|
||||||
|
g_ogl.scale_w, 0.0f,
|
||||||
|
g_ogl.scale_w, g_ogl.scale_h,
|
||||||
|
0.0f, g_ogl.scale_h,
|
||||||
|
};
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(tex_coord_pal), tex_coord_pal, GL_STATIC_DRAW);
|
||||||
|
glVertexAttribPointer(g_ogl.main_tex_coord_attr_loc, 2, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||||
|
glEnableVertexAttribArray(g_ogl.main_tex_coord_attr_loc);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -866,7 +872,7 @@ static void ogl_render()
|
|||||||
|
|
||||||
glViewport(0, 0, g_ddraw.width, g_ddraw.height);
|
glViewport(0, 0, g_ddraw.width, g_ddraw.height);
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, g_ogl.frame_buffer_id);
|
glBindFramebuffer(GL_FRAMEBUFFER, g_ogl.frame_buffer_id[0]);
|
||||||
|
|
||||||
glBindVertexArray(g_ogl.main_vao);
|
glBindVertexArray(g_ogl.main_vao);
|
||||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
|
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
|
||||||
@ -894,7 +900,7 @@ static void ogl_render()
|
|||||||
|
|
||||||
glUseProgram(g_ogl.scale_program);
|
glUseProgram(g_ogl.scale_program);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, g_ogl.frame_buffer_tex_id);
|
glBindTexture(GL_TEXTURE_2D, g_ogl.frame_buffer_tex_id[0]);
|
||||||
|
|
||||||
static int frames = 1;
|
static int frames = 1;
|
||||||
if (g_ogl.frame_count_uni_loc != -1)
|
if (g_ogl.frame_count_uni_loc != -1)
|
||||||
@ -951,13 +957,13 @@ static void ogl_delete_context(HGLRC context)
|
|||||||
|
|
||||||
if (g_ogl.scale_program)
|
if (g_ogl.scale_program)
|
||||||
{
|
{
|
||||||
glDeleteTextures(1, &g_ogl.frame_buffer_tex_id);
|
glDeleteTextures(FBO_COUNT, g_ogl.frame_buffer_tex_id);
|
||||||
|
|
||||||
if (glDeleteBuffers)
|
if (glDeleteBuffers)
|
||||||
glDeleteBuffers(3, g_ogl.scale_vbos);
|
glDeleteBuffers(3, g_ogl.scale_vbos);
|
||||||
|
|
||||||
if (glDeleteFramebuffers)
|
if (glDeleteFramebuffers)
|
||||||
glDeleteFramebuffers(1, &g_ogl.frame_buffer_id);
|
glDeleteFramebuffers(FBO_COUNT, g_ogl.frame_buffer_id);
|
||||||
|
|
||||||
if (glDeleteVertexArrays)
|
if (glDeleteVertexArrays)
|
||||||
glDeleteVertexArrays(1, &g_ogl.scale_vao);
|
glDeleteVertexArrays(1, &g_ogl.scale_vao);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user