Example #1
0
        internal Dictionary <TempVertex128, TempVertex128> Build(Dictionary <TempVertex128, TempVertex128> temp = null)
        {
            if (this.Building)
            {
                this.Building = false;
                var List = this.TempMeshes;
                this.TempMeshes = default(TempMesh128.List);
                try
                {
                    var Iter = List.first;
                    var Pos  = List.count;
                    while (0 != Pos--)
                    {
                        var New = new GeoMesh(this, Iter, ref temp);
                        Iter = Iter.next;

                        if (0 == Count++)
                        {
                            New.Next = New;
                            First    = New;
                        }
                        else
                        {
                            Last.Next = New;
                            New.Next  = First;
                        }
                        Last           = New;
                        DrawLayerMask |= (byte)(1 << (New.Material.drawLayerBillboard & 7));
                    }
                }
                finally
                {
                    TempMesh128.Free(ref List);
                }
            }
            return(temp);
        }
Example #2
0
        internal byte BindGL(GeoMesh prev, ref GeoMesh @this)
        {
            if (this.VertexCount != 0)
            {
                int vbo = this.State.Vertex.Gen();

                GL.BindBuffer(BufferTarget.ElementArrayBuffer, vbo);

                GL.BufferData(BufferTarget.ElementArrayBuffer,
                              this.VertexBuffer.Length,
                              VertexBuffer,
                              BufferUsageHint.StaticDraw);

                int ibo = this.State.Index.Gen();

                GL.BindBuffer(BufferTarget.ElementArrayBuffer, ibo);

                if (IndexElementSize == 4)
                {
                    GL.BufferData(
                        BufferTarget.ElementArrayBuffer,
                        this.IndexCount << 2,
                            (uint[])this.IndexBuffer,
                            BufferUsageHint.StaticDraw
                        );
                }
                else if (IndexElementSize == 2)
                {
                    GL.BufferData(
                        BufferTarget.ElementArrayBuffer,
                        this.IndexCount << 1,
                            (ushort[])this.IndexBuffer,
                            BufferUsageHint.StaticDraw);
                }
                else
                {
                    GL.BufferData(
                        BufferTarget.ElementArrayBuffer,
                        this.IndexCount,
                        (byte[])this.IndexBuffer,
                        BufferUsageHint.StaticDraw);
                }

                State.IndexCount     = (ushort)IndexCount;
                State.IndexPrimitive = IndexPrimitive.Triangles;
                State.IndexInteger   =
                    IndexElementSize == 4 ? IndexInteger.Int :
                    IndexElementSize == 2 ? IndexInteger.Short :
                    IndexInteger.Byte;

                State.LightMode = Material.Smooth ? LightMode.Smooth0 : LightMode.Hard0;
                switch (Material.numLight)
                {
                case 0:
                    State.Ambient = (Color4b)Material.light.Lights0.Ambient.Color;
                    break;

                case 1:
                    BindLight(Material.light.Lights1.Light1, ref State.Light1);
                    State.Ambient    = (Color4b)Material.light.Lights1.Ambient.Color;
                    State.LightMode |= LightMode.Hard1;
                    break;

                case 2:
                    BindLight(Material.light.Lights2.Light1, ref State.Light1);
                    BindLight(Material.light.Lights2.Light2, ref State.Light2);
                    State.Ambient    = (Color4b)Material.light.Lights2.Ambient.Color;
                    State.LightMode |= LightMode.Hard2;
                    break;

                case 3:
                    BindLight(Material.light.Lights3.Light1, ref State.Light1);
                    BindLight(Material.light.Lights3.Light2, ref State.Light2);
                    BindLight(Material.light.Lights3.Light3, ref State.Light3);
                    State.Ambient    = (Color4b)Material.light.Lights3.Ambient.Color;
                    State.LightMode |= LightMode.Hard3;
                    break;

                case 4:
                    BindLight(Material.light.Lights4.Light1, ref State.Light1);
                    BindLight(Material.light.Lights4.Light2, ref State.Light2);
                    BindLight(Material.light.Lights4.Light3, ref State.Light3);
                    BindLight(Material.light.Lights4.Light4, ref State.Light4);
                    State.Ambient    = (Color4b)Material.light.Lights4.Ambient.Color;
                    State.LightMode |= LightMode.Hard4;
                    break;

                case 5:
                    BindLight(Material.light.Lights5.Light1, ref State.Light1);
                    BindLight(Material.light.Lights5.Light2, ref State.Light2);
                    BindLight(Material.light.Lights5.Light3, ref State.Light3);
                    BindLight(Material.light.Lights5.Light4, ref State.Light4);
                    BindLight(Material.light.Lights5.Light5, ref State.Light5);
                    State.Ambient    = (Color4b)Material.light.Lights5.Ambient.Color;
                    State.LightMode |= LightMode.Hard5;
                    break;

                case 6:
                    BindLight(Material.light.Lights6.Light1, ref State.Light1);
                    BindLight(Material.light.Lights6.Light2, ref State.Light2);
                    BindLight(Material.light.Lights6.Light3, ref State.Light3);
                    BindLight(Material.light.Lights6.Light4, ref State.Light4);
                    BindLight(Material.light.Lights6.Light5, ref State.Light5);
                    BindLight(Material.light.Lights6.Light6, ref State.Light6);
                    State.Ambient    = (Color4b)Material.light.Lights6.Ambient.Color;
                    State.LightMode |= LightMode.Hard6;
                    break;

                default:
                    BindLight(Material.light.Lights7.Light1, ref State.Light1);
                    BindLight(Material.light.Lights7.Light2, ref State.Light2);
                    BindLight(Material.light.Lights7.Light3, ref State.Light3);
                    BindLight(Material.light.Lights7.Light4, ref State.Light4);
                    BindLight(Material.light.Lights7.Light5, ref State.Light5);
                    BindLight(Material.light.Lights7.Light6, ref State.Light6);
                    BindLight(Material.light.Lights7.Light7, ref State.Light7);
                    State.Ambient    = (Color4b)Material.light.Lights7.Ambient.Color;
                    State.LightMode |= LightMode.Hard7;
                    break;
                }
                ;
                State.Ambient.A   = 255;
                State.ElementMask = (Material.HasVertexColors ?
                                     ElementMask.Color : ElementMask.Normal) |
                                    (Material.HasTexture ?
                                     (null != texture && !texture.IsColorTexture) ?
                                     (ElementMask.Texture | ElementMask.Texcoord) :
                                     ElementMask.Texcoord : (ElementMask)0) |
                                    (ElementMask.Index | ElementMask.Position);

                if (0 != (State.ElementMask & ElementMask.Texture))
                {
                    State.Texture = texture.GetLoadedHandle();
                }

                State.TexturePresentation =
                    (0 == ((Material.wrapModes >> 8) & 1) ?
                     0 == ((Material.wrapModes >> 8) & 2) ?
                     (TexturePresentation)0 :
                     TexturePresentation.ClampS :
                     0 == ((Material.wrapModes >> 8) & 2) ?
                     TexturePresentation.MirrorS :
                     (TexturePresentation)0) |
                    (0 == ((Material.wrapModes) & 1) ?
                     0 == ((Material.wrapModes) & 2) ?
                     (TexturePresentation)0 :
                     TexturePresentation.ClampT :
                     0 == ((Material.wrapModes) & 2) ?
                     TexturePresentation.MirrorT :
                     (TexturePresentation)0);

                State.TextureScaleX = Material.texScaleX;
                State.TextureScaleY = Material.texScaleY;
                State.TextureWidth  = Material.w;
                State.TextureHeight = Material.h;

                if (null != texture && 0 != (State.ElementMask & ElementMask.Texcoord))
                {
                    State.Texture      = texture.GetLoadedHandle();
                    State.ElementMask |= ElementMask.Texture;
                }
                State.Fog           = (Color4b)Material.fogColor;
                State.FogMultiplier = Material.fogMultiplier;
                State.FogOffset     = Material.fogOffset;
                State.FeatureMask   = (FeatureMask)(Material.drawLayerBillboard & 7) |
                                      (this.Parent.Parent.ZTest ? FeatureMask.ZTest : (FeatureMask)0) |
                                      (Material.IsLit ? FeatureMask.Lit : (FeatureMask)0) |
                                      (Material.Fog ? FeatureMask.Fog : (FeatureMask)0);
                State.Color.Value = uint.MaxValue;
                //State.Color.Diffuse
                //State.Color = Material.lightColor;
                //State.Diffuse = Material.lightColor;
                //State.Ambient = Material.darkColor;
                State.VertexColor = VertexColor.Smooth;
                State.Culling     = Material.CullBack ? Material.CullFront ? Culling.Both : Culling.Back : Material.CullFront ? Culling.Front : Culling.Off;

                GraphicsState.Sanitize(ref State);
            }
            return(DrawLayerMask);
        }