Exemplo n.º 1
0
        public override Media.PixelFormat GetNativeFormat(Graphics.TextureType ttype, Media.PixelFormat format, Graphics.TextureUsage usage)
        {
            var caps = Root.Instance.RenderSystem.Capabilities;

            //Check compressed texture support
            //if a compressed formt not supported, rever to PixelFormat.A8R8G8B8
            if (PixelUtil.IsCompressed(format) && !caps.HasCapability(Graphics.Capabilities.TextureCompressionDXT) && !caps.HasCapability(Graphics.Capabilities.TextureCompressionPVRTC))
            {
                return(PixelFormat.A8R8G8B8);
            }
            //if floating point texture not supported, rever to PixelFormat.A8R8G8B8
            if (PixelUtil.IsFloatingPoint(format) && !caps.HasCapability(Graphics.Capabilities.TextureFloat))
            {
                return(PixelFormat.A8R8G8B8);
            }

            //Check if this is a valid rendertarget format
            if ((usage & Graphics.TextureUsage.RenderTarget) == Graphics.TextureUsage.RenderTarget)
            {
                //Get closest supported alternative
                //if format is supported it's returned
                return(GLES2RTTManager.Instance.GetSupportedAlternative(format));
            }

            //Supported
            return(format);
        }
Exemplo n.º 2
0
        public override PixelFormat GetNativeFormat(TextureType ttype, PixelFormat format, TextureUsage usage)
        {
            // Adjust requested parameters to capabilities
            RenderSystemCapabilities caps = Root.Instance.RenderSystem.Capabilities;

            // Check compressed texture support
            // if a compressed format not supported, revert to PF_A8R8G8B8
            if (PixelUtil.IsCompressed(format) && !caps.HasCapability(Capabilities.TextureCompressionDXT))
            {
                return(PixelFormat.A8R8G8B8);
            }
            // if floating point textures not supported, revert to PF_A8R8G8B8
            if (PixelUtil.IsFloatingPoint(format) && !caps.HasCapability(Capabilities.TextureFloat))
            {
                return(PixelFormat.A8R8G8B8);
            }

            // Check if this is a valid rendertarget format
            if ((usage & TextureUsage.RenderTarget) != 0)
            {
                /// Get closest supported alternative
                /// If mFormat is supported it's returned
                return(GLRTTManager.Instance.GetSupportedAlternative(format));
            }

            // Supported
            return(format);
        }
Exemplo n.º 3
0
        /// <summary>
        /// </summary>
        /// <param name="ttype"> </param>
        /// <param name="format"> </param>
        /// <param name="usage"> </param>
        /// <returns> </returns>
        public override Media.PixelFormat GetNativeFormat(TextureType ttype, Media.PixelFormat format, TextureUsage usage)
        {
            // Adjust requested parameters to capabilities
            RenderSystemCapabilities caps = Root.Instance.RenderSystem.HardwareCapabilities;

#warning check TextureCompressionVTC == RSC_TEXTURE_COMPRESSION_PVRTC
            // Check compressed texture support
            // if a compressed format not supported, revert to A8R8G8B8
            if (PixelUtil.IsCompressed(format) && !caps.HasCapability(Capabilities.TextureCompressionDXT) && !caps.HasCapability(Capabilities.TextureCompressionVTC))
            {
                return(Media.PixelFormat.A8R8G8B8);
            }
            // if floating point textures not supported, revert to A8R8G8B8
            if (PixelUtil.IsFloatingPoint(format) && !caps.HasCapability(Capabilities.TextureFloat))
            {
                return(Media.PixelFormat.A8R8G8B8);
            }

            // Check if this is a valid rendertarget format
            if ((usage & TextureUsage.RenderTarget) != 0)
            {
                /// Get closest supported alternative
                /// If format is supported it's returned
                return(GLESRTTManager.Instance.GetSupportedAlternative(format));
            }

            // Supported
            return(format);
        }
Exemplo n.º 4
0
        /// <summary>
        ///   Returns whether this render system has hardware filtering supported for the texture format requested with the given usage options.
        /// </summary>
        /// <param name="ttype"> The texture type requested </param>
        /// <param name="format"> The pixel format requested </param>
        /// <param name="usage"> the kind of usage this texture is intended for, a combination of the TextureUsage flags. </param>
        /// <param name="preciseFormatOnly"> Whether precise or fallback format mode is used to detecting. In case the pixel format doesn't supported by device, false will be returned if in precise mode, and natively used pixel format will be actually use to check if in fallback mode. </param>
        /// <returns> true if the texture filtering is supported. </returns>
        public override bool IsHardwareFilteringSupported(TextureType ttype, Media.PixelFormat format, int usage, bool preciseFormatOnly)
        {
            if (format == Media.PixelFormat.Unknown)
            {
                return(false);
            }

            // Check native format
            Media.PixelFormat nativeFormat = GetNativeFormat(ttype, format, (TextureUsage)usage);
            if (preciseFormatOnly && format != nativeFormat)
            {
                return(false);
            }

            // Assume non-floating point is supported always
            if (!PixelUtil.IsFloatingPoint(nativeFormat))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Detect allowed FBO formats
        /// </summary>
        private void _detectFBOFormats()
        {
            // Try all formats, and report which ones work as target
            int fb, tid;
            int old_drawbuffer, old_readbuffer;
            int target = Gl.GL_TEXTURE_2D;

            Gl.glGetIntegerv(Gl.GL_DRAW_BUFFER, out old_drawbuffer);
            Gl.glGetIntegerv(Gl.GL_READ_BUFFER, out old_readbuffer);

            for (int x = 0; x < (int)PixelFormat.Count; ++x)
            {
                this._props[x].Valid = false;

                // Fetch GL format token
                int fmt = GLPixelUtil.GetGLInternalFormat((PixelFormat)x);
                if (fmt == Gl.GL_NONE && x != 0)
                {
                    continue;
                }

                // No test for compressed formats
                if (PixelUtil.IsCompressed((PixelFormat)x))
                {
                    continue;
                }

                // Buggy ATI cards *crash* on non-RGB(A) formats
                int[] depths = PixelUtil.GetBitDepths((PixelFormat)x);
                if (fmt != Gl.GL_NONE && this._atiMode && (depths[0] == 0 || depths[1] == 0 || depths[2] == 0))
                {
                    continue;
                }

                // Buggy NVidia Drivers fail on 32Bit FP formats on Windows.
                if (PixelUtil.IsFloatingPoint((PixelFormat)x) && PlatformManager.IsWindowsOS && !this._atiMode)
                {
                    continue;
                }

                // Create and attach framebuffer
                Gl.glGenFramebuffersEXT(1, out fb);
                Gl.glBindFramebufferEXT(Gl.GL_FRAMEBUFFER_EXT, fb);
                if (fmt != Gl.GL_NONE)
                {
                    // Create and attach texture
                    Gl.glGenTextures(1, out tid);
                    Gl.glBindTexture(target, tid);

                    // Set some default parameters so it won't fail on NVidia cards
                    Gl.glTexParameteri(target, Gl.GL_TEXTURE_MAX_LEVEL, 0);
                    Gl.glTexParameteri(target, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_NEAREST);
                    Gl.glTexParameteri(target, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_NEAREST);
                    Gl.glTexParameteri(target, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP_TO_EDGE);
                    Gl.glTexParameteri(target, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP_TO_EDGE);

                    Gl.glTexImage2D(target, 0, fmt, PROBE_SIZE, PROBE_SIZE, 0, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, IntPtr.Zero);
                    Gl.glFramebufferTexture2DEXT(Gl.GL_FRAMEBUFFER_EXT, Gl.GL_COLOR_ATTACHMENT0_EXT, target, tid, 0);
                }
                else
                {
                    // Draw to nowhere -- stencil/depth only
                    tid = 0;
                    Gl.glDrawBuffer(Gl.GL_NONE);
                    Gl.glReadBuffer(Gl.GL_NONE);
                }
                // Check status
                int status = Gl.glCheckFramebufferStatusEXT(Gl.GL_FRAMEBUFFER_EXT);

                // Ignore status in case of fmt==GL_NONE, because no implementation will accept
                // a buffer without *any* attachment. Buffers with only stencil and depth attachment
                // might still be supported, so we must continue probing.
                if (fmt == Gl.GL_NONE || status == Gl.GL_FRAMEBUFFER_COMPLETE_EXT)
                {
                    this._props[x].Valid = true;
                    var str = new StringBuilder();
                    str.AppendFormat("\tFBO {0} depth/stencil support: ", PixelUtil.GetFormatName((PixelFormat)x));

                    // For each depth/stencil formats
                    for (int depth = 0; depth < this._depthFormats.GetLength(0); ++depth)
                    {
                        if (this._depthFormats[depth] != GL_DEPTH24_STENCIL8_EXT)
                        {
                            // General depth/stencil combination

                            for (int stencil = 0; stencil < this._stencilFormats.GetLength(0); ++stencil)
                            {
                                //LogManager.Instance.Write( "Trying {0} D{1}S{2} ", PixelUtil.GetFormatName( (PixelFormat)x ), _depthBits[ depth ], _stencilBits[ stencil ] );

                                if (_tryFormat(this._depthFormats[depth], this._stencilFormats[stencil]))
                                {
                                    /// Add mode to allowed modes
                                    str.AppendFormat("D{0}S{1} ", this._depthBits[depth], this._stencilBits[stencil]);
                                    FormatProperties.Mode mode;
                                    mode.Depth   = depth;
                                    mode.Stencil = stencil;
                                    this._props[x].Modes.Add(mode);
                                }
                            }
                        }
                        else
                        {
                            // Packed depth/stencil format
#if false
                            // Only query packed depth/stencil formats for 32-bit
                            // non-floating point formats (ie not R32!)
                            // Linux nVidia driver segfaults if you query others
                            if (!PlatformManager.IsWindowsOS &&
                                (PixelUtil.GetNumElemBits((PixelFormat)x) != 32 ||
                                 PixelUtil.IsFloatingPoint((PixelFormat)x)))
                            {
                                continue;
                            }
#endif
                            if (_tryPackedFormat(this._depthFormats[depth]))
                            {
                                /// Add mode to allowed modes
                                str.AppendFormat("Packed-D{0}S8 ", this._depthBits[depth]);
                                FormatProperties.Mode mode;
                                mode.Depth   = depth;
                                mode.Stencil = 0; // unuse
                                this._props[x].Modes.Add(mode);
                            }
                        }
                    }

                    LogManager.Instance.Write(str.ToString());
                }
                // Delete texture and framebuffer
                Gl.glBindFramebufferEXT(Gl.GL_FRAMEBUFFER_EXT, 0);
                Gl.glDeleteFramebuffersEXT(1, ref fb);

                // Workaround for NVIDIA / Linux 169.21 driver problem
                // see http://www.ogre3d.org/phpBB2/viewtopic.php?t=38037&start=25
                Gl.glFinish();

                Gl.glDeleteTextures(1, ref tid);
            }

            // It seems a bug in nVidia driver: glBindFramebufferEXT should restore
            // draw and read buffers, but in some unclear circumstances it won't.
            Gl.glDrawBuffer(old_drawbuffer);
            Gl.glReadBuffer(old_readbuffer);

            string fmtstring = "";
            for (int x = 0; x < (int)PixelFormat.Count; ++x)
            {
                if (this._props[x].Valid)
                {
                    fmtstring += PixelUtil.GetFormatName((PixelFormat)x) + " ";
                }
            }
            LogManager.Instance.Write("[GL] : Valid FBO targets " + fmtstring);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Create global rendertextures.
        /// </summary>
        private void CreateGlobalTextures()
        {
            if (this.supportedTechniques.Count == 0)
            {
                return;
            }

            //To make sure that we are consistent, it is demanded that all composition
            //techniques define the same set of global textures.
            var globalTextureNames = new List <string>();

            //Initialize global textures from first supported technique
            var firstTechnique = this.supportedTechniques[0];

            foreach (var def in firstTechnique.TextureDefinitions)
            {
                if (def.Scope == CompositionTechnique.TextureScope.Global)
                {
                    //Check that this is a legit global texture
                    if (!string.IsNullOrEmpty(def.ReferenceCompositorName))
                    {
                        throw new AxiomException("Global compositor texture definition can not be a reference.");
                    }

                    if (def.Width == 0 || def.Height == 0)
                    {
                        throw new AxiomException("Global compositor texture definition must have absolute size.");
                    }

                    if (def.Pooled)
                    {
                        LogManager.Instance.Write("Pooling global compositor textures has no effect", null);
                    }

                    globalTextureNames.Add(def.Name);

                    //TODO GSOC : Heavy copy-pasting from CompositorInstance. How to we solve it?
                    // Make the tetxure
                    RenderTarget renderTarget = null;
                    if (def.PixelFormats.Count > 1)
                    {
                        var MRTBaseName = string.Format("c{0}/{1}/{2}", autoNumber++.ToString(), _name, def.Name);
                        var mrt         = Root.Instance.RenderSystem.CreateMultiRenderTarget(MRTBaseName);
                        this.globalMRTs.Add(def.Name, mrt);

                        // create and bind individual surfaces
                        var atch = 0;
                        foreach (var p in def.PixelFormats)
                        {
                            var texName = string.Format("{0}/{1}", MRTBaseName, atch.ToString());
                            var tex     = TextureManager.Instance.CreateManual(texName, ResourceGroupManager.InternalResourceGroupName,
                                                                               TextureType.TwoD, def.Width, def.Height, 0, 0, p,
                                                                               TextureUsage.RenderTarget, null,
                                                                               def.HwGammaWrite && !PixelUtil.IsFloatingPoint(p),
                                                                               def.Fsaa ? 1 : 0);

                            var rt = tex.GetBuffer().GetRenderTarget();
                            rt.IsAutoUpdated = false;
                            mrt.BindSurface(atch, rt);
                            // Also add to local textures so we can look up
                            var mrtLocalName = GetMRTLocalName(def.Name, atch);
                            this.globalTextures.Add(mrtLocalName, tex);
                        }
                        renderTarget = mrt;
                    }
                    else
                    {
                        var texName = "c" + autoNumber++.ToString() + "/" + _name + "/" + def.Name;
                        // space in the name mixup the cegui in the compositor demo
                        // this is an auto generated name - so no spaces can't hart us.
                        texName = texName.Replace(" ", "_");
                        var tex = TextureManager.Instance.CreateManual(texName, ResourceGroupManager.InternalResourceGroupName,
                                                                       TextureType.TwoD, def.Width, def.Height, 0, def.PixelFormats[0],
                                                                       TextureUsage.RenderTarget, null,
                                                                       def.HwGammaWrite &&
                                                                       !PixelUtil.IsFloatingPoint(def.PixelFormats[0]),
                                                                       def.Fsaa ? 1 : 0);

                        renderTarget = tex.GetBuffer().GetRenderTarget();
                        this.globalTextures.Add(def.Name, tex);
                    }

                    //Set DepthBuffer pool for sharing
                    renderTarget.DepthBufferPool = def.DepthBufferId;
                }
            }

            //Validate that all other supported techniques expose the same set of global textures.
            foreach (var technique in this.supportedTechniques)
            {
                var isConsistent = true;
                var numGlobals   = 0;
                foreach (var texDef in technique.TextureDefinitions)
                {
                    if (texDef.Scope == CompositionTechnique.TextureScope.Global)
                    {
                        if (!globalTextureNames.Contains(texDef.Name))
                        {
                            isConsistent = false;
                            break;
                        }
                        numGlobals++;
                    }
                }
                if (numGlobals != globalTextureNames.Count)
                {
                    isConsistent = false;
                }
                if (!isConsistent)
                {
                    throw new AxiomException("Different composition techniques define different global textures.");
                }
            }
        }
Exemplo n.º 7
0
        public override bool IsHardwareFilteringSupported(TextureType ttype, PixelFormat format, TextureUsage usage,
                                                          bool preciseFormatOnly)
#endif
        {
            if (format == PixelFormat.Unknown)
            {
                return(false);
            }

            // Check natively format
            PixelFormat nativeFormat = GetNativeFormat(ttype, format, usage);

            if (preciseFormatOnly && format != nativeFormat)
            {
                return(false);
            }

            // Assume non-floating point is supported always
            if (!PixelUtil.IsFloatingPoint(nativeFormat))
            {
                return(true);
            }

            // Hack: there are no elegant GL API to detects texture filtering supported,
            // just hard code for cards based on vendor specifications.

            // TODO: Add cards that 16 bits floating point flitering supported by
            // hardware below
            String[] sFloat16SupportedCards =
            {
                // GeForce 8 Series
                "*GeForce*8800*",                   // GeForce 7 Series
                "*GeForce*7950*", "*GeForce*7900*", "*GeForce*7800*", "*GeForce*7600*",
                "*GeForce*7500*", "*GeForce*7300*", // GeForce 6 Series
                "*GeForce*6800*", "*GeForce*6700*", "*GeForce*6600*", "*GeForce*6500*",
                "*GeForce*6200*", ""                // Empty string means end of list
            };

            // TODO: Add cards that 32 bits floating point flitering supported by
            // hardware below
            String[] sFloat32SupportedCards =
            {
                // GeForce 8 Series
                "*GeForce*8800*", ""                                                                                 // Empty string means end of list
            };

            PixelComponentType pct = PixelUtil.GetComponentType(nativeFormat);

            String[] supportedCards;
            switch (pct)
            {
            case PixelComponentType.Float16:
                supportedCards = sFloat16SupportedCards;
                break;

            case PixelComponentType.Float32:
                supportedCards = sFloat32SupportedCards;
                break;

            default:
                return(false);
            }
            String pcRenderer = Gl.glGetString(Gl.GL_RENDERER);               // TAO 2.0

            //String pcRenderer = Marshal.PtrToStringAnsi( Gl.glGetString( Gl.GL_RENDERER ) );

            foreach (String str in supportedCards)
            {
                if (str == pcRenderer)
                {
                    return(true);
                }
            }

            return(false);
        }