2003/09/13 05:08:58
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:34:27 +0000 (07:34 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:34:27 +0000 (07:34 +0000)
darcs-hash:20040130073427-2ba56-8be350bcc856b491a520dad0863a741619e209b0.gz

src/org/xwt/plat/Darwin.cc
src/org/xwt/plat/OpenGL.cc

index 716719f..b923803 100644 (file)
@@ -9,6 +9,8 @@
 
 #define __private_extern__
 #include <mach-o/dyld.h>
+//#include <objc/objc-runtime.h>
+//#include <objc/hashtable.h>
 
 #include "POSIX.cc"
 #include "OpenGL.cc"
@@ -467,7 +469,7 @@ OSStatus our_windowEventHandler(EventHandlerCallRef handler, EventRef e, void *u
             
             switch(eKind) {
                 case kEventWindowUpdate: {
-                    surface->Dirty(0,0,surface->root->width,surface->root->height);
+                   surface->Dirty(0,0,surface->root->width,surface->root->height);
                     return noErr;
                 }
                 case kEventWindowBoundsChanged: {
@@ -534,13 +536,34 @@ void Darwin$CarbonSurface::natInit(jboolean framed) {
     // FIXME: unframed windows should appear in the window menu
     // This probably needs a hack similar to whats in Cocoa.mm
     WindowAttributes attr =  kWindowStandardHandlerAttribute|
-        (framed ? kWindowInWindowMenuAttribute|kWindowStandardDocumentAttributes|kWindowLiveResizeAttribute : 0);
+        (framed ? kWindowInWindowMenuAttribute|kWindowStandardDocumentAttributes|kWindowLiveResizeAttribute/*|kWindowMetalAttribute*/ : 0);
     OSStatus r;
     
     rect.top = 0; rect.left = 0; rect.bottom = 10; rect.right=10;
     r = CreateNewWindow(wc,attr,&rect,&window);
     checkStatus(r,"CreateNewWindow");
-    
+    /*
+    // setBackingType
+    NSString* 
+    Class NSWindowClass = NSClassFromString
+      NSWindowClass->methodLists
+
+      void *iterator = 0;     // Method list (category) iterator
+    struct objc_method_list* mlist;
+    Method currMethod;
+    int  j;
+    while ( mlist = class_nextMethodList( NSWindowClass, &iterator ) ) {
+      for ( j = 0; j < mlist->method_count; ++j ) {
+        currMethod = (mlist->method_list + j);
+       if (strcmp((const char *)currMethod->method_name, "setBackingStore")) {
+         IMP imp = currMethod->method_imp;
+         (*imp)(NSWindowInstance, currMethod->method_name, 0);
+         // do stuff
+       }
+      }
+    }
+    NSWindow* window = 
+    */
     GCJ$Retainer::retain(this); // Need to account for the EventHandlers pointer to us
     EventHandlerUPP upp = NewEventHandlerUPP(our_windowEventHandler);
     
@@ -917,21 +940,23 @@ void Darwin$GLCarbonDoubleBuffer::natInit() {
     
     r = CreateNewWindow(wc,attr,&rect,&window);
     checkStatus(r,"CreateNewWindow");
-        
+
     shared = (AGLContext) gl->rawSharedContext;
     fmt = (AGLPixelFormat) gl->rawPixelFormat;
     ctx = aglCreateContext(fmt,shared);
     checkStatus(ctx, "aglCreateContext");
     
-    b = aglSetDrawable(ctx,GetWindowPort(window));
+    b = aglSetDrawable(ctx, GetWindowPort(window));
     checkStatus(b,"aglSetDrawable");
     
     aglSetCurrentContext(ctx);
     aglUpdateContext(ctx);
-    drawableInit(width,height);
+    drawableInit(OpenGL::roundToPowerOf2(width),
+                OpenGL::roundToPowerOf2(height));
     glClear(GL_COLOR_BUFFER_BIT);
 
     aglSetCurrentContext(shared);
+
     target = rectTexture ? GL_TEXTURE_RECTANGLE_EXT : GL_TEXTURE_2D;
     glEnable(target);
     glGenTextures(1,&tex);
@@ -939,6 +964,10 @@ void Darwin$GLCarbonDoubleBuffer::natInit() {
     glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     aglSurfaceTexture (shared, target, GL_RGBA, ctx);
+    /*
+    glReadBuffer
+    glCopyTexImage2D(target, 0, GL_RGBA, 0, 0, width, height, 0);
+    */
     checkGLError();
     glDisable(target);
     
@@ -972,7 +1001,7 @@ void Darwin$GLCarbonSurface::natBlit(Darwin$GLCarbonDoubleBuffer *db, jint sx1,
     if(db->rectTexture) {
         glEnable(GL_TEXTURE_RECTANGLE_EXT);
         checkGLError();
-        glBindTexture(GL_TEXTURE_RECTANGLE_EXT, db->textureName);
+        glBindTexture(GL_TEXTURE_RECTANGLE_EXT, (GLuint)db->textureName);
         checkGLError();
         glBegin(GL_QUADS); 
             glTexCoord2i (sx1, sy1   );
@@ -996,7 +1025,10 @@ void Darwin$GLCarbonSurface::natBlit(Darwin$GLCarbonDoubleBuffer *db, jint sx1,
 
         glColor4f(1.0f,1.0f,1.0f,1.0f);
         glEnable(GL_TEXTURE_2D);
-        glBindTexture(GL_TEXTURE_2D, db->textureName);    
+       GLuint tname;
+       glGenTextures(1, &tname);
+        glBindTexture(GL_TEXTURE_2D, tname);    
+       aglSurfaceTexture (ctx, GL_TEXTURE_2D, GL_RGBA, (AGLContext)db->rawCTX);
         checkGLError();
         glBegin(GL_QUADS); 
             glTexCoord2f (tx1, ty1   );
index e307b45..9d2a3f1 100644 (file)
@@ -177,11 +177,12 @@ void OpenGL$RectGLPicture::natInit(JArray<jint> *data_) {
 }
 
 void OpenGL$RectGLPicture::draw(jint dx1, jint dy1, jint dx2, jint dy2,jint sx1, jint sy1, jint sx2, jint sy2) { 
-    glColor4f(1.0f,1.0f,1.0f,1.0f);
-    glEnable(GL_TEXTURE_RECTANGLE_EXT);
-    glBindTexture(GL_TEXTURE_RECTANGLE_EXT, textureName);    
-    glBegin(GL_QUADS); 
-        glTexCoord2i (sx1, sy1   );
+    if (hasRectangularTextures()) {
+       glColor4f(1.0f,1.0f,1.0f,1.0f);
+       glEnable(GL_TEXTURE_RECTANGLE_EXT);
+       glBindTexture(GL_TEXTURE_RECTANGLE_EXT, textureName);    
+       glBegin(GL_QUADS); 
+       glTexCoord2i (sx1, sy1   );
         glVertex3i   (dx1, dy1, 0);   
         glTexCoord2i (sx2, sy1   ); 
         glVertex3i   (dx2, dy1, 0);
@@ -189,10 +190,33 @@ void OpenGL$RectGLPicture::draw(jint dx1, jint dy1, jint dx2, jint dy2,jint sx1,
         glVertex3i   (dx2, dy2, 0);
         glTexCoord2i (sx1, sy2   );
         glVertex3i   (dx1, dy2, 0);
-    glEnd();
-    glDisable(GL_TEXTURE_RECTANGLE_EXT);
-    checkGLError();
+       glEnd();
+       glDisable(GL_TEXTURE_RECTANGLE_EXT);
+       checkGLError();
+    } else {
+        float tx1,ty1,tx2,ty2; // normalized texture coords
+        tx1 = (float) sx1 / (float) width;
+        ty1 = (float) sy1 / (float) height;
+        tx2 = (float) sx2 / (float) width;
+        ty2 = (float) sy2 / (float) height;
 
+        glColor4f(1.0f,1.0f,1.0f,1.0f);
+        glEnable(GL_TEXTURE_2D);
+        glBindTexture(GL_TEXTURE_2D, textureName);    
+        checkGLError();
+        glBegin(GL_QUADS); 
+            glTexCoord2f (tx1, ty1   );
+            glVertex3i   (dx1, dy1, 0);
+            glTexCoord2f (tx2, ty1   ); 
+            glVertex3i   (dx2, dy1, 0);
+            glTexCoord2f (tx2, ty2   ); 
+            glVertex3i   (dx2, dy2, 0);
+            glTexCoord2f (tx1, ty2   );
+            glVertex3i   (dx1, dy2, 0);
+        glEnd();
+        glDisable(GL_TEXTURE_2D);
+        checkGLError();
+    }
 }
 
 void OpenGL::natDeleteTexture(jint tex_) {