Exemple #1
0
        public static ShaderProgram CreateProgram(params GLShader[] shaders)
        {
            // Create the program
            uint programId = GL.CreateProgram();

            // Create the shader program
            ShaderProgram program = new ShaderProgram(programId, shaders);

            GManager.AllocateProgram(program);
            return(program);
        }
        public void Dispose()
        {
            activePipeline.Dispose();

            foreach (Renderer3D renderer in Renderer3Ds.Values)
            {
                renderer.Dispose();
            }
            foreach (Renderer2D renderer in Renderer2Ds.Values)
            {
                renderer.Dispose();
            }
            Sky.Dispose();

            GManager.CleanUpFinal();
        }
Exemple #3
0
        /// <summary>
        /// Loads a shader from a file.
        /// <para>At this stage, there is no auto-cleanup for this shader.
        /// Auto-Cleanup takes place once this is loaded to a ShaderProgram.</para>
        /// </summary>
        public static GLShader LoadShader(string path, ShaderType type)
        {
            GLShader shader;
            string   fileName = Path.GetFileName(path);

            // If shader is not found, load and compile it
            if (!GManager.TryGetShader(fileName, out shader))
            {
                path = Path.Combine(RootDirectory, "Shaders/", path);

                // Allocate the shader Id
                shader = GManager.CreateShader(fileName, type);
                uint shaderId = shader.Id;
                // Load the shader from the file
                string shaderCode = LoadFileToString(path);
                // Load the shader's sourcecode to the GL shader
                GL.ShaderSource(shaderId, shaderCode);
                // Compile the shader for the GPU
                GL.CompileShader(shaderId);

                // Check the compilation status
                int    status = GL.GetShader(shaderId, ShaderParameter.CompileStatus);
                string log    = GL.GetShaderInfoLog(shaderId);

                // Log
                if (status == 0)
                {
                    throw new GLoaderException(String.Format("Failed to compile {0}. Reason: {1}", Path.GetFileName(path), log));
                }
                else if (LogShaderCompilation)
                {
                    if (string.IsNullOrWhiteSpace(log))
                    {
                        DashCMD.WriteStandard("Compiled {0} with id {1}.", Path.GetFileName(path), shaderId);
                    }
                    else
                    {
                        DashCMD.WriteStandard("Compiled {0} with id {1}. Status: {2}", Path.GetFileName(path), shaderId, log);
                    }
                }
            }

            return(shader);
        }
Exemple #4
0
        public SpriteInstanceBuffer()
        {
            VAO = GManager.GenVertexArray();
            GL.BindVertexArray(VAO);

            float[] vertexData = new float[]
            {
                -0.5f, -0.5f,
                0.5f, -0.5f,
                -0.5f, 0.5f,
                0.5f, 0.5f
            };

            int floatSize = sizeof(float);

            // Setup buffers
            VertexBuffer = GManager.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBuffer);
            GL.BufferData(BufferTarget.ArrayBuffer, vertexData.Length * floatSize, vertexData, BufferUsageHint.StaticDraw);
            GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 0, IntPtr.Zero);

            PositionBuffer = GManager.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, PositionBuffer);
            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(MaxSprites * 2 * floatSize), IntPtr.Zero, BufferUsageHint.StreamDraw);
            GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 0, IntPtr.Zero);

            ColorBuffer = GManager.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, ColorBuffer);
            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(MaxSprites * 4 * sizeof(byte)), IntPtr.Zero, BufferUsageHint.StreamDraw);
            GL.VertexAttribPointer(2, 4, VertexAttribPointerType.UnsignedByte, true, 0, IntPtr.Zero);

            OrientationBuffer = GManager.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, OrientationBuffer);
            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(MaxSprites * 3 * floatSize), IntPtr.Zero, BufferUsageHint.StreamDraw);
            GL.VertexAttribPointer(3, 3, VertexAttribPointerType.Float, false, 0, IntPtr.Zero);

            GL.BindVertexArray(0);
        }
 public void Dispose()
 {
     GManager.DeleteBuffer(Id);
 }
 public CubeMap()
 {
     Id = GManager.GenTexture();
 }
 public void Dispose()
 {
     GManager.DeleteShader(this);
 }
 public void Dispose()
 {
     GManager.DeleteTexture(Id);
 }
 public virtual void Dispose()
 {
     GManager.DeleteFramebuffer(FBO);
 }