Beispiel #1
0
 public BuffersLayout LoadMesh(Mesh mesh)
 {
     if (!Buffers.ContainsKey(mesh.Id))
     {
         SetBuferData(mesh);
         SetBufferAttributes(mesh);
     }
     return(Buffers[mesh.Id]);
 }
Beispiel #2
0
 //データ読み込み
 public void Overrirde(T io)
 {
     if (Buffers.ContainsKey(io.SaveKey))
     {
         BinaryUtil.BinaryRead(Buffers[io.SaveKey], io.OnRead);
     }
     else
     {
         Debug.LogError(string.Format("Not found Save data Key [{0}] ", io.SaveKey));
     }
 }
Beispiel #3
0
 public GraphicsBuffer <T> CreateBuffer <T>(string attributeName, GraphicsBufferBase.BufferType bufferType) where T : struct
 {
     if (Buffers.ContainsKey(bufferType))
     {
         return(Buffers[bufferType] as GraphicsBuffer <T>);
     }
     else
     {
         var vbo = new GraphicsBuffer <T>(this, bufferType.ToString(), attributeName, bufferType);
         Buffers.Add(bufferType, vbo);
         return(vbo);
     }
 }
Beispiel #4
0
        public static void VsTextViewCreated(IVsTextView textViewAdapter, IWpfTextView textView)
        {
            var buffer = textView.TextBuffer;

            if (Buffers.ContainsKey(buffer))
            {
                ++Buffers[buffer];
            }
            else
            {
                Collectors.AddProperty(buffer, textView.ObtainOrAttachProperty(() => new SymbolCollector(textView)));
                Buffers[buffer] = 1;
            }

            WpfToVs[textView]     = textViewAdapter;
            WpfToBuffer[textView] = buffer;

            textView.Closed += ViewClosed;
        }
Beispiel #5
0
 //データを書き込み
 public void MakeBuffer(List <T> ioList)
 {
     Buffers.Clear();
     ioList.ForEach(
         x =>
     {
         if (Buffers.ContainsKey(x.SaveKey))
         {
             Debug.LogError(string.Format("Save data Key [{0}] is already exsits. Please use another key.", x.SaveKey));
         }
         else
         {
             Profiler.BeginSample("MakeBuffer : " + x.SaveKey);
             byte[] buffer = BinaryUtil.BinaryWrite(x.OnWrite);
             Buffers.Add(x.SaveKey, buffer);
             Profiler.EndSample();
         }
     }
         );
 }
Beispiel #6
0
        public override void OnUpdate(double dt)
        {
            if (!Buffers.ContainsKey(GraphicsBufferBase.BufferType.Index))
            {
                CreateBuffer <uint>("index", GraphicsBufferBase.BufferType.Index);
            }

            var indices = Buffers[GraphicsBufferBase.BufferType.Index] as GraphicsBuffer <uint>;

            if (indices.DataCount() == 0)
            {
                for (int i = 0; i < Buffers[GraphicsBufferBase.BufferType.Vertex].DataCount(); i++)
                {
                    indices.AddData((uint)i);
                }
            }

            if (Dirty)
            {
                foreach (var material in Materials)
                {
                    material.Shader.Use();

                    Bind();

                    foreach (var kvp in Buffers)
                    {
                        kvp.Value.BufferData(material.Shader);
                    }

                    Unbind();

                    material.Shader.Unuse();
                }

                Console.WriteLine("Geometry OnUpdate, dt : " + dt.ToString());

                Dirty = false;
            }
        }
Beispiel #7
0
        public override void OnRender(SceneEntity entity)
        {
            foreach (var material in Materials)
            {
                material.Shader.Use();


                #region Set Uniform To Shader
                var modelMatrix = entity.WorldMatrix;
                material.Shader.SetUniformMatrix4("model", false, ref modelMatrix);

                var viewMatrix = entity.Scene.MainCamera.ViewMatrix;
                material.Shader.SetUniformMatrix4("view", false, ref viewMatrix);

                var projectionMatrix = entity.Scene.MainCamera.ProjectionMatrix;
                material.Shader.SetUniformMatrix4("projection", false, ref projectionMatrix);

                var mvp = modelMatrix * viewMatrix * projectionMatrix;
                material.Shader.SetUniformMatrix4("mvp", false, ref mvp);

                if (material.Textures.Count > 0)
                {
                    for (int i = 0; i < material.Textures.Count; i++)
                    {
                        int         index       = (int)TextureUnit.Texture0;
                        TextureUnit textureUnit = (TextureUnit)(index + i);
                        GL.ActiveTexture(textureUnit);

                        GL.BindTexture(TextureTarget.Texture2D, material.Textures[i].TextureID);
                        material.Shader.SetUniform1(textureUnit.ToString(), i);
                        material.Shader.SetUniform1("useTexture" + i.ToString(), 1);
                    }
                }
                else
                {
                    material.Shader.SetUniform1("useTexture0", -1);
                }
                #endregion

                Bind();

                foreach (var kvp in Buffers)
                {
                    if (material.Shader.AttributeIDs.ContainsKey(kvp.Value.AttributeName))
                    {
                        int attributeID = material.Shader.AttributeIDs[kvp.Value.AttributeName];
                        if (attributeID != -1)
                        {
                            GL.EnableVertexAttribArray(attributeID);
                        }
                    }
                    else
                    {
                        if (Buffers.ContainsKey(GraphicsBufferBase.BufferType.Index))
                        {
                            Buffers[GraphicsBufferBase.BufferType.Index].Bind();
                        }
                    }
                }

                if (Buffers.ContainsKey(GraphicsBufferBase.BufferType.Index))
                {
                    //GL.DrawElements<uint>(PrimitiveType.Triangles, 3, DrawElementsType.UnsignedInt, (Buffers[GraphicsBufferBase.BufferType.Index]as GraphicsBuffer<uint>).Datas.ToArray());
                    GL.DrawElements(PrimitiveType.Triangles, Buffers[GraphicsBufferBase.BufferType.Index].DataCount(), DrawElementsType.UnsignedInt, 0);// (Buffers[GraphicsBufferBase.BufferType.Index] as GraphicsBuffer<uint>).Datas.ToArray());
                }
                else
                {
                    GL.DrawArrays(PrimitiveType.Triangles, 0, Buffers[GraphicsBufferBase.BufferType.Vertex].DataCount());
                }

                foreach (var kvp in Buffers)
                {
                    if (material.Shader.AttributeIDs.ContainsKey(kvp.Value.AttributeName))
                    {
                        int attributeID = material.Shader.AttributeIDs[kvp.Value.AttributeName];
                        if (attributeID != -1)
                        {
                            GL.DisableVertexAttribArray(attributeID);
                        }
                    }
                    {
                        if (Buffers.ContainsKey(GraphicsBufferBase.BufferType.Index))
                        {
                            Buffers[GraphicsBufferBase.BufferType.Index].Unbind();
                        }
                    }
                }

                Unbind();

                material.Shader.Unuse();
            }

            Console.WriteLine("Geometry OnRender");
        }