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 static bool useSingleGLContext = false;
32 class DisplayData : struct
34 ColorAlpha * flippingBuffer;
35 int flipBufH, flipBufW;
42 class SystemData : struct
47 class SurfaceData : struct
54 float foreground[4], background[4], bitmapMult[4];
57 class MeshData : struct
66 class IndexData : struct
73 static int primitiveTypes[RenderPrimitiveType] =
75 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 OpenGLDisplayDriver : 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 display.ambient = Color { 50,50,50 };
182 printf("CocoaOpenGLDisplayDriver:CreateDisplay %p %s:%i\n", display.window, __FILE__, __LINE__);
186 bool DisplaySize(Display display, int width, int height)
190 DisplayData displayData = display.driverData;
191 SystemData systemData = display.displaySystem.driverData;
193 printf("CocoaOpenGLDisplayDriver:DisplaySize(%i,%i) %s:%i\n", width, height, __FILE__, __LINE__);
195 CocoaOpenGLMakeCurrentContext(display.window);
197 glViewport(0,0,width,height);
201 glOrtho(0,width,height,0,0.0,1.0);
203 display.width = width;
204 display.height = height;
206 if(!displayData.flippingBuffer || displayData.flipBufW < width || displayData.flipBufH < height)
208 displayData.flipBufW = width;
209 displayData.flipBufH = height;
210 displayData.flippingBuffer = renew displayData.flippingBuffer ColorAlpha [width * height];
212 if(displayData.flippingBuffer)
218 void DisplayPosition(Display display, int x, int y)
220 DisplayData displayData = display.driverData;
222 printf("CocoaOpenGLDisplayDriver:DisplayPosition(%i,%i) %s:%i\n", x, y, __FILE__, __LINE__);
226 printf("glGetError():%i\n", glGetError());
229 void SetPalette(Display display, ColorAlpha * palette, bool colorMatch)
231 printf("CocoaOpenGLDisplayDriver:SetPalette STUB! %s:%i\n", __FILE__, __LINE__);
234 void RestorePalette(Display display)
236 printf("CocoaOpenGLDisplayDriver:RestorePalette STUB! %s:%i\n", __FILE__, __LINE__);
239 void StartUpdate(Display display)
241 printf("CocoaOpenGLDisplayDriver:StartUpdate STUB! %s:%i\n", __FILE__, __LINE__);
244 void EndUpdate(Display display)
246 printf("CocoaOpenGLDisplayDriver:EndUpdate STUB! %s:%i\n", __FILE__, __LINE__);
249 void Scroll(Display display, Box scroll, int x, int y, Extent dirty)
251 printf("CocoaOpenGLDisplayDriver:Scroll STUB! %s:%i\n", __FILE__, __LINE__);
254 void Update(Display display, Box updateBox)
256 //CocoaOpenGLUpdate(display.window);
257 printf("CocoaOpenGLDisplayDriver:Update %s:%i\n", __FILE__, __LINE__);
260 void FreeBitmap(DisplaySystem displaySystem, Bitmap bitmap)
262 glDeleteTextures(1, (int *)&bitmap.driverData);
263 bitmap.driverData = 0;
265 bitmap.driver = class(LFBDisplayDriver);
267 printf("CocoaOpenGLDisplayDriver:FreeBitmap %s:%i\n", __FILE__, __LINE__);
270 bool AllocateBitmap(DisplaySystem displaySystem, Bitmap bitmap, int width, int height, int stride, PixelFormat format, bool allocatePalette)
276 uint w = pow2i(Min(width, 1024)), h = pow2i(Min(height, 1024));
278 printf("CocoaOpenGLDisplayDriver:AllocateBitmap %s:%i\n", __FILE__, __LINE__);
281 glGenTextures(1, &glBitmap);
283 glBindTexture(GL_TEXTURE_2D, glBitmap);
286 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
289 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
291 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
294 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
296 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
299 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
301 mipMap.Allocate(null, w, h, w, pixelFormatRGBA, false);
304 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipMap.picture);
307 bitmap.driverData = (void *)glBitmap;
308 bitmap.driver = displaySystem.driver;
317 bool MakeDDBitmap(DisplaySystem displaySystem, Bitmap bitmap, bool mipMaps)
320 SystemData systemData = displaySystem.driverData;
322 // Pre process the bitmap... First make it 32 bit
323 if(bitmap.Convert(null, pixelFormat888, null))
326 uint w = pow2i(Min(bitmap.width, 1024)), h = pow2i(Min(bitmap.height, 1024));
329 // Switch ARGB to RGBA
330 //if(bitmap.format != pixelFormatRGBA)
332 for(c=0; c<bitmap.size; c++)
335 ColorAlpha color = ((ColorAlpha *)bitmap.picture)[c];
336 ((ColorRGBA *)bitmap.picture)[c] = ColorRGBA { color.color.r, color.color.g, color.color.b, color.a };
339 bitmap.pixelFormat = pixelFormat888;
342 glGenTextures(1, &glBitmap);
346 int error = glGetError();
352 glBindTexture(GL_TEXTURE_2D, glBitmap);
354 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
357 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
359 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mipMaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
362 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
364 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
367 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
372 for(level = 0; result && (w > 1 || h > 1); level++, w >>= 1, h >>= 1)
375 if(bitmap.width != w || bitmap.height != h)
378 if(mipMap.Allocate(null, w, h, w, bitmap.pixelFormat, false))
380 Surface mipSurface = mipMap.GetSurface(0,0,null);
381 mipSurface.Filter(bitmap, 0,0,0,0, w, h, bitmap.width, bitmap.height);
396 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipMap.picture);
398 if((error = glGetError()))
409 bitmap.driver.FreeBitmap(bitmap.displaySystem, bitmap);
410 bitmap.driverData = (void *)glBitmap;
411 bitmap.driver = displaySystem.driver;
414 FreeBitmap(displaySystem, bitmap);
415 else if(systemData.loadingFont)
417 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
419 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
421 systemData.loadingFont = false;
425 printf("CocoaOpenGLDisplayDriver:MakeDDBitmap %i %s:%i\n", result, __FILE__, __LINE__);
429 void ReleaseSurface(Display display, Surface surface)
431 printf("CocoaOpenGLDisplayDriver:ReleaseSurface %s:%i\n", __FILE__, __LINE__);
433 glDisable(GL_SCISSOR_TEST);
435 delete surface.driverData;
436 surface.driverData = null;
439 bool GetBitmapSurface(DisplaySystem displaySystem, Surface surface, Bitmap bitmap, int x, int y, Box clip)
441 printf("CocoaOpenGLDisplayDriver:GetBitmapSurface STUB! %s:%i\n", __FILE__, __LINE__);
445 bool GetSurface(Display display, Surface surface, int x,int y, Box clip)
449 SurfaceData surfaceData = SurfaceData { };
450 surface.driverData = surfaceData;
452 printf("CocoaOpenGLDisplayDriver:GetSurface %p %s:%i\n", surfaceData, __FILE__, __LINE__);
457 glViewport(0,0,display.width,display.height);
461 printf("display:%i, %i\n", display.width, display.height);
462 glOrtho(0, display.width, display.height, 0, 0.0f, 1.0f);
465 surface.offset.x = x;
466 surface.offset.y = y;
467 surface.unclippedBox = surface.box = clip;
468 surfaceData.bitmapMult[0] = 1;
469 surfaceData.bitmapMult[1] = 1;
470 surfaceData.bitmapMult[2] = 1;
471 surfaceData.bitmapMult[3] = 1;
473 glEnable(GL_SCISSOR_TEST);
477 (display.height) -(y+clip.bottom)-1,
478 clip.right-clip.left+1,
479 clip.bottom-clip.top+1);
487 void Clip(Display display, Surface surface, Box clip)
491 printf("CocoaOpenGLDisplayDriver:Clip STUB! %s:%i\n", __FILE__, __LINE__);
496 box.Clip(surface.unclippedBox);
501 box = surface.box = surface.unclippedBox;
504 box.left += surface.offset.x;
505 box.top += surface.offset.y;
506 box.right+= surface.offset.x;
507 box.bottom += surface.offset.y;
510 box.left,display.height - box.bottom - 1,
511 box.right-box.left+1, box.bottom-box.top+1);
514 bool GrabScreen(Display display, Bitmap bitmap, int x, int y, unsigned int w, unsigned int h)
517 printf("CocoaOpenGLDisplayDriver:GrabScreen STUB! %s:%i\n", __FILE__, __LINE__);
521 void SetForeground(Display display, Surface surface, ColorAlpha color)
523 SurfaceData surfaceData = surface.driverData;
525 printf("CocoaOpenGLDisplayDriver:SetForeground(%i,%i,%i,%i) %s:%i\n", color.color.r, color.color.g, color.color.b, color.a, __FILE__, __LINE__);
527 surfaceData.foreground[0] = color.color.r/255.0f;
528 surfaceData.foreground[1] = color.color.g/255.0f;
529 surfaceData.foreground[2] = color.color.b/255.0f;
530 surfaceData.foreground[3] = color.a/255.0f;
533 void SetBackground(Display display, Surface surface, ColorAlpha color)
535 SurfaceData surfaceData = surface.driverData;
537 printf("CocoaOpenGLDisplayDriver:SetBackground(%i,%i,%i,%i) %s:%i\n", color.color.r, color.color.g, color.color.b, color.a, __FILE__, __LINE__);
539 surfaceData.background[0] = color.color.r/255.0f;
540 surfaceData.background[1] = color.color.g/255.0f;
541 surfaceData.background[2] = color.color.b/255.0f;
542 surfaceData.background[3] = color.a/255.0f;
545 void SetBlitTint(Display display, Surface surface, ColorAlpha color)
547 SurfaceData surfaceData = surface.driverData;
549 printf("CocoaOpenGLDisplayDriver:SetBlitTint(%i,%i,%i,%i) %s:%i\n", color.color.r, color.color.g, color.color.b, color.a, __FILE__, __LINE__);
551 surfaceData.bitmapMult[0] = color.color.r/255.0f;
552 surfaceData.bitmapMult[1] = color.color.g/255.0f;
553 surfaceData.bitmapMult[2] = color.color.b/255.0f;
554 surfaceData.bitmapMult[3] = color.a/255.0f;
558 ColorAlpha GetPixel(Display display, Surface surface,int x,int y)
560 printf("CocoaOpenGLDisplayDriver:GetPixel STUB! %s:%i\n", __FILE__, __LINE__);
564 void PutPixel(Display display, Surface surface,int x,int y)
566 printf("CocoaOpenGLDisplayDriver:PutPixel %s:%i\n", __FILE__, __LINE__);
570 glVertex2f(x+surface.offset.x + 0.5f, y+surface.offset.y + 0.5f);
575 void DrawLine(Display display, Surface surface, int x1, int y1, int x2, int y2)
577 SurfaceData surfaceData = surface.driverData;
579 printf("CocoaOpenGLDisplayDriver:DrawLine %s:%i\n", __FILE__, __LINE__);
580 printf("--DrawLine(x1:%i, y1:%i, x2:%i, y2:%i)\n", x1, y1, x2, y2);
582 glColor4fv(surfaceData.foreground);
585 glVertex2f(x1+surface.offset.x + 0.5f, y1+surface.offset.y + 0.5f);
586 glVertex2f(x2+surface.offset.x + 0.5f, y2+surface.offset.y + 0.5f);
592 void Rectangle(Display display, Surface surface,int x1,int y1,int x2,int y2)
594 printf("CocoaOpenGLDisplayDriver:Rectangle %s:%i\n", __FILE__, __LINE__);
595 printf("--Rectangle(x1:%i, y1:%i, x2:%i, y2:%i)\n", x1, y1, x2, y2);
596 glBegin(GL_LINE_LOOP);
598 glVertex2f(x1+surface.offset.x + 0.5f, y1+surface.offset.y + 0.5f);
599 glVertex2f(x1+surface.offset.x + 0.5f, y2+surface.offset.y + 0.5f);
600 glVertex2f(x2+surface.offset.x + 0.5f, y2+surface.offset.y + 0.5f);
601 glVertex2f(x2+surface.offset.x + 0.5f, y1+surface.offset.y + 0.5f);
607 void Area(Display display, Surface surface,int x1,int y1,int x2,int y2)
609 SurfaceData surfaceData = surface.driverData;
611 printf("CocoaOpenGLDisplayDriver:Area %s:%i\n", __FILE__, __LINE__);
614 glColor4fv(surfaceData.background);
616 glRecti(x1+surface.offset.x, y1+surface.offset.y,
617 x2+surface.offset.x + 1, y2+surface.offset.y + 1);
621 void Clear(Display display, Surface surface, ClearType type)
623 DisplayData displayData = display.driverData;
624 SurfaceData surfaceData = surface.driverData;
626 if(type != depthBuffer)
628 glClearColor(surfaceData.background[0], surfaceData.background[1], surfaceData.background[2], surfaceData.background[3]);
631 if(type != colorBuffer && !displayData.depthWrite)
633 glDepthMask((byte)bool::true);
636 glClear(((type != depthBuffer) ? GL_COLOR_BUFFER_BIT : 0) |
637 ((type != colorBuffer) ? GL_DEPTH_BUFFER_BIT : 0));
640 if(type != colorBuffer && !displayData.depthWrite)
642 glDepthMask((byte)bool::false);
645 if(type != depthBuffer)
647 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
650 if(type != colorBuffer)
652 glDepthMask((byte)bool::true);
656 glClear(((type != depthBuffer) ? GL_COLOR_BUFFER_BIT : 0) |
657 ((type != colorBuffer) ? GL_DEPTH_BUFFER_BIT : 0));
660 if(type != colorBuffer)
662 glDepthMask((byte)bool::false);
665 printf("CocoaOpenGLDisplayDriver:Clear %s:%i\n", __FILE__, __LINE__);
668 bool ConvertBitmap(DisplaySystem displaySystem, Bitmap bitmap, PixelFormat format, ColorAlpha * palette)
672 printf("CocoaOpenGLDisplayDriver:ConvertBitmap %s:%i\n", __FILE__, __LINE__);
677 void Blit(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h)
679 printf("CocoaOpenGLDisplayDriver:Blit %s:%i\n", __FILE__, __LINE__);
680 printf("--BLIT(dx:%i, dy:%i, sx:%i, sy:%i, w:%i, h:%i)\n", dx, dy, sx, sy, w, h);
682 glEnable(GL_TEXTURE_2D);
683 glBindTexture(GL_TEXTURE_2D, (uint)bitmap.driverData);
688 glTexCoord2f((float)sx/ bitmap.width, (float)(sy-h)/ bitmap.height);
689 glVertex2i(dx+surface.offset.x, dy+surface.offset.y);
690 glTexCoord2f((float)(sx+w) / bitmap.width, (float)(sy-h)/ bitmap.height);
691 glVertex2i(dx+w+surface.offset.x, dy+surface.offset.y);
692 glTexCoord2f((float)(sx+w)/ bitmap.width, (float)sy/ bitmap.height);
693 glVertex2i(dx+w+surface.offset.x, dy-h+surface.offset.y);
694 glTexCoord2f((float)sx / bitmap.width, (float)sy/ bitmap.height);
695 glVertex2i(dx+surface.offset.x, dy-h+surface.offset.y);
699 glTexCoord2f((float)sx / bitmap.width, (float)sy/ bitmap.height);
700 glVertex2f((float)dx+surface.offset.x, (float)dy+surface.offset.y);
701 glTexCoord2f((float)(sx+w)/ bitmap.width, (float)sy/ bitmap.height);
702 glVertex2f((float)dx+w+surface.offset.x, (float)dy+surface.offset.y);
703 glTexCoord2f((float)(sx+w) / bitmap.width, (float)(sy+h)/ bitmap.height);
704 glVertex2f((float)dx+w+surface.offset.x, (float)dy+h+surface.offset.y);
705 glTexCoord2f((float)sx/ bitmap.width, (float)(sy+h)/ bitmap.height);
706 glVertex2f((float)dx+surface.offset.x, (float)dy+h+surface.offset.y);
712 void Stretch(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
714 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
715 glEnable(GL_TEXTURE_2D);
717 glBindTexture(GL_TEXTURE_2D, (uint)bitmap.driverData);
725 glTexCoord2f((float)(sx)/ bitmap.width, (float)(sy+sh)/ bitmap.height);
727 glVertex2i(dx+surface.offset.x, dy+surface.offset.y);
730 glTexCoord2f((float)(sx+sw) / bitmap.width, (float)(sy+sh)/ bitmap.height);
732 glVertex2i(dx+w+surface.offset.x, dy+surface.offset.y);
735 glTexCoord2f((float)(sx+sw)/ bitmap.width, (float)(sy)/ bitmap.height);
737 glVertex2i(dx+w+surface.offset.x, dy-h+surface.offset.y);
740 glTexCoord2f((float)(sx) / bitmap.width, (float)(sy)/ bitmap.height);
742 glVertex2i(dx+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+surface.offset.y);
752 glTexCoord2f((float)(sx+sw)/ bitmap.width, (float)(sy)/ bitmap.height);
754 glVertex2i(dx+w+surface.offset.x, dy+surface.offset.y);
757 glTexCoord2f((float)(sx+sw) / bitmap.width, (float)(sy+sh)/ bitmap.height);
759 glVertex2i(dx+w+surface.offset.x, dy+h+surface.offset.y);
762 glTexCoord2f((float)(sx)/ bitmap.width, (float)(sy+sh)/ bitmap.height);
764 glVertex2i(dx+surface.offset.x, dy+h+surface.offset.y);
771 glDisable(GL_TEXTURE_2D);
775 void Filter(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
777 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
778 Stretch(display, surface, bitmap, dx, dy, sx, sy, w, h, sw, sh);
781 void StretchDI(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
783 float s2dw,s2dh,d2sw,d2sh;
784 bool flipX = false, flipY = false;
786 printf("CocoaOpenGLDisplayDriver: %s:%i\n", __FILE__, __LINE__);
787 if(Sgn(w) != Sgn(sw))
793 if(Sgn(h) != Sgn(sh))
805 //Clip against the edges of the source
808 dx+=(int)((0-sx) * s2dw);
809 w-=(int)((0-sx) * s2dw);
815 dy+=(int)((0-sy) * s2dh);
816 h-=(int)((0-sy) * s2dh);
821 if(sx+sw>bitmap.width-1)
823 w-=(int)((sx+sw-(bitmap.width-1)-1)*s2dw);
824 sw-=sx+sw-(bitmap.width-1)-1;
826 if(sy+sh>(bitmap.height-1))
828 h-=(int)((sy+sh-(bitmap.height-1)-1)*s2dh);
829 sh-=sy+sh-(bitmap.height-1)-1;
831 //Clip against the edges of the surfaceination
832 if(dx<surface.box.left)
835 sx+=(int)((surface.box.left-dx)*d2sw);
836 sw-=(int)((surface.box.left-dx)*d2sw);
837 w-=surface.box.left-dx;
840 if(dy<surface.box.top)
842 sy+=(int)((surface.box.top-dy)*d2sh);
843 sh-=(int)((surface.box.top-dy)*d2sh);
844 h-=surface.box.top-dy;
847 if(dx+w>surface.box.right)
849 //if(flip) sx+=(int)((dx+w-surface.box.right-1)*d2sw);
850 sw-=(int)((dx+w-surface.box.right-1)*d2sw);
851 w-=dx+w-surface.box.right-1;
853 if(dy+h>surface.box.bottom)
855 sh-=(int)((dy+h-surface.box.bottom-1)*d2sh);
856 h-=dy+h-surface.box.bottom-1;
858 if((w<=0)||(h<=0)||(sw<=0)||(sh<=0)) return;
860 dx += surface.offset.x;
861 dy += surface.offset.y;
863 if(bitmap.pixelFormat == pixelFormat888 && !bitmap.paletteShades)
865 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
867 glPixelStorei(GL_UNPACK_ROW_LENGTH, bitmap.stride);
869 glPixelStorei(GL_UNPACK_SKIP_PIXELS, sx);
871 glPixelStorei(GL_UNPACK_SKIP_ROWS, sy);
873 glRasterPos2d(dx,dy);
875 //glPixelZoom(flipX ? -s2dw : s2dw, flipY ? s2dh : -s2dh);
877 glPixelZoom(s2dw, -s2dh);
879 glDrawPixels(sw,sh,GL_BGRA_EXT,GL_UNSIGNED_BYTE, bitmap.picture);
881 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
883 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
888 void BlitDI(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h)
890 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
891 //Clip against the edges of the source
904 if(sx+w>bitmap.width-1)
905 w-=sx+w-(bitmap.width-1)-1;
906 if(sy+h>bitmap.height-1)
907 h-=sy+h-(bitmap.height-1)-1;
908 //Clip against the edges of the surfaceination
909 if(dx<surface.box.left)
912 sx+=surface.box.left-dx;
913 w-=surface.box.left-dx;
916 if(dy<surface.box.top)
918 sy+=surface.box.top-dy;
919 h-=surface.box.top-dy;
922 if(dx+w>surface.box.right)
924 //if(flip) sx+=dx+w-surface.box.right-1;
925 w-=dx+w-surface.box.right-1;
927 if(dy+h>surface.box.bottom)
928 h-=dy+h-surface.box.bottom-1;
932 dx += surface.offset.x;
933 dy += surface.offset.y;
935 if(bitmap.pixelFormat == pixelFormat888 && !bitmap.paletteShades)
937 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
939 glPixelStorei(GL_UNPACK_ROW_LENGTH, bitmap.stride);
941 glPixelStorei(GL_UNPACK_SKIP_PIXELS, sx);
943 glPixelStorei(GL_UNPACK_SKIP_ROWS, sy);
945 glRasterPos2d(dx,dy);
949 glDrawPixels(w,h,GL_BGRA_EXT,GL_UNSIGNED_BYTE, bitmap.picture);
951 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
953 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
958 void FilterDI(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
960 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
961 StretchDI(display, surface, bitmap, dx, dy, sx, sy, w, h, sw, sh);
964 void UnloadFont(DisplaySystem displaySystem, Font font)
966 printf("CocoaOpenGLDisplayDriver:UnloadFont %s:%i\n", __FILE__, __LINE__);
967 LFBDisplayDriver::UnloadFont(displaySystem, font);
970 Font LoadFont(DisplaySystem displaySystem, char * faceName, float size, FontFlags flags)
972 Font font = LFBDisplayDriver::LoadFont(displaySystem, faceName, size, flags);
974 printf("CocoaOpenGLDisplayDriver:LoadFont(%s):%p %s:%i\n", faceName, font, __FILE__, __LINE__);
979 void FontExtent(DisplaySystem displaySystem, Font font, char * text, int len, int * width, int * height)
981 printf("CocoaOpenGLDisplayDriver:FontExtent() %s:%i\n", __FILE__, __LINE__);
982 LFBDisplayDriver::FontExtent(displaySystem, font, text, len, width, height);
985 void WriteText(Display display, Surface surface, int x, int y, char * text, int len)
987 SurfaceData surfaceData = surface.driverData;
988 SystemData systemData = display.displaySystem.driverData;
990 printf("CocoaOpenGLDisplayDriver:WriteText %s:%i\n", __FILE__, __LINE__);
992 systemData.loadingFont = true;
994 if(surface.textOpacity)
997 FontExtent(display.displaySystem, surface.font, text, len, &w, &h);
998 Area(display, surface,x,y,x+w-1,y+h-1);
1001 surfaceData.writingText = true;
1003 glEnable(GL_TEXTURE_2D);
1005 glColor4fv(surfaceData.foreground);
1008 LFBDisplayDriver::WriteText(display, surface, x, y, text, len);
1009 surfaceData.writingText = false;
1010 systemData.loadingFont = false;
1012 glDisable(GL_TEXTURE_2D);
1016 void TextFont(Display display, Surface surface, Font font)
1018 LFBDisplayDriver::TextFont(display, surface, font);
1019 printf("CocoaOpenGLDisplayDriver:TextFont %s:%i\n", __FILE__, __LINE__);
1022 void TextOpacity(Display display, Surface surface, bool opaque)
1024 SurfaceData surfaceData = surface.driverData;
1025 surfaceData.opaqueText = opaque;
1026 printf("CocoaOpenGLDisplayDriver:TextOpacity(%i) %s:%i\n", opaque, __FILE__, __LINE__);
1029 void TextExtent(Display display, Surface surface, char * text, int len, int * width, int * height)
1031 SurfaceData surfaceData = surface.driverData;
1032 SystemData systemData = display.displaySystem.driverData;
1033 systemData.loadingFont = true;
1034 FontExtent(display.displaySystem, surfaceData.font, text, len, width, height);
1035 systemData.loadingFont = false;
1037 printf("CocoaOpenGLDisplayDriver:TextExtent STUB! %s:%i\n", __FILE__, __LINE__);
1040 void DrawingChar(Display display, Surface surface, char character)
1042 printf("CocoaOpenGLDisplayDriver:DrawingChar STUB! %s:%i\n", __FILE__, __LINE__);
1046 void LineStipple(Display display, Surface surface, uint32 stipple)
1048 printf("CocoaOpenGLDisplayDriver:LineStipple %s:%i\n", __FILE__, __LINE__);
1051 glLineStipple(1, (uint16)stipple);
1053 glEnable(GL_LINE_STIPPLE);
1058 glDisable(GL_LINE_STIPPLE);
1061 printf("glGetError():%i\n", glGetError());
1064 void SetRenderState(Display display, RenderState state, uint value)
1066 printf("CocoaOpenGLDisplayDriver:SetRenderState STUB! %s:%i\n", __FILE__, __LINE__);
1071 glEnable(GL_MULTISAMPLE_ARB);
1073 glDisable(GL_MULTISAMPLE_ARB);
1077 glPolygonMode(GL_FRONT_AND_BACK, ((FillModeValue)value == solid) ? GL_FILL : GL_LINE);
1081 if(value) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
1085 if(value) glDepthMask((byte)bool::true); else glDepthMask((byte)bool::false);
1090 float color[4] = { ((Color)value).r/255.0f, ((Color)value).g/255.0f, ((Color)value).b/255.0f, 1.0f };
1091 glFogfv(GL_FOG_COLOR, (float *)&color);
1096 glFogf(GL_FOG_DENSITY, *(float *)(void *)&value);
1100 if(value) glEnable(GL_BLEND); else glDisable(GL_BLEND);
1105 float ambient[4] = { ((Color)value).r/255.0f, ((Color)value).g/255.0f, ((Color)value).b/255.0f, 1.0f };
1106 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
1112 if(value) glColorMask(1,1,1,1); else glColorMask(1,1,1,0);
1123 void SetLight(Display display, int id, Light light)
1125 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1128 Object lightObject = light.lightObject;
1129 float position[4] = { 0, 0, 0, 0 };
1130 float color[4] = { 0, 0, 0, 1 };
1132 glEnable(GL_LIGHT0 + id);
1135 if(!light.multiplier) light.multiplier = 1.0f;
1137 color[0] = light.diffuse.r * light.multiplier;
1138 color[1] = light.diffuse.g * light.multiplier;
1139 color[2] = light.diffuse.b * light.multiplier;
1140 glLightfv(GL_LIGHT0 + id, GL_DIFFUSE, color);
1142 color[0] = light.ambient.r * light.multiplier;
1143 color[1] = light.ambient.g * light.multiplier;
1144 color[2] = light.ambient.b * light.multiplier;
1145 glLightfv(GL_LIGHT0 + id, GL_AMBIENT, color);
1146 color[0] = light.specular.r * light.multiplier;
1147 color[1] = light.specular.g * light.multiplier;
1148 color[2] = light.specular.b * light.multiplier;
1149 glLightfv(GL_LIGHT0 + id, GL_SPECULAR,color);
1153 Vector3D positionVector;
1154 if(light.flags.spot)
1156 if(lightObject.flags.root || !lightObject.parent)
1158 positionVector = lightObject.transform.position;
1159 positionVector.Subtract(positionVector, display.display3D.camera.cPosition);
1163 positionVector.MultMatrix(lightObject.transform.position, lightObject.parent.matrix);
1164 if(display.display3D.camera)
1165 positionVector.Subtract(positionVector, display.display3D.camera.cPosition);
1171 if(!light.direction.x && !light.direction.y && !light.direction.z)
1173 Vector3Df vector { 0,0,-1 };
1175 mat.RotationQuaternion(light.orientation);
1176 positionVector.MultMatrixf(vector, mat);
1180 positionVector = light.direction;
1185 position[0] = (float)positionVector.x;
1186 position[1] = (float)positionVector.y;
1187 position[2] = (float)positionVector.z;
1189 glLightfv(GL_LIGHT0 + id, GL_POSITION, position);
1192 if(light.flags.attenuation)
1194 glLightf(GL_LIGHT0 + id, GL_CONSTANT_ATTENUATION, light.Kc);
1196 glLightf(GL_LIGHT0 + id, GL_LINEAR_ATTENUATION, light.Kl);
1198 glLightf(GL_LIGHT0 + id, GL_QUADRATIC_ATTENUATION, light.Kq);
1202 if(light.flags.spot)
1205 #define MAXLIGHT 0.9
1206 float direction[4] = { (float)light.direction.x, (float)light.direction.y, (float)light.direction.z, 1 };
1207 // Figure out exponent out of the hot spot
1208 exponent = (float)(log(MAXLIGHT) / log(cos((light.hotSpot / 2))));
1210 glLightfv(GL_LIGHT0 + id, GL_SPOT_DIRECTION, direction);
1212 glLightf(GL_LIGHT0 + id, GL_SPOT_CUTOFF, (float)(light.fallOff / 2));
1214 glLightf(GL_LIGHT0 + id, GL_SPOT_EXPONENT, exponent);
1220 Vector3Df vector { 0,0,-1 };
1221 Vector3Df direction;
1224 mat.RotationQuaternion(light.orientation);
1225 direction.MultMatrix(vector, mat);
1227 position[0] = direction.x;
1228 position[1] = direction.y;
1229 position[2] = direction.z;
1231 glLightfv(GL_LIGHT0 + id, GL_POSITION, position);
1236 glDisable(GL_LIGHT0 + id);
1240 void SetCamera(Display display, Surface surface, Camera camera)
1242 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1245 int left = surface.box.left + surface.offset.x;
1246 int top = surface.box.top + surface.offset.y;
1247 int right = surface.box.right + surface.offset.x;
1248 int bottom = surface.box.bottom + surface.offset.y;
1249 float origX = surface.offset.x + camera.origin.x;
1250 float origY = surface.offset.y + camera.origin.y;
1252 int y = display.height - bottom - 1;
1253 int w = right - left + 1;
1254 int h = bottom - top + 1;
1257 glViewport(x, y, w, h);
1259 // *** Projection Matrix ***
1260 if(!display.display3D.camera)
1263 glMatrixMode(GL_PROJECTION);
1264 if(display.display3D.collectingHits)
1266 float pickX = display.display3D.pickX + surface.offset.x;
1267 float pickY = display.height - (display.display3D.pickY + surface.offset.y) - 1;
1271 w / display.display3D.pickWidth, 0, 0, 0,
1272 0, h / display.display3D.pickHeight, 0, 0,
1274 (w + 2.0f * (x - pickX)) / display.display3D.pickWidth,
1275 (h + 2.0f * (y - pickY)) / display.display3D.pickHeight, 0, 1
1278 glLoadMatrixd(pickMatrix.array);
1283 (left - origX) * camera.zMin / camera.focalX,
1284 (right - origX) * camera.zMin / camera.focalX,
1285 (bottom - origY) * camera.zMin / camera.focalY,
1286 (top - origY) * camera.zMin / camera.focalY,
1287 camera.zMin, camera.zMax);
1289 glDisable(GL_BLEND);
1291 // *** Z Inverted Identity Matrix ***
1292 glMatrixMode(GL_MODELVIEW);
1293 if(!display.display3D.camera)
1297 glScalef(1.0f, 1.0f, -1.0f);
1299 // *** View Matrix ***
1300 glMultMatrixd(camera.viewMatrix.array);
1305 glEnable(GL_DEPTH_TEST);
1306 glEnable(GL_LIGHTING);
1307 glShadeModel(GL_SMOOTH);
1308 glDepthMask((byte)bool::true);
1310 glEnable(GL_MULTISAMPLE_ARB);
1312 else if(display.display3D.camera)
1314 glViewport(0,0,display.width,display.height);
1316 glDisable(GL_CULL_FACE);
1317 glDisable(GL_DEPTH_TEST);
1318 glDisable(GL_LIGHTING);
1320 glDisable(GL_TEXTURE_2D);
1321 glShadeModel(GL_FLAT);
1323 glDisable(GL_MULTISAMPLE_ARB);
1325 // *** Restore 2D MODELVIEW Matrix ***
1328 // *** Restore 2D PROJECTION Matrix ***
1329 glMatrixMode(GL_PROJECTION);
1334 glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
1335 printf("glGetError():%i\n", glGetError());
1338 void ApplyMaterial(Display display, Material material, Mesh mesh)
1340 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1342 if(material.flags.doubleSided)
1344 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, !material.flags.singleSideLight);
1345 glDisable(GL_CULL_FACE);
1349 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, bool::false);
1350 glEnable(GL_CULL_FACE);
1354 if(material.flags.noFog)
1360 if(material.baseMap && mesh.texCoords)
1362 Bitmap map = material.baseMap;
1363 glEnable(GL_TEXTURE_2D);
1364 glBindTexture(GL_TEXTURE_2D, (uint)map.driverData);
1366 if(material.flags.tile)
1368 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1369 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1373 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1374 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1378 glDisable(GL_TEXTURE_2D);
1380 if(mesh.flags.colors)
1382 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
1383 glEnable(GL_COLOR_MATERIAL);
1387 glDisable(GL_COLOR_MATERIAL);
1389 float color[4] = { material.diffuse.r, material.diffuse.g, material.diffuse.b, material.opacity };
1390 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
1393 float color[4] = { material.ambient.r, material.ambient.g, material.ambient.b, 0 };
1394 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color);
1398 float color[4] = { material.specular.r, material.specular.g, material.specular.b, 0 };
1399 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color);
1402 float color[4] = { material.emissive.r, material.emissive.g, material.emissive.b, 0 };
1403 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color);
1406 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &material.power);
1409 void FreeMesh(DisplaySystem displaySystem, Mesh mesh)
1411 MeshData meshData = mesh.data;
1412 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1415 if(!mesh.flags.vertices)
1417 if(meshData.vertices)
1419 glDeleteBuffersARB(1, &meshData.vertices);
1420 meshData.vertices = 0;
1422 delete mesh.vertices;
1424 if(!mesh.flags.normals)
1426 if(meshData.normals)
1428 glDeleteBuffersARB(1, &meshData.normals);
1429 meshData.normals = 0;
1431 delete mesh.normals;
1433 if(!mesh.flags.texCoords1)
1435 if(meshData.texCoords)
1437 glDeleteBuffersARB(1, &meshData.texCoords);
1438 meshData.texCoords = 0;
1440 delete mesh.texCoords;
1442 if(!mesh.flags.texCoords2)
1444 if(meshData.texCoords2)
1446 glDeleteBuffersARB(1, &meshData.texCoords2);
1447 meshData.texCoords2 = 0;
1450 if(!mesh.flags.colors)
1454 glDeleteBuffersARB(1, &meshData.colors);
1455 meshData.colors = 0;
1466 bool AllocateMesh(DisplaySystem displaySystem, Mesh mesh)
1468 bool result = false;
1469 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1472 mesh.data = MeshData { };
1476 MeshData meshData = mesh.data;
1478 if(mesh.flags.vertices && !meshData.vertices && !mesh.vertices)
1480 mesh.vertices = mesh.flags.doubleVertices ? (Vector3Df *)new Vector3D[mesh.nVertices] : new Vector3Df[mesh.nVertices];
1482 glGenBuffersARB(1, &meshData.vertices);
1484 if(mesh.flags.normals && !meshData.normals && !mesh.normals)
1487 glGenBuffersARB( 1, &meshData.normals);
1488 mesh.normals = mesh.flags.doubleNormals ? (Vector3Df *)new Vector3D[mesh.nVertices] : new Vector3Df[mesh.nVertices];
1490 if(mesh.flags.texCoords1 && !meshData.texCoords && !mesh.texCoords)
1493 glGenBuffersARB( 1, &meshData.texCoords);
1494 mesh.texCoords = new Pointf[mesh.nVertices];
1496 if(mesh.flags.colors && !meshData.colors && !mesh.colors)
1499 glGenBuffersARB( 1, &meshData.colors);
1500 mesh.colors = new ColorRGBAf[mesh.nVertices];
1507 void UnlockMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags)
1509 MeshData meshData = mesh.data;
1510 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1512 if(!flags) flags = mesh.flags;
1516 if(!(flags.vertices) || meshData.vertices)
1518 glBindBufferARB( GL_ARRAY_BUFFER_ARB, meshData.vertices);
1519 glBufferDataARB( GL_ARRAY_BUFFER_ARB, mesh.nVertices * (mesh.flags.doubleVertices ? sizeof(Vector3D) : sizeof(Vector3Df)), mesh.vertices, GL_STATIC_DRAW_ARB );
1522 if(!(flags.normals) || meshData.normals)
1524 glBindBufferARB( GL_ARRAY_BUFFER_ARB, meshData.normals);
1525 glBufferDataARB( GL_ARRAY_BUFFER_ARB, mesh.nVertices * (mesh.flags.doubleNormals ? sizeof(Vector3D) : sizeof(Vector3Df)), mesh.normals, GL_STATIC_DRAW_ARB );
1528 if(!(flags.texCoords1) || meshData.texCoords)
1530 glBindBufferARB( GL_ARRAY_BUFFER_ARB, meshData.texCoords);
1531 glBufferDataARB( GL_ARRAY_BUFFER_ARB, mesh.nVertices * sizeof(Pointf), mesh.texCoords, GL_STATIC_DRAW_ARB );
1534 if(!(flags.colors) || meshData.colors)
1536 glBindBufferARB( GL_ARRAY_BUFFER_ARB, meshData.colors);
1537 glBufferDataARB( GL_ARRAY_BUFFER_ARB, mesh.nVertices * sizeof(ColorRGBAf), mesh.colors, GL_STATIC_DRAW_ARB );
1540 glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0);
1544 bool LockMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags)
1547 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1551 void FreeIndices(DisplaySystem displaySystem, IndexData indexData)
1553 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1557 if(indexData.buffer)
1558 glDeleteBuffersARB(1, &indexData.buffer);
1559 delete indexData.indices;
1564 void * AllocateIndices(DisplaySystem displaySystem, int nIndices, bool indices32bit)
1566 IndexData indexData = IndexData { };
1567 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1570 indexData.indices = (void *)(indices32bit ? new uint32[nIndices] : new uint16[nIndices]);
1572 glGenBuffersARB( 1, &indexData.buffer);
1573 indexData.nIndices = nIndices;
1578 void UnlockIndices(DisplaySystem displaySystem, IndexData indexData, bool indices32bit, int nIndices)
1580 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1583 glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, indexData.buffer);
1584 glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, nIndices * (indices32bit ? sizeof(uint32) : sizeof(uint16)),
1585 indexData.indices, GL_STATIC_DRAW_ARB);
1586 glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
1590 uint16 * LockIndices(DisplaySystem displaySystem, IndexData indexData)
1592 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1594 return indexData.indices;
1597 void SelectMesh(Display display, Mesh mesh)
1599 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1601 if(display.display3D.mesh && glUnlockArraysEXT)
1602 glUnlockArraysEXT();
1606 DisplayData displayData = display.driverData;
1607 Mesh meshData = mesh.data;
1609 // *** Vertex Stream ***
1610 glEnableClientState(GL_VERTEX_ARRAY);
1611 if(!display.display3D.collectingHits && meshData)
1614 glBindBufferARB(GL_ARRAY_BUFFER_ARB, (long)meshData.vertices);
1615 glVertexPointer(3, mesh.flags.doubleVertices ? GL_DOUBLE : GL_FLOAT, 0, glBindBufferARB ? null : mesh.vertices);
1617 // *** Normals Stream ***
1620 glEnableClientState(GL_NORMAL_ARRAY);
1622 glBindBufferARB(GL_ARRAY_BUFFER_ARB, (long)meshData.normals);
1623 glNormalPointer(mesh.flags.doubleNormals ? GL_DOUBLE : GL_FLOAT, 0, glBindBufferARB ? null : mesh.normals);
1627 glDisableClientState(GL_NORMAL_ARRAY);
1630 // *** Texture Coordinates Stream ***
1633 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1635 glBindBufferARB( GL_ARRAY_BUFFER_ARB, (long)meshData.texCoords);
1636 glTexCoordPointer(2, GL_FLOAT, 0, glBindBufferARB ? null : mesh.texCoords);
1640 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1643 // *** Color Stream ***
1646 glEnableClientState(GL_COLOR_ARRAY);
1648 glBindBufferARB( GL_ARRAY_BUFFER_ARB, (long)meshData.colors);
1649 glColorPointer(4, GL_FLOAT, 0, glBindBufferARB ? null : mesh.colors);
1653 glDisableClientState(GL_COLOR_ARRAY);
1659 glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0);
1660 glVertexPointer(3,mesh.flags.doubleVertices ? GL_DOUBLE : GL_FLOAT,0,mesh.vertices);
1661 if(mesh.normals && !display.display3D.collectingHits)
1663 glEnableClientState(GL_NORMAL_ARRAY);
1664 glNormalPointer(mesh.flags.doubleNormals ? GL_DOUBLE : GL_FLOAT, 0, mesh.normals);
1667 glDisableClientState(GL_NORMAL_ARRAY);
1668 if(mesh.texCoords && !display.display3D.collectingHits)
1670 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1671 glTexCoordPointer(2, GL_FLOAT, 0, mesh.texCoords);
1674 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1675 if(mesh.colors && !display.display3D.collectingHits)
1677 glEnableClientState(GL_COLOR_ARRAY);
1678 glColorPointer(4, GL_FLOAT, 0, mesh.colors);
1681 glDisableClientState(GL_COLOR_ARRAY);
1684 if(glLockArraysEXT) glLockArraysEXT(0, mesh.nVertices);
1686 else if(glBindBufferARB)
1687 glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
1690 void DrawPrimitives(Display display, PrimitiveSingle * primitive, Mesh mesh)
1692 DisplayData displayData = display.driverData;
1693 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1695 if(primitive->type.vertexRange)
1696 glDrawArrays(primitiveTypes[primitive->type.primitiveType], primitive->first, primitive->nVertices);
1699 // *** Hoping the data won't be uploaded at all (Won't really work if another group of the mesh is using the mesh ) ***
1700 // HACK TO SPEED THINGS UP...
1701 if(primitive->nIndices < (mesh.nVertices >> 2) && !primitive->type.indices32bit)
1704 glBegin(primitiveTypes[primitive->type.primitiveType]);
1707 IndexData indexData = primitive->data;
1708 MeshFeatures flags = mesh.flags;
1709 for(c = 0; c < primitive->nIndices; c++)
1711 short index = ((short *) indexData.indices)[c];
1712 if(flags.normals) glNormal3fv((float *)&mesh.normals[index]);
1713 if(flags.texCoords1) glTexCoord2fv((float *)&mesh.texCoords[index]);
1714 if(flags.colors) glColor4fv((float *)&mesh.colors[index]);
1715 glVertex3fv((float *)&mesh.vertices[index]);
1722 IndexData indexData = primitive->data;
1724 if(!display.display3D.collectingHits && glBindBufferARB && indexData)
1726 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indexData.buffer);
1727 glDrawElements(primitiveTypes[primitive->type.primitiveType], primitive->nIndices,
1728 primitive->type.indices32bit ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0);
1729 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
1732 glDrawElements(primitiveTypes[primitive->type.primitiveType], primitive->nIndices,
1733 primitive->type.indices32bit ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, indexData.indices);
1735 glDrawElements(primitiveTypes[primitive->type.primitiveType], primitive->nIndices,
1736 primitive->type.indices32bit ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, primitive->indices);
1741 void PushMatrix(Display display)
1743 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1747 void PopMatrix(Display display, bool setMatrix)
1749 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1753 void SetTransform(Display display, Matrix transMatrix, bool viewSpace, bool useCamera)
1755 Matrix matrix = transMatrix;
1756 Camera camera = useCamera ? display.display3D.camera : null;
1758 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1762 glScalef(1.0f, 1.0f, -1.0f);
1767 matrix.m[3][0] - camera.cPosition.x,
1768 matrix.m[3][1] - camera.cPosition.y,
1769 matrix.m[3][2] - camera.cPosition.z);
1781 glMultMatrixd(matrix.array);
1785 public void UseSingleGLContext(bool useSingle)
1787 printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__);
1788 useSingleGLContext = useSingle;