window_bounds are now coordinates of the view on the screen (was the window before)
this eases dramatically the drawing of the clip from the buffer
now allocates m_clip_info whenever needed as some apps call EnableDirectMode() after DirectConnected(), ie GLTeapot.
MesaSoftwareRenderer:
implemented DirectConnected() support in Mesa Software Renderer
tested with GLTeapot on QEmu, B_RGB16 mode only


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20797 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2007-04-24 17:37:51 +00:00
parent f8486a0219
commit 7cfdfca2e2
3 changed files with 289 additions and 173 deletions
@@ -4,69 +4,71 @@
* *
* Authors: * Authors:
* Jérôme Duval, [email protected] * Jérôme Duval, [email protected]
* Philippe Houdoin, [email protected] * Philippe Houdoin, [email protected]
*/ */
/* /*
* Mesa 3-D graphics library * Mesa 3-D graphics library
* Version: 6.1 * Version: 6.1
* *
* Copyright (C) 1999-2004 Brian Paul All Rights Reserved. * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
*/ */
#define CALLED() //printf("CALLED %s\n",__PRETTY_FUNCTION__) #define CALLED() //printf("CALLED %s\n",__PRETTY_FUNCTION__)
#include "MesaSoftwareRenderer.h" #include "MesaSoftwareRenderer.h"
#include <GraphicsDefs.h>
#include <Screen.h>
extern "C" { extern "C" {
#include "array_cache/acache.h" #include "array_cache/acache.h"
#include "extensions.h" #include "extensions.h"
#include "drivers/common/driverfuncs.h" #include "drivers/common/driverfuncs.h"
#include "main/colormac.h" #include "main/colormac.h"
#include "main/buffers.h" #include "main/buffers.h"
#include "main/framebuffer.h" #include "main/framebuffer.h"
#include "main/renderbuffer.h" #include "main/renderbuffer.h"
#include "main/state.h" #include "main/state.h"
#include "main/version.h" #include "main/version.h"
#include "swrast/swrast.h" #include "swrast/swrast.h"
#include "swrast_setup/swrast_setup.h" #include "swrast_setup/swrast_setup.h"
#include "tnl/tnl.h" #include "tnl/tnl.h"
#include "tnl/t_context.h" #include "tnl/t_context.h"
#include "tnl/t_pipeline.h" #include "tnl/t_pipeline.h"
#if defined(USE_X86_ASM)
#include "x86/common_x86_asm.h"
#endif
#if defined(USE_PPC_ASM)
#include "ppc/common_ppc_features.h" #if defined(USE_X86_ASM)
#endif #include "x86/common_x86_asm.h"
#endif
#if defined(USE_PPC_ASM)
#include "ppc/common_ppc_features.h"
#endif
} }
extern const char * color_space_name(color_space space); extern const char * color_space_name(color_space space);
// BeOS component ordering for B_RGBA32 bitmap format // BeOS component ordering for B_RGBA32 bitmap format
#if B_HOST_IS_LENDIAN #if B_HOST_IS_LENDIAN
#define BE_RCOMP 2 #define BE_RCOMP 2
#define BE_GCOMP 1 #define BE_GCOMP 1
#define BE_BCOMP 0 #define BE_BCOMP 0
#define BE_ACOMP 3 #define BE_ACOMP 3
#define PACK_B_RGBA32(color) (color[BCOMP] | (color[GCOMP] << 8) | \ #define PACK_B_RGBA32(color) (color[BCOMP] | (color[GCOMP] << 8) | \
(color[RCOMP] << 16) | (color[ACOMP] << 24)) (color[RCOMP] << 16) | (color[ACOMP] << 24))
#define PACK_B_RGB32(color) (color[BCOMP] | (color[GCOMP] << 8) | \ #define PACK_B_RGB32(color) (color[BCOMP] | (color[GCOMP] << 8) | \
(color[RCOMP] << 16) | 0xFF000000) (color[RCOMP] << 16) | 0xFF000000)
#else #else
// Big Endian B_RGBA32 bitmap format // Big Endian B_RGBA32 bitmap format
#define BE_RCOMP 1 #define BE_RCOMP 1
#define BE_GCOMP 2 #define BE_GCOMP 2
#define BE_BCOMP 3 #define BE_BCOMP 3
#define BE_ACOMP 0 #define BE_ACOMP 0
#define PACK_B_RGBA32(color) (color[ACOMP] | (color[RCOMP] << 8) | \ #define PACK_B_RGBA32(color) (color[ACOMP] | (color[RCOMP] << 8) | \
(color[GCOMP] << 16) | (color[BCOMP] << 24)) (color[GCOMP] << 16) | (color[BCOMP] << 24))
#define PACK_B_RGB32(color) ((color[RCOMP] << 8) | (color[GCOMP] << 16) | \ #define PACK_B_RGB32(color) ((color[RCOMP] << 8) | (color[GCOMP] << 16) | \
(color[BCOMP] << 24) | 0xFF000000) (color[BCOMP] << 24) | 0xFF000000)
#endif #endif
@@ -99,8 +101,28 @@ extern const char * color_space_name(color_space space);
DST[ACOMP] = SRC[BE_ACOMP] DST[ACOMP] = SRC[BE_ACOMP]
#include "swrast/s_spantemp.h" #include "swrast/s_spantemp.h"
extern "C" _EXPORT BGLRenderer * /* 16-bit RGB */
instanciate_gl_renderer(BGLView *view, ulong options, BGLDispatcher *dispatcher) #define NAME(PREFIX) PREFIX##_RGB16
#define RB_TYPE GLubyte
#define SPAN_VARS \
MesaSoftwareRenderer *mr = (MesaSoftwareRenderer *) ctx->DriverCtx;
#define INIT_PIXEL_PTR(P, X, Y) \
GLushort *P = (GLushort *) (((GLubyte **) mr->GetRows())[Y] + (X) * 2)
#define INC_PIXEL_PTR(P) P += 1
#define STORE_PIXEL(DST, X, Y, VALUE) \
*DST = ( (((VALUE[RCOMP]) & 0xf8) << 8) | \
(((VALUE[GCOMP]) & 0xfc) << 3) | \
(((VALUE[BCOMP]) ) >> 3) )
#define FETCH_PIXEL(DST, SRC) \
DST[RCOMP] = ((*SRC & 0xf800) >> 8); \
DST[GCOMP] = ((*SRC & 0x07e0) >> 3); \
DST[BCOMP] = ((*SRC & 0x001f) << 3); \
DST[ACOMP] = 0xff
#include "swrast/s_spantemp.h"
extern "C" _EXPORT BGLRenderer *
instanciate_gl_renderer(BGLView *view, ulong options, BGLDispatcher *dispatcher)
{ {
return new MesaSoftwareRenderer(view, options, dispatcher); return new MesaSoftwareRenderer(view, options, dispatcher);
} }
@@ -109,9 +131,12 @@ instanciate_gl_renderer(BGLView *view, ulong options, BGLDispatcher *dispatcher)
MesaSoftwareRenderer::MesaSoftwareRenderer(BGLView *view, ulong options, BGLDispatcher *dispatcher) MesaSoftwareRenderer::MesaSoftwareRenderer(BGLView *view, ulong options, BGLDispatcher *dispatcher)
: BGLRenderer(view, options, dispatcher), : BGLRenderer(view, options, dispatcher),
fBitmap(NULL), fBitmap(NULL),
fDirectModeEnabled(false),
fInfo(NULL),
fContext(NULL), fContext(NULL),
fVisual(NULL), fVisual(NULL),
fFrameBuffer(NULL) fFrameBuffer(NULL),
fColorSpace(B_NO_COLOR_SPACE)
{ {
CALLED(); CALLED();
@@ -141,19 +166,19 @@ MesaSoftwareRenderer::MesaSoftwareRenderer(BGLView *view, ulong options, BGLDisp
//fOptions = options | BGL_INDIRECT; //fOptions = options | BGL_INDIRECT;
struct dd_function_table functions; struct dd_function_table functions;
fVisual = _mesa_create_visual( rgbFlag, dblFlag, stereoFlag, red, green, blue, alpha, fVisual = _mesa_create_visual(rgbFlag, dblFlag, stereoFlag, red, green, blue, alpha,
index, depth, stencil, accum, accum, accum, alpha ? accum : 0, 1); index, depth, stencil, accum, accum, accum, alpha ? accum : 0, 1);
// Initialize device driver function table // Initialize device driver function table
_mesa_init_driver_functions(&functions); _mesa_init_driver_functions(&functions);
functions.GetString = GetString; functions.GetString = GetString;
functions.UpdateState = UpdateState; functions.UpdateState = UpdateState;
functions.Clear = Clear; //functions.Clear = Clear;
functions.ClearIndex = ClearIndex; //functions.ClearIndex = ClearIndex;
functions.ClearColor = ClearColor; //functions.ClearColor = ClearColor;
functions.Error = Error; functions.Error = Error;
functions.Viewport = Viewport; functions.Viewport = Viewport;
// create core context // create core context
fContext = _mesa_create_context(fVisual, NULL, &functions, this); fContext = _mesa_create_context(fVisual, NULL, &functions, this);
@@ -180,32 +205,45 @@ MesaSoftwareRenderer::MesaSoftwareRenderer(BGLView *view, ulong options, BGLDisp
fRenderBuffer->Data = NULL; fRenderBuffer->Data = NULL;
fRenderBuffer->AllocStorage = RenderbufferStorage; fRenderBuffer->AllocStorage = RenderbufferStorage;
fRenderBuffer->GetRow = get_row_RGBA8; /*switch (fColorSpace) {
fRenderBuffer->GetValues = get_values_RGBA8; case B_RGBA32:
fRenderBuffer->PutRow = put_row_RGBA8; fRenderBuffer->GetRow = get_row_RGBA8;
fRenderBuffer->PutRowRGB = put_row_rgb_RGBA8; fRenderBuffer->GetValues = get_values_RGBA8;
fRenderBuffer->PutMonoRow = put_mono_row_RGBA8; fRenderBuffer->PutRow = put_row_RGBA8;
fRenderBuffer->PutValues = put_values_RGBA8; fRenderBuffer->PutRowRGB = put_row_rgb_RGBA8;
fRenderBuffer->PutMonoValues = put_mono_values_RGBA8; fRenderBuffer->PutMonoRow = put_mono_row_RGBA8;
fRenderBuffer->PutValues = put_values_RGBA8;
fRenderBuffer->PutMonoValues = put_mono_values_RGBA8;
break;
case B_RGB16:
fRenderBuffer->GetRow = get_row_RGB16;
fRenderBuffer->GetValues = get_values_RGB16;
fRenderBuffer->PutRow = put_row_RGB16;
fRenderBuffer->PutRowRGB = put_row_rgb_RGB16;
fRenderBuffer->PutMonoRow = put_mono_row_RGB16;
fRenderBuffer->PutValues = put_values_RGB16;
fRenderBuffer->PutMonoValues = put_mono_values_RGB16;
break;
}*/
_mesa_add_renderbuffer(fFrameBuffer, BUFFER_FRONT_LEFT, fRenderBuffer); _mesa_add_renderbuffer(fFrameBuffer, BUFFER_FRONT_LEFT, fRenderBuffer);
_mesa_add_soft_renderbuffers(fFrameBuffer, _mesa_add_soft_renderbuffers(fFrameBuffer,
GL_FALSE, GL_FALSE,
fVisual->haveDepthBuffer, fVisual->haveDepthBuffer,
fVisual->haveStencilBuffer, fVisual->haveStencilBuffer,
fVisual->haveAccumBuffer, fVisual->haveAccumBuffer,
alphaFlag, alphaFlag,
GL_FALSE ); GL_FALSE);
// Use default TCL pipeline // Use default TCL pipeline
TNL_CONTEXT( fContext )->Driver.RunPipeline = _tnl_run_pipeline; TNL_CONTEXT(fContext)->Driver.RunPipeline = _tnl_run_pipeline;
_mesa_enable_sw_extensions(fContext); _mesa_enable_sw_extensions(fContext);
_mesa_enable_1_3_extensions(fContext); _mesa_enable_1_3_extensions(fContext);
_mesa_enable_1_4_extensions(fContext); _mesa_enable_1_4_extensions(fContext);
_mesa_enable_1_5_extensions(fContext); _mesa_enable_1_5_extensions(fContext);
// some stupid applications (Quake2) don't even think about calling LockGL() // some stupid applications (Quake2) don't even think about calling LockGL()
// before using glGetString and its glGet*() friends... // before using glGetString and its glGet*() friends...
// so make sure there is at least a valid context. // so make sure there is at least a valid context.
@@ -221,7 +259,7 @@ MesaSoftwareRenderer::~MesaSoftwareRenderer()
_mesa_destroy_visual(fVisual); _mesa_destroy_visual(fVisual);
_mesa_destroy_framebuffer(fFrameBuffer); _mesa_destroy_framebuffer(fFrameBuffer);
_mesa_destroy_context(fContext); _mesa_destroy_context(fContext);
delete fBitmap; delete fBitmap;
} }
@@ -235,22 +273,49 @@ MesaSoftwareRenderer::LockGL()
_mesa_make_current(fContext, fFrameBuffer, fFrameBuffer); _mesa_make_current(fContext, fFrameBuffer, fFrameBuffer);
BRect b = GLView()->Bounds(); BRect b = GLView()->Bounds();
color_space cs = B_RGBA32;
if (fDirectModeEnabled && fInfo != NULL) {
cs = BScreen(GLView()->Window()).ColorSpace();
}
uint32 width = b.IntegerWidth() + 1; uint32 width = b.IntegerWidth() + 1;
uint32 height = b.IntegerHeight() + 1; uint32 height = b.IntegerHeight() + 1;
if (width != fWidth || height != fHeight || !fBitmap) { if (width != fWidth || height != fHeight || !fBitmap || cs != fColorSpace) {
if (cs != fColorSpace)
switch (cs) {
case B_RGBA32:
fRenderBuffer->GetRow = get_row_RGBA8;
fRenderBuffer->GetValues = get_values_RGBA8;
fRenderBuffer->PutRow = put_row_RGBA8;
fRenderBuffer->PutRowRGB = put_row_rgb_RGBA8;
fRenderBuffer->PutMonoRow = put_mono_row_RGBA8;
fRenderBuffer->PutValues = put_values_RGBA8;
fRenderBuffer->PutMonoValues = put_mono_values_RGBA8;
break;
case B_RGB16:
fRenderBuffer->GetRow = get_row_RGB16;
fRenderBuffer->GetValues = get_values_RGB16;
fRenderBuffer->PutRow = put_row_RGB16;
fRenderBuffer->PutRowRGB = put_row_rgb_RGB16;
fRenderBuffer->PutMonoRow = put_mono_row_RGB16;
fRenderBuffer->PutValues = put_values_RGB16;
fRenderBuffer->PutMonoValues = put_mono_values_RGB16;
break;
}
// allocate new size of back buffer bitmap // allocate new size of back buffer bitmap
if (fBitmap) if (fBitmap)
delete fBitmap; delete fBitmap;
fColorSpace = cs;
BRect rect(0.0, 0.0, width - 1, height - 1); BRect rect(0.0, 0.0, width - 1, height - 1);
fBitmap = new BBitmap(rect, B_RGBA32); fBitmap = new BBitmap(rect, fColorSpace);
for (uint i = 0; i < height; i++) for (uint i = 0; i < height; i++)
fRowAddr[height - i - 1] = (GLvoid *) ((GLubyte *) fBitmap->Bits() + i * fBitmap->BytesPerRow()); fRowAddr[height - i - 1] = (GLvoid *)((GLubyte *) fBitmap->Bits() + i * fBitmap->BytesPerRow());
_mesa_resize_framebuffer(fContext, fFrameBuffer, width, height); _mesa_resize_framebuffer(fContext, fFrameBuffer, width, height);
fWidth = width; fWidth = width;
fHeight = height; fHeight = height;
fRenderBuffer->Data = fBitmap->Bits(); fRenderBuffer->Data = fBitmap->Bits();
} }
} }
@@ -270,9 +335,27 @@ MesaSoftwareRenderer::SwapBuffers(bool VSync)
_mesa_notifySwapBuffers(fContext); _mesa_notifySwapBuffers(fContext);
if (fBitmap) { if (fBitmap) {
GLView()->LockLooper(); if (!fDirectModeEnabled || fInfo == NULL) {
GLView()->DrawBitmap(fBitmap); GLView()->LockLooper();
GLView()->UnlockLooper(); GLView()->DrawBitmap(fBitmap);
GLView()->UnlockLooper();
} else {
uint8 bytesPerPixel = fInfo->bits_per_pixel / 8;
uint32 bytesPerRow = fBitmap->BytesPerRow();
for (int i=0; i<fInfo->clip_list_count; i++) {
clipping_rect *clip = &fInfo->clip_list[i];
int32 height = clip->bottom - clip->top + 1;
int32 bytesWidth = (clip->right - clip->left + 1) * bytesPerPixel;
uint8 *p = (uint8 *)fInfo->bits + (clip->top * fInfo->bytes_per_row) + clip->left * bytesPerPixel;
uint8 *b = (uint8 *)fBitmap->Bits() + (clip->top - fInfo->window_bounds.top) * bytesPerRow
+ (clip->left - fInfo->window_bounds.left) * bytesPerPixel;
for (int y = 0; y < height; y++) {
memcpy(p, b, bytesWidth);
p += fInfo->bytes_per_row;
b += bytesPerRow;
}
}
}
} }
} }
@@ -281,8 +364,9 @@ void
MesaSoftwareRenderer::Draw(BRect updateRect) MesaSoftwareRenderer::Draw(BRect updateRect)
{ {
CALLED(); CALLED();
if (fBitmap) if (fBitmap && (!fDirectModeEnabled || (fInfo == NULL)))
GLView()->DrawBitmap(fBitmap, updateRect, updateRect); GLView()->DrawBitmap(fBitmap, updateRect, updateRect);
} }
@@ -299,24 +383,24 @@ MesaSoftwareRenderer::CopyPixelsOut(BPoint location, BBitmap *bitmap)
color_space_name(dcs)); color_space_name(dcs));
return B_BAD_TYPE; return B_BAD_TYPE;
} }
BRect sr = fBitmap->Bounds(); BRect sr = fBitmap->Bounds();
BRect dr = bitmap->Bounds(); BRect dr = bitmap->Bounds();
sr = sr & dr.OffsetBySelf(location); sr = sr & dr.OffsetBySelf(location);
dr = sr.OffsetByCopy(-location.x, -location.y); dr = sr.OffsetByCopy(-location.x, -location.y);
uint8 *ps = (uint8 *) fBitmap->Bits(); uint8 *ps = (uint8 *) fBitmap->Bits();
uint8 *pd = (uint8 *) bitmap->Bits(); uint8 *pd = (uint8 *) bitmap->Bits();
uint32 *s, *d; uint32 *s, *d;
uint32 y; uint32 y;
for (y = (uint32) sr.top; y <= (uint32) sr.bottom; y++) { for (y = (uint32) sr.top; y <= (uint32) sr.bottom; y++) {
s = (uint32 *) (ps + y * fBitmap->BytesPerRow()); s = (uint32 *)(ps + y * fBitmap->BytesPerRow());
s += (uint32) sr.left; s += (uint32) sr.left;
d = (uint32 *) (pd + (y + (uint32) (dr.top - sr.top)) * bitmap->BytesPerRow()); d = (uint32 *)(pd + (y + (uint32)(dr.top - sr.top)) * bitmap->BytesPerRow());
d += (uint32) dr.left; d += (uint32) dr.left;
memcpy(d, s, dr.IntegerWidth() * 4); memcpy(d, s, dr.IntegerWidth() * 4);
} }
return B_OK; return B_OK;
@@ -336,31 +420,31 @@ MesaSoftwareRenderer::CopyPixelsIn(BBitmap *bitmap, BPoint location)
color_space_name(dcs)); color_space_name(dcs));
return B_BAD_TYPE; return B_BAD_TYPE;
} }
BRect sr = bitmap->Bounds(); BRect sr = bitmap->Bounds();
BRect dr = fBitmap->Bounds(); BRect dr = fBitmap->Bounds();
sr = sr & dr.OffsetBySelf(location); sr = sr & dr.OffsetBySelf(location);
dr = sr.OffsetByCopy(-location.x, -location.y); dr = sr.OffsetByCopy(-location.x, -location.y);
uint8 *ps = (uint8 *) bitmap->Bits(); uint8 *ps = (uint8 *) bitmap->Bits();
uint8 *pd = (uint8 *) fBitmap->Bits(); uint8 *pd = (uint8 *) fBitmap->Bits();
uint32 *s, *d; uint32 *s, *d;
uint32 y; uint32 y;
for (y = (uint32) sr.top; y <= (uint32) sr.bottom; y++) { for (y = (uint32) sr.top; y <= (uint32) sr.bottom; y++) {
s = (uint32 *) (ps + y * bitmap->BytesPerRow()); s = (uint32 *)(ps + y * bitmap->BytesPerRow());
s += (uint32) sr.left; s += (uint32) sr.left;
d = (uint32 *) (pd + (y + (uint32) (dr.top - sr.top)) * fBitmap->BytesPerRow()); d = (uint32 *)(pd + (y + (uint32)(dr.top - sr.top)) * fBitmap->BytesPerRow());
d += (uint32) dr.left; d += (uint32) dr.left;
memcpy(d, s, dr.IntegerWidth() * 4); memcpy(d, s, dr.IntegerWidth() * 4);
} }
return B_OK; return B_OK;
} }
void void
MesaSoftwareRenderer::Viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h) MesaSoftwareRenderer::Viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h)
{ {
CALLED(); CALLED();
@@ -376,27 +460,27 @@ MesaSoftwareRenderer::GetString(GLcontext *ctx, GLenum name)
case GL_RENDERER: { case GL_RENDERER: {
static char buffer[256] = { '\0' }; static char buffer[256] = { '\0' };
if (!buffer[0] ) { if (!buffer[0]) {
// Let's build an renderer string // Let's build an renderer string
// TODO: add SVN revision // TODO: add SVN revision
strncat(buffer, "Haiku's Mesa " MESA_VERSION_STRING " Software Renderer", sizeof(buffer)); strncat(buffer, "Haiku's Mesa " MESA_VERSION_STRING " Software Renderer", sizeof(buffer));
// Append any CPU-specific information. // Append any CPU-specific information.
#ifdef USE_X86_ASM #ifdef USE_X86_ASM
if (_mesa_x86_cpu_features) if (_mesa_x86_cpu_features)
strncat(buffer, ", optimized for x86", sizeof(buffer)); strncat(buffer, ", optimized for x86", sizeof(buffer));
#ifdef USE_MMX_ASM #ifdef USE_MMX_ASM
if (cpu_has_mmx) if (cpu_has_mmx)
strncat(buffer, (cpu_has_mmxext) ? "/MMX+" : "/MMX", sizeof(buffer)); strncat(buffer, (cpu_has_mmxext) ? "/MMX+" : "/MMX", sizeof(buffer));
#endif #endif
#ifdef USE_3DNOW_ASM #ifdef USE_3DNOW_ASM
if (cpu_has_3dnow) if (cpu_has_3dnow)
strncat(buffer, (cpu_has_3dnowext) ? "/3DNow!+" : "/3DNow!", sizeof(buffer)); strncat(buffer, (cpu_has_3dnowext) ? "/3DNow!+" : "/3DNow!", sizeof(buffer));
#endif #endif
#ifdef USE_SSE_ASM #ifdef USE_SSE_ASM
if (cpu_has_xmm) if (cpu_has_xmm)
strncat(buffer, (cpu_has_xmm2) ? "/SSE2" : "/SSE", sizeof(buffer)); strncat(buffer, (cpu_has_xmm2) ? "/SSE2" : "/SSE", sizeof(buffer));
#endif #endif
#elif defined(USE_SPARC_ASM) #elif defined(USE_SPARC_ASM)
@@ -407,15 +491,15 @@ MesaSoftwareRenderer::GetString(GLcontext *ctx, GLenum name)
if (_mesa_ppc_cpu_features) if (_mesa_ppc_cpu_features)
strncat(buffer, (cpu_has_64) ? ", optimized for PowerPC 64" : ", optimized for PowerPC", sizeof(buffer)); strncat(buffer, (cpu_has_64) ? ", optimized for PowerPC 64" : ", optimized for PowerPC", sizeof(buffer));
#ifdef USE_VMX_ASM #ifdef USE_VMX_ASM
if (cpu_has_vmx) if (cpu_has_vmx)
strncat(buffer, "/Altivec", sizeof(buffer)); strncat(buffer, "/Altivec", sizeof(buffer));
#endif #endif
if (! cpu_has_fpu) if (! cpu_has_fpu)
strncat(buffer, "/No FPU", sizeof(buffer)); strncat(buffer, "/No FPU", sizeof(buffer));
#endif #endif
} }
return (const GLubyte *) buffer; return (const GLubyte *) buffer;
} }
@@ -426,7 +510,7 @@ MesaSoftwareRenderer::GetString(GLcontext *ctx, GLenum name)
} }
void void
MesaSoftwareRenderer::Error(GLcontext *ctx) MesaSoftwareRenderer::Error(GLcontext *ctx)
{ {
MesaSoftwareRenderer *mr = (MesaSoftwareRenderer *) ctx->DriverCtx; MesaSoftwareRenderer *mr = (MesaSoftwareRenderer *) ctx->DriverCtx;
@@ -435,31 +519,31 @@ MesaSoftwareRenderer::Error(GLcontext *ctx)
} }
void void
MesaSoftwareRenderer::ClearIndex(GLcontext *ctx, GLuint index) MesaSoftwareRenderer::ClearIndex(GLcontext *ctx, GLuint index)
{ {
CALLED(); CALLED();
MesaSoftwareRenderer *mr = (MesaSoftwareRenderer *) ctx->DriverCtx; MesaSoftwareRenderer *mr = (MesaSoftwareRenderer *) ctx->DriverCtx;
mr->fClearIndex = index; mr->fClearIndex = index;
} }
void void
MesaSoftwareRenderer::ClearColor(GLcontext *ctx, const GLfloat color[4]) MesaSoftwareRenderer::ClearColor(GLcontext *ctx, const GLfloat color[4])
{ {
CALLED(); CALLED();
MesaSoftwareRenderer *mr = (MesaSoftwareRenderer *) ctx->DriverCtx; MesaSoftwareRenderer *mr = (MesaSoftwareRenderer *) ctx->DriverCtx;
CLAMPED_FLOAT_TO_CHAN(mr->fClearColor[BE_RCOMP], color[0]); CLAMPED_FLOAT_TO_CHAN(mr->fClearColor[BE_RCOMP], color[0]);
CLAMPED_FLOAT_TO_CHAN(mr->fClearColor[BE_GCOMP], color[1]); CLAMPED_FLOAT_TO_CHAN(mr->fClearColor[BE_GCOMP], color[1]);
CLAMPED_FLOAT_TO_CHAN(mr->fClearColor[BE_BCOMP], color[2]); CLAMPED_FLOAT_TO_CHAN(mr->fClearColor[BE_BCOMP], color[2]);
CLAMPED_FLOAT_TO_CHAN(mr->fClearColor[BE_ACOMP], color[3]); CLAMPED_FLOAT_TO_CHAN(mr->fClearColor[BE_ACOMP], color[3]);
assert(mr->GLView()); assert(mr->GLView());
} }
void void
MesaSoftwareRenderer::Clear(GLcontext *ctx, GLbitfield mask) MesaSoftwareRenderer::Clear(GLcontext *ctx, GLbitfield mask)
{ {
CALLED(); CALLED();
@@ -468,21 +552,23 @@ MesaSoftwareRenderer::Clear(GLcontext *ctx, GLbitfield mask)
mask &= ~(BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT); mask &= ~(BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT);
if (mask) if (mask)
_swrast_Clear( ctx, mask); _swrast_Clear(ctx, mask);
} }
void void
MesaSoftwareRenderer::ClearFront(GLcontext *ctx) MesaSoftwareRenderer::ClearFront(GLcontext *ctx)
{ {
CALLED(); CALLED();
MesaSoftwareRenderer *mr = (MesaSoftwareRenderer *) ctx->DriverCtx; MesaSoftwareRenderer *mr = (MesaSoftwareRenderer *) ctx->DriverCtx;
BGLView *bglview = mr->GLView(); BGLView *bglview = mr->GLView();
assert(bglview); assert(bglview);
BBitmap *bitmap = mr->fBitmap; BBitmap *bitmap = mr->fBitmap;
assert(bitmap); assert(bitmap);
GLuint *start = (GLuint *) bitmap->Bits(); GLuint *start = (GLuint *) bitmap->Bits();
size_t pixelSize = 0;
get_pixel_size_for(bitmap->ColorSpace(), &pixelSize, NULL, NULL);
const GLuint *clearPixelPtr = (const GLuint *) mr->fClearColor; const GLuint *clearPixelPtr = (const GLuint *) mr->fClearColor;
const GLuint clearPixel = B_LENDIAN_TO_HOST_INT32(*clearPixelPtr); const GLuint clearPixel = B_LENDIAN_TO_HOST_INT32(*clearPixelPtr);
@@ -495,7 +581,7 @@ MesaSoftwareRenderer::ClearFront(GLcontext *ctx)
if (all) { if (all) {
const int numPixels = mr->fWidth * mr->fHeight; const int numPixels = mr->fWidth * mr->fHeight;
if (clearPixel == 0) { if (clearPixel == 0) {
memset(start, 0, numPixels * 4); memset(start, 0, numPixels * pixelSize);
} else { } else {
for (int i = 0; i < numPixels; i++) { for (int i = 0; i < numPixels; i++) {
start[i] = clearPixel; start[i] = clearPixel;
@@ -514,23 +600,37 @@ MesaSoftwareRenderer::ClearFront(GLcontext *ctx)
} }
void void
MesaSoftwareRenderer::UpdateState( GLcontext *ctx, GLuint new_state ) MesaSoftwareRenderer::UpdateState(GLcontext *ctx, GLuint new_state)
{ {
if (!ctx) if (!ctx)
return; return;
CALLED(); CALLED();
_swrast_InvalidateState( ctx, new_state ); _swrast_InvalidateState(ctx, new_state);
_swsetup_InvalidateState( ctx, new_state ); _swsetup_InvalidateState(ctx, new_state);
_ac_InvalidateState( ctx, new_state ); _ac_InvalidateState(ctx, new_state);
_tnl_InvalidateState( ctx, new_state ); _tnl_InvalidateState(ctx, new_state);
} }
GLboolean GLboolean
MesaSoftwareRenderer::RenderbufferStorage(GLcontext *ctx, struct gl_renderbuffer *render, MesaSoftwareRenderer::RenderbufferStorage(GLcontext *ctx, struct gl_renderbuffer *render,
GLenum internalFormat, GLuint width, GLuint height ) GLenum internalFormat, GLuint width, GLuint height)
{ {
return GL_TRUE; return GL_TRUE;
}
void
MesaSoftwareRenderer::EnableDirectMode(bool enabled)
{
fDirectModeEnabled = enabled;
}
void
MesaSoftwareRenderer::DirectConnected(direct_buffer_info *info)
{
fInfo = info;
} }
@@ -9,7 +9,7 @@
/* /*
* Mesa 3-D graphics library * Mesa 3-D graphics library
* Version: 6.1 * Version: 6.1
* *
* Copyright (C) 1999-2004 Brian Paul All Rights Reserved. * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
*/ */
#ifndef MESASOFTWARERENDERER_H #ifndef MESASOFTWARERENDERER_H
@@ -25,45 +25,51 @@ extern "C" {
class MesaSoftwareRenderer : public BGLRenderer class MesaSoftwareRenderer : public BGLRenderer
{ {
public: public:
MesaSoftwareRenderer(BGLView *view, ulong bgl_options, BGLDispatcher *dispatcher); MesaSoftwareRenderer(BGLView *view, ulong bgl_options, BGLDispatcher *dispatcher);
virtual ~MesaSoftwareRenderer(); virtual ~MesaSoftwareRenderer();
virtual void LockGL();
virtual void UnlockGL();
virtual void SwapBuffers(bool VSync = false); virtual void LockGL();
virtual void Draw(BRect updateRect); virtual void UnlockGL();
virtual status_t CopyPixelsOut(BPoint source, BBitmap *dest);
virtual status_t CopyPixelsIn(BBitmap *source, BPoint dest);
GLvoid ** GetRows() { return fRowAddr; }; 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: GLvoid ** GetRows() { return fRowAddr; };
static void Error(GLcontext *ctx);
static const GLubyte * GetString(GLcontext *ctx, GLenum name);
static void Viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h);
static void UpdateState(GLcontext *ctx, GLuint new_state);
static void ClearFront(GLcontext *ctx);
static void ClearIndex(GLcontext *ctx, GLuint index);
static void ClearColor(GLcontext *ctx, const GLfloat color[4]);
static void Clear(GLcontext *ctx, GLbitfield mask);
static GLboolean RenderbufferStorage(GLcontext *ctx, struct gl_renderbuffer *render,
GLenum internalFormat, GLuint width, GLuint height );
BBitmap *fBitmap;
GLcontext *fContext; virtual void EnableDirectMode(bool enabled);
GLvisual *fVisual; virtual void DirectConnected(direct_buffer_info *info);
GLframebuffer *fFrameBuffer;
struct gl_renderbuffer *fRenderBuffer;
GLchan fClearColor[4]; // buffer clear color private:
GLuint fClearIndex; // buffer clear color index static void Error(GLcontext *ctx);
GLuint fWidth; static const GLubyte * GetString(GLcontext *ctx, GLenum name);
GLuint fHeight; static void Viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h);
static void UpdateState(GLcontext *ctx, GLuint new_state);
static void ClearFront(GLcontext *ctx);
static void ClearIndex(GLcontext *ctx, GLuint index);
static void ClearColor(GLcontext *ctx, const GLfloat color[4]);
static void Clear(GLcontext *ctx, GLbitfield mask);
static GLboolean RenderbufferStorage(GLcontext *ctx, struct gl_renderbuffer *render,
GLenum internalFormat, GLuint width, GLuint height);
GLvoid * fRowAddr[MAX_HEIGHT]; /*< address of first pixel in each image row */ BBitmap *fBitmap;
bool fDirectModeEnabled;
direct_buffer_info *fInfo;
GLcontext *fContext;
GLvisual *fVisual;
GLframebuffer *fFrameBuffer;
struct gl_renderbuffer *fRenderBuffer;
GLchan fClearColor[4]; // buffer clear color
GLuint fClearIndex; // buffer clear color index
GLuint fWidth;
GLuint fHeight;
color_space fColorSpace;
GLvoid * fRowAddr[MAX_HEIGHT]; /*< address of first pixel in each image row */
}; };
#endif // MESASOFTWARERENDERER_H #endif // MESASOFTWARERENDERER_H
+26 -16
View File
@@ -1,3 +1,12 @@
/*
* Copyright 2006-2007, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Jérôme Duval, [email protected]
* Philippe Houdoin, [email protected]
* Stefano Ceccherini, [email protected]
*/
/* /*
* Mesa 3-D graphics library * Mesa 3-D graphics library
* Version: 6.1 * Version: 6.1
@@ -35,6 +44,7 @@
struct glview_direct_info { struct glview_direct_info {
direct_buffer_info *direct_info; direct_buffer_info *direct_info;
bool direct_connected; bool direct_connected;
bool enable_direct_mode;
glview_direct_info(); glview_direct_info();
~glview_direct_info(); ~glview_direct_info();
@@ -170,6 +180,11 @@ BGLView::AttachedToWindow()
// Set default OpenGL viewport: // Set default OpenGL viewport:
glViewport(0, 0, Bounds().IntegerWidth(), Bounds().IntegerHeight()); glViewport(0, 0, Bounds().IntegerWidth(), Bounds().IntegerHeight());
if (m_clip_info) {
fRenderer->DirectConnected(((glview_direct_info *)m_clip_info)->direct_info);
fRenderer->EnableDirectMode(((glview_direct_info *)m_clip_info)->enable_direct_mode);
}
return; return;
} }
@@ -285,14 +300,15 @@ BGLView::DirectConnected(direct_buffer_info *info)
// TODO: We should probably prevent the renderer to draw anything // TODO: We should probably prevent the renderer to draw anything
// (lock_draw() ??) while we are in this method // (lock_draw() ??) while we are in this method
if (!m_clip_info/* && m_direct_connection_disabled*/) if (!m_clip_info/* && m_direct_connection_disabled*/) {
return; m_clip_info = new glview_direct_info();
}
glview_direct_info *glviewDirectInfo = (glview_direct_info *)m_clip_info; glview_direct_info *glviewDirectInfo = (glview_direct_info *)m_clip_info;
direct_buffer_info *localInfo = glviewDirectInfo->direct_info; direct_buffer_info *localInfo = glviewDirectInfo->direct_info;
//direct_info_locker->Lock(); //direct_info_locker->Lock();
switch(info->buffer_state & B_DIRECT_MODE_MASK) { switch(info->buffer_state & B_DIRECT_MODE_MASK) {
case B_DIRECT_START: case B_DIRECT_START:
glviewDirectInfo->direct_connected = true; glviewDirectInfo->direct_connected = true;
case B_DIRECT_MODIFY: case B_DIRECT_MODIFY:
{ {
@@ -309,16 +325,12 @@ BGLView::DirectConnected(direct_buffer_info *info)
//localInfo->_dd_type_ = info->_dd_type_; //localInfo->_dd_type_ = info->_dd_type_;
//localInfo->_dd_token_ = info->_dd_token_; //localInfo->_dd_token_ = info->_dd_token_;
localInfo->window_bounds = info->window_bounds;
// Collect the rects into a BRegion, then clip to the view's bounds // Collect the rects into a BRegion, then clip to the view's bounds
BRegion region; BRegion region;
for (uint32 c = 0; c < info->clip_list_count; c++) for (uint32 c = 0; c < info->clip_list_count; c++)
region.Include(info->clip_list[c]); region.Include(info->clip_list[c]);
// TODO: I have the feeling that this Bounds() call won't work here. BRegion boundsRegion = m_bounds.OffsetByCopy(info->window_bounds.left, info->window_bounds.top);
// Probably m_bounds should be used, but it should then be maintained correctly localInfo->window_bounds = boundsRegion.RectAtInt(0); // window_bounds are now view bounds
// on view resizing/moving...
BRegion boundsRegion = m_bounds.OffsetByCopy(localInfo->window_bounds.left, localInfo->window_bounds.top);
region.IntersectWith(&boundsRegion); region.IntersectWith(&boundsRegion);
localInfo->clip_list_count = region.CountRects(); localInfo->clip_list_count = region.CountRects();
@@ -343,15 +355,12 @@ BGLView::DirectConnected(direct_buffer_info *info)
void void
BGLView::EnableDirectMode(bool enabled) BGLView::EnableDirectMode(bool enabled)
{ {
if (!m_clip_info && enabled)
m_clip_info = new glview_direct_info();
else if (m_clip_info && !enabled) {
delete (glview_direct_info *)m_clip_info;
m_clip_info = NULL;
}
if (fRenderer) if (fRenderer)
fRenderer->EnableDirectMode(enabled); fRenderer->EnableDirectMode(enabled);
if (!m_clip_info) {
m_clip_info = new glview_direct_info();
}
((glview_direct_info *)m_clip_info)->enable_direct_mode = enabled;
} }
@@ -511,6 +520,7 @@ glview_direct_info::glview_direct_info()
// TODO: See direct_window_data() in app_server's ServerWindow.cpp // TODO: See direct_window_data() in app_server's ServerWindow.cpp
direct_info = (direct_buffer_info *)calloc(1, B_PAGE_SIZE); direct_info = (direct_buffer_info *)calloc(1, B_PAGE_SIZE);
direct_connected = false; direct_connected = false;
enable_direct_mode = false;
} }