Exemplo n.º 1
0
        //Filter FBO2 and Write result in FBO1[0]
        private void ProcessFilterPass(ITexture2D sourceTexture, IRenderSurface fbo)
        {
            int halfKernelX = kernelSizeX / 2;
            int halfKernelY = kernelSizeY / 2;

            fbo.Activate();
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);


            shaderSATFilter.Activate();

            int SATSampler = GL.GetUniformLocation(shaderSATFilter.ProgramID, "sourceSampler");

            GL.Uniform1(SATSampler, 0);

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, sourceTexture.ID);
            //sourceTexture.Activate();

            shaderSATFilter.Uniform("width", sourceTexture.Width);
            shaderSATFilter.Uniform("height", sourceTexture.Height);
            shaderSATFilter.Uniform("halfKernelX", halfKernelX);
            shaderSATFilter.Uniform("halfKernelY", halfKernelY);

            GL.DrawArrays(PrimitiveType.Quads, 0, 4);

            //sourceTexture.Deactivate();

            shaderSATFilter.Deactivate();

            fbo.Deactivate();
        }
Exemplo n.º 2
0
        private void SumValues(ITexture2D sourceTexture, IShaderProgram program, IRenderSurface fbo)
        {
            int SATSampler = GL.GetUniformLocation(fullScreenQuad.ProgramID, "sourceSampler");

            fbo.Activate();
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);


            program.Activate();
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.Uniform1(SATSampler, 0);

            GL.ActiveTexture(TextureUnit.Texture0);

            GL.BindTexture(TextureTarget.Texture2D, sourceTexture.ID);
            program.Uniform("blockLengthX", blockSizeX);
            program.Uniform("blockLengthY", blockSizeX);
            program.Uniform("amountBlockX", amountBlocksX);
            program.Uniform("amountBlockY", amountBlocksX);
            //satFilter.GetFilterTexture().Activate();
            GL.DrawArrays(PrimitiveType.Quads, 0, 4);
            //satFilter.GetFilterTexture().Deactivate();
            program.Deactivate();

            fbo.Deactivate();
        }
        static void InitializeGradient(IRenderSurface display)
        {
            if (PreviousClientSize != display.Stride + display.Height)
            {
                PreviousClientSize = display.Stride + display.Height;
                PixelBuffer        = new int[display.Height * display.Width];

                Color[] gradient = ColorUtility.CreateGradient(display.Width, ColorSet);

                int[] initialLine = new int[display.Stride];

                for (int index = 0; index < display.Stride; index++)
                {
                    Color current = gradient[index];

                    initialLine[index] = BitConverter.ToInt32
                                         (
                        new byte[] { current.B, current.G, current.R, 0 }, 0
                                         );
                }

                unsafe
                {
                    for (int line = 0; line < display.Height; line++)
                    {
                        fixed(int *ptr = &PixelBuffer[display.Stride * line])
                        {
                            Marshal.Copy(initialLine, 0, ( IntPtr )ptr, initialLine.Length);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Configures the present parameters
        /// </summary>
        /// <param name="renderSurface">Surface where the scene is going to be renedered to</param>
        private void SetupPresentParameters(IRenderSurface renderSurface)
        {
            System.Windows.Forms.Control view = (System.Windows.Forms.Control)renderSurface;

            // reset Present Parameters for the new swap
            presentParams = new PresentParameters();

            presentParams.Windowed   = true;
            presentParams.SwapEffect = SwapEffect.Copy;

            // setup the backbuffer
            presentParams.DeviceWindow = view;

            // setup back buffer
            //presentParams.BackBufferFormat = Manager.Adapters[0].CurrentDisplayMode.Format;
            presentParams.BackBufferFormat = Manager.Adapters[0].CurrentDisplayMode.Format;
            presentParams.BackBufferHeight = view.ClientSize.Height;
            presentParams.BackBufferWidth  = view.ClientSize.Width;

            // make sure graphics card can support 16-bit depth stenciling
            if (Manager.CheckDepthStencilMatch(0, DeviceType.Hardware,
                                               presentParams.BackBufferFormat,
                                               presentParams.BackBufferFormat,
                                               DepthFormat.D16))
            {
                // enabling automatic depth stencilling
                presentParams.AutoDepthStencilFormat = DepthFormat.D16;
                presentParams.EnableAutoDepthStencil = true;
            }
            else
            {
                throw new Exception("Graphics card does not support 16 bit depth stenciling");
            }
        }
Exemplo n.º 5
0
        static void DrawFire(IRenderSurface display)
        {
            int height = display.Height >= FireBufferHeight ?
                         FireBufferHeight : FireBufferHeight - display.Height,
                start    = display.Height - height,
                position = 0;

            byte *dest; int offset; Color pixel;

            for (int row = start; row < (display.Height - CoalHeight); row++)
            {
                offset = display.YValues[row + CoalHeight];

                dest = ( byte * )(display.Surface) + (offset << 2);

                for (int x = 0; x < display.Stride; x++)
                {
                    pixel = Palette[FireBuffer[display.YValues[position] + x]];

                    dest[0] = pixel.B;
                    dest[1] = pixel.G;
                    dest[2] = pixel.R;

                    dest += 4;
                }

                position++;
            }
        }
Exemplo n.º 6
0
        static void Flame(IRenderSurface display)
        {
            byte p1, p2, p3, p4, p5, p6, p7;
            int  u, d, l, r;

            for (int x = 0; x < FireBufferWidth; x++)
            {
                l = x == 0 ? 0 : x - 1;
                r = x == FireBufferWidth - 1 ? FireBufferWidth - 1 : x + 1;

                for (int y = 0; y < FireBufferHeight - 1; y++)
                {
                    u = y == 0 ? 0 : y - 1;
                    d = y == FireBufferHeight - 1 ? FireBufferHeight : y + 1;

                    p1 = FireBuffer[display.YValues[u] + l];
                    p2 = FireBuffer[display.YValues[y] + l];
                    p3 = FireBuffer[display.YValues[d] + l];

                    p4 = FireBuffer[display.YValues[d] + x];

                    p5 = FireBuffer[display.YValues[u] + r];
                    p6 = FireBuffer[display.YValues[y] + r];
                    p7 = FireBuffer[display.YValues[d] + r];

                    FireBuffer[display.YValues[u] + x] = ( byte )((p1 + p2 + +p3 + p4 + p5 + p6 + p7) / 7);
                }
            }
        }
Exemplo n.º 7
0
 public void UpdateResolution(int width, int height)
 {
     ((FBO)PassOneSurface)?.Dispose();
     PassOneSurface = new FBO(Texture2dGL.Create(width, height, FboTexComponentCount, FboTexFloat));
     ((FBO)PassTwoSurface)?.Dispose();
     PassTwoSurface = new FBO(Texture2dGL.Create(width, height, FboTexComponentCount, FboTexFloat));
 }
Exemplo n.º 8
0
        public void EditorThread_CreateScene(IRenderSurface renderSurface, EInputClass cameraInputClass)
        {
            IsCreated = true;
            OnEngineThread(() =>
            {
                Input.RegisterListener(EngineThread_OnInputEvent, cameraInputClass);
                // Create a new renderer scene with our viewport
                SSceneViewInfo viewInfo       = new SSceneViewInfo();
                viewInfo.Fov                  = FieldOfView;
                viewInfo.ScreenFar            = ScreenFar;
                viewInfo.ScreenNear           = ScreenNear;
                viewInfo.FitProjectionToScene = true;
                viewInfo.ViewMatrix           = Matrix.Invert(m_cameraTransform.WorldMatrix);
                viewInfo.ViewLocation         = m_cameraTransform.Position;
                viewInfo.CreateBoundingFrustum();

                m_renderScene = CRenderer.Instance.CreateRenderScene(renderSurface);
                if (m_renderScene != null)
                {
                    m_renderScene.OnDoFrame += EngineThread_Update;
                    m_renderScene.UpdateViewInfo(in viewInfo);
                    m_ambientLight                    = new CAmbientLight();
                    m_ambientLight.LightColor         = Vector4.One * 0.2f;
                    m_directionalLight                = new CDirectionalLight();
                    m_directionalLight.LightDirection = new Vector3(0.3f, -0.7f, 0.0f);
                    m_directionalLight.LightColor     = Vector4.One * 0.8f;
                    m_renderScene.LightManager.AddLight(m_ambientLight);
                    m_renderScene.LightManager.AddLight(m_directionalLight);
                }
            });
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initialize the device (hardware support, Z-buffer, blending, etc)
        /// </summary>
        /// <param name="renderSurface">Surface where the scene is going to be renedered to</param>
        private void InitializeDevice(IRenderSurface renderSurface)
        {
            // setup the present parameters before the device is created
            SetupPresentParameters(renderSurface);

            // get the capabilities of the graphics card
            Caps gfxCapabilities = Manager.GetDeviceCaps(0, DeviceType.Hardware);

            // if the device supports hardware Vertex processing use it
            if (gfxCapabilities.DeviceCaps.SupportsHardwareTransformAndLight)
            {
                device = new Device(0, DeviceType.Hardware, (System.Windows.Forms.Control)renderSurface, CreateFlags.HardwareVertexProcessing | CreateFlags.MultiThreaded, presentParams);
            }
            else
            {
                device = new Device(0, DeviceType.Hardware, (System.Windows.Forms.Control)renderSurface, CreateFlags.SoftwareVertexProcessing | CreateFlags.MultiThreaded, presentParams);
            }

            // enabled z-buffering so objects don't have to be drawn in correct order (back-to-front)
            device.RenderState.ZBufferEnable = true;

            // allow transparent textures
            device.RenderState.SourceBlend      = Blend.SourceAlpha;
            device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
        }
Exemplo n.º 10
0
        public void InitScene(Device device, DeviceContext deviceContext, IRenderSurface renderSurface)
        {
            SceneRenderer.Init(renderSurface, device);
            m_cameraBuffer.Init(device);
            m_cubeCameraBuffer.Init(device);

            LightManager.Init(device, deviceContext);
        }
Exemplo n.º 11
0
        public void UpdateResolution(int width, int height)
        {
            _ssao.UpdateResolution(width, height);
            _blur.UpdateResolution(width, height);

            ((FBO)_outputSurface)?.Dispose();
            _outputSurface = new FBO(Texture2dGL.Create(width, height));
        }
Exemplo n.º 12
0
        public void LockMouseCursor()
        {
            IRenderSurface renderSurface = m_hostControl.GetRenderSurface();
            Rectangle      clipRect      = new Rectangle(renderSurface.GetLeft(), renderSurface.GetTop(), renderSurface.GetWidth(), renderSurface.GetHeight());

            System.Windows.Forms.Cursor.Clip = clipRect;
            Input.SetCursorVisibility(false);
        }
Exemplo n.º 13
0
 public void UpdateResolution(int width, int height)
 {
     ((FBO)_outputSurface)?.Dispose();
     _outputSurface = new FBOwithDepth(Texture2dGL.Create(width, height));
     _outputSurface.Attach(Texture2dGL.Create(width, height, 3, true));
     _outputSurface.Attach(Texture2dGL.Create(width, height, 1, true));
     _outputSurface.Attach(Texture2dGL.Create(width, height, 3, true));
 }
Exemplo n.º 14
0
        public void UpdateResolution(int width, int height)
        {
            ((FBO)_outputSurface)?.Dispose();
            _outputSurface = new FBO(Texture2dGL.Create(width, height, _fboTexComponentCount, _fboTexFloat));

            _postProcessShader.Activate();
            _postProcessShader.Uniform("iResolution", new Vector2(width, height));
            _postProcessShader.Deactivate();
        }
Exemplo n.º 15
0
        public void UpdateResolution(int width, int height)
        {
            ((FBO)_outputSurface)?.Dispose();
            _outputSurface = new FBO(Texture2dGL.Create(width, height));

            _sphereCutProgram.Activate();
            _sphereCutProgram.Uniform("iResolution", new Vector2(width, height));
            _sphereCutProgram.Deactivate();
        }
 private void OnViewPortLoaded(object sender, RoutedEventArgs e)
 {
     if (m_bWorldLoaded && !PreviewScene.IsCreated)
     {
         IRenderSurface renderSurface = m_viewPortControl.GetRenderSurface();
         PreviewScene.EditorThread_CreateScene(renderSurface, EInputClass.AssetPreview);
         Input.SetInputClassActive(EInputClass.AssetPreview, IsActive);
     }
 }
Exemplo n.º 17
0
        public static IObject3D Pick(int X, int Y, Midget.Cameras.MidgetCamera camera, IRenderSurface renderSurface)
        {
            Vector3 pickRayDirection	= new Vector3();
            Vector3 pickRayOrigin		= new Vector3();

            camera.UnProjectCoordinates(X,Y, renderSurface.ClientWidth, renderSurface.ClientHeight, ref pickRayOrigin, ref pickRayDirection);

            //			// compute the vector of the pick ray in screen space
            //			Vector3 v = new Vector3();
            //			v.X =  ( ( ( 2.0f * X ) / renderSurface.ClientWidth ) - 1 ) / camera.ProjectionMatrix.M11;
            //			v.Y = -( ( ( 2.0f * Y ) / renderSurface.ClientHeight ) - 1 ) / camera.ProjectionMatrix.M22;
            //			v.Z =  1.0f;
            //
            //			// Get the inverse view matrix
            //			Matrix m = Matrix.Invert(camera.ViewMatrix);
            //
            //			// Transform the screen space pick ray into 3D space
            //			pickRayDirection.X  = v.X*m.M11 + v.Y*m.M21 + v.Z*m.M31;
            //			pickRayDirection.Y  = v.X*m.M12 + v.Y*m.M22 + v.Z*m.M32;
            //			pickRayDirection.Z  = v.X*m.M13 + v.Y*m.M23 + v.Z*m.M33;
            //
            //			pickRayDirection.Normalize();
            //
            //			pickRayOrigin.X = m.M41;
            //			pickRayOrigin.Y = m.M42;
            //			pickRayOrigin.Z = m.M43;
            //
            //			// calc origin as intersection with near frustum
            //
            //			pickRayOrigin += pickRayDirection * 1.0f;

            //			int zDistance = -1;
            //			IObject3D closestObj = null;

            //			foreach (IObject3D obj in DeviceManager.Instance.ObjectList)
            //			{
            //
            //				// transform world space to object space
            //				Vector3 pickRayOriginTemp = new Vector3(pickRayOrigin.X, pickRayOrigin.Y, pickRayOrigin.Z);
            //				Vector3 pickRayDirectionTemp = new Vector3(pickRayDirection.X,pickRayDirection.Y,pickRayDirection.Z);
            //
            //				// convert ray from 3d space to model space
            //				pickRayOriginTemp.TransformCoordinate(Matrix.Invert(obj.WorldSpace));	//Matrix.Invert(Matrix.Identity));
            //				pickRayDirectionTemp.TransformNormal(Matrix.Invert(obj.WorldSpace));	//inverse);
            //
            //
            //				if (obj.Intersect(pickRayOriginTemp, pickRayDirectionTemp) > zDistance)
            //				{
            //					closestObj = obj;
            //				}
            //			}

            return SceneManager.Instance.Scene.Intersect(pickRayOrigin, pickRayDirection, camera.WorldMatrix);

            //return closestObj;
        }
Exemplo n.º 18
0
        public void Init(IRenderSurface surface, Device device)
        {
            Width           = surface.GetWidth();
            Height          = surface.GetHeight();
            Top             = surface.GetTop();
            Left            = surface.GetLeft();
            m_renderSurface = surface;

            InitializeDeviceResources(device);
        }
Exemplo n.º 19
0
        static void Render(IRenderSurface display)
        {
            EnsureCorrectBufferSize(display);

            GenerateCoalBed(display);

            Flame(display);

            DrawFire(display);
        }
Exemplo n.º 20
0
        public void UpdateResolution(int width, int height)
        {
            ((FBO)_depthSurface)?.Dispose();
            _depthSurface = new FBOwithDepth(Texture2dGL.Create(width * 4, height * 4, 1, true));
            ((FBO)_outputSurface)?.Dispose();
            _outputSurface = new FBOwithDepth(Texture2dGL.Create(width, height, 1));

            _depthShader.Uniform("iResolution", new Vector2(width, height));
            _shadowShader.Uniform("iResolution", new Vector2(width, height));
        }
Exemplo n.º 21
0
        public Visual(IRenderState renderState, IContentLoader contentLoader)
        {
            fbo = new FBO(Texture2dGL.Create(70, 70));
            fbo.Texture.Filter = TextureFilterMode.Nearest;
            copyToFrameBuffer  = new PostProcessing(contentLoader.LoadPixelShader("copy.frag"));

            renderState.Set(BlendStates.AlphaBlend);
            renderState.Set(new LineSmoothing(true));
            renderState.Set(new LineWidth(5f));
            GL.Enable(EnableCap.PointSmooth);
        }
Exemplo n.º 22
0
        static void EnsureCorrectBufferSize(IRenderSurface display)
        {
            int clientSize = display.Stride + display.Height;

            if (PreviousClientSize != clientSize)
            {
                CreateBuffer(display.Stride, display.Height);

                PreviousClientSize = clientSize;
            }
        }
Exemplo n.º 23
0
        public void Init(IRenderSurface surface)
        {
            m_owningThread = Thread.CurrentThread;
            m_d3dRenderer.Init();

            // Create the default scene
            CreateRenderScene(surface);
            ActiveScene = m_renderScenes[0];

            Init();
        }
Exemplo n.º 24
0
 private void SetUpBlocksAndTextures(int amountBlocksX, int amountBlocksY, int resX, int resY)
 {
     this.amountBlocksX = amountBlocksX;
     this.amountBlocksY = amountBlocksY;
     this.blockSizeX    = resX / amountBlocksX;
     this.blockSizeY    = resY / amountBlocksY;
     FBO1 = new FBO(Texture2dGL.Create(resX, resY, 4, true));
     FBO1.Texture.WrapFunction = TextureWrapFunction.MirroredRepeat;
     FBO2 = new FBO(Texture2dGL.Create(resX, resY, 4, true));
     FBO2.Texture.WrapFunction = TextureWrapFunction.MirroredRepeat;
 }
Exemplo n.º 25
0
        public void Begin(Environment environment, IRenderSurface renderSurface, bool showTitleText)
        {
            _environment = environment;
            _surface     = renderSurface;

            _environment.CurrentRoomId = _environment.GetPlayer().RoomId ?? ID_DEFAULT;

            if (showTitleText)
            {
                this.StartNarrating(_environment.Title);
            }
        }
        public override void PostWorldLoad()
        {
            base.PostWorldLoad();

            m_bWorldLoaded = true;
            if (m_viewPortControl.IsLoaded && !PreviewScene.IsCreated)
            {
                IRenderSurface renderSurface = m_viewPortControl.GetRenderSurface();
                PreviewScene.EditorThread_CreateScene(renderSurface, EInputClass.AssetPreview);
                Input.SetInputClassActive(EInputClass.AssetPreview, IsActive);
            }
        }
Exemplo n.º 27
0
        public Water(IContentLoader contentLoader)
        {
            waterMapShader = contentLoader.Load <IShaderProgram>("WaterMap.*");
            mapFBO         = new FBO(Texture2dGL.Create(256, 256, 4, true));
            mapFBO.Attach(Texture2dGL.Create(256, 256, 4, true));
            mapFBO.Textures[0].WrapFunction = TextureWrapFunction.MirroredRepeat;
            waveLayers = GetWaveLayer();
            List <Wave> waveList = GetWaves();

            numberOfWaves = waveList.Count;
            waveBuffer.Set(waveList.ToArray(), BufferUsageHint.StaticCopy);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Renders the current scene in a single viewport
        /// </summary>
        /// <param name="renderSurface">The view that is to be rendered too</param>
        public void RenderSingleView(IRenderSurface renderSurface)
        {
            // make sure the device is initialised and that the view is initialised
            if ((device != null) && (renderSurface.SwapChain != null) && (!renderSurface.SwapChain.Disposed))
            {
                // get the backbuffer of the surface that is to be rendered to
                Surface surface = renderSurface.SwapChain.GetBackBuffer(0, BackBufferType.Mono);

                // set the device so it renders to the back buffer
                device.SetRenderTarget(0, surface);

                surface.ReleaseGraphics();

                device.DepthStencilSurface = renderSurface.DepthStencil;

                // get the camera that current render surface is using
                MidgetCameras.MidgetCamera camera = renderSurface.Camera;

                // adjust the device camera
                device.Transform.View       = camera.ViewMatrix;
                device.Transform.Projection = camera.ProjectionMatrix;

                //device.PresentationParameters.DeviceWindow.

                // clear the backbuffer
                device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, renderSurface.BackColor, 1.0f, 0);

                // setup the render quality for the viewport
                SetupDrawMode(renderSurface.DrawMode);

                // start drawing the scene
                device.BeginScene();

                // render the scene
                //device.Transform.World = Matrix.Identity;
                SceneManager.Instance.Scene.Render(device, Matrix.Identity, SceneManager.Instance.CurrentFrameIndex);

                // display viewport description text
                Microsoft.DirectX.Direct3D.Font viewportD3DFont
                    = new Microsoft.DirectX.Direct3D.Font(device, new System.Drawing.Font("Arial", 12, FontStyle.Bold));
                viewportD3DFont.DrawText(renderSurface.Description, new Rectangle(4, 4, 100, 30),
                                         DrawTextFormat.Left, Color.Black);
                // TODO: FIX: D3DFont line causes NullReferenceExceptions to be thrown sometimes
                viewportD3DFont.DrawText(renderSurface.Description, new Rectangle(5, 5, 100, 30),
                                         DrawTextFormat.Left, Color.White);
                viewportD3DFont.Dispose();

                // end the scene and display it
                device.EndScene();
                renderSurface.SwapChain.Present();
            }
        }
Exemplo n.º 29
0
        public void UpdateResolution(int width, int height)
        {
            ((FBO)_outputSurface)?.Dispose();
            _outputSurface = new FBO(Texture2dGL.Create(width, height));
            for (int i = 0; i < _bloom.Length; i++)
            {
                _bloom[i].UpdateResolution(width, height);
            }

            _environmentMapProgram.Activate();
            _environmentMapProgram.Uniform("iResolution", new Vector2(width, height));
            _environmentMapProgram.Deactivate();
        }
Exemplo n.º 30
0
 public static void FillArea(this IRenderSurface surface, BitsyGame.Color c, int x, int y, int width, int height)
 {
     if (surface == null)
     {
         return;
     }
     for (int i = 0; i < width; i++)
     {
         for (int j = 0; j < height; j++)
         {
             surface.SetPixel(c, x + i, y + j);
         }
     }
 }
Exemplo n.º 31
0
        public void FillTile(BitsyGame.Color color, int x, int y, IRenderSurface context)
        {
            if (context == null)
            {
                return;
            }

            for (int i = 0; i < BitsyGame.TILESIZE * BitsyGame.PIXEL_SCALE; i++)
            {
                for (int j = 0; j < BitsyGame.TILESIZE * BitsyGame.PIXEL_SCALE; j++)
                {
                    context.SetPixel(color, x + i, y + j);
                }
            }
        }
Exemplo n.º 32
0
        public override void Render(IRenderSurface surface)
        {
            if (!Visible)
                return;
            //  Render shadow and car itself
            surface.RenderBitmap(ShadowBitmap, Location.X + 1, Location.Y + 1);
            base.Render(surface);

            // Calculate and render smoke
            int smokeScale = 0;
            if (smokeRotation > 5)
                smokeScale = 1;
            else if (smokeRotation < -5)
                smokeScale = 0;

            surface.BackGraphics.TranslateTransform(Location.X, Location.Y + 16);
            surface.BackGraphics.RotateTransform((float)smokeRotation);
            surface.BackGraphics.DrawImage(SmokeBitmap,
                new Rectangle(0, 0,
                    SmokeBitmap.Width + smokeScale, SmokeBitmap.Height + smokeScale));
            surface.BackGraphics.ResetTransform();
        }
Exemplo n.º 33
0
        public void SetSwapChain(IRenderSurface renderTarget)
        {
            if(renderTarget.SwapChain != null)
            {
                renderTarget.SwapChain.Dispose();

                renderTarget.SwapChain = null;

                SetupPresentParameters(renderTarget);

                // create new swap chain
                renderTarget.SwapChain = new SwapChain(device,presentParams);
            }

            if(renderTarget.DepthStencil != null)
            {
                renderTarget.DepthStencil.Dispose();

                renderTarget.DepthStencil = null;

                renderTarget.DepthStencil = device.CreateDepthStencilSurface(renderTarget.ClientWidth,renderTarget.ClientHeight,DepthFormat.D16, MultiSampleType.None,0,true);
            }
        }
Exemplo n.º 34
0
        /// <summary>
        /// Initialize the device (hardware support, Z-buffer, blending, etc)
        /// </summary>
        /// <param name="renderSurface">Surface where the scene is going to be renedered to</param>
        private void InitializeDevice(IRenderSurface renderSurface)
        {
            // setup the present parameters before the device is created
            SetupPresentParameters(renderSurface);

            // get the capabilities of the graphics card
            Caps gfxCapabilities = Manager.GetDeviceCaps(0,DeviceType.Hardware);

            // if the device supports hardware Vertex processing use it
            if(gfxCapabilities.DeviceCaps.SupportsHardwareTransformAndLight)
                device = new Device(0,DeviceType.Hardware,(System.Windows.Forms.Control)renderSurface, CreateFlags.HardwareVertexProcessing | CreateFlags.MultiThreaded, presentParams);
            else
                device = new Device(0,DeviceType.Hardware,(System.Windows.Forms.Control)renderSurface, CreateFlags.SoftwareVertexProcessing | CreateFlags.MultiThreaded, presentParams);

            // enabled z-buffering so objects don't have to be drawn in correct order (back-to-front)
            device.RenderState.ZBufferEnable = true;

            // allow transparent textures
            device.RenderState.SourceBlend = Blend.SourceAlpha;
            device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
        }
Exemplo n.º 35
0
        /// <summary>
        /// Configures the present parameters
        /// </summary>
        /// <param name="renderSurface">Surface where the scene is going to be renedered to</param>
        private void SetupPresentParameters(IRenderSurface renderSurface)
        {
            System.Windows.Forms.Control view = (System.Windows.Forms.Control)renderSurface;

            // reset Present Parameters for the new swap
            presentParams = new PresentParameters();

            presentParams.Windowed = true;
            presentParams.SwapEffect = SwapEffect.Copy;

            // setup the backbuffer
            presentParams.DeviceWindow = view;

            // setup back buffer
            //presentParams.BackBufferFormat = Manager.Adapters[0].CurrentDisplayMode.Format;
            presentParams.BackBufferFormat = Manager.Adapters[0].CurrentDisplayMode.Format;
            presentParams.BackBufferHeight = view.ClientSize.Height;
            presentParams.BackBufferWidth = view.ClientSize.Width;

            // make sure graphics card can support 16-bit depth stenciling
            if(Manager.CheckDepthStencilMatch(0, DeviceType.Hardware,
                presentParams.BackBufferFormat,
                presentParams.BackBufferFormat,
                DepthFormat.D16))
            {
                // enabling automatic depth stencilling
                presentParams.AutoDepthStencilFormat = DepthFormat.D16;
                presentParams.EnableAutoDepthStencil = true;
            }
            else
                throw new Exception("Graphics card does not support 16 bit depth stenciling");
        }
Exemplo n.º 36
0
 public void SetRenderSurface(IRenderSurface surface)
 {
     this.surface = surface;
     surface.SetNumbersBitmap(ResourceManager.GetBitmapResource("Numbers"), 5);
 }
Exemplo n.º 37
0
        /// <summary>
        /// Renders the current scene in a single viewport
        /// </summary>
        /// <param name="renderSurface">The view that is to be rendered too</param>
        public void RenderSingleView(IRenderSurface renderSurface)
        {
            // make sure the device is initialised and that the view is initialised
            if((device != null) && (renderSurface.SwapChain != null) && (!renderSurface.SwapChain.Disposed))
            {

                // get the backbuffer of the surface that is to be rendered to
                Surface surface =  renderSurface.SwapChain.GetBackBuffer(0,BackBufferType.Mono);

                // set the device so it renders to the back buffer
                device.SetRenderTarget(0,surface);

                surface.ReleaseGraphics();

                device.DepthStencilSurface = renderSurface.DepthStencil;

                // get the camera that current render surface is using
                MidgetCameras.MidgetCamera camera = renderSurface.Camera;

                // adjust the device camera
                device.Transform.View = camera.ViewMatrix;
                device.Transform.Projection = camera.ProjectionMatrix;

                //device.PresentationParameters.DeviceWindow.

                // clear the backbuffer
                device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, renderSurface.BackColor, 1.0f, 0);

                // setup the render quality for the viewport
                SetupDrawMode(renderSurface.DrawMode);

                // start drawing the scene
                device.BeginScene();

                // render the scene
                //device.Transform.World = Matrix.Identity;
                SceneManager.Instance.Scene.Render(device, Matrix.Identity, SceneManager.Instance.CurrentFrameIndex);

                // display viewport description text
                Microsoft.DirectX.Direct3D.Font viewportD3DFont
                    = new Microsoft.DirectX.Direct3D.Font(device, new System.Drawing.Font("Arial", 12, FontStyle.Bold));
                viewportD3DFont.DrawText(renderSurface.Description, new Rectangle(4, 4, 100, 30),
                    DrawTextFormat.Left, Color.Black);
                // TODO: FIX: D3DFont line causes NullReferenceExceptions to be thrown sometimes
                viewportD3DFont.DrawText(renderSurface.Description, new Rectangle(5, 5, 100, 30),
                    DrawTextFormat.Left, Color.White);
                viewportD3DFont.Dispose();

                // end the scene and display it
                device.EndScene();
                renderSurface.SwapChain.Present();
            }
        }
Exemplo n.º 38
0
 public virtual void Render(IRenderSurface surface)
 {
     if (Visible)
         surface.RenderBitmap(Bitmap, Location);
 }
Exemplo n.º 39
0
        /// <summary>
        /// Add a viewport (based on its display surface), and set up its swap chain
        /// </summary>
        /// <param name="renderTarget">the display surface to be drawn to</param>
        /// <returns>true if successful, false if an error occurs</returns>
        public bool AddViewport(IRenderSurface renderTarget)
        {
            try
            {
                // check for device existence, create if needed
                if (device == null)
                {
                    InitializeDevice(renderTarget);

                    // get Device SwapChain
                    renderTarget.SwapChain = device.GetSwapChain(0);

                    // add renderSurface to the list
                    renderSurfaceList.Add(renderTarget);
                }

                    // this is an additional view
                else
                {
                    SetupPresentParameters(renderTarget);

                    // create new swap chain
                    renderTarget.SwapChain = new SwapChain(device,presentParams);

                    // add renderSurface to the list
                    renderSurfaceList.Add(renderTarget);
                }
            }
            catch	// an error occurred somewhere
            {
                return false;
            }

            renderTarget.DepthStencil = device.CreateDepthStencilSurface(renderTarget.ClientWidth,renderTarget.ClientHeight,DepthFormat.D16, MultiSampleType.None,0,true);

            device.RenderState.ZBufferEnable = true;

            return true;
        }
Exemplo n.º 40
0
 public void SetRenderSurface(IRenderSurface surface)
 {
     this.surface = surface;
 }