radeon: initial couch code copy from radeon
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_fbo.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Red Hat 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 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
29 #include "main/imports.h"
30 #include "main/macros.h"
31 #include "main/mtypes.h"
32 #include "main/fbobject.h"
33 #include "main/framebuffer.h"
34 #include "main/renderbuffer.h"
35 #include "main/context.h"
36 #include "main/texformat.h"
37 #include "main/texrender.h"
38
39 #include "radeon_common.h"
40
41 static struct gl_framebuffer *
42 radeon_new_framebuffer(GLcontext *ctx, GLuint name)
43 {
44 return _mesa_new_framebuffer(ctx, name);
45 }
46
47 static void
48 radeon_delete_renderbuffer(struct gl_renderbuffer *rb)
49 {
50 GET_CURRENT_CONTEXT(ctx);
51 struct radeon_renderbuffer *rrb = radeon_renderbuffer(rb);
52
53 ASSERT(rrb);
54
55 if (rrb && rrb->bo) {
56 radeon_bo_unref(rrb->bo);
57 }
58
59
60 _mesa_free(rrb);
61 }
62
63 static void
64 radeon_resize_buffers(GLcontext *ctx, struct gl_framebuffer *fb,
65 GLuint width, GLuint height)
66 {
67
68 }
69
70 static void *
71 radeon_get_pointer(GLcontext *ctx, struct gl_renderbuffer *rb,
72 GLint x, GLint y)
73 {
74 return NULL;
75 }
76
77 /**
78 * Called via glRenderbufferStorageEXT() to set the format and allocate
79 * storage for a user-created renderbuffer.
80 */
81 static GLboolean
82 radeon_alloc_renderbuffer_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
83 GLenum internalFormat,
84 GLuint width, GLuint height)
85 {
86 struct radeon_context *radeon = RADEON_CONTEXT(ctx);
87 struct radeon_renderbuffer *rrb = radeon_renderbuffer(rb);
88 GLboolean software_buffer = GL_FALSE;
89 int cpp;
90
91 ASSERT(rb->Name != 0);
92
93 if (software_buffer) {
94 return _mesa_soft_renderbuffer_storage(ctx, rb, internalFormat,
95 width, height);
96 }
97 else {
98 /* TODO Alloc a BO */
99 return GL_TRUE;
100 }
101
102 }
103
104 static struct gl_renderbuffer *
105 radeon_new_renderbuffer(GLcontext * ctx, GLuint name)
106 {
107 struct radeon_renderbuffer *rrb;
108
109 rrb = CALLOC_STRUCT(radeon_renderbuffer);
110 if (!rrb)
111 return NULL;
112
113 _mesa_init_renderbuffer(&rrb->base, name);
114 rrb->base.ClassID = RADEON_RB_CLASS;
115
116 rrb->base.Delete = radeon_delete_renderbuffer;
117 rrb->base.AllocStorage = radeon_alloc_renderbuffer_storage;
118 rrb->base.GetPointer = radeon_get_pointer;
119
120 return &rrb->base;
121 }
122
123 static void
124 radeon_bind_framebuffer(GLcontext * ctx, GLenum target,
125 struct gl_framebuffer *fb, struct gl_framebuffer *fbread)
126 {
127 if (target == GL_FRAMEBUFFER_EXT || target == GL_DRAW_FRAMEBUFFER_EXT) {
128 radeon_draw_buffer(ctx, fb);
129 }
130 else {
131 /* don't need to do anything if target == GL_READ_FRAMEBUFFER_EXT */
132 }
133 }
134
135 static void
136 radeon_framebuffer_renderbuffer(GLcontext * ctx,
137 struct gl_framebuffer *fb,
138 GLenum attachment, struct gl_renderbuffer *rb)
139 {
140
141 radeonFlush(ctx);
142
143 _mesa_framebuffer_renderbuffer(ctx, fb, attachment, rb);
144 radeon_draw_buffer(ctx, fb);
145 }
146
147 static struct radeon_renderbuffer *
148 radeon_wrap_texture(GLcontext * ctx, struct gl_texture_image *texImage)
149 {
150
151 }
152 static void
153 radeon_render_texture(GLcontext * ctx,
154 struct gl_framebuffer *fb,
155 struct gl_renderbuffer_attachment *att)
156 {
157
158 }
159
160 static void
161 radeon_finish_render_texture(GLcontext * ctx,
162 struct gl_renderbuffer_attachment *att)
163 {
164
165 }
166 static void
167 radeon_validate_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb)
168 {
169 }
170
171 static void
172 radeon_blit_framebuffer(GLcontext *ctx,
173 GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
174 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
175 GLbitfield mask, GLenum filter)
176 {
177 }
178
179 void radeon_fbo_init(struct radeon_context *radeon)
180 {
181 radeon->glCtx->Driver.NewFramebuffer = radeon_new_framebuffer;
182 radeon->glCtx->Driver.NewRenderbuffer = radeon_new_renderbuffer;
183 radeon->glCtx->Driver.BindFramebuffer = radeon_bind_framebuffer;
184 radeon->glCtx->Driver.FramebufferRenderbuffer = radeon_framebuffer_renderbuffer;
185 radeon->glCtx->Driver.RenderTexture = radeon_render_texture;
186 radeon->glCtx->Driver.FinishRenderTexture = radeon_finish_render_texture;
187 radeon->glCtx->Driver.ResizeBuffers = radeon_resize_buffers;
188 radeon->glCtx->Driver.ValidateFramebuffer = radeon_validate_framebuffer;
189 radeon->glCtx->Driver.BlitFramebuffer = radeon_blit_framebuffer;
190 }
191
192
193