3 namespace gfx::drivers;
9 import "CocoaInterface.ec"
10 #include "CocoaEcereBridge.h"
15 #define glLoadMatrix glLoadMatrixd
16 #define glMultMatrix glMultMatrixd
17 #define glGetMatrix glGetDoublev
18 #define glTranslate glTranslated
19 #define glScale glScaled
21 #define GL_ARRAY_BUFFER_ARB 0x8892
22 #define GL_ELEMENT_ARRAY_BUFFER_ARB 0x8893
23 #define GL_STATIC_DRAW_ARB 0x88E4
24 #define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8
25 #define GL_SEPARATE_SPECULAR_COLOR 0x81FA
27 #define GL_MULTISAMPLE_ARB 0x809D
29 //static int displayWidth, displayHeight;
31 #define GL_CLAMP_TO_EDGE 0x812F
33 class DisplayData : struct
35 ColorAlpha * flippingBuffer;
36 int flipBufH, flipBufW;
43 class SystemData : struct
48 class SurfaceData : struct
56 float foreground[4], background[4], bitmapMult[4];
59 class MeshData : struct
68 class IndexData : struct
75 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
76 static int primitiveTypes[RenderPrimitiveType] =
78 GL_POINTS, GL_LINES, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS, GL_QUAD_STRIP, GL_LINE_STRIP
87 GLenum error = glGetError();
90 printf("**** glGetError():%i ****\n", error);
95 class CocoaOpenGLDisplayDriver : DisplayDriver
97 class_property(name) = "CocoaOpenGL";
99 bool LockSystem(DisplaySystem displaySystem)
101 printf("CocoaOpenGLDisplayDriver:LockSystem STUB! %s:%i\n", __FILE__, __LINE__);
105 void UnlockSystem(DisplaySystem displaySystem)
107 printf("CocoaOpenGLDisplayDriver:UnlockSystem STUB! %s:%i\n", __FILE__, __LINE__);
110 bool Lock(Display display)
112 printf("CocoaOpenGLDisplayDriver:Lock %s:%i\n", __FILE__, __LINE__);
113 return CocoaLock(display.window);
116 void Unlock(Display display)
118 printf("CocoaOpenGLDisplayDriver:Unlock %s:%i\n", __FILE__, __LINE__);
119 CocoaUnlock(display.window);
122 void DestroyDisplay(Display display)
124 printf("CocoaOpenGLDisplayDriver:DestroyDisplay STUB! %s:%i\n", __FILE__, __LINE__);
127 bool CreateDisplaySystem(DisplaySystem displaySystem)
131 SystemData system = SystemData { };
132 displaySystem.driverData = system;
134 printf("CocoaOpenGLDisplayDriver:CreateDisplaySystem %s:%i\n", __FILE__, __LINE__);
138 void DestroyDisplaySystem(DisplaySystem displaySystem)
140 printf("CocoaOpenGLDisplayDriver:DestroyDisplaySystem STUB! %s:%i\n", __FILE__, __LINE__);
143 bool CreateDisplay(Display display)
147 DisplayData displayData = display.driverData;
148 //SystemData systemData = display.displaySystem.driverData;
150 displayData = display.driverData = DisplayData { };
152 CocoaOpenGLMakeCurrentContext(display.window);
155 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
160 glMatrixMode(GL_MODELVIEW);
162 glScalef(1.0f, 1.0f, -1.0f);
164 glMatrixMode(GL_PROJECTION);
166 glShadeModel(GL_FLAT);
169 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
171 glFogi(GL_FOG_MODE, GL_EXP);
173 glFogf(GL_FOG_DENSITY, 0);
175 glEnable(GL_NORMALIZE);
177 glDepthFunc(GL_LESS);
181 glDisable(GL_MULTISAMPLE_ARB);
184 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
185 display.ambient = Color { 50,50,50 };
188 printf("CocoaOpenGLDisplayDriver:CreateDisplay %p %s:%i\n", display.window, __FILE__, __LINE__);
192 bool DisplaySize(Display display, int width, int height)
196 DisplayData displayData = display.driverData;
197 //SystemData systemData = display.displaySystem.driverData;
199 printf("CocoaOpenGLDisplayDriver:DisplaySize(%i,%i) %s:%i\n", width, height, __FILE__, __LINE__);
201 CocoaOpenGLMakeCurrentContext(display.window);
203 glViewport(0,0,width,height);
207 glOrtho(0,width,height,0,0.0,1.0);
209 display.width = width;
210 display.height = height;
212 if(!displayData.flippingBuffer || displayData.flipBufW < width || displayData.flipBufH < height)
214 displayData.flipBufW = width;
215 displayData.flipBufH = height;
216 displayData.flippingBuffer = renew displayData.flippingBuffer ColorAlpha [width * height];
218 if(displayData.flippingBuffer)
224 void DisplayPosition(Display display, int x, int y)
226 DisplayData displayData = display.driverData;
228 printf("CocoaOpenGLDisplayDriver:DisplayPosition(%i,%i) %s:%i\n", x, y, __FILE__, __LINE__);
232 printf("glGetError():%i\n", glGetError());
235 void SetPalette(Display display, ColorAlpha * palette, bool colorMatch)
237 printf("CocoaOpenGLDisplayDriver:SetPalette STUB! %s:%i\n", __FILE__, __LINE__);
240 void RestorePalette(Display display)
242 printf("CocoaOpenGLDisplayDriver:RestorePalette STUB! %s:%i\n", __FILE__, __LINE__);
245 void StartUpdate(Display display)
247 printf("CocoaOpenGLDisplayDriver:StartUpdate STUB! %s:%i\n", __FILE__, __LINE__);
250 void EndUpdate(Display display)
252 printf("CocoaOpenGLDisplayDriver:EndUpdate STUB! %s:%i\n", __FILE__, __LINE__);
255 void Scroll(Display display, Box scroll, int x, int y, Extent dirty)
257 printf("CocoaOpenGLDisplayDriver:Scroll STUB! %s:%i\n", __FILE__, __LINE__);
260 void Update(Display display, Box updateBox)
262 //CocoaOpenGLUpdate(display.window);
263 printf("CocoaOpenGLDisplayDriver:Update %s:%i\n", __FILE__, __LINE__);
266 void FreeBitmap(DisplaySystem displaySystem, Bitmap bitmap)
268 uint glBitmap = (uint)(uintptr)bitmap.driverData;
269 glDeleteTextures(1, &glBitmap);
270 bitmap.driverData = 0;
272 bitmap.driver = class(LFBDisplayDriver);
274 printf("CocoaOpenGLDisplayDriver:FreeBitmap %s:%i\n", __FILE__, __LINE__);
277 bool AllocateBitmap(DisplaySystem displaySystem, Bitmap bitmap, int width, int height, int stride, PixelFormat format, bool allocatePalette)
283 uint w = pow2i(Min(width, 1024)), h = pow2i(Min(height, 1024));
285 printf("CocoaOpenGLDisplayDriver:AllocateBitmap %s:%i\n", __FILE__, __LINE__);
288 glGenTextures(1, &glBitmap);
290 glBindTexture(GL_TEXTURE_2D, glBitmap);
293 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
296 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
298 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
301 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
303 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
306 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
308 mipMap.Allocate(null, w, h, w, pixelFormatRGBA, false);
311 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipMap.picture);
314 bitmap.driverData = (void *)(uintptr)glBitmap;
315 bitmap.driver = displaySystem.driver;
324 bool MakeDDBitmap(DisplaySystem displaySystem, Bitmap bitmap, bool mipMaps)
327 SystemData systemData = displaySystem.driverData;
329 // Pre process the bitmap... First make it 32 bit
330 if(bitmap.Convert(null, pixelFormat888, null))
333 uint w = pow2i(Min(bitmap.width, 1024)), h = pow2i(Min(bitmap.height, 1024));
336 // Switch ARGB to RGBA
337 //if(bitmap.format != pixelFormatRGBA)
339 for(c=0; c<bitmap.size; c++)
342 ColorAlpha color = ((ColorAlpha *)bitmap.picture)[c];
343 ((ColorRGBA *)bitmap.picture)[c] = ColorRGBA { color.color.r, color.color.g, color.color.b, color.a };
346 bitmap.pixelFormat = pixelFormat888;
349 glGenTextures(1, &glBitmap);
353 //int error = glGetError();
359 glBindTexture(GL_TEXTURE_2D, glBitmap);
361 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
364 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
366 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mipMaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
369 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
371 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
374 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
379 for(level = 0; result && (w > 1 || h > 1); level++, w >>= 1, h >>= 1)
382 if(bitmap.width != w || bitmap.height != h)
385 if(mipMap.Allocate(null, w, h, w, bitmap.pixelFormat, false))
387 Surface mipSurface = mipMap.GetSurface(0,0,null);
388 mipSurface.Filter(bitmap, 0,0,0,0, w, h, bitmap.width, bitmap.height);
403 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipMap.picture);
405 if((error = glGetError()))
416 bitmap.driver.FreeBitmap(bitmap.displaySystem, bitmap);
417 bitmap.driverData = (void *)(uintptr)glBitmap;
418 bitmap.driver = displaySystem.driver;
421 FreeBitmap(displaySystem, bitmap);
422 else if(systemData.loadingFont)
424 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
426 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
428 systemData.loadingFont = false;
432 printf("CocoaOpenGLDisplayDriver:MakeDDBitmap %i %s:%i\n", result, __FILE__, __LINE__);
436 void ReleaseSurface(Display display, Surface surface)
438 printf("CocoaOpenGLDisplayDriver:ReleaseSurface %s:%i\n", __FILE__, __LINE__);
440 glDisable(GL_SCISSOR_TEST);
442 delete surface.driverData;
443 surface.driverData = null;
446 bool GetBitmapSurface(DisplaySystem displaySystem, Surface surface, Bitmap bitmap, int x, int y, Box clip)
448 printf("CocoaOpenGLDisplayDriver:GetBitmapSurface STUB! %s:%i\n", __FILE__, __LINE__);
452 bool GetSurface(Display display, Surface surface, int x,int y, Box clip)
456 SurfaceData surfaceData = SurfaceData { };
457 surface.driverData = surfaceData;
459 printf("CocoaOpenGLDisplayDriver:GetSurface %p %s:%i\n", surfaceData, __FILE__, __LINE__);
464 glViewport(0,0,display.width,display.height);
468 printf("display:%i, %i\n", display.width, display.height);
469 glOrtho(0, display.width, display.height, 0, 0.0f, 1.0f);
472 surface.offset.x = x;
473 surface.offset.y = y;
474 surface.unclippedBox = surface.box = clip;
475 surfaceData.bitmapMult[0] = 1;
476 surfaceData.bitmapMult[1] = 1;
477 surfaceData.bitmapMult[2] = 1;
478 surfaceData.bitmapMult[3] = 1;
480 glEnable(GL_SCISSOR_TEST);
484 (display.height) -(y+clip.bottom)-1,
485 clip.right-clip.left+1,
486 clip.bottom-clip.top+1);
494 void Clip(Display display, Surface surface, Box clip)
498 printf("CocoaOpenGLDisplayDriver:Clip STUB! %s:%i\n", __FILE__, __LINE__);
503 box.Clip(surface.unclippedBox);
508 box = surface.box = surface.unclippedBox;
511 box.left += surface.offset.x;
512 box.top += surface.offset.y;
513 box.right+= surface.offset.x;
514 box.bottom += surface.offset.y;
517 box.left,display.height - box.bottom - 1,
518 box.right-box.left+1, box.bottom-box.top+1);
521 bool GrabScreen(Display display, Bitmap bitmap, int x, int y, unsigned int w, unsigned int h)
524 printf("CocoaOpenGLDisplayDriver:GrabScreen STUB! %s:%i\n", __FILE__, __LINE__);
528 void SetForeground(Display display, Surface surface, ColorAlpha color)
530 SurfaceData surfaceData = surface.driverData;
532 printf("CocoaOpenGLDisplayDriver:SetForeground(%i,%i,%i,%i) %s:%i\n", color.color.r, color.color.g, color.color.b, color.a, __FILE__, __LINE__);
534 surfaceData.foreground[0] = color.color.r/255.0f;
535 surfaceData.foreground[1] = color.color.g/255.0f;
536 surfaceData.foreground[2] = color.color.b/255.0f;
537 surfaceData.foreground[3] = color.a/255.0f;
540 void SetBackground(Display display, Surface surface, ColorAlpha color)
542 SurfaceData surfaceData = surface.driverData;
544 printf("CocoaOpenGLDisplayDriver:SetBackground(%i,%i,%i,%i) %s:%i\n", color.color.r, color.color.g, color.color.b, color.a, __FILE__, __LINE__);
546 surfaceData.background[0] = color.color.r/255.0f;
547 surfaceData.background[1] = color.color.g/255.0f;
548 surfaceData.background[2] = color.color.b/255.0f;
549 surfaceData.background[3] = color.a/255.0f;
552 void SetBlitTint(Display display, Surface surface, ColorAlpha color)
554 SurfaceData surfaceData = surface.driverData;
556 printf("CocoaOpenGLDisplayDriver:SetBlitTint(%i,%i,%i,%i) %s:%i\n", color.color.r, color.color.g, color.color.b, color.a, __FILE__, __LINE__);
558 surfaceData.bitmapMult[0] = color.color.r/255.0f;
559 surfaceData.bitmapMult[1] = color.color.g/255.0f;
560 surfaceData.bitmapMult[2] = color.color.b/255.0f;
561 surfaceData.bitmapMult[3] = color.a/255.0f;
565 ColorAlpha GetPixel(Display display, Surface surface,int x,int y)
567 printf("CocoaOpenGLDisplayDriver:GetPixel STUB! %s:%i\n", __FILE__, __LINE__);
571 void PutPixel(Display display, Surface surface,int x,int y)
573 printf("CocoaOpenGLDisplayDriver:PutPixel %s:%i\n", __FILE__, __LINE__);
577 glVertex2f(x+surface.offset.x + 0.5f, y+surface.offset.y + 0.5f);
582 void DrawLine(Display display, Surface surface, int x1, int y1, int x2, int y2)
584 SurfaceData surfaceData = surface.driverData;
586 printf("CocoaOpenGLDisplayDriver:DrawLine %s:%i\n", __FILE__, __LINE__);
587 printf("--DrawLine(x1:%i, y1:%i, x2:%i, y2:%i)\n", x1, y1, x2, y2);
589 glColor4fv(surfaceData.foreground);
592 glVertex2f(x1+surface.offset.x + 0.5f, y1+surface.offset.y + 0.5f);
593 glVertex2f(x2+surface.offset.x + 0.5f, y2+surface.offset.y + 0.5f);
599 void Rectangle(Display display, Surface surface,int x1,int y1,int x2,int y2)
601 printf("CocoaOpenGLDisplayDriver:Rectangle %s:%i\n", __FILE__, __LINE__);
602 printf("--Rectangle(x1:%i, y1:%i, x2:%i, y2:%i)\n", x1, y1, x2, y2);
603 glBegin(GL_LINE_LOOP);
605 glVertex2f(x1+surface.offset.x + 0.5f, y1+surface.offset.y + 0.5f);
606 glVertex2f(x1+surface.offset.x + 0.5f, y2+surface.offset.y + 0.5f);
607 glVertex2f(x2+surface.offset.x + 0.5f, y2+surface.offset.y + 0.5f);
608 glVertex2f(x2+surface.offset.x + 0.5f, y1+surface.offset.y + 0.5f);
614 void Area(Display display, Surface surface,int x1,int y1,int x2,int y2)
616 SurfaceData surfaceData = surface.driverData;
618 printf("CocoaOpenGLDisplayDriver:Area %s:%i\n", __FILE__, __LINE__);
621 glColor4fv(surfaceData.background);
623 glRecti(x1+surface.offset.x, y1+surface.offset.y,
624 x2+surface.offset.x + 1, y2+surface.offset.y + 1);
628 void Clear(Display display, Surface surface, ClearType type)
630 DisplayData displayData = display.driverData;
631 SurfaceData surfaceData = surface.driverData;
633 if(type != depthBuffer)
635 glClearColor(surfaceData.background[0], surfaceData.background[1], surfaceData.background[2], surfaceData.background[3]);
638 if(type != colorBuffer && !displayData.depthWrite)
640 glDepthMask((byte)bool::true);
643 glClear(((type != depthBuffer) ? GL_COLOR_BUFFER_BIT : 0) |
644 ((type != colorBuffer) ? GL_DEPTH_BUFFER_BIT : 0));
647 if(type != colorBuffer && !displayData.depthWrite)
649 glDepthMask((byte)bool::false);
652 if(type != depthBuffer)
654 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
657 if(type != colorBuffer)
659 glDepthMask((byte)bool::true);
663 glClear(((type != depthBuffer) ? GL_COLOR_BUFFER_BIT : 0) |
664 ((type != colorBuffer) ? GL_DEPTH_BUFFER_BIT : 0));
667 if(type != colorBuffer)
669 glDepthMask((byte)bool::false);
672 printf("CocoaOpenGLDisplayDriver:Clear %s:%i\n", __FILE__, __LINE__);
675 bool ConvertBitmap(DisplaySystem displaySystem, Bitmap bitmap, PixelFormat format, ColorAlpha * palette)
679 printf("CocoaOpenGLDisplayDriver:ConvertBitmap %s:%i\n", __FILE__, __LINE__);
684 void Blit(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h)
686 printf("CocoaOpenGLDisplayDriver:Blit %s:%i\n", __FILE__, __LINE__);
687 printf("--BLIT(dx:%i, dy:%i, sx:%i, sy:%i, w:%i, h:%i)\n", dx, dy, sx, sy, w, h);
689 glEnable(GL_TEXTURE_2D);
690 glBindTexture(GL_TEXTURE_2D, (uint)bitmap.driverData);
695 glTexCoord2f((float)sx/ bitmap.width, (float)(sy-h)/ bitmap.height);
696 glVertex2i(dx+surface.offset.x, dy+surface.offset.y);
697 glTexCoord2f((float)(sx+w) / bitmap.width, (float)(sy-h)/ bitmap.height);
698 glVertex2i(dx+w+surface.offset.x, dy+surface.offset.y);
699 glTexCoord2f((float)(sx+w)/ bitmap.width, (float)sy/ bitmap.height);
700 glVertex2i(dx+w+surface.offset.x, dy-h+surface.offset.y);
701 glTexCoord2f((float)sx / bitmap.width, (float)sy/ bitmap.height);
702 glVertex2i(dx+surface.offset.x, dy-h+surface.offset.y);
706 glTexCoord2f((float)sx / bitmap.width, (float)sy/ bitmap.height);
707 glVertex2f((float)dx+surface.offset.x, (float)dy+surface.offset.y);
708 glTexCoord2f((float)(sx+w)/ bitmap.width, (float)sy/ bitmap.height);
709 glVertex2f((float)dx+w+surface.offset.x, (float)dy+surface.offset.y);
710 glTexCoord2f((float)(sx+w) / bitmap.width, (float)(sy+h)/ bitmap.height);
711 glVertex2f((float)dx+w+surface.offset.x, (float)dy+h+surface.offset.y);
712 glTexCoord2f((float)sx/ bitmap.width, (float)(sy+h)/ bitmap.height);
713 glVertex2f((float)dx+surface.offset.x, (float)dy+h+surface.offset.y);
719 void Stretch(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
721 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
722 glEnable(GL_TEXTURE_2D);
724 glBindTexture(GL_TEXTURE_2D, (uint)bitmap.driverData);
732 glTexCoord2f((float)(sx)/ bitmap.width, (float)(sy+sh)/ bitmap.height);
734 glVertex2i(dx+surface.offset.x, dy+surface.offset.y);
737 glTexCoord2f((float)(sx+sw) / bitmap.width, (float)(sy+sh)/ bitmap.height);
739 glVertex2i(dx+w+surface.offset.x, dy+surface.offset.y);
742 glTexCoord2f((float)(sx+sw)/ bitmap.width, (float)(sy)/ bitmap.height);
744 glVertex2i(dx+w+surface.offset.x, dy-h+surface.offset.y);
747 glTexCoord2f((float)(sx) / bitmap.width, (float)(sy)/ bitmap.height);
749 glVertex2i(dx+surface.offset.x, dy-h+surface.offset.y);
754 glTexCoord2f((float)(sx) / bitmap.width, (float)(sy)/ bitmap.height);
756 glVertex2i(dx+surface.offset.x, dy+surface.offset.y);
759 glTexCoord2f((float)(sx+sw)/ bitmap.width, (float)(sy)/ bitmap.height);
761 glVertex2i(dx+w+surface.offset.x, dy+surface.offset.y);
764 glTexCoord2f((float)(sx+sw) / bitmap.width, (float)(sy+sh)/ bitmap.height);
766 glVertex2i(dx+w+surface.offset.x, dy+h+surface.offset.y);
769 glTexCoord2f((float)(sx)/ bitmap.width, (float)(sy+sh)/ bitmap.height);
771 glVertex2i(dx+surface.offset.x, dy+h+surface.offset.y);
778 glDisable(GL_TEXTURE_2D);
782 void Filter(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
784 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
785 Stretch(display, surface, bitmap, dx, dy, sx, sy, w, h, sw, sh);
788 void StretchDI(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
790 float s2dw,s2dh,d2sw,d2sh;
791 bool flipX = false, flipY = false;
793 printf("CocoaOpenGLDisplayDriver: %s:%i\n", __FILE__, __LINE__);
794 if(Sgn(w) != Sgn(sw))
800 if(Sgn(h) != Sgn(sh))
812 //Clip against the edges of the source
815 dx+=(int)((0-sx) * s2dw);
816 w-=(int)((0-sx) * s2dw);
822 dy+=(int)((0-sy) * s2dh);
823 h-=(int)((0-sy) * s2dh);
828 if(sx+sw>bitmap.width-1)
830 w-=(int)((sx+sw-(bitmap.width-1)-1)*s2dw);
831 sw-=sx+sw-(bitmap.width-1)-1;
833 if(sy+sh>(bitmap.height-1))
835 h-=(int)((sy+sh-(bitmap.height-1)-1)*s2dh);
836 sh-=sy+sh-(bitmap.height-1)-1;
838 //Clip against the edges of the surfaceination
839 if(dx<surface.box.left)
842 sx+=(int)((surface.box.left-dx)*d2sw);
843 sw-=(int)((surface.box.left-dx)*d2sw);
844 w-=surface.box.left-dx;
847 if(dy<surface.box.top)
849 sy+=(int)((surface.box.top-dy)*d2sh);
850 sh-=(int)((surface.box.top-dy)*d2sh);
851 h-=surface.box.top-dy;
854 if(dx+w>surface.box.right)
856 //if(flip) sx+=(int)((dx+w-surface.box.right-1)*d2sw);
857 sw-=(int)((dx+w-surface.box.right-1)*d2sw);
858 w-=dx+w-surface.box.right-1;
860 if(dy+h>surface.box.bottom)
862 sh-=(int)((dy+h-surface.box.bottom-1)*d2sh);
863 h-=dy+h-surface.box.bottom-1;
865 if((w<=0)||(h<=0)||(sw<=0)||(sh<=0)) return;
867 dx += surface.offset.x;
868 dy += surface.offset.y;
870 if(bitmap.pixelFormat == pixelFormat888 && !bitmap.paletteShades)
872 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
874 glPixelStorei(GL_UNPACK_ROW_LENGTH, bitmap.stride);
876 glPixelStorei(GL_UNPACK_SKIP_PIXELS, sx);
878 glPixelStorei(GL_UNPACK_SKIP_ROWS, sy);
880 glRasterPos2d(dx,dy);
882 //glPixelZoom(flipX ? -s2dw : s2dw, flipY ? s2dh : -s2dh);
884 glPixelZoom(s2dw, -s2dh);
886 glDrawPixels(sw,sh,GL_BGRA_EXT,GL_UNSIGNED_BYTE, bitmap.picture);
888 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
890 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
895 void BlitDI(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h)
897 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
898 //Clip against the edges of the source
911 if(sx+w>bitmap.width-1)
912 w-=sx+w-(bitmap.width-1)-1;
913 if(sy+h>bitmap.height-1)
914 h-=sy+h-(bitmap.height-1)-1;
915 //Clip against the edges of the surfaceination
916 if(dx<surface.box.left)
919 sx+=surface.box.left-dx;
920 w-=surface.box.left-dx;
923 if(dy<surface.box.top)
925 sy+=surface.box.top-dy;
926 h-=surface.box.top-dy;
929 if(dx+w>surface.box.right)
931 //if(flip) sx+=dx+w-surface.box.right-1;
932 w-=dx+w-surface.box.right-1;
934 if(dy+h>surface.box.bottom)
935 h-=dy+h-surface.box.bottom-1;
939 dx += surface.offset.x;
940 dy += surface.offset.y;
942 if(bitmap.pixelFormat == pixelFormat888 && !bitmap.paletteShades)
944 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
946 glPixelStorei(GL_UNPACK_ROW_LENGTH, bitmap.stride);
948 glPixelStorei(GL_UNPACK_SKIP_PIXELS, sx);
950 glPixelStorei(GL_UNPACK_SKIP_ROWS, sy);
952 glRasterPos2d(dx,dy);
956 glDrawPixels(w,h,GL_BGRA_EXT,GL_UNSIGNED_BYTE, bitmap.picture);
958 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
960 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
965 void FilterDI(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
967 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
968 StretchDI(display, surface, bitmap, dx, dy, sx, sy, w, h, sw, sh);
971 void UnloadFont(DisplaySystem displaySystem, Font font)
973 printf("CocoaOpenGLDisplayDriver:UnloadFont %s:%i\n", __FILE__, __LINE__);
974 LFBDisplayDriver::UnloadFont(displaySystem, font);
977 Font LoadFont(DisplaySystem displaySystem, const char * faceName, float size, FontFlags flags)
979 Font font = LFBDisplayDriver::LoadFont(displaySystem, faceName, size, flags);
981 printf("CocoaOpenGLDisplayDriver:LoadFont(%s):%p %s:%i\n", faceName, font, __FILE__, __LINE__);
986 void FontExtent(DisplaySystem displaySystem, Font font, const char * text, int len, int * width, int * height)
988 printf("CocoaOpenGLDisplayDriver:FontExtent() %s:%i\n", __FILE__, __LINE__);
989 LFBDisplayDriver::FontExtent(displaySystem, font, text, len, width, height);
992 void WriteText(Display display, Surface surface, int x, int y, const char * text, int len)
994 SurfaceData surfaceData = surface.driverData;
995 SystemData systemData = display.displaySystem.driverData;
997 printf("CocoaOpenGLDisplayDriver:WriteText %s:%i\n", __FILE__, __LINE__);
999 systemData.loadingFont = true;
1001 if(surface.textOpacity)
1004 FontExtent(display.displaySystem, surface.font, text, len, &w, &h);
1005 Area(display, surface,x,y,x+w-1,y+h-1);
1008 surfaceData.writingText = true;
1010 glEnable(GL_TEXTURE_2D);
1012 glColor4fv(surfaceData.foreground);
1015 LFBDisplayDriver::WriteText(display, surface, x, y, text, len);
1016 surfaceData.writingText = false;
1017 systemData.loadingFont = false;
1019 glDisable(GL_TEXTURE_2D);
1023 void TextFont(Display display, Surface surface, Font font)
1025 LFBDisplayDriver::TextFont(display, surface, font);
1026 printf("CocoaOpenGLDisplayDriver:TextFont %s:%i\n", __FILE__, __LINE__);
1029 void TextOpacity(Display display, Surface surface, bool opaque)
1031 SurfaceData surfaceData = surface.driverData;
1032 surfaceData.opaqueText = opaque;
1033 printf("CocoaOpenGLDisplayDriver:TextOpacity(%i) %s:%i\n", opaque, __FILE__, __LINE__);
1036 void TextExtent(Display display, Surface surface, const char * text, int len, int * width, int * height)
1038 SurfaceData surfaceData = surface.driverData;
1039 SystemData systemData = display.displaySystem.driverData;
1040 systemData.loadingFont = true;
1041 FontExtent(display.displaySystem, surfaceData.font, text, len, width, height);
1042 systemData.loadingFont = false;
1044 printf("CocoaOpenGLDisplayDriver:TextExtent STUB! %s:%i\n", __FILE__, __LINE__);
1047 void DrawingChar(Display display, Surface surface, char character)
1049 printf("CocoaOpenGLDisplayDriver:DrawingChar STUB! %s:%i\n", __FILE__, __LINE__);
1053 void LineStipple(Display display, Surface surface, uint32 stipple)
1055 printf("CocoaOpenGLDisplayDriver:LineStipple %s:%i\n", __FILE__, __LINE__);
1058 glLineStipple(1, (uint16)stipple);
1060 glEnable(GL_LINE_STIPPLE);
1065 glDisable(GL_LINE_STIPPLE);
1068 printf("glGetError():%i\n", glGetError());
1071 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
1072 void SetRenderState(Display display, RenderState state, uint value)
1074 printf("CocoaOpenGLDisplayDriver:SetRenderState STUB! %s:%i\n", __FILE__, __LINE__);
1079 glEnable(GL_MULTISAMPLE_ARB);
1081 glDisable(GL_MULTISAMPLE_ARB);
1085 glPolygonMode(GL_FRONT_AND_BACK, ((FillModeValue)value == solid) ? GL_FILL : GL_LINE);
1089 if(value) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
1093 if(value) glDepthMask((byte)bool::true); else glDepthMask((byte)bool::false);
1098 float color[4] = { ((Color)value).r/255.0f, ((Color)value).g/255.0f, ((Color)value).b/255.0f, 1.0f };
1099 glFogfv(GL_FOG_COLOR, (float *)&color);
1104 glFogf(GL_FOG_DENSITY, *(float *)(void *)&value);
1108 if(value) glEnable(GL_BLEND); else glDisable(GL_BLEND);
1113 float ambient[4] = { ((Color)value).r/255.0f, ((Color)value).g/255.0f, ((Color)value).b/255.0f, 1.0f };
1114 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
1120 if(value) glColorMask(1,1,1,1); else glColorMask(1,1,1,0);
1131 void SetLight(Display display, int id, Light light)
1133 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1136 Object lightObject = light.lightObject;
1137 float position[4] = { 0, 0, 0, 0 };
1138 float color[4] = { 0, 0, 0, 1 };
1140 glEnable(GL_LIGHT0 + id);
1143 if(!light.multiplier) light.multiplier = 1.0f;
1145 color[0] = light.diffuse.r * light.multiplier;
1146 color[1] = light.diffuse.g * light.multiplier;
1147 color[2] = light.diffuse.b * light.multiplier;
1148 glLightfv(GL_LIGHT0 + id, GL_DIFFUSE, color);
1150 color[0] = light.ambient.r * light.multiplier;
1151 color[1] = light.ambient.g * light.multiplier;
1152 color[2] = light.ambient.b * light.multiplier;
1153 glLightfv(GL_LIGHT0 + id, GL_AMBIENT, color);
1154 color[0] = light.specular.r * light.multiplier;
1155 color[1] = light.specular.g * light.multiplier;
1156 color[2] = light.specular.b * light.multiplier;
1157 glLightfv(GL_LIGHT0 + id, GL_SPECULAR,color);
1161 Vector3D positionVector;
1162 if(light.flags.spot)
1164 if(lightObject.flags.root || !lightObject.parent)
1166 positionVector = lightObject.transform.position;
1167 positionVector.Subtract(positionVector, display.display3D.camera.cPosition);
1171 positionVector.MultMatrix(lightObject.transform.position, lightObject.parent.matrix);
1172 if(display.display3D.camera)
1173 positionVector.Subtract(positionVector, display.display3D.camera.cPosition);
1179 if(!light.direction.x && !light.direction.y && !light.direction.z)
1181 Vector3Df vector { 0,0,-1 };
1183 mat.RotationQuaternion(light.orientation);
1184 positionVector.MultMatrixf(vector, mat);
1188 positionVector = light.direction;
1193 position[0] = (float)positionVector.x;
1194 position[1] = (float)positionVector.y;
1195 position[2] = (float)positionVector.z;
1197 glLightfv(GL_LIGHT0 + id, GL_POSITION, position);
1200 if(light.flags.attenuation)
1202 glLightf(GL_LIGHT0 + id, GL_CONSTANT_ATTENUATION, light.Kc);
1204 glLightf(GL_LIGHT0 + id, GL_LINEAR_ATTENUATION, light.Kl);
1206 glLightf(GL_LIGHT0 + id, GL_QUADRATIC_ATTENUATION, light.Kq);
1210 if(light.flags.spot)
1213 #define MAXLIGHT 0.9
1214 float direction[4] = { (float)light.direction.x, (float)light.direction.y, (float)light.direction.z, 1 };
1215 // Figure out exponent out of the hot spot
1216 exponent = (float)(log(MAXLIGHT) / log(cos((light.hotSpot / 2))));
1218 glLightfv(GL_LIGHT0 + id, GL_SPOT_DIRECTION, direction);
1220 glLightf(GL_LIGHT0 + id, GL_SPOT_CUTOFF, (float)(light.fallOff / 2));
1222 glLightf(GL_LIGHT0 + id, GL_SPOT_EXPONENT, exponent);
1228 Vector3Df vector { 0,0,-1 };
1229 Vector3Df direction;
1232 mat.RotationQuaternion(light.orientation);
1233 direction.MultMatrix(vector, mat);
1235 position[0] = direction.x;
1236 position[1] = direction.y;
1237 position[2] = direction.z;
1239 glLightfv(GL_LIGHT0 + id, GL_POSITION, position);
1244 glDisable(GL_LIGHT0 + id);
1248 void SetCamera(Display display, Surface surface, Camera camera)
1250 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1253 int left = surface.box.left + surface.offset.x;
1254 int top = surface.box.top + surface.offset.y;
1255 int right = surface.box.right + surface.offset.x;
1256 int bottom = surface.box.bottom + surface.offset.y;
1257 float origX = surface.offset.x + camera.origin.x;
1258 float origY = surface.offset.y + camera.origin.y;
1260 int y = display.height - bottom - 1;
1261 int w = right - left + 1;
1262 int h = bottom - top + 1;
1265 glViewport(x, y, w, h);
1267 // *** Projection Matrix ***
1268 if(!display.display3D.camera)
1271 glMatrixMode(GL_PROJECTION);
1272 if(display.display3D.collectingHits)
1274 float pickX = display.display3D.pickX + surface.offset.x;
1275 float pickY = display.height - (display.display3D.pickY + surface.offset.y) - 1;
1279 w / display.display3D.pickWidth, 0, 0, 0,
1280 0, h / display.display3D.pickHeight, 0, 0,
1282 (w + 2.0f * (x - pickX)) / display.display3D.pickWidth,
1283 (h + 2.0f * (y - pickY)) / display.display3D.pickHeight, 0, 1
1286 glLoadMatrixd(pickMatrix.array);
1291 (left - origX) * camera.zMin / camera.focalX,
1292 (right - origX) * camera.zMin / camera.focalX,
1293 (bottom - origY) * camera.zMin / camera.focalY,
1294 (top - origY) * camera.zMin / camera.focalY,
1295 camera.zMin, camera.zMax);
1297 glDisable(GL_BLEND);
1299 // *** Z Inverted Identity Matrix ***
1300 glMatrixMode(GL_MODELVIEW);
1301 if(!display.display3D.camera)
1305 glScalef(1.0f, 1.0f, -1.0f);
1307 // *** View Matrix ***
1308 glMultMatrixd(camera.viewMatrix.array);
1313 glEnable(GL_DEPTH_TEST);
1314 glEnable(GL_LIGHTING);
1315 glShadeModel(GL_SMOOTH);
1316 glDepthMask((byte)bool::true);
1318 glEnable(GL_MULTISAMPLE_ARB);
1320 else if(display.display3D.camera)
1322 glViewport(0,0,display.width,display.height);
1324 glDisable(GL_CULL_FACE);
1325 glDisable(GL_DEPTH_TEST);
1326 glDisable(GL_LIGHTING);
1328 glDisable(GL_TEXTURE_2D);
1329 glShadeModel(GL_FLAT);
1331 glDisable(GL_MULTISAMPLE_ARB);
1333 // *** Restore 2D MODELVIEW Matrix ***
1336 // *** Restore 2D PROJECTION Matrix ***
1337 glMatrixMode(GL_PROJECTION);
1342 glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
1343 printf("glGetError():%i\n", glGetError());
1346 void ApplyMaterial(Display display, Material material, Mesh mesh)
1348 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1350 if(material.flags.doubleSided)
1352 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, !material.flags.singleSideLight);
1353 glDisable(GL_CULL_FACE);
1357 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, bool::false);
1358 glEnable(GL_CULL_FACE);
1362 if(material.flags.noFog)
1368 if(material.baseMap && mesh.texCoords)
1370 Bitmap map = material.baseMap;
1371 glEnable(GL_TEXTURE_2D);
1372 glBindTexture(GL_TEXTURE_2D, (uint)map.driverData);
1374 if(material.flags.tile)
1376 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1377 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1381 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1382 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1386 glDisable(GL_TEXTURE_2D);
1388 if(mesh.flags.colors)
1390 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
1391 glEnable(GL_COLOR_MATERIAL);
1395 glDisable(GL_COLOR_MATERIAL);
1397 float color[4] = { material.diffuse.r, material.diffuse.g, material.diffuse.b, material.opacity };
1398 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
1401 float color[4] = { material.ambient.r, material.ambient.g, material.ambient.b, 0 };
1402 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color);
1406 float color[4] = { material.specular.r, material.specular.g, material.specular.b, 0 };
1407 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color);
1410 float color[4] = { material.emissive.r, material.emissive.g, material.emissive.b, 0 };
1411 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color);
1414 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &material.power);
1417 void FreeMesh(DisplaySystem displaySystem, Mesh mesh)
1419 MeshData meshData = mesh.data;
1420 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1423 if(!mesh.flags.vertices)
1425 if(meshData.vertices)
1427 glDeleteBuffersARB(1, &meshData.vertices);
1428 meshData.vertices = 0;
1430 delete mesh.vertices;
1432 if(!mesh.flags.normals)
1434 if(meshData.normals)
1436 glDeleteBuffersARB(1, &meshData.normals);
1437 meshData.normals = 0;
1439 delete mesh.normals;
1441 if(!mesh.flags.texCoords1)
1443 if(meshData.texCoords)
1445 glDeleteBuffersARB(1, &meshData.texCoords);
1446 meshData.texCoords = 0;
1448 delete mesh.texCoords;
1450 if(!mesh.flags.texCoords2)
1452 if(meshData.texCoords2)
1454 glDeleteBuffersARB(1, &meshData.texCoords2);
1455 meshData.texCoords2 = 0;
1458 if(!mesh.flags.colors)
1462 glDeleteBuffersARB(1, &meshData.colors);
1463 meshData.colors = 0;
1474 bool AllocateMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags, int nVertices)
1476 bool result = false;
1477 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1480 OGLMesh oglMesh = mesh.data;
1481 if(mesh.nVertices == nVertices)
1483 // Same number of vertices, adding features (Leaves the other features pointers alone)
1484 if(mesh.flags != flags)
1486 if(!mesh.flags.vertices && flags.vertices)
1488 if(flags.doubleVertices)
1490 mesh.vertices = (Vector3Df *)new Vector3D[nVertices];
1493 mesh.vertices = new Vector3Df[nVertices];
1494 if(!oglMesh.vertices)
1495 GLGenBuffers(1, &oglMesh.vertices);
1497 if(!mesh.flags.normals && flags.normals)
1499 if(flags.doubleNormals)
1501 mesh.normals = (Vector3Df *)new Vector3D[nVertices];
1504 mesh.normals = new Vector3Df[nVertices];
1505 if(!oglMesh.normals)
1506 GLGenBuffers( 1, &oglMesh.normals);
1508 if(!mesh.flags.texCoords1 && flags.texCoords1)
1510 mesh.texCoords = new Pointf[nVertices];
1511 if(!oglMesh.texCoords)
1512 GLGenBuffers( 1, &oglMesh.texCoords);
1514 if(!mesh.flags.colors && flags.colors)
1516 mesh.colors = new ColorRGBAf[nVertices];
1518 GLGenBuffers( 1, &oglMesh.colors);
1524 // New number of vertices, reallocate all current and new features
1525 flags |= mesh.flags;
1528 if(flags.doubleVertices)
1530 mesh.vertices = (Vector3Df *)renew mesh.vertices Vector3D[nVertices];
1533 mesh.vertices = renew mesh.vertices Vector3Df[nVertices];
1534 if(!oglMesh.vertices)
1535 GLGenBuffers(1, &oglMesh.vertices);
1539 if(flags.doubleNormals)
1541 mesh.normals = (Vector3Df *)renew mesh.normals Vector3D[nVertices];
1544 mesh.normals = renew mesh.normals Vector3Df[nVertices];
1545 if(!oglMesh.normals)
1546 GLGenBuffers( 1, &oglMesh.normals);
1548 if(flags.texCoords1)
1550 mesh.texCoords = renew mesh.texCoords Pointf[nVertices];
1551 if(!oglMesh.texCoords)
1552 GLGenBuffers( 1, &oglMesh.texCoords);
1556 mesh.colors = renew mesh.colors ColorRGBAf[nVertices];
1558 GLGenBuffers( 1, &oglMesh.colors);
1566 void UnlockMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags)
1568 MeshData meshData = mesh.data;
1569 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1571 if(!flags) flags = mesh.flags;
1575 if(!(flags.vertices) || meshData.vertices)
1577 glBindBufferARB( GL_ARRAY_BUFFER_ARB, meshData.vertices);
1578 glBufferDataARB( GL_ARRAY_BUFFER_ARB, mesh.nVertices * (mesh.flags.doubleVertices ? sizeof(Vector3D) : sizeof(Vector3Df)), mesh.vertices, GL_STATIC_DRAW_ARB );
1581 if(!(flags.normals) || meshData.normals)
1583 glBindBufferARB( GL_ARRAY_BUFFER_ARB, meshData.normals);
1584 glBufferDataARB( GL_ARRAY_BUFFER_ARB, mesh.nVertices * (mesh.flags.doubleNormals ? sizeof(Vector3D) : sizeof(Vector3Df)), mesh.normals, GL_STATIC_DRAW_ARB );
1587 if(!(flags.texCoords1) || meshData.texCoords)
1589 glBindBufferARB( GL_ARRAY_BUFFER_ARB, meshData.texCoords);
1590 glBufferDataARB( GL_ARRAY_BUFFER_ARB, mesh.nVertices * sizeof(Pointf), mesh.texCoords, GL_STATIC_DRAW_ARB );
1593 if(!(flags.colors) || meshData.colors)
1595 glBindBufferARB( GL_ARRAY_BUFFER_ARB, meshData.colors);
1596 glBufferDataARB( GL_ARRAY_BUFFER_ARB, mesh.nVertices * sizeof(ColorRGBAf), mesh.colors, GL_STATIC_DRAW_ARB );
1599 glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0);
1603 bool LockMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags)
1606 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1610 void FreeIndices(DisplaySystem displaySystem, IndexData indexData)
1612 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1616 if(indexData.buffer)
1617 glDeleteBuffersARB(1, &indexData.buffer);
1618 delete indexData.indices;
1623 void * AllocateIndices(DisplaySystem displaySystem, int nIndices, bool indices32bit)
1625 IndexData indexData = IndexData { };
1626 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1629 indexData.indices = (void *)(indices32bit ? new uint32[nIndices] : new uint16[nIndices]);
1631 glGenBuffersARB( 1, &indexData.buffer);
1632 indexData.nIndices = nIndices;
1637 void UnlockIndices(DisplaySystem displaySystem, IndexData indexData, bool indices32bit, int nIndices)
1639 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1642 glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, indexData.buffer);
1643 glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, nIndices * (indices32bit ? sizeof(uint32) : sizeof(uint16)),
1644 indexData.indices, GL_STATIC_DRAW_ARB);
1645 glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
1649 uint16 * LockIndices(DisplaySystem displaySystem, IndexData indexData)
1651 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1653 return indexData.indices;
1656 void SelectMesh(Display display, Mesh mesh)
1658 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1660 /*if(display.display3D.mesh && glUnlockArraysEXT)
1661 glUnlockArraysEXT();*/
1665 //DisplayData displayData = display.driverData;
1666 MeshData meshData = mesh.data;
1668 // *** Vertex Stream ***
1669 glEnableClientState(GL_VERTEX_ARRAY);
1670 if(!display.display3D.collectingHits && meshData)
1673 glBindBufferARB(GL_ARRAY_BUFFER_ARB, meshData.vertices);
1674 glVertexPointer(3, mesh.flags.doubleVertices ? GL_DOUBLE : GL_FLOAT, 0, glBindBufferARB ? null : mesh.vertices);
1676 // *** Normals Stream ***
1679 glEnableClientState(GL_NORMAL_ARRAY);
1681 glBindBufferARB(GL_ARRAY_BUFFER_ARB, meshData.normals);
1682 glNormalPointer(mesh.flags.doubleNormals ? GL_DOUBLE : GL_FLOAT, 0, glBindBufferARB ? null : mesh.normals);
1686 glDisableClientState(GL_NORMAL_ARRAY);
1689 // *** Texture Coordinates Stream ***
1692 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1694 glBindBufferARB( GL_ARRAY_BUFFER_ARB, meshData.texCoords);
1695 glTexCoordPointer(2, GL_FLOAT, 0, glBindBufferARB ? null : mesh.texCoords);
1699 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1702 // *** Color Stream ***
1705 glEnableClientState(GL_COLOR_ARRAY);
1707 glBindBufferARB( GL_ARRAY_BUFFER_ARB, meshData.colors);
1708 glColorPointer(4, GL_FLOAT, 0, glBindBufferARB ? null : mesh.colors);
1712 glDisableClientState(GL_COLOR_ARRAY);
1718 glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0);
1719 glVertexPointer(3,mesh.flags.doubleVertices ? GL_DOUBLE : GL_FLOAT,0,mesh.vertices);
1720 if(mesh.normals && !display.display3D.collectingHits)
1722 glEnableClientState(GL_NORMAL_ARRAY);
1723 glNormalPointer(mesh.flags.doubleNormals ? GL_DOUBLE : GL_FLOAT, 0, mesh.normals);
1726 glDisableClientState(GL_NORMAL_ARRAY);
1727 if(mesh.texCoords && !display.display3D.collectingHits)
1729 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1730 glTexCoordPointer(2, GL_FLOAT, 0, mesh.texCoords);
1733 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1734 if(mesh.colors && !display.display3D.collectingHits)
1736 glEnableClientState(GL_COLOR_ARRAY);
1737 glColorPointer(4, GL_FLOAT, 0, mesh.colors);
1740 glDisableClientState(GL_COLOR_ARRAY);
1743 //if(glLockArraysEXT) glLockArraysEXT(0, mesh.nVertices);
1745 else if(glBindBufferARB)
1746 glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
1749 void DrawPrimitives(Display display, PrimitiveSingle * primitive, Mesh mesh)
1751 //DisplayData displayData = display.driverData;
1752 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1754 if(primitive->type.vertexRange)
1755 glDrawArrays(primitiveTypes[primitive->type.primitiveType], primitive->first, primitive->nVertices);
1758 // *** Hoping the data won't be uploaded at all (Won't really work if another group of the mesh is using the mesh ) ***
1759 // HACK TO SPEED THINGS UP...
1760 if(primitive->nIndices < (mesh.nVertices >> 2) && !primitive->type.indices32bit)
1763 glBegin(primitiveTypes[primitive->type.primitiveType]);
1766 IndexData indexData = primitive->data;
1767 MeshFeatures flags = mesh.flags;
1768 for(c = 0; c < primitive->nIndices; c++)
1770 short index = ((short *) indexData.indices)[c];
1771 if(flags.normals) glNormal3fv((float *)&mesh.normals[index]);
1772 if(flags.texCoords1) glTexCoord2fv((float *)&mesh.texCoords[index]);
1773 if(flags.colors) glColor4fv((float *)&mesh.colors[index]);
1774 glVertex3fv((float *)&mesh.vertices[index]);
1781 IndexData indexData = primitive->data;
1783 if(!display.display3D.collectingHits && glBindBufferARB && indexData)
1785 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indexData.buffer);
1786 glDrawElements(primitiveTypes[primitive->type.primitiveType], primitive->nIndices,
1787 primitive->type.indices32bit ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0);
1788 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
1791 glDrawElements(primitiveTypes[primitive->type.primitiveType], primitive->nIndices,
1792 primitive->type.indices32bit ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, indexData.indices);
1794 glDrawElements(primitiveTypes[primitive->type.primitiveType], primitive->nIndices,
1795 primitive->type.indices32bit ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, primitive->indices);
1800 void PushMatrix(Display display)
1802 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1806 void PopMatrix(Display display, bool setMatrix)
1808 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1812 void SetTransform(Display display, Matrix transMatrix, bool viewSpace, bool useCamera)
1814 Matrix matrix = transMatrix;
1815 Camera camera = useCamera ? display.display3D.camera : null;
1817 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1821 glScalef(1.0f, 1.0f, -1.0f);
1826 matrix.m[3][0] - camera.cPosition.x,
1827 matrix.m[3][1] - camera.cPosition.y,
1828 matrix.m[3][2] - camera.cPosition.z);
1840 glMultMatrixd(matrix.array);