Skip to content

Commit

Permalink
code cleanup and patch time
Browse files Browse the repository at this point in the history
  • Loading branch information
JazzMaster committed Jun 24, 2019
1 parent 0bf9936 commit f79f2b1
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 47 deletions.
63 changes: 54 additions & 9 deletions SDL code/old bgi/lazgfx.pas
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -416,27 +426,47 @@ 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.


// 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,
Expand Down Expand Up @@ -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:
Expand All @@ -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"

Expand Down
68 changes: 30 additions & 38 deletions lazgfx.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -42,15 +47,17 @@
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.
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.
Expand All @@ -63,7 +70,6 @@
{$R+}

{$IFDEF debug}
//memory tracing only.
{$S+}
{$ENDIF}

Expand All @@ -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.
Expand All @@ -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):
Expand All @@ -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:
Expand Down Expand Up @@ -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-
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -536,20 +530,13 @@ Twhere=record
//sort of -SDL_Rect implementation

PSDL_Rect=^Rect;
PRect=^Rect;
SDLRect=record
x:byte;
y:byte;
h:byte;
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.
Expand All @@ -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);


{
Expand Down Expand Up @@ -594,6 +581,7 @@ Vertex3d=record
z:Word;
end;


//usully goes around clock-wise
Quad=array [0..3] of Vertex;

Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f79f2b1

Please sign in to comment.