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