Revert "Revert "Implement framebuffer and renderbuffer objects""
This reverts commit b0f5f4338f.
This commit is contained in:
1 parent
44b8a8a0d8
commit
58de3a35a0
7 files changed
+210
-13
No files matched your search
@@ -279,6 +279,7 @@ typedef struct FSurfaceInfo FSurfaceInfo;
|
||||
|
||||
enum hwdsetspecialstate
|
||||
{
|
||||
HWD_SET_FRAMEBUFFER,
|
||||
HWD_SET_SHADERS,
|
||||
|
||||
HWD_SET_TEXTUREFILTERMODE,
|
||||
|
||||
@@ -59,7 +59,7 @@ EXPORT void HWRAPI(FlushScreenTextures) (void);
|
||||
EXPORT void HWRAPI(DoScreenWipe) (int wipeStart, int wipeEnd);
|
||||
EXPORT void HWRAPI(DrawScreenTexture) (int tex, FSurfaceInfo *surf, FBITFIELD polyflags);
|
||||
EXPORT void HWRAPI(MakeScreenTexture) (int tex);
|
||||
EXPORT void HWRAPI(DrawScreenFinalTexture) (int tex, int width, int height);
|
||||
EXPORT void HWRAPI(DrawScreenFinalTexture) (int tex, INT32 width, INT32 height);
|
||||
|
||||
EXPORT void HWRAPI(RenderVhsEffect) (fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize);
|
||||
|
||||
|
||||
+12
-2
@@ -68,6 +68,7 @@ static boolean gr_palette_rendering_state = false;
|
||||
// Commands and console variables
|
||||
// ==========================================================================
|
||||
|
||||
static void CV_grframebuffer_OnChange(void);
|
||||
static void CV_filtermode_ONChange(void);
|
||||
static void CV_anisotropic_ONChange(void);
|
||||
static void CV_screentextures_ONChange(void);
|
||||
@@ -96,6 +97,8 @@ consvar_t cv_grsolvetjoin = {"gr_solvetjoin", "On", 0, CV_OnOff, NULL, 0, NULL,
|
||||
|
||||
consvar_t cv_grbatching = {"gr_batching", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
|
||||
|
||||
consvar_t cv_grframebuffer = {"gr_framebuffer", "On", CV_SAVE|CV_CALL, CV_OnOff, CV_grframebuffer_OnChange, 0, NULL, NULL, 0, 0, NULL};
|
||||
|
||||
consvar_t cv_grfofcut = {"gr_fofcut", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
|
||||
|
||||
consvar_t cv_fofzfightfix = {"fofzfightfix", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
|
||||
@@ -163,6 +166,12 @@ consvar_t cv_grhorizonlines = {"gr_horizonlines", "On", CV_SAVE, CV_OnOff, NULL,
|
||||
|
||||
#define ONLY_IF_GL_LOADED if (vid.glstate != VID_GL_LIBRARY_LOADED) return;
|
||||
|
||||
static void CV_grframebuffer_OnChange(void)
|
||||
{
|
||||
ONLY_IF_GL_LOADED
|
||||
HWD.pfnSetSpecialState(HWD_SET_FRAMEBUFFER, cv_grframebuffer.value);
|
||||
}
|
||||
|
||||
static void CV_filtermode_ONChange(void)
|
||||
{
|
||||
ONLY_IF_GL_LOADED
|
||||
@@ -5920,7 +5929,7 @@ static inline void HWR_ClearView(void)
|
||||
(INT32)(gr_viewwindowx + gr_viewwidth),
|
||||
(INT32)(gr_viewwindowy + gr_viewheight),
|
||||
ZCLIP_PLANE, FAR_ZCLIP_DEFAULT);
|
||||
HWD.pfnClearBuffer(false, true, true, 0);
|
||||
HWD.pfnClearBuffer(false, true, true, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -6482,6 +6491,7 @@ void HWR_TogglePaletteRendering(void)
|
||||
//added by Hurdler: console varibale that are saved
|
||||
void HWR_AddCommands(void)
|
||||
{
|
||||
CV_RegisterVar(&cv_grframebuffer);
|
||||
CV_RegisterVar(&cv_grfiltermode);
|
||||
CV_RegisterVar(&cv_granisotropicmode);
|
||||
CV_RegisterVar(&cv_grcorrecttricks);
|
||||
@@ -6761,7 +6771,7 @@ void HWR_MakeScreenFinalTexture(void)
|
||||
HWD.pfnMakeScreenTexture(HWD_SCREENTEXTURE_GENERIC2);
|
||||
}
|
||||
|
||||
void HWR_DrawScreenFinalTexture(int width, int height)
|
||||
void HWR_DrawScreenFinalTexture(INT32 width, INT32 height)
|
||||
{
|
||||
HWD.pfnDrawScreenFinalTexture(HWD_SCREENTEXTURE_GENERIC2, width, height);
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ void HWR_DrawIntermissionBG(void);
|
||||
void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum);
|
||||
void HWR_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize);
|
||||
void HWR_MakeScreenFinalTexture(void);
|
||||
void HWR_DrawScreenFinalTexture(int width, int height);
|
||||
void HWR_DrawScreenFinalTexture(INT32 width, INT32 height);
|
||||
|
||||
// hw_main.c: Planes
|
||||
void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, FBITFIELD PolyFlags, INT32 lightlevel, lumpnum_t lumpnum, sector_t *FOFsector, UINT8 alpha, extracolormap_t *planecolormap);
|
||||
@@ -170,6 +170,7 @@ void HWR_SetShaderState(void);
|
||||
|
||||
// Console variables
|
||||
extern consvar_t cv_grshaders;
|
||||
extern consvar_t cv_grframebuffer;
|
||||
extern consvar_t cv_grfofcut;
|
||||
extern consvar_t cv_fofzfightfix;
|
||||
extern consvar_t cv_splitwallfix;
|
||||
|
||||
@@ -114,6 +114,10 @@ static GLfloat projMatrix[16];
|
||||
static GLint viewport[4];
|
||||
|
||||
|
||||
GLuint FramebufferObject, FramebufferTexture, RenderbufferObject;
|
||||
GLboolean FrameBufferEnabled = GL_FALSE, RenderToFramebuffer = GL_FALSE;
|
||||
|
||||
|
||||
// Sryder: NextTexAvail is broken for these because palette changes or changes to the texture filter or antialiasing
|
||||
// flush all of the stored textures, leaving them unavailable at times such as between levels
|
||||
// These need to start at 0 and be set to their number, and be reset to 0 when deleted so that Intel GPUs
|
||||
@@ -308,6 +312,19 @@ static void GL_MSG_Error(const char *format, ...)
|
||||
#define pglCopyTexImage2D glCopyTexImage2D
|
||||
#define pglCopyTexSubImage2D glCopyTexSubImage2D
|
||||
|
||||
/* 3.0 functions for framebuffers and renderbuffers */
|
||||
#define pglGenFramebuffers glGenFramebuffers
|
||||
#define pglBindFramebuffer glBindFramebuffer
|
||||
#define pglDeleteFramebuffers glDeleteFramebuffers
|
||||
#define pglFramebufferTexture2D glFramebufferTexture2D
|
||||
#define pglCheckFramebufferStatus glCheckFramebufferStatus
|
||||
#define pglGenRenderbuffers glGenRenderbuffers
|
||||
#define pglBindRenderbuffer glBindRenderbuffer
|
||||
#define pglDeleteRenderbuffers glDeleteRenderbuffers
|
||||
#define pglRenderbufferStorage glRenderbufferStorage
|
||||
#define pglFramebufferRenderbuffer glFramebufferRenderbuffer
|
||||
|
||||
|
||||
#else //!STATIC_OPENGL
|
||||
|
||||
/* 1.0 functions */
|
||||
@@ -431,6 +448,28 @@ static PFNglCopyTexSubImage2D pglCopyTexSubImage2D;
|
||||
typedef void (APIENTRY * PFNglGenerateMipmap) (GLenum target);
|
||||
static PFNglGenerateMipmap pglGenerateMipmap;
|
||||
|
||||
/* 3.0 functions for framebuffers and renderbuffers */
|
||||
typedef void (APIENTRY * PFNglGenFramebuffers) (GLsizei n, GLuint *ids);
|
||||
static PFNglGenFramebuffers pglGenFramebuffers;
|
||||
typedef void (APIENTRY * PFNglBindFramebuffer) (GLenum target, GLuint framebuffer);
|
||||
static PFNglBindFramebuffer pglBindFramebuffer;
|
||||
typedef void (APIENTRY * PFNglDeleteFramebuffers) (GLsizei n, GLuint *ids);
|
||||
static PFNglDeleteFramebuffers pglDeleteFramebuffers;
|
||||
typedef void (APIENTRY * PFNglFramebufferTexture2D) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
|
||||
static PFNglFramebufferTexture2D pglFramebufferTexture2D;
|
||||
typedef GLenum (APIENTRY * PFNglCheckFramebufferStatus) (GLenum target);
|
||||
static PFNglCheckFramebufferStatus pglCheckFramebufferStatus;
|
||||
typedef void (APIENTRY * PFNglGenRenderbuffers) (GLsizei n, GLuint *renderbuffers);
|
||||
static PFNglGenRenderbuffers pglGenRenderbuffers;
|
||||
typedef void (APIENTRY * PFNglBindRenderbuffer) (GLenum target, GLuint renderbuffer);
|
||||
static PFNglBindRenderbuffer pglBindRenderbuffer;
|
||||
typedef void (APIENTRY * PFNglDeleteRenderbuffers) (GLsizei n, GLuint *renderbuffers);
|
||||
static PFNglDeleteRenderbuffers pglDeleteRenderbuffers;
|
||||
typedef void (APIENTRY * PFNglRenderbufferStorage) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
|
||||
static PFNglRenderbufferStorage pglRenderbufferStorage;
|
||||
typedef void (APIENTRY * PFNglFramebufferRenderbuffer) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLenum renderbuffer);
|
||||
static PFNglFramebufferRenderbuffer pglFramebufferRenderbuffer;
|
||||
|
||||
/* 1.2 functions for 3D textures */
|
||||
typedef void (APIENTRY * PFNglTexImage3D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
|
||||
static PFNglTexImage3D pglTexImage3D;
|
||||
@@ -492,6 +531,17 @@ boolean SetupGLfunc(void)
|
||||
GL_MSG_Warning("failed to get OpenGL function: %s", #proc); \
|
||||
} \
|
||||
|
||||
GETOPENGLFUNC(pglGenFramebuffers, glGenFramebuffers);
|
||||
GETOPENGLFUNC(pglBindFramebuffer, glBindFramebuffer);
|
||||
GETOPENGLFUNC(pglDeleteFramebuffers, glDeleteFramebuffers);
|
||||
GETOPENGLFUNC(pglFramebufferTexture2D, glFramebufferTexture2D);
|
||||
GETOPENGLFUNC(pglCheckFramebufferStatus, glCheckFramebufferStatus);
|
||||
GETOPENGLFUNC(pglGenRenderbuffers, glGenRenderbuffers);
|
||||
GETOPENGLFUNC(pglBindRenderbuffer, glBindRenderbuffer);
|
||||
GETOPENGLFUNC(pglDeleteRenderbuffers, glDeleteRenderbuffers);
|
||||
GETOPENGLFUNC(pglRenderbufferStorage, glRenderbufferStorage);
|
||||
GETOPENGLFUNC(pglFramebufferRenderbuffer, glFramebufferRenderbuffer);
|
||||
|
||||
GETOPENGLFUNC(pglClearColor, glClearColor)
|
||||
|
||||
GETOPENGLFUNC(pglClear, glClear)
|
||||
@@ -743,6 +793,17 @@ void SetupGLFunc4(void)
|
||||
#endif
|
||||
|
||||
pglGenerateMipmap = GetGLFunc("glGenerateMipmap");
|
||||
|
||||
pglGenFramebuffers = GetGLFunc("glGenFramebuffers");
|
||||
pglBindFramebuffer = GetGLFunc("glBindFramebuffer");
|
||||
pglDeleteFramebuffers = GetGLFunc("glDeleteFramebuffers");
|
||||
pglFramebufferTexture2D = GetGLFunc("glFramebufferTexture2D");
|
||||
pglCheckFramebufferStatus = GetGLFunc("glCheckFramebufferStatus");
|
||||
pglGenRenderbuffers = GetGLFunc("glGenRenderbuffers");
|
||||
pglBindRenderbuffer = GetGLFunc("glBindRenderbuffer");
|
||||
pglDeleteRenderbuffers = GetGLFunc("glDeleteRenderbuffers");
|
||||
pglRenderbufferStorage = GetGLFunc("glRenderbufferStorage");
|
||||
pglFramebufferRenderbuffer = GetGLFunc("glFramebufferRenderbuffer");
|
||||
}
|
||||
|
||||
EXPORT boolean HWRAPI(InitShaders) (void)
|
||||
@@ -934,13 +995,6 @@ void SetModelView(GLint w, GLint h)
|
||||
{
|
||||
//GL_DBG_Printf("SetModelView(): %dx%d\n", (int)w, (int)h);
|
||||
|
||||
// The screen textures need to be flushed if the width or height change so that they be remade for the correct size
|
||||
if (screen_width != w || screen_height != h)
|
||||
FlushScreenTextures();
|
||||
|
||||
screen_width = w;
|
||||
screen_height = h;
|
||||
|
||||
pglViewport(0, 0, w, h);
|
||||
|
||||
pglMatrixMode(GL_PROJECTION);
|
||||
@@ -992,6 +1046,98 @@ void SetStates(void)
|
||||
pglGetFloatv(GL_MODELVIEW_MATRIX, modelMatrix); // added for new coronas' code (without depth buffer)
|
||||
}
|
||||
|
||||
void GLFramebuffer_Generate(void)
|
||||
{
|
||||
// Generate the framebuffer
|
||||
if (FramebufferObject == 0)
|
||||
pglGenFramebuffers(1, &FramebufferObject);
|
||||
|
||||
if (pglCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE)
|
||||
GLFramebuffer_GenerateAttachments();
|
||||
}
|
||||
|
||||
void GLFramebuffer_Delete(void)
|
||||
{
|
||||
// Unbind the framebuffer
|
||||
pglBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
if (FramebufferObject)
|
||||
pglDeleteFramebuffers(1, &FramebufferObject);
|
||||
|
||||
GLFramebuffer_DeleteAttachments();
|
||||
FramebufferObject = 0;
|
||||
}
|
||||
|
||||
void GLFramebuffer_GenerateAttachments(void)
|
||||
{
|
||||
// Bind the framebuffer
|
||||
pglBindFramebuffer(GL_FRAMEBUFFER, FramebufferObject);
|
||||
|
||||
// Generate the framebuffer texture
|
||||
if (FramebufferTexture == 0)
|
||||
{
|
||||
pglGenTextures(1, &FramebufferTexture);
|
||||
pglBindTexture(GL_TEXTURE_2D, FramebufferTexture);
|
||||
pglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screen_width, screen_height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
||||
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
pglBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
// Attach the framebuffer texture to the framebuffer
|
||||
pglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, FramebufferTexture, 0);
|
||||
}
|
||||
|
||||
// Generate the renderbuffer
|
||||
if (RenderbufferObject == 0)
|
||||
{
|
||||
pglGenRenderbuffers(1, &RenderbufferObject);
|
||||
|
||||
pglBindRenderbuffer(GL_RENDERBUFFER, RenderbufferObject);
|
||||
pglRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, screen_width, screen_height);
|
||||
pglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, RenderbufferObject);
|
||||
|
||||
// Clear the renderbuffer
|
||||
ClearBuffer(true, true, true, NULL);
|
||||
|
||||
pglBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
}
|
||||
|
||||
// Unbind the framebuffer
|
||||
pglBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
void GLFramebuffer_DeleteAttachments(void)
|
||||
{
|
||||
// Unbind the framebuffer
|
||||
pglBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
if (FramebufferTexture)
|
||||
pglDeleteTextures(1, &FramebufferTexture);
|
||||
|
||||
if (RenderbufferObject)
|
||||
pglDeleteRenderbuffers(1, &RenderbufferObject);
|
||||
|
||||
FramebufferTexture = 0;
|
||||
RenderbufferObject = 0;
|
||||
}
|
||||
|
||||
void GLFramebuffer_Enable(void)
|
||||
{
|
||||
if (FramebufferObject == 0)
|
||||
GLFramebuffer_Generate();
|
||||
else if (FramebufferTexture == 0 || RenderbufferObject == 0)
|
||||
GLFramebuffer_GenerateAttachments();
|
||||
|
||||
pglBindFramebuffer(GL_FRAMEBUFFER, FramebufferObject);
|
||||
pglBindRenderbuffer(GL_RENDERBUFFER, RenderbufferObject);
|
||||
}
|
||||
|
||||
void GLFramebuffer_Disable(void)
|
||||
{
|
||||
pglBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
pglBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
}
|
||||
|
||||
// -----------------+
|
||||
// Flush : flush OpenGL textures
|
||||
// : Clear list of downloaded mipmaps
|
||||
@@ -2156,6 +2302,10 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value)
|
||||
case HWD_SET_SHADERS:
|
||||
gl_allowshaders = Value;
|
||||
break;
|
||||
|
||||
case HWD_SET_FRAMEBUFFER:
|
||||
FrameBufferEnabled = Value ? GL_TRUE : GL_FALSE;
|
||||
break;
|
||||
|
||||
case HWD_SET_TEXTUREFILTERMODE:
|
||||
switch (Value)
|
||||
@@ -3189,7 +3339,7 @@ EXPORT void HWRAPI(MakeScreenTexture) (int tex)
|
||||
tex_downloaded = screenTextures[tex];
|
||||
}
|
||||
|
||||
EXPORT void HWRAPI(DrawScreenFinalTexture)(int tex, int width, int height)
|
||||
EXPORT void HWRAPI(DrawScreenFinalTexture)(int tex, INT32 width, INT32 height)
|
||||
{
|
||||
float xfix, yfix;
|
||||
float origaspect, newaspect;
|
||||
|
||||
@@ -104,6 +104,18 @@ static PFNglEnableClientState pglEnableClientState;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void GLFramebuffer_Generate(void);
|
||||
void GLFramebuffer_Delete(void);
|
||||
|
||||
void GLFramebuffer_GenerateAttachments(void);
|
||||
void GLFramebuffer_DeleteAttachments(void);
|
||||
|
||||
void GLFramebuffer_Enable(void);
|
||||
void GLFramebuffer_Disable(void);
|
||||
|
||||
extern GLuint FramebufferObject, FramebufferTexture, RenderbufferObject;
|
||||
extern GLboolean FrameBufferEnabled, RenderToFramebuffer;
|
||||
|
||||
// ==========================================================================
|
||||
// GLOBAL
|
||||
// ==========================================================================
|
||||
|
||||
+24
-1
@@ -164,10 +164,26 @@ boolean OglSdlSurface(INT32 w, INT32 h)
|
||||
granisotropicmode_cons_t[1].value = maximumAnisotropy;
|
||||
|
||||
SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0);
|
||||
|
||||
// The screen textures need to be flushed if the width or height change so that they be remade for the correct size
|
||||
if (screen_width != w || screen_height != h)
|
||||
{
|
||||
FlushScreenTextures();
|
||||
GLFramebuffer_DeleteAttachments();
|
||||
}
|
||||
|
||||
screen_width = (GLint)w;
|
||||
screen_height = (GLint)h;
|
||||
|
||||
SetModelView(w, h);
|
||||
SetStates();
|
||||
pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
RenderToFramebuffer = FrameBufferEnabled;
|
||||
GLFramebuffer_Disable();
|
||||
|
||||
if (RenderToFramebuffer)
|
||||
GLFramebuffer_Enable();
|
||||
|
||||
HWR_Startup();
|
||||
textureformatGL = cbpp > 16 ? GL_RGBA : GL_RGB5_A1;
|
||||
@@ -193,9 +209,16 @@ void OglSdlFinishUpdate(boolean waitvbl)
|
||||
oldwaitvbl = waitvbl;
|
||||
|
||||
SDL_GetWindowSize(window, &sdlw, &sdlh);
|
||||
|
||||
HWR_MakeScreenFinalTexture();
|
||||
|
||||
GLFramebuffer_Disable();
|
||||
RenderToFramebuffer = FrameBufferEnabled;
|
||||
|
||||
HWR_DrawScreenFinalTexture(sdlw, sdlh);
|
||||
|
||||
if (RenderToFramebuffer)
|
||||
GLFramebuffer_Enable();
|
||||
|
||||
SDL_GL_SwapWindow(window);
|
||||
|
||||
GClipRect(0, 0, realwidth, realheight, NZCLIP_PLANE, FAR_ZCLIP_DEFAULT);
|
||||
|
||||
Reference in new issue
Block a user