work in progress on Mesa renderer

TODO : reorganization for GLRenderer.h MesaRenderer.* and libmesa.a


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18765 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2006-09-05 16:00:15 +00:00
parent 69031529d4
commit 51f05ea6fc
5 changed files with 272 additions and 9 deletions
+88 -6
View File
@@ -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)
{
}
+7 -3
View File
@@ -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);
+7
View File
@@ -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
;
+127
View File
@@ -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;
}
+43
View File
@@ -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