5 #include "renderbuffer.h"
9 * Render-to-texture code for GL_EXT_framebuffer_object
14 * Derived from gl_renderbuffer class
16 struct texture_renderbuffer
18 struct gl_renderbuffer Base
; /* Base class object */
19 struct gl_texture_image
*TexImage
;
27 texture_get_row(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
28 GLint x
, GLint y
, void *values
)
34 texture_get_values(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
35 const GLint x
[], const GLint y
[], void *values
)
41 texture_put_row(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
42 GLint x
, GLint y
, const void *values
, const GLubyte
*mask
)
44 const struct texture_renderbuffer
*trb
45 = (const struct texture_renderbuffer
*) rb
;
46 const GLint z
= trb
->Zoffset
;
47 const GLchan
*rgba
= (const GLchan
*) values
;
49 for (i
= 0; i
< count
; i
++) {
50 if (!mask
|| mask
[i
]) {
51 trb
->Store(trb
->TexImage
, x
+ i
, y
, z
, rgba
);
58 texture_put_mono_row(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
59 GLint x
, GLint y
, const void *value
, const GLubyte
*mask
)
61 const struct texture_renderbuffer
*trb
62 = (const struct texture_renderbuffer
*) rb
;
63 const GLint z
= trb
->Zoffset
;
64 const GLchan
*rgba
= (const GLchan
*) value
;
66 for (i
= 0; i
< count
; i
++) {
67 if (!mask
|| mask
[i
]) {
68 trb
->Store(trb
->TexImage
, x
+ i
, y
, z
, rgba
);
74 texture_put_values(GLcontext
*ctx
, struct gl_renderbuffer
*rb
, GLuint count
,
75 const GLint x
[], const GLint y
[], const void *values
,
78 const struct texture_renderbuffer
*trb
79 = (const struct texture_renderbuffer
*) rb
;
80 const GLint z
= trb
->Zoffset
;
81 const GLchan
*rgba
= (const GLchan
*) values
;
83 for (i
= 0; i
< count
; i
++) {
84 if (!mask
|| mask
[i
]) {
85 trb
->Store(trb
->TexImage
, x
[i
], y
[i
], z
, rgba
);
92 texture_put_mono_values(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
93 GLuint count
, const GLint x
[], const GLint y
[],
94 const void *value
, const GLubyte
*mask
)
96 const struct texture_renderbuffer
*trb
97 = (const struct texture_renderbuffer
*) rb
;
98 const GLint z
= trb
->Zoffset
;
99 const GLchan
*rgba
= (const GLchan
*) value
;
101 for (i
= 0; i
< count
; i
++) {
102 if (!mask
|| mask
[i
]) {
103 trb
->Store(trb
->TexImage
, x
[i
], y
[i
], z
, rgba
);
110 delete_texture_wrapper(struct gl_renderbuffer
*rb
)
117 * If a render buffer attachment specifies a texture image, we'll use
118 * this function to make a gl_renderbuffer wrapper around the texture image.
119 * This allows other parts of Mesa to access the texture image as if it
120 * was a renderbuffer.
123 wrap_texture(GLcontext
*ctx
, struct gl_renderbuffer_attachment
*att
)
125 struct texture_renderbuffer
*trb
;
126 const GLuint name
= 0;
128 ASSERT(att
->Type
== GL_TEXTURE
);
129 ASSERT(att
->Renderbuffer
== NULL
);
131 ASSERT(att->Complete);
134 trb
= CALLOC_STRUCT(texture_renderbuffer
);
136 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "wrap_texture");
140 _mesa_init_renderbuffer(&trb
->Base
, name
);
142 trb
->TexImage
= att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
143 assert(trb
->TexImage
);
145 trb
->Store
= trb
->TexImage
->TexFormat
->StoreTexel
;
148 trb
->Zoffset
= att
->Zoffset
;
150 trb
->Base
.Width
= trb
->TexImage
->Width
;
151 trb
->Base
.Height
= trb
->TexImage
->Height
;
152 trb
->Base
.InternalFormat
= trb
->TexImage
->IntFormat
; /* XXX fix? */
153 trb
->Base
._BaseFormat
= trb
->TexImage
->TexFormat
->BaseFormat
;
155 /* fix/avoid this assertion someday */
156 assert(trb
->Base
._BaseFormat
== GL_RGB
||
157 trb
->Base
._BaseFormat
== GL_RGBA
||
158 trb
->Base
._BaseFormat
== GL_DEPTH_COMPONENT
);
160 trb
->Base
.DataType
= GL_UNSIGNED_BYTE
; /* XXX fix! */
161 trb
->Base
.Data
= trb
->TexImage
->Data
;
163 trb
->Base
.GetRow
= texture_get_row
;
164 trb
->Base
.GetValues
= texture_get_values
;
165 trb
->Base
.PutRow
= texture_put_row
;
166 trb
->Base
.PutMonoRow
= texture_put_mono_row
;
167 trb
->Base
.PutValues
= texture_put_values
;
168 trb
->Base
.PutMonoValues
= texture_put_mono_values
;
170 trb
->Base
.Delete
= delete_texture_wrapper
;
171 trb
->Base
.AllocStorage
= NULL
; /* illegal! */
173 att
->Renderbuffer
= &(trb
->Base
);
179 * Software fallback for ctx->Driver.RenderbufferTexture.
180 * This is called via the glRenderbufferTexture1D/2D/3D() functions.
181 * If we're unbinding a texture, texObj will be NULL.
182 * The framebuffer of interest is ctx->DrawBuffer.
183 * \sa _mesa_framebuffer_renderbuffer
186 _mesa_renderbuffer_texture(GLcontext
*ctx
,
187 struct gl_renderbuffer_attachment
*att
,
188 struct gl_texture_object
*texObj
,
189 GLenum texTarget
, GLuint level
, GLuint zoffset
)
192 _mesa_set_texture_attachment(ctx
, att
, texObj
,
193 texTarget
, level
, zoffset
);
195 wrap_texture(ctx
, att
);
198 _mesa_remove_attachment(ctx
, att
);