public static void Cull(All cullMode) { if (_cull != cullMode) { _cull = cullMode; // TODO GL.Enable(_cull); } }
private void InitWithBitmap(Bitmap image, All filter) { BitmapData bitmapData = image.LockBits(new System.Drawing.Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); _format = SurfaceFormat.Color; // when we load a image which is not xnb, the color order is not what the opengl expects InitWithData(bitmapData.Scan0, _format, image.Width, image.Height, new Size(image.Width, image.Height), filter, true); image.UnlockBits(bitmapData); }
private void InitWithData (IntPtr data, SurfaceFormat pixelSurfaceFormat, int width, int height, Size size, All filter, bool invertColorOrdering) { GL.GenTextures (1, out _name); GL.BindTexture (TextureTarget.Texture2D, _name); GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)filter); PixelInternalFormat internalFormat; OpenTK.Graphics.OpenGL.PixelFormat pixelFormat; PixelType pixelType; switch (pixelSurfaceFormat) { case SurfaceFormat.Color /*kTexture2DPixelFormat_RGBA8888*/: case SurfaceFormat.Dxt1: case SurfaceFormat.Dxt3: internalFormat = PixelInternalFormat.Rgba; pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba; pixelType = PixelType.UnsignedByte; break; case SurfaceFormat.Bgra4444 /*kTexture2DPixelFormat_RGBA4444*/: internalFormat = PixelInternalFormat.Rgba; pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba; pixelType = PixelType.UnsignedShort4444; break; case SurfaceFormat.Bgra5551 /*kTexture2DPixelFormat_RGB5A1*/: internalFormat = PixelInternalFormat.Rgba; pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba; pixelType = PixelType.UnsignedShort5551; break; case SurfaceFormat.Alpha8 /*kTexture2DPixelFormat_A8*/: internalFormat = PixelInternalFormat.Alpha; pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Alpha; pixelType = PixelType.UnsignedByte; break; default: throw new NotSupportedException ("Texture format"); ; } if (invertColorOrdering) pixelFormat = InvertColorOrder(internalFormat); GL.TexImage2D (TextureTarget.Texture2D, 0, internalFormat, (int)width, (int)height, 0, pixelFormat, pixelType, data); _size = size; _width = width; _height = height; _format = pixelSurfaceFormat; _maxS = size.Width / (float)width; _maxT = size.Height / (float)height; _pixelData = data; }
public void InitWithData(IntPtr data, SurfaceFormat pixelFormat, int width, int height, Size size, All filter) { GL.GenTextures(1, out _name); GL.BindTexture(TextureTarget.Texture2D, _name); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)filter); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)filter); int sz = 0; switch (pixelFormat) { case SurfaceFormat.Rgba32 /*kTexture2DPixelFormat_RGBA8888*/: case SurfaceFormat.Dxt3: sz = 4; GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)width, (int)height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, data); break; case SurfaceFormat.Bgra4444 /*kTexture2DPixelFormat_RGBA4444*/: sz = 2; GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)width, (int)height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedShort4444, data); break; case SurfaceFormat.Bgra5551 /*kTexture2DPixelFormat_RGB5A1*/: sz = 2; GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)width, (int)height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedShort5551, data); break; case SurfaceFormat.Rgb32 /*kTexture2DPixelFormat_RGB565*/: sz = 2; GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, (int)width, (int)height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgb, PixelType.UnsignedShort565, data); break; case SurfaceFormat.Alpha8 /*kTexture2DPixelFormat_A8*/: sz = 1; GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Alpha, (int)width, (int)height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Alpha, PixelType.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; }
private static void SetTexture2DParameter(TextureParameterName name, All value) { GL.TexParameter(TextureTarget.Texture2D, name, (int)value); }
public ESTexture2D(Bitmap image, All filter) { InitWithBitmap(image, filter); }
public ESTexture2D (IntPtr data, SurfaceFormat pixelFormat, int width, int height, Size size, All filter) { InitWithData(data,pixelFormat,width,height,size, filter); }
internal static extern void GLRenderbufferStorageMultisampleApple(All target, int samples, All internalformat, int width, int height);
internal static extern void GLDiscardFramebufferExt(All target, int numAttachments, [MarshalAs(UnmanagedType.LPArray)] All[] attachments);
internal FramebufferHelper(GraphicsDevice graphicsDevice) { #if IOS if (graphicsDevice._extensions.Contains("GL_EXT_discard_framebuffer")) { this.GLInvalidateFramebuffer = new GLInvalidateFramebufferDelegate(GLDiscardFramebufferExt); this.SupportsInvalidateFramebuffer = true; } if (graphicsDevice._extensions.Contains("GL_APPLE_framebuffer_multisample")) { this.GLRenderbufferStorageMultisample = new GLRenderbufferStorageMultisampleDelegate(GLRenderbufferStorageMultisampleApple); this.GLBlitFramebuffer = new GLBlitFramebufferDelegate(GLBlitFramebufferApple); this.AllReadFramebuffer = AllReadFramebufferApple; this.AllDrawFramebuffer = AllDrawFramebufferApple; } #elif ANDROID // eglGetProcAddress doesn't guarantied returning NULL if the entry point doesn't exist. The returned address *should* be the same for all invalid entry point var invalidFuncPtr = EGLGetProcAddress("InvalidFunctionName"); if (graphicsDevice._extensions.Contains("GL_EXT_discard_framebuffer")) { var glDiscardFramebufferEXTPtr = EGLGetProcAddress("glDiscardFramebufferEXT"); if (glDiscardFramebufferEXTPtr != invalidFuncPtr) { this.GLInvalidateFramebuffer = Marshal.GetDelegateForFunctionPointer<GLInvalidateFramebufferDelegate>(glDiscardFramebufferEXTPtr); this.SupportsInvalidateFramebuffer = true; } } if (graphicsDevice._extensions.Contains("GL_EXT_multisampled_render_to_texture")) { var glRenderbufferStorageMultisampleEXTPtr = EGLGetProcAddress("glRenderbufferStorageMultisampleEXT"); var glFramebufferTexture2DMultisampleEXTPtr = EGLGetProcAddress("glFramebufferTexture2DMultisampleEXT"); if (glRenderbufferStorageMultisampleEXTPtr != invalidFuncPtr && glFramebufferTexture2DMultisampleEXTPtr != invalidFuncPtr) { this.GLRenderbufferStorageMultisample = Marshal.GetDelegateForFunctionPointer<GLRenderbufferStorageMultisampleDelegate>(glRenderbufferStorageMultisampleEXTPtr); this.GLFramebufferTexture2DMultisample = Marshal.GetDelegateForFunctionPointer<GLFramebufferTexture2DMultisampleDelegate>(glFramebufferTexture2DMultisampleEXTPtr); } } else if (graphicsDevice._extensions.Contains("GL_IMG_multisampled_render_to_texture")) { var glRenderbufferStorageMultisampleIMGPtr = EGLGetProcAddress("glRenderbufferStorageMultisampleIMG"); var glFramebufferTexture2DMultisampleIMGPtr = EGLGetProcAddress("glFramebufferTexture2DMultisampleIMG"); if (glRenderbufferStorageMultisampleIMGPtr != invalidFuncPtr && glFramebufferTexture2DMultisampleIMGPtr != invalidFuncPtr) { this.GLRenderbufferStorageMultisample = Marshal.GetDelegateForFunctionPointer<GLRenderbufferStorageMultisampleDelegate>(glRenderbufferStorageMultisampleIMGPtr); this.GLFramebufferTexture2DMultisample = Marshal.GetDelegateForFunctionPointer<GLFramebufferTexture2DMultisampleDelegate>(glFramebufferTexture2DMultisampleIMGPtr); } } else if (graphicsDevice._extensions.Contains("GL_NV_framebuffer_multisample")) { var glRenderbufferStorageMultisampleNVPtr = EGLGetProcAddress("glRenderbufferStorageMultisampleNV"); var glBlitFramebufferNVPtr = EGLGetProcAddress("glBlitFramebufferNV"); if (glRenderbufferStorageMultisampleNVPtr != invalidFuncPtr && glBlitFramebufferNVPtr != invalidFuncPtr) { this.GLRenderbufferStorageMultisample = Marshal.GetDelegateForFunctionPointer<GLRenderbufferStorageMultisampleDelegate>(glRenderbufferStorageMultisampleNVPtr); this.GLBlitFramebuffer = Marshal.GetDelegateForFunctionPointer<GLBlitFramebufferDelegate>(glBlitFramebufferNVPtr); this.AllReadFramebuffer = AllReadFramebufferNV; this.AllDrawFramebuffer = AllDrawFramebufferNV; } } #endif this.SupportsBlitFramebuffer = this.GLBlitFramebuffer != null; }
public ESImage(Bitmap image, float imageScale, All filter) { texture = new ESTexture2D(image,filter); Initialize(imageScale); }
public ESImage(Bitmap image, All filter) { // By default set the scale to 1.0f texture = new ESTexture2D(image,filter); Initialize(1.0f); }
public ESTexture2D (IntPtr data, SurfaceFormat pixelFormat, int width, int height, Size size, All filter) { // XNB color order are already inverted InitWithData (data, pixelFormat, width, height, size, filter, false); }
public void InitWithData(IntPtr data, int dataLength, SurfaceFormat pixelFormat, int width, int height, Size size, All filter) { //GG somehow these become off on NACL size.Width = width; size.Height = height; //NaCl.Debug.print("InitWithData: " + pixelFormat + "," +data+ "," +dataLength+ "," +width+ "," +height+ "," +size+ "," +filter); GL.GenTextures(1, out _name); GL.BindTexture(TextureTarget.Texture2D, _name); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)filter); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)filter); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.ClampToEdge); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.ClampToEdge); switch (pixelFormat) { case SurfaceFormat.Dxt1: // GG EDIT added GL.CompressedTexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.CompressedRgbaS3tcDxt1Ext, (int)width, (int)height, 0, dataLength, data); break; case SurfaceFormat.Dxt3: // GG EDIT added #if NO_DXT35 return; // throw new ContentLoadException("GG TEMPORARILY NOT SUPPORTING DXT3"); #else GL.CompressedTexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.CompressedRgbaS3tcDxt3Ext, (int)width, (int)height, 0, dataLength, data); break; #endif case SurfaceFormat.Dxt5: // GG EDIT added #if NO_DXT35 break;// throw new ContentLoadException("GG TEMPORARILY NOT SUPPORTING DXT5"); #else GL.CompressedTexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.CompressedRgbaS3tcDxt5Ext, (int)width, (int)height, 0, dataLength, data); break; #endif case SurfaceFormat.Color: // GG EDIT using BGRA because that's what uncompressed on-disk textures are stored in GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)width, (int)height, 0, GLPixelFormat.Bgra, PixelType.UnsignedByte, data); break; case SurfaceFormat.Rgba32: // GG EDIT RGBA32 is the code word for "CPU-decompressed DXT" GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)width, (int)height, 0, GLPixelFormat.Rgba, PixelType.UnsignedByte, data); break; case SurfaceFormat.Bgra4444 /*kTexture2DPixelFormat_RGBA4444*/: GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)width, (int)height, 0, GLPixelFormat.Rgba, PixelType.UnsignedShort4444, data); break; case SurfaceFormat.Bgra5551 /*kTexture2DPixelFormat_RGB5A1*/: GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)width, (int)height, 0, GLPixelFormat.Rgba, PixelType.UnsignedShort5551, data); break; case SurfaceFormat.Alpha8 /*kTexture2DPixelFormat_A8*/: GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Alpha, (int)width, (int)height, 0, GLPixelFormat.Alpha, PixelType.UnsignedByte, data); break; default: throw new NotSupportedException("Texture format " + pixelFormat); } _size = size; _width = width; _height = height; _format = pixelFormat; _maxS = size.Width / (float)width; _maxT = size.Height / (float)height; }
public void InitWithBitmap(Bitmap image, All filter) { BitmapData bitmapData = image.LockBits(new System.Drawing.Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); _format = SurfaceFormat.Color; InitWithData(bitmapData.Scan0, _format, image.Width, image.Height, new Size(image.Width, image.Height), filter); image.UnlockBits(bitmapData); }