本文整理汇总了C++中IndexBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ IndexBuffer类的具体用法?C++ IndexBuffer怎么用?C++ IndexBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IndexBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: backWallColor
//----------------------------------------------------------------------------
void BouncingSpheres::CreateBackWall ()
{
VertexFormat* vformat = VertexFormat::Create(2,
VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0);
int vstride = vformat->GetStride();
Float3 backWallColor(209.0f/255.0f, 204.0f/255.0f, 180.0f/255.0f);
VertexBuffer* vbuffer = new0 VertexBuffer(4, vstride);
VertexBufferAccessor vba(vformat, vbuffer);
vba.Position<Float3>(0) = Float3(1.0f, 1.0f, 1.0f);
vba.Position<Float3>(1) = Float3(1.0f, 20.0f, 1.0f);
vba.Position<Float3>(2) = Float3(1.0f, 20.0f, 17.0f);
vba.Position<Float3>(3) = Float3(1.0f, 1.0f, 17.0f);
vba.Color<Float3>(0, 0) = backWallColor;
vba.Color<Float3>(0, 1) = backWallColor;
vba.Color<Float3>(0, 2) = backWallColor;
vba.Color<Float3>(0, 3) = backWallColor;
IndexBuffer* ibuffer = new0 IndexBuffer(6, sizeof(int));
int* indices = (int*)ibuffer->GetData();
indices[0] = 0; indices[1] = 1; indices[2] = 2;
indices[3] = 0; indices[4] = 2; indices[5] = 3;
mBackWall = new0 TriMesh(vformat, vbuffer, ibuffer);
mBackWall->SetEffectInstance(VertexColor3Effect::CreateUniqueInstance());
}
示例2: Draw
void Renderer::Draw(const VertexArray& va, const IndexBuffer& ib, const Shader& shader) const
{
shader.Bind();
ib.Bind();
va.Bind();
GLCall(glDrawElements(GL_TRIANGLES, ib.GetCount(), GL_UNSIGNED_INT, 0));
}
示例3: Float2
//----------------------------------------------------------------------------
TriMesh *ScreenTarget::CreateRectangle (VertexFormat* vformat,
float xMin, float xMax, float yMin, float yMax, float zValue)
{
if (!ValidFormat(vformat))
return 0;
Float2 tc0, tc1, tc2, tc3;
tc0 = Float2(0.0f, 0.0f);
tc1 = Float2(1.0f, 0.0f);
tc2 = Float2(1.0f, 1.0f);
tc3 = Float2(0.0f, 1.0f);
int vstride = vformat->GetStride();
VertexBuffer* vbuffer = new0 VertexBuffer(4, vstride);
VertexBufferAccessor vba(vformat, vbuffer);
vba.Position<Float3>(0) = Float3(xMin, yMin, zValue);
vba.Position<Float3>(1) = Float3(xMax, yMin, zValue);
vba.Position<Float3>(2) = Float3(xMax, yMax, zValue);
vba.Position<Float3>(3) = Float3(xMin, yMax, zValue);
vba.TCoord<Float2>(0, 0) = tc0;
vba.TCoord<Float2>(0, 1) = tc1;
vba.TCoord<Float2>(0, 2) = tc2;
vba.TCoord<Float2>(0, 3) = tc3;
// 为square创建IndexBuffer
IndexBuffer* ibuffer = new0 IndexBuffer(6, sizeof(int));
int* indices = (int*)ibuffer->GetData();
indices[0] = 0; indices[1] = 1; indices[2] = 2;
indices[3] = 0; indices[4] = 2; indices[5] = 3;
return new0 TriMesh(vformat, vbuffer, ibuffer);
}
示例4: VertexBuffer
//----------------------------------------------------------------------------
TriMesh* PolyhedronDistance::CreatePlane ()
{
VertexFormat* vformat = VertexFormat::Create(2,
VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0);
int vstride = vformat->GetStride();
VertexBuffer* vbuffer = new0 VertexBuffer(4, vstride);
VertexBufferAccessor vba(vformat, vbuffer);
float size = 16.0f;
vba.Position<Float3>(0) = Float3(-size, -size, -0.1f);
vba.Position<Float3>(1) = Float3(+size, -size, -0.1f);
vba.Position<Float3>(2) = Float3(+size, +size, -0.1f);
vba.Position<Float3>(3) = Float3(-size, +size, -0.1f);
vba.Color<Float3>(0, 0) = Float3(0.0f, 0.50f, 0.00f);
vba.Color<Float3>(0, 1) = Float3(0.0f, 0.25f, 0.00f);
vba.Color<Float3>(0, 2) = Float3(0.0f, 0.75f, 0.00f);
vba.Color<Float3>(0, 3) = Float3(0.0f, 1.00f, 0.00f);
IndexBuffer* ibuffer = new0 IndexBuffer(6, sizeof(int));
int* indices = (int*)ibuffer->GetData();
indices[0] = 0; indices[1] = 1; indices[2] = 2;
indices[3] = 0; indices[4] = 2; indices[5] = 3;
TriMesh* mesh = new0 TriMesh(vformat, vbuffer, ibuffer);
mesh->SetEffectInstance(VertexColor3Effect::CreateUniqueInstance());
return mesh;
}
示例5: indices
IndexBuffer TerrainTessellator::createPatchIndexBuffer(const GraphicsDevice& device, unsigned levelOfDetail)
{
// distance between two neighbor vertices
int delta = MathHelper::pow2(levelOfDetail);
// size of grid in current lod (e.g. lod 0: 64, lod 1: 32)
int lodSize = size / delta;
// main indices + skirt indices
int numIndices = lodSize * lodSize * 6;
IndexCollection indices(numIndices);
int count = 0;
unsigned interval = min(stripeSize * delta, size);
// init main indices
for (unsigned i = 0; i < size / interval; ++i)
for (unsigned row = 0; row < size; row += delta)
for (unsigned col = i * interval; col < (i+1) * interval; col += delta)
initQuadIndices(row, col, delta, delta, &indices, &count);
IndexBuffer indexBuffer = device.createIndexBuffer(sizeof(TerrainIndex) * numIndices, indexFormat, D3DUSAGE_WRITEONLY);
indexBuffer.setData(indices);
return indexBuffer;
}
示例6: UpdateCbPerDraw
void BasicRenderer::DrawIndexedPrimitive(PrimitiveTypeEnum pt,
ObjectGUID vbId,
ObjectGUID ibId,
uint32_t startIndex,
uint32_t indexCount,
uint32_t startVertex,
float* color,
float* xform)
{
if(!m_context) return;
UpdateCbPerDraw(xform,color);
// Set primitive topology
m_context->IASetPrimitiveTopology( (D3D11_PRIMITIVE_TOPOLOGY)pt );
// set vertex buffer
VertexBuffer* vb = reinterpret_cast<VertexBuffer*>(vbId);
UINT stride = vb->GetStride();
UINT Offset = 0;
ID3D11Buffer* buffer = vb->GetBuffer();
m_context->IASetVertexBuffers( 0, 1, &buffer, &stride, &Offset);
// set index buffer
IndexBuffer* ib = reinterpret_cast<IndexBuffer*>(ibId);
m_context->IASetIndexBuffer(ib->GetBuffer(),(DXGI_FORMAT)ib->GetFormat(),0);
m_context->DrawIndexed(indexCount,startIndex,startVertex);
}
示例7: mIsDynamic
//----------------------------------------------------------------------------
Billboard::Billboard () :
mIsDynamic(true),
mIsUseTexAsSize(false),
mIsDoAlphaDisAfterStop(true),
mDoAlphaDisAfterStopSpeed(0.5f),
mIsUseTrim(false)
{
SetTex("Data/engine/default.png");
mAnchorPoint = Float2(0.5f, 0.5f);
SetLocal(true);
SetDynamic(mIsDynamic);
IndexBuffer *iBuffer = new0 IndexBuffer(6, 2, Buffer::BU_STATIC);
unsigned short *indices = (unsigned short*)iBuffer->GetData();
unsigned short v0 = 0;
unsigned short v1 = 1;
unsigned short v2 = 2;
unsigned short v3 = 3;
*indices++ = v0;
*indices++ = v1;
*indices++ = v2;
*indices++ = v1;
*indices++ = v3;
*indices++ = v2;
SetIndexBuffer(iBuffer);
mEffectableCtrl = new0 BillboardController();
mEffectableCtrl->SetName("BillboardController");
AttachController(mEffectableCtrl);
}
示例8: HasDynamicBuffers
bool HasDynamicBuffers(Model* model, unsigned lodLevel)
{
unsigned numGeometries = model->GetNumGeometries();
for (unsigned i = 0; i < numGeometries; ++i)
{
Geometry* geometry = model->GetGeometry(i, lodLevel);
if (!geometry)
continue;
unsigned numVertexBuffers = geometry->GetNumVertexBuffers();
for (unsigned j = 0; j < numVertexBuffers; ++j)
{
VertexBuffer* buffer = geometry->GetVertexBuffer(j);
if (!buffer)
continue;
if (buffer->IsDynamic())
return true;
}
IndexBuffer* buffer = geometry->GetIndexBuffer();
if (buffer && buffer->IsDynamic())
return true;
}
return false;
}
示例9: CreateTangentSpace
//--------------------------------------------------------------------------
Helper::Ptr HelperManager::CreateTangentSpace( VertexBuffer3F& _pvbo,
VertexBuffer3F& _nvbo,
VertexBuffer4F& _tvbo,
IndexBuffer& _ibo,
int _startIndex,
int _countIndex,
float _vectorSize)
{
Helper::Ptr ref = Helper::Create();
ref->vbuffer.Allocate(6*_countIndex,GL_STATIC_DRAW);
ref->cbuffer.Allocate(6*_countIndex,GL_STATIC_DRAW);
ref->type = GL_LINES;
ref->transform = glm::mat4(1.f);
glm::vec3* hvertices = ref->vbuffer.Lock();
glm::vec3* hcolors = ref->cbuffer.Lock();
glm::vec3* vertices = _pvbo.Lock();
glm::vec4* tangents = _tvbo.Lock();
glm::vec3* normals = _nvbo.Lock();
unsigned int* indices= _ibo.Lock();
int current = 0;
for(int i=_startIndex; i<_startIndex+_countIndex; ++i)
{
int index = indices[i];
// Tangent
hvertices[current+0] = vertices[index];
hvertices[current+1] = vertices[index] + glm::vec3(tangents[index]) * _vectorSize;
// Bitangent
glm::vec3 bitangent = glm::cross(glm::vec3(tangents[index]),normals[index]) * glm::sign(tangents[index].w);
hvertices[current+2] = vertices[index];
hvertices[current+3] = vertices[index] + bitangent * _vectorSize;
// Normal
hvertices[current+4] = vertices[index];
hvertices[current+5] = vertices[index] + normals[index] * _vectorSize;
hcolors[current+0] = glm::vec3(1.f,0.f,0.f);
hcolors[current+1] = glm::vec3(1.f,0.f,0.f);
hcolors[current+2] = glm::vec3(0.f,1.f,0.f);
hcolors[current+3] = glm::vec3(0.f,1.f,0.f);
hcolors[current+4] = glm::vec3(0.f,0.f,1.f);
hcolors[current+5] = glm::vec3(0.f,0.f,1.f);
current += 6;
}
_ibo.Unlock();
_nvbo.Unlock();
_tvbo.Unlock();
_pvbo.Unlock();
ref->cbuffer.Unlock();
ref->vbuffer.Unlock();
helpers.push_back(ref);
return ref;
}
示例10: PartitionMesh
//----------------------------------------------------------------------------
void ClipMesh::Update ()
{
// Transform the model-space vertices to world space.
int numVertices = (int)mTorusVerticesMS.size();
int i;
for (i = 0; i < numVertices; ++i)
{
mTorusVerticesWS[i] = mTorus->LocalTransform*mTorusVerticesMS[i];
}
// Partition the torus mesh.
std::vector<APoint> clipVertices;
std::vector<int> negIndices, posIndices;
PartitionMesh(mTorusVerticesWS, mTorusIndices, mPlane, clipVertices,
negIndices, posIndices);
// Replace the torus vertex buffer.
numVertices = (int)clipVertices.size();
int stride = mTorus->GetVertexFormat()->GetStride();
VertexBuffer* vbuffer = new0 VertexBuffer(numVertices, stride,
Buffer::BU_STATIC);
mTorus->SetVertexBuffer(vbuffer);
VertexBufferAccessor vba(mTorus);
Float3 black(0.0f, 0.0f, 0.0f);
for (i = 0; i < numVertices; ++i)
{
// Transform the world-space vertex to model space.
vba.Position<Float3>(i) =
mTorus->LocalTransform.Inverse()*clipVertices[i];
vba.Color<Float3>(0, i) = black;
}
// Modify the vertex color based on which mesh the vertices lie.
int negQuantity = (int)negIndices.size();
for (i = 0; i < negQuantity; ++i)
{
vba.Color<Float3>(0, negIndices[i])[2] = 1.0f;
}
int posQuantity = (int)posIndices.size();
for (i = 0; i < posQuantity; ++i)
{
vba.Color<Float3>(0, posIndices[i])[0] = 1.0f;
}
// To display the triangles generated by the split.
int numIndices = negQuantity + posQuantity;
IndexBuffer* ibuffer = new0 IndexBuffer(numIndices, sizeof(int));
mTorus->SetIndexBuffer(ibuffer);
int* indices = (int*)ibuffer->GetData();
memcpy(indices, &negIndices[0], negQuantity*sizeof(int));
memcpy(indices + negQuantity, &posIndices[0], posQuantity*sizeof(int));
}
示例11: Node
//----------------------------------------------------------------------------
void ClipMesh::CreateScene ()
{
mScene = new0 Node();
VertexFormat* vformat = VertexFormat::Create(2,
VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0);
// The plane is fixed at z = 0.
mPlane.SetNormal(AVector::UNIT_Z);
mPlane.SetConstant(0.0f);
mMeshPlane = StandardMesh(vformat).Rectangle(32, 32, 16.0f, 16.0f);
VisualEffectInstance* instance =
VertexColor3Effect::CreateUniqueInstance();
instance->GetEffect()->GetWireState(0,0)->Enabled = true;
mMeshPlane->SetEffectInstance(instance);
mScene->AttachChild(mMeshPlane);
VertexBufferAccessor vba(mMeshPlane);
Float3 green(0.0f, 1.0f, 0.0f);
int i;
for (i = 0; i < vba.GetNumVertices(); ++i)
{
vba.Color<Float3>(0, i) = green;
}
// Get the positions and indices for a torus.
mTorus = StandardMesh(vformat).Torus(64, 64, 4.0f, 1.0f);
instance = VertexColor3Effect::CreateUniqueInstance();
mTorusWireState = instance->GetEffect()->GetWireState(0, 0);
mTorus->SetEffectInstance(instance);
mScene->AttachChild(mTorus);
vba.ApplyTo(mTorus);
mTorusVerticesMS.resize(vba.GetNumVertices());
mTorusVerticesWS.resize(vba.GetNumVertices());
Float3 black(0.0f, 0.0f, 0.0f);
for (i = 0; i < vba.GetNumVertices(); ++i)
{
mTorusVerticesMS[i] = vba.Position<Float3>(i);
mTorusVerticesWS[i] = mTorusVerticesMS[i];
vba.Color<Float3>(0, i) = black;
}
IndexBuffer* ibuffer = mTorus->GetIndexBuffer();
int numIndices = ibuffer->GetNumElements();
int* indices = (int*)ibuffer->GetData();
mTorusIndices.resize(numIndices);
memcpy(&mTorusIndices[0], indices, numIndices*sizeof(int));
Update();
}
示例12: InitIndexBuffer
void InitIndexBuffer(IndexBuffer & pIB, LPVOID indices, UINT idxCnt, UINT stride)
{
D3DFORMAT format;
if (stride == sizeof(WORD))
format = D3DFMT_INDEX16;
else if (stride == sizeof(DWORD))
format = D3DFMT_INDEX32;
GetD3D9Device()->CreateIndexBuffer(idxCnt * stride, NULL, format, D3DPOOL_MANAGED, &pIB, NULL);
LPVOID pIndex;
pIB->Lock(0, 0, (LPVOID*)&pIndex, 0);
memcpy(pIndex, indices, idxCnt * stride);
pIB->Unlock();
}
示例13: VertexBuffer
//----------------------------------------------------------------------------
TriMesh* StandardMesh::Hexahedron ()
{
float fSqrtThird = Mathf::Sqrt(1.0f/3.0f);
int numVertices = 8;
int numTriangles = 12;
int numIndices = 3*numTriangles;
int stride = mVFormat->GetStride();
// Create a vertex buffer.
VertexBuffer* vbuffer = new0 VertexBuffer(numVertices, stride, mUsage);
VertexBufferAccessor vba(mVFormat, vbuffer);
// Generate geometry.
vba.Position<Float3>(0) = Float3(-fSqrtThird, -fSqrtThird, -fSqrtThird);
vba.Position<Float3>(1) = Float3( fSqrtThird, -fSqrtThird, -fSqrtThird);
vba.Position<Float3>(2) = Float3( fSqrtThird, fSqrtThird, -fSqrtThird);
vba.Position<Float3>(3) = Float3(-fSqrtThird, fSqrtThird, -fSqrtThird);
vba.Position<Float3>(4) = Float3(-fSqrtThird, -fSqrtThird, fSqrtThird);
vba.Position<Float3>(5) = Float3( fSqrtThird, -fSqrtThird, fSqrtThird);
vba.Position<Float3>(6) = Float3( fSqrtThird, fSqrtThird, fSqrtThird);
vba.Position<Float3>(7) = Float3(-fSqrtThird, fSqrtThird, fSqrtThird);
CreatePlatonicNormals(vba);
CreatePlatonicUVs(vba);
TransformData(vba);
// Generate indices.
IndexBuffer* ibuffer = new0 IndexBuffer(numIndices, 4, mUsage);
int* indices = (int*)ibuffer->GetData();
indices[ 0] = 0; indices[ 1] = 3; indices[ 2] = 2;
indices[ 3] = 0; indices[ 4] = 2; indices[ 5] = 1;
indices[ 6] = 0; indices[ 7] = 1; indices[ 8] = 5;
indices[ 9] = 0; indices[10] = 5; indices[11] = 4;
indices[12] = 0; indices[13] = 4; indices[14] = 7;
indices[15] = 0; indices[16] = 7; indices[17] = 3;
indices[18] = 6; indices[19] = 5; indices[20] = 1;
indices[21] = 6; indices[22] = 1; indices[23] = 2;
indices[24] = 6; indices[25] = 2; indices[26] = 3;
indices[27] = 6; indices[28] = 3; indices[29] = 7;
indices[30] = 6; indices[31] = 7; indices[32] = 4;
indices[33] = 6; indices[34] = 4; indices[35] = 5;
if (mInside)
{
ReverseTriangleOrder(numTriangles,indices);
}
return new0 TriMesh(mVFormat, vbuffer, ibuffer);
}
示例14: VertexBuffer
//----------------------------------------------------------------------------
Node* ExtremalQuery::CreateVisualConvexPolyhedron ()
{
const Vector3f* vertices = mConvexPolyhedron->GetVertices();
int numTriangles = mConvexPolyhedron->GetNumTriangles();
int numIndices = 3*numTriangles;
const int* polyIndices = mConvexPolyhedron->GetIndices();
// Visualize the convex polyhedron as a collection of face-colored
// triangles.
VertexFormat* vformat = VertexFormat::Create(2,
VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0);
int vstride = vformat->GetStride();
VertexBuffer* vbuffer = new0 VertexBuffer(numIndices, vstride);
VertexBufferAccessor vba(vformat, vbuffer);
IndexBuffer* ibuffer = new0 IndexBuffer(numIndices, sizeof(int));
int* indices = (int*)ibuffer->GetData();
int i;
for (i = 0; i < numIndices; ++i)
{
vba.Position<Vector3f>(i) = vertices[polyIndices[i]];
indices[i] = i;
}
TriMesh* mesh = new0 TriMesh(vformat, vbuffer, ibuffer);
// Use randomly generated vertex colors.
for (i = 0; i < numTriangles; ++i)
{
Float3 color;
for (int j = 0; j < 3; ++j)
{
color[j] = Mathf::UnitRandom();
}
vba.Color<Float3>(0, 3*i ) = color;
vba.Color<Float3>(0, 3*i+1) = color;
vba.Color<Float3>(0, 3*i+2) = color;
}
mesh->SetEffectInstance(VertexColor3Effect::CreateUniqueInstance());
Node* root = new0 Node();
root->AttachChild(mesh);
return root;
}
示例15: Error
Mesh::Mesh(
const Attribute& position,
const IndexBuffer& indices,
MeshType type
)
: position(position)
, indices(&indices)
, start(0)
, count(indices.getCount())
, type(type)
{
if (count + start > indices.getCount()) {
throw Error("Invalid mesh range.", __FILE__, __LINE__);
}
}