Changeset 71 for trunk/tests/render_test
- Timestamp:
- 06/01/13 00:24:46 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/render_test/rl.cc
r50 r71 15 15 #include <nv/string.hh> 16 16 #include <nv/types.hh> 17 18 typedef glm::detail::tvec3<char> byte3; 17 #include <nv/interface/mesh.hh> 19 18 20 19 const nv::uint16 size_x = 16; … … 62 61 }; 63 62 64 struct world;65 struct being;66 67 63 class application 68 64 { … … 70 66 application(); 71 67 bool initialize(); 72 bool init_program( const std::string& name, nv::program*& p, nv::vertex_array*& va, int count, void* vertex, void* material);68 bool init_program( const std::string& name, nv::program*& p, nv::vertex_array*& va, nv::mesh* m ); 73 69 bool run(); 74 70 ~application(); … … 110 106 { 111 107 { // CHARACTER 112 byte3 vertex[6]; 113 byte3 material[6]; 108 nv::mesh cmesh; 109 nv::vertex_attribute<nv::i8vec3>::list& vtx = cmesh.add_attribute<nv::i8vec3>("coords")->get(); 110 nv::vertex_attribute<nv::i8vec3>::list& mat = cmesh.add_attribute<nv::i8vec3>("material")->get(); 114 111 int m = 16; int x = 0; int y = 0; int h = 0; 115 vertex[0] = byte3( x, h, y ); material[0] = byte3( m, 1, 0 ); 116 vertex[1] = byte3( x, h, y+1 ); material[1] = byte3( m, 1, 0 ); 117 vertex[2] = byte3( x+1, h, y+1 ); material[2] = byte3( m, 1, 0 ); 118 vertex[3] = byte3( x+1, h, y+1 ); material[3] = byte3( m, 1, 0 ); 119 vertex[4] = byte3( x+1, h, y ); material[4] = byte3( m, 1, 0 ); 120 vertex[5] = byte3( x, h, y ); material[5] = byte3( m, 1, 0 ); 121 122 if (!init_program( "char", m_char_program, m_char_va, 6, vertex, material ) ) return false; 112 vtx.emplace_back( x, h, y ); 113 vtx.emplace_back( x, h, y+1 ); 114 vtx.emplace_back( x+1, h, y+1 ); 115 vtx.emplace_back( x+1, h, y+1 ); 116 vtx.emplace_back( x+1, h, y ); 117 vtx.emplace_back( x, h, y ); 118 mat.insert( mat.end(), 6, nv::i8vec3( m, 1, 0 ) ); 119 120 if (!init_program( "char", m_char_program, m_char_va, &cmesh ) ) return false; 123 121 } 124 122 125 123 { // WORLD 126 byte3 vertex[size_x * size_y * 256];127 byte3 material[size_x * size_y * 256];128 m_count = 0;129 int mcount = 0; 124 nv::mesh wmesh; 125 nv::vertex_attribute<nv::i8vec3>::list& vtx = wmesh.add_attribute<nv::i8vec3>("coords")->get(); 126 nv::vertex_attribute<nv::i8vec3>::list& mat = wmesh.add_attribute<nv::i8vec3>("material")->get(); 127 130 128 for (int i = 0; i < size_x * size_y; ++i ) 131 129 { … … 133 131 int y = i / size_x; 134 132 135 v ertex[m_count++] = byte3( x, height[i], y ); material[mcount++] = byte3( map[i], 2, 0 );136 v ertex[m_count++] = byte3( x, height[i], y+1 ); material[mcount++] = byte3( map[i], 2, 0 );137 v ertex[m_count++] = byte3( x+1, height[i], y+1 ); material[mcount++] = byte3( map[i], 2, 0 );138 139 v ertex[m_count++] = byte3( x+1, height[i], y+1 ); material[mcount++] = byte3( map[i], 2, 0 );140 v ertex[m_count++] = byte3( x+1, height[i], y ); material[mcount++] = byte3( map[i], 2, 0 );141 vertex[m_count++] = byte3( x, height[i], y ); material[mcount++] = byte3( map[i], 2, 0);133 vtx.emplace_back( x, height[i], y ); 134 vtx.emplace_back( x, height[i], y+1 ); 135 vtx.emplace_back( x+1, height[i], y+1 ); 136 vtx.emplace_back( x+1, height[i], y+1 ); 137 vtx.emplace_back( x+1, height[i], y ); 138 vtx.emplace_back( x, height[i], y ); 139 mat.insert( mat.end(), 6, nv::i8vec3( map[i], 2, 0 ) ); 142 140 143 141 if (i > 0 && height[i-1] != height[i]) … … 147 145 for ( int h = height[i-1]; h != height[i]; h = h + dir ) 148 146 { 149 vertex[m_count++] = byte3( x, h, y ); material[mcount++] = byte3( m, -dir, 0 ); 150 vertex[m_count++] = byte3( x, h, y+1 ); material[mcount++] = byte3( m, -dir, 0 ); 151 vertex[m_count++] = byte3( x, h+dir, y+1 ); material[mcount++] = byte3( m, -dir, 0 ); 152 153 vertex[m_count++] = byte3( x, h+dir, y+1 ); material[mcount++] = byte3( m, -dir, 0 ); 154 vertex[m_count++] = byte3( x, h+dir, y ); material[mcount++] = byte3( m, -dir, 0 ); 155 vertex[m_count++] = byte3( x, h, y ); material[mcount++] = byte3( m, -dir, 0 ); 147 m_count += 6; 148 vtx.emplace_back( x, h, y ); 149 vtx.emplace_back( x, h, y+1 ); 150 vtx.emplace_back( x, h+dir, y+1 ); 151 vtx.emplace_back( x, h+dir, y+1 ); 152 vtx.emplace_back( x, h+dir, y ); 153 vtx.emplace_back( x, h, y ); 154 mat.insert( mat.end(), 6, nv::i8vec3( m, -dir, 0 ) ); 156 155 } 157 156 } … … 163 162 for ( int h = height[i-size_x]; h != height[i]; h = h + dir ) 164 163 { 165 vertex[m_count++] = byte3( x, h, y ); material[mcount++] = byte3( m, -3*dir, 0 ); 166 vertex[m_count++] = byte3( x, h+dir, y ); material[mcount++] = byte3( m, -3*dir, 0 ); 167 vertex[m_count++] = byte3( x+1, h+dir, y ); material[mcount++] = byte3( m, -3*dir, 0 ); 168 169 vertex[m_count++] = byte3( x+1, h+dir, y ); material[mcount++] = byte3( m, -3*dir, 0 ); 170 vertex[m_count++] = byte3( x+1, h, y ); material[mcount++] = byte3( m, -3*dir, 0 ); 171 vertex[m_count++] = byte3( x, h, y ); material[mcount++] = byte3( m, -3*dir, 0 ); 164 vtx.emplace_back( x, h, y ); 165 vtx.emplace_back( x, h+dir, y ); 166 vtx.emplace_back( x+1, h+dir, y ); 167 168 vtx.emplace_back( x+1, h+dir, y ); 169 vtx.emplace_back( x+1, h, y ); 170 vtx.emplace_back( x, h, y ); 171 mat.insert( mat.end(), 6, nv::i8vec3( m, -3*dir, 0 ) ); 172 172 } 173 173 } … … 175 175 } 176 176 177 if (!init_program( "box", m_box_program, m_box_va, m_count, vertex, material ) ) return false; 177 m_count = vtx.size(); 178 if (!init_program( "box", m_box_program, m_box_va, &wmesh ) ) return false; 178 179 } 179 180 … … 181 182 } 182 183 183 bool application::init_program( const std::string& name, nv::program*& p, nv::vertex_array*& va, int count, void* vertex, void* material)184 bool application::init_program( const std::string& name, nv::program*& p, nv::vertex_array*& va, nv::mesh* m ) 184 185 { 185 186 p = m_device->create_program( nv::slurp( name+".vert" ), nv::slurp( name+".frag" ) ); 186 187 va = m_device->create_vertex_array(); 187 188 nv::vertex_buffer* vbcoords = m_device->create_vertex_buffer( nv::STATIC_DRAW, count*sizeof(byte3), vertex ); 189 va->add_vertex_buffer( p->get_attribute( "coords" )->get_location(), vbcoords, nv::BYTE, 3 ); 190 nv::vertex_buffer* vbmaterial = m_device->create_vertex_buffer( nv::STATIC_DRAW, count*sizeof(byte3), material ); 191 va->add_vertex_buffer( p->get_attribute( "material" )->get_location(), vbmaterial, nv::BYTE, 3 ); 192 188 const nv::mesh::map& attrs = m->get_attributes(); 189 190 for ( auto attr : attrs ) 191 { 192 nv::vertex_buffer* vb = m_device->create_vertex_buffer( nv::STATIC_DRAW, attr.second->get_size(), attr.second->get_data() ); 193 va->add_vertex_buffer( p->get_attribute( attr.first )->get_location(), vb, attr.second->get_base_type(), attr.second->get_components() ); 194 } 193 195 return true; 194 196 }
Note: See TracChangeset
for help on using the changeset viewer.