1 /* $Id: GLView.cpp,v 1.7 2002/10/17 14:25:30 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.
38 #include "extensions.h"
44 #include "texformat.h"
46 #include "array_cache/acache.h"
47 #include "swrast/swrast.h"
48 #include "swrast_setup/swrast_setup.h"
49 #include "swrast/s_context.h"
50 #include "swrast/s_depth.h"
51 #include "swrast/s_lines.h"
52 #include "swrast/s_triangle.h"
53 #include "swrast/s_trispan.h"
55 #include "tnl/t_context.h"
56 #include "tnl/t_pipeline.h"
62 // BeOS component ordering for B_RGBA32 bitmap format
68 #define PACK_B_RGBA32(color) (color[BCOMP] | (color[GCOMP] << 8) | \
69 (color[RCOMP] << 16) | (color[ACOMP] << 24))
71 #define PACK_B_RGB32(color) (color[BCOMP] | (color[GCOMP] << 8) | \
72 (color[RCOMP] << 16) | 0xFF000000)
74 #define FLIP(coord) (LIBGGI_MODE(ggi_ctx->ggi_visual)->visible.y-(coord) - 1)
77 // This object hangs off of the BGLView object. We have to use
78 // Be's BGLView class as-is to maintain binary compatibility (we
79 // can't add new members to it). Instead we just put all our data
80 // in this class and use BGLVIew::m_gc to point to it.
87 void Init(BGLView
* bglview
, GLcontext
* c
, GLvisual
* v
, GLframebuffer
* b
);
91 void SwapBuffers() const;
92 void CopySubBuffer(GLint x
, GLint y
, GLuint width
, GLuint height
) const;
93 void Draw(BRect updateRect
) const;
96 MesaDriver(const MesaDriver
&rhs
); // copy constructor illegal
97 MesaDriver
&operator=(const MesaDriver
&rhs
); // assignment oper. illegal
99 GLcontext
* m_glcontext
;
100 GLvisual
* m_glvisual
;
101 GLframebuffer
* m_glframebuffer
;
106 GLchan m_clear_color
[4]; // buffer clear color
107 GLuint m_clear_index
; // buffer clear color index
108 GLint m_bottom
; // used for flipping Y coords
112 // Mesa Device Driver functions
113 static void UpdateState(GLcontext
*ctx
, GLuint new_state
);
114 static void ClearIndex(GLcontext
*ctx
, GLuint index
);
115 static void ClearColor(GLcontext
*ctx
, const GLfloat color
[4]);
116 static void Clear(GLcontext
*ctx
, GLbitfield mask
,
117 GLboolean all
, GLint x
, GLint y
,
118 GLint width
, GLint height
);
119 static void ClearFront(GLcontext
*ctx
, GLboolean all
, GLint x
, GLint y
,
120 GLint width
, GLint height
);
121 static void ClearBack(GLcontext
*ctx
, GLboolean all
, GLint x
, GLint y
,
122 GLint width
, GLint height
);
123 static void Index(GLcontext
*ctx
, GLuint index
);
124 static void Color(GLcontext
*ctx
, GLubyte r
, GLubyte g
,
125 GLubyte b
, GLubyte a
);
126 static void SetBuffer(GLcontext
*ctx
, GLframebuffer
*colorBuffer
,
128 static void GetBufferSize(GLframebuffer
* framebuffer
, GLuint
*width
,
130 static const GLubyte
* GetString(GLcontext
*ctx
, GLenum name
);
132 // Front-buffer functions
133 static void WriteRGBASpanFront(const GLcontext
*ctx
, GLuint n
,
135 CONST GLubyte rgba
[][4],
136 const GLubyte mask
[]);
137 static void WriteRGBSpanFront(const GLcontext
*ctx
, GLuint n
,
139 CONST GLubyte rgba
[][3],
140 const GLubyte mask
[]);
141 static void WriteMonoRGBASpanFront(const GLcontext
*ctx
, GLuint n
,
143 const GLchan color
[4],
144 const GLubyte mask
[]);
145 static void WriteRGBAPixelsFront(const GLcontext
*ctx
, GLuint n
,
146 const GLint x
[], const GLint y
[],
147 CONST GLubyte rgba
[][4],
148 const GLubyte mask
[]);
149 static void WriteMonoRGBAPixelsFront(const GLcontext
*ctx
, GLuint n
,
150 const GLint x
[], const GLint y
[],
151 const GLchan color
[4],
152 const GLubyte mask
[]);
153 static void WriteCI32SpanFront(const GLcontext
*ctx
, GLuint n
,
155 const GLuint index
[], const GLubyte mask
[]);
156 static void WriteCI8SpanFront(const GLcontext
*ctx
, GLuint n
,
158 const GLubyte index
[], const GLubyte mask
[]);
159 static void WriteMonoCISpanFront(const GLcontext
*ctx
, GLuint n
,
161 GLuint colorIndex
, const GLubyte mask
[]);
162 static void WriteCI32PixelsFront(const GLcontext
*ctx
,
163 GLuint n
, const GLint x
[], const GLint y
[],
164 const GLuint index
[], const GLubyte mask
[]);
165 static void WriteMonoCIPixelsFront(const GLcontext
*ctx
, GLuint n
,
166 const GLint x
[], const GLint y
[],
167 GLuint colorIndex
, const GLubyte mask
[]);
168 static void ReadCI32SpanFront(const GLcontext
*ctx
,
169 GLuint n
, GLint x
, GLint y
, GLuint index
[]);
170 static void ReadRGBASpanFront(const GLcontext
*ctx
, GLuint n
,
173 static void ReadCI32PixelsFront(const GLcontext
*ctx
,
174 GLuint n
, const GLint x
[], const GLint y
[],
175 GLuint indx
[], const GLubyte mask
[]);
176 static void ReadRGBAPixelsFront(const GLcontext
*ctx
,
177 GLuint n
, const GLint x
[], const GLint y
[],
178 GLubyte rgba
[][4], const GLubyte mask
[]);
180 // Back buffer functions
181 static void WriteRGBASpanBack(const GLcontext
*ctx
, GLuint n
,
183 CONST GLubyte rgba
[][4],
184 const GLubyte mask
[]);
185 static void WriteRGBSpanBack(const GLcontext
*ctx
, GLuint n
,
187 CONST GLubyte rgba
[][3],
188 const GLubyte mask
[]);
189 static void WriteMonoRGBASpanBack(const GLcontext
*ctx
, GLuint n
,
191 const GLchan color
[4],
192 const GLubyte mask
[]);
193 static void WriteRGBAPixelsBack(const GLcontext
*ctx
, GLuint n
,
194 const GLint x
[], const GLint y
[],
195 CONST GLubyte rgba
[][4],
196 const GLubyte mask
[]);
197 static void WriteMonoRGBAPixelsBack(const GLcontext
*ctx
, GLuint n
,
198 const GLint x
[], const GLint y
[],
199 const GLchan color
[4],
200 const GLubyte mask
[]);
201 static void WriteCI32SpanBack(const GLcontext
*ctx
, GLuint n
,
203 const GLuint index
[], const GLubyte mask
[]);
204 static void WriteCI8SpanBack(const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
205 const GLubyte index
[], const GLubyte mask
[]);
206 static void WriteMonoCISpanBack(const GLcontext
*ctx
, GLuint n
,
207 GLint x
, GLint y
, GLuint colorIndex
,
208 const GLubyte mask
[]);
209 static void WriteCI32PixelsBack(const GLcontext
*ctx
,
210 GLuint n
, const GLint x
[], const GLint y
[],
211 const GLuint index
[], const GLubyte mask
[]);
212 static void WriteMonoCIPixelsBack(const GLcontext
*ctx
,
213 GLuint n
, const GLint x
[], const GLint y
[],
214 GLuint colorIndex
, const GLubyte mask
[]);
215 static void ReadCI32SpanBack(const GLcontext
*ctx
,
216 GLuint n
, GLint x
, GLint y
, GLuint index
[]);
217 static void ReadRGBASpanBack(const GLcontext
*ctx
, GLuint n
,
220 static void ReadCI32PixelsBack(const GLcontext
*ctx
,
221 GLuint n
, const GLint x
[], const GLint y
[],
222 GLuint indx
[], const GLubyte mask
[]);
223 static void ReadRGBAPixelsBack(const GLcontext
*ctx
,
224 GLuint n
, const GLint x
[], const GLint y
[],
225 GLubyte rgba
[][4], const GLubyte mask
[]);
229 //------------------------------------------------------------------
230 // Public interface methods
231 //------------------------------------------------------------------
235 // Input: rect - initial rectangle
236 // name - window name
237 // resizingMode - example: B_FOLLOW_NONE
238 // mode - usually 0 ?
239 // options - Bitwise-OR of BGL_* tokens
241 BGLView::BGLView(BRect rect
, char *name
,
242 ulong resizingMode
, ulong mode
,
244 :BView(rect
, name
, resizingMode
, mode
| B_WILL_DRAW
| B_FRAME_EVENTS
) // | B_FULL_UPDATE_ON_RESIZE)
246 const GLboolean rgbFlag
= (options
& BGL_RGB
) == BGL_RGB
;
247 const GLboolean alphaFlag
= (options
& BGL_ALPHA
) == BGL_ALPHA
;
248 const GLboolean dblFlag
= (options
& BGL_DOUBLE
) == BGL_DOUBLE
;
249 const GLboolean stereoFlag
= false;
250 const GLint depth
= (options
& BGL_DEPTH
) ? 16 : 0;
251 const GLint stencil
= (options
& BGL_STENCIL
) ? 8 : 0;
252 const GLint accum
= (options
& BGL_ACCUM
) ? 16 : 0;
253 const GLint index
= (options
& BGL_INDEX
) ? 32 : 0;
254 const GLint red
= (options
& BGL_RGB
) ? 8 : 0;
255 const GLint green
= (options
& BGL_RGB
) ? 8 : 0;
256 const GLint blue
= (options
& BGL_RGB
) ? 8 : 0;
257 const GLint alpha
= (options
& BGL_RGB
) ? 8 : 0;
260 fprintf(stderr
, "Mesa Warning: color index mode not supported\n");
263 // Allocate auxiliary data object
264 MesaDriver
* md
= new MesaDriver
;
266 // examine option flags and create gl_context struct
267 GLvisual
* visual
= _mesa_create_visual( rgbFlag
,
270 red
, green
, blue
, alpha
,
274 accum
, accum
, accum
, accum
,
278 // create core context
280 _mesa_init_default_imports(&imports
, md
);
281 GLcontext
* ctx
= _mesa_create_context( visual
, NULL
, &imports
);
284 // create core framebuffer
285 GLframebuffer
* buffer
= _mesa_create_framebuffer(visual
,
286 depth
> 0 ? GL_TRUE
: GL_FALSE
,
287 stencil
> 0 ? GL_TRUE
: GL_FALSE
,
288 accum
> 0 ? GL_TRUE
: GL_FALSE
,
292 _mesa_enable_sw_extensions(ctx
);
293 _mesa_enable_1_3_extensions(ctx
);
294 //_mesa_enable_1_4_extensions(ctx);
296 /* Initialize the software rasterizer and helper modules.
298 _swrast_CreateContext(ctx
);
299 _ac_CreateContext(ctx
);
300 _tnl_CreateContext(ctx
);
301 _swsetup_CreateContext(ctx
);
302 _swsetup_Wakeup(ctx
);
304 md
->Init(this, ctx
, visual
, buffer
);
306 // Hook aux data into BGLView object
313 printf("BGLView destructor\n");
314 MesaDriver
* md
= (MesaDriver
*) m_gc
;
319 void BGLView::LockGL()
321 MesaDriver
* md
= (MesaDriver
*) m_gc
;
326 void BGLView::UnlockGL()
328 MesaDriver
* md
= (MesaDriver
*) m_gc
;
333 void BGLView::SwapBuffers()
335 MesaDriver
* md
= (MesaDriver
*) m_gc
;
341 void BGLView::CopySubBufferMESA(GLint x
, GLint y
, GLuint width
, GLuint height
)
343 MesaDriver
* md
= (MesaDriver
*) m_gc
;
345 md
->CopySubBuffer(x
, y
, width
, height
);
349 BView
* BGLView::EmbeddedView()
355 status_t
BGLView::CopyPixelsOut(BPoint source
, BBitmap
*dest
)
358 printf("BGLView::CopyPixelsOut() not implemented yet!\n");
359 return B_UNSUPPORTED
;
363 status_t
BGLView::CopyPixelsIn(BBitmap
*source
, BPoint dest
)
366 printf("BGLView::CopyPixelsIn() not implemented yet!\n");
367 return B_UNSUPPORTED
;
370 void BGLView::ErrorCallback(unsigned long errorCode
) // GLenum errorCode)
373 printf("BGLView::ErrorCallback() not implemented yet!\n");
377 void BGLView::Draw(BRect updateRect
)
379 // printf("BGLView::Draw()\n");
380 MesaDriver
* md
= (MesaDriver
*) m_gc
;
382 md
->Draw(updateRect
);
385 void BGLView::AttachedToWindow()
387 BView::AttachedToWindow();
389 // don't paint window background white when resized
390 SetViewColor(B_TRANSPARENT_32_BIT
);
393 void BGLView::AllAttached()
395 BView::AllAttached();
396 // printf("BGLView AllAttached\n");
399 void BGLView::DetachedFromWindow()
401 BView::DetachedFromWindow();
404 void BGLView::AllDetached()
406 BView::AllDetached();
407 // printf("BGLView AllDetached");
410 void BGLView::FrameResized(float width
, float height
)
412 return BView::FrameResized(width
, height
);
415 status_t
BGLView::Perform(perform_code d
, void *arg
)
417 return BView::Perform(d
, arg
);
421 status_t
BGLView::Archive(BMessage
*data
, bool deep
) const
423 return BView::Archive(data
, deep
);
426 void BGLView::MessageReceived(BMessage
*msg
)
428 BView::MessageReceived(msg
);
431 void BGLView::SetResizingMode(uint32 mode
)
433 BView::SetResizingMode(mode
);
438 // printf("BGLView Show\n");
444 // printf("BGLView Hide\n");
448 BHandler
*BGLView::ResolveSpecifier(BMessage
*msg
, int32 index
,
449 BMessage
*specifier
, int32 form
,
450 const char *property
)
452 return BView::ResolveSpecifier(msg
, index
, specifier
, form
, property
);
455 status_t
BGLView::GetSupportedSuites(BMessage
*data
)
457 return BView::GetSupportedSuites(data
);
460 void BGLView::DirectConnected( direct_buffer_info
*info
)
465 void BGLView::EnableDirectMode( bool enabled
)
472 //---- private methods ----------
474 void BGLView::_ReservedGLView1() {}
475 void BGLView::_ReservedGLView2() {}
476 void BGLView::_ReservedGLView3() {}
477 void BGLView::_ReservedGLView4() {}
478 void BGLView::_ReservedGLView5() {}
479 void BGLView::_ReservedGLView6() {}
480 void BGLView::_ReservedGLView7() {}
481 void BGLView::_ReservedGLView8() {}
484 BGLView::BGLView(const BGLView
&v
)
487 // XXX not sure how this should work
488 printf("Warning BGLView::copy constructor not implemented\n");
493 BGLView
&BGLView::operator=(const BGLView
&v
)
495 printf("Warning BGLView::operator= not implemented\n");
499 void BGLView::dither_front()
504 bool BGLView::confirm_dither()
510 void BGLView::draw(BRect r
)
515 /* Direct Window stuff */
516 void BGLView::drawScanline( int x1
, int x2
, int y
, void *data
)
521 void BGLView::scanlineHandler(struct rasStateRec
*state
,
527 void BGLView::lock_draw()
532 void BGLView::unlock_draw()
537 bool BGLView::validateView()
545 MesaDriver::MesaDriver()
549 m_glframebuffer
= NULL
;
553 m_clear_color
[BE_RCOMP
] = 0;
554 m_clear_color
[BE_GCOMP
] = 0;
555 m_clear_color
[BE_BCOMP
] = 0;
556 m_clear_color
[BE_ACOMP
] = 0;
562 MesaDriver::~MesaDriver()
564 _mesa_destroy_visual(m_glvisual
);
565 _mesa_destroy_framebuffer(m_glframebuffer
);
566 _mesa_destroy_context(m_glcontext
);
571 void MesaDriver::Init(BGLView
* bglview
, GLcontext
* ctx
, GLvisual
* visual
, GLframebuffer
* framebuffer
)
576 m_glframebuffer
= framebuffer
;
578 MesaDriver
* md
= (MesaDriver
*) ctx
->DriverCtx
;
579 struct swrast_device_driver
* swdd
= _swrast_GetDeviceDriverReference( ctx
);
580 TNLcontext
* tnl
= TNL_CONTEXT(ctx
);
582 assert(md
->m_glcontext
== ctx
);
584 ctx
->Driver
.GetString
= MesaDriver::GetString
;
585 ctx
->Driver
.UpdateState
= MesaDriver::UpdateState
;
586 ctx
->Driver
.GetBufferSize
= MesaDriver::GetBufferSize
;
587 ctx
->Driver
.ResizeBuffers
= _swrast_alloc_buffers
;
589 ctx
->Driver
.Accum
= _swrast_Accum
;
590 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
591 ctx
->Driver
.ClearIndex
= MesaDriver::ClearIndex
;
592 ctx
->Driver
.ClearColor
= MesaDriver::ClearColor
;
593 ctx
->Driver
.Clear
= MesaDriver::Clear
;
594 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
595 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
596 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
598 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
599 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
600 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
601 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
602 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
603 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
604 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
605 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
607 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
608 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
609 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
610 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
611 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
612 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
613 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
614 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
615 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
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 swdd
->SetBuffer
= MesaDriver::SetBuffer
;
626 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
628 _swsetup_Wakeup(ctx
);
632 void MesaDriver::LockGL()
634 m_bglview
->LockLooper();
636 UpdateState(m_glcontext
, 0);
637 _mesa_make_current(m_glcontext
, m_glframebuffer
);
641 void MesaDriver::UnlockGL()
643 m_bglview
->UnlockLooper();
644 // Could call _mesa_make_current(NULL, NULL) but it would just
645 // hinder performance
649 void MesaDriver::SwapBuffers() const
651 // _mesa_swap_buffers();
654 m_bglview
->LockLooper();
655 m_bglview
->DrawBitmap(m_bitmap
, BPoint(0, 0));
656 m_bglview
->UnlockLooper();
661 void MesaDriver::CopySubBuffer(GLint x
, GLint y
, GLuint width
, GLuint height
) const
664 // Source bitmap and view's bitmap are same size.
665 // Source and dest rectangle are the same.
666 // Note (x,y) = (0,0) is the lower-left corner, have to flip Y
669 srcAndDest
.right
= x
+ width
- 1;
670 srcAndDest
.bottom
= m_bottom
- y
;
671 srcAndDest
.top
= srcAndDest
.bottom
- height
+ 1;
672 m_bglview
->DrawBitmap(m_bitmap
, srcAndDest
, srcAndDest
);
677 void MesaDriver::Draw(BRect updateRect
) const
680 m_bglview
->DrawBitmap(m_bitmap
, updateRect
, updateRect
);
684 void MesaDriver::UpdateState( GLcontext
*ctx
, GLuint new_state
)
686 struct swrast_device_driver
* swdd
= _swrast_GetDeviceDriverReference( ctx
);
688 _swrast_InvalidateState( ctx
, new_state
);
689 _swsetup_InvalidateState( ctx
, new_state
);
690 _ac_InvalidateState( ctx
, new_state
);
691 _tnl_InvalidateState( ctx
, new_state
);
693 if (ctx
->Color
.DrawBuffer
== GL_FRONT
) {
694 /* read/write front buffer */
695 swdd
->WriteRGBASpan
= MesaDriver::WriteRGBASpanFront
;
696 swdd
->WriteRGBSpan
= MesaDriver::WriteRGBSpanFront
;
697 swdd
->WriteRGBAPixels
= MesaDriver::WriteRGBAPixelsFront
;
698 swdd
->WriteMonoRGBASpan
= MesaDriver::WriteMonoRGBASpanFront
;
699 swdd
->WriteMonoRGBAPixels
= MesaDriver::WriteMonoRGBAPixelsFront
;
700 swdd
->WriteCI32Span
= MesaDriver::WriteCI32SpanFront
;
701 swdd
->WriteCI8Span
= MesaDriver::WriteCI8SpanFront
;
702 swdd
->WriteMonoCISpan
= MesaDriver::WriteMonoCISpanFront
;
703 swdd
->WriteCI32Pixels
= MesaDriver::WriteCI32PixelsFront
;
704 swdd
->WriteMonoCIPixels
= MesaDriver::WriteMonoCIPixelsFront
;
705 swdd
->ReadRGBASpan
= MesaDriver::ReadRGBASpanFront
;
706 swdd
->ReadRGBAPixels
= MesaDriver::ReadRGBAPixelsFront
;
707 swdd
->ReadCI32Span
= MesaDriver::ReadCI32SpanFront
;
708 swdd
->ReadCI32Pixels
= MesaDriver::ReadCI32PixelsFront
;
711 /* read/write back buffer */
712 swdd
->WriteRGBASpan
= MesaDriver::WriteRGBASpanBack
;
713 swdd
->WriteRGBSpan
= MesaDriver::WriteRGBSpanBack
;
714 swdd
->WriteRGBAPixels
= MesaDriver::WriteRGBAPixelsBack
;
715 swdd
->WriteMonoRGBASpan
= MesaDriver::WriteMonoRGBASpanBack
;
716 swdd
->WriteMonoRGBAPixels
= MesaDriver::WriteMonoRGBAPixelsBack
;
717 swdd
->WriteCI32Span
= MesaDriver::WriteCI32SpanBack
;
718 swdd
->WriteCI8Span
= MesaDriver::WriteCI8SpanBack
;
719 swdd
->WriteMonoCISpan
= MesaDriver::WriteMonoCISpanBack
;
720 swdd
->WriteCI32Pixels
= MesaDriver::WriteCI32PixelsBack
;
721 swdd
->WriteMonoCIPixels
= MesaDriver::WriteMonoCIPixelsBack
;
722 swdd
->ReadRGBASpan
= MesaDriver::ReadRGBASpanBack
;
723 swdd
->ReadRGBAPixels
= MesaDriver::ReadRGBAPixelsBack
;
724 swdd
->ReadCI32Span
= MesaDriver::ReadCI32SpanBack
;
725 swdd
->ReadCI32Pixels
= MesaDriver::ReadCI32PixelsBack
;
730 void MesaDriver::ClearIndex(GLcontext
*ctx
, GLuint index
)
732 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
733 md
->m_clear_index
= index
;
737 void MesaDriver::ClearColor(GLcontext
*ctx
, const GLfloat color
[4])
739 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
740 CLAMPED_FLOAT_TO_CHAN(md
->m_clear_color
[BE_RCOMP
], color
[0]);
741 CLAMPED_FLOAT_TO_CHAN(md
->m_clear_color
[BE_GCOMP
], color
[1]);
742 CLAMPED_FLOAT_TO_CHAN(md
->m_clear_color
[BE_BCOMP
], color
[2]);
743 CLAMPED_FLOAT_TO_CHAN(md
->m_clear_color
[BE_ACOMP
], color
[3]);
744 assert(md
->m_bglview
);
748 void MesaDriver::Clear(GLcontext
*ctx
, GLbitfield mask
,
749 GLboolean all
, GLint x
, GLint y
,
750 GLint width
, GLint height
)
752 if (mask
& DD_FRONT_LEFT_BIT
)
753 ClearFront(ctx
, all
, x
, y
, width
, height
);
754 if (mask
& DD_BACK_LEFT_BIT
)
755 ClearBack(ctx
, all
, x
, y
, width
, height
);
757 mask
&= ~(DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
);
759 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
765 void MesaDriver::ClearFront(GLcontext
*ctx
,
766 GLboolean all
, GLint x
, GLint y
,
767 GLint width
, GLint height
)
769 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
770 BGLView
*bglview
= md
->m_bglview
;
773 bglview
->SetHighColor(md
->m_clear_color
[BE_RCOMP
],
774 md
->m_clear_color
[BE_GCOMP
],
775 md
->m_clear_color
[BE_BCOMP
],
776 md
->m_clear_color
[BE_ACOMP
]);
777 bglview
->SetLowColor(md
->m_clear_color
[BE_RCOMP
],
778 md
->m_clear_color
[BE_GCOMP
],
779 md
->m_clear_color
[BE_BCOMP
],
780 md
->m_clear_color
[BE_ACOMP
]);
782 BRect b
= bglview
->Bounds();
783 bglview
->FillRect(b
);
790 b
.bottom
= md
->m_height
- y
- 1;
791 b
.top
= b
.bottom
- height
;
792 bglview
->FillRect(b
);
795 // restore drawing color
797 bglview
->SetHighColor(md
->mColor
[BE_RCOMP
],
798 md
->mColor
[BE_GCOMP
],
799 md
->mColor
[BE_BCOMP
],
800 md
->mColor
[BE_ACOMP
]);
801 bglview
->SetLowColor(md
->mColor
[BE_RCOMP
],
802 md
->mColor
[BE_GCOMP
],
803 md
->mColor
[BE_BCOMP
],
804 md
->mColor
[BE_ACOMP
]);
809 void MesaDriver::ClearBack(GLcontext
*ctx
,
810 GLboolean all
, GLint x
, GLint y
,
811 GLint width
, GLint height
)
813 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
814 BGLView
*bglview
= md
->m_bglview
;
816 BBitmap
*bitmap
= md
->m_bitmap
;
818 GLuint
*start
= (GLuint
*) bitmap
->Bits();
819 const GLuint
*clearPixelPtr
= (const GLuint
*) md
->m_clear_color
;
820 const GLuint clearPixel
= *clearPixelPtr
;
823 const int numPixels
= md
->m_width
* md
->m_height
;
824 if (clearPixel
== 0) {
825 memset(start
, 0, numPixels
* 4);
828 for (int i
= 0; i
< numPixels
; i
++) {
829 start
[i
] = clearPixel
;
835 start
+= y
* md
->m_width
+ x
;
836 for (int i
= 0; i
< height
; i
++) {
837 for (int j
= 0; j
< width
; j
++) {
838 start
[j
] = clearPixel
;
840 start
+= md
->m_width
;
846 void MesaDriver::SetBuffer(GLcontext
*ctx
, GLframebuffer
*buffer
,
855 void MesaDriver::GetBufferSize(GLframebuffer
* framebuffer
, GLuint
*width
,
858 GET_CURRENT_CONTEXT(ctx
);
862 MesaDriver
* md
= (MesaDriver
*) ctx
->DriverCtx
;
863 BGLView
*bglview
= md
->m_bglview
;
866 BRect b
= bglview
->Bounds();
867 *width
= (GLuint
) b
.IntegerWidth() + 1; // (b.right - b.left + 1);
868 *height
= (GLuint
) b
.IntegerHeight() + 1; // (b.bottom - b.top + 1);
869 md
->m_bottom
= (GLint
) b
.bottom
;
871 if (ctx
->Visual
.doubleBufferMode
) {
872 if (*width
!= md
->m_width
|| *height
!= md
->m_height
) {
873 // allocate new size of back buffer bitmap
876 BRect
rect(0.0, 0.0, *width
- 1, *height
- 1);
877 md
->m_bitmap
= new BBitmap(rect
, B_RGBA32
);
885 md
->m_width
= *width
;
886 md
->m_height
= *height
;
890 const GLubyte
*MesaDriver::GetString(GLcontext
*ctx
, GLenum name
)
894 return (const GLubyte
*) "Mesa BGLView (software)";
896 // Let core library handle all other cases
902 // Plot a pixel. (0,0) is upper-left corner
903 // This is only used when drawing to the front buffer.
904 static void Plot(BGLView
*bglview
, int x
, int y
)
906 // XXX There's got to be a better way!
907 BPoint
p(x
, y
), q(x
+1, y
);
908 bglview
->StrokeLine(p
, q
);
912 void MesaDriver::WriteRGBASpanFront(const GLcontext
*ctx
, GLuint n
,
914 CONST GLubyte rgba
[][4],
915 const GLubyte mask
[])
917 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
918 BGLView
*bglview
= md
->m_bglview
;
920 int flippedY
= md
->m_bottom
- y
;
922 for (GLuint i
= 0; i
< n
; i
++) {
924 bglview
->SetHighColor(rgba
[i
][0], rgba
[i
][1], rgba
[i
][2], rgba
[i
][3]);
925 Plot(bglview
, x
++, flippedY
);
930 for (GLuint i
= 0; i
< n
; i
++) {
931 bglview
->SetHighColor(rgba
[i
][0], rgba
[i
][1], rgba
[i
][2], rgba
[i
][3]);
932 Plot(bglview
, x
++, flippedY
);
937 void MesaDriver::WriteRGBSpanFront(const GLcontext
*ctx
, GLuint n
,
939 CONST GLubyte rgba
[][3],
940 const GLubyte mask
[])
942 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
943 BGLView
*bglview
= md
->m_bglview
;
945 int flippedY
= md
->m_bottom
- y
;
947 for (GLuint i
= 0; i
< n
; i
++) {
949 bglview
->SetHighColor(rgba
[i
][0], rgba
[i
][1], rgba
[i
][2]);
950 Plot(bglview
, x
++, flippedY
);
955 for (GLuint i
= 0; i
< n
; i
++) {
956 bglview
->SetHighColor(rgba
[i
][0], rgba
[i
][1], rgba
[i
][2]);
957 Plot(bglview
, x
++, flippedY
);
962 void MesaDriver::WriteMonoRGBASpanFront(const GLcontext
*ctx
, GLuint n
,
964 const GLchan color
[4],
965 const GLubyte mask
[])
967 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
968 BGLView
*bglview
= md
->m_bglview
;
970 int flippedY
= md
->m_bottom
- y
;
971 bglview
->SetHighColor(color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
973 for (GLuint i
= 0; i
< n
; i
++) {
975 Plot(bglview
, x
++, flippedY
);
980 for (GLuint i
= 0; i
< n
; i
++) {
981 Plot(bglview
, x
++, flippedY
);
986 void MesaDriver::WriteRGBAPixelsFront(const GLcontext
*ctx
,
987 GLuint n
, const GLint x
[], const GLint y
[],
988 CONST GLubyte rgba
[][4],
989 const GLubyte mask
[] )
991 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
992 BGLView
*bglview
= md
->m_bglview
;
995 for (GLuint i
= 0; i
< n
; i
++) {
997 bglview
->SetHighColor(rgba
[i
][0], rgba
[i
][1], rgba
[i
][2]);
998 Plot(bglview
, x
[i
], md
->m_bottom
- y
[i
]);
1003 for (GLuint i
= 0; i
< n
; i
++) {
1004 bglview
->SetHighColor(rgba
[i
][0], rgba
[i
][1], rgba
[i
][2]);
1005 Plot(bglview
, x
[i
], md
->m_bottom
- y
[i
]);
1011 void MesaDriver::WriteMonoRGBAPixelsFront(const GLcontext
*ctx
, GLuint n
,
1012 const GLint x
[], const GLint y
[],
1013 const GLchan color
[4],
1014 const GLubyte mask
[])
1016 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
1017 BGLView
*bglview
= md
->m_bglview
;
1019 // plot points using current color
1020 bglview
->SetHighColor(color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1022 for (GLuint i
= 0; i
< n
; i
++) {
1024 Plot(bglview
, x
[i
], md
->m_bottom
- y
[i
]);
1029 for (GLuint i
= 0; i
< n
; i
++) {
1030 Plot(bglview
, x
[i
], md
->m_bottom
- y
[i
]);
1036 void MesaDriver::WriteCI32SpanFront( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1037 const GLuint index
[], const GLubyte mask
[] )
1042 void MesaDriver::WriteCI8SpanFront( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
1043 const GLubyte index
[], const GLubyte mask
[] )
1048 void MesaDriver::WriteMonoCISpanFront( const GLcontext
*ctx
, GLuint n
,
1050 GLuint colorIndex
, const GLubyte mask
[] )
1056 void MesaDriver::WriteCI32PixelsFront( const GLcontext
*ctx
, GLuint n
,
1057 const GLint x
[], const GLint y
[],
1058 const GLuint index
[], const GLubyte mask
[] )
1063 void MesaDriver::WriteMonoCIPixelsFront( const GLcontext
*ctx
, GLuint n
,
1064 const GLint x
[], const GLint y
[],
1065 GLuint colorIndex
, const GLubyte mask
[] )
1071 void MesaDriver::ReadCI32SpanFront( const GLcontext
*ctx
,
1072 GLuint n
, GLint x
, GLint y
, GLuint index
[] )
1074 printf("ReadCI32SpanFront() not implemented yet!\n");
1079 void MesaDriver::ReadRGBASpanFront( const GLcontext
*ctx
, GLuint n
,
1080 GLint x
, GLint y
, GLubyte rgba
[][4] )
1082 printf("ReadRGBASpanFront() not implemented yet!\n");
1087 void MesaDriver::ReadCI32PixelsFront( const GLcontext
*ctx
,
1088 GLuint n
, const GLint x
[], const GLint y
[],
1089 GLuint indx
[], const GLubyte mask
[] )
1091 printf("ReadCI32PixelsFront() not implemented yet!\n");
1096 void MesaDriver::ReadRGBAPixelsFront( const GLcontext
*ctx
,
1097 GLuint n
, const GLint x
[], const GLint y
[],
1098 GLubyte rgba
[][4], const GLubyte mask
[] )
1100 printf("ReadRGBAPixelsFront() not implemented yet!\n");
1107 void MesaDriver::WriteRGBASpanBack(const GLcontext
*ctx
, GLuint n
,
1109 CONST GLubyte rgba
[][4],
1110 const GLubyte mask
[])
1112 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
1113 BBitmap
*bitmap
= md
->m_bitmap
;
1115 static bool already_called
= false;
1116 if (! already_called
) {
1117 printf("WriteRGBASpanBack() called.\n");
1118 already_called
= true;
1123 int row
= md
->m_bottom
- y
;
1124 uint8
* ptr
= (uint8
*) bitmap
->Bits() + (row
* bitmap
->BytesPerRow()) + x
* 4;
1125 uint32
* pixel
= (uint32
*) ptr
;
1130 *pixel
= PACK_B_RGBA32(rgba
[0]);
1136 *pixel
++ = PACK_B_RGBA32(rgba
[0]);
1143 void MesaDriver::WriteRGBSpanBack(const GLcontext
*ctx
, GLuint n
,
1145 CONST GLubyte rgb
[][3],
1146 const GLubyte mask
[])
1148 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
1149 BBitmap
*bitmap
= md
->m_bitmap
;
1151 static bool already_called
= false;
1152 if (! already_called
) {
1153 printf("WriteRGBSpanBack() called.\n");
1154 already_called
= true;
1159 int row
= md
->m_bottom
- y
;
1160 uint8
* ptr
= (uint8
*) bitmap
->Bits() + (row
* bitmap
->BytesPerRow()) + x
* 4;
1161 uint32
* pixel
= (uint32
*) ptr
;
1166 *pixel
= PACK_B_RGB32(rgb
[0]);
1172 *pixel
++ = PACK_B_RGB32(rgb
[0]);
1181 void MesaDriver::WriteMonoRGBASpanBack(const GLcontext
*ctx
, GLuint n
,
1183 const GLchan color
[4], const GLubyte mask
[])
1185 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
1186 BBitmap
*bitmap
= md
->m_bitmap
;
1188 static bool already_called
= false;
1189 if (! already_called
) {
1190 printf("WriteMonoRGBASpanBack() called.\n");
1191 already_called
= true;
1196 int row
= md
->m_bottom
- y
;
1197 uint8
* ptr
= (uint8
*) bitmap
->Bits() + (row
* bitmap
->BytesPerRow()) + x
* 4;
1198 uint32
* pixel
= (uint32
*) ptr
;
1199 uint32 pixel_color
= PACK_B_RGBA32(color
);
1204 *pixel
= pixel_color
;
1209 *pixel
++ = pixel_color
;
1215 void MesaDriver::WriteRGBAPixelsBack(const GLcontext
*ctx
,
1216 GLuint n
, const GLint x
[], const GLint y
[],
1217 CONST GLubyte rgba
[][4],
1218 const GLubyte mask
[] )
1220 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
1221 BBitmap
*bitmap
= md
->m_bitmap
;
1223 static bool already_called
= false;
1224 if (! already_called
) {
1225 printf("WriteRGBAPixelsBack() called.\n");
1226 already_called
= true;
1233 int row
= md
->m_bottom
- *y
;
1234 uint8
* pixel
= (uint8
*) bitmap
->Bits() + (row
* bitmap
->BytesPerRow()) + *x
* 4;
1235 *((uint32
*) pixel
) = PACK_B_RGBA32(rgba
[0]);
1243 for (GLuint i
= 0; i
< n
; i
++) {
1245 GLubyte
*pixel
= (GLubyte
*) bitmap
->Bits()
1246 + ((md
->m_bottom
- y
[i
]) * bitmap
->BytesPerRow()) + x
[i
] * 4;
1247 pixel
[BE_RCOMP
] = rgba
[i
][RCOMP
];
1248 pixel
[BE_GCOMP
] = rgba
[i
][GCOMP
];
1249 pixel
[BE_BCOMP
] = rgba
[i
][BCOMP
];
1250 pixel
[BE_ACOMP
] = rgba
[i
][ACOMP
];
1255 for (GLuint i
= 0; i
< n
; i
++) {
1256 GLubyte
*pixel
= (GLubyte
*) bitmap
->Bits()
1257 + ((md
->m_bottom
- y
[i
]) * bitmap
->BytesPerRow()) + x
[i
] * 4;
1258 pixel
[BE_RCOMP
] = rgba
[i
][RCOMP
];
1259 pixel
[BE_GCOMP
] = rgba
[i
][GCOMP
];
1260 pixel
[BE_BCOMP
] = rgba
[i
][BCOMP
];
1261 pixel
[BE_ACOMP
] = rgba
[i
][ACOMP
];
1268 void MesaDriver::WriteMonoRGBAPixelsBack(const GLcontext
*ctx
, GLuint n
,
1269 const GLint x
[], const GLint y
[],
1270 const GLchan color
[4],
1271 const GLubyte mask
[])
1273 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
1274 BBitmap
*bitmap
= md
->m_bitmap
;
1276 static bool already_called
= false;
1277 if (! already_called
) {
1278 printf("WriteMonoRGBAPixelsBack() called.\n");
1279 already_called
= true;
1284 uint32 pixel_color
= PACK_B_RGBA32(color
);
1288 int row
= md
->m_bottom
- *y
;
1289 uint8
* pixel
= (uint8
*) bitmap
->Bits() + (row
* bitmap
->BytesPerRow()) + *x
* 4;
1291 *((uint32
*) pixel
) = pixel_color
;
1298 for (GLuint i
= 0; i
< n
; i
++) {
1300 GLubyte
* ptr
= (GLubyte
*) bitmap
->Bits()
1301 + ((md
->m_bottom
- y
[i
]) * bitmap
->BytesPerRow()) + x
[i
] * 4;
1302 *((uint32
*) ptr
) = pixel_color
;
1307 for (GLuint i
= 0; i
< n
; i
++) {
1308 GLubyte
* ptr
= (GLubyte
*) bitmap
->Bits()
1309 + ((md
->m_bottom
- y
[i
]) * bitmap
->BytesPerRow()) + x
[i
] * 4;
1310 *((uint32
*) ptr
) = pixel_color
;
1317 void MesaDriver::WriteCI32SpanBack( const GLcontext
*ctx
, GLuint n
,
1319 const GLuint index
[], const GLubyte mask
[] )
1324 void MesaDriver::WriteCI8SpanBack( const GLcontext
*ctx
, GLuint n
,
1326 const GLubyte index
[], const GLubyte mask
[] )
1331 void MesaDriver::WriteMonoCISpanBack( const GLcontext
*ctx
, GLuint n
,
1333 GLuint colorIndex
, const GLubyte mask
[] )
1339 void MesaDriver::WriteCI32PixelsBack( const GLcontext
*ctx
, GLuint n
,
1340 const GLint x
[], const GLint y
[],
1341 const GLuint index
[], const GLubyte mask
[] )
1346 void MesaDriver::WriteMonoCIPixelsBack( const GLcontext
*ctx
, GLuint n
,
1347 const GLint x
[], const GLint y
[],
1348 GLuint colorIndex
, const GLubyte mask
[] )
1354 void MesaDriver::ReadCI32SpanBack( const GLcontext
*ctx
,
1355 GLuint n
, GLint x
, GLint y
, GLuint index
[] )
1361 void MesaDriver::ReadRGBASpanBack( const GLcontext
*ctx
, GLuint n
,
1362 GLint x
, GLint y
, GLubyte rgba
[][4] )
1364 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
1365 const BBitmap
*bitmap
= md
->m_bitmap
;
1367 int row
= md
->m_bottom
- y
;
1368 const GLubyte
*pixel
= (GLubyte
*) bitmap
->Bits()
1369 + (row
* bitmap
->BytesPerRow()) + x
* 4;
1371 for (GLuint i
= 0; i
< n
; i
++) {
1372 rgba
[i
][RCOMP
] = pixel
[BE_RCOMP
];
1373 rgba
[i
][GCOMP
] = pixel
[BE_GCOMP
];
1374 rgba
[i
][BCOMP
] = pixel
[BE_BCOMP
];
1375 rgba
[i
][ACOMP
] = pixel
[BE_ACOMP
];
1381 void MesaDriver::ReadCI32PixelsBack( const GLcontext
*ctx
,
1382 GLuint n
, const GLint x
[], const GLint y
[],
1383 GLuint indx
[], const GLubyte mask
[] )
1389 void MesaDriver::ReadRGBAPixelsBack( const GLcontext
*ctx
,
1390 GLuint n
, const GLint x
[], const GLint y
[],
1391 GLubyte rgba
[][4], const GLubyte mask
[] )
1393 MesaDriver
*md
= (MesaDriver
*) ctx
->DriverCtx
;
1394 const BBitmap
*bitmap
= md
->m_bitmap
;
1398 for (GLuint i
= 0; i
< n
; i
++) {
1400 GLubyte
*pixel
= (GLubyte
*) bitmap
->Bits()
1401 + ((md
->m_bottom
- y
[i
]) * bitmap
->BytesPerRow()) + x
[i
] * 4;
1402 rgba
[i
][RCOMP
] = pixel
[BE_RCOMP
];
1403 rgba
[i
][GCOMP
] = pixel
[BE_GCOMP
];
1404 rgba
[i
][BCOMP
] = pixel
[BE_BCOMP
];
1405 rgba
[i
][ACOMP
] = pixel
[BE_ACOMP
];
1409 for (GLuint i
= 0; i
< n
; i
++) {
1410 GLubyte
*pixel
= (GLubyte
*) bitmap
->Bits()
1411 + ((md
->m_bottom
- y
[i
]) * bitmap
->BytesPerRow()) + x
[i
] * 4;
1412 rgba
[i
][RCOMP
] = pixel
[BE_RCOMP
];
1413 rgba
[i
][GCOMP
] = pixel
[BE_GCOMP
];
1414 rgba
[i
][BCOMP
] = pixel
[BE_BCOMP
];
1415 rgba
[i
][ACOMP
] = pixel
[BE_ACOMP
];