Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualKingofNoobs

Posted 27 November 2012 - 01:47 AM

Hello,

Could anyone tell me if there is anything wrong with initializing "reverse iterators" for reverse list iteration by moving to end() -1 and begin() -1 and then running my for loop in reverse. The code follows:

AtlasBuffers::iterator begin;
AtlasBuffers::iterator end;
if(mFromTop)
{
begin = --mAtlasBuffers.end();
end = --mAtlasBuffers.begin();
}
else
{
begin = mAtlasBuffers.begin();
end = mAtlasBuffers.end();
}
for(; begin != end;)
{
const Atlas * tempAtlas = begin->first;
VIAggregator tempVIAggregator = begin->second;
std::vector<SimpleVertex> tempVertexAggregator = tempVIAggregator.first;
std::vector<uint32_t> tempIndexAggregator = tempVIAggregator.second;

// Only update VRAM buffers if they have changed
if(mVertexBufferChanged)
{
ID3D11Buffer * vertexBuffer = 0;
CreateVertexBuffer(&vertexBuffer, tempVertexAggregator);
unsigned int stride = sizeof(SimpleVertex);
unsigned int offset = 0;
mContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset);
ReleaseCOM(vertexBuffer);
// Index buffer only changed if vertex buffer changed
if(mIndexBufferChanged)
{
ID3D11Buffer * indexBuffer = 0;
CreateIndexBuffer(&indexBuffer, tempIndexAggregator);
mContext->IASetIndexBuffer(indexBuffer, DXGI_FORMAT_R32_UINT, 0);
ReleaseCOM(indexBuffer);
}

}

// Only reset texture if it has changed.
if(tempAtlas != mLastAtlasUsed)
{
mContext->PSSetShaderResources( 0, 1, (ID3D11ShaderResourceView*const*) &(mAtlasBuffers.begin()->first->GetTexture()) );
mLastAtlasUsed = tempAtlas;
}
mContext->DrawIndexed( tempIndexAggregator.size(), 0, 0 );
if(mFromTop)
{
++begin;
}
else
{
--begin;
}

} // for
mFromTop = !mFromTop;

Thanks in advance.

-Dave Ottley

#1KingofNoobs

Posted 27 November 2012 - 01:43 AM

Hello,

Could anyone tell me if there is anything wrong with initializing "reverse iterators" for reverse list iteration by moving to end() -1 and begin() -1 and then running my for loop in reverse. The code follows:

AtlasBuffers::iterator begin;
AtlasBuffers::iterator end;
if(mFromTop)
{
begin = mAtlasBuffers.end() - 1;
end = mAtlasBuffers.begin() - 1;
mFromTop = false;
}
else
{
begin = mAtlasBuffers.begin();
end = mAtlasBuffers.end();
mFromTop = true;
}
for(; begin != end;)
{
const Atlas * tempAtlas = begin->first;
VIAggregator tempVIAggregator = begin->second;
std::vector<SimpleVertex> tempVertexAggregator = tempVIAggregator.first;
std::vector<uint32_t> tempIndexAggregator = tempVIAggregator.second;

// Only update VRAM buffers if they have changed
if(mVertexBufferChanged)
{
ID3D11Buffer * vertexBuffer = 0;
CreateVertexBuffer(&vertexBuffer, tempVertexAggregator);
unsigned int stride = sizeof(SimpleVertex);
unsigned int offset = 0;
mContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset);
ReleaseCOM(vertexBuffer);
// Index buffer only changed if vertex buffer changed
if(mIndexBufferChanged)
{
ID3D11Buffer * indexBuffer = 0;
CreateIndexBuffer(&indexBuffer, tempIndexAggregator);
mContext->IASetIndexBuffer(indexBuffer, DXGI_FORMAT_R32_UINT, 0);
ReleaseCOM(indexBuffer);
}

}

// Only reset texture if it has changed.
if(tempAtlas != mLastAtlasUsed)
{
mContext->PSSetShaderResources( 0, 1, (ID3D11ShaderResourceView*const*) &(mAtlasBuffers.begin()->first->GetTexture()) );
mLastAtlasUsed = tempAtlas;
}
mContext->DrawIndexed( tempIndexAggregator.size(), 0, 0 );
if(mFromTop)
{
++begin;
}
else
{
--begin;
}

} // for

Thanks in advance.

-Dave Ottley

PARTNERS