X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=scene.h;h=a4f6bd1f005e02cfcc221a7d426df3344eebd6bb;hb=b9dedb4dd2a1e94ae76a3986716ee3c57e568213;hp=8754d00985ba6f1a22af9a42b423bbf736c6b790;hpb=d045af680c6b8ca267a7aded69e2e510e659d2ab;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/scene.h b/scene.h index 8754d00..a4f6bd1 100644 --- a/scene.h +++ b/scene.h @@ -28,10 +28,6 @@ struct scene mdl_submesh submesh; }; -#if 0 -GLuint tex_dual_noise; -#endif - static void scene_init( scene *pscene ) { pscene->verts = NULL; @@ -45,74 +41,19 @@ static void scene_init( scene *pscene ) v3_fill( pscene->bbx[0], 999999.9f ); v3_fill( pscene->bbx[1], -999999.9f ); - -#if 0 - static int noise_ready = 0; - if( !noise_ready ) - { - noise_ready = 1; - - u8 *buf = malloc( 256*256*2 ); - - for( int i=0; i<256*256; i++ ) - { - u8 val = rand()&0xff; - buf[i*2] = val; - } - - for( int y=0; y<256; y++ ) - { - for( int x=0; x<256; x++ ) - { - u8 *pr = &buf[(y*256+x)*2], - *pg = &buf[(((y+17)&0xff)*256+((x+37)&0xff))*2+1]; - *pg = *pr; - } - } - - /* TODO: This texture should be delted somewhere */ - glGenTextures( 1, &tex_dual_noise ); - glBindTexture( GL_TEXTURE_2D, tex_dual_noise ); - glTexImage2D( GL_TEXTURE_2D, 0, GL_RG, 256, 256, 0, GL_RG, - GL_UNSIGNED_BYTE, buf ); - - vg_tex2d_linear(); - vg_tex2d_repeat(); - - free( buf ); - } -#endif -} - -static void *buffer_reserve( void *buffer, u32 count, u32 *cap, u32 amount, - size_t emsize ) -{ - if( count+amount > *cap ) - { - *cap = VG_MAX( (*cap)*2, (*cap)+amount ); - - return realloc( buffer, (*cap) * emsize ); - } - - return buffer; -} - -static void *buffer_fix( void *buffer, u32 count, u32 *cap, size_t emsize ) -{ - *cap = count; - return realloc( buffer, (*cap) * emsize ); } /* * Append a model into the scene with a given transform */ static void scene_add_submesh( scene *pscene, mdl_header *mdl, - mdl_submesh *sm, m4x3f transform ) + mdl_submesh *sm, m4x3f transform ) { - pscene->verts = buffer_reserve( pscene->verts, pscene->vertex_count, - &pscene->vertex_cap, sm->vertex_count, sizeof(mdl_vert) ); + pscene->verts = buffer_reserve( pscene->verts, pscene->vertex_count, + &pscene->vertex_cap, sm->vertex_count, sizeof(mdl_vert) ); + pscene->indices = buffer_reserve( pscene->indices, pscene->indice_count, - &pscene->indice_cap, sm->indice_count, sizeof(u32) ); + &pscene->indice_cap, sm->indice_count, sizeof(u32) ); m3x3f normal_matrix; m3x3_copy( transform, normal_matrix ); @@ -160,7 +101,7 @@ static void scene_add_submesh( scene *pscene, mdl_header *mdl, static void scene_push_tri( scene *pscene, u32 tri[3] ) { pscene->indices = buffer_reserve( pscene->indices, pscene->indice_count, - &pscene->indice_cap, 3, sizeof(u32) ); + &pscene->indice_cap, 3, sizeof(u32) ); u32 *dst = &pscene->indices[pscene->indice_count]; dst[0] = tri[0]; @@ -173,8 +114,7 @@ static void scene_push_tri( scene *pscene, u32 tri[3] ) static void scene_push_vert( scene *pscene, mdl_vert *v ) { pscene->verts = buffer_reserve( pscene->verts, pscene->vertex_count, - &pscene->vertex_cap, 1, sizeof(mdl_vert) ); - + &pscene->vertex_cap, 1, sizeof(mdl_vert) ); pscene->verts[pscene->vertex_count ++] = *v; } @@ -202,8 +142,8 @@ static void scene_fix( scene *pscene ) static void scene_upload( scene *pscene ) { mesh_upload( &pscene->mesh, - pscene->verts, pscene->vertex_count, - pscene->indices, pscene->indice_count ); + pscene->verts, pscene->vertex_count, + pscene->indices, pscene->indice_count ); vg_info( "Scene upload\n" ); vg_info( " indices:%u\n", pscene->indice_count ); @@ -222,18 +162,13 @@ static void scene_draw( scene *pscene ) static void scene_free_offline_buffers( scene *pscene ) { - free( pscene->verts ); - free( pscene->indices ); + vg_free( pscene->verts ); + vg_free( pscene->indices ); } static void scene_free( scene *pscene ) { scene_free_offline_buffers( pscene ); - /* TODO: bvh */ -} - -static void scene_register(void) -{ } /*