From f79f2b1f4ea2100609a3aee4494e80558a005c5c Mon Sep 17 00:00:00 2001 From: JazzMaster Date: Mon, 24 Jun 2019 01:50:44 -0700 Subject: [PATCH] code cleanup and patch time --- SDL code/old bgi/lazgfx.pas | 63 +++++++++++++++++++++++++++++----- lazgfx.pas | 68 ++++++++++++++++--------------------- 2 files changed, 84 insertions(+), 47 deletions(-) diff --git a/SDL code/old bgi/lazgfx.pas b/SDL code/old bgi/lazgfx.pas index 4d58e44..a9cf149 100644 --- a/SDL code/old bgi/lazgfx.pas +++ b/SDL code/old bgi/lazgfx.pas @@ -1,6 +1,16 @@ Unit LazGFX; {$mode objfpc} +//Range and overflow checks =ON +{$Q+} +{$R+} + +{$IFDEF debug} +//memory tracing, along with heap. + {$S+} +{$ENDIF} + + { A "fully creative rewrite" of the "Borland Graphic Interface" in SDL(and maybe libSVGA) (c) 2017-18 (and beyond) Richard Jasmin -with the assistance of others. @@ -416,7 +426,15 @@ interface //if we need to use one or the other- // we will use CThreads. - cthreads,cmem,ctypes,sysUtils,{$IFDEF unix}baseunix,{$ENDIF} + cthreads,cmem,ctypes,classes, + +{$IFDEF unix} + sysUtils,baseunix, + {$IFDEF fallback} + X, XLib, //X11CorePrimitives + {$ENDIF} + +{$ENDIF} //ctypes: cint,uint,PTRUint,PTR-USINT,sint...etc. @@ -424,19 +442,31 @@ interface // A hackish trick...test if LCL unit(s) are loaded or linked in, then adjust "console" logging... {$IFDEF MSWINDOWS} //as if theres a non-MS WINDOWS? - MMsystem, //audio subsystem + Windows,MMsystem, //audio subsystem + + {$IFDEF fallback} + WinGraph, //WinAPI-needs rework + {$endif} + {$ENDIF} +{$IFDEF LCL} + {$IFDEF LCLGTK2} + gtk2, + {$ENDIF} + + {$IFDEF LCLQT} + qtwidgets, + {$ENDIF} - {$IFDEF LCL} + //works on Linux+Qt but not windows??? I have WINE and a VM- lets figure it out. + LazUtils, Interfaces, Dialogs, LCLType,Forms,Controls, {$IFDEF MSWINDOWS} + //we will check if this is set later. {$DEFINE NOCONSOLE } - //cant use crtstuff if theres no crt units available. - {$ENDIF} - //LCL is linked in but we are not in windows. Not critical. If you want output, set it up. - LazUtils, - {$ENDIF} + +{$ENDIF} //its possible to have a Windows "console app" thru FPC, @@ -466,7 +496,9 @@ interface //FPC generic units(OS independent) - SDL2,SDL2_TTF,strings,typinfo,SDL2_Image + SDL2,SDL2_TTF,strings,typinfo,SDL2_Image,uos,logger + +//Logger was the unit "throwing EIO errors" all over...FNF- I reset instead of reWrote... {for 3d: @@ -475,9 +507,22 @@ interface I still need to fix some "rendering bugs" with OGL. + + +STIPPLE(borrowed from GL): +-- -- -- -- -- -- (and lines like that) + + when drawing a line- this is supposed to dictate if the line is dashed or not + AND how thick it is. We can fake by isolating chunk percentages (not drawing)- + -or- + what we can do is: modify the new demo code with the "pixelled line" in it ... + +dotted and dashed lines are stipple, center uses other math + } + //SDL2_gfx is untested as of yet. functions start with GPU_ not SDL_. // gfx is "specific optimized routines" diff --git a/lazgfx.pas b/lazgfx.pas index 11d16b5..c936de0 100644 --- a/lazgfx.pas +++ b/lazgfx.pas @@ -12,25 +12,30 @@ ***** WARNING ****** -This code may be "irreprebly fucked". GL is refusing to chainload via library-as SDL/SDLv2 does. +This code may be "irreprebly fucked". + +PATCHED: + GL is refusing to chainload via library (solution: export the graphics context pointer) + + Further- output is inconsistent. -Rendered cubes are missing sides, etc. Vertexes being off is due to changes in the code- +Rendered cubes are missing sides, etc. + +Vertexes being off is due to changes in the code- but as of yet- doesnt produce this problem. -Several other SDL issues were noted since then. These are major bugs w SDL/GL. VENDORS DO NOT CARE ENOUGH to fix "GL in the drivers". - -So how things are working right now- I have NO IDEA. +So how things are working right now- for others- I have NO IDEA. ******************* Lazarus graphics unit is severely lacking(provides TCanvas instead)...use this instead. THIS IS NOT A GAME ENGINE. -Then engine stacks between this and your code. +This code stacks between "graphics routine filth" and your code. Only OPEN/free units and code will ever be here. Only cross-platform methods will be used. @@ -42,8 +47,9 @@ I dont care what you use the source code for. - I would prefer- however- - THAT YOU STICK TO FPC/LAZARUS. My support for other programming languages is LIMITED. +I would prefer- however- + THAT YOU STICK TO FPC/LAZARUS. +My support for other programming languages is LIMITED. You must cite original authors and sub authors, as appropriate(standard attribution rules) when modifying this code. DO NOT CLAIM THIS CODE AS YOUR OWN and you MAY NOT remove this notice. @@ -51,6 +57,7 @@ Notice that you use this unit-(or have modified it) and where to find the original sources (in your code) would be nice. It is not required, however. + } //exception handling requires oop- despite no oop or objects in use. @@ -63,7 +70,6 @@ {$R+} {$IFDEF debug} -//memory tracing only. {$S+} {$ENDIF} @@ -87,8 +93,7 @@ Although designed "for games programming"..the integration involved by the USE, ABUSE, and REUSE- of SDL and X11Core/WinAPI(GDI)/Cairo(GTK/GDK)/OpenGL/DirectX highlights so many OS internals its not even funny. -GL by itself doesnt require X11- but (GLX?) does require some X11 code for "input processing". -***GLX is broken. DONT USE IT. *** +GL -by itself(ES)- doesnt require X11- but (GLX?) does require some X11 code for "input processing". -It is Linux that is the complex BEAST that needs taming. Everyone seems to be writing in proprietary windowsGL, DirectX,etc. these days. @@ -102,8 +107,7 @@ interface This is not -and never will be- your program. Sorry, Jim. RELEASES are stable builds and nothing else is guaranteed. -We output to Surface/Texture (buffer/video buffer) usually via memcopy operations. - +We output thru Surface->Texture (buffer/video buffer) usually via memcopy operations. For framebuffer(tty access): @@ -112,7 +116,7 @@ interface We switch to graphics mode and do something (catch all crashes) We drop back to text mode -(framebuffer -FBO- is also a part of openGL--that I skip over) +(FBO- is a part of openGL--I skip over this mess- for now) Macintosh: @@ -246,10 +250,11 @@ interface Some idiot wrote the logging code wrong and it needs to be updated for FILE STREAM IO. I havent done this yet. + (Call me lazy or just not up "streaming Lazarus") You should log something. - + You should log everything. animations: to animate- @@ -286,7 +291,6 @@ interface WONTFIX: "Rendering onto more than one window (or renderer) can cause issues" -"You must render in the same window that handles input" ("depth" in OGL is considered cubic depth (think layers of felt) , not bpp) @@ -297,23 +301,13 @@ interface TODO: - Get some framebuffer fallback code working and put it here. + Get some framebuffer fallback code working and put it here. (DAMN YOU- and your changes, Linus!) } -//dont remove this (it enables windows units to work as-is) - -{$MACRO on} -{$ifdef mswindows} - {$DEFINE extdecl:= stdcall} -{$ELSE} - {$DEFINE extdecl:= cdecl} -{$ENDIF} - -//use: -// procedure exes(why:iduuno):exes; extdecl; +//this will not work "for callbacks": +//ifdef mswindows: cdecl-> stdcall -//extern; is different... uses @@ -536,7 +530,6 @@ Twhere=record //sort of -SDL_Rect implementation PSDL_Rect=^Rect; -PRect=^Rect; SDLRect=record x:byte; y:byte; @@ -544,12 +537,6 @@ SDLRect=record w:byte; end; -Rect=record - x:byte; - y:byte; - h:byte; - w:byte; -end; { A Ton of code enforces a viewport mandate- that even sans viewports- the screen is one. @@ -561,10 +548,10 @@ Rect=record Theres only ONE Fatal Flaw in the old code: It presumes use on PC only. Presumption and ASSumptions are BAD. -How do you detect non-PC variants? In this case- you make another unit. +How do you detect non-PC variants? In this case- you make another unit for that platform. } - graphics_driver=(DETECT, FakeCGA, VGA,VESA); + graphics_driver=(DETECT, CGA,EGA, VGA,VESA); { @@ -594,6 +581,7 @@ Vertex3d=record z:Word; end; + //usully goes around clock-wise Quad=array [0..3] of Vertex; @@ -602,11 +590,13 @@ Vertex3d=record {$ifndef mswindows} +//bytes PSDL_Color=^SDL_Color; SDL_Color=record r,g,b,a:byte; end; +//floats GL_Color=record r,g,b,a:single; end; @@ -672,6 +662,8 @@ Tmode=record //you cant fuck up the first 16- Borland INC (RIP) made that "the standard" TPalette16Names=(BLACK,RED,BLUE,GREEN,CYAN,MAGENTA,BROWN,LTGRAY,GRAY,LTRED,LTBLUE,LTGREEN,LTCYAN,LTMAGENTA,YELLOW,WHITE); + +//not pulled from specs yet TPalette64Names=( BLACK64, RED64,