From 895c7f1a06de2d89347909d62da41be9d62f0d09 Mon Sep 17 00:00:00 2001 From: jussi Date: Wed, 12 Apr 2023 00:05:57 +0300 Subject: glBlitFramebuffer. --- src/gl.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lua_core.c | 17 +++++++++------ 2 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 src/gl.c (limited to 'src') diff --git a/src/gl.c b/src/gl.c new file mode 100644 index 0000000..18947d5 --- /dev/null +++ b/src/gl.c @@ -0,0 +1,65 @@ +#include "main.h" +#include "state.h" +#include "lua_core.h" +#include "textures.h" +#include "lgl.h" + +/* +## OpenGL - Framebuffer management +*/ + +/* +> success = RL.glBlitFramebuffer( RenderTexture srcTex, RenderTexture dstTex, Rectangle srcRect, Rectangle dstRect, int mask, int filter ) + +Copy a block of pixels from one framebuffer object to another. +Use -1 RenderTexture for window framebuffer. + +- Failure return false +- Success return true +*/ +int lglBlitFramebuffer( lua_State *L ) { + if ( !lua_isnumber( L, 1) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) + || !lua_istable( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.glBlitFramebuffer( RenderTexture srcTex, RenderTexture dstTex, Rectangle srcRect, Rectangle dstRect, int mask, int filter )" ); + lua_pushboolean( L, false ); + return 1; + } + int srcTexId = lua_tointeger( L, 1 ); + int dstTexId = lua_tointeger( L, 2 ); + Rectangle srcRect = uluaGetRectangleIndex( L, 3 ); + Rectangle dstRect = uluaGetRectangleIndex( L, 4 ); + int mask = lua_tointeger( L, 5 ); + int filter = lua_tointeger( L, 6 ); + + if ( ( !validRenderTexture( srcTexId ) && srcTexId != -1 ) && ( !validRenderTexture( dstTexId ) && dstTexId != -1 ) ) { + lua_pushboolean( L, false ); + return 1; + } + + if ( srcTexId == -1 ) { + glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 ); + } + else { + glBindFramebuffer( GL_READ_FRAMEBUFFER, state->renderTextures[ srcTexId ]->id ); + } + + if ( dstTexId == -1 ) { + glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 ); + } + else { + glBindFramebuffer( GL_DRAW_FRAMEBUFFER, state->renderTextures[ dstTexId ]->id ); + } + + glBlitFramebuffer( + srcRect.x, srcRect.y, srcRect.width, srcRect.height, + dstRect.x, dstRect.y, dstRect.width, dstRect.height, + mask, + filter + // GL_COLOR_BUFFER_BIT, // mask + // GL_NEAREST // filter + ); + + lua_pushboolean( L, true ); + + return 1; +} \ No newline at end of file diff --git a/src/lua_core.c b/src/lua_core.c index dae916e..3c839c6 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -11,6 +11,7 @@ #include "rgui.h" #include "lights.h" #include "lrlgl.h" +#include "lgl.h" #include "reasings.h" static void assignGlobalInt( int value, const char *name ) { @@ -491,6 +492,12 @@ void defineGlobals() { /* LightType */ assignGlobalInt( LIGHT_DIRECTIONAL, "LIGHT_DIRECTIONAL" ); assignGlobalInt( LIGHT_POINT, "LIGHT_POINT" ); + /* OpenGL */ + assignGlobalInt( GL_COLOR_BUFFER_BIT, "GL_COLOR_BUFFER_BIT" ); + assignGlobalInt( GL_DEPTH_BUFFER_BIT, "GL_DEPTH_BUFFER_BIT" ); + assignGlobalInt( GL_STENCIL_BUFFER_BIT, "GL_STENCIL_BUFFER_BIT" ); + assignGlobalInt( GL_NEAREST, "GL_NEAREST" ); + assignGlobalInt( GL_LINEAR, "GL_LINEAR" ); /*DOC_END*/ lua_pop( L, -1 ); @@ -999,10 +1006,8 @@ void luaRegister() { /* Texture Drawing. */ assingGlobalFunction( "DrawTexture", ltexturesDrawTexture ); assingGlobalFunction( "DrawTextureRec", ltexturesDrawTextureRec ); - // assingGlobalFunction( "DrawTextureTiled", ltexturesDrawTextureTiled ); assingGlobalFunction( "DrawTexturePro", ltexturesDrawTexturePro ); assingGlobalFunction( "DrawTextureNPatch", ltexturesDrawTextureNPatch ); - // assingGlobalFunction( "DrawTexturePoly", ltexturesDrawTexturePoly ); assingGlobalFunction( "BeginTextureMode", ltexturesBeginTextureMode ); assingGlobalFunction( "EndTextureMode", ltexturesEndTextureMode ); assingGlobalFunction( "SetTextureSource", ltexturesSetTextureSource ); @@ -1038,7 +1043,6 @@ void luaRegister() { assingGlobalFunction( "DrawTriangle3D", lmodelsDrawTriangle3D ); assingGlobalFunction( "DrawCube", lmodelsDrawCube ); assingGlobalFunction( "DrawCubeWires", lmodelsDrawCubeWires ); - // assingGlobalFunction( "DrawCubeTexture", lmodelsDrawCubeTexture ); assingGlobalFunction( "DrawSphere", lmodelsDrawSphere ); assingGlobalFunction( "DrawSphereEx", lmodelsDrawSphereEx ); assingGlobalFunction( "DrawSphereWires", lmodelsDrawSphereWires ); @@ -1138,9 +1142,6 @@ void luaRegister() { assingGlobalFunction( "StopSound", laudioStopSound ); assingGlobalFunction( "PauseSound", laudioPauseSound ); assingGlobalFunction( "ResumeSound", laudioResumeSound ); - // assingGlobalFunction( "PlaySoundMulti", laudioPlaySoundMulti ); - // assingGlobalFunction( "StopSoundMulti", laudioStopSoundMulti ); - // assingGlobalFunction( "GetSoundsPlaying", laudioGetSoundsPlaying ); assingGlobalFunction( "IsSoundPlaying", laudioIsSoundPlaying ); assingGlobalFunction( "SetSoundVolume", laudioSetSoundVolume ); assingGlobalFunction( "SetSoundPitch", laudioSetSoundPitch ); @@ -1347,6 +1348,10 @@ void luaRegister() { assingGlobalFunction( "rlglSetLineWidth", lrlglSetLineWidth ); assingGlobalFunction( "rlglGetLineWidth", lrlglGetLineWidth ); + /* OpenGL */ + /* Framebuffer management. */ + assingGlobalFunction( "glBlitFramebuffer", lglBlitFramebuffer ); + /* Easings */ /* Linear Easing functions. */ assingGlobalFunction( "EaseLinear", leasingsEaseLinear ); -- cgit v1.2.3