• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ VertexBufferPtr类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中VertexBufferPtr的典型用法代码示例。如果您正苦于以下问题:C++ VertexBufferPtr类的具体用法?C++ VertexBufferPtr怎么用?C++ VertexBufferPtr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了VertexBufferPtr类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: _updateRays

    void UnderWaterGodRay::_updateRays()
    {
        Camera * cam = World::Instance()->MainCamera();
        const Vec3 * corner = cam->GetCorner();
        float FarWidth   = (corner[4] - corner[5]).Length();
        float RaysLength = cam->GetFarClip();

        VertexBufferPtr vb = mRender.vxStream.GetStream(0);
        Vec3 * vert = (Vec3*)vb->Lock(0, 0, LOCK_DISCARD);

        Vec2 Pos;
        float Dis, RayLength;

        for(int k = 0; k < mNumberOfRays; k++)
        {
            Pos       = _calculateRayPosition(k);
            Dis       = mRaysSize * RaysLength;
            RayLength = RaysLength * (0.3f + Pos.Length());

            Pos *= FarWidth/2;

            // 4 Planes, 3 vertices each plane, 12 vertices per ray
            // ----> 1/4
            // 0
            *vert++ = Vec3(0, 0, 0);
            // A
            *vert++ = Vec3(Pos.x, Pos.y, -RayLength);
            // B
            *vert++ = Vec3(Pos.x+Dis, Pos.y, -RayLength);
            // ----> 2/4
            // 0
            *vert++ = Vec3(0, 0, 0);
            // D
            *vert++ = Vec3(Pos.x+Dis, Pos.y+Dis, -RayLength);
            // B
            *vert++ = Vec3(Pos.x+Dis, Pos.y, -RayLength);
            // ----> 3/4
            // 0
            *vert++ = Vec3(0, 0, 0);
            // C
            *vert++ = Vec3(Pos.x, Pos.y+Dis, -RayLength);
            // D
            *vert++ = Vec3(Pos.x+Dis, Pos.y+Dis, -RayLength);
            // ----> 4/4
            // 0
            *vert++ = Vec3(0, 0, 0);
            // C
            *vert++ = Vec3(Pos.x, Pos.y+Dis, -RayLength);
            // A
            *vert++ = Vec3(Pos.x, Pos.y, -RayLength);
        }

        vb->Unlock();
    }
开发者ID:ak4hige,项目名称:myway3d,代码行数:54,代码来源:MWUnderWater.cpp


示例2: CreateRect2D

    i32 CreateRect2D(Resources::CMesh* pMesh, const IInputLayout* pIL, const SRect2DOptions& Opts)
    {
        Vec3 vecScale( 100 ); 
        Vec2 vecWidth( 0, 100 );
        Vec2 vecHeight( 0, 100 );

        IndexBufferPtr pIB = pMesh->CreateIndexBuffer();
        VertexBufferPtr pVB = pMesh->CreateVertexBuffer();

        pVB->SetVertexCount( 4 );
        pVB->SetInputLayout( pIL );
        pVB->SetTopologyType( TopologyTypes::TRIANGLE_LIST );
        pVB->SetUsage( Opts.eUsage );

        pIB->SetIndexCount( 6 );
        pIB->SetUsage( BufferUsages::STATIC );

        pVB->Lock();
        CVertexData& VData = pVB->GetVertexData();

        if( pIL->IsPosition() )
        {
            VData.SetPosition( 0, Vec3( 0,			0,				0 ) );
            VData.SetPosition( 1, Vec3( vecScale.x, 0,				0 ) );
            VData.SetPosition( 2, Vec3( vecScale.x, -vecScale.y,	0 ) );
            VData.SetPosition( 3, Vec3( 0,			-vecScale.y,	0) );
        }

        if( pIL->IsColor() )
        {
            VData.SetColor( 0, Vec4( 1, 1, 1, 1 ) );
            VData.SetColor( 1, Vec4( 1, 1, 1, 1 ) );
            VData.SetColor( 2, Vec4( 1, 1, 1, 1 ) );
            VData.SetColor( 3, Vec4( 1, 1, 1, 1 ) );
        }

        if( pIL->IsTexCoord0() )
        {
            VData.SetTexCoord( 0, 0, Vec2( 0, 1 ) );
            VData.SetTexCoord( 1, 0, Vec2( 1, 1 ) );
            VData.SetTexCoord( 2, 0, Vec2( 0, 1 ) );
            VData.SetTexCoord( 3, 0, Vec2( 0, 0 ) );
        }

        pVB->Unlock();
        pVB->Create();

        pIB->Lock();
        CIndexData& IData = pIB->GetIndexData();

        IData.SetTriangle( 0, 0, 2, 3 );
        IData.SetTriangle( 1, 1, 2, 0 );

        return XST_OK;
    }
开发者ID:przemyslaw-szymanski,项目名称:x-source-engine,代码行数:55,代码来源:XSECMeshManager.cpp


示例3: sizeof

void MeshLoader_v0::ReadVertexStream(VertexBufferPtr & vb, int & stride, int count, DataStreamPtr & stream)
{
    EXCEPTION_DEBUG(vb.IsNull(), "model file error.");

    stream->Read(&stride, sizeof(int));

    vb = VideoBufferManager::Instance()->CreateVertexBuffer(stride * count, stride);
    
    void * data = vb->Lock(0, 0, LOCK_DISCARD);

    stream->Read(data, stride * count);

    vb->Unlock();
}
开发者ID:ak4hige,项目名称:myway3d,代码行数:14,代码来源:MWMeshLoader.cpp


示例4: _createGodRays

    void UnderWaterGodRay::_createGodRays()
    {
        VertexStream * vxStream = &mRender.vxStream;
        IndexStream * ixStream = &mRender.ixStream;

        int iVertexCount = mNumberOfRays * 12;
        int iIndexCount = mNumberOfRays * 12;
        int iPrimCount = iIndexCount / 3;
        int iStride = 12;

        VertexDeclarationPtr decl = VideoBufferManager::Instance()->CreateVertexDeclaration();
        decl->AddElement(0, 0, DT_FLOAT3, DU_POSITION, 0);
        decl->Init();

        vxStream->SetDeclaration(decl);

        VertexBufferPtr vb = VideoBufferManager::Instance()->CreateVertexBuffer(iVertexCount * 20, 20, USAGE_DYNAMIC);
        IndexBufferPtr ib = VideoBufferManager::Instance()->CreateIndexBuffer(iIndexCount * sizeof(short));

        float * vert = (float *)vb->Lock(0, 0, LOCK_NORMAL);
        short * idx = (short *)ib->Lock(0, 0, LOCK_NORMAL);

        int index = 0;
        for (int j = 0; j < mNumberOfRays; ++j)
        {
            for (int i = 0; i < 12; ++i)
            {
                *vert++ = 0; *vert++ = 0; *vert++ = 0;
                *idx++ = index++; 
            }
        }

        vb->Unlock();
        ib->Unlock();

        vxStream->Bind(0,vb, iStride);
        vxStream->SetCount(iVertexCount);

        ixStream->Bind(ib, 0);
        ixStream->SetCount(iIndexCount);

        mRender.iPrimCount = iPrimCount;
        mRender.ePrimType = PRIM_TRIANGLELIST;
        mRender.rState.blendMode = BM_ADD;
        mRender.rState.cullMode = CULL_NONE;
        mRender.rState.fillMode = FILL_SOLID;
        mRender.rState.depthWrite = false;
        mRender.rState.depthCheck = DCM_NONE;
    }
开发者ID:ak4hige,项目名称:myway3d,代码行数:49,代码来源:MWUnderWater.cpp


示例5: createVertexArray

VertexArrayPtr RenderContext::createVertexArray(VertexDescription description, VertexBufferPtr buffer) {
  VertexArrayPtr vao = VertexArrayPtr(new VertexArray());
  vao->bind();
  buffer->bind();
  int offset = 0;
  for(VertexDescriptionElement e : description) {
    if(e.shaderAttribLocation() != -1) {
      glVertexAttribPointer(e.shaderAttribLocation(), e.numberOfComponents(), (int)e.type(), GL_FALSE, description.sizeInBytes(), (char*)nullptr + offset);
      glEnableVertexAttribArray(e.shaderAttribLocation());
    }
    offset += e.sizeInBytes();
  }
  buffer->release();
  vao->release();
  return vao;
}
开发者ID:aplars,项目名称:spiral,代码行数:16,代码来源:rendercontext.cpp


示例6: _geometry

    void Moon::_geometry()
    {
        VertexStream * vxStream = &mRender.vxStream;
        IndexStream * ixStream = &mRender.ixStream;

        int iVertexCount = 4;
        int iPrimCount = 2;

        VertexDeclarationPtr decl = VideoBufferManager::Instance()->CreateVertexDeclaration();
        decl->AddElement(0, 0, DT_FLOAT3, DU_POSITION, 0);
        decl->AddElement(0, 12, DT_FLOAT2, DU_TEXCOORD, 0);
        decl->Init();

        vxStream->SetDeclaration(decl);

        VertexBufferPtr vb = VideoBufferManager::Instance()->CreateVertexBuffer(iVertexCount * 20, 20);

        float * vert = (float *)vb->Lock(0, 0, LOCK_DISCARD);
        {
            float x = 0, y = 0, z = 0;

            *vert++ = x; *vert++ = y; *vert++ = z;
            *vert++ = 0; *vert++ = 0;

            *vert++ = x; *vert++ = y; *vert++ = z;
            *vert++ = 1; *vert++ = 0;

            *vert++ = x; *vert++ = y; *vert++ = z;
            *vert++ = 0; *vert++ = 1;

            *vert++ = x; *vert++ = y; *vert++ = z;
            *vert++ = 1; *vert++ = 1;
        }
        vb->Unlock();

        vxStream->Bind(0, vb, 20);
        vxStream->SetCount(iVertexCount);

        mRender.iPrimCount = iPrimCount;
        mRender.ePrimType = PRIM_TRIANGLESTRIP;

        mRender.rState.blendMode = BM_ALPHA_BLEND;
        mRender.rState.depthWrite = false;
        mRender.rState.depthCheck = DCM_LESS_EQUAL;
    }
开发者ID:ak4hige,项目名称:myway3d,代码行数:45,代码来源:MWMoon.cpp


示例7: _geom

    void UnderWaterBubble::_geom()
    {
        VertexStream * vxStream = &mRender.vxStream;

        VertexBufferPtr vb = vxStream->GetStream(0);

        float * v = (float *)vb->Lock(0, 0, LOCK_DISCARD);
        {
            List<Bubble>::Iterator whr = mBubbles.Begin();
            List<Bubble>::Iterator end = mBubbles.End();

            while (whr != end)
            {
                const Bubble & b = *whr;
                *v++ = b.position.x;
                *v++ = b.position.y;
                *v++ = b.position.z;
                *v++ = b.size;
                *v++ = b.alpha;

                *v++ = b.position.x;
                *v++ = b.position.y;
                *v++ = b.position.z;
                *v++ = b.size;
                *v++ = b.alpha;

                *v++ = b.position.x;
                *v++ = b.position.y;
                *v++ = b.position.z;
                *v++ = b.size;
                *v++ = b.alpha;

                *v++ = b.position.x;
                *v++ = b.position.y;
                *v++ = b.position.z;
                *v++ = b.size;
                *v++ = b.alpha;

                ++whr;
            }
        }
        vb->Unlock();

        mRender.iPrimCount = mBubbles.Size() * 2;
    }
开发者ID:ak4hige,项目名称:myway3d,代码行数:45,代码来源:MWUnderWater.cpp


示例8: updateGeometryData

	//-------------------------------------------------------------------------------//
	void OverlayPanelElement::updateGeometryData()
	{
		/*
			0-----2
			|    /|
			|  /  |
			|/    |
			1-----3
		*/
		Renderer* renderer = Root::getSingleton().getActiveRenderer();
		float offsetLeft = mLeft + renderer->getHorizontalTexelOffset() / OverlayMgr::getSingleton().getViewportWidth();
		float offsetTop = mTop + renderer->getVerticalTexelOffset() / OverlayMgr::getSingleton().getViewportHeight();
		float left, right, top, bottom;
		left = offsetLeft * 2 - 1;
		right = left + mWidth * 2;
		top = -((offsetTop * 2) - 1);
		bottom = top - mHeight * 2;

		VertexBufferPtr vbuf = mRenderData.vertexData->vertexBufferBinding->getBuffer(0);

		float* pPos = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));

		float zValue = Root::getSingleton().getActiveRenderer()->getMaxDepthValue();
		*pPos++ = left;
		*pPos++ = top;
		*pPos++ = zValue;

		*pPos++ = left;
		*pPos++ = bottom;
		*pPos++ = zValue;

		*pPos++ = right;
		*pPos++ = top;
		*pPos++ = zValue;

		*pPos++ = right;
		*pPos++ = bottom;
		*pPos++ = zValue;

		vbuf->unlock();

		
	}
开发者ID:cty41,项目名称:Titan,代码行数:44,代码来源:TiOverlayPanelElement.cpp


示例9: updateTexData

	//-------------------------------------------------------------------------------//
	void OverlayPanelElement::updateTexData()
	{
		if(!mTexture.isNull() &&mIsInitialised)
		{
			VertexDeclaration* decl = mRenderData.vertexData->vertexDecl;
			if(mTexCoordNum == 0)
			{
				decl->addElement(1, 0,VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);

				VertexBufferPtr vbuf = HardwareBufferMgr::getSingletonPtr()->createVertexBuffer(decl->getVertexSize(1), mRenderData.vertexData->vertexCount,
					HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);

				mRenderData.vertexData->vertexBufferBinding->setBinding(1,vbuf);
				mTexCoordNum = 1;
			}

			if(mTexCoordNum)
			{
				VertexBufferPtr buf = mRenderData.vertexData->vertexBufferBinding->getBuffer(1);
				float* pVBStart = static_cast<float*>(buf->lock(HardwareBuffer::HBL_DISCARD));

				size_t uvSize = VertexElement::getTypeSize(VET_FLOAT2) / sizeof(float);
				size_t vertexSize = decl->getVertexSize(1) / sizeof(float);
				
				float* pTex = pVBStart;

				pTex[0] = mU1;	pTex[1] = mV1;
				pTex += vertexSize;

				pTex[0] = mU1;	pTex[1] = mV2;
				pTex += vertexSize;
				
				pTex[0] = mU2;	pTex[1] = mV1;
				pTex += vertexSize;

				pTex[0] = mU2;	pTex[1] = mV2;

				buf->unlock();
			}
			
		}
	}
开发者ID:cty41,项目名称:Titan,代码行数:43,代码来源:TiOverlayPanelElement.cpp


示例10: unpack

std::shared_ptr<render::VertexBuffer>
GeometryParser::deserializeVertexBuffer(std::string&                                serializedVertexBuffer,
                                        std::shared_ptr<render::AbstractContext>    context)
{
    msgpack::type::tuple<std::string, std::vector<SerializeAttribute>>	deserializedVertex;

    unpack(deserializedVertex, serializedVertexBuffer.data(), serializedVertexBuffer.size());

    std::vector<float>		vector			= deserialize::TypeDeserializer::deserializeVector<float>(deserializedVertex.get<0>());
    VertexBufferPtr			vertexBuffer	= render::VertexBuffer::create(context, vector);

    uint numAttributes = deserializedVertex.get<1>().size();

    for (unsigned int attributesIndex = 0; attributesIndex < numAttributes; ++attributesIndex)
        vertexBuffer->addAttribute(
            deserializedVertex.get<1>()[attributesIndex].get<0>(),
            deserializedVertex.get<1>()[attributesIndex].get<1>(),
            deserializedVertex.get<1>()[attributesIndex].get<2>());

    return vertexBuffer;
}
开发者ID:nonconforme,项目名称:minko,代码行数:21,代码来源:GeometryParser.cpp


示例11: OnRender

SkinRenderer::SkinRenderer()
	: OnRender(RenderEvent::OnRenderGUI2, this, &SkinRenderer::Render)
{
	msInstance = this;

	mEnable = false;

	mRenderOp = new RenderOp;

	VertexDeclarationPtr vdecl = VideoBufferManager::Instance()->CreateVertexDeclaration();
	vdecl->AddElement(0, 0, DT_FLOAT2, DU_POSITION, 0);
	vdecl->Init();

	mRenderOp->vxStream.SetDeclaration(vdecl);

	VertexBufferPtr vb = VideoBufferManager::Instance()->CreateVertexBuffer(8 * 4, 8);

	float * vert = (float *)vb->Lock(0, 0, LOCK_NORMAL);
	{
		*vert++ = 0; *vert++ = 0;
		*vert++ = 1; *vert++ = 0;
		*vert++ = 0; *vert++ = 1;
		*vert++ = 1; *vert++ = 1;
	}
	vb->Unlock();

	mRenderOp->vxStream.Bind(0, vb);
	mRenderOp->vxStream.SetCount(4);

	mRenderOp->rState.depthCheck = DCM_NONE;
	mRenderOp->rState.depthWrite = false;
	mRenderOp->ePrimType = PRIM_TRIANGLESTRIP;
	mRenderOp->iPrimCount = 2;
	
	mTech = App::Instance()->GetShaderLib()->GetTechnique("SkinRenderer");

	d_assert (mTech != NULL);

	mBackTexture = VideoBufferManager::Instance()->Load2DTexture("BackgroundTile.png", "BackgroundTile.png");
}
开发者ID:ak4hige,项目名称:myway3d,代码行数:40,代码来源:SkinRenderer.cpp


示例12: CreateCircle

    i32 CreateCircle( Resources::CMesh* pMesh, const IInputLayout* pIL, const SCircleOptions& Options )
    {
        xst_vector< Vec3 > vPoints;
        f32 fAngle = 0.0f;
        for( u32 i = 0; i <= 360; i += Options.uStep )
        {
            fAngle = XST::Math::DegreesToRadians( (f32)i );
            vPoints.push_back( Vec3( XST::Math::Cos( fAngle ) * Options.fRadius, XST::Math::Sin( fAngle ) * Options.fRadius, 0.0f ) );
        }

        bool bIsNormal = pIL->IsNormal();
        ul32 ulVertCount = vPoints.size();
        VertexBufferPtr pVB = pMesh->CreateVertexBuffer();

        pVB->SetTopologyType( TopologyTypes::LINE_STRIP );
        pVB->SetUsage( BufferUsages::DEFAULT );
        pVB->SetVertexCount( ulVertCount );
        pVB->SetInputLayout( pIL );

        if( XST_FAILED( pVB->Lock() ) )
        {
            return XST_FAIL;
        }

        CVertexData& Data = pVB->GetVertexData();

        ul32 vs = pIL->GetVertexSize();

        for( u32 i = 0; i < vPoints.size(); ++i )
        {
            if( pIL->IsPosition() )
            {
                Data.SetPosition( i, vPoints[ i ] + Options.vecPos );
            }
        }

        if( XST_FAILED( pVB->Unlock() ) || XST_FAILED( pVB->Create() ) )
        {
            return XST_FAIL;
        }

        return XST_OK;
    }
开发者ID:przemyslaw-szymanski,项目名称:x-source-engine,代码行数:43,代码来源:XSECMeshManager.cpp


示例13: bindAttribWithVertexBuffer

 bool Model::bindAttribWithVertexBuffer(const char *name, VertexBufferPtr &vertices, bool overWrite)
 {
     int location;
     std::map<std::string, int>::iterator it = _locations.find(name);
     if (it != _locations.end())
     {
         location = it->second;
     }else{
         location = _shaderProgram->getAttribLocation(name);
         if (location < 1)
         {
             printf("can't find attrib : %s", name);
             return false;
         }
         _locations.insert(std::map<std::string, int>::value_type(name, location));
     }
     vertices->bindToAttribLocation(location);
     _attribs.push_back(vertices);
     _isDirty = true;
     return true;
 }
开发者ID:gustplus,项目名称:GPengine,代码行数:21,代码来源:GPModel.cpp


示例14: RenderOp

void xObjBound::Init(Event * sender)
{
	mRenderAABB = new RenderOp();

	VertexStream * vxStream = &mRenderAABB->vxStream;
	IndexStream * ixStream = &mRenderAABB->ixStream;

	int iVertexCount = 8;
	int iIndexCount = 12 * 2;
	int iPrimCount = 12;

	VertexDeclarationPtr decl = VideoBufferManager::Instance()->CreateVertexDeclaration();
	decl->AddElement(0, 0, DT_FLOAT3, DU_POSITION, 0);
	decl->Init();

	vxStream->SetDeclaration(decl);

	VertexBufferPtr vb = VideoBufferManager::Instance()->CreateVertexBuffer(iVertexCount * 12, 12);

	float * vert = (float *)vb->Lock(0, 0, LOCK_DISCARD);
	{
		const float half_w = 0.5f;
		const float half_h = 0.5f;
		const float half_d = 0.5f;
		Vec3 pos;

		//front
		pos = Vec3(-half_w, half_h, -half_d);
		*vert++ = pos.x;
		*vert++ = pos.y;
		*vert++ = pos.z;

		pos = Vec3(half_w, half_h, -half_d);
		*vert++ = pos.x;
		*vert++ = pos.y;
		*vert++ = pos.z;

		pos = Vec3(-half_w, -half_h, -half_d);
		*vert++ = pos.x;
		*vert++ = pos.y;
		*vert++ = pos.z;

		pos = Vec3(half_w, -half_h, -half_d);
		*vert++ = pos.x;
		*vert++ = pos.y;
		*vert++ = pos.z;

		//back
		pos = Vec3(-half_w, half_h, half_d);
		*vert++ = pos.x;
		*vert++ = pos.y;
		*vert++ = pos.z;

		pos = Vec3(half_w, half_h, half_d);
		*vert++ = pos.x;
		*vert++ = pos.y;
		*vert++ = pos.z;

		pos = Vec3(-half_w, -half_h, half_d);
		*vert++ = pos.x;
		*vert++ = pos.y;
		*vert++ = pos.z;

		pos = Vec3(half_w, -half_h, half_d);
		*vert++ = pos.x;
		*vert++ = pos.y;
		*vert++ = pos.z;
	}
	vb->Unlock();

	vxStream->Bind(0, vb, 12);
	vxStream->SetCount(iVertexCount);

	IndexBufferPtr ibuffer = VideoBufferManager::Instance()->CreateIndexBuffer(iIndexCount * sizeof(short));
	short * indices = (short *)ibuffer->Lock(0, 0, LOCK_DISCARD);
	{
		*indices++ = 0, *indices++ = 1;
		*indices++ = 2, *indices++ = 3;
		*indices++ = 0, *indices++ = 2;
		*indices++ = 1, *indices++ = 3;

		*indices++ = 4, *indices++ = 5;
		*indices++ = 6, *indices++ = 7;
		*indices++ = 4, *indices++ = 6;
		*indices++ = 5, *indices++ = 7;

		*indices++ = 0, *indices++ = 4;
		*indices++ = 1, *indices++ = 5;
		*indices++ = 2, *indices++ = 6;
		*indices++ = 3, *indices++ = 7;
	}
	ibuffer->Unlock();

	ixStream->SetCount(iIndexCount);
	ixStream->Bind(ibuffer, 0);

	mRenderAABB->iPrimCount = iPrimCount;
	mRenderAABB->ePrimType = PRIM_LINELIST;

	mRenderAABB->rState.cullMode = CULL_NONE;
//.........这里部分代码省略.........
开发者ID:ak4hige,项目名称:myway3d,代码行数:101,代码来源:xObjBound.cpp


示例15: d_assert

	Mesh * PS_MeshSet::_createCone(bool up)
	{
		Float3 offset = mCenter;
		int rings = (mRings + 3) / 4;
		int segments = mSegments;
		float radius = mRadius;
		float height = mHeight;

		if (rings < 1)
			return NULL;

		Mesh * pMesh = new Mesh;
		SubMesh * sm = pMesh->NewSubMesh();

		float h1 = up ? 0 : height;
		float h2 = up ? height : 0;

		int iVertexCount = 1 + (rings * 4 + 1);
		int iIndexCount = rings * 4 * 3;
		int iPrimCount = iIndexCount / 3;

		d_assert(iIndexCount < 65536);

		sm->GetRenderOp()->vertexDeclarations[0].AddElement(eVertexSemantic::POSITION, eVertexType::FLOAT3);
		sm->GetRenderOp()->vertexDeclarations[0].AddElement(eVertexSemantic::TEXCOORD0, eVertexType::FLOAT2);

		VertexBufferPtr buffer = HWBufferManager::Instance()->NewVertexBuffer(20, iVertexCount);

		float * vert = (float *)buffer->Lock(eLockFlag::WRITE);
		{
			float r_step = (PI2 / (rings * 4));
			float d_step = (radius * 2 / rings);
			float u_step = 1 / (float)rings;
			float v_step = u_step;
			float x, z;
			float rads = -PI * 0.25f;

			*vert++ = 0 + offset.x;
			*vert++ = h1 + offset.x;
			*vert++ = 0 + offset.z;
			*vert++ = 0.5f;
			*vert++ = 0.5f;

			// top
			for (int i = 0; i <= rings; ++i)
			{
				Math::SinCos(rads, z, x);

				x *= radius;
				z *= radius;

				*vert++ = x + offset.x;
				*vert++ = h2 + offset.y;
				*vert++ = z + offset.z;
				*vert++ = i * u_step;
				*vert++ = 0;

				rads += r_step;
			}

			// right
			for (int i = 1; i <= rings; ++i)
			{
				Math::SinCos(rads, z, x);

				x *= radius;
				z *= radius;

				*vert++ = x + offset.x;
				*vert++ = h2 + offset.y;
				*vert++ = z + offset.z;
				*vert++ = 1;
				*vert++ = i * v_step;

				rads += r_step;
			}

			// bottom
			for (int i = 1; i <= rings; ++i)
			{
				Math::SinCos(rads, z, x);

				x *= radius;
				z *= radius;

				*vert++ = x + offset.x;
				*vert++ = h2 + offset.y;
				*vert++ = z + offset.z;
				*vert++ = 1 - i * u_step;
				*vert++ = 1;

				rads += r_step;
			}

			// left
			for (int i = 1; i <= rings; ++i)
			{
				Math::SinCos(rads, z, x);

				x *= radius;
//.........这里部分代码省略.........
开发者ID:MSoft1115,项目名称:Rad3D,代码行数:101,代码来源:PSMeshSet.cpp


示例16: CreateBox

    i32 CreateBox(Resources::CMesh* pMesh, const IInputLayout* pIL, const SBoxOptions& Options)
    {
        bool bIsNormal = pIL->IsNormal();
        ul32 ulVertCount = ( bIsNormal )? 24 : 8; //if there are normals use more vertices
        ul32 ulIndexCount = 36;
        VertexBufferPtr pVB = pMesh->CreateVertexBuffer();
        
        pVB->SetTopologyType( TopologyTypes::TRIANGLE_LIST );
        pVB->SetUsage( BufferUsages::DEFAULT );
        pVB->SetVertexCount( ulVertCount );
        pVB->SetInputLayout( pIL );

        pVB->Lock();

        CVertexData& Data = pVB->GetVertexData();

        cf32 fUnit = 1.0f;
        ul32 vs = pIL->GetVertexSize();
        const Vec3 vecSize( Options.vecSize * 0.5f );
        const Vec3 vecPos( vecSize + Options.vecPos );

        if( pIL->IsPosition() )
        {
            if( bIsNormal )
            {
                Data.SetPosition( 0, Vec3( -vecSize.x, vecSize.y, -vecSize.z ) + Options.vecPos );
                Data.SetPosition( 1, Vec3( vecSize.x, vecSize.y, -vecSize.z ) + Options.vecPos ); 
                Data.SetPosition( 2, Vec3( vecSize.x, vecSize.y, vecSize.z ) + Options.vecPos  ); 
                Data.SetPosition( 3, Vec3( -vecSize.x, vecSize.y, vecSize.z ) + Options.vecPos );

                Data.SetPosition( 4, Vec3( -vecSize.x, -vecSize.y, vecSize.z ) + Options.vecPos );
                Data.SetPosition( 5, Vec3( -vecSize.x, -vecSize.y, -vecSize.z ) + Options.vecPos ); 
                Data.SetPosition( 6, Vec3( -vecSize.x, vecSize.y, -vecSize.z ) + Options.vecPos ); 
                Data.SetPosition( 7, Vec3( -vecSize.x, vecSize.y, vecSize.z ) + Options.vecPos );

                Data.SetPosition( 8, Vec3( vecSize.x, -vecSize.y, vecSize.z ) + Options.vecPos ); 
                Data.SetPosition( 9, Vec3( vecSize.x, -vecSize.y, -vecSize.z ) + Options.vecPos ); 
                Data.SetPosition( 10, Vec3( vecSize.x, vecSize.y, -vecSize.z ) + Options.vecPos ); 
                Data.SetPosition( 11, Vec3( vecSize.x, vecSize.y, vecSize.z ) + Options.vecPos ); 

                Data.SetPosition( 12, Vec3( -vecSize.x, -vecSize.y, -vecSize.z ) + Options.vecPos ); 
                Data.SetPosition( 13, Vec3( vecSize.x, -vecSize.y, -vecSize.z ) + Options.vecPos );
                Data.SetPosition( 14, Vec3( vecSize.x, vecSize.y, -vecSize.z ) + Options.vecPos ); 
                Data.SetPosition( 15, Vec3( -vecSize.x, vecSize.y, -vecSize.z ) + Options.vecPos );

                Data.SetPosition( 16, Vec3( -vecSize.x, -vecSize.y, vecSize.z ) + Options.vecPos );
                Data.SetPosition( 17, Vec3( vecSize.x, -vecSize.y, vecSize.z ) + Options.vecPos );
                Data.SetPosition( 18, Vec3( vecSize.x, vecSize.y, vecSize.z ) + Options.vecPos  ); 
                Data.SetPosition( 19, Vec3( -vecSize.x, vecSize.y, vecSize.z ) + Options.vecPos ); 

                Data.SetPosition( 20, Vec3( -vecSize.x, -vecSize.y, -vecSize.z ) + Options.vecPos ); 
                Data.SetPosition( 21, Vec3( vecSize.x, -vecSize.y, -vecSize.z ) + Options.vecPos ); 
                Data.SetPosition( 22, Vec3( vecSize.x, -vecSize.y, vecSize.z ) + Options.vecPos ); 
                Data.SetPosition( 23, Vec3( -vecSize.x, -vecSize.y, vecSize.z ) + Options.vecPos ); 
                
            }
            else
            {
                Data.SetPosition( 0, Vec3( -vecSize.x, vecSize.y, -vecSize.z ) + Options.vecPos ); 
                Data.SetPosition( 1, Vec3( vecSize.x, vecSize.y, -vecSize.z ) + Options.vecPos ); 
                Data.SetPosition( 2, Vec3( vecSize.x, vecSize.y, vecSize.z ) + Options.vecPos ); 
                Data.SetPosition( 3, Vec3( -vecSize.x, vecSize.y, vecSize.z ) + Options.vecPos ); 
                Data.SetPosition( 4, Vec3( -vecSize.x, -vecSize.y, -vecSize.z ) + Options.vecPos ); 
                Data.SetPosition( 5, Vec3( vecSize.x, -vecSize.y, -vecSize.z ) + Options.vecPos ); 
                Data.SetPosition( 6, Vec3( vecSize.x, -vecSize.y, vecSize.z ) + Options.vecPos ); 
                Data.SetPosition( 7, Vec3( -vecSize.x, -vecSize.y, vecSize.z ) + Options.vecPos ); 
            }
        }

        if( pIL->IsColor() )
        {
            f32 fc = 0.05f;
            for(ul32 i = 0; i < ulVertCount; ++i)
            {
                /*Data.SetColor( 0, Vec4( 1, 0, 0, 1 ) ); 
                Data.SetColor( 1, Vec4( 1, 1, 1, 1 ) ); 
                Data.SetColor( 2, Vec4( 0, 1, 0, 1 ) ); 
                Data.SetColor( 3, Vec4( 0.5, 0.3, 1, 1 ) ); */
                Data.SetColor( i, Options.colColor.ToVector4() ); 
            }
        }

        if( bIsNormal )
        {
            Data.SetNormal( 0, Vec3( -1, 1, -1 ) ); 
            Data.SetNormal( 1, Vec3( 1, 1, -1 ) ); 
            Data.SetNormal( 2, Vec3( 1, 1, 1 ) ); 
            Data.SetNormal( 3, Vec3( -1, 1, 1 ) ); 
            Data.SetNormal( 4, Vec3( -1, -1, -1 ) ); 
            Data.SetNormal( 5, Vec3( 1, -1, -1 ) ); 
            Data.SetNormal( 6, Vec3( 1, -1, 1 ) ); 
            Data.SetNormal( 7, Vec3( -1, -1, 1 ) ); 
        }

        pVB->Unlock();
        pVB->Create();

        IndexBufferPtr pIB = pMesh->CreateIndexBuffer();
        pIB->SetUsage( BufferUsages::DEFAULT );
        pIB->SetIndexCount( ulIndexCount );
//.........这里部分代码省略.........
开发者ID:przemyslaw-szymanski,项目名称:x-source-engine,代码行数:101,代码来源:XSECMeshManager.cpp


示例17: _genMesh

	void MeshGroup::_genMesh(const Array<Mesh *> & arr, int first, int last, bool hasLightingColor)
	{
		MeshSourcePtr source = arr[0]->GetSource();
		Mesh * mesh = new Mesh;

		for (int i = 0; i < source->GetMeshBufferCount(); ++i)
		{
			SubMesh * submesh = mesh->NewSubMesh();
			VertexBufferPtr srcVB = source->GetMeshBuffer(i)->GetRenderOp()->vertexBuffers[0];
			IndexBufferPtr srcIB = source->GetMeshBuffer(i)->GetRenderOp()->indexBuffer;
			int p_offset = source->GetMeshBuffer(i)->GetRenderOp()->vertexDeclarations[0].GetElementOffset(eVertexSemantic::POSITION);
			int n_offset = source->GetMeshBuffer(i)->GetRenderOp()->vertexDeclarations[0].GetElementOffset(eVertexSemantic::NORMAL);
			int stride = srcVB->GetStride();

			VertexBufferPtr vb = HWBufferManager::Instance()->NewVertexBuffer(stride, srcVB->GetCount() * (last - first));
			
			const char * v_src = (const char *)srcVB->Lock(eLockFlag::READ);
			char * v_dest = (char *)vb->Lock(eLockFlag::WRITE);
			for (int j = first; j < last; ++j)
			{
				const Mat4 & worldTM = arr[j]->GetWorldTM();
				bool hasScale = arr[j]->GetWorldScale() != Float3(1, 1, 1);

				for (int k = 0; k < srcVB->GetCount(); ++k)
				{
					memcpy(v_dest, v_src, stride);

					Float3 * position = (Float3 *)(v_dest + p_offset);
					position->TransformA(worldTM);
					
					if (n_offset != -1)
					{
						Float3 * normal = (Float3 *)(v_dest + n_offset);
						normal->TransformN(worldTM);

						if (hasScale)
						{
							normal->Normalize();
						}
					}

					v_dest += stride;
					v_src += stride;
				}
			}
			vb->Unlock();
			srcVB->Unlock();

			IndexBufferPtr ib = HWBufferManager::Instance()->NewIndexBuffer(srcIB->GetCount() * (last - first));

			int startVertex = 0;
			const short * i_src = (const short *)srcIB->Lock(eLockFlag::READ);
			char * i_dest = (char *)ib->Lock(eLockFlag::WRITE);
			for (int j = first; j < last; ++j)
			{
				for (int k = 0; k < srcIB->GetCount(); ++k)
				{
					*i_dest++ = (*i_src++) + startVertex;
				}

				startVertex += srcVB->GetCount();
			}
			ib->Unlock();
			srcIB->Unlock();
			
			submesh->GetRenderOp()->vertexDeclarations[0] = source->GetMeshBuffer(i)->GetRenderOp()->vertexDeclarations[0];
			submesh->GetRenderOp()->vertexBuffers[0] = vb;
			submesh->GetRenderOp()->indexBuffer = ib;
			submesh->GetRenderOp()->primCount = ib->GetCount() / 3;
			submesh->GetRenderOp()->primType = ePrimType::TRIANGLE_LIST;

			if (hasLightingColor)
			{
				int count = submesh->GetRenderOp()->vertexBuffers[0]->GetCount();
				submesh->GetRenderOp()->vertexDeclarations[LIGHTING_COLOR_STREAM].AddElement(eVertexSemantic::LIGHTING_COLOR, eVertexType::UBYTE4);
				submesh->GetRenderOp()->vertexBuffers[LIGHTING_COLOR_STREAM] = HWBufferManager::Instance()->NewVertexBuffer(4, count);

				Array<Rgba32> lightColors;
				Rgba32 * data = (Rgba32 *)submesh->GetRenderOp()->vertexBuffers[LIGHTING_COLOR_STREAM]->Lock(eLockFlag::WRITE);
				for (int j = first; j < last; ++j)
				{
					arr[j]->GetLightingColor(lightColors);
					d_assert (lightColors.Size() > 0);

					memcpy(data, &lightColors[0], 4 * count);

					startVertex += count;
					lightColors.Clear();
				}
				submesh->GetRenderOp()->vertexBuffers[LIGHTING_COLOR_STREAM]->Unlock();
			}

			*submesh->GetMaterial() = *source->GetMeshBuffer(i)->GetMaterial();

			submesh->SetMeshShader(source->GetMeshBuffer(i)->GetShader());
		}

		mesh->SetSLMode(hasLightingColor ? eStaticLightingMode::LIGHTING_COLOR : eStaticLightingMode::NONE);

		mMeshes.PushBack(mesh);
//.........这里部分代码省略.........
开发者ID:MSoft1115,项目名称:Rad3D,代码行数:101,代码来源:MMeshGroup.cpp


示例18: _initMat

	void MActorRes::_init()
	{
		_initMat();

		int iVertexCount = 0, iIndexCount = 0;
		mAabb = Aabb::Zero;

		//int numBoneForPrim = (DeviceCaps::Instance()->MaxVertexShaderConst() - K_NumNoSkinShaderConst) / 3;
		int numBoneForPrim = 50;

		MCore::Array<EMotionFX::HwShaderBuffer> hwShaderBufferArray;
		mActor->GenerateHardwareShaderBuffers(hwShaderBufferArray, 0, numBoneForPrim);

		mMeshCount = hwShaderBufferArray.Size();
		mMeshes = new SMesh[mMeshCount];

		for (int i = 0; i < mMeshCount; ++i)
		{
			EMotionFX::HwShaderBuffer & buffer = hwShaderBufferArray[i];

			int iVertexCount = buffer.GetNumVertices();
			bool skined = buffer.GetNumInfluences() > 0;
			int iStride = skined ? sizeof(VertexSkined) : sizeof(Vertex);

			VertexBufferPtr vb = VideoBufferManager::Instance()->CreateVertexBuffer(iStride * iVertexCount, iStride);

			void * vert = vb->Lock(0, 0, LOCK_DISCARD);

			if (skined)
				_fillVertexSkined(vert, buffer);
			else
				_fillVertexNoSkined(vert, buffer);
			
			vb->Unlock();

			int iIndexCount = buffer.GetNumIndices();
			d_assert(iIndexCount <= 65535);

			IndexBufferPtr ib = VideoBufferManager::Instance()->CreateIndexBuffer(sizeof(short) * iIndexCount);

			unsigned short * idx = (unsigned short *)ib->Lock(0, 0, LOCK_DISCARD);
			for (int k = 0; k < iIndexCount; ++k)
			{
				*idx++ = (unsigned short)buffer.GetIndex(k);
			}

			ib->Unlock();

			SMesh * smesh = &mMeshes[i];

			for (int b = 0; b < buffer.GetNumBones(); ++b)
			{
				smesh->BoneArray.PushBack(buffer.GetBone(b));
			}

			// update aabb
			for (int v = 0; v < iVertexCount; ++v)
			{
				EMotionFX::HwShaderVertex &	vtx		= buffer.GetVertex(v);
				EMotionFX::Mesh *			mesh	= vtx.GetMesh();
				MCore::Vector3 *			pPosAr	= mesh->GetPositions();
				const int					vtxNr	= vtx.GetVertexNumber();

				mAabb.Merge(Vec3(pPosAr[vtxNr].x, pPosAr[vtxNr].y, pPosAr[vtxNr].z));
			}

			const int numPrimitives = buffer.GetNumPrimitives();

			smesh->PrimCount = numPrimitives;
			smesh->Primitives = new SPrim[numPrimitives];

			for (int p=0; p<numPrimitives; ++p)
			{
				const EMotionFX::HwShaderPrimitive & bufferPrim	= buffer.GetPrimitive(p);
				SPrim & prim = smesh->Primitives[p];

				int StartVertex = bufferPrim.GetStartVertex();
				int NumVertices = bufferPrim.GetNumVertices();
				int StartIndex	= bufferPrim.GetStartIndex();
				int NumTriangles = bufferPrim.GetNumTriangles();

				prim.NodeId	= bufferPrim.GetNode()->GetID();
				prim.MaterialId	= bufferPrim.GetMaterialNr();
				
				prim.Rop.vxStream.SetDeclaration(MActorManager::Instance()->GetVertexDeclaration(skined));
				prim.Rop.vxStream.Bind(0, vb, iStride);
				prim.Rop.vxStream.SetStart(StartVertex);
				prim.Rop.vxStream.SetCount(NumVertices);

				prim.Rop.ixStream.Bind(ib, 0);
				prim.Rop.ixStream.SetStart(StartIndex);
				prim.Rop.ixStream.SetCount(iIndexCount);

				prim.Rop.iPrimCount = NumTriangles;
				prim.Rop.ePrimType = PRIM_TRIANGLELIST;

				SMtl * mtl = GetMaterial(prim.MaterialId);

				if (mtl->DoubleSide)
					prim.Rop.rState.cullMode = CULL_NONE;
//.........这里部分代码省略.........
开发者ID:ak4hige,项目名称:myway3d,代码行数:101,代码来源:MActorRes.cpp


示例19: mRenderColMesh

EntityBound::EntityBound()
	: mRenderColMesh(NULL)
{
	mRenderAABB = new RenderOp();

	int iVertexCount = 8;
	int iIndexCount = 12 * 2;
	int iPrimCount = 12;

	mRenderAABB->vertexDeclarations[0].AddElement(eVertexSemantic::POSITION, eVertexType::FLOAT3);

	VertexBufferPtr vb = HWBufferManager::Instance()->NewVertexBuffer(iVertexCount, sizeof(float) * 3);
	float * vert = (float *)vb->Lock(eLockFlag::WRITE);
	{
		const float half_w = 0.5f;
		const float half_h = 0.5f;
		const float half_d = 0.5f;
		Float3 pos;

		//front
		pos = Float3(-half_w, half_h, -half_d);
		*vert++ = pos.x;
		*vert++ = pos.y;
		*vert++ = pos.z;

		pos = Float3(half_w, half_h, -half_d);
		*vert++ = pos.x;
		*vert++ = pos.y;
		*vert++ = pos.z;

		pos = Float3(-half_w, -half_h, -half_d);
		*vert++ = pos.x;
		*vert++ = pos.y;
		*vert++ = pos.z;

		pos = Float3(half_w, -half_h, -half_d);
		*vert++ = pos.x;
		*vert++ = pos.y;
		*vert++ = pos.z;

		//back
		pos = Float3(-half_w, half_h, half_d);
		*vert++ = pos.x;
		*vert++ = pos.y;
		*vert++ = pos.z;

		pos = Float3(half_w, half_h, half_d);
		*vert++ = pos.x;
		*vert++ = pos.y;
		*vert++ = pos.z;

		pos = Float3(-half_w, -half_h, half_d);
		*vert++ = pos.x;
		*vert++ = pos.y;
		*vert++ = pos.z;

		pos = Float3(half_w, -half_h, half_d);
		*vert++ = pos.x;
		*vert++ = pos.y;
		*vert++ = pos.z;
	}
	vb->Unlock();
	mRenderAABB->vertexBuffers[0] = vb;

	IndexBufferPtr ibuffer = HWBufferManager::Instance()->NewIndexBuffer(iIndexCount * sizeof(short));
	short * indices = (short *)ibuffer->Lock(eLockFlag::WRITE);
	{
		*indices++ = 0, *indices++ = 1;
		*indices++ = 2, *indices++ = 3;
		*indices++ = 0, *indices++ = 2;
		*indices++ = 1, *indices++ = 3;

		*indices++ = 4, *indices++ = 5;
		*indices++ = 6, *indices++ = 7;
		*indices++ = 4, *indices++ = 6;
		*indices++ = 5, *indices++ = 7;

		*indices++ = 0, *indices++ = 4;
		*indices++ = 1, *indices++ = 5;
		*indices++ = 2, *indices++ = 6;
		*indices++ = 3, *indices++ = 7;
	}
	ibuffer->Unlock();
	mRenderAABB->indexBuffer = ibuffer;

	mRenderAABB->primCount = iPrimCount;
	mRenderAABB->primType = ePrimType::LINE_LIST;

	Editor::Instance()->E_NodeSelect += new cListener0<EntityBound>(this, &EntityBound::OnShapeSelectedChanged);
	World::Instance()->E_RenderSolid += new cListener0<EntityBound>(this, &EntityBound::OnRender);
}
开发者ID:MSoft1115,项目名称:Rad3D,代码行数:91,代码来源:EntityBound.cpp


示例20: CreatePlane

    i32 CreatePlane(Resources::CMesh* pMesh, const IInputLayout* pIL, const SPlaneOptions& Opts)
    {
        bool bIsNormal = pIL->IsNormal();
        u16 ulVVertCount = (u16)Opts.vecVertexCount.x;
        u16 ulHVertCount = (u16)Opts.vecVertexCount.y;
        ul32 ulVertCount = ulVVertCount * ulHVertCount;
        //ul32 ulIndexCount = 36;
        VertexBufferPtr pVB = pMesh->CreateVertexBuffer();
        pVB->SetInputLayout( pIL );
        
        pVB->SetTopologyType( TopologyTypes::TRIANGLE_STRIP );
        pVB->SetUsage( BufferUsages::DEFAULT );
        pVB->SetVertexCount( ulVertCount );
        pVB->SetInputLayout( pIL );

        pVB->Lock();

        CVertexData& Data = pVB->GetVertexData();

        cf32 fUnit = 1.0f;
        ul32 vs = pIL->GetVertexSize();
        Vec2 vecTC( Vec2::ZERO );
        Vec3 vecTmpPos;

        if( pIL->IsPosition() )
        {
            ul32 ulVertId = 0;
            Vec2 vecVertDist( Opts.vecSize.x / ( Opts.vecVertexCount.x - 1 ), Opts.vecSize.y / ( Opts.vecVertexCount.y - 1 ) );
            Vec2 vecPos( Vec2::ZERO );

            for(ul32 y = 0; y < ulVVertCount; ++y, vecPos.y += vecVertDist.y)
            {
                for(ul32 x = 0; x < ulHVertCount; ++x, vecPos.x += vecVertDist.x)
                {
                    vecTmpPos = Vec3( vecPos.x, 0, vecPos.y );
                    Data.SetPosition( ulVertId, vecTmpPos );
                    if( pIL->IsTexCoord0() )
                    {
                        vecTC. 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ VertexBufferState类代码示例发布时间:2022-05-31
下一篇:
C++ VertexBufferBinding类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap