a44989b5fdd9fc63c23f9efc1ffc7daf6f9bdb53
[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 "intel_screen.h"
32
33 struct intel_context;
34
35 /**
36 * Intel framebuffer, derived from gl_framebuffer.
37 */
38 struct intel_framebuffer
39 {
40 struct gl_framebuffer Base;
41
42 struct intel_renderbuffer *color_rb[2];
43
44 /* VBI
45 */
46 GLuint vbl_waited;
47
48 int64_t swap_ust;
49 int64_t swap_missed_ust;
50
51 GLuint swap_count;
52 GLuint swap_missed_count;
53 };
54
55
56 /**
57 * Intel renderbuffer, derived from gl_renderbuffer.
58 * Note: The PairedDepth and PairedStencil fields use renderbuffer IDs,
59 * not pointers because in some circumstances a deleted renderbuffer could
60 * result in a dangling pointer here.
61 */
62 struct intel_renderbuffer
63 {
64 struct gl_renderbuffer Base;
65 struct intel_region *region;
66 GLuint pfPitch; /* possibly paged flipped pitch */
67 GLboolean RenderToTexture; /* RTT? */
68
69 GLuint pf_pending; /**< sequence number of pending flip */
70
71 GLuint vbl_pending; /**< vblank sequence number of pending flip */
72
73 uint8_t *span_cache;
74 unsigned long span_cache_offset;
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 *
91 intel_renderbuffer(struct gl_renderbuffer *rb)
92 {
93 struct intel_renderbuffer *irb = (struct intel_renderbuffer *) rb;
94 if (irb && irb->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 * Return a framebuffer's renderbuffer, named by a BUFFER_x index.
105 */
106 static INLINE struct intel_renderbuffer *
107 intel_get_renderbuffer(struct gl_framebuffer *fb, int attIndex)
108 {
109 if (attIndex >= 0)
110 return intel_renderbuffer(fb->Attachment[attIndex].Renderbuffer);
111 else
112 return NULL;
113 }
114
115
116 extern void
117 intel_renderbuffer_set_region(struct intel_renderbuffer *irb,
118 struct intel_region *region);
119
120
121 extern struct intel_renderbuffer *
122 intel_create_renderbuffer(GLenum intFormat);
123
124
125 extern void
126 intel_fbo_init(struct intel_context *intel);
127
128
129 extern void
130 intel_flip_renderbuffers(struct intel_framebuffer *intel_fb);
131
132
133 static INLINE struct intel_region *
134 intel_get_rb_region(struct gl_framebuffer *fb, GLuint attIndex)
135 {
136 struct intel_renderbuffer *irb = intel_get_renderbuffer(fb, attIndex);
137 if (irb)
138 return irb->region;
139 else
140 return NULL;
141 }
142
143
144 /**
145 * Are we currently rendering into a texture?
146 */
147 static INLINE GLboolean
148 intel_rendering_to_texture(const GLcontext *ctx)
149 {
150 if (ctx->DrawBuffer->Name) {
151 /* User-created FBO */
152 const struct intel_renderbuffer *irb =
153 intel_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]);
154 return irb && irb->RenderToTexture;
155 }
156 else {
157 return GL_FALSE;
158 }
159 }
160
161
162 #endif /* INTEL_FBO_H */