Exemplo n.º 1
0
        private void Setup()
        {
            // Initialize the main viewport
            _viewport = new Viewport(0, 0,
                                     DisplayMode.Width, DisplayMode.Height);
            _viewport.MaxDepth = 1.0f;

            PlatformSetup();

            Textures      = new TextureCollection(MaxTextureSlots);
            SamplerStates = new SamplerStateCollection(this, MaxTextureSlots);

            _blendStateAdditive         = BlendState.Additive.Clone();
            _blendStateAlphaBlend       = BlendState.AlphaBlend.Clone();
            _blendStateNonPremultiplied = BlendState.NonPremultiplied.Clone();
            _blendStateOpaque           = BlendState.Opaque.Clone();

            BlendState = BlendState.Opaque;

            _depthStencilStateDefault   = DepthStencilState.Default.Clone();
            _depthStencilStateDepthRead = DepthStencilState.DepthRead.Clone();
            _depthStencilStateNone      = DepthStencilState.None.Clone();

            DepthStencilState = DepthStencilState.Default;

            _rasterizerStateCullClockwise        = RasterizerState.CullClockwise.Clone();
            _rasterizerStateCullCounterClockwise = RasterizerState.CullCounterClockwise.Clone();
            _rasterizerStateCullNone             = RasterizerState.CullNone.Clone();

            RasterizerState = RasterizerState.CullCounterClockwise;

            EffectCache = new Dictionary <int, Effect>();
        }
Exemplo n.º 2
0
        private void Setup()
        {
#if DEBUG
            if (DisplayMode == null)
            {
                throw new Exception(
                          "Unable to determine the current display mode.  This can indicate that the " +
                          "game is not configured to be HiDPI aware under Windows 10 or later.  See " +
                          "https://github.com/MonoGame/MonoGame/issues/5040 for more information.");
            }
#endif

            // Initialize the main viewport
            _viewport = new Viewport(0, 0,
                                     DisplayMode.Width, DisplayMode.Height);
            _viewport.MaxDepth = 1.0f;

            PlatformSetup();

            VertexTextures      = new TextureCollection(this, MaxVertexTextureSlots, true);
            VertexSamplerStates = new SamplerStateCollection(this, MaxVertexTextureSlots, true);

            Textures      = new TextureCollection(this, MaxTextureSlots, false);
            SamplerStates = new SamplerStateCollection(this, MaxTextureSlots, false);

            EffectCache = new Dictionary <int, Effect>();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphicsDevice" /> class.
        /// </summary>
        /// <param name="adapter">The graphics adapter.</param>
        /// <param name="graphicsProfile">The graphics profile.</param>
        /// <param name="presentationParameters">The presentation options.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="presentationParameters"/> is <see langword="null"/>.
        /// </exception>
        public GraphicsDevice(
            GraphicsAdapter adapter,
            GraphicsProfile graphicsProfile,
            PresentationParameters presentationParameters
            )
        {
            if (presentationParameters == null)
            {
                throw new ArgumentNullException("presentationParameters");
            }

            // Set the properties from the constructor parameters.
            Adapter = adapter;
            PresentationParameters = presentationParameters;
            GraphicsProfile        = graphicsProfile;
            PresentationParameters.MultiSampleCount = MathHelper.ClosestMSAAPower(
                PresentationParameters.MultiSampleCount
                );

            // Set up the OpenGL Device. Loads entry points.
            GLDevice = new OpenGLDevice(PresentationParameters);

            // Force set the default render states.
            BlendState        = BlendState.Opaque;
            DepthStencilState = DepthStencilState.Default;
            RasterizerState   = RasterizerState.CullCounterClockwise;

            // Initialize the Texture/Sampler state containers
            int maxTextures       = Math.Min(GLDevice.MaxTextureSlots, 16);                // Per XNA4 spec
            int maxVertexTextures = MathHelper.Clamp(GLDevice.MaxTextureSlots - 16, 0, 4); // Per XNA4 HiDef spec

            vertexSamplerStart = GLDevice.MaxTextureSlots - maxVertexTextures;
            Textures           = new TextureCollection(
                maxTextures,
                modifiedSamplers
                );
            SamplerStates = new SamplerStateCollection(
                maxTextures,
                modifiedSamplers
                );
            VertexTextures = new TextureCollection(
                maxVertexTextures,
                modifiedVertexSamplers
                );
            VertexSamplerStates = new SamplerStateCollection(
                maxVertexTextures,
                modifiedVertexSamplers
                );

            // Set the default viewport and scissor rect.
            Viewport         = new Viewport(PresentationParameters.Bounds);
            ScissorRectangle = Viewport.Bounds;
        }
Exemplo n.º 4
0
        /* Public Functions */

        public void BeginApplySampler(SamplerStateCollection samplers, int register)
        {
            SamplerState oldSampler = samplers[register];

            AddressU      = oldSampler.AddressU;
            AddressV      = oldSampler.AddressV;
            AddressW      = oldSampler.AddressW;
            MaxAnisotropy = oldSampler.MaxAnisotropy;
            MaxMipLevel   = oldSampler.MaxMipLevel;
            MipMapLODBias = oldSampler.MipMapLevelOfDetailBias;
            Filter        = oldSampler.Filter;
        }
Exemplo n.º 5
0
        private void Setup()
        {
            // Initialize the main viewport
            _viewport = new Viewport(0, 0,
                                     DisplayMode.Width, DisplayMode.Height);
            _viewport.MaxDepth = 1.0f;

            PlatformSetup();

            Textures      = new TextureCollection(MaxTextureSlots);
            SamplerStates = new SamplerStateCollection(MaxTextureSlots);
        }
        private static void SetShaderSamplers(this EffectPass pass, EffectPassProperties props, Shader shader, TextureCollection textures, SamplerStateCollection samplerStates)
        {
            foreach (var sampler in shader.Samplers)
            {
                var param = props.Effect.Parameters[sampler.parameter];
                var texture = param.Data as Texture;

                textures[sampler.textureSlot] = texture;

                // If there is a sampler state set it.
                if (sampler.state != null)
                    samplerStates[sampler.samplerSlot] = sampler.state;
            }
        }
Exemplo n.º 7
0
        private void SetShaderSamplers(Shader shader, TextureCollection textures, SamplerStateCollection samplerStates)
        {
            foreach (var sampler in shader.Samplers)
            {
                var param   = _effect.Parameters[sampler.parameter];
                var texture = param.Data as Texture;

                textures[sampler.textureSlot] = texture;

                // If there is a sampler state set it.
                if (sampler.state != null)
                {
                    samplerStates[sampler.samplerSlot] = sampler.state;
                }
            }
        }
Exemplo n.º 8
0
        public void EndApplySampler(SamplerStateCollection samplers, int register)
        {
            StateHash hash = GetSamplerHash(
                AddressU,
                AddressV,
                AddressW,
                MaxAnisotropy,
                MaxMipLevel,
                MipMapLODBias,
                Filter
                );
            SamplerState newSampler;

            if (!samplerCache.TryGetValue(hash, out newSampler))
            {
                newSampler = new SamplerState();

                newSampler.Filter                  = Filter;
                newSampler.AddressU                = AddressU;
                newSampler.AddressV                = AddressV;
                newSampler.AddressW                = AddressW;
                newSampler.MaxAnisotropy           = MaxAnisotropy;
                newSampler.MaxMipLevel             = MaxMipLevel;
                newSampler.MipMapLevelOfDetailBias = MipMapLODBias;

                samplerCache.Add(hash, newSampler);
#if VERBOSE_PIPELINECACHE
                FNALoggerEXT.LogInfo(
                    "New SamplerState added to pipeline cache with hash:\n" +
                    hash.ToString()
                    );
                FNALoggerEXT.LogInfo(
                    "Updated size of SamplerState cache: " +
                    samplerCache.Count
                    );
            }
            else
            {
                FNALoggerEXT.LogInfo(
                    "Retrieved SamplerState from pipeline cache with hash:\n" +
                    hash.ToString()
                    );
#endif
            }

            samplers[register] = newSampler;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphicsDevice" /> class.
        /// </summary>
        /// <param name="adapter">The graphics adapter.</param>
        /// <param name="graphicsProfile">The graphics profile.</param>
        /// <param name="presentationParameters">The presentation options.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="presentationParameters"/> is <see langword="null"/>.
        /// </exception>
        public GraphicsDevice(
            GraphicsAdapter adapter,
            GraphicsProfile graphicsProfile,
            PresentationParameters presentationParameters
            )
        {
            if (presentationParameters == null)
            {
                throw new ArgumentNullException("presentationParameters");
            }

            // Set the properties from the constructor parameters.
            Adapter = adapter;
            PresentationParameters = presentationParameters;
            GraphicsProfile        = graphicsProfile;

            // Set up the OpenGL Device. Loads entry points.
            GLDevice = new OpenGLDevice(PresentationParameters);

            // Force set the default render states.
            BlendState        = BlendState.Opaque;
            DepthStencilState = DepthStencilState.Default;
            RasterizerState   = RasterizerState.CullCounterClockwise;

            // Initialize the Texture/Sampler state containers
            Textures      = new TextureCollection(this);
            SamplerStates = new SamplerStateCollection(this);

            // Clear constant buffers
            vertexConstantBuffers.Clear();
            pixelConstantBuffers.Clear();

            // First draw will need to set the shaders.
            vertexShaderDirty = true;
            pixelShaderDirty  = true;

            // Set the default viewport and scissor rect.
            Viewport         = new Viewport(PresentationParameters.Bounds);
            ScissorRectangle = Viewport.Bounds;

            // Free all the cached shader programs.
            programCache.Clear();
            shaderProgram = null;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphicsDevice" /> class.
        /// </summary>
        /// <param name="adapter">The graphics adapter.</param>
        /// <param name="graphicsProfile">The graphics profile.</param>
        /// <param name="presentationParameters">The presentation options.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="presentationParameters"/> is <see langword="null"/>.
        /// </exception>
        public GraphicsDevice(GraphicsAdapter adapter, GraphicsProfile graphicsProfile, PresentationParameters presentationParameters)
        {
            if (presentationParameters == null)
            {
                throw new ArgumentNullException("presentationParameters");
            }

            // Set the properties from the constructor parameters.
            Adapter = adapter;
            PresentationParameters = presentationParameters;
            GraphicsProfile        = graphicsProfile;

            // Force set the default render states.
            BlendState        = BlendState.Opaque;
            DepthStencilState = DepthStencilState.Default;
            RasterizerState   = RasterizerState.CullCounterClockwise;

            // Initialize the Texture/Sampler state containers
            Textures      = new TextureCollection(OpenGLDevice.Instance.MaxTextureSlots);
            SamplerStates = new SamplerStateCollection(OpenGLDevice.Instance.MaxTextureSlots);
            Textures.Clear();
            SamplerStates.Clear();

            // Clear constant buffers
            vertexConstantBuffers.Clear();
            pixelConstantBuffers.Clear();

            // Force set the buffers and shaders on next ApplyState() call
            vertexBufferBindings = new VertexBufferBinding[OpenGLDevice.Instance.MaxVertexAttributes];

            // First draw will need to set the shaders.
            vertexShaderDirty = true;
            pixelShaderDirty  = true;

            // Set the default scissor rect.
            ScissorRectangle = Viewport.Bounds;

            // Free all the cached shader programs.
            programCache.Clear();
            shaderProgram = null;
        }
Exemplo n.º 11
0
        public GraphicsDevice()
        {
            // Initialize the main viewport
            _viewport          = new Viewport();
            _viewport.X        = 0;
            _viewport.Y        = 0;
            _viewport.Width    = Math.Max(DisplayMode.Width, DisplayMode.Height); /// hackhack: assume landscape.
            _viewport.Height   = Math.Min(DisplayMode.Width, DisplayMode.Height); //
            _viewport.MinDepth = 0.0f;
            _viewport.MaxDepth = 1.0f;
            Textures           = new TextureCollection();

            // Init RasterizerState
            RasterizerState = new RasterizerState();

            // Init Default SamplerState
            _samplerStates = new SamplerStateCollection();

            // Initialize OpenGL states
            GL11.Disable(ALL11.DepthTest);
            GL11.TexEnv(ALL11.TextureEnv, ALL11.TextureEnvMode, (int)ALL11.BlendSrc);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphicsDevice" /> class.
        /// </summary>
        /// <param name="adapter">The graphics adapter.</param>
        /// <param name="graphicsProfile">The graphics profile.</param>
        /// <param name="presentationParameters">The presentation options.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="presentationParameters"/> is <see langword="null"/>.
        /// </exception>
        public GraphicsDevice(
            GraphicsAdapter adapter,
            GraphicsProfile graphicsProfile,
            PresentationParameters presentationParameters
            )
        {
            if (presentationParameters == null)
            {
                throw new ArgumentNullException("presentationParameters");
            }

            // Set the properties from the constructor parameters.
            Adapter = adapter;
            PresentationParameters = presentationParameters;
            GraphicsProfile        = graphicsProfile;
            PresentationParameters.MultiSampleCount = MathHelper.ClosestMSAAPower(
                PresentationParameters.MultiSampleCount
                );

            // Set up the IGLDevice
            GLDevice = FNAPlatform.CreateGLDevice(PresentationParameters, adapter);

            // The mouse needs to know this for faux-backbuffer mouse scaling.
            Input.Mouse.INTERNAL_BackBufferWidth  = PresentationParameters.BackBufferWidth;
            Input.Mouse.INTERNAL_BackBufferHeight = PresentationParameters.BackBufferHeight;

            // The Touch Panel needs this too, for the same reason.
            Input.Touch.TouchPanel.DisplayWidth  = PresentationParameters.BackBufferWidth;
            Input.Touch.TouchPanel.DisplayHeight = PresentationParameters.BackBufferHeight;

            // Force set the default render states.
            BlendState        = BlendState.Opaque;
            DepthStencilState = DepthStencilState.Default;
            RasterizerState   = RasterizerState.CullCounterClockwise;

            // Initialize the Texture/Sampler state containers
            int maxTextures       = Math.Min(GLDevice.MaxTextureSlots, MAX_TEXTURE_SAMPLERS);
            int maxVertexTextures = MathHelper.Clamp(
                GLDevice.MaxTextureSlots - MAX_TEXTURE_SAMPLERS,
                0,
                MAX_VERTEXTEXTURE_SAMPLERS
                );

            vertexSamplerStart = GLDevice.MaxTextureSlots - maxVertexTextures;
            Textures           = new TextureCollection(
                maxTextures,
                modifiedSamplers
                );
            SamplerStates = new SamplerStateCollection(
                maxTextures,
                modifiedSamplers
                );
            VertexTextures = new TextureCollection(
                maxVertexTextures,
                modifiedVertexSamplers
                );
            VertexSamplerStates = new SamplerStateCollection(
                maxVertexTextures,
                modifiedVertexSamplers
                );

            // Set the default viewport and scissor rect.
            Viewport         = new Viewport(PresentationParameters.Bounds);
            ScissorRectangle = Viewport.Bounds;

            // Allocate the pipeline cache to be used by Effects
            PipelineCache = new PipelineCache(this);
#if WIIU_GAMEPAD
            wiiuStream = DRC.drc_new_streamer();
            if (wiiuStream == IntPtr.Zero)
            {
                FNALoggerEXT.LogError("Failed to alloc GamePad stream!");
                return;
            }
            if (DRC.drc_start_streamer(wiiuStream) < 1)             // ???
            {
                FNALoggerEXT.LogError("Failed to start GamePad stream!");
                DRC.drc_delete_streamer(wiiuStream);
                wiiuStream = IntPtr.Zero;
                return;
            }
            DRC.drc_enable_system_input_feeder(wiiuStream);
            wiiuPixelData = new byte[
                PresentationParameters.BackBufferWidth *
                PresentationParameters.BackBufferHeight *
                4
                            ];
#endif
        }
Exemplo n.º 13
0
        private static void SetShaderSamplers(this EffectPass pass, EffectPassProperties props, Shader shader, TextureCollection textures, SamplerStateCollection samplerStates)
        {
            foreach (var sampler in shader.Samplers)
            {
                var param   = props.Effect.Parameters[sampler.parameter];
                var texture = param.Data as Texture;

                textures[sampler.textureSlot] = texture;

                // If there is a sampler state set it.
                if (sampler.state != null)
                {
                    samplerStates[sampler.samplerSlot] = sampler.state;
                }
            }
        }
Exemplo n.º 14
0
        private unsafe void INTERNAL_updateSamplers(
			uint changeCount,
			MojoShader.MOJOSHADER_samplerStateRegister* registers,
			TextureCollection textures,
			SamplerStateCollection samplers
		)
        {
            for (int i = 0; i < changeCount; i += 1)
            {
                if (registers[i].sampler_state_count == 0)
                {
                    // Nothing to do
                    continue;
                }

                int register = (int) registers[i].sampler_register;

                /* We're going to store this state locally, then generate a
                 * new object later if needed. Otherwise the GC loses its
                 * mind.
                 * -flibit
                 */
                SamplerState oldSampler = samplers[register];

                // Used to prevent redundant sampler changes
                bool samplerChanged = false;
                bool filterChanged = false;

                // Current sampler state
                TextureAddressMode addressU = oldSampler.AddressU;
                TextureAddressMode addressV = oldSampler.AddressV;
                TextureAddressMode addressW = oldSampler.AddressW;
                int maxAnisotropy = oldSampler.MaxAnisotropy;
                int maxMipLevel = oldSampler.MaxMipLevel;
                float mipMapLODBias = oldSampler.MipMapLevelOfDetailBias;

                // Current sampler filter
                TextureFilter filter = oldSampler.Filter;
                MojoShader.MOJOSHADER_textureFilterType magFilter = XNAMag[(int) filter];
                MojoShader.MOJOSHADER_textureFilterType minFilter = XNAMin[(int) filter];
                MojoShader.MOJOSHADER_textureFilterType mipFilter = XNAMip[(int) filter];

                MojoShader.MOJOSHADER_effectSamplerState* states = (MojoShader.MOJOSHADER_effectSamplerState*) registers[i].sampler_states;
                for (int j = 0; j < registers[i].sampler_state_count; j += 1)
                {
                    MojoShader.MOJOSHADER_samplerStateType type = states[j].type;
                    if (type == MojoShader.MOJOSHADER_samplerStateType.MOJOSHADER_SAMP_TEXTURE)
                    {
                        string samplerName = Marshal.PtrToStringAnsi(
                            registers[i].sampler_name
                        );
                        if (samplerMap.ContainsKey(samplerName))
                        {
                            Texture texture = samplerMap[samplerName].texture;
                            if (texture != null)
                            {
                                textures[register] = texture;
                            }
                        }
                    }
                    else if (type == MojoShader.MOJOSHADER_samplerStateType.MOJOSHADER_SAMP_ADDRESSU)
                    {
                        MojoShader.MOJOSHADER_textureAddress* val = (MojoShader.MOJOSHADER_textureAddress*) states[j].value.values;
                        addressU = XNAAddress[(int) *val];
                        samplerChanged = true;
                    }
                    else if (type == MojoShader.MOJOSHADER_samplerStateType.MOJOSHADER_SAMP_ADDRESSV)
                    {
                        MojoShader.MOJOSHADER_textureAddress* val = (MojoShader.MOJOSHADER_textureAddress*) states[j].value.values;
                        addressV = XNAAddress[(int) *val];
                        samplerChanged = true;
                    }
                    else if (type == MojoShader.MOJOSHADER_samplerStateType.MOJOSHADER_SAMP_ADDRESSW)
                    {
                        MojoShader.MOJOSHADER_textureAddress* val = (MojoShader.MOJOSHADER_textureAddress*) states[j].value.values;
                        addressW = XNAAddress[(int) *val];
                        samplerChanged = true;
                    }
                    else if (type == MojoShader.MOJOSHADER_samplerStateType.MOJOSHADER_SAMP_MAGFILTER)
                    {
                        MojoShader.MOJOSHADER_textureFilterType* val = (MojoShader.MOJOSHADER_textureFilterType*) states[j].value.values;
                        magFilter = *val;
                        filterChanged = true;
                    }
                    else if (type == MojoShader.MOJOSHADER_samplerStateType.MOJOSHADER_SAMP_MINFILTER)
                    {
                        MojoShader.MOJOSHADER_textureFilterType* val = (MojoShader.MOJOSHADER_textureFilterType*) states[j].value.values;
                        minFilter = *val;
                        filterChanged = true;
                    }
                    else if (type == MojoShader.MOJOSHADER_samplerStateType.MOJOSHADER_SAMP_MIPFILTER)
                    {
                        MojoShader.MOJOSHADER_textureFilterType* val = (MojoShader.MOJOSHADER_textureFilterType*) states[j].value.values;
                        mipFilter = *val;
                        filterChanged = true;
                    }
                    else if (type == MojoShader.MOJOSHADER_samplerStateType.MOJOSHADER_SAMP_MIPMAPLODBIAS)
                    {
                        float* val = (float*) states[i].value.values;
                        mipMapLODBias = *val;
                        samplerChanged = true;
                    }
                    else if (type == MojoShader.MOJOSHADER_samplerStateType.MOJOSHADER_SAMP_MAXMIPLEVEL)
                    {
                        int* val = (int*) states[i].value.values;
                        maxMipLevel = *val;
                        samplerChanged = true;
                    }
                    else if (type == MojoShader.MOJOSHADER_samplerStateType.MOJOSHADER_SAMP_MAXANISOTROPY)
                    {
                        int* val = (int*) states[i].value.values;
                        maxAnisotropy = *val;
                        samplerChanged = true;
                    }
                    else
                    {
                        throw new Exception("Unhandled sampler state!");
                    }
                }
                if (filterChanged)
                {
                    if (	magFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_ANISOTROPIC ||
                        minFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_ANISOTROPIC ||
                        mipFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_ANISOTROPIC	)
                    {
                        // Just assume we wanted Anisotropic if any of these qualify.
                        filter = TextureFilter.Anisotropic;
                    }
                    else if (magFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_POINT)
                    {
                        if (minFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_POINT)
                        {
                            if (	mipFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_NONE ||
                                mipFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_POINT	)
                            {
                                filter = TextureFilter.Point;
                            }
                            else if (mipFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_LINEAR)
                            {
                                filter = TextureFilter.PointMipLinear;
                            }
                            else
                            {
                                throw new NotImplementedException("Unhandled mipfilter type!");
                            }
                        }
                        else if (minFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_LINEAR)
                        {
                            if (	mipFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_NONE ||
                                mipFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_POINT	)
                            {
                                filter = TextureFilter.MinLinearMagPointMipPoint;
                            }
                            else if (mipFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_LINEAR)
                            {
                                filter = TextureFilter.MinLinearMagPointMipLinear;
                            }
                            else
                            {
                                throw new NotImplementedException("Unhandled mipfilter type!");
                            }
                        }
                        else
                        {
                            throw new NotImplementedException("Unhandled minfilter type!");
                        }
                    }
                    else if (magFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_LINEAR)
                    {
                        if (minFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_POINT)
                        {
                            if (	mipFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_NONE ||
                                mipFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_POINT	)
                            {
                                filter = TextureFilter.MinPointMagLinearMipPoint;
                            }
                            else if (mipFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_LINEAR)
                            {
                                filter = TextureFilter.MinPointMagLinearMipLinear;
                            }
                            else
                            {
                                throw new NotImplementedException("Unhandled mipfilter type!");
                            }
                        }
                        else if (minFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_LINEAR)
                        {
                            if (	mipFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_NONE ||
                                mipFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_POINT	)
                            {
                                filter = TextureFilter.LinearMipPoint;
                            }
                            else if (mipFilter == MojoShader.MOJOSHADER_textureFilterType.MOJOSHADER_TEXTUREFILTER_LINEAR)
                            {
                                filter = TextureFilter.Linear;
                            }
                            else
                            {
                                throw new NotImplementedException("Unhandled mipfilter type!");
                            }
                        }
                        else
                        {
                            throw new NotImplementedException("Unhandled minfilter type!");
                        }
                    }
                    else
                    {
                        throw new NotImplementedException("Unhandled magfilter type!");
                    }
                    samplerChanged = true;
                }

                if (samplerChanged)
                {
                    // FIXME: This is part of the state cache hack! -flibit
                    SamplerState newSampler;
                    if (samplers[register] == samplerCache[register])
                    {
                        // FIXME: 30 is arbitrary! -flibit
                        newSampler = samplerCache[register + 30];
                    }
                    else
                    {
                        newSampler = samplerCache[register];
                    }
                    newSampler.Filter = filter;
                    newSampler.AddressU = addressU;
                    newSampler.AddressV = addressV;
                    newSampler.AddressW = addressW;
                    newSampler.MaxAnisotropy = maxAnisotropy;
                    newSampler.MaxMipLevel = maxMipLevel;
                    newSampler.MipMapLevelOfDetailBias = mipMapLODBias;
                    samplers[register] = newSampler;
                }
            }
        }
Exemplo n.º 15
0
        private void SetShaderSamplers(Shader shader, TextureCollection textures, SamplerStateCollection samplerStates)
        {
            foreach (var sampler in shader.Samplers)
            {
                var param = _effect.Parameters[sampler.parameter];
                var texture = param.Data as Texture;

                textures[sampler.textureSlot] = texture;

                // If there is a sampler state set it.
                if (sampler.state != null)
                    samplerStates[sampler.samplerSlot] = sampler.state;
            }
        }