public ESTexture2D(byte[] data, SurfaceFormat pixelFormat, int width, int height, Size size, ALL11 filter) { if (GraphicsDevice.OpenGLESVersion != OpenTK.Graphics.GLContextVersion.Gles2_0) { using(Bitmap bm = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888)) { using (var buffer = ByteBuffer.Wrap(data)) { bm.CopyPixelsFromBuffer(buffer); } InitWithBitmap(bm, filter); } } else { var imagePtr = IntPtr.Zero; try { imagePtr = Marshal.AllocHGlobal (data.Length); Marshal.Copy (data, 0, imagePtr, data.Length); InitWithData(imagePtr, pixelFormat, width, height, size, filter); } finally { Marshal.FreeHGlobal (imagePtr); } } }
internal void GenerateBuffer <T>() where T : struct { All11 bufferUsage = (_bufferUsage == BufferUsage.WriteOnly) ? All11.StaticDraw : All11.DynamicDraw; GL11.GenBuffers(1, out _bufferStore); GL11.BindBuffer(All11.ElementArrayBuffer, _bufferStore); GL11.BufferData <T>(All11.ElementArrayBuffer, (IntPtr)_size, (T[])_buffer, bufferUsage); }
public void SetRenderTargets(params RenderTargetBinding[] renderTargets) { currentRenderTargets = renderTargets; if (currentRenderTargets != null) { // http://www.songho.ca/opengl/gl_fbo.html // create framebuffer GL11.Oes.GenFramebuffers(1, ref framebufferId); GL11.Oes.BindFramebuffer(All11.FramebufferOes, framebufferId); renderBufferIDs = new int[currentRenderTargets.Length]; GL11.Oes.GenRenderbuffers(currentRenderTargets.Length, renderBufferIDs); for (int i = 0; i < currentRenderTargets.Length; i++) { RenderTarget2D target = (RenderTarget2D)currentRenderTargets[0].RenderTarget; // attach the texture to FBO color attachment point GL11.Oes.FramebufferTexture2D(All11.FramebufferOes, All11.ColorAttachment0Oes, All11.Texture2D, target.ID, 0); // create a renderbuffer object to store depth info GL11.Oes.BindRenderbuffer(All11.RenderbufferOes, renderBufferIDs[i]); GL11.Oes.RenderbufferStorage(All11.RenderbufferOes, All11.DepthComponent24Oes, target.Width, target.Height); GL11.Oes.BindRenderbuffer(All11.RenderbufferOes, 0); // attach the renderbuffer to depth attachment point GL11.Oes.FramebufferRenderbuffer(All11.FramebufferOes, All11.DepthAttachmentOes, All11.RenderbufferOes, renderBufferIDs[i]); } All11 status = GL11.Oes.CheckFramebufferStatus(All11.FramebufferOes); if (status != All11.FramebufferCompleteOes) { throw new Exception("Error creating framebuffer: " + status); } //GL.ClearColor (Color4.Transparent); //GL.Clear((int)(All.ColorBufferBit | All.DepthBufferBit)); } }
public static int GetClipPlanex(OpenTK.Graphics.ES11.All plane) { throw new NotImplementedException(); }
public void InitWithData(IntPtr data, SurfaceFormat pixelFormat, int width, int height, Size size, ALL11 filter) { InitWithData(data, pixelFormat, width, height, size, filter, ALL11.Repeat); }
public void InitWithData(IntPtr data, SurfaceFormat pixelFormat, int width, int height, Size size, ALL11 filter, ALL11 wrap) { if (GraphicsDevice.OpenGLESVersion == OpenTK.Graphics.GLContextVersion.Gles2_0) { if (!MathHelper.IsPowerOfTwo(width) || !MathHelper.IsPowerOfTwo(height)) { filter = ALL11.Linear; wrap = ALL11.ClampToEdge; } GL20.GenTextures(1, ref _name); GL20.BindTexture(ALL20.Texture2D, _name); GL20.TexParameter(ALL20.Texture2D, ALL20.TextureMinFilter, (int)filter); GL20.TexParameter(ALL20.Texture2D, ALL20.TextureMagFilter, (int)filter); GL20.TexParameter(ALL20.Texture2D, ALL20.TextureWrapS, (int)wrap); GL20.TexParameter(ALL20.Texture2D, ALL20.TextureWrapT, (int)wrap); switch (pixelFormat) { case SurfaceFormat.Color /*kTexture2DPixelFormat_RGBA8888*/: case SurfaceFormat.Dxt1: case SurfaceFormat.Dxt3: //sz = 4; GL20.TexImage2D(ALL20.Texture2D, 0, (int)ALL20.Rgba, (int)width, (int)height, 0, ALL20.Rgba, ALL20.UnsignedByte, data); break; case SurfaceFormat.Bgra4444 /*kTexture2DPixelFormat_RGBA4444*/: //sz = 2; GL20.TexImage2D(ALL20.Texture2D, 0, (int)ALL20.Rgba, (int)width, (int)height, 0, ALL20.Rgba, ALL20.UnsignedShort4444, data); break; case SurfaceFormat.Bgra5551 /*kTexture2DPixelFormat_RGB5A1*/: //sz = 2; GL20.TexImage2D(ALL20.Texture2D, 0, (int)ALL20.Rgba, (int)width, (int)height, 0, ALL20.Rgba, ALL20.UnsignedShort5551, data); break; case SurfaceFormat.Alpha8 /*kTexture2DPixelFormat_A8*/: //sz = 1; GL20.TexImage2D(ALL20.Texture2D, 0, (int)ALL20.Alpha, (int)width, (int)height, 0, ALL20.Alpha, ALL20.UnsignedByte, data); break; default: throw new NotSupportedException("Texture format"); } } else { GL11.GenTextures(1, ref _name); GL11.BindTexture(ALL11.Texture2D, _name); GL11.TexParameter(ALL11.Texture2D, ALL11.TextureMinFilter, (int)filter); GL11.TexParameter(ALL11.Texture2D, ALL11.TextureMagFilter, (int)filter); GL11.TexParameter(ALL11.Texture2D, ALL11.TextureWrapS, (int)ALL11.ClampToEdge); GL11.TexParameter(ALL11.Texture2D, ALL11.TextureWrapT, (int)ALL11.ClampToEdge); switch (pixelFormat) { case SurfaceFormat.Color /*kTexture2DPixelFormat_RGBA8888*/: case SurfaceFormat.Dxt1: case SurfaceFormat.Dxt3: GL11.TexImage2D(ALL11.Texture2D, 0, (int)ALL11.Rgba, (int)width, (int)height, 0, ALL11.Rgba, ALL11.UnsignedByte, data); break; case SurfaceFormat.Bgra4444 /*kTexture2DPixelFormat_RGBA4444*/: GL11.TexImage2D(ALL11.Texture2D, 0, (int)ALL11.Rgba, (int)width, (int)height, 0, ALL11.Rgba, ALL11.UnsignedShort4444, data); break; case SurfaceFormat.Bgra5551 /*kTexture2DPixelFormat_RGB5A1*/: GL11.TexImage2D(ALL11.Texture2D, 0, (int)ALL11.Rgba, (int)width, (int)height, 0, ALL11.Rgba, ALL11.UnsignedShort5551, data); break; case SurfaceFormat.Alpha8 /*kTexture2DPixelFormat_A8*/: GL11.TexImage2D(ALL11.Texture2D, 0, (int)ALL11.Alpha, (int)width, (int)height, 0, ALL11.Alpha, ALL11.UnsignedByte, data); break; default: throw new NotSupportedException("Texture format"); } } _size = size; _width = width; _height = height; _format = pixelFormat; _maxS = size.Width / (float)_width; _maxT = size.Height / (float)_height; }
public void InitWithBitmap(Bitmap imageSource, ALL11 filter) { // The default wrap mode is Repeat InitWithBitmap(imageSource, filter, ALL11.Repeat); }
public void InitWithBitmap(Bitmap imageSource, ALL11 filter, ALL11 wrap) { //TODO: Android.Opengl.GLUtils.GetInternalFormat() try { _format = SurfaceFormat.Color; if (imageSource.HasAlpha) _format = SurfaceFormat.Color; if (GraphicsDevice.OpenGLESVersion == OpenTK.Graphics.GLContextVersion.Gles2_0) { _width = imageSource.Width; _height = imageSource.Height; // There are rules for npot textures that we must abide by (wrap = ClampToEdge and filter = Nearest or Linear) if (!MathHelper.IsPowerOfTwo(_width) || !MathHelper.IsPowerOfTwo(_height)) { filter = ALL11.Linear; wrap = ALL11.ClampToEdge; } } else { //scale up bitmap to be power of 2 dimensions but dont exceed 1024x1024. //Note: may not have to do this with OpenGL 2+ _width = (int)Math.Pow(2, Math.Min(10, Math.Ceiling(Math.Log10(imageSource.Width) / Math.Log10(2)))); _height = (int)Math.Pow(2, Math.Min(10, Math.Ceiling(Math.Log10(imageSource.Height) / Math.Log10(2)))); } _size.Width = _width; _size.Height = _height; if (GraphicsDevice.OpenGLESVersion == OpenTK.Graphics.GLContextVersion.Gles2_0) { GL20.GenTextures(1, ref _name); } else { GL11.GenTextures(1, ref _name); } if (_name == 0) { _originalBitmap = imageSource; _originalFilter = filter; _originalWrap = wrap; PrimaryThreadLoader.AddToList(this); _textureCreated = false; } else { _originalBitmap = null; _textureCreated = true; using ( Bitmap imagePadded = Bitmap.CreateBitmap(_width, _height, Bitmap.Config.Argb8888) ) { using(Canvas can = new Canvas(imagePadded)) { can.DrawARGB(0, 0, 0, 0); if(AndroidCompatibility.ScaleImageToPowerOf2) can.DrawBitmap(imageSource, new Rect(0, 0, imageSource.Width, imageSource.Height), new Rect(0, 0, _width, _height), null); //Scale to texture else can.DrawBitmap(imageSource, 0, 0, null); if (GraphicsDevice.OpenGLESVersion == OpenTK.Graphics.GLContextVersion.Gles2_0) { GL20.BindTexture(ALL20.Texture2D, _name); GL20.TexParameter(ALL20.Texture2D, ALL20.TextureMinFilter, (int)filter); GL20.TexParameter(ALL20.Texture2D, ALL20.TextureMagFilter, (int)filter); GL20.TexParameter(ALL20.Texture2D, ALL20.TextureWrapS, (int)wrap); GL20.TexParameter(ALL20.Texture2D, ALL20.TextureWrapT, (int)wrap); Android.Opengl.GLUtils.TexImage2D((int)ALL20.Texture2D, 0, imagePadded, 0); // error checking //int errAndroidGL = Android.Opengl.GLES20.GlGetError(); //ALL20 errGenericGL = GL20.GetError(); //if (errAndroidGL != Android.Opengl.GLES20.GlNoError || errGenericGL != ALL20.NoError) // Console.WriteLine(string.Format("OpenGL ES 2.0:\n\tAndroid error: {0,10:X}\n\tGeneric error: {1, 10:X}", errAndroidGL, errGenericGL)); } else { GL11.BindTexture(ALL11.Texture2D, _name); GL11.TexParameter(ALL11.Texture2D, ALL11.TextureMinFilter, (int)filter); GL11.TexParameter(ALL11.Texture2D, ALL11.TextureMagFilter, (int)filter); GL11.TexParameter(ALL11.Texture2D, ALL11.TextureWrapS, (int)wrap); GL11.TexParameter(ALL11.Texture2D, ALL11.TextureWrapT, (int)wrap); GL11.TexParameter(ALL11.Texture2D, ALL11.GenerateMipmap, 1); Android.Opengl.GLUtils.TexImage2D((int)ALL11.Texture2D, 0, imagePadded, 0); } } } } } finally { if (_originalBitmap != imageSource) { // free bitmap imageSource.Dispose(); } } _maxS = _size.Width / (float)_width; _maxT = _size.Height / (float)_height; }
public ESTexture2D(IntPtr data, SurfaceFormat pixelFormat, int width, int height, Size size, ALL11 filter) { InitWithData(data, pixelFormat, width, height, size, filter); }
public ESTexture2D(Bitmap image, ALL11 filter) { InitWithBitmap(image, filter); }
public void SetRenderTargets(params RenderTargetBinding[] renderTargets) { currentRenderTargets = renderTargets; if (currentRenderTargets != null) { // TODO: For speed we need to consider using FBO switching instead // of multiple FBO's if they are the same size. // http://www.songho.ca/opengl/gl_fbo.html // Get the currently bound frame buffer object. On most platforms this just gives 0. GL11.GetInteger(ALL11.FramebufferBindingOes, out originalFbo); frameBufferIDs = new int[currentRenderTargets.Length]; renderBufferIDs = new int[currentRenderTargets.Length]; GL11.Oes.GenRenderbuffers(currentRenderTargets.Length, renderBufferIDs); for (int i = 0; i < currentRenderTargets.Length; i++) { RenderTarget2D target = (RenderTarget2D)currentRenderTargets[i].RenderTarget; // create a renderbuffer object to store depth info GL11.Oes.BindRenderbuffer(ALL11.RenderbufferOes, renderBufferIDs[i]); ClearOptions clearOptions = ClearOptions.Target | ClearOptions.DepthBuffer; switch (target.DepthStencilFormat) { case DepthFormat.Depth16: GL11.Oes.RenderbufferStorage(ALL11.RenderbufferOes, ALL11.DepthComponent16Oes, target.Width, target.Height); break; case DepthFormat.Depth24: GL11.Oes.RenderbufferStorage(ALL11.RenderbufferOes, ALL11.DepthComponent24Oes, target.Width, target.Height); break; case DepthFormat.Depth24Stencil8: GL11.Oes.RenderbufferStorage(ALL11.RenderbufferOes, ALL11.Depth24Stencil8Oes, target.Width, target.Height); GL11.Oes.FramebufferRenderbuffer(ALL11.FramebufferOes, ALL11.StencilAttachmentOes, ALL11.RenderbufferOes, renderBufferIDs[i]); clearOptions = clearOptions | ClearOptions.Stencil; break; default: GL11.Oes.RenderbufferStorage(ALL11.RenderbufferOes, ALL11.DepthComponent24Oes, target.Width, target.Height); break; } // create framebuffer GL11.Oes.GenFramebuffers(1, out frameBufferIDs[i]); GL11.Oes.BindFramebuffer(ALL11.FramebufferOes, frameBufferIDs[i]); // attach the texture to FBO color attachment point GL11.Oes.FramebufferTexture2D(ALL11.FramebufferOes, ALL11.ColorAttachment0Oes, ALL11.Texture2D, target.ID, 0); // attach the renderbuffer to depth attachment point GL11.Oes.FramebufferRenderbuffer(ALL11.FramebufferOes, ALL11.DepthAttachmentOes, ALL11.RenderbufferOes, renderBufferIDs[i]); if (target.RenderTargetUsage == RenderTargetUsage.DiscardContents) { Clear(clearOptions, Color.Transparent, 0, 0); } GL11.Oes.BindRenderbuffer(ALL11.FramebufferOes, originalFbo); } ALL11 status = GL11.Oes.CheckFramebufferStatus(ALL11.FramebufferOes); if (status != ALL11.FramebufferCompleteOes) { throw new Exception("Error creating framebuffer: " + status); } // We need to start saving off the ViewPort and setting the current ViewPort to // the width and height of the texture. Then when we pop off the rendertarget // it needs to be reset. This causes drawing problems if we do not set the viewport. // Makes sense once you follow the flow (hits head on desk) // For an example of this take a look at NetRumble's sample for the BloomPostprocess // Save off the current viewport to be reset later savedViewport = Viewport; // Create a new Viewport Viewport renderTargetViewPort = new Viewport(); // Set the new viewport to the width and height of the render target Texture2D target2 = (Texture2D)currentRenderTargets[0].RenderTarget; renderTargetViewPort.Width = target2.Width; renderTargetViewPort.Height = target2.Height; // now we set our viewport to the new rendertarget viewport just created. Viewport = renderTargetViewPort; } }
public void InitWithBitmap(Bitmap imageSource, ALL11 filter) { //TODO: Android.Opengl.GLUtils.GetInternalFormat() _format = SurfaceFormat.Color; if (imageSource.HasAlpha) _format = SurfaceFormat.Color; if (GraphicsDevice.OpenGLESVersion == OpenTK.Graphics.GLContextVersion.Gles2_0) { _width = imageSource.Width; _height = imageSource.Height; } else { // scale up bitmap to be power of 2 dimensions but dont exceed 1024x1024. // Note: may not have to do this with OpenGL 2+ _width = (int)Math.Pow(2, Math.Min(10, Math.Ceiling(Math.Log10(imageSource.Width) / Math.Log10(2)))); _height = (int)Math.Pow(2, Math.Min(10, Math.Ceiling(Math.Log10(imageSource.Height) / Math.Log10(2)))); } _size.Width = _width; _size.Height = _height; using (Bitmap imagePadded = Bitmap.CreateBitmap(_width, _height, Bitmap.Config.Argb8888)) { Canvas can = new Canvas(imagePadded); can.DrawARGB(0, 0, 0, 0); can.DrawBitmap(imageSource, 0, 0, null); if (GraphicsDevice.OpenGLESVersion == OpenTK.Graphics.GLContextVersion.Gles2_0) { GL11.GenTextures(1, ref _name); GL11.BindTexture(ALL11.Texture2D, _name); GL11.TexParameter(ALL11.Texture2D, ALL11.TextureMinFilter, (int)filter); GL11.TexParameter(ALL11.Texture2D, ALL11.TextureMagFilter, (int)filter); Android.Opengl.GLUtils.TexImage2D((int)ALL11.Texture2D, 0, imagePadded, 0); // free bitmap imageSource.Recycle(); // error checking int errAndroidGL = Android.Opengl.GLES20.GlGetError(); ALL20 errGenericGL = GL20.GetError(); if (errAndroidGL != Android.Opengl.GLES20.GlNoError || errGenericGL != ALL20.NoError) Console.WriteLine(string.Format("OpenGL ES 2.0:\n\tAndroid error: {0,10:X}\n\tGeneric error: {1, 10:X}", errAndroidGL, errGenericGL)); } else { GL20.GenTextures(1, ref _name); GL20.BindTexture(ALL20.Texture2D, _name); GL20.TexParameter(ALL20.Texture2D, ALL20.TextureMinFilter, (int)filter); GL20.TexParameter(ALL20.Texture2D, ALL20.TextureMagFilter, (int)filter); Android.Opengl.GLUtils.TexImage2D((int)ALL20.Texture2D, 0, imagePadded, 0); } } _maxS = _size.Width / (float)_width; _maxT = _size.Height / (float)_height; }
public ESTexture2D(byte[] data, SurfaceFormat pixelFormat, int width, int height, Size size, ALL11 filter) { if (GraphicsDevice.OpenGLESVersion != OpenTK.Graphics.GLContextVersion.Gles2_0) { using (Bitmap bm = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888)) { using (var buffer = ByteBuffer.Wrap(data)) { bm.CopyPixelsFromBuffer(buffer); } InitWithBitmap(bm, filter); } } else { var imagePtr = IntPtr.Zero; try { imagePtr = Marshal.AllocHGlobal(data.Length); Marshal.Copy(data, 0, imagePtr, data.Length); InitWithData(imagePtr, pixelFormat, width, height, size, filter); } finally { Marshal.FreeHGlobal(imagePtr); } } }
public void InitWithBitmap(Bitmap imageSource, ALL11 filter, ALL11 wrap) { //TODO: Android.Opengl.GLUtils.GetInternalFormat() try { _format = SurfaceFormat.Color; if (imageSource.HasAlpha) { _format = SurfaceFormat.Color; } if (GraphicsDevice.OpenGLESVersion == OpenTK.Graphics.GLContextVersion.Gles2_0) { _width = imageSource.Width; _height = imageSource.Height; // There are rules for npot textures that we must abide by (wrap = ClampToEdge and filter = Nearest or Linear) if (!MathHelper.IsPowerOfTwo(_width) || !MathHelper.IsPowerOfTwo(_height)) { filter = ALL11.Linear; wrap = ALL11.ClampToEdge; } } else { //scale up bitmap to be power of 2 dimensions but dont exceed 1024x1024. //Note: may not have to do this with OpenGL 2+ _width = (int)Math.Pow(2, Math.Min(10, Math.Ceiling(Math.Log10(imageSource.Width) / Math.Log10(2)))); _height = (int)Math.Pow(2, Math.Min(10, Math.Ceiling(Math.Log10(imageSource.Height) / Math.Log10(2)))); } _size.Width = _width; _size.Height = _height; if (GraphicsDevice.OpenGLESVersion == OpenTK.Graphics.GLContextVersion.Gles2_0) { GL20.GenTextures(1, ref _name); } else { GL11.GenTextures(1, ref _name); } if (_name == 0) { _originalBitmap = imageSource; _originalFilter = filter; _originalWrap = wrap; PrimaryThreadLoader.AddToList(this); _textureCreated = false; } else { _originalBitmap = null; _textureCreated = true; using ( Bitmap imagePadded = Bitmap.CreateBitmap(_width, _height, Bitmap.Config.Argb8888) ) { using (Canvas can = new Canvas(imagePadded)) { can.DrawARGB(0, 0, 0, 0); if (AndroidCompatibility.ScaleImageToPowerOf2) { can.DrawBitmap(imageSource, new Rect(0, 0, imageSource.Width, imageSource.Height), new Rect(0, 0, _width, _height), null); //Scale to texture } else { can.DrawBitmap(imageSource, 0, 0, null); } if (GraphicsDevice.OpenGLESVersion == OpenTK.Graphics.GLContextVersion.Gles2_0) { GL20.BindTexture(ALL20.Texture2D, _name); GL20.TexParameter(ALL20.Texture2D, ALL20.TextureMinFilter, (int)filter); GL20.TexParameter(ALL20.Texture2D, ALL20.TextureMagFilter, (int)filter); GL20.TexParameter(ALL20.Texture2D, ALL20.TextureWrapS, (int)wrap); GL20.TexParameter(ALL20.Texture2D, ALL20.TextureWrapT, (int)wrap); Android.Opengl.GLUtils.TexImage2D((int)ALL20.Texture2D, 0, imagePadded, 0); // error checking //int errAndroidGL = Android.Opengl.GLES20.GlGetError(); //ALL20 errGenericGL = GL20.GetError(); //if (errAndroidGL != Android.Opengl.GLES20.GlNoError || errGenericGL != ALL20.NoError) // Console.WriteLine(string.Format("OpenGL ES 2.0:\n\tAndroid error: {0,10:X}\n\tGeneric error: {1, 10:X}", errAndroidGL, errGenericGL)); } else { GL11.BindTexture(ALL11.Texture2D, _name); GL11.TexParameter(ALL11.Texture2D, ALL11.TextureMinFilter, (int)filter); GL11.TexParameter(ALL11.Texture2D, ALL11.TextureMagFilter, (int)filter); GL11.TexParameter(ALL11.Texture2D, ALL11.TextureWrapS, (int)wrap); GL11.TexParameter(ALL11.Texture2D, ALL11.TextureWrapT, (int)wrap); GL11.TexParameter(ALL11.Texture2D, ALL11.GenerateMipmap, 1); Android.Opengl.GLUtils.TexImage2D((int)ALL11.Texture2D, 0, imagePadded, 0); } } } } } finally { if (_originalBitmap != imageSource) { // free bitmap imageSource.Dispose(); } } _maxS = _size.Width / (float)_width; _maxT = _size.Height / (float)_height; }
public static int GetClipPlanex(OpenTK.Graphics.ES11.All plane) { throw new BindingsNotRewrittenException(); }
unsafe void GetObjectLabel(OpenTK.Graphics.ES11.All type, UInt32 @object, Int32 bufSize, Int32 *length, String label) { throw new NotSupportedException("Use the overload with strongly typed enumerations and StringBuilder final parameter. This overload is not supported."); }