Ejemplo n.º 1
0
        public CCRenderTexture(CCSize contentSize, CCSize textureSizeInPixels, 
            CCSurfaceFormat colorFormat=CCSurfaceFormat.Color, 
            CCDepthFormat depthFormat=CCDepthFormat.None, 
            CCRenderTargetUsage usage=CCRenderTargetUsage.DiscardContents) : this()
        {
            int textureWidth = (int)textureSizeInPixels.Width;
            int textureHeight = (int)textureSizeInPixels.Height;

            renderTarget2D = drawManager.CreateRenderTarget(
                textureWidth, textureHeight, colorFormat, depthFormat, usage);

            Texture = new CCTexture2D(renderTarget2D, colorFormat, true, false);
            Texture.IsAntialiased = false;

            Sprite = new CCSprite(Texture);
            Sprite.ContentSize = contentSize;
            Sprite.BlendFunc = CCBlendFunc.AlphaBlend;

            CCPoint center = contentSize.Center;

            renderViewMatrix = 
                Matrix.CreateLookAt(new CCPoint3(center, 300.0f).XnaVector, new CCPoint3(center, 0.0f).XnaVector, Vector3.Up);
            renderProjMatrix = 
                Matrix.CreateOrthographic(contentSize.Width, contentSize.Height, 1024f, -1024);
            renderViewport = new Viewport(0, 0, textureWidth, textureHeight);


            clearColor = CCColor4B.Transparent;
            drawManager.SetRenderTarget(Texture);
            drawManager.Clear(clearColor);
            drawManager.RestoreRenderTarget();
        }
Ejemplo n.º 2
0
        internal CCDrawManager(GraphicsDevice device)
        {
            Renderer = new CCRenderer(this);

            depthTest = true;
            allowNonPower2Textures = true;
            hasStencilBuffer       = true;
            currBlend           = CCBlendFunc.AlphaBlend;
            platformDepthFormat = CCDepthFormat.Depth24;
            transform           = Matrix.Identity;

            TmpVertices = new CCRawList <CCV3F_C4B_T2F>();
            matrixStack = new Matrix[100];
            blendStates = new Dictionary <CCBlendFunc, BlendState>();
            effectStack = new Stack <Effect>();

            InitializeRawQuadBuffers();

            rasterizerStatesCache = new List <RasterizerState>();

            hasStencilBuffer = true;

            graphicsDevice = device;
            InitializeGraphicsDevice();
        }
Ejemplo n.º 3
0
        public CCRenderTexture(CCSize contentSize, CCSize textureSizeInPixels,
                               CCSurfaceFormat colorFormat = CCSurfaceFormat.Color,
                               CCDepthFormat depthFormat   = CCDepthFormat.None,
                               CCRenderTargetUsage usage   = CCRenderTargetUsage.DiscardContents) : this()
        {
            int textureWidth  = (int)textureSizeInPixels.Width;
            int textureHeight = (int)textureSizeInPixels.Height;

            renderTarget2D = drawManager.CreateRenderTarget(
                textureWidth, textureHeight, colorFormat, depthFormat, usage);

            Texture = new CCTexture2D(renderTarget2D, colorFormat, true, false);
            Texture.IsAntialiased = false;

            Sprite             = new CCSprite(Texture);
            Sprite.ContentSize = contentSize;
            Sprite.BlendFunc   = CCBlendFunc.AlphaBlend;

            CCPoint center = contentSize.Center;

            renderViewMatrix =
                Matrix.CreateLookAt(new CCPoint3(center, 300.0f).XnaVector, new CCPoint3(center, 0.0f).XnaVector, Vector3.Up);
            renderProjMatrix =
                Matrix.CreateOrthographic(contentSize.Width, contentSize.Height, 1024f, -1024);
            renderViewport = new Viewport(0, 0, textureWidth, textureHeight);


            clearColor = CCColor4B.Transparent;
            drawManager.SetRenderTarget(Texture);
            drawManager.Clear(clearColor);
            drawManager.RestoreRenderTarget();
        }
Ejemplo n.º 4
0
        internal CCDrawManager(GraphicsDeviceManager deviceManager, CCSize proposedScreenSize,
                               CCDisplayOrientation supportedOrientations)
        {
            Renderer = new CCRenderer(this);

            graphicsDeviceMgr = deviceManager;

            depthTest = true;
            allowNonPower2Textures = true;
            hasStencilBuffer       = true;
            currBlend           = CCBlendFunc.AlphaBlend;
            platformDepthFormat = CCDepthFormat.Depth24;
            transform           = Matrix.Identity;

            TmpVertices = new CCRawList <CCV3F_C4B_T2F>();
            matrixStack = new Matrix[100];
            blendStates = new Dictionary <CCBlendFunc, BlendState>();
            effectStack = new Stack <Effect>();

            rasterizerStatesCache = new List <RasterizerState>();

            hasStencilBuffer = (deviceManager.PreferredDepthStencilFormat == DepthFormat.Depth24Stencil8);


            if (deviceManager.GraphicsDevice == null)
            {
                initialProposedScreenSizeInPixels           = proposedScreenSize;
                graphicsDeviceMgr.PreferredBackBufferWidth  = (int)initialProposedScreenSizeInPixels.Width;
                graphicsDeviceMgr.PreferredBackBufferHeight = (int)initialProposedScreenSizeInPixels.Height;
                graphicsDeviceMgr.SupportedOrientations     = (DisplayOrientation)supportedOrientations;
                graphicsDeviceMgr.DeviceCreated            += GraphicsDeviceCreated;
                graphicsDeviceMgr.PreparingDeviceSettings  += PreparingDeviceSettings;
            }
        }
Ejemplo n.º 5
0
        public CCRenderTexture(CCSize contentSize, CCSize textureSizeInPixels, 
            CCSurfaceFormat colorFormat=CCSurfaceFormat.Color, 
            CCDepthFormat depthFormat=CCDepthFormat.None, 
            CCRenderTargetUsage usage=CCRenderTargetUsage.DiscardContents)
        {
            int textureWidth = (int)textureSizeInPixels.Width;
            int textureHeight = (int)textureSizeInPixels.Height;

            firstUsage = true;
            renderTarget2D = CCDrawManager.SharedDrawManager.CreateRenderTarget(textureWidth, textureHeight, colorFormat, depthFormat, usage);

            Texture = new CCTexture2D(renderTarget2D, colorFormat, true, false);
            Texture.IsAntialiased = false;

            Sprite = new CCSprite(Texture);
            Sprite.ContentSize = contentSize;
            Sprite.BlendFunc = CCBlendFunc.AlphaBlend;

            AddChild(Sprite);
        }
Ejemplo n.º 6
0
        public CCRenderTexture(CCSize contentSize, CCSize textureSizeInPixels,
                               CCSurfaceFormat colorFormat = CCSurfaceFormat.Color,
                               CCDepthFormat depthFormat   = CCDepthFormat.None,
                               CCRenderTargetUsage usage   = CCRenderTargetUsage.DiscardContents)
        {
            int textureWidth  = (int)textureSizeInPixels.Width;
            int textureHeight = (int)textureSizeInPixels.Height;

            firstUsage     = true;
            renderTarget2D = CCDrawManager.SharedDrawManager.CreateRenderTarget(textureWidth, textureHeight, colorFormat, depthFormat, usage);

            Texture = new CCTexture2D(renderTarget2D, colorFormat, true, false);
            Texture.IsAntialiased = false;

            Sprite             = new CCSprite(Texture);
            Sprite.ContentSize = contentSize;
            Sprite.BlendFunc   = CCBlendFunc.AlphaBlend;

            AddChild(Sprite);
        }
Ejemplo n.º 7
0
 internal RenderTarget2D CreateRenderTarget(int width, int height, CCSurfaceFormat colorFormat, CCDepthFormat depthFormat,
                                            CCRenderTargetUsage usage)
 {
     if (!allowNonPower2Textures)
     {
         width  = CCUtils.CCNextPOT(width);
         height = CCUtils.CCNextPOT(height);
     }
     return(new RenderTarget2D(graphicsDevice, width, height, false, (SurfaceFormat)colorFormat, (DepthFormat)depthFormat, 0, (RenderTargetUsage)usage));
 }
Ejemplo n.º 8
0
        void InitializeGraphicsDevice()
        {
            SpriteBatch   = new SpriteBatch(graphicsDevice);
            defaultEffect = new BasicEffect(graphicsDevice);

            AlphaTestEffect = new AlphaTestEffect(graphicsDevice);

            PrimitiveEffect = new BasicEffect(graphicsDevice)
            {
                TextureEnabled     = false,
                VertexColorEnabled = true
            };

            depthEnableStencilState = new DepthStencilState
            {
                DepthBufferEnable      = true,
                DepthBufferWriteEnable = true,
                TwoSidedStencilMode    = true
            };

            depthDisableStencilState = new DepthStencilState
            {
                DepthBufferEnable = false
            };

            #if !WINDOWS_PHONE && !XBOX && !WINDOWS && !NETFX_CORE
            List <string> extensions = CCUtils.GetGLExtensions();
            foreach (string s in extensions)
            {
                switch (s)
                {
                case "GL_OES_depth24":
                    platformDepthFormat = CCDepthFormat.Depth24;
                    break;

                case "GL_IMG_texture_npot":
                    allowNonPower2Textures = true;
                    break;

                case "GL_NV_depth_nonlinear":                       // nVidia Depth 16 non-linear
                    platformDepthFormat = CCDepthFormat.Depth16;
                    break;

                case "GL_NV_texture_npot_2D_mipmap":                // nVidia - nPot textures and mipmaps
                    allowNonPower2Textures = true;
                    break;
                }
            }
            #endif

            projectionMatrix = Matrix.Identity;
            viewMatrix       = Matrix.Identity;
            worldMatrix      = Matrix.Identity;
            matrix           = Matrix.Identity;

            worldMatrixChanged = viewMatrixChanged = projectionMatrixChanged = true;

            graphicsDevice.Disposing         += GraphicsDeviceDisposing;
            graphicsDevice.DeviceLost        += GraphicsDeviceDeviceLost;
            graphicsDevice.DeviceReset       += GraphicsDeviceDeviceReset;
            graphicsDevice.DeviceResetting   += GraphicsDeviceDeviceResetting;
            graphicsDevice.ResourceCreated   += GraphicsDeviceResourceCreated;
            graphicsDevice.ResourceDestroyed += GraphicsDeviceResourceDestroyed;

            DepthTest = false;

            ResetDevice();
        }