af3a835d82a77e43ce44eac2e6045094479e241a
[mesa.git] / src / mesa / drivers / dri / i965 / 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 "main/macros.h"
35 #include "intel_context.h"
36 #include "intel_mipmap_tree.h"
37 #include "intel_screen.h"
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 struct intel_context;
44 struct intel_mipmap_tree;
45 struct intel_texture_image;
46
47 /**
48 * Intel renderbuffer, derived from gl_renderbuffer.
49 */
50 struct intel_renderbuffer
51 {
52 struct swrast_renderbuffer Base;
53 struct intel_mipmap_tree *mt; /**< The renderbuffer storage. */
54
55 /**
56 * \name Miptree view
57 * \{
58 *
59 * Multiple renderbuffers may simultaneously wrap a single texture and each
60 * provide a different view into that texture. The fields below indicate
61 * which miptree slice is wrapped by this renderbuffer. The fields' values
62 * are consistent with the 'level' and 'layer' parameters of
63 * glFramebufferTextureLayer().
64 *
65 * For renderbuffers not created with glFramebufferTexture*(), mt_level and
66 * mt_layer are 0.
67 */
68 unsigned int mt_level;
69 unsigned int mt_layer;
70 /** \} */
71
72 GLuint draw_x, draw_y; /**< Offset of drawing within the region */
73 };
74
75
76 /**
77 * gl_renderbuffer is a base class which we subclass. The Class field
78 * is used for simple run-time type checking.
79 */
80 #define INTEL_RB_CLASS 0x12345678
81
82
83 /**
84 * Return a gl_renderbuffer ptr casted to intel_renderbuffer.
85 * NULL will be returned if the rb isn't really an intel_renderbuffer.
86 * This is determined by checking the ClassID.
87 */
88 static INLINE struct intel_renderbuffer *
89 intel_renderbuffer(struct gl_renderbuffer *rb)
90 {
91 struct intel_renderbuffer *irb = (struct intel_renderbuffer *) rb;
92 if (irb && irb->Base.Base.ClassID == INTEL_RB_CLASS) {
93 /*_mesa_warning(NULL, "Returning non-intel Rb\n");*/
94 return irb;
95 }
96 else
97 return NULL;
98 }
99
100
101 /**
102 * \brief Return the framebuffer attachment specified by attIndex.
103 *
104 * If the framebuffer lacks the specified attachment, then return null.
105 *
106 * If the attached renderbuffer is a wrapper, then return wrapped
107 * renderbuffer.
108 */
109 static INLINE struct intel_renderbuffer *
110 intel_get_renderbuffer(struct gl_framebuffer *fb, gl_buffer_index attIndex)
111 {
112 struct gl_renderbuffer *rb;
113
114 assert((unsigned)attIndex < ARRAY_SIZE(fb->Attachment));
115
116 rb = fb->Attachment[attIndex].Renderbuffer;
117 if (!rb)
118 return NULL;
119
120 return intel_renderbuffer(rb);
121 }
122
123
124 static INLINE gl_format
125 intel_rb_format(const struct intel_renderbuffer *rb)
126 {
127 return rb->Base.Base.Format;
128 }
129
130 extern struct intel_renderbuffer *
131 intel_create_renderbuffer(gl_format format, unsigned num_samples);
132
133 struct intel_renderbuffer *
134 intel_create_private_renderbuffer(gl_format format, unsigned num_samples);
135
136 struct gl_renderbuffer*
137 intel_create_wrapped_renderbuffer(struct gl_context * ctx,
138 int width, int height,
139 gl_format format);
140
141 extern void
142 intel_fbo_init(struct intel_context *intel);
143
144 void
145 intel_renderbuffer_set_draw_offset(struct intel_renderbuffer *irb);
146
147 static inline uint32_t
148 intel_renderbuffer_get_tile_offsets(struct intel_renderbuffer *irb,
149 uint32_t *tile_x,
150 uint32_t *tile_y)
151 {
152 return intel_miptree_get_tile_offsets(irb->mt, irb->mt_level, irb->mt_layer,
153 tile_x, tile_y);
154 }
155
156 void
157 intel_renderbuffer_set_needs_downsample(struct intel_renderbuffer *irb);
158
159 bool
160 intel_renderbuffer_has_hiz(struct intel_renderbuffer *irb);
161
162 void
163 intel_renderbuffer_set_needs_hiz_resolve(struct intel_renderbuffer *irb);
164
165 void
166 intel_renderbuffer_set_needs_depth_resolve(struct intel_renderbuffer *irb);
167
168
169 /**
170 * \brief Perform a HiZ resolve on the renderbuffer.
171 *
172 * It is safe to call this function on a renderbuffer without HiZ. In that
173 * case, the function is a no-op.
174 *
175 * \return false if no resolve was needed
176 */
177 bool
178 intel_renderbuffer_resolve_hiz(struct intel_context *intel,
179 struct intel_renderbuffer *irb);
180
181 /**
182 * \brief Perform a depth resolve on the renderbuffer.
183 *
184 * It is safe to call this function on a renderbuffer without HiZ. In that
185 * case, the function is a no-op.
186 *
187 * \return false if no resolve was needed
188 */
189 bool
190 intel_renderbuffer_resolve_depth(struct intel_context *intel,
191 struct intel_renderbuffer *irb);
192
193 void intel_renderbuffer_move_to_temp(struct intel_context *intel,
194 struct intel_renderbuffer *irb,
195 bool invalidate);
196
197 unsigned
198 intel_quantize_num_samples(struct intel_screen *intel, unsigned num_samples);
199
200 #ifdef __cplusplus
201 }
202 #endif
203
204 #endif /* INTEL_FBO_H */