1/**************************************************************************
2 *
3 * Copyright 2006 VMware, Inc.
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 VMWARE 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 "main/macros.h"
35#include "intel_context.h"
36#include "intel_mipmap_tree.h"
37#include "intel_screen.h"
38
39struct intel_context;
40struct intel_mipmap_tree;
41struct intel_texture_image;
42
43/**
44 * Intel renderbuffer, derived from gl_renderbuffer.
45 */
46struct intel_renderbuffer
47{
48   struct swrast_renderbuffer Base;
49   struct intel_mipmap_tree *mt; /**< The renderbuffer storage. */
50
51   /**
52    * \name Miptree view
53    * \{
54    *
55    * Multiple renderbuffers may simultaneously wrap a single texture and each
56    * provide a different view into that texture. The fields below indicate
57    * which miptree slice is wrapped by this renderbuffer.  The fields' values
58    * are consistent with the 'level' and 'layer' parameters of
59    * glFramebufferTextureLayer().
60    *
61    * For renderbuffers not created with glFramebufferTexture*(), mt_level and
62    * mt_layer are 0.
63    */
64   unsigned int mt_level;
65   unsigned int mt_layer;
66   /** \} */
67
68   GLuint draw_x, draw_y; /**< Offset of drawing within the region */
69};
70
71
72/**
73 * gl_renderbuffer is a base class which we subclass.  The Class field
74 * is used for simple run-time type checking.
75 */
76#define INTEL_RB_CLASS 0x12345678
77
78
79/**
80 * Return a gl_renderbuffer ptr casted to intel_renderbuffer.
81 * NULL will be returned if the rb isn't really an intel_renderbuffer.
82 * This is determined by checking the ClassID.
83 */
84static inline struct intel_renderbuffer *
85intel_renderbuffer(struct gl_renderbuffer *rb)
86{
87   struct intel_renderbuffer *irb = (struct intel_renderbuffer *) rb;
88   if (irb && irb->Base.Base.ClassID == INTEL_RB_CLASS)
89      return irb;
90   else
91      return NULL;
92}
93
94
95/**
96 * \brief Return the framebuffer attachment specified by attIndex.
97 *
98 * If the framebuffer lacks the specified attachment, then return null.
99 *
100 * If the attached renderbuffer is a wrapper, then return wrapped
101 * renderbuffer.
102 */
103static inline struct intel_renderbuffer *
104intel_get_renderbuffer(struct gl_framebuffer *fb, gl_buffer_index attIndex)
105{
106   struct gl_renderbuffer *rb;
107
108   assert((unsigned)attIndex < ARRAY_SIZE(fb->Attachment));
109
110   rb = fb->Attachment[attIndex].Renderbuffer;
111   if (!rb)
112      return NULL;
113
114   return intel_renderbuffer(rb);
115}
116
117
118static inline mesa_format
119intel_rb_format(const struct intel_renderbuffer *rb)
120{
121   return rb->Base.Base.Format;
122}
123
124extern struct intel_renderbuffer *
125intel_create_renderbuffer(mesa_format format);
126
127struct intel_renderbuffer *
128intel_create_private_renderbuffer(mesa_format format);
129
130struct gl_renderbuffer*
131intel_create_wrapped_renderbuffer(struct gl_context * ctx,
132				  int width, int height,
133				  mesa_format format);
134
135extern void
136intel_fbo_init(struct intel_context *intel);
137
138
139extern void
140intel_flip_renderbuffers(struct gl_framebuffer *fb);
141
142void
143intel_renderbuffer_set_draw_offset(struct intel_renderbuffer *irb);
144
145static inline uint32_t
146intel_renderbuffer_get_tile_offsets(struct intel_renderbuffer *irb,
147                                    uint32_t *tile_x,
148                                    uint32_t *tile_y)
149{
150   return intel_miptree_get_tile_offsets(irb->mt, irb->mt_level, irb->mt_layer,
151                                         tile_x, tile_y);
152}
153
154struct intel_region*
155intel_get_rb_region(struct gl_framebuffer *fb, GLuint attIndex);
156
157#endif /* INTEL_FBO_H */
158