protected void Initialize() { uint[] bufferIds = new uint[1]; NativeGl.glGenBuffers(1, bufferIds); this.BufferId = bufferIds[0]; }
public void UniformMatrix4Fv(uint location, int count, byte transpose, Matrix4 matrix) { unsafe { float *matrixPtr = &matrix.Row0.X; NativeGl.glUniformMatrix4fv(location, count, transpose, matrixPtr); } }
public string GetInfoLog() { int length; var error = new char[MaxInfologLength]; NativeGl.glGetProgramInfoLog(this.ProgramId, MaxInfologLength, out length, error); return(StringExtensions.GetAnsiString(error, length)); }
public uint GetUniformLocation(string name) { var pname = MarshalExtensions.StringToPtrAnsi(name); var handle = NativeGl.glGetUniformLocation(this.ProgramId, pname); Marshal.FreeHGlobal(pname); return(handle); }
protected override void Dispose(bool disposing) { if (this.ShaderId != 0) { NativeGl.glDeleteShader(this.ShaderId); } base.Dispose(disposing); }
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; } }
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); }
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); }
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(); } }
protected override void Dispose(bool disposing) { if (this.BufferId > 0) { NativeGl.glDeleteBuffers( 1, new[] { this.BufferId }); } base.Dispose(disposing); }
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); } }
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); }
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); }
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; }
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); }
public void DisableBuffer(uint target) { NativeGl.glBindBuffer(target, 0); }
public void BindTexture(TextureTarget textureTarget, uint textureName) { NativeGl.glBindTexture((uint)textureTarget, textureName); }
public void Clear(ClearMask mask) { NativeGl.glClear((uint)mask); }
public void BindBuffer(DeviceBuffer buffer) { NativeGl.glBindBuffer((uint)buffer.Target, buffer.BufferId); }
public void ActivateTextureUnit(TextureUnit textureUnit) { NativeGl.glActiveTexture((uint)textureUnit); }
private void UpdateViewport(Rectangle vp) { NativeGl.glViewport(vp.Left, vp.Top, vp.Width, vp.Height); }
public void DisableVertexAttribArray(uint indx) { NativeGl.glDisableVertexAttribArray(indx); }
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); }
public void UseProgram(ShaderProgram program) { NativeGl.glUseProgram(program.ProgramId); }
public void EnableVertexAttribArray(uint index) { NativeGl.glEnableVertexAttribArray(index); }
public void Disable(Cap cap) { NativeGl.glDisable((uint)cap); }
public void Enable(Cap cap) { NativeGl.glEnable((uint)cap); }
public void DrawArrays(PrimitiveType mode, int first, int count) { NativeGl.glDrawArrays((uint)mode, first, count); }
public void DrawElements(PrimitiveType mode, int count, uint type) { NativeGl.glDrawElements((uint)mode, count, type, IntPtr.Zero); }
private void UpdateClearColor(Vector4 color) { NativeGl.glClearColor(color.X, color.Y, color.Z, color.W); }