First small step toward OpenGL renderers interface.

Our libGL.so GLView is still a stub, drawing "No OpenGL renderer available!"
instead ;-)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17406 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin
2006-05-09 21:56:08 +00:00
parent 925479d7b3
commit 3f70d609a9
6 changed files with 123 additions and 187 deletions
+4 -4
View File
@@ -79,23 +79,23 @@ extern "C" {
#include "GLDispatcher.h" #include "GLDispatcher.h"
GLDispatcher::GLDispatcher() BGLDispatcher::BGLDispatcher()
{ {
} }
GLDispatcher::~GLDispatcher() BGLDispatcher::~BGLDispatcher()
{ {
} }
status_t status_t
GLDispatcher::CheckTable(const struct _glapi_table *table) BGLDispatcher::CheckTable(const struct _glapi_table *table)
{ {
_glapi_check_table(table ? table : _glapi_get_dispatch()); _glapi_check_table(table ? table : _glapi_get_dispatch());
return B_OK; return B_OK;
} }
status_t status_t
GLDispatcher::SetTable(struct _glapi_table *table) BGLDispatcher::SetTable(struct _glapi_table *table)
{ {
_glapi_set_dispatch(table); _glapi_set_dispatch(table);
return B_OK; return B_OK;
+13 -13
View File
@@ -9,15 +9,15 @@ extern "C" {
#include "glapi.h" #include "glapi.h"
} }
class GLDispatcher class BGLDispatcher
{ {
// Private unimplemented copy constructors // Private unimplemented copy constructors
GLDispatcher(const GLDispatcher &); BGLDispatcher(const BGLDispatcher &);
GLDispatcher & operator=(const GLDispatcher &); BGLDispatcher & operator=(const BGLDispatcher &);
public: public:
GLDispatcher(); BGLDispatcher();
~GLDispatcher(); ~BGLDispatcher();
const char * Version(); const char * Version();
@@ -36,49 +36,49 @@ class GLDispatcher
}; };
// Inlines methods // Inlines methods
inline const char * GLDispatcher::Version() inline const char * BGLDispatcher::Version()
{ {
return _glapi_get_version(); return _glapi_get_version();
} }
inline void GLDispatcher::SetCurrentContext(void * context) inline void BGLDispatcher::SetCurrentContext(void * context)
{ {
_glapi_set_context(context); _glapi_set_context(context);
} }
inline void * GLDispatcher::CurrentContext() inline void * BGLDispatcher::CurrentContext()
{ {
return _glapi_get_context(); return _glapi_get_context();
} }
inline struct _glapi_table * GLDispatcher::Table() inline struct _glapi_table * BGLDispatcher::Table()
{ {
return _glapi_get_dispatch(); return _glapi_get_dispatch();
} }
inline uint32 GLDispatcher::TableSize() inline uint32 BGLDispatcher::TableSize()
{ {
return _glapi_get_dispatch_table_size(); 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); 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); 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); return (uint32) _glapi_get_proc_offset(function_name);
} }
+18
View File
@@ -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)
{
}
+28 -141
View File
@@ -2,161 +2,48 @@
#define GLRENDERER_H #define GLRENDERER_H
#include <BeBuild.h> #include <BeBuild.h>
#include <GLView.h>
class GLDispatcher; class BGLDispatcher;
class GLRenderer class BGLRenderer
{ {
// Private unimplemented copy constructors // Private unimplemented copy constructors
GLRenderer(const GLRenderer &); BGLRenderer(const BGLRenderer &);
GLRenderer & operator=(const GLRenderer &); BGLRenderer & operator=(const BGLRenderer &);
public: public:
GLRenderer(); BGLRenderer(BGLView *view, BGLDispatcher *dispatcher);
~GLRenderer(); virtual ~BGLRenderer();
void Init(BGLView * bglview, GLcontext * c, GLvisual * v, GLframebuffer * b); status_t Acquire();
status_t Release();
void LockGL(); void LockGL();
void UnlockGL(); void UnlockGL();
void SwapBuffers(bool VSync = false) const;
void Draw(BRect updateRect) const; 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: private:
MesaDriver(const MesaDriver &rhs); // copy constructor illegal uint32 fRefCount;
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[]);
}; };
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 #endif // GLRENDERER_H
+43 -13
View File
@@ -27,33 +27,31 @@
#include <stdio.h> #include <stdio.h>
#include <GLView.h> #include <GLView.h>
#include "GLRenderersManager.h"
#include "GLRenderer.h"
// BGLView::BGLView(BRect rect, char *name, ulong resizingMode, ulong mode, ulong options)
// Input: rect - initial rectangle : BView(rect, name, B_FOLLOW_ALL_SIDES, mode | B_WILL_DRAW | B_FRAME_EVENTS), // | B_FULL_UPDATE_ON_RESIZE)
// name - window name fRenderer(NULL)
// 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() BGLView::~BGLView()
{ {
delete fRenderer;
} }
void BGLView::LockGL() void BGLView::LockGL()
{ {
if (fRenderer)
fRenderer->LockGL();
} }
void BGLView::UnlockGL() void BGLView::UnlockGL()
{ {
if (fRenderer)
fRenderer->UnlockGL();
} }
void BGLView::SwapBuffers() void BGLView::SwapBuffers()
@@ -63,6 +61,8 @@ void BGLView::SwapBuffers()
void BGLView::SwapBuffers(bool vSync) void BGLView::SwapBuffers(bool vSync)
{ {
if (fRenderer)
fRenderer->SwapBuffers(vSync);
} }
BView * BGLView::EmbeddedView() BView * BGLView::EmbeddedView()
@@ -75,6 +75,9 @@ status_t BGLView::CopyPixelsOut(BPoint source, BBitmap *dest)
if (! dest || ! dest->Bounds().IsValid()) if (! dest || ! dest->Bounds().IsValid())
return B_BAD_VALUE; return B_BAD_VALUE;
if (fRenderer)
return fRenderer->CopyPixelsOut(source, dest);
return B_ERROR; return B_ERROR;
} }
@@ -83,6 +86,9 @@ status_t BGLView::CopyPixelsIn(BBitmap *source, BPoint dest)
if (! source || ! source->Bounds().IsValid()) if (! source || ! source->Bounds().IsValid())
return B_BAD_VALUE; return B_BAD_VALUE;
if (fRenderer)
return fRenderer->CopyPixelsIn(source, dest);
return B_ERROR; return B_ERROR;
} }
@@ -98,14 +104,27 @@ void BGLView::ErrorCallback(unsigned long errorCode) // Mesa's GLenum is not ulo
void BGLView::Draw(BRect updateRect) 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() void BGLView::AttachedToWindow()
{ {
BView::AttachedToWindow(); BView::AttachedToWindow();
// don't paint window background white when resized if (fRenderer) {
// Don't paint white window background when resized
SetViewColor(B_TRANSPARENT_32_BIT); 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() void BGLView::AllAttached()
@@ -173,6 +192,12 @@ status_t BGLView::GetSupportedSuites(BMessage *data)
void BGLView::DirectConnected( direct_buffer_info *info ) 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 0
if (! m_direct_connected && m_direct_connection_disabled) if (! m_direct_connected && m_direct_connection_disabled)
return; return;
@@ -202,10 +227,15 @@ void BGLView::DirectConnected( direct_buffer_info *info )
} }
direct_info_locker->Unlock(); direct_info_locker->Unlock();
#endif #endif
if (fRenderer)
return fRenderer->DirectConnected(info);
} }
void BGLView::EnableDirectMode( bool enabled ) void BGLView::EnableDirectMode( bool enabled )
{ {
if (fRenderer)
return fRenderer->EnableDirectMode(enabled);
} }
+1
View File
@@ -39,6 +39,7 @@ SEARCH_SOURCE += [ FDirName $(SUBDIR) mesa $(TARGET_ARCH) ] ;
SharedLibrary libGL.so : SharedLibrary libGL.so :
GLView.cpp GLView.cpp
GLDispatcher.cpp GLDispatcher.cpp
GLRenderer.cpp
# mesa/$(TARGET_ARCH) # mesa/$(TARGET_ARCH)
glapi_$(TARGET_ARCH).S glapi_$(TARGET_ARCH).S