Vulkan2D
2D renderer written in C using Vulkan and SDL2
Loading...
Searching...
No Matches
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.
VK2DTexture vk2dTextureLoad (const char *filename)
 Loads a texture from a file (png, bmp, jpg, tiff).
VK2DTexture vk2dTextureFrom (const void *data, int size)
 Same as vk2dTextureLoad but it uses a byte buffer instead of pulling from a file.
VK2DTexture vk2dTextureCreate (float w, float h)
 Creates a texture meant as a drawing target - see vk2dRendererSetTarget.
bool vk2dTextureUpdate (VK2DTexture tex, const void *pixels)
 Replaces all pixels of a texture.
bool vk2dTextureUpdateRegion (VK2DTexture tex, const void *pixels, int x, int y, int w, int h)
 Replaces a rectangle of pixels in a texture.
float vk2dTextureWidth (VK2DTexture tex)
 Gets the width in pixels of a texture.
float vk2dTextureHeight (VK2DTexture tex)
 Gets the height in pixels of a texture.
bool vk2dTextureIsTarget (VK2DTexture tex)
 Checks if a texture was created as a target or not.
VK2DImage vk2dTextureGetImage (VK2DTexture tex)
 Returns a texture's internal image.
uint32_t vk2dTextureGetID (VK2DTexture tex)
 Returns a unique ID for this texture.
void vk2dTextureFree (VK2DTexture tex)
 Frees a texture from memory.
bool vk2dTextureCopyPixels (VK2DTexture tex, void *outPixels)
 Reads a texture's pixels back from the GPU.

Detailed Description

Makes managing textures samplers and off-screen rendering simpler.

Author
Paolo Mazzon

Function Documentation

◆ vk2dTextureCopyPixels()

bool vk2dTextureCopyPixels ( VK2DTexture tex,
void * outPixels )

Reads a texture's pixels back from the GPU.

Parameters
texTexture to read, either loaded or a render target
outPixelsBuffer of at least width * height * 4 bytes that receives tightly packed 8-bit RGBA pixels
Returns
Returns true if the pixels were read
Warning
Not thread-safe, and waits for the device queue to go idle.

◆ 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 ( const 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

◆ vk2dTextureUpdate()

bool vk2dTextureUpdate ( VK2DTexture tex,
const void * pixels )

Replaces all pixels of a texture.

Parameters
texTexture loaded from a file, memory or an image; render targets are refused
pixelsTightly packed 8-bit RGBA pixels, width * height * 4 bytes
Returns
Returns true if the pixels were uploaded
Warning
Same rules as vk2dImageUpdate: main thread only, waits for the device queue to go idle, and the new pixels apply to every draw of the frame being recorded.

◆ vk2dTextureUpdateRegion()

bool vk2dTextureUpdateRegion ( VK2DTexture tex,
const void * pixels,
int x,
int y,
int w,
int h )

Replaces a rectangle of pixels in a texture.

Parameters
texTexture loaded from a file, memory or an image; render targets are refused
pixelsTightly packed 8-bit RGBA pixels for the rectangle, w * h * 4 bytes
xLeft edge of the rectangle in pixels
yTop edge of the rectangle in pixels
wWidth of the rectangle in pixels
hHeight of the rectangle in pixels
Returns
Returns true if the pixels were uploaded, false if the texture is a render target or the rectangle does not fit inside it
Warning
Same rules as vk2dImageUpdate.

◆ 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