| 1 |
/* |
| 2 |
* Mesa 3-D graphics library |
| 3 |
* Version: 6.4.2 |
| 4 |
* |
| 5 |
* Copyright (C) 1999-2005 Brian Paul All Rights Reserved. |
| 6 |
* |
| 7 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 8 |
* copy of this software and associated documentation files (the "Software"), |
| 9 |
* to deal in the Software without restriction, including without limitation |
| 10 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 12 |
* Software is furnished to do so, subject to the following conditions: |
| 13 |
* |
| 14 |
* The above copyright notice and this permission notice shall be included |
| 15 |
* in all copies or substantial portions of the Software. |
| 16 |
* |
| 17 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 |
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 21 |
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 |
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 |
*/ |
| 24 |
|
| 25 |
|
| 26 |
#include "glxheader.h" |
| 27 |
#include "GL/xmesa.h" |
| 28 |
#include "xmesaP.h" |
| 29 |
#include "imports.h" |
| 30 |
#include "renderbuffer.h" |
| 31 |
|
| 32 |
|
| 33 |
static void |
| 34 |
xmesa_delete_renderbuffer(struct gl_renderbuffer *rb) |
| 35 |
{ |
| 36 |
/* XXX Note: the ximage or Pixmap attached to this renderbuffer |
| 37 |
* should probably get freed here, but that's currently done in |
| 38 |
* XMesaDestroyBuffer(). |
| 39 |
*/ |
| 40 |
_mesa_free(rb); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
/** |
| 45 |
* Reallocate renderbuffer storage. |
| 46 |
* This is called when the window's resized. It'll get called once for |
| 47 |
* the front color renderbuffer and again for the back color renderbuffer. |
| 48 |
*/ |
| 49 |
static GLboolean |
| 50 |
xmesa_alloc_storage(GLcontext *ctx, struct gl_renderbuffer *rb, |
| 51 |
GLenum internalFormat, GLuint width, GLuint height) |
| 52 |
{ |
| 53 |
struct xmesa_renderbuffer *xrb = (struct xmesa_renderbuffer *) rb; |
| 54 |
|
| 55 |
if (xrb->ximage) { |
| 56 |
/* Needed by PIXELADDR1 macro */ |
| 57 |
xrb->width1 = xrb->ximage->bytes_per_line; |
| 58 |
xrb->origin1 = (GLubyte *) xrb->ximage->data + xrb->width1 * (height - 1); |
| 59 |
|
| 60 |
/* Needed by PIXELADDR2 macro */ |
| 61 |
xrb->width2 = xrb->ximage->bytes_per_line / 2; |
| 62 |
xrb->origin2 = (GLushort *) xrb->ximage->data + xrb->width2 * (height - 1); |
| 63 |
|
| 64 |
/* Needed by PIXELADDR3 macro */ |
| 65 |
xrb->width3 = xrb->ximage->bytes_per_line; |
| 66 |
xrb->origin3 = (GLubyte *) xrb->ximage->data + xrb->width3 * (height - 1); |
| 67 |
|
| 68 |
/* Needed by PIXELADDR4 macro */ |
| 69 |
xrb->width4 = xrb->ximage->width; |
| 70 |
xrb->origin4 = (GLuint *) xrb->ximage->data + xrb->width4 * (height - 1); |
| 71 |
} |
| 72 |
else { |
| 73 |
/* this assertion will fail if we happend to run out of memory */ |
| 74 |
/*assert(xrb->pixmap);*/ |
| 75 |
} |
| 76 |
|
| 77 |
/* for the FLIP macro: */ |
| 78 |
xrb->bottom = height - 1; |
| 79 |
|
| 80 |
rb->Width = width; |
| 81 |
rb->Height = height; |
| 82 |
rb->InternalFormat = internalFormat; |
| 83 |
|
| 84 |
return GL_TRUE; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
struct xmesa_renderbuffer * |
| 89 |
xmesa_new_renderbuffer(GLcontext *ctx, GLuint name, GLboolean rgbMode) |
| 90 |
{ |
| 91 |
struct xmesa_renderbuffer *xrb = CALLOC_STRUCT(xmesa_renderbuffer); |
| 92 |
if (xrb) { |
| 93 |
GLuint name = 0; |
| 94 |
_mesa_init_renderbuffer(&xrb->Base, name); |
| 95 |
|
| 96 |
xrb->Base.Delete = xmesa_delete_renderbuffer; |
| 97 |
xrb->Base.AllocStorage = xmesa_alloc_storage; |
| 98 |
|
| 99 |
if (rgbMode) { |
| 100 |
xrb->Base.InternalFormat = GL_RGBA; |
| 101 |
xrb->Base._BaseFormat = GL_RGBA; |
| 102 |
xrb->Base.DataType = GL_UNSIGNED_BYTE; |
| 103 |
} |
| 104 |
else { |
| 105 |
xrb->Base.InternalFormat = GL_COLOR_INDEX; |
| 106 |
xrb->Base._BaseFormat = GL_COLOR_INDEX; |
| 107 |
xrb->Base.DataType = GL_UNSIGNED_INT; |
| 108 |
} |
| 109 |
xrb->Base.ComponentSizes[0] = 0; /* XXX fix? */ |
| 110 |
} |
| 111 |
return xrb; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|