3 namespace gfx::drivers;
7 import "CocoaInterface.h"
12 #define glLoadMatrix glLoadMatrixd
13 #define glMultMatrix glMultMatrixd
14 #define glGetMatrix glGetDoublev
15 #define glTranslate glTranslated
16 #define glScale glScaled
18 #define GL_ARRAY_BUFFER_ARB 0x8892
19 #define GL_ELEMENT_ARRAY_BUFFER_ARB 0x8893
20 #define GL_STATIC_DRAW_ARB 0x88E4
21 #define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8
22 #define GL_SEPARATE_SPECULAR_COLOR 0x81FA
24 #define GL_MULTISAMPLE_ARB 0x809D
26 //static int displayWidth, displayHeight;
28 #define GL_CLAMP_TO_EDGE 0x812F
30 class DisplayData : struct
32 ColorAlpha * flippingBuffer;
33 int flipBufH, flipBufW;
40 class SystemData : struct
45 class SurfaceData : struct
52 float foreground[4], background[4], bitmapMult[4];
55 class MeshData : struct
64 class IndexData : struct
71 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
72 static int primitiveTypes[RenderPrimitiveType] =
74 GL_POINTS, GL_LINES, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS, GL_QUAD_STRIP, GL_LINE_STRIP
83 GLenum error = glGetError();
86 printf("**** glGetError():%i ****\n", error);
91 class CocoaOpenGLDisplayDriver : DisplayDriver
93 class_property(name) = "CocoaOpenGL";
95 bool LockSystem(DisplaySystem displaySystem)
97 printf("CocoaOpenGLDisplayDriver:LockSystem STUB! %s:%i\n", __FILE__, __LINE__);
101 void UnlockSystem(DisplaySystem displaySystem)
103 printf("CocoaOpenGLDisplayDriver:UnlockSystem STUB! %s:%i\n", __FILE__, __LINE__);
106 bool Lock(Display display)
108 printf("CocoaOpenGLDisplayDriver:Lock %s:%i\n", __FILE__, __LINE__);
109 return CocoaLock(display.window);
112 void Unlock(Display display)
114 printf("CocoaOpenGLDisplayDriver:Unlock %s:%i\n", __FILE__, __LINE__);
115 CocoaUnlock(display.window);
118 void DestroyDisplay(Display display)
120 printf("CocoaOpenGLDisplayDriver:DestroyDisplay STUB! %s:%i\n", __FILE__, __LINE__);
123 bool CreateDisplaySystem(DisplaySystem displaySystem)
127 SystemData system = SystemData { };
128 displaySystem.driverData = system;
130 printf("CocoaOpenGLDisplayDriver:CreateDisplaySystem %s:%i\n", __FILE__, __LINE__);
134 void DestroyDisplaySystem(DisplaySystem displaySystem)
136 printf("CocoaOpenGLDisplayDriver:DestroyDisplaySystem STUB! %s:%i\n", __FILE__, __LINE__);
139 bool CreateDisplay(Display display)
143 DisplayData displayData = display.driverData;
144 SystemData systemData = display.displaySystem.driverData;
146 displayData = display.driverData = DisplayData { };
148 CocoaOpenGLMakeCurrentContext(display.window);
151 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
156 glMatrixMode(GL_MODELVIEW);
158 glScalef(1.0f, 1.0f, -1.0f);
160 glMatrixMode(GL_PROJECTION);
162 glShadeModel(GL_FLAT);
165 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
167 glFogi(GL_FOG_MODE, GL_EXP);
169 glFogf(GL_FOG_DENSITY, 0);
171 glEnable(GL_NORMALIZE);
173 glDepthFunc(GL_LESS);
177 glDisable(GL_MULTISAMPLE_ARB);
180 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
181 display.ambient = Color { 50,50,50 };
184 printf("CocoaOpenGLDisplayDriver:CreateDisplay %p %s:%i\n", display.window, __FILE__, __LINE__);
188 bool DisplaySize(Display display, int width, int height)
192 DisplayData displayData = display.driverData;
193 SystemData systemData = display.displaySystem.driverData;
195 printf("CocoaOpenGLDisplayDriver:DisplaySize(%i,%i) %s:%i\n", width, height, __FILE__, __LINE__);
197 CocoaOpenGLMakeCurrentContext(display.window);
199 glViewport(0,0,width,height);
203 glOrtho(0,width,height,0,0.0,1.0);
205 display.width = width;
206 display.height = height;
208 if(!displayData.flippingBuffer || displayData.flipBufW < width || displayData.flipBufH < height)
210 displayData.flipBufW = width;
211 displayData.flipBufH = height;
212 displayData.flippingBuffer = renew displayData.flippingBuffer ColorAlpha [width * height];
214 if(displayData.flippingBuffer)
220 void DisplayPosition(Display display, int x, int y)
222 DisplayData displayData = display.driverData;
224 printf("CocoaOpenGLDisplayDriver:DisplayPosition(%i,%i) %s:%i\n", x, y, __FILE__, __LINE__);
228 printf("glGetError():%i\n", glGetError());
231 void SetPalette(Display display, ColorAlpha * palette, bool colorMatch)
233 printf("CocoaOpenGLDisplayDriver:SetPalette STUB! %s:%i\n", __FILE__, __LINE__);
236 void RestorePalette(Display display)
238 printf("CocoaOpenGLDisplayDriver:RestorePalette STUB! %s:%i\n", __FILE__, __LINE__);
241 void StartUpdate(Display display)
243 printf("CocoaOpenGLDisplayDriver:StartUpdate STUB! %s:%i\n", __FILE__, __LINE__);
246 void EndUpdate(Display display)
248 printf("CocoaOpenGLDisplayDriver:EndUpdate STUB! %s:%i\n", __FILE__, __LINE__);
251 void Scroll(Display display, Box scroll, int x, int y, Extent dirty)
253 printf("CocoaOpenGLDisplayDriver:Scroll STUB! %s:%i\n", __FILE__, __LINE__);
256 void Update(Display display, Box updateBox)
258 //CocoaOpenGLUpdate(display.window);
259 printf("CocoaOpenGLDisplayDriver:Update %s:%i\n", __FILE__, __LINE__);
262 void FreeBitmap(DisplaySystem displaySystem, Bitmap bitmap)
264 glDeleteTextures(1, (int *)&bitmap.driverData);
265 bitmap.driverData = 0;
267 bitmap.driver = class(LFBDisplayDriver);
269 printf("CocoaOpenGLDisplayDriver:FreeBitmap %s:%i\n", __FILE__, __LINE__);
272 bool AllocateBitmap(DisplaySystem displaySystem, Bitmap bitmap, int width, int height, int stride, PixelFormat format, bool allocatePalette)
278 uint w = pow2i(Min(width, 1024)), h = pow2i(Min(height, 1024));
280 printf("CocoaOpenGLDisplayDriver:AllocateBitmap %s:%i\n", __FILE__, __LINE__);
283 glGenTextures(1, &glBitmap);
285 glBindTexture(GL_TEXTURE_2D, glBitmap);
288 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
291 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
293 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
296 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
298 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
301 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
303 mipMap.Allocate(null, w, h, w, pixelFormatRGBA, false);
306 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipMap.picture);
309 bitmap.driverData = (void *)glBitmap;
310 bitmap.driver = displaySystem.driver;
319 bool MakeDDBitmap(DisplaySystem displaySystem, Bitmap bitmap, bool mipMaps)
322 SystemData systemData = displaySystem.driverData;
324 // Pre process the bitmap... First make it 32 bit
325 if(bitmap.Convert(null, pixelFormat888, null))
328 uint w = pow2i(Min(bitmap.width, 1024)), h = pow2i(Min(bitmap.height, 1024));
331 // Switch ARGB to RGBA
332 //if(bitmap.format != pixelFormatRGBA)
334 for(c=0; c<bitmap.size; c++)
337 ColorAlpha color = ((ColorAlpha *)bitmap.picture)[c];
338 ((ColorRGBA *)bitmap.picture)[c] = ColorRGBA { color.color.r, color.color.g, color.color.b, color.a };
341 bitmap.pixelFormat = pixelFormat888;
344 glGenTextures(1, &glBitmap);
348 int error = glGetError();
354 glBindTexture(GL_TEXTURE_2D, glBitmap);
356 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
359 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
361 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mipMaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
364 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
366 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
369 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
374 for(level = 0; result && (w > 1 || h > 1); level++, w >>= 1, h >>= 1)
377 if(bitmap.width != w || bitmap.height != h)
380 if(mipMap.Allocate(null, w, h, w, bitmap.pixelFormat, false))
382 Surface mipSurface = mipMap.GetSurface(0,0,null);
383 mipSurface.Filter(bitmap, 0,0,0,0, w, h, bitmap.width, bitmap.height);
398 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipMap.picture);
400 if((error = glGetError()))
411 bitmap.driver.FreeBitmap(bitmap.displaySystem, bitmap);
412 bitmap.driverData = (void *)glBitmap;
413 bitmap.driver = displaySystem.driver;
416 FreeBitmap(displaySystem, bitmap);
417 else if(systemData.loadingFont)
419 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
421 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
423 systemData.loadingFont = false;
427 printf("CocoaOpenGLDisplayDriver:MakeDDBitmap %i %s:%i\n", result, __FILE__, __LINE__);
431 void ReleaseSurface(Display display, Surface surface)
433 printf("CocoaOpenGLDisplayDriver:ReleaseSurface %s:%i\n", __FILE__, __LINE__);
435 glDisable(GL_SCISSOR_TEST);
437 delete surface.driverData;
438 surface.driverData = null;
441 bool GetBitmapSurface(DisplaySystem displaySystem, Surface surface, Bitmap bitmap, int x, int y, Box clip)
443 printf("CocoaOpenGLDisplayDriver:GetBitmapSurface STUB! %s:%i\n", __FILE__, __LINE__);
447 bool GetSurface(Display display, Surface surface, int x,int y, Box clip)
451 SurfaceData surfaceData = SurfaceData { };
452 surface.driverData = surfaceData;
454 printf("CocoaOpenGLDisplayDriver:GetSurface %p %s:%i\n", surfaceData, __FILE__, __LINE__);
459 glViewport(0,0,display.width,display.height);
463 printf("display:%i, %i\n", display.width, display.height);
464 glOrtho(0, display.width, display.height, 0, 0.0f, 1.0f);
467 surface.offset.x = x;
468 surface.offset.y = y;
469 surface.unclippedBox = surface.box = clip;
470 surfaceData.bitmapMult[0] = 1;
471 surfaceData.bitmapMult[1] = 1;
472 surfaceData.bitmapMult[2] = 1;
473 surfaceData.bitmapMult[3] = 1;
475 glEnable(GL_SCISSOR_TEST);
479 (display.height) -(y+clip.bottom)-1,
480 clip.right-clip.left+1,
481 clip.bottom-clip.top+1);
489 void Clip(Display display, Surface surface, Box clip)
493 printf("CocoaOpenGLDisplayDriver:Clip STUB! %s:%i\n", __FILE__, __LINE__);
498 box.Clip(surface.unclippedBox);
503 box = surface.box = surface.unclippedBox;
506 box.left += surface.offset.x;
507 box.top += surface.offset.y;
508 box.right+= surface.offset.x;
509 box.bottom += surface.offset.y;
512 box.left,display.height - box.bottom - 1,
513 box.right-box.left+1, box.bottom-box.top+1);
516 bool GrabScreen(Display display, Bitmap bitmap, int x, int y, unsigned int w, unsigned int h)
519 printf("CocoaOpenGLDisplayDriver:GrabScreen STUB! %s:%i\n", __FILE__, __LINE__);
523 void SetForeground(Display display, Surface surface, ColorAlpha color)
525 SurfaceData surfaceData = surface.driverData;
527 printf("CocoaOpenGLDisplayDriver:SetForeground(%i,%i,%i,%i) %s:%i\n", color.color.r, color.color.g, color.color.b, color.a, __FILE__, __LINE__);
529 surfaceData.foreground[0] = color.color.r/255.0f;
530 surfaceData.foreground[1] = color.color.g/255.0f;
531 surfaceData.foreground[2] = color.color.b/255.0f;
532 surfaceData.foreground[3] = color.a/255.0f;
535 void SetBackground(Display display, Surface surface, ColorAlpha color)
537 SurfaceData surfaceData = surface.driverData;
539 printf("CocoaOpenGLDisplayDriver:SetBackground(%i,%i,%i,%i) %s:%i\n", color.color.r, color.color.g, color.color.b, color.a, __FILE__, __LINE__);
541 surfaceData.background[0] = color.color.r/255.0f;
542 surfaceData.background[1] = color.color.g/255.0f;
543 surfaceData.background[2] = color.color.b/255.0f;
544 surfaceData.background[3] = color.a/255.0f;
547 void SetBlitTint(Display display, Surface surface, ColorAlpha color)
549 SurfaceData surfaceData = surface.driverData;
551 printf("CocoaOpenGLDisplayDriver:SetBlitTint(%i,%i,%i,%i) %s:%i\n", color.color.r, color.color.g, color.color.b, color.a, __FILE__, __LINE__);
553 surfaceData.bitmapMult[0] = color.color.r/255.0f;
554 surfaceData.bitmapMult[1] = color.color.g/255.0f;
555 surfaceData.bitmapMult[2] = color.color.b/255.0f;
556 surfaceData.bitmapMult[3] = color.a/255.0f;
560 ColorAlpha GetPixel(Display display, Surface surface,int x,int y)
562 printf("CocoaOpenGLDisplayDriver:GetPixel STUB! %s:%i\n", __FILE__, __LINE__);
566 void PutPixel(Display display, Surface surface,int x,int y)
568 printf("CocoaOpenGLDisplayDriver:PutPixel %s:%i\n", __FILE__, __LINE__);
572 glVertex2f(x+surface.offset.x + 0.5f, y+surface.offset.y + 0.5f);
577 void DrawLine(Display display, Surface surface, int x1, int y1, int x2, int y2)
579 SurfaceData surfaceData = surface.driverData;
581 printf("CocoaOpenGLDisplayDriver:DrawLine %s:%i\n", __FILE__, __LINE__);
582 printf("--DrawLine(x1:%i, y1:%i, x2:%i, y2:%i)\n", x1, y1, x2, y2);
584 glColor4fv(surfaceData.foreground);
587 glVertex2f(x1+surface.offset.x + 0.5f, y1+surface.offset.y + 0.5f);
588 glVertex2f(x2+surface.offset.x + 0.5f, y2+surface.offset.y + 0.5f);
594 void Rectangle(Display display, Surface surface,int x1,int y1,int x2,int y2)
596 printf("CocoaOpenGLDisplayDriver:Rectangle %s:%i\n", __FILE__, __LINE__);
597 printf("--Rectangle(x1:%i, y1:%i, x2:%i, y2:%i)\n", x1, y1, x2, y2);
598 glBegin(GL_LINE_LOOP);
600 glVertex2f(x1+surface.offset.x + 0.5f, y1+surface.offset.y + 0.5f);
601 glVertex2f(x1+surface.offset.x + 0.5f, y2+surface.offset.y + 0.5f);
602 glVertex2f(x2+surface.offset.x + 0.5f, y2+surface.offset.y + 0.5f);
603 glVertex2f(x2+surface.offset.x + 0.5f, y1+surface.offset.y + 0.5f);
609 void Area(Display display, Surface surface,int x1,int y1,int x2,int y2)
611 SurfaceData surfaceData = surface.driverData;
613 printf("CocoaOpenGLDisplayDriver:Area %s:%i\n", __FILE__, __LINE__);
616 glColor4fv(surfaceData.background);
618 glRecti(x1+surface.offset.x, y1+surface.offset.y,
619 x2+surface.offset.x + 1, y2+surface.offset.y + 1);
623 void Clear(Display display, Surface surface, ClearType type)
625 DisplayData displayData = display.driverData;
626 SurfaceData surfaceData = surface.driverData;
628 if(type != depthBuffer)
630 glClearColor(surfaceData.background[0], surfaceData.background[1], surfaceData.background[2], surfaceData.background[3]);
633 if(type != colorBuffer && !displayData.depthWrite)
635 glDepthMask((byte)bool::true);
638 glClear(((type != depthBuffer) ? GL_COLOR_BUFFER_BIT : 0) |
639 ((type != colorBuffer) ? GL_DEPTH_BUFFER_BIT : 0));
642 if(type != colorBuffer && !displayData.depthWrite)
644 glDepthMask((byte)bool::false);
647 if(type != depthBuffer)
649 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
652 if(type != colorBuffer)
654 glDepthMask((byte)bool::true);
658 glClear(((type != depthBuffer) ? GL_COLOR_BUFFER_BIT : 0) |
659 ((type != colorBuffer) ? GL_DEPTH_BUFFER_BIT : 0));
662 if(type != colorBuffer)
664 glDepthMask((byte)bool::false);
667 printf("CocoaOpenGLDisplayDriver:Clear %s:%i\n", __FILE__, __LINE__);
670 bool ConvertBitmap(DisplaySystem displaySystem, Bitmap bitmap, PixelFormat format, ColorAlpha * palette)
674 printf("CocoaOpenGLDisplayDriver:ConvertBitmap %s:%i\n", __FILE__, __LINE__);
679 void Blit(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h)
681 printf("CocoaOpenGLDisplayDriver:Blit %s:%i\n", __FILE__, __LINE__);
682 printf("--BLIT(dx:%i, dy:%i, sx:%i, sy:%i, w:%i, h:%i)\n", dx, dy, sx, sy, w, h);
684 glEnable(GL_TEXTURE_2D);
685 glBindTexture(GL_TEXTURE_2D, (uint)bitmap.driverData);
690 glTexCoord2f((float)sx/ bitmap.width, (float)(sy-h)/ bitmap.height);
691 glVertex2i(dx+surface.offset.x, dy+surface.offset.y);
692 glTexCoord2f((float)(sx+w) / bitmap.width, (float)(sy-h)/ bitmap.height);
693 glVertex2i(dx+w+surface.offset.x, dy+surface.offset.y);
694 glTexCoord2f((float)(sx+w)/ bitmap.width, (float)sy/ bitmap.height);
695 glVertex2i(dx+w+surface.offset.x, dy-h+surface.offset.y);
696 glTexCoord2f((float)sx / bitmap.width, (float)sy/ bitmap.height);
697 glVertex2i(dx+surface.offset.x, dy-h+surface.offset.y);
701 glTexCoord2f((float)sx / bitmap.width, (float)sy/ bitmap.height);
702 glVertex2f((float)dx+surface.offset.x, (float)dy+surface.offset.y);
703 glTexCoord2f((float)(sx+w)/ bitmap.width, (float)sy/ bitmap.height);
704 glVertex2f((float)dx+w+surface.offset.x, (float)dy+surface.offset.y);
705 glTexCoord2f((float)(sx+w) / bitmap.width, (float)(sy+h)/ bitmap.height);
706 glVertex2f((float)dx+w+surface.offset.x, (float)dy+h+surface.offset.y);
707 glTexCoord2f((float)sx/ bitmap.width, (float)(sy+h)/ bitmap.height);
708 glVertex2f((float)dx+surface.offset.x, (float)dy+h+surface.offset.y);
714 void Stretch(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
716 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
717 glEnable(GL_TEXTURE_2D);
719 glBindTexture(GL_TEXTURE_2D, (uint)bitmap.driverData);
727 glTexCoord2f((float)(sx)/ bitmap.width, (float)(sy+sh)/ bitmap.height);
729 glVertex2i(dx+surface.offset.x, dy+surface.offset.y);
732 glTexCoord2f((float)(sx+sw) / bitmap.width, (float)(sy+sh)/ bitmap.height);
734 glVertex2i(dx+w+surface.offset.x, dy+surface.offset.y);
737 glTexCoord2f((float)(sx+sw)/ bitmap.width, (float)(sy)/ bitmap.height);
739 glVertex2i(dx+w+surface.offset.x, dy-h+surface.offset.y);
742 glTexCoord2f((float)(sx) / bitmap.width, (float)(sy)/ bitmap.height);
744 glVertex2i(dx+surface.offset.x, dy-h+surface.offset.y);
749 glTexCoord2f((float)(sx) / bitmap.width, (float)(sy)/ bitmap.height);
751 glVertex2i(dx+surface.offset.x, dy+surface.offset.y);
754 glTexCoord2f((float)(sx+sw)/ bitmap.width, (float)(sy)/ bitmap.height);
756 glVertex2i(dx+w+surface.offset.x, dy+surface.offset.y);
759 glTexCoord2f((float)(sx+sw) / bitmap.width, (float)(sy+sh)/ bitmap.height);
761 glVertex2i(dx+w+surface.offset.x, dy+h+surface.offset.y);
764 glTexCoord2f((float)(sx)/ bitmap.width, (float)(sy+sh)/ bitmap.height);
766 glVertex2i(dx+surface.offset.x, dy+h+surface.offset.y);
773 glDisable(GL_TEXTURE_2D);
777 void Filter(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
779 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
780 Stretch(display, surface, bitmap, dx, dy, sx, sy, w, h, sw, sh);
783 void StretchDI(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
785 float s2dw,s2dh,d2sw,d2sh;
786 bool flipX = false, flipY = false;
788 printf("CocoaOpenGLDisplayDriver: %s:%i\n", __FILE__, __LINE__);
789 if(Sgn(w) != Sgn(sw))
795 if(Sgn(h) != Sgn(sh))
807 //Clip against the edges of the source
810 dx+=(int)((0-sx) * s2dw);
811 w-=(int)((0-sx) * s2dw);
817 dy+=(int)((0-sy) * s2dh);
818 h-=(int)((0-sy) * s2dh);
823 if(sx+sw>bitmap.width-1)
825 w-=(int)((sx+sw-(bitmap.width-1)-1)*s2dw);
826 sw-=sx+sw-(bitmap.width-1)-1;
828 if(sy+sh>(bitmap.height-1))
830 h-=(int)((sy+sh-(bitmap.height-1)-1)*s2dh);
831 sh-=sy+sh-(bitmap.height-1)-1;
833 //Clip against the edges of the surfaceination
834 if(dx<surface.box.left)
837 sx+=(int)((surface.box.left-dx)*d2sw);
838 sw-=(int)((surface.box.left-dx)*d2sw);
839 w-=surface.box.left-dx;
842 if(dy<surface.box.top)
844 sy+=(int)((surface.box.top-dy)*d2sh);
845 sh-=(int)((surface.box.top-dy)*d2sh);
846 h-=surface.box.top-dy;
849 if(dx+w>surface.box.right)
851 //if(flip) sx+=(int)((dx+w-surface.box.right-1)*d2sw);
852 sw-=(int)((dx+w-surface.box.right-1)*d2sw);
853 w-=dx+w-surface.box.right-1;
855 if(dy+h>surface.box.bottom)
857 sh-=(int)((dy+h-surface.box.bottom-1)*d2sh);
858 h-=dy+h-surface.box.bottom-1;
860 if((w<=0)||(h<=0)||(sw<=0)||(sh<=0)) return;
862 dx += surface.offset.x;
863 dy += surface.offset.y;
865 if(bitmap.pixelFormat == pixelFormat888 && !bitmap.paletteShades)
867 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
869 glPixelStorei(GL_UNPACK_ROW_LENGTH, bitmap.stride);
871 glPixelStorei(GL_UNPACK_SKIP_PIXELS, sx);
873 glPixelStorei(GL_UNPACK_SKIP_ROWS, sy);
875 glRasterPos2d(dx,dy);
877 //glPixelZoom(flipX ? -s2dw : s2dw, flipY ? s2dh : -s2dh);
879 glPixelZoom(s2dw, -s2dh);
881 glDrawPixels(sw,sh,GL_BGRA_EXT,GL_UNSIGNED_BYTE, bitmap.picture);
883 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
885 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
890 void BlitDI(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h)
892 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
893 //Clip against the edges of the source
906 if(sx+w>bitmap.width-1)
907 w-=sx+w-(bitmap.width-1)-1;
908 if(sy+h>bitmap.height-1)
909 h-=sy+h-(bitmap.height-1)-1;
910 //Clip against the edges of the surfaceination
911 if(dx<surface.box.left)
914 sx+=surface.box.left-dx;
915 w-=surface.box.left-dx;
918 if(dy<surface.box.top)
920 sy+=surface.box.top-dy;
921 h-=surface.box.top-dy;
924 if(dx+w>surface.box.right)
926 //if(flip) sx+=dx+w-surface.box.right-1;
927 w-=dx+w-surface.box.right-1;
929 if(dy+h>surface.box.bottom)
930 h-=dy+h-surface.box.bottom-1;
934 dx += surface.offset.x;
935 dy += surface.offset.y;
937 if(bitmap.pixelFormat == pixelFormat888 && !bitmap.paletteShades)
939 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
941 glPixelStorei(GL_UNPACK_ROW_LENGTH, bitmap.stride);
943 glPixelStorei(GL_UNPACK_SKIP_PIXELS, sx);
945 glPixelStorei(GL_UNPACK_SKIP_ROWS, sy);
947 glRasterPos2d(dx,dy);
951 glDrawPixels(w,h,GL_BGRA_EXT,GL_UNSIGNED_BYTE, bitmap.picture);
953 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
955 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
960 void FilterDI(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
962 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
963 StretchDI(display, surface, bitmap, dx, dy, sx, sy, w, h, sw, sh);
966 void UnloadFont(DisplaySystem displaySystem, Font font)
968 printf("CocoaOpenGLDisplayDriver:UnloadFont %s:%i\n", __FILE__, __LINE__);
969 LFBDisplayDriver::UnloadFont(displaySystem, font);
972 Font LoadFont(DisplaySystem displaySystem, char * faceName, float size, FontFlags flags)
974 Font font = LFBDisplayDriver::LoadFont(displaySystem, faceName, size, flags);
976 printf("CocoaOpenGLDisplayDriver:LoadFont(%s):%p %s:%i\n", faceName, font, __FILE__, __LINE__);
981 void FontExtent(DisplaySystem displaySystem, Font font, char * text, int len, int * width, int * height)
983 printf("CocoaOpenGLDisplayDriver:FontExtent() %s:%i\n", __FILE__, __LINE__);
984 LFBDisplayDriver::FontExtent(displaySystem, font, text, len, width, height);
987 void WriteText(Display display, Surface surface, int x, int y, char * text, int len)
989 SurfaceData surfaceData = surface.driverData;
990 SystemData systemData = display.displaySystem.driverData;
992 printf("CocoaOpenGLDisplayDriver:WriteText %s:%i\n", __FILE__, __LINE__);
994 systemData.loadingFont = true;
996 if(surface.textOpacity)
999 FontExtent(display.displaySystem, surface.font, text, len, &w, &h);
1000 Area(display, surface,x,y,x+w-1,y+h-1);
1003 surfaceData.writingText = true;
1005 glEnable(GL_TEXTURE_2D);
1007 glColor4fv(surfaceData.foreground);
1010 LFBDisplayDriver::WriteText(display, surface, x, y, text, len);
1011 surfaceData.writingText = false;
1012 systemData.loadingFont = false;
1014 glDisable(GL_TEXTURE_2D);
1018 void TextFont(Display display, Surface surface, Font font)
1020 LFBDisplayDriver::TextFont(display, surface, font);
1021 printf("CocoaOpenGLDisplayDriver:TextFont %s:%i\n", __FILE__, __LINE__);
1024 void TextOpacity(Display display, Surface surface, bool opaque)
1026 SurfaceData surfaceData = surface.driverData;
1027 surfaceData.opaqueText = opaque;
1028 printf("CocoaOpenGLDisplayDriver:TextOpacity(%i) %s:%i\n", opaque, __FILE__, __LINE__);
1031 void TextExtent(Display display, Surface surface, char * text, int len, int * width, int * height)
1033 SurfaceData surfaceData = surface.driverData;
1034 SystemData systemData = display.displaySystem.driverData;
1035 systemData.loadingFont = true;
1036 FontExtent(display.displaySystem, surfaceData.font, text, len, width, height);
1037 systemData.loadingFont = false;
1039 printf("CocoaOpenGLDisplayDriver:TextExtent STUB! %s:%i\n", __FILE__, __LINE__);
1042 void DrawingChar(Display display, Surface surface, char character)
1044 printf("CocoaOpenGLDisplayDriver:DrawingChar STUB! %s:%i\n", __FILE__, __LINE__);
1048 void LineStipple(Display display, Surface surface, uint32 stipple)
1050 printf("CocoaOpenGLDisplayDriver:LineStipple %s:%i\n", __FILE__, __LINE__);
1053 glLineStipple(1, (uint16)stipple);
1055 glEnable(GL_LINE_STIPPLE);
1060 glDisable(GL_LINE_STIPPLE);
1063 printf("glGetError():%i\n", glGetError());
1066 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
1067 void SetRenderState(Display display, RenderState state, uint value)
1069 printf("CocoaOpenGLDisplayDriver:SetRenderState STUB! %s:%i\n", __FILE__, __LINE__);
1074 glEnable(GL_MULTISAMPLE_ARB);
1076 glDisable(GL_MULTISAMPLE_ARB);
1080 glPolygonMode(GL_FRONT_AND_BACK, ((FillModeValue)value == solid) ? GL_FILL : GL_LINE);
1084 if(value) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
1088 if(value) glDepthMask((byte)bool::true); else glDepthMask((byte)bool::false);
1093 float color[4] = { ((Color)value).r/255.0f, ((Color)value).g/255.0f, ((Color)value).b/255.0f, 1.0f };
1094 glFogfv(GL_FOG_COLOR, (float *)&color);
1099 glFogf(GL_FOG_DENSITY, *(float *)(void *)&value);
1103 if(value) glEnable(GL_BLEND); else glDisable(GL_BLEND);
1108 float ambient[4] = { ((Color)value).r/255.0f, ((Color)value).g/255.0f, ((Color)value).b/255.0f, 1.0f };
1109 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
1115 if(value) glColorMask(1,1,1,1); else glColorMask(1,1,1,0);
1126 void SetLight(Display display, int id, Light light)
1128 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1131 Object lightObject = light.lightObject;
1132 float position[4] = { 0, 0, 0, 0 };
1133 float color[4] = { 0, 0, 0, 1 };
1135 glEnable(GL_LIGHT0 + id);
1138 if(!light.multiplier) light.multiplier = 1.0f;
1140 color[0] = light.diffuse.r * light.multiplier;
1141 color[1] = light.diffuse.g * light.multiplier;
1142 color[2] = light.diffuse.b * light.multiplier;
1143 glLightfv(GL_LIGHT0 + id, GL_DIFFUSE, color);
1145 color[0] = light.ambient.r * light.multiplier;
1146 color[1] = light.ambient.g * light.multiplier;
1147 color[2] = light.ambient.b * light.multiplier;
1148 glLightfv(GL_LIGHT0 + id, GL_AMBIENT, color);
1149 color[0] = light.specular.r * light.multiplier;
1150 color[1] = light.specular.g * light.multiplier;
1151 color[2] = light.specular.b * light.multiplier;
1152 glLightfv(GL_LIGHT0 + id, GL_SPECULAR,color);
1156 Vector3D positionVector;
1157 if(light.flags.spot)
1159 if(lightObject.flags.root || !lightObject.parent)
1161 positionVector = lightObject.transform.position;
1162 positionVector.Subtract(positionVector, display.display3D.camera.cPosition);
1166 positionVector.MultMatrix(lightObject.transform.position, lightObject.parent.matrix);
1167 if(display.display3D.camera)
1168 positionVector.Subtract(positionVector, display.display3D.camera.cPosition);
1174 if(!light.direction.x && !light.direction.y && !light.direction.z)
1176 Vector3Df vector { 0,0,-1 };
1178 mat.RotationQuaternion(light.orientation);
1179 positionVector.MultMatrixf(vector, mat);
1183 positionVector = light.direction;
1188 position[0] = (float)positionVector.x;
1189 position[1] = (float)positionVector.y;
1190 position[2] = (float)positionVector.z;
1192 glLightfv(GL_LIGHT0 + id, GL_POSITION, position);
1195 if(light.flags.attenuation)
1197 glLightf(GL_LIGHT0 + id, GL_CONSTANT_ATTENUATION, light.Kc);
1199 glLightf(GL_LIGHT0 + id, GL_LINEAR_ATTENUATION, light.Kl);
1201 glLightf(GL_LIGHT0 + id, GL_QUADRATIC_ATTENUATION, light.Kq);
1205 if(light.flags.spot)
1208 #define MAXLIGHT 0.9
1209 float direction[4] = { (float)light.direction.x, (float)light.direction.y, (float)light.direction.z, 1 };
1210 // Figure out exponent out of the hot spot
1211 exponent = (float)(log(MAXLIGHT) / log(cos((light.hotSpot / 2))));
1213 glLightfv(GL_LIGHT0 + id, GL_SPOT_DIRECTION, direction);
1215 glLightf(GL_LIGHT0 + id, GL_SPOT_CUTOFF, (float)(light.fallOff / 2));
1217 glLightf(GL_LIGHT0 + id, GL_SPOT_EXPONENT, exponent);
1223 Vector3Df vector { 0,0,-1 };
1224 Vector3Df direction;
1227 mat.RotationQuaternion(light.orientation);
1228 direction.MultMatrix(vector, mat);
1230 position[0] = direction.x;
1231 position[1] = direction.y;
1232 position[2] = direction.z;
1234 glLightfv(GL_LIGHT0 + id, GL_POSITION, position);
1239 glDisable(GL_LIGHT0 + id);
1243 void SetCamera(Display display, Surface surface, Camera camera)
1245 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1248 int left = surface.box.left + surface.offset.x;
1249 int top = surface.box.top + surface.offset.y;
1250 int right = surface.box.right + surface.offset.x;
1251 int bottom = surface.box.bottom + surface.offset.y;
1252 float origX = surface.offset.x + camera.origin.x;
1253 float origY = surface.offset.y + camera.origin.y;
1255 int y = display.height - bottom - 1;
1256 int w = right - left + 1;
1257 int h = bottom - top + 1;
1260 glViewport(x, y, w, h);
1262 // *** Projection Matrix ***
1263 if(!display.display3D.camera)
1266 glMatrixMode(GL_PROJECTION);
1267 if(display.display3D.collectingHits)
1269 float pickX = display.display3D.pickX + surface.offset.x;
1270 float pickY = display.height - (display.display3D.pickY + surface.offset.y) - 1;
1274 w / display.display3D.pickWidth, 0, 0, 0,
1275 0, h / display.display3D.pickHeight, 0, 0,
1277 (w + 2.0f * (x - pickX)) / display.display3D.pickWidth,
1278 (h + 2.0f * (y - pickY)) / display.display3D.pickHeight, 0, 1
1281 glLoadMatrixd(pickMatrix.array);
1286 (left - origX) * camera.zMin / camera.focalX,
1287 (right - origX) * camera.zMin / camera.focalX,
1288 (bottom - origY) * camera.zMin / camera.focalY,
1289 (top - origY) * camera.zMin / camera.focalY,
1290 camera.zMin, camera.zMax);
1292 glDisable(GL_BLEND);
1294 // *** Z Inverted Identity Matrix ***
1295 glMatrixMode(GL_MODELVIEW);
1296 if(!display.display3D.camera)
1300 glScalef(1.0f, 1.0f, -1.0f);
1302 // *** View Matrix ***
1303 glMultMatrixd(camera.viewMatrix.array);
1308 glEnable(GL_DEPTH_TEST);
1309 glEnable(GL_LIGHTING);
1310 glShadeModel(GL_SMOOTH);
1311 glDepthMask((byte)bool::true);
1313 glEnable(GL_MULTISAMPLE_ARB);
1315 else if(display.display3D.camera)
1317 glViewport(0,0,display.width,display.height);
1319 glDisable(GL_CULL_FACE);
1320 glDisable(GL_DEPTH_TEST);
1321 glDisable(GL_LIGHTING);
1323 glDisable(GL_TEXTURE_2D);
1324 glShadeModel(GL_FLAT);
1326 glDisable(GL_MULTISAMPLE_ARB);
1328 // *** Restore 2D MODELVIEW Matrix ***
1331 // *** Restore 2D PROJECTION Matrix ***
1332 glMatrixMode(GL_PROJECTION);
1337 glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
1338 printf("glGetError():%i\n", glGetError());
1341 void ApplyMaterial(Display display, Material material, Mesh mesh)
1343 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1345 if(material.flags.doubleSided)
1347 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, !material.flags.singleSideLight);
1348 glDisable(GL_CULL_FACE);
1352 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, bool::false);
1353 glEnable(GL_CULL_FACE);
1357 if(material.flags.noFog)
1363 if(material.baseMap && mesh.texCoords)
1365 Bitmap map = material.baseMap;
1366 glEnable(GL_TEXTURE_2D);
1367 glBindTexture(GL_TEXTURE_2D, (uint)map.driverData);
1369 if(material.flags.tile)
1371 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1372 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1376 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1377 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1381 glDisable(GL_TEXTURE_2D);
1383 if(mesh.flags.colors)
1385 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
1386 glEnable(GL_COLOR_MATERIAL);
1390 glDisable(GL_COLOR_MATERIAL);
1392 float color[4] = { material.diffuse.r, material.diffuse.g, material.diffuse.b, material.opacity };
1393 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
1396 float color[4] = { material.ambient.r, material.ambient.g, material.ambient.b, 0 };
1397 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color);
1401 float color[4] = { material.specular.r, material.specular.g, material.specular.b, 0 };
1402 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color);
1405 float color[4] = { material.emissive.r, material.emissive.g, material.emissive.b, 0 };
1406 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color);
1409 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &material.power);
1412 void FreeMesh(DisplaySystem displaySystem, Mesh mesh)
1414 MeshData meshData = mesh.data;
1415 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1418 if(!mesh.flags.vertices)
1420 if(meshData.vertices)
1422 glDeleteBuffersARB(1, &meshData.vertices);
1423 meshData.vertices = 0;
1425 delete mesh.vertices;
1427 if(!mesh.flags.normals)
1429 if(meshData.normals)
1431 glDeleteBuffersARB(1, &meshData.normals);
1432 meshData.normals = 0;
1434 delete mesh.normals;
1436 if(!mesh.flags.texCoords1)
1438 if(meshData.texCoords)
1440 glDeleteBuffersARB(1, &meshData.texCoords);
1441 meshData.texCoords = 0;
1443 delete mesh.texCoords;
1445 if(!mesh.flags.texCoords2)
1447 if(meshData.texCoords2)
1449 glDeleteBuffersARB(1, &meshData.texCoords2);
1450 meshData.texCoords2 = 0;
1453 if(!mesh.flags.colors)
1457 glDeleteBuffersARB(1, &meshData.colors);
1458 meshData.colors = 0;
1469 bool AllocateMesh(DisplaySystem displaySystem, Mesh mesh)
1471 bool result = false;
1472 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1475 mesh.data = MeshData { };
1479 MeshData meshData = mesh.data;
1481 if(mesh.flags.vertices && !meshData.vertices && !mesh.vertices)
1483 mesh.vertices = mesh.flags.doubleVertices ? (Vector3Df *)new Vector3D[mesh.nVertices] : new Vector3Df[mesh.nVertices];
1485 glGenBuffersARB(1, &meshData.vertices);
1487 if(mesh.flags.normals && !meshData.normals && !mesh.normals)
1490 glGenBuffersARB( 1, &meshData.normals);
1491 mesh.normals = mesh.flags.doubleNormals ? (Vector3Df *)new Vector3D[mesh.nVertices] : new Vector3Df[mesh.nVertices];
1493 if(mesh.flags.texCoords1 && !meshData.texCoords && !mesh.texCoords)
1496 glGenBuffersARB( 1, &meshData.texCoords);
1497 mesh.texCoords = new Pointf[mesh.nVertices];
1499 if(mesh.flags.colors && !meshData.colors && !mesh.colors)
1502 glGenBuffersARB( 1, &meshData.colors);
1503 mesh.colors = new ColorRGBAf[mesh.nVertices];
1510 void UnlockMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags)
1512 MeshData meshData = mesh.data;
1513 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1515 if(!flags) flags = mesh.flags;
1519 if(!(flags.vertices) || meshData.vertices)
1521 glBindBufferARB( GL_ARRAY_BUFFER_ARB, meshData.vertices);
1522 glBufferDataARB( GL_ARRAY_BUFFER_ARB, mesh.nVertices * (mesh.flags.doubleVertices ? sizeof(Vector3D) : sizeof(Vector3Df)), mesh.vertices, GL_STATIC_DRAW_ARB );
1525 if(!(flags.normals) || meshData.normals)
1527 glBindBufferARB( GL_ARRAY_BUFFER_ARB, meshData.normals);
1528 glBufferDataARB( GL_ARRAY_BUFFER_ARB, mesh.nVertices * (mesh.flags.doubleNormals ? sizeof(Vector3D) : sizeof(Vector3Df)), mesh.normals, GL_STATIC_DRAW_ARB );
1531 if(!(flags.texCoords1) || meshData.texCoords)
1533 glBindBufferARB( GL_ARRAY_BUFFER_ARB, meshData.texCoords);
1534 glBufferDataARB( GL_ARRAY_BUFFER_ARB, mesh.nVertices * sizeof(Pointf), mesh.texCoords, GL_STATIC_DRAW_ARB );
1537 if(!(flags.colors) || meshData.colors)
1539 glBindBufferARB( GL_ARRAY_BUFFER_ARB, meshData.colors);
1540 glBufferDataARB( GL_ARRAY_BUFFER_ARB, mesh.nVertices * sizeof(ColorRGBAf), mesh.colors, GL_STATIC_DRAW_ARB );
1543 glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0);
1547 bool LockMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags)
1550 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1554 void FreeIndices(DisplaySystem displaySystem, IndexData indexData)
1556 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1560 if(indexData.buffer)
1561 glDeleteBuffersARB(1, &indexData.buffer);
1562 delete indexData.indices;
1567 void * AllocateIndices(DisplaySystem displaySystem, int nIndices, bool indices32bit)
1569 IndexData indexData = IndexData { };
1570 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1573 indexData.indices = (void *)(indices32bit ? new uint32[nIndices] : new uint16[nIndices]);
1575 glGenBuffersARB( 1, &indexData.buffer);
1576 indexData.nIndices = nIndices;
1581 void UnlockIndices(DisplaySystem displaySystem, IndexData indexData, bool indices32bit, int nIndices)
1583 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1586 glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, indexData.buffer);
1587 glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, nIndices * (indices32bit ? sizeof(uint32) : sizeof(uint16)),
1588 indexData.indices, GL_STATIC_DRAW_ARB);
1589 glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
1593 uint16 * LockIndices(DisplaySystem displaySystem, IndexData indexData)
1595 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1597 return indexData.indices;
1600 void SelectMesh(Display display, Mesh mesh)
1602 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1604 /*if(display.display3D.mesh && glUnlockArraysEXT)
1605 glUnlockArraysEXT();*/
1609 DisplayData displayData = display.driverData;
1610 Mesh meshData = mesh.data;
1612 // *** Vertex Stream ***
1613 glEnableClientState(GL_VERTEX_ARRAY);
1614 if(!display.display3D.collectingHits && meshData)
1617 glBindBufferARB(GL_ARRAY_BUFFER_ARB, (long)meshData.vertices);
1618 glVertexPointer(3, mesh.flags.doubleVertices ? GL_DOUBLE : GL_FLOAT, 0, glBindBufferARB ? null : mesh.vertices);
1620 // *** Normals Stream ***
1623 glEnableClientState(GL_NORMAL_ARRAY);
1625 glBindBufferARB(GL_ARRAY_BUFFER_ARB, (long)meshData.normals);
1626 glNormalPointer(mesh.flags.doubleNormals ? GL_DOUBLE : GL_FLOAT, 0, glBindBufferARB ? null : mesh.normals);
1630 glDisableClientState(GL_NORMAL_ARRAY);
1633 // *** Texture Coordinates Stream ***
1636 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1638 glBindBufferARB( GL_ARRAY_BUFFER_ARB, (long)meshData.texCoords);
1639 glTexCoordPointer(2, GL_FLOAT, 0, glBindBufferARB ? null : mesh.texCoords);
1643 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1646 // *** Color Stream ***
1649 glEnableClientState(GL_COLOR_ARRAY);
1651 glBindBufferARB( GL_ARRAY_BUFFER_ARB, (long)meshData.colors);
1652 glColorPointer(4, GL_FLOAT, 0, glBindBufferARB ? null : mesh.colors);
1656 glDisableClientState(GL_COLOR_ARRAY);
1662 glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0);
1663 glVertexPointer(3,mesh.flags.doubleVertices ? GL_DOUBLE : GL_FLOAT,0,mesh.vertices);
1664 if(mesh.normals && !display.display3D.collectingHits)
1666 glEnableClientState(GL_NORMAL_ARRAY);
1667 glNormalPointer(mesh.flags.doubleNormals ? GL_DOUBLE : GL_FLOAT, 0, mesh.normals);
1670 glDisableClientState(GL_NORMAL_ARRAY);
1671 if(mesh.texCoords && !display.display3D.collectingHits)
1673 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1674 glTexCoordPointer(2, GL_FLOAT, 0, mesh.texCoords);
1677 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1678 if(mesh.colors && !display.display3D.collectingHits)
1680 glEnableClientState(GL_COLOR_ARRAY);
1681 glColorPointer(4, GL_FLOAT, 0, mesh.colors);
1684 glDisableClientState(GL_COLOR_ARRAY);
1687 //if(glLockArraysEXT) glLockArraysEXT(0, mesh.nVertices);
1689 else if(glBindBufferARB)
1690 glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
1693 void DrawPrimitives(Display display, PrimitiveSingle * primitive, Mesh mesh)
1695 DisplayData displayData = display.driverData;
1696 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1698 if(primitive->type.vertexRange)
1699 glDrawArrays(primitiveTypes[primitive->type.primitiveType], primitive->first, primitive->nVertices);
1702 // *** Hoping the data won't be uploaded at all (Won't really work if another group of the mesh is using the mesh ) ***
1703 // HACK TO SPEED THINGS UP...
1704 if(primitive->nIndices < (mesh.nVertices >> 2) && !primitive->type.indices32bit)
1707 glBegin(primitiveTypes[primitive->type.primitiveType]);
1710 IndexData indexData = primitive->data;
1711 MeshFeatures flags = mesh.flags;
1712 for(c = 0; c < primitive->nIndices; c++)
1714 short index = ((short *) indexData.indices)[c];
1715 if(flags.normals) glNormal3fv((float *)&mesh.normals[index]);
1716 if(flags.texCoords1) glTexCoord2fv((float *)&mesh.texCoords[index]);
1717 if(flags.colors) glColor4fv((float *)&mesh.colors[index]);
1718 glVertex3fv((float *)&mesh.vertices[index]);
1725 IndexData indexData = primitive->data;
1727 if(!display.display3D.collectingHits && glBindBufferARB && indexData)
1729 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indexData.buffer);
1730 glDrawElements(primitiveTypes[primitive->type.primitiveType], primitive->nIndices,
1731 primitive->type.indices32bit ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0);
1732 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
1735 glDrawElements(primitiveTypes[primitive->type.primitiveType], primitive->nIndices,
1736 primitive->type.indices32bit ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, indexData.indices);
1738 glDrawElements(primitiveTypes[primitive->type.primitiveType], primitive->nIndices,
1739 primitive->type.indices32bit ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, primitive->indices);
1744 void PushMatrix(Display display)
1746 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1750 void PopMatrix(Display display, bool setMatrix)
1752 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1756 void SetTransform(Display display, Matrix transMatrix, bool viewSpace, bool useCamera)
1758 Matrix matrix = transMatrix;
1759 Camera camera = useCamera ? display.display3D.camera : null;
1761 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1765 glScalef(1.0f, 1.0f, -1.0f);
1770 matrix.m[3][0] - camera.cPosition.x,
1771 matrix.m[3][1] - camera.cPosition.y,
1772 matrix.m[3][2] - camera.cPosition.z);
1784 glMultMatrixd(matrix.array);