示例#1
0
        protected void Initialize()
        {
            uint[] bufferIds = new uint[1];
            NativeGl.glGenBuffers(1, bufferIds);

            this.BufferId = bufferIds[0];
        }
示例#2
0
 public void UniformMatrix4Fv(uint location, int count, byte transpose, Matrix4 matrix)
 {
     unsafe
     {
         float *matrixPtr = &matrix.Row0.X;
         NativeGl.glUniformMatrix4fv(location, count, transpose, matrixPtr);
     }
 }
示例#3
0
        public string GetInfoLog()
        {
            int length;
            var error = new char[MaxInfologLength];

            NativeGl.glGetProgramInfoLog(this.ProgramId, MaxInfologLength, out length, error);

            return(StringExtensions.GetAnsiString(error, length));
        }
示例#4
0
        public uint GetUniformLocation(string name)
        {
            var pname  = MarshalExtensions.StringToPtrAnsi(name);
            var handle = NativeGl.glGetUniformLocation(this.ProgramId, pname);

            Marshal.FreeHGlobal(pname);

            return(handle);
        }
示例#5
0
        protected override void Dispose(bool disposing)
        {
            if (this.ShaderId != 0)
            {
                NativeGl.glDeleteShader(this.ShaderId);
            }

            base.Dispose(disposing);
        }
示例#6
0
文件: Game.cs 项目: pekkah/oglesv2cf
        private void InitializeGraphics()
        {
            try
            {
                // platform graphics setup
                this.RenderingWindow = new RenderingWindow();
                this.RenderingWindow.Show();

                this.DisplayManager = new DisplayManager();

                this.PlatformManager = new PlatformGraphicsManager(this.DisplayManager.GetDisplay(this.RenderingWindow));

                this.PlatformManager.BindApi(Api.EGL_OPENGL_ES_API);

                var attribs = new Attribs <ConfigAttributes>();

                this.OnConfigureAttributes(attribs);

                var config = this.PlatformManager.ChooseConfigs(attribs, 1).FirstOrDefault();

                if (config == null)
                {
                    throw new InvalidOperationException("Could not find matching configuration");
                }

                this.RenderingContext = this.PlatformManager.CreateContext(config, ContextVersion.OPENGL_ES_2);

                this.RenderingSurface = this.PlatformManager.CreateWindowSurface(config, this.RenderingWindow);

                this.RenderingContext.MakeCurrent(this.RenderingSurface, this.RenderingSurface);

                // graphics device setup
                this.GraphicsDevice = new GraphicsDevice
                {
                    ClearColor = new Vector4(1, 1, 1, 1f),
                    Viewport   = new Rectangle(
                        0,
                        0,
                        this.RenderingWindow.Width,
                        this.RenderingWindow.Height)
                };

                var error = NativeGl.glGetError();

                if (error != NativeGl.GL_NO_ERROR)
                {
                    throw new InvalidOperationException("Error while initializing graphics.");
                }
            }
            catch (PlatformGraphicsException x)
            {
                MessageBox.Show(x.ToString());
                this.ExitGame = true;
            }
        }
示例#7
0
        protected override void Dispose(bool disposing)
        {
            if (this.TextureName != 0)
            {
                var textures = new uint[1];
                textures[0] = this.TextureName;

                NativeGl.glDeleteTextures(1, textures);
            }

            base.Dispose(disposing);
        }
示例#8
0
        public bool Compile()
        {
            NativeGl.glCompileShader(this.ShaderId);

            var success = new[]
            {
                -1
            };

            NativeGl.glGetShaderiv(this.ShaderId, NativeGl.GL_COMPILE_STATUS, success);

            return(success[0] == NativeGl.GL_TRUE);
        }
示例#9
0
        public void BufferData <T>(int size, [In] T[] data, BufferUsage usage) where T : struct
        {
            GCHandle dataHandle = GCHandle.Alloc(data, GCHandleType.Pinned);

            try
            {
                NativeGl.glBufferData((uint)this.Target, (IntPtr)size, dataHandle.AddrOfPinnedObject(), (uint)usage);
            }
            finally
            {
                dataHandle.Free();
            }
        }
示例#10
0
        protected override void Dispose(bool disposing)
        {
            if (this.BufferId > 0)
            {
                NativeGl.glDeleteBuffers(
                    1,
                    new[]
                {
                    this.BufferId
                });
            }

            base.Dispose(disposing);
        }
示例#11
0
        public void ShaderSource(string source)
        {
            unsafe
            {
                int length = source.Length;

                IntPtr[] ptrArray = new IntPtr[1];
                IntPtr   strPtr   = MarshalExtensions.StringToPtrAnsi(source);
                ptrArray[0] = strPtr;

                NativeGl.glShaderSource(this.ShaderId, 1, ptrArray, &length);
                Marshal.FreeHGlobal(strPtr);
            }
        }
示例#12
0
        public Texture CreateFromBytes(byte[] data, int width, int height, uint format, uint type)
        {
            uint textureId;

            uint[] tex = new uint[1];

            NativeGl.glGenTextures(1, tex);

            textureId = tex[0];

            NativeGl.glActiveTexture(NativeGl.GL_TEXTURE0);
            NativeGl.glBindTexture(NativeGl.GL_TEXTURE_2D, textureId);

            var handle = GCHandle.Alloc(data, GCHandleType.Pinned);

            try
            {
                NativeGl.glTexParameterf(NativeGl.GL_TEXTURE_2D, NativeGl.GL_TEXTURE_MIN_FILTER, NativeGl.GL_LINEAR);
                NativeGl.glTexParameterf(NativeGl.GL_TEXTURE_2D, NativeGl.GL_TEXTURE_MAG_FILTER, NativeGl.GL_LINEAR);
                NativeGl.glTexParameterf(NativeGl.GL_TEXTURE_2D, NativeGl.GL_TEXTURE_WRAP_S, NativeGl.GL_CLAMP_TO_EDGE);
                NativeGl.glTexParameterf(NativeGl.GL_TEXTURE_2D, NativeGl.GL_TEXTURE_WRAP_T, NativeGl.GL_CLAMP_TO_EDGE);

                NativeGl.glTexImage2D(
                    NativeGl.GL_TEXTURE_2D,
                    0,
                    (int)format,
                    width,
                    height,
                    0,
                    format,
                    type,
                    handle.AddrOfPinnedObject());
            }
            catch (Exception x)
            {
                NativeGl.glDeleteTextures(1, tex);
                throw;
            }
            finally
            {
                handle.Free();
            }

            NativeGl.glBindTexture(NativeGl.GL_TEXTURE_2D, 0);

            var texture = new Texture(NativeGl.GL_TEXTURE_2D, textureId);

            return(texture);
        }
示例#13
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                foreach (var shader in this.shaders)
                {
                    NativeGl.glDetachShader(this.ProgramId, shader.ShaderId);
                    shader.Dispose();
                }
            }

            if (this.ProgramId != 0)
            {
                NativeGl.glDeleteProgram(this.ProgramId);
            }

            base.Dispose(disposing);
        }
示例#14
0
文件: Game.cs 项目: pekkah/oglesv2cf
        private void Render(double deltaTime)
        {
            this.OnRender(deltaTime);

            this.RenderingSurface.SwapBuffers();

            var errorCode = NativeGl.glGetError();

            if (errorCode == NativeGl.GL_NO_ERROR)
            {
                return;
            }

            var codeString = errorCode.ToString("X");

            Trace.WriteLine(codeString);
            this.ExitGame = true;
        }
示例#15
0
        public bool Link()
        {
            this.OnBeforeLinked();

            NativeGl.glLinkProgram(this.ProgramId);

            var success = new[]
            {
                -1
            };

            NativeGl.glGetProgramiv(this.ProgramId, NativeGl.GL_LINK_STATUS, success);

            var ok = success[0] == NativeGl.GL_TRUE;

            if (ok)
            {
                this.OnLinked();
            }

            return(ok);
        }
示例#16
0
 public void DisableBuffer(uint target)
 {
     NativeGl.glBindBuffer(target, 0);
 }
示例#17
0
 public void BindTexture(TextureTarget textureTarget, uint textureName)
 {
     NativeGl.glBindTexture((uint)textureTarget, textureName);
 }
示例#18
0
 public void Clear(ClearMask mask)
 {
     NativeGl.glClear((uint)mask);
 }
示例#19
0
 public void BindBuffer(DeviceBuffer buffer)
 {
     NativeGl.glBindBuffer((uint)buffer.Target, buffer.BufferId);
 }
示例#20
0
 public void ActivateTextureUnit(TextureUnit textureUnit)
 {
     NativeGl.glActiveTexture((uint)textureUnit);
 }
示例#21
0
 private void UpdateViewport(Rectangle vp)
 {
     NativeGl.glViewport(vp.Left, vp.Top, vp.Width, vp.Height);
 }
示例#22
0
 public void DisableVertexAttribArray(uint indx)
 {
     NativeGl.glDisableVertexAttribArray(indx);
 }
示例#23
0
 public void VertexAttribPointer(uint indx, int size, GlType type, GlBoolean normalized, int stride, IntPtr ptr)
 {
     NativeGl.glVertexAttribPointer(indx, size, (uint)type, (byte)normalized, stride, ptr);
 }
示例#24
0
 public void UseProgram(ShaderProgram program)
 {
     NativeGl.glUseProgram(program.ProgramId);
 }
示例#25
0
 public void EnableVertexAttribArray(uint index)
 {
     NativeGl.glEnableVertexAttribArray(index);
 }
示例#26
0
 public void Disable(Cap cap)
 {
     NativeGl.glDisable((uint)cap);
 }
示例#27
0
 public void Enable(Cap cap)
 {
     NativeGl.glEnable((uint)cap);
 }
示例#28
0
 public void DrawArrays(PrimitiveType mode, int first, int count)
 {
     NativeGl.glDrawArrays((uint)mode, first, count);
 }
示例#29
0
 public void DrawElements(PrimitiveType mode, int count, uint type)
 {
     NativeGl.glDrawElements((uint)mode, count, type, IntPtr.Zero);
 }
示例#30
0
 private void UpdateClearColor(Vector4 color)
 {
     NativeGl.glClearColor(color.X, color.Y, color.Z, color.W);
 }