1 namespace gfx::drivers;
3 #ifdef BUILDING_ECERE_COM
8 public import static "ecere"
16 #if !defined(NO_SDL_DRIVERS) && !defined(NO_SDL1_DRIVER)
20 // source file line number printf (sflnprintf)
21 #define sflnprintf(format,...) printf("%s:% 5d: " format, __FILE__, __LINE__, ##__VA_ARGS__)
27 class SDLDisplay : LFBDisplay
31 class SDLDisplayDriver : DisplayDriver
33 class_property(name) = "SDL1";
36 // Constructor / Destructor
38 bool ::CreateDisplaySystem(DisplaySystem displaySystem)
41 sflnprintf("class(SDLDisplayDriver) ::CreateDisplaySystem [WIP!]\n");
42 displaySystem.flags.memBackBuffer = true;
47 void ::DestroyDisplaySystem(DisplaySystem displaySystem)
49 sflnprintf("class(SDLDisplayDriver) ::DestroyDisplaySystem [STUB!]\n");
52 bool ::CreateDisplay(Display display)
55 SDLDisplay sdlDisplay = display.driverData = SDLDisplay { };
56 sflnprintf("class(SDLDisplayDriver) ::CreateDisplay [WIP!]\n");
59 // To find out the format...
60 DisplaySize(display, 1, 1);
66 void ::DestroyDisplay(Display display)
68 SDLDisplay sdlDisplay = display.driverData;
69 sflnprintf("class(SDLDisplayDriver) ::DestroyDisplay [STUB!]\n");
72 ((subclass(DisplayDriver))class(LFBDisplayDriver)).DestroyDisplay(display);
74 // TODO: Implementation
77 display.driverData = null;
81 // Display Position and Size
83 bool ::DisplaySize(Display display, int width, int height)
85 SDLDisplay sdlDisplay = display.driverData;
87 sflnprintf("class(SDLDisplayDriver) ::DisplaySize [WIP!]\n");
89 // TODO: Implementation
92 bool validFormat = true;
93 switch(backDesc.ddpfPixelFormat.dwRGBBitCount)
95 case 8: bitmap.pixelFormat = pixelFormat8; break;
96 case 15: bitmap.pixelFormat = pixelFormat555; break;
98 if(backDesc.ddpfPixelFormat.dwGBitMask == 0x3E0)
99 bitmap.pixelFormat = pixelFormat555;
101 bitmap.pixelFormat = pixelFormat565;
104 bitmap.pixelFormat = pixelFormat888; break;
111 bitmap.picture = (byte *)backDesc.lpSurface;
112 bitmap.stride = backDesc.lPitch;
113 bitmap.stride >>= GetColorDepthShifts(bitmap.pixelFormat);
114 bitmap.size = bitmap.stride * bitmap.height;
117 display.displaySystem.pixelFormat = sdlDisplay.bitmap.pixelFormat;
120 ((subclass(DisplayDriver))class(LFBDisplayDriver)).DisplaySize(display, width, height);
122 display.width = width;
123 display.height = height;
128 void ::DisplayPosition(Display display, int x, int y)
130 ((subclass(DisplayDriver))class(LFBDisplayDriver)).DisplayPosition(display, x, y);
136 void ::SetPalette(Display display, ColorAlpha * palette, bool colorMatch)
138 SDLDisplay sdlDisplay = display.driverData;
139 sflnprintf("class(SDLDisplayDriver) ::SetPalette [WIP!]\n");
140 if(sdlDisplay.bitmap.pixelFormat == pixelFormat8)
142 // TODO: Implementation
145 ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetPalette(display, palette, colorMatch);
148 void ::RestorePalette(Display display)
150 //SDLDisplay sdlDisplay = display.driverData;
151 sflnprintf("class(SDLDisplayDriver) ::RestorePalette [STUB!]\n");
155 // Display the back buffer content
157 void ::StartUpdate(Display display)
159 //SDLDisplay sdlDisplay = display.driverData;
160 sflnprintf("class(SDLDisplayDriver) ::StartUpdate [STUB!]\n");
163 void ::EndUpdate(Display display)
165 //SDLDisplay sdlDisplay = display.driverData;
166 sflnprintf("class(SDL2DisplayDriver) ::EndUpdate [STUB!]\n");
167 //--//SDL_RenderPresent();
170 void ::Scroll(Display display, Box scroll, int x, int y, Extent dirty)
174 void ::Update(Display display, Box updateBox)
176 //SDLDisplay sdlDisplay = display.driverData;
177 //--//Box * box = updateBox;
178 sflnprintf("class(SDLDisplayDriver) ::Update [STUB!]\n");
179 // SDL_RenderPresent();
183 // Allocate/free a bitmap
185 bool ::AllocateBitmap(DisplaySystem displaySystem, Bitmap bitmap, int width, int height, int stride, PixelFormat format, bool allocatePalette)
187 return ((subclass(DisplayDriver))class(LFBDisplayDriver)).AllocateBitmap(displaySystem, bitmap, width, height, stride, format, allocatePalette);
190 void ::FreeBitmap(DisplaySystem displaySystem, Bitmap bitmap)
192 ((subclass(DisplayDriver))class(LFBDisplayDriver)).FreeBitmap(displaySystem, bitmap);
198 bool ::LockSystem(DisplaySystem displaySystem)
200 sflnprintf("class(SDLDisplayDriver) ::LockSystem [STUB!]\n");
204 void ::UnlockSystem(DisplaySystem displaySystem)
206 sflnprintf("class(SDLDisplayDriver) ::UnlockSystem [STUB!]\n");
209 bool ::Lock(Display display)
211 //SDLDisplay sdlDisplay = display.driverData;
212 sflnprintf("class(SDLDisplayDriver) ::Lock [STUB!]\n");
216 void ::Unlock(Display display)
218 //SDLDisplay sdlDisplay = display.driverData;
219 sflnprintf("class(SDLDisplayDriver) ::Unlock [STUB!]\n");
223 // Get/release a surface
225 bool ::GetSurface(Display display, Surface surface, int x,int y, Box clip)
227 //SDLDisplay sdlDisplay = display.driverData;
228 LFBSurface lfbSurface;
230 sflnprintf("class(SDLDisplayDriver) ::GetSurface [WIP!]\n");
232 if((surface.driverData = lfbSurface = LFBSurface { }))
234 surface.offset.x = x;
235 surface.offset.y = y;
236 //surface.unclippedBox = surface.box = clip;
237 // TODO: Implementation
238 result = ((subclass(DisplayDriver))class(LFBDisplayDriver)).GetSurface(display, surface, x, y, clip);
244 bool ::GetBitmapSurface(DisplaySystem displaySystem, Surface surface, Bitmap bitmap, int x, int y, Box clip)
246 return ((subclass(DisplayDriver))class(LFBDisplayDriver)).GetBitmapSurface(displaySystem, surface, bitmap, x, y, clip);
249 void ::ReleaseSurface(Display display, Surface surface)
251 //SDLDisplay sdlDisplay = display.driverData;
252 sflnprintf("class(SDL2DisplayDriver) ::ReleaseSurface [WIP!]\n");
253 ((subclass(DisplayDriver))class(LFBDisplayDriver)).ReleaseSurface(display, surface);
254 // TODO: Implementation
260 void ::Clip(Display display, Surface surface, Box clip)
262 ((subclass(DisplayDriver))class(LFBDisplayDriver)).Clip(display, surface, clip);
266 // Grab from the screen
268 bool ::GrabScreen(Display display, Bitmap bitmap, int x, int y, unsigned int w, unsigned int h)
271 //SDLDisplay sdlDisplay = display.driverData;
272 sflnprintf("class(SDL2DisplayDriver) ::GrabScreen [WIP!]\n");
273 // TODO: Implementation
274 result = ((subclass(DisplayDriver))class(LFBDisplayDriver)).GrabScreen(display, bitmap, x,y, w,h);
279 // Converts a bitmap format
281 bool ::ConvertBitmap(DisplaySystem displaySystem, Bitmap src, PixelFormat format, ColorAlpha * palette)
283 return ((subclass(DisplayDriver))class(LFBDisplayDriver)).ConvertBitmap(displaySystem, src, format, palette);
287 // Converts an LFB bitmap into an offscreen bitmap for this device
289 bool ::MakeDDBitmap(DisplaySystem displaySystem, Bitmap bitmap, bool mipMaps)
291 return ((subclass(DisplayDriver))class(LFBDisplayDriver)).MakeDDBitmap(displaySystem, bitmap, mipMaps);
297 Font ::LoadFont(DisplaySystem displaySystem, const char * faceName, float size, FontFlags flags)
299 Font font = (Font)((subclass(DisplayDriver))class(LFBDisplayDriver)).LoadFont(displaySystem, faceName, size, flags);
303 void ::UnloadFont(DisplaySystem displaySystem, Font font)
305 ((subclass(DisplayDriver))class(LFBDisplayDriver)).UnloadFont(displaySystem, font);
311 void ::SetForeground(Display display, Surface surface, ColorAlpha color)
313 ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetForeground(display, surface, color);
316 void ::SetBackground(Display display, Surface surface, ColorAlpha color)
318 ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetBackground(display, surface, color);
321 void ::SetBlitTint(Display display, Surface surface, ColorAlpha tint)
323 sflnprintf("class(SDLDisplayDriver) ::SetBlitTint [STUB!]\n");
326 void ::LineStipple(Display display, Surface surface, uint stipple)
328 ((subclass(DisplayDriver))class(LFBDisplayDriver)).LineStipple(display, surface, stipple);
331 ColorAlpha ::GetPixel(Display display, Surface surface, int x, int y)
333 sflnprintf("class(SDLDisplayDriver) ::GetPixel [STUB!]\n");
337 void ::PutPixel(Display display, Surface surface, int x, int y)
339 ((subclass(DisplayDriver))class(LFBDisplayDriver)).PutPixel(display, surface, x,y);
342 void ::DrawLine(Display display, Surface surface, int x1, int y1, int x2, int y2)
344 ((subclass(DisplayDriver))class(LFBDisplayDriver)).DrawLine(display, surface, x1,y1,x2,y2);
347 void ::Rectangle(Display display, Surface surface, int x1, int y1, int x2, int y2)
349 ((subclass(DisplayDriver))class(LFBDisplayDriver)).Rectangle(display, surface, x1,y1,x2,y2);
352 void ::Area(Display display, Surface surface,int x1, int y1, int x2, int y2)
354 /* if(x1>x2) { int tmp = x2; x2 = x1; x1 = tmp; }
356 if(x1<surface.box.left) x1=surface.box.left;
357 if(x2>surface.box.right) x2=surface.box.right;
358 if(y1<surface.box.top) y1=surface.box.top;
359 if(y2>surface.box.bottom) y2=surface.box.bottom;
361 x1 += surface.offset.x;
362 x2 += surface.offset.x;
363 y1 += surface.offset.y;
364 y2 += surface.offset.y;
367 //--//SDL_Rect rect = { (short)x1, (short)y1, (short)(x2-x1+1), (short)(y2-y1+1) };
368 //--//SDL_SetRenderDrawColor(surface.background.color.r, surface.background.color.g, surface.background.color.b, surface.background.a);
369 //--//SDL_RenderFill(&rect);
371 // ((subclass(DisplayDriver))class(LFBDisplayDriver)).Area(display, surface, x1,y1,x2,y2);
375 void ::Clear(Display display, Surface surface, ClearType type)
377 sflnprintf("class(SDL2DisplayDriver) ::Clear [WIP!]\n");
378 //--//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) };
379 //--//SDL_SetRenderDrawColor(surface.background.color.r, surface.background.color.g, surface.background.color.b, surface.background.a);
380 //--//SDL_RenderFill(&rect);
381 ((subclass(DisplayDriver))class(LFBDisplayDriver)).Clear(display, surface, type);
384 void ::Blit(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h)
386 ((subclass(DisplayDriver))class(LFBDisplayDriver)).Blit(display, surface, src, dx, dy, sx, sy, w, h);
389 void ::Stretch(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
391 ((subclass(DisplayDriver))class(LFBDisplayDriver)).Stretch(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
394 void ::Filter(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
396 ((subclass(DisplayDriver))class(LFBDisplayDriver)).Filter(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
399 void ::BlitDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h)
402 ((subclass(DisplayDriver))class(LFBDisplayDriver)).Blit(display, surface, src, dx, dy, sx, sy, w, h);
405 void ::StretchDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
408 ((subclass(DisplayDriver))class(LFBDisplayDriver)).Stretch(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
411 void ::FilterDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
414 //Filter(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
415 ((subclass(DisplayDriver))class(LFBDisplayDriver)).Filter(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
418 void ::TextFont(Display display, Surface surface, Font font)
420 ((subclass(DisplayDriver))class(LFBDisplayDriver)).TextFont(display, surface, font);
422 SetForeground(display, surface, surface.foreground);
425 void ::TextOpacity(Display display, Surface surface, bool opaque)
427 ((subclass(DisplayDriver))class(LFBDisplayDriver)).TextOpacity(display, surface, opaque);
430 void ::WriteText(Display display, Surface surface, int x, int y, const char * text, int len)
432 if(surface.textOpacity)
435 ((subclass(DisplayDriver))class(LFBDisplayDriver)).FontExtent(display.displaySystem, surface.font, text, len, &w, &h);
436 Area(display, surface, x, y, x+w-1, y+h-1);
438 ((subclass(DisplayDriver))class(LFBDisplayDriver)).WriteText(display, surface, x,y, text, len);
441 void ::TextExtent(Display display, Surface surface, const char * text, int len, int * width, int * height)
443 ((subclass(DisplayDriver))class(LFBDisplayDriver)).TextExtent(display, surface, text, len, width, height);
446 void ::FontExtent(DisplaySystem displaySystem, Font font, const char * text, int len, int * width, int * height)
448 ((subclass(DisplayDriver))class(LFBDisplayDriver)).FontExtent(displaySystem, font, text, len, width, height);
451 void ::DrawingChar(Display display, Surface surface, char character)
453 sflnprintf("class(SDLDisplayDriver) ::DrawingChar [STUB!]\n");
456 void ::NextPage(Display display)
458 sflnprintf("class(SDLDisplayDriver) ::NextPage [STUB!]\n");
463 #if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
464 void ::SetRenderState(Display display, RenderState state, uint value)
466 sflnprintf("class(SDLDisplayDriver) ::SetRenderState [STUB!]\n");
469 void ::SetLight(Display display, int id, Light light)
471 sflnprintf("class(SDLDisplayDriver) ::SetLight [STUB!]\n");
474 void ::SetCamera(Display display, Surface surface, Camera camera)
476 sflnprintf("class(SDLDisplayDriver) ::SetCamera [STUB!]\n");
479 bool ::AllocateMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags, int nVertices)
481 sflnprintf("class(SDLDisplayDriver) ::AllocateMesh [STUB!]\n");
485 void ::FreeMesh(DisplaySystem displaySystem, Mesh mesh)
487 sflnprintf("class(SDLDisplayDriver) ::FreeMesh [STUB!]\n");
490 bool ::LockMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags)
492 sflnprintf("class(SDLDisplayDriver) ::LockMesh [STUB!]\n");
496 void ::UnlockMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags)
498 sflnprintf("class(SDLDisplayDriver) ::UnlockMesh [STUB!]\n");
501 void * ::AllocateIndices(DisplaySystem displaySystem, int nIndices, bool indices32bit)
503 sflnprintf("class(SDLDisplayDriver) ::AllocateIndices [STUB!]\n");
507 void ::FreeIndices(DisplaySystem displaySystem, void * indices)
509 sflnprintf("class(SDLDisplayDriver) ::FreeIndices [STUB!]\n");
512 uint16 * ::LockIndices(DisplaySystem displaySystem, void * indices)
514 sflnprintf("class(SDLDisplayDriver) ::LockIndices [STUB!]\n");
518 void ::UnlockIndices(DisplaySystem displaySystem, void * indices, bool indices32bit, int nIndices)
520 sflnprintf("class(SDLDisplayDriver) ::UnlockIndices [STUB!]\n");
523 void ::SelectMesh(Display display, Mesh mesh)
525 sflnprintf("class(SDLDisplayDriver) ::SelectMesh [STUB!]\n");
528 void ::ApplyMaterial(Display display, Material material, Mesh mesh)
530 sflnprintf("class(SDLDisplayDriver) ::ApplyMaterial [STUB!]\n");
533 void ::DrawPrimitives(Display display, PrimitiveSingle * primitive, Mesh mesh)
535 sflnprintf("class(SDLDisplayDriver) ::DrawPrimitives [STUB!]\n");
538 void ::PushMatrix(Display display)
540 sflnprintf("class(SDLDisplayDriver) ::PushMatrix [STUB!]\n");
543 void ::PopMatrix(Display display, bool setMatrix)
545 sflnprintf("class(SDLDisplayDriver) ::PopMatrix [STUB!]\n");
548 void ::SetTransform(Display display, Matrix transMatrix, bool viewSpace, bool useCamera)
550 sflnprintf("class(SDLDisplayDriver) ::SetTransform [STUB!]\n");
556 #endif // !defined(NO_SDL_DRIVERS) && !defined(NO_SDL1_DRIVER)