Esempio n. 1
0
        public GraphicsContext(int width, int height, PixelFormat colorFormat, PixelFormat depthFormat, MultiSampleMode multiSampleMode)
        {
            int errorCode = PsmGraphicsContext.Create(width, height, colorFormat, depthFormat, multiSampleMode, out this.handle);

            if (errorCode != 0)
            {
                Error.ThrowNativeException(errorCode);
            }
            this.caps   = new GraphicsCaps(this);
            this.screen = (this.deviceScreen = new FrameBuffer(this));
            if (ScreenBuffer.NeedVirtualScreen(this.screen, ref width, ref height))
            {
                this.screen = (this.virtualScreen = new ScreenBuffer(this, this.deviceScreen, width, height, colorFormat, depthFormat, multiSampleMode));
                GraphicsContext.notifyUpdate |= (GraphicsUpdate)6U;
            }
            this.SetFrameBuffer(null);
            this.state.Reset(this.screen);
            GraphicsContext.notifyUpdate |= GraphicsUpdate.Viewport;
        }
Esempio n. 2
0
        public static bool NeedVirtualScreen(FrameBuffer screen, ref int width, ref int height)
        {
            if (width == 0)
            {
                width = screen.Width;
            }
            if (height == 0)
            {
                height = screen.Height;
            }
            int screenWidth;
            int screenHeight;

            PsmGraphicsContext.GetMaxScreenSize(out screenWidth, out screenHeight);
            if (width > screenWidth || height > screenHeight)
            {
                ScreenBuffer.FitRect(screenWidth, screenHeight, ref width, ref height);
            }
            return(screen.Width != width || screen.Height != height);
        }
Esempio n. 3
0
 public void Reset(FrameBuffer screen)
 {
     this.Enable           = EnableMode.Dither;
     this.Scissor          = new ImageRect(0, 0, screen.Width, screen.Height);
     this.Viewport         = new ImageRect(0, 0, screen.Width, screen.Height);
     this.DepthRange       = new Vector2(0f, 1f);
     this.ClearColor       = new Vector4(0f, 0f, 0f, 0f);
     this.ClearDepth       = 1f;
     this.ClearStencil     = 0;
     this.CullFace         = new CullFace(CullFaceMode.Back, CullFaceDirection.Ccw);
     this.BlendFuncRgb     = new BlendFunc(BlendFuncMode.Add, BlendFuncFactor.One, BlendFuncFactor.Zero);
     this.BlendFuncAlpha   = this.BlendFuncRgb;
     this.DepthFunc        = new DepthFunc(DepthFuncMode.Less, true);
     this.PolygonOffset    = new PolygonOffset(0f, 0f);
     this.StencilFuncFront = new StencilFunc(StencilFuncMode.Always, 0, 255, 255);
     this.StencilOpFront   = new StencilOp(StencilOpMode.Keep, StencilOpMode.Keep, StencilOpMode.Keep);
     this.StencilFuncBack  = this.StencilFuncFront;
     this.StencilOpBack    = this.StencilOpFront;
     this.ColorMask        = ColorMask.Rgba;
     this.LineWidth        = 1f;
 }
Esempio n. 4
0
        private void AdjustAspect(GraphicsContext graphics, FrameBuffer deviceScreen, int width, int height)
        {
            int endPointY    = 0;
            int endPointX    = 0;
            int w            = width;
            int h            = height;
            int screenWidth  = deviceScreen.Width;
            int screenHeight = deviceScreen.Height;

            ushort[] vertexData = new ushort[4];
            float    multip;

            if (ScreenBuffer.FitRect(screenWidth, screenHeight, ref width, ref height))
            {
                endPointY     = (screenWidth - width) / 2;
                multip        = (float)endPointY / (float)screenWidth * 2f - 1f;
                vertexData[0] = 18;
                vertexData[1] = 27;
                vertexData[2] = 36;
                vertexData[3] = 45;
            }
            else
            {
                endPointX     = (screenHeight - height) / 2;
                multip        = (float)endPointX / (float)screenHeight * -2f + 1f;
                vertexData[0] = 10;
                vertexData[1] = 28;
                vertexData[2] = 37;
                vertexData[3] = 55;
            }
            for (int i = 0; i < 4; i++)
            {
                ScreenBuffer.vertexData[(int)vertexData[i]]        = multip;
                ScreenBuffer.vertexData[(int)(vertexData[i] + 36)] = -multip;
            }
            PsmGraphicsContext.SetActiveScreen(graphics.handle, endPointY, endPointX, width, height);
            PsmGraphicsContext.SetVirtualScreen(graphics.handle, 0, 0, w, h);
        }
Esempio n. 5
0
        protected override bool init(DisposableI parent, string fileName, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback)
        {
            if (!base.init(parent, fileName, width, height, false, multiSampleType, surfaceFormat, renderTargetUsage, usage, true, loadedCallback))
            {
                return(false);
            }

            try
            {
                if (usage == BufferUsages.Write)
                {
                    Debug.ThrowError("RenderTarget", "Only Textures may be writable");
                }

                frameBuffer = new G.FrameBuffer();
                frameBuffer.SetColorTarget(texture, 0);
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                Dispose();
                if (loadedCallback != null)
                {
                    loadedCallback(this, false);
                }
                return(false);
            }

            Loaded = true;
            if (loadedCallback != null)
            {
                loadedCallback(this, true);
            }
            return(true);
        }
Esempio n. 6
0
        protected override bool init(DisposableI parent, string fileName, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback)
        {
            if (!base.init(parent, fileName, width, height, false, multiSampleType, surfaceFormat, renderTargetUsage, usage, true, loadedCallback)) return false;

            try
            {
                if (usage == BufferUsages.Write) Debug.ThrowError("RenderTarget", "Only Textures may be writable");

                frameBuffer = new G.FrameBuffer();
                frameBuffer.SetColorTarget(texture, 0);
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                Dispose();
                if (loadedCallback != null) loadedCallback(this, false);
                return false;
            }

            Loaded = true;
            if (loadedCallback != null) loadedCallback(this, true);
            return true;
        }
Esempio n. 7
0
 /// <summary>Sets the frame buffer</summary>
 /// <param name="buffer">Frame buffer (release when NULL)</param>
 public void SetFrameBuffer(FrameBuffer buffer)
 {
     this.frameBuffer              = ((buffer != null) ? buffer : this.screen);
     this.handles[1]               = this.frameBuffer.handle;
     GraphicsContext.notifyUpdate |= GraphicsUpdate.FrameBuffer;
 }