Compare commits

...

1 Commits

Author SHA1 Message Date
Simon Robertshaw
3b3a80d7de Remove pre-processor conditional blocks for OpenGL Renderer and OpenGL Interface graphics. 2019-09-10 21:40:07 +01:00
17 changed files with 33 additions and 1558 deletions

View File

@ -506,11 +506,6 @@ if not GetOption('nolua') and not GetOption('renderer') and not GetOption('font'
if GetOption('nohttp') or GetOption('renderer'):
env.Append(CPPDEFINES=['NOHTTP'])
if GetOption('opengl') or GetOption('opengl-renderer'):
env.Append(CPPDEFINES=['OGLI', 'PIX32OGL'])
if GetOption('opengl-renderer'):
env.Append(CPPDEFINES=['OGLR'])
if GetOption('renderer'):
env.Append(CPPDEFINES=['RENDERER'])

View File

@ -135,12 +135,6 @@ void CalculateMousePosition(int *x, int *y)
*y = (globalMy - windowY) / scale;
}
#ifdef OGLI
void blit()
{
SDL_GL_SwapBuffers();
}
#else
void blit(pixel * vid)
{
SDL_UpdateTexture(sdl_texture, NULL, vid, WINDOWW * sizeof (Uint32));
@ -150,7 +144,6 @@ void blit(pixel * vid)
SDL_RenderCopy(sdl_renderer, sdl_texture, NULL, NULL);
SDL_RenderPresent(sdl_renderer);
}
#endif
void RecreateWindow();
int SDLOpen()
@ -520,11 +513,7 @@ void EngineProcess()
engine->GetForceIntegerScaling());
}
#ifdef OGLI
blit();
#else
blit(engine->g->vid);
#endif
int frameTime = SDL_GetTicks() - frameStart;
frameTimeAvg = frameTimeAvg * 0.8 + frameTime * 0.2;
@ -590,11 +579,8 @@ void BlueScreen(String detailMessage)
while (SDL_PollEvent(&event))
if(event.type == SDL_QUIT)
exit(-1);
#ifdef OGLI
blit();
#else
blit(engine->g->vid);
#endif
}
}
@ -717,18 +703,6 @@ int main(int argc, char * argv[])
showDoubleScreenDialog = true;
}
#ifdef OGLI
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
//glScaled(2.0f, 2.0f, 1.0f);
#endif
#if defined(OGLI) && !defined(MACOSX)
int status = glewInit();
if(status != GLEW_OK)
{
fprintf(stderr, "Initializing Glew: %d\n", status);
exit(-1);
}
#endif
ui::Engine::Ref().g = new Graphics();
ui::Engine::Ref().Scale = scale;
ui::Engine::Ref().SetResizable(resizable);
@ -806,11 +780,9 @@ int main(int argc, char * argv[])
engine->g->drawrect((engine->GetWidth()/2)-100, (engine->GetHeight()/2)-25, 200, 50, 255, 255, 255, 180);
engine->g->drawtext((engine->GetWidth()/2)-(Graphics::textwidth("Loading save...")/2), (engine->GetHeight()/2)-5, "Loading save...", style::Colour::InformationTitle.Red, style::Colour::InformationTitle.Green, style::Colour::InformationTitle.Blue, 255);
#ifdef OGLI
blit();
#else
blit(engine->g->vid);
#endif
ByteString ptsaveArg = arguments["ptsave"];
try
{

View File

@ -1061,10 +1061,7 @@ pixel *Graphics::render_packed_rgb(void *image, int width, int height, int cmp_s
VideoBuffer Graphics::DumpFrame()
{
#ifdef OGLI
#else
VideoBuffer newBuffer(WINDOWW, WINDOWH);
std::copy(vid, vid+(WINDOWW*WINDOWH), newBuffer.Buffer);
return newBuffer;
#endif
}

View File

@ -2,9 +2,6 @@
#define GRAPHICS_H
#include "common/String.h"
#if defined(OGLI)
#include "OpenGLHeaders.h"
#endif
#include "Config.h"
#include "common/tpt-inline.h"
#include "Pixel.h"
@ -25,20 +22,6 @@ public:
void Resize(int width, int height, bool resample = false, bool fixedRatio = true);
TPT_INLINE void BlendPixel(int x, int y, int r, int g, int b, int a)
{
#ifdef PIX32OGL
pixel t;
if (x<0 || y<0 || x>=Width || y>=Height)
return;
if (a!=255)
{
t = Buffer[y*(Width)+x];
r = (a*r + (255-a)*PIXR(t)) >> 8;
g = (a*g + (255-a)*PIXG(t)) >> 8;
b = (a*b + (255-a)*PIXB(t)) >> 8;
a = a > PIXA(t) ? a : PIXA(t);
}
Buffer[y*(Width)+x] = PIXRGBA(r,g,b,a);
#else
pixel t;
if (x<0 || y<0 || x>=Width || y>=Height)
return;
@ -50,18 +33,13 @@ public:
b = (a*b + (255-a)*PIXB(t)) >> 8;
}
Buffer[y*(Width)+x] = PIXRGB(r,g,b);
#endif
}
TPT_INLINE void SetPixel(int x, int y, int r, int g, int b, int a)
{
if (x<0 || y<0 || x>=Width || y>=Height)
return;
#ifdef PIX32OGL
Buffer[y*(Width)+x] = PIXRGBA(r,g,b,a);
#else
Buffer[y*(Width)+x] = PIXRGB((r*a)>>8, (g*a)>>8, (b*a)>>8);
#endif
}
TPT_INLINE void AddPixel(int x, int y, int r, int g, int b, int a)
@ -92,14 +70,6 @@ class Graphics
public:
pixel *vid;
int sdl_scale;
#ifdef OGLI
//OpenGL specific instance variables
GLuint vidBuf, textTexture;
void Reset();
void LoadDefaults();
void InitialiseTextures();
void DestroyTextures();
#endif
//Common graphics methods in Graphics.cpp
static char * GenerateGradient(pixel * colours, float * points, int pointcount, int size);

View File

@ -24,16 +24,6 @@
#define PIXR(x) (((x)>>8)&0xFF)
#define PIXG(x) (((x)>>16)&0xFF)
#define PIXB(x) (((x)>>24)&0xFF)
#elif defined(PIX32OGL)
#undef PIXELCHANNELS
#define PIXELCHANNELS 4
#define PIXPACK(x) (0xFF000000|((x)&0xFFFFFF)) //32bit ARGB in 32bit int: AARRGGBB
#define PIXRGB(r,g,b) (0xFF000000|((r)<<16)|((g)<<8)|((b)))
#define PIXRGBA(r,g,b,a) (((a)<<24)|((r)<<16)|((g)<<8)|((b)))
#define PIXA(x) (((x)>>24)&0xFF)
#define PIXR(x) (((x)>>16)&0xFF)
#define PIXG(x) (((x)>>8)&0xFF)
#define PIXB(x) ((x)&0xFF)
#else
#define PIXPACK(x) (x) //24bit RGB in 32bit int: 00RRGGBB.
#define PIXRGB(r,g,b) (((r)<<16)|((g)<<8)|(b))

View File

@ -3,8 +3,6 @@
#include <cstdlib>
#include <cstring>
#ifndef OGLI
Graphics::Graphics():
sdl_scale(1)
{
@ -34,5 +32,3 @@ void Graphics::Finalise()
#undef VIDYRES
#undef VIDXRES
#undef PIXELMETHODS_CLASS
#endif

File diff suppressed because it is too large Load Diff

View File

@ -2,9 +2,6 @@
#define RENDERER_H
#include <vector>
#ifdef OGLR
#include "OpenGLHeaders.h"
#endif
#include "Graphics.h"
#include "Config.h"
@ -97,13 +94,6 @@ public:
void clearScreen(float alpha);
void SetSample(int x, int y);
#ifdef OGLR
void checkShader(GLuint shader, const char * shname);
void checkProgram(GLuint program, const char * progname);
void loadShaders();
GLuint vidBuf,textTexture;
GLint prevFbo;
#endif
pixel * vid;
pixel * persistentVid;
pixel * warpVid;
@ -166,26 +156,6 @@ public:
private:
int gridSize;
#ifdef OGLR
GLuint zoomTex, airBuf, fireAlpha, glowAlpha, blurAlpha, partsFboTex, partsFbo, partsTFX, partsTFY, airPV, airVY, airVX;
GLuint fireProg, airProg_Pressure, airProg_Velocity, airProg_Cracker, lensProg;
GLuint fireV[(YRES*XRES)*2];
GLfloat fireC[(YRES*XRES)*4];
GLuint smokeV[(YRES*XRES)*2];
GLfloat smokeC[(YRES*XRES)*4];
GLuint blobV[(YRES*XRES)*2];
GLfloat blobC[(YRES*XRES)*4];
GLuint blurV[(YRES*XRES)*2];
GLfloat blurC[(YRES*XRES)*4];
GLuint glowV[(YRES*XRES)*2];
GLfloat glowC[(YRES*XRES)*4];
GLuint flatV[(YRES*XRES)*2];
GLfloat flatC[(YRES*XRES)*4];
GLuint addV[(YRES*XRES)*2];
GLfloat addC[(YRES*XRES)*4];
GLfloat lineV[(((YRES*XRES)*2)*6)];
GLfloat lineC[(((YRES*XRES)*2)*6)];
#endif
};
#endif

View File

@ -2416,7 +2416,6 @@ void GameView::OnDraw()
g->fillrect(XRES-20-textWidth, 12, textWidth+8, 15, 0, 0, 0, alpha*0.5f);
g->drawtext(XRES-16-textWidth, 16, sampleInfo.Build(), 255, 255, 255, alpha*0.75f);
#ifndef OGLI
if (wavelengthGfx)
{
int i, cr, cg, cb, j, h = 3, x = XRES-19-textWidth, y = 10;
@ -2451,7 +2450,6 @@ void GameView::OnDraw()
}
}
}
#endif
if (showDebug)
{

View File

@ -212,20 +212,13 @@ void SignWindow::DoDraw()
y = currentSign.y;
dx = 1 - currentSign.ju;
dy = (currentSign.y > 18) ? -1 : 1;
#ifdef OGLR
glBegin(GL_LINES);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glVertex2i(x, y);
glVertex2i(x+(dx*4), y+(dy*4));
glEnd();
#else
for (int j=0; j<4; j++)
{
g->blendpixel(x, y, 192, 192, 192, 255);
x+=dx;
y+=dy;
}
#endif
}
}
if(!signMoving)

View File

@ -117,9 +117,7 @@ void Engine::ShowWindow(Window * window)
}
lastBuffer = (pixel*)malloc((width_ * height_) * PIXELSIZE);
#ifndef OGLI
memcpy(lastBuffer, g->vid, (width_ * height_) * PIXELSIZE);
#endif
windows.push(state_);
mousePositions.push(ui::Point(mousex_, mousey_));
@ -225,12 +223,10 @@ void Engine::Draw()
if(lastBuffer && !(state_ && state_->Position.X == 0 && state_->Position.Y == 0 && state_->Size.X == width_ && state_->Size.Y == height_))
{
g->Clear();
#ifndef OGLI
memcpy(g->vid, lastBuffer, (width_ * height_) * PIXELSIZE);
if(windowOpenState < 20)
windowOpenState++;
g->fillrect(0, 0, width_, height_, 0, 0, 0, 255-std::pow(.98, windowOpenState)*255);
#endif
}
else
{

View File

@ -13,30 +13,7 @@ Panel::Panel(Point position, Point size):
ViewportPosition(0, 0),
mouseInside(false)
{
#ifdef OGLI
GLint lastVid;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &lastVid);
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &myVidTex);
glBindTexture(GL_TEXTURE_2D, myVidTex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, WINDOWW, WINDOWH, 0, GL_RGBA, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
//FBO
glGenFramebuffers(1, &myVid);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, myVid);
glEnable(GL_BLEND);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, myVidTex, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); // Reset framebuffer binding
glDisable(GL_TEXTURE_2D);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, lastVid);
#else
myVid = new pixel[WINDOWW*WINDOWH];
#endif
}
Panel::~Panel()
@ -45,12 +22,8 @@ Panel::~Panel()
{
delete children[i];
}
#ifdef OGLI
glDeleteTextures(1, &myVidTex);
glDeleteFramebuffers(1, &myVid);
#else
delete[] myVid;
#endif
}
void Panel::AddChild(Component* c)
@ -97,17 +70,10 @@ void Panel::Draw(const Point& screenPos)
// draw ourself first
XDraw(screenPos);
#ifdef OGLI
GLint lastVid;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &lastVid);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, myVid);
glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
#else
pixel * lastVid = ui::Engine::Ref().g->vid;
ui::Engine::Ref().g->vid = myVid;
std::fill(myVid, myVid+(WINDOWW*WINDOWH), 0);
#endif
// attempt to draw all children
for (size_t i = 0; i < children.size(); ++i)
@ -127,32 +93,6 @@ void Panel::Draw(const Point& screenPos)
}
}
#ifdef OGLI
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, lastVid);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, myVidTex);
int x = screenPos.X, y = screenPos.Y;
int h = Size.Y, w = Size.X;
double texX = double(Size.X)/WINDOWW, texY = 1, texYB = 1-(double(Size.Y)/WINDOWH);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2d(0, texYB);
glVertex2f(x, y+h);
glTexCoord2d(texX, texYB);
glVertex2f(x+w, y+h);
glTexCoord2d(texX, texY);
glVertex2f(x+w, y);
glTexCoord2d(0, texY);
glVertex2f(x, y);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
#else
ui::Engine::Ref().g->vid = lastVid;
//dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x;
@ -160,7 +100,6 @@ void Panel::Draw(const Point& screenPos)
{
std::copy(myVid+(row*WINDOWW), myVid+(row*WINDOWW)+Size.X, lastVid+((screenPos.Y+row)*WINDOWW)+screenPos.X);
}
#endif
}
void Panel::Tick(float dt)

View File

@ -5,11 +5,6 @@
#include "gui/interface/Point.h"
#include "gui/interface/Component.h"
#ifdef OGLI
#include "graphics/OpenGLHeaders.h"
#endif
class Graphics;
namespace ui
{
@ -27,11 +22,8 @@ class Component;
public:
friend class Component;
#ifdef OGLI
GLuint myVid, myVidTex;
#else
pixel * myVid;
#endif
ui::Point InnerSize;
ui::Point ViewportPosition;

View File

@ -109,13 +109,9 @@ void Slider::Draw(const Point& screenPos)
if(bgGradient)
{
#ifndef OGLI
for (int j = 3; j < Size.Y-7; j++)
for (int i = 3; i < Size.X-7; i++)
g->blendpixel(screenPos.X+i+2, screenPos.Y+j+2, bgGradient[(i-3)*3], bgGradient[(i-3)*3+1], bgGradient[(i-3)*3+2], 255);
#else
g->gradientrect(screenPos.X+5, screenPos.Y+5, Size.X-10, Size.Y-10, col1.Red, col1.Green, col1.Blue, col1.Alpha, col2.Red, col2.Green, col2.Blue, col2.Alpha);
#endif
}
g->drawrect(screenPos.X+3, screenPos.Y+3, Size.X-6, Size.Y-6, 255, 255, 255, 255);

View File

@ -246,11 +246,7 @@ RenderView::RenderView():
tCheckbox->SetActionCallback(new DisplayModeAction(this, DISPLAY_WARP));
AddComponent(tCheckbox);
#ifdef OGLR
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4), ui::Point(30, 16), "Effect", "Some type of OpenGL effect ... maybe"); //I would remove the whole checkbox, but then there's a large empty space
#else
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4), ui::Point(30, 16), "Effect", "Enables moving solids, stickmen guns, and premium(tm) graphics");
#endif
displayModes.push_back(tCheckbox);
tCheckbox->SetIcon(IconEffect);
tCheckbox->SetActionCallback(new DisplayModeAction(this, DISPLAY_EFFE));

View File

@ -13,24 +13,6 @@ SaveRenderer::SaveRenderer(){
ren = new Renderer(g, sim);
ren->decorations_enable = true;
ren->blackDecorations = true;
#if defined(OGLR) || defined(OGLI)
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &fboTex);
glBindTexture(GL_TEXTURE_2D, fboTex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, XRES, YRES, 0, GL_RGBA, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
//FBO
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
glEnable(GL_BLEND);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboTex, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); // Reset framebuffer binding
glDisable(GL_TEXTURE_2D);
#endif
}
VideoBuffer * SaveRenderer::Render(GameSave * save, bool decorations, bool fire)
@ -50,67 +32,7 @@ VideoBuffer * SaveRenderer::Render(GameSave * save, bool decorations, bool fire)
{
ren->decorations_enable = true;
ren->blackDecorations = !decorations;
#if defined(OGLR) || defined(OGLI)
pixel * pData = NULL;
unsigned char * texData = NULL;
glTranslated(0, MENUSIZE, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
ren->clearScreen(1.0f);
ren->ClearAccumulation();
#ifdef OGLR
ren->RenderBegin();
ren->RenderEnd();
#else
if (fire)
{
int frame = 15;
while(frame)
{
frame--;
ren->render_parts();
ren->render_fire();
ren->clearScreen(1.0f);
}
}
ren->RenderBegin();
ren->RenderEnd();
#endif
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glTranslated(0, -MENUSIZE, 0);
glEnable( GL_TEXTURE_2D );
glBindTexture(GL_TEXTURE_2D, fboTex);
pData = new pixel[XRES*YRES];
texData = new unsigned char[(XRES*YRES)*PIXELSIZE];
std::fill(texData, texData+(XRES*YRES)*PIXELSIZE, 0xDD);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
glDisable(GL_TEXTURE_2D);
for(int x = 0; x < width*CELL; x++)
{
for(int y = 0; y < height*CELL; y++)
{
unsigned char red = texData[((((YRES-1-y)*XRES)+x)*4)];
unsigned char green = texData[((((YRES-1-y)*XRES)+x)*4)+1];
unsigned char blue = texData[((((YRES-1-y)*XRES)+x)*4)+2];
pData[(y*(width*CELL))+x] = PIXRGBA(red, green, blue, 255);
}
}
tempThumb = new VideoBuffer(pData, width*CELL, height*CELL);
delete[] pData;
delete[] texData;
pData = NULL;
#else
pixel * pData = NULL;
pixel * dst;
pixel * src = g->vid;
@ -143,7 +65,6 @@ VideoBuffer * SaveRenderer::Render(GameSave * save, bool decorations, bool fire)
}
tempThumb = new VideoBuffer(pData, width*CELL, height*CELL);
free(pData);
#endif
}
if(doCollapse)
save->Collapse();

View File

@ -1,8 +1,5 @@
#ifndef SAVERENDERER_H_
#define SAVERENDERER_H_
#ifdef OGLI
#include "graphics/OpenGLHeaders.h"
#endif
#include "common/Singleton.h"
#include <mutex>
@ -24,11 +21,6 @@ public:
void CopyModes(Renderer *source);
void ResetModes();
virtual ~SaveRenderer();
private:
#if defined(OGLR) || defined(OGLI)
GLuint fboTex, fbo;
#endif
};
#endif /* SAVERENDERER_H_ */