本文整理汇总了C++中StreamReader::Ensure方法的典型用法代码示例。如果您正苦于以下问题:C++ StreamReader::Ensure方法的具体用法?C++ StreamReader::Ensure怎么用?C++ StreamReader::Ensure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StreamReader
的用法示例。
在下文中一共展示了StreamReader::Ensure方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadVertexData
//=================================================================================================
// Wczytuje dane wierzcho³ków z modelu (na razie dzia³a tylko dla Vec3)
//=================================================================================================
void Mesh::LoadVertexData(VertexData* vd, StreamReader& stream)
{
// read and check header
Header head;
if(!stream.Read(head))
throw "Failed to read file header.";
if(memcmp(head.format, "QMSH", 4) != 0)
throw Format("Invalid file signature '%.4s'.", head.format);
if(head.version != 20)
throw Format("Invalid file version '%d'.", head.version);
if(head.flags != F_PHYSICS)
throw Format("Invalid mesh flags '%d'.", head.flags);
vd->radius = head.radius;
// read vertices
uint size = sizeof(Vec3) * head.n_verts;
if(!stream.Ensure(size))
throw "Failed to read vertex data.";
vd->verts.resize(head.n_verts);
stream.Read(vd->verts.data(), size);
// read faces
size = sizeof(Face) * head.n_tris;
if(!stream.Ensure(size))
throw "Failed to read triangle data.";
vd->faces.resize(head.n_tris);
stream.Read(vd->faces.data(), size);
}
示例2: LoadPoints
void Mesh::LoadPoints(StreamReader& stream)
{
uint size = Point::MIN_SIZE * head.n_points;
if(!stream.Ensure(size))
throw "Failed to read points.";
attach_points.clear();
attach_points.resize(head.n_points);
for(word i = 0; i < head.n_points; ++i)
{
Point& p = attach_points[i];
stream.Read(p.name);
stream.Read(p.mat);
stream.Read(p.bone);
stream.Read(p.type);
stream.Read(p.size);
stream.Read(p.rot);
p.rot.y = Clip(-p.rot.y);
}
}
示例3: Load
//=================================================================================================
// Wczytywanie modelu z pliku
//=================================================================================================
void Mesh::Load(StreamReader& stream, IDirect3DDevice9* device)
{
assert(device);
LoadHeader(stream);
SetVertexSizeDecl();
// ------ vertices
// ensure size
uint size = vertex_size * head.n_verts;
if(!stream.Ensure(size))
throw "Failed to read vertex buffer.";
// create vertex buffer
HRESULT hr = device->CreateVertexBuffer(size, 0, 0, D3DPOOL_MANAGED, &vb, nullptr);
if(FAILED(hr))
throw Format("Failed to create vertex buffer (%d).", hr);
// read
void* ptr;
V(vb->Lock(0, size, &ptr, 0));
stream.Read(ptr, size);
V(vb->Unlock());
// ----- triangles
// ensure size
size = sizeof(word) * head.n_tris * 3;
if(!stream.Ensure(size))
throw "Failed to read index buffer.";
// create index buffer
hr = device->CreateIndexBuffer(size, 0, D3DFMT_INDEX16, D3DPOOL_MANAGED, &ib, nullptr);
if(FAILED(hr))
throw Format("Failed to create index buffer (%d).", hr);
// read
V(ib->Lock(0, size, &ptr, 0));
stream.Read(ptr, size);
V(ib->Unlock());
// ----- submeshes
size = Submesh::MIN_SIZE * head.n_subs;
if(!stream.Ensure(size))
throw "Failed to read submesh data.";
subs.resize(head.n_subs);
for(word i = 0; i < head.n_subs; ++i)
{
Submesh& sub = subs[i];
stream.Read(sub.first);
stream.Read(sub.tris);
stream.Read(sub.min_ind);
stream.Read(sub.n_ind);
stream.Read(sub.name);
stream.ReadString1();
if(BUF[0])
sub.tex = ResourceManager::Get<Texture>().GetLoaded(BUF);
else
sub.tex = nullptr;
// specular value
stream.Read(sub.specular_color);
stream.Read(sub.specular_intensity);
stream.Read(sub.specular_hardness);
// normalmap
if(IS_SET(head.flags, F_TANGENTS))
{
stream.ReadString1();
if(BUF[0])
{
sub.tex_normal = ResourceManager::Get<Texture>().GetLoaded(BUF);
stream.Read(sub.normal_factor);
}
else
sub.tex_normal = nullptr;
}
else
sub.tex_normal = nullptr;
// specular map
stream.ReadString1();
if(BUF[0])
{
sub.tex_specular = ResourceManager::Get<Texture>().GetLoaded(BUF);
stream.Read(sub.specular_factor);
stream.Read(sub.specular_color_factor);
}
else
sub.tex_specular = nullptr;
if(!stream)
throw Format("Failed to read submesh %u.", i);
}
//.........这里部分代码省略.........