diff --git a/src/kits/opengl/GLRenderer.cpp b/src/kits/opengl/GLRenderer.cpp index 20c11290f0..6989fbc408 100644 --- a/src/kits/opengl/GLRenderer.cpp +++ b/src/kits/opengl/GLRenderer.cpp @@ -1,29 +1,111 @@ +/* + * Copyright 2006, Philippe Houdoin. All rights reserved. + * Distributed under the terms of the MIT License. + */ + #include "GLRenderer.h" -void BGLRenderer::Acquire() +BGLRenderer::BGLRenderer(BGLView *view, ulong bgl_options, BGLDispatcher *dispatcher) +{ + +} + + +BGLRenderer::~BGLRenderer() +{ +} + +void +BGLRenderer::Acquire() { atomic_add(&fRefCount, 1); } -void BGLRenderer::Release() + +void +BGLRenderer::Release() { if (atomic_add(&fRefCount, -1) < 1) delete this; } -void BGLRenderer::LockGL() + +void +BGLRenderer::LockGL() { } -void BGLRenderer::UnlockGL() + +void +BGLRenderer::UnlockGL() { } -void BGLRenderer::DirectConnected(direct_buffer_info *info) + +void +BGLRenderer::SwapBuffers(bool VSync = false) { } -void BGLRenderer::EnableDirectMode(bool enabled) + +void +BGLRenderer::Draw(BRect updateRect) +{ +} + + +status_t +BGLRenderer::CopyPixelsOut(BPoint source, BBitmap *dest) +{ + return B_OK; +} + + +status_t +BGLRenderer::CopyPixelsIn(BBitmap *source, BPoint dest) +{ + return B_OK; +} + + +void +BGLRenderer::AttachedToWindow() +{ +} + + +void +BGLRenderer::AllAttached() +{ +} + + +void +BGLRenderer::DetachedFromWindow() +{ +} + + +void +BGLRenderer::AllDetached() +{ +} + + +void +BGLRenderer::FrameResized(float width, float height) +{ +} + + +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 0d8fe47161..fe383007c4 100644 --- a/src/kits/opengl/GLRenderer.h +++ b/src/kits/opengl/GLRenderer.h @@ -1,3 +1,7 @@ +/* + * Copyright 2006, Philippe Houdoin. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef GLRENDERER_H #define GLRENDERER_H @@ -20,10 +24,10 @@ public: void Acquire(); void Release(); - void LockGL(); - void UnlockGL(); + virtual void LockGL(); + virtual void UnlockGL(); - virtual void SwapBuffers(bool VSync = false) const; + virtual void SwapBuffers(bool VSync = false); virtual void Draw(BRect updateRect); virtual status_t CopyPixelsOut(BPoint source, BBitmap *dest); virtual status_t CopyPixelsIn(BBitmap *source, BPoint dest); diff --git a/src/kits/opengl/mesa/Jamfile b/src/kits/opengl/mesa/Jamfile index 7f2a554954..1b0b3809b3 100644 --- a/src/kits/opengl/mesa/Jamfile +++ b/src/kits/opengl/mesa/Jamfile @@ -9,6 +9,7 @@ if $(TARGET_PLATFORM) != haiku { UsePrivateHeaders opengl ; +UseHeaders [ FDirName $(SUBDIR) $(DOTDOT) ] ; UseHeaders [ FDirName $(SUBDIR) main ] ; UseHeaders [ FDirName $(SUBDIR) glapi ] ; UseHeaders [ FDirName $(SUBDIR) math ] ; @@ -40,6 +41,7 @@ SEARCH_SOURCE += [ FDirName $(SUBDIR) tnl ] ; defines = [ FDefines $(defines) ] ; SubDirCcFlags $(defines) ; SubDirC++Flags $(defines) ; + SubDirAsFlags $(defines) ; } local arch_sources ; @@ -246,3 +248,8 @@ StaticLibrary libmesa.a : glthread.c ; +Addon Mesa : opengl : + MesaRenderer.cpp + : false + : libmesa.a libGL.so be +; diff --git a/src/kits/opengl/mesa/MesaRenderer.cpp b/src/kits/opengl/mesa/MesaRenderer.cpp new file mode 100644 index 0000000000..15a869b096 --- /dev/null +++ b/src/kits/opengl/mesa/MesaRenderer.cpp @@ -0,0 +1,127 @@ +/* + * Copyright 2006, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + */ +/* + * Mesa 3-D graphics library + * Version: 6.1 + * + * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. + */ + +#include "MesaRenderer.h" + +extern const char * color_space_name(color_space space); + +MesaRenderer::MesaRenderer(BGLView *view, ulong bgl_options, BGLDispatcher *dispatcher) + : BGLRenderer(view, bgl_options, dispatcher), + fBitmap(NULL), + fContext(NULL), + fVisual(NULL), + fFrameBuffer(NULL) +{ + +} + +MesaRenderer::~MesaRenderer() +{ + _mesa_destroy_visual(fVisual); + _mesa_destroy_framebuffer(fFrameBuffer); + _mesa_destroy_context(fContext); + + delete fBitmap; +} + + +void +MesaRenderer::SwapBuffers(bool VSync = false) +{ + _mesa_notifySwapBuffers(fContext); + + if (fBitmap) { + GLView()->LockLooper(); + GLView()->DrawBitmap(fBitmap); + GLView()->UnlockLooper(); + } +} + + +void +MesaRenderer::Draw(BRect updateRect) +{ + if (fBitmap) + GLView()->DrawBitmap(fBitmap, updateRect, updateRect); +} + + +status_t +MesaRenderer::CopyPixelsOut(BPoint location, BBitmap *bitmap) +{ + color_space scs = fBitmap->ColorSpace(); + color_space dcs = bitmap->ColorSpace(); + + if (scs != dcs && (scs != B_RGBA32 || dcs != B_RGB32)) { + fprintf(stderr, "CopyPixelsOut(): incompatible color space: %s != %s\n", + color_space_name(scs), + color_space_name(dcs)); + return B_BAD_TYPE; + } + + BRect sr = fBitmap->Bounds(); + BRect dr = bitmap->Bounds(); + + sr = sr & dr.OffsetBySelf(location); + dr = sr.OffsetByCopy(-location.x, -location.y); + + uint8 *ps = (uint8 *) fBitmap->Bits(); + uint8 *pd = (uint8 *) bitmap->Bits(); + uint32 *s, *d; + uint32 y; + for (y = (uint32) sr.top; y <= (uint32) sr.bottom; y++) { + s = (uint32 *) (ps + y * fBitmap->BytesPerRow()); + s += (uint32) sr.left; + + d = (uint32 *) (pd + (y + (uint32) (dr.top - sr.top)) * bitmap->BytesPerRow()); + d += (uint32) dr.left; + + memcpy(d, s, dr.IntegerWidth() * 4); + } + return B_OK; +} + + +status_t +MesaRenderer::CopyPixelsIn(BBitmap *bitmap, BPoint location) +{ + color_space scs = bitmap->ColorSpace(); + color_space dcs = fBitmap->ColorSpace(); + + if (scs != dcs && (dcs != B_RGBA32 || scs != B_RGB32)) { + fprintf(stderr, "CopyPixelsIn(): incompatible color space: %s != %s\n", + color_space_name(scs), + color_space_name(dcs)); + return B_BAD_TYPE; + } + + BRect sr = bitmap->Bounds(); + BRect dr = fBitmap->Bounds(); + + sr = sr & dr.OffsetBySelf(location); + dr = sr.OffsetByCopy(-location.x, -location.y); + + uint8 *ps = (uint8 *) bitmap->Bits(); + uint8 *pd = (uint8 *) fBitmap->Bits(); + uint32 *s, *d; + uint32 y; + for (y = (uint32) sr.top; y <= (uint32) sr.bottom; y++) { + s = (uint32 *) (ps + y * bitmap->BytesPerRow()); + s += (uint32) sr.left; + + d = (uint32 *) (pd + (y + (uint32) (dr.top - sr.top)) * fBitmap->BytesPerRow()); + d += (uint32) dr.left; + + memcpy(d, s, dr.IntegerWidth() * 4); + } + return B_OK; +} + diff --git a/src/kits/opengl/mesa/MesaRenderer.h b/src/kits/opengl/mesa/MesaRenderer.h new file mode 100644 index 0000000000..73dde70d5b --- /dev/null +++ b/src/kits/opengl/mesa/MesaRenderer.h @@ -0,0 +1,43 @@ +/* + * Copyright 2006, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + */ +/* + * Mesa 3-D graphics library + * Version: 6.1 + * + * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. + */ +#ifndef MESARENDERER_H +#define MESARENDERER_H + +#include "GLRenderer.h" + +extern "C" { + +#include "context.h" + +} + +class MesaRenderer : public BGLRenderer +{ +public: + MesaRenderer(BGLView *view, ulong bgl_options, BGLDispatcher *dispatcher); + virtual ~MesaRenderer(); + + virtual void SwapBuffers(bool VSync = false); + virtual void Draw(BRect updateRect); + virtual status_t CopyPixelsOut(BPoint source, BBitmap *dest); + virtual status_t CopyPixelsIn(BBitmap *source, BPoint dest); + +private: + BBitmap *fBitmap; + + GLcontext *fContext; + GLvisual *fVisual; + GLframebuffer *fFrameBuffer; + +}; + +#endif // MESARENDERER_H +