37f2fd5dae2f9f321087adda7f9c2c40b76f4714
[mesa.git] / src / mesa / drivers / beos / GLView.cpp
1 /* $Id: GLView.cpp,v 1.7 2002/10/17 14:25:30 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 4.1
6 *
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 */
26
27
28 #include "glheader.h"
29
30 #include <assert.h>
31 #include <stdio.h>
32
33 extern "C" {
34
35 #include "context.h"
36 #include "colormac.h"
37 #include "depth.h"
38 #include "extensions.h"
39 #include "macros.h"
40 #include "matrix.h"
41 #include "mem.h"
42 #include "mmath.h"
43 #include "mtypes.h"
44 #include "texformat.h"
45 #include "texstore.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"
54 #include "tnl/tnl.h"
55 #include "tnl/t_context.h"
56 #include "tnl/t_pipeline.h"
57
58 } // extern "C"
59
60 #include <GLView.h>
61
62 // BeOS component ordering for B_RGBA32 bitmap format
63 #define BE_RCOMP 2
64 #define BE_GCOMP 1
65 #define BE_BCOMP 0
66 #define BE_ACOMP 3
67
68 #define PACK_B_RGBA32(color) (color[BCOMP] | (color[GCOMP] << 8) | \
69 (color[RCOMP] << 16) | (color[ACOMP] << 24))
70
71 #define PACK_B_RGB32(color) (color[BCOMP] | (color[GCOMP] << 8) | \
72 (color[RCOMP] << 16) | 0xFF000000)
73
74 #define FLIP(coord) (LIBGGI_MODE(ggi_ctx->ggi_visual)->visible.y-(coord) - 1)
75
76 //
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.
81 //
82 class MesaDriver
83 {
84 public:
85 MesaDriver();
86 ~MesaDriver();
87 void Init(BGLView * bglview, GLcontext * c, GLvisual * v, GLframebuffer * b);
88
89 void LockGL();
90 void UnlockGL();
91 void SwapBuffers() const;
92 void CopySubBuffer(GLint x, GLint y, GLuint width, GLuint height) const;
93 void Draw(BRect updateRect) const;
94
95 private:
96 MesaDriver(const MesaDriver &rhs); // copy constructor illegal
97 MesaDriver &operator=(const MesaDriver &rhs); // assignment oper. illegal
98
99 GLcontext * m_glcontext;
100 GLvisual * m_glvisual;
101 GLframebuffer * m_glframebuffer;
102
103 BGLView * m_bglview;
104 BBitmap * m_bitmap;
105
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
109 GLuint m_width;
110 GLuint m_height;
111
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,
127 GLenum mode);
128 static void GetBufferSize(GLframebuffer * framebuffer, GLuint *width,
129 GLuint *height);
130 static const GLubyte * GetString(GLcontext *ctx, GLenum name);
131
132 // Front-buffer functions
133 static void WriteRGBASpanFront(const GLcontext *ctx, GLuint n,
134 GLint x, GLint y,
135 CONST GLubyte rgba[][4],
136 const GLubyte mask[]);
137 static void WriteRGBSpanFront(const GLcontext *ctx, GLuint n,
138 GLint x, GLint y,
139 CONST GLubyte rgba[][3],
140 const GLubyte mask[]);
141 static void WriteMonoRGBASpanFront(const GLcontext *ctx, GLuint n,
142 GLint x, GLint y,
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,
154 GLint x, GLint y,
155 const GLuint index[], const GLubyte mask[]);
156 static void WriteCI8SpanFront(const GLcontext *ctx, GLuint n,
157 GLint x, GLint y,
158 const GLubyte index[], const GLubyte mask[]);
159 static void WriteMonoCISpanFront(const GLcontext *ctx, GLuint n,
160 GLint x, GLint y,
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,
171 GLint x, GLint y,
172 GLubyte rgba[][4]);
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[]);
179
180 // Back buffer functions
181 static void WriteRGBASpanBack(const GLcontext *ctx, GLuint n,
182 GLint x, GLint y,
183 CONST GLubyte rgba[][4],
184 const GLubyte mask[]);
185 static void WriteRGBSpanBack(const GLcontext *ctx, GLuint n,
186 GLint x, GLint y,
187 CONST GLubyte rgba[][3],
188 const GLubyte mask[]);
189 static void WriteMonoRGBASpanBack(const GLcontext *ctx, GLuint n,
190 GLint x, GLint y,
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,
202 GLint x, GLint y,
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,
218 GLint x, GLint y,
219 GLubyte rgba[][4]);
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[]);
226
227 };
228
229 //------------------------------------------------------------------
230 // Public interface methods
231 //------------------------------------------------------------------
232
233
234 //
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
240 //
241 BGLView::BGLView(BRect rect, char *name,
242 ulong resizingMode, ulong mode,
243 ulong options)
244 :BView(rect, name, resizingMode, mode | B_WILL_DRAW | B_FRAME_EVENTS) // | B_FULL_UPDATE_ON_RESIZE)
245 {
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;
258
259 if (!rgbFlag) {
260 fprintf(stderr, "Mesa Warning: color index mode not supported\n");
261 }
262
263 // Allocate auxiliary data object
264 MesaDriver * md = new MesaDriver;
265
266 // examine option flags and create gl_context struct
267 GLvisual * visual = _mesa_create_visual( rgbFlag,
268 dblFlag,
269 stereoFlag,
270 red, green, blue, alpha,
271 index,
272 depth,
273 stencil,
274 accum, accum, accum, accum,
275 1
276 );
277
278 // create core context
279 __GLimports imports;
280 _mesa_init_default_imports(&imports, md);
281 GLcontext * ctx = _mesa_create_context( visual, NULL, &imports);
282
283
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,
289 alphaFlag
290 );
291
292 _mesa_enable_sw_extensions(ctx);
293 _mesa_enable_1_3_extensions(ctx);
294 //_mesa_enable_1_4_extensions(ctx);
295
296 /* Initialize the software rasterizer and helper modules.
297 */
298 _swrast_CreateContext(ctx);
299 _ac_CreateContext(ctx);
300 _tnl_CreateContext(ctx);
301 _swsetup_CreateContext(ctx);
302 _swsetup_Wakeup(ctx);
303
304 md->Init(this, ctx, visual, buffer );
305
306 // Hook aux data into BGLView object
307 m_gc = md;
308 }
309
310
311 BGLView::~BGLView()
312 {
313 printf("BGLView destructor\n");
314 MesaDriver * md = (MesaDriver *) m_gc;
315 assert(md);
316 delete md;
317 }
318
319 void BGLView::LockGL()
320 {
321 MesaDriver * md = (MesaDriver *) m_gc;
322 assert(md);
323 md->LockGL();
324 }
325
326 void BGLView::UnlockGL()
327 {
328 MesaDriver * md = (MesaDriver *) m_gc;
329 assert(md);
330 md->UnlockGL();
331 }
332
333 void BGLView::SwapBuffers()
334 {
335 MesaDriver * md = (MesaDriver *) m_gc;
336 assert(md);
337 md->SwapBuffers();
338 }
339
340
341 void BGLView::CopySubBufferMESA(GLint x, GLint y, GLuint width, GLuint height)
342 {
343 MesaDriver * md = (MesaDriver *) m_gc;
344 assert(md);
345 md->CopySubBuffer(x, y, width, height);
346 }
347
348
349 BView * BGLView::EmbeddedView()
350 {
351 // XXX to do
352 return NULL;
353 }
354
355 status_t BGLView::CopyPixelsOut(BPoint source, BBitmap *dest)
356 {
357 // XXX to do
358 printf("BGLView::CopyPixelsOut() not implemented yet!\n");
359 return B_UNSUPPORTED;
360 }
361
362
363 status_t BGLView::CopyPixelsIn(BBitmap *source, BPoint dest)
364 {
365 // XXX to do
366 printf("BGLView::CopyPixelsIn() not implemented yet!\n");
367 return B_UNSUPPORTED;
368 }
369
370 void BGLView::ErrorCallback(unsigned long errorCode) // GLenum errorCode)
371 {
372 // XXX to do
373 printf("BGLView::ErrorCallback() not implemented yet!\n");
374 return;
375 }
376
377 void BGLView::Draw(BRect updateRect)
378 {
379 // printf("BGLView::Draw()\n");
380 MesaDriver * md = (MesaDriver *) m_gc;
381 assert(md);
382 md->Draw(updateRect);
383 }
384
385 void BGLView::AttachedToWindow()
386 {
387 BView::AttachedToWindow();
388
389 // don't paint window background white when resized
390 SetViewColor(B_TRANSPARENT_32_BIT);
391 }
392
393 void BGLView::AllAttached()
394 {
395 BView::AllAttached();
396 // printf("BGLView AllAttached\n");
397 }
398
399 void BGLView::DetachedFromWindow()
400 {
401 BView::DetachedFromWindow();
402 }
403
404 void BGLView::AllDetached()
405 {
406 BView::AllDetached();
407 // printf("BGLView AllDetached");
408 }
409
410 void BGLView::FrameResized(float width, float height)
411 {
412 return BView::FrameResized(width, height);
413 }
414
415 status_t BGLView::Perform(perform_code d, void *arg)
416 {
417 return BView::Perform(d, arg);
418 }
419
420
421 status_t BGLView::Archive(BMessage *data, bool deep) const
422 {
423 return BView::Archive(data, deep);
424 }
425
426 void BGLView::MessageReceived(BMessage *msg)
427 {
428 BView::MessageReceived(msg);
429 }
430
431 void BGLView::SetResizingMode(uint32 mode)
432 {
433 BView::SetResizingMode(mode);
434 }
435
436 void BGLView::Show()
437 {
438 // printf("BGLView Show\n");
439 BView::Show();
440 }
441
442 void BGLView::Hide()
443 {
444 // printf("BGLView Hide\n");
445 BView::Hide();
446 }
447
448 BHandler *BGLView::ResolveSpecifier(BMessage *msg, int32 index,
449 BMessage *specifier, int32 form,
450 const char *property)
451 {
452 return BView::ResolveSpecifier(msg, index, specifier, form, property);
453 }
454
455 status_t BGLView::GetSupportedSuites(BMessage *data)
456 {
457 return BView::GetSupportedSuites(data);
458 }
459
460 void BGLView::DirectConnected( direct_buffer_info *info )
461 {
462 // XXX to do
463 }
464
465 void BGLView::EnableDirectMode( bool enabled )
466 {
467 // XXX to do
468 }
469
470
471
472 //---- private methods ----------
473
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() {}
482
483 #if 0
484 BGLView::BGLView(const BGLView &v)
485 : BView(v)
486 {
487 // XXX not sure how this should work
488 printf("Warning BGLView::copy constructor not implemented\n");
489 }
490 #endif
491
492
493 BGLView &BGLView::operator=(const BGLView &v)
494 {
495 printf("Warning BGLView::operator= not implemented\n");
496 return *this;
497 }
498
499 void BGLView::dither_front()
500 {
501 // no-op
502 }
503
504 bool BGLView::confirm_dither()
505 {
506 // no-op
507 return false;
508 }
509
510 void BGLView::draw(BRect r)
511 {
512 // XXX no-op ???
513 }
514
515 /* Direct Window stuff */
516 void BGLView::drawScanline( int x1, int x2, int y, void *data )
517 {
518 // no-op
519 }
520
521 void BGLView::scanlineHandler(struct rasStateRec *state,
522 GLint x1, GLint x2)
523 {
524 // no-op
525 }
526
527 void BGLView::lock_draw()
528 {
529 // no-op
530 }
531
532 void BGLView::unlock_draw()
533 {
534 // no-op
535 }
536
537 bool BGLView::validateView()
538 {
539 // no-op
540 return true;
541 }
542
543 // #pragma mark -
544
545 MesaDriver::MesaDriver()
546 {
547 m_glcontext = NULL;
548 m_glvisual = NULL;
549 m_glframebuffer = NULL;
550 m_bglview = NULL;
551 m_bitmap = NULL;
552
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;
557
558 m_clear_index = 0;
559 }
560
561
562 MesaDriver::~MesaDriver()
563 {
564 _mesa_destroy_visual(m_glvisual);
565 _mesa_destroy_framebuffer(m_glframebuffer);
566 _mesa_destroy_context(m_glcontext);
567
568 }
569
570
571 void MesaDriver::Init(BGLView * bglview, GLcontext * ctx, GLvisual * visual, GLframebuffer * framebuffer)
572 {
573 m_bglview = bglview;
574 m_glcontext = ctx;
575 m_glvisual = visual;
576 m_glframebuffer = framebuffer;
577
578 MesaDriver * md = (MesaDriver *) ctx->DriverCtx;
579 struct swrast_device_driver * swdd = _swrast_GetDeviceDriverReference( ctx );
580 TNLcontext * tnl = TNL_CONTEXT(ctx);
581
582 assert(md->m_glcontext == ctx );
583
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;
588
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;
597
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;
606
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;
616
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;
623
624 swdd->SetBuffer = MesaDriver::SetBuffer;
625
626 tnl->Driver.RunPipeline = _tnl_run_pipeline;
627
628 _swsetup_Wakeup(ctx);
629 }
630
631
632 void MesaDriver::LockGL()
633 {
634 m_bglview->LockLooper();
635
636 UpdateState(m_glcontext, 0);
637 _mesa_make_current(m_glcontext, m_glframebuffer);
638 }
639
640
641 void MesaDriver::UnlockGL()
642 {
643 m_bglview->UnlockLooper();
644 // Could call _mesa_make_current(NULL, NULL) but it would just
645 // hinder performance
646 }
647
648
649 void MesaDriver::SwapBuffers() const
650 {
651 // _mesa_swap_buffers();
652
653 if (m_bitmap) {
654 m_bglview->LockLooper();
655 m_bglview->DrawBitmap(m_bitmap, BPoint(0, 0));
656 m_bglview->UnlockLooper();
657 };
658 }
659
660
661 void MesaDriver::CopySubBuffer(GLint x, GLint y, GLuint width, GLuint height) const
662 {
663 if (m_bitmap) {
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
667 BRect srcAndDest;
668 srcAndDest.left = x;
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);
673 }
674 }
675
676
677 void MesaDriver::Draw(BRect updateRect) const
678 {
679 if (m_bitmap)
680 m_bglview->DrawBitmap(m_bitmap, updateRect, updateRect);
681 }
682
683
684 void MesaDriver::UpdateState( GLcontext *ctx, GLuint new_state )
685 {
686 struct swrast_device_driver * swdd = _swrast_GetDeviceDriverReference( ctx );
687
688 _swrast_InvalidateState( ctx, new_state );
689 _swsetup_InvalidateState( ctx, new_state );
690 _ac_InvalidateState( ctx, new_state );
691 _tnl_InvalidateState( ctx, new_state );
692
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;
709 }
710 else {
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;
726 }
727 }
728
729
730 void MesaDriver::ClearIndex(GLcontext *ctx, GLuint index)
731 {
732 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
733 md->m_clear_index = index;
734 }
735
736
737 void MesaDriver::ClearColor(GLcontext *ctx, const GLfloat color[4])
738 {
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);
745 }
746
747
748 void MesaDriver::Clear(GLcontext *ctx, GLbitfield mask,
749 GLboolean all, GLint x, GLint y,
750 GLint width, GLint height)
751 {
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);
756
757 mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT);
758 if (mask)
759 _swrast_Clear( ctx, mask, all, x, y, width, height );
760
761 return;
762 }
763
764
765 void MesaDriver::ClearFront(GLcontext *ctx,
766 GLboolean all, GLint x, GLint y,
767 GLint width, GLint height)
768 {
769 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
770 BGLView *bglview = md->m_bglview;
771 assert(bglview);
772
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]);
781 if (all) {
782 BRect b = bglview->Bounds();
783 bglview->FillRect(b);
784 }
785 else {
786 // XXX untested
787 BRect b;
788 b.left = x;
789 b.right = x + width;
790 b.bottom = md->m_height - y - 1;
791 b.top = b.bottom - height;
792 bglview->FillRect(b);
793 }
794
795 // restore drawing color
796 #if 0
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]);
805 #endif
806 }
807
808
809 void MesaDriver::ClearBack(GLcontext *ctx,
810 GLboolean all, GLint x, GLint y,
811 GLint width, GLint height)
812 {
813 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
814 BGLView *bglview = md->m_bglview;
815 assert(bglview);
816 BBitmap *bitmap = md->m_bitmap;
817 assert(bitmap);
818 GLuint *start = (GLuint *) bitmap->Bits();
819 const GLuint *clearPixelPtr = (const GLuint *) md->m_clear_color;
820 const GLuint clearPixel = *clearPixelPtr;
821
822 if (all) {
823 const int numPixels = md->m_width * md->m_height;
824 if (clearPixel == 0) {
825 memset(start, 0, numPixels * 4);
826 }
827 else {
828 for (int i = 0; i < numPixels; i++) {
829 start[i] = clearPixel;
830 }
831 }
832 }
833 else {
834 // XXX untested
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;
839 }
840 start += md->m_width;
841 }
842 }
843 }
844
845
846 void MesaDriver::SetBuffer(GLcontext *ctx, GLframebuffer *buffer,
847 GLenum mode)
848 {
849 /* TODO */
850 (void) ctx;
851 (void) buffer;
852 (void) mode;
853 }
854
855 void MesaDriver::GetBufferSize(GLframebuffer * framebuffer, GLuint *width,
856 GLuint *height)
857 {
858 GET_CURRENT_CONTEXT(ctx);
859 if (!ctx)
860 return;
861
862 MesaDriver * md = (MesaDriver *) ctx->DriverCtx;
863 BGLView *bglview = md->m_bglview;
864 assert(bglview);
865
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;
870
871 if (ctx->Visual.doubleBufferMode) {
872 if (*width != md->m_width || *height != md->m_height) {
873 // allocate new size of back buffer bitmap
874 if (md->m_bitmap)
875 delete md->m_bitmap;
876 BRect rect(0.0, 0.0, *width - 1, *height - 1);
877 md->m_bitmap = new BBitmap(rect, B_RGBA32);
878 }
879 }
880 else
881 {
882 md->m_bitmap = NULL;
883 }
884
885 md->m_width = *width;
886 md->m_height = *height;
887 }
888
889
890 const GLubyte *MesaDriver::GetString(GLcontext *ctx, GLenum name)
891 {
892 switch (name) {
893 case GL_RENDERER:
894 return (const GLubyte *) "Mesa BGLView (software)";
895 default:
896 // Let core library handle all other cases
897 return NULL;
898 }
899 }
900
901
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)
905 {
906 // XXX There's got to be a better way!
907 BPoint p(x, y), q(x+1, y);
908 bglview->StrokeLine(p, q);
909 }
910
911
912 void MesaDriver::WriteRGBASpanFront(const GLcontext *ctx, GLuint n,
913 GLint x, GLint y,
914 CONST GLubyte rgba[][4],
915 const GLubyte mask[])
916 {
917 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
918 BGLView *bglview = md->m_bglview;
919 assert(bglview);
920 int flippedY = md->m_bottom - y;
921 if (mask) {
922 for (GLuint i = 0; i < n; i++) {
923 if (mask[i]) {
924 bglview->SetHighColor(rgba[i][0], rgba[i][1], rgba[i][2], rgba[i][3]);
925 Plot(bglview, x++, flippedY);
926 }
927 }
928 }
929 else {
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);
933 }
934 }
935 }
936
937 void MesaDriver::WriteRGBSpanFront(const GLcontext *ctx, GLuint n,
938 GLint x, GLint y,
939 CONST GLubyte rgba[][3],
940 const GLubyte mask[])
941 {
942 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
943 BGLView *bglview = md->m_bglview;
944 assert(bglview);
945 int flippedY = md->m_bottom - y;
946 if (mask) {
947 for (GLuint i = 0; i < n; i++) {
948 if (mask[i]) {
949 bglview->SetHighColor(rgba[i][0], rgba[i][1], rgba[i][2]);
950 Plot(bglview, x++, flippedY);
951 }
952 }
953 }
954 else {
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);
958 }
959 }
960 }
961
962 void MesaDriver::WriteMonoRGBASpanFront(const GLcontext *ctx, GLuint n,
963 GLint x, GLint y,
964 const GLchan color[4],
965 const GLubyte mask[])
966 {
967 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
968 BGLView *bglview = md->m_bglview;
969 assert(bglview);
970 int flippedY = md->m_bottom - y;
971 bglview->SetHighColor(color[RCOMP], color[GCOMP], color[BCOMP]);
972 if (mask) {
973 for (GLuint i = 0; i < n; i++) {
974 if (mask[i]) {
975 Plot(bglview, x++, flippedY);
976 }
977 }
978 }
979 else {
980 for (GLuint i = 0; i < n; i++) {
981 Plot(bglview, x++, flippedY);
982 }
983 }
984 }
985
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[] )
990 {
991 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
992 BGLView *bglview = md->m_bglview;
993 assert(bglview);
994 if (mask) {
995 for (GLuint i = 0; i < n; i++) {
996 if (mask[i]) {
997 bglview->SetHighColor(rgba[i][0], rgba[i][1], rgba[i][2]);
998 Plot(bglview, x[i], md->m_bottom - y[i]);
999 }
1000 }
1001 }
1002 else {
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]);
1006 }
1007 }
1008 }
1009
1010
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[])
1015 {
1016 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
1017 BGLView *bglview = md->m_bglview;
1018 assert(bglview);
1019 // plot points using current color
1020 bglview->SetHighColor(color[RCOMP], color[GCOMP], color[BCOMP]);
1021 if (mask) {
1022 for (GLuint i = 0; i < n; i++) {
1023 if (mask[i]) {
1024 Plot(bglview, x[i], md->m_bottom - y[i]);
1025 }
1026 }
1027 }
1028 else {
1029 for (GLuint i = 0; i < n; i++) {
1030 Plot(bglview, x[i], md->m_bottom - y[i]);
1031 }
1032 }
1033 }
1034
1035
1036 void MesaDriver::WriteCI32SpanFront( const GLcontext *ctx, GLuint n, GLint x, GLint y,
1037 const GLuint index[], const GLubyte mask[] )
1038 {
1039 // XXX to do
1040 }
1041
1042 void MesaDriver::WriteCI8SpanFront( const GLcontext *ctx, GLuint n, GLint x, GLint y,
1043 const GLubyte index[], const GLubyte mask[] )
1044 {
1045 // XXX to do
1046 }
1047
1048 void MesaDriver::WriteMonoCISpanFront( const GLcontext *ctx, GLuint n,
1049 GLint x, GLint y,
1050 GLuint colorIndex, const GLubyte mask[] )
1051 {
1052 // XXX to do
1053 }
1054
1055
1056 void MesaDriver::WriteCI32PixelsFront( const GLcontext *ctx, GLuint n,
1057 const GLint x[], const GLint y[],
1058 const GLuint index[], const GLubyte mask[] )
1059 {
1060 // XXX to do
1061 }
1062
1063 void MesaDriver::WriteMonoCIPixelsFront( const GLcontext *ctx, GLuint n,
1064 const GLint x[], const GLint y[],
1065 GLuint colorIndex, const GLubyte mask[] )
1066 {
1067 // XXX to do
1068 }
1069
1070
1071 void MesaDriver::ReadCI32SpanFront( const GLcontext *ctx,
1072 GLuint n, GLint x, GLint y, GLuint index[] )
1073 {
1074 printf("ReadCI32SpanFront() not implemented yet!\n");
1075 // XXX to do
1076 }
1077
1078
1079 void MesaDriver::ReadRGBASpanFront( const GLcontext *ctx, GLuint n,
1080 GLint x, GLint y, GLubyte rgba[][4] )
1081 {
1082 printf("ReadRGBASpanFront() not implemented yet!\n");
1083 // XXX to do
1084 }
1085
1086
1087 void MesaDriver::ReadCI32PixelsFront( const GLcontext *ctx,
1088 GLuint n, const GLint x[], const GLint y[],
1089 GLuint indx[], const GLubyte mask[] )
1090 {
1091 printf("ReadCI32PixelsFront() not implemented yet!\n");
1092 // XXX to do
1093 }
1094
1095
1096 void MesaDriver::ReadRGBAPixelsFront( const GLcontext *ctx,
1097 GLuint n, const GLint x[], const GLint y[],
1098 GLubyte rgba[][4], const GLubyte mask[] )
1099 {
1100 printf("ReadRGBAPixelsFront() not implemented yet!\n");
1101 // XXX to do
1102 }
1103
1104
1105
1106
1107 void MesaDriver::WriteRGBASpanBack(const GLcontext *ctx, GLuint n,
1108 GLint x, GLint y,
1109 CONST GLubyte rgba[][4],
1110 const GLubyte mask[])
1111 {
1112 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
1113 BBitmap *bitmap = md->m_bitmap;
1114
1115 static bool already_called = false;
1116 if (! already_called) {
1117 printf("WriteRGBASpanBack() called.\n");
1118 already_called = true;
1119 }
1120
1121 assert(bitmap);
1122
1123 int row = md->m_bottom - y;
1124 uint8 * ptr = (uint8 *) bitmap->Bits() + (row * bitmap->BytesPerRow()) + x * 4;
1125 uint32 * pixel = (uint32 *) ptr;
1126
1127 if (mask) {
1128 while(n--) {
1129 if (*mask++)
1130 *pixel = PACK_B_RGBA32(rgba[0]);
1131 pixel++;
1132 rgba++;
1133 };
1134 } else {
1135 while(n--) {
1136 *pixel++ = PACK_B_RGBA32(rgba[0]);
1137 rgba++;
1138 };
1139 };
1140 }
1141
1142
1143 void MesaDriver::WriteRGBSpanBack(const GLcontext *ctx, GLuint n,
1144 GLint x, GLint y,
1145 CONST GLubyte rgb[][3],
1146 const GLubyte mask[])
1147 {
1148 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
1149 BBitmap *bitmap = md->m_bitmap;
1150
1151 static bool already_called = false;
1152 if (! already_called) {
1153 printf("WriteRGBSpanBack() called.\n");
1154 already_called = true;
1155 }
1156
1157 assert(bitmap);
1158
1159 int row = md->m_bottom - y;
1160 uint8 * ptr = (uint8 *) bitmap->Bits() + (row * bitmap->BytesPerRow()) + x * 4;
1161 uint32 * pixel = (uint32 *) ptr;
1162
1163 if (mask) {
1164 while(n--) {
1165 if (*mask++)
1166 *pixel = PACK_B_RGB32(rgb[0]);
1167 pixel++;
1168 rgb++;
1169 };
1170 } else {
1171 while(n--) {
1172 *pixel++ = PACK_B_RGB32(rgb[0]);
1173 rgb++;
1174 };
1175 };
1176 }
1177
1178
1179
1180
1181 void MesaDriver::WriteMonoRGBASpanBack(const GLcontext *ctx, GLuint n,
1182 GLint x, GLint y,
1183 const GLchan color[4], const GLubyte mask[])
1184 {
1185 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
1186 BBitmap *bitmap = md->m_bitmap;
1187
1188 static bool already_called = false;
1189 if (! already_called) {
1190 printf("WriteMonoRGBASpanBack() called.\n");
1191 already_called = true;
1192 }
1193
1194 assert(bitmap);
1195
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);
1200
1201 if (mask) {
1202 while(n--) {
1203 if (*mask++)
1204 *pixel = pixel_color;
1205 pixel++;
1206 };
1207 } else {
1208 while(n--) {
1209 *pixel++ = pixel_color;
1210 };
1211 };
1212 }
1213
1214
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[] )
1219 {
1220 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
1221 BBitmap *bitmap = md->m_bitmap;
1222
1223 static bool already_called = false;
1224 if (! already_called) {
1225 printf("WriteRGBAPixelsBack() called.\n");
1226 already_called = true;
1227 }
1228
1229 assert(bitmap);
1230 #if 0
1231 while(n--) {
1232 if (*mask++) {
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]);
1236 };
1237 x++;
1238 y++;
1239 rgba++;
1240 };
1241 #else
1242 if (mask) {
1243 for (GLuint i = 0; i < n; i++) {
1244 if (mask[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];
1251 }
1252 }
1253 }
1254 else {
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];
1262 }
1263 }
1264 #endif
1265 }
1266
1267
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[])
1272 {
1273 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
1274 BBitmap *bitmap = md->m_bitmap;
1275
1276 static bool already_called = false;
1277 if (! already_called) {
1278 printf("WriteMonoRGBAPixelsBack() called.\n");
1279 already_called = true;
1280 }
1281
1282 assert(bitmap);
1283
1284 uint32 pixel_color = PACK_B_RGBA32(color);
1285 #if 0
1286 while(n--) {
1287 if (*mask++) {
1288 int row = md->m_bottom - *y;
1289 uint8 * pixel = (uint8 *) bitmap->Bits() + (row * bitmap->BytesPerRow()) + *x * 4;
1290
1291 *((uint32 *) pixel) = pixel_color;
1292 };
1293 x++;
1294 y++;
1295 };
1296 #else
1297 if (mask) {
1298 for (GLuint i = 0; i < n; i++) {
1299 if (mask[i]) {
1300 GLubyte * ptr = (GLubyte *) bitmap->Bits()
1301 + ((md->m_bottom - y[i]) * bitmap->BytesPerRow()) + x[i] * 4;
1302 *((uint32 *) ptr) = pixel_color;
1303 }
1304 }
1305 }
1306 else {
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;
1311 }
1312 }
1313 #endif
1314 }
1315
1316
1317 void MesaDriver::WriteCI32SpanBack( const GLcontext *ctx, GLuint n,
1318 GLint x, GLint y,
1319 const GLuint index[], const GLubyte mask[] )
1320 {
1321 // XXX to do
1322 }
1323
1324 void MesaDriver::WriteCI8SpanBack( const GLcontext *ctx, GLuint n,
1325 GLint x, GLint y,
1326 const GLubyte index[], const GLubyte mask[] )
1327 {
1328 // XXX to do
1329 }
1330
1331 void MesaDriver::WriteMonoCISpanBack( const GLcontext *ctx, GLuint n,
1332 GLint x, GLint y,
1333 GLuint colorIndex, const GLubyte mask[] )
1334 {
1335 // XXX to do
1336 }
1337
1338
1339 void MesaDriver::WriteCI32PixelsBack( const GLcontext *ctx, GLuint n,
1340 const GLint x[], const GLint y[],
1341 const GLuint index[], const GLubyte mask[] )
1342 {
1343 // XXX to do
1344 }
1345
1346 void MesaDriver::WriteMonoCIPixelsBack( const GLcontext *ctx, GLuint n,
1347 const GLint x[], const GLint y[],
1348 GLuint colorIndex, const GLubyte mask[] )
1349 {
1350 // XXX to do
1351 }
1352
1353
1354 void MesaDriver::ReadCI32SpanBack( const GLcontext *ctx,
1355 GLuint n, GLint x, GLint y, GLuint index[] )
1356 {
1357 // XXX to do
1358 }
1359
1360
1361 void MesaDriver::ReadRGBASpanBack( const GLcontext *ctx, GLuint n,
1362 GLint x, GLint y, GLubyte rgba[][4] )
1363 {
1364 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
1365 const BBitmap *bitmap = md->m_bitmap;
1366 assert(bitmap);
1367 int row = md->m_bottom - y;
1368 const GLubyte *pixel = (GLubyte *) bitmap->Bits()
1369 + (row * bitmap->BytesPerRow()) + x * 4;
1370
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];
1376 pixel += 4;
1377 }
1378 }
1379
1380
1381 void MesaDriver::ReadCI32PixelsBack( const GLcontext *ctx,
1382 GLuint n, const GLint x[], const GLint y[],
1383 GLuint indx[], const GLubyte mask[] )
1384 {
1385 // XXX to do
1386 }
1387
1388
1389 void MesaDriver::ReadRGBAPixelsBack( const GLcontext *ctx,
1390 GLuint n, const GLint x[], const GLint y[],
1391 GLubyte rgba[][4], const GLubyte mask[] )
1392 {
1393 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
1394 const BBitmap *bitmap = md->m_bitmap;
1395 assert(bitmap);
1396
1397 if (mask) {
1398 for (GLuint i = 0; i < n; i++) {
1399 if (mask[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];
1406 };
1407 };
1408 } else {
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];
1416 };
1417 };
1418 }
1419
1420
1421