Example #1
0
        private void InitializeTextureUnits()
        {
            //  Bind a dummy texture to all texture units
            byte[] whiteData = new byte[4];
            whiteData[0] = 255;
            whiteData[1] = 255;
            whiteData[2] = 255;
            whiteData[3] = 255;
            dummyTexture = new TextureGL(1, 1, PixelFormat.Rgba, PixelInternalFormat.Rgba);
            dummyTexture.Upload(whiteData, 0);
            nearestSampler           = new SamplerGL1();
            nearestSampler.MinFilter = TextureMinFilter.Nearest;
            nearestSampler.MagFilter = TextureMagFilter.Nearest;
            nearestSampler.Wrap      = TextureWrapMode.ClampToEdge;
            int textureUnits = 4;

            try
            {
                GL.GetInteger(GetPName.MaxTextureUnits, out textureUnits);
            }
            catch (Exception)
            {
            }
            for (int i = 0; i < textureUnits; ++i)
            {
                try
                {
                    GL.ActiveTexture(TextureUnit.Texture0 + i);
                    dummyTexture.Apply();
                    nearestSampler.Apply(i, TextureTarget.Texture2D);
                }
                catch (Exception)
                {
                }
            }

            float[] zeros = { 0.0f, 0.0f, 0.0f, 0.0f };
            for (int i = 0; i < 8; ++i)
            {
                GL.Light(LightName.Light0 + i, LightParameter.Ambient, zeros);
            }
        }
Example #2
0
        // \brief Find a sampler based on key and set it to use the specified texture
        // \note This does not change any Program state; Programs are assumed to be already associated with samplers
        public void SetTexture(string key, TextureGL texture)
        {
            var samplerUniform = Samplers.Global.Sampler(key);

            if (samplerUniform == null)
            {
                return;
            }

            int textureUnitIndex = samplerUniform.TextureUnitIndex;

            if (textureUnitIndex == -1)
            {
                return;
            }

            GL.ActiveTexture(TextureUnit.Texture0 + textureUnitIndex);
            texture.Apply();
            samplerUniform.Sampler.Apply(textureUnitIndex, texture.BindTarget);

            // \todo cache textures? textures[key] = texture;
        }