本文整理汇总了C++中VertexBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ VertexBuffer类的具体用法?C++ VertexBuffer怎么用?C++ VertexBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VertexBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw_elements
void Painter::draw_elements(DrawMode mode,
VertexBuffer& indices,
etc::size_type start,
etc::size_type count)
{
ETC_TRACE.debug("draw elements");
if (indices.attributes().size() == 0)
throw Exception{
"No attributes found in indices VertexBuffer."
};
if (indices.attributes().size() > 1)
throw Exception{
"Indices VertexBuffer contains more that one attributes."
};
auto const& attr = indices.attributes()[0];
if (count == ((etc::size_type) -1))
count = attr->nb_elements - start;
else if (count > attr->nb_elements - start)
throw Exception{"Count is out of range."};
Bindable::Guard guard{indices, this->state()};
_renderer.draw_elements(
mode,
count,
attr->type,
(uint8_t*)0 + (start * get_content_type_size(attr->type))
);
}
示例2: OnFirstUpdate
void SkinController::OnFirstUpdate()
{
// Get access to the vertex buffer positions to store the blended targets.
Visual* visual = reinterpret_cast<Visual*>(mObject);
VertexBuffer* vbuffer = visual->GetVertexBuffer().get();
if (mNumVertices == static_cast<int>(vbuffer->GetNumElements()))
{
// Get the position data.
VertexFormat vformat = vbuffer->GetFormat();
int const numAttributes = vformat.GetNumAttributes();
for (int i = 0; i < numAttributes; ++i)
{
VASemantic semantic;
DFType type;
unsigned int unit, offset;
if (vformat.GetAttribute(i, semantic, type, unit, offset))
{
if (semantic == VA_POSITION && (type == DF_R32G32B32_FLOAT
|| type == DF_R32G32B32A32_FLOAT))
{
mPosition = vbuffer->GetData() + offset;
mStride = vformat.GetVertexSize();
mCanUpdate = true;
break;
}
}
}
}
mCanUpdate = (mPosition != nullptr);
}
示例3: VertexBuffer
VertexBuffer *VertexBuffer::createQuad() {
VertexBuffer *vbo = new VertexBuffer();
GLfloat vertices[] = {0, 1.0, 0, // top left corner
1.0, 1.0, 0, // top right corner
1.0, 0, 0, // bottom right corner
0, 0, 0}; // bottom left corner
GLfloat uvs[] = {
0, 1,
1, 1,
1, 0,
0, 0
};
GLubyte indices[] = {0,1,2, // first triangle (bottom left - top left - top right)
0,2,3}; // second triangle (bottom left - top right - bottom right)
for(int i = 0; i < 4; i++)
vbo->addVertex(glm::vec3(vertices[i*3], vertices[(i*3)+1], vertices[(i*3)+2]));
for(int i = 0; i < 4; i++)
vbo->addUV(glm::vec2(uvs[i*2], uvs[(i*2)+1]));
for(int i = 0; i < 6; i++)
vbo->addIndex(indices[i]);
vbo->upload();
return vbo;
}
示例4: doadvance
void PrimitiveShape::doadvance()
{
VertexBuffer* vb = m_vertexbuffer;
if( vb )
{
vb->advance();
}
// IndexBuffer* ib = m_indexbuffer;
// if( ib )
// {
// ib->advance();
// }
Program* pr = m_program;
if( pr )
{
pr->advance();
}
// for( int i = 0; i < 8; ++i )
// {
// Texture* t = m_textures[ i ];
// if( t )
// {
// t->advance();
// }
// }
}
示例5: sizeof
bool Fluids3DWindow::CreateNestedBoxes()
{
std::string path = mEnvironment.GetPath("VolumeRender.hlsl");
std::shared_ptr<VisualProgram> program =
mProgramFactory.CreateFromFiles(path, path, "");
if (!program)
{
return false;
}
mPVWMatrixBuffer = std::make_shared<ConstantBuffer>(
sizeof(Matrix4x4<float>), true);
*mPVWMatrixBuffer->Get<Matrix4x4<float>>() = Matrix4x4<float>::Identity();
mTrilinearClampSampler = std::make_shared<SamplerState>();
mTrilinearClampSampler->filter = SamplerState::MIN_L_MAG_L_MIP_P;
mTrilinearClampSampler->mode[0] = SamplerState::CLAMP;
mTrilinearClampSampler->mode[1] = SamplerState::CLAMP;
mTrilinearClampSampler->mode[2] = SamplerState::CLAMP;
program->GetVShader()->Set("PVWMatrix", mPVWMatrixBuffer);
program->GetPShader()->Set("volumeTexture", mFluid.GetState());
program->GetPShader()->Set("trilinearClampSampler",
mTrilinearClampSampler);
std::shared_ptr<VisualEffect> effect =
std::make_shared<VisualEffect>(program);
struct Vertex { Vector3<float> position, tcoord; };
VertexFormat vformat;
vformat.Bind(VA_POSITION, DF_R32G32B32_FLOAT, 0);
vformat.Bind(VA_TEXCOORD, DF_R32G32B32_FLOAT, 0);
MeshFactory mf;
mf.SetVertexFormat(vformat);
int const numBoxes = 128;
for (int i = 1; i <= numBoxes; ++i)
{
float extent = 0.5f*i/(numBoxes - 1.0f);
std::shared_ptr<Visual> visual(mf.CreateBox(extent, extent, extent));
VertexBuffer* vbuffer = visual->GetVertexBuffer().get();
Vertex* vertex = vbuffer->Get<Vertex>();
for (unsigned int j = 0; j < vbuffer->GetNumElements(); ++j, ++vertex)
{
Vector3<float>& tcd = vertex->tcoord;
Vector3<float> pos = vertex->position;
Vector4<float> tmp{ pos[0] + 0.5f, pos[1] + 0.5f, pos[2] + 0.5f,
0.0f };
for (int k = 0; k < 3; ++k)
{
tcd[k] = 0.5f*(tmp[k] + 1.0f);
}
}
visual->SetEffect(effect);
mVisible.push_back(visual);
}
return true;
}
示例6: vba
//----------------------------------------------------------------------------
void GeoObjFactory::UpdateCtrlColor1(Movable *mov, Float4 color)
{
PX2::Node *node = DynamicCast<Node>(mov);
if (!node)
return;
for (int i = 0; i < node->GetNumChildren(); i++)
{
PX2::Movable *child = node->GetChild(i);
PX2::TriMesh *mesh = DynamicCast<TriMesh>(child);
if (mesh)
{
VertexBuffer *vBuffer = mesh->GetVertexBuffer();
VertexFormat *vf = PX2_GR.GetVertexFormat(GraphicsRoot::VFT_PC);
VertexBufferAccessor vba(vf, vBuffer);
for (int i = 0; i < vBuffer->GetNumElements(); i++)
{
vba.Color<Float4>(0, i) = color;
}
Renderer::UpdateAll(vBuffer);
}
}
}
示例7: Process
void ProjectPass::Process(VertexBuffer& localBuf,VertexBuffer& globalBuf,Int32 p)
{
VertexBuffer& buf = p < 0 ? globalBuf : localBuf;
p = p >= 0 ? p : -p;
Point& pt = buf.GetPosition(p);
pt = r_pCamera->GetProjectMatrix() * pt;
pt.ProjectDiv();
pt = r_pCamera->GetScreenMatrix() * pt;
if(localBuf.HasAttribute(VA_TEXTCOOR))
{
TextureCoord& coor = buf.GetTextureCoord(p);
coor.t *= pt.z;
coor.s *= pt.z;
Int32 nT = TextFix::Double2Fix(coor.t);
Int32 nS = TextFix::Double2Fix(coor.s);
++nS;
}
if(localBuf.HasAttribute(VA_TEXTCOOR1))
{
TextureCoord& coor1 = buf.GetTextureCoord1(p);
coor1.t *= pt.z;
coor1.s *= pt.z;
TextFix::Double2Fix(coor1.t);
TextFix::Double2Fix(coor1.s);
}
Fix28::Double2Fix(pt.z);
}
示例8: 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);
}
示例9: cos
Skydome::Skydome() {
VertexBuffer buff;
int nb_segments=64;
int i,j;
const float R = 1./(float)(nb_segments-1);
for(i = 0; i<nb_segments; i++) {
for(j = 0; j<nb_segments; j++) {
float x = cos(2*M_PI*j*R)*sin(M_PI*i*R);
float y = sin(-M_PI_2+M_PI*i*R);
float z = sin(2*M_PI*j*R)*sin(M_PI*i*R);
buff.addVertex(Vertex3D(glm::vec3(x,y,z), glm::vec3(-x,-y,-z), glm::vec2(0,0), sf::Color(255,255,255,255)));
}
}
for(i=0; i<nb_segments; i++){
for(j=0; j<nb_segments; j++){
//buff.getVertex(i*nb_segments+j).normal = glm::normalize(buff.getVertex(i*nb_segments+j).normal);
buff.addTriangle(sf::Vector3i((i*nb_segments+j), (i*nb_segments+j+1), ((i+1)*nb_segments+j)));
buff.addTriangle(sf::Vector3i((i*nb_segments+j+1), ((i+1)*nb_segments+j+1), ((i+1)*nb_segments+j)));
}
}
loadFromMemory(buff);
}
示例10: SHOOT_ASSERT
//! adds an entity to a render map
void EntityRenderer::AddToRenderMap(RenderMap& renderMap, GraphicComponent* pGraphic)
{
Material* pMaterial = pGraphic->GetMaterial();
VertexBuffer* pVertexBuffer = pGraphic->GetVertexBuffer();
if(pMaterial && pVertexBuffer)
{
if(pVertexBuffer->GetNumVertices() || pVertexBuffer->GetNumIndices())
{
SHOOT_ASSERT(pGraphic->GetParent()->IsA(RenderableEntity::TypeID), "Invalid GraphicComponent");
RenderableEntity* pEntity = static_cast<RenderableEntity*>(pGraphic->GetParent());
u32 materialID = (u32)pMaterial;
u32 ID = ((pGraphic->GetRenderingPriority()&0xFF)<<24) | (materialID&0x00FFFFFF);
u32 vbID = (u32)pVertexBuffer;
renderMap[ID].pMaterial = pMaterial;
renderMap[ID].m_VertexMap[vbID].pVertexBuffer = pVertexBuffer;
renderMap[ID].m_VertexMap[vbID].aWorldTransforms.push_back(pEntity->GetTransformationMatrix());
renderMap[ID].m_VertexMap[vbID].aTextureTransforms.push_back(pEntity->GetTextureTransformationMatrix());
}
}
else
{
SHOOT_WARNING(false, "Incomplete GraphicComponent found");
}
}
示例11:
const ShaderFeatures& Submesh::features()
{
if (mFeatures.isEmpty() && !mVertexBuffers.empty()) {
// build the features struct
for (VertexBuffers::iterator it = mVertexBuffers.begin(); it != mVertexBuffers.end(); ++it) {
VertexBuffer* vb = *it;
int nElems = vb->vertexElementCount();
for (int i=0; i<nElems; ++i) {
VertexElement* elem = vb->vertexElement(i);
switch(elem->mUsage) {
case VEU_POSITION:
mFeatures.setFeature(INTERP_POSITION);
break;
case VEU_NORMAL:
mFeatures.setFeature(INTERP_NORMAL);
break;
case VEU_TEXCOORD:
mFeatures.setFeature(INTERP_TEXCOORD, elem->mIndex);
break;
}
}
}
}
return mFeatures;
}
示例12: VertexBuffer
VertexBuffer* VertexBufferManager::CreateVertexBuffer( const VertexSettings& Settings )
{
VertexBuffer* pVertex = new VertexBuffer( Settings );
pVertex->Init();
mVBOs[ mVboCount++ ] = pVertex;
return pVertex;
}
示例13: vba
//----------------------------------------------------------------------------
void GeoObjFactory::UpdateCtrlColor(PX2::Renderer *renderer,
PX2::Movable *mov, Float4 color)
{
PX2::Node *node = DynamicCast<Node>(mov);
if (!node)
return;
for (int i = 0; i < node->GetNumChildren(); i++)
{
PX2::Movable *child = node->GetChild(i);
PX2::Polysegment *poly = DynamicCast<Polysegment>(child);
if (poly)
{
VertexBuffer *vBuffer = poly->GetVertexBuffer();
VertexFormat *vf = PX2_GR.GetVertexFormat(GraphicsRoot::VFT_PC);
VertexBufferAccessor vba(vf, vBuffer);
for (int i = 0; i < vBuffer->GetNumElements(); i++)
{
vba.Color<Float4>(0, i) = color;
}
renderer->Update(vBuffer);
}
}
}
示例14: Material
//! called during the initialization of the entity
void PelletManager::Init()
{
super::Init();
GraphicComponent* pGraphic = GetComponent<GraphicComponent>();
if(!pGraphic->GetMaterial())
{
pGraphic->SetMaterial(snew Material());
}
u32 maxBullets = m_BulletPoolSize/sizeof(Bullet);
VertexBuffer* pVB = GraphicsDriver::Instance()->CreateVertexBuffer();
pVB->SetVertexFlag(Vertex3D::VF_Pos);
pVB->SetName(GetClassName());
if(GraphicExtensionHandler::Instance()->HasExtension(GraphicExtensionHandler::E_PointSprite))
{
pVB->SetPrimitiveType(GraphicsDriver::PT_Point);
pVB->SetRenderStateSetter(snew PointSpriteStateSetter(m_fBulletSize));
pVB->SetVertices(snew Vertex3D[maxBullets], maxBullets);
}
else
{
pVB->SetPrimitiveType(GraphicsDriver::PT_Triangle);
pVB->SetVertexFlag(Vertex3D::VF_UV);
pVB->SetVertices(snew Vertex3D[maxBullets*6], maxBullets*6);
}
pGraphic->SetVertexBuffer(pVB);
pVB->SetDynamic(true);
}
示例15: bindBuffers
bool RenderDevice::bindBuffers(RenderBatch* renderable)
{
BufferManager* buffers = activeContext->bufferManager;
GeometryBuffer* gb = renderable->getGeometryBuffer().get();
VertexBuffer* vb = buffers->getVertexBuffer(gb).get();
IndexBuffer* ib = buffers->getIndexBuffer(gb).get();
if( !vb ) return false;
if( !vb->isBuilt() || gb->needsRebuild )
{
// If the vertex buffer is not built yet, then we build it.
renderBackend->buildVertexBuffer(vb);
}
renderBackend->bindVertexBuffer(vb);
// If there is no index buffer associated with the geometry, we are done.
if( !ib ) goto done;
renderBackend->bindIndexBuffer(ib);
if( !ib->isBuilt || gb->needsRebuild )
{
// If the index buffer is not built, we also need to build it.
renderBackend->buildIndexBuffer(ib);
}
done:
gb->needsRebuild = false;
return true;
}