intel_fbo.h revision 24da7335b22432ef4c2d57cab86e4b8fbe8733d5
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
37struct intel_context;
38struct intel_mipmap_tree;
39struct intel_texture_image;
40
41/**
42 * Intel renderbuffer, derived from gl_renderbuffer.
43 */
44struct intel_renderbuffer
45{
46   struct gl_renderbuffer Base;
47   struct intel_mipmap_tree *mt; /**< The renderbuffer storage. */
48   drm_intel_bo *map_bo;
49
50   void *map_buffer;
51   GLuint map_x, map_y, map_w, map_h;
52   GLbitfield map_mode;
53
54   /**
55    * \name Miptree view
56    * \{
57    *
58    * Multiple renderbuffers may simultaneously wrap a single texture and each
59    * provide a different view into that texture. The fields below indicate
60    * which miptree slice is wrapped by this renderbuffer.  The fields' values
61    * are consistent with the 'level' and 'layer' parameters of
62    * glFramebufferTextureLayer().
63    *
64    * For renderbuffers not created with glFramebufferTexture*(), mt_level and
65    * mt_layer are 0.
66    */
67   unsigned int mt_level;
68   unsigned int mt_layer;
69   /** \} */
70
71   /**
72    * \name Packed depth/stencil unwrappers
73    *
74    * If the intel_context is using separate stencil and this renderbuffer has
75    * a packed depth/stencil format, then wrapped_depth and wrapped_stencil
76    * are the real renderbuffers.
77    */
78   struct gl_renderbuffer *wrapped_depth;
79   struct gl_renderbuffer *wrapped_stencil;
80   /** \} */
81
82   GLuint draw_x, draw_y; /**< Offset of drawing within the region */
83};
84
85
86/**
87 * gl_renderbuffer is a base class which we subclass.  The Class field
88 * is used for simple run-time type checking.
89 */
90#define INTEL_RB_CLASS 0x12345678
91
92
93/**
94 * Return a gl_renderbuffer ptr casted to intel_renderbuffer.
95 * NULL will be returned if the rb isn't really an intel_renderbuffer.
96 * This is determined by checking the ClassID.
97 */
98static INLINE struct intel_renderbuffer *
99intel_renderbuffer(struct gl_renderbuffer *rb)
100{
101   struct intel_renderbuffer *irb = (struct intel_renderbuffer *) rb;
102   if (irb && irb->Base.ClassID == INTEL_RB_CLASS) {
103      /*_mesa_warning(NULL, "Returning non-intel Rb\n");*/
104      return irb;
105   }
106   else
107      return NULL;
108}
109
110
111/**
112 * \brief Return the framebuffer attachment specified by attIndex.
113 *
114 * If the framebuffer lacks the specified attachment, then return null.
115 *
116 * If the attached renderbuffer is a wrapper, then return wrapped
117 * renderbuffer.
118 */
119static INLINE struct intel_renderbuffer *
120intel_get_renderbuffer(struct gl_framebuffer *fb, gl_buffer_index attIndex)
121{
122   struct gl_renderbuffer *rb;
123   struct intel_renderbuffer *irb;
124
125   assert((unsigned)attIndex < ARRAY_SIZE(fb->Attachment));
126
127   rb = fb->Attachment[attIndex].Renderbuffer;
128   if (!rb)
129      return NULL;
130
131   irb = intel_renderbuffer(rb);
132   if (!irb)
133      return NULL;
134
135   switch (attIndex) {
136   case BUFFER_DEPTH:
137      if (irb->wrapped_depth) {
138	 irb = intel_renderbuffer(irb->wrapped_depth);
139      }
140      break;
141   case BUFFER_STENCIL:
142      if (irb->wrapped_stencil) {
143	 irb = intel_renderbuffer(irb->wrapped_stencil);
144      }
145      break;
146   default:
147      break;
148   }
149
150   return irb;
151}
152
153bool
154intel_framebuffer_has_hiz(struct gl_framebuffer *fb);
155
156extern struct intel_renderbuffer *
157intel_create_renderbuffer(gl_format format);
158
159struct gl_renderbuffer*
160intel_create_wrapped_renderbuffer(struct gl_context * ctx,
161				  int width, int height,
162				  gl_format format);
163
164GLboolean
165intel_alloc_renderbuffer_storage(struct gl_context * ctx,
166				 struct gl_renderbuffer *rb,
167                                 GLenum internalFormat,
168                                 GLuint width, GLuint height);
169
170extern void
171intel_fbo_init(struct intel_context *intel);
172
173
174extern void
175intel_flip_renderbuffers(struct gl_framebuffer *fb);
176
177void
178intel_renderbuffer_set_draw_offset(struct intel_renderbuffer *irb,
179				   struct intel_texture_image *intel_image,
180				   int zoffset);
181
182uint32_t
183intel_renderbuffer_tile_offsets(struct intel_renderbuffer *irb,
184				uint32_t *tile_x,
185				uint32_t *tile_y);
186
187struct intel_region*
188intel_get_rb_region(struct gl_framebuffer *fb, GLuint attIndex);
189
190#endif /* INTEL_FBO_H */
191