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