Exemple #1
0
 public void Dispose()
 {
     if (texture != null) texture.Dispose();
     if (vbo != null) vbo.Dispose();
     texture = null;
     vbo = null;
 }
Exemple #2
0
        public static void Create(FBO fbo, string lightMaskFileName)
        {
            if (Settings.DisableShadowMapping)
            {
                UseShadowMapping = false;
                return;
            }

            if (FBO.IsSupported == false)
            {
                Log.WriteLine("FBOs not supported so no shadow mapping.");
                UseShadowMapping = false;
                return;
            }

            ShadowMapping.fbo = fbo;
            UseShadowMapping = true;
            TextureLoaderParameters.WrapModeS = TextureWrapMode.ClampToEdge;
            TextureLoaderParameters.WrapModeT = TextureWrapMode.ClampToEdge;
            try
            {
                lightMask = Texture.Load(lightMaskFileName);
            }
            catch (Exception) { } // skipataan valitukset jos tiedostoa ei löydy
            TextureLoaderParameters.WrapModeS = TextureWrapMode.Repeat;
            TextureLoaderParameters.WrapModeT = TextureWrapMode.Repeat;
            depthShader = GLSLShader.Load("depth.shader");
            depthShaderAlphaTest = GLSLShader.Load("depth.shader:ALPHATEST");
        }
Exemple #3
0
        /// <summary>
        /// lataa texture
        /// </summary>
        public static Texture Load(string fileName, bool useTexDir)
        {
            Texture tex;
            // jos texture on jo ladattu, palauta se
            textures.TryGetValue(fileName, out tex);
            if (tex != null) return tex;
            tex = new Texture();

            tex.textureName = fileName;
            Log.WriteLine("Texture: " + tex.textureName, false);

            if (useTexDir) fileName = Settings.TextureDir + fileName;
            TextureTarget target = TextureTarget.Texture2D;

            try
            {
                if (fileName.Contains(".dds")) // jos dds texture
                {
                    ImageDDS.LoadFromDisk(fileName, out tex.TextureID, out target);
                }
                else
                {
                    ImageGDI.LoadFromDisk(fileName, out tex.TextureID, out target);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }

            int pwidth, pheight;
            tex.Bind(0);
            GL.GetTexLevelParameter(TextureTarget.Texture2D, 0, GetTextureParameter.TextureWidth, out pwidth);
            GL.GetTexLevelParameter(TextureTarget.Texture2D, 0, GetTextureParameter.TextureHeight, out pheight);
            tex.Width = pwidth;
            tex.Height = pheight;
            tex.Target = target;

            if (fileName.Contains(".dds")) // dds tiedostoja ei skaalata ^2 kokoon
            {
                tex.RealWidth = tex.Width;
                tex.RealHeight = tex.Height;
            }
            else
            {
                tex.RealWidth = ImageGDI.RealWidth;
                tex.RealHeight = ImageGDI.RealHeight;
            }
            textures.Add(tex.textureName, tex);
            UnBind(0);
            return tex;
        }