public void DrawScreenTexture(Texture2D texture, Shader shader, SamplerObject sampler)
        {
            if (texture == null)
            {
                return;
            }

            // Always check program creation before using shaders to prevent crashes.
            if (!shader.LinkStatusIsOk)
            {
                return;
            }

            // Render using the shader.
            shader.UseProgram();

            // The sampler's parameters are used instead of the texture's parameters.
            int textureUnit = 0;

            sampler.Bind(textureUnit);

            shader.SetInt("attributeIndex", 1);
            Matrix4 matrix4 = Matrix4.Identity;

            shader.SetMatrix4x4("mvpMatrix", ref matrix4);

            shader.SetTexture("uvTexture", texture, textureUnit);

            GL.Disable(EnableCap.DepthTest);

            Draw(shader);
        }
示例#2
0
        private static void SetSamplerInformation(RMaterial material, MatlAttribute a)
        {
            var samplerStruct = (MatlAttribute.MatlSampler)a.DataObject;

            SamplerObject sampler = new SamplerObject
            {
                TextureWrapS = MatlToGl.GetWrapMode(samplerStruct.WrapS),
                TextureWrapT = MatlToGl.GetWrapMode(samplerStruct.WrapT),
                TextureWrapR = MatlToGl.GetWrapMode(samplerStruct.WrapR),
                MagFilter    = MatlToGl.GetMagFilter(samplerStruct.MagFilter),
                MinFilter    = MatlToGl.GetMinFilter(samplerStruct.MinFilter)
            };

            GL.SamplerParameter(sampler.Id, SamplerParameterName.TextureLodBias, samplerStruct.LodBias);

            if (samplerStruct.Unk6 == 2 && RenderSettings.Instance.EnableExperimental)
            {
                GL.SamplerParameter(sampler.Id, SamplerParameterName.TextureMaxAnisotropyExt, (float)samplerStruct.MaxAnisotropy);
            }
            else
            {
                GL.SamplerParameter(sampler.Id, SamplerParameterName.TextureMaxAnisotropyExt, 1.0f);
            }

            material.samplerByParamId[a.ParamId] = sampler;
        }
 private void CreateSamplerObject()
 {
     samplerObject = new SamplerObject
     {
         MinFilter = TextureMinFilter.NearestMipmapLinear,
         MagFilter = TextureMagFilter.Nearest
     };
 }
示例#4
0
        public void TextureMaxAnisotropy()
        {
            var sampler = new SamplerObject {
                TextureMaxAnisotropy = 16f
            };

            GL.GetSamplerParameter(sampler.Id, SamplerParameterName.TextureMaxAnisotropyExt, out float param);
            Assert.AreEqual(16f, param);
        }
示例#5
0
        public void TextureLodBias()
        {
            var sampler = new SamplerObject {
                TextureLodBias = -1.234f
            };

            GL.GetSamplerParameter(sampler.Id, SamplerParameterName.TextureLodBias, out float param);
            Assert.AreEqual(-1.234f, param);
        }
示例#6
0
        public void TextureWrapR()
        {
            var sampler = new SamplerObject {
                TextureWrapR = TextureWrapMode.MirroredRepeat
            };

            GL.GetSamplerParameter(sampler.Id, SamplerParameterName.TextureWrapR, out int param);
            Assert.AreEqual((int)TextureWrapMode.MirroredRepeat, param);
        }
示例#7
0
        public void MagFilter()
        {
            var sampler = new SamplerObject {
                MagFilter = TextureMagFilter.Linear
            };

            GL.GetSamplerParameter(sampler.Id, SamplerParameterName.TextureMagFilter, out int param);
            Assert.AreEqual((int)TextureMagFilter.Linear, param);
        }
示例#8
0
        private void SetSamplerInformation(Material material, MatlAttribute a)
        {
            // TODO: This could be cleaner.
            SamplerObject sampler = null;

            switch ((long)a.ParamId)
            {
            case (long)ParamId.ColSampler:
                sampler = material.colSampler;
                break;

            case (long)ParamId.NorSampler:
                sampler = material.norSampler;
                break;

            case (long)ParamId.PrmSampler:
                sampler = material.prmSampler;
                break;

            case (long)ParamId.EmiSampler:
                sampler = material.emiSampler;
                break;
            }

            if (sampler != null)
            {
                var samplerStruct = (MatlAttribute.MatlSampler)a.DataObject;
                sampler.TextureWrapS = MatlToGl.GetWrapMode(samplerStruct.WrapS);
                sampler.TextureWrapT = MatlToGl.GetWrapMode(samplerStruct.WrapT);
                sampler.TextureWrapR = MatlToGl.GetWrapMode(samplerStruct.WrapR);
                sampler.MagFilter    = MatlToGl.GetMagFilter(samplerStruct.MagFilter);
                sampler.MinFilter    = MatlToGl.GetMinFilter(samplerStruct.MinFilter);

                GL.SamplerParameter(sampler.Id, SamplerParameterName.TextureLodBias, samplerStruct.LodBias);

                if (samplerStruct.Unk6 == 2 && RenderSettings.Instance.EnableExperimental)
                {
                    GL.SamplerParameter(sampler.Id, SamplerParameterName.TextureMaxAnisotropyExt, (float)samplerStruct.MaxAnisotropy);
                }
                else
                {
                    GL.SamplerParameter(sampler.Id, SamplerParameterName.TextureMaxAnisotropyExt, 1.0f);
                }
            }
        }
示例#9
0
        public static void DrawTexture(Texture texture)
        {
            if (triangle == null)
            {
                triangle = new ScreenTriangle();
            }
            if (sampler == null)
            {
                sampler = new SamplerObject {
                    MagFilter = TextureMagFilter.Nearest, MinFilter = TextureMinFilter.Nearest
                }
            }
            ;

            var shader = ShaderContainer.GetShader("ScreenTexture");

            shader.UseProgram();

            sampler.Bind(0);
            shader.SetTexture("image", texture, 0);

            triangle.Draw(shader);
        }
示例#10
0
 /// <summary>
 /// Adds a sampler uniform to the material.
 /// </summary>
 /// <param name="uniformName">The name of the uniform variable</param>
 /// <param name="value">The value to set for the uniform</param>
 /// <param name="sampler">A sampler for the texture <paramref name="value"/></param>
 public void AddTexture(string uniformName, Texture value, SamplerObject sampler)
 {
     textureUniformNames.Add(uniformName);
     textureValues.Add(value);
     samplerValues.Add(sampler);
 }
示例#11
0
 private void CreateSamplerObject()
 {
     samplerObject           = new SamplerObject();
     samplerObject.MinFilter = TextureMinFilter.NearestMipmapLinear;
     samplerObject.MagFilter = TextureMagFilter.Nearest;
 }