deferred fog, fix of first frame on double buffered option
This commit is contained in:
parent
48f63fc9df
commit
1296d41ad7
@ -147,6 +147,12 @@ typedef struct {
|
|||||||
} DeferredCommandDepthRange;
|
} DeferredCommandDepthRange;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
float start, end, density;
|
||||||
|
Color color;
|
||||||
|
} DeferredCommandApplyFog;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
enum DeferredCommandType {
|
enum DeferredCommandType {
|
||||||
DEFERRED_COMMAND_TYPE_DRAW,
|
DEFERRED_COMMAND_TYPE_DRAW,
|
||||||
@ -155,6 +161,8 @@ typedef struct {
|
|||||||
DEFERRED_COMMAND_TYPE_USE_PIPIELINE,
|
DEFERRED_COMMAND_TYPE_USE_PIPIELINE,
|
||||||
DEFERRED_COMMAND_TYPE_USE_TEXTURE_MODE,
|
DEFERRED_COMMAND_TYPE_USE_TEXTURE_MODE,
|
||||||
DEFERRED_COMMAND_TYPE_DEPTH_RANGE,
|
DEFERRED_COMMAND_TYPE_DEPTH_RANGE,
|
||||||
|
DEFERRED_COMMAND_TYPE_APPLY_FOG,
|
||||||
|
DEFERRED_COMMAND_TYPE_POP_FOG,
|
||||||
} type;
|
} type;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
@ -164,6 +172,7 @@ typedef struct {
|
|||||||
DeferredCommandUsePipeline use_pipeline;
|
DeferredCommandUsePipeline use_pipeline;
|
||||||
DeferredCommandUseTextureMode use_texture_mode;
|
DeferredCommandUseTextureMode use_texture_mode;
|
||||||
DeferredCommandDepthRange depth_range;
|
DeferredCommandDepthRange depth_range;
|
||||||
|
DeferredCommandApplyFog apply_fog;
|
||||||
};
|
};
|
||||||
} DeferredCommand;
|
} DeferredCommand;
|
||||||
|
|
||||||
@ -208,6 +217,8 @@ static void finally_use_2d_pipeline(void);
|
|||||||
static void finally_use_space_pipeline(void);
|
static void finally_use_space_pipeline(void);
|
||||||
static void finally_use_texture_mode(TextureMode mode);
|
static void finally_use_texture_mode(TextureMode mode);
|
||||||
static void deferred_render_skybox(char *paths);
|
static void deferred_render_skybox(char *paths);
|
||||||
|
static void deferred_apply_fog(float start, float end, float density, Color color);
|
||||||
|
static void deferred_pop_fog(void);
|
||||||
|
|
||||||
static DeferredCommand *deferred_commands;
|
static DeferredCommand *deferred_commands;
|
||||||
|
|
||||||
@ -346,6 +357,19 @@ static void issue_deferred_draw_commands(void) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case DEFERRED_COMMAND_TYPE_APPLY_FOG: {
|
||||||
|
deferred_apply_fog(deferred_commands[i].apply_fog.start,
|
||||||
|
deferred_commands[i].apply_fog.end,
|
||||||
|
deferred_commands[i].apply_fog.density,
|
||||||
|
deferred_commands[i].apply_fog.color);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case DEFERRED_COMMAND_TYPE_POP_FOG: {
|
||||||
|
deferred_pop_fog();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
SDL_assert(false);
|
SDL_assert(false);
|
||||||
}
|
}
|
||||||
@ -376,7 +400,7 @@ void start_render_frame(void) {
|
|||||||
|
|
||||||
|
|
||||||
void end_render_frame(void) {
|
void end_render_frame(void) {
|
||||||
if (!ctx.render_double_buffered || ctx.game.frame_number == 0) {
|
if (!ctx.render_double_buffered || ctx.game.frame_number == 1) {
|
||||||
issue_deferred_draw_commands();
|
issue_deferred_draw_commands();
|
||||||
SDL_GL_SwapWindow(ctx.window);
|
SDL_GL_SwapWindow(ctx.window);
|
||||||
arrsetlen(deferred_commands, 0);
|
arrsetlen(deferred_commands, 0);
|
||||||
@ -1086,6 +1110,21 @@ static void deferred_render_skybox(char *paths) {
|
|||||||
|
|
||||||
|
|
||||||
void finally_apply_fog(float start, float end, float density, Color color) {
|
void finally_apply_fog(float start, float end, float density, Color color) {
|
||||||
|
DeferredCommand command = {
|
||||||
|
.type = DEFERRED_COMMAND_TYPE_APPLY_FOG,
|
||||||
|
.apply_fog = (DeferredCommandApplyFog){
|
||||||
|
.start = start,
|
||||||
|
.end = end,
|
||||||
|
.density = density,
|
||||||
|
.color = color
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
arrpush(deferred_commands, command);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void deferred_apply_fog(float start, float end, float density, Color color) {
|
||||||
if (density < 0.0f || density > 1.0f)
|
if (density < 0.0f || density > 1.0f)
|
||||||
log_warn("Invalid fog density given, should be in range [0..1]");
|
log_warn("Invalid fog density given, should be in range [0..1]");
|
||||||
|
|
||||||
@ -1108,6 +1147,15 @@ void finally_apply_fog(float start, float end, float density, Color color) {
|
|||||||
|
|
||||||
|
|
||||||
void finally_pop_fog(void) {
|
void finally_pop_fog(void) {
|
||||||
|
DeferredCommand command = {
|
||||||
|
.type = DEFERRED_COMMAND_TYPE_POP_FOG,
|
||||||
|
};
|
||||||
|
|
||||||
|
arrpush(deferred_commands, command);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void deferred_pop_fog(void) {
|
||||||
glDisable(GL_FOG);
|
glDisable(GL_FOG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user