Skip to content
This repository
Browse code

switched back to vertex struct

  • Loading branch information...
commit 02a37a0e46f195f5a46404747d659d26490e6c32 1 parent 9c42574
David Herberth authored
31  brala/dine/builder/builder.d
@@ -18,19 +18,10 @@ mixin template BlockBuilder() {
18 18
                     float u, float v, float u_biome, float v_biome)
19 19
         in { assert(elements+1 <= buffer_length, "not enough allocated memory for tessellator"); }
20 20
         body {
21  
-            buffer[elements++] = x;
22  
-            buffer[elements++] = y;
23  
-            buffer[elements++] = z;
24  
-            buffer[elements++] = nx;
25  
-            buffer[elements++] = ny;
26  
-            buffer[elements++] = nz;
27  
-            buffer[elements++] = u;
28  
-            buffer[elements++] = v;
29  
-            buffer[elements++] = u_biome;
30  
-            buffer[elements++] = v_biome;
  21
+            buffer[elements++] = Vertex(x, y, z, nx, ny, nz, u, v, u_biome, v_biome);
31 22
         }
32 23
 
33  
-    void add_template_vertices(const ref float[] vertices,
  24
+    void add_template_vertices(const ref Vertex[] vertices,
34 25
                                float x_offset, float y_offset, float z_offset,
35 26
                                float u_biome, float v_biome)
36 27
         in { assert(elements+vertices.length <= buffer_length, "not enough allocated memory for tessellator"); }
@@ -39,16 +30,16 @@ mixin template BlockBuilder() {
39 30
 
40 31
             size_t end = elements+vertices.length;
41 32
             for(; elements < end;) {
42  
-                buffer[elements++] += x_offset;
43  
-                buffer[elements++] += y_offset;
44  
-                buffer[elements++] += z_offset;
45  
-                elements += 5;
46  
-                buffer[elements++] += u_biome;
47  
-                buffer[elements++] += v_biome;
  33
+                Vertex* vertex = &buffer[elements++];
  34
+                vertex.x += x_offset;
  35
+                vertex.y += y_offset;
  36
+                vertex.z += z_offset;
  37
+                vertex.u_biome += u_biome;
  38
+                vertex.v_biome += v_biome;
48 39
             }
49 40
         }
50 41
 
51  
-    void add_vertices(const ref float[] vertices)
  42
+    void add_vertices(const ref Vertex[] vertices)
52 43
         in { assert(elements+vertices.length <= buffer_length, "not enough allocated memory for tesselator"); }
53 44
         body {
54 45
             buffer[elements..(elements+(vertices.length))] = vertices;
@@ -58,7 +49,7 @@ mixin template BlockBuilder() {
58 49
     // blocks
59 50
     void grass_block(Side s)(const ref Block block, const ref BiomeData biome_data,
60 51
                              float x_offset, float y_offset, float z_offset) {
61  
-        float[] vertices = get_vertices!(s)(block.id);
  52
+        Vertex[] vertices = get_vertices!(s)(block.id);
62 53
 
63 54
         add_template_vertices(vertices, x_offset, y_offset, z_offset,
64 55
                               biome_data.grass_uv.field);
@@ -66,7 +57,7 @@ mixin template BlockBuilder() {
66 57
         
67 58
     void leave_block(Side s)(const ref Block block, const ref BiomeData biome_data,
68 59
                              float x_offset, float y_offset, float z_offset) {
69  
-        float[] vertices = get_vertices!(s)(block.id);
  60
+        Vertex[] vertices = get_vertices!(s)(block.id);
70 61
 
71 62
         add_template_vertices(vertices, x_offset, y_offset, z_offset,
72 63
                               biome_data.leave_uv.field);
12  brala/dine/builder/tessellator.d
@@ -36,30 +36,30 @@ align(1) struct Vertex {
36 36
     float nz;
37 37
     float u_terrain;
38 38
     float v_terrain;
39  
-    float u_palette;
40  
-    float v_palette;
  39
+    float u_biome;
  40
+    float v_biome;
41 41
 }
42 42
 
43 43
 
44 44
 struct Tessellator {
45 45
     World world;
46 46
     
47  
-    float* buffer;
  47
+    Vertex* buffer;
48 48
     size_t buffer_length;
49 49
 
50 50
     uint elements = 0;
51 51
 
52 52
     mixin BlockBuilder!();
53 53
     
54  
-    this(World world, ref float* buffer, ref size_t buffer_length) {
  54
+    this(World world, ref Vertex* buffer, ref size_t buffer_length) {
55 55
         this.world = world;
56 56
         this.buffer = buffer;
57 57
         this.buffer_length = buffer_length;
58 58
     }
59 59
 
60 60
     void realloc_buffer(size_t interval) {
61  
-        buffer_length += interval*float.sizeof;
62  
-        buffer = cast(float*)realloc(buffer, buffer_length);
  61
+        buffer_length += interval*Vertex.sizeof;
  62
+        buffer = cast(Vertex*)realloc(buffer, buffer_length);
63 63
     }
64 64
 
65 65
     void realloc_buffer_if_needed(size_t interval) {
24  brala/dine/builder/vertices.d
@@ -83,7 +83,7 @@ immutable CubeSideData[6] CUBE_VERTICES = [
83 83
        [0.0f, -1.0f, 0.0f] }
84 84
 ];
85 85
 
86  
-float[] simple_block(Side side, MCTextureSlice texture_slice) {
  86
+Vertex[] simple_block(Side side, MCTextureSlice texture_slice) {
87 87
     CubeSideData cbsd = CUBE_VERTICES[side];
88 88
 
89 89
     float[3][6] positions = to_triangles(cbsd.positions);
@@ -92,26 +92,26 @@ float[] simple_block(Side side, MCTextureSlice texture_slice) {
92 92
                  // vertex      normal       texcoords     palette
93 93
     Vertex[] data;
94 94
 
95  
-    /*foreach(i; 0..6) {
  95
+    foreach(i; 0..6) {
96 96
         data ~= Vertex(positions[i][0], positions[i][1], positions[i][2],
97 97
                        cbsd.normal[0], cbsd.normal[1], cbsd.normal[2],
98 98
                        texcoords[i][0], texcoords[i][1],
99 99
                        0, 0);
100 100
     }
101 101
 
102  
-    return data;*/
103  
-    
  102
+    return data;
  103
+    /*
104 104
     return join([positions[0], cbsd.normal, texcoords[0], [0.0f, 0.0f],
105 105
                  positions[1], cbsd.normal, texcoords[1], [0.0f, 0.0f],
106 106
                  positions[2], cbsd.normal, texcoords[2], [0.0f, 0.0f],
107 107
                  positions[3], cbsd.normal, texcoords[3], [0.0f, 0.0f],
108 108
                  positions[4], cbsd.normal, texcoords[4], [0.0f, 0.0f],
109  
-                 positions[5], cbsd.normal, texcoords[5], [0.0f, 0.0f]]);
  109
+                 positions[5], cbsd.normal, texcoords[5], [0.0f, 0.0f]]);*/
110 110
 }
111 111
 
112 112
 private alias MCTextureSlice t;
113 113
 
114  
-float[][] BLOCK_VERTICES_LEFT = [
  114
+Vertex[][] BLOCK_VERTICES_LEFT = [
115 115
     [], // air
116 116
     simple_block(Side.LEFT, t(1, 1)), // stone
117 117
     simple_block(Side.LEFT, t(3, 1)), // grass
@@ -243,7 +243,7 @@ float[][] BLOCK_VERTICES_LEFT = [
243 243
     []
244 244
 ];
245 245
 
246  
-float[][] BLOCK_VERTICES_RIGHT = [
  246
+Vertex[][] BLOCK_VERTICES_RIGHT = [
247 247
     [], // air
248 248
     simple_block(Side.RIGHT, t(1, 1)), // stone
249 249
     simple_block(Side.RIGHT, t(3, 1)), // grass
@@ -375,7 +375,7 @@ float[][] BLOCK_VERTICES_RIGHT = [
375 375
     []
376 376
 ];
377 377
 
378  
-float[][] BLOCK_VERTICES_NEAR = [
  378
+Vertex[][] BLOCK_VERTICES_NEAR = [
379 379
     [], // air
380 380
     simple_block(Side.NEAR, t(1, 1)), // stone
381 381
     simple_block(Side.NEAR, t(3, 1)), // grass
@@ -507,7 +507,7 @@ float[][] BLOCK_VERTICES_NEAR = [
507 507
     []
508 508
 ];
509 509
 
510  
-float[][] BLOCK_VERTICES_FAR = [
  510
+Vertex[][] BLOCK_VERTICES_FAR = [
511 511
     [], // air
512 512
     simple_block(Side.FAR, t(1, 1)), // stone
513 513
     simple_block(Side.FAR, t(3, 1)), // grass
@@ -639,7 +639,7 @@ float[][] BLOCK_VERTICES_FAR = [
639 639
     []
640 640
 ];
641 641
 
642  
-float[][] BLOCK_VERTICES_TOP = [
  642
+Vertex[][] BLOCK_VERTICES_TOP = [
643 643
     [], // air
644 644
     simple_block(Side.TOP, t(1, 1)), // stone
645 645
     simple_block(Side.TOP, t(0, 1)), // grass
@@ -771,7 +771,7 @@ float[][] BLOCK_VERTICES_TOP = [
771 771
     []
772 772
 ];
773 773
 
774  
-float[][] BLOCK_VERTICES_BOTTOM = [
  774
+Vertex[][] BLOCK_VERTICES_BOTTOM = [
775 775
     [], // air
776 776
     simple_block(Side.BOTTOM, t(1, 1)), // stone
777 777
     simple_block(Side.BOTTOM, t(2, 1)), // grass
@@ -903,7 +903,7 @@ float[][] BLOCK_VERTICES_BOTTOM = [
903 903
     []
904 904
 ];
905 905
 
906  
-ref float[] get_vertices(Side side, T)(T index) if(isIntegral!T) {
  906
+ref Vertex[] get_vertices(Side side, T)(T index) if(isIntegral!T) {
907 907
     static if(side == Side.LEFT) {
908 908
         return BLOCK_VERTICES_LEFT[index];
909 909
     } else static if(side == Side.RIGHT) {
14  brala/dine/world.d
@@ -17,12 +17,12 @@ private {
17 17
 private const Block AIR_BLOCK = Block(0);
18 18
 
19 19
 class World {
20  
-    static float* tessellate_buffer;
  20
+    static Vertex* tessellate_buffer;
21 21
     static size_t tessellate_buffer_length;
22 22
     
23 23
     static this() {
24  
-        tessellate_buffer_length = width*height*depth*20; // this value is the result of testing!
25  
-        tessellate_buffer = cast(float*)malloc(tessellate_buffer_length*float.sizeof);
  24
+        tessellate_buffer_length = width*height*depth*5; // this value is the result of testing!
  25
+        tessellate_buffer = cast(Vertex*)malloc(tessellate_buffer_length*Vertex.sizeof);
26 26
     }
27 27
     
28 28
     static ~this() {
@@ -162,7 +162,7 @@ class World {
162 162
 
163 163
     // fills the vbo with the chunk content
164 164
     // original version from florian boesch - http://codeflow.org/
165  
-    void tessellate(Chunk chunk, vec3i chunkc, ref float* v, ref size_t length, bool force=false) {
  165
+    void tessellate(Chunk chunk, vec3i chunkc, ref Vertex* v, ref size_t length, bool force=false) {
166 166
         Tessellator tessellator = Tessellator(this, v, length);
167 167
 
168 168
         if(chunk.vbo is null) {
@@ -250,8 +250,8 @@ class World {
250 250
                 }
251 251
             }
252 252
 
253  
-            //chunk.vbo_vcount = tessellator.elements * __traits(allMembers, Vertex).length;
254  
-            chunk.vbo_vcount = tessellator.elements / 10;
  253
+            chunk.vbo_vcount = tessellator.elements * __traits(allMembers, Vertex).length;
  254
+            //chunk.vbo_vcount = tessellator.elements / 10;
255 255
             tessellator.fill_vbo(chunk.vbo);
256 256
 
257 257
             chunk.dirty = false;
@@ -272,7 +272,7 @@ class World {
272 272
             chunk.vbo.bind(position, GL_FLOAT, 3, 0, stride);
273 273
             chunk.vbo.bind(normal, GL_FLOAT, 3, Vertex().nx.offsetof, stride);
274 274
             chunk.vbo.bind(texcoord, GL_FLOAT, 2, Vertex().u_terrain.offsetof, stride);
275  
-            chunk.vbo.bind(palettecoord, GL_FLOAT, 2, Vertex().u_palette.offsetof, stride);
  275
+            chunk.vbo.bind(palettecoord, GL_FLOAT, 2, Vertex().u_biome.offsetof, stride);
276 276
         }
277 277
     
278 278
     void draw(BraLaEngine engine) {

0 notes on commit 02a37a0

David Herberth

.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.