From: DeaDDooMER Date: Sat, 23 Jun 2018 22:27:53 +0000 (+0300) Subject: Added new OpenGL ES wrapper X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=92c7868df227201d6914f9f07c9a29ba0e2863cb;p=d2df-sdl.git Added new OpenGL ES wrapper --- diff --git a/README b/README index 7cedece..c8ab162 100644 --- a/README +++ b/README @@ -20,7 +20,8 @@ fpc -O3 -Fi../lib/vampimg -Fi../lib/vampimg/JpegLib -Fi../lib/vampimg/ZLib -Fu.. If you want SDL_mixer instead of FMOD, add -dUSE_SDLMIXER. If you want the server to be able to forward ports via UPNP, add -dUSE_MINIUPNPC. -If you want to debug game with Holmes, add -dENABLE_HOLMES. +If you want to debug game with Holmes, add -dENABLE_HOLMES (not supported in GLES mode). +If you want to render graphics using OpenGL ES, add -dUSE_GLES1. To build a headless (no video/audio, for dedicated servers) executable, add -dHEADLESS. Replace -O3 with -g -gl to enable debugging features. Run the game with --gdb when using a debugger to prevent it from eating exceptions. diff --git a/android/README b/android/README index de9cb1b..b10d352 100644 --- a/android/README +++ b/android/README @@ -14,10 +14,8 @@ Requirements: * FPC >= 3.0.4; * SDL >= 2.0.7; * SDL_mixer >= 2.0; -* libenet >= 1.3.13; -* nanoGL. +* libenet >= 1.3.13. -D2DF uses special version of nanoGL ( https://github.com/DeaDDooMER/nanogl ) with some added functions. Build all shared libraries using NDK toolchain and put into directory ./ass/lib/armeabi-v7a/. Also you need to build FPC crosscompiler ( http://wiki.freepascal.org/Android ). Put game resources into direcotor resources/ (or install it manually into external/internal storage). @@ -41,7 +39,7 @@ rm -rf tmp mkdir -p tmp cd ../src/game ppcrossarm \ - -g -gl -dUSE_SDLMIXER -dUSE_NANOGL -O3 \ + -g -gl -dUSE_SDLMIXER -dUSE_GLES1 -O3 \ -Tandroid \ -Cparmv7a \ -Cfvfpv3 \ diff --git a/src/engine/e_graphics.pas b/src/engine/e_graphics.pas index c5ec8f3..d0f9672 100644 --- a/src/engine/e_graphics.pas +++ b/src/engine/e_graphics.pas @@ -19,11 +19,7 @@ unit e_graphics; interface uses -{$IFDEF USE_NANOGL} - nanoGL, -{$ELSE} - GL, GLExt, -{$ENDIF} + {$INCLUDE ../nogl/noGLuses.inc} SysUtils, Classes, Math, e_log, e_texture, SDL2, MAPDEF, ImagingTypes, Imaging, ImagingUtility; type @@ -1525,7 +1521,7 @@ begin with e_TextureFonts[id] do begin -{$IF not DEFINED(USE_NANOGL)} +{$IF not DEFINED(USE_NANOGL) and not DEFINED(USE_NOGL)} Base := glGenLists(XCount*YCount); {$ENDIF} TextureID := e_Textures[Tex].tx.id; @@ -1537,7 +1533,7 @@ begin SPC := Space; end; -{$IF not DEFINED(USE_NANOGL)} +{$IF not DEFINED(USE_NANOGL) and not DEFINED(USE_NOGL)} glBindTexture(GL_TEXTURE_2D, e_Textures[Tex].tx.id); for loop1 := 0 to XCount*YCount-1 do begin @@ -1569,13 +1565,13 @@ end; procedure e_TextureFontKill(FontID: DWORD); begin if e_NoGraphics then Exit; -{$IF not DEFINED(USE_NANOGL)} +{$IF not DEFINED(USE_NANOGL) and not DEFINED(USE_NOGL)} glDeleteLists(e_TextureFonts[FontID].Base, 256); {$ENDIF} e_TextureFonts[FontID].Base := 0; end; -{$IFDEF USE_NANOGL} +{$IF DEFINED(USE_NANOGL) or DEFINED(USE_NOGL)} procedure e_TextureFontDrawChar(ch: Char; FontID: DWORD); var index: Integer; @@ -1629,7 +1625,7 @@ begin glBindTexture(GL_TEXTURE_2D, e_TextureFonts[FontID].TextureID); glEnable(GL_TEXTURE_2D); glTranslatef(x, y, 0); -{$IFDEF USE_NANOGL} +{$IF DEFINED(USE_NANOGL) or DEFINED(USE_NOGL)} e_TextureFontDrawString(Text, FontID); {$ELSE} glListBase(DWORD(Integer(e_TextureFonts[FontID].Base)-32)); @@ -1651,7 +1647,7 @@ begin begin glColor4ub(0, 0, 0, 128); glTranslatef(X+1, Y+1, 0); -{$IFDEF USE_NANOGL} +{$IF DEFINED(USE_NANOGL) or DEFINED(USE_NOGL)} e_TextureFontDrawChar(Ch, FontID); {$ELSE} glCallLists(1, GL_UNSIGNED_BYTE, @Ch); @@ -1662,7 +1658,7 @@ begin glColor4ub(e_Colors.R, e_Colors.G, e_Colors.B, 255); glTranslatef(X, Y, 0); -{$IFDEF USE_NANOGL} +{$IF DEFINED(USE_NANOGL) or DEFINED(USE_NOGL)} e_TextureFontDrawChar(Ch, FontID); {$ELSE} glCallLists(1, GL_UNSIGNED_BYTE, @Ch); @@ -1715,7 +1711,7 @@ begin glBindTexture(GL_TEXTURE_2D, e_TextureFonts[FontID].TextureID); glEnable(GL_TEXTURE_2D); -{$IF not DEFINED(USE_NANOGL)} +{$IF not DEFINED(USE_NANOGL) and not DEFINED(USE_NOGL)} glListBase(DWORD(Integer(e_TextureFonts[FontID].Base)-32)); {$ENDIF} @@ -1795,7 +1791,7 @@ begin glBindTexture(GL_TEXTURE_2D, e_TextureFonts[FontID].TextureID); glEnable(GL_TEXTURE_2D); -{$IF not DEFINED(USE_NANOGL)} +{$IF not DEFINED(USE_NANOGL) and not DEFINED(USE_NOGL)} glListBase(DWORD(Integer(e_TextureFonts[FontID].Base)-32)); {$ENDIF} @@ -1807,7 +1803,7 @@ begin glColor4ub(0, 0, 0, 128); glTranslatef(x+1, y+1, 0); glScalef(Scale, Scale, 0); -{$IFDEF USE_NANOGL} +{$IF DEFINED(USE_NANOGL) or DEFINED(USE_NOGL)} e_TextureFontDrawString(Text, FontID); {$ELSE} glCallLists(Length(Text), GL_UNSIGNED_BYTE, PChar(Text)); @@ -1819,7 +1815,7 @@ begin glColor4ub(Red, Green, Blue, 255); glTranslatef(x, y, 0); glScalef(Scale, Scale, 0); -{$IFDEF USE_NANOGL} +{$IF DEFINED(USE_NANOGL) or DEFINED(USE_NOGL)} e_TextureFontDrawString(Text, FontID); {$ELSE} glCallLists(Length(Text), GL_UNSIGNED_BYTE, PChar(Text)); @@ -1852,7 +1848,7 @@ begin for i := 0 to High(e_TextureFonts) do if e_TextureFonts[i].Base <> 0 then begin -{$IFNDEF USE_NANOGL} +{$IF not DEFINED(USE_NANOGL) and not DEFINED(USE_NOGL)} glDeleteLists(e_TextureFonts[i].Base, 256); {$ENDIF} e_TextureFonts[i].Base := 0; diff --git a/src/engine/e_texture.pas b/src/engine/e_texture.pas index c99d4eb..e4ffca3 100644 --- a/src/engine/e_texture.pas +++ b/src/engine/e_texture.pas @@ -23,13 +23,8 @@ unit e_texture; interface uses -{$IFDEF USE_NANOGL} - nanoGL, -{$ELSE} - GL, GLExt, -{$ENDIF} - SysUtils, e_log, - ImagingTypes, Imaging, ImagingUtility; + {$INCLUDE ../nogl/noGLuses.inc} + SysUtils, e_log, ImagingTypes, Imaging, ImagingUtility; type GLTexture = record diff --git a/src/flexui/fui_gfx_gl.pas b/src/flexui/fui_gfx_gl.pas index d386699..a226dee 100644 --- a/src/flexui/fui_gfx_gl.pas +++ b/src/flexui/fui_gfx_gl.pas @@ -21,11 +21,7 @@ unit fui_gfx_gl; interface uses -{$IFDEF USE_NANOGL} - nanoGL, -{$ELSE} - GL, GLExt, -{$ENDIF} + {$INCLUDE ../nogl/noGLuses.inc} SysUtils, Classes, SDL2, sdlcarcass, diff --git a/src/flexui/sdlcarcass.pas b/src/flexui/sdlcarcass.pas index 4bd2a6b..26bea1f 100644 --- a/src/flexui/sdlcarcass.pas +++ b/src/flexui/sdlcarcass.pas @@ -69,11 +69,7 @@ implementation uses SysUtils, Classes, - {$IFDEF USE_NANOGL} - nanoGL, - {$ELSE} - GL, GLExt, - {$ENDIF} + {$INCLUDE ../nogl/noGLuses.inc} {$IF DEFINED(LINUX) OR DEFINED(ANDROID)} unixtype, linux {$ELSEIF DEFINED(WINDOWS)} diff --git a/src/game/Doom2DF.lpr b/src/game/Doom2DF.lpr index 91fd3a6..3c3c94a 100644 --- a/src/game/Doom2DF.lpr +++ b/src/game/Doom2DF.lpr @@ -42,12 +42,9 @@ uses conbuf in '../shared/conbuf.pas', geom in '../shared/geom.pas', math, -{$IFDEF USE_NANOGL} - nanoGL in '../lib/nanogl/nanoGL.pas', -{$ELSE} - GL, - GLExt, -{$ENDIF} + +{$INCLUDE ../nogl/noGLuses.inc} + {$IFDEF USE_MINIUPNPC} miniupnpc in '../lib/miniupnpc/miniupnpc.pas', {$ENDIF} diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 83da686..bb11269 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -354,11 +354,7 @@ function gPause (): Boolean; inline; implementation uses -{$IFDEF USE_NANOGL} - nanoGL, -{$ELSE} - GL, GLExt, -{$ENDIF} +{$INCLUDE ../nogl/noGLuses.inc} {$IFDEF ENABLE_HOLMES} g_holmes, {$ENDIF} diff --git a/src/game/g_gfx.pas b/src/game/g_gfx.pas index df1d3c7..4e9cdd8 100644 --- a/src/game/g_gfx.pas +++ b/src/game/g_gfx.pas @@ -78,11 +78,7 @@ function awmIsSetHolmes (x, y: Integer): Boolean; inline; implementation uses -{$IFDEF USE_NANOGL} - nanoGL, -{$ELSE} - GL, GLExt, -{$ENDIF} + {$INCLUDE ../nogl/noGLuses.inc} g_map, g_panel, g_basic, Math, e_graphics, g_options, g_console, SysUtils, g_triggers, MAPDEF, g_game, g_language, g_net, utils, xprofiler; diff --git a/src/game/g_gui.pas b/src/game/g_gui.pas index 96df55b..d50e9a6 100644 --- a/src/game/g_gui.pas +++ b/src/game/g_gui.pas @@ -549,11 +549,7 @@ procedure g_GUI_LoadMenuPos(); implementation uses -{$IFDEF USE_NANOGL} - nanoGL, -{$ELSE} - GL, GLExt, -{$ENDIF} + {$INCLUDE ../nogl/noGLuses.inc} g_textures, g_sound, SysUtils, g_game, Math, StrUtils, g_player, g_options, g_map, g_weapons, xdynrec, wadreader; diff --git a/src/game/g_holmes.pas b/src/game/g_holmes.pas index 83b74ac..96c1c01 100644 --- a/src/game/g_holmes.pas +++ b/src/game/g_holmes.pas @@ -48,11 +48,7 @@ var implementation uses -{$IFDEF USE_NANOGL} - nanoGL, -{$ELSE} - GL, -{$ENDIF} + {$INCLUDE ../nogl/noGLuses.inc} {rttiobj,} typinfo, e_texture, SysUtils, Classes, SDL2, MAPDEF, g_main, g_options, diff --git a/src/game/g_main.pas b/src/game/g_main.pas index 874907e..34de5cf 100644 --- a/src/game/g_main.pas +++ b/src/game/g_main.pas @@ -37,11 +37,7 @@ var implementation uses -{$IFDEF USE_NANOGL} - nanoGL, -{$ELSE} - GL, GLExt, -{$ENDIF} +{$INCLUDE ../nogl/noGLuses.inc} {$IFDEF ENABLE_HOLMES} g_holmes, fui_wadread, fui_style, fui_gfx_gl, {$ENDIF} diff --git a/src/game/g_map.pas b/src/game/g_map.pas index 4e347ef..97c56d0 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -252,11 +252,7 @@ var implementation uses -{$IFDEF USE_NANOGL} - nanoGL, -{$ELSE} - GL, GLExt, -{$ENDIF} + {$INCLUDE ../nogl/noGLuses.inc} e_input, g_main, e_log, e_texture, g_items, g_gfx, g_console, g_weapons, g_game, g_sound, e_sound, CONFIG, g_options, g_triggers, g_player, diff --git a/src/game/g_menu.pas b/src/game/g_menu.pas index b84467f..a9b4566 100644 --- a/src/game/g_menu.pas +++ b/src/game/g_menu.pas @@ -42,11 +42,7 @@ var implementation uses -{$IFDEF USE_NANOGL} - nanoGL, -{$ELSE} - GL, GLExt, -{$ENDIF} + {$INCLUDE ../nogl/noGLuses.inc} g_gui, g_textures, e_graphics, g_main, g_window, g_game, g_map, g_basic, g_console, g_sound, g_gfx, g_player, g_options, g_weapons, e_log, SysUtils, CONFIG, g_playermodel, DateUtils, sdl2, diff --git a/src/game/g_options.pas b/src/game/g_options.pas index 54acb69..42b3ef7 100644 --- a/src/game/g_options.pas +++ b/src/game/g_options.pas @@ -134,11 +134,7 @@ var implementation uses -{$IFDEF USE_NANOGL} - nanoGL, -{$ELSE} - GL, GLExt, -{$ENDIF} + {$INCLUDE ../nogl/noGLuses.inc} e_log, e_input, g_window, g_sound, g_gfx, g_player, Math, g_map, g_net, g_netmaster, SysUtils, CONFIG, g_game, g_main, e_texture, g_items, wadreader, e_graphics, g_touch, SDL2; diff --git a/src/game/g_panel.pas b/src/game/g_panel.pas index c3d8224..0268c09 100644 --- a/src/game/g_panel.pas +++ b/src/game/g_panel.pas @@ -212,11 +212,7 @@ var implementation uses -{$IFDEF USE_NANOGL} - nanoGL, -{$ELSE} - GL, -{$ENDIF} + {$INCLUDE ../nogl/noGLuses.inc} e_texture, g_basic, g_map, g_game, g_gfx, e_graphics, g_weapons, g_triggers, g_console, g_language, g_monsters, g_player, g_grid, e_log, geom, utils, xstreams; diff --git a/src/game/g_player.pas b/src/game/g_player.pas index 8c62656..355ecf3 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -588,11 +588,7 @@ procedure g_Bot_RemoveAll(); implementation uses -{$IFDEF USE_NANOGL} - nanoGL, -{$ELSE} - GL, -{$ENDIF} +{$INCLUDE ../nogl/noGLuses.inc} {$IFDEF ENABLE_HOLMES} g_holmes, {$ENDIF} diff --git a/src/game/g_playermodel.pas b/src/game/g_playermodel.pas index 5400de6..af85837 100644 --- a/src/game/g_playermodel.pas +++ b/src/game/g_playermodel.pas @@ -141,11 +141,7 @@ function g_PlayerModel_GetGibs(ModelName: String; var Gibs: TGibsArray): Boolea implementation uses -{$IFDEF USE_NANOGL} - nanoGL, -{$ELSE} - GL, GLExt, -{$ENDIF} + {$INCLUDE ../nogl/noGLuses.inc} g_main, g_sound, g_console, SysUtils, g_player, CONFIG, e_sound, g_options, g_map, Math, e_log, wadreader; diff --git a/src/game/g_textures.pas b/src/game/g_textures.pas index 72b65b5..9f551f5 100644 --- a/src/game/g_textures.pas +++ b/src/game/g_textures.pas @@ -119,11 +119,7 @@ function g_Texture_Light (): Integer; implementation uses -{$IFDEF USE_NANOGL} - nanoGL, -{$ELSE} - GL, -{$ENDIF} + {$INCLUDE ../nogl/noGLuses.inc} g_game, e_log, g_basic, g_console, wadreader, g_language, utils, xstreams; diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 7f54250..e57defe 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -51,11 +51,7 @@ implementation uses {$IFDEF WINDOWS}Windows,{$ENDIF} -{$IFDEF USE_NANOGL} - nanoGL, -{$ELSE} - GL, GLExt, -{$ENDIF} +{$INCLUDE ../nogl/noGLuses.inc} {$IFDEF ENABLE_HOLMES} g_holmes, sdlcarcass, fui_ctls, {$ENDIF} @@ -98,9 +94,15 @@ begin if (h_Wnd <> nil) then SDL_DestroyWindow(h_Wnd); if (h_GL <> nil) and (not preserveGL) then begin + {$IFDEF USE_NANOGL} nanoGL_Destroy; -{$ENDIF USE_NANOGL} +{$ENDIF} + +{$IFDEF USE_NOGL} + nogl_Quit; +{$ENDIF} + SDL_GL_DeleteContext(h_GL); end; h_Wnd := nil; @@ -564,6 +566,9 @@ begin e_WriteLog('nanoGL initialization error', TMsgType.Fatal); exit; end; +{$ENDIF} +{$IFDEF USE_NOGL} + nogl_Init; {$ENDIF} {$IFDEF ENABLE_HOLMES} if (assigned(oglInitCB)) then oglInitCB(); @@ -819,7 +824,7 @@ end; procedure InitOpenGL (); begin {$IF not DEFINED(HEADLESS)} - {$IFDEF USE_NANOGL} + {$IFDEF USE_GLES1} SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); diff --git a/src/nogl/noGL.pas b/src/nogl/noGL.pas new file mode 100644 index 0000000..20d18bc --- /dev/null +++ b/src/nogl/noGL.pas @@ -0,0 +1,175 @@ +{$INCLUDE ../shared/a_modes.inc} +unit noGL; + +interface + + uses ctypes; + + type + GLenum = cuint; PGLenum = ^GLenum; + GLboolean = cuchar; PGLboolean = ^GLboolean; + GLbitfield = cuint; PGLbitfield = ^GLbitfield; + GLbyte = cschar; PGLbyte = ^GLbyte; + GLshort = cshort; PGLshort = ^GLshort; + GLint = cint; PGLint = ^GLint; + GLsizei = cint; PGLsizei = ^GLsizei; + GLubyte = cuchar; PGLubyte = ^GLubyte; + GLushort = cushort; PGLushort = ^GLushort; + GLuint = cuint; PGLuint = ^GLuint; + GLfloat = cfloat; PGLfloat = ^GLfloat; + GLclampf = cfloat; PGLclampf = ^GLclampf; + GLdouble = cdouble; PGLdouble = ^GLdouble; + GLclampd = cdouble; PGLclampd = ^GLclampd; + { GLvoid = void; } PGLvoid = Pointer; PPGLvoid = ^PGLvoid; + GLfixed = cint; PGLfixed = ^Integer; + GLclampx = cint; PGLclampx = ^Integer; + + TGLenum = GLenum; + TGLboolean = GLboolean; + TGLbitfield = GLbitfield; + TGLbyte = GLbyte; + TGLshort = GLshort; + TGLint = GLint; + TGLsizei = GLsizei; + TGLubyte = GLubyte; + TGLushort = GLushort; + TGLuint = GLuint; + TGLfloat = GLfloat; + TGLclampf = GLclampf; + TGLdouble = GLdouble; + TGLclampd = GLclampd; + TGLfixed = GLfixed; + TGLclampx = GLclampx; + + const + GL_NEAREST = $2600; + GL_DEPTH_TEST = $0B71; + GL_SCISSOR_TEST = $0C11; + GL_MODELVIEW = $1700; + GL_PROJECTION = $1701; + GL_BLEND = $0BE2; + GL_SRC_ALPHA = $0302; + GL_ONE_MINUS_SRC_ALPHA = $0303; + GL_ONE = $1; + GL_TEXTURE_2D = $0DE1; + GL_QUADS = $0007; + GL_ZERO = $0; + GL_POINTS = $0000; + GL_LINES = $0001; + GL_DST_COLOR = $0306; + GL_SRC_COLOR = $0300; + GL_ONE_MINUS_DST_COLOR = $0307; + GL_GREATER = $0204; + GL_COLOR_BUFFER_BIT = $00004000; + GL_RGB = $1907; + GL_UNSIGNED_BYTE = $1401; + GL_ALPHA_TEST = $0BC0; + GL_VIEWPORT = $0BA2; + GL_TEXTURE_WRAP_S = $2802; + GL_TEXTURE_WRAP_T = $2803; + GL_REPEAT = $2901; + GL_TEXTURE_MIN_FILTER = $2801; + GL_TEXTURE_MAG_FILTER = $2800; + GL_RGBA = $1908; + GL_POINT_SMOOTH = $0B10; + GL_STENCIL_TEST = $0B90; + GL_SCISSOR_BOX = $0C10; + GL_FALSE = $0; + GL_TRUE = $1; + GL_ALWAYS = $0207; + GL_STENCIL_BUFFER_BIT = $00000400; + GL_EQUAL = $0202; + GL_KEEP = $1E00; + GL_INCR = $1E02; + GL_LINEAR = $2601; + GL_EXTENSIONS = $1F03; + GL_TEXTURE_ENV = $2300; + GL_TEXTURE_ENV_MODE = $2200; + GL_MODULATE = $2100; + +// const +// GL_CULL_FACE = $0B44; +// GL_FLOAT = $1406; +// GL_VERTEX_ARRAY = $8074; +// GL_NORMAL_ARRAY = $8075; +// GL_COLOR_ARRAY = $8076; +// GL_TEXTURE_COORD_ARRAY = $8078; +// GL_NOTEQUAL = $0205; +// GL_LINE_SMOOTH = $0B20; +// GL_POLYGON_SMOOTH = $0B41; +// GL_LIGHTING = $0B50; +// GL_DITHER = $0BD0; +// GL_MODELVIEW_MATRIX = $0BA6; +// GL_MATRIX_MODE = $0BA0; +// GL_TEXTURE_BINDING_2D = $8069; +// GL_TEXTURE = $1702; +// GL_COLOR = $1800; +// GL_ALL_ATTRIB_BITS = $000FFFFF; + + procedure glEnable(cap: GLenum); + procedure glDisable(cap: GLenum); + function glIsEnabled(cap: GLenum): GLboolean; + function glGetString(name: GLenum): PChar; + procedure glClearColor(red, green, blue, alpha: GLclampf); + procedure glClear(mask: GLbitfield); + procedure glAlphaFunc(func: GLenum; ref: GLclampf); + procedure glBlendFunc(sfactor, dfactor: GLenum); + procedure glPointSize(size: GLfloat); + procedure glLineWidth(width: GLfloat); + procedure glGetIntegerv(pname: GLenum; params: PGLint); + procedure glFlush; + procedure glFinish; + + procedure glBegin(mode: GLenum); + procedure glEnd; + procedure glTexCoord2f(s, t: GLfloat); + procedure glVertex2i(x, y: GLint); + procedure glColor4ub(red, green, blue, alpha: GLubyte); + procedure glColor3ub(red, green, blue: GLubyte); + procedure glVertex2f(x, y: GLfloat); + procedure glTexCoord2i(s, t: GLint); + procedure glColor4f(red, green, blue, alpha: GLfloat); + + procedure glReadPixels(x, y: GLint; width, height: GLsizei; format, atype: GLenum; pixels: Pointer); + + procedure glLoadIdentity; + procedure glScissor(x, y: GLint; width, height: GLsizei); + procedure glViewport(x, y: GLint; width, height: GLsizei); + procedure glMatrixMode(mode: GLenum); + procedure glLoadMatrixd(const m: PGLdouble); + procedure glPushMatrix; + procedure glTranslatef(x, y, z: GLfloat); + procedure glRotatef(angle, x, y, z: GLfloat); + procedure glScalef(x, y, z: GLfloat); + procedure glPopMatrix; + + procedure glStencilMask(mask: GLuint); + procedure glStencilFunc(func: GLenum; ref: GLint; mask: GLuint); + procedure glStencilOp(fail, zfail, zpass: GLenum); + procedure glColorMask(red, green, blue, alpha: GLboolean); + + procedure glBindTexture(target: GLenum; texture: GLuint); + procedure glGenTextures(n: GLsizei; textures: PGLuint); + procedure glTexEnvi(target: GLenum; pname: GLenum; param: GLint); + procedure glTexParameterf(target: GLenum; pname: GLenum; param: GLfloat); + procedure glTexParameteri(target: GLenum; pname: GLenum; param: GLint); + procedure glTexImage2D(target: GLenum; level, internalformat: GLint; width, height: GLsizei; border: GLint; format, atype: GLenum; const pixels: Pointer); + procedure glTexSubImage2D(target: GLenum; level, xoffset, yoffset: GLint; width, height: GLsizei; format, atype: GLenum; const pixels: Pointer); + procedure glDeleteTextures(n: GLsizei; const textures: PGLuint); + +// procedure glVertexPointer(size: GLint; atype: GLenum; stride: GLsizei; const pointer: Pointer); +// procedure glEnableClientState(aarray: GLenum); +// procedure glDisableClientState(aarray: GLenum); +// procedure glDrawArrays(mode: GLenum; first: GLint; count: GLsizei); +// procedure glGetFloatv(pname: GLenum; params: PGLfloat); +// procedure glPushAttrib(mask: GLbitfield); +// procedure glOrtho(left, right, bottom, top, zNear, zFar: GLdouble); +// procedure glPopAttrib; +// procedure glColorPointer(size: GLint; atype: GLenum; stride: GLsizei; const pointer: Pointer); + + procedure nogl_Init; + procedure nogl_Quit; + +{$I noGLES1.inc} + +end. diff --git a/src/nogl/noGLES1.inc b/src/nogl/noGLES1.inc new file mode 100644 index 0000000..a4c6589 --- /dev/null +++ b/src/nogl/noGLES1.inc @@ -0,0 +1,519 @@ +implementation + + uses SDL2; + + const + GL_FLOAT = $1406; + GL_VERTEX_ARRAY = $8074; + GL_NORMAL_ARRAY = $8075; + GL_COLOR_ARRAY = $8076; + GL_TEXTURE_COORD_ARRAY = $8078; + GL_TRIANGLES = $0004; + GL_TEXTURE0 = $84C0; + GL_INVALID_ENUM = $0500; + + const + ValPerVertex = 2; + ValPerColor = 4; + ValPerCoord = 2; + + type + TArrayFloat = array of GLfloat; + + TCmds = record + mode: GLenum; + v, c, t: TArrayFloat; + end; + + var + cmds: TCmds; + + var + es_glVertexPointer: procedure (size: GLint; _type: GLenum; stride: GLsizei; pointer: PGLvoid); cdecl; + es_glColorPointer: procedure (size: GLint; _type: GLenum; stride: GLsizei; pointer: PGLvoid); cdecl; + es_glTexCoordPointer: procedure (size: GLint; _type: GLenum; stride: GLsizei; pointer: PGLvoid); cdecl; + es_glEnableClientState: procedure (arr: GLenum); cdecl; + es_glDisableClientState: procedure (arr: GLenum); cdecl; + es_glDrawArrays: procedure (mode: GLenum; first: GLint; count: GLsizei); cdecl; + es_glActiveTexture: procedure(texture: GLenum); cdecl; + es_glClientActiveTexture: procedure(texture: GLenum); cdecl; + es_glColor4f: procedure(red, green, blue, alpha: GLfloat); cdecl; + + es_glEnable: procedure (cap: GLenum); cdecl; + es_glDisable: procedure (cap: GLenum); cdecl; + es_glIsEnabled: function (cap: GLenum): GLBoolean; cdecl; + es_glGetString: function (name: GLenum): PChar; cdecl; + es_glClearColor: procedure (red, green, blue, alpha: GLclampf); cdecl; + es_glClear: procedure (mask: GLbitfield); cdecl; + es_glAlphaFunc: procedure (func: GLenum; ref: GLclampf); cdecl; + es_glBlendFunc: procedure (sfactor, dfactor: GLenum); cdecl; + es_glPointSize: procedure (size: GLfloat); cdecl; + es_glLineWidth: procedure (width: GLfloat); cdecl; + es_glGetIntegerv: procedure (pname: GLenum; params: PGLint); cdecl; + es_glFlush: procedure; cdecl; + es_glFinish: procedure; cdecl; + + es_glLoadIdentity: procedure; cdecl; + es_glMatrixMode: procedure (mode: GLenum); cdecl; + es_glLoadMatrixf: procedure (m: PGLfloat); cdecl; + es_glPushMatrix: procedure; cdecl; + es_glPopMatrix: procedure; cdecl; + es_glTranslatef: procedure (x, y, z: GLfloat); cdecl; + es_glRotatef: procedure (angle, x, y, z: GLfloat); cdecl; + es_glScalef: procedure (x, y, z: GLfloat); cdecl; + + es_glReadPixels: procedure (x, y: GLint; width, height: GLsizei; format,_type: GLenum; pixels: PGLvoid); cdecl; + + es_glViewport: procedure (x, y: GLint; width, height: GLsizei); cdecl; + es_glScissor: procedure (x, y: GLint; width, height: GLsizei); cdecl; + es_glStencilMask: procedure (mask: GLuint); cdecl; + es_glStencilFunc: procedure (func: GLenum; ref: GLint; mask: GLuint); cdecl; + es_glStencilOp: procedure (fail, zfail, zpass: GLenum); cdecl; + es_glColorMask: procedure (red: GLboolean; green: GLboolean; blue: GLboolean; alpha: GLboolean); cdecl; + + es_glBindTexture: procedure (target: GLenum; texture: GLuint); cdecl; + es_glGenTextures: procedure (n: GLsizei; textures: PGLuint); cdecl; + es_glTexEnvi: procedure (target: GLenum; pname: GLenum; param: GLint); cdecl; + es_glTexParameterf: procedure (target: GLenum; pname: GLenum; param: GLfloat); cdecl; + es_glTexParameteri: procedure (target: GLenum; pname: GLenum; param: GLint); cdecl; + es_glTexImage2D: procedure (target: GLenum; level, internalformat: GLint; width, height: GLsizei; border: GLint; format, _type:GLenum; pixels: PGLvoid); cdecl; + es_glTexSubImage2D: procedure (target: GLenum; level: GLint; xoffset, yoffset: GLint; width, height: GLsizei; format, _type: GLenum; pixels: PGLvoid); cdecl; + es_glDeleteTextures: procedure (n: GLsizei; textures: PGLuint); cdecl; + + procedure glEnable(cap: GLenum); + begin + es_glEnable(cap); + end; + + procedure glDisable(cap: GLenum); + begin + es_glDisable(cap); + end; + + function glIsEnabled(cap: GLenum): GLboolean; + begin + result := es_glIsEnabled(cap); + end; + + function glGetString(name: GLenum): PChar; + begin + result := es_glGetString(name); + end; + + procedure glClearColor(red, green, blue, alpha: GLclampf); + begin + es_glClearColor(red, green, blue, alpha); + end; + + procedure glClear(mask: GLbitfield); + begin + es_glClear(mask); + end; + + procedure glAlphaFunc(func: GLenum; ref: GLclampf); + begin + es_glAlphaFunc(func, ref); + end; + + procedure glBlendFunc(sfactor, dfactor: GLenum); + begin + es_glBlendFunc(sfactor, dfactor); + end; + + procedure glPointSize(size: GLfloat); + begin + es_glPointSize(size); + end; + + procedure glLineWidth(width: GLfloat); + begin + es_glLineWidth(width); + end; + + procedure glGetIntegerv(pname: GLenum; params: PGLint); + begin + es_glGetIntegerv(pname, params); + end; + + procedure glFlush; + begin + es_glFlush; + end; + + procedure glFinish; + begin + es_glFinish; + end; + + + + + + procedure glBegin(mode: GLenum); + begin + assert(cmds.mode = GL_INVALID_ENUM); + assert((mode = GL_POINTS) or (mode = GL_LINES) or (mode = GL_QUADS)); + cmds.mode := mode; + SetLength(cmds.v, 0); + SetLength(cmds.c, 0); + SetLength(cmds.t, 0); + end; + + procedure glEnd; + var count: Integer; + begin + assert(cmds.mode <> GL_INVALID_ENUM); + assert(Length(cmds.v) mod ValPerVertex = 0); + assert(Length(cmds.c) mod ValPerColor = 0); + assert(Length(cmds.t) mod ValPerCoord = 0); + if Length(cmds.c) <> 0 then + assert(Length(cmds.v) div ValPerVertex = Length(cmds.c) div ValPerColor); + if Length(cmds.t) <> 0 then + assert(Length(cmds.v) div ValPerVertex = Length(cmds.t) div ValPerCoord); + + es_glVertexPointer(ValPerVertex, GL_FLOAT, 0, @cmds.v[0]); + es_glColorPointer(ValPerColor, GL_FLOAT, 0, @cmds.c[0]); + es_glTexCoordPointer(ValPerCoord, GL_FLOAT, 0, @cmds.t[0]); + es_glEnableClientState(GL_VERTEX_ARRAY); + es_glEnableClientState(GL_COLOR_ARRAY); + es_glEnableClientState(GL_TEXTURE_COORD_ARRAY); + es_glDisableClientState(GL_NORMAL_ARRAY); + + if Length(cmds.c) = 0 then + es_glDisableClientState(GL_COLOR_ARRAY); + if Length(cmds.t) = 0 then + es_glDisableClientState(GL_TEXTURE_COORD_ARRAY); + + if cmds.mode = GL_QUADS then + es_glDrawArrays(GL_TRIANGLES, 0, Length(cmds.v) div ValPerVertex) + else + es_glDrawArrays(cmds.mode, 0, Length(cmds.v) div ValPerVertex); + + SetLength(cmds.v, 0); + SetLength(cmds.c, 0); + SetLength(cmds.t, 0); + cmds.mode := GL_INVALID_ENUM; + end; + +(* ---------- begin internals ---------- *) + + procedure AddFloatRaw (var x: TArrayFloat; f: GLfloat); + var i: Integer; + begin + i := Length(x); + SetLength(x, i + 1); + x[i] := f; + end; + + procedure AddFloatX (var x: TArrayFloat; v: array of GLfloat); inline; + var i, j, vpx: Integer; + begin + i := Length(x); + vpx := Length(v); + if (cmds.mode = GL_QUADS) and (i div vpx mod 4 = 3) then + begin + for j := 0 to vpx - 1 do + AddFloatRaw(x, x[i - 3*vpx + j]); + for j := 0 to vpx - 1 do + AddFloatRaw(x, x[i - 1*vpx + j]); + end; + for j := 0 to vpx - 1 do + AddFloatRaw(x, v[j]); + end; + +(* ---------- end internals ---------- *) + + procedure glVertex2f(x, y: GLfloat); + begin + AddFloatX(cmds.v, [x, y]); + end; + + procedure glVertex2i(x, y: GLint); + begin + AddFloatX(cmds.v, [x, y]); + end; + + procedure glColor4f(red, green, blue, alpha: GLfloat); + begin + if cmds.mode = GL_INVALID_ENUM then + es_glColor4f(red, green, blue, alpha) + else + AddFloatX(cmds.c, [red, green, blue, alpha]) + end; + + procedure glColor4ub(red, green, blue, alpha: GLubyte); + begin + glColor4f(red / 255, green / 255, blue / 255, alpha / 255) + end; + + procedure glColor3ub(red, green, blue: GLubyte); + begin + glColor4f(red / 255, green / 255, blue / 255, 255) + end; + + procedure glTexCoord2f(s, t: GLfloat); + begin + AddFloatX(cmds.t, [s, t]); + end; + + procedure glTexCoord2i(s, t: GLint); + begin + AddFloatX(cmds.t, [s, t]); + end; + + + + + + + + procedure glReadPixels(x, y: GLint; width, height: GLsizei; format, atype: GLenum; pixels: Pointer); + begin + es_glReadPixels(x, y, width, height, format, atype, pixels); + end; + + + + + + + procedure glLoadIdentity; + begin + es_glLoadIdentity; + end; + + procedure glMatrixMode(mode: GLenum); + begin + es_glMatrixMode(mode); + end; + + procedure glLoadMatrixd(const m: PGLdouble); + var + i: Integer; + n: array [0..15] of GLfloat; + begin + for i := 0 to 15 do + n[i] := m[i]; + es_glLoadMatrixf(@n[0]); + end; + + procedure glPushMatrix; + begin + es_glPushMatrix; + end; + + procedure glPopMatrix; + begin + es_glPopMatrix; + end; + + procedure glTranslatef(x, y, z: GLfloat); + begin + es_glTranslatef(x, y, z); + end; + + procedure glRotatef(angle, x, y, z: GLfloat); + begin + es_glRotatef(angle, x, y, z); + end; + + procedure glScalef(x, y, z: GLfloat); + begin + es_glScalef(x, y, z); + end; + + + + + + + procedure glViewport(x, y: GLint; width, height: GLsizei); + begin + es_glViewport(x, y, width, height); + end; + + procedure glScissor(x, y: GLint; width, height: GLsizei); + begin + es_glScissor(x, y, width, height); + end; + + procedure glStencilMask(mask: GLuint); + begin + es_glStencilMask(mask); + end; + + procedure glStencilFunc(func: GLenum; ref: GLint; mask: GLuint); + begin + es_glStencilFunc(func, ref, mask); + end; + + procedure glStencilOp(fail, zfail, zpass: GLenum); + begin + es_glStencilOp(fail, zfail, zpass); + end; + + procedure glColorMask(red, green, blue, alpha: GLboolean); + begin + es_glColorMask(red, green, blue, alpha); + end; + + + + + + + procedure glBindTexture(target: GLenum; texture: GLuint); + begin + es_glBindTexture(target, texture); + end; + + procedure glGenTextures(n: GLsizei; textures: PGLuint); + begin + es_glGenTextures(n, textures); + end; + + procedure glTexEnvi(target: GLenum; pname: GLenum; param: GLint); + begin + es_glTexEnvi(target, pname, param); + end; + + procedure glTexParameterf(target: GLenum; pname: GLenum; param: GLfloat); + begin + es_glTexParameterf(target, pname, param); + end; + + procedure glTexParameteri(target: GLenum; pname: GLenum; param: GLint); + begin + es_glTexParameteri(target, pname, param); + end; + + procedure glTexImage2D(target: GLenum; level, internalformat: GLint; width, height: GLsizei; border: GLint; format, atype: GLenum; const pixels: Pointer); + begin + es_glTexImage2D(target, level, internalformat, width, height, border, format, atype, pixels); + end; + + procedure glTexSubImage2D(target: GLenum; level, xoffset, yoffset: GLint; width, height: GLsizei; format, atype: GLenum; const pixels: Pointer); + begin + es_glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, atype, pixels); + end; + + procedure glDeleteTextures(n: GLsizei; const textures: PGLuint); + begin + es_glDeleteTextures(n, textures); + end; + + + + + + procedure nogl_Init; + begin + es_glVertexPointer := SDL_GL_GetProcAddress('glVertexPointer'); + es_glColorPointer := SDL_GL_GetProcAddress('glColorPointer'); + es_glTexCoordPointer := SDL_GL_GetProcAddress('glTexCoordPointer'); + es_glEnableClientState := SDL_GL_GetProcAddress('glEnableClientState'); + es_glDisableClientState := SDL_GL_GetProcAddress('glDisableClientState'); + es_glDrawArrays := SDL_GL_GetProcAddress('glDrawArrays'); + es_glActiveTexture := SDL_GL_GetProcAddress('glActiveTexture'); + es_glClientActiveTexture := SDL_GL_GetProcAddress('glClientActiveTexture'); + es_glColor4f := SDL_GL_GetProcAddress('glColor4f'); + + es_glEnable := SDL_GL_GetProcAddress('glEnable'); + es_glDisable := SDL_GL_GetProcAddress('glDisable'); + es_glIsEnabled := SDL_GL_GetProcAddress('glIsEnabled'); + es_glGetString := SDL_GL_GetProcAddress('glGetString'); + es_glClearColor := SDL_GL_GetProcAddress('glClearColor'); + es_glClear := SDL_GL_GetProcAddress('glClear'); + es_glAlphaFunc := SDL_GL_GetProcAddress('glAlphaFunc'); + es_glBlendFunc := SDL_GL_GetProcAddress('glBlendFunc'); + es_glPointSize := SDL_GL_GetProcAddress('glPointSize'); + es_glLineWidth := SDL_GL_GetProcAddress('glLineWidth'); + es_glGetIntegerv := SDL_GL_GetProcAddress('glGetIntegerv'); + es_glFlush := SDL_GL_GetProcAddress('glFlush'); + es_glFinish := SDL_GL_GetProcAddress('glFinish'); + + es_glLoadIdentity := SDL_GL_GetProcAddress('glLoadIdentity'); + es_glMatrixMode := SDL_GL_GetProcAddress('glMatrixMode'); + es_glLoadMatrixf := SDL_GL_GetProcAddress('glLoadMatrixf'); + es_glPushMatrix := SDL_GL_GetProcAddress('glPushMatrix'); + es_glPopMatrix := SDL_GL_GetProcAddress('glPopMatrix'); + es_glTranslatef := SDL_GL_GetProcAddress('glTranslatef'); + es_glRotatef := SDL_GL_GetProcAddress('glRotatef'); + es_glScalef := SDL_GL_GetProcAddress('glScalef'); + + es_glReadPixels := SDL_GL_GetProcAddress('glReadPixels'); + + es_glViewport := SDL_GL_GetProcAddress('glViewport'); + es_glScissor := SDL_GL_GetProcAddress('glScissor'); + es_glStencilMask := SDL_GL_GetProcAddress('glStencilMask'); + es_glStencilFunc := SDL_GL_GetProcAddress('glStencilFunc'); + es_glStencilOp := SDL_GL_GetProcAddress('glStencilOp'); + es_glColorMask := SDL_GL_GetProcAddress('glColorMask'); + + es_glBindTexture := SDL_GL_GetProcAddress('glBindTexture'); + es_glGenTextures := SDL_GL_GetProcAddress('glGenTextures'); + es_glTexEnvi := SDL_GL_GetProcAddress('glTexEnvi'); + es_glTexParameterf := SDL_GL_GetProcAddress('glTexParameterf'); + es_glTexParameteri := SDL_GL_GetProcAddress('glTexParameteri'); + es_glTexImage2D := SDL_GL_GetProcAddress('glTexImage2D'); + es_glTexSubImage2D := SDL_GL_GetProcAddress('glTexSubImage2D'); + es_glDeleteTextures := SDL_GL_GetProcAddress('glDeleteTextures'); + + cmds.mode := GL_INVALID_ENUM + end; + + procedure nogl_Quit; + begin + es_glVertexPointer := nil; + es_glColorPointer := nil; + es_glTexCoordPointer := nil; + es_glEnableClientState := nil; + es_glDisableClientState := nil; + es_glDrawArrays := nil; + es_glActiveTexture := nil; + es_glClientActiveTexture := nil; + es_glColor4f := nil; + + es_glEnable := nil; + es_glDisable := nil; + es_glIsEnabled := nil; + es_glGetString := nil; + es_glClearColor := nil; + es_glClear := nil; + es_glAlphaFunc := nil; + es_glBlendFunc := nil; + es_glPointSize := nil; + es_glLineWidth := nil; + es_glGetIntegerv := nil; + es_glFlush := nil; + es_glFinish := nil; + + es_glLoadIdentity := nil; + es_glMatrixMode := nil; + es_glLoadMatrixf := nil; + es_glPushMatrix := nil; + es_glPopMatrix := nil; + es_glTranslatef := nil; + es_glRotatef := nil; + es_glScalef := nil; + + es_glReadPixels := nil; + + es_glViewport := nil; + es_glScissor := nil; + es_glStencilMask := nil; + es_glStencilFunc := nil; + es_glStencilOp := nil; + es_glColorMask := nil; + + es_glBindTexture := nil; + es_glGenTextures := nil; + es_glTexEnvi := nil; + es_glTexParameterf := nil; + es_glTexParameteri := nil; + es_glTexImage2D := nil; + es_glTexSubImage2D := nil; + es_glDeleteTextures := nil; + end; + +initialization diff --git a/src/nogl/noGLuses.inc b/src/nogl/noGLuses.inc new file mode 100644 index 0000000..458f546 --- /dev/null +++ b/src/nogl/noGLuses.inc @@ -0,0 +1,27 @@ +{$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} +{$ENDIF}