diff options
| author | raysan5 <[email protected]> | 2020-09-18 02:11:49 +0200 |
|---|---|---|
| committer | raysan5 <[email protected]> | 2020-09-18 02:11:49 +0200 |
| commit | cdc8850e6877084657a9c2be1142878e8e1a7f0a (patch) | |
| tree | 23e75572844f6a8dc689b231e201ec6e440828e0 /src/textures.c | |
| parent | fa2c1146366557e5ce779d8b5c2575579dfa6389 (diff) | |
| download | raylib-cdc8850e6877084657a9c2be1142878e8e1a7f0a.tar.gz raylib-cdc8850e6877084657a9c2be1142878e8e1a7f0a.zip | |
WARNING: REDESIGN of rlgl framebuffers API #721
This redesign allows more flexibility when creating RenderTexture and a simplification (and hopefully removal) of `GenTexture*()` functions, that should not belong to this model but the user code, due to the use of custom shaders.
Also, this new API opens the door for a possible GBuffers type and advance rendering possibilities...
Some functions of the API have been also simplified or even removed.
rlgl module can be used as an standalone library, so, a version for the library has been added: v3.1.0, matching current raylib version.
Diffstat (limited to 'src/textures.c')
| -rw-r--r-- | src/textures.c | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/src/textures.c b/src/textures.c index c1c60d08..cc636ac5 100644 --- a/src/textures.c +++ b/src/textures.c @@ -72,7 +72,7 @@ #include "utils.h" // Required for: fopen() Android mapping #include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3 or ES2 - // Required for: rlLoadTexture() rlDeleteTextures(), + // Required for: rlLoadTexture() rlUnloadTexture(), // rlGenerateMipmaps(), some funcs for DrawTexturePro() // Support only desired texture formats on stb_image @@ -2796,7 +2796,38 @@ TextureCubemap LoadTextureCubemap(Image image, int layoutType) // NOTE: Render texture is loaded by default with RGBA color attachment and depth RenderBuffer RenderTexture2D LoadRenderTexture(int width, int height) { - RenderTexture2D target = rlLoadRenderTexture(width, height, UNCOMPRESSED_R8G8B8A8, 24, false); + RenderTexture2D target = { 0 }; + + target.id = rlLoadFramebuffer(width, height); // Load an empty framebuffer + + if (target.id > 0) + { + rlEnableFramebuffer(target.id); + + // Create color texture (default to RGBA) + target.texture.id = rlLoadTexture(NULL, width, height, UNCOMPRESSED_R8G8B8A8, 1); + target.texture.width = width; + target.texture.height = height; + target.texture.format = UNCOMPRESSED_R8G8B8A8; + target.texture.mipmaps = 1; + + // Create depth renderbuffer/texture + target.depth.id = rlLoadTextureDepth(width, height, true); + target.depth.width = width; + target.depth.height = height; + target.depth.format = 19; //DEPTH_COMPONENT_24BIT? + target.depth.mipmaps = 1; + + // Attach color texture and depth renderbuffer/texture to FBO + rlFramebufferAttach(target.id, target.texture.id, RL_ATTACHMENT_COLOR_TEXTURE); // COLOR attachment + rlFramebufferAttach(target.id, target.depth.id, RL_ATTACHMENT_DEPTH_RENDERBUFFER); // DEPTH attachment + + // Check if fbo is complete with attachments (valid) + if (rlFramebufferComplete(target.id)) TRACELOG(LOG_INFO, "FBO: [ID %i] Framebuffer object created successfully", target.id); + + rlDisableFramebuffer(); + } + else TRACELOG(LOG_WARNING, "FBO: Framebuffer object can not be created"); return target; } @@ -2806,7 +2837,7 @@ void UnloadTexture(Texture2D texture) { if (texture.id > 0) { - rlDeleteTextures(texture.id); + rlUnloadTexture(texture.id); TRACELOG(LOG_INFO, "TEXTURE: [ID %i] Unloaded texture data from VRAM (GPU)", texture.id); } @@ -2815,7 +2846,15 @@ void UnloadTexture(Texture2D texture) // Unload render texture from GPU memory (VRAM) void UnloadRenderTexture(RenderTexture2D target) { - if (target.id > 0) rlDeleteRenderTextures(target); + if (target.id > 0) + { + // Color texture attached to FBO is deleted + rlUnloadTexture(target.texture.id); + + // NOTE: Depth texture/renderbuffer is automatically + // queried and deleted before deleting framebuffer + rlUnloadFramebuffer(target.id); + } } // Update GPU texture with new data |
