Exemple #1
0
 public override void OnRender(SceneEntity entity)
 {
 }
 public override void OnRender(SceneEntity entity)
 {
     base.OnRender(entity);
 }
Exemple #3
0
 public abstract void OnRender(SceneEntity entity);
Exemple #4
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");
        }