Bridge class to the openGL dll. Provides constants and function definitions.
Esempio n. 1
0
 /// <summary>
 /// Sets the blend equation.
 /// </summary>
 /// <param name="rgbEquation">The RGB equation.</param>
 /// <param name="alphaEquation">The alpha equation.</param>
 public static void BlendEquation(GL rgbEquation, GL alphaEquation)
 {
     Native.glBlendEquationSeparate(rgbEquation, alphaEquation);
 }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Texture" /> class.
 /// </summary>
 /// <param name="target">The texture target.</param>
 /// <param name="colorSpace">The source image color space.</param>
 /// <param name="sampling">The sampling options.</param>
 internal Texture(GL target, ColorSpace colorSpace, Sampling sampling)
 {
     this.target = target;
     this.ColorSpace = colorSpace;
     this.Sampling = sampling;
 }
Esempio n. 3
0
        /// <summary>
        /// Begins the vertex buffer data streaming.
        /// </summary>
        /// <param name="primitive">The vertex buffer primitive type.</param>
        /// <param name="vertexCount">The vertex count.</param>
        /// <param name="indexCount">The index count.</param>
        /// <returns>Reference to self for method call chaining.</returns>
        private unsafe VertexBuffer Begin(GL primitive, int vertexCount, int indexCount)
        {
            if (vertexCount < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(vertexCount));
            }

            if (indexCount < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(indexCount));
            }

            if (this.Handle == 0)
            {
                this.Handle = gl.CreateBuffer();
            }

            this.Bind();

            if (this.VertexCount > 0)
            {
                gl.BufferData(GL.ARRAY_BUFFER, 0, null, GL.STATIC_DRAW);
            }

            this.primitive = primitive;
            this.VertexCount = vertexCount;
            this.IndexCount = indexCount;

            var valueArraySize = vertexCount * this.stride;
            var indexArraySize = indexCount * sizeof(ushort);
            gl.BufferData(GL.ARRAY_BUFFER, valueArraySize + indexArraySize, null, (GL)this.caching);

            blockStart = 0;
            blockCount = 0;
            indexStart = valueArraySize;
            indexCount = 0;

            this.BaseVertex(0)
                .Origin(0, 0, 0)
                .Normal(0, 0, 1)
                .Tangent(1, 0, 0)
                .Color(255, 255, 255, 255)
                .UV(0, 0);

            return this;
        }
Esempio n. 4
0
 /// <summary>
 /// Generates the texture mipmap.
 /// </summary>
 /// <param name="target">The texture target.</param>
 public static void GenerateMipmap(GL target)
 {
     Native.glGenerateMipmap(target);
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes the texture image.
 /// </summary>
 /// <param name="width">The texture image width.</param>
 /// <param name="height">The texture image height.</param>
 /// <param name="format">The image data format.</param>
 /// <param name="data">The image data.</param>
 internal void Initialize(int width, int height, GL format, IntPtr data)
 {
     this.Initialize((GL)this.Texture.ColorSpace, width, height, format, GL.UNSIGNED_BYTE, data);
 }
Esempio n. 6
0
 /// <summary>
 /// Enables an option.
 /// </summary>
 /// <param name="option">The option.</param>
 public static void Enable(GL option)
 {
     Native.glEnable(option);
 }
Esempio n. 7
0
 /// <summary>
 /// Attaches a texture to a framebuffer.
 /// </summary>
 /// <param name="target">The framebuffer target.</param>
 /// <param name="attachment">The framebuffer attachment.</param>
 /// <param name="textureTarget">The texture target.</param>
 /// <param name="texture">The texture object.</param>
 /// <param name="level">The mip level.</param>
 public static void FramebufferTexture2D(GL target, GL attachment, GL textureTarget, int texture, int level)
 {
     Native.glFramebufferTexture2D(target, attachment, textureTarget, texture, level);
 }
Esempio n. 8
0
 /// <summary>
 /// Copies the texture image from the framebuffer.
 /// </summary>
 /// <param name="target">The texture target.</param>
 /// <param name="level">The mip level.</param>
 /// <param name="xOffset">The target X offset.</param>
 /// <param name="yOffset">The target Y offset.</param>
 /// <param name="x">The X coordinate.</param>
 /// <param name="y">The Y coordinate.</param>
 /// <param name="width">The width in pixels.</param>
 /// <param name="height">The height in pixels.</param>
 public static void CopyTexSubImage2D(GL target, int level, int xOffset, int yOffset, int x, int y, int width, int height)
 {
     Native.glCopyTexSubImage2D(target, level, xOffset, yOffset, x, y, width, height);
 }
Esempio n. 9
0
 /// <summary>
 /// Creates a shader.
 /// </summary>
 /// <param name="type">The shader type.</param>
 /// <returns>The shader object.</returns>
 public static int CreateShader(GL type)
 {
     return Native.glCreateShader(type);
 }
Esempio n. 10
0
 /// <summary>
 /// Checks the framebuffer status.
 /// </summary>
 /// <param name="target">The framebuffer target.</param>
 /// <returns>The status code.</returns>
 public static GL CheckFramebufferStatus(GL target)
 {
     return Native.glCheckFramebufferStatus(target);
 }
Esempio n. 11
0
 /// <summary>
 /// Copies the texture image from the framebuffer.
 /// </summary>
 /// <param name="target">The texture target.</param>
 /// <param name="level">The mip level.</param>
 /// <param name="internalFormat">The internal format.</param>
 /// <param name="x">The X coordinate.</param>
 /// <param name="y">The Y coordinate.</param>
 /// <param name="width">The width in pixels.</param>
 /// <param name="height">The height in pixels.</param>
 /// <param name="border">The border thickness.</param>
 public static void CopyTexImage2D(GL target, int level, GL internalFormat, int x, int y, int width, int height, int border)
 {
     Native.glCopyTexImage2D(target, level, internalFormat, x, y, width, height, border);
 }
Esempio n. 12
0
 /// <summary>
 /// Uploads the buffer data.
 /// </summary>
 /// <param name="target">The buffer target.</param>
 /// <param name="offset">The data offset.</param>
 /// <param name="size">The data size.</param>
 /// <param name="data">The data pointer.</param>
 public static void BufferSubData(GL target, int offset, int size, void* data)
 {
     Native.glBufferSubData(target, (IntPtr)offset, (IntPtr)size, data);
 }
Esempio n. 13
0
 /// <summary>
 /// Uploads the buffer data.
 /// </summary>
 /// <param name="target">The buffer target.</param>
 /// <param name="size">The data size.</param>
 /// <param name="data">The data pointer.</param>
 /// <param name="usage">The data usage pattern.</param>
 public static void BufferData(GL target, int size, void* data, GL usage)
 {
     Native.glBufferData(target, (IntPtr)size, data, usage);
 }
Esempio n. 14
0
 /// <summary>
 /// Sets the blend function.
 /// </summary>
 /// <param name="rgbSource">The RGB source factor.</param>
 /// <param name="rgbTarget">The RGB target factor.</param>
 /// <param name="alphaSource">The alpha source factor.</param>
 /// <param name="alphaTarget">The alpha target factor.</param>
 public static void BlendFunc(GL rgbSource, GL rgbTarget, GL alphaSource, GL alphaTarget)
 {
     Native.glBlendFuncSeparate(rgbSource, rgbTarget, alphaSource, alphaTarget);
 }
Esempio n. 15
0
        /// <summary>
        /// Sets the output buffers.
        /// </summary>
        /// <param name="buffer0">The first buffer.</param>
        /// <param name="buffer1">The second buffer.</param>
        /// <param name="buffer2">The third buffer.</param>
        /// <param name="buffer3">The fourth buffer.</param>
        public static void DrawBuffers(GL buffer0, GL buffer1, GL buffer2, GL buffer3)
        {
            var buffers = stackalloc GL[4];
            buffers[0] = buffer0;
            buffers[1] = buffer1;
            buffers[2] = buffer2;
            buffers[3] = buffer3;

            Native.glDrawBuffers(4, ref buffers[0]);
        }
Esempio n. 16
0
 /// <summary>
 /// Sets the face culling mode.
 /// </summary>
 /// <param name="mode">The culling mode.</param>
 public static void CullFace(GL mode)
 {
     Native.glCullFace(mode);
 }
Esempio n. 17
0
 /// <summary>
 /// Draws the indexed vertex arrays.
 /// </summary>
 /// <param name="mode">The primitive type.</param>
 /// <param name="count">The index count.</param>
 /// <param name="type">The index type.</param>
 /// <param name="indices">The starting offset in the index buffer.</param>
 public static void DrawElements(GL mode, int count, GL type, int indices)
 {
     Native.glDrawElements(mode, count, type, (IntPtr)indices);
 }
Esempio n. 18
0
 /// <summary>
 /// Sets the depth test function.
 /// </summary>
 /// <param name="func">The test function.</param>
 public static void DepthFunc(GL func)
 {
     Native.glDepthFunc(func);
 }
Esempio n. 19
0
 /// <summary>
 /// Attaches a renderbuffer to a framebuffer.
 /// </summary>
 /// <param name="target">The framebuffer target.</param>
 /// <param name="attachment">The framebuffer attachment.</param>
 /// <param name="renderbufferTarget">The renderbuffer target.</param>
 /// <param name="renderbuffer">The renderbuffer object.</param>
 public static void FramebufferRenderbuffer(GL target, GL attachment, GL renderbufferTarget, int renderbuffer)
 {
     Native.glFramebufferRenderbuffer(target, attachment, renderbufferTarget, renderbuffer);
 }
Esempio n. 20
0
 /// <summary>
 /// Disables an option.
 /// </summary>
 /// <param name="option">The option.</param>
 public static void Disable(GL option)
 {
     Native.glDisable(option);
 }
Esempio n. 21
0
 /// <summary>
 /// Sets the front face.
 /// </summary>
 /// <param name="face">The front face.</param>
 public static void FrontFace(GL face)
 {
     Native.glFrontFace(face);
 }
Esempio n. 22
0
 /// <summary>
 /// Draws the vertex arrays.
 /// </summary>
 /// <param name="primitive">The primitive type.</param>
 /// <param name="first">The index of the first vertex.</param>
 /// <param name="count">The vertex count.</param>
 public static void DrawArrays(GL primitive, int first, int count)
 {
     Native.glDrawArrays(primitive, first, count);
 }
Esempio n. 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TextureImage" /> class.
 /// </summary>
 /// <param name="texture">The texture.</param>
 /// <param name="image">The texture image.</param>
 internal TextureImage(Texture texture, GL image)
 {
     this.Texture = texture;
     this.image = image;
 }
Esempio n. 24
0
 /// <summary>
 /// Sets the output buffers.
 /// </summary>
 /// <param name="buffer">The buffer.</param>
 public static void DrawBuffers(GL buffer)
 {
     Native.glDrawBuffer(buffer);
 }
Esempio n. 25
0
            /// <summary>
            /// Initializes the texture image.
            /// </summary>
            /// <param name="internalFormat">The internal format.</param>
            /// <param name="width">The texture image width.</param>
            /// <param name="height">The texture image height.</param>
            /// <param name="format">The image data format.</param>
            /// <param name="type">The image data type.</param>
            /// <param name="data">The image data.</param>
            internal void Initialize(GL internalFormat, int width, int height, GL format, GL type, IntPtr data)
            {
                this.Texture.Bind(true);
                this.Texture.Width = width;
                this.Texture.Height = height;

                gl.TexImage2D(image, 0, internalFormat, width, height, 0, format, type, data);

                this.Modified();
            }
Esempio n. 26
0
        /// <summary>
        /// Sets the output buffers.
        /// </summary>
        /// <param name="buffer0">The first buffer.</param>
        /// <param name="buffer1">The second buffer.</param>
        public static void DrawBuffers(GL buffer0, GL buffer1)
        {
            var buffers = stackalloc GL[2];
            buffers[0] = buffer0;
            buffers[1] = buffer1;

            Native.glDrawBuffers(2, ref buffers[0]);
        }
Esempio n. 27
0
        /// <summary>
        /// Releases the object.
        /// </summary>
        public override void Dispose()
        {
            if (current == this.Handle)
            {
                gl.BindBuffer(GL.ARRAY_BUFFER, 0);
                gl.BindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0);
                current = 0;
            }

            if (this.Handle != 0)
            {
                gl.DeleteBuffer(this.Handle);
            }

            this.Handle = 0;
            this.primitive = 0;
            this.VertexCount = 0;
            this.IndexCount = 0;
        }
Esempio n. 28
0
        /// <summary>
        /// Sets the output buffers.
        /// </summary>
        /// <param name="buffer0">The first buffer.</param>
        /// <param name="buffer1">The second buffer.</param>
        /// <param name="buffer2">The third buffer.</param>
        public static void DrawBuffers(GL buffer0, GL buffer1, GL buffer2)
        {
            var buffers = stackalloc GL[3];
            buffers[0] = buffer0;
            buffers[1] = buffer1;
            buffers[2] = buffer2;

            Native.glDrawBuffers(3, ref buffers[0]);
        }
Esempio n. 29
0
        /// <summary>
        /// Compiles the shader.
        /// </summary>
        /// <param name="sourceCode">The source code.</param>
        /// <param name="shaderType">The shader type.</param>
        /// <returns>The shader handle.</returns>
        private int CompileShader(string sourceCode, GL shaderType)
        {
            var code = new StringBuilder()
                .AppendLine("#version 120")
                .AppendLine("#define gl_ViewMatrix                  gl_TextureMatrix[0]")
                .AppendLine("#define gl_ViewMatrixInverse           gl_TextureMatrixInverse[0]")
                .AppendLine("#define gl_ViewMatrixTranspose         gl_TextureMatrixTranspose[0]")
                .AppendLine("#define gl_ViewMatrixInverseTranspose  gl_TextureMatrixInverseTranspose[0]")
                .AppendLine("#define gl_ViewNormalMatrix            mat3(gl_TextureMatrixInverseTranspose[0])");

            if (shaderType == GL.VERTEX_SHADER)
            {
                foreach (var attribute in Shader.Attributes.Values)
                {
                    code.AppendFormat("attribute {0};", attribute).AppendLine();
                }
            }

            if (this.Uniform.Count > 0)
            {
                foreach (var uniform in this.Uniform)
                {
                    code.AppendFormat("uniform {0};", uniform).AppendLine();
                }
            }

            if (this.Varying.Count > 0)
            {
                foreach (var varying in this.Varying)
                {
                    code.AppendFormat("varying {0};", varying).AppendLine();
                }
            }

            code.AppendLine()
                .AppendLine(sourceCode);

            var shader = gl.CreateShader(shaderType);
            gl.ShaderSource(shader, code.ToString());

            if (!gl.CompileShader(shader))
            {
                var error = new StringBuilder()
                    .AppendLine("Shader compilation failed")
                    .AppendLine(gl.GetShaderInfoLog(shader))
                    .AppendLine();

                var lines = code.ToString().Split('\n');

                for (var i = 0; i < lines.Length; i++)
                {
                    error.AppendLine($"{i + 1,4}  {lines[i].TrimEnd()}");
                }

                Trace.TraceError(error.ToString());
                gl.DeleteShader(shader);

                return 0;
            }

            return shader;
        }
Esempio n. 30
0
 /// <summary>
 /// Binds the texture.
 /// </summary>
 /// <param name="target">The texture target.</param>
 /// <param name="texture">The texture object.</param>
 public static void BindTexture(GL target, int texture)
 {
     Native.glBindTexture(target, texture);
 }