radeon_span.c revision 0e893b42610a2e8f2797bd7da68669dac38d9538
1/************************************************************************** 2 3Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved. 4Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and 5 VA Linux Systems Inc., Fremont, California. 6 7The Weather Channel (TM) funded Tungsten Graphics to develop the 8initial release of the Radeon 8500 driver under the XFree86 license. 9This notice must be preserved. 10 11All Rights Reserved. 12 13Permission is hereby granted, free of charge, to any person obtaining 14a copy of this software and associated documentation files (the 15"Software"), to deal in the Software without restriction, including 16without limitation the rights to use, copy, modify, merge, publish, 17distribute, sublicense, and/or sell copies of the Software, and to 18permit persons to whom the Software is furnished to do so, subject to 19the following conditions: 20 21The above copyright notice and this permission notice (including the 22next paragraph) shall be included in all copies or substantial 23portions of the Software. 24 25THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 28IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 29LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 33**************************************************************************/ 34 35/* 36 * Authors: 37 * Kevin E. Martin <martin@valinux.com> 38 * Gareth Hughes <gareth@valinux.com> 39 * Keith Whitwell <keith@tungstengraphics.com> 40 * 41 */ 42 43#include "main/glheader.h" 44#include "main/texformat.h" 45#include "main/renderbuffer.h" 46#include "swrast/swrast.h" 47#include "swrast/s_renderbuffer.h" 48 49#include "radeon_common.h" 50#include "radeon_span.h" 51 52 53static void 54radeon_renderbuffer_map(struct gl_context *ctx, struct gl_renderbuffer *rb) 55{ 56 struct radeon_renderbuffer *rrb = radeon_renderbuffer(rb); 57 GLubyte *map; 58 int stride; 59 60 if (!rb || !rrb) 61 return; 62 63 ctx->Driver.MapRenderbuffer(ctx, rb, 0, 0, rb->Width, rb->Height, 64 GL_MAP_READ_BIT | GL_MAP_WRITE_BIT, 65 &map, &stride); 66 67 rrb->base.Map = map; 68 rrb->base.RowStride = stride; 69 /* No floating point color buffers, use GLubytes */ 70 rrb->Base.ColorType = GL_UNSIGNED_BYTE; 71} 72 73static void 74radeon_renderbuffer_unmap(struct gl_context *ctx, struct gl_renderbuffer *rb) 75{ 76 struct radeon_renderbuffer *rrb = radeon_renderbuffer(rb); 77 if (!rb || !rrb) 78 return; 79 80 ctx->Driver.UnmapRenderbuffer(ctx, rb); 81 82 rrb->base.Map = NULL; 83 rrb->base.RowStride = 0; 84} 85 86static void 87radeon_map_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb) 88{ 89 GLuint i; 90 91 radeon_print(RADEON_MEMORY, RADEON_TRACE, 92 "%s( %p , fb %p )\n", 93 __func__, ctx, fb); 94 95 /* check for render to textures */ 96 for (i = 0; i < BUFFER_COUNT; i++) 97 radeon_renderbuffer_map(ctx, fb->Attachment[i].Renderbuffer); 98 99 radeon_check_front_buffer_rendering(ctx); 100} 101 102static void 103radeon_unmap_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb) 104{ 105 GLuint i; 106 107 radeon_print(RADEON_MEMORY, RADEON_TRACE, 108 "%s( %p , fb %p)\n", 109 __func__, ctx, fb); 110 111 /* check for render to textures */ 112 for (i = 0; i < BUFFER_COUNT; i++) 113 radeon_renderbuffer_unmap(ctx, fb->Attachment[i].Renderbuffer); 114 115 radeon_check_front_buffer_rendering(ctx); 116} 117 118static void radeonSpanRenderStart(struct gl_context * ctx) 119{ 120 radeonContextPtr rmesa = RADEON_CONTEXT(ctx); 121 int i; 122 123 radeon_firevertices(rmesa); 124 125 for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) { 126 if (ctx->Texture.Unit[i]._ReallyEnabled) { 127 radeon_validate_texture_miptree(ctx, ctx->Texture.Unit[i]._Current); 128 radeon_swrast_map_texture_images(ctx, ctx->Texture.Unit[i]._Current); 129 } 130 } 131 132 radeon_map_framebuffer(ctx, ctx->DrawBuffer); 133 if (ctx->ReadBuffer != ctx->DrawBuffer) 134 radeon_map_framebuffer(ctx, ctx->ReadBuffer); 135} 136 137static void radeonSpanRenderFinish(struct gl_context * ctx) 138{ 139 int i; 140 141 _swrast_flush(ctx); 142 143 for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) 144 if (ctx->Texture.Unit[i]._ReallyEnabled) 145 radeon_swrast_unmap_texture_images(ctx, ctx->Texture.Unit[i]._Current); 146 147 radeon_unmap_framebuffer(ctx, ctx->DrawBuffer); 148 if (ctx->ReadBuffer != ctx->DrawBuffer) 149 radeon_unmap_framebuffer(ctx, ctx->ReadBuffer); 150} 151 152void radeonInitSpanFuncs(struct gl_context * ctx) 153{ 154 struct swrast_device_driver *swdd = 155 _swrast_GetDeviceDriverReference(ctx); 156 swdd->SpanRenderStart = radeonSpanRenderStart; 157 swdd->SpanRenderFinish = radeonSpanRenderFinish; 158} 159 160