Provides access to OpenGL ES 2.0 methods.
Inheritance: GraphicsBindingsBase
Example #1
0
File: GL.cs Project: mortend/uno
        public GLShaderHandle CreateShader(GLShaderType type)
        {
            int shaderName = TKGL.CreateShader((ShaderType)type);

            AddContextObject(new ShaderDisposable(shaderName));
            return(new GLShaderHandle(shaderName));
        }
Example #2
0
        internal void ApplyPass()
        {
            // Create a Program object
            shaderProgram = GL20.CreateProgram();

            // Attach our compiled shaders
            if (VertexIndex < _technique._effect.vertexShaders.Count)
            {
                GL20.AttachShader(shaderProgram, _technique._effect.vertexShaders[VertexIndex]);
            }
            if (FragmentIndex < _technique._effect.fragmentShaders.Count)
            {
                GL20.AttachShader(shaderProgram, _technique._effect.fragmentShaders[FragmentIndex]);
            }

            // Set the parameters
            // TODO GL20.ProgramParameter (shaderProgram, AssemblyProgramParameterArb.GeometryInputType, (int)All.Lines);
            // TODO GL20.ProgramParameter (shaderProgram, AssemblyProgramParameterArb.GeometryOutputType, (int)All.Line);

            // Set the max vertices
            int maxVertices;

            // TODO GL20.GetInteger (GetPName.MaxGeometryOutputVertices, out maxVertices);
            // TODO GL20.ProgramParameter (shaderProgram, AssemblyProgramParameterArb.GeometryVerticesOut, maxVertices);

            // Link the program
            GL20.LinkProgram(shaderProgram);
            string name = String.Format("Technique {0} - Pass {1}: ", _technique.Name, Name);

            ShaderLog(name, shaderProgram);
        }
        public GLES2HardwareIndexBuffer(HardwareBufferManagerBase manager, IndexType type, int numIndices, BufferUsage usage, bool useShadowBuffer)
            : base(manager, type, numIndices, usage, false, useShadowBuffer)
        {
            if (type == IndexType.Size32)
            {
                throw new AxiomException("32 bit hardware buffers are not allowed in OpenGL ES.");
            }

            if (!useShadowBuffer)
            {
                throw new AxiomException("Only support with shadowBuffer");
            }

            OpenGL.GenBuffers(1, ref this._bufferId);
            GLES2Config.GlCheckError(this);
            if (this._bufferId == 0)
            {
                throw new AxiomException("Cannot create GL index buffer");
            }

            OpenGL.BindBuffer(All.ElementArrayBuffer, this._bufferId);
            GLES2Config.GlCheckError(this);
            OpenGL.BufferData(All.ElementArrayBuffer, new IntPtr(sizeInBytes), IntPtr.Zero, GLES2HardwareBufferManager.GetGLUsage(usage));
            GLES2Config.GlCheckError(this);
        }
Example #4
0
File: GL.cs Project: mortend/uno
        public int GetProgramParameter(GLProgramHandle program, GLProgramParameter pname)
        {
            int result;

            TKGL.GetProgram((uint)(int)program, (GetProgramParameterName)pname, out result);
            return(result);
        }
Example #5
0
File: GL.cs Project: mortend/uno
        public int GetShaderParameter(GLShaderHandle shader, GLShaderParameter pname)
        {
            int result;

            TKGL.GetShader((uint)(int)shader, (ShaderParameter)pname, out result);
            return(result);
        }
Example #6
0
File: GL.cs Project: mortend/uno
 public void TexImage2D(GLTextureTarget target, int level, GLPixelFormat internalFormat, int width, int height, int border, GLPixelFormat format, GLPixelType type, IntPtr data)
 {
     TKGL.TexImage2D((TextureTarget2d)target, level,
                     (TextureComponentCount)internalFormat, width, height, border,
                     (PixelFormat)format, (PixelType)type,
                     data);
 }
Example #7
0
File: GL.cs Project: mortend/uno
        public GLProgramHandle CreateProgram()
        {
            int programName = TKGL.CreateProgram();

            AddContextObject(new ProgramDisposable(programName));
            return(new GLProgramHandle(programName));
        }
Example #8
0
File: GL.cs Project: mortend/uno
 public void UniformMatrix4(int location, bool transpose, Float4x4[] value)
 {
     if (value.Length > 0)
     {
         TKGL.UniformMatrix4(location, value.Length, transpose, ref value[0].M11);
     }
 }
Example #9
0
File: GL.cs Project: mortend/uno
        public GLTextureHandle CreateTexture()
        {
            int texture = TKGL.GenTexture();

            AddContextObject(new TextureDisposable(texture));
            return(new GLTextureHandle(texture));
        }
Example #10
0
File: GL.cs Project: mortend/uno
        public Int4 GetInteger(GLInteger4Name pname)
        {
            var p = new int[4];

            TKGL.GetInteger((GetPName)pname, p);
            return(new Int4(p[0], p[1], p[2], p[3]));
        }
Example #11
0
File: GL.cs Project: mortend/uno
        public GLRenderbufferHandle CreateRenderbuffer()
        {
            int r;

            TKGL.GenRenderbuffers(1, out r);
            AddContextObject(new RenderbufferDisposable(r));
            return(new GLRenderbufferHandle(r));
        }
Example #12
0
File: GL.cs Project: mortend/uno
        public GLBufferHandle CreateBuffer()
        {
            int r;

            TKGL.GenBuffers(1, out r);
            AddContextObject(new BufferDisposable(r));
            return(new GLBufferHandle(r));
        }
Example #13
0
File: GL.cs Project: mortend/uno
 public void Uniform4(int location, Float4[] value)
 {
     if (value.Length > 0)
     {
         unsafe
         {
             fixed(float *p = &value[0].X)
             TKGL.Uniform4(location, value.Length, p);
         }
     }
 }
Example #14
0
File: GL.cs Project: mortend/uno
 public void Uniform3(int location, Int3[] value)
 {
     if (value.Length > 0)
     {
         unsafe
         {
             fixed(int *p = &value[0].X)
             TKGL.Uniform3(location, value.Length, p);
         }
     }
 }
        /// <summary>
        /// </summary>
        /// <param name="disposeManagedResources"> </param>
        protected override void dispose(bool disposeManagedResources)
        {
            if (!IsDisposed)
            {
                if (disposeManagedResources)
                {
                    OpenGL.DeleteBuffers(1, ref this._bufferId);
                    GLES2Config.GlCheckError(this);
                }
            }

            // If it is available, make the call to the
            // base class's Dispose(Boolean) method
            base.dispose(disposeManagedResources);
        }
Example #16
0
File: GL.cs Project: mortend/uno
 public void TexSubImage2D(GLTextureTarget target,
                           int level,
                           int xoffset,
                           int yoffset,
                           int width,
                           int height,
                           GLPixelFormat format,
                           GLPixelType type,
                           IntPtr data)
 {
     TKGL.TexSubImage2D((TextureTarget2d)target, level,
                        xoffset, yoffset, width, height,
                        (PixelFormat)format, (PixelType)type,
                        data);
 }
Example #17
0
        protected override void CreateFrameBuffer()
        {
            ContextRenderingApi = EAGLRenderingAPI.OpenGLES2;
            base.CreateFrameBuffer();
            // Create a depth renderbuffer
            GL.GenRenderbuffers(1, out depthRenderBuffer);
            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, depthRenderBuffer);

            // Allocate storage for the new renderbuffer
            GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferInternalFormat.DepthComponent16,
                                   (int)(Size.Width * screenScale), (int)(Size.Height * screenScale));

            // Attach the renderbuffer to the framebuffer's depth attachment point
            GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferSlot.DepthAttachment, RenderbufferTarget.Renderbuffer, depthRenderBuffer);

            GL.ClearDepth(1.0f);                // Depth Buffer Setup
            GL.DepthFunc(DepthFunction.Lequal); // The Type Of Depth Test To Do
        }
        /// <summary>
        /// </summary>
        /// <param name="offset"> </param>
        /// <param name="length"> </param>
        /// <param name="src"> </param>
        /// <param name="discardWholeBuffer"> </param>
        public override void WriteData(int offset, int length, BufferBase src, bool discardWholeBuffer)
        {
            OpenGL.BindBuffer(All.ElementArrayBuffer, this._bufferId);
            GLES2Config.GlCheckError(this);
            // Update the shadow buffer
            if (useShadowBuffer)
            {
                var destData = shadowBuffer.Lock(offset, length, discardWholeBuffer ? BufferLocking.Discard : BufferLocking.Normal);
                Memory.Copy(src, destData, length);
                shadowBuffer.Unlock();
            }

            var srcPtr = src.Ptr;

            if (offset == 0 && length == sizeInBytes)
            {
                OpenGL.BufferData(All.ElementArrayBuffer, new IntPtr(sizeInBytes), ref srcPtr, GLES2HardwareBufferManager.GetGLUsage(usage));
                GLES2Config.GlCheckError(this);
            }
            else
            {
                if (discardWholeBuffer)
                {
                    OpenGL.BufferData(All.ElementArrayBuffer, new IntPtr(sizeInBytes), IntPtr.Zero, GLES2HardwareBufferManager.GetGLUsage(usage));
                    GLES2Config.GlCheckError(this);
                }
                // Now update the real buffer
                OpenGL.BufferSubData(All.ElementArrayBuffer, new IntPtr(offset), new IntPtr(length), ref srcPtr);
                GLES2Config.GlCheckError(this);
            }

            if (src.Ptr != srcPtr)
            {
                LogManager.Instance.Write("[GLES2] HardwareIndexBuffer.WriteData - buffer pointer modified by GL.BufferData.");
            }
        }
 /// <summary>
 /// </summary>
 protected override void UnlockImpl()
 {
     if (this._lockedToScratch)
     {
         if (this._scratchUploadOnUnlock)
         {
             // have to write the data back to vertex buffer
             this.WriteData(this._scratchOffset, this._scratchSize, this._scratchPtr, this._scratchOffset == 0 && this._scratchSize == sizeInBytes);
         }
         // deallocate from scratch buffer
         ((GLES2HardwareBufferManager)HardwareBufferManager.Instance).DeallocateScratch(this._scratchPtr);
         this._lockedToScratch = false;
     }
     else
     {
         OpenGL.BindBuffer(All.ElementArrayBuffer, this._bufferId);
         GLES2Config.GlCheckError(this);
         if (!OpenGLOES.UnmapBuffer(All.ElementArrayBuffer))
         {
             throw new AxiomException("Buffer data corrupted, please reload");
         }
     }
     isLocked = false;
 }
        /// <summary>
        /// </summary>
        protected override void UpdateFromShadow()
        {
            if (useShadowBuffer && shadowUpdated && !suppressHardwareUpdate)
            {
                var srcData = shadowBuffer.Lock(lockStart, lockSize, BufferLocking.ReadOnly);
                OpenGL.BindBuffer(All.ElementArrayBuffer, this._bufferId);
                GLES2Config.GlCheckError(this);

                var srcPtr = new IntPtr(srcData.Ptr);
                // Update whole buffer if possible, otherwise normal
                if (lockStart == 0 && lockSize == sizeInBytes)
                {
                    OpenGL.BufferData(All.ElementArrayBuffer, new IntPtr(sizeInBytes), srcPtr, GLES2HardwareBufferManager.GetGLUsage(usage));
                    GLES2Config.GlCheckError(this);
                }
                else
                {
                    OpenGL.BufferSubData(All.ElementArrayBuffer, new IntPtr(lockStart), new IntPtr(lockSize), srcPtr);
                    GLES2Config.GlCheckError(this);
                }
                shadowBuffer.Unlock();
                shadowUpdated = false;
            }
        }
 public void Viewport(int x, int y, int width, int height)
 {
     GLES20.Viewport(x, y, width, height);
 }
 public void GetInteger(All name, ref int value)
 {
     GLES20.GetInteger((GetPName)name, out value);
 }
 public void Scissor(int x, int y, int width, int height)
 {
     GLES20.Scissor(x, y, width, height);
 }
 public void GenFramebuffers(int n, ref int framebuffers)
 {
     GLES20.GenFramebuffers(n, out framebuffers);
 }
 public void GenRenderbuffers(int n, ref int renderbuffers)
 {
     GLES20.GenRenderbuffers(n, out renderbuffers);
 }
 public void FramebufferRenderbuffer(
     All target, All attachment, All renderbuffertarget, int renderbuffer)
 {
     GLES20.FramebufferRenderbuffer((FramebufferTarget)target, (FramebufferSlot)attachment, (RenderbufferTarget)renderbuffertarget, renderbuffer);
 }
 public void DeleteRenderbuffers(int n, ref int renderbuffers)
 {
     GLES20.DeleteRenderbuffers(n, ref renderbuffers);
 }
 public void DeleteFramebuffers(int n, ref int framebuffers)
 {
     GLES20.DeleteFramebuffers(n, ref framebuffers);
 }
 public void BindRenderbuffer(All target, int renderbuffer)
 {
     GLES20.BindRenderbuffer((RenderbufferTarget)target, renderbuffer);
 }
 public void BindFramebuffer(All target, int framebuffer)
 {
     GLES20.BindFramebuffer((FramebufferTarget)target, framebuffer);
 }