+namespace gfx::drivers;
+
+#ifdef BUILDING_ECERE_COM
+import "instance"
+import "Display"
+#else
+#ifdef ECERE_STATIC
+public import static "ecere"
+#else
+public import "ecere"
+#endif
+#endif
+
+import "SDLInterface"
+
+#if !defined(NO_SDL_DRIVERS) && !defined(NO_SDL1_DRIVER)
+
+#include <stdio.h>
+
+// source file line number printf (sflnprintf)
+#define sflnprintf(format,...) printf("%s:% 5d: " format, __FILE__, __LINE__, ##__VA_ARGS__)
+
+#define watch _watch
+#include <SDL.h>
+#undef watch
+
+class SDLDisplay : LFBDisplay
+{
+};
+
+class SDLDisplayDriver : DisplayDriver
+{
+ class_property(name) = "SDL1";
+
+
+ // Constructor / Destructor
+
+ bool ::CreateDisplaySystem(DisplaySystem displaySystem)
+ {
+ bool result = false;
+ sflnprintf("class(SDLDisplayDriver) ::CreateDisplaySystem [WIP!]\n");
+ displaySystem.flags.memBackBuffer = true;
+ result = true;
+ return result;
+ }
+
+ void ::DestroyDisplaySystem(DisplaySystem displaySystem)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::DestroyDisplaySystem [STUB!]\n");
+ }
+
+ bool ::CreateDisplay(Display display)
+ {
+ bool result = false;
+ SDLDisplay sdlDisplay = display.driverData = SDLDisplay { };
+ sflnprintf("class(SDLDisplayDriver) ::CreateDisplay [WIP!]\n");
+ if(sdlDisplay)
+ {
+ // To find out the format...
+ DisplaySize(display, 1, 1);
+ result = true;
+ }
+ return result;
+ }
+
+ void ::DestroyDisplay(Display display)
+ {
+ SDLDisplay sdlDisplay = display.driverData;
+ sflnprintf("class(SDLDisplayDriver) ::DestroyDisplay [STUB!]\n");
+
+ if(display)
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).DestroyDisplay(display);
+
+ // TODO: Implementation
+
+ delete sdlDisplay;
+ display.driverData = null;
+ }
+
+
+ // Display Position and Size
+
+ bool ::DisplaySize(Display display, int width, int height)
+ {
+ SDLDisplay sdlDisplay = display.driverData;
+ bool result = false;
+ sflnprintf("class(SDLDisplayDriver) ::DisplaySize [WIP!]\n");
+
+ // TODO: Implementation
+
+ /*
+ bool validFormat = true;
+ switch(backDesc.ddpfPixelFormat.dwRGBBitCount)
+ {
+ case 8: bitmap.pixelFormat = pixelFormat8; break;
+ case 15: bitmap.pixelFormat = pixelFormat555; break;
+ case 16:
+ if(backDesc.ddpfPixelFormat.dwGBitMask == 0x3E0)
+ bitmap.pixelFormat = pixelFormat555;
+ else
+ bitmap.pixelFormat = pixelFormat565;
+ break;
+ case 32:
+ bitmap.pixelFormat = pixelFormat888; break;
+ default:
+ validFormat = false;
+ break;
+ }
+ if(validFormat)
+ {
+ bitmap.picture = (byte *)backDesc.lpSurface;
+ bitmap.stride = backDesc.lPitch;
+ bitmap.stride >>= GetColorDepthShifts(bitmap.pixelFormat);
+ bitmap.size = bitmap.stride * bitmap.height;
+ }
+ */
+ display.displaySystem.pixelFormat = sdlDisplay.bitmap.pixelFormat;
+ result = true;
+
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).DisplaySize(display, width, height);
+
+ display.width = width;
+ display.height = height;
+
+ return result;
+ }
+
+ void ::DisplayPosition(Display display, int x, int y)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).DisplayPosition(display, x, y);
+ }
+
+
+ // Palettes
+
+ void ::SetPalette(Display display, ColorAlpha * palette, bool colorMatch)
+ {
+ SDLDisplay sdlDisplay = display.driverData;
+ sflnprintf("class(SDLDisplayDriver) ::SetPalette [WIP!]\n");
+ if(sdlDisplay.bitmap.pixelFormat == pixelFormat8)
+ {
+ // TODO: Implementation
+ }
+ else
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetPalette(display, palette, colorMatch);
+ }
+
+ void ::RestorePalette(Display display)
+ {
+ //SDLDisplay sdlDisplay = display.driverData;
+ sflnprintf("class(SDLDisplayDriver) ::RestorePalette [STUB!]\n");
+ }
+
+
+ // Display the back buffer content
+
+ void ::StartUpdate(Display display)
+ {
+ //SDLDisplay sdlDisplay = display.driverData;
+ sflnprintf("class(SDLDisplayDriver) ::StartUpdate [STUB!]\n");
+ }
+
+ void ::EndUpdate(Display display)
+ {
+ //SDLDisplay sdlDisplay = display.driverData;
+ sflnprintf("class(SDL2DisplayDriver) ::EndUpdate [STUB!]\n");
+ //--//SDL_RenderPresent();
+ }
+
+ void ::Scroll(Display display, Box scroll, int x, int y, Extent dirty)
+ {
+ }
+
+ void ::Update(Display display, Box updateBox)
+ {
+ //SDLDisplay sdlDisplay = display.driverData;
+ //--//Box * box = updateBox;
+ sflnprintf("class(SDLDisplayDriver) ::Update [STUB!]\n");
+ // SDL_RenderPresent();
+ }
+
+
+ // Allocate/free a bitmap
+
+ bool ::AllocateBitmap(DisplaySystem displaySystem, Bitmap bitmap, int width, int height, int stride, PixelFormat format, bool allocatePalette)
+ {
+ return ((subclass(DisplayDriver))class(LFBDisplayDriver)).AllocateBitmap(displaySystem, bitmap, width, height, stride, format, allocatePalette);
+ }
+
+ void ::FreeBitmap(DisplaySystem displaySystem, Bitmap bitmap)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).FreeBitmap(displaySystem, bitmap);
+ }
+
+
+ // Lock
+
+ bool ::LockSystem(DisplaySystem displaySystem)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::LockSystem [STUB!]\n");
+ return false;
+ }
+
+ void ::UnlockSystem(DisplaySystem displaySystem)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::UnlockSystem [STUB!]\n");
+ }
+
+ bool ::Lock(Display display)
+ {
+ //SDLDisplay sdlDisplay = display.driverData;
+ sflnprintf("class(SDLDisplayDriver) ::Lock [STUB!]\n");
+ return true;
+ }
+
+ void ::Unlock(Display display)
+ {
+ //SDLDisplay sdlDisplay = display.driverData;
+ sflnprintf("class(SDLDisplayDriver) ::Unlock [STUB!]\n");
+ }
+
+
+ // Get/release a surface
+
+ bool ::GetSurface(Display display, Surface surface, int x,int y, Box clip)
+ {
+ //SDLDisplay sdlDisplay = display.driverData;
+ LFBSurface lfbSurface;
+ bool result = false;
+ sflnprintf("class(SDLDisplayDriver) ::GetSurface [WIP!]\n");
+ {
+ if((surface.driverData = lfbSurface = LFBSurface { }))
+ {
+ surface.offset.x = x;
+ surface.offset.y = y;
+ //surface.unclippedBox = surface.box = clip;
+ // TODO: Implementation
+ result = ((subclass(DisplayDriver))class(LFBDisplayDriver)).GetSurface(display, surface, x, y, clip);
+ }
+ }
+ return result;
+ }
+
+ bool ::GetBitmapSurface(DisplaySystem displaySystem, Surface surface, Bitmap bitmap, int x, int y, Box clip)
+ {
+ return ((subclass(DisplayDriver))class(LFBDisplayDriver)).GetBitmapSurface(displaySystem, surface, bitmap, x, y, clip);
+ }
+
+ void ::ReleaseSurface(Display display, Surface surface)
+ {
+ //SDLDisplay sdlDisplay = display.driverData;
+ sflnprintf("class(SDL2DisplayDriver) ::ReleaseSurface [WIP!]\n");
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).ReleaseSurface(display, surface);
+ // TODO: Implementation
+ }
+
+
+ // Clip a surface
+
+ void ::Clip(Display display, Surface surface, Box clip)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).Clip(display, surface, clip);
+ }
+
+
+ // Grab from the screen
+
+ bool ::GrabScreen(Display display, Bitmap bitmap, int x, int y, unsigned int w, unsigned int h)
+ {
+ bool result = false;
+ //SDLDisplay sdlDisplay = display.driverData;
+ sflnprintf("class(SDL2DisplayDriver) ::GrabScreen [WIP!]\n");
+ // TODO: Implementation
+ result = ((subclass(DisplayDriver))class(LFBDisplayDriver)).GrabScreen(display, bitmap, x,y, w,h);
+ return result;
+ }
+
+
+ // Converts a bitmap format
+
+ bool ::ConvertBitmap(DisplaySystem displaySystem, Bitmap src, PixelFormat format, ColorAlpha * palette)
+ {
+ return ((subclass(DisplayDriver))class(LFBDisplayDriver)).ConvertBitmap(displaySystem, src, format, palette);
+ }
+
+
+ // Converts an LFB bitmap into an offscreen bitmap for this device
+
+ bool ::MakeDDBitmap(DisplaySystem displaySystem, Bitmap bitmap, bool mipMaps)
+ {
+ return ((subclass(DisplayDriver))class(LFBDisplayDriver)).MakeDDBitmap(displaySystem, bitmap, mipMaps);
+ }
+
+
+ // Font loading
+
+ Font ::LoadFont(DisplaySystem displaySystem, const char * faceName, float size, FontFlags flags)
+ {
+ Font font = (Font)((subclass(DisplayDriver))class(LFBDisplayDriver)).LoadFont(displaySystem, faceName, size, flags);
+ return font;
+ }
+
+ void ::UnloadFont(DisplaySystem displaySystem, Font font)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).UnloadFont(displaySystem, font);
+ }
+
+
+ // 2D Drawing
+
+ void ::SetForeground(Display display, Surface surface, ColorAlpha color)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetForeground(display, surface, color);
+ }
+
+ void ::SetBackground(Display display, Surface surface, ColorAlpha color)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetBackground(display, surface, color);
+ }
+
+ void ::SetBlitTint(Display display, Surface surface, ColorAlpha tint)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::SetBlitTint [STUB!]\n");
+ }
+
+ void ::LineStipple(Display display, Surface surface, uint stipple)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).LineStipple(display, surface, stipple);
+ }
+
+ ColorAlpha ::GetPixel(Display display, Surface surface, int x, int y)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::GetPixel [STUB!]\n");
+ return 0;
+ }
+
+ void ::PutPixel(Display display, Surface surface, int x, int y)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).PutPixel(display, surface, x,y);
+ }
+
+ void ::DrawLine(Display display, Surface surface, int x1, int y1, int x2, int y2)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).DrawLine(display, surface, x1,y1,x2,y2);
+ }
+
+ void ::Rectangle(Display display, Surface surface, int x1, int y1, int x2, int y2)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).Rectangle(display, surface, x1,y1,x2,y2);
+ }
+
+ void ::Area(Display display, Surface surface,int x1, int y1, int x2, int y2)
+ {
+ /* if(x1>x2) { int tmp = x2; x2 = x1; x1 = tmp; }
+
+ if(x1<surface.box.left) x1=surface.box.left;
+ if(x2>surface.box.right) x2=surface.box.right;
+ if(y1<surface.box.top) y1=surface.box.top;
+ if(y2>surface.box.bottom) y2=surface.box.bottom;
+*/
+ x1 += surface.offset.x;
+ x2 += surface.offset.x;
+ y1 += surface.offset.y;
+ y2 += surface.offset.y;
+
+ {
+ //--//SDL_Rect rect = { (short)x1, (short)y1, (short)(x2-x1+1), (short)(y2-y1+1) };
+ //--//SDL_SetRenderDrawColor(surface.background.color.r, surface.background.color.g, surface.background.color.b, surface.background.a);
+ //--//SDL_RenderFill(&rect);
+ //SDL_FillRect()
+ // ((subclass(DisplayDriver))class(LFBDisplayDriver)).Area(display, surface, x1,y1,x2,y2);
+ }
+ }
+
+ void ::Clear(Display display, Surface surface, ClearType type)
+ {
+ sflnprintf("class(SDL2DisplayDriver) ::Clear [WIP!]\n");
+ //--//SDL_Rect rect = { (short)surface.box.left, (short)surface.box.top, (short)(surface.box.right-surface.box.left+1), (short)(surface.box.bottom-surface.box.top+1) };
+ //--//SDL_SetRenderDrawColor(surface.background.color.r, surface.background.color.g, surface.background.color.b, surface.background.a);
+ //--//SDL_RenderFill(&rect);
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).Clear(display, surface, type);
+ }
+
+ void ::Blit(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).Blit(display, surface, src, dx, dy, sx, sy, w, h);
+ }
+
+ void ::Stretch(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).Stretch(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
+ }
+
+ void ::Filter(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).Filter(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
+ }
+
+ void ::BlitDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h)
+ {
+ // Using Blit()
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).Blit(display, surface, src, dx, dy, sx, sy, w, h);
+ }
+
+ void ::StretchDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
+ {
+ // Using Stretch()
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).Stretch(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
+ }
+
+ void ::FilterDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
+ {
+ // Using Filter()
+ //Filter(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).Filter(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
+ }
+
+ void ::TextFont(Display display, Surface surface, Font font)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).TextFont(display, surface, font);
+ // why this?
+ SetForeground(display, surface, surface.foreground);
+ }
+
+ void ::TextOpacity(Display display, Surface surface, bool opaque)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).TextOpacity(display, surface, opaque);
+ }
+
+ void ::WriteText(Display display, Surface surface, int x, int y, const char * text, int len)
+ {
+ if(surface.textOpacity)
+ {
+ int w, h;
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).FontExtent(display.displaySystem, surface.font, text, len, &w, &h);
+ Area(display, surface, x, y, x+w-1, y+h-1);
+ }
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).WriteText(display, surface, x,y, text, len);
+ }
+
+ void ::TextExtent(Display display, Surface surface, const char * text, int len, int * width, int * height)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).TextExtent(display, surface, text, len, width, height);
+ }
+
+ void ::FontExtent(DisplaySystem displaySystem, Font font, const char * text, int len, int * width, int * height)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).FontExtent(displaySystem, font, text, len, width, height);
+ }
+
+ void ::DrawingChar(Display display, Surface surface, char character)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::DrawingChar [STUB!]\n");
+ }
+
+ void ::NextPage(Display display)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::NextPage [STUB!]\n");
+ }
+
+ // 3D Graphics
+
+#if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
+ void ::SetRenderState(Display display, RenderState state, uint value)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::SetRenderState [STUB!]\n");
+ }
+
+ void ::SetLight(Display display, int id, Light light)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::SetLight [STUB!]\n");
+ }
+
+ void ::SetCamera(Display display, Surface surface, Camera camera)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::SetCamera [STUB!]\n");
+ }
+
+ bool ::AllocateMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags, int nVertices)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::AllocateMesh [STUB!]\n");
+ return false;
+ }
+
+ void ::FreeMesh(DisplaySystem displaySystem, Mesh mesh)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::FreeMesh [STUB!]\n");
+ }
+
+ bool ::LockMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::LockMesh [STUB!]\n");
+ return false;
+ }
+
+ void ::UnlockMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::UnlockMesh [STUB!]\n");
+ }
+
+ void * ::AllocateIndices(DisplaySystem displaySystem, int nIndices, bool indices32bit)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::AllocateIndices [STUB!]\n");
+ return null;
+ }
+
+ void ::FreeIndices(DisplaySystem displaySystem, void * indices)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::FreeIndices [STUB!]\n");
+ }
+
+ uint16 * ::LockIndices(DisplaySystem displaySystem, void * indices)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::LockIndices [STUB!]\n");
+ return null;
+ }
+
+ void ::UnlockIndices(DisplaySystem displaySystem, void * indices, bool indices32bit, int nIndices)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::UnlockIndices [STUB!]\n");
+ }
+
+ void ::SelectMesh(Display display, Mesh mesh)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::SelectMesh [STUB!]\n");
+ }
+
+ void ::ApplyMaterial(Display display, Material material, Mesh mesh)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::ApplyMaterial [STUB!]\n");
+ }
+
+ void ::DrawPrimitives(Display display, PrimitiveSingle * primitive, Mesh mesh)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::DrawPrimitives [STUB!]\n");
+ }
+
+ void ::PushMatrix(Display display)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::PushMatrix [STUB!]\n");
+ }
+
+ void ::PopMatrix(Display display, bool setMatrix)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::PopMatrix [STUB!]\n");
+ }
+
+ void ::SetTransform(Display display, Matrix transMatrix, bool viewSpace, bool useCamera)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::SetTransform [STUB!]\n");
+ }
+#endif
+
+}
+
+#endif // !defined(NO_SDL_DRIVERS) && !defined(NO_SDL1_DRIVER)