From d63e6eaaecbc83b40c9b932b3381fc324f6a2461 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Sun, 13 Oct 2019 03:31:05 +0300 Subject: [PATCH] add stub opengl wrapper and remove nanogl wrapper. --- src/engine/e_graphics.pas | 99 +++++-------------- src/game/g_gfx.pas | 39 -------- src/game/g_window.pas | 2 +- src/game/sdl/g_system.pas | 4 +- src/game/sdl2/g_system.pas | 4 +- src/nogl/noGL.pas | 7 +- src/nogl/noGLSTUB.inc | 193 +++++++++++++++++++++++++++++++++++++ src/nogl/noGLuses.inc | 34 ++----- src/shared/a_modes.inc | 34 ++++++- 9 files changed, 266 insertions(+), 150 deletions(-) create mode 100644 src/nogl/noGLSTUB.inc diff --git a/src/engine/e_graphics.pas b/src/engine/e_graphics.pas index ca6dcf1..6e8966e 100644 --- a/src/engine/e_graphics.pas +++ b/src/engine/e_graphics.pas @@ -859,9 +859,6 @@ end; procedure e_DrawQuad(X1, Y1, X2, Y2: Integer; Red, Green, Blue: Byte; Alpha: Byte = 0); var nX1, nY1, nX2, nY2: Integer; -{$IFDEF USE_NANOGL} - v: array [0..15] of GLfloat; -{$ENDIF} begin if e_NoGraphics then Exit; // Only top-left/bottom-right quad @@ -882,40 +879,13 @@ begin begin glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - end else + end + else glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); glColor4ub(Red, Green, Blue, 255-Alpha); glLineWidth(1); -{$IFDEF USE_NANOGL} - nX1 := X1; nY1 := Y1; - nX2 := X2; nY2 := Y1; - e_LineCorrection(nX1, nY1, nX2, nY2); - v[0] := nX1; v[1] := nY1; v[2] := nX2; v[3] := nY2; - - nX1 := X2; nY1 := Y1; - nX2 := X2; nY2 := Y2; - e_LineCorrection(nX1, nY1, nX2, nY2); - v[4] := nX1; v[5] := nY1; v[6] := nX2; v[7] := nY2; - - nX1 := X2; nY1 := Y2; - nX2 := X1; nY2 := Y2; - e_LineCorrection(nX1, nY1, nX2, nY2); - v[8] := nX1; v[9] := nY1; v[10] := nX2; v[11] := nY2; - - nX1 := X1; nY1 := Y2; - nX2 := X1; nY2 := Y1; - e_LineCorrection(nX1, nY1, nX2, nY2); - v[12] := nX1; v[13] := nY1; v[14] := nX2; v[15] := nY2; - - glVertexPointer(2, GL_FLOAT, 0, @v[0]); - glEnableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDrawArrays(GL_LINES, 0, 16); -{$ELSE} glBegin(GL_LINES); nX1 := X1; nY1 := Y1; nX2 := X2; nY2 := Y1; @@ -941,10 +911,7 @@ begin glVertex2i(nX1, nY1); glVertex2i(nX2, nY2); glEnd(); -{$ENDIF} - glColor4ub(e_Colors.R, e_Colors.G, e_Colors.B, 255); - glDisable(GL_BLEND); end; @@ -1016,10 +983,6 @@ end; procedure e_DrawLine(Width: Byte; X1, Y1, X2, Y2: Integer; Red, Green, Blue: Byte; Alpha: Byte = 0); -{$IFDEF USE_NANOGL} - var - v: array [0..3] of GLfloat; -{$ENDIF} begin if e_NoGraphics then Exit; // Pixel-perfect lines @@ -1036,22 +999,10 @@ begin glDisable(GL_TEXTURE_2D); glColor4ub(Red, Green, Blue, 255-Alpha); glLineWidth(Width); - -{$IFDEF USE_NANOGL} - v[0] := X1; v[1] := Y1; v[2] := X2; v[3] := Y2; - glVertexPointer(2, GL_FLOAT, 0, @v[0]); - glEnableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDrawArrays(GL_LINES, 0, 4); -{$ELSE} glBegin(GL_LINES); glVertex2i(X1, Y1); glVertex2i(X2, Y2); glEnd(); -{$ENDIF} - glColor4ub(e_Colors.R, e_Colors.G, e_Colors.B, 255); glDisable(GL_BLEND); @@ -1504,7 +1455,7 @@ end; procedure e_TextureFontBuild(Tex: DWORD; var FontID: DWORD; XCount, YCount: Word; Space: ShortInt=0); var -{$IF not DEFINED(USE_NANOGL) and not DEFINED(USE_NOGL)} +{$IFDEF NOGL_LISTS} loop1 : GLuint; cx, cy : real; {$ENDIF} @@ -1531,7 +1482,7 @@ begin with e_TextureFonts[id] do begin -{$IF not DEFINED(USE_NANOGL) and not DEFINED(USE_NOGL)} +{$IFDEF NOGL_LISTS} Base := glGenLists(XCount*YCount); {$ENDIF} TextureID := e_Textures[Tex].tx.id; @@ -1543,7 +1494,7 @@ begin SPC := Space; end; -{$IF not DEFINED(USE_NANOGL) and not DEFINED(USE_NOGL)} +{$IFDEF NOGL_LISTS} glBindTexture(GL_TEXTURE_2D, e_Textures[Tex].tx.id); for loop1 := 0 to XCount*YCount-1 do begin @@ -1575,13 +1526,13 @@ end; procedure e_TextureFontKill(FontID: DWORD); begin if e_NoGraphics then Exit; -{$IF not DEFINED(USE_NANOGL) and not DEFINED(USE_NOGL)} +{$IFDEF NOGL_LISTS} glDeleteLists(e_TextureFonts[FontID].Base, 256); {$ENDIF} e_TextureFonts[FontID].Base := 0; end; -{$IF DEFINED(USE_NANOGL) or DEFINED(USE_NOGL)} +{$IFNDEF NOGL_LISTS} procedure e_TextureFontDrawChar(ch: Char; FontID: DWORD); var index: Integer; @@ -1635,11 +1586,11 @@ begin glBindTexture(GL_TEXTURE_2D, e_TextureFonts[FontID].TextureID); glEnable(GL_TEXTURE_2D); glTranslatef(x, y, 0); -{$IF DEFINED(USE_NANOGL) or DEFINED(USE_NOGL)} - e_TextureFontDrawString(Text, FontID); -{$ELSE} +{$IFDEF NOGL_LISTS} glListBase(DWORD(Integer(e_TextureFonts[FontID].Base)-32)); glCallLists(Length(Text), GL_UNSIGNED_BYTE, PChar(Text)); +{$ELSE} + e_TextureFontDrawString(Text, FontID); {$ENDIF} glDisable(GL_TEXTURE_2D); glPopMatrix; @@ -1657,10 +1608,10 @@ begin begin glColor4ub(0, 0, 0, 128); glTranslatef(X+1, Y+1, 0); -{$IF DEFINED(USE_NANOGL) or DEFINED(USE_NOGL)} - e_TextureFontDrawChar(Ch, FontID); -{$ELSE} +{$IFDEF NOGL_LISTS} glCallLists(1, GL_UNSIGNED_BYTE, @Ch); +{$ELSE} + e_TextureFontDrawChar(Ch, FontID); {$ENDIF} glPopMatrix; glPushMatrix; @@ -1668,10 +1619,10 @@ begin glColor4ub(e_Colors.R, e_Colors.G, e_Colors.B, 255); glTranslatef(X, Y, 0); -{$IF DEFINED(USE_NANOGL) or DEFINED(USE_NOGL)} - e_TextureFontDrawChar(Ch, FontID); -{$ELSE} +{$IFDEF NOGL_LISTS} glCallLists(1, GL_UNSIGNED_BYTE, @Ch); +{$ELSE} + e_TextureFontDrawChar(Ch, FontID); {$ENDIF} glPopMatrix; @@ -1723,7 +1674,7 @@ begin glBindTexture(GL_TEXTURE_2D, e_TextureFonts[FontID].TextureID); glEnable(GL_TEXTURE_2D); -{$IF not DEFINED(USE_NANOGL) and not DEFINED(USE_NOGL)} +{$IFDEF NOGL_LISTS} glListBase(DWORD(Integer(e_TextureFonts[FontID].Base)-32)); {$ENDIF} @@ -1806,7 +1757,7 @@ begin glBindTexture(GL_TEXTURE_2D, e_TextureFonts[FontID].TextureID); glEnable(GL_TEXTURE_2D); -{$IF not DEFINED(USE_NANOGL) and not DEFINED(USE_NOGL)} +{$IFDEF NOGL_LISTS} glListBase(DWORD(Integer(e_TextureFonts[FontID].Base)-32)); {$ENDIF} @@ -1818,10 +1769,10 @@ begin glColor4ub(0, 0, 0, 128); glTranslatef(x+1, y+1, 0); glScalef(Scale, Scale, 0); -{$IF DEFINED(USE_NANOGL) or DEFINED(USE_NOGL)} - e_TextureFontDrawString(Text, FontID); -{$ELSE} +{$IFDEF NOGL_LISTS} glCallLists(Length(Text), GL_UNSIGNED_BYTE, PChar(Text)); +{$ELSE} + e_TextureFontDrawString(Text, FontID); {$ENDIF} glPopMatrix; glPushMatrix; @@ -1830,10 +1781,10 @@ begin glColor4ub(Red, Green, Blue, 255); glTranslatef(x, y, 0); glScalef(Scale, Scale, 0); -{$IF DEFINED(USE_NANOGL) or DEFINED(USE_NOGL)} - e_TextureFontDrawString(Text, FontID); -{$ELSE} +{$IFDEF NOGL_LISTS} glCallLists(Length(Text), GL_UNSIGNED_BYTE, PChar(Text)); +{$ELSE} + e_TextureFontDrawString(Text, FontID); {$ENDIF} glDisable(GL_TEXTURE_2D); @@ -1863,7 +1814,7 @@ begin for i := 0 to High(e_TextureFonts) do if e_TextureFonts[i].Base <> 0 then begin -{$IF not DEFINED(USE_NANOGL) and not DEFINED(USE_NOGL)} +{$IFDEF NOGL_LISTS} glDeleteLists(e_TextureFonts[i].Base, 256); {$ENDIF} e_TextureFonts[i].Base := 0; diff --git a/src/game/g_gfx.pas b/src/game/g_gfx.pas index e9118a3..8094c4e 100644 --- a/src/game/g_gfx.pas +++ b/src/game/g_gfx.pas @@ -1674,16 +1674,6 @@ end; procedure g_GFX_Draw (); var a, len: Integer; -{$IFDEF USE_NANOGL} - type - Vertex = record - x, y: GLfloat; - r, g, b, a: GLfloat; - end; - var - count: Integer; - v: array of Vertex; -{$ENDIF} begin if not gpart_dbg_enabled then exit; @@ -1698,34 +1688,6 @@ begin glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -{$IFDEF USE_NANOGL} - count := 0; - SetLength(v, Length(Particles)); - for a := 0 to High(Particles) do - begin - with Particles[a] do - begin - if alive and (x >= sX) and (y >= sY) and (x <= sX + sWidth) and (sY <= sY + sHeight) then - begin - v[count].x := x + 0.37; - v[count].y := y + 0.37; - v[count].r := red / 255; - v[count].g := green / 255; - v[count].b := blue / 255; - v[count].a := alpha / 255; - Inc(count); - end; - end; - end; - - glVertexPointer(2, GL_FLOAT, SizeOf(Vertex), @v[0].x); - glColorPointer(4, GL_FLOAT, SizeOf(Vertex), @v[0].r); - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDrawArrays(GL_POINTS, 0, count); -{$ELSE} glBegin(GL_POINTS); len := High(Particles); @@ -1743,7 +1705,6 @@ begin end; glEnd(); -{$ENDIF} glDisable(GL_BLEND); end; diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 3ea192b..6cce561 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -322,7 +322,7 @@ begin end; end; -{$IFDEF USE_SYSSTUB} +{$IFNDEF USE_SYSSTUB} PrintGLSupportedExtensions; glLegacyNPOT := GLExtensionSupported('GL_ARB_texture_non_power_of_two') or GLExtensionSupported('GL_OES_texture_npot'); {$ELSE} diff --git a/src/game/sdl/g_system.pas b/src/game/sdl/g_system.pas index 3e78fad..b86a70b 100644 --- a/src/game/sdl/g_system.pas +++ b/src/game/sdl/g_system.pas @@ -109,7 +109,7 @@ implementation screen := SDL_SetVideoMode(w, h, bpp, flags); if screen <> nil then begin - {$IFDEF USE_NOGL} + {$IFDEF NOGL_INIT} nogl_Init; {$ENDIF} SDL_WM_SetCaption(GameTitle, nil); @@ -470,7 +470,7 @@ implementation RemoveJoystick(i); if screen <> nil then begin - {$IFDEF USE_NOGL} + {$IFDEF NOGL_INIT} nogl_Quit; {$ENDIF} SDL_FreeSurface(screen) diff --git a/src/game/sdl2/g_system.pas b/src/game/sdl2/g_system.pas index 9485fd9..85e5d94 100644 --- a/src/game/sdl2/g_system.pas +++ b/src/game/sdl2/g_system.pas @@ -128,7 +128,7 @@ implementation context := SDL_GL_CreateContext(window); if context <> nil then begin - {$IFDEF USE_NOGL} + {$IFDEF NOGL_INIT} nogl_Init; {$ENDIF} UpdateSize(w, h); @@ -475,7 +475,7 @@ implementation e_WriteLog('Releasing SDL2', TMsgType.Notify); if context <> nil then begin - {$IFDEF USE_NOGL} + {$IFDEF NOGL_INIT} nogl_Quit; {$ENDIF} SDL_GL_DeleteContext(context); diff --git a/src/nogl/noGL.pas b/src/nogl/noGL.pas index 941c8d2..7f7ab2e 100644 --- a/src/nogl/noGL.pas +++ b/src/nogl/noGL.pas @@ -175,6 +175,11 @@ interface procedure nogl_Init; procedure nogl_Quit; -{$I noGLES1.inc} +{$IFDEF USE_GLES1} + {$I noGLES1.inc} +{$ENDIF} +{$IFDEF USE_GLSTUB} + {$I noGLSTUB.inc} +{$ENDIF} end. diff --git a/src/nogl/noGLSTUB.inc b/src/nogl/noGLSTUB.inc new file mode 100644 index 0000000..dc01c71 --- /dev/null +++ b/src/nogl/noGLSTUB.inc @@ -0,0 +1,193 @@ +implementation + + procedure glEnable(cap: GLenum); + begin + end; + + procedure glDisable(cap: GLenum); + begin + end; + + function glIsEnabled(cap: GLenum): GLboolean; + begin + result := 0 + end; + + function glGetString(name: GLenum): PChar; + begin + result := '' + end; + + procedure glClearColor(red, green, blue, alpha: GLclampf); + begin + end; + + procedure glClear(mask: GLbitfield); + begin + end; + + procedure glAlphaFunc(func: GLenum; ref: GLclampf); + begin + end; + + procedure glBlendFunc(sfactor, dfactor: GLenum); + begin + end; + + procedure glPointSize(size: GLfloat); + begin + end; + + procedure glLineWidth(width: GLfloat); + begin + end; + + procedure glGetIntegerv(pname: GLenum; params: PGLint); + begin + end; + + procedure glFlush; + begin + end; + + procedure glFinish; + begin + end; + + procedure glBegin(mode: GLenum); + begin + end; + + procedure glEnd; + begin + end; + + procedure glVertex2f(x, y: GLfloat); + begin + end; + + procedure glVertex2i(x, y: GLint); + begin + end; + + procedure glColor4f(red, green, blue, alpha: GLfloat); + begin + end; + + procedure glColor4ub(red, green, blue, alpha: GLubyte); + begin + end; + + procedure glColor3ub(red, green, blue: GLubyte); + begin + end; + + procedure glTexCoord2f(s, t: GLfloat); + begin + end; + + procedure glTexCoord2i(s, t: GLint); + begin + end; + + procedure glReadPixels(x, y: GLint; width, height: GLsizei; format, atype: GLenum; pixels: Pointer); + begin + end; + + procedure glLoadIdentity; + begin + end; + + procedure glMatrixMode(mode: GLenum); + begin + end; + + procedure glLoadMatrixd(const m: PGLdouble); + begin + end; + + procedure glPushMatrix; + begin + end; + + procedure glPopMatrix; + begin + end; + + procedure glTranslatef(x, y, z: GLfloat); + begin + end; + + procedure glRotatef(angle, x, y, z: GLfloat); + begin + end; + + procedure glScalef(x, y, z: GLfloat); + begin + end; + + procedure glViewport(x, y: GLint; width, height: GLsizei); + begin + end; + + procedure glScissor(x, y: GLint; width, height: GLsizei); + begin + end; + + procedure glStencilMask(mask: GLuint); + begin + end; + + procedure glStencilFunc(func: GLenum; ref: GLint; mask: GLuint); + begin + end; + + procedure glStencilOp(fail, zfail, zpass: GLenum); + begin + end; + + procedure glColorMask(red, green, blue, alpha: GLboolean); + begin + end; + + procedure glBindTexture(target: GLenum; texture: GLuint); + begin + end; + + procedure glGenTextures(n: GLsizei; textures: PGLuint); + begin + end; + + procedure glTexEnvi(target: GLenum; pname: GLenum; param: GLint); + begin + end; + + procedure glTexParameterf(target: GLenum; pname: GLenum; param: GLfloat); + begin + end; + + procedure glTexParameteri(target: GLenum; pname: GLenum; param: GLint); + begin + end; + + procedure glTexImage2D(target: GLenum; level, internalformat: GLint; width, height: GLsizei; border: GLint; format, atype: GLenum; const pixels: Pointer); + begin + end; + + procedure glTexSubImage2D(target: GLenum; level, xoffset, yoffset: GLint; width, height: GLsizei; format, atype: GLenum; const pixels: Pointer); + begin + end; + + procedure glDeleteTextures(n: GLsizei; const textures: PGLuint); + begin + end; + + procedure nogl_Init; + begin + end; + + procedure nogl_Quit; + begin + end; + +initialization diff --git a/src/nogl/noGLuses.inc b/src/nogl/noGLuses.inc index 458f546..acfe89e 100644 --- a/src/nogl/noGLuses.inc +++ b/src/nogl/noGLuses.inc @@ -1,27 +1,9 @@ -{$IFDEF USE_NANOGL} - {$DEFINE USE_GLES1} -{$ELSE} - {$IFDEF USE_NOGL} - {$DEFINE USE_GLES1} - {$ENDIF} -{$ENDIF} - -{$IFDEF USE_GLES1} - {$IFNDEF USE_NANOGL} - {$DEFINE USE_NOGL} - {$ENDIF} -{$ENDIF} - -{$IF DEFINED(USE_NANOGL) and DEFINED(USE_NOGL)} - {$WARNING you can use only one OpenGL ES wrapper} -{$ENDIF} - -{$IFDEF USE_NANOGL} - nanoGL in '../lib/nanogl/nanoGL.pas', -{$ELSE} - {$IFDEF USE_NOGL} - noGL in '../nogl/noGL.pas', - {$ELSE} - GL, GLExt, - {$ENDIF} +{$IF DEFINED(USE_GLES1) OR DEFINED(USE_GLSTUB)} + {$UNDEF NOGL_LISTS} + {$DEFINE NOGL_INIT} + noGL in '../nogl/noGL.pas', +{$ENDIF} +{$IFDEF USE_OPENGL} + {$DEFINE NOGL_LISTS} + GL, GLExt, {$ENDIF} diff --git a/src/shared/a_modes.inc b/src/shared/a_modes.inc index 733abb8..c9fd457 100644 --- a/src/shared/a_modes.inc +++ b/src/shared/a_modes.inc @@ -92,6 +92,16 @@ {$UNDEF USE_SDL} {$UNDEF USE_SDL2} {$ENDIF} + {$DEFINE USE_GLSTUB} + {$IF DEFINED(USE_GLES1) OR DEFINED(USE_OPENGL)} + {$WARNING Render drivers not needed in headless mode. Force stub driver...} + {$UNDEF USE_GLES1} + {$UNDEF USE_OPENGL} + {$ENDIF} + {$IFDEF ENABLE_HOLMES} + {$WARNING Holmes in headless mode has no sense. Disabled.} + {$UNDEF ENABLE_HOLMES} + {$ENDIF} {$ENDIF} {$IF DEFINED(USE_SYSSTUB)} @@ -131,14 +141,28 @@ {$ERROR Sound driver not selected. Use -dUSE_SOUNDSTUB or -dUSE_SDLMIXER or -dUSE_FMOD or -dUSE_OPENAL} {$ENDIF} -{$IFDEF ENABLE_HOLMES} - {$IFDEF HEADLESS} - {$ERROR Holmes in HEADLESS mode has no sense} +{$IF DEFINED(USE_GLSTUB)} + {$IF DEFINED(USE_GLES1) OR DEFINED(USE_OPENGL)} + {$ERROR Only one render driver must be selected!} + {$ENDIF} +{$ELSEIF DEFINED(USE_GLES1)} + {$IF DEFINED(USE_GLSTUB) OR DEFINED(USE_OPENGL)} + {$ERROR Only one render driver must be selected!} + {$ENDIF} +{$ELSEIF DEFINED(USE_OPENGL)} + {$IF DEFINED(USE_GLSTUB) OR DEFINED(USE_GLES1)} + {$ERROR Only one render driver must be selected!} {$ENDIF} +{$ELSE} + {$DEFINE USE_OPENGL} + {.$ERROR Render driver not selected. Use -dUSE_GLSTUB or -dUSE_GLES1 or -dUSE_OPENGL} +{$ENDIF} + +{$IFDEF ENABLE_HOLMES} {$IFNDEF USE_SDL2} {$ERROR Holmes supported only with SDL2} {$ENDIF} - {$IFDEF USE_GLES1} - {$ERROR Holmes not supported with GLES} + {$IFNDEF USE_OPENGL} + {$ERROR Holmes supported only with desktop OpenGL} {$ENDIF} {$ENDIF} -- 2.29.2