2013-06-23 07:49:34 +00:00
|
|
|
/*
|
|
|
|
** gl1_renderer.cpp
|
|
|
|
** Renderer interface
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2008 Christoph Oelckers
|
|
|
|
** 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.
|
|
|
|
** 4. When not used as part of GZDoom or a GZDoom derivative, this code will be
|
|
|
|
** covered by the terms of the GNU Lesser General Public License as published
|
|
|
|
** by the Free Software Foundation; either version 2.1 of the License, or (at
|
|
|
|
** your option) any later version.
|
|
|
|
** 5. Full disclosure of the entire project's source code, except for third
|
|
|
|
** party libraries is mandatory. (NOTE: This clause is non-negotiable!)
|
|
|
|
**
|
|
|
|
** 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.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gl/system/gl_system.h"
|
|
|
|
#include "files.h"
|
|
|
|
#include "m_swap.h"
|
|
|
|
#include "v_video.h"
|
|
|
|
#include "r_data/r_translate.h"
|
|
|
|
#include "m_png.h"
|
|
|
|
#include "m_crc32.h"
|
|
|
|
#include "w_wad.h"
|
|
|
|
//#include "gl/gl_intern.h"
|
|
|
|
#include "gl/gl_functions.h"
|
|
|
|
#include "vectors.h"
|
|
|
|
|
2013-09-03 16:29:39 +00:00
|
|
|
#include "gl/system/gl_interface.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
#include "gl/system/gl_framebuffer.h"
|
|
|
|
#include "gl/system/gl_threads.h"
|
2014-05-20 22:36:04 +00:00
|
|
|
#include "gl/system/gl_cvars.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
#include "gl/renderer/gl_renderer.h"
|
|
|
|
#include "gl/renderer/gl_lightdata.h"
|
|
|
|
#include "gl/renderer/gl_renderstate.h"
|
|
|
|
#include "gl/data/gl_data.h"
|
|
|
|
#include "gl/data/gl_vertexbuffer.h"
|
|
|
|
#include "gl/dynlights/gl_lightbuffer.h"
|
|
|
|
#include "gl/scene/gl_drawinfo.h"
|
|
|
|
#include "gl/shaders/gl_shader.h"
|
|
|
|
#include "gl/textures/gl_texture.h"
|
|
|
|
#include "gl/textures/gl_translate.h"
|
|
|
|
#include "gl/textures/gl_material.h"
|
|
|
|
#include "gl/utility/gl_clock.h"
|
|
|
|
#include "gl/utility/gl_templates.h"
|
|
|
|
#include "gl/models/gl_models.h"
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// Renderer interface
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
EXTERN_CVAR(Bool, gl_render_segs)
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Initialize
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2013-08-18 13:41:52 +00:00
|
|
|
FGLRenderer::FGLRenderer(OpenGLFrameBuffer *fb)
|
|
|
|
{
|
|
|
|
framebuffer = fb;
|
|
|
|
mCurrentPortal = NULL;
|
|
|
|
mMirrorCount = 0;
|
|
|
|
mPlaneMirrorCount = 0;
|
|
|
|
mLightCount = 0;
|
|
|
|
mAngles = FRotator(0,0,0);
|
|
|
|
mViewVector = FVector2(0,0);
|
|
|
|
mCameraPos = FVector3(0,0,0);
|
|
|
|
mVBO = NULL;
|
2014-06-13 23:24:28 +00:00
|
|
|
mSkyVBO = NULL;
|
2013-08-18 13:41:52 +00:00
|
|
|
gl_spriteindex = 0;
|
|
|
|
mShaderManager = NULL;
|
|
|
|
glpart2 = glpart = gllight = mirrortexture = NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
void FGLRenderer::Initialize()
|
|
|
|
{
|
|
|
|
glpart2 = FTexture::CreateTexture(Wads.GetNumForFullName("glstuff/glpart2.png"), FTexture::TEX_MiscPatch);
|
|
|
|
glpart = FTexture::CreateTexture(Wads.GetNumForFullName("glstuff/glpart.png"), FTexture::TEX_MiscPatch);
|
|
|
|
mirrortexture = FTexture::CreateTexture(Wads.GetNumForFullName("glstuff/mirror.png"), FTexture::TEX_MiscPatch);
|
|
|
|
gllight = FTexture::CreateTexture(Wads.GetNumForFullName("glstuff/gllight.png"), FTexture::TEX_MiscPatch);
|
|
|
|
|
|
|
|
mVBO = new FFlatVertexBuffer;
|
2014-06-13 23:24:28 +00:00
|
|
|
mSkyVBO = new FSkyVertexBuffer;
|
2014-05-20 22:36:04 +00:00
|
|
|
gl_RenderState.SetVertexBuffer(mVBO);
|
2013-06-23 07:49:34 +00:00
|
|
|
mFBID = 0;
|
|
|
|
SetupLevel();
|
|
|
|
mShaderManager = new FShaderManager;
|
|
|
|
//mThreadManager = new FGLThreadManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
FGLRenderer::~FGLRenderer()
|
|
|
|
{
|
|
|
|
gl_DeleteAllAttachedLights();
|
|
|
|
FMaterial::FlushAll();
|
|
|
|
//if (mThreadManager != NULL) delete mThreadManager;
|
|
|
|
if (mShaderManager != NULL) delete mShaderManager;
|
|
|
|
if (mVBO != NULL) delete mVBO;
|
2014-06-13 23:24:28 +00:00
|
|
|
if (mSkyVBO != NULL) delete mSkyVBO;
|
2013-06-23 07:49:34 +00:00
|
|
|
if (glpart2) delete glpart2;
|
|
|
|
if (glpart) delete glpart;
|
|
|
|
if (mirrortexture) delete mirrortexture;
|
|
|
|
if (gllight) delete gllight;
|
2013-09-03 16:29:39 +00:00
|
|
|
if (mFBID != 0) glDeleteFramebuffers(1, &mFBID);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void FGLRenderer::SetupLevel()
|
|
|
|
{
|
|
|
|
mVBO->CreateVBO();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FGLRenderer::Begin2D()
|
|
|
|
{
|
|
|
|
gl_RenderState.EnableFog(false);
|
|
|
|
gl_RenderState.Set2DMode(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void FGLRenderer::ProcessLowerMiniseg(seg_t *seg, sector_t * frontsector, sector_t * backsector)
|
|
|
|
{
|
|
|
|
GLWall wall;
|
|
|
|
wall.ProcessLowerMiniseg(seg, frontsector, backsector);
|
|
|
|
rendered_lines++;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void FGLRenderer::ProcessSprite(AActor *thing, sector_t *sector)
|
|
|
|
{
|
|
|
|
GLSprite glsprite;
|
|
|
|
glsprite.Process(thing, sector);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void FGLRenderer::ProcessParticle(particle_t *part, sector_t *sector)
|
|
|
|
{
|
|
|
|
GLSprite glsprite;
|
|
|
|
glsprite.ProcessParticle(part, sector);//, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void FGLRenderer::ProcessSector(sector_t *fakesector)
|
|
|
|
{
|
|
|
|
GLFlat glflat;
|
|
|
|
glflat.ProcessSector(fakesector);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void FGLRenderer::FlushTextures()
|
|
|
|
{
|
|
|
|
FMaterial::FlushAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
bool FGLRenderer::StartOffscreen()
|
|
|
|
{
|
2014-06-21 13:50:32 +00:00
|
|
|
if (mFBID == 0) glGenFramebuffers(1, &mFBID);
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, mFBID);
|
|
|
|
return true;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void FGLRenderer::EndOffscreen()
|
|
|
|
{
|
2014-06-21 13:50:32 +00:00
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
unsigned char *FGLRenderer::GetTextureBuffer(FTexture *tex, int &w, int &h)
|
|
|
|
{
|
|
|
|
FMaterial * gltex = FMaterial::ValidateTexture(tex);
|
|
|
|
if (gltex)
|
|
|
|
{
|
2014-05-11 17:44:19 +00:00
|
|
|
return gltex->CreateTexBuffer(0, w, h);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void FGLRenderer::ClearBorders()
|
|
|
|
{
|
|
|
|
OpenGLFrameBuffer *glscreen = static_cast<OpenGLFrameBuffer*>(screen);
|
|
|
|
|
|
|
|
// Letterbox time! Draw black top and bottom borders.
|
|
|
|
int width = glscreen->GetWidth();
|
|
|
|
int height = glscreen->GetHeight();
|
|
|
|
int trueHeight = glscreen->GetTrueHeight();
|
|
|
|
|
|
|
|
int borderHeight = (trueHeight - height) / 2;
|
|
|
|
|
2013-09-03 12:05:41 +00:00
|
|
|
glViewport(0, 0, width, trueHeight);
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
glOrtho(0.0, width * 1.0, 0.0, trueHeight, -1.0, 1.0);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2014-05-11 20:57:42 +00:00
|
|
|
gl_RenderState.SetColor(0.f ,0.f ,0.f ,1.f);
|
2013-06-23 07:49:34 +00:00
|
|
|
gl_RenderState.Set2DMode(true);
|
|
|
|
gl_RenderState.EnableTexture(false);
|
2014-05-11 20:57:42 +00:00
|
|
|
gl_RenderState.Apply();
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2014-06-14 23:14:41 +00:00
|
|
|
FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer();
|
|
|
|
ptr->Set(0, borderHeight, 0, 0, 0); ptr++;
|
|
|
|
ptr->Set(0, 0, 0, 0, 0); ptr++;
|
|
|
|
ptr->Set(width, 0, 0, 0, 0); ptr++;
|
|
|
|
ptr->Set(width, borderHeight, 0, 0, 0); ptr++;
|
|
|
|
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
|
|
|
|
ptr->Set(0, trueHeight, 0, 0, 0); ptr++;
|
|
|
|
ptr->Set(0, trueHeight - borderHeight, 0, 0, 0); ptr++;
|
|
|
|
ptr->Set(width, trueHeight - borderHeight, 0, 0, 0); ptr++;
|
|
|
|
ptr->Set(width, trueHeight, 0, 0, 0); ptr++;
|
|
|
|
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
|
2013-06-23 07:49:34 +00:00
|
|
|
gl_RenderState.EnableTexture(true);
|
|
|
|
|
2013-09-03 12:05:41 +00:00
|
|
|
glViewport(0, (trueHeight - height) / 2, width, height);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Draws a texture
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void FGLRenderer::DrawTexture(FTexture *img, DCanvas::DrawParms &parms)
|
|
|
|
{
|
|
|
|
double xscale = parms.destwidth / parms.texwidth;
|
|
|
|
double yscale = parms.destheight / parms.texheight;
|
|
|
|
double x = parms.x - parms.left * xscale;
|
|
|
|
double y = parms.y - parms.top * yscale;
|
|
|
|
double w = parms.destwidth;
|
|
|
|
double h = parms.destheight;
|
2014-05-11 20:57:42 +00:00
|
|
|
float u1, v1, u2, v2;
|
|
|
|
int light = 255;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
FMaterial * gltex = FMaterial::ValidateTexture(img);
|
|
|
|
|
|
|
|
if (parms.colorOverlay && (parms.colorOverlay & 0xffffff) == 0)
|
|
|
|
{
|
|
|
|
// Right now there's only black. Should be implemented properly later
|
2014-05-11 20:57:42 +00:00
|
|
|
light = 255 - APART(parms.colorOverlay);
|
2013-06-23 07:49:34 +00:00
|
|
|
parms.colorOverlay = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!img->bHasCanvas)
|
|
|
|
{
|
2014-05-11 20:57:42 +00:00
|
|
|
int translation = 0;
|
|
|
|
if (!parms.alphaChannel)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
if (parms.remap != NULL && !parms.remap->Inactive)
|
|
|
|
{
|
|
|
|
GLTranslationPalette * pal = static_cast<GLTranslationPalette*>(parms.remap->GetNative());
|
|
|
|
if (pal) translation = -pal->GetIndex();
|
|
|
|
}
|
|
|
|
}
|
2014-05-11 21:56:53 +00:00
|
|
|
gl_SetRenderStyle(parms.style, !parms.masked, false);
|
|
|
|
gltex->BindPatch(translation, 0, !!(parms.style.Flags & STYLEF_RedIsAlpha));
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
u1 = gltex->GetUL();
|
|
|
|
v1 = gltex->GetVT();
|
|
|
|
u2 = gltex->GetUR();
|
|
|
|
v2 = gltex->GetVB();
|
2014-05-11 21:56:53 +00:00
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-11 19:47:54 +00:00
|
|
|
gltex->Bind(0, 0);
|
2013-06-23 07:49:34 +00:00
|
|
|
u2=1.f;
|
|
|
|
v2=-1.f;
|
|
|
|
u1 = v1 = 0.f;
|
|
|
|
gl_RenderState.SetTextureMode(TM_OPAQUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parms.flipX)
|
|
|
|
{
|
|
|
|
float temp = u1;
|
|
|
|
u1 = u2;
|
|
|
|
u2 = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (parms.windowleft > 0 || parms.windowright < parms.texwidth)
|
|
|
|
{
|
|
|
|
x += parms.windowleft * xscale;
|
|
|
|
w -= (parms.texwidth - parms.windowright + parms.windowleft) * xscale;
|
|
|
|
|
|
|
|
u1 = float(u1 + parms.windowleft / parms.texwidth);
|
|
|
|
u2 = float(u2 - (parms.texwidth - parms.windowright) / parms.texwidth);
|
|
|
|
}
|
|
|
|
|
2014-05-11 20:57:42 +00:00
|
|
|
PalEntry color;
|
2013-06-23 07:49:34 +00:00
|
|
|
if (parms.style.Flags & STYLEF_ColorIsFixed)
|
|
|
|
{
|
2014-05-11 20:57:42 +00:00
|
|
|
color = parms.fillcolor;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-11 20:57:42 +00:00
|
|
|
color = PalEntry(light, light, light);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
2014-05-11 20:57:42 +00:00
|
|
|
color.a = Scale(parms.alpha, 255, FRACUNIT);
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
// scissor test doesn't use the current viewport for the coordinates, so use real screen coordinates
|
|
|
|
int btm = (SCREENHEIGHT - screen->GetHeight()) / 2;
|
|
|
|
btm = SCREENHEIGHT - btm;
|
|
|
|
|
2013-09-03 12:05:41 +00:00
|
|
|
glEnable(GL_SCISSOR_TEST);
|
2013-06-23 07:49:34 +00:00
|
|
|
int space = (static_cast<OpenGLFrameBuffer*>(screen)->GetTrueHeight()-screen->GetHeight())/2;
|
2013-09-03 12:05:41 +00:00
|
|
|
glScissor(parms.lclip, btm - parms.dclip + space, parms.rclip - parms.lclip, parms.dclip - parms.uclip);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2014-05-11 20:57:42 +00:00
|
|
|
gl_RenderState.SetColor(color);
|
2013-06-23 07:49:34 +00:00
|
|
|
gl_RenderState.EnableAlphaTest(false);
|
|
|
|
gl_RenderState.Apply();
|
2014-06-14 23:14:41 +00:00
|
|
|
|
|
|
|
FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer();
|
|
|
|
ptr->Set(x, y, 0, u1, v1); ptr++;
|
|
|
|
ptr->Set(x, y + h, 0, u1, v2); ptr++;
|
|
|
|
ptr->Set(x + w, y, 0, u2, v1); ptr++;
|
|
|
|
ptr->Set(x + w, y + h, 0, u2, v2); ptr++;
|
|
|
|
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
|
2014-05-20 22:36:04 +00:00
|
|
|
|
|
|
|
if (parms.colorOverlay)
|
|
|
|
{
|
|
|
|
gl_RenderState.SetTextureMode(TM_MASK);
|
|
|
|
gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
gl_RenderState.BlendEquation(GL_FUNC_ADD);
|
|
|
|
gl_RenderState.SetColor(PalEntry(parms.colorOverlay));
|
|
|
|
gl_RenderState.Apply();
|
|
|
|
|
2014-06-14 23:14:41 +00:00
|
|
|
FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer();
|
|
|
|
ptr->Set(x, y, 0, u1, v1); ptr++;
|
|
|
|
ptr->Set(x, y + h, 0, u1, v2); ptr++;
|
|
|
|
ptr->Set(x + w, y, 0, u2, v1); ptr++;
|
|
|
|
ptr->Set(x + w, y + h, 0, u2, v2); ptr++;
|
|
|
|
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
|
2014-05-20 22:36:04 +00:00
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
gl_RenderState.EnableAlphaTest(true);
|
|
|
|
|
2013-09-03 12:05:41 +00:00
|
|
|
glScissor(0, 0, screen->GetWidth(), screen->GetHeight());
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
2013-06-23 07:49:34 +00:00
|
|
|
gl_RenderState.SetTextureMode(TM_MODULATE);
|
|
|
|
gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
gl_RenderState.BlendEquation(GL_FUNC_ADD);
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
void FGLRenderer::DrawLine(int x1, int y1, int x2, int y2, int palcolor, uint32 color)
|
|
|
|
{
|
|
|
|
PalEntry p = color? (PalEntry)color : GPalette.BaseColors[palcolor];
|
|
|
|
gl_RenderState.EnableTexture(false);
|
2014-05-11 20:57:42 +00:00
|
|
|
gl_RenderState.SetColorAlpha(p, 1.f);
|
|
|
|
gl_RenderState.Apply();
|
2014-06-14 23:14:41 +00:00
|
|
|
|
|
|
|
FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer();
|
|
|
|
ptr->Set(x1, y1, 0, 0, 0); ptr++;
|
|
|
|
ptr->Set(x2, y2, 0, 0, 0); ptr++;
|
|
|
|
GLRenderer->mVBO->RenderCurrent(ptr, GL_LINES);
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
gl_RenderState.EnableTexture(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
void FGLRenderer::DrawPixel(int x1, int y1, int palcolor, uint32 color)
|
|
|
|
{
|
|
|
|
PalEntry p = color? (PalEntry)color : GPalette.BaseColors[palcolor];
|
|
|
|
gl_RenderState.EnableTexture(false);
|
2014-05-11 20:57:42 +00:00
|
|
|
gl_RenderState.SetColorAlpha(p, 1.f);
|
|
|
|
gl_RenderState.Apply();
|
2014-06-14 23:14:41 +00:00
|
|
|
|
|
|
|
FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer();
|
|
|
|
ptr->Set(x1, y1, 0, 0, 0); ptr++;
|
|
|
|
GLRenderer->mVBO->RenderCurrent(ptr, GL_POINTS);
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
gl_RenderState.EnableTexture(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void FGLRenderer::Dim(PalEntry color, float damount, int x1, int y1, int w, int h)
|
|
|
|
{
|
|
|
|
gl_RenderState.EnableTexture(false);
|
|
|
|
gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
gl_RenderState.AlphaFunc(GL_GREATER,0);
|
2014-05-11 20:57:42 +00:00
|
|
|
gl_RenderState.SetColorAlpha(color, damount);
|
|
|
|
gl_RenderState.Apply();
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2014-06-14 23:14:41 +00:00
|
|
|
FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer();
|
|
|
|
ptr->Set(x1, y1, 0, 0, 0); ptr++;
|
|
|
|
ptr->Set(x1, y1+h, 0, 0, 0); ptr++;
|
|
|
|
ptr->Set(x1+w, y1+h, 0, 0, 0); ptr++;
|
|
|
|
ptr->Set(x1+w, y1, 0, 0, 0); ptr++;
|
|
|
|
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_FAN);
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
gl_RenderState.EnableTexture(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
void FGLRenderer::FlatFill (int left, int top, int right, int bottom, FTexture *src, bool local_origin)
|
|
|
|
{
|
|
|
|
float fU1,fU2,fV1,fV2;
|
|
|
|
|
|
|
|
FMaterial *gltexture=FMaterial::ValidateTexture(src);
|
|
|
|
|
|
|
|
if (!gltexture) return;
|
|
|
|
|
2014-05-11 19:47:54 +00:00
|
|
|
gltexture->Bind(0, 0);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// scaling is not used here.
|
|
|
|
if (!local_origin)
|
|
|
|
{
|
|
|
|
fU1 = float(left) / src->GetWidth();
|
|
|
|
fV1 = float(top) / src->GetHeight();
|
|
|
|
fU2 = float(right) / src->GetWidth();
|
|
|
|
fV2 = float(bottom) / src->GetHeight();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fU1 = 0;
|
|
|
|
fV1 = 0;
|
|
|
|
fU2 = float(right-left) / src->GetWidth();
|
|
|
|
fV2 = float(bottom-top) / src->GetHeight();
|
|
|
|
}
|
2014-05-11 20:57:42 +00:00
|
|
|
gl_RenderState.ResetColor();
|
2013-06-23 07:49:34 +00:00
|
|
|
gl_RenderState.Apply();
|
2014-06-14 23:14:41 +00:00
|
|
|
|
|
|
|
FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer();
|
|
|
|
ptr->Set(left, top, 0, fU1, fV1); ptr++;
|
|
|
|
ptr->Set(left, bottom, 0, fU1, fV2); ptr++;
|
|
|
|
ptr->Set(right, top, 0, fU2, fV1); ptr++;
|
|
|
|
ptr->Set(right, bottom, 0, fU2, fV2); ptr++;
|
|
|
|
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
void FGLRenderer::Clear(int left, int top, int right, int bottom, int palcolor, uint32 color)
|
|
|
|
{
|
|
|
|
int rt;
|
|
|
|
int offY = 0;
|
|
|
|
PalEntry p = palcolor==-1 || color != 0? (PalEntry)color : GPalette.BaseColors[palcolor];
|
|
|
|
int width = right-left;
|
|
|
|
int height= bottom-top;
|
|
|
|
|
|
|
|
|
|
|
|
rt = screen->GetHeight() - top;
|
|
|
|
|
|
|
|
int space = (static_cast<OpenGLFrameBuffer*>(screen)->GetTrueHeight()-screen->GetHeight())/2; // ugh...
|
|
|
|
rt += space;
|
|
|
|
/*
|
|
|
|
if (!m_windowed && (m_trueHeight != m_height))
|
|
|
|
{
|
|
|
|
offY = (m_trueHeight - m_height) / 2;
|
|
|
|
rt += offY;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2013-09-03 12:05:41 +00:00
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
glScissor(left, rt - height, width, height);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2013-09-03 12:05:41 +00:00
|
|
|
glClearColor(p.r/255.0f, p.g/255.0f, p.b/255.0f, 0.f);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2013-09-03 12:05:41 +00:00
|
|
|
glDisable(GL_SCISSOR_TEST);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// D3DFB :: FillSimplePoly
|
|
|
|
//
|
|
|
|
// Here, "simple" means that a simple triangle fan can draw it.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void FGLRenderer::FillSimplePoly(FTexture *texture, FVector2 *points, int npoints,
|
|
|
|
double originx, double originy, double scalex, double scaley,
|
|
|
|
angle_t rotation, FDynamicColormap *colormap, int lightlevel)
|
|
|
|
{
|
|
|
|
if (npoints < 3)
|
|
|
|
{ // This is no polygon.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FMaterial *gltexture = FMaterial::ValidateTexture(texture);
|
|
|
|
|
|
|
|
if (gltexture == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FColormap cm;
|
|
|
|
cm = colormap;
|
|
|
|
|
2014-05-11 22:13:19 +00:00
|
|
|
gl_SetColor(lightlevel, 0, cm, 1.f);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2014-05-11 19:47:54 +00:00
|
|
|
gltexture->Bind();
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
int i;
|
|
|
|
float rot = float(rotation * M_PI / float(1u << 31));
|
|
|
|
bool dorotate = rot != 0;
|
|
|
|
|
|
|
|
float cosrot = cos(rot);
|
|
|
|
float sinrot = sin(rot);
|
|
|
|
|
|
|
|
//float yoffs = GatheringWipeScreen ? 0 : LBOffset;
|
|
|
|
float uscale = float(1.f / (texture->GetScaledWidth() * scalex));
|
|
|
|
float vscale = float(1.f / (texture->GetScaledHeight() * scaley));
|
|
|
|
if (gltexture->tex->bHasCanvas)
|
|
|
|
{
|
|
|
|
vscale = 0 - vscale;
|
|
|
|
}
|
|
|
|
float ox = float(originx);
|
|
|
|
float oy = float(originy);
|
|
|
|
|
|
|
|
gl_RenderState.Apply();
|
2014-06-14 23:14:41 +00:00
|
|
|
|
|
|
|
FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer();
|
|
|
|
for (i = 0; i < npoints; ++i)
|
2014-05-20 22:36:04 +00:00
|
|
|
{
|
2014-06-14 23:14:41 +00:00
|
|
|
float u = points[i].X - 0.5f - ox;
|
|
|
|
float v = points[i].Y - 0.5f - oy;
|
|
|
|
if (dorotate)
|
2014-05-20 22:36:04 +00:00
|
|
|
{
|
2014-06-14 23:14:41 +00:00
|
|
|
float t = u;
|
|
|
|
u = t * cosrot - v * sinrot;
|
|
|
|
v = v * cosrot + t * sinrot;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
2014-06-14 23:14:41 +00:00
|
|
|
ptr->Set(points[i].X, points[i].Y, 0, u*uscale, v*vscale);
|
|
|
|
ptr++;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
2014-06-14 23:14:41 +00:00
|
|
|
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_FAN);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|