当前位置: 首页>>代码示例>>C++>>正文


C++ VertexBuffer类代码示例

本文整理汇总了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))
		);
	}
开发者ID:hotgloupi,项目名称:8cube,代码行数:31,代码来源:Painter.cpp

示例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);
}
开发者ID:c0g,项目名称:FaceWarpApp,代码行数:31,代码来源:GteSkinController.cpp

示例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;
}
开发者ID:tdgunes,项目名称:Spy-E,代码行数:30,代码来源:VertexBuffer.cpp

示例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();
			// }
		// }
	}
开发者ID:delfigamer,项目名称:mist,代码行数:26,代码来源:primitiveshape.cpp

示例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;
}
开发者ID:c0g,项目名称:FaceWarpApp,代码行数:60,代码来源:Fluids3DWindow.cpp

示例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);
		}

	}
}
开发者ID:PhoenixSteam,项目名称:Phoenix3D,代码行数:28,代码来源:PX2GeoObjFactory.cpp

示例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);
}
开发者ID:shgli,项目名称:GameEngine,代码行数:29,代码来源:ProjectPass.cpp

示例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);	
   
 }
开发者ID:Clever-Boy,项目名称:XLE,代码行数:29,代码来源:BasicRenderer.cpp

示例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);
	}
开发者ID:IMACoconut,项目名称:ImaKart,代码行数:27,代码来源:Skydome.cpp

示例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");
		}
	}
开发者ID:aminere,项目名称:VLADHeavyStrikePublic,代码行数:27,代码来源:EntityRenderer.cpp

示例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;
}
开发者ID:nbtdev,项目名称:teardrop,代码行数:26,代码来源:Submesh.cpp

示例12: VertexBuffer

VertexBuffer* VertexBufferManager::CreateVertexBuffer( const VertexSettings& Settings )
{
	VertexBuffer* pVertex = new VertexBuffer( Settings );
	pVertex->Init();
	mVBOs[ mVboCount++ ] = pVertex;
	return pVertex;
}
开发者ID:Kaaml,项目名称:Vxy,代码行数:7,代码来源:VBOManager.cpp

示例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);
		}

	}
}
开发者ID:JamShan,项目名称:Phoenix3D_2.1,代码行数:29,代码来源:PX2GeoObjFactory.cpp

示例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);
	}	
开发者ID:aminere,项目名称:VLADHeavyStrikePublic,代码行数:33,代码来源:PelletManager.cpp

示例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;
}
开发者ID:FloodProject,项目名称:flood,代码行数:34,代码来源:RenderDevice.cpp


注:本文中的VertexBuffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。