public override MappedTexture2D Map(int subResource, MapType map, bool doNotWait) { MappedTexture2D m = new MappedTexture2D(); int rowSize = Width * Utils.GetSize(glType) * Utils.GetElements(glClientFormat); m.RowPitch = rowSize + rowSize % PACK_ALIGNMENT; if (stagingBuffer == null) { if (Description.Options == ResourceOptionFlags.TextureCube) { int arrayIndex; int level; Texture2DBase.DecoupleSubresource(subResource, MipLevels, out arrayIndex, out level); GL.BindTexture(All.TextureCubeMap, texture); GL.ExtGetTexSubImageQCOM(Utils.GetTextureCubeFace(arrayIndex), level, 0, 0, 0, Width, Height, 0, glClientFormat, glType, m.DataPointer); } else { GL.BindTexture(All.Texture2D, texture); GL.ExtGetTexSubImageQCOM(All.Texture2D, subResource, 0, 0, 0, Width, Height, 0, glClientFormat, glType, m.DataPointer); } } else { handle = GCHandle.Alloc(stagingBuffer, GCHandleType.Pinned); m.DataPointer = ClrRuntime.Runtime.GetPtr(stagingBuffer, 0); } return(m); }
private void CopyTextureToRenderTarget(GraphicsDevice device, Texture2DBase texture, RenderTarget2D renderTarget) { device.SetRenderTargets(renderTarget); texToTargetEffect.Parameters["CopyTexture"].SetResource(texture); texToTargetEffect.Parameters["CopyTextureSamp"].SetResource(device.SamplerStates.LinearClamp); device.DrawQuad(texToTargetEffect); }
//public override void ResolveMSAA(Texture2DBase sourceRenderTexture, SwapChainBase destinationSwapChain) //{ // var src = (RenderTexture2D)sourceRenderTexture; // var dst = (SwapChain)destinationSwapChain; // CommandList.Orbital_Video_D3D12_CommandList_ResolveRenderTextureToSwapChain(handle, src.handle, dst.handle); //} public override void CopyTexture(Texture2DBase sourceTexture, Texture2DBase destinationTexture) { var src = (RenderTexture2D)sourceTexture; var dst = (RenderTexture2D)destinationTexture; CommandList.Orbital_Video_D3D12_CommandList_CopyTexture(handle, src.handle, dst.handle); }
//public override void CopyTexture(Texture2DBase sourceTexture, SwapChainBase destinationSwapChain) //{ // var src = (RenderTexture2D)sourceTexture; // var dst = (SwapChain)destinationSwapChain; // CommandList.Orbital_Video_D3D12_CommandList_CopyTextureToSwapChain(handle, src.handle, dst.handle); //} public override void CopyTexture(Texture2DBase sourceTexture, Texture2DBase destinationTexture, Point2 sourceOffset, Point2 destinationOffset, Size2 size, int sourceMipmapLevel, int destinationMipmapLevel) { var src = (RenderTexture2D)sourceTexture; var dst = (RenderTexture2D)destinationTexture; CommandList.Orbital_Video_D3D12_CommandList_CopyTextureRegion(handle, src.handle, dst.handle, (uint)sourceOffset.x, (uint)sourceOffset.y, 0, (uint)destinationOffset.x, (uint)destinationOffset.y, 0, (uint)size.width, (uint)size.height, 1, (uint)sourceMipmapLevel, (uint)destinationMipmapLevel); }
public override void Screenshot() { Texture2DBase t2d = room.RoomRenderTarget; int i = 0; string name; string date = DateTime.Now.ToShortDateString().Replace('/', '-'); do { name = "..//..//..//Screenshots//SS_" + date + "_#" + i + ".png"; i += 1; } while (File.Exists(name)); //Scheduler.fanfare.Play(); Stream st = new FileStream(name, FileMode.Create); t2d.Save(st, ImageFileType.Png); st.Close(); //t2d.Dispose(); }
public void Dispose() { if (renderState != null) { renderState.Dispose(); renderState = null; } if (renderPass != null) { renderPass.Dispose(); renderPass = null; } if (renderTexture != null) { renderTexture.Dispose(); renderTexture = null; } if (shaderEffect != null) { shaderEffect.Dispose(); shaderEffect = null; } if (vertexBuffer != null) { vertexBuffer.Dispose(); vertexBuffer = null; } if (vertexBufferStreamer != null) { vertexBufferStreamer.Dispose(); vertexBufferStreamer = null; } }
public void Dispose() { if (texture != null) { texture.Dispose(); texture = null; } if (texture2 != null) { texture2.Dispose(); texture2 = null; } if (constantBuffer != null) { constantBuffer.Dispose(); constantBuffer = null; } if (vertexBuffer != null) { vertexBuffer.Dispose(); vertexBuffer = null; } if (renderState != null) { renderState.Dispose(); renderState = null; } if (shaderEffect != null) { shaderEffect.Dispose(); shaderEffect = null; } if (renderPass != null) { renderPass.Dispose(); renderPass = null; } if (commandList != null) { commandList.Dispose(); commandList = null; } if (device != null) { device.Dispose(); device = null; } if (instance != null) { instance.Dispose(); instance = null; } }
public RenderTextureTest(DeviceBase device) { // create render texture const int size = 256; renderTexture = device.CreateRenderTexture2D(size, size, TextureFormat.Default, RenderTextureUsage.Discard, TextureMode.GPUOptimized, MSAALevel.Disabled, true, MultiGPUNodeResourceVisibility.Self); // load shader effect using (var vsStream = new FileStream("Shaders\\Triangle_D3D12.vs", FileMode.Open, FileAccess.Read, FileShare.Read)) using (var psStream = new FileStream("Shaders\\Triangle_D3D12.ps", FileMode.Open, FileAccess.Read, FileShare.Read)) { var vs = new Video.D3D12.Shader((Video.D3D12.Device)device, ShaderType.VS); var ps = new Video.D3D12.Shader((Video.D3D12.Device)device, ShaderType.PS); if (!vs.Init(vsStream)) { throw new Exception("Failed to init VS shader"); } if (!ps.Init(psStream)) { throw new Exception("Failed to init PS shader"); } var desc = new ShaderEffectDesc(); shaderEffect = device.CreateShaderEffect(vs, ps, null, null, null, desc, true); } // create vertex buffer var vertices = new Vec3[3] { new Vec3(-1, -1, 0), new Vec3(0, 1, 0), new Vec3(1, -1, 0) }; vertexBuffer = device.CreateVertexBuffer <Vec3>(vertices, VertexBufferMode.GPUOptimized); // create vertex buffer streamer var vertexBufferStreamLayout = new VertexBufferStreamLayout() { descs = new VertexBufferStreamDesc[1], elements = new VertexBufferStreamElement[1] }; vertexBufferStreamLayout.descs[0] = new VertexBufferStreamDesc() { vertexBuffer = vertexBuffer, type = VertexBufferStreamType.VertexData }; vertexBufferStreamLayout.elements[0] = new VertexBufferStreamElement() { type = VertexBufferStreamElementType.Float3, usage = VertexBufferStreamElementUsage.Position, offset = 0 }; vertexBufferStreamer = device.CreateVertexBufferStreamer(vertexBufferStreamLayout); // create render pass var renderPassDesc = RenderPassDesc.CreateDefault(new Color4F(0, 0, 0, 0), 1); renderPass = renderTexture.CreateRenderPass(renderPassDesc); // create render state var renderStateDesc = new RenderStateDesc() { renderPass = renderPass, shaderEffect = shaderEffect, vertexBufferTopology = VertexBufferTopology.Triangle, vertexBufferStreamer = vertexBufferStreamer, triangleCulling = TriangleCulling.Back, triangleFillMode = TriangleFillMode.Solid }; renderState = device.CreateRenderState(renderStateDesc); }
public void Init(string platformPath, string folder64Bit, string folder32Bit) { // pre-load native libs string libFolderBit; if (IntPtr.Size == 8) { libFolderBit = folder64Bit; } else if (IntPtr.Size == 4) { libFolderBit = folder32Bit; } else { throw new NotSupportedException("Unsupported bit size: " + IntPtr.Size.ToString()); } #if RELEASE const string config = "Release"; #else const string config = "Debug"; #endif // load api abstraction (api-instance and hardware-device) var abstractionDesc = new AbstractionDesc(AbstractionInitType.DefaultSingleGPU); abstractionDesc.supportedAPIs = new AbstractionAPI[] { AbstractionAPI.D3D12 }; abstractionDesc.deviceDescD3D12.window = window; //abstractionDesc.deviceDescD3D12.adapterIndex = 1; //abstractionDesc.deviceDescD3D12.vSyncMode = SwapChainVSyncMode.VSyncOff; abstractionDesc.nativeLibPathD3D12 = Path.Combine(platformPath, @"Shared\Orbital.Video.D3D12.Native\bin", libFolderBit, config); abstractionDesc.deviceDescVulkan.window = window; abstractionDesc.nativeLibPathVulkan = Path.Combine(platformPath, @"Shared\Orbital.Video.Vulkan.Native\bin", libFolderBit, config); if (!Abstraction.InitFirstAvaliable(abstractionDesc, out instance, out device)) { throw new Exception("Failed to init abstraction"); } // create render texture test objects renderTextureTest = new RenderTextureTest(device); // create msaa render texture if (!device.GetMaxMSAALevel(TextureFormat.Default, out var msaaLevel)) { throw new Exception("Failed to get MSAA level"); } msaaLevel = MSAALevel.Disabled; var windowSize = window.GetSize(WindowSizeType.WorkingArea); renderTextureMSAA = device.CreateRenderTexture2D(windowSize.width, windowSize.height, TextureFormat.Default, RenderTextureUsage.Discard, TextureMode.GPUOptimized, StencilUsage.Discard, DepthStencilFormat.DefaultDepth, DepthStencilMode.GPUOptimized, msaaLevel, false, MultiGPUNodeResourceVisibility.All); // create command list commandList = device.CreateRasterizeCommandList(); commandList_Compute = device.CreateComputeCommandList(); // create render pass var renderPassDesc = RenderPassDesc.CreateDefault(new Color4F(0, .2f, .4f, 1), 1); //renderPass = device.CreateRenderPass(renderPassDesc, device.swapChain.depthStencil); renderPass = renderTextureMSAA.CreateRenderPass(renderPassDesc, renderTextureMSAA.GetDepthStencil()); // create texture int textureWidth = 256, textureHeight = 256; var textureData = new byte[textureWidth * textureHeight * 4]; for (int y = 0; y != textureHeight; ++y) { for (int x = 0; x != textureWidth; ++x) { int i = (x * 4) + (y * textureWidth * 4); if (x % 16 <= 7 && y % 16 <= 7) { textureData[i + 0] = 0; textureData[i + 1] = 0; textureData[i + 2] = 0; textureData[i + 3] = 0; } else { textureData[i + 0] = 255; textureData[i + 1] = 255; textureData[i + 2] = 255; textureData[i + 3] = 255; } } } texture = device.CreateTexture2D(textureWidth, textureHeight, TextureFormat.B8G8R8A8, textureData, TextureMode.GPUOptimized, MultiGPUNodeResourceVisibility.Self); // create texture 2 textureWidth = 100; textureHeight = 100; textureData = new byte[textureWidth * textureHeight * 4]; for (int y = 0; y != textureHeight; ++y) { for (int x = 0; x != textureWidth; ++x) { int i = (x * 4) + (y * textureWidth * 4); if (x % 16 <= 7 && y % 16 <= 7) { textureData[i + 0] = 0; textureData[i + 1] = 0; textureData[i + 2] = 0; textureData[i + 3] = 0; } else { textureData[i + 0] = 255; textureData[i + 1] = 255; textureData[i + 2] = 255; textureData[i + 3] = 255; } } } texture2 = device.CreateTexture2D(textureWidth, textureHeight, TextureFormat.B8G8R8A8, textureData, TextureMode.GPUOptimized, MultiGPUNodeResourceVisibility.Self); // load shaders // TODO: load CS2X compiled ShaderEffect /*using (var stream = new FileStream("Shader.se", FileMode.Open, FileAccess.Read, FileShare.Read)) * { * shaderEffect = device.CreateShaderEffect(stream, ShaderEffectSamplerAnisotropy.Default); * }*/ using (var vsStream = new FileStream("Shaders\\Shader_D3D12.vs", FileMode.Open, FileAccess.Read, FileShare.Read)) using (var psStream = new FileStream("Shaders\\Shader_D3D12.ps", FileMode.Open, FileAccess.Read, FileShare.Read)) { var vs = new Video.D3D12.Shader((Video.D3D12.Device)device, ShaderType.VS); var ps = new Video.D3D12.Shader((Video.D3D12.Device)device, ShaderType.PS); if (!vs.Init(vsStream)) { throw new Exception("Failed to init VS shader"); } if (!ps.Init(psStream)) { throw new Exception("Failed to init PS shader"); } var desc = new ShaderEffectDesc(); desc.constantBuffers = new ShaderEffectConstantBuffer[1]; desc.constantBuffers[0] = new ShaderEffectConstantBuffer() { registerIndex = 0, usage = ShaderEffectResourceUsage.VS, variables = new ShaderVariable[2] }; desc.constantBuffers[0].variables[0] = new ShaderVariable() { name = "constrast", type = ShaderVariableType.Float }; desc.constantBuffers[0].variables[1] = new ShaderVariable() { name = "camera", type = ShaderVariableType.Float4x4 }; desc.textures = new ShaderEffectTexture[3]; desc.textures[0] = new ShaderEffectTexture() { registerIndex = 0, usage = ShaderEffectResourceUsage.PS }; desc.textures[1] = new ShaderEffectTexture() { registerIndex = 1, usage = ShaderEffectResourceUsage.PS }; desc.textures[2] = new ShaderEffectTexture() { registerIndex = 2, usage = ShaderEffectResourceUsage.PS }; desc.samplers = new ShaderEffectSampler[1]; desc.samplers[0] = new ShaderEffectSampler() { registerIndex = 0, filter = ShaderSamplerFilter.Default, anisotropy = ShaderSamplerAnisotropy.Default, addressU = ShaderSamplerAddress.Wrap, addressV = ShaderSamplerAddress.Wrap, addressW = ShaderSamplerAddress.Wrap, usage = ShaderEffectResourceUsage.PS }; shaderEffect = device.CreateShaderEffect(vs, ps, null, null, null, desc, true); } if (!shaderEffect.FindVariable("constrast", out shaderEffectVar_Constrast)) { throw new Exception("Failed to find shader effect variable"); } if (!shaderEffect.FindVariable("camera", out shaderEffectVar_Camera)) { throw new Exception("Failed to find shader effect variable"); } // create constant buffer constantBuffer = device.CreateConstantBuffer(shaderEffect.constantBufferMappings[0].size, ConstantBufferMode.Write); // create vertex buffer const float size = 1 / 2f; var rotUpAxisMat = Mat3.FromEuler(0, MathTools.DegToRad(90), 0); var rotRightAxisMat = Mat3.FromEuler(MathTools.DegToRad(90), 0, 0); var vertices = new Vertex[4 * 6]; // 4 vertices per face var indices = new ushort[6 * 6]; // 6 indices per face var colorKey = new Color4[4] { Color4.blue, Color4.red, Color4.white, Color4.white }; for (int v = 0, i = 0, r = 0; v < (4 * 4); v += 4, i += 6, ++r) // caluclate front, right, back, left faces { vertices[v + 0] = new Vertex(new Vec3(-size, -size, size), colorKey[r], new Vec2(0, 0)).Transform(rotUpAxisMat, r); vertices[v + 1] = new Vertex(new Vec3(-size, size, size), colorKey[r], new Vec2(0, 1)).Transform(rotUpAxisMat, r); vertices[v + 2] = new Vertex(new Vec3(size, size, size), colorKey[r], new Vec2(1, 1)).Transform(rotUpAxisMat, r); vertices[v + 3] = new Vertex(new Vec3(size, -size, size), colorKey[r], new Vec2(1, 0)).Transform(rotUpAxisMat, r); indices[i + 0] = (ushort)(v + 0); indices[i + 1] = (ushort)(v + 1); indices[i + 2] = (ushort)(v + 2); indices[i + 3] = (ushort)(v + 0); indices[i + 4] = (ushort)(v + 2); indices[i + 5] = (ushort)(v + 3); } colorKey = new Color4[2] { Color4.green, Color4.white }; for (int v = (4 * 4), i = (6 * 4), r = 1; v < (4 * 6); v += 4, i += 6, r = 3) // caluclate top, bottom faces { vertices[v + 0] = new Vertex(new Vec3(-size, -size, size), colorKey[r / 3], new Vec2(0, 0)).Transform(rotRightAxisMat, r); vertices[v + 1] = new Vertex(new Vec3(-size, size, size), colorKey[r / 3], new Vec2(0, 1)).Transform(rotRightAxisMat, r); vertices[v + 2] = new Vertex(new Vec3(size, size, size), colorKey[r / 3], new Vec2(1, 1)).Transform(rotRightAxisMat, r); vertices[v + 3] = new Vertex(new Vec3(size, -size, size), colorKey[r / 3], new Vec2(1, 0)).Transform(rotRightAxisMat, r); indices[i + 0] = (ushort)(v + 0); indices[i + 1] = (ushort)(v + 1); indices[i + 2] = (ushort)(v + 2); indices[i + 3] = (ushort)(v + 0); indices[i + 4] = (ushort)(v + 2); indices[i + 5] = (ushort)(v + 3); } vertexBuffer = device.CreateVertexBuffer <Vertex>(vertices, indices, VertexBufferMode.GPUOptimized); // create vertex buffer streamer var vertexBufferStreamLayout = new VertexBufferStreamLayout() { descs = new VertexBufferStreamDesc[1], elements = new VertexBufferStreamElement[3] }; vertexBufferStreamLayout.descs[0] = new VertexBufferStreamDesc() { vertexBuffer = vertexBuffer, type = VertexBufferStreamType.VertexData }; vertexBufferStreamLayout.elements[0] = new VertexBufferStreamElement() { type = VertexBufferStreamElementType.Float3, usage = VertexBufferStreamElementUsage.Position, offset = 0 }; vertexBufferStreamLayout.elements[1] = new VertexBufferStreamElement() { type = VertexBufferStreamElementType.RGBAx8, usage = VertexBufferStreamElementUsage.Color, offset = (sizeof(float) * 3) }; vertexBufferStreamLayout.elements[2] = new VertexBufferStreamElement() { type = VertexBufferStreamElementType.Float2, usage = VertexBufferStreamElementUsage.UV, offset = (sizeof(float) * 3) + 4 }; vertexBufferStreamer = device.CreateVertexBufferStreamer(vertexBufferStreamLayout); // create render state var renderStateDesc = new RenderStateDesc() { renderPass = renderPass, shaderEffect = shaderEffect, constantBuffers = new ConstantBufferBase[1], textures = new TextureBase[3], vertexBufferTopology = VertexBufferTopology.Triangle, vertexBufferStreamer = vertexBufferStreamer, triangleCulling = TriangleCulling.Back, triangleFillMode = TriangleFillMode.Solid, depthStencilDesc = DepthStencilDesc.StandardDepthTesting() }; //renderStateDesc.blendDesc.renderTargetBlendDescs = new RenderTargetBlendDesc[1] {RenderTargetBlendDesc.AlphaBlending()}; renderStateDesc.constantBuffers[0] = constantBuffer; renderStateDesc.textures[0] = texture; renderStateDesc.textures[1] = texture2; renderStateDesc.textures[2] = renderTextureTest.renderTexture; renderState = device.CreateRenderState(renderStateDesc); // create compute shader using (var csStream = new FileStream("Shaders\\Compute_D3D12.cs", FileMode.Open, FileAccess.Read, FileShare.Read)) { var csDesc = new ComputeShaderDesc() { randomAccessBuffers = new ComputeShaderRandomAccessBuffer[1] }; csDesc.randomAccessBuffers[0] = new ComputeShaderRandomAccessBuffer() { registerIndex = 0 }; computeShader = device.CreateComputeShader(csStream, csDesc); } // create compute state var computeStateDesc = new ComputeStateDesc() { computeShader = computeShader, randomAccessBuffers = new object[1] }; computeStateDesc.randomAccessBuffers[0] = renderTextureTest.renderTexture; computeState = device.CreateComputeState(computeStateDesc); // print all GPUs this abstraction supports if (!instance.QuerySupportedAdapters(false, out var adapters)) { throw new Exception("Failed: QuerySupportedAdapters"); } foreach (var adapter in adapters) { Debug.WriteLine(adapter.name); } // setup camera camera = new Camera(); }
public override void ResolveMSAA(Texture2DBase sourceRenderTexture, Texture2DBase destinationRenderTexture) { throw new System.NotImplementedException(); }
public override void CopyTexture(Texture2DBase sourceTexture) { Orbital_Video_D3D12_SwapChain_CopyTexture(handle, sourceTexture.GetHandle()); }
public override void ResolveMSAA(Texture2DBase sourceRenderTexture) { throw new NotImplementedException(); }
/// <summary> /// Gets a <see cref="RenderTarget" /> output for the specified description with a single mipmap. /// </summary> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="format">Describes the format to use.</param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param> /// <param name="arraySize">Size of the texture 2D array, default to 1.</param> /// <returns>A new instance of <see cref="RenderTarget" /> class.</returns> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short> public RenderTarget GetTemporaryRenderTarget2D(int width, int height, PixelFormat format, TextureFlags flags = TextureFlags.RenderTarget | TextureFlags.ShaderResource, int arraySize = 1) { return(GetTemporaryTexture(Texture2DBase.NewDescription(width, height, format, flags, 1, arraySize, GraphicsResourceUsage.Default)).ToRenderTarget()); }
public void Init(string platformPath, string folder64Bit, string folder32Bit) { // pre-load native libs string libFolderBit; if (IntPtr.Size == 8) { libFolderBit = folder64Bit; } else if (IntPtr.Size == 4) { libFolderBit = folder32Bit; } else { throw new NotSupportedException("Unsupported bit size: " + IntPtr.Size.ToString()); } #if RELEASE const string config = "Release"; #else const string config = "Debug"; #endif // load api abstraction (api-instance and hardware-device) var abstractionDesc = new AbstractionDesc(true); abstractionDesc.supportedAPIs = new AbstractionAPI[] { AbstractionAPI.D3D12 }; abstractionDesc.deviceDescD3D12.window = window; abstractionDesc.nativeLibPathD3D12 = Path.Combine(platformPath, @"Shared\Orbital.Video.D3D12.Native\bin", libFolderBit, config); abstractionDesc.deviceDescVulkan.window = window; abstractionDesc.nativeLibPathVulkan = Path.Combine(platformPath, @"Shared\Orbital.Video.Vulkan.Native\bin", libFolderBit, config); if (!Abstraction.InitFirstAvaliable(abstractionDesc, out instance, out device)) { throw new Exception("Failed to init abstraction"); } // create command list commandList = device.CreateCommandList(); // create render pass var renderPassDesc = new RenderPassDesc() { clearColor = true, clearColorValue = new Vec4(0, .2f, .4f, 1) }; renderPass = device.CreateRenderPass(renderPassDesc); // create texture int textureWidth = 256, textureHeight = 256; var textureData = new byte[textureWidth * textureHeight * 4]; for (int y = 0; y != textureHeight; ++y) { for (int x = 0; x != textureWidth; ++x) { int i = (x * 4) + (y * textureWidth * 4); if (x % 16 <= 7 && y % 16 <= 7) { textureData[i + 0] = 0; textureData[i + 1] = 0; textureData[i + 2] = 0; textureData[i + 3] = 0; } else { textureData[i + 0] = 255; textureData[i + 1] = 255; textureData[i + 2] = 255; textureData[i + 3] = 255; } } } texture = device.CreateTexture2D(TextureFormat.B8G8R8A8, textureWidth, textureHeight, textureData, TextureMode.GPUOptimized); // create texture 2 textureWidth = 100; textureHeight = 100; textureData = new byte[textureWidth * textureHeight * 4]; for (int y = 0; y != textureHeight; ++y) { for (int x = 0; x != textureWidth; ++x) { int i = (x * 4) + (y * textureWidth * 4); if (x % 16 <= 7 && y % 16 <= 7) { textureData[i + 0] = 0; textureData[i + 1] = 0; textureData[i + 2] = 0; textureData[i + 3] = 0; } else { textureData[i + 0] = 255; textureData[i + 1] = 255; textureData[i + 2] = 255; textureData[i + 3] = 255; } } } texture2 = device.CreateTexture2D(TextureFormat.B8G8R8A8, textureWidth, textureHeight, textureData, TextureMode.GPUOptimized); // create constant buffer constantBufferObject = new ConstantBufferObject() { offset = .5f, constrast = .5f }; constantBuffer = device.CreateConstantBuffer <ConstantBufferObject>(constantBufferObject, ConstantBufferMode.Write); // load shaders // TODO: load CS2X compiled ShaderEffect /*using (var stream = new FileStream("Shader.se", FileMode.Open, FileAccess.Read, FileShare.Read)) * { * shaderEffect = device.CreateShaderEffect(stream, ShaderEffectSamplerAnisotropy.Default); * }*/ using (var vsStream = new FileStream("Shaders\\Shader_D3D12.vs", FileMode.Open, FileAccess.Read, FileShare.Read)) using (var psStream = new FileStream("Shaders\\Shader_D3D12.ps", FileMode.Open, FileAccess.Read, FileShare.Read)) { var vs = new Video.D3D12.Shader((Video.D3D12.Device)device, ShaderType.VS); var ps = new Video.D3D12.Shader((Video.D3D12.Device)device, ShaderType.PS); if (!vs.Init(vsStream)) { throw new Exception("Failed to init VS shader"); } if (!ps.Init(psStream)) { throw new Exception("Failed to init PS shader"); } var desc = new ShaderEffectDesc(); desc.constantBuffers = new ShaderEffectConstantBuffer[1]; desc.constantBuffers[0] = new ShaderEffectConstantBuffer() { registerIndex = 0, usage = ShaderEffectResourceUsage.VS }; desc.textures = new ShaderEffectTexture[2]; desc.textures[0] = new ShaderEffectTexture() { registerIndex = 0, usage = ShaderEffectResourceUsage.PS }; desc.textures[1] = new ShaderEffectTexture() { registerIndex = 1, usage = ShaderEffectResourceUsage.PS }; desc.samplers = new ShaderEffectSampler[1]; desc.samplers[0] = new ShaderEffectSampler() { registerIndex = 0, filter = ShaderEffectSamplerFilter.Default, anisotropy = ShaderEffectSamplerAnisotropy.Default, addressU = ShaderEffectSamplerAddress.Wrap, addressV = ShaderEffectSamplerAddress.Wrap, addressW = ShaderEffectSamplerAddress.Wrap }; shaderEffect = device.CreateShaderEffect(vs, ps, null, null, null, desc, true); } // create vertex buffer var vertexBufferLayout = new VertexBufferLayout(); vertexBufferLayout.elements = new VertexBufferLayoutElement[3]; vertexBufferLayout.elements[0] = new VertexBufferLayoutElement() { type = VertexBufferLayoutElementType.Float3, usage = VertexBufferLayoutElementUsage.Position, streamIndex = 0, usageIndex = 0, byteOffset = 0 }; vertexBufferLayout.elements[1] = new VertexBufferLayoutElement() { type = VertexBufferLayoutElementType.RGBAx8, usage = VertexBufferLayoutElementUsage.Color, streamIndex = 0, usageIndex = 0, byteOffset = (sizeof(float) * 3) }; vertexBufferLayout.elements[2] = new VertexBufferLayoutElement() { type = VertexBufferLayoutElementType.Float2, usage = VertexBufferLayoutElementUsage.UV, streamIndex = 0, usageIndex = 0, byteOffset = (sizeof(float) * 3) + 4 }; var vertices = new Vertex[] { new Vertex(new Vec3(-1, -1, 0), Color4.red, new Vec2(0, 0)), new Vertex(new Vec3(0, 1, 0), Color4.green, new Vec2(.5f, 1)), new Vertex(new Vec3(1, -1, 0), Color4.blue, new Vec2(1, 0)) }; vertexBuffer = device.CreateVertexBuffer <Vertex>(vertices, vertexBufferLayout, VertexBufferMode.GPUOptimized); // create render state var renderStateDesc = new RenderStateDesc() { renderPass = renderPass, shaderEffect = shaderEffect, constantBuffers = new ConstantBufferBase[1], textures = new TextureBase[2], vertexBuffer = vertexBuffer, vertexBufferTopology = VertexBufferTopology.Triangle }; renderStateDesc.constantBuffers[0] = constantBuffer; renderStateDesc.textures[0] = texture; renderStateDesc.textures[1] = texture2; renderState = device.CreateRenderState(renderStateDesc, 0); // print all GPUs this abstraction supports if (!instance.QuerySupportedAdapters(false, out var adapters)) { throw new Exception("Failed: QuerySupportedAdapters"); } foreach (var adapter in adapters) { Debug.WriteLine(adapter.name); } }
public override void CopyTexture(Texture2DBase sourceTexture) { throw new NotImplementedException(); }
public override void ResolveMSAA(Texture2DBase sourceRenderTexture) { Orbital_Video_D3D12_SwapChain_ResolveRenderTexture(handle, sourceRenderTexture.GetHandle()); }
public override void CopyTexture(Texture2DBase sourceTexture, Point2 sourceOffset, Point2 destinationOffset, Size2 size, int sourceMipmapLevel) { throw new NotImplementedException(); }
public override void CopyTexture(Texture2DBase sourceTexture, Point2 sourceOffset, Point2 destinationOffset, Size2 size, int sourceMipmapLevel) { Orbital_Video_D3D12_SwapChain_CopyTextureRegion(handle, sourceTexture.GetHandle(), sourceOffset.x, sourceOffset.y, destinationOffset.x, destinationOffset.y, size.width, size.height, sourceMipmapLevel); }
public override void CopyTexture(Texture2DBase sourceTexture, Texture2DBase destinationTexture) { throw new System.NotImplementedException(); }