public TexturedExtensibleRectangle(IContext context, Vector2I size, Texture texture, int fixedBorderRadius) { DeviceContext = context.DirectX.DeviceContext; _shader = context.Shaders.Get<TextureShader>(); _texture = texture; _fixedBorderRadius = fixedBorderRadius; const int vertexCount = 16; _vertices = new VertexDefinition.PositionTexture[vertexCount]; VertexBuffer = Buffer.Create(context.DirectX.Device, _vertices, new BufferDescription { Usage = ResourceUsage.Dynamic, SizeInBytes = Utilities.SizeOf<VertexDefinition.PositionTexture>() * vertexCount, BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None, StructureByteStride = 0 }); IndexCount = 54; uint[] indices = new uint[IndexCount]; for(uint i=0; i< 3; i++) for (uint j = 0; j < 3; j++) { indices[(i * 3 + j) * 6] = (i + 1) * 4 + j + 1; indices[(i * 3 + j) * 6 + 1] = i * 4 + j + 1; indices[(i * 3 + j) * 6 + 2] = i * 4 + j; indices[(i * 3 + j) * 6 + 3] = (i + 1) * 4 + j; indices[(i * 3 + j) * 6 + 4] = (i + 1) * 4 + j + 1; indices[(i * 3 + j) * 6 + 5] = i * 4 + j; } IndexBuffer = Buffer.Create(context.DirectX.Device, BindFlags.IndexBuffer, indices); Size = size; }
public TexturedRectangle(IContext context, ShaderResourceView texture, Vector2I size) { _shader = context.Shaders.Get<TextureShader>(); _texture = texture; _deviceContext = context.DirectX.Device.ImmediateContext; const int vertexCount = 4; _vertices = new VertexDefinition.PositionTexture[vertexCount]; VertexBuffer = Buffer.Create(context.DirectX.Device, _vertices, new BufferDescription { Usage = ResourceUsage.Dynamic, SizeInBytes = Utilities.SizeOf<VertexDefinition.PositionTexture>() * vertexCount, BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None, StructureByteStride = 0 }); IndexCount = 6; uint[] indices = { 0, 1, 2, 0, 3, 1 }; IndexBuffer = Buffer.Create(context.DirectX.Device, BindFlags.IndexBuffer, indices); Size = size; }