Remove stray references to struct pipe_region.
[mesa.git] / src / mesa / state_tracker / st_framebuffer.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #include "main/imports.h"
30 #include "main/context.h"
31 #include "main/framebuffer.h"
32 #include "main/renderbuffer.h"
33 #include "st_public.h"
34 #include "st_context.h"
35 #include "st_cb_fbo.h"
36
37
38 struct st_framebuffer *st_create_framebuffer( const __GLcontextModes *visual,
39 boolean createRenderbuffers,
40 void *private)
41 {
42 struct st_framebuffer *stfb
43 = CALLOC_STRUCT(st_framebuffer);
44 if (stfb) {
45 GLenum rgbFormat = (visual->redBits == 5 ? GL_RGB5 : GL_RGBA8);
46
47 _mesa_initialize_framebuffer(&stfb->Base, visual);
48
49 if (createRenderbuffers) {
50 {
51 /* fake frontbuffer */
52 /* XXX allocation should only happen in the unusual case
53 it's actually needed */
54 struct gl_renderbuffer *rb = st_new_renderbuffer_fb(rgbFormat);
55 _mesa_add_renderbuffer(&stfb->Base, BUFFER_FRONT_LEFT, rb);
56 }
57
58 if (visual->doubleBufferMode) {
59 struct gl_renderbuffer *rb = st_new_renderbuffer_fb(rgbFormat);
60 _mesa_add_renderbuffer(&stfb->Base, BUFFER_BACK_LEFT, rb);
61 }
62
63 if (visual->depthBits == 24 && visual->stencilBits == 8) {
64 /* combined depth/stencil buffer */
65 struct gl_renderbuffer *depthStencilRb
66 = st_new_renderbuffer_fb(GL_DEPTH24_STENCIL8_EXT);
67 /* note: bind RB to two attachment points */
68 _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthStencilRb);
69 _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, depthStencilRb);
70 }
71 else {
72 /* separate depth and/or stencil */
73
74 if (visual->depthBits == 32) {
75 /* 32-bit depth buffer */
76 struct gl_renderbuffer *depthRb
77 = st_new_renderbuffer_fb(GL_DEPTH_COMPONENT32);
78 _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb);
79 }
80 else if (visual->depthBits == 24) {
81 /* 24-bit depth buffer, ignore stencil bits */
82 struct gl_renderbuffer *depthRb
83 = st_new_renderbuffer_fb(GL_DEPTH24_STENCIL8_EXT);
84 _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb);
85 }
86 else if (visual->depthBits > 0) {
87 /* 16-bit depth buffer */
88 struct gl_renderbuffer *depthRb
89 = st_new_renderbuffer_fb(GL_DEPTH_COMPONENT16);
90 _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb);
91 }
92
93 if (visual->stencilBits > 0) {
94 /* 8-bit stencil */
95 struct gl_renderbuffer *stencilRb
96 = st_new_renderbuffer_fb(GL_STENCIL_INDEX8_EXT);
97 _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, stencilRb);
98 }
99 }
100
101 #if 0
102 if (visual->accumRedBits > 0) {
103 /* 16-bit/channel accum */
104 struct gl_renderbuffer *accumRb
105 = st_new_renderbuffer_fb(GL_RGBA16);
106 _mesa_add_renderbuffer(&stfb->Base, BUFFER_ACCUM, accumRb);
107 }
108 #endif
109
110 /* now add any/all software-based renderbuffers we may need */
111 _mesa_add_soft_renderbuffers(&stfb->Base,
112 GL_FALSE, /* never sw color */
113 GL_FALSE, /* never sw depth */
114 GL_FALSE, /* stencil */
115 visual->accumRedBits > 0,
116 GL_FALSE, /* never sw alpha */
117 GL_FALSE /* never sw aux */ );
118 }
119
120 stfb->Base.Initialized = GL_TRUE;
121
122 stfb->Private = private;
123 }
124 return stfb;
125 }
126
127
128 void st_resize_framebuffer( struct st_framebuffer *stfb,
129 uint width, uint height )
130 {
131 if (stfb->Base.Width != width || stfb->Base.Height != height) {
132 GET_CURRENT_CONTEXT(ctx);
133 if (ctx) {
134 _mesa_resize_framebuffer(ctx, &stfb->Base, width, height);
135
136 assert(stfb->Base.Width == width);
137 assert(stfb->Base.Height == height);
138 }
139 }
140 }
141
142
143 void st_unreference_framebuffer( struct st_framebuffer **stfb )
144 {
145 _mesa_unreference_framebuffer((struct gl_framebuffer **) stfb);
146 }
147
148
149
150 /**
151 * Return the pipe_surface for the given renderbuffer.
152 */
153 struct pipe_surface *
154 st_get_framebuffer_surface(struct st_framebuffer *stfb, uint surfIndex)
155 {
156 struct st_renderbuffer *strb;
157
158 assert(surfIndex <= ST_SURFACE_DEPTH);
159
160 /* sanity checks, ST tokens should match Mesa tokens */
161 assert(ST_SURFACE_FRONT_LEFT == BUFFER_FRONT_LEFT);
162 assert(ST_SURFACE_BACK_RIGHT == BUFFER_BACK_RIGHT);
163
164 strb = st_renderbuffer(stfb->Base.Attachment[surfIndex].Renderbuffer);
165 if (strb)
166 return strb->surface;
167 return NULL;
168 }
169
170
171 /**
172 * This function is to be called prior to SwapBuffers on the given
173 * framebuffer. It checks if the current context is bound to the framebuffer
174 * and flushes rendering if needed.
175 */
176 void
177 st_notify_swapbuffers(struct st_framebuffer *stfb)
178 {
179 GET_CURRENT_CONTEXT(ctx);
180
181 if (ctx && ctx->DrawBuffer == &stfb->Base) {
182 st_flush(ctx->st, 0x0);
183 }
184 }
185
186
187 void *st_framebuffer_private( struct st_framebuffer *stfb )
188 {
189 return stfb->Private;
190 }
191