mesa/formats: add new mesa formats and their pack/unpack functions.
[mesa.git] / src / mesa / swrast / s_texrender.c
1
2 #include "main/context.h"
3 #include "main/colormac.h"
4 #include "main/fbobject.h"
5 #include "main/macros.h"
6 #include "main/teximage.h"
7 #include "main/renderbuffer.h"
8 #include "swrast/swrast.h"
9 #include "swrast/s_context.h"
10 #include "swrast/s_texfetch.h"
11
12
13 /*
14 * Render-to-texture code for GL_EXT_framebuffer_object
15 */
16
17
18 static void
19 delete_texture_wrapper(struct gl_context *ctx, struct gl_renderbuffer *rb)
20 {
21 ASSERT(rb->RefCount == 0);
22 free(rb);
23 }
24
25 /**
26 * Update the renderbuffer wrapper for rendering to a texture.
27 * For example, update the width, height of the RB based on the texture size,
28 * update the internal format info, etc.
29 */
30 static void
31 update_wrapper(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
32 {
33 struct gl_renderbuffer *rb = att->Renderbuffer;
34 struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
35 struct swrast_texture_image *swImage;
36 mesa_format format;
37 GLuint zOffset;
38
39 (void) ctx;
40
41 swImage = swrast_texture_image(rb->TexImage);
42 assert(swImage);
43
44 format = swImage->Base.TexFormat;
45
46 if (att->Texture->Target == GL_TEXTURE_1D_ARRAY_EXT) {
47 zOffset = 0;
48 }
49 else {
50 zOffset = att->Zoffset;
51 }
52
53 /* Want to store linear values, not sRGB */
54 rb->Format = _mesa_get_srgb_format_linear(format);
55
56 srb->Buffer = swImage->ImageSlices[zOffset];
57 }
58
59
60
61 /**
62 * Called when rendering to a texture image begins, or when changing
63 * the dest mipmap level, cube face, etc.
64 * This is a fallback routine for software render-to-texture.
65 *
66 * Called via the glRenderbufferTexture1D/2D/3D() functions
67 * and elsewhere (such as glTexImage2D).
68 *
69 * The image we're rendering into is
70 * att->Texture->Image[att->CubeMapFace][att->TextureLevel];
71 * It'll never be NULL.
72 *
73 * \param fb the framebuffer object the texture is being bound to
74 * \param att the fb attachment point of the texture
75 *
76 * \sa _mesa_framebuffer_renderbuffer
77 */
78 void
79 _swrast_render_texture(struct gl_context *ctx,
80 struct gl_framebuffer *fb,
81 struct gl_renderbuffer_attachment *att)
82 {
83 struct gl_renderbuffer *rb = att->Renderbuffer;
84 (void) fb;
85
86 /* plug in our texture_renderbuffer-specific functions */
87 rb->Delete = delete_texture_wrapper;
88
89 update_wrapper(ctx, att);
90 }
91
92
93 void
94 _swrast_finish_render_texture(struct gl_context *ctx,
95 struct gl_renderbuffer *rb)
96 {
97 /* do nothing */
98 /* The renderbuffer texture wrapper will get deleted by the
99 * normal mechanism for deleting renderbuffers.
100 */
101 (void) ctx;
102 (void) rb;
103 }