Changeset 2507
- Timestamp:
- Feb 26, 2013, 5:22:00 PM (10 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/easymesh/easymesh.cpp
r2506 r2507 142 142 AddUniform("in_Damage"); 143 143 AddUniform("u_Lights"); 144 AddAttribute("in_Vertex", VertexUsage::Position, 0);145 AddAttribute("in_Normal", VertexUsage::Normal, 0);146 AddAttribute("in_Color", VertexUsage::Color, 0);147 if (with_UV)148 AddAttribute("in_TexCoord", VertexUsage::TexCoord, 0);149 144 } 150 145 … … 194 189 } 195 190 191 #define BUILD_VFLAG(bool_value, flag_value, check_flag) \ 192 bool bool_value = (check_flag & (1 << flag_value)) != 0; \ 193 check_flag &= ~(1 << flag_value); 194 #define BUILD_VFLAG_OR(bool_value, flag_value, check_flag) \ 195 bool_value = (bool_value || (check_flag & (1 << flag_value)) != 0); \ 196 check_flag &= ~(1 << flag_value); 197 #define BUILD_VFLAG_COUNT(bool_value, flag_value, check_flag, count_value) \ 198 BUILD_VFLAG(bool_value, flag_value, check_flag) \ 199 count_value += (int)bool_value; 200 196 201 //----------------------------------------------------------------------------- 197 202 void GpuEasyMeshData::AddGpuData(GpuShaderData* gpudata, EasyMesh* src_mesh) 198 203 { 204 uint16_t vflags = gpudata->m_vert_decl_flags; 205 206 BUILD_VFLAG(has_position, VertexUsage::Position, vflags); 207 BUILD_VFLAG(has_normal, VertexUsage::Normal, vflags); 208 BUILD_VFLAG(has_color, VertexUsage::Color, vflags); 209 BUILD_VFLAG(has_texcoord, VertexUsage::TexCoord, vflags); 210 BUILD_VFLAG_OR(has_texcoord, VertexUsage::TexCoordExt, vflags); 211 ASSERT(!vflags, String("Vertex Useage setup is not implemented for : ") + VertexUsage::GetNameList(vflags) + String(", feel free to do so.")); 212 213 if (has_position) gpudata->AddAttribute(gpudata->GetInVertexName(), VertexUsage::Position, 0); 214 if (has_normal) gpudata->AddAttribute(gpudata->GetInNormalName(), VertexUsage::Normal, 0); 215 if (has_color) gpudata->AddAttribute(gpudata->GetInColorName(), VertexUsage::Color, 0); 216 if (has_texcoord) gpudata->AddAttribute(gpudata->GetInTexCoordName(), VertexUsage::TexCoord, 0); 217 199 218 SetupVertexData(gpudata->m_vert_decl_flags, src_mesh); 200 219 … … 227 246 228 247 //----------------------------------------------------------------------------- 229 void GpuEasyMeshData::SetupVertexData(uint16_t v decl_flags, EasyMesh* src_mesh)248 void GpuEasyMeshData::SetupVertexData(uint16_t vflags, EasyMesh* src_mesh) 230 249 { 231 250 for (int i = 0; i < m_vdatas.Count(); ++i) 232 if (m_vdatas[i].m1 == v decl_flags)251 if (m_vdatas[i].m1 == vflags) 233 252 return; 234 253 … … 244 263 new_vbo->Unlock(); 245 264 246 uint16_t baseflag = (1 << VertexUsage::Position) | (1 << VertexUsage::Normal) | (1 << VertexUsage::Color); 247 if (vdecl_flags == (baseflag | (1 << VertexUsage::TexCoordExt)) || 248 vdecl_flags == (baseflag | (1 << VertexUsage::TexCoord) | 249 (1 << VertexUsage::TexCoordExt))) 265 //Keep a count of the flags 266 uint16_t saveflags = vflags; 267 int flagnb = 0; 268 BUILD_VFLAG_COUNT(has_position, VertexUsage::Position, saveflags, flagnb); 269 BUILD_VFLAG_COUNT(has_normal, VertexUsage::Normal, saveflags, flagnb); 270 BUILD_VFLAG_COUNT(has_color, VertexUsage::Color, saveflags, flagnb); 271 BUILD_VFLAG_COUNT(has_texcoord, VertexUsage::TexCoord, saveflags, flagnb); 272 BUILD_VFLAG_COUNT(has_texcoordExt,VertexUsage::TexCoordExt, saveflags, flagnb); 273 ASSERT(!saveflags, String("Vertex Declaration setup is not implemented for : ") + VertexUsage::GetNameList(vflags) + String(", feel free to do so.")); 274 275 if (has_position && has_normal && has_color && has_texcoord && has_texcoordExt && flagnb == 5) 250 276 { 251 277 new_vdecl = new VertexDeclaration( … … 269 295 COPY_VBO; 270 296 } 271 else if (vdecl_flags == (baseflag | (1 << VertexUsage::TexCoord))) 297 else if (has_position && has_texcoord && has_texcoordExt && flagnb == 3) 298 { 299 new_vdecl = new VertexDeclaration(VertexStream<vec3,vec4>(VertexUsage::Position, VertexUsage::TexCoord)); 300 301 Array<vec3, vec4> vertexlist; 302 for (int i = 0; i < src_mesh->m_vert.Count(); i++) 303 vertexlist.Push(src_mesh->m_vert[i].m_coord, src_mesh->m_vert[i].m_texcoord); 304 305 vbo_data = &vertexlist[0]; 306 vbo_bytes = vertexlist.Bytes(); 307 m_vertexcount = vertexlist.Count(); 308 309 COPY_VBO; 310 } 311 else if (has_position && has_texcoord && flagnb == 2) 312 { 313 new_vdecl = new VertexDeclaration(VertexStream<vec3,vec2>(VertexUsage::Position, VertexUsage::TexCoord)); 314 315 Array<vec3, vec2> vertexlist; 316 for (int i = 0; i < src_mesh->m_vert.Count(); i++) 317 vertexlist.Push(src_mesh->m_vert[i].m_coord, src_mesh->m_vert[i].m_texcoord.xy); 318 319 vbo_data = &vertexlist[0]; 320 vbo_bytes = vertexlist.Bytes(); 321 m_vertexcount = vertexlist.Count(); 322 323 COPY_VBO; 324 } 325 else if (has_position && has_normal && has_color && has_texcoord && flagnb == 4) 272 326 { 273 327 new_vdecl = new VertexDeclaration( … … 291 345 COPY_VBO; 292 346 } 293 else if ( vdecl_flags == baseflag)347 else if (has_position && has_normal && has_color && flagnb == 3) 294 348 { 295 349 new_vdecl = new VertexDeclaration( … … 312 366 } 313 367 314 m_vdatas.Push(v decl_flags, new_vdecl, new_vbo);368 m_vdatas.Push(vflags, new_vdecl, new_vbo); 315 369 } 316 370 … … 338 392 vdecl->Bind(); 339 393 340 uint16_t baseflag = (1 << VertexUsage::Position) | (1 << VertexUsage::Normal) | (1 << VertexUsage::Color); 341 if (vflags == (baseflag | (1 << VertexUsage::TexCoord)) || 342 vflags == (baseflag | (1 << VertexUsage::TexCoordExt)) || 343 vflags == (baseflag | (1 << VertexUsage::TexCoord) | 344 (1 << VertexUsage::TexCoordExt))) 345 346 { 347 vdecl->SetStream(vbo, *gpu_sd.GetAttribute(lol::String("in_Vertex")), 348 *gpu_sd.GetAttribute(lol::String("in_Normal")), 349 *gpu_sd.GetAttribute(lol::String("in_Color")), 350 *gpu_sd.GetAttribute(lol::String("in_TexCoord"))); 351 } 352 else if (vflags == baseflag) 353 { 354 vdecl->SetStream(vbo, *gpu_sd.GetAttribute(lol::String("in_Vertex")), 355 *gpu_sd.GetAttribute(lol::String("in_Normal")), 356 *gpu_sd.GetAttribute(lol::String("in_Color"))); 357 } 394 BUILD_VFLAG(has_position, VertexUsage::Position, vflags); 395 BUILD_VFLAG(has_normal, VertexUsage::Normal, vflags); 396 BUILD_VFLAG(has_color, VertexUsage::Color, vflags); 397 BUILD_VFLAG(has_texcoord, VertexUsage::TexCoord, vflags); 398 BUILD_VFLAG_OR(has_texcoord,VertexUsage::TexCoordExt, vflags); 399 ASSERT(!vflags, String("Vertex Stream setup is not implemented for : ") + VertexUsage::GetNameList(vflags) + String(", feel free to do so.")); 400 401 int idx = 0; 402 ShaderAttrib Attribs[4] = { lol::ShaderAttrib(), lol::ShaderAttrib(), lol::ShaderAttrib(), lol::ShaderAttrib() }; 403 404 if (has_position) Attribs[idx++] = *gpu_sd.GetAttribute(gpu_sd.GetInVertexName()); 405 if (has_normal) Attribs[idx++] = *gpu_sd.GetAttribute(gpu_sd.GetInNormalName()); 406 if (has_color) Attribs[idx++] = *gpu_sd.GetAttribute(gpu_sd.GetInColorName()); 407 if (has_texcoord) Attribs[idx++] = *gpu_sd.GetAttribute(gpu_sd.GetInTexCoordName()); 408 409 vdecl->SetStream(vbo, Attribs[0], Attribs[1], Attribs[2], Attribs[3]); 358 410 359 411 m_ibo->Bind(); -
trunk/src/easymesh/easymesh.h
r2506 r2507 83 83 //-- 84 84 virtual void SetupShaderDatas(mat4 const &model) { UNUSED(model); } 85 //-- 86 virtual lol::String GetInVertexName() { return lol::String("in_Vertex"); } 87 virtual lol::String GetInNormalName() { return lol::String("in_Normal"); } 88 virtual lol::String GetInColorName() { return lol::String("in_Color"); } 89 virtual lol::String GetInTexCoordName() { return lol::String("in_TexCoord"); } 85 90 86 91 protected: -
trunk/src/lol/gpu/vertexbuffer.h
r2506 r2507 60 60 Depth, 61 61 Sample, 62 63 Max 62 64 } 63 65 m_value; 64 66 67 private: 68 static String GetName(Value v, bool use_simple) 69 { 70 String tmp = String(""); 71 if (!use_simple) tmp += "<"; 72 switch (v) 73 { 74 case Position: { tmp += "Position"; break; } 75 case BlendWeight: { tmp += "BlendWeight"; break; } 76 case BlendIndices: { tmp += "BlendIndices";break; } 77 case Normal: { tmp += "Normal"; break; } 78 case PointSize: { tmp += "PointSize"; break; } 79 case TexCoord: { tmp += "TexCoord"; break; } 80 case TexCoordExt: { tmp += "TexCoordExt"; break; } 81 case Tangent: { tmp += "Tangent"; break; } 82 case Binormal: { tmp += "Binormal"; break; } 83 case TessFactor: { tmp += "TessFactor"; break; } 84 case PositionT: { tmp += "PositionT"; break; } 85 case Color: { tmp += "Color"; break; } 86 case Fog: { tmp += "Fog"; break; } 87 case Depth: { tmp += "Depth"; break; } 88 case Sample: { tmp += "Sample"; break; } 89 default: { tmp += "UNDEFINED"; break; } 90 } 91 if (!use_simple) tmp += ">"; 92 return tmp; 93 } 94 95 public: 96 static String GetName(Value v) 97 { 98 return GetName(v, false); 99 } 100 101 static String GetNameList(uint32_t v) 102 { 103 String tmp = String("<"); 104 int nb = 0; 105 for (int i = 0; i < Max; ++i) 106 { 107 if (v & (1<<i)) 108 { 109 if (nb != 0) 110 tmp += ", "; 111 tmp += GetName(Value(i), true); 112 ++nb; 113 } 114 } 115 return tmp + ">"; 116 } 117 65 118 inline VertexUsage(Value v) : m_value(v) {} 119 inline VertexUsage(int v) : m_value((Value)v) {} 66 120 inline operator Value() { return m_value; } 67 121 };
Note: See TracChangeset
for help on using the changeset viewer.