PixelFarm.DrawingGL.GLBitmap.GetServerTextureId C# (CSharp) Method

GetServerTextureId() private method

private GetServerTextureId ( ) : int
return int
        internal int GetServerTextureId()
        {
            if (this.textureId == 0)
            {
                //server part
                //gen texture 
                GL.GenTextures(1, out this.textureId);
                //bind
                GL.BindTexture(TextureTarget.Texture2D, this.textureId);
                if (nativeImgMem != IntPtr.Zero)
                {
                    GL.TexImage2D(TextureTarget.Texture2D, 0,
                          PixelInternalFormat.Rgba, this.width, this.height, 0,
                          PixelFormat.Rgba, // 
                          PixelType.UnsignedByte, nativeImgMem);
                }
                else if (this.rawBuffer != null)
                {
                    unsafe
                    {
                        //ES20 dose not have BGRA 
                        //so in little-endian machine we need to convert 
                        fixed (byte* bmpScan0 = &this.rawBuffer[0])
                        {
                            GL.TexImage2D(TextureTarget.Texture2D, 0,
                            PixelInternalFormat.Rgba, this.width, this.height, 0,
                            PixelFormat.Rgba, // 
                            PixelType.UnsignedByte, (IntPtr)bmpScan0);
                        }
                    }
                }
                else if (this.rawIntBuffer != null)
                {
                    unsafe
                    {
                        fixed (int* head = &rawIntBuffer[0])
                        {

                            GL.TexImage2D(TextureTarget.Texture2D, 0,
                            PixelInternalFormat.Rgba, this.width, this.height, 0,
                            PixelFormat.Rgba, // 
                            PixelType.UnsignedByte, new IntPtr((void*)head));
                        }
                    }

                }
                else if (this.bmp != null)
                {
                    GL.TexImage2D(TextureTarget.Texture2D, 0,
                           PixelInternalFormat.Rgba, this.width, this.height, 0,
                           PixelFormat.Rgba, // 
                           PixelType.UnsignedByte, bmp.GetNativeImageHandle());
                }
                else
                {
                    //use lazy provider
                    IntPtr bmpScan0 = this.lazyProvider.GetRawBufferHead();
                    GL.TexImage2D(TextureTarget.Texture2D, 0,
                           PixelInternalFormat.Rgba, this.width, this.height, 0,
                           PixelFormat.Rgba,
                           PixelType.UnsignedByte, (IntPtr)bmpScan0);
                    this.lazyProvider.ReleaseBufferHead();
                }
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            }

            return this.textureId;
        }

Usage Example

Ejemplo n.º 1
0
 void UploadGradientLookupTable(GLBitmap bmp)
 {
     //load before use with RenderSubImage
     //-------------------------------------------------------------------------------------
     // Bind the texture...
     GL.ActiveTexture(TextureUnit.Texture0);
     GL.BindTexture(TextureTarget.Texture2D, bmp.GetServerTextureId());
     // Set the texture sampler to texture unit to 0
     s_texture.SetValue(0);
 }
All Usage Examples Of PixelFarm.DrawingGL.GLBitmap::GetServerTextureId