OSDN Git Service

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