public string CreateTextureContentFromShader(string effectFilename, string functionName, int width, int height, string outputPath) { // Adopted from Nvidia DXSas Sample string errors; ConstantTable constants; // We may be here for the first creation of the function texture, or we may be here // because the function texture is associated with the viewport size, and it needs to be rebuilt. string effectText = File.ReadAllText(effectFilename); GraphicsStream functionStream = ShaderLoader.CompileShader(effectText, functionName, null, null, "tx_1_0", 0, out errors, out constants); if (functionStream == null) { throw new InvalidOperationException("Couldn't find texture function: " + functionName); } TextureShader shader = new TextureShader(functionStream); if (shader == null) { throw new InvalidOperationException("Couldn't create texture shader from function stream for: " + functionName); } Texture texture = new Texture(Device, (int)width, (int)height, 1, 0, Format.A8R8G8B8, Pool.Managed); TextureLoader.FillTexture(texture, shader); outputPath = Path.Combine(outputPath, Path.ChangeExtension(Path.GetFileName(effectFilename), functionName + ".dds")); TextureLoader.Save(outputPath, ImageFileFormat.Dds, texture); return(outputPath); }
public void Shutdown() { // Release the light object. Light = null; // Release the camera object. Camera = null; // Release the texture shader object. TextureShader?.ShutDown(); TextureShader = null; // Release the debug window object. DebugWindow?.Shutdown(); DebugWindow = null; // Release the render to texture object. RenderTexture?.Shutdown(); RenderTexture = null; // Release the light shader object. LightShader?.ShutDown(); LightShader = null; // Release the model object. Model?.Shutdown(); Model = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
private bool RenderReflectionScene() { // Use the camera to calculate the reflection matrix. Camera.RenderReflection(-1.5f); // Get the world, view, and projection matrices from camera and d3d objects. var viewMatrix = Camera.ReflectionViewMatrix; var worldMatrix = D3D.WorldMatrix; var projectionMatrix = D3D.ProjectionMatrix; // Rotate the world matrix by the rotation value so that the triangle will spin. Rotate(); // Rotate the world matrix by the rotation value so that the triangle will spin. Matrix.RotationY(Rotation, out worldMatrix); // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing. Model.Render(D3D.DeviceContext); // Render the model using the color shader. if (!TextureShader.Render(D3D.DeviceContext, Model.IndexCount, worldMatrix, viewMatrix, projectionMatrix, Model.TextureCollection.Select(item => item.TextureResource).First())) { return(false); } return(true); }
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; }
public Gui(Sdl2Window window, GraphicsDevice device) { LoadSettings(); Window = window; Device = device; Factory = device.ResourceFactory; TextRenderer = new TextRenderer(Device); ColorShader = new ColorShader(Factory); TextureShader = new TextureShader(Factory); // Create pipeline var pipelineDescription = new GraphicsPipelineDescription( BlendStateDescription.SingleAlphaBlend, new DepthStencilStateDescription( depthTestEnabled: true, depthWriteEnabled: true, comparisonKind: ComparisonKind.LessEqual), new RasterizerStateDescription( cullMode: FaceCullMode.Back, fillMode: PolygonFillMode.Solid, frontFace: FrontFace.Clockwise, depthClipEnabled: true, scissorTestEnabled: false), PrimitiveTopology.TriangleStrip, new ShaderSetDescription( vertexLayouts: new VertexLayoutDescription[] { ColorShader.Layout }, shaders: new Shader[] { ColorShader.VertexShader, ColorShader.FragmentShader }), new[] { ColorShader.ResourceLayout }, Device.SwapchainFramebuffer.OutputDescription ); Pipeline = Factory.CreateGraphicsPipeline(pipelineDescription); var texturePipelineDesc = new GraphicsPipelineDescription( BlendStateDescription.SingleAlphaBlend, new DepthStencilStateDescription( depthTestEnabled: true, depthWriteEnabled: true, comparisonKind: ComparisonKind.LessEqual), new RasterizerStateDescription( cullMode: FaceCullMode.Back, fillMode: PolygonFillMode.Solid, frontFace: FrontFace.Clockwise, depthClipEnabled: true, scissorTestEnabled: false), PrimitiveTopology.TriangleStrip, new ShaderSetDescription( vertexLayouts: new VertexLayoutDescription[] { TextureShader.Layout }, shaders: new Shader[] { TextureShader.VertexShader, TextureShader.FragmentShader }), new[] { TextureShader.ProjViewLayout, TextureShader.TextureLayout }, Device.SwapchainFramebuffer.OutputDescription ); TexturePipeline = Factory.CreateGraphicsPipeline(texturePipelineDesc); CommandList = Factory.CreateCommandList(); }
public void ShutDown() { // Release the light object. Light = null; // Release the camera object. Camera = null; // Release the model object. BitMap?.Shutdown(); BitMap = null; // Release the text object. Text?.Shutdown(); Text = null; // Release the light shader object. LightShader?.ShutDown(); LightShader = null; // Release the model object. Model?.Shutdown(); Model = null; // Release the input object. Input?.Shutdown(); Input = null; // Release the texture shader object. TextureShader?.ShutDown(); TextureShader = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
private bool Render2DTextureScene() { // Clear the buffers to begin the scene. D3D.BeginScene(1.0f, 0.0f, 0.0f, 0.0f); // Generate the view matrix based on the camera's position. Camera.Render(); // Get the world, view, and ortho matrices from the camera and d3d objects. Matrix worldMatrix = D3D.WorldMatrix; Matrix viewMatrix = Camera.ViewMatrix; Matrix orthoMatrix = D3D.OrthoMatrix; // Turn off the Z buffer to begin all 2D rendering. D3D.TurnZBufferOff(); // Put the full screen ortho window vertex and index buffers on the graphics pipeline to prepare them for drawing. FullScreenWindow.Render(D3D.DeviceContext); // Render the full screen ortho window using the texture shader and the full screen sized blurred render to texture resource. if (!TextureShader.Render(D3D.DeviceContext, FullScreenWindow.IndexCount, worldMatrix, viewMatrix, orthoMatrix, UpSampleTexure.ShaderResourceView)) { return(false); } // Turn the Z buffer back on now that all 2D rendering has completed. D3D.TurnZBufferOn(); // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
private bool Render() { // Clear the buffer to begin the scene. D3D.BeginScene(0f, 0f, 0f, 1f); // Generate the view matrix based on the camera position. Camera.Render(); // Get the world, view, and projection matrices from camera and d3d objects. Matrix viewMatrix = Camera.ViewMatrix; Matrix worldMatrix = D3D.WorldMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing. Model.Render(D3D.DeviceContext); // Render the model using the color shader. if (!TextureShader.Render(D3D.DeviceContext, Model.IndexCount, worldMatrix, viewMatrix, projectionMatrix, Model.Texture.TextureResource)) { return(false); } // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
public void ShutDown() { // Release the font shader object. FontShader?.Shuddown(); FontShader = null; // Release the texture shader object. TextureShader?.ShutDown(); TextureShader = null; }
public bool Render() { if (SystemConfiguration.DebugWindowOn) { // Render the entire scene to the texture first. if (!RenderToDebugTexture()) { return(false); } } // Render the entire scene as a reflection to the texture first. if (!RenderToReflectionTexture()) { return(false); } // Clear the buffer to begin the scene. D3D.BeginScene(0, 0, 0, 1f); // Render the scene as normal to the back buffer. if (!RenderScene()) { return(false); } if (SystemConfiguration.DebugWindowOn) { // Turn off the Z buffer to begin all 2D rendering. D3D.TurnZBufferOff(); // Get the world, view, and orthotic matrices from camera and d3d objects. var viewMatrix = Camera.ViewMatrix; var worldMatrix = D3D.WorldMatrix; var orthoMatrix = D3D.OrthoMatrix; // Put the debug window vertex and index buffer on the graphics pipeline them for drawing. if (!DebugWindow.Render(D3D.DeviceContext, 50, 50)) { return(false); } // Render the debug window using the texture shader. if (!TextureShader.Render(D3D.DeviceContext, DebugWindow.IndexCount, worldMatrix, viewMatrix, orthoMatrix, RenderDebugTexture.ShaderResourceView)) { return(false); } // Turn the Z buffer back on now that all 2D rendering has completed. D3D.TurnZBufferOn(); } // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
public bool RenderTextureShader(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView texture) { // Render the TextureShader. if (!TextureShader.Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture)) { return(false); } return(true); }
public void ShutDown() { Camera = null; Timer = null; TextureShader?.ShutDown(); TextureShader = null; Model?.ShutDown(); Model = null; D3D?.ShutDown(); D3D = null; }
public void ShutDown() { // Release the bump map shader object. BumpMapShader?.ShutDown(); BumpMapShader = null; // Release the light shader object. LightShader?.ShutDown(); LightShader = null; // Release the texture shader object. TextureShader?.ShutDown(); TextureShader = null; }
public void Shutdown() { // Release the camera object. Camera = null; // Release the glow shader object. GlowShader?.ShutDown(); GlowShader = null; // Release the glow map shader object. GlowMapShader?.ShutDown(); GlowMapShader = null; // Release the full screen ortho window object. FullScreenWindow?.Shutdown(); FullScreenWindow = null; // Release the small ortho window object. SmallWindow?.Shutdown(); SmallWindow = null; // Release the up sample render to texture object. UpSampleTexure?.Shutdown(); UpSampleTexure = null; // Release the vertical blur render to texture object. VerticalBlurTexture?.Shutdown(); VerticalBlurTexture = null; // Release the vertical blur shader object. VerticalBlurShader?.ShutDown(); VerticalBlurShader = null; // Release the horizontal blur render to texture object. HorizontalBlurTexture?.Shutdown(); HorizontalBlurTexture = null; // Release the horizontal blur shader object. HorizontalBlurShader?.ShutDown(); HorizontalBlurShader = null; // Release the small ortho window object. SmallWindow?.Shutdown(); SmallWindow = null; // Release the down sample render to texture object. DownSampleTexture?.Shutdown(); DownSampleTexture = null; // Release the render to texture object. RenderTexture?.Shutdown(); RenderTexture = null; // Release the model object. BitMap?.Shutdown(); BitMap = null; // Release the texture shader object. TextureShader?.ShutDown(); TextureShader = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
public bool Render(float rotation) { Matrix worldMatrix, viewMatrix, projectionMatrix; float refractionScale; // First set the refraction scale to modify how much perturbation occurs in the glass. // Set the refraction scale for the glass shader. refractionScale = 0.01f; // Clear the buffers to begin the scene. D3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f); // Get the world, view, and projection matrices from the camera and d3d objects. worldMatrix = D3D.WorldMatrix; viewMatrix = Camera.ViewMatrix; projectionMatrix = D3D.ProjectionMatrix; // Then render the 3D spinning cube scene as normal. // Multiply the world matrix by the rotation. Matrix.RotationY(rotation, out worldMatrix); // Put the cube model vertex and index buffers on the graphics pipeline to prepare them for drawing. Model.Render(D3D.DeviceContext); // Render the cube model using the texture shader. if (!TextureShader.Render(D3D.DeviceContext, Model.IndexCount, worldMatrix, viewMatrix, projectionMatrix, Model.TextureCollection.Select(item => item.TextureResource).First())) { return(false); } // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Now render the window model using the glass shader with the color texture, normal map, refraction render to texture, and refraction scale as input. // Translate to back where the window model will be rendered. Matrix.Translation(0.0f, 0.0f, -1.5f, out worldMatrix); // // Put the window model vertex and index buffers on the graphics pipeline to prepare them for drawing. WindowModel.Render(D3D.DeviceContext); // Render the window model using the glass shader. if (!GlassShader.Render(D3D.DeviceContext, WindowModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, WindowModel.TextureCollection.Select(item => item.TextureResource).First(), WindowModel.TextureCollection.Select(item => item.TextureResource).ToArray()[1], RenderTexture.ShaderResourceView, refractionScale)) { return(false); } // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
private bool Render() { D3D.BeginScene(0.1f, 0f, 0f, 1f); Camera.Render(); Model.Render(D3D.DeviceContext); if (!TextureShader.Render(D3D.DeviceContext, Model.IndexCount, D3D.WorldMatrix, Camera.ViewMatrix, D3D.ProjectionMatrix, Model.Texture.TextureResource)) { return(false); } D3D.EndScene(); return(true); }
public void ShutDown() { Timer = null; Camera = null; // Release the color shader object. TextureShader?.ShutDown(); TextureShader = null; // Release the model object. Bitmap?.Shutdown(); Bitmap = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
protected override void DrawOpaqueInterior(Action <TexturedVertex2D> vertexAction) { base.DrawOpaqueInterior(vertexAction); if (Texture?.Available != true) { return; } TextureShader.Bind(); BlitOpaqueInterior(vertexAction); TextureShader.Unbind(); }
public void ShutDown() { // Release the Timer object. Timer = null; // Release the camera object. Camera = null; // Release the TextureShader Object. TextureShader?.ShutDown(); TextureShader = null; // Release the model object. Model?.ShutDown(); Model = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
private bool RenderScene() { // Clear the buffer to begin the scene as Black. D3D.BeginScene(0, 0, 0, 1f); // Generate the view matrix based on the camera position. Camera.Render(); // Get the world, view, and projection matrices from camera and d3d objects. var viewMatrix = Camera.ViewMatrix; var worldMatrix = D3D.WorldMatrix; var projectionMatrix = D3D.ProjectionMatrix; //// Rotate the world matrix by the rotation value so that the triangle will spin. Matrix.RotationY(Rotation, out worldMatrix); // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing. Model.Render(D3D.DeviceContext); // Render the model with the texture shader. if (!TextureShader.Render(D3D.DeviceContext, Model.IndexCount, worldMatrix, viewMatrix, projectionMatrix, Model.TextureCollection.Select(item => item.TextureResource).First())) { return(false); } // Get the world matrix again and translate down for the floor model to render underneath the cube. worldMatrix = D3D.WorldMatrix; Matrix.Translation(0, -1.5f, 0, out worldMatrix); // Get the camera reflection view matrix. var reflectionMatrix = Camera.ReflectionViewMatrix; // Put the floor model vertex and index buffers on the graphics pipeline to prepare them for drawing. FloorModel.Render(D3D.DeviceContext); // Render the floor model using the reflection shader, reflection texture, and reflection view matrix. if (!ReflectionShader.Render(D3D.DeviceContext, FloorModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, FloorModel.TextureCollection.Select(item => item.TextureResource).First(), RenderTexture.ShaderResourceView, reflectionMatrix)) { return(false); } // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
private bool RenderScene() { // Generate the view matrix based on the camera position. Camera.Render(); // Get the world, view, and projection matrices from camera and d3d objects. var viewMatrix = Camera.ViewMatrix; var worldMatrix = D3D.WorldMatrix; var projectionMatrix = D3D.ProjectionMatrix; // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing. Model.Render(D3D.DeviceContext); // Render the model using the color shader. if (!TextureShader.Render(D3D.DeviceContext, Model.IndexCount, worldMatrix, viewMatrix, projectionMatrix, Model.TextureCollection.Select(item => item.TextureResource).First())) { return(false); } // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing. Model.Render(D3D.DeviceContext); // Translate to the right by one unit and towards the camera by one unit. Matrix.Translation(1, 0, -1, out worldMatrix); // Setup a clipping plane. var blendAmount = 0.5f; // Turn on alpha blending for the transparency to work. D3D.TurnOnAlphaBlending(); // Put the second square model on the graphics pipeline. Model2.Render(D3D.DeviceContext); // Render the model using the color shader. if (!TransparentShader.Render(D3D.DeviceContext, Model2.IndexCount, worldMatrix, viewMatrix, projectionMatrix, Model2.TextureCollection.Select(item => item.TextureResource).ToArray(), blendAmount)) { return(false); } // Turn off alpha blending. D3D.TurnOffAlphaBlending(); return(true); }
public void Dispose() { if (SceneGraph != null) { SceneGraph.DisposeAll(); SceneGraph = null; } if (TextRenderer != null) { TextRenderer.Dispose(); TextRenderer = null; } if (CommandList != null) { CommandList.Dispose(); CommandList = null; } if (TexturePipeline != null) { TexturePipeline.Dispose(); TexturePipeline = null; } if (Pipeline != null) { Pipeline.Dispose(); Pipeline = null; } if (TextureShader != null) { TextureShader.Dispose(); TextureShader = null; } if (ColorShader != null) { ColorShader.Dispose(); ColorShader = null; } }
private bool DownSampleTextureMethod() { // Set the render target to be the render to texture. DownSampleTexture.SetRenderTarget(D3D.DeviceContext); // Clear the render to texture. DownSampleTexture.ClearRenderTarget(D3D.DeviceContext, 0.0f, 1.0f, 0.0f, 1.0f); // Generate the view matrix based on the camera's position. Camera.Render(); // Get the world and view matrices from the camera and d3d objects. Matrix worldMatrix = D3D.WorldMatrix; Matrix viewMatrix = Camera.ViewMatrix; // Get the ortho matrix from the render to texture since texture has different dimensions being that it is smaller. Matrix orthoMatrix = DownSampleTexture.OrthoMatrix; // Turn off the Z buffer to begin all 2D rendering. D3D.TurnZBufferOff(); // Put the small ortho window vertex and index buffers on the graphics pipeline to prepare them for drawing. if (!SmallWindow.Render(D3D.DeviceContext)) { return(false); } // Render the small ortho window using the texture shader and the render to texture of the scene as the texture resource. if (!TextureShader.Render(D3D.DeviceContext, SmallWindow.IndexCount, worldMatrix, viewMatrix, orthoMatrix, RenderTexture.ShaderResourceView)) { return(false); } // Turn the Z buffer back on now that all 2D rendering has completed. D3D.TurnZBufferOn(); // Reset the render target back to the original back buffer and not the render to texture anymore. D3D.SetBackBufferRenderTarget(); // Reset the viewport back to the original. D3D.ResetViewPort(); return(true); }
private bool RenderUIElementsToTexture() { // Set the render target to be the render to texture. RenderTexture.SetRenderTarget(D3D.DeviceContext); // Clear the render to texture. RenderTexture.ClearRenderTarget(D3D.DeviceContext, 0.0f, 0.0f, 0.0f, 1.0f); // Generate the view matrix based on the camera's position. Camera.Render(); // Get the world, view, and ortho matrices from the camera and d3d objects. Matrix worldMatrix = D3D.WorldMatrix; Matrix viewMatrix = Camera.ViewMatrix; Matrix orthoMatrix = D3D.OrthoMatrix; // Turn off the Z buffer to begin all 2D rendering. D3D.TurnZBufferOff(); // Put the bitmap vertex and index buffers on the graphics pipeline to prepare them for drawing. if (!BitMap.Render(D3D.DeviceContext, 100, 100)) { return(false); } // Render the bitmap using the texture shader. if (!TextureShader.Render(D3D.DeviceContext, BitMap.IndexCount, worldMatrix, viewMatrix, orthoMatrix, BitMap.Texture.TextureResource)) { return(false); } // Turn the Z buffer back on now that all 2D rendering has completed. D3D.TurnZBufferOn(); // Reset the render target back to the original back buffer and not the render to texture anymore. D3D.SetBackBufferRenderTarget(); // Reset the viewport back to the original. D3D.ResetViewPort(); return(true); }
public void Shutdown() { // Release the position object. Position = null; // Release the light object. Light = null; // Release the fps object. FPS = null; // Release the camera object. Camera = null; // Release the depth shader object. DepthShader?.ShutDown(); DepthShader = null; // Release the render to texture object. RenderTexture?.Shutdown(); RenderTexture = null; // Release the texture shader object. TextureShader?.ShutDown(); TextureShader = null; // Release the debug window bitmap object. DebugWindow?.Shutdown(); DebugWindow = null; // Release the text object. Text?.Shutdown(); Text = null; // Release the cpu object. CPU?.Shutdown(); CPU = null; // Release the terrain shader object. TerrainShader?.ShutDown(); TerrainShader = null; // Release the tree object. TerrainModel?.ShutDown(); TerrainModel = null; // Release the input object. Input?.Shutdown(); Input = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
public void Shutdown() { // Release the camera object. Camera = null; // Release the transparent shader object. TransparentShader?.ShutDown(); TransparentShader = null; // Release the texture shader object. TextureShader?.ShutDown(); TextureShader = null; //// Release the model object. Model?.Shutdown(); Model = null; Model2?.Shutdown(); Model2 = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
private void Initialize() { SetEGLContextClientVersion(2); // GLES 2 // SetZOrderOnTop(true); // SetEGLConfigChooser(8, 8, 8, 8, 16, 0); // Holder.SetFormat(Format.Rgba8888); // // setEGLConfigChooser(8, 8, 8, 8, 16, 0); // // setDebugFlags(DEBUG_CHECK_GL_ERROR | DEBUG_LOG_GL_CALLS); // TODO: find better way to handle shaders. Static dont work when restarting context AmbientShader.Reset(); ThresholdShader.Reset(); TextureShader.Reset(); renderer = new CountViewRenderer(Context); SetRenderer(renderer); gestureDetector = new GestureDetector(this); gestureDetector.IsLongpressEnabled = true; scaleGestureDetector = new ScaleGestureDetector(Context, this); }
private bool RenderToReflectionTexture() { // Set the render to be the render to the texture. RenderTexture.SetRenderTarget(D3D.DeviceContext, D3D.DepthStencilView); // Clear the render to texture. RenderTexture.ClearRenderTarget(D3D.DeviceContext, D3D.DepthStencilView, 0, 0, 0, 1); // Use the camera to calculate the reflection matrix. Camera.RenderReflection(-1.5f); // Get the camera reflection view matrix instead of the normal view matrix. var viewMatrix = Camera.ReflectionViewMatrix; // Get the world and projection matrices. var worldMatrix = D3D.WorldMatrix; var projectionMatrix = D3D.ProjectionMatrix; // Update the rotation variable each frame. Rotate(); // Rotate the world matrix by the rotation value Matrix.RotationY(Rotation, out worldMatrix); // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing. Model.Render(D3D.DeviceContext); // Render the model using the texture shader and the reflection view matrix. if (!TextureShader.Render(D3D.DeviceContext, Model.IndexCount, worldMatrix, viewMatrix, projectionMatrix, Model.TextureCollection.Select(item => item.TextureResource).First())) { return(false); } // Reset the render target back to the original back buffer and not to texture anymore. D3D.SetBackBufferRenderTarget(); return(true); }
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; }
/// <summary> /// Builds the shader(s) and passes required buffer array sizes. /// </summary> private void BuildShaders() { #if (DEBUG) using (new DisposableStopwatch(MethodBase.GetCurrentMethod().Name, true)) #endif { Dictionary <int, EBufferTypes> bufferTypes = new(); bufferTypes.Add(0, EBufferTypes.VertexArrayObject); bufferTypes.Add(1, EBufferTypes.VertexArrayObject); bufferTypes.Add(2, EBufferTypes.VertexArrayObject); triangleAndPointShader = ShaderProgramFactory.BuildTriangleAndPointShaderProgram("shaders/shader.vert", "shaders/shader.frag", bufferTypes); triangleAndPointShader.CurrentBuffer = 0; triangleAndPointShader.Vertexes = new float[stars.StarVertexesCount]; triangleAndPointShader.Indexes = new uint[stars.StarIndexesCount]; triangleAndPointShader.CurrentBuffer = 1; triangleAndPointShader.Vertexes = new float[spectrumBars.SpectrumBarVertexesCount]; triangleAndPointShader.Indexes = new uint[spectrumBars.SpectrumBarIndexesCount]; bufferTypes.Clear(); bufferTypes.Add(0, EBufferTypes.VertexArrayObject); textureShader = ShaderProgramFactory.BuildTextureShaderProgram("shaders/textureShader.vert", "shaders/textureShader.frag", bufferTypes); } }