Framebuffer code moved to SDL_bframebuffer.*, OpenGL support began
authorNathan Heisey <nathanheisey@gmail.com>
Sat, 30 Jul 2011 18:26:13 +0000
changeset 5931 edf9a8e68b34
parent 5930 a2372d470620
child 5932 cd08863bcb49
Framebuffer code moved to SDL_bframebuffer.*, OpenGL support began
src/main/beos/SDL_BApp.h
src/video/bwindow/SDL_BWin.h
src/video/bwindow/SDL_bframebuffer.cc
src/video/bwindow/SDL_bframebuffer.h
src/video/bwindow/SDL_bmodes.cc
src/video/bwindow/SDL_bmodes.h
src/video/bwindow/SDL_bopengl.cc
src/video/bwindow/SDL_bopengl.h
src/video/bwindow/SDL_bvideo.cc
--- a/src/main/beos/SDL_BApp.h	Thu Jul 28 18:21:38 2011 +0000
+++ b/src/main/beos/SDL_BApp.h	Sat Jul 30 18:26:13 2011 +0000
@@ -22,6 +22,7 @@
 #define SDL_BAPP_H
 
 #include <InterfaceKit.h>
+#include <OpenGLKit.h>
 
 #include "../../video/bwindow/SDL_bkeyboard.h"
 
@@ -37,15 +38,13 @@
 /* Local includes */
 #include "../../events/SDL_events_c.h"
 #include "../../video/bwindow/SDL_bkeyboard.h"
-#include "../../video/bwindow/SDL_bmodes.h"
+#include "../../video/bwindow/SDL_bframebuffer.h"
 
 #ifdef __cplusplus
 }
+#endif
 
-#include <vector>	/* Vector should only be included if we use a C++
-					   compiler */
-
-#endif
+#include <vector>
 
 
 
@@ -82,18 +81,15 @@
 public:
 	SDL_BApp(const char* signature) :
 		BApplication(signature) {
-#ifndef __cplusplus
-		/* Set vector imitation variables */
-		_ResizeArray();
-		_size = 0;
-		_length = 0;
-#endif
+		_current_context = NULL;
 	}
+	
+	
 	virtual ~SDL_BApp() {
-#ifndef __cplusplus
-		SDL_free(window_map);
-#endif
 	}
+	
+	
+	
 		/* Event-handling functions */
 	virtual void MessageReceived(BMessage* message) {
 		/* Sort out SDL-related messages */
@@ -182,9 +178,9 @@
     }
     
     /* Modes methods */
-    void SetPrevMode(display_mode *prevMode) { saved_mode = prevMode; }
+    void SetPrevMode(display_mode *prevMode) { _saved_mode = prevMode; }
     
-    display_mode* GetPrevMode() { return saved_mode; }
+    display_mode* GetPrevMode() { return _saved_mode; }
     
     /* FIXME: Bad coding practice, but I can't include SDL_BWin.h here.  Is
        there another way to do this? */
@@ -192,9 +188,15 @@
     
     
 	SDL_Window *GetSDLWindow(int32 winID) {
-		return window_map[winID];
+		return _window_map[winID];
 	}
     
+    void SetCurrentContext(BGLView *newContext) {
+    	if(_current_context)
+    		_current_context->UnlockGL();
+    	_current_context = newContext;
+    	_current_context->LockGL();
+    }
 private:
 	/* Event management */
 	void _HandleBasicWindowEvent(BMessage *msg, int32 sdlEventType) {
@@ -359,27 +361,28 @@
 	/* Vector functions: Wraps vector stuff in case we need to change 
 	   implementation */
 	void _SetSDLWindow(SDL_Window *win, int32 winID) {
-		window_map[winID] = win;
+		_window_map[winID] = win;
 	}
 	
 	int32 _GetNumWindowSlots() {
-		return window_map.size();
+		return _window_map.size();
 	}
 	
 	
 	void _PopBackWindow() {
-		window_map.pop_back();
+		_window_map.pop_back();
 	}
 
 	void _PushBackWindow(SDL_Window *win) {
-		window_map.push_back(win);
+		_window_map.push_back(win);
 	}
 
 
 	/* Members */
-	vector<SDL_Window*> window_map; /* Keeps track of SDL_Windows by index-id */
+	vector<SDL_Window*> _window_map; /* Keeps track of SDL_Windows by index-id */
 
-	display_mode *saved_mode;
+	display_mode *_saved_mode;
+	BGLView      *_current_context;
 };
 
 #endif
--- a/src/video/bwindow/SDL_BWin.h	Thu Jul 28 18:21:38 2011 +0000
+++ b/src/video/bwindow/SDL_BWin.h	Sat Jul 30 18:26:13 2011 +0000
@@ -29,6 +29,7 @@
 #include "SDL_config.h"
 #include "SDL.h"
 #include "SDL_syswm.h"
+#include "SDL_bframebuffer.h"
 
 #ifdef __cplusplus
 }
@@ -44,6 +45,7 @@
 #include "SDL_events.h"
 #include "../../main/beos/SDL_BApp.h"
 
+
 enum WinCommands {
 	BWIN_MOVE_WINDOW,
 	BWIN_RESIZE_WINDOW,
@@ -113,38 +115,36 @@
     }
     
 
-    /* Other construction */
+    /* * * * * OpenGL functionality * * * * */
 #if SDL_VIDEO_OPENGL
-    virtual int CreateView(Uint32 flags, Uint32 gl_flags)
-    {
-        int retval;
-
-        retval = 0;
+    virtual BGLView *CreateGLView(Uint32 gl_flags) {
         Lock();
-        if (flags & SDL_OPENGL/*SDL_INTERNALOPENGL*/) {
-            if (_SDL_GLView == NULL) {
-                _SDL_GLView = new BGLView(Bounds(), "SDL GLView",
-                                         B_FOLLOW_ALL_SIDES,
-                                         (B_WILL_DRAW | B_FRAME_EVENTS),
-                                         gl_flags);
-            }
-            if (_the_view != _SDL_GLView) {
-                if (_the_view) {
-                    RemoveChild(_the_view);
-                }
-                AddChild(_SDL_GLView);
-                _SDL_GLView->LockGL();
-                _the_view = _SDL_GLView;
-            }
-        } else {
-            if (_the_view) {
-                    _SDL_GLView->UnlockGL();
-                RemoveChild(_the_view);
-            }
+        if (_SDL_GLView == NULL) {
+            _SDL_GLView = new BGLView(Bounds(), "SDL GLView",
+                                     B_FOLLOW_ALL_SIDES,
+                                     (B_WILL_DRAW | B_FRAME_EVENTS),
+                                     gl_flags);
         }
+        AddChild(_SDL_GLView);
+        _SDL_GLView->LockGL();	/* "New" GLViews are created */
         Unlock();
-        return (retval);
+        return (_SDL_GLView);
     }
+    
+    virtual void RemoveGLView() {
+    	Lock();
+    	if(_SDL_GLView) {
+    		_SDL_GLView->UnlockGL();
+    		RemoveChild(_SDL_GLView);
+    	}
+    	Unlock();
+    }
+    
+    virtual void SwapBuffers(void) {
+		_SDL_GLView->UnlockGL();
+		_SDL_GLView->LockGL();
+		_SDL_GLView->SwapBuffers();
+	}
 #endif
     
     /* * * * * Framebuffering* * * * */
@@ -180,9 +180,6 @@
     			_bounds = info->window_bounds;
     			_bytes_per_px = info->bits_per_pixel / 8;
     			_buffer_dirty = true;
-    			
-    			/* Now we check for a good buffer */
-//    			SetBufferExists(!_trash_window_buffer);
     		}
     		break;
 
@@ -190,6 +187,11 @@
     		_connected = false;
     		break;
     	}
+#if SDL_VIDEO_OPENGL
+		if(_SDL_GLView) {
+			_SDL_GLView->DirectConnected(info);
+		}
+#endif
     	
     	UnlockBuffer();
     }
@@ -213,8 +215,8 @@
     virtual void FrameResized(float width, float height) {
     	/* Post a message to the BApp so that it can handle the window event */
     	BMessage msg(BAPP_WINDOW_RESIZED);
-		msg.AddInt32("window-w", (int)width) + 1;	/* TODO: Check that +1 is needed */
-		msg.AddInt32("window-h", (int)height) + 1;
+		msg.AddInt32("window-w", (int)width + 1);	/* TODO: Check that +1 is needed */
+		msg.AddInt32("window-h", (int)height + 1);
     	_PostWindowEvent(msg);
 		
 		/* Perform normal hook operations */
@@ -413,22 +415,6 @@
 	void UnlockBuffer() { _buffer_locker->Unlock(); }
 	void SetBufferDirty(bool bufferDirty) { _buffer_dirty = bufferDirty; }
 	void SetTrashBuffer(bool trash) { _trash_window_buffer = trash; 	}
-
-
-
-#if SDL_VIDEO_OPENGL
-    virtual void SwapBuffers(void)
-    {
-        _SDL_GLView->UnlockGL();
-        _SDL_GLView->LockGL();
-        _SDL_GLView->SwapBuffers();
-    }
-#endif
-    virtual BView *View(void)
-    {
-        return (_the_view);
-    }
-	
 	
 	
 private:
@@ -581,7 +567,6 @@
 #if SDL_VIDEO_OPENGL
     BGLView * _SDL_GLView;
 #endif
-    BView *_the_view;
     
     int32 _last_buttons;
     int32 _id;	/* Window id used by SDL_BApp */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/bwindow/SDL_bframebuffer.cc	Sat Jul 30 18:26:13 2011 +0000
@@ -0,0 +1,172 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "SDL_bframebuffer.h"
+
+#include <AppKit.h>
+#include <InterfaceKit.h>
+#include "SDL_bmodes.h"
+#include "SDL_BWin.h"
+
+#include "../../main/beos/SDL_BApp.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline SDL_BWin *_ToBeWin(SDL_Window *window) {
+	return ((SDL_BWin*)(window->driverdata));
+}
+
+static inline SDL_BApp *_GetBeApp() {
+	return ((SDL_BApp*)be_app);
+}
+
+int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window,
+                                       Uint32 * format,
+                                       void ** pixels, int *pitch) {
+	SDL_BWin *bwin = _ToBeWin(window);
+	BScreen bscreen;
+	if(!bscreen.IsValid()) {
+		return -1;
+	}
+
+	while(!bwin->Connected()) { snooze(100); }
+	
+	/* Make sure we have exclusive access to frame buffer data */
+	bwin->LockBuffer();
+	
+	/* format */
+	display_mode bmode;
+	bscreen.GetMode(&bmode);
+	int32 bpp = ColorSpaceToBitsPerPixel(bmode.space);
+	*format = BPPToSDLPxFormat(bpp);
+
+	/* pitch = width of screen, in bytes */
+	*pitch = bwin->GetFbWidth() * bwin->GetBytesPerPx();
+
+	/* Create a copy of the pixel buffer if it doesn't recycle */
+	*pixels = bwin->GetWindowFramebuffer();
+	if( (*pixels) != NULL ) {
+		SDL_free(*pixels);
+	}
+	*pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() * 
+		bwin->GetBytesPerPx(), sizeof(uint8));
+	bwin->SetWindowFramebuffer((uint8*)(*pixels));
+
+	bwin->SetBufferExists(true);
+	bwin->SetTrashBuffer(false);
+	bwin->UnlockBuffer();
+	return 0;
+}
+
+
+
+int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window,
+                                      SDL_Rect * rects, int numrects) {
+	if(!window)
+		return 0;
+
+	SDL_BWin *bwin = _ToBeWin(window);
+	
+	bwin->LockBuffer();
+	bwin->SetBufferDirty(true);
+	bwin->UnlockBuffer();
+
+	return 0;
+}
+
+int32 BE_DrawThread(void *data) {
+	SDL_BWin *bwin = (SDL_BWin*)data;
+	SDL_Window *window = _GetBeApp()->GetSDLWindow(bwin->GetID());
+	
+	BScreen bscreen;
+	if(!bscreen.IsValid()) {
+		return -1;
+	}
+
+	while(bwin->ConnectionEnabled()) {
+		if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) {
+			bwin->LockBuffer();
+			int32 windowPitch = window->surface->pitch;
+			int32 bufferPitch = bwin->GetRowBytes();
+			uint8 *windowpx;
+			uint8 *bufferpx;
+
+			int32 BPP = bwin->GetBytesPerPx();
+			uint8 *windowBaseAddress = (uint8*)window->surface->pixels;
+			int32 windowSub = bwin->GetFbX() * BPP +
+						  bwin->GetFbY() * windowPitch;
+			clipping_rect *clips = bwin->GetClips();
+			int32 numClips = bwin->GetNumClips();
+			int i, y;
+
+			/* Blit each clipping rectangle */
+			bscreen.WaitForRetrace();
+			for(i = 0; i < numClips; ++i) {
+				clipping_rect rc = clips[i];
+				/* Get addresses of the start of each clipping rectangle */
+				int32 width = clips[i].right - clips[i].left + 1;
+				int32 height = clips[i].bottom - clips[i].top + 1;
+				bufferpx = bwin->GetBufferPx() + 
+					clips[i].top * bufferPitch + clips[i].left * BPP;
+				windowpx = windowBaseAddress + 
+					clips[i].top * windowPitch + clips[i].left * BPP - windowSub;
+
+				/* Copy each row of pixels from the window buffer into the frame
+				   buffer */
+				for(y = 0; y < height; ++y)
+				{
+					if(bwin->CanTrashWindowBuffer()) {
+						goto escape;	/* Break out before the buffer is killed */
+					}
+					memcpy(bufferpx, windowpx, width * BPP);
+					bufferpx += bufferPitch;
+					windowpx += windowPitch;
+				}
+			}
+			bwin->SetBufferDirty(false);
+escape:
+			bwin->UnlockBuffer();
+		} else {
+			snooze(16000);
+		}
+	}
+	
+	return B_OK;
+}
+
+void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) {
+	SDL_BWin *bwin = _ToBeWin(window);
+	
+	bwin->LockBuffer();
+	
+	/* Free and clear the window buffer */
+	uint8* winBuffer = bwin->GetWindowFramebuffer();
+	SDL_free(winBuffer);
+	bwin->SetWindowFramebuffer(NULL);
+	bwin->SetBufferExists(false);
+	bwin->UnlockBuffer();
+}
+
+#ifdef __cplusplus
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/bwindow/SDL_bframebuffer.h	Sat Jul 30 18:26:13 2011 +0000
@@ -0,0 +1,43 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_BFRAMEBUFFER_H
+#define SDL_BFRAMEBUFFER_H
+#include <SupportDefs.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "../SDL_sysvideo.h"
+
+extern int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window,
+                                       Uint32 * format,
+                                       void ** pixels, int *pitch);
+extern int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window,
+                                       SDL_Rect * rects, int numrects);
+extern void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window);
+extern int32 BE_DrawThread(void *data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--- a/src/video/bwindow/SDL_bmodes.cc	Thu Jul 28 18:21:38 2011 +0000
+++ b/src/video/bwindow/SDL_bmodes.cc	Sat Jul 30 18:26:13 2011 +0000
@@ -54,7 +54,7 @@
 		/ float(mode.timing.h_total * mode.timing.v_total);
 }
 
-static inline int ColorSpaceToBitsPerPixel(uint32 colorspace)
+static inline int32 ColorSpaceToBitsPerPixel(uint32 colorspace)
 {
 	int bitsperpixel;
 
@@ -207,135 +207,6 @@
 	return -1;
 }
 
-
-
-int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window,
-                                       Uint32 * format,
-                                       void ** pixels, int *pitch) {
-	SDL_BWin *bwin = _ToBeWin(window);
-	BScreen bscreen;
-	if(!bscreen.IsValid()) {
-		return -1;
-	}
-
-	while(!bwin->Connected()) { snooze(100); }
-	
-	/* Make sure we have exclusive access to frame buffer data */
-	bwin->LockBuffer();
-	
-	/* format */
-	display_mode bmode;
-	bscreen.GetMode(&bmode);
-	int32 bpp = ColorSpaceToBitsPerPixel(bmode.space);
-	*format = BPPToSDLPxFormat(bpp);
-
-	/* pitch = width of screen, in bytes */
-	*pitch = bwin->GetFbWidth() * bwin->GetBytesPerPx();
-
-	/* Create a copy of the pixel buffer if it doesn't recycle */
-	*pixels = bwin->GetWindowFramebuffer();
-	if( (*pixels) != NULL ) {
-		SDL_free(*pixels);
-	}
-	*pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() * 
-		bwin->GetBytesPerPx(), sizeof(uint8));
-	bwin->SetWindowFramebuffer((uint8*)(*pixels));
-
-	bwin->SetBufferExists(true);
-	bwin->SetTrashBuffer(false);
-	bwin->UnlockBuffer();
-	return 0;
-}
-
-
-
-int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window,
-                                      SDL_Rect * rects, int numrects) {
-	if(!window)
-		return 0;
-
-	SDL_BWin *bwin = _ToBeWin(window);
-	
-	bwin->LockBuffer();
-	bwin->SetBufferDirty(true);
-	bwin->UnlockBuffer();
-
-	return 0;
-}
-
-int32 BE_DrawThread(void *data) {
-	SDL_BWin *bwin = (SDL_BWin*)data;
-	SDL_Window *window = _GetBeApp()->GetSDLWindow(bwin->GetID());
-	
-	BScreen bscreen;
-	if(!bscreen.IsValid()) {
-		return -1;
-	}
-
-	while(bwin->ConnectionEnabled()) {
-		if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) {
-			bwin->LockBuffer();
-			int32 windowPitch = window->surface->pitch;
-			int32 bufferPitch = bwin->GetRowBytes();
-			uint8 *windowpx;
-			uint8 *bufferpx;
-
-			int32 BPP = bwin->GetBytesPerPx();
-			uint8 *windowBaseAddress = (uint8*)window->surface->pixels;
-			int32 windowSub = bwin->GetFbX() * BPP +
-						  bwin->GetFbY() * windowPitch;
-			clipping_rect *clips = bwin->GetClips();
-			int32 numClips = bwin->GetNumClips();
-			int i, y;
-
-			/* Blit each clipping rectangle */
-			bscreen.WaitForRetrace();
-			for(i = 0; i < numClips; ++i) {
-				clipping_rect rc = clips[i];
-				/* Get addresses of the start of each clipping rectangle */
-				int32 width = clips[i].right - clips[i].left + 1;
-				int32 height = clips[i].bottom - clips[i].top + 1;
-				bufferpx = bwin->GetBufferPx() + 
-					clips[i].top * bufferPitch + clips[i].left * BPP;
-				windowpx = windowBaseAddress + 
-					clips[i].top * windowPitch + clips[i].left * BPP - windowSub;
-
-				/* Copy each row of pixels from the window buffer into the frame
-				   buffer */
-				for(y = 0; y < height; ++y)
-				{
-					if(bwin->CanTrashWindowBuffer()) {
-						goto escape;	/* Break out before the buffer is killed */
-					}
-					memcpy(bufferpx, windowpx, width * BPP);
-					bufferpx += bufferPitch;
-					windowpx += windowPitch;
-				}
-			}
-			bwin->SetBufferDirty(false);
-escape:
-			bwin->UnlockBuffer();
-		} else {
-			snooze(16000);
-		}
-	}
-	
-	return B_OK;
-}
-
-void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) {
-	SDL_BWin *bwin = _ToBeWin(window);
-	
-	bwin->LockBuffer();
-	
-	/* Free and clear the window buffer */
-	uint8* winBuffer = bwin->GetWindowFramebuffer();
-	SDL_free(winBuffer);
-	bwin->SetWindowFramebuffer(NULL);
-	bwin->SetBufferExists(false);
-	bwin->UnlockBuffer();
-}
-
 #ifdef __cplusplus
 }
 #endif
--- a/src/video/bwindow/SDL_bmodes.h	Thu Jul 28 18:21:38 2011 +0000
+++ b/src/video/bwindow/SDL_bmodes.h	Sat Jul 30 18:26:13 2011 +0000
@@ -28,6 +28,9 @@
 
 #include "../SDL_sysvideo.h"
 
+extern int32 ColorSpaceToBitsPerPixel(uint32 colorspace);
+extern int32 BPPToSDLPxFormat(int32 bpp);
+
 extern int BE_InitModes(_THIS);
 extern int BE_QuitModes(_THIS);
 extern int BE_GetDisplayBounds(_THIS, SDL_VideoDisplay *display,
@@ -36,15 +39,6 @@
 extern int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display,
 	SDL_DisplayMode *mode);
 
-extern int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window,
-                                       Uint32 * format,
-                                       void ** pixels, int *pitch);
-extern int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window,
-                                       SDL_Rect * rects, int numrects);
-extern void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window);
-extern int32 BE_DrawThread(void *data);
-
-
 #ifdef __cplusplus
 }
 #endif
--- a/src/video/bwindow/SDL_bopengl.cc	Thu Jul 28 18:21:38 2011 +0000
+++ b/src/video/bwindow/SDL_bopengl.cc	Sat Jul 30 18:26:13 2011 +0000
@@ -21,14 +21,27 @@
 
 #include "SDL_bopengl.h"
 
+#include <unistd.h>
+#include <KernelKit.h>
+#include <OpenGLKit.h>
+#include "SDL_BWin.h"
+#include "../../main/beos/SDL_BApp.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+static inline SDL_BWin *_ToBeWin(SDL_Window *window) {
+	return ((SDL_BWin*)(window->driverdata));
+}
+
+static inline SDL_BApp *_GetBeApp() {
+	return ((SDL_BApp*)be_app);
+}
+
 /* Passing a NULL path means load pointers from the application */
 int BE_GL_LoadLibrary(_THIS, const char *path)
 {
-#if 0
 	if (path == NULL) {
 		if (_this->gl_config.dll_handle == NULL) {
 			image_info info;
@@ -83,12 +96,10 @@
 		*_this->gl_config.driver_path = '\0';
 		return -1;
 	}
-#endif
 }
 
 void *BE_GL_GetProcAddress(_THIS, const char *proc)
 {
-#if 0
 	if (_this->gl_config.dll_handle != NULL) {
 		void *location = NULL;
 		status_t err;
@@ -105,29 +116,9 @@
 		SDL_SetError("OpenGL library not loaded");
 		return NULL;
 	}
-#endif
 }
 
 
-
-
-int BE_GL_MakeCurrent(_THIS)
-{
-	/* FIXME: should we glview->unlock and then glview->lock()? */
-	return 0;
-}
-
-
-
-
-
-
-
-
-
-
-
-
 #if 0 /* Functions from 1.2 that do not appear to be used in 1.3 */
 
     int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
@@ -190,11 +181,39 @@
         return 0;
     }
 
-    void BE_GL_SwapBuffers(_THIS)
-    {
-        SDL_Win->SwapBuffers();
+#endif
+    void BE_GL_SwapWindow(_THIS, SDL_Window * window) {
+        _ToBeWin(window)->SwapBuffers();
     }
-#endif
+
+int BE_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) {
+	_GetBeApp()->SetCurrentContext((BGLView*)context);
+	return 0;
+}
+
+
+SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window) {
+	/* FIXME: Not sure what flags should be included here; may want to have
+	   most of them */
+	return (SDL_GLContext)(_ToBeWin(window)->CreateGLView(
+		BGL_RGB | BGL_DOUBLE));
+}
+
+void BE_GL_DeleteContext(_THIS, SDL_GLContext context) {
+	/* Currently, automatically unlocks the view */
+//	_ToBeWin(window)->RemoveGLView();	FIXME: Need to get the bwindow somehow
+}
+
+
+int BE_GL_SetSwapInterval(_THIS, int interval) {
+}
+
+int BE_GL_GetSwapInterval(_THIS) {
+}
+
+
+void BE_GL_UnloadLibrary(_THIS) {
+}
 
 #ifdef __cplusplus
 }
--- a/src/video/bwindow/SDL_bopengl.h	Thu Jul 28 18:21:38 2011 +0000
+++ b/src/video/bwindow/SDL_bopengl.h	Sat Jul 30 18:26:13 2011 +0000
@@ -29,10 +29,19 @@
 #include "../SDL_sysvideo.h"
 
 
+extern int BE_GL_LoadLibrary(_THIS, const char *path);					//FIXME
+extern void *BE_GL_GetProcAddress(_THIS, const char *proc);				//FIXME
+extern void BE_GL_UnloadLibrary(_THIS);									//TODO
+//extern int BE_GL_SetupWindow(_THIS, SDL_Window * window);				//TODO
+extern int BE_GL_MakeCurrent(_THIS, SDL_Window * window,
+                              SDL_GLContext context);
+extern int BE_GL_SetSwapInterval(_THIS, int interval);					//TODO
+extern int BE_GL_GetSwapInterval(_THIS);								//TODO
+extern void BE_GL_SwapWindow(_THIS, SDL_Window * window);
+extern SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window);
+extern void BE_GL_DeleteContext(_THIS, SDL_GLContext context);
 
-extern int BE_GL_LoadLibrary(_THIS, const char *path);
-extern void *BE_GL_GetProcAddress(_THIS, const char *proc);
-extern int BE_GL_MakeCurrent(_THIS);
+
 
 #ifdef __cplusplus
 }
--- a/src/video/bwindow/SDL_bvideo.cc	Thu Jul 28 18:21:38 2011 +0000
+++ b/src/video/bwindow/SDL_bvideo.cc	Sat Jul 30 18:26:13 2011 +0000
@@ -32,22 +32,11 @@
 #include "SDL_bvideo.h"
 #include "SDL_bopengl.h"
 #include "SDL_bmodes.h"
+#include "SDL_bframebuffer.h"
 #include "SDL_bevents.h"
 
 /* FIXME: Undefined functions */
 //    #define BE_PumpEvents NULL
-    
-#if SDL_VIDEO_OPENGL_WGL	/* FIXME: Replace with BeOs's SDL OPENGL stuff */
-//    #define BE_GL_LoadLibrary NULL
-//    #define BE_GL_GetProcAddress NULL
-    #define BE_GL_UnloadLibrary NULL
-    #define BE_GL_CreateContext NULL
-//    #define BE_GL_MakeCurrent NULL
-    #define BE_GL_SetSwapInterval NULL
-    #define BE_GL_GetSwapInterval NULL
-    #define BE_GL_SwapWindow NULL
-    #define BE_GL_DeleteContext NULL
-#endif
     #define BE_StartTextInput NULL
     #define BE_StopTextInput NULL
     #define BE_SetTextInputRect NULL
@@ -115,8 +104,8 @@
     device->shape_driver.CreateShaper = NULL;
     device->shape_driver.SetWindowShape = NULL;
     device->shape_driver.ResizeWindowShape = NULL;
-    
-#if SDL_VIDEO_OPENGL_WGL	/* FIXME: Replace with BeOs's SDL OPENGL stuff */
+
+//#if SDL_VIDEO_OPENGL_WGL	/* FIXME: Replace with BeOs's SDL OPENGL stuff */
     device->GL_LoadLibrary = BE_GL_LoadLibrary;
     device->GL_GetProcAddress = BE_GL_GetProcAddress;
     device->GL_UnloadLibrary = BE_GL_UnloadLibrary;
@@ -126,7 +115,7 @@
     device->GL_GetSwapInterval = BE_GL_GetSwapInterval;
     device->GL_SwapWindow = BE_GL_SwapWindow;
     device->GL_DeleteContext = BE_GL_DeleteContext;
-#endif
+//#endif
     device->StartTextInput = BE_StartTextInput;
     device->StopTextInput = BE_StopTextInput;
     device->SetTextInputRect = BE_SetTextInputRect;