#include "shaders/blitblur.h"
#include "shaders/blitcolour.h"
-#if 0
-#include "shaders/standard.h"
-#include "shaders/vblend.h"
-#endif
-
-VG_STATIC void render_water_texture( world_instance *world, camera *cam,
- int layer_depth );
-VG_STATIC void render_water_surface( world_instance *world, camera *cam );
-VG_STATIC void render_world( world_instance *world, camera *cam,
- int layer_depth );
-VG_STATIC void render_world_depth( world_instance *world, camera *cam );
-
+#define WORKSHOP_PREVIEW_WIDTH 504
+#define WORKSHOP_PREVIEW_HEIGHT 336
#ifndef RENDER_H
#define RENDER_H
framebuffer *fb_main,
*fb_water_reflection,
- *fb_water_beneath;
+ *fb_water_beneath,
+ *fb_workshop_preview;
int ready;
float view_render_scale,
enum framebuffer_attachment_type{
k_framebuffer_attachment_type_none,
- k_framebuffer_attachment_type_colour,
- k_framebuffer_attachment_type_renderbuffer
+ k_framebuffer_attachment_type_texture,
+ k_framebuffer_attachment_type_renderbuffer,
+ k_framebuffer_attachment_type_texture_depth
}
purpose;
.attachments =
{
{
- "colour", k_framebuffer_attachment_type_colour,
+ "colour", k_framebuffer_attachment_type_texture,
.internalformat = GL_RGB,
.format = GL_RGB,
.attachment = GL_COLOR_ATTACHMENT0
},
{
- "motion", k_framebuffer_attachment_type_colour,
+ "motion", k_framebuffer_attachment_type_texture,
.quality = k_framebuffer_quality_high_only,
.internalformat = GL_RG16F,
.internalformat = GL_DEPTH24_STENCIL8,
#else
- "depth_stencil", k_framebuffer_attachment_type_colour,
+ "depth_stencil", k_framebuffer_attachment_type_texture_depth,
.internalformat = GL_DEPTH24_STENCIL8,
.format = GL_DEPTH_STENCIL,
.type = GL_UNSIGNED_INT_24_8,
.attachments =
{
{
- "colour", k_framebuffer_attachment_type_colour,
+ "colour", k_framebuffer_attachment_type_texture,
.internalformat = GL_RGB,
.format = GL_RGB,
.type = GL_UNSIGNED_BYTE,
.attachments =
{
{
- "colour", k_framebuffer_attachment_type_colour,
+ "colour", k_framebuffer_attachment_type_texture,
.internalformat = GL_RED,
.format = GL_RED,
.type = GL_UNSIGNED_BYTE,
.attachment = GL_DEPTH_STENCIL_ATTACHMENT
}
}
+ },
+ {
+ "workshop_preview",
+ .link = &gpipeline.fb_workshop_preview,
+ .resolution_div = 0,
+ .fixed_w = WORKSHOP_PREVIEW_WIDTH, .fixed_h = WORKSHOP_PREVIEW_HEIGHT,
+ .attachments =
+ {
+ {
+ "colour", k_framebuffer_attachment_type_texture,
+ .internalformat = GL_RGB,
+ .format = GL_RGB,
+ .type = GL_UNSIGNED_BYTE,
+ .attachment = GL_COLOR_ATTACHMENT0
+ },
+ {
+ "depth_stencil", k_framebuffer_attachment_type_renderbuffer,
+ .internalformat = GL_DEPTH24_STENCIL8,
+ .attachment = GL_DEPTH_STENCIL_ATTACHMENT
+ }
+ }
}
};
{
struct framebuffer_attachment *at = &fb->attachments[attachment];
- if( at->purpose != k_framebuffer_attachment_type_colour ){
- vg_fatal_exit_loop( "illegal operation: bind non-colour framebuffer"
+ if( (at->purpose != k_framebuffer_attachment_type_texture) &&
+ (at->purpose != k_framebuffer_attachment_type_texture_depth) )
+ {
+ vg_fatal_error( "illegal operation: bind non-texture framebuffer"
" attachment to texture slot" );
}
glBindRenderbuffer( GL_RENDERBUFFER, a->id );
glRenderbufferStorage( GL_RENDERBUFFER, a->internalformat, rx, ry );
}
- else if( a->purpose == k_framebuffer_attachment_type_colour ){
+ else if( a->purpose == k_framebuffer_attachment_type_texture ||
+ a->purpose == k_framebuffer_attachment_type_texture_depth )
+ {
glBindTexture( GL_TEXTURE_2D, a->id );
glTexImage2D( GL_TEXTURE_2D, 0, a->internalformat, rx, ry,
0, a->format, a->type, NULL );
GL_DEPTH_STENCIL_ATTACHMENT,
GL_RENDERBUFFER, attachment->id );
}
- else if( attachment->purpose == k_framebuffer_attachment_type_colour ){
+ else if( attachment->purpose == k_framebuffer_attachment_type_texture ||
+ attachment->purpose == k_framebuffer_attachment_type_texture_depth )
+ {
glGenTextures( 1, &attachment->id );
render_fb_allocate_texture( fb, attachment );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glFramebufferTexture2D( GL_FRAMEBUFFER, attachment->attachment,
GL_TEXTURE_2D, attachment->id, 0 );
- colour_attachments[ colour_count ++ ] = attachment->attachment;
+ if( attachment->purpose == k_framebuffer_attachment_type_texture )
+ colour_attachments[ colour_count ++ ] = attachment->attachment;
}
}
vg_error( " status: Generic Error" );
vg_info( "}\n" );
- vg_fatal_exit_loop( "Incomplete framebuffer (see logs)" );
+ vg_fatal_error( "Incomplete framebuffer (see logs)" );
}
}
VG_STATIC int render_framebuffer_control( int argc, char const *argv[] );
VG_STATIC void render_framebuffer_poll( int argc, char const *argv[] );
-VG_STATIC void render_init_fs_quad(void)
+
+VG_STATIC void async_render_init( void *payload, u32 size )
{
- vg_info( "[render] Allocate quad\n" );
+ /*
+ * Complete Framebuffers
+ */
+ for( int i=0; i<vg_list_size(framebuffers); i++ ){
+ struct framebuffer *fb = &framebuffers[i];
+ render_fb_allocate( fb );
+ }
+
+ f32 rh = 0x1p-4f, ih = 0.3f;
float quad[] = {
- 0.00f,0.00f, 1.00f,1.00f, 0.00f,1.00f,
- 0.00f,0.00f, 1.00f,0.00f, 1.00f,1.00f,
+ 0.00f,0.00f, 1.00f,1.00f, 0.00f,1.00f, /* fsquad */
+ 0.00f,0.00f, 1.00f,0.00f, 1.00f,1.00f,
- 0.20f,0.00f, 0.80f,1.00f, 0.20f,1.00f,
- 0.20f,0.00f, 0.80f,0.00f, 0.80f,1.00f,
+ 0.00f,0.00f, 1.00f,rh, 0.00f,rh, /* fsquad1 */
+ 0.00f,0.00f, 1.00f,0.00f, 1.00f,rh,
/* 9x9 debug grid */
/* row0 */
0.30f,0.60f, 0.60f,0.60f, 0.60f,0.90f,
0.60f,0.60f, 0.90f,0.90f, 0.60f,0.90f,
0.60f,0.60f, 0.90f,0.60f, 0.90f,0.90f,
+
+ 0.00f,ih, 1.00f,ih+rh, 0.00f,ih+rh, /* fsquad2 */
+ 0.00f,ih, 1.00f,ih, 1.00f,ih+rh,
};
vg_console_reg_cmd( "fb", render_framebuffer_control,
render_framebuffer_poll );
+ vg_console_reg_var( "render_scale", &gpipeline.view_render_scale,
+ k_var_dtype_f32, VG_VAR_PERSISTENT );
glGenVertexArrays( 1, &gpipeline.fsquad.vao );
glGenBuffers( 1, &gpipeline.fsquad.vbo );
glEnableVertexAttribArray( 0 );
VG_CHECK_GL_ERR();
+
+ glBindFramebuffer( GL_FRAMEBUFFER, 0 );
+ gpipeline.ready = 1;
}
VG_STATIC void render_init(void)
shader_blitblur_register();
shader_blitcolour_register();
- vg_acquire_thread_sync();
- {
- /*
- * Complete Framebuffers
- */
- for( int i=0; i<vg_list_size(framebuffers); i++ ){
- struct framebuffer *fb = &framebuffers[i];
- render_fb_allocate( fb );
- }
-
- render_init_fs_quad();
-
- glBindFramebuffer( GL_FRAMEBUFFER, 0 );
- gpipeline.ready = 1;
- }
-
- vg_release_thread_sync();
+ vg_async_call( async_render_init, NULL, 0 );
}
/*
glDrawArrays( GL_TRIANGLES, 6, 6 );
}
+VG_STATIC void render_fsquad2(void)
+{
+ glBindVertexArray( gpipeline.fsquad.vao );
+ glDrawArrays( GL_TRIANGLES, 66,6 );
+}
+
/*
* Call this inside the UI function
*/
VG_STATIC void render_view_framebuffer_ui(void)
{
+#if 0
int viewing_count = 0;
glBindVertexArray( gpipeline.fsquad.vao );
viewing_count ++;
}
}
+#endif
}
VG_STATIC void render_framebuffer_show( struct framebuffer *fb,