509f5887225ac066054ac2f6782169289464edbd
[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
37 /**
38 * Intel renderbuffer, derived from gl_renderbuffer.
39 */
40 struct intel_renderbuffer
41 {
42 struct gl_renderbuffer Base;
43 struct intel_region *region;
44
45 /** Only used by depth renderbuffers for which HiZ is enabled. */
46 struct intel_region *hiz_region;
47
48 GLuint draw_offset; /**< Offset of drawing address within the region */
49 GLuint draw_x, draw_y; /**< Offset of drawing within the region */
50 };
51
52
53 /**
54 * gl_renderbuffer is a base class which we subclass. The Class field
55 * is used for simple run-time type checking.
56 */
57 #define INTEL_RB_CLASS 0x12345678
58
59
60 /**
61 * Return a gl_renderbuffer ptr casted to intel_renderbuffer.
62 * NULL will be returned if the rb isn't really an intel_renderbuffer.
63 * This is determined by checking the ClassID.
64 */
65 static INLINE struct intel_renderbuffer *
66 intel_renderbuffer(struct gl_renderbuffer *rb)
67 {
68 struct intel_renderbuffer *irb = (struct intel_renderbuffer *) rb;
69 if (irb && irb->Base.ClassID == INTEL_RB_CLASS) {
70 /*_mesa_warning(NULL, "Returning non-intel Rb\n");*/
71 return irb;
72 }
73 else
74 return NULL;
75 }
76
77
78 /**
79 * Return a framebuffer's renderbuffer, named by a BUFFER_x index.
80 */
81 static INLINE struct intel_renderbuffer *
82 intel_get_renderbuffer(struct gl_framebuffer *fb, int attIndex)
83 {
84 if (attIndex >= 0)
85 return intel_renderbuffer(fb->Attachment[attIndex].Renderbuffer);
86 else
87 return NULL;
88 }
89
90 /**
91 * If the framebuffer has a depth buffer attached, then return its HiZ region.
92 * The HiZ region may be null.
93 */
94 static INLINE struct intel_region*
95 intel_framebuffer_get_hiz_region(struct gl_framebuffer *fb)
96 {
97 struct intel_renderbuffer *rb = NULL;
98 if (fb)
99 rb = intel_get_renderbuffer(fb, BUFFER_DEPTH);
100
101 if (rb)
102 return rb->hiz_region;
103 else
104 return NULL;
105 }
106
107 static INLINE bool
108 intel_framebuffer_has_hiz(struct gl_framebuffer *fb)
109 {
110 return intel_framebuffer_get_hiz_region(fb) != NULL;
111 }
112
113
114 extern void
115 intel_renderbuffer_set_region(struct intel_context *intel,
116 struct intel_renderbuffer *irb,
117 struct intel_region *region);
118
119 extern void
120 intel_renderbuffer_set_hiz_region(struct intel_context *intel,
121 struct intel_renderbuffer *rb,
122 struct intel_region *region);
123
124
125 extern struct intel_renderbuffer *
126 intel_create_renderbuffer(gl_format format);
127
128
129 extern void
130 intel_fbo_init(struct intel_context *intel);
131
132
133 extern void
134 intel_flip_renderbuffers(struct gl_framebuffer *fb);
135
136 uint32_t
137 intel_renderbuffer_tile_offsets(struct intel_renderbuffer *irb,
138 uint32_t *tile_x,
139 uint32_t *tile_y);
140
141 static INLINE struct intel_region *
142 intel_get_rb_region(struct gl_framebuffer *fb, GLuint attIndex)
143 {
144 struct intel_renderbuffer *irb = intel_get_renderbuffer(fb, attIndex);
145 if (irb)
146 return irb->region;
147 else
148 return NULL;
149 }
150
151 #endif /* INTEL_FBO_H */