rewrote GLView.h (left out BGLScreen for now, will integrate it later),
adapted GLView.cpp to the new variable naming scheme. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23716 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
2b5d39e859
commit
455a252e0d
@ -1,18 +1,14 @@
|
||||
/*******************************************************************************
|
||||
/
|
||||
/ File: GLView.h
|
||||
/
|
||||
/ Copyright 1993-98, Be Incorporated, All Rights Reserved.
|
||||
/
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
* Copyright 2008, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef BGLVIEW_H
|
||||
#define BGLVIEW_H
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
#define BGL_RGB 0
|
||||
#define BGL_INDEX 1
|
||||
#define BGL_INDEX 1
|
||||
#define BGL_SINGLE 0
|
||||
#define BGL_DOUBLE 2
|
||||
#define BGL_DIRECT 0
|
||||
@ -26,171 +22,99 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
|
||||
#include <AppKit.h>
|
||||
#include <interface/Window.h>
|
||||
#include <interface/View.h>
|
||||
#include <interface/Bitmap.h>
|
||||
#include <game/WindowScreen.h>
|
||||
#include <game/DirectWindow.h>
|
||||
#include <Bitmap.h>
|
||||
#include <DirectWindow.h>
|
||||
#include <View.h>
|
||||
#include <Window.h>
|
||||
#include <WindowScreen.h>
|
||||
|
||||
class BGLRenderer;
|
||||
class GLRendererRoster;
|
||||
|
||||
class BGLView : public BView {
|
||||
public:
|
||||
|
||||
BGLView(BRect rect, char *name,
|
||||
ulong resizingMode, ulong mode,
|
||||
ulong options);
|
||||
virtual ~BGLView();
|
||||
|
||||
void LockGL();
|
||||
void UnlockGL();
|
||||
void SwapBuffers();
|
||||
void SwapBuffers( bool vSync );
|
||||
BView * EmbeddedView();
|
||||
status_t CopyPixelsOut(BPoint source, BBitmap *dest);
|
||||
status_t CopyPixelsIn(BBitmap *source, BPoint dest);
|
||||
virtual void ErrorCallback(unsigned long errorCode); // Mesa's GLenum is uint where Be's ones was ulong!
|
||||
virtual ~BGLView();
|
||||
|
||||
void LockGL();
|
||||
void UnlockGL();
|
||||
void SwapBuffers();
|
||||
void SwapBuffers(bool vSync);
|
||||
|
||||
virtual void Draw(BRect updateRect);
|
||||
BView* EmbeddedView(); // deprecated, returns NULL
|
||||
|
||||
status_t CopyPixelsOut(BPoint source, BBitmap *dest);
|
||||
status_t CopyPixelsIn(BBitmap *source, BPoint dest);
|
||||
|
||||
// Mesa's GLenum is uint where Be's ones was ulong!
|
||||
virtual void ErrorCallback(unsigned long errorCode);
|
||||
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void AttachedToWindow();
|
||||
virtual void AllAttached();
|
||||
virtual void DetachedFromWindow();
|
||||
virtual void AllDetached();
|
||||
|
||||
virtual void FrameResized(float newWidth, float newHeight);
|
||||
virtual status_t Perform(perform_code d, void *arg);
|
||||
|
||||
virtual status_t Archive(BMessage *data, bool deep = true) const;
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void AllAttached();
|
||||
virtual void DetachedFromWindow();
|
||||
virtual void AllDetached();
|
||||
|
||||
virtual void FrameResized(float width, float height);
|
||||
virtual status_t Perform(perform_code d, void *arg);
|
||||
|
||||
/* The public methods below, for the moment,
|
||||
are just pass-throughs to BView */
|
||||
|
||||
virtual status_t Archive(BMessage *data, bool deep = true) const;
|
||||
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
virtual void SetResizingMode(uint32 mode);
|
||||
|
||||
virtual void Show();
|
||||
virtual void Hide();
|
||||
|
||||
virtual BHandler *ResolveSpecifier(BMessage *msg, int32 index,
|
||||
BMessage *specifier, int32 form,
|
||||
const char *property);
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
virtual void SetResizingMode(uint32 mode);
|
||||
|
||||
virtual void Show();
|
||||
virtual void Hide();
|
||||
|
||||
virtual BHandler* ResolveSpecifier(BMessage *msg, int32 index,
|
||||
BMessage *specifier, int32 form,
|
||||
const char *property);
|
||||
virtual status_t GetSupportedSuites(BMessage *data);
|
||||
|
||||
/* New public functions */
|
||||
void DirectConnected( direct_buffer_info *info );
|
||||
void EnableDirectMode( bool enabled );
|
||||
void DirectConnected(direct_buffer_info *info);
|
||||
void EnableDirectMode(bool enabled);
|
||||
|
||||
void * getGC() { return m_gc; }
|
||||
|
||||
void* getGC() { return fGc; } // ???
|
||||
private:
|
||||
|
||||
virtual void _ReservedGLView1();
|
||||
virtual void _ReservedGLView2();
|
||||
virtual void _ReservedGLView3();
|
||||
virtual void _ReservedGLView4();
|
||||
virtual void _ReservedGLView5();
|
||||
virtual void _ReservedGLView6();
|
||||
virtual void _ReservedGLView7();
|
||||
virtual void _ReservedGLView8();
|
||||
|
||||
virtual void _ReservedGLView1();
|
||||
virtual void _ReservedGLView2();
|
||||
virtual void _ReservedGLView3();
|
||||
virtual void _ReservedGLView4();
|
||||
virtual void _ReservedGLView5();
|
||||
virtual void _ReservedGLView6();
|
||||
virtual void _ReservedGLView7();
|
||||
virtual void _ReservedGLView8();
|
||||
|
||||
BGLView(const BGLView &);
|
||||
BGLView &operator=(const BGLView &);
|
||||
BGLView &operator=(const BGLView &);
|
||||
|
||||
void dither_front();
|
||||
bool confirm_dither();
|
||||
void draw(BRect r);
|
||||
void _DitherFront();
|
||||
bool _ConfirmDither();
|
||||
void _Draw(BRect rect);
|
||||
|
||||
void * fGc;
|
||||
uint32 fOptions;
|
||||
uint32 fDitherCount;
|
||||
BLocker fDrawLock;
|
||||
BLocker fDisplayLock;
|
||||
void * fClipInfo;
|
||||
|
||||
void * m_gc;
|
||||
uint32 m_options;
|
||||
uint32 m_ditherCount;
|
||||
BLocker m_drawLock;
|
||||
BLocker m_displayLock;
|
||||
void * m_clip_info;
|
||||
BGLRenderer *fRenderer;
|
||||
GLRendererRoster *fRoster;
|
||||
|
||||
BBitmap * m_ditherMap;
|
||||
BRect m_bounds;
|
||||
int16 * m_errorBuffer[2];
|
||||
BBitmap * fDitherMap;
|
||||
BRect fBounds;
|
||||
int16 * fErrorBuffer[2];
|
||||
uint64 _reserved[8];
|
||||
|
||||
/* Direct Window stuff */
|
||||
private:
|
||||
void drawScanline( int x1, int x2, int y, void *data );
|
||||
static void scanlineHandler(struct rasStateRec *state, GLint x1, GLint x2);
|
||||
|
||||
void lock_draw();
|
||||
void unlock_draw();
|
||||
bool validateView();
|
||||
|
||||
void _LockDraw();
|
||||
void _UnlockDraw();
|
||||
};
|
||||
|
||||
|
||||
|
||||
class BGLScreen : public BWindowScreen {
|
||||
public:
|
||||
BGLScreen(char *name,
|
||||
ulong screenMode, ulong options,
|
||||
status_t *error, bool debug=false);
|
||||
~BGLScreen();
|
||||
|
||||
void LockGL();
|
||||
void UnlockGL();
|
||||
void SwapBuffers();
|
||||
virtual void ErrorCallback(unsigned long errorCode); // Mesa's GLenum is uint where Be's ones was ulong!
|
||||
|
||||
virtual void ScreenConnected(bool connected);
|
||||
virtual void FrameResized(float width, float height);
|
||||
virtual status_t Perform(perform_code d, void *arg);
|
||||
|
||||
/* The public methods below, for the moment,
|
||||
are just pass-throughs to BWindowScreen */
|
||||
|
||||
virtual status_t Archive(BMessage *data, bool deep = true) const;
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
|
||||
virtual void Show();
|
||||
virtual void Hide();
|
||||
|
||||
virtual BHandler *ResolveSpecifier(BMessage *msg,
|
||||
int32 index,
|
||||
BMessage *specifier,
|
||||
int32 form,
|
||||
const char *property);
|
||||
virtual status_t GetSupportedSuites(BMessage *data);
|
||||
|
||||
private:
|
||||
|
||||
virtual void _ReservedGLScreen1();
|
||||
virtual void _ReservedGLScreen2();
|
||||
virtual void _ReservedGLScreen3();
|
||||
virtual void _ReservedGLScreen4();
|
||||
virtual void _ReservedGLScreen5();
|
||||
virtual void _ReservedGLScreen6();
|
||||
virtual void _ReservedGLScreen7();
|
||||
virtual void _ReservedGLScreen8();
|
||||
|
||||
BGLScreen(const BGLScreen &);
|
||||
BGLScreen &operator=(const BGLScreen &);
|
||||
|
||||
void * m_gc;
|
||||
long m_options;
|
||||
BLocker m_drawLock;
|
||||
#endif // __cplusplus
|
||||
|
||||
int32 m_colorSpace;
|
||||
uint32 m_screen_mode;
|
||||
|
||||
uint64 _reserved[7];
|
||||
};
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // BGLVIEW_H
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // BGLVIEW_H
|
||||
|
@ -56,8 +56,15 @@ struct glview_direct_info {
|
||||
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)
|
||||
m_clip_info(NULL),
|
||||
fRenderer(NULL)
|
||||
fGc(NULL),
|
||||
fOptions(options),
|
||||
fDitherCount(0),
|
||||
fDrawLock("BGLView draw lock"),
|
||||
fDisplayLock("BGLView display lock"),
|
||||
fClipInfo(NULL),
|
||||
fRenderer(NULL),
|
||||
fRoster(NULL),
|
||||
fDitherMap(NULL)
|
||||
{
|
||||
fRoster = new GLRendererRoster(this, options);
|
||||
}
|
||||
@ -65,7 +72,7 @@ BGLView::BGLView(BRect rect, char *name, ulong resizingMode, ulong mode,
|
||||
|
||||
BGLView::~BGLView()
|
||||
{
|
||||
delete (glview_direct_info *)m_clip_info;
|
||||
delete (glview_direct_info *)fClipInfo;
|
||||
if (fRenderer)
|
||||
fRenderer->Release();
|
||||
}
|
||||
@ -104,9 +111,9 @@ void
|
||||
BGLView::SwapBuffers(bool vSync)
|
||||
{
|
||||
if (fRenderer) {
|
||||
lock_draw();
|
||||
_LockDraw();
|
||||
fRenderer->SwapBuffers(vSync);
|
||||
unlock_draw();
|
||||
_UnlockDraw();
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,9 +170,9 @@ void
|
||||
BGLView::Draw(BRect updateRect)
|
||||
{
|
||||
if (fRenderer) {
|
||||
lock_draw();
|
||||
_LockDraw();
|
||||
fRenderer->Draw(updateRect);
|
||||
unlock_draw();
|
||||
_UnlockDraw();
|
||||
return;
|
||||
}
|
||||
// TODO: auto-size and center the string
|
||||
@ -179,9 +186,9 @@ BGLView::AttachedToWindow()
|
||||
{
|
||||
BView::AttachedToWindow();
|
||||
|
||||
m_bounds = Bounds();
|
||||
fBounds = Bounds();
|
||||
for (BView *view = this; view != NULL; view = view->Parent())
|
||||
view->ConvertToParent(&m_bounds);
|
||||
view->ConvertToParent(&fBounds);
|
||||
|
||||
fRenderer = fRoster->GetRenderer();
|
||||
if (fRenderer != NULL) {
|
||||
@ -199,11 +206,11 @@ BGLView::AttachedToWindow()
|
||||
// Set default OpenGL viewport:
|
||||
glViewport(0, 0, Bounds().IntegerWidth(), Bounds().IntegerHeight());
|
||||
|
||||
if (m_clip_info) {
|
||||
if (fClipInfo) {
|
||||
fRenderer->DirectConnected(
|
||||
((glview_direct_info *)m_clip_info)->direct_info);
|
||||
((glview_direct_info *)fClipInfo)->direct_info);
|
||||
fRenderer->EnableDirectMode(
|
||||
((glview_direct_info *)m_clip_info)->enable_direct_mode);
|
||||
((glview_direct_info *)fClipInfo)->enable_direct_mode);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -246,9 +253,9 @@ BGLView::AllDetached()
|
||||
void
|
||||
BGLView::FrameResized(float width, float height)
|
||||
{
|
||||
m_bounds = Bounds();
|
||||
fBounds = Bounds();
|
||||
for (BView *v = this; v; v = v->Parent())
|
||||
v->ConvertToParent(&m_bounds);
|
||||
v->ConvertToParent(&fBounds);
|
||||
|
||||
if (fRenderer)
|
||||
fRenderer->FrameResized(width, height);
|
||||
@ -318,17 +325,17 @@ BGLView::GetSupportedSuites(BMessage *data)
|
||||
void
|
||||
BGLView::DirectConnected(direct_buffer_info *info)
|
||||
{
|
||||
if (!m_clip_info/* && m_direct_connection_disabled*/) {
|
||||
m_clip_info = new glview_direct_info();
|
||||
if (!fClipInfo/* && m_direct_connection_disabled*/) {
|
||||
fClipInfo = new glview_direct_info();
|
||||
}
|
||||
|
||||
glview_direct_info *glviewDirectInfo = (glview_direct_info *)m_clip_info;
|
||||
glview_direct_info *glviewDirectInfo = (glview_direct_info *)fClipInfo;
|
||||
direct_buffer_info *localInfo = glviewDirectInfo->direct_info;
|
||||
|
||||
switch(info->buffer_state & B_DIRECT_MODE_MASK) {
|
||||
case B_DIRECT_START:
|
||||
glviewDirectInfo->direct_connected = true;
|
||||
unlock_draw();
|
||||
_UnlockDraw();
|
||||
case B_DIRECT_MODIFY:
|
||||
{
|
||||
localInfo->buffer_state = info->buffer_state;
|
||||
@ -348,7 +355,7 @@ BGLView::DirectConnected(direct_buffer_info *info)
|
||||
BRegion region;
|
||||
for (uint32 c = 0; c < info->clip_list_count; c++)
|
||||
region.Include(info->clip_list[c]);
|
||||
BRegion boundsRegion = m_bounds.OffsetByCopy(info->window_bounds.left, info->window_bounds.top);
|
||||
BRegion boundsRegion = fBounds.OffsetByCopy(info->window_bounds.left, info->window_bounds.top);
|
||||
localInfo->window_bounds = boundsRegion.RectAtInt(0); // window_bounds are now view bounds
|
||||
region.IntersectWith(&boundsRegion);
|
||||
|
||||
@ -362,7 +369,7 @@ BGLView::DirectConnected(direct_buffer_info *info)
|
||||
}
|
||||
case B_DIRECT_STOP:
|
||||
glviewDirectInfo->direct_connected = false;
|
||||
lock_draw();
|
||||
_LockDraw();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -376,34 +383,34 @@ BGLView::EnableDirectMode(bool enabled)
|
||||
{
|
||||
if (fRenderer)
|
||||
fRenderer->EnableDirectMode(enabled);
|
||||
if (!m_clip_info) {
|
||||
m_clip_info = new glview_direct_info();
|
||||
}
|
||||
((glview_direct_info *)m_clip_info)->enable_direct_mode = enabled;
|
||||
if (!fClipInfo) {
|
||||
fClipInfo = new glview_direct_info();
|
||||
}
|
||||
((glview_direct_info *)fClipInfo)->enable_direct_mode = enabled;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BGLView::lock_draw()
|
||||
BGLView::_LockDraw()
|
||||
{
|
||||
glview_direct_info *info = (glview_direct_info *)m_clip_info;
|
||||
glview_direct_info *info = (glview_direct_info *)fClipInfo;
|
||||
|
||||
if (!info || !info->enable_direct_mode)
|
||||
return;
|
||||
|
||||
m_drawLock.Lock();
|
||||
fDrawLock.Lock();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BGLView::unlock_draw()
|
||||
BGLView::_UnlockDraw()
|
||||
{
|
||||
glview_direct_info *info = (glview_direct_info *)m_clip_info;
|
||||
glview_direct_info *info = (glview_direct_info *)fClipInfo;
|
||||
|
||||
if (!info || !info->enable_direct_mode)
|
||||
return;
|
||||
|
||||
m_drawLock.Unlock();
|
||||
fDrawLock.Unlock();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user