0c24b0f29f3c6e7d9864ac5c4fb966b7c59ec410
[mesa.git] / src / mesa / drivers / beos / GLView.cpp
1 /* $Id: GLView.cpp,v 1.10 2003/12/13 01:26:14 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 5.0
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 <assert.h>
29 #include <stdio.h>
30
31 extern "C" {
32
33 #include "glheader.h"
34 #include "buffers.h"
35 #include "bufferobj.h"
36 #include "context.h"
37 #include "colormac.h"
38 #include "depth.h"
39 #include "extensions.h"
40 #include "macros.h"
41 #include "matrix.h"
42 #include "mtypes.h"
43 #include "texformat.h"
44 #include "texobj.h"
45 #include "teximage.h"
46 #include "texstore.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"
55 #include "tnl/tnl.h"
56 #include "tnl/t_context.h"
57 #include "tnl/t_pipeline.h"
58
59 } // extern "C"
60
61 #include "GLView.h"
62
63 // BeOS component ordering for B_RGBA32 bitmap format
64 #define BE_RCOMP 2
65 #define BE_GCOMP 1
66 #define BE_BCOMP 0
67 #define BE_ACOMP 3
68
69 #define PACK_B_RGBA32(color) (color[BCOMP] | (color[GCOMP] << 8) | \
70 (color[RCOMP] << 16) | (color[ACOMP] << 24))
71
72 #define PACK_B_RGB32(color) (color[BCOMP] | (color[GCOMP] << 8) | \
73 (color[RCOMP] << 16) | 0xFF000000)
74
75 #define FLIP(coord) (LIBGGI_MODE(ggi_ctx->ggi_visual)->visible.y-(coord) - 1)
76
77 //
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.
82 //
83 class MesaDriver
84 {
85 public:
86 MesaDriver();
87 ~MesaDriver();
88 void Init(BGLView * bglview, GLcontext * c, GLvisual * v, GLframebuffer * b);
89
90 void LockGL();
91 void UnlockGL();
92 void SwapBuffers() const;
93 void CopySubBuffer(GLint x, GLint y, GLuint width, GLuint height) const;
94 void Draw(BRect updateRect) const;
95
96 private:
97 MesaDriver(const MesaDriver &rhs); // copy constructor illegal
98 MesaDriver &operator=(const MesaDriver &rhs); // assignment oper. illegal
99
100 GLcontext * m_glcontext;
101 GLvisual * m_glvisual;
102 GLframebuffer * m_glframebuffer;
103
104 BGLView * m_bglview;
105 BBitmap * m_bitmap;
106
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
110 GLuint m_width;
111 GLuint m_height;
112
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,
128 GLenum mode);
129 static void GetBufferSize(GLframebuffer * framebuffer, GLuint *width,
130 GLuint *height);
131 static const GLubyte * GetString(GLcontext *ctx, GLenum name);
132
133 // Front-buffer functions
134 static void WriteRGBASpanFront(const GLcontext *ctx, GLuint n,
135 GLint x, GLint y,
136 CONST GLubyte rgba[][4],
137 const GLubyte mask[]);
138 static void WriteRGBSpanFront(const GLcontext *ctx, GLuint n,
139 GLint x, GLint y,
140 CONST GLubyte rgba[][3],
141 const GLubyte mask[]);
142 static void WriteMonoRGBASpanFront(const GLcontext *ctx, GLuint n,
143 GLint x, GLint y,
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,
155 GLint x, GLint y,
156 const GLuint index[], const GLubyte mask[]);
157 static void WriteCI8SpanFront(const GLcontext *ctx, GLuint n,
158 GLint x, GLint y,
159 const GLubyte index[], const GLubyte mask[]);
160 static void WriteMonoCISpanFront(const GLcontext *ctx, GLuint n,
161 GLint x, GLint y,
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,
172 GLint x, GLint y,
173 GLubyte rgba[][4]);
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[]);
180
181 // Back buffer functions
182 static void WriteRGBASpanBack(const GLcontext *ctx, GLuint n,
183 GLint x, GLint y,
184 CONST GLubyte rgba[][4],
185 const GLubyte mask[]);
186 static void WriteRGBSpanBack(const GLcontext *ctx, GLuint n,
187 GLint x, GLint y,
188 CONST GLubyte rgba[][3],
189 const GLubyte mask[]);
190 static void WriteMonoRGBASpanBack(const GLcontext *ctx, GLuint n,
191 GLint x, GLint y,
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,
203 GLint x, GLint y,
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,
219 GLint x, GLint y,
220 GLubyte rgba[][4]);
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[]);
227
228 };
229
230 //------------------------------------------------------------------
231 // Public interface methods
232 //------------------------------------------------------------------
233
234
235 //
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
241 //
242 BGLView::BGLView(BRect rect, char *name,
243 ulong resizingMode, ulong mode,
244 ulong options)
245 :BView(rect, name, resizingMode, mode | B_WILL_DRAW | B_FRAME_EVENTS) // | B_FULL_UPDATE_ON_RESIZE)
246 {
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;
259
260 if (!rgbFlag) {
261 fprintf(stderr, "Mesa Warning: color index mode not supported\n");
262 }
263
264 // Allocate auxiliary data object
265 MesaDriver * md = new MesaDriver;
266
267 // examine option flags and create gl_context struct
268 GLvisual * visual = _mesa_create_visual( rgbFlag,
269 dblFlag,
270 stereoFlag,
271 red, green, blue, alpha,
272 index,
273 depth,
274 stencil,
275 accum, accum, accum, accum,
276 1
277 );
278
279 // create core context
280 GLcontext * ctx = _mesa_create_context(visual, NULL, md, GL_FALSE);
281
282 ctx->Driver.NewTextureObject = _mesa_new_texture_object;
283 ctx->Driver.DeleteTexture = _mesa_delete_texture_object;
284
285 _mesa_initialize_context(ctx, visual, NULL, md, GL_FALSE);
286
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);
291
292
293
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,
299 alphaFlag
300 );
301
302 /* Initialize the software rasterizer and helper modules.
303 */
304 _swrast_CreateContext(ctx);
305 _ac_CreateContext(ctx);
306 _tnl_CreateContext(ctx);
307 _swsetup_CreateContext(ctx);
308 _swsetup_Wakeup(ctx);
309
310 md->Init(this, ctx, visual, buffer );
311
312 // Hook aux data into BGLView object
313 m_gc = md;
314 }
315
316
317 BGLView::~BGLView()
318 {
319 printf("BGLView destructor\n");
320 MesaDriver * md = (MesaDriver *) m_gc;
321 assert(md);
322 delete md;
323 }
324
325 void BGLView::LockGL()
326 {
327 MesaDriver * md = (MesaDriver *) m_gc;
328 assert(md);
329 md->LockGL();
330 }
331
332 void BGLView::UnlockGL()
333 {
334 MesaDriver * md = (MesaDriver *) m_gc;
335 assert(md);
336 md->UnlockGL();
337 }
338
339 void BGLView::SwapBuffers()
340 {
341 MesaDriver * md = (MesaDriver *) m_gc;
342 assert(md);
343 md->SwapBuffers();
344 }
345
346
347 void BGLView::CopySubBufferMESA(GLint x, GLint y, GLuint width, GLuint height)
348 {
349 MesaDriver * md = (MesaDriver *) m_gc;
350 assert(md);
351 md->CopySubBuffer(x, y, width, height);
352 }
353
354
355 BView * BGLView::EmbeddedView()
356 {
357 // XXX to do
358 return NULL;
359 }
360
361 status_t BGLView::CopyPixelsOut(BPoint source, BBitmap *dest)
362 {
363 // XXX to do
364 printf("BGLView::CopyPixelsOut() not implemented yet!\n");
365 return B_UNSUPPORTED;
366 }
367
368
369 status_t BGLView::CopyPixelsIn(BBitmap *source, BPoint dest)
370 {
371 // XXX to do
372 printf("BGLView::CopyPixelsIn() not implemented yet!\n");
373 return B_UNSUPPORTED;
374 }
375
376 void BGLView::ErrorCallback(unsigned long errorCode) // GLenum errorCode)
377 {
378 // XXX to do
379 printf("BGLView::ErrorCallback() not implemented yet!\n");
380 return;
381 }
382
383 void BGLView::Draw(BRect updateRect)
384 {
385 // printf("BGLView::Draw()\n");
386 MesaDriver * md = (MesaDriver *) m_gc;
387 assert(md);
388 md->Draw(updateRect);
389 }
390
391 void BGLView::AttachedToWindow()
392 {
393 BView::AttachedToWindow();
394
395 // don't paint window background white when resized
396 SetViewColor(B_TRANSPARENT_32_BIT);
397 }
398
399 void BGLView::AllAttached()
400 {
401 BView::AllAttached();
402 // printf("BGLView AllAttached\n");
403 }
404
405 void BGLView::DetachedFromWindow()
406 {
407 BView::DetachedFromWindow();
408 }
409
410 void BGLView::AllDetached()
411 {
412 BView::AllDetached();
413 // printf("BGLView AllDetached");
414 }
415
416 void BGLView::FrameResized(float width, float height)
417 {
418 return BView::FrameResized(width, height);
419 }
420
421 status_t BGLView::Perform(perform_code d, void *arg)
422 {
423 return BView::Perform(d, arg);
424 }
425
426
427 status_t BGLView::Archive(BMessage *data, bool deep) const
428 {
429 return BView::Archive(data, deep);
430 }
431
432 void BGLView::MessageReceived(BMessage *msg)
433 {
434 BView::MessageReceived(msg);
435 }
436
437 void BGLView::SetResizingMode(uint32 mode)
438 {
439 BView::SetResizingMode(mode);
440 }
441
442 void BGLView::Show()
443 {
444 // printf("BGLView Show\n");
445 BView::Show();
446 }
447
448 void BGLView::Hide()
449 {
450 // printf("BGLView Hide\n");
451 BView::Hide();
452 }
453
454 BHandler *BGLView::ResolveSpecifier(BMessage *msg, int32 index,
455 BMessage *specifier, int32 form,
456 const char *property)
457 {
458 return BView::ResolveSpecifier(msg, index, specifier, form, property);
459 }
460
461 status_t BGLView::GetSupportedSuites(BMessage *data)
462 {
463 return BView::GetSupportedSuites(data);
464 }
465
466 void BGLView::DirectConnected( direct_buffer_info *info )
467 {
468 // XXX to do
469 }
470
471 void BGLView::EnableDirectMode( bool enabled )
472 {
473 // XXX to do
474 }
475
476
477
478 //---- private methods ----------
479
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() {}
488
489 #if 0
490 BGLView::BGLView(const BGLView &v)
491 : BView(v)
492 {
493 // XXX not sure how this should work
494 printf("Warning BGLView::copy constructor not implemented\n");
495 }
496 #endif
497
498
499 BGLView &BGLView::operator=(const BGLView &v)
500 {
501 printf("Warning BGLView::operator= not implemented\n");
502 return *this;
503 }
504
505 void BGLView::dither_front()
506 {
507 // no-op
508 }
509
510 bool BGLView::confirm_dither()
511 {
512 // no-op
513 return false;
514 }
515
516 void BGLView::draw(BRect r)
517 {
518 // XXX no-op ???
519 }
520
521 /* Direct Window stuff */
522 void BGLView::drawScanline( int x1, int x2, int y, void *data )
523 {
524 // no-op
525 }
526
527 void BGLView::scanlineHandler(struct rasStateRec *state,
528 GLint x1, GLint x2)
529 {
530 // no-op
531 }
532
533 void BGLView::lock_draw()
534 {
535 // no-op
536 }
537
538 void BGLView::unlock_draw()
539 {
540 // no-op
541 }
542
543 bool BGLView::validateView()
544 {
545 // no-op
546 return true;
547 }
548
549 // #pragma mark -
550
551 MesaDriver::MesaDriver()
552 {
553 m_glcontext = NULL;
554 m_glvisual = NULL;
555 m_glframebuffer = NULL;
556 m_bglview = NULL;
557 m_bitmap = NULL;
558
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;
563
564 m_clear_index = 0;
565 }
566
567
568 MesaDriver::~MesaDriver()
569 {
570 _mesa_destroy_visual(m_glvisual);
571 _mesa_destroy_framebuffer(m_glframebuffer);
572 _mesa_destroy_context(m_glcontext);
573
574 }
575
576
577 void MesaDriver::Init(BGLView * bglview, GLcontext * ctx, GLvisual * visual, GLframebuffer * framebuffer)
578 {
579 m_bglview = bglview;
580 m_glcontext = ctx;
581 m_glvisual = visual;
582 m_glframebuffer = framebuffer;
583
584 MesaDriver * md = (MesaDriver *) ctx->DriverCtx;
585 struct swrast_device_driver * swdd = _swrast_GetDeviceDriverReference( ctx );
586 TNLcontext * tnl = TNL_CONTEXT(ctx);
587
588 assert(md->m_glcontext == ctx );
589
590 // Use default TCL pipeline
591 tnl->Driver.RunPipeline = _tnl_run_pipeline;
592
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;
597
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;
607
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;
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 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;
633
634 swdd->SetBuffer = MesaDriver::SetBuffer;
635 }
636
637
638 void MesaDriver::LockGL()
639 {
640 m_bglview->LockLooper();
641
642 UpdateState(m_glcontext, 0);
643 _mesa_make_current(m_glcontext, m_glframebuffer);
644 }
645
646
647 void MesaDriver::UnlockGL()
648 {
649 m_bglview->UnlockLooper();
650 // Could call _mesa_make_current(NULL, NULL) but it would just
651 // hinder performance
652 }
653
654
655 void MesaDriver::SwapBuffers() const
656 {
657 // _mesa_notifySwapBuffers(m_glcontext);
658
659 if (m_bitmap) {
660 m_bglview->LockLooper();
661 m_bglview->DrawBitmap(m_bitmap, BPoint(0, 0));
662 m_bglview->UnlockLooper();
663 };
664 }
665
666
667 void MesaDriver::CopySubBuffer(GLint x, GLint y, GLuint width, GLuint height) const
668 {
669 if (m_bitmap) {
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
673 BRect srcAndDest;
674 srcAndDest.left = x;
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);
679 }
680 }
681
682
683 void MesaDriver::Draw(BRect updateRect) const
684 {
685 if (m_bitmap)
686 m_bglview->DrawBitmap(m_bitmap, updateRect, updateRect);
687 }
688
689
690 void MesaDriver::UpdateState( GLcontext *ctx, GLuint new_state )
691 {
692 struct swrast_device_driver * swdd = _swrast_GetDeviceDriverReference( ctx );
693
694 _swrast_InvalidateState( ctx, new_state );
695 _swsetup_InvalidateState( ctx, new_state );
696 _ac_InvalidateState( ctx, new_state );
697 _tnl_InvalidateState( ctx, new_state );
698
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;
715 }
716 else {
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;
732 }
733 }
734
735
736 void MesaDriver::ClearIndex(GLcontext *ctx, GLuint index)
737 {
738 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
739 md->m_clear_index = index;
740 }
741
742
743 void MesaDriver::ClearColor(GLcontext *ctx, const GLfloat color[4])
744 {
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);
751 }
752
753
754 void MesaDriver::Clear(GLcontext *ctx, GLbitfield mask,
755 GLboolean all, GLint x, GLint y,
756 GLint width, GLint height)
757 {
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);
762
763 mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT);
764 if (mask)
765 _swrast_Clear( ctx, mask, all, x, y, width, height );
766
767 return;
768 }
769
770
771 void MesaDriver::ClearFront(GLcontext *ctx,
772 GLboolean all, GLint x, GLint y,
773 GLint width, GLint height)
774 {
775 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
776 BGLView *bglview = md->m_bglview;
777 assert(bglview);
778
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]);
787 if (all) {
788 BRect b = bglview->Bounds();
789 bglview->FillRect(b);
790 }
791 else {
792 // XXX untested
793 BRect b;
794 b.left = x;
795 b.right = x + width;
796 b.bottom = md->m_height - y - 1;
797 b.top = b.bottom - height;
798 bglview->FillRect(b);
799 }
800
801 // restore drawing color
802 #if 0
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]);
811 #endif
812 }
813
814
815 void MesaDriver::ClearBack(GLcontext *ctx,
816 GLboolean all, GLint x, GLint y,
817 GLint width, GLint height)
818 {
819 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
820 BGLView *bglview = md->m_bglview;
821 assert(bglview);
822 BBitmap *bitmap = md->m_bitmap;
823 assert(bitmap);
824 GLuint *start = (GLuint *) bitmap->Bits();
825 const GLuint *clearPixelPtr = (const GLuint *) md->m_clear_color;
826 const GLuint clearPixel = *clearPixelPtr;
827
828 if (all) {
829 const int numPixels = md->m_width * md->m_height;
830 if (clearPixel == 0) {
831 memset(start, 0, numPixels * 4);
832 }
833 else {
834 for (int i = 0; i < numPixels; i++) {
835 start[i] = clearPixel;
836 }
837 }
838 }
839 else {
840 // XXX untested
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;
845 }
846 start += md->m_width;
847 }
848 }
849 }
850
851
852 void MesaDriver::SetBuffer(GLcontext *ctx, GLframebuffer *buffer,
853 GLenum mode)
854 {
855 /* TODO */
856 (void) ctx;
857 (void) buffer;
858 (void) mode;
859 }
860
861 void MesaDriver::GetBufferSize(GLframebuffer * framebuffer, GLuint *width,
862 GLuint *height)
863 {
864 GET_CURRENT_CONTEXT(ctx);
865 if (!ctx)
866 return;
867
868 MesaDriver * md = (MesaDriver *) ctx->DriverCtx;
869 BGLView *bglview = md->m_bglview;
870 assert(bglview);
871
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;
876
877 if (ctx->Visual.doubleBufferMode) {
878 if (*width != md->m_width || *height != md->m_height) {
879 // allocate new size of back buffer bitmap
880 if (md->m_bitmap)
881 delete md->m_bitmap;
882 BRect rect(0.0, 0.0, *width - 1, *height - 1);
883 md->m_bitmap = new BBitmap(rect, B_RGBA32);
884 }
885 }
886 else
887 {
888 md->m_bitmap = NULL;
889 }
890
891 md->m_width = *width;
892 md->m_height = *height;
893 }
894
895
896 const GLubyte *MesaDriver::GetString(GLcontext *ctx, GLenum name)
897 {
898 switch (name) {
899 case GL_RENDERER:
900 return (const GLubyte *) "Mesa BGLView (software)";
901 default:
902 // Let core library handle all other cases
903 return NULL;
904 }
905 }
906
907
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)
911 {
912 // XXX There's got to be a better way!
913 BPoint p(x, y), q(x+1, y);
914 bglview->StrokeLine(p, q);
915 }
916
917
918 void MesaDriver::WriteRGBASpanFront(const GLcontext *ctx, GLuint n,
919 GLint x, GLint y,
920 CONST GLubyte rgba[][4],
921 const GLubyte mask[])
922 {
923 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
924 BGLView *bglview = md->m_bglview;
925 assert(bglview);
926 int flippedY = md->m_bottom - y;
927 if (mask) {
928 for (GLuint i = 0; i < n; i++) {
929 if (mask[i]) {
930 bglview->SetHighColor(rgba[i][0], rgba[i][1], rgba[i][2], rgba[i][3]);
931 Plot(bglview, x++, flippedY);
932 }
933 }
934 }
935 else {
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);
939 }
940 }
941 }
942
943 void MesaDriver::WriteRGBSpanFront(const GLcontext *ctx, GLuint n,
944 GLint x, GLint y,
945 CONST GLubyte rgba[][3],
946 const GLubyte mask[])
947 {
948 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
949 BGLView *bglview = md->m_bglview;
950 assert(bglview);
951 int flippedY = md->m_bottom - y;
952 if (mask) {
953 for (GLuint i = 0; i < n; i++) {
954 if (mask[i]) {
955 bglview->SetHighColor(rgba[i][0], rgba[i][1], rgba[i][2]);
956 Plot(bglview, x++, flippedY);
957 }
958 }
959 }
960 else {
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);
964 }
965 }
966 }
967
968 void MesaDriver::WriteMonoRGBASpanFront(const GLcontext *ctx, GLuint n,
969 GLint x, GLint y,
970 const GLchan color[4],
971 const GLubyte mask[])
972 {
973 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
974 BGLView *bglview = md->m_bglview;
975 assert(bglview);
976 int flippedY = md->m_bottom - y;
977 bglview->SetHighColor(color[RCOMP], color[GCOMP], color[BCOMP]);
978 if (mask) {
979 for (GLuint i = 0; i < n; i++) {
980 if (mask[i]) {
981 Plot(bglview, x++, flippedY);
982 }
983 }
984 }
985 else {
986 for (GLuint i = 0; i < n; i++) {
987 Plot(bglview, x++, flippedY);
988 }
989 }
990 }
991
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[] )
996 {
997 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
998 BGLView *bglview = md->m_bglview;
999 assert(bglview);
1000 if (mask) {
1001 for (GLuint i = 0; i < n; i++) {
1002 if (mask[i]) {
1003 bglview->SetHighColor(rgba[i][0], rgba[i][1], rgba[i][2]);
1004 Plot(bglview, x[i], md->m_bottom - y[i]);
1005 }
1006 }
1007 }
1008 else {
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]);
1012 }
1013 }
1014 }
1015
1016
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[])
1021 {
1022 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
1023 BGLView *bglview = md->m_bglview;
1024 assert(bglview);
1025 // plot points using current color
1026 bglview->SetHighColor(color[RCOMP], color[GCOMP], color[BCOMP]);
1027 if (mask) {
1028 for (GLuint i = 0; i < n; i++) {
1029 if (mask[i]) {
1030 Plot(bglview, x[i], md->m_bottom - y[i]);
1031 }
1032 }
1033 }
1034 else {
1035 for (GLuint i = 0; i < n; i++) {
1036 Plot(bglview, x[i], md->m_bottom - y[i]);
1037 }
1038 }
1039 }
1040
1041
1042 void MesaDriver::WriteCI32SpanFront( const GLcontext *ctx, GLuint n, GLint x, GLint y,
1043 const GLuint index[], const GLubyte mask[] )
1044 {
1045 // XXX to do
1046 }
1047
1048 void MesaDriver::WriteCI8SpanFront( const GLcontext *ctx, GLuint n, GLint x, GLint y,
1049 const GLubyte index[], const GLubyte mask[] )
1050 {
1051 // XXX to do
1052 }
1053
1054 void MesaDriver::WriteMonoCISpanFront( const GLcontext *ctx, GLuint n,
1055 GLint x, GLint y,
1056 GLuint colorIndex, const GLubyte mask[] )
1057 {
1058 // XXX to do
1059 }
1060
1061
1062 void MesaDriver::WriteCI32PixelsFront( const GLcontext *ctx, GLuint n,
1063 const GLint x[], const GLint y[],
1064 const GLuint index[], const GLubyte mask[] )
1065 {
1066 // XXX to do
1067 }
1068
1069 void MesaDriver::WriteMonoCIPixelsFront( const GLcontext *ctx, GLuint n,
1070 const GLint x[], const GLint y[],
1071 GLuint colorIndex, const GLubyte mask[] )
1072 {
1073 // XXX to do
1074 }
1075
1076
1077 void MesaDriver::ReadCI32SpanFront( const GLcontext *ctx,
1078 GLuint n, GLint x, GLint y, GLuint index[] )
1079 {
1080 printf("ReadCI32SpanFront() not implemented yet!\n");
1081 // XXX to do
1082 }
1083
1084
1085 void MesaDriver::ReadRGBASpanFront( const GLcontext *ctx, GLuint n,
1086 GLint x, GLint y, GLubyte rgba[][4] )
1087 {
1088 printf("ReadRGBASpanFront() not implemented yet!\n");
1089 // XXX to do
1090 }
1091
1092
1093 void MesaDriver::ReadCI32PixelsFront( const GLcontext *ctx,
1094 GLuint n, const GLint x[], const GLint y[],
1095 GLuint indx[], const GLubyte mask[] )
1096 {
1097 printf("ReadCI32PixelsFront() not implemented yet!\n");
1098 // XXX to do
1099 }
1100
1101
1102 void MesaDriver::ReadRGBAPixelsFront( const GLcontext *ctx,
1103 GLuint n, const GLint x[], const GLint y[],
1104 GLubyte rgba[][4], const GLubyte mask[] )
1105 {
1106 printf("ReadRGBAPixelsFront() not implemented yet!\n");
1107 // XXX to do
1108 }
1109
1110
1111
1112
1113 void MesaDriver::WriteRGBASpanBack(const GLcontext *ctx, GLuint n,
1114 GLint x, GLint y,
1115 CONST GLubyte rgba[][4],
1116 const GLubyte mask[])
1117 {
1118 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
1119 BBitmap *bitmap = md->m_bitmap;
1120
1121 static bool already_called = false;
1122 if (! already_called) {
1123 printf("WriteRGBASpanBack() called.\n");
1124 already_called = true;
1125 }
1126
1127 assert(bitmap);
1128
1129 int row = md->m_bottom - y;
1130 uint8 * ptr = (uint8 *) bitmap->Bits() + (row * bitmap->BytesPerRow()) + x * 4;
1131 uint32 * pixel = (uint32 *) ptr;
1132
1133 if (mask) {
1134 while(n--) {
1135 if (*mask++)
1136 *pixel = PACK_B_RGBA32(rgba[0]);
1137 pixel++;
1138 rgba++;
1139 };
1140 } else {
1141 while(n--) {
1142 *pixel++ = PACK_B_RGBA32(rgba[0]);
1143 rgba++;
1144 };
1145 };
1146 }
1147
1148
1149 void MesaDriver::WriteRGBSpanBack(const GLcontext *ctx, GLuint n,
1150 GLint x, GLint y,
1151 CONST GLubyte rgb[][3],
1152 const GLubyte mask[])
1153 {
1154 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
1155 BBitmap *bitmap = md->m_bitmap;
1156
1157 static bool already_called = false;
1158 if (! already_called) {
1159 printf("WriteRGBSpanBack() called.\n");
1160 already_called = true;
1161 }
1162
1163 assert(bitmap);
1164
1165 int row = md->m_bottom - y;
1166 uint8 * ptr = (uint8 *) bitmap->Bits() + (row * bitmap->BytesPerRow()) + x * 4;
1167 uint32 * pixel = (uint32 *) ptr;
1168
1169 if (mask) {
1170 while(n--) {
1171 if (*mask++)
1172 *pixel = PACK_B_RGB32(rgb[0]);
1173 pixel++;
1174 rgb++;
1175 };
1176 } else {
1177 while(n--) {
1178 *pixel++ = PACK_B_RGB32(rgb[0]);
1179 rgb++;
1180 };
1181 };
1182 }
1183
1184
1185
1186
1187 void MesaDriver::WriteMonoRGBASpanBack(const GLcontext *ctx, GLuint n,
1188 GLint x, GLint y,
1189 const GLchan color[4], const GLubyte mask[])
1190 {
1191 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
1192 BBitmap *bitmap = md->m_bitmap;
1193
1194 static bool already_called = false;
1195 if (! already_called) {
1196 printf("WriteMonoRGBASpanBack() called.\n");
1197 already_called = true;
1198 }
1199
1200 assert(bitmap);
1201
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);
1206
1207 if (mask) {
1208 while(n--) {
1209 if (*mask++)
1210 *pixel = pixel_color;
1211 pixel++;
1212 };
1213 } else {
1214 while(n--) {
1215 *pixel++ = pixel_color;
1216 };
1217 };
1218 }
1219
1220
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[] )
1225 {
1226 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
1227 BBitmap *bitmap = md->m_bitmap;
1228
1229 static bool already_called = false;
1230 if (! already_called) {
1231 printf("WriteRGBAPixelsBack() called.\n");
1232 already_called = true;
1233 }
1234
1235 assert(bitmap);
1236 #if 0
1237 while(n--) {
1238 if (*mask++) {
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]);
1242 };
1243 x++;
1244 y++;
1245 rgba++;
1246 };
1247 #else
1248 if (mask) {
1249 for (GLuint i = 0; i < n; i++) {
1250 if (mask[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];
1257 }
1258 }
1259 }
1260 else {
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];
1268 }
1269 }
1270 #endif
1271 }
1272
1273
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[])
1278 {
1279 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
1280 BBitmap *bitmap = md->m_bitmap;
1281
1282 static bool already_called = false;
1283 if (! already_called) {
1284 printf("WriteMonoRGBAPixelsBack() called.\n");
1285 already_called = true;
1286 }
1287
1288 assert(bitmap);
1289
1290 uint32 pixel_color = PACK_B_RGBA32(color);
1291 #if 0
1292 while(n--) {
1293 if (*mask++) {
1294 int row = md->m_bottom - *y;
1295 uint8 * pixel = (uint8 *) bitmap->Bits() + (row * bitmap->BytesPerRow()) + *x * 4;
1296
1297 *((uint32 *) pixel) = pixel_color;
1298 };
1299 x++;
1300 y++;
1301 };
1302 #else
1303 if (mask) {
1304 for (GLuint i = 0; i < n; i++) {
1305 if (mask[i]) {
1306 GLubyte * ptr = (GLubyte *) bitmap->Bits()
1307 + ((md->m_bottom - y[i]) * bitmap->BytesPerRow()) + x[i] * 4;
1308 *((uint32 *) ptr) = pixel_color;
1309 }
1310 }
1311 }
1312 else {
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;
1317 }
1318 }
1319 #endif
1320 }
1321
1322
1323 void MesaDriver::WriteCI32SpanBack( const GLcontext *ctx, GLuint n,
1324 GLint x, GLint y,
1325 const GLuint index[], const GLubyte mask[] )
1326 {
1327 // XXX to do
1328 }
1329
1330 void MesaDriver::WriteCI8SpanBack( const GLcontext *ctx, GLuint n,
1331 GLint x, GLint y,
1332 const GLubyte index[], const GLubyte mask[] )
1333 {
1334 // XXX to do
1335 }
1336
1337 void MesaDriver::WriteMonoCISpanBack( const GLcontext *ctx, GLuint n,
1338 GLint x, GLint y,
1339 GLuint colorIndex, const GLubyte mask[] )
1340 {
1341 // XXX to do
1342 }
1343
1344
1345 void MesaDriver::WriteCI32PixelsBack( const GLcontext *ctx, GLuint n,
1346 const GLint x[], const GLint y[],
1347 const GLuint index[], const GLubyte mask[] )
1348 {
1349 // XXX to do
1350 }
1351
1352 void MesaDriver::WriteMonoCIPixelsBack( const GLcontext *ctx, GLuint n,
1353 const GLint x[], const GLint y[],
1354 GLuint colorIndex, const GLubyte mask[] )
1355 {
1356 // XXX to do
1357 }
1358
1359
1360 void MesaDriver::ReadCI32SpanBack( const GLcontext *ctx,
1361 GLuint n, GLint x, GLint y, GLuint index[] )
1362 {
1363 // XXX to do
1364 }
1365
1366
1367 void MesaDriver::ReadRGBASpanBack( const GLcontext *ctx, GLuint n,
1368 GLint x, GLint y, GLubyte rgba[][4] )
1369 {
1370 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
1371 const BBitmap *bitmap = md->m_bitmap;
1372 assert(bitmap);
1373 int row = md->m_bottom - y;
1374 const GLubyte *pixel = (GLubyte *) bitmap->Bits()
1375 + (row * bitmap->BytesPerRow()) + x * 4;
1376
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];
1382 pixel += 4;
1383 }
1384 }
1385
1386
1387 void MesaDriver::ReadCI32PixelsBack( const GLcontext *ctx,
1388 GLuint n, const GLint x[], const GLint y[],
1389 GLuint indx[], const GLubyte mask[] )
1390 {
1391 // XXX to do
1392 }
1393
1394
1395 void MesaDriver::ReadRGBAPixelsBack( const GLcontext *ctx,
1396 GLuint n, const GLint x[], const GLint y[],
1397 GLubyte rgba[][4], const GLubyte mask[] )
1398 {
1399 MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
1400 const BBitmap *bitmap = md->m_bitmap;
1401 assert(bitmap);
1402
1403 if (mask) {
1404 for (GLuint i = 0; i < n; i++) {
1405 if (mask[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];
1412 };
1413 };
1414 } else {
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];
1422 };
1423 };
1424 }
1425
1426
1427