Texture update functions.
This commit is contained in:
116
API.md
116
API.md
@@ -2123,7 +2123,7 @@ Get collision rectangle for two rectangles collision
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Textures - Load
|
## Textures - Image Loading
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -2180,51 +2180,6 @@ Export image as code file defining an array of bytes, returns true on success
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
> texture = RL_LoadTexture( string fileName )
|
|
||||||
|
|
||||||
Load texture from file into GPU memory ( VRAM )
|
|
||||||
|
|
||||||
- Failure return -1
|
|
||||||
- Success return int
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
> texture = RL_LoadTextureFromImage( Image image )
|
|
||||||
|
|
||||||
Load texture from image data
|
|
||||||
|
|
||||||
- Failure return -1
|
|
||||||
- Success return int
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
> success = RL_UnloadTexture( Texture2D texture )
|
|
||||||
|
|
||||||
Unload texture from GPU memory ( VRAM )
|
|
||||||
|
|
||||||
- Failure return false
|
|
||||||
- Success return true
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
> renderTexture = RL_LoadRenderTexture( Vector2 size )
|
|
||||||
|
|
||||||
Load texture for rendering ( framebuffer )
|
|
||||||
|
|
||||||
- Failure return -1
|
|
||||||
- Success return int
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
> success = RL_UnloadRenderTexture( RenderTexture2D target )
|
|
||||||
|
|
||||||
Unload render texture from GPU memory ( VRAM )
|
|
||||||
|
|
||||||
- Failure return false
|
|
||||||
- Success return true
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Textures - Image Generation
|
## Textures - Image Generation
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -2664,6 +2619,75 @@ Get image data format ( PixelFormat type )
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Textures - Texture Loading
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
> texture = RL_LoadTexture( string fileName )
|
||||||
|
|
||||||
|
Load texture from file into GPU memory ( VRAM )
|
||||||
|
|
||||||
|
- Failure return -1
|
||||||
|
- Success return int
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
> texture = RL_LoadTextureFromImage( Image image )
|
||||||
|
|
||||||
|
Load texture from image data
|
||||||
|
|
||||||
|
- Failure return -1
|
||||||
|
- Success return int
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
> success = RL_UnloadTexture( Texture2D texture )
|
||||||
|
|
||||||
|
Unload texture from GPU memory ( VRAM )
|
||||||
|
|
||||||
|
- Failure return false
|
||||||
|
- Success return true
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
> renderTexture = RL_LoadRenderTexture( Vector2 size )
|
||||||
|
|
||||||
|
Load texture for rendering ( framebuffer )
|
||||||
|
|
||||||
|
- Failure return -1
|
||||||
|
- Success return int
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
> success = RL_UnloadRenderTexture( RenderTexture2D target )
|
||||||
|
|
||||||
|
Unload render texture from GPU memory ( VRAM )
|
||||||
|
|
||||||
|
- Failure return false
|
||||||
|
- Success return true
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
> success = RL_UpdateTexture( Texture2D texture, int pixels{ {} } )
|
||||||
|
|
||||||
|
Update GPU texture with new data
|
||||||
|
NOTE! Should be TEXTURE_SOURCE_TEXTURE. Pixel should be in format { { 255, 255, 255, 255 }... } depending on the pixel format
|
||||||
|
|
||||||
|
- Failure return false
|
||||||
|
- Success return true
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
> success = RL_UpdateTextureRec( Texture2D texture, Rectangle rec, int pixels{ {} } )
|
||||||
|
|
||||||
|
Update GPU texture rectangle with new data
|
||||||
|
NOTE! Should be TEXTURE_SOURCE_TEXTURE. Pixel should be in format { { 255, 255, 255, 255 }... } depending on the pixel format
|
||||||
|
|
||||||
|
- Failure return false
|
||||||
|
- Success return true
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Textures - Texture Drawing
|
## Textures - Texture Drawing
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ List of some MISSING features that are planned to be included. For specific func
|
|||||||
|
|
||||||
* Core
|
* Core
|
||||||
* VR stereo config functions for VR simulator
|
* VR stereo config functions for VR simulator
|
||||||
* Textures
|
|
||||||
* Texture update functions
|
|
||||||
* Audio
|
* Audio
|
||||||
* Wave
|
* Wave
|
||||||
* AudioStream management functions
|
* AudioStream management functions
|
||||||
|
|||||||
@@ -8,18 +8,13 @@ bool validTexture( size_t id );
|
|||||||
bool validRenderTexture( size_t id );
|
bool validRenderTexture( size_t id );
|
||||||
bool validSourceTexture( size_t id );
|
bool validSourceTexture( size_t id );
|
||||||
Texture2D* texturesGetSourceTexture( size_t index );
|
Texture2D* texturesGetSourceTexture( size_t index );
|
||||||
/* File. */
|
/* Image Loading. */
|
||||||
int ltexturesLoadImage( lua_State *L );
|
int ltexturesLoadImage( lua_State *L );
|
||||||
int ltexturesLoadImageFromTexture( lua_State *L );
|
int ltexturesLoadImageFromTexture( lua_State *L );
|
||||||
int ltexturesLoadImageFromScreen( lua_State *L );
|
int ltexturesLoadImageFromScreen( lua_State *L );
|
||||||
int ltexturesUnloadImage( lua_State *L );
|
int ltexturesUnloadImage( lua_State *L );
|
||||||
int ltexturesExportImage( lua_State *L );
|
int ltexturesExportImage( lua_State *L );
|
||||||
int ltexturesExportImageAsCode( lua_State *L );
|
int ltexturesExportImageAsCode( lua_State *L );
|
||||||
int ltexturesLoadTexture( lua_State *L );
|
|
||||||
int ltexturesLoadTextureFromImage( lua_State *L );
|
|
||||||
int ltexturesUnloadTexture( lua_State *L );
|
|
||||||
int ltexturesLoadRenderTexture( lua_State *L );
|
|
||||||
int ltexturesUnloadRenderTexture( lua_State *L );
|
|
||||||
/* Image Generation. */
|
/* Image Generation. */
|
||||||
int ltexturesGenImageColor( lua_State *L );
|
int ltexturesGenImageColor( lua_State *L );
|
||||||
int ltexturesGenImageGradientV( lua_State *L );
|
int ltexturesGenImageGradientV( lua_State *L );
|
||||||
@@ -71,6 +66,14 @@ int ltexturesImageDrawTextEx( lua_State *L );
|
|||||||
int ltexturesGetImageSize( lua_State *L );
|
int ltexturesGetImageSize( lua_State *L );
|
||||||
int ltexturesGetImageMipmaps( lua_State *L );
|
int ltexturesGetImageMipmaps( lua_State *L );
|
||||||
int ltexturesGetImageFormat( lua_State *L );
|
int ltexturesGetImageFormat( lua_State *L );
|
||||||
|
/* Texture Loading. */
|
||||||
|
int ltexturesLoadTexture( lua_State *L );
|
||||||
|
int ltexturesLoadTextureFromImage( lua_State *L );
|
||||||
|
int ltexturesUnloadTexture( lua_State *L );
|
||||||
|
int ltexturesLoadRenderTexture( lua_State *L );
|
||||||
|
int ltexturesUnloadRenderTexture( lua_State *L );
|
||||||
|
int ltexturesUpdateTexture( lua_State *L );
|
||||||
|
int ltexturesUpdateTextureRec( lua_State *L );
|
||||||
/* Texture Drawing. */
|
/* Texture Drawing. */
|
||||||
int ltexturesDrawTexture( lua_State *L );
|
int ltexturesDrawTexture( lua_State *L );
|
||||||
int ltexturesDrawTextureRec( lua_State *L );
|
int ltexturesDrawTextureRec( lua_State *L );
|
||||||
|
|||||||
@@ -651,18 +651,13 @@ void luaRegister() {
|
|||||||
lua_register( L, "RL_GetCollisionRec", lshapesGetCollisionRec );
|
lua_register( L, "RL_GetCollisionRec", lshapesGetCollisionRec );
|
||||||
|
|
||||||
/* Textures. */
|
/* Textures. */
|
||||||
/* File. */
|
/* Image Loading. */
|
||||||
lua_register( L, "RL_LoadImage", ltexturesLoadImage );
|
lua_register( L, "RL_LoadImage", ltexturesLoadImage );
|
||||||
lua_register( L, "RL_LoadImageFromTexture", ltexturesLoadImageFromTexture );
|
lua_register( L, "RL_LoadImageFromTexture", ltexturesLoadImageFromTexture );
|
||||||
lua_register( L, "RL_LoadImageFromScreen", ltexturesLoadImageFromScreen );
|
lua_register( L, "RL_LoadImageFromScreen", ltexturesLoadImageFromScreen );
|
||||||
lua_register( L, "RL_UnloadImage", ltexturesUnloadImage );
|
lua_register( L, "RL_UnloadImage", ltexturesUnloadImage );
|
||||||
lua_register( L, "RL_ExportImage", ltexturesExportImage );
|
lua_register( L, "RL_ExportImage", ltexturesExportImage );
|
||||||
lua_register( L, "RL_ExportImageAsCode", ltexturesExportImageAsCode );
|
lua_register( L, "RL_ExportImageAsCode", ltexturesExportImageAsCode );
|
||||||
lua_register( L, "RL_LoadTexture", ltexturesLoadTexture );
|
|
||||||
lua_register( L, "RL_LoadTextureFromImage", ltexturesLoadTextureFromImage );
|
|
||||||
lua_register( L, "RL_UnloadTexture", ltexturesUnloadTexture );
|
|
||||||
lua_register( L, "RL_LoadRenderTexture", ltexturesLoadRenderTexture );
|
|
||||||
lua_register( L, "RL_UnloadRenderTexture", ltexturesUnloadRenderTexture );
|
|
||||||
/* Image Generation. */
|
/* Image Generation. */
|
||||||
lua_register( L, "RL_GenImageColor", ltexturesGenImageColor );
|
lua_register( L, "RL_GenImageColor", ltexturesGenImageColor );
|
||||||
lua_register( L, "RL_GenImageGradientV", ltexturesGenImageGradientV );
|
lua_register( L, "RL_GenImageGradientV", ltexturesGenImageGradientV );
|
||||||
@@ -714,6 +709,14 @@ void luaRegister() {
|
|||||||
lua_register( L, "RL_GetImageSize", ltexturesGetImageSize );
|
lua_register( L, "RL_GetImageSize", ltexturesGetImageSize );
|
||||||
lua_register( L, "RL_GetImageMipmaps", ltexturesGetImageMipmaps );
|
lua_register( L, "RL_GetImageMipmaps", ltexturesGetImageMipmaps );
|
||||||
lua_register( L, "RL_GetImageFormat", ltexturesGetImageFormat );
|
lua_register( L, "RL_GetImageFormat", ltexturesGetImageFormat );
|
||||||
|
/* Texture Loading. */
|
||||||
|
lua_register( L, "RL_LoadTexture", ltexturesLoadTexture );
|
||||||
|
lua_register( L, "RL_LoadTextureFromImage", ltexturesLoadTextureFromImage );
|
||||||
|
lua_register( L, "RL_UnloadTexture", ltexturesUnloadTexture );
|
||||||
|
lua_register( L, "RL_LoadRenderTexture", ltexturesLoadRenderTexture );
|
||||||
|
lua_register( L, "RL_UnloadRenderTexture", ltexturesUnloadRenderTexture );
|
||||||
|
lua_register( L, "RL_UpdateTexture", ltexturesUpdateTexture );
|
||||||
|
lua_register( L, "RL_UpdateTextureRec", ltexturesUpdateTextureRec );
|
||||||
/* Texture Drawing. */
|
/* Texture Drawing. */
|
||||||
lua_register( L, "RL_DrawTexture", ltexturesDrawTexture );
|
lua_register( L, "RL_DrawTexture", ltexturesDrawTexture );
|
||||||
lua_register( L, "RL_DrawTextureRec", ltexturesDrawTextureRec );
|
lua_register( L, "RL_DrawTextureRec", ltexturesDrawTextureRec );
|
||||||
|
|||||||
391
src/textures.c
391
src/textures.c
@@ -132,7 +132,7 @@ Texture2D* texturesGetSourceTexture( size_t index ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
## Textures - Load
|
## Textures - Image Loading
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -282,144 +282,6 @@ int ltexturesExportImageAsCode( lua_State *L ) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
> texture = RL_LoadTexture( string fileName )
|
|
||||||
|
|
||||||
Load texture from file into GPU memory ( VRAM )
|
|
||||||
|
|
||||||
- Failure return -1
|
|
||||||
- Success return int
|
|
||||||
*/
|
|
||||||
int ltexturesLoadTexture( lua_State *L ) {
|
|
||||||
if ( !lua_isstring( L, -1 ) ) {
|
|
||||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadTexture( string fileName )" );
|
|
||||||
lua_pushinteger( L, -1 );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( FileExists( lua_tostring( L, -1 ) ) ) {
|
|
||||||
int i = newTexture();
|
|
||||||
*state->textures[i] = LoadTexture( lua_tostring( L, -1 ) );
|
|
||||||
lua_pushinteger( L, i );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lua_pushinteger( L, -1 );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
> texture = RL_LoadTextureFromImage( Image image )
|
|
||||||
|
|
||||||
Load texture from image data
|
|
||||||
|
|
||||||
- Failure return -1
|
|
||||||
- Success return int
|
|
||||||
*/
|
|
||||||
int ltexturesLoadTextureFromImage( lua_State *L ) {
|
|
||||||
if ( !lua_isnumber( L, -1 ) ) {
|
|
||||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadTextureFromImage( Image image )" );
|
|
||||||
lua_pushinteger( L, -1 );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
size_t imageId = lua_tointeger( L, -1 );
|
|
||||||
|
|
||||||
if ( !validImage( imageId ) ) {
|
|
||||||
lua_pushboolean( L, false );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
int i = newTexture();
|
|
||||||
*state->textures[i] = LoadTextureFromImage( *state->images[ imageId ] );
|
|
||||||
lua_pushinteger( L, i );
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
> success = RL_UnloadTexture( Texture2D texture )
|
|
||||||
|
|
||||||
Unload texture from GPU memory ( VRAM )
|
|
||||||
|
|
||||||
- Failure return false
|
|
||||||
- Success return true
|
|
||||||
*/
|
|
||||||
int ltexturesUnloadTexture( lua_State *L ) {
|
|
||||||
if ( !lua_isnumber( L, -1 ) ) {
|
|
||||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_UnloadTexture( Texture2D texture )" );
|
|
||||||
lua_pushboolean( L, false );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
size_t id = lua_tointeger( L, -1 );
|
|
||||||
|
|
||||||
if ( !validTexture( id ) ) {
|
|
||||||
lua_pushboolean( L, false );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
UnloadTexture( *state->textures[ id ] );
|
|
||||||
state->textures[ id ] = NULL;
|
|
||||||
lua_pushboolean( L, true );
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
> renderTexture = RL_LoadRenderTexture( Vector2 size )
|
|
||||||
|
|
||||||
Load texture for rendering ( framebuffer )
|
|
||||||
|
|
||||||
- Failure return -1
|
|
||||||
- Success return int
|
|
||||||
*/
|
|
||||||
int ltexturesLoadRenderTexture( lua_State *L ) {
|
|
||||||
if ( !lua_istable( L, -1 ) ) {
|
|
||||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadRenderTexture( Vector2 size )" );
|
|
||||||
lua_pushinteger( L, -1 );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
Vector2 size = uluaGetVector2( L );
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
for ( i = 0; i < state->renderTextureCount; i++ ) {
|
|
||||||
if ( state->renderTextures[i] == NULL ) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
state->renderTextures[i] = malloc( sizeof( RenderTexture2D ) );
|
|
||||||
*state->renderTextures[i] = LoadRenderTexture( (int)size.x, (int)size.y );
|
|
||||||
lua_pushinteger( L, i );
|
|
||||||
checkRenderTextureRealloc( i );
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
> success = RL_UnloadRenderTexture( RenderTexture2D target )
|
|
||||||
|
|
||||||
Unload render texture from GPU memory ( VRAM )
|
|
||||||
|
|
||||||
- Failure return false
|
|
||||||
- Success return true
|
|
||||||
*/
|
|
||||||
int ltexturesUnloadRenderTexture( lua_State *L ) {
|
|
||||||
if ( !lua_isnumber( L, -1 ) ) {
|
|
||||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_UnloadRenderTexture( RenderTexture2D target )" );
|
|
||||||
lua_pushboolean( L, false );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
size_t id = lua_tointeger( L, -1 );
|
|
||||||
|
|
||||||
if ( !validRenderTexture( id ) ) {
|
|
||||||
lua_pushboolean( L, false );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
UnloadRenderTexture( *state->renderTextures[ id ] );
|
|
||||||
state->renderTextures[ id ] = NULL;
|
|
||||||
lua_pushboolean( L, true );
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
## Textures - Image Generation
|
## Textures - Image Generation
|
||||||
*/
|
*/
|
||||||
@@ -1788,6 +1650,256 @@ int ltexturesGetImageFormat( lua_State *L ) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
## Textures - Texture Loading
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
> texture = RL_LoadTexture( string fileName )
|
||||||
|
|
||||||
|
Load texture from file into GPU memory ( VRAM )
|
||||||
|
|
||||||
|
- Failure return -1
|
||||||
|
- Success return int
|
||||||
|
*/
|
||||||
|
int ltexturesLoadTexture( lua_State *L ) {
|
||||||
|
if ( !lua_isstring( L, -1 ) ) {
|
||||||
|
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadTexture( string fileName )" );
|
||||||
|
lua_pushinteger( L, -1 );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( FileExists( lua_tostring( L, -1 ) ) ) {
|
||||||
|
int i = newTexture();
|
||||||
|
*state->textures[i] = LoadTexture( lua_tostring( L, -1 ) );
|
||||||
|
lua_pushinteger( L, i );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lua_pushinteger( L, -1 );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
> texture = RL_LoadTextureFromImage( Image image )
|
||||||
|
|
||||||
|
Load texture from image data
|
||||||
|
|
||||||
|
- Failure return -1
|
||||||
|
- Success return int
|
||||||
|
*/
|
||||||
|
int ltexturesLoadTextureFromImage( lua_State *L ) {
|
||||||
|
if ( !lua_isnumber( L, -1 ) ) {
|
||||||
|
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadTextureFromImage( Image image )" );
|
||||||
|
lua_pushinteger( L, -1 );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
size_t imageId = lua_tointeger( L, -1 );
|
||||||
|
|
||||||
|
if ( !validImage( imageId ) ) {
|
||||||
|
lua_pushboolean( L, false );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
int i = newTexture();
|
||||||
|
*state->textures[i] = LoadTextureFromImage( *state->images[ imageId ] );
|
||||||
|
lua_pushinteger( L, i );
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
> success = RL_UnloadTexture( Texture2D texture )
|
||||||
|
|
||||||
|
Unload texture from GPU memory ( VRAM )
|
||||||
|
|
||||||
|
- Failure return false
|
||||||
|
- Success return true
|
||||||
|
*/
|
||||||
|
int ltexturesUnloadTexture( lua_State *L ) {
|
||||||
|
if ( !lua_isnumber( L, -1 ) ) {
|
||||||
|
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_UnloadTexture( Texture2D texture )" );
|
||||||
|
lua_pushboolean( L, false );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
size_t id = lua_tointeger( L, -1 );
|
||||||
|
|
||||||
|
if ( !validTexture( id ) ) {
|
||||||
|
lua_pushboolean( L, false );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
UnloadTexture( *state->textures[ id ] );
|
||||||
|
state->textures[ id ] = NULL;
|
||||||
|
lua_pushboolean( L, true );
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
> renderTexture = RL_LoadRenderTexture( Vector2 size )
|
||||||
|
|
||||||
|
Load texture for rendering ( framebuffer )
|
||||||
|
|
||||||
|
- Failure return -1
|
||||||
|
- Success return int
|
||||||
|
*/
|
||||||
|
int ltexturesLoadRenderTexture( lua_State *L ) {
|
||||||
|
if ( !lua_istable( L, -1 ) ) {
|
||||||
|
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadRenderTexture( Vector2 size )" );
|
||||||
|
lua_pushinteger( L, -1 );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
Vector2 size = uluaGetVector2( L );
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
for ( i = 0; i < state->renderTextureCount; i++ ) {
|
||||||
|
if ( state->renderTextures[i] == NULL ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state->renderTextures[i] = malloc( sizeof( RenderTexture2D ) );
|
||||||
|
*state->renderTextures[i] = LoadRenderTexture( (int)size.x, (int)size.y );
|
||||||
|
lua_pushinteger( L, i );
|
||||||
|
checkRenderTextureRealloc( i );
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
> success = RL_UnloadRenderTexture( RenderTexture2D target )
|
||||||
|
|
||||||
|
Unload render texture from GPU memory ( VRAM )
|
||||||
|
|
||||||
|
- Failure return false
|
||||||
|
- Success return true
|
||||||
|
*/
|
||||||
|
int ltexturesUnloadRenderTexture( lua_State *L ) {
|
||||||
|
if ( !lua_isnumber( L, -1 ) ) {
|
||||||
|
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_UnloadRenderTexture( RenderTexture2D target )" );
|
||||||
|
lua_pushboolean( L, false );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
size_t id = lua_tointeger( L, -1 );
|
||||||
|
|
||||||
|
if ( !validRenderTexture( id ) ) {
|
||||||
|
lua_pushboolean( L, false );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
UnloadRenderTexture( *state->renderTextures[ id ] );
|
||||||
|
state->renderTextures[ id ] = NULL;
|
||||||
|
lua_pushboolean( L, true );
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
> success = RL_UpdateTexture( Texture2D texture, int pixels{ {} } )
|
||||||
|
|
||||||
|
Update GPU texture with new data
|
||||||
|
NOTE! Should be TEXTURE_SOURCE_TEXTURE. Pixel should be in format { { 255, 255, 255, 255 }... } depending on the pixel format
|
||||||
|
|
||||||
|
- Failure return false
|
||||||
|
- Success return true
|
||||||
|
*/
|
||||||
|
int ltexturesUpdateTexture( lua_State *L ) {
|
||||||
|
if ( !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||||
|
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_UpdateTexture( Texture2D texture, int pixels{ {} } )" );
|
||||||
|
lua_pushboolean( L, false );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
size_t texId = lua_tointeger( L, -2 );
|
||||||
|
|
||||||
|
if ( !validTexture( texId ) ) {
|
||||||
|
lua_pushboolean( L, false );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
size_t len = uluaGetTableLen( L );
|
||||||
|
unsigned char *pixels = malloc( len * 4 * sizeof( unsigned char ) );
|
||||||
|
|
||||||
|
int t = lua_gettop( L );
|
||||||
|
int i = 0;
|
||||||
|
lua_pushnil( L );
|
||||||
|
|
||||||
|
while ( lua_next( L, t ) != 0 ) {
|
||||||
|
size_t colLen = uluaGetTableLen( L );
|
||||||
|
|
||||||
|
int t2 = lua_gettop( L );
|
||||||
|
int j = 0;
|
||||||
|
lua_pushnil( L );
|
||||||
|
|
||||||
|
while ( lua_next( L, t2 ) != 0 ) {
|
||||||
|
*( pixels + ( i * colLen ) + j ) = lua_tointeger( L, -1 );
|
||||||
|
|
||||||
|
j++;
|
||||||
|
lua_pop( L, 1 );
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
lua_pop( L, 1 );
|
||||||
|
}
|
||||||
|
UpdateTexture( *state->textures[ texId ], pixels );
|
||||||
|
lua_pushboolean( L, true );
|
||||||
|
|
||||||
|
free( pixels );
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
> success = RL_UpdateTextureRec( Texture2D texture, Rectangle rec, int pixels{ {} } )
|
||||||
|
|
||||||
|
Update GPU texture rectangle with new data
|
||||||
|
NOTE! Should be TEXTURE_SOURCE_TEXTURE. Pixel should be in format { { 255, 255, 255, 255 }... } depending on the pixel format
|
||||||
|
|
||||||
|
- Failure return false
|
||||||
|
- Success return true
|
||||||
|
*/
|
||||||
|
int ltexturesUpdateTextureRec( lua_State *L ) {
|
||||||
|
if ( !lua_isnumber( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
|
||||||
|
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_UpdateTextureRec( Texture2D texture, Rectangle rec, int pixels{ {} } )" );
|
||||||
|
lua_pushboolean( L, false );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
size_t texId = lua_tointeger( L, -3 );
|
||||||
|
|
||||||
|
if ( !validTexture( texId ) ) {
|
||||||
|
lua_pushboolean( L, false );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
size_t len = uluaGetTableLen( L );
|
||||||
|
unsigned char *pixels = malloc( len * 4 * sizeof( unsigned char ) );
|
||||||
|
|
||||||
|
int t = lua_gettop( L );
|
||||||
|
int i = 0;
|
||||||
|
lua_pushnil( L );
|
||||||
|
|
||||||
|
while ( lua_next( L, t ) != 0 ) {
|
||||||
|
size_t colLen = uluaGetTableLen( L );
|
||||||
|
|
||||||
|
int t2 = lua_gettop( L );
|
||||||
|
int j = 0;
|
||||||
|
lua_pushnil( L );
|
||||||
|
|
||||||
|
while ( lua_next( L, t2 ) != 0 ) {
|
||||||
|
*( pixels + ( i * colLen ) + j ) = lua_tointeger( L, -1 );
|
||||||
|
|
||||||
|
j++;
|
||||||
|
lua_pop( L, 1 );
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
lua_pop( L, 1 );
|
||||||
|
}
|
||||||
|
lua_pop( L, 1 ); /* Pixels arg. */
|
||||||
|
|
||||||
|
Rectangle rec = uluaGetRectangle( L );
|
||||||
|
|
||||||
|
UpdateTextureRec( *state->textures[ texId ], rec, pixels );
|
||||||
|
lua_pushboolean( L, true );
|
||||||
|
|
||||||
|
free( pixels );
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
## Textures - Texture Drawing
|
## Textures - Texture Drawing
|
||||||
*/
|
*/
|
||||||
@@ -2490,7 +2602,6 @@ int ltexturesGetPixelColor( lua_State *L ) {
|
|||||||
lua_pop( L, 1 );
|
lua_pop( L, 1 );
|
||||||
size_t texId = lua_tointeger( L, -2 );
|
size_t texId = lua_tointeger( L, -2 );
|
||||||
|
|
||||||
// if ( !validTexture( texId ) ) {
|
|
||||||
if ( !validSourceTexture( texId ) ) {
|
if ( !validSourceTexture( texId ) ) {
|
||||||
lua_pushboolean( L, false );
|
lua_pushboolean( L, false );
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user