это мой первый пост с переполнением стека!
Я использую SlimDX для игры, которую делает моя команда, и я столкнулся с проблемой. Я пытаюсь создать ShaderResourceView из значений RGBA в объекте Color4. Я искал ответы на мою проблему, и это так далеко, как я получил.
private ShaderResourceView GetTexture(Device device, int width, int height, Color4 color)
{
//create the texture
Texture2D texture = null;
Texture2DDescription desc2 = new Texture2DDescription();
desc2.SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0);
desc2.Width = width;
desc2.Height = height;
desc2.MipLevels = 1;
desc2.ArraySize = 1;
desc2.Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm;
desc2.Usage = ResourceUsage.Dynamic;
desc2.BindFlags = BindFlags.ShaderResource;
desc2.CpuAccessFlags = CpuAccessFlags.Write;
texture = new Texture2D(device, desc2);
// fill the texture with rgba values
DataRectangle rect = texture.Map(0, MapMode.WriteDiscard, MapFlags.None);
if (rect.Data.CanWrite)
{
for (int row = 0; row < texture.Description.Height; row++)
{
int rowStart = row * rect.Pitch;
rect.Data.Seek(rowStart, System.IO.SeekOrigin.Begin);
for (int col = 0; col < texture.Description.Width; col++)
{
rect.Data.WriteByte((byte)color.Red);
rect.Data.WriteByte((byte)color.Green);
rect.Data.WriteByte((byte)color.Blue);
rect.Data.WriteByte((byte)color.Alpha);
}
}
}
texture.Unmap(0);
// create shader resource that is what the renderer needs
ShaderResourceViewDescription desc = new ShaderResourceViewDescription();
desc.Format = texture.Description.Format;
desc.Dimension = ShaderResourceViewDimension.Texture2D;
desc.MostDetailedMip = 0;
desc.MipLevels = 1;
ShaderResourceView srv = new ShaderResourceView(device, texture, desc);
return srv;
}
Я считаю, что данные текстуры устанавливаются, но я не уверен, потому что ничего не отображается. Я знаю, что мой рендерер работает, так как я могу отлично загрузить текстуру из файла, но у меня, похоже, проблема, которую я не могу найти Заранее спасибо за помощь!