various cleanup; vheight works (only one path tested)

This commit is contained in:
Sean Barrett
2015-02-22 17:42:46 -08:00
parent 1d18b23ea1
commit f9c24c20fc
5 changed files with 167 additions and 103 deletions

View File

@ -286,7 +286,6 @@ unsigned char minecraft_info[256][7] =
};
unsigned char minecraft_tex1_for_blocktype[256][6];
unsigned char minecraft_trans_for_blocktype[256];
unsigned char effective_blocktype[256];
unsigned char effective_block_add[256];
unsigned char minecraft_color_for_blocktype[256][6];
@ -551,6 +550,8 @@ void build_chunk(int chunk_x, int chunk_y, fast_chunk *fc_table[4][4], raw_mesh
int a,b,z;
stbvox_input_description *map;
//unsigned char vheight[34][34][18];
assert((chunk_x & 1) == 0);
assert((chunk_y & 1) == 0);
@ -596,6 +597,24 @@ void build_chunk(int chunk_x, int chunk_y, fast_chunk *fc_table[4][4], raw_mesh
map->blocktype = &rm->sv_blocktype[1][1][1-z]; // specify location of 0,0,0 so that accessing z0..z1 gets right data
map->lighting = &rm->sv_lighting[1][1][1-z];
#if 0
// hacky test of vheight
for (a=0; a < 34; ++a) {
for (b=0; b < 34; ++b) {
int c;
for (c=0; c < 17; ++c) {
if (rm->sv_blocktype[a][b][c] != 0 && rm->sv_blocktype[a][b][c+1] == 0) {
// topmost block
rm->sv_blocktype[a][b][c] = 168;
vheight[a][b][c] = rand() & 255;
}
}
vheight[a][b][c] = STBVOX_MAKE_VHEIGHT(2,2,2,2); // flat top
}
}
map->vheight = &vheight[1][1][1-z];
#endif
{
stbvox_set_input_range(&rm->mm, 0,0,z0, 32,32,z1);
stbvox_set_default_mesh(&rm->mm, 0);
@ -680,7 +699,6 @@ void mesh_init(void)
for (i=0; i < 256; ++i) {
memcpy(minecraft_tex1_for_blocktype[i], minecraft_info[i]+1, 6);
minecraft_trans_for_blocktype[i] = (minecraft_info[i][0] != C_solid && minecraft_info[i][0] != C_water);
effective_blocktype[i] = (minecraft_info[i][0] == C_empty ? 0 : i);
minecraft_geom_for_blocktype[i] = geom_map[minecraft_info[i][0]];
}
@ -708,6 +726,17 @@ void mesh_init(void)
minecraft_color_for_blocktype[11][i] = 63; // emissive
}
#if 0 // vheight test
effective_blocktype[168] = 168;
minecraft_tex1_for_blocktype[168][0] = 1;
minecraft_tex1_for_blocktype[168][1] = 1;
minecraft_tex1_for_blocktype[168][2] = 1;
minecraft_tex1_for_blocktype[168][3] = 1;
minecraft_tex1_for_blocktype[168][4] = 1;
minecraft_tex1_for_blocktype[168][5] = 1;
minecraft_geom_for_blocktype[168] = STBVOX_GEOM_floor_vheight_02;
#endif
remap[53] = 1;
remap[67] = 2;
remap[108] = 3;

View File

@ -10,8 +10,6 @@
#include "stb_image.h"
#include "stb.h"
// @TODO: need to unload LRU compressed chunks
#define NUM_CHUNKS_PER_REGION 32 // only on one axis
#define NUM_CHUNKS_PER_REGION_LOG2 5
@ -523,6 +521,7 @@ static decoded_buffer decoded_buffers[MAX_DECODED_CHUNK_Z][MAX_DECODED_CHUNK_X];
void lock_chunk_get_mutex(void);
void unlock_chunk_get_mutex(void);
#ifdef FAST_CHUNK
fast_chunk *get_decoded_fastchunk_uncached(int chunk_x, int chunk_z)
{
unsigned char *decoded;
@ -592,7 +591,9 @@ fast_chunk *get_decoded_fastchunk(int chunk_x, int chunk_z)
decoded_buffer *db = get_decoded_buffer(chunk_x, chunk_z);
return db->fc;
}
#endif
#ifndef FAST_CHUNK
chunk *get_decoded_chunk_raw(int chunk_x, int chunk_z)
{
unsigned char *decoded;
@ -628,17 +629,4 @@ chunk *get_decoded_chunk(int chunk_x, int chunk_z)
decoded_chunks[chunk_z&(MAX_DECODED_CHUNK_Z-1)][chunk_x&(MAX_DECODED_CHUNK_X-1)] = c;
return c;
}
#if 0
chunk *map[257][257];
int main(int argc, char **argv)
{
int i,j;
for (j= -32; j <= 32; ++j)
for (i= -32; i <= 32; ++i)
map[j+128][i+128] = get_decoded_chunk(i,j);
return 0;
}
#endif

View File

@ -1,5 +1,6 @@
// This file takes renders vertex buffers and manages
// threads that invoke mesh building (found in cave_mesher.c)
// This file renders vertex buffers, converts raw meshes
// to GL meshes, and manages threads that do the raw-mesh
// building (found in cave_mesher.c)
#include "stb_voxel_render.h"
@ -14,11 +15,14 @@
#include "sdl.h"
#include "sdl_thread.h"
#include <math.h>
#include <assert.h>
// currently no dynamic way to set mesh cache size or view distance
//#define SHORTVIEW
// renderer maintains GL meshes, draws them
stbvox_mesh_maker g_mesh_maker;
GLuint main_prog;
@ -182,7 +186,7 @@ GLint tablei[2];
void setup_uniforms(float pos[3])
{
int i,j;
for (i=0; i < STBVOX_UNIFORM__count; ++i) {
for (i=0; i < STBVOX_UNIFORM_count; ++i) {
stbvox_uniform_info *ui = stbvox_get_uniform_info(&g_mesh_maker, i);
uniform_loc[i] = -1;
@ -663,6 +667,7 @@ static void matd_mul(double out[4][4], double src1[4][4], double src2[4][4])
}
}
// https://fgiesen.wordpress.com/2012/08/31/frustum-planes-from-the-projection-matrix/
static void compute_frustum(void)
{
int i;
@ -684,6 +689,7 @@ static int test_plane(plane *p, float x0, float y0, float z0, float x1, float y1
{
// return false if the box is entirely behind the plane
float d=0;
assert(x0 <= x1 && y0 <= y1 && z0 <= z1);
if (p->x > 0) d += x1*p->x; else d += x0*p->x;
if (p->y > 0) d += y1*p->y; else d += y0*p->y;
if (p->z > 0) d += z1*p->z; else d += z0*p->z;

View File

@ -6,27 +6,7 @@ GLEXT(TexSubImage3D,TEXSUBIMAGE3D)
GLEXT(GenerateMipmap,GENERATEMIPMAP)
GLARB(DebugMessageCallback,DEBUGMESSAGECALLBACK)
//GLARB(DeleteObject,DELETEOBJECT)
//GLARB(CreateProgramObject,CREATEPROGRAMOBJECT)
//GLARB(UseProgramObject,USEPROGRAMOBJECT)
//GLARB(CreateShaderObject,CREATESHADEROBJECT)
//GLARB(ShaderSource,SHADERSOURCE)
//GLARB(CompileShader,COMPILESHADER)
//GLARB(GetInfoLog,GETINFOLOG)
//GLARB(AttachObject,ATTACHOBJECT)
//GLARB(LinkProgram,LINKPROGRAM)
//GLARB(GetObjectParameteriv,GETOBJECTPARAMETERIV)
//GLARB(GetUniformLocation,GETUNIFORMLOCATION)
////GLARB(Uniform1i,UNIFORM1I)
//GLARB(Uniform1f,UNIFORM1F)
//GLARB(Uniform4f,UNIFORM4F)
//GLARB(Uniform2fv,UNIFORM2FV)
//GLARB(Uniform3fv,UNIFORM3FV)
//GLARB(Uniform4fv,UNIFORM4FV)
//GLARB(VertexAttribPointer,VERTEXATTRIBPOINTER)
GLCORE(VertexAttribIPointer,VERTEXATTRIBIPOINTER)
//GLARB(EnableVertexAttribArray,ENABLEVERTEXATTRIBARRAY)
//GLARB(DisableVertexAttribArray,DISABLEVERTEXATTRIBARRAY)
GLEXT(BindFramebuffer,BINDFRAMEBUFFER)
GLEXT(DeleteFramebuffers,DELETEFRAMEBUFFERS)