List of commits:
Subject Hash Author Date (UTC)
Put framebuffer textures in an array ad44ec442db02cbb194559948d7183580b488cec fluffrabbit 2024-07-11 19:33:58
Initial commit cd1f3278f6f9a79255ba17b3b9eb0c224c8fd091 fluffrabbit 2024-07-10 17:32:30
Commit ad44ec442db02cbb194559948d7183580b488cec - Put framebuffer textures in an array
Author: fluffrabbit
Author date (UTC): 2024-07-11 19:33
Committer name: fluffrabbit
Committer date (UTC): 2024-07-11 19:33
Parent(s): cd1f3278f6f9a79255ba17b3b9eb0c224c8fd091
Signer:
Signing key:
Signing status: N
Tree: c84e30ec7eda242e9b3374bb3ad5452958d2cb70
File Lines added Lines deleted
include/fgc.h 17 18
File include/fgc.h changed (mode: 100644) (index 057f0e5..1834285)
... ... typedef struct {
179 179 typedef struct { typedef struct {
180 180 bool success; bool success;
181 181 GLuint fbo; GLuint fbo;
182 GLuint texture;
183 GLuint texture_z;
182 GLuint textures[16];
184 183 GLenum texture_type; GLenum texture_type;
185 184 GLenum texture_fmt; GLenum texture_fmt;
186 185 GLuint rbo; GLuint rbo;
 
... ... void fgcSetFog( FGCColor col );
304 303
305 304 FGCFramebuffer fgcCreateFramebuffer( GLsizei width, GLsizei height, bool cubemap, GLenum internalFmt, GLsizei multisample ); FGCFramebuffer fgcCreateFramebuffer( GLsizei width, GLsizei height, bool cubemap, GLenum internalFmt, GLsizei multisample );
306 305 void fgcResizeFramebuffer( FGCFramebuffer *fb, GLsizei width, GLsizei height, GLsizei multisample ); void fgcResizeFramebuffer( FGCFramebuffer *fb, GLsizei width, GLsizei height, GLsizei multisample );
307 FGCTexture fgcGetFramebufferTexture( FGCFramebuffer *fb );
306 FGCTexture fgcGetFramebufferTexture( FGCFramebuffer *fb, unsigned int i );
308 307 void fgcSetFramebuffer( FGCFramebuffer *fb, float viewScale ); void fgcSetFramebuffer( FGCFramebuffer *fb, float viewScale );
309 void fgcDrawFramebuffer( FGCFramebuffer *fb, bool drawZ, float viewScale );
308 void fgcDrawFramebuffer( FGCFramebuffer *fb, unsigned int drawIndex, float viewScale );
310 309
311 310 FGCMesh fgcLoadMesh( FGCMesh fgcLoadMesh(
312 311 size_t nvertices, size_t nvertices,
 
... ... FGCFramebuffer fgcCreateFramebuffer( GLsizei width, GLsizei height, bool cubemap
609 608 #endif #endif
610 609
611 610 fb.texture_fmt = internalFmt; fb.texture_fmt = internalFmt;
612 glGenTextures( 1, &fb.texture );
613 glBindTexture( fb.texture_type, fb.texture );
611 glGenTextures( 1, &fb.textures[0] );
612 glBindTexture( fb.texture_type, fb.textures[0] );
614 613
615 614 GLenum format, pixType; GLenum format, pixType;
616 615 if( internalFmt == GL_RGB ){ if( internalFmt == GL_RGB ){
 
... ... FGCFramebuffer fgcCreateFramebuffer( GLsizei width, GLsizei height, bool cubemap
653 652 GL_FRAMEBUFFER, GL_FRAMEBUFFER,
654 653 GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT0,
655 654 GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
656 fb.texture,
655 fb.textures[0],
657 656 0 0
658 657 ); );
659 658 } }
 
... ... FGCFramebuffer fgcCreateFramebuffer( GLsizei width, GLsizei height, bool cubemap
667 666 #endif #endif
668 667 glTexImage2D( GL_TEXTURE_2D, 0, internalFmt, width, height, 0, format, pixType, NULL ); glTexImage2D( GL_TEXTURE_2D, 0, internalFmt, width, height, 0, format, pixType, NULL );
669 668
670 glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, fb.texture_type, fb.texture, 0 );
669 glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, fb.texture_type, fb.textures[0], 0 );
671 670 } }
672 671
673 672 if( multisample == 0 ){ if( multisample == 0 ){
 
... ... FGCFramebuffer fgcCreateFramebuffer( GLsizei width, GLsizei height, bool cubemap
686 685 #endif #endif
687 686 ){ ){
688 687 // Cubemap depth textures are unsupported. // Cubemap depth textures are unsupported.
689 fb.texture_z = 0;
688 fb.textures[1] = 0;
690 689 // Create a depth renderbuffer. // Create a depth renderbuffer.
691 690 glGenRenderbuffers( 1, &fb.rbo ); glGenRenderbuffers( 1, &fb.rbo );
692 691 glBindRenderbuffer( GL_RENDERBUFFER, fb.rbo ); glBindRenderbuffer( GL_RENDERBUFFER, fb.rbo );
 
... ... FGCFramebuffer fgcCreateFramebuffer( GLsizei width, GLsizei height, bool cubemap
701 700 }else{ }else{
702 701 fb.rbo = 0; fb.rbo = 0;
703 702 // Create a depth texture. // Create a depth texture.
704 glGenTextures( 1, &fb.texture_z );
705 glBindTexture( fb.texture_type, fb.texture_z );
703 glGenTextures( 1, &fb.textures[1] );
704 glBindTexture( fb.texture_type, fb.textures[1] );
706 705 glTexImage2D( fb.texture_type, 0, GL_DEPTH_COMPONENT32F, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL ); glTexImage2D( fb.texture_type, 0, GL_DEPTH_COMPONENT32F, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL );
707 glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, fb.texture_type, fb.texture_z, 0 );
706 glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, fb.texture_type, fb.textures[1], 0 );
708 707 glTexParameteri( fb.texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( fb.texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
709 708 glTexParameteri( fb.texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); glTexParameteri( fb.texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
710 709 glTexParameteri( fb.texture_type, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri( fb.texture_type, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
 
... ... void fgcResizeFramebuffer( FGCFramebuffer *fb, GLsizei width, GLsizei height, GL
743 742
744 743 glBindFramebuffer( GL_FRAMEBUFFER, fb->fbo ); glBindFramebuffer( GL_FRAMEBUFFER, fb->fbo );
745 744
746 glBindTexture( fb->texture_type, fb->texture );
745 glBindTexture( fb->texture_type, fb->textures[0] );
747 746
748 747 GLenum format, pixType; GLenum format, pixType;
749 748 if( fb->texture_fmt == GL_RG16F ){ if( fb->texture_fmt == GL_RG16F ){
 
... ... void fgcResizeFramebuffer( FGCFramebuffer *fb, GLsizei width, GLsizei height, GL
810 809 glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fb->rbo ); glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fb->rbo );
811 810 }else{ }else{
812 811 // Resize the depth texture. // Resize the depth texture.
813 glBindTexture( fb->texture_type, fb->texture_z );
812 glBindTexture( fb->texture_type, fb->textures[1] );
814 813 glTexImage2D( fb->texture_type, 0, GL_DEPTH_COMPONENT32F, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL ); glTexImage2D( fb->texture_type, 0, GL_DEPTH_COMPONENT32F, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL );
815 814 // Unbind the texture. // Unbind the texture.
816 815 glBindTexture( fb->texture_type, 0 ); glBindTexture( fb->texture_type, 0 );
 
... ... void fgcResizeFramebuffer( FGCFramebuffer *fb, GLsizei width, GLsizei height, GL
822 821 fb->multisample = multisample; fb->multisample = multisample;
823 822 } }
824 823
825 FGCTexture fgcGetFramebufferTexture( FGCFramebuffer *fb ){
824 FGCTexture fgcGetFramebufferTexture( FGCFramebuffer *fb, unsigned int i ){
826 825 FGCTexture tex; FGCTexture tex;
827 826 tex.success = fb->success; tex.success = fb->success;
828 tex.texture = fb->texture;
827 tex.texture = fb->textures[i];
829 828 tex.width = fb->width; tex.width = fb->width;
830 829 tex.height = fb->height; tex.height = fb->height;
831 830 tex.channels = 4; // TODO: Is this accurate? tex.channels = 4; // TODO: Is this accurate?
 
... ... void fgcSetFramebuffer( FGCFramebuffer *fb, float viewScale ){
845 844 } }
846 845 } }
847 846
848 void fgcDrawFramebuffer( FGCFramebuffer *fb, bool drawZ, float viewScale ){
847 void fgcDrawFramebuffer( FGCFramebuffer *fb, unsigned int drawIndex, float viewScale ){
849 848 if( !fb || !fb->success ) return; if( !fb || !fb->success ) return;
850 849 if( fb->multisample > 0 ){ if( fb->multisample > 0 ){
851 850 // Blit and rely on OpenGL to resolve samples. // Blit and rely on OpenGL to resolve samples.
 
... ... void fgcDrawFramebuffer( FGCFramebuffer *fb, bool drawZ, float viewScale ){
861 860 glDisable( GL_DEPTH_TEST ); glDisable( GL_DEPTH_TEST );
862 861 glDisable( GL_CULL_FACE ); glDisable( GL_CULL_FACE );
863 862 glActiveTexture( GL_TEXTURE0 ); glActiveTexture( GL_TEXTURE0 );
864 glBindTexture( fb->texture_type, drawZ ? fb->texture_z : fb->texture );
863 glBindTexture( fb->texture_type, fb->textures[drawIndex] );
865 864 fgcTexMatrix = MAT4_IDEN; fgcTexMatrix = MAT4_IDEN;
866 865 // Stretch to screen bounds and flip vertically. // Stretch to screen bounds and flip vertically.
867 866 fgcDrawMesh( fgcDrawMesh(
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/fluffrabbit/cfps

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/fluffrabbit/cfps

Clone this repository using git:
git clone git://git.rocketgit.com/user/fluffrabbit/cfps

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main