11#include "map_overlay.h"
21#include "nlua_shader.h"
28typedef struct PPShader_s {
35 GLint ClipSpaceFromLocal;
39 GLint love_ScreenSize;
47static unsigned int pp_shaders_id = 0;
48static PPShader *pp_shaders_list[PP_LAYER_MAX];
51static int pp_gamma_correction = 0;
56static void render_fbo(
double dt, GLuint fbo, GLuint tex,
PPShader *shader )
59 glBlendFuncSeparate( GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA );
61 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
63 glUseProgram( shader->program );
66 if (shader->love_ScreenSize >= 0)
68 glUniform4f( shader->love_ScreenSize, SCREEN_W, SCREEN_H, 1., 0. );
71 if (shader->u_time >= 0) {
73 glUniform1f( shader->u_time, shader->dt );
77 glEnableVertexAttribArray( shader->VertexPosition );
79 if (shader->VertexTexCoord >= 0) {
80 glEnableVertexAttribArray( shader->VertexTexCoord );
85 glBindTexture( GL_TEXTURE_2D, tex );
86 glUniform1i( shader->MainTex, 0 );
87 for (
int i=0; i<
array_size(shader->tex); i++) {
89 glActiveTexture( t->active );
90 glBindTexture( GL_TEXTURE_2D, t->texid );
91 glUniform1i( t->uniform, t->value );
93 glActiveTexture( GL_TEXTURE0 );
97 gl_uniformMat4(shader->ClipSpaceFromLocal, &ortho);
100 glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
103 glDisableVertexAttribArray( shader->VertexPosition );
104 if (shader->VertexTexCoord >= 0)
105 glDisableVertexAttribArray( shader->VertexTexCoord );
109 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
115static void render_fbo_list(
double dt,
PPShader *list,
int *current,
int done )
175 int pp_final, pp_gui, pp_game;
179 pp_game = (
array_size(pp_shaders_list[PP_LAYER_GAME]) > 0);
180 pp_gui = (
array_size(pp_shaders_list[PP_LAYER_GUI]) > 0);
181 pp_final = (
array_size(pp_shaders_list[PP_LAYER_FINAL]) > 0);
184 if (pp_game || pp_gui || pp_final) {
186 glBindFramebuffer(GL_FRAMEBUFFER, 0);
187 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
191 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
201 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
229 render_fbo_list( dt, pp_shaders_list[PP_LAYER_GAME], &cur, !(pp_final || pp_gui) );
235 render_fbo_list( dt, pp_shaders_list[PP_LAYER_GUI], &cur, !pp_final );
248 render_fbo_list( dt, pp_shaders_list[PP_LAYER_FINAL], &cur, 1 );
257static int ppshader_compare(
const void *a,
const void *b )
278unsigned int render_postprocessAdd(
LuaShader_t *shader,
int layer,
int priority,
unsigned int flags )
284 if (layer < 0 || layer >= PP_LAYER_MAX) {
285 WARN(_(
"Unknown post-processing shader layer '%d'!"), layer);
288 pp_shaders = &pp_shaders_list[layer];
290 if (*pp_shaders==NULL)
293 id = ++pp_shaders_id;
298 pp->ClipSpaceFromLocal = shader->ClipSpaceFromLocal;
299 pp->MainTex = shader->MainTex;
300 pp->VertexPosition = shader->VertexPosition;
301 pp->VertexTexCoord = shader->VertexTexCoord;
302 if (shader->tex != NULL)
308 pp->love_ScreenSize = glGetUniformLocation( pp->
program,
"love_ScreenSize" );
325int render_postprocessRm(
unsigned int id )
329 for (j=0; j<PP_LAYER_MAX; j++) {
330 PPShader *pp_shaders = pp_shaders_list[j];
331 for (
int i=0; i<
array_size(pp_shaders); i++) {
348 array_erase( &pp_shaders_list[j], &pp_shaders_list[j][found], &pp_shaders_list[j][found+1] );
355void render_postprocessCleanup (
void)
357 for (
int j=0; j<PP_LAYER_MAX; j++) {
358 PPShader *pp_shaders = pp_shaders_list[j];
359 for (
int i=
array_size(pp_shaders)-1; i>=0; i--) {
361 if (pp->
flags & PP_SHADER_PERMANENT)
363 array_erase( &pp_shaders_list[j], &pp_shaders_list[j][i], &pp_shaders_list[j][i+1] );
372void render_init (
void)
376 s->program = shaders.gamma_correction.program;
377 s->VertexPosition = shaders.gamma_correction.VertexPosition;
378 s->ClipSpaceFromLocal = shaders.gamma_correction.ClipSpaceFromLocal;
379 s->MainTex = shaders.gamma_correction.MainTex;
388void render_exit (
void)
390 for (
int i=0; i<PP_LAYER_MAX; i++) {
392 pp_shaders_list[i] = NULL;
399void render_setGamma(
double gamma )
401 if (pp_gamma_correction > 0) {
402 render_postprocessRm( pp_gamma_correction );
403 pp_gamma_correction = 0;
407 if (fabs(gamma-1.) < 1e-3)
411 glUseProgram( shaders.gamma_correction.program );
412 glUniform1f( shaders.gamma_correction.gamma, gamma );
414 pp_gamma_correction = render_postprocessAdd( &gamma_correction_shader, PP_LAYER_FINAL, 98, PP_SHADER_PERMANENT );
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
#define array_copy(basic_type, ptr_array)
Returns a shallow copy of the input array.
#define array_erase(ptr_array, first, last)
Erases elements in interval [first, last).
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
void gui_renderReticles(double dt)
Renders the gui targeting reticles.
void gui_render(double dt)
Renders the player's GUI.
int hooks_run(const char *stack)
Runs all the hooks of stack.
mat4 mat4_ortho(double left, double right, double bottom, double top, double nearVal, double farVal)
Creates an orthographic projection matrix.
void display_fps(const double dt)
Displays FPS on the screen.
Header file with generic functions and naev-specifics.
void gl_defViewport(void)
Resets viewport to default.
void gl_viewport(int x, int y, int w, int h)
Sets the opengl viewport.
void gl_vboActivateAttribOffset(gl_vbo *vbo, GLuint index, GLuint offset, GLint size, GLenum type, GLsizei stride)
Activates a VBO's offset.
void pilots_renderOverlay(void)
Renders all the pilots overlays.
void pilots_render(void)
Renders all the pilots.
void player_render(double dt)
Renders the player.
void player_renderUnderlay(double dt)
Renders the player underlay.
void space_render(const double dt)
Renders the system.
void space_renderOverlay(const double dt)
Renders the system overlay.
void spobs_render(void)
Renders the current systems' spobs.
void spfx_render(int layer)
Renders the entire spfx layer.
GLuint fbo_tex[OPENGL_NUM_FBOS]
GLuint fbo[OPENGL_NUM_FBOS]
void weapons_render(const WeaponLayer layer, const double dt)
Renders all the weapons in a layer.