コード例 #1
0
ファイル: VertexBuffer.cpp プロジェクト: VinTeohK/3DProject2
bool VertexBuffer::SetData(const Description& description, IndexVector* indices)
{
    // Release all old buffers
    SafeRelease(mVertexBuffer);
    SafeRelease(mIndexBuffer);
    mIndexCount = 0;

    // Setup index buffer
    if (indices != NULL)
    {
        if (!SetupIndexBuffer(indices, description.Usage))
        {
            MessageBox(NULL, "Failed to create index buffer", "Error", MB_OK | MB_ICONERROR);
            return false;
        }
    }

    // Setup vertex buffer
    if (!CreateBuffer(&mVertexBuffer, description, D3D10_BIND_VERTEX_BUFFER))
    {
        MessageBox(NULL, "Failed to create vertex buffer", "Error", MB_OK | MB_ICONERROR);
        return false;
    }

    // Set new buffer description
    mElementCount = description.ElementCount;
    mElementSize = description.ElementSize;
    mTopology = description.Topology;

    return true;
}
コード例 #2
0
ファイル: GPUData.cpp プロジェクト: nian0601/MagmaEngine
	void GPUData::UpdateBuffers(int aIndexCount, char* aIndexData, int aVertexCount, int aVertexStride, char* aVertexData, GPUContext& aGPUContext)
	{
		SetupIndexBuffer(aIndexCount, aIndexData, aGPUContext);
		SetupVertexBuffer(aVertexCount, aVertexData, aGPUContext);

		myIndexData->myNumberOfIndices = aIndexCount;
		myVertexData->myNumberOfVertices = aVertexCount;
		myVertexData->myStride = aVertexStride;
	}
コード例 #3
0
ファイル: GPUData.cpp プロジェクト: nian0601/MagmaEngine
	void GPUData::Init(EffectID aEffect, GPUContext& aGPUContext, AssetContainer& aAssetContainer)
	{
		InitInputLayout(aEffect, aGPUContext, aAssetContainer);

		InitVertexBuffer(myVertexData->myStride, D3D11_USAGE_IMMUTABLE, 0);
		InitIndexBuffer();

		SetupVertexBuffer(myVertexData->myNumberOfVertices, myVertexData->myVertexData, aGPUContext);
		SetupIndexBuffer(myIndexData->myNumberOfIndices, myIndexData->myIndexData, aGPUContext);

		myTechniqueName = "Render";
	}
コード例 #4
0
ファイル: GPUData.cpp プロジェクト: nian0601/MagmaEngine
	void GPUData::Init(EffectID aEffect, int aIndexCount, char* aIndexData
		, int aVertexCount, int aVertexStride, char* aVertexData, GPUContext& aGPUContext, AssetContainer& aAssetContainer)
	{
		InitInputLayout(aEffect, aGPUContext, aAssetContainer);

		InitVertexBuffer(aVertexStride, D3D11_USAGE_IMMUTABLE, 0);
		InitIndexBuffer();

		SetupIndexBuffer(aIndexCount, aIndexData, aGPUContext);
		SetupVertexBuffer(aVertexCount, aVertexData, aGPUContext);

		myTechniqueName = "Render";
	}
コード例 #5
0
ファイル: Terrain.cpp プロジェクト: nian0601/Spaceshooter
	void Terrain::CreateVertices()
	{
		CU::GrowingArray<VertexPosNormUV> vertices(myHeightMap->myWidth * myHeightMap->myDepth);
		CU::GrowingArray<int> indices(myHeightMap->myWidth * myHeightMap->myDepth * 6);

		for (int z = 0; z < myHeightMap->myDepth; ++z)
		{
			for (int x = 0; x < myHeightMap->myWidth; ++x)
			{
				VertexPosNormUV vertex;
				vertex.myPos.x = float(x) * mySize.x / float(myHeightMap->myWidth);
				vertex.myPos.y = myHeightMap->myData[z * myHeightMap->myWidth + x] * myHeight / 255.f; 
				vertex.myPos.z = float(z) * mySize.y / float(myHeightMap->myDepth);
				vertex.myUV.x = float(x) / float(myHeightMap->myWidth);
				vertex.myUV.y = float(z) / float(myHeightMap->myDepth);
				vertices.Add(vertex);
			}
		}

		CalcNormals(vertices);

		for (int z = 0; z < myHeightMap->myDepth - 1; ++z)
		{
			for (int x = 0; x < myHeightMap->myWidth - 1; ++x)
			{
				indices.Add(z * myHeightMap->myWidth + x);
				indices.Add(z * myHeightMap->myWidth + x + 1);
				indices.Add((z + 1) * myHeightMap->myWidth + x);

				indices.Add((z + 1) * myHeightMap->myWidth + x);
				indices.Add(z * myHeightMap->myWidth + x + 1);
				indices.Add((z + 1) * myHeightMap->myWidth + x + 1);
			}
		}

		SetupVertexBuffer(vertices.Size(), sizeof(VertexPosNormUV), reinterpret_cast<char*>(&vertices[0])
			, "Terrain::VertexBuffer");
		SetupIndexBuffer(indices.Size(), reinterpret_cast<char*>(&indices[0]), "Terrain::IndexBuffer");

		mySurfaces[0]->SetVertexCount(vertices.Size());
		mySurfaces[0]->SetIndexCount(indices.Size());
	}
コード例 #6
0
ファイル: Sprite.cpp プロジェクト: nian0601/Spaceshooter
void Prism::Sprite::CreateVertices()
{
	CU::GrowingArray<VertexPosUV> vertices(4);
	CU::GrowingArray<int> indices(6);

	float left = 0 - myHotspot.x;
	float right = left + mySize.x;
	float top = 0 + myHotspot.y;
	float bottom = top - mySize.y;

	VertexPosUV vert;
	vert.myPos = { left, top, 0.0f };
	vert.myUV = { 0.0f, 0.0f };
	vertices.Add(vert);

	vert.myPos = { right, bottom, 0.0f };
	vert.myUV = { 1.0f, 1.0f };
	vertices.Add(vert);

	vert.myPos = { left, bottom, 0.0f };
	vert.myUV = { 0.0f, 1.0f };
	vertices.Add(vert);

	vert.myPos = { right, top, 0.0f };
	vert.myUV = { 1.0f, 0.0f };
	vertices.Add(vert);


	indices.Add(0);
	indices.Add(1);
	indices.Add(2);

	indices.Add(0);
	indices.Add(3);
	indices.Add(1);

	SetupVertexBuffer(vertices.Size(), sizeof(VertexPosUV), reinterpret_cast<char*>(&vertices[0]), "Sprite::VertexBuffer");
	SetupIndexBuffer(indices.Size(), reinterpret_cast<char*>(&indices[0]), "Sprite::IndexBuffer");

	mySurfaces[0]->SetVertexCount(vertices.Size());
	mySurfaces[0]->SetIndexCount(indices.Size());
}
コード例 #7
0
ファイル: GPUData.cpp プロジェクト: nian0601/GfxEngine
	void GPUData::Init(EffectID aEffect, int aIndexCount, char* aIndexData, int aVertexCount, int aVertexStride, char* aVertexData)
	{
		const int size = myVertexFormat.Size();
		D3D11_INPUT_ELEMENT_DESC* vertexDesc = new D3D11_INPUT_ELEMENT_DESC[size];
		for (int i = 0; i < myVertexFormat.Size(); ++i)
		{
			vertexDesc[i] = *myVertexFormat[i];
		}

		InitInputLayout(vertexDesc, size, aEffect);
		delete[] vertexDesc;

		InitVertexBuffer(aVertexStride, D3D11_USAGE_IMMUTABLE, 0);
		InitIndexBuffer();

		SetupVertexBuffer(aVertexCount, aVertexData);
		SetupIndexBuffer(aIndexCount, aIndexData);

		myTechniqueName = "Render";
	}
コード例 #8
0
ファイル: GPUData.cpp プロジェクト: nian0601/GfxEngine
	void GPUData::Init(EffectID aEffect)
	{
		const int size = myVertexFormat.Size();
		D3D11_INPUT_ELEMENT_DESC* vertexDesc = new D3D11_INPUT_ELEMENT_DESC[size];
		for (int i = 0; i < myVertexFormat.Size(); ++i)
		{
			vertexDesc[i] = *myVertexFormat[i];
		}

		InitInputLayout(vertexDesc, size, aEffect);
		delete[] vertexDesc;

		InitVertexBuffer(myVertexData->myStride, D3D11_USAGE_IMMUTABLE, 0);
		InitIndexBuffer();

		SetupVertexBuffer(myVertexData->myNumberOfVertices, myVertexData->myVertexData);
		SetupIndexBuffer(myIndexData->myNumberOfIndices, myIndexData->myIndexData);

		myTechniqueName = "Render";
	}
コード例 #9
0
ファイル: Text.cpp プロジェクト: nian0601/Spaceshooter
void Prism::Text::ConstructBuffers()
{
	//debug:
	//CU::Vector2<float> myCharSize(16.f, 16.f);
	//float myCharSpacing(0);
	//debug end

	int numOfLetters = myText.length();
	float drawX = 0;
	float drawY = 0;
	float z = 1.f;

	myVertices.RemoveAll();
	myIndices.RemoveAll();
	VertexPosUV vert;
	for (int i = 0, row = 0; i < numOfLetters; ++i)
	{
		if (myText[i] == '\n')
		{
			drawX = 0;
			drawY -= 48.f;
			++row;
			continue;
		}
		Font::CharacterData charData = myFont.GetCharData(myText[i]);

		float left = drawX + charData.myOffset.x;
		float right = left + charData.mySize.x;
		float top = drawY + charData.myOffset.y;
		float bottom = top - charData.mySize.y;


		vert.myPos = CU::Vector3<float>(left, top, z);
		vert.myUV = charData.myTopLeftUV;
		myVertices.Add(vert);

		vert.myPos = CU::Vector3<float>(right, bottom, z);
		vert.myUV = charData.myBottomRightUV;
		myVertices.Add(vert);

		vert.myPos = CU::Vector3<float>(left, bottom, z);
		vert.myUV = { charData.myTopLeftUV.x, charData.myBottomRightUV.y };
		myVertices.Add(vert);

		vert.myPos = CU::Vector3<float>(right, top, z);
		vert.myUV = { charData.myBottomRightUV.x, charData.myTopLeftUV.y };
		myVertices.Add(vert);


		int startIndex = (i - row) * 4;
		myIndices.Add(startIndex + 0);
		myIndices.Add(startIndex + 1);
		myIndices.Add(startIndex + 2);

		myIndices.Add(startIndex + 0);
		myIndices.Add(startIndex + 3);
		myIndices.Add(startIndex + 1);


		drawX += charData.myAdvanceX;
		z -= 0.001f;
	}

	SetupVertexBuffer(myVertices.Size(), sizeof(VertexPosUV), reinterpret_cast<char*>(&myVertices[0]), "Text::VertexBuffer");
	SetupIndexBuffer(myIndices.Size(), reinterpret_cast<char*>(&myIndices[0]), "Text::IndexBuffer");

	mySurfaces[0]->SetVertexCount(myVertices.Size());
	mySurfaces[0]->SetIndexCount(myIndices.Size());

	//myTextWidth = drawX - myTextWidth;
}