intel_fbo.h revision 53fa28f7b1f21251a3807abf1f234f52beff0256
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
38extern "C" {
39#endif
40
41struct intel_context;
42struct intel_mipmap_tree;
43struct intel_texture_image;
44
45/**
46 * Intel renderbuffer, derived from gl_renderbuffer.
47 */
48struct 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 */
90static INLINE struct intel_renderbuffer *
91intel_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 */
111static INLINE struct intel_renderbuffer *
112intel_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
126static INLINE gl_format
127intel_rb_format(const struct intel_renderbuffer *rb)
128{
129   return rb->Base.Base.Format;
130}
131
132extern struct intel_renderbuffer *
133intel_create_renderbuffer(gl_format format);
134
135struct intel_renderbuffer *
136intel_create_private_renderbuffer(gl_format format);
137
138struct gl_renderbuffer*
139intel_create_wrapped_renderbuffer(struct gl_context * ctx,
140				  int width, int height,
141				  gl_format format);
142
143GLboolean
144intel_alloc_renderbuffer_storage(struct gl_context * ctx,
145				 struct gl_renderbuffer *rb,
146                                 GLenum internalFormat,
147                                 GLuint width, GLuint height);
148
149extern void
150intel_fbo_init(struct intel_context *intel);
151
152
153extern void
154intel_flip_renderbuffers(struct gl_framebuffer *fb);
155
156void
157intel_renderbuffer_set_draw_offset(struct intel_renderbuffer *irb);
158
159void
160intel_renderbuffer_fine_offset_masks(struct intel_renderbuffer *irb,
161                                     uint32_t *fine_offset_mask_x,
162                                     uint32_t *fine_offset_mask_y);
163
164uint32_t
165intel_renderbuffer_tile_offsets(struct intel_renderbuffer *irb,
166				uint32_t *tile_x,
167				uint32_t *tile_y);
168
169struct intel_region*
170intel_get_rb_region(struct gl_framebuffer *fb, GLuint attIndex);
171
172void
173intel_renderbuffer_set_needs_hiz_resolve(struct intel_renderbuffer *irb);
174
175void
176intel_renderbuffer_set_needs_depth_resolve(struct intel_renderbuffer *irb);
177
178
179/**
180 * \brief Perform a HiZ resolve on the renderbuffer.
181 *
182 * It is safe to call this function on a renderbuffer without HiZ. In that
183 * case, the function is a no-op.
184 *
185 * \return false if no resolve was needed
186 */
187bool
188intel_renderbuffer_resolve_hiz(struct intel_context *intel,
189			       struct intel_renderbuffer *irb);
190
191/**
192 * \brief Perform a depth resolve on the renderbuffer.
193 *
194 * It is safe to call this function on a renderbuffer without HiZ. In that
195 * case, the function is a no-op.
196 *
197 * \return false if no resolve was needed
198 */
199bool
200intel_renderbuffer_resolve_depth(struct intel_context *intel,
201				 struct intel_renderbuffer *irb);
202
203unsigned
204intel_quantize_num_samples(struct intel_screen *intel, unsigned num_samples);
205
206#ifdef __cplusplus
207}
208#endif
209
210#endif /* INTEL_FBO_H */
211