2 * Copyright (C) 2009 Francisco Jerez.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "nouveau_driver.h"
28 #include "nouveau_fbo.h"
29 #include "nouveau_context.h"
30 #include "nouveau_texture.h"
32 #include "main/framebuffer.h"
33 #include "main/renderbuffer.h"
34 #include "main/fbobject.h"
37 set_renderbuffer_format(struct gl_renderbuffer
*rb
, GLenum internalFormat
)
39 struct nouveau_surface
*s
= &to_nouveau_renderbuffer(rb
)->surface
;
41 rb
->InternalFormat
= internalFormat
;
43 switch (internalFormat
) {
46 rb
->_BaseFormat
= GL_RGB
;
47 rb
->Format
= MESA_FORMAT_XRGB8888
;
48 rb
->DataType
= GL_UNSIGNED_BYTE
;
53 rb
->_BaseFormat
= GL_RGBA
;
54 rb
->Format
= MESA_FORMAT_ARGB8888
;
55 rb
->DataType
= GL_UNSIGNED_BYTE
;
59 rb
->_BaseFormat
= GL_RGB
;
60 rb
->Format
= MESA_FORMAT_RGB565
;
61 rb
->DataType
= GL_UNSIGNED_BYTE
;
64 case GL_DEPTH_COMPONENT16
:
65 rb
->_BaseFormat
= GL_DEPTH_COMPONENT
;
66 rb
->Format
= MESA_FORMAT_Z16
;
67 rb
->DataType
= GL_UNSIGNED_SHORT
;
70 case GL_DEPTH_COMPONENT
:
71 case GL_DEPTH_COMPONENT24
:
72 case GL_STENCIL_INDEX8_EXT
:
73 case GL_DEPTH24_STENCIL8_EXT
:
74 rb
->_BaseFormat
= GL_DEPTH_STENCIL
;
75 rb
->Format
= MESA_FORMAT_Z24_S8
;
76 rb
->DataType
= GL_UNSIGNED_INT_24_8_EXT
;
83 s
->format
= rb
->Format
;
89 nouveau_renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
90 GLenum internalFormat
,
91 GLuint width
, GLuint height
)
93 struct nouveau_surface
*s
= &to_nouveau_renderbuffer(rb
)->surface
;
95 if (!set_renderbuffer_format(rb
, internalFormat
))
101 nouveau_surface_alloc(ctx
, s
, TILED
, NOUVEAU_BO_VRAM
| NOUVEAU_BO_MAP
,
102 rb
->Format
, width
, height
);
104 context_dirty(ctx
, FRAMEBUFFER
);
109 nouveau_renderbuffer_del(struct gl_renderbuffer
*rb
)
111 struct nouveau_surface
*s
= &to_nouveau_renderbuffer(rb
)->surface
;
113 nouveau_surface_ref(NULL
, s
);
117 static struct gl_renderbuffer
*
118 nouveau_renderbuffer_new(struct gl_context
*ctx
, GLuint name
)
120 struct gl_renderbuffer
*rb
;
122 rb
= (struct gl_renderbuffer
*)
123 CALLOC_STRUCT(nouveau_renderbuffer
);
127 _mesa_init_renderbuffer(rb
, name
);
129 rb
->AllocStorage
= nouveau_renderbuffer_storage
;
130 rb
->Delete
= nouveau_renderbuffer_del
;
136 nouveau_renderbuffer_dri_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
137 GLenum internalFormat
,
138 GLuint width
, GLuint height
)
140 if (!set_renderbuffer_format(rb
, internalFormat
))
149 struct gl_renderbuffer
*
150 nouveau_renderbuffer_dri_new(GLenum format
, __DRIdrawable
*drawable
)
152 struct gl_renderbuffer
*rb
;
154 rb
= nouveau_renderbuffer_new(NULL
, 0);
158 rb
->AllocStorage
= nouveau_renderbuffer_dri_storage
;
160 if (!set_renderbuffer_format(rb
, format
)) {
161 nouveau_renderbuffer_del(rb
);
168 static struct gl_framebuffer
*
169 nouveau_framebuffer_new(struct gl_context
*ctx
, GLuint name
)
171 struct nouveau_framebuffer
*nfb
;
173 nfb
= CALLOC_STRUCT(nouveau_framebuffer
);
177 _mesa_initialize_user_framebuffer(&nfb
->base
, name
);
182 struct gl_framebuffer
*
183 nouveau_framebuffer_dri_new(const struct gl_config
*visual
)
185 struct nouveau_framebuffer
*nfb
;
187 nfb
= CALLOC_STRUCT(nouveau_framebuffer
);
191 _mesa_initialize_window_framebuffer(&nfb
->base
, visual
);
192 nfb
->need_front
= !visual
->doubleBufferMode
;
198 nouveau_bind_framebuffer(struct gl_context
*ctx
, GLenum target
,
199 struct gl_framebuffer
*dfb
,
200 struct gl_framebuffer
*rfb
)
202 context_dirty(ctx
, FRAMEBUFFER
);
206 nouveau_framebuffer_renderbuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
207 GLenum attachment
, struct gl_renderbuffer
*rb
)
209 _mesa_framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
);
211 context_dirty(ctx
, FRAMEBUFFER
);
215 get_tex_format(struct gl_texture_image
*ti
)
217 switch (ti
->TexFormat
) {
218 case MESA_FORMAT_ARGB8888
:
220 case MESA_FORMAT_XRGB8888
:
222 case MESA_FORMAT_RGB565
:
230 nouveau_render_texture(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
231 struct gl_renderbuffer_attachment
*att
)
233 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
234 struct gl_texture_image
*ti
=
235 att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
237 /* Allocate a renderbuffer object for the texture if we
238 * haven't already done so. */
240 rb
= nouveau_renderbuffer_new(ctx
, ~0);
243 rb
->AllocStorage
= NULL
;
244 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
247 /* Update the renderbuffer fields from the texture. */
248 set_renderbuffer_format(rb
, get_tex_format(ti
));
249 rb
->Width
= ti
->Width
;
250 rb
->Height
= ti
->Height
;
251 nouveau_surface_ref(&to_nouveau_teximage(ti
)->surface
,
252 &to_nouveau_renderbuffer(rb
)->surface
);
254 context_dirty(ctx
, FRAMEBUFFER
);
258 nouveau_finish_render_texture(struct gl_context
*ctx
,
259 struct gl_renderbuffer_attachment
*att
)
261 texture_dirty(att
->Texture
);
265 nouveau_fbo_functions_init(struct dd_function_table
*functions
)
267 #if FEATURE_EXT_framebuffer_object
268 functions
->NewFramebuffer
= nouveau_framebuffer_new
;
269 functions
->NewRenderbuffer
= nouveau_renderbuffer_new
;
270 functions
->BindFramebuffer
= nouveau_bind_framebuffer
;
271 functions
->FramebufferRenderbuffer
= nouveau_framebuffer_renderbuffer
;
272 functions
->RenderTexture
= nouveau_render_texture
;
273 functions
->FinishRenderTexture
= nouveau_finish_render_texture
;