glBlitFramebuffer.

This commit is contained in:
jussi
2023-04-12 00:05:57 +03:00
parent 3445d935d6
commit 895c7f1a06
13 changed files with 8829 additions and 15 deletions

26
API.md
View File

@@ -921,6 +921,18 @@ LIGHT_DIRECTIONAL
LIGHT_POINT
## Globals - OpenGL
GL_COLOR_BUFFER_BIT
GL_DEPTH_BUFFER_BIT
GL_STENCIL_BUFFER_BIT
GL_NEAREST
GL_LINEAR
## Types
Raylib structs in Lua
@@ -6388,6 +6400,20 @@ Get the line drawing width
---
## 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
---
## Easings - Linear Easing functions
---

View File

@@ -542,6 +542,14 @@ RL.HUEBAR_SELECTOR_OVERFLOW=20
RL.LIGHT_DIRECTIONAL=0
RL.LIGHT_POINT=1
-- Globals - OpenGL
RL.GL_COLOR_BUFFER_BIT=16384
RL.GL_DEPTH_BUFFER_BIT=256
RL.GL_STENCIL_BUFFER_BIT=1024
RL.GL_NEAREST=9728
RL.GL_LINEAR=9729
-- Core - Window
---Check if window has been initialized successfully
@@ -5199,6 +5207,21 @@ function RL.rlSetLineWidth( width ) end
---@return any width
function RL.rlGetLineWidth() end
-- OpenGL - Framebuffer management
---Copy a block of pixels from one framebuffer object to another.
---Use -1 RenderTexture for window framebuffer.
---- Failure return false
---- Success return true
---@param srcTex any
---@param dstTex any
---@param srcRect table
---@param dstRect table
---@param mask integer
---@param filter integer
---@return any success
function RL.glBlitFramebuffer( srcTex, dstTex, srcRect, dstRect, mask, filter ) end
-- Easings - Linear Easing functions
---Ease linear

View File

@@ -49,6 +49,7 @@ Detailed changes:
- ADDED: Camera3DRoll
- ADDED: GetCamera3DViewMatrix
- ADDED: GetCamera3DProjectionMatrix
- ADDED: glBlitFramebuffer
------------------------------------------------------------------------
Release: ReiLua version 0.4.0 Using Raylib 4.2

View File

@@ -1,5 +1,4 @@
Current {
* ReiLua camera3D lib.
* Check new functions from https://github.com/raysan5/raylib/blob/master/CHANGELOG
}

View File

@@ -122,6 +122,7 @@ luaApiFile:write(
local srcFile = io.open( "../src/lua_core.c", "r" )
local writing = false
local globalVariableCount = 0
repeat
line = srcFile:read( "*l" )
@@ -144,6 +145,7 @@ repeat
local value = RL[ globalName ]
globalName = "RL."..globalName
globalVariableCount = globalVariableCount + 1
if value == nil then
luaApiFile:write( globalName.."=nil\n" )
@@ -259,9 +261,12 @@ local sourceFiles = {
"rgui",
"lights",
"rlgl",
"gl",
"easings",
}
local functionCount = 0
for _, src in ipairs( sourceFiles ) do
srcFile = io.open( "../src/"..src..".c", "r" )
local line = ""
@@ -289,6 +294,7 @@ for _, src in ipairs( sourceFiles ) do
luaApiFile:write( "-- "..line:sub( 4 ).."\n" )
elseif line:sub( 1, 1 ) == ">" then
funcStr = parseFunction( line )
functionCount = functionCount + 1
elseif line:sub( 1, 1 ) ~= "" then
luaApiFile:write( "---"..line.."\n" )
end
@@ -310,3 +316,5 @@ end
if not separate then
apiFile:close()
end
print( "Parsed:\n"..globalVariableCount.." Global variables\n"..functionCount.." Functions" )

View File

@@ -39,8 +39,8 @@ function RL.init()
camera:setPosition( { 0, 8, 16 } )
camera:setTarget( { 0, 0, 0 } )
camera:setUp( { 0, 1, 0 } )
-- camera.mode = camera.MODES.ORBITAL
camera.mode = camera.MODES.FREE
camera.mode = camera.MODES.ORBITAL
-- camera.mode = camera.MODES.FREE
-- camera.mode = camera.MODES.FIRST_PERSON
heigthImage = RL.LoadImage( RL.GetBasePath().."../resources/images/heightmap.png" )

View File

@@ -300,7 +300,9 @@ function RL.draw()
drawPlayer()
RL.EndTextureMode()
RL.SetTextureSource( RL.TEXTURE_SOURCE_RENDER_TEXTURE )
RL.DrawTexturePro( framebuffer, { 0, 0, res.x, -res.y }, { 0, 0, winSize.x, winSize.y }, { 0, 0 }, 0.0, RL.WHITE )
RL.SetTextureSource( RL.TEXTURE_SOURCE_TEXTURE )
-- RL.SetTextureSource( RL.TEXTURE_SOURCE_RENDER_TEXTURE )
-- RL.DrawTexturePro( framebuffer, { 0, 0, res.x, -res.y }, { 0, 0, winSize.x, winSize.y }, { 0, 0 }, 0.0, RL.WHITE )
-- RL.SetTextureSource( RL.TEXTURE_SOURCE_TEXTURE )
RL.glBlitFramebuffer( framebuffer, -1, res, winSize, RL.GL_COLOR_BUFFER_BIT, RL.GL_NEAREST )
end

8682
include/glad.h Normal file

File diff suppressed because it is too large Load Diff

4
include/lgl.h Normal file
View File

@@ -0,0 +1,4 @@
#pragma once
/* Framebuffer management. */
int lglBlitFramebuffer( lua_State *L );

View File

@@ -7,15 +7,16 @@
#define VERSION_PATCH 0
#define VERSION_DEV 1
#include "glad.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "raylib.h"
#include "rlgl.h"
#include "raymath.h"
#include "raygui.h"
#include "rlights.h"
#include "rcamera.h"
#include "rlgl.h"
#include "glfw3.h"
#include "glfw3native.h"
#include <lua.h>

View File

@@ -80,10 +80,8 @@ int ltexturesUpdateTextureRec( lua_State *L );
/* Texture Drawing. */
int ltexturesDrawTexture( lua_State *L );
int ltexturesDrawTextureRec( lua_State *L );
// int ltexturesDrawTextureTiled( lua_State *L );
int ltexturesDrawTexturePro( lua_State *L );
int ltexturesDrawTextureNPatch( lua_State *L );
// int ltexturesDrawTexturePoly( lua_State *L );
int ltexturesBeginTextureMode( lua_State *L );
int ltexturesEndTextureMode( lua_State *L );
int ltexturesSetTextureSource( lua_State *L );

65
src/gl.c Normal file
View File

@@ -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;
}

View File

@@ -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 );