-static void plane_clip_projection( m4x4f mat, v4f plane )
-{
- v4f c =
- {
- (vg_signf(plane[0]) + mat[2][0]) / mat[0][0],
- (vg_signf(plane[1]) + mat[2][1]) / mat[1][1],
- -1.0f,
- (1.0f + mat[2][2]) / mat[3][2]
- };
-
- v4_muls( plane, 2.0f / v4_dot(plane,c), c );
-
- mat[0][2] = c[0];
- mat[1][2] = c[1];
- mat[2][2] = c[2] + 1.0f;
- mat[3][2] = c[3];
-}
-
-static void pipeline_projection( m4x4f mat, float nearz, float farz )
-{
- m4x4_projection( mat,
- gpipeline.fov,
- (float)vg_window_x / (float)vg_window_y,
- nearz, farz );
-}
-
-static void fb_use( struct framebuffer *fb )
-{
- if( !fb )
- {
- glBindFramebuffer( GL_FRAMEBUFFER, 0 );
- glViewport( 0, 0, vg_window_x, vg_window_y );
- }
- else
- {
- glBindFramebuffer( GL_FRAMEBUFFER, fb->fb );
- glViewport( 0, 0, vg_window_x / fb->div, vg_window_y / fb->div );
- }
-}
-
-static void fb_init( struct framebuffer *fb )
-{
- i32 ix = vg_window_x / fb->div,
- iy = vg_window_y / fb->div;
-
- glGenFramebuffers( 1, &fb->fb );
- glBindFramebuffer( GL_FRAMEBUFFER, fb->fb );
-
- glGenTextures( 1, &fb->colour );
- glBindTexture( GL_TEXTURE_2D, fb->colour );
- glTexImage2D( GL_TEXTURE_2D, 0, fb->format, ix, iy,
- 0, fb->format, GL_UNSIGNED_BYTE, NULL);
-
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
- GL_TEXTURE_2D, fb->colour, 0);
-
- glGenRenderbuffers( 1, &fb->rb );
- glBindRenderbuffer( GL_RENDERBUFFER, fb->rb );
- glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, ix, iy );
-
- glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
- GL_RENDERBUFFER, fb->rb );
-}
-
-static void fb_bindtex( struct framebuffer *fb, int texture )
-{
- glActiveTexture( GL_TEXTURE0 + texture );
- glBindTexture( GL_TEXTURE_2D, fb->colour );
-}
-
-static void fb_resize( struct framebuffer *fb )
-{
- i32 ix = vg_window_x / fb->div,
- iy = vg_window_y / fb->div;
-
- glBindTexture( GL_TEXTURE_2D, fb->colour );
- glTexImage2D( GL_TEXTURE_2D, 0, fb->format, ix, iy, 0,
- fb->format, GL_UNSIGNED_BYTE, NULL );
-
- glBindRenderbuffer( GL_RENDERBUFFER, fb->rb );
- glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, ix, iy );
-}
-
-static void render_fb_resize(void)
-{
- glBindTexture( GL_TEXTURE_2D, gpipeline.rgb_background );
- glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, vg_window_x, vg_window_y, 0,
- GL_RGB, GL_UNSIGNED_BYTE, NULL );
-}
-
-static void render_init(void)