Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualsimpler

Posted 30 October 2012 - 04:22 AM

Thanks for the great reply, I learned a lot. I'm however getting weird results when I do as you suggested. This is the code that copies the data to the texture, just like you showed:

The code snippet don't want to work this time...

// Map the texture.
D3D11_MAPPED_SUBRESOURCE data;
GetD3DContext()->Map(texture, 0, D3D11_MAP_WRITE_DISCARD, 0, &data);

// All pixels red just for testing.
vector<XMFLOAT3> redVector;
for(int i = 0; i < mInfo.HeightmapWidth * mInfo.HeightmapHeight; i++)
redVector.push_back(XMFLOAT3(1, 0, 0));

const uint32_t pixelSize = sizeof(XMFLOAT3); // 12
const uint32_t srcPitch = pixelSize * mInfo.HeightmapWidth;
uint8_t* textureData = reinterpret_cast<uint8_t*>(data.pData);
const uint8_t* srcData = reinterpret_cast<uint8_t*>(redVector.data());

for(uint32_t i = 0; i < mInfo.HeightmapHeight; ++i)
{
memcpy(textureData, srcData, srcPitch);
textureData += data.RowPitch;
srcData += srcPitch;
}
GetD3DContext()->Unmap(texture, 0);


This is what the texture looks like after mapping and updating it:

Posted Image

As you can see there is a stripe pattern and the color of the texture is not red as it is suppose to be. I don't know why this is the case but since I'm memcpy()ing in a row fassion then it maybe has something to do with that?

#9simpler

Posted 30 October 2012 - 04:21 AM

Thanks for the great reply, I learned a lot. I'm however getting weird results when I do as you suggested. This is the code that copies the data to the texture, just like you showed:

The code snippet don't want to work this time...
    // Map the texture.
	D3D11_MAPPED_SUBRESOURCE data;
	GetD3DContext()->Map(texture, 0, D3D11_MAP_WRITE_DISCARD, 0, &data);
	// All pixels red just for testing.
	vector<XMFLOAT3> redVector;
	for(int i = 0; i < mInfo.HeightmapWidth * mInfo.HeightmapHeight; i++)
		redVector.push_back(XMFLOAT3(1, 0, 0));
	const uint32_t pixelSize = sizeof(XMFLOAT3);	// 12
	const uint32_t srcPitch = pixelSize * mInfo.HeightmapWidth;
	uint8_t* textureData = reinterpret_cast<uint8_t*>(data.pData);
	const uint8_t* srcData = reinterpret_cast<uint8_t*>(redVector.data());
	for(uint32_t i = 0; i < mInfo.HeightmapHeight; ++i)
	{
		memcpy(textureData, srcData, srcPitch);
		textureData += data.RowPitch;
		srcData += srcPitch;
	}
	GetD3DContext()->Unmap(texture, 0);


This is what the texture looks like after mapping and updating it:

Posted Image

As you can see there is a stripe pattern and the color of the texture is not red as it is suppose to be. I don't know why this is the case but since I'm memcpy()ing in a row fassion then it maybe has something to do with that?

#8simpler

Posted 30 October 2012 - 04:21 AM

Thanks for the great reply, I learned a lot. I'm however getting weird results when I do as you suggested. This is the code that copies the data to the texture, just like you showed:

The code snippet don't want to work this time...

// Map the texture.
D3D11_MAPPED_SUBRESOURCE data;
GetD3DContext()->Map(texture, 0, D3D11_MAP_WRITE_DISCARD, 0, &data);
// All pixels red just for testing.
vector<XMFLOAT3> redVector;
for(int i = 0; i < mInfo.HeightmapWidth * mInfo.HeightmapHeight; i++)
redVector.push_back(XMFLOAT3(1, 0, 0));
const uint32_t pixelSize = sizeof(XMFLOAT3); // 12
const uint32_t srcPitch = pixelSize * mInfo.HeightmapWidth;
uint8_t* textureData = reinterpret_cast<uint8_t*>(data.pData);
const uint8_t* srcData = reinterpret_cast<uint8_t*>(redVector.data());
for(uint32_t i = 0; i < mInfo.HeightmapHeight; ++i)
{
memcpy(textureData, srcData, srcPitch);
textureData += data.RowPitch;
srcData += srcPitch;
}
GetD3DContext()->Unmap(texture, 0);



This is what the texture looks like after mapping and updating it:

Posted Image

As you can see there is a stripe pattern and the color of the texture is not red as it is suppose to be. I don't know why this is the case but since I'm memcpy()ing in a row fassion then it maybe has something to do with that?

#7simpler

Posted 30 October 2012 - 04:20 AM

Thanks for the great reply, I learned a lot. I'm however getting weird results when I do as you suggested. This is the code that copies the data to the texture, just like you showed:

// Map the texture.
D3D11_MAPPED_SUBRESOURCE data;
GetD3DContext()->Map(texture, 0, D3D11_MAP_WRITE_DISCARD, 0, &data);
// All pixels red just for testing.
vector<XMFLOAT3> redVector;
for(int i = 0; i < mInfo.HeightmapWidth * mInfo.HeightmapHeight; i++)
redVector.push_back(XMFLOAT3(1, 0, 0));
const uint32_t pixelSize = sizeof(XMFLOAT3); // 12
const uint32_t srcPitch = pixelSize * mInfo.HeightmapWidth;
uint8_t* textureData = reinterpret_cast<uint8_t*>(data.pData);
const uint8_t* srcData = reinterpret_cast<uint8_t*>(redVector.data());
for(uint32_t i = 0; i < mInfo.HeightmapHeight; ++i)
{
memcpy(textureData, srcData, srcPitch);
textureData += data.RowPitch;
srcData += srcPitch;
}
GetD3DContext()->Unmap(texture, 0);



This is what the texture looks like after mapping and updating it:

Posted Image

As you can see there is a stripe pattern and the color of the texture is not red as it is suppose to be. I don't know why this is the case but since I'm memcpy()ing in a row fassion then it maybe has something to do with that?

#6simpler

Posted 30 October 2012 - 04:20 AM

Thanks for the great reply, I learned a lot. I'm however getting weird results when I do as you suggested. This is the code that copies the data to the texture, just like you showed:

// Map the texture.
	D3D11_MAPPED_SUBRESOURCE data;
	GetD3DContext()->Map(texture, 0, D3D11_MAP_WRITE_DISCARD, 0, &data);
	// All pixels red just for testing.
	vector<XMFLOAT3> redVector;
	for(int i = 0; i < mInfo.HeightmapWidth * mInfo.HeightmapHeight; i++)
		redVector.push_back(XMFLOAT3(1, 0, 0));
	const uint32_t pixelSize = sizeof(XMFLOAT3);	// 12
	const uint32_t srcPitch = pixelSize * mInfo.HeightmapWidth;
	uint8_t* textureData = reinterpret_cast<uint8_t*>(data.pData);
	const uint8_t* srcData = reinterpret_cast<uint8_t*>(redVector.data());
	for(uint32_t i = 0; i < mInfo.HeightmapHeight; ++i)
	{
		memcpy(textureData, srcData, srcPitch);
		textureData += data.RowPitch;
		srcData += srcPitch;
	}
	GetD3DContext()->Unmap(texture, 0);


This is what the texture looks like after mapping and updating it:

Posted Image

As you can see there is a stripe pattern and the color of the texture is not red as it is suppose to be. I don't know why this is the case but since I'm memcpy()ing in a row fassion then it maybe has something to do with that?

#5simpler

Posted 30 October 2012 - 04:19 AM

Thanks for the great reply, I learned a lot. I'm however getting weird results when I do as you suggested. This is the code that copies the data to the texture, just like you showed:

[source lang="cpp"] // Map the texture. D3D11_MAPPED_SUBRESOURCE data; GetD3DContext()->Map(texture, 0, D3D11_MAP_WRITE_DISCARD, 0, &data); // All pixels red just for testing. vector<XMFLOAT3> redVector; for(int i = 0; i < mInfo.HeightmapWidth * mInfo.HeightmapHeight; i++) redVector.push_back(XMFLOAT3(1, 0, 0)); const uint32_t pixelSize = sizeof(XMFLOAT3); // 12 const uint32_t srcPitch = pixelSize * mInfo.HeightmapWidth; uint8_t* textureData = reinterpret_cast<uint8_t*>(data.pData); const uint8_t* srcData = reinterpret_cast<uint8_t*>(redVector.data()); for(uint32_t i = 0; i < mInfo.HeightmapHeight; ++i) { memcpy(textureData, srcData, srcPitch); textureData += data.RowPitch; srcData += srcPitch; } GetD3DContext()->Unmap(texture, 0);[/source]


This is what the texture looks like after mapping and updating it:

Posted Image

As you can see there is a stripe pattern and the color of the texture is not red as it is suppose to be. I don't know why this is the case but since I'm memcpy()ing in a row fassion then it maybe has something to do with that?

PARTNERS