mdl_submesh submesh;
};
-#if 0
-GLuint tex_dual_noise;
-#endif
-
static void scene_init( scene *pscene )
{
pscene->verts = NULL;
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 );
m4x3_mulv( transform, src->co, pvert->co );
m3x3_mulv( normal_matrix, src->norm, pvert->norm );
-
- v4_copy( src->colour, pvert->colour );
+
+ pvert->colour[0] = src->colour[0];
+ pvert->colour[1] = src->colour[1];
+ pvert->colour[2] = src->colour[2];
+ pvert->colour[3] = src->colour[3];
v2_copy( src->uv, pvert->uv );
}
pscene->indice_count += sm->indice_count;
}
+/*
+ * One by one adders for simplified access (mostly procedural stuff)
+ */
+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) );
+
+ u32 *dst = &pscene->indices[pscene->indice_count];
+ dst[0] = tri[0];
+ dst[1] = tri[1];
+ dst[2] = tri[2];
+
+ pscene->indice_count += 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->verts[pscene->vertex_count ++] = *v;
+}
+
static void scene_copy_slice( scene *pscene, mdl_submesh *sm )
{
sm->indice_start = pscene->submesh.indice_start;
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 );
mesh_drawn( 0, pscene->indice_count );
}
-static void scene_free( scene *pscene )
+static void scene_free_offline_buffers( scene *pscene )
{
- free( pscene->verts );
- free( pscene->indices );
-
- /* TODO: bvh */
+ vg_free( pscene->verts );
+ vg_free( pscene->indices );
}
-static void scene_register(void)
+static void scene_free( scene *pscene )
{
+ scene_free_offline_buffers( pscene );
}
/*