-
Notifications
You must be signed in to change notification settings - Fork 4
9. Loading a texture
To maximize performance, renderXF uses its own unmanaged buffers. To make things easier, renderXF accepts both bitmaps and file paths for GLTexture creation.
//Load Texture From a File
GLTexture myTexture = new GLTexture("myTexture.png", MemoryLocation.Heap);
//Load Texture From a Bitmap
GLTexture myTexture = new GLTexture(myBitmap, MemoryLocation.Heap);
During texture loading renderXF allows for bit depth conversion, image flipping and alpha copy.
//Convert Texture To 32bpp During Load:
GLTexture myTexture = new GLTexture("myTexture.png", MemoryLocation.Heap, DuringLoad.ConvertTo32bpp);
//Copy Alpha During Load: (Exception will occur if output texture is 24bpp)
GLTexture myTexture = new GLTexture("myTexture.png", MemoryLocation.Heap, DuringLoad.CopyAlpha);
//Flip Texture During Load:
GLTexture myTexture = new GLTexture("myTexture.png", MemoryLocation.Heap, DuringLoad.Flip);
These options can also be stacked together:
GLTexture myTexture = new GLTexture("myTexture.png", MemoryLocation.Heap, DuringLoad.Flip, DuringLoad.CopyAlpha);
renderXF can store the buffer in the heap, or the stack. Storing the buffer on the stack is experimental and is easily subject to random stack overflow errors. It is recommended to store all buffers in heap memory.
//Buffer allocated in the heap
GLTexture heap_Texture = new GLTexture("myTexture.png", MemoryLocation.Heap);
//Buffer allocated in the stack
GLTexture stackTexture = new GLTexture("myTexture.png", MemoryLocation.Stack);
The only reason this option exists was to test the speed differences. It was determined that there are none.
It is also possible to get the true memory address via the GetAddress() function.
IntPtr addr = myTexture.GetAddress();
//For 24bpp or 32bpp With Effects
byte* fldr = (byte*)myTexture.GetAddress();
//For 32bpp Only
int* iaddr = (int*)myTexture.GetAddress();
This is used for drawing textures to screen from the fragment shader.
GLTextures will self dispose, however this may take up to a few seconds after runtime. To dispose instantly, just call the Dispose() function.
if (myTexture!= null)
myTexture.Dispose();
- Initializing the renderer
- Setting the transform data
- Blitting and clearing the viewport
- Initializing a vertex buffer
- Creating a shader
- Drawing an object
- Screen space shaders
- Blitting bitmaps
- Loading a texture
- Creating a framebuffer
- Displaying a texture