1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Mesa 3-D graphics library
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
8bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
9bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
11bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
12bf215546Sopenharmony_ci *
13bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included
14bf215546Sopenharmony_ci * in all copies or substantial portions of the Software.
15bf215546Sopenharmony_ci *
16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22bf215546Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
23bf215546Sopenharmony_ci */
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci#ifndef FRAMEBUFFER_H
27bf215546Sopenharmony_ci#define FRAMEBUFFER_H
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include "mtypes.h"
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_cistruct gl_config;
32bf215546Sopenharmony_cistruct gl_context;
33bf215546Sopenharmony_cistruct gl_renderbuffer;
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ciextern struct gl_framebuffer *
36bf215546Sopenharmony_ci_mesa_new_framebuffer(struct gl_context *ctx, GLuint name);
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_ciextern void
39bf215546Sopenharmony_ci_mesa_initialize_window_framebuffer(struct gl_framebuffer *fb,
40bf215546Sopenharmony_ci				     const struct gl_config *visual);
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_ciextern void
43bf215546Sopenharmony_ci_mesa_initialize_user_framebuffer(struct gl_framebuffer *fb, GLuint name);
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ciextern void
46bf215546Sopenharmony_ci_mesa_destroy_framebuffer(struct gl_framebuffer *buffer);
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ciextern void
49bf215546Sopenharmony_ci_mesa_free_framebuffer_data(struct gl_framebuffer *buffer);
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ciextern void
52bf215546Sopenharmony_ci_mesa_reference_framebuffer_(struct gl_framebuffer **ptr,
53bf215546Sopenharmony_ci                             struct gl_framebuffer *fb);
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_cistatic inline void
56bf215546Sopenharmony_ci_mesa_reference_framebuffer(struct gl_framebuffer **ptr,
57bf215546Sopenharmony_ci                            struct gl_framebuffer *fb)
58bf215546Sopenharmony_ci{
59bf215546Sopenharmony_ci   if (*ptr != fb)
60bf215546Sopenharmony_ci      _mesa_reference_framebuffer_(ptr, fb);
61bf215546Sopenharmony_ci}
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ciextern void
64bf215546Sopenharmony_ci_mesa_resize_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
65bf215546Sopenharmony_ci                         GLuint width, GLuint height);
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ciextern void
69bf215546Sopenharmony_ci_mesa_resizebuffers( struct gl_context *ctx );
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_ciextern void
72bf215546Sopenharmony_ci_mesa_intersect_scissor_bounding_box(const struct gl_context *ctx,
73bf215546Sopenharmony_ci                                     unsigned idx, int *bbox);
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_cistatic inline GLuint
76bf215546Sopenharmony_ci_mesa_geometric_width(const struct gl_framebuffer *buffer)
77bf215546Sopenharmony_ci{
78bf215546Sopenharmony_ci   return buffer->_HasAttachments ?
79bf215546Sopenharmony_ci      buffer->Width : buffer->DefaultGeometry.Width;
80bf215546Sopenharmony_ci}
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_cistatic inline GLuint
83bf215546Sopenharmony_ci_mesa_geometric_height(const struct gl_framebuffer *buffer)
84bf215546Sopenharmony_ci{
85bf215546Sopenharmony_ci   return buffer->_HasAttachments ?
86bf215546Sopenharmony_ci      buffer->Height : buffer->DefaultGeometry.Height;
87bf215546Sopenharmony_ci}
88bf215546Sopenharmony_ci
89bf215546Sopenharmony_cistatic inline GLuint
90bf215546Sopenharmony_ci_mesa_geometric_samples(const struct gl_framebuffer *buffer)
91bf215546Sopenharmony_ci{
92bf215546Sopenharmony_ci   return buffer->_HasAttachments ?
93bf215546Sopenharmony_ci      buffer->Visual.samples :
94bf215546Sopenharmony_ci      buffer->DefaultGeometry._NumSamples;
95bf215546Sopenharmony_ci}
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_cistatic inline GLuint
98bf215546Sopenharmony_ci_mesa_geometric_layers(const struct gl_framebuffer *buffer)
99bf215546Sopenharmony_ci{
100bf215546Sopenharmony_ci   return buffer->_HasAttachments ?
101bf215546Sopenharmony_ci      buffer->MaxNumLayers : buffer->DefaultGeometry.Layers;
102bf215546Sopenharmony_ci}
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_ci#define Y_0_TOP 1
105bf215546Sopenharmony_ci#define Y_0_BOTTOM 2
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_cistatic inline GLuint
108bf215546Sopenharmony_ci_mesa_fb_orientation(const struct gl_framebuffer *fb)
109bf215546Sopenharmony_ci{
110bf215546Sopenharmony_ci   if (fb && fb->FlipY) {
111bf215546Sopenharmony_ci      /* Drawing into a window (on-screen buffer).
112bf215546Sopenharmony_ci       *
113bf215546Sopenharmony_ci       * Negate Y scale to flip image vertically.
114bf215546Sopenharmony_ci       * The NDC Y coords prior to viewport transformation are in the range
115bf215546Sopenharmony_ci       * [y=-1=bottom, y=1=top]
116bf215546Sopenharmony_ci       * Hardware window coords are in the range [y=0=top, y=H-1=bottom] where
117bf215546Sopenharmony_ci       * H is the window height.
118bf215546Sopenharmony_ci       * Use the viewport transformation to invert Y.
119bf215546Sopenharmony_ci       */
120bf215546Sopenharmony_ci      return Y_0_TOP;
121bf215546Sopenharmony_ci   }
122bf215546Sopenharmony_ci   else {
123bf215546Sopenharmony_ci      /* Drawing into user-created FBO (very likely a texture).
124bf215546Sopenharmony_ci       *
125bf215546Sopenharmony_ci       * For textures, T=0=Bottom, so by extension Y=0=Bottom for rendering.
126bf215546Sopenharmony_ci       */
127bf215546Sopenharmony_ci      return Y_0_BOTTOM;
128bf215546Sopenharmony_ci   }
129bf215546Sopenharmony_ci}
130bf215546Sopenharmony_ci
131bf215546Sopenharmony_ciextern void
132bf215546Sopenharmony_ci_mesa_update_draw_buffer_bounds(struct gl_context *ctx,
133bf215546Sopenharmony_ci                                struct gl_framebuffer *drawFb);
134bf215546Sopenharmony_ci
135bf215546Sopenharmony_ciextern void
136bf215546Sopenharmony_ci_mesa_update_framebuffer_visual(struct gl_context *ctx,
137bf215546Sopenharmony_ci				struct gl_framebuffer *fb);
138bf215546Sopenharmony_ci
139bf215546Sopenharmony_ciextern void
140bf215546Sopenharmony_ci_mesa_update_framebuffer(struct gl_context *ctx,
141bf215546Sopenharmony_ci                         struct gl_framebuffer *readFb,
142bf215546Sopenharmony_ci                         struct gl_framebuffer *drawFb);
143bf215546Sopenharmony_ci
144bf215546Sopenharmony_ciextern GLboolean
145bf215546Sopenharmony_ci_mesa_source_buffer_exists(struct gl_context *ctx, GLenum format);
146bf215546Sopenharmony_ci
147bf215546Sopenharmony_ciextern GLboolean
148bf215546Sopenharmony_ci_mesa_dest_buffer_exists(struct gl_context *ctx, GLenum format);
149bf215546Sopenharmony_ci
150bf215546Sopenharmony_ciextern GLenum
151bf215546Sopenharmony_ci_mesa_get_color_read_type(struct gl_context *ctx,
152bf215546Sopenharmony_ci                          struct gl_framebuffer *fb,
153bf215546Sopenharmony_ci                          const char *caller);
154bf215546Sopenharmony_ci
155bf215546Sopenharmony_ciextern GLenum
156bf215546Sopenharmony_ci_mesa_get_color_read_format(struct gl_context *ctx,
157bf215546Sopenharmony_ci                            struct gl_framebuffer *fb,
158bf215546Sopenharmony_ci                            const char *caller);
159bf215546Sopenharmony_ci
160bf215546Sopenharmony_ciextern struct gl_renderbuffer *
161bf215546Sopenharmony_ci_mesa_get_read_renderbuffer_for_format(const struct gl_context *ctx,
162bf215546Sopenharmony_ci                                       GLenum format);
163bf215546Sopenharmony_ci
164bf215546Sopenharmony_ciextern void
165bf215546Sopenharmony_ci_mesa_print_framebuffer(const struct gl_framebuffer *fb);
166bf215546Sopenharmony_ci
167bf215546Sopenharmony_ciextern bool
168bf215546Sopenharmony_ci_mesa_is_multisample_enabled(const struct gl_context *ctx);
169bf215546Sopenharmony_ci
170bf215546Sopenharmony_ciextern bool
171bf215546Sopenharmony_ci_mesa_is_alpha_test_enabled(const struct gl_context *ctx);
172bf215546Sopenharmony_ci
173bf215546Sopenharmony_civoid
174bf215546Sopenharmony_ci_mesa_draw_buffer_allocate(struct gl_context *ctx);
175bf215546Sopenharmony_ci
176bf215546Sopenharmony_ci#endif /* FRAMEBUFFER_H */
177