1 /* $Id: GLView.cpp,v 1.10 2003/12/13 01:26:14 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 #include "bufferobj.h"
39 #include "extensions.h"
43 #include "texformat.h"
47 #include "array_cache/acache.h"
48 #include "swrast/swrast.h"
49 #include "swrast_setup/swrast_setup.h"
50 #include "swrast/s_context.h"
51 #include "swrast/s_depth.h"
52 #include "swrast/s_lines.h"
53 #include "swrast/s_triangle.h"
54 #include "swrast/s_trispan.h"
56 #include "tnl/t_context.h"
57 #include "tnl/t_pipeline.h"
63 // BeOS component ordering for B_RGBA32 bitmap format
69 #define PACK_B_RGBA32(color) (color[BCOMP] | (color[GCOMP] << 8) | \
70 (color[RCOMP] << 16) | (color[ACOMP] << 24))
72 #define PACK_B_RGB32(color) (color[BCOMP] | (color[GCOMP] << 8) | \
73 (color[RCOMP] << 16) | 0xFF000000)
75 #define FLIP(coord) (LIBGGI_MODE(ggi_ctx->ggi_visual)->visible.y-(coord) - 1)
78 // This object hangs off of the BGLView object. We have to use
79 // Be's BGLView class as-is to maintain binary compatibility (we
80 // can't add new members to it). Instead we just put all our data
81 // in this class and use BGLVIew::m_gc to point to it.
88 void Init(BGLView
* bglview
, GLcontext
* c
, GLvisual
* v
, GLframebuffer
* b
);
92 void SwapBuffers() const;
93 void CopySubBuffer(GLint x
, GLint y
, GLuint width
, GLuint height
) const;
94 void Draw(BRect updateRect
) const;
97 MesaDriver(const MesaDriver
&rhs
); // copy constructor illegal
98 MesaDriver
&operator=(const MesaDriver
&rhs
); // assignment oper. illegal
100 GLcontext
* m_glcontext
;
101 GLvisual
* m_glvisual
;
102 GLframebuffer
* m_glframebuffer
;
107 GLchan m_clear_color
[4]; // buffer clear color
108 GLuint m_clear_index
; // buffer clear color index
109 GLint m_bottom
; // used for flipping Y coords
113 // Mesa Device Driver functions
114 static void UpdateState(GLcontext
*ctx
, GLuint new_state
);
115 static void ClearIndex(GLcontext
*ctx
, GLuint index
);
116 static void ClearColor(GLcontext
*ctx
, const GLfloat color
[4]);
117 static void Clear(GLcontext
*ctx
, GLbitfield mask
,
118 GLboolean all
, GLint x
, GLint y
,
119 GLint width
, GLint height
);
120 static void ClearFront(GLcontext
*ctx
, GLboolean all
, GLint x
, GLint y
,
121 GLint width
, GLint height
);
122 static void ClearBack(GLcontext
*ctx
, GLboolean all
, GLint x
, GLint y
,
123 GLint width
, GLint height
);
124 static void Index(GLcontext
*ctx
, GLuint index
);
125 static void Color(GLcontext
*ctx
, GLubyte r
, GLubyte g
,
126 GLubyte b
, GLubyte a
);
127 static void SetBuffer(GLcontext
*ctx
, GLframebuffer
*colorBuffer
,
129 static void GetBufferSize(GLframebuffer
* framebuffer
, GLuint
*width
,
131 static const GLubyte
* GetString(GLcontext
*ctx
, GLenum name
);
133 // Front-buffer functions
134 static void WriteRGBASpanFront(const GLcontext
*ctx
, GLuint n
,
136 CONST GLubyte rgba
[][4],
137 const GLubyte mask
[]);
138 static void WriteRGBSpanFront(const GLcontext
*ctx
, GLuint n
,
140 CONST GLubyte rgba
[][3],
141 const GLubyte mask
[]);
142 static void WriteMonoRGBASpanFront(const GLcontext
*ctx
, GLuint n
,
144 const GLchan color
[4],
145 const GLubyte mask
[]);
146 static void WriteRGBAPixelsFront(const GLcontext
*ctx
, GLuint n
,
147 const GLint x
[], const GLint y
[],
148 CONST GLubyte rgba
[][4],
149 const GLubyte mask
[]);
150 static void WriteMonoRGBAPixelsFront(const GLcontext
*ctx
, GLuint n
,
151 const GLint x
[], const GLint y
[],
152 const GLchan color
[4],
153 const GLubyte mask
[]);
154 static void WriteCI32SpanFront(const GLcontext
*ctx
, GLuint n
,
156 const GLuint index
[], const GLubyte mask
[]);
157 static void WriteCI8SpanFront(const GLcontext
*ctx
, GLuint n
,
159 const GLubyte index
[], const GLubyte mask
[]);
160 static void WriteMonoCISpanFront(const GLcontext
*ctx
, GLuint n
,
162 GLuint colorIndex
, const GLubyte mask
[]);
163 static void WriteCI32PixelsFront(const GLcontext
*ctx
,
164 GLuint n
, const GLint x
[], const GLint y
[],
165 const GLuint index
[], const GLubyte mask
[]);
166 static void WriteMonoCIPixelsFront(const GLcontext
*ctx
, GLuint n
,
167 const GLint x
[], const GLint y
[],
168 GLuint colorIndex
, const GLubyte mask
[]);
169 static void ReadCI32SpanFront(const GLcontext
*ctx
,
170 GLuint n
, GLint x
, GLint y
, GLuint index
[]);
171 static void ReadRGBASpanFront(const GLcontext
*ctx
, GLuint n
,
174 static void ReadCI32PixelsFront(const GLcontext
*ctx
,
175 GLuint n
, const GLint x
[], const GLint y
[],
176 GLuint indx
[], const GLubyte mask
[]);
177 static void ReadRGBAPixelsFront(const GLcontext
*ctx
,
178 GLuint n
, const GLint x
[], const GLint y
[],
179 GLubyte rgba
[][4], const GLubyte mask
[]);
181 // Back buffer functions
182 static void WriteRGBASpanBack(const GLcontext
*ctx
, GLuint n
,
184 CONST GLubyte rgba
[][4],
185 const GLubyte mask
[]);
186 static void WriteRGBSpanBack(const GLcontext
*ctx
, GLuint n
,
188 CONST GLubyte rgba
[][3],
189 const GLubyte mask
[]);
190 static void WriteMonoRGBASpanBack(const GLcontext
*ctx
, GLuint n
,
192 const GLchan color
[4],
193 const GLubyte mask
[]);
194 static void WriteRGBAPixelsBack(const GLcontext
*ctx
, GLuint n
,
195 const GLint x
[], const GLint y
[],
196 CONST GLubyte rgba
[][4],
197 const GLubyte mask
[]);
198 static void WriteMonoRGBAPixelsBack(const GLcontext
*ctx
, GLuint n
,
199 const GLint x
[], const GLint y
[],
200 const GLchan color
[4],
201 const GLubyte mask
[]);
202 static void WriteCI32SpanBack(const GLcontext
*ctx
, GLuint n
,
204 const GLuint index
[], const GLubyte mask
[]);
205 static void WriteCI8SpanBack(const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
206 const GLubyte index
[], const GLubyte mask
[]);
207 static void WriteMonoCISpanBack(const GLcontext
*ctx
, GLuint n
,
208 GLint x
, GLint y
, GLuint colorIndex
,
209 const GLubyte mask
[]);
210 static void WriteCI32PixelsBack(const GLcontext
*ctx
,
211 GLuint n
, const GLint x
[], const GLint y
[],
212 const GLuint index
[], const GLubyte mask
[]);
213 static void WriteMonoCIPixelsBack(const GLcontext
*ctx
,
214 GLuint n
, const GLint x
[], const GLint y
[],
215 GLuint colorIndex
, const GLubyte mask
[]);
216 static void ReadCI32SpanBack(const GLcontext
*ctx
,
217 GLuint n
, GLint x
, GLint y
, GLuint index
[]);
218 static void ReadRGBASpanBack(const GLcontext
*ctx
, GLuint n
,
221 static void ReadCI32PixelsBack(const GLcontext
*ctx
,
222 GLuint n
, const GLint x
[], const GLint y
[],
223 GLuint indx
[], const GLubyte mask
[]);
224 static void ReadRGBAPixelsBack(const GLcontext
*ctx
,
225 GLuint n
, const GLint x
[], const GLint y
[],
226 GLubyte rgba
[][4], const GLubyte mask
[]);
230 //------------------------------------------------------------------
231 // Public interface methods
232 //------------------------------------------------------------------
236 // Input: rect - initial rectangle
237 // name - window name
238 // resizingMode - example: B_FOLLOW_NONE
239 // mode - usually 0 ?
240 // options - Bitwise-OR of BGL_* tokens
242 BGLView::BGLView(BRect rect
, char *name
,
243 ulong resizingMode
, ulong mode
,
245 :BView(rect
, name
, resizingMode
, mode
| B_WILL_DRAW
| B_FRAME_EVENTS
) // | B_FULL_UPDATE_ON_RESIZE)
247 const GLboolean rgbFlag
= (options
& BGL_RGB
) == BGL_RGB
;
248 const GLboolean alphaFlag
= (options
& BGL_ALPHA
) == BGL_ALPHA
;
249 const GLboolean dblFlag
= (options
& BGL_DOUBLE
) == BGL_DOUBLE
;
250 const GLboolean stereoFlag
= false;
251 const GLint depth
= (options
& BGL_DEPTH
) ? 16 : 0;
252 const GLint stencil
= (options
& BGL_STENCIL
) ? 8 : 0;
253 const GLint accum
= (options
& BGL_ACCUM
) ? 16 : 0;
254 const GLint index
= (options
& BGL_INDEX
) ? 32 : 0;
255 const GLint red
= (options
& BGL_RGB
) ? 8 : 0;
256 const GLint green
= (options
& BGL_RGB
) ? 8 : 0;
257 const GLint blue
= (options
& BGL_RGB
) ? 8 : 0;
258 const GLint alpha
= (options
& BGL_RGB
) ? 8 : 0;
261 fprintf(stderr
, "Mesa Warning: color index mode not supported\n");
264 // Allocate auxiliary data object
265 MesaDriver
* md
= new MesaDriver
;
267 // examine option flags and create gl_context struct
268 GLvisual
* visual
= _mesa_create_visual( rgbFlag
,
271 red
, green
, blue
, alpha
,
275 accum
, accum
, accum
, accum
,
279 // create core context
280 GLcontext
* ctx
= _mesa_create_context(visual
, NULL
, md
, GL_FALSE
);
282 ctx
->Driver
.NewTextureObject
= _mesa_new_texture_object
;
283 ctx
->Driver
.DeleteTexture
= _mesa_delete_texture_object
;
285 _mesa_initialize_context(ctx
, visual
, NULL
, md
, GL_FALSE
);
287 _mesa_enable_sw_extensions(ctx
);
288 _mesa_enable_1_3_extensions(ctx
);
289 _mesa_enable_1_4_extensions(ctx
);
290 _mesa_enable_1_5_extensions(ctx
);
294 // create core framebuffer
295 GLframebuffer
* buffer
= _mesa_create_framebuffer(visual
,
296 depth
> 0 ? GL_TRUE
: GL_FALSE
,
297 stencil
> 0 ? GL_TRUE
: GL_FALSE
,
298 accum
> 0 ? GL_TRUE
: GL_FALSE
,
302 /* Initialize the software rasterizer and helper modules.
304 _swrast_CreateContext(ctx
);
305 _ac_CreateContext(ctx
);
306 _tnl_CreateContext(ctx
);
307 _swsetup_CreateContext(ctx
);
308 _swsetup_Wakeup(ctx
);
310 md
->Init(this, ctx
, visual
, buffer
);
312 // Hook aux data into BGLView object
319 printf("BGLView destructor\n");
320 MesaDriver
* md
= (MesaDriver
*) m_gc
;
325 void BGLView::LockGL()
327 MesaDriver
* md
= (MesaDriver
*) m_gc
;
332 void BGLView::UnlockGL()
334 MesaDriver
* md
= (MesaDriver
*) m_gc
;
339 void BGLView::SwapBuffers()
341 MesaDriver
* md
= (MesaDriver
*) m_gc
;
347 void BGLView::CopySubBufferMESA(GLint x
, GLint y
, GLuint width
, GLuint height
)
349 MesaDriver
* md
= (MesaDriver
*) m_gc
;
351 md
->CopySubBuffer(x
, y
, width
, height
);
355 BView
* BGLView::EmbeddedView()
361 status_t
BGLView::CopyPixelsOut(BPoint source
, BBitmap
*dest
)
364 printf("BGLView::CopyPixelsOut() not implemented yet!\n");
365 return B_UNSUPPORTED
;
369 status_t
BGLView::CopyPixelsIn(BBitmap
*source
, BPoint dest
)
372 printf("BGLView::CopyPixelsIn() not implemented yet!\n");
373 return B_UNSUPPORTED
;
376 void BGLView::ErrorCallback(unsigned long errorCode
) // GLenum errorCode)
379 printf("BGLView::ErrorCallback() not implemented yet!\n");
383 void BGLView::Draw(BRect updateRect
)
385 // printf("BGLView::Draw()\n");
386 MesaDriver
* md
= (MesaDriver
*) m_gc
;
388 md
->Draw(updateRect
);
391 void BGLView::AttachedToWindow()
393 BView::AttachedToWindow();
395 // don't paint window background white when resized
396 SetViewColor(B_TRANSPARENT_32_BIT
);
399 void BGLView::AllAttached()
401 BView::AllAttached();
402 // printf("BGLView AllAttached\n");
405 void BGLView::DetachedFromWindow()
407 BView::DetachedFromWindow();
410 void BGLView::AllDetached()
412 BView::AllDetached();
413 // printf("BGLView AllDetached");
416 void BGLView::FrameResized(float width
, float height
)
418 return BView::FrameResized(width
, height
);
421 status_t
BGLView::Perform(perform_code d
, void *arg
)
423 return BView::Perform(d
, arg
);
427 status_t
BGLView::Archive(BMessage
*data
, bool deep
) const
429 return BView::Archive(data
, deep
);
432 void BGLView::MessageReceived(BMessage
*msg
)
434 BView::MessageReceived(msg
);
437 void BGLView::SetResizingMode(uint32 mode
)
439 BView::SetResizingMode(mode
);
444 // printf("BGLView Show\n");
450 // printf("BGLView Hide\n");
454 BHandler
*BGLView::ResolveSpecifier(BMessage
*msg
, int32 index
,
455 BMessage
*specifier
, int32 form
,
456 const char *property
)
458 return BView::ResolveSpecifier(msg
, index
, specifier
, form
, property
);
461 status_t
BGLView::GetSupportedSuites(BMessage
*data
)
463 return BView::GetSupportedSuites(data
);
466 void BGLView::DirectConnected( direct_buffer_info
*info
)
471 void BGLView::EnableDirectMode( bool enabled
)
478 //---- private methods ----------
480 void BGLView::_ReservedGLView1() {}
481 void BGLView::_ReservedGLView2() {}
482 void BGLView::_ReservedGLView3() {}
483 void BGLView::_ReservedGLView4() {}
484 void BGLView::_ReservedGLView5() {}
485 void BGLView::_ReservedGLView6() {}
486 void BGLView::_ReservedGLView7() {}
487 void BGLView::_ReservedGLView8() {}
490 BGLView::BGLView(const BGLView
&v
)
493 // XXX not sure how this should work
494 printf("Warning BGLView::copy constructor not implemented\n");
499 BGLView
&BGLView::operator=(const BGLView
&v
)
501 printf("Warning BGLView::operator= not implemented\n");
505 void BGLView::dither_front()
510 bool BGLView::confirm_dither()
516 void BGLView::draw(BRect r
)
521 /* Direct Window stuff */
522 void BGLView::drawScanline( int x1
, int x2
, int y
, void *data
)
527 void BGLView::scanlineHandler(struct rasStateRec
*state
,
533 void BGLView::lock_draw()
538 void BGLView::unlock_draw()
543 bool BGLView::validateView()
551 MesaDriver::MesaDriver()
555 m_glframebuffer
= NULL
;
559 m_clear_color
[BE_RCOMP
] = 0;
560 m_clear_color
[BE_GCOMP
] = 0;
561 m_clear_color
[BE_BCOMP
] = 0;
562 m_clear_color
[BE_ACOMP
] = 0;
568 MesaDriver::~MesaDriver()
570 _mesa_destroy_visual(m_glvisual
);
571 _mesa_destroy_framebuffer(m_glframebuffer
);
572 _mesa_destroy_context(m_glcontext
);
577 void MesaDriver::Init(BGLView
* bglview
, GLcontext
* ctx
, GLvisual
* visual
, GLframebuffer
* framebuffer
)
582 m_glframebuffer
= framebuffer
;
584 MesaDriver
* md
= (MesaDriver
*) ctx
->DriverCtx
;
585 struct swrast_device_driver
* swdd
= _swrast_GetDeviceDriverReference( ctx
);
586 TNLcontext
* tnl
= TNL_CONTEXT(ctx
);
588 assert(md
->m_glcontext
== ctx
);
590 // Use default TCL pipeline
591 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
593 ctx
->Driver
.GetString
= MesaDriver::GetString
;
594 ctx
->Driver
.UpdateState
= MesaDriver::UpdateState
;
595 ctx
->Driver
.ResizeBuffers
= _swrast_alloc_buffers
;
596 ctx
->Driver
.GetBufferSize
= MesaDriver::GetBufferSize
;
598 ctx
->Driver
.Accum
= _swrast_Accum
;
599 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
600 ctx
->Driver
.Clear
= MesaDriver::Clear
;
601 // ctx->Driver.ClearIndex = MesaDriver::ClearIndex;
602 // ctx->Driver.ClearColor = MesaDriver::ClearColor;
603 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
604 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
605 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
606 ctx
->Driver
.DrawBuffer
= _swrast_DrawBuffer
;
608 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
609 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
610 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
611 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
612 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
613 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
614 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
615 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
617 ctx
->Driver
.CompressedTexImage1D
= _mesa_store_compressed_teximage1d
;
618 ctx
->Driver
.CompressedTexImage2D
= _mesa_store_compressed_teximage2d
;
619 ctx
->Driver
.CompressedTexImage3D
= _mesa_store_compressed_teximage3d
;
620 ctx
->Driver
.CompressedTexSubImage1D
= _mesa_store_compressed_texsubimage1d
;
621 ctx
->Driver
.CompressedTexSubImage2D
= _mesa_store_compressed_texsubimage2d
;
622 ctx
->Driver
.CompressedTexSubImage3D
= _mesa_store_compressed_texsubimage3d
;
624 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
625 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
626 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
627 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
628 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
629 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
630 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
631 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
632 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
634 swdd
->SetBuffer
= MesaDriver::SetBuffer
;
638 void MesaDriver::LockGL()
640 m_bglview
->LockLooper();
642 UpdateState(m_glcontext
, 0);
643 _mesa_make_current(m_glcontext
, m_glframebuffer
);
647 void MesaDriver::UnlockGL()
649 m_bglview
->UnlockLooper();
650 // Could call _mesa_make_current(NULL, NULL) but it would just
651 // hinder performance
655 void MesaDriver::SwapBuffers() const
657 // _mesa_notifySwapBuffers(m_glcontext);
660 m_bglview
->LockLooper();
661 m_bglview
->DrawBitmap(m_bitmap
, BPoint(0, 0));
662 m_bglview
->UnlockLooper();
667 void MesaDriver::CopySubBuffer(GLint x
, GLint y
, GLuint width
, GLuint height
) const
670 // Source bitmap and view's bitmap are same size.
671 // Source and dest rectangle are the same.
672 // Note (x,y) = (0,0) is the lower-left corner, have to flip Y
675 srcAndDest
.right
= x
+ width
- 1;
676 srcAndDest
.bottom
= m_bottom
- y
;
677 srcAndDest
.top
= srcAndDest
.bottom
- height
+ 1;
678 m_bglview
->DrawBitmap(m_bitmap
, srcAndDest
, srcAndDest
);
683 void MesaDriver::Draw(BRect updateRect
) const
686 m_bglview
->DrawBitmap(m_bitmap
, updateRect
, updateRect
);
690 void MesaDriver::UpdateState( GLcontext
*ctx
, GLuint new_state
)
692 struct swrast_device_driver
* swdd
= _swrast_GetDeviceDriverReference( ctx
);
694 _swrast_InvalidateState( ctx
, new_state
);
695 _swsetup_InvalidateState( ctx
, new_state
);
696 _ac_InvalidateState( ctx
, new_state
);
697 _tnl_InvalidateState( ctx
, new_state
);
699 if (ctx
->Color
.DrawBuffer
== GL_FRONT
) {
700 /* read/write front buffer */
701 swdd
->WriteRGBASpan
= MesaDriver::WriteRGBASpanFront
;
702 swdd
->WriteRGBSpan
= MesaDriver::WriteRGBSpanFront
;
703 swdd
->WriteRGBAPixels
= MesaDriver::WriteRGBAPixelsFront
;
704 swdd
->WriteMonoRGBASpan
= MesaDriver::WriteMonoRGBASpanFront
;
705 swdd
->WriteMonoRGBAPixels
= MesaDriver::WriteMonoRGBAPixelsFront
;
706 swdd
->WriteCI32Span
= MesaDriver::WriteCI32SpanFront
;
707 swdd
->WriteCI8Span
= MesaDriver::WriteCI8SpanFront
;
708 swdd
->WriteMonoCISpan
= MesaDriver::WriteMonoCISpanFront
;
709 swdd
->WriteCI32Pixels
= MesaDriver::WriteCI32PixelsFront
;
710 swdd
->WriteMonoCIPixels
= MesaDriver::WriteMonoCIPixelsFront
;
711 swdd
->ReadRGBASpan
= MesaDriver::ReadRGBASpanFront
;
712 swdd
->ReadRGBAPixels
= MesaDriver::ReadRGBAPixelsFront
;
713 swdd
->ReadCI32Span
= MesaDriver::ReadCI32SpanFront
;
714 swdd
->ReadCI32Pixels
= MesaDriver::ReadCI32PixelsFront
;
717 /* read/write back buffer */
718 swdd
->WriteRGBASpan
= MesaDriver::WriteRGBASpanBack
;
719 swdd
->WriteRGBSpan
= MesaDriver::WriteRGBSpanBack
;
720 swdd
->WriteRGBAPixels
= MesaDriver::WriteRGBAPixelsBack
;
721 swdd
->WriteMonoRGBASpan
= MesaDriver::WriteMonoRGBASpanBack
;
722 swdd
->WriteMonoRGBAPixels
= MesaDriver::WriteMonoRGBAPixelsBack
;
723 swdd
->WriteCI32Span
= MesaDriver::WriteCI32SpanBack
;
724 swdd
->WriteCI8Span
= MesaDriver::WriteCI8SpanBack
;
725 swdd
->WriteMonoCISpan
= MesaDriver::WriteMonoCISpanBack
;
726 swdd
->WriteCI32Pixels
= MesaDriver::WriteCI32PixelsBack
;
727 swdd
->WriteMonoCIPixels
= MesaDriver::WriteMonoCIPixelsBack
;
728 swdd
->ReadRGBASpan
= MesaDriver::ReadRGBASpanBack
;
729 swdd
->ReadRGBAPixels
= MesaDriver::ReadRGBAPixelsBack
;
730 swdd
->ReadCI32Span
= MesaDriver::ReadCI32SpanBack
;
731 swdd
->ReadCI32Pixels
= MesaDriver::ReadCI32PixelsBack
;
736 void MesaDriver::ClearIndex(GLcontext
*ctx
, GLuint index
)
738 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
739 md
->m_clear_index
= index
;
743 void MesaDriver::ClearColor(GLcontext
*ctx
, const GLfloat color
[4])
745 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
746 CLAMPED_FLOAT_TO_CHAN(md
->m_clear_color
[BE_RCOMP
], color
[0]);
747 CLAMPED_FLOAT_TO_CHAN(md
->m_clear_color
[BE_GCOMP
], color
[1]);
748 CLAMPED_FLOAT_TO_CHAN(md
->m_clear_color
[BE_BCOMP
], color
[2]);
749 CLAMPED_FLOAT_TO_CHAN(md
->m_clear_color
[BE_ACOMP
], color
[3]);
750 assert(md
->m_bglview
);
754 void MesaDriver::Clear(GLcontext
*ctx
, GLbitfield mask
,
755 GLboolean all
, GLint x
, GLint y
,
756 GLint width
, GLint height
)
758 if (mask
& DD_FRONT_LEFT_BIT
)
759 ClearFront(ctx
, all
, x
, y
, width
, height
);
760 if (mask
& DD_BACK_LEFT_BIT
)
761 ClearBack(ctx
, all
, x
, y
, width
, height
);
763 mask
&= ~(DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
);
765 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
771 void MesaDriver::ClearFront(GLcontext
*ctx
,
772 GLboolean all
, GLint x
, GLint y
,
773 GLint width
, GLint height
)
775 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
776 BGLView
*bglview
= md
->m_bglview
;
779 bglview
->SetHighColor(md
->m_clear_color
[BE_RCOMP
],
780 md
->m_clear_color
[BE_GCOMP
],
781 md
->m_clear_color
[BE_BCOMP
],
782 md
->m_clear_color
[BE_ACOMP
]);
783 bglview
->SetLowColor(md
->m_clear_color
[BE_RCOMP
],
784 md
->m_clear_color
[BE_GCOMP
],
785 md
->m_clear_color
[BE_BCOMP
],
786 md
->m_clear_color
[BE_ACOMP
]);
788 BRect b
= bglview
->Bounds();
789 bglview
->FillRect(b
);
796 b
.bottom
= md
->m_height
- y
- 1;
797 b
.top
= b
.bottom
- height
;
798 bglview
->FillRect(b
);
801 // restore drawing color
803 bglview
->SetHighColor(md
->mColor
[BE_RCOMP
],
804 md
->mColor
[BE_GCOMP
],
805 md
->mColor
[BE_BCOMP
],
806 md
->mColor
[BE_ACOMP
]);
807 bglview
->SetLowColor(md
->mColor
[BE_RCOMP
],
808 md
->mColor
[BE_GCOMP
],
809 md
->mColor
[BE_BCOMP
],
810 md
->mColor
[BE_ACOMP
]);
815 void MesaDriver::ClearBack(GLcontext
*ctx
,
816 GLboolean all
, GLint x
, GLint y
,
817 GLint width
, GLint height
)
819 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
820 BGLView
*bglview
= md
->m_bglview
;
822 BBitmap
*bitmap
= md
->m_bitmap
;
824 GLuint
*start
= (GLuint
*) bitmap
->Bits();
825 const GLuint
*clearPixelPtr
= (const GLuint
*) md
->m_clear_color
;
826 const GLuint clearPixel
= *clearPixelPtr
;
829 const int numPixels
= md
->m_width
* md
->m_height
;
830 if (clearPixel
== 0) {
831 memset(start
, 0, numPixels
* 4);
834 for (int i
= 0; i
< numPixels
; i
++) {
835 start
[i
] = clearPixel
;
841 start
+= y
* md
->m_width
+ x
;
842 for (int i
= 0; i
< height
; i
++) {
843 for (int j
= 0; j
< width
; j
++) {
844 start
[j
] = clearPixel
;
846 start
+= md
->m_width
;
852 void MesaDriver::SetBuffer(GLcontext
*ctx
, GLframebuffer
*buffer
,
861 void MesaDriver::GetBufferSize(GLframebuffer
* framebuffer
, GLuint
*width
,
864 GET_CURRENT_CONTEXT(ctx
);
868 MesaDriver
* md
= (MesaDriver
*) ctx
->DriverCtx
;
869 BGLView
*bglview
= md
->m_bglview
;
872 BRect b
= bglview
->Bounds();
873 *width
= (GLuint
) b
.IntegerWidth() + 1; // (b.right - b.left + 1);
874 *height
= (GLuint
) b
.IntegerHeight() + 1; // (b.bottom - b.top + 1);
875 md
->m_bottom
= (GLint
) b
.bottom
;
877 if (ctx
->Visual
.doubleBufferMode
) {
878 if (*width
!= md
->m_width
|| *height
!= md
->m_height
) {
879 // allocate new size of back buffer bitmap
882 BRect
rect(0.0, 0.0, *width
- 1, *height
- 1);
883 md
->m_bitmap
= new BBitmap(rect
, B_RGBA32
);
891 md
->m_width
= *width
;
892 md
->m_height
= *height
;
896 const GLubyte
*MesaDriver::GetString(GLcontext
*ctx
, GLenum name
)
900 return (const GLubyte
*) "Mesa BGLView (software)";
902 // Let core library handle all other cases
908 // Plot a pixel. (0,0) is upper-left corner
909 // This is only used when drawing to the front buffer.
910 inline void Plot(BGLView
*bglview
, int x
, int y
)
912 // XXX There's got to be a better way!
913 BPoint
p(x
, y
), q(x
+1, y
);
914 bglview
->StrokeLine(p
, q
);
918 void MesaDriver::WriteRGBASpanFront(const GLcontext
*ctx
, GLuint n
,
920 CONST GLubyte rgba
[][4],
921 const GLubyte mask
[])
923 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
924 BGLView
*bglview
= md
->m_bglview
;
926 int flippedY
= md
->m_bottom
- y
;
928 for (GLuint i
= 0; i
< n
; i
++) {
930 bglview
->SetHighColor(rgba
[i
][0], rgba
[i
][1], rgba
[i
][2], rgba
[i
][3]);
931 Plot(bglview
, x
++, flippedY
);
936 for (GLuint i
= 0; i
< n
; i
++) {
937 bglview
->SetHighColor(rgba
[i
][0], rgba
[i
][1], rgba
[i
][2], rgba
[i
][3]);
938 Plot(bglview
, x
++, flippedY
);
943 void MesaDriver::WriteRGBSpanFront(const GLcontext
*ctx
, GLuint n
,
945 CONST GLubyte rgba
[][3],
946 const GLubyte mask
[])
948 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
949 BGLView
*bglview
= md
->m_bglview
;
951 int flippedY
= md
->m_bottom
- y
;
953 for (GLuint i
= 0; i
< n
; i
++) {
955 bglview
->SetHighColor(rgba
[i
][0], rgba
[i
][1], rgba
[i
][2]);
956 Plot(bglview
, x
++, flippedY
);
961 for (GLuint i
= 0; i
< n
; i
++) {
962 bglview
->SetHighColor(rgba
[i
][0], rgba
[i
][1], rgba
[i
][2]);
963 Plot(bglview
, x
++, flippedY
);
968 void MesaDriver::WriteMonoRGBASpanFront(const GLcontext
*ctx
, GLuint n
,
970 const GLchan color
[4],
971 const GLubyte mask
[])
973 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
974 BGLView
*bglview
= md
->m_bglview
;
976 int flippedY
= md
->m_bottom
- y
;
977 bglview
->SetHighColor(color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
979 for (GLuint i
= 0; i
< n
; i
++) {
981 Plot(bglview
, x
++, flippedY
);
986 for (GLuint i
= 0; i
< n
; i
++) {
987 Plot(bglview
, x
++, flippedY
);
992 void MesaDriver::WriteRGBAPixelsFront(const GLcontext
*ctx
,
993 GLuint n
, const GLint x
[], const GLint y
[],
994 CONST GLubyte rgba
[][4],
995 const GLubyte mask
[] )
997 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
998 BGLView
*bglview
= md
->m_bglview
;
1001 for (GLuint i
= 0; i
< n
; i
++) {
1003 bglview
->SetHighColor(rgba
[i
][0], rgba
[i
][1], rgba
[i
][2]);
1004 Plot(bglview
, x
[i
], md
->m_bottom
- y
[i
]);
1009 for (GLuint i
= 0; i
< n
; i
++) {
1010 bglview
->SetHighColor(rgba
[i
][0], rgba
[i
][1], rgba
[i
][2]);
1011 Plot(bglview
, x
[i
], md
->m_bottom
- y
[i
]);
1017 void MesaDriver::WriteMonoRGBAPixelsFront(const GLcontext
*ctx
, GLuint n
,
1018 const GLint x
[], const GLint y
[],
1019 const GLchan color
[4],
1020 const GLubyte mask
[])
1022 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
1023 BGLView
*bglview
= md
->m_bglview
;
1025 // plot points using current color
1026 bglview
->SetHighColor(color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1028 for (GLuint i
= 0; i
< n
; i
++) {
1030 Plot(bglview
, x
[i
], md
->m_bottom
- y
[i
]);
1035 for (GLuint i
= 0; i
< n
; i
++) {
1036 Plot(bglview
, x
[i
], md
->m_bottom
- y
[i
]);
1042 void MesaDriver::WriteCI32SpanFront( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1043 const GLuint index
[], const GLubyte mask
[] )
1048 void MesaDriver::WriteCI8SpanFront( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1049 const GLubyte index
[], const GLubyte mask
[] )
1054 void MesaDriver::WriteMonoCISpanFront( const GLcontext
*ctx
, GLuint n
,
1056 GLuint colorIndex
, const GLubyte mask
[] )
1062 void MesaDriver::WriteCI32PixelsFront( const GLcontext
*ctx
, GLuint n
,
1063 const GLint x
[], const GLint y
[],
1064 const GLuint index
[], const GLubyte mask
[] )
1069 void MesaDriver::WriteMonoCIPixelsFront( const GLcontext
*ctx
, GLuint n
,
1070 const GLint x
[], const GLint y
[],
1071 GLuint colorIndex
, const GLubyte mask
[] )
1077 void MesaDriver::ReadCI32SpanFront( const GLcontext
*ctx
,
1078 GLuint n
, GLint x
, GLint y
, GLuint index
[] )
1080 printf("ReadCI32SpanFront() not implemented yet!\n");
1085 void MesaDriver::ReadRGBASpanFront( const GLcontext
*ctx
, GLuint n
,
1086 GLint x
, GLint y
, GLubyte rgba
[][4] )
1088 printf("ReadRGBASpanFront() not implemented yet!\n");
1093 void MesaDriver::ReadCI32PixelsFront( const GLcontext
*ctx
,
1094 GLuint n
, const GLint x
[], const GLint y
[],
1095 GLuint indx
[], const GLubyte mask
[] )
1097 printf("ReadCI32PixelsFront() not implemented yet!\n");
1102 void MesaDriver::ReadRGBAPixelsFront( const GLcontext
*ctx
,
1103 GLuint n
, const GLint x
[], const GLint y
[],
1104 GLubyte rgba
[][4], const GLubyte mask
[] )
1106 printf("ReadRGBAPixelsFront() not implemented yet!\n");
1113 void MesaDriver::WriteRGBASpanBack(const GLcontext
*ctx
, GLuint n
,
1115 CONST GLubyte rgba
[][4],
1116 const GLubyte mask
[])
1118 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
1119 BBitmap
*bitmap
= md
->m_bitmap
;
1121 static bool already_called
= false;
1122 if (! already_called
) {
1123 printf("WriteRGBASpanBack() called.\n");
1124 already_called
= true;
1129 int row
= md
->m_bottom
- y
;
1130 uint8
* ptr
= (uint8
*) bitmap
->Bits() + (row
* bitmap
->BytesPerRow()) + x
* 4;
1131 uint32
* pixel
= (uint32
*) ptr
;
1136 *pixel
= PACK_B_RGBA32(rgba
[0]);
1142 *pixel
++ = PACK_B_RGBA32(rgba
[0]);
1149 void MesaDriver::WriteRGBSpanBack(const GLcontext
*ctx
, GLuint n
,
1151 CONST GLubyte rgb
[][3],
1152 const GLubyte mask
[])
1154 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
1155 BBitmap
*bitmap
= md
->m_bitmap
;
1157 static bool already_called
= false;
1158 if (! already_called
) {
1159 printf("WriteRGBSpanBack() called.\n");
1160 already_called
= true;
1165 int row
= md
->m_bottom
- y
;
1166 uint8
* ptr
= (uint8
*) bitmap
->Bits() + (row
* bitmap
->BytesPerRow()) + x
* 4;
1167 uint32
* pixel
= (uint32
*) ptr
;
1172 *pixel
= PACK_B_RGB32(rgb
[0]);
1178 *pixel
++ = PACK_B_RGB32(rgb
[0]);
1187 void MesaDriver::WriteMonoRGBASpanBack(const GLcontext
*ctx
, GLuint n
,
1189 const GLchan color
[4], const GLubyte mask
[])
1191 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
1192 BBitmap
*bitmap
= md
->m_bitmap
;
1194 static bool already_called
= false;
1195 if (! already_called
) {
1196 printf("WriteMonoRGBASpanBack() called.\n");
1197 already_called
= true;
1202 int row
= md
->m_bottom
- y
;
1203 uint8
* ptr
= (uint8
*) bitmap
->Bits() + (row
* bitmap
->BytesPerRow()) + x
* 4;
1204 uint32
* pixel
= (uint32
*) ptr
;
1205 uint32 pixel_color
= PACK_B_RGBA32(color
);
1210 *pixel
= pixel_color
;
1215 *pixel
++ = pixel_color
;
1221 void MesaDriver::WriteRGBAPixelsBack(const GLcontext
*ctx
,
1222 GLuint n
, const GLint x
[], const GLint y
[],
1223 CONST GLubyte rgba
[][4],
1224 const GLubyte mask
[] )
1226 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
1227 BBitmap
*bitmap
= md
->m_bitmap
;
1229 static bool already_called
= false;
1230 if (! already_called
) {
1231 printf("WriteRGBAPixelsBack() called.\n");
1232 already_called
= true;
1239 int row
= md
->m_bottom
- *y
;
1240 uint8
* pixel
= (uint8
*) bitmap
->Bits() + (row
* bitmap
->BytesPerRow()) + *x
* 4;
1241 *((uint32
*) pixel
) = PACK_B_RGBA32(rgba
[0]);
1249 for (GLuint i
= 0; i
< n
; i
++) {
1251 GLubyte
*pixel
= (GLubyte
*) bitmap
->Bits()
1252 + ((md
->m_bottom
- y
[i
]) * bitmap
->BytesPerRow()) + x
[i
] * 4;
1253 pixel
[BE_RCOMP
] = rgba
[i
][RCOMP
];
1254 pixel
[BE_GCOMP
] = rgba
[i
][GCOMP
];
1255 pixel
[BE_BCOMP
] = rgba
[i
][BCOMP
];
1256 pixel
[BE_ACOMP
] = rgba
[i
][ACOMP
];
1261 for (GLuint i
= 0; i
< n
; i
++) {
1262 GLubyte
*pixel
= (GLubyte
*) bitmap
->Bits()
1263 + ((md
->m_bottom
- y
[i
]) * bitmap
->BytesPerRow()) + x
[i
] * 4;
1264 pixel
[BE_RCOMP
] = rgba
[i
][RCOMP
];
1265 pixel
[BE_GCOMP
] = rgba
[i
][GCOMP
];
1266 pixel
[BE_BCOMP
] = rgba
[i
][BCOMP
];
1267 pixel
[BE_ACOMP
] = rgba
[i
][ACOMP
];
1274 void MesaDriver::WriteMonoRGBAPixelsBack(const GLcontext
*ctx
, GLuint n
,
1275 const GLint x
[], const GLint y
[],
1276 const GLchan color
[4],
1277 const GLubyte mask
[])
1279 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
1280 BBitmap
*bitmap
= md
->m_bitmap
;
1282 static bool already_called
= false;
1283 if (! already_called
) {
1284 printf("WriteMonoRGBAPixelsBack() called.\n");
1285 already_called
= true;
1290 uint32 pixel_color
= PACK_B_RGBA32(color
);
1294 int row
= md
->m_bottom
- *y
;
1295 uint8
* pixel
= (uint8
*) bitmap
->Bits() + (row
* bitmap
->BytesPerRow()) + *x
* 4;
1297 *((uint32
*) pixel
) = pixel_color
;
1304 for (GLuint i
= 0; i
< n
; i
++) {
1306 GLubyte
* ptr
= (GLubyte
*) bitmap
->Bits()
1307 + ((md
->m_bottom
- y
[i
]) * bitmap
->BytesPerRow()) + x
[i
] * 4;
1308 *((uint32
*) ptr
) = pixel_color
;
1313 for (GLuint i
= 0; i
< n
; i
++) {
1314 GLubyte
* ptr
= (GLubyte
*) bitmap
->Bits()
1315 + ((md
->m_bottom
- y
[i
]) * bitmap
->BytesPerRow()) + x
[i
] * 4;
1316 *((uint32
*) ptr
) = pixel_color
;
1323 void MesaDriver::WriteCI32SpanBack( const GLcontext
*ctx
, GLuint n
,
1325 const GLuint index
[], const GLubyte mask
[] )
1330 void MesaDriver::WriteCI8SpanBack( const GLcontext
*ctx
, GLuint n
,
1332 const GLubyte index
[], const GLubyte mask
[] )
1337 void MesaDriver::WriteMonoCISpanBack( const GLcontext
*ctx
, GLuint n
,
1339 GLuint colorIndex
, const GLubyte mask
[] )
1345 void MesaDriver::WriteCI32PixelsBack( const GLcontext
*ctx
, GLuint n
,
1346 const GLint x
[], const GLint y
[],
1347 const GLuint index
[], const GLubyte mask
[] )
1352 void MesaDriver::WriteMonoCIPixelsBack( const GLcontext
*ctx
, GLuint n
,
1353 const GLint x
[], const GLint y
[],
1354 GLuint colorIndex
, const GLubyte mask
[] )
1360 void MesaDriver::ReadCI32SpanBack( const GLcontext
*ctx
,
1361 GLuint n
, GLint x
, GLint y
, GLuint index
[] )
1367 void MesaDriver::ReadRGBASpanBack( const GLcontext
*ctx
, GLuint n
,
1368 GLint x
, GLint y
, GLubyte rgba
[][4] )
1370 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
1371 const BBitmap
*bitmap
= md
->m_bitmap
;
1373 int row
= md
->m_bottom
- y
;
1374 const GLubyte
*pixel
= (GLubyte
*) bitmap
->Bits()
1375 + (row
* bitmap
->BytesPerRow()) + x
* 4;
1377 for (GLuint i
= 0; i
< n
; i
++) {
1378 rgba
[i
][RCOMP
] = pixel
[BE_RCOMP
];
1379 rgba
[i
][GCOMP
] = pixel
[BE_GCOMP
];
1380 rgba
[i
][BCOMP
] = pixel
[BE_BCOMP
];
1381 rgba
[i
][ACOMP
] = pixel
[BE_ACOMP
];
1387 void MesaDriver::ReadCI32PixelsBack( const GLcontext
*ctx
,
1388 GLuint n
, const GLint x
[], const GLint y
[],
1389 GLuint indx
[], const GLubyte mask
[] )
1395 void MesaDriver::ReadRGBAPixelsBack( const GLcontext
*ctx
,
1396 GLuint n
, const GLint x
[], const GLint y
[],
1397 GLubyte rgba
[][4], const GLubyte mask
[] )
1399 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
1400 const BBitmap
*bitmap
= md
->m_bitmap
;
1404 for (GLuint i
= 0; i
< n
; i
++) {
1406 GLubyte
*pixel
= (GLubyte
*) bitmap
->Bits()
1407 + ((md
->m_bottom
- y
[i
]) * bitmap
->BytesPerRow()) + x
[i
] * 4;
1408 rgba
[i
][RCOMP
] = pixel
[BE_RCOMP
];
1409 rgba
[i
][GCOMP
] = pixel
[BE_GCOMP
];
1410 rgba
[i
][BCOMP
] = pixel
[BE_BCOMP
];
1411 rgba
[i
][ACOMP
] = pixel
[BE_ACOMP
];
1415 for (GLuint i
= 0; i
< n
; i
++) {
1416 GLubyte
*pixel
= (GLubyte
*) bitmap
->Bits()
1417 + ((md
->m_bottom
- y
[i
]) * bitmap
->BytesPerRow()) + x
[i
] * 4;
1418 rgba
[i
][RCOMP
] = pixel
[BE_RCOMP
];
1419 rgba
[i
][GCOMP
] = pixel
[BE_GCOMP
];
1420 rgba
[i
][BCOMP
] = pixel
[BE_BCOMP
];
1421 rgba
[i
][ACOMP
] = pixel
[BE_ACOMP
];