Commits

Ivan Vučica committed 964a2bd

Old work on Fireplace

Comments (0)

Files changed (4)

FPManagedWindow.h

 	GLuint _textureTarget;
 
 	int _x, _y, _z;
+	int _depth;
 	int _width, _height;
 	BOOL _hasAlpha;
 	BOOL _hasOutput;

FPManagedWindow.m

 
 #define USE_GLX1_3 1
 
-#define SWITCH_CONTEXTS 1
+#define SWITCH_CONTEXTS 0
 
+#define GRABSERVER 0
 #if !SAFE_MODE
 	#define HAVE_GL_COPY_TEX_IMAGE_2D 1
 	#define FORCE_TEXTURE_2D 1
 	#define USE_GLXBINDTEXIMAGE 0
 	#undef USE_GLX1_3
 	#define USE_GLX1_3 0
+	#undef SWITCH_CONTEXTS
+	#define SWITCH_CONTEXTS 1
 #endif
 static int DamageNotify = -1;
 static PFNGLXBINDTEXIMAGEEXTPROC glXBindTexImageEXT = 0;
 		GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGBA_EXT,
 		None
 	};            
-	
+NSLog(@"Making a pixmap...");	
 	_pixmap = XCompositeNameWindowPixmap (display, _window);
 	if(!_pixmap)
 		NSLog(@"Failed to make a pixmap");
+NSLog(@"Building glx pixmap...");
 #if !USE_GLX1_3
 	_drawable = glXCreateGLXPixmap (display, [_manager visualInfo], _pixmap);
 #else
-	_drawable = glXCreatePixmap (display, [_manager glxFBConfigs][0], _pixmap, pixmap_attribs);
+	if(![_manager glxFBConfigs][_depth])
+		NSLog(@"No fbconfig for depth %d for window %p", _depth, _window);
+	_drawable = glXCreatePixmap (display, [_manager glxFBConfigs][_depth], _pixmap, pixmap_attribs);
 #endif
 	if(!_drawable)
 		NSLog(@"Failed to make a drawable");
+
 	_damage = XDamageCreate (display, _window, XDamageReportDeltaRectangles);
 	if(!_texture)
 		glGenTextures (1, &_texture);
 
+/*
 	if(glXBindTexImageEXT)
 		glXBindTexImageEXT(display, _drawable, GLX_FRONT_EXT, NULL);
+*/
 }
 -(void)_freeResources
 {
 	FPX11Display * mainDisplay = [FPX11Display mainDisplay];
 	Display * display = [mainDisplay display];
-
+/*
 	if(glXReleaseTexImageEXT)
 		glXReleaseTexImageEXT(display, _drawable, GLX_FRONT_EXT);
-
+*/
 	/*
 	if(_damage)
 		XDamageDestroy(display, _damage);
 	*/
-	if(_pixmap)
-		XFreePixmap(display, _pixmap);
+	if(_texture)
+		glDeleteTextures(1, &_texture);
 	if(_drawable)
-#if USE_GLX1_3
+#if !USE_GLX1_3
 		glXDestroyGLXPixmap(display, _drawable);
 #else
 		glXDestroyPixmap(display, _drawable);
 #endif
-	if(_texture)
-		glDeleteTextures(1, &_texture);
+	if(_pixmap)
+		XFreePixmap(display, _pixmap);
 }
 -(void)_collectAttributes
 {
 	_x = attr.x;
 	_y = attr.y;
 	_z = 0;
+	_depth = attr.depth;
 	_isMapped = (attr.map_state == IsViewable);
 	_hasOutput = (attr.class == InputOutput);
 	_hasAlpha = (attr.depth > 3 * attr.visual->bits_per_rgb);
 		break;
 	}
 }
+-(void)drawWindowNew
+{
+	FPX11Display * mainDisplay = [FPX11Display mainDisplay];
+	Display * display = [mainDisplay display];
+		
+		glEnable(GL_TEXTURE_2D); //_textureTarget);
+		glXWaitX();
+		glBindTexture(_textureTarget, _texture);
+		glXWaitX();
+NSLog(@"Bound texture, now binding drawable %ld", _drawable);
+		glXWaitX();
+		glXBindTexImageEXT(display, _drawable, GLX_FRONT_EXT, NULL);
+		glXWaitX();
+
+	NSLog(@"Painting.");	
+	glMatrixMode(GL_MODELVIEW);
+	glPushMatrix ();
+		glTranslatef (_x, _y /* TODO remove the 100 */ +100, _z);
+		/*
+		extent_clip (0, 0, mirror->w, mirror->h);
+		*/
+		glBegin(GL_QUADS);
+		/*
+		for (list = mirror->draw_zone; list; list = g_slist_next (list))
+			quad_draw (list->data);
+		*/
+
+		#define INVERTED_Y 1
+		#if INVERTED_Y
+		#define _Y(y) 1-y
+		#else
+		#define _Y(y) y
+		#endif
+
+		glTexCoord2f(0,_Y(0)); glVertex3f(0,0,0);
+		glTexCoord2f(0,_Y(1)); glVertex3f(0,_height,0);
+		glTexCoord2f(1,_Y(1)); glVertex3f(_width, _height, 0);
+		glTexCoord2f(1,_Y(0)); glVertex3f(_width, 0, 0);
+		
+		#undef _Y
+		
+		glEnd();
+		/*
+		extent_unclip ();
+		*/
+
+		glLineWidth(4);		
+		glDisable(_textureTarget);
+		glColor4f(0,0,0,1);
+		glBegin(GL_LINE_LOOP);
+		glVertex2f(0,0);
+		glVertex2f(0,_height);
+		glVertex2f(_width,_height);
+		glVertex2f(_width,0);
+		glEnd();
+		glColor4f(1,1,1,1);
+		glEnable(_textureTarget);
+		glLineWidth(1);
+
+	glPopMatrix ();
+	NSLog(@"Done");
+		glXReleaseTexImageEXT(display, _drawable, GLX_FRONT_EXT);
+	NSLog(@"Released drawable");
+}
 -(void)drawWindow
 {
 
 	//glColor3f((rand() % 100) / 100., (rand() % 100) / 100., (rand() % 100) / 100.);
 	//glColor4f(1,1,1,1);
 	glColor4f(1,1,0.5+sin(_timeAlive*2)/2,1);
-	NSLog(@"%g %g", _timeAlive, 0.5+sin(_timeAlive/5)/2);
 	glBindTexture(_textureTarget, _texture);
-	
+
+	NSLog(@"Painting.");	
 	glMatrixMode(GL_MODELVIEW);
 	glPushMatrix ();
-		glTranslatef (_x, _y, _z);
+		glTranslatef (_x, _y /* TODO remove the 100 */ +100, _z);
 		/*
 		extent_clip (0, 0, mirror->w, mirror->h);
 		*/
 	FPX11Display * mainDisplay = [FPX11Display mainDisplay];
 	Display * display = [mainDisplay display];
 
+	[self _freeResources];
+	[self _buildResources];
 	if(!_drawable)
 	{
 		NSLog(@"No drawable, skipping bind");
 	}
 		
 	glXWaitX();
+	glXWaitGL();
 	XSync(display, None);
 	grabCount++;
 	NSLog(@"Grabbing server %d", grabCount);
-	//XGrabServer (display);
+#if GRABSERVER
+	XGrabServer (display);
+#endif
 
 #if SWITCH_CONTEXTS
 	NSLog(@"Context switch");
 NSLog(@"Switching context");
 		glXMakeContextCurrent (display, [_manager stage], [_manager stage], [_manager glxContext]);
 #endif
-NSLog(@"Beginning bind");
+NSLog(@"------");
 		glEnable(_textureTarget);
+NSLog(@"Beginning bind to %d", _textureTarget);
 		glBindTexture(_textureTarget, _texture);
-NSLog(@"Bound texture, now binding drawable %d", _drawable);
-		glXBindTexImageEXT(display, _drawable, GLX_FRONT_EXT, NULL);
+NSLog(@"Bound texture to %d, now binding drawable %ld", _textureTarget, _drawable);
+		glXBindTexImageEXT(display, _drawable, GLX_FRONT_LEFT_EXT, NULL);
+		//gluBuild2DMipmaps(_textureTarget, GL_RGBA, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char[]){255, 0, 0, 0,         0, 0, 0, 0,     0, 0, 0, 0,           255, 0, 00} );
+		glBindTexture(_textureTarget, 0);
 NSLog(@"Bound drawable");
 	}
 	else
 
 	NSLog(@"Ungrabbing server %d", grabCount);
 	grabCount--;
-	glXWaitX();
-	NSLog(@"Waited gl");
-	XSync(display, None);
-	NSLog(@"Ungrabing");
-	//XUngrabServer (display);
+#if GRABSERVER
+	XUngrabServer (display);
+#endif
 	NSLog(@"Wiating x");
 	glXWaitX();
 	NSLog(@"Syncing x");
 	XSync(display, None);
 	NSLog(@"Done ungrab");
 
+	
 }
 -(void)updateWithDeltaTime:(float)sec;
 {
 	_timeAlive += sec;
-	NSLog(@"Update %g", sec);
 }
 @end

FPWindowManager.m

 #import "FPManagedWindow.h"
 
 #define VBOXCOMPAT 1 // virtualbox compatibility
-#define TEX2D 0 // tex2d or rectangle?
+#define TEX2D 1 // tex2d or rectangle?
 static int attrListSgl[] = {
     GLX_RGBA, GLX_RED_SIZE, 4,
     GLX_GREEN_SIZE, 4,
     GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_RECTANGLE_BIT_EXT,
 #endif
     GLX_Y_INVERTED_EXT, GLX_DONT_CARE,
+    
+    GLX_RGBA, GLX_DOUBLEBUFFER,
+    GLX_RED_SIZE, 4,
+    GLX_GREEN_SIZE, 4,
+    GLX_BLUE_SIZE, 4,
+    GLX_DEPTH_SIZE, 16,
     None
 };
 
 	Visual * glxVisual;
 	
 	////////	
+	int c = 0;
+	_glxFBConfigs = glXChooseFBConfig(display, screen, fbconfig, &c);
+	if(!_glxFBConfigs)
+	{
+		// TODO: throw exception or return nil instead of exiting
+		NSLog(@"No FBConfigs");
+		exit(1);
+	}
+	
+	///////////
+#if 0
 	glxVisualInfo = _visualInfo = glXChooseVisual(display, screen, attrListDbl);
 	if (glxVisualInfo == NULL)
 	{
 	{
 		_isVisualDoubleBuffered = YES;
 	}
-
+#else
+	_isVisualDoubleBuffered = YES;
+	for(int i = 0; i < c; i++)
+	{
+		NSLog(@"%d / %d", i, c);
+		glxVisualInfo = _visualInfo = glXGetVisualFromFBConfig(display, _glxFBConfigs[i]);
+		if(_visualInfo)
+		{
+			break;
+		}
+	}
+#endif
 	glxRootWindow = _root = [mainDisplay rootWindowForScreen:glxVisualInfo->screen];
 	glxVisual = glxVisualInfo->visual;
 	glxColorMap = XCreateColormap(
 		0, 
 		NULL);
 
-	glXMakeCurrent(display, _stage, _glxContext);
+	glXMakeContextCurrent ([[FPX11Display mainDisplay] display], _stage, _stage, _glxContext);
 	
+	NSLog(@"Renderer: %s", glGetString(GL_RENDERER));
 	///////////
 		
-	int c = 0;
-	_glxFBConfigs = glXChooseFBConfig(display, screen, fbconfig, &c);
-	if(!_glxFBConfigs)
-	{
-		// TODO: throw exception or return nil instead of exiting
-		NSLog(@"No FBConfigs");
-		exit(1);
-	}
-	
-	///////////
 	
 	XGetGeometry(
 		display, 
 		if(!_wasExposed)
 		{
 			[self _execCommand:@"/usr/bin/xterm"];
+			//[self _execCommand:@"/usr/bin/gedit"];
 		}
 		_wasExposed = YES;
 		break;
 
 make
-LIBGL_ALWAYS_INDIRECT=1 ./run-xephyr /usr/GNUstep/System/Tools/openapp ./Fireplace.app
-#./run-xephyr /usr/GNUstep/System/Tools/openapp ./Fireplace.app
+#LIBGL_ALWAYS_INDIRECT=1 ./run-xephyr /usr/GNUstep/System/Tools/openapp ./Fireplace.app
+./run-xephyr /usr/GNUstep/System/Tools/openapp ./Fireplace.app
+
+#./Fireplace.app/Fireplace
 
 #./run-xephyr &
 #DISPLAY=:3 /usr/bin/gdb ./Fireplace.app/Fireplace