diff --git a/src/kits/opengl/GLDispatcher.cpp b/src/kits/opengl/GLDispatcher.cpp index 1526676c87..2b5e5977b7 100644 --- a/src/kits/opengl/GLDispatcher.cpp +++ b/src/kits/opengl/GLDispatcher.cpp @@ -79,23 +79,23 @@ extern "C" { #include "GLDispatcher.h" -GLDispatcher::GLDispatcher() +BGLDispatcher::BGLDispatcher() { } -GLDispatcher::~GLDispatcher() +BGLDispatcher::~BGLDispatcher() { } status_t -GLDispatcher::CheckTable(const struct _glapi_table *table) +BGLDispatcher::CheckTable(const struct _glapi_table *table) { _glapi_check_table(table ? table : _glapi_get_dispatch()); return B_OK; } status_t -GLDispatcher::SetTable(struct _glapi_table *table) +BGLDispatcher::SetTable(struct _glapi_table *table) { _glapi_set_dispatch(table); return B_OK; diff --git a/src/kits/opengl/GLDispatcher.h b/src/kits/opengl/GLDispatcher.h index 5204f56fa9..80422d1e9c 100644 --- a/src/kits/opengl/GLDispatcher.h +++ b/src/kits/opengl/GLDispatcher.h @@ -9,15 +9,15 @@ extern "C" { #include "glapi.h" } -class GLDispatcher +class BGLDispatcher { // Private unimplemented copy constructors - GLDispatcher(const GLDispatcher &); - GLDispatcher & operator=(const GLDispatcher &); + BGLDispatcher(const BGLDispatcher &); + BGLDispatcher & operator=(const BGLDispatcher &); public: - GLDispatcher(); - ~GLDispatcher(); + BGLDispatcher(); + ~BGLDispatcher(); const char * Version(); @@ -36,49 +36,49 @@ class GLDispatcher }; // Inlines methods -inline const char * GLDispatcher::Version() +inline const char * BGLDispatcher::Version() { return _glapi_get_version(); } -inline void GLDispatcher::SetCurrentContext(void * context) +inline void BGLDispatcher::SetCurrentContext(void * context) { _glapi_set_context(context); } -inline void * GLDispatcher::CurrentContext() +inline void * BGLDispatcher::CurrentContext() { return _glapi_get_context(); } -inline struct _glapi_table * GLDispatcher::Table() +inline struct _glapi_table * BGLDispatcher::Table() { return _glapi_get_dispatch(); } -inline uint32 GLDispatcher::TableSize() +inline uint32 BGLDispatcher::TableSize() { return _glapi_get_dispatch_table_size(); } -inline const _glapi_proc GLDispatcher::operator[](const char *function_name) +inline const _glapi_proc BGLDispatcher::operator[](const char *function_name) { return _glapi_get_proc_address(function_name); } -inline const char * GLDispatcher::operator[](uint32 offset) +inline const char * BGLDispatcher::operator[](uint32 offset) { return _glapi_get_proc_name((GLuint) offset); } -inline uint32 GLDispatcher::OffsetOf(const char *function_name) +inline uint32 BGLDispatcher::OffsetOf(const char *function_name) { return (uint32) _glapi_get_proc_offset(function_name); } diff --git a/src/kits/opengl/GLRenderer.cpp b/src/kits/opengl/GLRenderer.cpp new file mode 100644 index 0000000000..3b0fcd8362 --- /dev/null +++ b/src/kits/opengl/GLRenderer.cpp @@ -0,0 +1,18 @@ +#include "GLRenderer.h" + +void BGLRenderer::LockGL() +{ +} + +void BGLRenderer::UnlockGL() +{ +} + +void BGLRenderer::DirectConnected(direct_buffer_info *info) +{ +} + +void BGLRenderer::EnableDirectMode(bool enabled) +{ +} + diff --git a/src/kits/opengl/GLRenderer.h b/src/kits/opengl/GLRenderer.h index 57a070afe3..9b268bb271 100644 --- a/src/kits/opengl/GLRenderer.h +++ b/src/kits/opengl/GLRenderer.h @@ -2,161 +2,48 @@ #define GLRENDERER_H #include +#include -class GLDispatcher; +class BGLDispatcher; -class GLRenderer +class BGLRenderer { + // Private unimplemented copy constructors - GLRenderer(const GLRenderer &); - GLRenderer & operator=(const GLRenderer &); + BGLRenderer(const BGLRenderer &); + BGLRenderer & operator=(const BGLRenderer &); public: - GLRenderer(); - ~GLRenderer(); + BGLRenderer(BGLView *view, BGLDispatcher *dispatcher); + virtual ~BGLRenderer(); - void Init(BGLView * bglview, GLcontext * c, GLvisual * v, GLframebuffer * b); + status_t Acquire(); + status_t Release(); - void LockGL(); - void UnlockGL(); - void SwapBuffers(bool VSync = false) const; - void Draw(BRect updateRect) const; + void LockGL(); + void UnlockGL(); + + virtual void SwapBuffers(bool VSync = false) const; + virtual void Draw(BRect updateRect); + virtual status_t CopyPixelsOut(BPoint source, BBitmap *dest); + virtual status_t CopyPixelsIn(BBitmap *source, BPoint dest); + + + virtual void AttachedToWindow(); + virtual void AllAttached(); + virtual void DetachedFromWindow(); + virtual void AllDetached(); + + virtual void FrameResized(float width, float height); + + void DirectConnected( direct_buffer_info *info ); + void EnableDirectMode( bool enabled ); private: - MesaDriver(const MesaDriver &rhs); // copy constructor illegal - MesaDriver &operator=(const MesaDriver &rhs); // assignment oper. illegal - - GLcontext * m_glcontext; - GLvisual * m_glvisual; - GLframebuffer * m_glframebuffer; - - BGLView * m_bglview; - BBitmap * m_bitmap; - - GLchan m_clear_color[4]; // buffer clear color - GLuint m_clear_index; // buffer clear color index - GLint m_bottom; // used for flipping Y coords - GLuint m_width; - GLuint m_height; - - // Mesa Device Driver functions - static void UpdateState(GLcontext *ctx, GLuint new_state); - static void ClearIndex(GLcontext *ctx, GLuint index); - static void ClearColor(GLcontext *ctx, const GLfloat color[4]); - static void Clear(GLcontext *ctx, GLbitfield mask, - GLboolean all, GLint x, GLint y, - GLint width, GLint height); - static void ClearFront(GLcontext *ctx, GLboolean all, GLint x, GLint y, - GLint width, GLint height); - static void ClearBack(GLcontext *ctx, GLboolean all, GLint x, GLint y, - GLint width, GLint height); - static void Index(GLcontext *ctx, GLuint index); - static void Color(GLcontext *ctx, GLubyte r, GLubyte g, - GLubyte b, GLubyte a); - static void SetBuffer(GLcontext *ctx, GLframebuffer *colorBuffer, - GLenum mode); - static void GetBufferSize(GLframebuffer * framebuffer, GLuint *width, - GLuint *height); - static const GLubyte * GetString(GLcontext *ctx, GLenum name); - - // Front-buffer functions - static void WriteRGBASpanFront(const GLcontext *ctx, GLuint n, - GLint x, GLint y, - CONST GLubyte rgba[][4], - const GLubyte mask[]); - static void WriteRGBSpanFront(const GLcontext *ctx, GLuint n, - GLint x, GLint y, - CONST GLubyte rgba[][3], - const GLubyte mask[]); - static void WriteMonoRGBASpanFront(const GLcontext *ctx, GLuint n, - GLint x, GLint y, - const GLchan color[4], - const GLubyte mask[]); - static void WriteRGBAPixelsFront(const GLcontext *ctx, GLuint n, - const GLint x[], const GLint y[], - CONST GLubyte rgba[][4], - const GLubyte mask[]); - static void WriteMonoRGBAPixelsFront(const GLcontext *ctx, GLuint n, - const GLint x[], const GLint y[], - const GLchan color[4], - const GLubyte mask[]); - static void WriteCI32SpanFront(const GLcontext *ctx, GLuint n, - GLint x, GLint y, - const GLuint index[], const GLubyte mask[]); - static void WriteCI8SpanFront(const GLcontext *ctx, GLuint n, - GLint x, GLint y, - const GLubyte index[], const GLubyte mask[]); - static void WriteMonoCISpanFront(const GLcontext *ctx, GLuint n, - GLint x, GLint y, - GLuint colorIndex, const GLubyte mask[]); - static void WriteCI32PixelsFront(const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - const GLuint index[], const GLubyte mask[]); - static void WriteMonoCIPixelsFront(const GLcontext *ctx, GLuint n, - const GLint x[], const GLint y[], - GLuint colorIndex, const GLubyte mask[]); - static void ReadCI32SpanFront(const GLcontext *ctx, - GLuint n, GLint x, GLint y, GLuint index[]); - static void ReadRGBASpanFront(const GLcontext *ctx, GLuint n, - GLint x, GLint y, - GLubyte rgba[][4]); - static void ReadCI32PixelsFront(const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - GLuint indx[], const GLubyte mask[]); - static void ReadRGBAPixelsFront(const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - GLubyte rgba[][4], const GLubyte mask[]); - - // Back buffer functions - static void WriteRGBASpanBack(const GLcontext *ctx, GLuint n, - GLint x, GLint y, - CONST GLubyte rgba[][4], - const GLubyte mask[]); - static void WriteRGBSpanBack(const GLcontext *ctx, GLuint n, - GLint x, GLint y, - CONST GLubyte rgba[][3], - const GLubyte mask[]); - static void WriteMonoRGBASpanBack(const GLcontext *ctx, GLuint n, - GLint x, GLint y, - const GLchan color[4], - const GLubyte mask[]); - static void WriteRGBAPixelsBack(const GLcontext *ctx, GLuint n, - const GLint x[], const GLint y[], - CONST GLubyte rgba[][4], - const GLubyte mask[]); - static void WriteMonoRGBAPixelsBack(const GLcontext *ctx, GLuint n, - const GLint x[], const GLint y[], - const GLchan color[4], - const GLubyte mask[]); - static void WriteCI32SpanBack(const GLcontext *ctx, GLuint n, - GLint x, GLint y, - const GLuint index[], const GLubyte mask[]); - static void WriteCI8SpanBack(const GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLubyte index[], const GLubyte mask[]); - static void WriteMonoCISpanBack(const GLcontext *ctx, GLuint n, - GLint x, GLint y, GLuint colorIndex, - const GLubyte mask[]); - static void WriteCI32PixelsBack(const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - const GLuint index[], const GLubyte mask[]); - static void WriteMonoCIPixelsBack(const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - GLuint colorIndex, const GLubyte mask[]); - static void ReadCI32SpanBack(const GLcontext *ctx, - GLuint n, GLint x, GLint y, GLuint index[]); - static void ReadRGBASpanBack(const GLcontext *ctx, GLuint n, - GLint x, GLint y, - GLubyte rgba[][4]); - static void ReadCI32PixelsBack(const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - GLuint indx[], const GLubyte mask[]); - static void ReadRGBAPixelsBack(const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - GLubyte rgba[][4], const GLubyte mask[]); - + uint32 fRefCount; }; -extern "C" _EXPORT GLRenderer * instanciate_gl_renderer(BGLView *view, GLDispatcher *dispatcher); +extern "C" _EXPORT BGLRenderer * instanciate_gl_renderer(BGLView *view, BGLDispatcher *dispatcher); #endif // GLRENDERER_H diff --git a/src/kits/opengl/GLView.cpp b/src/kits/opengl/GLView.cpp index d42b90d64f..afb6237652 100644 --- a/src/kits/opengl/GLView.cpp +++ b/src/kits/opengl/GLView.cpp @@ -27,33 +27,31 @@ #include #include +#include "GLRenderersManager.h" +#include "GLRenderer.h" -// -// Input: rect - initial rectangle -// name - window name -// resizingMode - example: B_FOLLOW_NONE -// mode - usually 0 ? -// options - Bitwise-OR of BGL_* tokens -// - -BGLView::BGLView(BRect rect, char *name, - ulong resizingMode, ulong mode, - ulong options) - : BView(rect, name, B_FOLLOW_ALL_SIDES, mode | B_WILL_DRAW | B_FRAME_EVENTS) // | B_FULL_UPDATE_ON_RESIZE) +BGLView::BGLView(BRect rect, char *name, ulong resizingMode, ulong mode, ulong options) + : BView(rect, name, B_FOLLOW_ALL_SIDES, mode | B_WILL_DRAW | B_FRAME_EVENTS), // | B_FULL_UPDATE_ON_RESIZE) + fRenderer(NULL) { } BGLView::~BGLView() { + delete fRenderer; } void BGLView::LockGL() { + if (fRenderer) + fRenderer->LockGL(); } void BGLView::UnlockGL() { + if (fRenderer) + fRenderer->UnlockGL(); } void BGLView::SwapBuffers() @@ -63,6 +61,8 @@ void BGLView::SwapBuffers() void BGLView::SwapBuffers(bool vSync) { + if (fRenderer) + fRenderer->SwapBuffers(vSync); } BView * BGLView::EmbeddedView() @@ -75,6 +75,9 @@ status_t BGLView::CopyPixelsOut(BPoint source, BBitmap *dest) if (! dest || ! dest->Bounds().IsValid()) return B_BAD_VALUE; + if (fRenderer) + return fRenderer->CopyPixelsOut(source, dest); + return B_ERROR; } @@ -83,6 +86,9 @@ status_t BGLView::CopyPixelsIn(BBitmap *source, BPoint dest) if (! source || ! source->Bounds().IsValid()) return B_BAD_VALUE; + if (fRenderer) + return fRenderer->CopyPixelsIn(source, dest); + return B_ERROR; } @@ -98,81 +104,100 @@ void BGLView::ErrorCallback(unsigned long errorCode) // Mesa's GLenum is not ulo void BGLView::Draw(BRect updateRect) { + if (fRenderer) + return fRenderer->Draw(updateRect); + + // TODO: auto-size and center the string + MovePenTo(8, 32); + DrawString("No OpenGL renderer available!"); } void BGLView::AttachedToWindow() { - BView::AttachedToWindow(); + BView::AttachedToWindow(); - // don't paint window background white when resized - SetViewColor(B_TRANSPARENT_32_BIT); + if (fRenderer) { + // Don't paint white window background when resized + SetViewColor(B_TRANSPARENT_32_BIT); + return fRenderer->AttachedToWindow(); + } + + // No Renderer, no rendering. Setup a minimal "No Renderer" string drawing context + SetFont(be_bold_font); + // SetFontSize(16); } void BGLView::AllAttached() { - BView::AllAttached(); + BView::AllAttached(); } void BGLView::DetachedFromWindow() { - BView::DetachedFromWindow(); + BView::DetachedFromWindow(); } void BGLView::AllDetached() { - BView::AllDetached(); + BView::AllDetached(); } void BGLView::FrameResized(float width, float height) { - return BView::FrameResized(width, height); + return BView::FrameResized(width, height); } status_t BGLView::Perform(perform_code d, void *arg) { - return BView::Perform(d, arg); + return BView::Perform(d, arg); } status_t BGLView::Archive(BMessage *data, bool deep) const { - return BView::Archive(data, deep); + return BView::Archive(data, deep); } void BGLView::MessageReceived(BMessage *msg) { - BView::MessageReceived(msg); + BView::MessageReceived(msg); } void BGLView::SetResizingMode(uint32 mode) { - BView::SetResizingMode(mode); + BView::SetResizingMode(mode); } void BGLView::Show() { - BView::Show(); + BView::Show(); } void BGLView::Hide() { - BView::Hide(); + BView::Hide(); } BHandler *BGLView::ResolveSpecifier(BMessage *msg, int32 index, BMessage *specifier, int32 form, const char *property) { - return BView::ResolveSpecifier(msg, index, specifier, form, property); + return BView::ResolveSpecifier(msg, index, specifier, form, property); } status_t BGLView::GetSupportedSuites(BMessage *data) { - return BView::GetSupportedSuites(data); + return BView::GetSupportedSuites(data); } void BGLView::DirectConnected( direct_buffer_info *info ) { + /* TODO: + - update local copy of caller's BDirectWindow's direct_buffer_info + - clip it against BGLView's visible region + - pass the view's clipped direct_buffer_info to renderer's DirectConnect() + */ + #if 0 if (! m_direct_connected && m_direct_connection_disabled) return; @@ -202,10 +227,15 @@ void BGLView::DirectConnected( direct_buffer_info *info ) } direct_info_locker->Unlock(); #endif + + if (fRenderer) + return fRenderer->DirectConnected(info); } void BGLView::EnableDirectMode( bool enabled ) { + if (fRenderer) + return fRenderer->EnableDirectMode(enabled); } diff --git a/src/kits/opengl/Jamfile b/src/kits/opengl/Jamfile index 0a0097b032..4ac0e495dd 100644 --- a/src/kits/opengl/Jamfile +++ b/src/kits/opengl/Jamfile @@ -39,6 +39,7 @@ SEARCH_SOURCE += [ FDirName $(SUBDIR) mesa $(TARGET_ARCH) ] ; SharedLibrary libGL.so : GLView.cpp GLDispatcher.cpp + GLRenderer.cpp # mesa/$(TARGET_ARCH) glapi_$(TARGET_ARCH).S