Beispiel #1
0
            /// <summary>
            /// Bind material data<para/>
            /// Присвоение материала
            /// </summary>
            void BindMaterial(RendererBase renderer, Surface surf, TextureDictionary td)
            {
                Material mat = surf.Material;

                if (mat.Textures != null)
                {
                    Texture t = (Texture)mat.Textures[0];
                    TextureDictionary.Texture tex = t.CachedTexture;

                    // Caching texture
                    // Кешируем текстуру
                    if (tex != null)
                    {
                        if (tex.State == TextureDictionary.ReadyState.Obsolette)
                        {
                            tex = null;
                        }
                    }
                    if (tex == null)
                    {
                        string lname = t.Name.ToLower();
                        if (td.Textures.ContainsKey(lname))
                        {
                            tex             = td.Textures[lname];
                            t.CachedTexture = tex;
                        }
                    }

                    // Binding texture coord array
                    // Установка массива текстурных координат
                    GL.EnableClientState(ArrayCap.TextureCoordArray);
                    GL.BindBuffer(BufferTarget.ArrayBuffer, tex1Buffer);
                    GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero);

                    // Binding it
                    // Установка текстуры
                    if (tex != null)
                    {
                        if (tex.State == TextureDictionary.ReadyState.Complete)
                        {
                            // Binding tex
                            // Установка текстуры
                            tex.Bind();

                            // Setting up addressing and filtering
                            // Установка адресации и фильтрации
                            TextureFile.FilterMode fm = t.Filter;
                            if (true)                              //!tex.Mipmapped) {
                            {
                                switch (t.Filter)
                                {
                                case TextureFile.FilterMode.MipNearest:
                                    fm = TextureFile.FilterMode.Nearest;
                                    break;

                                case TextureFile.FilterMode.MipLinear:
                                    fm = TextureFile.FilterMode.Nearest;
                                    break;

                                case TextureFile.FilterMode.LinearMipNearest:
                                    fm = TextureFile.FilterMode.Linear;
                                    break;

                                case TextureFile.FilterMode.LinearMipLinear:
                                    fm = TextureFile.FilterMode.Linear;
                                    break;
                                }
                            }
                            switch (fm)
                            {
                            case TextureFile.FilterMode.Nearest:
                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Nearest);
                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Nearest);
                                break;

                            case TextureFile.FilterMode.Linear:
                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear);
                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear);
                                break;

                            case TextureFile.FilterMode.MipNearest:
                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.NearestMipmapNearest);
                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Nearest);
                                break;

                            case TextureFile.FilterMode.MipLinear:
                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.NearestMipmapLinear);
                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Nearest);
                                break;

                            case TextureFile.FilterMode.LinearMipNearest:
                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.LinearMipmapNearest);
                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear);
                                break;

                            case TextureFile.FilterMode.LinearMipLinear:
                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.LinearMipmapLinear);
                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear);
                                break;

                            default:
                                throw new Exception("[Model] Invalid value for FilterMode");
                            }

                            // U addressing
                            // Адресация текстуры по горизонтали
                            switch (t.AddressU)
                            {
                            case TextureFile.AddressMode.Repeat:
                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.Repeat);
                                break;

                            case TextureFile.AddressMode.Mirror:
                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.MirroredRepeat);
                                break;

                            case TextureFile.AddressMode.Clamp:
                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.Clamp);
                                break;

                            default:
                                throw new Exception("[Model] Invalid value for AddressMode");
                            }

                            // V addressing
                            // Адресация текстуры по вертикали
                            switch (t.AddressV)
                            {
                            case TextureFile.AddressMode.Repeat:
                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.Repeat);
                                break;

                            case TextureFile.AddressMode.Mirror:
                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.MirroredRepeat);
                                break;

                            case TextureFile.AddressMode.Clamp:
                                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.Clamp);
                                break;

                            default:
                                throw new Exception("[Model] Invalid value for AddressMode");
                            }
                        }
                    }
                    else
                    {
                        GL.BindTexture(TextureTarget.Texture2D, Renderer.EmptyTexture);
                    }
                }
                else
                {
                    GL.BindTexture(TextureTarget.Texture2D, Renderer.EmptyTexture);
                }
                renderer.SetupSurface(surf, mat, geometry);
            }