1848b8605Smrg 2848b8605Smrg#include "main/context.h" 3848b8605Smrg#include "main/fbobject.h" 4848b8605Smrg#include "main/macros.h" 5848b8605Smrg#include "main/teximage.h" 6848b8605Smrg#include "main/renderbuffer.h" 7848b8605Smrg#include "swrast/swrast.h" 8848b8605Smrg#include "swrast/s_context.h" 9848b8605Smrg#include "swrast/s_texfetch.h" 10848b8605Smrg 11848b8605Smrg 12848b8605Smrg/* 13848b8605Smrg * Render-to-texture code for GL_EXT_framebuffer_object 14848b8605Smrg */ 15848b8605Smrg 16848b8605Smrg 17848b8605Smrgstatic void 18848b8605Smrgdelete_texture_wrapper(struct gl_context *ctx, struct gl_renderbuffer *rb) 19848b8605Smrg{ 20b8e80941Smrg assert(rb->RefCount == 0); 21848b8605Smrg free(rb); 22848b8605Smrg} 23848b8605Smrg 24848b8605Smrg/** 25848b8605Smrg * Update the renderbuffer wrapper for rendering to a texture. 26848b8605Smrg * For example, update the width, height of the RB based on the texture size, 27848b8605Smrg * update the internal format info, etc. 28848b8605Smrg */ 29848b8605Smrgstatic void 30848b8605Smrgupdate_wrapper(struct gl_context *ctx, struct gl_renderbuffer_attachment *att) 31848b8605Smrg{ 32848b8605Smrg struct gl_renderbuffer *rb = att->Renderbuffer; 33848b8605Smrg struct swrast_renderbuffer *srb = swrast_renderbuffer(rb); 34848b8605Smrg struct swrast_texture_image *swImage; 35848b8605Smrg mesa_format format; 36848b8605Smrg GLuint zOffset; 37848b8605Smrg 38848b8605Smrg (void) ctx; 39848b8605Smrg 40848b8605Smrg swImage = swrast_texture_image(rb->TexImage); 41848b8605Smrg assert(swImage); 42848b8605Smrg 43848b8605Smrg format = swImage->Base.TexFormat; 44848b8605Smrg 45848b8605Smrg if (att->Texture->Target == GL_TEXTURE_1D_ARRAY_EXT) { 46848b8605Smrg zOffset = 0; 47848b8605Smrg } 48848b8605Smrg else { 49848b8605Smrg zOffset = att->Zoffset; 50848b8605Smrg } 51848b8605Smrg 52848b8605Smrg /* Want to store linear values, not sRGB */ 53848b8605Smrg rb->Format = _mesa_get_srgb_format_linear(format); 54848b8605Smrg 55848b8605Smrg srb->Buffer = swImage->ImageSlices[zOffset]; 56848b8605Smrg} 57848b8605Smrg 58848b8605Smrg 59848b8605Smrg 60848b8605Smrg/** 61848b8605Smrg * Called when rendering to a texture image begins, or when changing 62848b8605Smrg * the dest mipmap level, cube face, etc. 63848b8605Smrg * This is a fallback routine for software render-to-texture. 64848b8605Smrg * 65848b8605Smrg * Called via the glRenderbufferTexture1D/2D/3D() functions 66848b8605Smrg * and elsewhere (such as glTexImage2D). 67848b8605Smrg * 68848b8605Smrg * The image we're rendering into is 69848b8605Smrg * att->Texture->Image[att->CubeMapFace][att->TextureLevel]; 70848b8605Smrg * It'll never be NULL. 71848b8605Smrg * 72848b8605Smrg * \param fb the framebuffer object the texture is being bound to 73848b8605Smrg * \param att the fb attachment point of the texture 74848b8605Smrg * 75b8e80941Smrg * \sa _mesa_FramebufferRenderbuffer_sw 76848b8605Smrg */ 77848b8605Smrgvoid 78848b8605Smrg_swrast_render_texture(struct gl_context *ctx, 79848b8605Smrg struct gl_framebuffer *fb, 80848b8605Smrg struct gl_renderbuffer_attachment *att) 81848b8605Smrg{ 82848b8605Smrg struct gl_renderbuffer *rb = att->Renderbuffer; 83848b8605Smrg (void) fb; 84848b8605Smrg 85848b8605Smrg /* plug in our texture_renderbuffer-specific functions */ 86848b8605Smrg rb->Delete = delete_texture_wrapper; 87848b8605Smrg 88848b8605Smrg update_wrapper(ctx, att); 89848b8605Smrg} 90848b8605Smrg 91848b8605Smrg 92848b8605Smrgvoid 93848b8605Smrg_swrast_finish_render_texture(struct gl_context *ctx, 94848b8605Smrg struct gl_renderbuffer *rb) 95848b8605Smrg{ 96848b8605Smrg /* do nothing */ 97848b8605Smrg /* The renderbuffer texture wrapper will get deleted by the 98848b8605Smrg * normal mechanism for deleting renderbuffers. 99848b8605Smrg */ 100848b8605Smrg (void) ctx; 101848b8605Smrg (void) rb; 102848b8605Smrg} 103