This commit is contained in:
nashmuhandes 2016-05-01 10:43:54 +08:00
commit 4a2a0cf2e3
19 changed files with 1867 additions and 1629 deletions

View file

@ -59,7 +59,8 @@ struct FGLLinePortal
// defines the complete span of this portal
vertex_t *v1, *v2; // vertices, from v1 to v2
DVector2 delta; // precalculated v2 - v1 for side checking
FLinePortal *reference; // one of the associated line portals, for retrieving translation info etc.
TArray<FLinePortal *> lines;
int validcount = 0;
};
extern TArray<FPortal *> portals;

View file

@ -443,7 +443,12 @@ void gl_InitPortals()
tempindex[i] = glLinePortals.Size();
line_t *pSrcLine = linePortals[i].mOrigin;
line_t *pLine = linePortals[i].mDestination;
FGLLinePortal glport = { pLine->v1, pLine->v2, {0, 0}, &linePortals[i] };
FGLLinePortal glport;
glport.v1 = pLine->v1;
glport.v2 = pLine->v2;
glport.delta = { 0, 0 };
glport.lines.Push(&linePortals[i]);
glLinePortals.Push(glport);
// We cannot do this grouping for non-linked portals because they can be changed at run time.
@ -474,6 +479,7 @@ void gl_InitPortals()
tempindex[j] = tempindex[i];
if (pLine->v1 == pLine2->v2) glLinePortals[tempindex[i]].v1 = pLine2->v1;
else glLinePortals[tempindex[i]].v2 = pLine2->v2;
glLinePortals[tempindex[i]].lines.Push(&linePortals[j]);
}
}
}

View file

@ -122,6 +122,7 @@ void FGLRenderer::Initialize()
else mLights = NULL;
gl_RenderState.SetVertexBuffer(mVBO);
mFBID = 0;
mOldFBID = 0;
SetupLevel();
mShaderManager = new FShaderManager;
@ -237,6 +238,7 @@ void FGLRenderer::FlushTextures()
bool FGLRenderer::StartOffscreen()
{
if (mFBID == 0) glGenFramebuffers(1, &mFBID);
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &mOldFBID);
glBindFramebuffer(GL_FRAMEBUFFER, mFBID);
return true;
}
@ -249,7 +251,7 @@ bool FGLRenderer::StartOffscreen()
void FGLRenderer::EndOffscreen()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, mOldFBID);
}
//===========================================================================

View file

@ -71,6 +71,7 @@ public:
int gl_spriteindex;
unsigned int mFBID;
unsigned int mVAOID;
int mOldFBID;
FTexture *gllight;
FTexture *glpart2;

View file

@ -102,7 +102,7 @@ UniqueList<GLHorizonInfo> UniqueHorizons;
UniqueList<secplane_t> UniquePlaneMirrors;
UniqueList<FGLLinePortal> UniqueLineToLines;
void gl_RenderActorsInPortal(FGLLinePortal *glport);
//==========================================================================
//
@ -1003,7 +1003,7 @@ void GLLineToLinePortal::DrawContents()
GLRenderer->mClipPortal = this;
line_t *origin = glport->reference->mOrigin;
line_t *origin = glport->lines[0]->mOrigin;
P_TranslatePortalXY(origin, ViewPos.X, ViewPos.Y);
P_TranslatePortalAngle(origin, ViewAngle);
P_TranslatePortalZ(origin, ViewPos.Z);
@ -1038,17 +1038,22 @@ void GLLineToLinePortal::DrawContents()
currentmapsection[mapsection >> 3] |= 1 << (mapsection & 7);
}
GLRenderer->mViewActor = NULL;
GLRenderer->mViewActor = nullptr;
GLRenderer->SetupView(ViewPos.X, ViewPos.Y, ViewPos.Z, ViewAngle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));
ClearClipper();
gl_RenderState.SetClipLine(glport->reference->mDestination);
gl_RenderState.SetClipLine(glport->lines[0]->mDestination);
gl_RenderState.EnableClipLine(true);
GLRenderer->DrawScene();
gl_RenderState.EnableClipLine(false);
RestoreMapSection();
}
void GLLineToLinePortal::RenderAttached()
{
gl_RenderActorsInPortal(glport);
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//

View file

@ -169,6 +169,7 @@ public:
virtual int ClipSubsector(subsector_t *sub) { return PClip_Inside; }
virtual int ClipPoint(const DVector2 &pos) { return PClip_Inside; }
virtual line_t *ClipLine() { return NULL; }
virtual void RenderAttached() {}
static void BeginScene();
static void StartFrame();
@ -194,10 +195,10 @@ struct GLLinePortal : public GLPortal
GLLinePortal(FGLLinePortal *line)
{
if (line->reference->mType != PORTT_LINKED)
if (line->lines[0]->mType != PORTT_LINKED)
{
// For non-linked portals we must check the actual linedef.
line_t *lline = line->reference->mDestination;
line_t *lline = line->lines[0]->mDestination;
v1 = lline->v1;
v2 = lline->v2;
}
@ -258,6 +259,7 @@ protected:
virtual void * GetSource() const { return glport; }
virtual const char *GetName();
virtual line_t *ClipLine() { return line(); }
virtual void RenderAttached();
public:

View file

@ -308,6 +308,7 @@ void FGLRenderer::CreateScene()
R_SetView();
validcount++; // used for processing sidedefs only once by the renderer.
gl_RenderBSPNode (nodes + numnodes - 1);
if (GLRenderer->mCurrentPortal != NULL) GLRenderer->mCurrentPortal->RenderAttached();
Bsp.Unclock();
// And now the crappy hacks that have to be done to avoid rendering anomalies:

View file

@ -521,7 +521,7 @@ void GLSprite::PerformSpriteClipAdjustment(AActor *thing, const DVector2 &thingp
//
//==========================================================================
void GLSprite::Process(AActor* thing, sector_t * sector, bool thruportal)
void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal)
{
sector_t rs;
sector_t * rendersector;
@ -552,7 +552,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, bool thruportal)
// [RH] Interpolate the sprite's position to make it look smooth
DVector3 thingpos = thing->InterpolatedPosition(r_TicFracF);
if (thruportal) thingpos += Displacements.getOffset(thing->Sector->PortalGroup, sector->PortalGroup);
if (thruportal == 1) thingpos += Displacements.getOffset(thing->Sector->PortalGroup, sector->PortalGroup);
// Too close to the camera. This doesn't look good if it is a sprite.
if (fabs(thingpos.X - ViewPos.X) < 2 && fabs(thingpos.Y - ViewPos.Y) < 2)
@ -581,7 +581,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, bool thruportal)
thing->flags7 |= MF7_FLYCHEAT; // do this only once for the very first frame, but not if it gets into range again.
}
if (GLRenderer->mClipPortal)
if (thruportal != 2 && GLRenderer->mClipPortal)
{
int clipres = GLRenderer->mClipPortal->ClipPoint(thingpos);
if (clipres == GLPortal::PClip_InFront) return;
@ -601,7 +601,6 @@ void GLSprite::Process(AActor* thing, sector_t * sector, bool thruportal)
topclip = rendersector->PortalBlocksMovement(sector_t::ceiling) ? LARGE_VALUE : rendersector->GetPortalPlaneZ(sector_t::ceiling);
bottomclip = rendersector->PortalBlocksMovement(sector_t::floor) ? -LARGE_VALUE : rendersector->GetPortalPlaneZ(sector_t::floor);
x = thingpos.X;
z = thingpos.Z - thing->Floorclip;
y = thingpos.Y;
@ -1019,5 +1018,56 @@ void GLSprite::ProcessParticle (particle_t *particle, sector_t *sector)//, int s
rendered_sprites++;
}
//==========================================================================
//
//
//
//==========================================================================
void gl_RenderActorsInPortal(FGLLinePortal *glport)
{
TMap<AActor*, bool> processcheck;
if (glport->validcount == validcount) return; // only process once per frame
glport->validcount = validcount;
for (auto port : glport->lines)
{
line_t *line = port->mOrigin;
if (line->isLinePortal()) // only crossable ones
{
FLinePortal *port2 = port->mDestination->getPortal();
// process only if the other side links back to this one.
if (port2 != nullptr && port->mDestination == port2->mOrigin && port->mOrigin == port2->mDestination)
{
for (portnode_t *node = port->render_thinglist; node != nullptr; node = node->m_snext)
{
AActor *th = node->m_thing;
// process each actor only once per portal.
bool *check = processcheck.CheckKey(th);
if (check && *check) continue;
processcheck[th] = true;
DAngle savedangle = th->Angles.Yaw;
DVector3 savedpos = th->Pos();
DVector3 newpos = savedpos;
sector_t fakesector;
P_TranslatePortalXY(line, newpos.X, newpos.Y);
P_TranslatePortalZ(line, newpos.Z);
P_TranslatePortalAngle(line, th->Angles.Yaw);
th->SetXYZ(newpos);
th->Prev += newpos - savedpos;
GLSprite spr;
th->fillcolor = 0xff0000ff;
spr.Process(th, gl_FakeFlat(th->Sector, &fakesector, false), 2);
th->fillcolor = 0xffffffff;
th->Angles.Yaw = savedangle;
th->SetXYZ(savedpos);
th->Prev -= newpos - savedpos;
}
}
}
}
}

View file

@ -359,7 +359,7 @@ public:
void Draw(int pass);
void PutSprite(bool translucent);
void Process(AActor* thing,sector_t * sector, bool thruportal = false);
void Process(AActor* thing,sector_t * sector, int thruportal = false);
void ProcessParticle (particle_t *particle, sector_t *sector);//, int shade, int fakeside)
void SetThingColor(PalEntry);
@ -376,5 +376,6 @@ inline float Dist2(float x1,float y1,float x2,float y2)
void gl_SetDynSpriteLight(AActor *self, float x, float y, float z, subsector_t *subsec);
void gl_SetDynSpriteLight(AActor *actor, particle_t *particle);
void gl_RenderActorsInPortal(FGLLinePortal *glport);
#endif

View file

@ -214,7 +214,15 @@ void GLWall::PutPortal(int ptype)
case PORTALTYPE_LINETOLINE:
portal=GLPortal::FindPortal(lineportal);
if (!portal) portal=new GLLineToLinePortal(lineportal);
if (!portal)
{
line_t *otherside = lineportal->lines[0]->mDestination;
if (otherside != NULL)
{
gl_RenderActorsInPortal(linePortalToGL[otherside->portalindex]);
}
portal = new GLLineToLinePortal(lineportal);
}
portal->AddLine(this);
break;

View file

@ -75,6 +75,7 @@ void PatchCommon(FString &code)
void PatchVertShader(FString &code)
{
PatchCommon(code);
code.Substitute("in vec", "attribute vec");
code.Substitute("out vec", "varying vec");
code.Substitute("gl_ClipDistance", "//");
}

View file

@ -0,0 +1,14 @@
-- List of OpenGL extensions for glLoadGen
-- Generation of gl_load.c and gl_load.h files:
-- > lua LoadGen.lua -style=pointer_c -spec=gl -version=3.3 -profile=compatibility -extfile=gl_extlist.txt load
APPLE_client_storage
ARB_buffer_storage
ARB_shader_storage_buffer_object
ARB_texture_compression
ARB_texture_rectangle
EXT_framebuffer_object
EXT_texture_compression_s3tc
EXT_texture_filter_anisotropic
EXT_texture_sRGB

View file

@ -130,12 +130,9 @@ void OpenGLFrameBuffer::InitializeState()
if (first)
{
first=false;
// [BB] For some reason this crashes, if compiled with MinGW and optimization. Has to be investigated.
#ifdef _MSC_VER
gl_PrintStartupLog();
#endif
}
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glDepthFunc(GL_LESS);

View file

@ -236,12 +236,23 @@ void gl_LoadExtensions()
}
int v;
glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &v);
gl.maxuniforms = v;
glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &v);
gl.maxuniformblock = v;
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &v);
gl.uniformblockalignment = v;
if (gl.lightmethod != LM_SOFTWARE && !(gl.flags & RFL_SHADER_STORAGE_BUFFER))
{
glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &v);
gl.maxuniforms = v;
glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &v);
gl.maxuniformblock = v;
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &v);
gl.uniformblockalignment = v;
}
else
{
gl.maxuniforms = 0;
gl.maxuniformblock = 0;
gl.uniformblockalignment = 0;
}
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl.max_texturesize);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@ -289,21 +300,24 @@ void gl_PrintStartupLog()
Printf("\nMax. texture size: %d\n", v);
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &v);
Printf ("Max. texture units: %d\n", v);
glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &v);
Printf ("Max. fragment uniforms: %d\n", v);
glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, &v);
Printf ("Max. vertex uniforms: %d\n", v);
glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &v);
Printf ("Max. uniform block size: %d\n", v);
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &v);
Printf ("Uniform block alignment: %d\n", v);
glGetIntegerv(GL_MAX_VARYING_FLOATS, &v);
Printf ("Max. varying: %d\n", v);
glGetIntegerv(GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS, &v);
Printf("Max. combined shader storage blocks: %d\n", v);
glGetIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &v);
Printf("Max. vertex shader storage blocks: %d\n", v);
if (gl.lightmethod != LM_SOFTWARE && !(gl.flags & RFL_SHADER_STORAGE_BUFFER))
{
glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &v);
Printf ("Max. uniform block size: %d\n", v);
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &v);
Printf ("Uniform block alignment: %d\n", v);
}
if (gl.flags & RFL_SHADER_STORAGE_BUFFER)
{
glGetIntegerv(GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS, &v);
Printf("Max. combined shader storage blocks: %d\n", v);
glGetIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &v);
Printf("Max. vertex shader storage blocks: %d\n", v);
}
// For shader-less, the special alphatexture translation must be changed to actually set the alpha, because it won't get translated by a shader.
if (gl.glslversion == 0)

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -86,9 +86,6 @@ template <typename T>
inline T max( T a, T b) { return (((a)>(b)) ? (a) : (b)); }
#define _access(a,b) access(a,b)
#endif
#ifndef _WIN32
#include <SDL.h>
#endif
#ifdef LoadMenu

View file

@ -372,16 +372,7 @@ private:
// ---------------------------------------------------------------------------
struct CapabilityChecker
{
CapabilityChecker();
};
// ---------------------------------------------------------------------------
class CocoaOpenGLFrameBuffer : public OpenGLFrameBuffer, private CapabilityChecker, private NonCopyable
class CocoaOpenGLFrameBuffer : public OpenGLFrameBuffer, private NonCopyable
{
typedef OpenGLFrameBuffer Super;
@ -1163,12 +1154,14 @@ SDLGLFB::SDLGLFB(void*, const int width, const int height, int, int, const bool
, m_lock(-1)
, m_isUpdatePending(false)
, m_supportsGamma(true)
, m_gammaTexture(GAMMA_TABLE_SIZE, 1, false, false, true, true)
, m_gammaProgram("gamma_correction")
, m_gammaTexture(GAMMA_TABLE_SIZE, 1, true)
{
}
SDLGLFB::SDLGLFB()
: m_gammaTexture(0, 0, false, false, false, false)
: m_gammaProgram(nullptr)
, m_gammaTexture(0, 0, false)
{
}
@ -1392,7 +1385,7 @@ bool BoundTextureSaveAsPNG(const GLenum target, const char* const path)
RenderTarget::RenderTarget(const GLsizei width, const GLsizei height)
: m_ID(0)
, m_oldID(0)
, m_texture(width, height, false, false, true, true)
, m_texture(width, height, true)
{
glGenFramebuffersEXT(1, &m_ID);
@ -1438,26 +1431,12 @@ GLuint RenderTarget::GetBoundID()
// ---------------------------------------------------------------------------
CapabilityChecker::CapabilityChecker()
{
if (!(gl.flags & RFL_FRAMEBUFFER))
{
I_FatalError(
"The graphics hardware in your system does not support Frame Buffer Object (FBO).\n"
"It is required to run this version of " GAMENAME ".\n");
}
}
// ---------------------------------------------------------------------------
CocoaOpenGLFrameBuffer::CocoaOpenGLFrameBuffer(void* hMonitor, int width, int height, int bits, int refreshHz, bool fullscreen)
: OpenGLFrameBuffer(hMonitor, width, height, bits, refreshHz, fullscreen)
, m_renderTarget(width, height)
{
SetSmoothPicture(gl_smooth_rendered);
/*
// Setup uniform samplers for gamma correction shader
m_gammaProgram.Load("GammaCorrection", "shaders/glsl/main.vp",
@ -1469,7 +1448,7 @@ CocoaOpenGLFrameBuffer::CocoaOpenGLFrameBuffer(void* hMonitor, int width, int he
glUniform1i(glGetUniformLocation(program, "backbuffer"), 0);
glUniform1i(glGetUniformLocation(program, "gammaTable"), 1);
glUseProgram(0);
*/
// Fill render target with black color
m_renderTarget.Bind();
@ -1524,8 +1503,8 @@ void CocoaOpenGLFrameBuffer::DrawRenderTarget()
{
m_renderTarget.Unbind();
m_renderTarget.GetColorTexture().Bind(0, 0);
m_gammaTexture.Bind(1, 0);
m_renderTarget.GetColorTexture().Bind(0, 0, 0);
m_gammaTexture.Bind(1, 0, 0);
if (rbOpts.dirty)
{
@ -1539,7 +1518,7 @@ void CocoaOpenGLFrameBuffer::DrawRenderTarget()
glViewport(rbOpts.shiftX, rbOpts.shiftY, rbOpts.width, rbOpts.height);
m_gammaProgram.Bind(0.0f);
//m_gammaProgram.Bind();
BoundTextureDraw2D(Width, Height);
glViewport(0, 0, Width, Height);
@ -1549,7 +1528,7 @@ void CocoaOpenGLFrameBuffer::DrawRenderTarget()
void CocoaOpenGLFrameBuffer::SetSmoothPicture(const bool smooth)
{
FHardwareTexture& texture = m_renderTarget.GetColorTexture();
texture.Bind(0, 0);
texture.Bind(0, 0, 0);
BoundTextureSetFilter(GL_TEXTURE_2D, smooth ? GL_LINEAR : GL_NEAREST);
}

View file

@ -0,0 +1,90 @@
/*
** sdlglvideo.h
**
**---------------------------------------------------------------------------
** Copyright 2012-2014 Alexey Lysiuk
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3. The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**---------------------------------------------------------------------------
**
*/
// IMPORTANT NOTE!
// This file was intentially named sdlglvideo.h but it has nothing with SDL
// The name was selected to avoid spreding of changes over the project
// The same applies to SDLGLFB class
// See gl/system/gl_framebuffer.h for details about its usage
#ifndef COCOA_SDLGLVIDEO_H_INCLUDED
#define COCOA_SDLGLVIDEO_H_INCLUDED
#include "v_video.h"
#include "gl/shaders/gl_shader.h"
#include "gl/textures/gl_hwtexture.h"
class SDLGLFB : public DFrameBuffer
{
public:
// This must have the same parameters as the Windows version, even if they are not used!
SDLGLFB(void *hMonitor, int width, int height, int, int, bool fullscreen);
~SDLGLFB();
virtual bool Lock(bool buffered = true);
virtual void Unlock();
virtual bool IsLocked();
virtual bool IsFullscreen();
virtual void SetVSync(bool vsync);
int GetTrueHeight() { return GetHeight(); }
protected:
int m_lock;
bool m_isUpdatePending;
bool m_supportsGamma;
FShader m_gammaProgram;
FHardwareTexture m_gammaTexture;
static const size_t GAMMA_TABLE_SIZE = 256;
uint32_t m_gammaTable[GAMMA_TABLE_SIZE];
SDLGLFB();
void InitializeState();
bool CanUpdate();
void SwapBuffers();
void SetGammaTable(WORD* table);
};
#endif // COCOA_SDLGLVIDEO_H_INCLUDED