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_COMPONENT24
:
71 case GL_STENCIL_INDEX8_EXT
:
72 case GL_DEPTH24_STENCIL8_EXT
:
73 rb
->_BaseFormat
= GL_DEPTH_STENCIL
;
74 rb
->Format
= MESA_FORMAT_Z24_S8
;
75 rb
->DataType
= GL_UNSIGNED_INT_24_8_EXT
;
82 s
->format
= rb
->Format
;
88 nouveau_renderbuffer_storage(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
89 GLenum internalFormat
,
90 GLuint width
, GLuint height
)
92 struct nouveau_surface
*s
= &to_nouveau_renderbuffer(rb
)->surface
;
94 if (!set_renderbuffer_format(rb
, internalFormat
))
100 nouveau_surface_alloc(ctx
, s
, TILED
, NOUVEAU_BO_VRAM
| NOUVEAU_BO_MAP
,
101 rb
->Format
, width
, height
);
103 context_dirty(ctx
, FRAMEBUFFER
);
108 nouveau_renderbuffer_del(struct gl_renderbuffer
*rb
)
110 struct nouveau_surface
*s
= &to_nouveau_renderbuffer(rb
)->surface
;
112 nouveau_surface_ref(NULL
, s
);
116 static struct gl_renderbuffer
*
117 nouveau_renderbuffer_new(GLcontext
*ctx
, GLuint name
)
119 struct gl_renderbuffer
*rb
;
121 rb
= (struct gl_renderbuffer
*)
122 CALLOC_STRUCT(nouveau_renderbuffer
);
126 _mesa_init_renderbuffer(rb
, name
);
128 rb
->AllocStorage
= nouveau_renderbuffer_storage
;
129 rb
->Delete
= nouveau_renderbuffer_del
;
135 nouveau_renderbuffer_dri_storage(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
136 GLenum internalFormat
,
137 GLuint width
, GLuint height
)
139 if (!set_renderbuffer_format(rb
, internalFormat
))
148 struct gl_renderbuffer
*
149 nouveau_renderbuffer_dri_new(GLenum format
, __DRIdrawable
*drawable
)
151 struct gl_renderbuffer
*rb
;
153 rb
= nouveau_renderbuffer_new(NULL
, 0);
157 rb
->AllocStorage
= nouveau_renderbuffer_dri_storage
;
159 if (!set_renderbuffer_format(rb
, format
)) {
160 nouveau_renderbuffer_del(rb
);
167 static struct gl_framebuffer
*
168 nouveau_framebuffer_new(GLcontext
*ctx
, GLuint name
)
170 struct nouveau_framebuffer
*nfb
;
172 nfb
= CALLOC_STRUCT(nouveau_framebuffer
);
176 _mesa_initialize_user_framebuffer(&nfb
->base
, name
);
181 struct gl_framebuffer
*
182 nouveau_framebuffer_dri_new(const GLvisual
*visual
)
184 struct nouveau_framebuffer
*nfb
;
186 nfb
= CALLOC_STRUCT(nouveau_framebuffer
);
190 _mesa_initialize_window_framebuffer(&nfb
->base
, visual
);
196 nouveau_bind_framebuffer(GLcontext
*ctx
, GLenum target
,
197 struct gl_framebuffer
*dfb
,
198 struct gl_framebuffer
*rfb
)
200 context_dirty(ctx
, FRAMEBUFFER
);
204 nouveau_framebuffer_renderbuffer(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
205 GLenum attachment
, struct gl_renderbuffer
*rb
)
207 _mesa_framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
);
209 context_dirty(ctx
, FRAMEBUFFER
);
213 get_tex_format(struct gl_texture_image
*ti
)
215 switch (ti
->TexFormat
) {
216 case MESA_FORMAT_ARGB8888
:
218 case MESA_FORMAT_XRGB8888
:
220 case MESA_FORMAT_RGB565
:
228 nouveau_render_texture(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
229 struct gl_renderbuffer_attachment
*att
)
231 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
232 struct gl_texture_image
*ti
=
233 att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
236 /* Allocate a renderbuffer object for the texture if we
237 * haven't already done so. */
239 rb
= nouveau_renderbuffer_new(ctx
, ~0);
242 rb
->AllocStorage
= NULL
;
243 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
246 /* Update the renderbuffer fields from the texture. */
247 ret
= set_renderbuffer_format(rb
, get_tex_format(ti
));
250 rb
->Width
= ti
->Width
;
251 rb
->Height
= ti
->Height
;
252 nouveau_surface_ref(&to_nouveau_teximage(ti
)->surface
,
253 &to_nouveau_renderbuffer(rb
)->surface
);
255 context_dirty(ctx
, FRAMEBUFFER
);
259 nouveau_finish_render_texture(GLcontext
*ctx
,
260 struct gl_renderbuffer_attachment
*att
)
262 texture_dirty(att
->Texture
);
266 nouveau_fbo_functions_init(struct dd_function_table
*functions
)
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
;