static unsafe void Reset(MyGeneratedTexture tex, byte[] data, int nchannels) { if (data == null) { tex.Reset(null); } else { fixed(byte *dptr = data) { int numMiplevels = tex.NumMipLevels; DataBox[] dataBox = new DataBox[numMiplevels]; int width = tex.Size.X; int height = tex.Size.Y; int offset = 0; for (int i = 0; i < numMiplevels; ++i) { dataBox[i].DataPointer = new IntPtr(dptr + offset); dataBox[i].RowPitch = width * nchannels; offset += width * height * nchannels; width >>= 1; height >>= 1; } tex.Reset(dataBox); } } }
void CreateR32G32B32A32_Float(MyGeneratedTexture tex, string name, Vector2I resolution, Vector4[] colors) { Texture2DDescription desc = m_descDefault; desc.Format = Format.R32G32B32A32_Float; int width = resolution.X; int height = resolution.Y; desc.Height = width; desc.Width = height; tex.Init(name, desc, new Vector2I(width, height), width * height * 16); if (colors != null) { float[] values = new float[width * height * 4]; int inOffset = 0; int outOffset = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { values[outOffset++] = colors[inOffset].X; values[outOffset++] = colors[inOffset].Y; values[outOffset++] = colors[inOffset].Z; values[outOffset++] = colors[inOffset].W; inOffset++; } } Reset(tex, values, width, 4); } }
static unsafe void Reset(MyGeneratedTexture tex, int data) { void *ptr = &data; m_tmpDataBoxArray1[0].DataPointer = new IntPtr(ptr); m_tmpDataBoxArray1[0].RowPitch = 4; tex.Reset(m_tmpDataBoxArray1); }
static unsafe void Reset(MyGeneratedTexture tex, float[] data, int rowlength, int nchannels) { fixed(float *dptr = data) { m_tmpDataBoxArray1[0].DataPointer = new IntPtr(dptr); m_tmpDataBoxArray1[0].RowPitch = rowlength * nchannels * 4; tex.Reset(m_tmpDataBoxArray1); } }
void CreateR_1x1(MyGeneratedTexture tex, string name, byte data) { Texture2DDescription desc = m_descDefault; desc.Format = Format.R8_UNorm; desc.Height = 1; desc.Width = 1; tex.Init(name, desc, new Vector2I(1, 1), 1); Reset(tex, data); }
static unsafe void ResetCube(MyGeneratedTexture tex, int data) { void *ptr = &data; for (int i = 0; i < 6; i++) { m_tmpDataBoxArray6[i].DataPointer = new IntPtr(ptr); m_tmpDataBoxArray6[i].RowPitch = 4; } tex.Reset(m_tmpDataBoxArray6); }
void CreateRGBA_1x1(MyGeneratedTexture tex, string name, Color color) { Texture2DDescription desc = m_descDefault; desc.Format = Format.R8G8B8A8_UNorm; desc.Height = 1; desc.Width = 1; tex.Init(name, desc, new Vector2I(1, 1), 4); int data = color.ToRgba(); Reset(tex, data); }
unsafe void CreateR_1x1(MyGeneratedTexture tex, string name, byte data) { Texture2DDescription desc = m_descDefault; desc.Format = Format.R8_UNorm; desc.Height = 1; desc.Width = 1; void *ptr = &data; m_tmpDataBoxArray1[0].DataPointer = new IntPtr(ptr); m_tmpDataBoxArray1[0].RowPitch = 1; CreateTexture(tex, name, desc, m_tmpDataBoxArray1, new Vector2I(1, 1), 1); }
void CreateCubeRGBA_1x1(MyGeneratedTexture tex, string name, Color color) { Texture2DDescription desc = m_descDefault; desc.Format = Format.R8G8B8A8_UNorm; desc.Height = 1; desc.Width = 1; desc.ArraySize = 6; desc.OptionFlags = ResourceOptionFlags.TextureCube; tex.Init(name, desc, new Vector2I(1, 1), 4); int data = color.ToRgba(); ResetCube(tex, data); }
unsafe void CreateRGBA_1x1(MyGeneratedTexture tex, string name, Color color) { Texture2DDescription desc = m_descDefault; desc.Format = Format.R8G8B8A8_UNorm; desc.Height = 1; desc.Width = 1; int data = color.ToRgba(); void *ptr = &data; m_tmpDataBoxArray1[0].DataPointer = new IntPtr(ptr); m_tmpDataBoxArray1[0].RowPitch = 4; CreateTexture(tex, name, desc, m_tmpDataBoxArray1, new Vector2I(1, 1), 4); }
void CreateR(MyGeneratedTexture tex, string name, Vector2I resolution, byte[] data, bool userTexture = false, int numMipLebels = 1) { Texture2DDescription desc = m_descDefault; desc.Usage = userTexture ? ResourceUsage.Default : ResourceUsage.Immutable; desc.Format = Format.R8_UNorm; int width = resolution.X; int height = resolution.Y; desc.Height = height; desc.Width = width; desc.MipLevels = numMipLebels; tex.Init(name, desc, new Vector2I(width, height), width * height); if (data != null) { Reset(tex, data, 1); } }
unsafe void CreateR(MyGeneratedTexture tex, string name, Vector2I resolution, byte[] data) { Texture2DDescription desc = m_descDefault; desc.Format = Format.R8_UNorm; int width = resolution.X; int height = resolution.Y; desc.Height = height; desc.Width = width; fixed(byte *dptr = data) { m_tmpDataBoxArray1[0].DataPointer = new IntPtr(dptr); m_tmpDataBoxArray1[0].RowPitch = width; CreateTexture(tex, name, desc, m_tmpDataBoxArray1, new Vector2I(width, height), width * height); m_tmpDataBoxArray1[0].DataPointer = new IntPtr(null); } }
void CreateRGBA(MyGeneratedTexture tex, string name, Vector2I resolution, bool srgb, byte[] data, bool userTexture = false, int numMipLevels = 1) { Texture2DDescription desc = m_descDefault; desc.Usage = userTexture ? ResourceUsage.Default : ResourceUsage.Immutable; desc.Format = srgb ? Format.R8G8B8A8_UNorm_SRgb : Format.B8G8R8A8_UNorm; int width = resolution.X; int height = resolution.Y; desc.Width = width; desc.Height = height; desc.MipLevels = numMipLevels; tex.Init(name, desc, new Vector2I(width, height), width * height * 4); if (data != null) { Debug.Assert(width * height * 4 == data.Length, "Wrong data array size for RGBA texture"); Reset(tex, data, 4); } }
unsafe void CreateCubeRGBA_1x1(MyGeneratedTexture tex, string name, Color color) { Texture2DDescription desc = m_descDefault; desc.Format = Format.R8G8B8A8_UNorm; desc.Height = 1; desc.Width = 1; desc.ArraySize = 6; desc.OptionFlags = ResourceOptionFlags.TextureCube; int data = color.ToRgba(); void *ptr = &data; for (int i = 0; i < 6; i++) { m_tmpDataBoxArray6[i].DataPointer = new IntPtr(ptr); m_tmpDataBoxArray6[i].RowPitch = 4; } CreateTexture(tex, name, desc, m_tmpDataBoxArray6, new Vector2I(1, 1), 4); }
void CreateCheckerRGBA(MyGeneratedTexture tex, string name, Vector2I resolution, Color v1, Color v2) { int width = resolution.X; int height = resolution.Y; Color[] rawData = new Color[width * height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Color v = v1; if (((y + x) & 1) == 0) { v = v2; } rawData[y * width + x] = v; } } CreateRGBA(tex, name, resolution, false, rawData); }
unsafe void CreateRGBA(MyGeneratedTexture tex, string name, Vector2I resolution, bool srgb, Color[] colors, int numMipLevels = 1) { int width = resolution.X; int height = resolution.Y; byte[] rawData = new byte[width * height * 4]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int offset = x + y * width; Color currentColor = colors[offset]; rawData[offset * 4 + 0] = currentColor.R; rawData[offset * 4 + 1] = currentColor.G; rawData[offset * 4 + 2] = currentColor.B; rawData[offset * 4 + 3] = currentColor.A; } } CreateRGBA(tex, name, resolution, srgb, rawData); }
void CreateCheckerR(MyGeneratedTexture tex, string name, Vector2I resolution, byte v1, byte v2) { int width = resolution.X; int height = resolution.Y; byte[] ditherData = new byte[width * height]; for (int y = 0; y < height; y++) { for (int x = 0; x < height; x++) { byte v = v1; if (((y + x) & 1) == 0) { v = v2; } ditherData[y * width + x] = v; } } CreateR(tex, name, resolution, ditherData); }
unsafe void CreateR32G32B32A32_Float(MyGeneratedTexture tex, string name, Vector2I resolution, Vector4[] colors) { Texture2DDescription desc = m_descDefault; desc.Format = Format.R32G32B32A32_Float; int width = resolution.X; int height = resolution.Y; desc.Height = width; desc.Width = height; float[] values = new float[width * height * 4]; int inOffset = 0; int outOffset = 0; for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) { values[outOffset++] = colors[inOffset].X; values[outOffset++] = colors[inOffset].Y; values[outOffset++] = colors[inOffset].Z; values[outOffset++] = colors[inOffset].W; inOffset++; } fixed (float* dptr = values) { m_tmpDataBoxArray1[0].DataPointer = new IntPtr(dptr); m_tmpDataBoxArray1[0].RowPitch = width * 16; CreateTexture(tex, name, desc, m_tmpDataBoxArray1, new Vector2I(width, height), width * height * 16); m_tmpDataBoxArray1[0].DataPointer = new IntPtr(null); } }
unsafe void CreateRGBA(MyGeneratedTexture tex, string name, Vector2I resolution, Color[] colors) { Texture2DDescription desc = m_descDefault; desc.Format = Format.R8G8B8A8_UNorm; int width = resolution.X; int height = resolution.Y; desc.Height = width; desc.Width = height; byte[] rawData = new byte[width * height * 4]; for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) { int offset = x + y*width; Color currentColor = colors[offset]; rawData[offset*4 + 0] = currentColor.R; rawData[offset*4 + 1] = currentColor.G; rawData[offset*4 + 2] = currentColor.B; rawData[offset*4 + 3] = currentColor.A; } fixed (byte* dptr = rawData) { m_tmpDataBoxArray1[0].DataPointer = new IntPtr(dptr); m_tmpDataBoxArray1[0].RowPitch = width*4; CreateTexture(tex, name, desc, m_tmpDataBoxArray1, new Vector2I(width, height), width*height*4); m_tmpDataBoxArray1[0].DataPointer = new IntPtr(null); } }
unsafe void CreateR(MyGeneratedTexture tex, string name, Vector2I resolution, byte[] data) { Texture2DDescription desc = m_descDefault; desc.Format = Format.R8_UNorm; int width = resolution.X; int height = resolution.Y; desc.Height = height; desc.Width = width; fixed (byte* dptr = data) { m_tmpDataBoxArray1[0].DataPointer = new IntPtr(dptr); m_tmpDataBoxArray1[0].RowPitch = width; CreateTexture(tex, name, desc, m_tmpDataBoxArray1, new Vector2I(width, height), width * height); m_tmpDataBoxArray1[0].DataPointer = new IntPtr(null); } }
unsafe void CreateCubeRGBA_1x1(MyGeneratedTexture tex, string name, Color color) { Texture2DDescription desc = m_descDefault; desc.Format = Format.R8G8B8A8_UNorm; desc.Height = 1; desc.Width = 1; desc.ArraySize = 6; desc.OptionFlags = ResourceOptionFlags.TextureCube; int data = color.ToRgba(); void* ptr = &data; for (int i = 0; i < 6; i++) { m_tmpDataBoxArray6[i].DataPointer = new IntPtr(ptr); m_tmpDataBoxArray6[i].RowPitch = 4; } CreateTexture(tex, name, desc, m_tmpDataBoxArray6, new Vector2I(1, 1), 4); }
unsafe void CreateRGBA_1x1(MyGeneratedTexture tex, string name, Color color) { Texture2DDescription desc = m_descDefault; desc.Format = Format.R8G8B8A8_UNorm; desc.Height = 1; desc.Width = 1; int data = color.ToRgba(); void* ptr = &data; m_tmpDataBoxArray1[0].DataPointer = new IntPtr(ptr); m_tmpDataBoxArray1[0].RowPitch = 4; CreateTexture(tex, name, desc, m_tmpDataBoxArray1, new Vector2I(1, 1), 4); }
void CreateTexture(MyGeneratedTexture tex, string name, Texture2DDescription desc, DataBox[] dataBoxes, Vector2I size, int bytes, bool enableDxInitialisation = true) { tex.Init(name, desc, dataBoxes, size, bytes, enableDxInitialisation); }
static unsafe void ResetCube(MyGeneratedTexture tex, int data) { void* ptr = &data; for (int i = 0; i < 6; i++) { m_tmpDataBoxArray6[i].DataPointer = new IntPtr(ptr); m_tmpDataBoxArray6[i].RowPitch = 4; } tex.Reset(m_tmpDataBoxArray6); }
void CreateR(MyGeneratedTexture tex, string name, Vector2I resolution, byte[] data, bool userTexture = false, int numMipLebels = 1) { Texture2DDescription desc = m_descDefault; desc.Usage = userTexture ? ResourceUsage.Default : ResourceUsage.Immutable; desc.Format = Format.R8_UNorm; int width = resolution.X; int height = resolution.Y; desc.Height = height; desc.Width = width; desc.MipLevels = numMipLebels; tex.Init(name, desc, new Vector2I(width, height), width * height); if (data != null) Reset(tex, data, 1); }
static unsafe void Reset(MyGeneratedTexture tex, byte[] data, int nchannels) { if (data == null) { tex.Reset(null); } else { fixed (byte* dptr = data) { int numMiplevels = tex.NumMipLevels; DataBox[] dataBox = new DataBox[numMiplevels]; int width = tex.Size.X; int height = tex.Size.Y; int offset = 0; for (int i = 0; i < numMiplevels; ++i) { dataBox[i].DataPointer = new IntPtr(dptr + offset); dataBox[i].RowPitch = width * nchannels; offset += width * height * nchannels; width >>= 1; height >>= 1; } tex.Reset(dataBox); } } }
unsafe void CreateCheckerR(MyGeneratedTexture tex, string name, Vector2I resolution, byte v1, byte v2) { int width = resolution.X; int height = resolution.Y; byte[] ditherData = new byte[width * height]; for (int y = 0; y < height; y++) for (int x = 0; x < height; x++) { byte v = v1; if (((y + x) & 1) == 0) v = v2; ditherData[y*width + x] = v; } CreateR(tex, name, resolution, ditherData); }
static unsafe void Reset(MyGeneratedTexture tex, int data) { void* ptr = &data; m_tmpDataBoxArray1[0].DataPointer = new IntPtr(ptr); m_tmpDataBoxArray1[0].RowPitch = 4; tex.Reset(m_tmpDataBoxArray1); }
unsafe void CreateCheckerRGBA(MyGeneratedTexture tex, string name, Vector2I resolution, Color v1, Color v2) { int width = resolution.X; int height = resolution.Y; Color[] rawData = new Color[width * height]; for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) { Color v = v1; if (((y + x) & 1) == 0) v = v2; rawData[y * width + x] = v; } CreateRGBA(tex, name, resolution, rawData); }
unsafe void CreateR_1x1(MyGeneratedTexture tex, string name, byte data) { Texture2DDescription desc = m_descDefault; desc.Format = Format.R8_UNorm; desc.Height = 1; desc.Width = 1; void* ptr = &data; m_tmpDataBoxArray1[0].DataPointer = new IntPtr(ptr); m_tmpDataBoxArray1[0].RowPitch = 1; CreateTexture(tex, name, desc, m_tmpDataBoxArray1, new Vector2I(1, 1), 1); }
static unsafe void Reset(MyGeneratedTexture tex, float[] data, int rowlength, int nchannels) { fixed (float* dptr = data) { m_tmpDataBoxArray1[0].DataPointer = new IntPtr(dptr); m_tmpDataBoxArray1[0].RowPitch = rowlength * nchannels * 4; tex.Reset(m_tmpDataBoxArray1); } }
unsafe void CreateRGBA(MyGeneratedTexture tex, string name, Vector2I resolution, Color[] colors) { Texture2DDescription desc = m_descDefault; desc.Format = Format.R8G8B8A8_UNorm; int width = resolution.X; int height = resolution.Y; desc.Height = width; desc.Width = height; byte[] rawData = new byte[width * height * 4]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int offset = x + y * width; Color currentColor = colors[offset]; rawData[offset * 4 + 0] = currentColor.R; rawData[offset * 4 + 1] = currentColor.G; rawData[offset * 4 + 2] = currentColor.B; rawData[offset * 4 + 3] = currentColor.A; } fixed(byte *dptr = rawData) { m_tmpDataBoxArray1[0].DataPointer = new IntPtr(dptr); m_tmpDataBoxArray1[0].RowPitch = width * 4; CreateTexture(tex, name, desc, m_tmpDataBoxArray1, new Vector2I(width, height), width * height * 4); m_tmpDataBoxArray1[0].DataPointer = new IntPtr(null); } } unsafe void CreateR32G32B32A32_Float(MyGeneratedTexture tex, string name, Vector2I resolution, Vector4[] colors) { Texture2DDescription desc = m_descDefault; desc.Format = Format.R32G32B32A32_Float; int width = resolution.X; int height = resolution.Y; desc.Height = width; desc.Width = height; float[] values = new float[width * height * 4]; int inOffset = 0; int outOffset = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { values[outOffset++] = colors[inOffset].X; values[outOffset++] = colors[inOffset].Y; values[outOffset++] = colors[inOffset].Z; values[outOffset++] = colors[inOffset].W; inOffset++; } fixed(float *dptr = values) { m_tmpDataBoxArray1[0].DataPointer = new IntPtr(dptr); m_tmpDataBoxArray1[0].RowPitch = width * 16; CreateTexture(tex, name, desc, m_tmpDataBoxArray1, new Vector2I(width, height), width * height * 16); m_tmpDataBoxArray1[0].DataPointer = new IntPtr(null); } } unsafe void CreateCheckerR(MyGeneratedTexture tex, string name, Vector2I resolution, byte v1, byte v2) { int width = resolution.X; int height = resolution.Y; byte[] ditherData = new byte[width * height]; for (int y = 0; y < height; y++) { for (int x = 0; x < height; x++) { byte v = v1; if (((y + x) & 1) == 0) { v = v2; } ditherData[y * width + x] = v; } } CreateR(tex, name, resolution, ditherData); } unsafe void CreateCheckerRGBA(MyGeneratedTexture tex, string name, Vector2I resolution, Color v1, Color v2) { int width = resolution.X; int height = resolution.Y; Color[] rawData = new Color[width * height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Color v = v1; if (((y + x) & 1) == 0) { v = v2; } rawData[y * width + x] = v; } } CreateRGBA(tex, name, resolution, rawData); } unsafe void CreateAllTextures() { CreateRGBA_1x1((MyGeneratedTexture)ZeroTex, "Zero", new Color(0, 0, 0, 0)); CreateRGBA_1x1((MyGeneratedTexture)PinkTex, "Pink", new Color(255, 0, 255)); CreateRGBA_1x1((MyGeneratedTexture)ReleaseMissingNormalGlossTex, "ReleaseMissingNormalGloss", new Color(127, 127, 255, 0)); CreateR_1x1((MyGeneratedTexture)ReleaseMissingAlphamaskTex, "ReleaseMissingAlphamask", 255); CreateRGBA_1x1((MyGeneratedTexture)ReleaseMissingExtensionTex, "ReleaseMissingExtension", new Color(255, 0, 0, 0)); CreateCubeRGBA_1x1((MyGeneratedTexture)ReleaseMissingCubeTex, "ReleaseMissingCube", new Color(0, 0, 0, 0)); CreateCheckerRGBA((MyGeneratedTexture)DebugMissingNormalGlossTex, "DebugMissingNormalGloss", new Vector2I(8, 8), new Color(91, 0, 217, 0), new Color(217, 0, 217, 255)); CreateCheckerR((MyGeneratedTexture)DebugMissingAlphamaskTex, "DebugMissingAlphamask", new Vector2I(8, 8), 255, 0); CreateCheckerRGBA((MyGeneratedTexture)DebugMissingExtensionTex, "DebugMissingExtension", new Vector2I(8, 8), new Color(255, 255, 0, 0), new Color(0, 0, 0, 0)); CreateCubeRGBA_1x1((MyGeneratedTexture)DebugMissingCubeTex, "DebubMissingCube", new Color(255, 0, 255, 0)); m_missingNormalGlossTex.Init(ReleaseMissingNormalGlossTex, DebugMissingNormalGlossTex); m_missingAlphamaskTex.Init(ReleaseMissingNormalGlossTex, DebugMissingNormalGlossTex); m_missingExtensionTex.Init(ReleaseMissingExtensionTex, DebugMissingExtensionTex); m_missingCubeTex.Init(ReleaseMissingCubeTex, DebugMissingCubeTex); CreateCubeRGBA_1x1((MyGeneratedTexture)IntelFallbackCubeTex, "IntelFallbackCubeTex", new Color(10, 10, 10, 0)); InitializeRandomTexture(); byte[] ditherData = new byte[] { 0, 32, 8, 40, 2, 34, 10, 42, 48, 16, 56, 24, 50, 18, 58, 26, 12, 44, 4, 36, 14, 46, 6, 38, 60, 28, 52, 20, 62, 30, 54, 22, 3, 35, 11, 43, 1, 33, 9, 41, 51, 19, 59, 27, 49, 17, 57, 25, 15, 47, 7, 39, 13, 45, 5, 37, 63, 31, 55, 23, 61, 29, 53, 21 }; for (int i = 0; i < 64; i++) ditherData[i] = (byte)(ditherData[i] * 4); } CreateR((MyGeneratedTexture)Dithering8x8Tex, "Dither_8x8", new Vector2I(8, 8), ditherData); }