10#include "map_overlay.h"
13#include "nlua_canvas.h"
23#include "nlua_shader.h"
30typedef struct PPShader_s {
37 GLint ClipSpaceFromLocal;
41 GLint love_ScreenSize;
49static unsigned int pp_shaders_id = 0;
50static PPShader *pp_shaders_list[PP_LAYER_MAX];
54static int pp_gamma_correction = 0;
59static void render_fbo(
double dt, GLuint fbo, GLuint tex,
PPShader *shader )
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 );
80 if ( shader->VertexTexCoord >= 0 ) {
81 glEnableVertexAttribArray( shader->VertexTexCoord );
87 glBindTexture( GL_TEXTURE_2D, tex );
88 glUniform1i( shader->MainTex, 0 );
89 for (
int i = 0; i <
array_size( shader->tex ); i++ ) {
91 glActiveTexture( t->active );
92 glBindTexture( GL_TEXTURE_2D, t->texid );
93 glUniform1i( t->uniform, t->value );
95 glActiveTexture( GL_TEXTURE0 );
99 gl_uniformMat4( shader->ClipSpaceFromLocal, &ortho );
102 glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
105 glDisableVertexAttribArray( shader->VertexPosition );
106 if ( shader->VertexTexCoord >= 0 )
107 glDisableVertexAttribArray( shader->VertexTexCoord );
114static void render_fbo_list(
double dt,
PPShader *list,
int *current,
int done )
121 for ( i = 0; i <
array_size( list ) - 1; i++ ) {
135 glBindFramebuffer( GL_FRAMEBUFFER,
gl_screen.current_fbo );
146 glBindFramebuffer( GL_FRAMEBUFFER,
gl_screen.current_fbo );
172 NTracingZone( _ctx, 1 );
175 int pp_core, 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 );
182 pp_core = (
array_size( pp_shaders_list[PP_LAYER_CORE] ) > 0 );
185 glClearColor( 0., 0., 0., 1. );
188 if ( pp_game || pp_gui || pp_final || pp_core ) {
190 glBindFramebuffer( GL_FRAMEBUFFER, 0 );
191 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
194 glBindFramebuffer( GL_FRAMEBUFFER,
gl_screen.fbo[1] );
195 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
203 glBindFramebuffer( GL_FRAMEBUFFER,
gl_screen.current_fbo );
204 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
205 glClearColor( 0., 0., 0., 0. );
216 NTracingZoneName( _ctx_renderbg,
"hooks[renderbg]", 1 );
218 NTracingZoneEnd( _ctx_renderbg );
235 NTracingZoneName( _ctx_renderfg,
"hooks[renderfg]", 1 );
237 NTracingZoneEnd( _ctx_renderfg );
242 NTracingZoneName( _ctx_pp_game,
"postprocess_shader[game]", 1 );
243 render_fbo_list( dt, pp_shaders_list[PP_LAYER_GAME], &cur,
244 !( pp_core || pp_final || pp_gui ) );
245 NTracingZoneEnd( _ctx_pp_game );
253 NTracingZoneName( _ctx_pp_gui,
"postprocess_shader[gui]", 1 );
254 render_fbo_list( dt, pp_shaders_list[PP_LAYER_GUI], &cur,
255 !( pp_core || pp_final ) );
256 NTracingZoneEnd( _ctx_pp_gui );
264 NTracingZoneName( _ctx_rendertop,
"hooks[rendertop]", 1 );
266 NTracingZoneEnd( _ctx_rendertop );
274 NTracingZoneName( _ctx_pp_final,
"postprocess_shader[final]", 1 );
275 render_fbo_list( dt, pp_shaders_list[PP_LAYER_FINAL], &cur,
277 NTracingZoneEnd( _ctx_pp_final );
285 NTracingZoneName( _ctx_pp_core,
"postprocess_shader[core]", 1 );
286 render_fbo_list( dt, pp_shaders_list[PP_LAYER_CORE], &cur, 1 );
287 NTracingZoneEnd( _ctx_pp_core );
293 NTracingZoneEnd( _ctx );
299static int ppshader_compare(
const void *a,
const void *b )
319unsigned int render_postprocessAdd(
LuaShader_t *shader,
int layer,
320 int priority,
unsigned int flags )
326 if ( layer < 0 || layer >= PP_LAYER_MAX ) {
327 WARN( _(
"Unknown post-processing shader layer '%d'!" ), layer );
330 pp_shaders = &pp_shaders_list[layer];
332 if ( *pp_shaders == NULL )
335 id = ++pp_shaders_id;
340 pp->ClipSpaceFromLocal = shader->ClipSpaceFromLocal;
341 pp->MainTex = shader->MainTex;
342 pp->VertexPosition = shader->VertexPosition;
343 pp->VertexTexCoord = shader->VertexTexCoord;
344 if ( shader->tex != NULL )
350 pp->love_ScreenSize = glGetUniformLocation( pp->
program,
"love_ScreenSize" );
368int render_postprocessRm(
unsigned int id )
372 for ( j = 0; j < PP_LAYER_MAX; j++ ) {
373 PPShader *pp_shaders = pp_shaders_list[j];
374 for (
int i = 0; i <
array_size( pp_shaders ); i++ ) {
375 const PPShader *pp = &pp_shaders[i];
393 array_erase( &pp_shaders_list[j], &pp_shaders_list[j][found],
394 &pp_shaders_list[j][found + 1] );
401void render_postprocessCleanup(
void )
403 for (
int j = 0; j < PP_LAYER_MAX; j++ ) {
404 PPShader *pp_shaders = pp_shaders_list[j];
405 for (
int i =
array_size( pp_shaders ) - 1; i >= 0; i-- ) {
406 const PPShader *pp = &pp_shaders[i];
407 if ( pp->
flags & PP_SHADER_PERMANENT )
409 array_erase( &pp_shaders_list[j], &pp_shaders_list[j][i],
410 &pp_shaders_list[j][i + 1] );
419void render_init(
void )
423 s->program = shaders.gamma_correction.program;
424 s->VertexPosition = shaders.gamma_correction.VertexPosition;
425 s->ClipSpaceFromLocal = shaders.gamma_correction.ClipSpaceFromLocal;
426 s->MainTex = shaders.gamma_correction.MainTex;
429 render_setGamma( conf.gamma_correction );
435void render_exit(
void )
437 for (
int i = 0; i < PP_LAYER_MAX; i++ ) {
439 pp_shaders_list[i] = NULL;
446void render_setGamma(
double gamma )
448 if ( pp_gamma_correction > 0 ) {
449 render_postprocessRm( pp_gamma_correction );
450 pp_gamma_correction = 0;
454 if ( fabs( gamma - 1. ) < 1e-3 )
458 glUseProgram( shaders.gamma_correction.program );
459 glUniform1f( shaders.gamma_correction.gamma, gamma );
461 pp_gamma_correction = render_postprocessAdd(
462 &gamma_correction_shader, PP_LAYER_CORE, 98, PP_SHADER_PERMANENT );
465static int needsReset = 0;
469void render_reset(
void )
475 glBlendEquation( GL_FUNC_ADD );
476 glBlendFuncSeparate( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE,
477 GL_ONE_MINUS_SRC_ALPHA );
486void render_needsReset(
void )
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 fps_display(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_unclipRect(void)
Clears the 2d clipping planes.
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, double dt)
Renders the entire spfx layer.
void weapons_render(const WeaponLayer layer, double dt)
Renders all the weapons in a layer.