i965: use _mesa_readpixels() instead of _swrast_ReadPixels()
[mesa.git] / src / mesa / drivers / dri / intel / intel_fbo.h
1 /**************************************************************************
2 *
3 * Copyright 2006 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 #ifndef INTEL_FBO_H
29 #define INTEL_FBO_H
30
31 #include <stdbool.h>
32 #include <assert.h>
33 #include "main/formats.h"
34 #include "intel_context.h"
35 #include "intel_screen.h"
36
37 struct intel_context;
38 struct intel_texture_image;
39
40 /**
41 * Intel renderbuffer, derived from gl_renderbuffer.
42 */
43 struct intel_renderbuffer
44 {
45 struct gl_renderbuffer Base;
46 struct intel_region *region;
47 drm_intel_bo *map_bo;
48 void *map_buffer;
49 GLuint map_x, map_y, map_w, map_h;
50 GLbitfield map_mode;
51
52 /** Only used by depth renderbuffers for which HiZ is enabled. */
53 struct intel_region *hiz_region;
54
55 /**
56 * \name Packed depth/stencil unwrappers
57 *
58 * If the intel_context is using separate stencil and this renderbuffer has
59 * a packed depth/stencil format, then wrapped_depth and wrapped_stencil
60 * are the real renderbuffers.
61 */
62 struct gl_renderbuffer *wrapped_depth;
63 struct gl_renderbuffer *wrapped_stencil;
64 /** \} */
65
66 GLuint draw_x, draw_y; /**< Offset of drawing within the region */
67 };
68
69
70 /**
71 * gl_renderbuffer is a base class which we subclass. The Class field
72 * is used for simple run-time type checking.
73 */
74 #define INTEL_RB_CLASS 0x12345678
75
76
77 /**
78 * Return a gl_renderbuffer ptr casted to intel_renderbuffer.
79 * NULL will be returned if the rb isn't really an intel_renderbuffer.
80 * This is determined by checking the ClassID.
81 */
82 static INLINE struct intel_renderbuffer *
83 intel_renderbuffer(struct gl_renderbuffer *rb)
84 {
85 struct intel_renderbuffer *irb = (struct intel_renderbuffer *) rb;
86 if (irb && irb->Base.ClassID == INTEL_RB_CLASS) {
87 /*_mesa_warning(NULL, "Returning non-intel Rb\n");*/
88 return irb;
89 }
90 else
91 return NULL;
92 }
93
94
95 /**
96 * \brief Return the framebuffer attachment specified by attIndex.
97 *
98 * If the framebuffer lacks the specified attachment, then return null.
99 *
100 * If the attached renderbuffer is a wrapper, then return wrapped
101 * renderbuffer.
102 */
103 static INLINE struct intel_renderbuffer *
104 intel_get_renderbuffer(struct gl_framebuffer *fb, gl_buffer_index attIndex)
105 {
106 struct gl_renderbuffer *rb;
107 struct intel_renderbuffer *irb;
108
109 assert((unsigned)attIndex < ARRAY_SIZE(fb->Attachment));
110
111 rb = fb->Attachment[attIndex].Renderbuffer;
112 if (!rb)
113 return NULL;
114
115 irb = intel_renderbuffer(rb);
116 if (!irb)
117 return NULL;
118
119 switch (attIndex) {
120 case BUFFER_DEPTH:
121 if (irb->wrapped_depth) {
122 irb = intel_renderbuffer(irb->wrapped_depth);
123 }
124 break;
125 case BUFFER_STENCIL:
126 if (irb->wrapped_stencil) {
127 irb = intel_renderbuffer(irb->wrapped_stencil);
128 }
129 break;
130 default:
131 break;
132 }
133
134 return irb;
135 }
136
137 /**
138 * If the framebuffer has a depth buffer attached, then return its HiZ region.
139 * The HiZ region may be null.
140 */
141 static INLINE struct intel_region*
142 intel_framebuffer_get_hiz_region(struct gl_framebuffer *fb)
143 {
144 struct intel_renderbuffer *rb = NULL;
145 if (fb)
146 rb = intel_get_renderbuffer(fb, BUFFER_DEPTH);
147
148 if (rb)
149 return rb->hiz_region;
150 else
151 return NULL;
152 }
153
154 static INLINE bool
155 intel_framebuffer_has_hiz(struct gl_framebuffer *fb)
156 {
157 return intel_framebuffer_get_hiz_region(fb) != NULL;
158 }
159
160 extern struct intel_renderbuffer *
161 intel_create_renderbuffer(gl_format format);
162
163 struct gl_renderbuffer*
164 intel_create_wrapped_renderbuffer(struct gl_context * ctx,
165 int width, int height,
166 gl_format format);
167
168 GLboolean
169 intel_alloc_renderbuffer_storage(struct gl_context * ctx,
170 struct gl_renderbuffer *rb,
171 GLenum internalFormat,
172 GLuint width, GLuint height);
173
174 extern void
175 intel_fbo_init(struct intel_context *intel);
176
177
178 extern void
179 intel_flip_renderbuffers(struct gl_framebuffer *fb);
180
181 void
182 intel_renderbuffer_set_draw_offset(struct intel_renderbuffer *irb,
183 struct intel_texture_image *intel_image,
184 int zoffset);
185
186 uint32_t
187 intel_renderbuffer_tile_offsets(struct intel_renderbuffer *irb,
188 uint32_t *tile_x,
189 uint32_t *tile_y);
190
191 static INLINE struct intel_region *
192 intel_get_rb_region(struct gl_framebuffer *fb, GLuint attIndex)
193 {
194 struct intel_renderbuffer *irb = intel_get_renderbuffer(fb, attIndex);
195 if (irb)
196 return irb->region;
197 else
198 return NULL;
199 }
200
201 #endif /* INTEL_FBO_H */