public override void Activate() { if (linked == 0 && !triedToLinkAndFailed) { GL.GetError(); glProgramHandle = GL.CreateProgram(); GLES2Config.GlCheckError(this); #if !AXIOM_NO_GLES2_GLSL_OPTIMIZER if (vertexProgram != null) { string paramStr = vertexProgram.GLSLProgram.GetParameter["use_optimiser"]; if (paramStr == "true" || paramStr.Length == 0) { GLSLESLinkProgramManager.Instance.OptimizeShaderSource(vertexProgram); } } if (vertexProgram != null) { string paramStr = fragmentProgram.GLSLProgram.GetParameter("use_optimiser"); if (paramStr == "true" || paramStr.Length == 0) { GLSLESLinkProgramManager.Instance.OptimizeShaderSource(fragmentProgram); } } #endif this.CompileAndLink(); this.ExtractLayoutQualifiers(); this.BuildGLUniformReferences(); } this._useProgram(); }
protected override void OnRenderFrame(FrameEventArgs e) { GL.ClearColor(Color4.Red); GL.Clear(OpenTK.Graphics.ES20.ClearBufferMask.ColorBufferBit); SwapBuffers(); }
public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) : base(graphicsDevice, width, height, mipMap, preferredFormat) { #if IPHONE if (GraphicsDevice.OpenGLESVersion == MonoTouch.OpenGLES.EAGLRenderingAPI.OpenGLES2) { GL20.GenFramebuffers(1, ref frameBuffer); } else { RenderTargetUsage = usage; DepthStencilFormat = preferredDepthFormat; } #elif ANDROID if (GraphicsDevice.OpenGLESVersion == OpenTK.Graphics.GLContextVersion.Gles2_0) { GL20.GenFramebuffers(1, ref frameBuffer); } else { RenderTargetUsage = usage; DepthStencilFormat = preferredDepthFormat; } #else RenderTargetUsage = usage; DepthStencilFormat = preferredDepthFormat; #endif }
public override int GetAttributeIndex(Graphics.VertexElementSemantic semantic, int index) { int res = customAttribues[(int)semantic - 1, index]; if (res == NullCustomAttributesIndex) { int handle = vertexProgram.GLSLProgram.GLProgramHandle; string attString = GetAttributeSemanticString(semantic); int attrib = GL.GetAttribLocation(handle, attString); GLES2Config.GlCheckError(this); if (attrib == NotFoundCustomAttributesIndex && semantic == VertexElementSemantic.Position) { attrib = GL.GetAttribLocation(handle, "position"); GLES2Config.GlCheckError(this); } if (attrib == NotFoundCustomAttributesIndex) { string attStringWithSemantic = attString + index.ToString(); attrib = GL.GetAttribLocation(handle, attStringWithSemantic); GLES2Config.GlCheckError(this); } customAttribues[(int)semantic - 1, index] = attrib; res = attrib; } return(res); }
public virtual int GetAttributeIndex(VertexElementSemantic semantic, int index) { int res = this.customAttribues[(int)semantic - 1, index]; if (res == NullCustomAttributesIndex) { string attString = this.GetAttributeSemanticString(semantic); int attrib = GL.GetAttribLocation(this.glProgramHandle, attString); GLES2Config.GlCheckError(this); //sadly position is a special case if (attrib == NotFoundCustomAttributesIndex && semantic == VertexElementSemantic.Position) { attrib = GL.GetAttribLocation(this.glProgramHandle, "position"); GLES2Config.GlCheckError(this); } //for uv and other case the index is a part of the name if (attrib == NotFoundCustomAttributesIndex) { string attStringWithSemantic = attString + index.ToString(); attrib = GL.GetAttribLocation(this.glProgramHandle, attStringWithSemantic); GLES2Config.GlCheckError(this); } //update customAttributes with the index we found (or didnt' find) this.customAttribues[(int)semantic - 1, index] = attrib; res = attrib; } return(res); }
protected override void CompileAndLink() { //Compile and attach vertex program if (!vertexProgram.GLSLProgram.Compile(true)) { triedToLinkAndFailed = true; return; } vertexProgram.GLSLProgram.AttachToProgramObject(glProgramHandle); SkeletalAnimationIncluded = vertexProgram.IsSkeletalAnimationIncluded; //Compile and attach fragment program if (!fragmentProgram.GLSLProgram.Compile(true)) { triedToLinkAndFailed = true; return; } fragmentProgram.GLSLProgram.AttachToProgramObject(glProgramHandle); //The link GL.LinkProgram(glProgramHandle); GLES2Config.GlCheckError(this); GL.GetProgram(glProgramHandle, GLenum.LinkStatus, ref linked); GLES2Config.GlCheckError(this); triedToLinkAndFailed = (linked == 0) ? true : false; }
void FlushVertexArray20(int start, int end) { // draw stuff if (start != end) { GL20.DrawElements(All20.Triangles, (end - start) / 2 * 3, All20.UnsignedShort, (IntPtr)((uint)_indexHandle.AddrOfPinnedObject() + (uint)(start / 2 * 3 * sizeof(short)))); } }
protected override void _useProgram() { if (linked != 0) { GL.UseProgram(glProgramHandle); GLES2Config.GlCheckError(this); } }
internal static void GlClearError() { var e = (int)OpenGL.GetError(); if (e != 0) { LogManager.Instance.Write(string.Format("[GLES2] Ignoring error {0} on stack.", e)); } }
public void CheckAndFixInvalidDefaultPrecisionError(string message) { string precisionQualifierErrorString = ": 'Default Precision Qualifier' : invalid type Type for default precision qualifier can be only float or int"; string[] los = source.Split('\n'); var linesOfSource = new List <string>(los); if (message.Contains(precisionQualifierErrorString)) { LogManager.Instance.Write("Fixing invalid type Type fore default precision qualifier by deleting bad lines then re-compiling"); //remove releavant lines from source string[] errors = message.Split('\n'); //going from the end so when we delete a line the numbers of the lines beforew will not change for (int i = errors.Length - 1; i >= 0; i--) { string curError = errors[i]; int foundPos = curError.IndexOf(precisionQualifierErrorString); if (foundPos != -1) { string lineNumber = curError.Substring(0, foundPos); int posOfStartOfNumber = lineNumber.LastIndexOf(':'); if (posOfStartOfNumber != -1) { lineNumber = lineNumber.Substring(posOfStartOfNumber + 1, lineNumber.Length - (posOfStartOfNumber + 1)); int numLine = -1; if (int.TryParse(lineNumber, out numLine)) { linesOfSource.RemoveAt(numLine - 1); } } } } //rebuild source var newSource = new StringBuilder(); for (int i = 0; i < linesOfSource.Count; i++) { newSource.AppendLine(linesOfSource[i]); } source = newSource.ToString(); int r = 0; var sourceArray = new string[] { source }; GL.ShaderSource(this.glShaderHandle, 1, sourceArray, ref r); GLES2Config.GlCheckError(this); if (this.Compile()) { LogManager.Instance.Write("The removing of the lines fixed the invalid type Type for default precision qualifier error."); } else { LogManager.Instance.Write("The removing of the lines didn't help."); } } }
public void Bind() { #if !AXIOM_NO_GLES2_VAO_SUPPORT #if GL_OES_vertex_array_object LogManager.Instance.Write("[GLES2] Binding VAO {0}.", _vao); GL.BindVertexArraysOES(1, &_vao); GLES2Config.CheckError(this); #endif #endif }
private void SetUniformMatrix4(int location, bool transpose, ref Matrix4 matrix) { unsafe { fixed(float *matrix_ptr = &matrix.Row0.X) { GL20.UniformMatrix4(location, 1, transpose, matrix_ptr); } } }
private void BuildMipmaps(PixelBox data) { int width, height, logW, logH, level; PixelBox scaled = data; scaled.Data = data.Data; scaled.Left = data.Left; scaled.Right = data.Right; scaled.Top = data.Top; scaled.Bottom = data.Bottom; scaled.Front = data.Front; scaled.Back = data.Back; width = data.Width; height = data.Height; logW = (int)System.Math.Log(width); logH = (int)System.Math.Log(height); level = (logW > logH ? logW : logH); for (int mip = 0; mip < level; mip++) { All glFormat = GLES2PixelUtil.GetGLOriginFormat(scaled.Format); All dataType = GLES2PixelUtil.GetGLOriginDataType(scaled.Format); GL.TexImage2D(this.faceTarget, mip, (int)glFormat, width, height, 0, glFormat, dataType, scaled.Data.Pin()); GLES2Config.GlCheckError(this); if (mip != 0) { scaled.Data = null; } if (width > 1) { width /= 2; } if (height > 1) { height /= 2; } int sizeInBytes = PixelUtil.GetMemorySize(width, height, 1, data.Format); scaled = new PixelBox(width, height, 1, data.Format); scaled.Data = BufferBase.Wrap(new byte[sizeInBytes]); Image.Scale(data, scaled, ImageFilter.Linear); } //Delete the scaled data for the last level if (level > 0) { scaled.Data = null; } }
public void Present() { if (openGLESVersion == GLContextVersion.Gles2_0) { GL20.Flush(); } else { GL11.Flush(); } }
private void End20() { // Disable Blending by default = BlendState.Opaque GL20.Disable(All20.Blend); // set the blend mode if (_blendState == BlendState.NonPremultiplied) { GL20.BlendFunc(All20.One, All20.OneMinusSrcAlpha); GL20.Enable(All20.Blend); GL20.BlendEquation(All20.FuncAdd); } if (_blendState == BlendState.AlphaBlend) { GL20.BlendFunc(All20.SrcAlpha, All20.OneMinusSrcAlpha); GL20.Enable(All20.Blend); GL20.BlendEquation(All20.FuncAdd); } if (_blendState == BlendState.Additive) { GL20.BlendFunc(All20.SrcAlpha, All20.One); GL20.Enable(All20.Blend); GL20.BlendEquation(All20.FuncAdd); } //CullMode GL20.FrontFace(All20.Cw); GL20.Enable(All20.CullFace); GL20.Viewport(0, 0, this.graphicsDevice.Viewport.Width, this.graphicsDevice.Viewport.Height); // configura el viewport GL20.UseProgram(program); if (GraphicsDevice.defaultFramebuffer) { GL20.CullFace(All20.Back); SetUniformMatrix4(uniformWVP, false, ref matWVPScreen); } else { GL20.CullFace(All20.Front); SetUniformMatrix4(uniformWVP, false, ref matWVPFramebuffer); GL20.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL20.Clear((int)(All20.ColorBufferBit | All20.DepthBufferBit)); } _batcher.DrawBatch20(_sortMode); GL20.Disable(All20.Texture2D); }
public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount, RenderTargetUsage usage) : base(graphicsDevice, width, height, false, format) { if (GraphicsDevice.openGLESVersion == MonoTouch.OpenGLES.EAGLRenderingAPI.OpenGLES2) { GL20.GenFramebuffers(1, ref framebuffer); } else { allocateOpenGLTexture(); } }
public static void GlCheckError(object caller, bool raiseException) #endif { var e = OpenGL.GetError(); if (e != OpenTK.Graphics.ES20.All.None) { var msg = string.Format("[GLES2] Error {0}: {1} from {2}", (int)e, e, caller.ToString()); LogManager.Instance.Write(msg); if (raiseException) { throw new AxiomException(msg); } } }
public void Clear(Color color) { Vector4 vector = color.ToEAGLColor(); if (openGLESVersion == GLContextVersion.Gles2_0) { GL20.ClearColor(vector.X, vector.Y, vector.Z, vector.W); GL20.Clear((uint)All20.ColorBufferBit); } else { GL11.ClearColor(vector.X, vector.Y, vector.Z, vector.W); GL11.Clear((uint)All11.ColorBufferBit); } }
void FlushVertexArray20(int start, int end) { // draw stuff if (start != end) { GL20.DrawElements(All20.Triangles, (end - start) / 2 * 3, All20.UnsignedShort, (IntPtr)((uint)_indexHandle.AddrOfPinnedObject() + (uint)(start / 2 * 3 * sizeof(short)))); //int errAndroidGL = Android.Opengl.GLES20.GlGetError(); //All20 errGenericGL = GL20.GetError(); //if (errAndroidGL != Android.Opengl.GLES20.GlNoError || errGenericGL != All20.NoError) //{ // string error = string.Format("OpenGL-ES 2.0:\n\tAndroid:{0,10:X}\n\tGeneric:{0, 10:X}", ((Android.Opengl.GLES20)errAndroidGL), (All20)errGenericGL); // Console.WriteLine(error); //} } }
protected override void UnloadHighLevelImpl() { if (IsSupported) { GL.DeleteShader(this.glShaderHandle); GLES2Config.GlCheckError(this); // TODO : Root.Instance.RenderSystem.Capabilities.HasCapability(Capabilities.SeperateShaderObjects)) if (false) { GL.DeleteProgram(this.glProgramHandle); GLES2Config.GlCheckError(this); } } }
public void Clear(ClearOptions options, Vector4 color, float depth, int stencil) { if (openGLESVersion == GLContextVersion.Gles2_0) { GL20.ClearColor(color.X, color.Y, color.Z, color.W); GL20.ClearDepth(depth); GL20.ClearStencil(stencil); GL20.Clear((uint)(All20.ColorBufferBit | All20.DepthBufferBit | All20.StencilBufferBit)); } else { GL11.ClearColor(color.X, color.Y, color.Z, color.W); GL11.ClearDepth(depth); GL11.ClearStencil(stencil); GL11.Clear((uint)(All11.ColorBufferBit | All11.DepthBufferBit | All11.StencilBufferBit)); } }
protected override void dispose(bool disposeManagedResources) { if (!IsDisposed) { if (disposeManagedResources) { } #if !AXIOM_NO_GLES2_VAO_SUPPORT #if GL_OES_vertex_array_object LogManager.Instance.Write("[GLES2] Deleting VAO {0}.", _vao); GL.DeleteVertexArraysOES(1, &_vao); GLES2Config.CheckError(this); #endif #endif } base.dispose(disposeManagedResources); }
public GLES2VertexDeclaration() { _vao = 0; #if !AXIOM_NO_GLES2_VAO_SUPPORT #if GL_OES_vertex_array_object GL.GenVertexArraysOES(1, &_vao); LogManager.Instance.Write("[GLES2] Created VAO {0}.", _vao); GLES2Config.CheckError(this); if (_vao != 0) { throw new AxiomException("[GLES2] Cannot create GL ES Vertex Array Object"); } #endif #endif }
public void ForceRetryToCreateTexture() { if (_name != 0) { if (GraphicsDevice.OpenGLESVersion == OpenTK.Graphics.GLContextVersion.Gles2_0) { GL20.DeleteTextures(1, ref _name); } else { GL11.DeleteTextures(1, ref _name); } _name = 0; } _textureCreated = false; RetryToCreateTexture(); }
/// <summary> /// Build the shaders /// </summary> private int LoadShader(All20 type, string source) { int shader = GL20.CreateShader(type); if (shader == 0) { throw new InvalidOperationException("Unable to create shader"); } // Load the shader source int length = 0; GL20.ShaderSource(shader, 1, new string[] { source }, new int[] { source.Length }); // Compile the shader GL20.CompileShader(shader); int[] compiled = new int[1]; GL20.GetShader(shader, All20.CompileStatus, compiled); if (compiled[0] == 0) { length = 0; GL20.GetShader(shader, All20.InfoLogLength, ref length); var log = new StringBuilder(length); GL20.GetShaderInfoLog(shader, length, ref length, log); Console.WriteLine("GL2" + log.ToString()); GL20.DeleteShader(shader); //length = 0; //GL20.GetShader(shader, All20.InfoLogLength, ref length); //if (length > 0) //{ // var log = new StringBuilder(length); // GL20.GetShaderInfoLog(shader, length, ref length, log); // Console.WriteLine("GL2" + log.ToString()); //} //GL20.DeleteShader(shader); throw new InvalidOperationException("Unable to compile shader of type : " + type.ToString()); } return(shader); }
public void Dispose() { if (_originalBitmap != null) { _originalBitmap.Dispose(); _originalBitmap = null; } if (_name != 0) { if (GraphicsDevice.OpenGLESVersion == OpenTK.Graphics.GLContextVersion.Gles2_0) { GL20.DeleteTextures(1, ref _name); } else { GL11.DeleteTextures(1, ref _name); } } }
public void SetRenderTargetGL20(RenderTarget2D rendertarget) { if (rendertarget == null) { GL20.BindFramebuffer(All20.Framebuffer, framebufferScreen); defaultFramebuffer = true; } else { GL20.BindFramebuffer(All20.Framebuffer, rendertarget.framebuffer); GL20.FramebufferTexture2D(All20.Framebuffer, All20.ColorAttachment0, All20.Texture2D, rendertarget.ID, 0); All20 status = GL20.CheckFramebufferStatus(All20.Framebuffer); if (status != All20.FramebufferComplete) { throw new Exception("Error creating framebuffer: " + status); } defaultFramebuffer = false; } }
public override void UpdatePassIterationUniforms(Graphics.GpuProgramParameters parms) { if (parms.HasPassIterationNumber) { int index = parms.PassIterationNumberIndex; foreach (var currentUniform in glUniformReferences) { if (index == currentUniform.ConstantDef.PhysicalIndex) { unsafe { GL.Uniform1(currentUniform.Location, 1, parms.GetFloatPointer(index).Pointer.ToFloatPointer()); GLES2Config.GlCheckError(this); //There will only be one multipass entry return; } } } } }
public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount, RenderTargetUsage usage) : base(graphicsDevice, width, height, false, format) { //if (GraphicsDevice.openGLESVersion == MonoTouch.OpenGLES.EAGLRenderingAPI.OpenGLES2) if (GraphicsDevice.openGLESVersion == GLContextVersion.Gles2_0) { GL20.GenFramebuffers(1, ref framebuffer); //GL20.GenTextures(1, ref framebuffer); //GL20.TexImage2D(All20.Texture2D, 0, (int)All20.Rgba, width, height, 100, All20.Rgba, All20.UnsignedByte, IntPtr.Zero); //Android.Opengl.GLES20.Frame //FIX:Tamaño del Framebuffer; //GL20.TexImage2D(All20.Texture2D, 0, (int)All20.Rgba, width, height, 0, All20.Rgba, All20.UnsignedByte, IntPtr.Zero); } else { allocateOpenGLTexture(); } }
public GLES2RenderBuffer(All format, int width, int height, int numSamples) : base(width, height, 1, GLES2PixelUtil.GetClosestAxiomFormat(format, (All)PixelFormat.A8R8G8B8), BufferUsage.WriteOnly) { GlInternalFormat = format; //Genearte renderbuffer GL.GenRenderbuffers(1, ref this.renderBufferID); GLES2Config.GlCheckError(this); //Bind it to FBO GL.BindRenderbuffer(All.Renderbuffer, this.renderBufferID); GLES2Config.GlCheckError(this); //Allocate storage for depth buffer if (numSamples > 0) { } else { GL.RenderbufferStorage(All.Renderbuffer, format, width, height); GLES2Config.GlCheckError(this); } }