Vulkan2D
2D renderer written in C using Vulkan and SDL2
Texture.h File Reference

Makes managing textures samplers and off-screen rendering simpler. More...

#include <vulkan/vulkan.h>
#include "VK2D/Structs.h"
Include dependency graph for Texture.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

VK2DTexture vk2dTextureLoadFromImage (VK2DImage image)
 Creates a texture from an image. More...
 
VK2DTexture vk2dTextureLoad (const char *filename)
 Loads a texture from a file (png, bmp, jpg, tiff) More...
 
VK2DTexture vk2dTextureFrom (void *data, int size)
 Same as vk2dTextureLoad but it uses a byte buffer instead of pulling from a file. More...
 
VK2DTexture vk2dTextureCreate (float w, float h)
 Creates a texture meant as a drawing target - see vk2dRendererSetTarget More...
 
float vk2dTextureWidth (VK2DTexture tex)
 Gets the width in pixels of a texture. More...
 
float vk2dTextureHeight (VK2DTexture tex)
 Gets the height in pixels of a texture. More...
 
bool vk2dTextureIsTarget (VK2DTexture tex)
 Checks if a texture was created as a target or not. More...
 
VK2DImage vk2dTextureGetImage (VK2DTexture tex)
 Returns a texture's internal image. More...
 
uint32_t vk2dTextureGetID (VK2DTexture tex)
 Returns a unique ID for this texture. More...
 
void vk2dTextureFree (VK2DTexture tex)
 Frees a texture from memory. More...
 

Detailed Description

Makes managing textures samplers and off-screen rendering simpler.

Author
Paolo Mazzon

Function Documentation

◆ vk2dTextureCreate()

VK2DTexture vk2dTextureCreate ( float  w,
float  h 
)

Creates a texture meant as a drawing target - see vk2dRendererSetTarget

Parameters
wWidth of the texture
hHeight of the texture
Returns
Returns a new texture or NULL if it failed
Warning
If you do not completely fill the created texture (ie, with something like vk2dRendererEmpty or vk2dRendererClear) before you draw this texture it will cause crashes on certain hardware.

◆ vk2dTextureFree()

void vk2dTextureFree ( VK2DTexture  tex)

Frees a texture from memory.

Parameters
texTexture to free

◆ vk2dTextureFrom()

VK2DTexture vk2dTextureFrom ( void *  data,
int  size 
)

Same as vk2dTextureLoad but it uses a byte buffer instead of pulling from a file.

Parameters
dataPointer to the image data, either png, bmp, jpg, or tiff
sizeSize in bytes of the data buffer
Returns
Returns a new texture or NULL if it failed
Warning
Textures created with this function are NOT valid render targets

◆ vk2dTextureGetID()

uint32_t vk2dTextureGetID ( VK2DTexture  tex)

Returns a unique ID for this texture.

Parameters
texTexture to get the id of
Returns
Returns a unique uint32_t ID for this texture, used for sprite batching/user shaders

This function is thread-safe.

◆ vk2dTextureGetImage()

VK2DImage vk2dTextureGetImage ( VK2DTexture  tex)

Returns a texture's internal image.

Parameters
texTexture to check
Returns
Returns the texture's image

◆ vk2dTextureHeight()

float vk2dTextureHeight ( VK2DTexture  tex)

Gets the height in pixels of a texture.

Parameters
texTexture to get the height from
Returns
Returns the height in pixels

◆ vk2dTextureIsTarget()

bool vk2dTextureIsTarget ( VK2DTexture  tex)

Checks if a texture was created as a target or not.

Parameters
texTexture to check
Returns
Returns true if its a valid target, false otherwise

◆ vk2dTextureLoad()

VK2DTexture vk2dTextureLoad ( const char *  filename)

Loads a texture from a file (png, bmp, jpg, tiff)

Parameters
filenameFile to load
Returns
Returns a new texture or NULL if it failed
Warning
Textures created with this function are NOT valid render targets

◆ vk2dTextureLoadFromImage()

VK2DTexture vk2dTextureLoadFromImage ( VK2DImage  image)

Creates a texture from an image.

Parameters
imageImage to use
Returns
Returns a new texture or NULL if it failed
Warning
Textures created with this function are NOT valid render targets

◆ vk2dTextureWidth()

float vk2dTextureWidth ( VK2DTexture  tex)

Gets the width in pixels of a texture.

Parameters
texTexture to get the width from
Returns
Returns the width in pixels