Exemple #1
0
 /// <summary>
 /// Called when the window is loading, only to be used by the startup process.
 /// </summary>
 void Window_Load(object sender, EventArgs e)
 {
     SysConsole.Output(OutputType.INIT, "Window generated!");
     DPIScale = Window.Width / CVars.r_width.ValueF;
     SysConsole.Output(OutputType.INIT, "DPIScale is " + DPIScale + "!");
     SysConsole.Output(OutputType.INIT, "Loading base textures...");
     PreInitRendering();
     Textures = new TextureEngine();
     Textures.InitTextureSystem(this);
     ItemFrame = Textures.GetTexture("ui/hud/item_frame");
     SysConsole.Output(OutputType.INIT, "Loading shaders...");
     Shaders = new ShaderEngine();
     GLVendor = GL.GetString(StringName.Vendor);
     CVars.s_glvendor.Value = GLVendor;
     GLVersion = GL.GetString(StringName.Version);
     CVars.s_glversion.Value = GLVersion;
     GLRenderer = GL.GetString(StringName.Renderer);
     CVars.s_glrenderer.Value = GLRenderer;
     SysConsole.Output(OutputType.INIT, "Vendor: " + GLVendor + ", GLVersion: " + GLVersion + ", Renderer: " + GLRenderer);
     if (GLVendor.ToLowerFast().Contains("intel"))
     {
         SysConsole.Output(OutputType.INIT, "Disabling good graphics (Appears to be Intel: '" + GLVendor + "')");
         Shaders.MCM_GOOD_GRAPHICS = false;
     }
     Shaders.InitShaderSystem(this);
     View3D.CheckError("Load - Shaders");
     SysConsole.Output(OutputType.INIT, "Loading rendering helper...");
     Rendering = new Renderer(Textures, Shaders);
     Rendering.Init();
     SysConsole.Output(OutputType.INIT, "Preparing load screen...");
     Texture load_screen = Textures.GetTexture("ui/menus/loadscreen");
     load_screen.Bind();
     Shaders.ColorMultShader.Bind();
     Establish2D();
     Rendering.RenderRectangle(0, 0, Window.Width, Window.Height);
     Window.SwapBuffers();
     SysConsole.Output(OutputType.INIT, "Loading block textures...");
     TBlock = new TextureBlock();
     TBlock.Generate(this, CVars, Textures);
     View3D.CheckError("Load - Textures");
     SysConsole.Output(OutputType.INIT, "Loading fonts...");
     Fonts = new GLFontEngine(Shaders);
     Fonts.Init(this);
     FontSets = new FontSetEngine(Fonts);
     FontSets.Init(this);
     View3D.CheckError("Load - Fonts");
     SysConsole.Output(OutputType.INIT, "Loading animation engine...");
     Animations = new AnimationEngine();
     SysConsole.Output(OutputType.INIT, "Loading model engine...");
     Models = new ModelEngine();
     Models.Init(Animations, this);
     SysConsole.Output(OutputType.INIT, "Loading general graphics settings...");
     CVars.r_vsync.OnChanged += onVsyncChanged;
     onVsyncChanged(CVars.r_vsync, null);
     CVars.r_cloudshadows.OnChanged += onCloudShadowChanged;
     View3D.CheckError("Load - General Graphics");
     SysConsole.Output(OutputType.INIT, "Loading UI engine...");
     UIConsole.InitConsole(); // TODO: make this non-static
     InitChatSystem();
     View3D.CheckError("Load - UI");
     SysConsole.Output(OutputType.INIT, "Preparing rendering engine...");
     InitRendering();
     View3D.CheckError("Load - Rendering");
     SysConsole.Output(OutputType.INIT, "Loading particle effect engine...");
     Particles = new ParticleHelper(this) { Engine = new ParticleEngine(this) };
     SysConsole.Output(OutputType.INIT, "Preparing mouse, keyboard, and gamepad handlers...");
     KeyHandler.Init();
     GamePadHandler.Init();
     View3D.CheckError("Load - Keyboard/mouse");
     SysConsole.Output(OutputType.INIT, "Building the sound system...");
     Sounds = new SoundEngine();
     Sounds.Init(this, CVars);
     View3D.CheckError("Load - Sound");
     SysConsole.Output(OutputType.INIT, "Building game world...");
     BuildWorld();
     View3D.CheckError("Load - World");
     SysConsole.Output(OutputType.INIT, "Preparing networking...");
     Network = new NetworkBase(this);
     RegisterDefaultEntityTypes();
     View3D.CheckError("Load - Net");
     SysConsole.Output(OutputType.INIT, "Playing background music...");
     BackgroundMusic();
     CVars.a_musicvolume.OnChanged += onMusicVolumeChanged;
     CVars.a_musicpitch.OnChanged += onMusicPitchChanged;
     CVars.a_music.OnChanged += onMusicChanged;
     CVars.a_echovolume.OnChanged += OnEchoVolumeChanged;
     OnEchoVolumeChanged(null, null);
     SysConsole.Output(OutputType.INIT, "Setting up screens...");
     TheMainMenuScreen = new MainMenuScreen(this);
     TheGameScreen = new GameScreen(this);
     TheSingleplayerMenuScreen = new SingleplayerMenuScreen(this);
     SysConsole.Output(OutputType.INIT, "Preparing inventory...");
     InitInventory();
     SysConsole.Output(OutputType.INIT, "Showing main menu...");
     ShowMainMenu();
     SysConsole.Output(OutputType.INIT, "Trying to grab RawGamePad...");
     try
     {
         RawGamePad = new XInput();
     }
     catch (Exception ex)
     {
         SysConsole.Output(OutputType.INIT, "Failed to grab RawGamePad: " + ex.Message);
     }
     View3D.CheckError("Load - Final");
     SysConsole.Output(OutputType.INIT, "Ready and looping!");
 }
Exemple #2
0
 public void LoadSkin(TextureEngine texs)
 {
     if (Skinned)
     {
         return;
     }
     Skinned = true;
     if (Engine.TheClient.Files.Exists("models/" + Name + ".skin"))
     {
         string[] data = Engine.TheClient.Files.ReadText("models/" + Name + ".skin").SplitFast('\n');
         foreach (string datum in data)
         {
             if (datum.Length > 0)
             {
                 string[] datums = datum.SplitFast('=');
                 if (datums.Length == 2)
                 {
                     Texture tex     = texs.GetTexture(datums[1]);
                     bool    success = false;
                     string  typer;
                     string  datic = datums[0].BeforeAndAfter(":::", out typer);
                     typer = typer.ToLowerFast();
                     for (int i = 0; i < Meshes.Count; i++)
                     {
                         if (Meshes[i].Name == datic)
                         {
                             if (typer == "specular")
                             {
                                 Meshes[i].vbo.Tex_Specular = tex;
                             }
                             else if (typer == "reflectivity")
                             {
                                 Meshes[i].vbo.Tex_Reflectivity = tex;
                             }
                             else if (typer == "normal")
                             {
                                 Meshes[i].vbo.Tex_Normal = tex;
                             }
                             else if (typer == "")
                             {
                                 Meshes[i].vbo.Tex = tex;
                             }
                             else
                             {
                                 SysConsole.Output(OutputType.WARNING, "Unknown skin entry typer: '" + typer + "', expected reflectivity, specular, or simply no specification!");
                             }
                             success = true;
                         }
                     }
                     if (!success)
                     {
                         SysConsole.Output(OutputType.WARNING, "Unknown skin entry " + datums[0]);
                         StringBuilder all = new StringBuilder(Meshes.Count * 100);
                         for (int i = 0; i < Meshes.Count; i++)
                         {
                             all.Append(Meshes[i].Name + ", ");
                         }
                         SysConsole.Output(OutputType.WARNING, "Available: " + all.ToString());
                     }
                 }
             }
         }
     }
     else
     {
         SysConsole.Output(OutputType.WARNING, "Can't find models/" + Name + ".skin!");
     }
 }
Exemple #3
0
 public Renderer(TextureEngine tengine, ShaderEngine shaderdet)
 {
     Engine  = tengine;
     Shaders = shaderdet;
 }
Exemple #4
0
        public void Generate(Client tclient, ClientCVar cvars, TextureEngine eng, bool delayable)
        {
            TheClient = tclient;
            if (TextureID > -1)
            {
                GL.DeleteTexture(TextureID);
                GL.DeleteTexture(NormalTextureID);
                GL.DeleteTexture(HelpTextureID);
            }
            List <MaterialTextureInfo> texs = new List <MaterialTextureInfo>(MaterialHelpers.Textures.Length);

            TexList = texs;
            int extras = 0;

            for (int i = 0; i < MaterialHelpers.Textures.Length; i++)
            {
                string[] basic = MaterialHelpers.Textures[i].SplitFast('@')[0].SplitFast('$')[0].SplitFast('%')[0].SplitFast(',');
                texs.Add(new MaterialTextureInfo()
                {
                    Mat = i, ResultantID = extras
                });
                extras += basic.Length;
            }
            TEngine   = eng;
            TextureID = GL.GenTexture();
            TWidth    = cvars.r_blocktexturewidth.ValueI;
            HelpTWMin = TEX_REQUIRED_BITS / (TWidth * TWidth);
            GL.BindTexture(TextureTarget.Texture2DArray, TextureID);
            int levels = TheClient.CVars.r_block_mipmaps.ValueB ? (TWidth == 256 ? 6 : 4) : 1; // TODO: 6/4 -> Setting

            GL.TexStorage3D(TextureTarget3d.Texture2DArray, levels, SizedInternalFormat.Rgba8, TWidth, TWidth, extras);
            GL.GenerateMipmap(GenerateMipmapTarget.Texture2DArray);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)(cvars.r_blocktexturelinear.ValueB ? TextureMinFilter.LinearMipmapLinear : TextureMinFilter.Nearest));
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)(cvars.r_blocktexturelinear.ValueB ? TextureMagFilter.Linear : TextureMagFilter.Nearest));
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
            HelpTextureID = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2DArray, HelpTextureID);
            GL.TexStorage3D(TextureTarget3d.Texture2DArray, levels, SizedInternalFormat.Rgba8, TWidth, TWidth, extras + HelpTWMin);
            GL.GenerateMipmap(GenerateMipmapTarget.Texture2DArray);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
            NormalTextureID = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2DArray, NormalTextureID);
            GL.TexStorage3D(TextureTarget3d.Texture2DArray, levels, SizedInternalFormat.Rgba8, TWidth, TWidth, extras);
            GL.GenerateMipmap(GenerateMipmapTarget.Texture2DArray);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
            // TODO: Use normal.a!
            IntTexs = new string[MaterialHelpers.Textures.Length];
            for (int ia = 0; ia < MaterialHelpers.Textures.Length; ia++)
            {
                int    i = ia;
                Action a = () =>
                {
                    MaterialTextureInfo tex = texs[i];
                    int      resID          = tex.ResultantID;
                    string[] refrornot      = MaterialHelpers.Textures[i].SplitFast('@');
                    if (refrornot.Length > 1)
                    {
                        string[] rorn = refrornot[1].SplitFast('%');
                        if (rorn.Length > 1)
                        {
                            tex.RefrRate = Utilities.StringToFloat(rorn[1]);
                        }
                        tex.RefractTextures = rorn[0].SplitFast(',');
                    }
                    string[] glowornot = refrornot[0].SplitFast('!');
                    if (glowornot.Length > 1)
                    {
                        tex.GlowingTextures = glowornot[1].SplitFast(',');
                    }
                    string[] reflornot = glowornot[0].SplitFast('*');
                    if (reflornot.Length > 1)
                    {
                        tex.ReflectTextures = reflornot[1].SplitFast(',');
                    }
                    string[] specularornot = reflornot[0].SplitFast('&');
                    if (specularornot.Length > 1)
                    {
                        tex.SpecularTextures = specularornot[1].SplitFast(',');
                    }
                    string[] normalornot = specularornot[0].SplitFast('$');
                    GL.BindTexture(TextureTarget.Texture2DArray, NormalTextureID);
                    if (normalornot.Length > 1)
                    {
                        string[] rorn = normalornot[1].SplitFast('%');
                        if (rorn.Length > 1)
                        {
                            tex.NormRate = Utilities.StringToFloat(rorn[1]);
                        }
                        tex.NormalTextures = rorn[0].SplitFast(',');
                        if (tex.NormalTextures.Length > 1)
                        {
                            SetAnimated((int)resID, tex.NormRate, tex.NormalTextures, NormalTextureID, -1);
                        }
                    }
                    else
                    {
                        SetTexture((int)resID, "normal_def", -1);
                    }
                    string[] rateornot = normalornot[0].SplitFast('%');
                    if (rateornot.Length > 1)
                    {
                        tex.Rate = Utilities.StringToFloat(rateornot[1]);
                    }
                    tex.Textures = rateornot[0].SplitFast(',');
                    GL.BindTexture(TextureTarget.Texture2DArray, TextureID);
                    if (tex.Textures.Length > 1)
                    {
                        SetAnimated((int)resID, tex.Rate, tex.Textures, TextureID, resID);
                        if (tex.NormalTextures == null)
                        {
                            GL.BindTexture(TextureTarget.Texture2DArray, NormalTextureID);
                            tex.NormalTextures = new string[tex.Textures.Length];
                            tex.NormRate       = tex.Rate;
                            for (int fz = 0; fz < tex.NormalTextures.Length; fz++)
                            {
                                tex.NormalTextures[fz] = "normal_def";
                            }
                            SetAnimated((int)resID, tex.Rate, tex.NormalTextures, NormalTextureID, -1);
                        }
                    }
                    else
                    {
                        SetTexture((int)resID, tex.Textures[0], resID);
                        if (tex.NormalTextures == null)
                        {
                            tex.NormalTextures = new string[] { "normal_def" };
                        }
                    }
                    if (tex.ReflectTextures == null)
                    {
                        tex.ReflectTextures = new string[tex.Textures.Length];
                        for (int fz = 0; fz < tex.ReflectTextures.Length; fz++)
                        {
                            tex.ReflectTextures[fz] = "black";
                        }
                        tex.RefractTextures  = tex.ReflectTextures;
                        tex.GlowingTextures  = tex.ReflectTextures;
                        tex.SpecularTextures = tex.ReflectTextures;
                    }
                    if (tex.NormRate != tex.Rate || tex.RefrRate != tex.Rate)
                    {
                        SysConsole.Output(OutputType.WARNING, "Rates wrong for " + MaterialHelpers.Textures[i]);
                        tex.NormRate = tex.Rate;
                        tex.RefrRate = tex.Rate;
                    }
                    if (tex.Textures.Length != tex.NormalTextures.Length || tex.ReflectTextures.Length != tex.Textures.Length)
                    {
                        SysConsole.Output(OutputType.WARNING, "Texture counts wrong for " + MaterialHelpers.Textures[i]);
                    }
                    IntTexs[(int)tex.Mat] = tex.Textures[0];
                    if (!delayable)
                    {
                        TheClient.PassLoadScreen();
                    }
                };
                if (delayable)
                {
                    TheClient.Schedule.ScheduleSyncTask(a, i * LoadRate);
                }
                else
                {
                    a();
                }
            }
            double time = (MaterialHelpers.Textures.Length + 1) * LoadRate;

            for (int ia = 0; ia < texs.Count; ia++)
            {
                int    i = ia;
                Action a = () =>
                {
                    GL.BindTexture(TextureTarget.Texture2DArray, HelpTextureID);
                    Bitmap combo = GetCombo(texs[i], 0);
                    if ((texs[i].SpecularTextures != null) && (texs[i].ReflectTextures != null) && (texs[i].RefractTextures != null) && (texs[i].GlowingTextures != null) && texs[i].SpecularTextures.Length > 1)
                    {
                        Bitmap[] bmps = new Bitmap[texs[i].SpecularTextures.Length];
                        bmps[0] = combo;
                        for (int x = 1; x < bmps.Length; x++)
                        {
                            bmps[x] = GetCombo(texs[i], x);
                        }
                        SetAnimated((int)texs[i].ResultantID + HelpTWMin, texs[i].RefrRate, bmps, HelpTextureID);
                        for (int x = 1; x < bmps.Length; x++)
                        {
                            bmps[x].Dispose();
                        }
                    }
                    else
                    {
                        TEngine.LockBitmapToTexture(combo, (int)texs[i].ResultantID + HelpTWMin);
                    }
                    combo.Dispose();
                    if (!delayable)
                    {
                        TheClient.PassLoadScreen();
                    }
                };
                if (delayable)
                {
                    TheClient.Schedule.ScheduleSyncTask(a, time + i * LoadRate);
                }
                else
                {
                    a();
                }
            }
            if (TheClient.CVars.r_block_mipmaps.ValueB)
            {
                Action mipmap = () =>
                {
                    GL.BindTexture(TextureTarget.Texture2DArray, TextureID);
                    GL.GenerateMipmap(GenerateMipmapTarget.Texture2DArray);
                    GL.BindTexture(TextureTarget.Texture2DArray, NormalTextureID);
                    GL.GenerateMipmap(GenerateMipmapTarget.Texture2DArray);
                    GL.BindTexture(TextureTarget.Texture2DArray, HelpTextureID);
                    GL.GenerateMipmap(GenerateMipmapTarget.Texture2DArray);
                    GraphicsUtil.CheckError("Mipmapping");
                };
                if (delayable)
                {
                    TheClient.Schedule.ScheduleSyncTask(mipmap, time * 2);
                }
                else
                {
                    mipmap();
                }
            }
            GL.BindTexture(TextureTarget.Texture2DArray, 0);
        }
Exemple #5
0
        public void Generate(Client tclient, ClientCVar cvars, TextureEngine eng, bool delayable)
        {
            TheClient = tclient;
            if (Anims != null)
            {
                for (int i = 0; i < Anims.Count; i++)
                {
                    Anims[i].Destroy();
                }
            }
            if (TextureID > -1)
            {
                GL.DeleteTexture(TextureID);
                GL.DeleteTexture(NormalTextureID);
                GL.DeleteTexture(HelpTextureID);
            }
            Anims     = new List <AnimatedTexture>();
            TEngine   = eng;
            TextureID = GL.GenTexture();
            TWidth    = cvars.r_blocktexturewidth.ValueI;
            GL.BindTexture(TextureTarget.Texture2DArray, TextureID);
            int levels = TheClient.CVars.r_block_mipmaps.ValueB ? 4 : 1;

            GL.TexStorage3D(TextureTarget3d.Texture2DArray, levels, SizedInternalFormat.Rgba8, TWidth, TWidth, MaterialHelpers.Textures.Length);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)(cvars.r_blocktexturelinear.ValueB ? TextureMinFilter.Linear: TextureMinFilter.Nearest));
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)(cvars.r_blocktexturelinear.ValueB ? TextureMagFilter.Linear : TextureMagFilter.Nearest));
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            HelpTextureID = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2DArray, HelpTextureID);
            GL.TexStorage3D(TextureTarget3d.Texture2DArray, 1, SizedInternalFormat.Rgba8, TWidth, TWidth, MaterialHelpers.Textures.Length);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            NormalTextureID = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2DArray, NormalTextureID);
            GL.TexStorage3D(TextureTarget3d.Texture2DArray, 1, SizedInternalFormat.Rgba8, TWidth, TWidth, MaterialHelpers.Textures.Length);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            // TODO: Use normal.a!
            List <MaterialTextureInfo> texs = new List <MaterialTextureInfo>(MaterialHelpers.Textures.Length);

            IntTexs = new string[MaterialHelpers.Textures.Length];
            for (int ia = 0; ia < MaterialHelpers.Textures.Length; ia++)
            {
                int    i = ia;
                Action a = () =>
                {
                    MaterialTextureInfo tex = new MaterialTextureInfo()
                    {
                        Mat = (Material)i
                    };
                    string[] refrornot = MaterialHelpers.Textures[i].SplitFast('@');
                    if (refrornot.Length > 1)
                    {
                        string[] rorn = refrornot[1].SplitFast('%');
                        if (rorn.Length > 1)
                        {
                            tex.RefrRate = Utilities.StringToFloat(rorn[1]);
                        }
                        tex.RefractTextures = rorn[0].SplitFast(',');
                    }
                    string[] glowornot = refrornot[0].SplitFast('!');
                    if (glowornot.Length > 1)
                    {
                        tex.GlowingTextures = glowornot[1].SplitFast(',');
                    }
                    string[] reflornot = glowornot[0].SplitFast('*');
                    if (reflornot.Length > 1)
                    {
                        tex.ReflectTextures = reflornot[1].SplitFast(',');
                    }
                    string[] specularornot = reflornot[0].SplitFast('&');
                    if (specularornot.Length > 1)
                    {
                        tex.SpecularTextures = specularornot[1].SplitFast(',');
                    }
                    string[] normalornot = specularornot[0].SplitFast('$');
                    GL.BindTexture(TextureTarget.Texture2DArray, NormalTextureID);
                    if (normalornot.Length > 1)
                    {
                        string[] rorn = normalornot[1].SplitFast('%');
                        if (rorn.Length > 1)
                        {
                            tex.NormRate = Utilities.StringToFloat(rorn[1]);
                        }
                        tex.NormalTextures = rorn[0].SplitFast(',');
                        SetTexture((int)tex.Mat, tex.NormalTextures[0]);
                        if (tex.NormalTextures.Length > 1)
                        {
                            SetAnimated((int)tex.Mat, tex.NormRate, tex.NormalTextures, NormalTextureID);
                        }
                    }
                    else
                    {
                        SetTexture((int)tex.Mat, "normal_def");
                    }
                    string[] rateornot = normalornot[0].SplitFast('%');
                    if (rateornot.Length > 1)
                    {
                        tex.Rate = Utilities.StringToFloat(rateornot[1]);
                    }
                    tex.Textures = rateornot[0].SplitFast(',');
                    GL.BindTexture(TextureTarget.Texture2DArray, TextureID);
                    SetTexture((int)tex.Mat, tex.Textures[0]);
                    if (tex.Textures.Length > 1)
                    {
                        SetAnimated((int)tex.Mat, tex.Rate, tex.Textures, TextureID);
                    }
                    texs.Add(tex);
                    IntTexs[(int)tex.Mat] = tex.Textures[0];
                    if (!delayable)
                    {
                        TheClient.PassLoadScreen();
                    }
                };
                if (delayable)
                {
                    TheClient.Schedule.ScheduleSyncTask(a, i * LoadRate);
                }
                else
                {
                    a();
                }
            }
            double time = (MaterialHelpers.Textures.Length + 1) * LoadRate;

            if (TheClient.CVars.r_block_mipmaps.ValueB)
            {
                Action mipmap = () =>
                {
                    GL.BindTexture(TextureTarget.Texture2DArray, TextureID);
                    GL.GenerateMipmap(GenerateMipmapTarget.Texture2DArray);
                    View3D.CheckError("Mipmapping");
                };
                if (delayable)
                {
                    TheClient.Schedule.ScheduleSyncTask(mipmap, time);
                }
                else
                {
                    mipmap();
                }
            }
            for (int ia = 0; ia < texs.Count; ia++)
            {
                int    i = ia;
                Action a = () =>
                {
                    GL.BindTexture(TextureTarget.Texture2DArray, HelpTextureID);
                    Bitmap combo = GetCombo(texs[i], 0);
                    TEngine.LockBitmapToTexture(combo, (int)texs[i].Mat);
                    if ((texs[i].SpecularTextures != null) && (texs[i].ReflectTextures != null) && (texs[i].RefractTextures != null) && (texs[i].GlowingTextures != null) && texs[i].SpecularTextures.Length > 1)
                    {
                        Bitmap[] bmps = new Bitmap[texs[i].SpecularTextures.Length];
                        bmps[0] = combo;
                        for (int x = 1; x < bmps.Length; x++)
                        {
                            bmps[x] = GetCombo(texs[i], x);
                        }
                        SetAnimated((int)texs[i].Mat, texs[i].RefrRate, bmps, HelpTextureID);
                        for (int x = 1; x < bmps.Length; x++)
                        {
                            bmps[x].Dispose();
                        }
                    }
                    combo.Dispose();
                    if (!delayable)
                    {
                        TheClient.PassLoadScreen();
                    }
                };
                if (delayable)
                {
                    TheClient.Schedule.ScheduleSyncTask(a, time + i * LoadRate);
                }
                else
                {
                    a();
                }
            }
            GL.BindTexture(TextureTarget.Texture2DArray, 0);
            GL.BindTexture(TextureTarget.Texture2DArray, 0);
        }
Exemple #6
0
        public void Generate(Client tclient, ClientCVar cvars, TextureEngine eng)
        {
            TheClient = tclient;
            if (Anims != null)
            {
                for (int i = 0; i < Anims.Count; i++)
                {
                    Anims[i].Destroy();
                }
            }
            if (TextureID > -1)
            {
                GL.DeleteTexture(TextureID);
                GL.DeleteTexture(NormalTextureID);
                GL.DeleteTexture(HelpTextureID);
            }
            Anims     = new List <AnimatedTexture>();
            TEngine   = eng;
            TextureID = GL.GenTexture();
            TWidth    = cvars.r_blocktexturewidth.ValueI;
            GL.BindTexture(TextureTarget.Texture2DArray, TextureID);
            GL.TexStorage3D(TextureTarget3d.Texture2DArray, 1, SizedInternalFormat.Rgba8, TWidth, TWidth, MaterialHelpers.Textures.Length);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)(cvars.r_blocktexturelinear.ValueB ? TextureMinFilter.Linear: TextureMinFilter.Nearest));
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)(cvars.r_blocktexturelinear.ValueB ? TextureMagFilter.Linear : TextureMagFilter.Nearest));
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            HelpTextureID = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2DArray, HelpTextureID);
            GL.TexStorage3D(TextureTarget3d.Texture2DArray, 1, SizedInternalFormat.Rgba8, TWidth, TWidth, MaterialHelpers.Textures.Length);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            NormalTextureID = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2DArray, NormalTextureID);
            GL.TexStorage3D(TextureTarget3d.Texture2DArray, 1, SizedInternalFormat.Rgba8, TWidth, TWidth, MaterialHelpers.Textures.Length);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            // TODO: Use normal.a!
            List <MaterialTextureInfo> texs = new List <MaterialTextureInfo>(MaterialHelpers.Textures.Length);

            IntTexs = new string[MaterialHelpers.Textures.Length];
            //float time = 0;
            for (int ia = 0; ia < MaterialHelpers.Textures.Length; ia++)
            {
                int i = ia;
                // TODO: Make this saner, and don't allow entering a game until it's done maybe?
                //TheClient.Schedule.ScheduleSyncTask(() =>
                {
                    MaterialTextureInfo tex = new MaterialTextureInfo();
                    tex.Mat = (Material)i;
                    string[] refrornot = MaterialHelpers.Textures[i].SplitFast('@');
                    if (refrornot.Length > 1)
                    {
                        string[] rorn = refrornot[1].SplitFast('%');
                        if (rorn.Length > 1)
                        {
                            tex.RefrRate = Utilities.StringToFloat(rorn[1]);
                        }
                        tex.RefractTextures = rorn[0].SplitFast(',');
                    }
                    string[] glowornot = refrornot[0].SplitFast('!');
                    if (glowornot.Length > 1)
                    {
                        tex.GlowingTextures = glowornot[1].SplitFast(',');
                    }
                    string[] reflornot = glowornot[0].SplitFast('*');
                    if (reflornot.Length > 1)
                    {
                        tex.ReflectTextures = reflornot[1].SplitFast(',');
                    }
                    string[] specularornot = reflornot[0].SplitFast('&');
                    if (specularornot.Length > 1)
                    {
                        tex.SpecularTextures = specularornot[1].SplitFast(',');
                    }
                    string[] normalornot = specularornot[0].SplitFast('$');
                    GL.BindTexture(TextureTarget.Texture2DArray, NormalTextureID);
                    if (normalornot.Length > 1)
                    {
                        string[] rorn = normalornot[1].SplitFast('%');
                        if (rorn.Length > 1)
                        {
                            tex.NormRate = Utilities.StringToFloat(rorn[1]);
                        }
                        tex.NormalTextures = rorn[0].SplitFast(',');
                        SetTexture((int)tex.Mat, tex.NormalTextures[0]);
                        if (tex.NormalTextures.Length > 1)
                        {
                            SetAnimated((int)tex.Mat, tex.NormRate, tex.NormalTextures, NormalTextureID);
                        }
                    }
                    else
                    {
                        SetTexture((int)tex.Mat, "normal_def");
                    }
                    string[] rateornot = normalornot[0].SplitFast('%');
                    if (rateornot.Length > 1)
                    {
                        tex.Rate = Utilities.StringToFloat(rateornot[1]);
                    }
                    tex.Textures = rateornot[0].SplitFast(',');
                    GL.BindTexture(TextureTarget.Texture2DArray, TextureID);
                    SetTexture((int)tex.Mat, tex.Textures[0]);
                    if (tex.Textures.Length > 1)
                    {
                        SetAnimated((int)tex.Mat, tex.Rate, tex.Textures, TextureID);
                    }
                    texs.Add(tex);
                    IntTexs[(int)tex.Mat] = tex.Textures[0];
                }//, i * LoadRate);
                 //time = i * 0.1f;
            }
            for (int ia = 0; ia < texs.Count; ia++)
            {
                int i = ia;
                //TheClient.Schedule.ScheduleSyncTask(() =>
                {
                    GL.BindTexture(TextureTarget.Texture2DArray, HelpTextureID);
                    Bitmap combo = GetCombo(texs[i], 0);
                    TEngine.LockBitmapToTexture(combo, (int)texs[i].Mat);
                    if ((texs[i].SpecularTextures != null) && (texs[i].ReflectTextures != null) && (texs[i].RefractTextures != null) && (texs[i].GlowingTextures != null) && texs[i].SpecularTextures.Length > 1)
                    {
                        Bitmap[] bmps = new Bitmap[texs[i].SpecularTextures.Length];
                        bmps[0] = combo;
                        for (int x = 1; x < bmps.Length; x++)
                        {
                            bmps[x] = GetCombo(texs[i], x);
                        }
                        SetAnimated((int)texs[i].Mat, texs[i].RefrRate, bmps, HelpTextureID);
                        for (int x = 1; x < bmps.Length; x++)
                        {
                            bmps[x].Dispose();
                        }
                    }
                    combo.Dispose();
                }//, time + i * LoadRate);
            }
            GL.BindTexture(TextureTarget.Texture2DArray, 0);
            GL.BindTexture(TextureTarget.Texture2DArray, 0);
        }
Exemple #7
0
 public void Generate(Client tclient, ClientCVar cvars, TextureEngine eng)
 {
     TheClient = tclient;
     if (Anims != null)
     {
         for (int i = 0; i < Anims.Count; i++)
         {
             Anims[i].Destroy();
         }
     }
     if (TextureID > -1)
     {
         GL.DeleteTexture(TextureID);
         GL.DeleteTexture(NormalTextureID);
         GL.DeleteTexture(HelpTextureID);
     }
     Anims = new List<AnimatedTexture>();
     TEngine = eng;
     TextureID = GL.GenTexture();
     TWidth = cvars.r_blocktexturewidth.ValueI;
     GL.BindTexture(TextureTarget.Texture2DArray, TextureID);
     GL.TexStorage3D(TextureTarget3d.Texture2DArray, 1, SizedInternalFormat.Rgba8, TWidth, TWidth, MaterialHelpers.Textures.Length);
     GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)(cvars.r_blocktexturelinear.ValueB ? TextureMinFilter.Linear: TextureMinFilter.Nearest));
     GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)(cvars.r_blocktexturelinear.ValueB ? TextureMagFilter.Linear : TextureMagFilter.Nearest));
     GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
     GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
     HelpTextureID = GL.GenTexture();
     GL.BindTexture(TextureTarget.Texture2DArray, HelpTextureID);
     GL.TexStorage3D(TextureTarget3d.Texture2DArray, 1, SizedInternalFormat.Rgba8, TWidth, TWidth, MaterialHelpers.Textures.Length);
     GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
     GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
     GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
     GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
     NormalTextureID = GL.GenTexture();
     GL.BindTexture(TextureTarget.Texture2DArray, NormalTextureID);
     GL.TexStorage3D(TextureTarget3d.Texture2DArray, 1, SizedInternalFormat.Rgba8, TWidth, TWidth, MaterialHelpers.Textures.Length);
     GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
     GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
     GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
     GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
     // TODO: Use normal.a!
     List<MaterialTextureInfo> texs = new List<MaterialTextureInfo>(MaterialHelpers.Textures.Length);
     IntTexs = new string[MaterialHelpers.Textures.Length];
     //float time = 0;
     for (int ia = 0; ia < MaterialHelpers.Textures.Length; ia++)
     {
         int i = ia;
         // TODO: Make this saner, and don't allow entering a game until it's done maybe?
         //TheClient.Schedule.ScheduleSyncTask(() =>
         {
             MaterialTextureInfo tex = new MaterialTextureInfo();
             tex.Mat = (Material)i;
             string[] refrornot = MaterialHelpers.Textures[i].SplitFast('@');
             if (refrornot.Length > 1)
             {
                 string[] rorn = refrornot[1].SplitFast('%');
                 if (rorn.Length > 1)
                 {
                     tex.RefrRate = Utilities.StringToFloat(rorn[1]);
                 }
                 tex.RefractTextures = rorn[0].SplitFast(',');
             }
             string[] glowornot = refrornot[0].SplitFast('!');
             if (glowornot.Length > 1)
             {
                 tex.GlowingTextures = glowornot[1].SplitFast(',');
             }
             string[] reflornot = glowornot[0].SplitFast('*');
             if (reflornot.Length > 1)
             {
                 tex.ReflectTextures = reflornot[1].SplitFast(',');
             }
             string[] specularornot = reflornot[0].SplitFast('&');
             if (specularornot.Length > 1)
             {
                 tex.SpecularTextures = specularornot[1].SplitFast(',');
             }
             string[] normalornot = specularornot[0].SplitFast('$');
             GL.BindTexture(TextureTarget.Texture2DArray, NormalTextureID);
             if (normalornot.Length > 1)
             {
                 string[] rorn = normalornot[1].SplitFast('%');
                 if (rorn.Length > 1)
                 {
                     tex.NormRate = Utilities.StringToFloat(rorn[1]);
                 }
                 tex.NormalTextures = rorn[0].SplitFast(',');
                 SetTexture((int)tex.Mat, tex.NormalTextures[0]);
                 if (tex.NormalTextures.Length > 1)
                 {
                     SetAnimated((int)tex.Mat, tex.NormRate, tex.NormalTextures, NormalTextureID);
                 }
             }
             else
             {
                 SetTexture((int)tex.Mat, "normal_def");
             }
             string[] rateornot = normalornot[0].SplitFast('%');
             if (rateornot.Length > 1)
             {
                 tex.Rate = Utilities.StringToFloat(rateornot[1]);
             }
             tex.Textures = rateornot[0].SplitFast(',');
             GL.BindTexture(TextureTarget.Texture2DArray, TextureID);
             SetTexture((int)tex.Mat, tex.Textures[0]);
             if (tex.Textures.Length > 1)
             {
                 SetAnimated((int)tex.Mat, tex.Rate, tex.Textures, TextureID);
             }
             texs.Add(tex);
             IntTexs[(int)tex.Mat] = tex.Textures[0];
         }//, i * LoadRate);
         //time = i * 0.1f;
     }
     for (int ia = 0; ia < texs.Count; ia++)
     {
         int i = ia;
         //TheClient.Schedule.ScheduleSyncTask(() =>
         {
             GL.BindTexture(TextureTarget.Texture2DArray, HelpTextureID);
             Bitmap combo = GetCombo(texs[i], 0);
             TEngine.LockBitmapToTexture(combo, (int)texs[i].Mat);
             if ((texs[i].SpecularTextures != null) && (texs[i].ReflectTextures != null) && (texs[i].RefractTextures != null) && (texs[i].GlowingTextures != null) && texs[i].SpecularTextures.Length > 1)
             {
                 Bitmap[] bmps = new Bitmap[texs[i].SpecularTextures.Length];
                 bmps[0] = combo;
                 for (int x = 1; x < bmps.Length; x++)
                 {
                     bmps[x] = GetCombo(texs[i], x);
                 }
                 SetAnimated((int)texs[i].Mat, texs[i].RefrRate, bmps, HelpTextureID);
                 for (int x = 1; x < bmps.Length; x++)
                 {
                     bmps[x].Dispose();
                 }
             }
             combo.Dispose();
         }//, time + i * LoadRate);
     }
     GL.BindTexture(TextureTarget.Texture2DArray, 0);
     GL.BindTexture(TextureTarget.Texture2DArray, 0);
 }
Exemple #8
0
 public void LoadSkin(TextureEngine texs)
 {
     if (Skinned)
     {
         return;
     }
     Skinned = true;
     if (Engine.TheClient.Files.Exists("models/" + Name + ".skin"))
     {
         string[] data = Engine.TheClient.Files.ReadText("models/" + Name + ".skin").SplitFast('\n');
         foreach (string datum in data)
         {
             if (datum.Length > 0)
             {
                 string[] datums = datum.SplitFast('=');
                 if (datums.Length == 2)
                 {
                     Texture tex = texs.GetTexture(datums[1]);
                     bool success = false;
                     string typer;
                     string datic = datums[0].BeforeAndAfter(":::", out typer);
                     typer = typer.ToLowerFast();
                     for (int i = 0; i < Meshes.Count; i++)
                     {
                         if (Meshes[i].Name == datic)
                         {
                             if (typer == "specular")
                             {
                                 Meshes[i].vbo.Tex_Specular = tex;
                             }
                             else if (typer == "reflectivity")
                             {
                                 Meshes[i].vbo.Tex_Reflectivity = tex;
                             }
                             else if (typer == "normal")
                             {
                                 Meshes[i].vbo.Tex_Normal = tex;
                             }
                             else if (typer == "")
                             {
                                 Meshes[i].vbo.Tex = tex;
                             }
                             else
                             {
                                 SysConsole.Output(OutputType.WARNING, "Unknown skin entry typer: '" + typer + "', expected reflectivity, specular, or simply no specification!");
                             }
                             success = true;
                         }
                     }
                     if (!success)
                     {
                         SysConsole.Output(OutputType.WARNING, "Unknown skin entry " + datums[0]);
                         StringBuilder all = new StringBuilder(Meshes.Count * 100);
                         for (int i = 0; i < Meshes.Count; i++)
                         {
                             all.Append(Meshes[i].Name + ", ");
                         }
                         SysConsole.Output(OutputType.WARNING, "Available: " + all.ToString());
                     }
                 }
             }
         }
     }
     else
     {
         SysConsole.Output(OutputType.WARNING, "Can't find models/" + Name + ".skin!");
     }
 }
Exemple #9
0
 public Renderer(TextureEngine tengine, ShaderEngine shaderdet)
 {
     Engine = tengine;
     Shaders = shaderdet;
 }