render: fx_end() no longer takes fb handle

main
Dominik Madarász 2023-09-23 18:23:38 +02:00
parent 0beb264e2b
commit b44fd791a6
23 changed files with 69 additions and 63 deletions

View File

@ -608,7 +608,7 @@ if "!vis!"=="yes" echo !cc! engine\v4k.c !export! !args! ^&^& if "!dll!"=="dll"
rem editor
if "!editor!"=="yes" (
set edit=-DCOOK_ON_DEMAND -DUI_LESSER_SPACING -DUI_ICONS_SMALL -DVFS_ALWAYS_PACK
set edit=-DCOOK_ON_DEMAND -DUI_LESSER_SPACING -DUI_ICONS_SMALL
rem if "!vis!"=="yes" echo !cc! !o! editor.exe tools\editor\editor.c !edit! !import! !args!
rem !echo! editor && !cc! !o! editor.exe tools\editor\editor.c !edit! !import! !args! || set rc=1
rem !echo! editor2 && !cc! !o! editor2.exe tools\editor\editor2.c !edit! !args! || set rc=1

View File

@ -180,7 +180,7 @@ int main() {
}
// post-fxs end here
fx_end(0);
fx_end();
// font demo
do_once font_scales(FONT_FACE1, 48, 24, 18, 12, 9, 6);

View File

@ -124,7 +124,7 @@ int main() {
);
// post-fxs end here
fx_end(0);
fx_end();
// ui
if( ui_panel("Audio", 0)) {

View File

@ -88,7 +88,7 @@ int main() {
collide_demo();
}
fx_end(0);
fx_end();
// ui
if( ui_panel("App", 0) ) {

View File

@ -90,7 +90,7 @@ int main() {
}
}
fx_end(0);
fx_end();
if( ui_panel("Animation", 0) ) {
if( ui_bool("Show aabb", &do_showaabb) );

View File

@ -125,7 +125,7 @@ int main() {
}
// post-fxs end here
fx_end(0);
fx_end();
// queue ui
if( ui_panel("Camera", 0)) {

View File

@ -69,7 +69,7 @@ int main() {
model_render(witch, cam.proj, cam.view, witch.pivot, 0);
// render end (postfx)
fx_end(0);
fx_end();
// input controllers

View File

@ -169,7 +169,7 @@ int main() {
skybox_render(&sky, cam.proj, cam.view);
draw_world();
fx_end(0);
fx_end();
}
return 0;

View File

@ -577,7 +577,7 @@ int main( int argc, const char *argv[] ) {
glDepthFunc( GL_LESS );
}
fx_end(0);
fx_end();
// ---------------------------------------------------------------------
// UI

View File

@ -70,6 +70,6 @@ int main() {
model_render(sponza, cam.proj, cam.view, M, 0);
// post-fxs end here
fx_end(0);
fx_end();
}
}

View File

@ -191,7 +191,7 @@ int main(int argc, char **argv) {
}
// post-fxs end here
fx_end(0);
fx_end();
// draw pixel-art hud, 16x16 ui element, scaled and positioned in resolution-independant way
{

View File

@ -584,7 +584,7 @@ void game_loop(void *userdata) {
//fx_begin();
//ddraw_flush();
//fx_end(0);
//fx_end();
if( ui_panel("Vis", 0) ) {
ui_bool("Skybox render", &draw_skybox);

View File

@ -46,29 +46,26 @@ const int LIGHT_SPOT = 2;
uniform light_t u_lights[MAX_LIGHTS];
vec3 calculate_light(light_t l, vec3 normal, vec3 fragPos, vec3 viewDir) {
vec3 lightColor = l.color;
vec3 lightDir;
float attenuation = 1.0;
if (l.type == LIGHT_DIRECTIONAL) {
lightDir = normalize(-l.dir);
} else if (l.type == LIGHT_POINT) {
vec3 toLight = fragPos - l.pos;
vec3 toLight = l.pos - fragPos;
lightDir = normalize(toLight);
float distance = length(toLight);
float factor = distance / l.radius;
float factor = distance / (l.radius*l.radius);
attenuation = clamp(1.0 - factor, 0.0, 1.0);
}
float diff = max(dot(normal, lightDir), 0.0);
vec3 diffuse = diff * lightColor;
// vec3 reflectDir = reflect(-lightDir, normal);
// float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
// vec3 specular = spec * lightColor;
return (diffuse /* + specular */) * l.color;
return (diff /* + specular */) * l.color;
}
void main() {
@ -95,9 +92,9 @@ void main() {
// analytical lights (phong shading)
// @todo: support more shading models (blinn-phong, ue4 brdf, ...)
// for (int i=0; i<u_num_lights; i++) {
// lit += vec4(calculate_light(u_lights[i], n, v_position, /* @todo: push vdeye */ vec3(1.0,1.0,1.0)), 0.0);
// }
for (int i=0; i<u_num_lights; i++) {
lit += vec4(calculate_light(u_lights[i], n, v_position, /* @todo: push vdeye */ vec3(1.0,1.0,1.0)), 0.0);
}
// base
vec4 diffuse;

View File

@ -2591,7 +2591,7 @@ float *pixels;
int fx_load_from_mem(const char *nameid, const char *content);
void fx_begin();
void fx_begin_res(int w, int h);
void fx_end(handle fb);
void fx_end();
void fx_enable(int pass, int enabled);
int fx_enabled(int pass);
void fx_enable_all(int enabled);

View File

@ -17014,7 +17014,7 @@ API int fx_load(const char *file);
API int fx_load_from_mem(const char *nameid, const char *content);
API void fx_begin();
API void fx_begin_res(int w, int h);
API void fx_end(handle fb);
API void fx_end();
API void fx_enable(int pass, int enabled);
API int fx_enabled(int pass);
API void fx_enable_all(int enabled);
@ -342558,7 +342558,7 @@ void postfx_destroy(postfx *fx);
bool postfx_load(postfx *fx, const char *name, const char *fragment);
bool postfx_begin(postfx *fx, int width, int height);
bool postfx_end(postfx *fx, handle fb);
bool postfx_end(postfx *fx);
bool postfx_enabled(postfx *fx, int pass_number);
bool postfx_enable(postfx *fx, int pass_number, bool enabled);
@ -342709,6 +342709,8 @@ void postfx_clear(postfx *fx) {
fx->mask = fx->enabled = 0;
}
static __thread array(handle) last_fb;
bool postfx_begin(postfx *fx, int width, int height) {
// reset clear color: needed in case transparent window is being used (alpha != 0)
glClearColor(0,0,0,0); // @transparent
@ -342716,9 +342718,9 @@ bool postfx_begin(postfx *fx, int width, int height) {
width += !width;
height += !height;
int last_fb;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &last_fb);
fbo_bind(last_fb);
int fb;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &fb);
array_push(last_fb, fb);
// resize if needed
if( fx->diffuse[0].w != width || fx->diffuse[0].h != height ) {
@ -342743,7 +342745,8 @@ bool postfx_begin(postfx *fx, int width, int height) {
uint64_t num_active_passes = popcnt64(fx->mask);
bool active = fx->enabled && num_active_passes;
if( !active ) {
fbo_bind(last_fb);
array_pop(last_fb);
fbo_bind(fb);
return false;
}
@ -342760,13 +342763,15 @@ bool postfx_begin(postfx *fx, int width, int height) {
return true;
}
bool postfx_end(postfx *fx, handle fb) {
bool postfx_end(postfx *fx) {
uint64_t num_active_passes = popcnt64(fx->mask);
bool active = fx->enabled && num_active_passes;
if( !active ) {
return false;
}
handle fb = *array_back(last_fb);
array_pop(last_fb);
fbo_bind(fb);
// disable depth test in 2d rendering
@ -342829,8 +342834,6 @@ bool postfx_end(postfx *fx, handle fb) {
if(is_depth_test_enabled);
glEnable(GL_DEPTH_TEST);
fbo_bind(fb);
return true;
}
@ -342855,8 +342858,8 @@ void fx_begin() {
void fx_begin_res(int w, int h) {
postfx_begin(&fx, w, h);
}
void fx_end(handle fb) {
postfx_end(&fx,fb);
void fx_end() {
postfx_end(&fx);
}
int fx_enabled(int pass) {
return postfx_enabled(&fx, pass);

View File

@ -2948,7 +2948,7 @@ void postfx_destroy(postfx *fx);
bool postfx_load(postfx *fx, const char *name, const char *fragment);
bool postfx_begin(postfx *fx, int width, int height);
bool postfx_end(postfx *fx, handle fb);
bool postfx_end(postfx *fx);
bool postfx_enabled(postfx *fx, int pass_number);
bool postfx_enable(postfx *fx, int pass_number, bool enabled);
@ -3099,6 +3099,8 @@ void postfx_clear(postfx *fx) {
fx->mask = fx->enabled = 0;
}
static __thread array(handle) last_fb;
bool postfx_begin(postfx *fx, int width, int height) {
// reset clear color: needed in case transparent window is being used (alpha != 0)
glClearColor(0,0,0,0); // @transparent
@ -3106,9 +3108,9 @@ bool postfx_begin(postfx *fx, int width, int height) {
width += !width;
height += !height;
int last_fb;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &last_fb);
fbo_bind(last_fb);
int fb;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &fb);
array_push(last_fb, fb);
// resize if needed
if( fx->diffuse[0].w != width || fx->diffuse[0].h != height ) {
@ -3133,7 +3135,8 @@ bool postfx_begin(postfx *fx, int width, int height) {
uint64_t num_active_passes = popcnt64(fx->mask);
bool active = fx->enabled && num_active_passes;
if( !active ) {
fbo_bind(last_fb);
array_pop(last_fb);
fbo_bind(fb);
return false;
}
@ -3150,13 +3153,15 @@ bool postfx_begin(postfx *fx, int width, int height) {
return true;
}
bool postfx_end(postfx *fx, handle fb) {
bool postfx_end(postfx *fx) {
uint64_t num_active_passes = popcnt64(fx->mask);
bool active = fx->enabled && num_active_passes;
if( !active ) {
return false;
}
handle fb = *array_back(last_fb);
array_pop(last_fb);
fbo_bind(fb);
// disable depth test in 2d rendering
@ -3219,8 +3224,6 @@ bool postfx_end(postfx *fx, handle fb) {
if(is_depth_test_enabled);
glEnable(GL_DEPTH_TEST);
fbo_bind(fb);
return true;
}
@ -3245,8 +3248,8 @@ void fx_begin() {
void fx_begin_res(int w, int h) {
postfx_begin(&fx, w, h);
}
void fx_end(handle fb) {
postfx_end(&fx,fb);
void fx_end() {
postfx_end(&fx);
}
int fx_enabled(int pass) {
return postfx_enabled(&fx, pass);

View File

@ -664,7 +664,7 @@ API int fx_load(const char *file);
API int fx_load_from_mem(const char *nameid, const char *content);
API void fx_begin();
API void fx_begin_res(int w, int h);
API void fx_end(handle fb);
API void fx_end();
API void fx_enable(int pass, int enabled);
API int fx_enabled(int pass);
API void fx_enable_all(int enabled);

View File

@ -13212,7 +13212,7 @@ void postfx_destroy(postfx *fx);
bool postfx_load(postfx *fx, const char *name, const char *fragment);
bool postfx_begin(postfx *fx, int width, int height);
bool postfx_end(postfx *fx, handle fb);
bool postfx_end(postfx *fx);
bool postfx_enabled(postfx *fx, int pass_number);
bool postfx_enable(postfx *fx, int pass_number, bool enabled);
@ -13363,6 +13363,8 @@ void postfx_clear(postfx *fx) {
fx->mask = fx->enabled = 0;
}
static __thread array(handle) last_fb;
bool postfx_begin(postfx *fx, int width, int height) {
// reset clear color: needed in case transparent window is being used (alpha != 0)
glClearColor(0,0,0,0); // @transparent
@ -13370,9 +13372,9 @@ bool postfx_begin(postfx *fx, int width, int height) {
width += !width;
height += !height;
int last_fb;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &last_fb);
fbo_bind(last_fb);
int fb;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &fb);
array_push(last_fb, fb);
// resize if needed
if( fx->diffuse[0].w != width || fx->diffuse[0].h != height ) {
@ -13397,7 +13399,8 @@ bool postfx_begin(postfx *fx, int width, int height) {
uint64_t num_active_passes = popcnt64(fx->mask);
bool active = fx->enabled && num_active_passes;
if( !active ) {
fbo_bind(last_fb);
array_pop(last_fb);
fbo_bind(fb);
return false;
}
@ -13414,13 +13417,15 @@ bool postfx_begin(postfx *fx, int width, int height) {
return true;
}
bool postfx_end(postfx *fx, handle fb) {
bool postfx_end(postfx *fx) {
uint64_t num_active_passes = popcnt64(fx->mask);
bool active = fx->enabled && num_active_passes;
if( !active ) {
return false;
}
handle fb = *array_back(last_fb);
array_pop(last_fb);
fbo_bind(fb);
// disable depth test in 2d rendering
@ -13483,8 +13488,6 @@ bool postfx_end(postfx *fx, handle fb) {
if(is_depth_test_enabled);
glEnable(GL_DEPTH_TEST);
fbo_bind(fb);
return true;
}
@ -13509,8 +13512,8 @@ void fx_begin() {
void fx_begin_res(int w, int h) {
postfx_begin(&fx, w, h);
}
void fx_end(handle fb) {
postfx_end(&fx,fb);
void fx_end() {
postfx_end(&fx);
}
int fx_enabled(int pass) {
return postfx_enabled(&fx, pass);

View File

@ -3097,7 +3097,7 @@ API int fx_load(const char *file);
API int fx_load_from_mem(const char *nameid, const char *content);
API void fx_begin();
API void fx_begin_res(int w, int h);
API void fx_end(handle fb);
API void fx_end();
API void fx_enable(int pass, int enabled);
API int fx_enabled(int pass);
API void fx_enable_all(int enabled);

View File

@ -80,7 +80,7 @@ int main() {
model_render(girl, cam.proj, cam.view, girl.pivot, 0);
// post-fxs end here
fx_end(0);
fx_end();
gizmo(&pos, &rot, &sca);
model_render_skeleton(girl, girl.pivot);

View File

@ -1772,7 +1772,7 @@ int main() {
editor_obj_call0(obj, fn_draw);
}
fx_end(0);
fx_end();
// draw gizmos, aabbs, markers, etc
for each_set_ptr(editor_selection, void*, o) {

View File

@ -133,7 +133,7 @@ __declspec(dllexport) int plug_tick(asset_t *f) {
ddraw_grid(0);
ddraw_flush();
model_render(models[s->model], cam.proj, cam.view, models[s->model].pivot, 0);
fx_end(s->fb);
fx_end();
// fbo_bind(s->fb);
// fullscreen_quad_rgb(s->tex, 1.0);

View File

@ -115,11 +115,11 @@ int main() {
}
ui_panel_end();
static bool show_main_window = 1;
if ( ui_window("Workbench", &show_main_window) ) {
ui_label("v4.games");
}
ui_window_end();
// static bool show_main_window = 1;
// if ( ui_window("Workbench", &show_main_window) ) {
// ui_label("v4.games");
// }
// ui_window_end();
for (int i=0; i<array_count(assets); i++) {
asset_t *f = (assets+i);