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