summaryrefslogtreecommitdiffstats
path: root/src/mesa/pipe/xlib/xm_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/pipe/xlib/xm_api.c')
-rw-r--r--src/mesa/pipe/xlib/xm_api.c120
1 files changed, 73 insertions, 47 deletions
diff --git a/src/mesa/pipe/xlib/xm_api.c b/src/mesa/pipe/xlib/xm_api.c
index 4021af187c7..142074bc650 100644
--- a/src/mesa/pipe/xlib/xm_api.c
+++ b/src/mesa/pipe/xlib/xm_api.c
@@ -251,6 +251,52 @@ xmesa_get_window_size(XMesaDisplay *dpy, XMesaBuffer b,
}
+/**
+ * Choose the pixel format for the given visual.
+ * This will tell the gallium driver how to pack pixel data into
+ * drawing surfaces.
+ */
+static GLuint
+choose_pixel_format(XMesaVisual v)
+{
+ if ( GET_REDMASK(v) == 0x0000ff
+ && GET_GREENMASK(v) == 0x00ff00
+ && GET_BLUEMASK(v) == 0xff0000
+ && v->BitsPerPixel == 32) {
+ if (CHECK_BYTE_ORDER(v)) {
+ /* no byteswapping needed */
+ return 0 /* PIXEL_FORMAT_U_A8_B8_G8_R8 */;
+ }
+ else {
+ return PIPE_FORMAT_R8G8B8A8_UNORM;
+ }
+ }
+ else if ( GET_REDMASK(v) == 0xff0000
+ && GET_GREENMASK(v) == 0x00ff00
+ && GET_BLUEMASK(v) == 0x0000ff
+ && v->BitsPerPixel == 32) {
+ if (CHECK_BYTE_ORDER(v)) {
+ /* no byteswapping needed */
+ return PIPE_FORMAT_A8R8G8B8_UNORM;
+ }
+ else {
+ return PIPE_FORMAT_B8G8R8A8_UNORM;
+ }
+ }
+ else if ( GET_REDMASK(v) == 0xf800
+ && GET_GREENMASK(v) == 0x07e0
+ && GET_BLUEMASK(v) == 0x001f
+ && CHECK_BYTE_ORDER(v)
+ && v->BitsPerPixel == 16) {
+ /* 5-6-5 RGB */
+ return PIPE_FORMAT_R5G6B5_UNORM;
+ }
+
+ assert(0);
+ return 0;
+}
+
+
/**********************************************************************/
/***** Linked list of XMesaBuffers *****/
@@ -276,6 +322,7 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type,
{
XMesaBuffer b;
GLframebuffer *fb;
+ enum pipe_format colorFormat, depthFormat, stencilFormat;
ASSERT(type == WINDOW || type == PIXMAP || type == PBUFFER);
@@ -289,10 +336,35 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type,
b->type = type;
b->cmap = cmap;
+ /* determine PIPE_FORMATs for buffers */
+ colorFormat = choose_pixel_format(vis);
+
+ if (vis->mesa_visual.depthBits == 0)
+ depthFormat = PIPE_FORMAT_NONE;
+ else if (vis->mesa_visual.depthBits <= 16)
+ depthFormat = PIPE_FORMAT_Z16_UNORM;
+ else if (vis->mesa_visual.depthBits <= 24)
+ depthFormat = PIPE_FORMAT_S8Z24_UNORM;
+ else
+ depthFormat = PIPE_FORMAT_Z32_UNORM;
+
+ if (vis->mesa_visual.stencilBits == 8) {
+ if (depthFormat == PIPE_FORMAT_S8Z24_UNORM)
+ stencilFormat = depthFormat;
+ else
+ stencilFormat = PIPE_FORMAT_S8_UNORM;
+ }
+ else {
+ stencilFormat = PIPE_FORMAT_NONE;
+ }
+
+
/*
* Create framebuffer, but we'll plug in our own renderbuffers below.
*/
- b->stfb = st_create_framebuffer(&vis->mesa_visual, GL_TRUE, (void *) b);
+ b->stfb = st_create_framebuffer(&vis->mesa_visual, GL_TRUE,
+ colorFormat, depthFormat, stencilFormat,
+ (void *) b);
fb = &b->stfb->Base;
/*
@@ -388,52 +460,6 @@ xmesa_free_buffer(XMesaBuffer buffer)
/**
- * Choose the pixel format for the given visual.
- * This will tell the gallium driver how to pack pixel data into
- * drawing surfaces.
- */
-static GLuint
-choose_pixel_format(XMesaVisual v)
-{
- if ( GET_REDMASK(v) == 0x0000ff
- && GET_GREENMASK(v) == 0x00ff00
- && GET_BLUEMASK(v) == 0xff0000
- && v->BitsPerPixel == 32) {
- if (CHECK_BYTE_ORDER(v)) {
- /* no byteswapping needed */
- return 0 /* PIXEL_FORMAT_U_A8_B8_G8_R8 */;
- }
- else {
- return PIPE_FORMAT_R8G8B8A8_UNORM;
- }
- }
- else if ( GET_REDMASK(v) == 0xff0000
- && GET_GREENMASK(v) == 0x00ff00
- && GET_BLUEMASK(v) == 0x0000ff
- && v->BitsPerPixel == 32) {
- if (CHECK_BYTE_ORDER(v)) {
- /* no byteswapping needed */
- return PIPE_FORMAT_A8R8G8B8_UNORM;
- }
- else {
- return PIPE_FORMAT_B8G8R8A8_UNORM;
- }
- }
- else if ( GET_REDMASK(v) == 0xf800
- && GET_GREENMASK(v) == 0x07e0
- && GET_BLUEMASK(v) == 0x001f
- && CHECK_BYTE_ORDER(v)
- && v->BitsPerPixel == 16) {
- /* 5-6-5 RGB */
- return PIPE_FORMAT_R5G6B5_UNORM;
- }
-
- assert(0);
- return 0;
-}
-
-
-/**
* When a context is bound for the first time, we can finally finish
* initializing the context's visual and buffer information.
* \param v the XMesaVisual to initialize