Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

switched back to vertex struct

  • Loading branch information...
commit 02a37a0e46f195f5a46404747d659d26490e6c32 1 parent 9c42574
@Dav1dde authored
View
31 brala/dine/builder/builder.d
@@ -18,19 +18,10 @@ mixin template BlockBuilder() {
float u, float v, float u_biome, float v_biome)
in { assert(elements+1 <= buffer_length, "not enough allocated memory for tessellator"); }
body {
- buffer[elements++] = x;
- buffer[elements++] = y;
- buffer[elements++] = z;
- buffer[elements++] = nx;
- buffer[elements++] = ny;
- buffer[elements++] = nz;
- buffer[elements++] = u;
- buffer[elements++] = v;
- buffer[elements++] = u_biome;
- buffer[elements++] = v_biome;
+ buffer[elements++] = Vertex(x, y, z, nx, ny, nz, u, v, u_biome, v_biome);
}
- void add_template_vertices(const ref float[] vertices,
+ void add_template_vertices(const ref Vertex[] vertices,
float x_offset, float y_offset, float z_offset,
float u_biome, float v_biome)
in { assert(elements+vertices.length <= buffer_length, "not enough allocated memory for tessellator"); }
@@ -39,16 +30,16 @@ mixin template BlockBuilder() {
size_t end = elements+vertices.length;
for(; elements < end;) {
- buffer[elements++] += x_offset;
- buffer[elements++] += y_offset;
- buffer[elements++] += z_offset;
- elements += 5;
- buffer[elements++] += u_biome;
- buffer[elements++] += v_biome;
+ Vertex* vertex = &buffer[elements++];
+ vertex.x += x_offset;
+ vertex.y += y_offset;
+ vertex.z += z_offset;
+ vertex.u_biome += u_biome;
+ vertex.v_biome += v_biome;
}
}
- void add_vertices(const ref float[] vertices)
+ void add_vertices(const ref Vertex[] vertices)
in { assert(elements+vertices.length <= buffer_length, "not enough allocated memory for tesselator"); }
body {
buffer[elements..(elements+(vertices.length))] = vertices;
@@ -58,7 +49,7 @@ mixin template BlockBuilder() {
// blocks
void grass_block(Side s)(const ref Block block, const ref BiomeData biome_data,
float x_offset, float y_offset, float z_offset) {
- float[] vertices = get_vertices!(s)(block.id);
+ Vertex[] vertices = get_vertices!(s)(block.id);
add_template_vertices(vertices, x_offset, y_offset, z_offset,
biome_data.grass_uv.field);
@@ -66,7 +57,7 @@ mixin template BlockBuilder() {
void leave_block(Side s)(const ref Block block, const ref BiomeData biome_data,
float x_offset, float y_offset, float z_offset) {
- float[] vertices = get_vertices!(s)(block.id);
+ Vertex[] vertices = get_vertices!(s)(block.id);
add_template_vertices(vertices, x_offset, y_offset, z_offset,
biome_data.leave_uv.field);
View
12 brala/dine/builder/tessellator.d
@@ -36,30 +36,30 @@ align(1) struct Vertex {
float nz;
float u_terrain;
float v_terrain;
- float u_palette;
- float v_palette;
+ float u_biome;
+ float v_biome;
}
struct Tessellator {
World world;
- float* buffer;
+ Vertex* buffer;
size_t buffer_length;
uint elements = 0;
mixin BlockBuilder!();
- this(World world, ref float* buffer, ref size_t buffer_length) {
+ this(World world, ref Vertex* buffer, ref size_t buffer_length) {
this.world = world;
this.buffer = buffer;
this.buffer_length = buffer_length;
}
void realloc_buffer(size_t interval) {
- buffer_length += interval*float.sizeof;
- buffer = cast(float*)realloc(buffer, buffer_length);
+ buffer_length += interval*Vertex.sizeof;
+ buffer = cast(Vertex*)realloc(buffer, buffer_length);
}
void realloc_buffer_if_needed(size_t interval) {
View
24 brala/dine/builder/vertices.d
@@ -83,7 +83,7 @@ immutable CubeSideData[6] CUBE_VERTICES = [
[0.0f, -1.0f, 0.0f] }
];
-float[] simple_block(Side side, MCTextureSlice texture_slice) {
+Vertex[] simple_block(Side side, MCTextureSlice texture_slice) {
CubeSideData cbsd = CUBE_VERTICES[side];
float[3][6] positions = to_triangles(cbsd.positions);
@@ -92,26 +92,26 @@ float[] simple_block(Side side, MCTextureSlice texture_slice) {
// vertex normal texcoords palette
Vertex[] data;
- /*foreach(i; 0..6) {
+ foreach(i; 0..6) {
data ~= Vertex(positions[i][0], positions[i][1], positions[i][2],
cbsd.normal[0], cbsd.normal[1], cbsd.normal[2],
texcoords[i][0], texcoords[i][1],
0, 0);
}
- return data;*/
-
+ return data;
+ /*
return join([positions[0], cbsd.normal, texcoords[0], [0.0f, 0.0f],
positions[1], cbsd.normal, texcoords[1], [0.0f, 0.0f],
positions[2], cbsd.normal, texcoords[2], [0.0f, 0.0f],
positions[3], cbsd.normal, texcoords[3], [0.0f, 0.0f],
positions[4], cbsd.normal, texcoords[4], [0.0f, 0.0f],
- positions[5], cbsd.normal, texcoords[5], [0.0f, 0.0f]]);
+ positions[5], cbsd.normal, texcoords[5], [0.0f, 0.0f]]);*/
}
private alias MCTextureSlice t;
-float[][] BLOCK_VERTICES_LEFT = [
+Vertex[][] BLOCK_VERTICES_LEFT = [
[], // air
simple_block(Side.LEFT, t(1, 1)), // stone
simple_block(Side.LEFT, t(3, 1)), // grass
@@ -243,7 +243,7 @@ float[][] BLOCK_VERTICES_LEFT = [
[]
];
-float[][] BLOCK_VERTICES_RIGHT = [
+Vertex[][] BLOCK_VERTICES_RIGHT = [
[], // air
simple_block(Side.RIGHT, t(1, 1)), // stone
simple_block(Side.RIGHT, t(3, 1)), // grass
@@ -375,7 +375,7 @@ float[][] BLOCK_VERTICES_RIGHT = [
[]
];
-float[][] BLOCK_VERTICES_NEAR = [
+Vertex[][] BLOCK_VERTICES_NEAR = [
[], // air
simple_block(Side.NEAR, t(1, 1)), // stone
simple_block(Side.NEAR, t(3, 1)), // grass
@@ -507,7 +507,7 @@ float[][] BLOCK_VERTICES_NEAR = [
[]
];
-float[][] BLOCK_VERTICES_FAR = [
+Vertex[][] BLOCK_VERTICES_FAR = [
[], // air
simple_block(Side.FAR, t(1, 1)), // stone
simple_block(Side.FAR, t(3, 1)), // grass
@@ -639,7 +639,7 @@ float[][] BLOCK_VERTICES_FAR = [
[]
];
-float[][] BLOCK_VERTICES_TOP = [
+Vertex[][] BLOCK_VERTICES_TOP = [
[], // air
simple_block(Side.TOP, t(1, 1)), // stone
simple_block(Side.TOP, t(0, 1)), // grass
@@ -771,7 +771,7 @@ float[][] BLOCK_VERTICES_TOP = [
[]
];
-float[][] BLOCK_VERTICES_BOTTOM = [
+Vertex[][] BLOCK_VERTICES_BOTTOM = [
[], // air
simple_block(Side.BOTTOM, t(1, 1)), // stone
simple_block(Side.BOTTOM, t(2, 1)), // grass
@@ -903,7 +903,7 @@ float[][] BLOCK_VERTICES_BOTTOM = [
[]
];
-ref float[] get_vertices(Side side, T)(T index) if(isIntegral!T) {
+ref Vertex[] get_vertices(Side side, T)(T index) if(isIntegral!T) {
static if(side == Side.LEFT) {
return BLOCK_VERTICES_LEFT[index];
} else static if(side == Side.RIGHT) {
View
14 brala/dine/world.d
@@ -17,12 +17,12 @@ private {
private const Block AIR_BLOCK = Block(0);
class World {
- static float* tessellate_buffer;
+ static Vertex* tessellate_buffer;
static size_t tessellate_buffer_length;
static this() {
- tessellate_buffer_length = width*height*depth*20; // this value is the result of testing!
- tessellate_buffer = cast(float*)malloc(tessellate_buffer_length*float.sizeof);
+ tessellate_buffer_length = width*height*depth*5; // this value is the result of testing!
+ tessellate_buffer = cast(Vertex*)malloc(tessellate_buffer_length*Vertex.sizeof);
}
static ~this() {
@@ -162,7 +162,7 @@ class World {
// fills the vbo with the chunk content
// original version from florian boesch - http://codeflow.org/
- void tessellate(Chunk chunk, vec3i chunkc, ref float* v, ref size_t length, bool force=false) {
+ void tessellate(Chunk chunk, vec3i chunkc, ref Vertex* v, ref size_t length, bool force=false) {
Tessellator tessellator = Tessellator(this, v, length);
if(chunk.vbo is null) {
@@ -250,8 +250,8 @@ class World {
}
}
- //chunk.vbo_vcount = tessellator.elements * __traits(allMembers, Vertex).length;
- chunk.vbo_vcount = tessellator.elements / 10;
+ chunk.vbo_vcount = tessellator.elements * __traits(allMembers, Vertex).length;
+ //chunk.vbo_vcount = tessellator.elements / 10;
tessellator.fill_vbo(chunk.vbo);
chunk.dirty = false;
@@ -272,7 +272,7 @@ class World {
chunk.vbo.bind(position, GL_FLOAT, 3, 0, stride);
chunk.vbo.bind(normal, GL_FLOAT, 3, Vertex().nx.offsetof, stride);
chunk.vbo.bind(texcoord, GL_FLOAT, 2, Vertex().u_terrain.offsetof, stride);
- chunk.vbo.bind(palettecoord, GL_FLOAT, 2, Vertex().u_palette.offsetof, stride);
+ chunk.vbo.bind(palettecoord, GL_FLOAT, 2, Vertex().u_biome.offsetof, stride);

This?

@Dav1dde Owner
Dav1dde added a note

.u_platte was the old name, only thing changed is the name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
}
void draw(BraLaEngine engine) {
@Dav1dde

.u_platte was the old name, only thing changed is the name.

Please sign in to comment.
Something went wrong with that request. Please try again.