1848b8605Smrg/* 2848b8605Smrg * Mesa 3-D graphics library 3848b8605Smrg * 4848b8605Smrg * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. 5848b8605Smrg * 6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7848b8605Smrg * copy of this software and associated documentation files (the "Software"), 8848b8605Smrg * to deal in the Software without restriction, including without limitation 9848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the 11848b8605Smrg * Software is furnished to do so, subject to the following conditions: 12848b8605Smrg * 13848b8605Smrg * The above copyright notice and this permission notice shall be included 14848b8605Smrg * in all copies or substantial portions of the Software. 15848b8605Smrg * 16848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20848b8605Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21848b8605Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22848b8605Smrg * OTHER DEALINGS IN THE SOFTWARE. 23848b8605Smrg * 24848b8605Smrg */ 25848b8605Smrg 26848b8605Smrg/** 27848b8605Smrg * \file swrast/swrast.h 28848b8605Smrg * \brief Public interface to the software rasterization functions. 29848b8605Smrg * \author Keith Whitwell <keithw@vmware.com> 30848b8605Smrg */ 31848b8605Smrg 32848b8605Smrg#ifndef SWRAST_H 33848b8605Smrg#define SWRAST_H 34848b8605Smrg 35848b8605Smrg#include "main/mtypes.h" 36848b8605Smrg#include "swrast/s_chan.h" 37848b8605Smrg 38848b8605Smrg 39848b8605Smrg/** 40848b8605Smrg * If non-zero use GLdouble for walking triangle edges, for better accuracy. 41848b8605Smrg */ 42848b8605Smrg#define TRIANGLE_WALK_DOUBLE 0 43848b8605Smrg 44848b8605Smrg 45848b8605Smrg/** 46848b8605Smrg * Bits per depth buffer value (max is 32). 47848b8605Smrg */ 48848b8605Smrg#ifndef DEFAULT_SOFTWARE_DEPTH_BITS 49848b8605Smrg#define DEFAULT_SOFTWARE_DEPTH_BITS 16 50848b8605Smrg#endif 51848b8605Smrg/** Depth buffer data type */ 52848b8605Smrg#if DEFAULT_SOFTWARE_DEPTH_BITS <= 16 53848b8605Smrg#define DEFAULT_SOFTWARE_DEPTH_TYPE GLushort 54848b8605Smrg#else 55848b8605Smrg#define DEFAULT_SOFTWARE_DEPTH_TYPE GLuint 56848b8605Smrg#endif 57848b8605Smrg 58848b8605Smrg 59848b8605Smrg/** 60848b8605Smrg * Max image/surface/texture size. 61848b8605Smrg */ 62848b8605Smrg#define SWRAST_MAX_WIDTH 16384 63848b8605Smrg#define SWRAST_MAX_HEIGHT 16384 64848b8605Smrg 65848b8605Smrg 66848b8605Smrg/** 67848b8605Smrg * \struct SWvertex 68848b8605Smrg * \brief Data-structure to handle vertices in the software rasterizer. 69848b8605Smrg * 70848b8605Smrg * The software rasterizer now uses this format for vertices. Thus a 71848b8605Smrg * 'RasterSetup' stage or other translation is required between the 72848b8605Smrg * tnl module and the swrast rasterization functions. This serves to 73848b8605Smrg * isolate the swrast module from the internals of the tnl module, and 74848b8605Smrg * improve its usefulness as a fallback mechanism for hardware 75848b8605Smrg * drivers. 76848b8605Smrg * 77848b8605Smrg * wpos = attr[VARYING_SLOT_POS] and MUST BE THE FIRST values in the 78848b8605Smrg * vertex because of the tnl clipping code. 79848b8605Smrg 80848b8605Smrg * wpos[0] and [1] are the screen-coords of SWvertex. 81848b8605Smrg * wpos[2] is the z-buffer coord (if 16-bit Z buffer, in range [0,65535]). 82848b8605Smrg * wpos[3] is 1/w where w is the clip-space W coord. This is the value 83848b8605Smrg * that clip{XYZ} were multiplied by to get ndc{XYZ}. 84848b8605Smrg * 85848b8605Smrg * Full software drivers: 86848b8605Smrg * - Register the rastersetup and triangle functions from 87848b8605Smrg * utils/software_helper. 88848b8605Smrg * - On statechange, update the rasterization pointers in that module. 89848b8605Smrg * 90848b8605Smrg * Rasterization hardware drivers: 91848b8605Smrg * - Keep native rastersetup. 92848b8605Smrg * - Implement native twoside,offset and unfilled triangle setup. 93848b8605Smrg * - Implement a translator from native vertices to swrast vertices. 94848b8605Smrg * - On partial fallback (mix of accelerated and unaccelerated 95848b8605Smrg * prims), call a pass-through function which translates native 96848b8605Smrg * vertices to SWvertices and calls the appropriate swrast function. 97848b8605Smrg * - On total fallback (vertex format insufficient for state or all 98848b8605Smrg * primitives unaccelerated), hook in swrast_setup instead. 99848b8605Smrg */ 100848b8605Smrgtypedef struct { 101848b8605Smrg GLfloat attrib[VARYING_SLOT_MAX][4]; 102848b8605Smrg GLchan color[4]; /** integer color */ 103848b8605Smrg GLfloat pointSize; 104848b8605Smrg} SWvertex; 105848b8605Smrg 106848b8605Smrg 107848b8605Smrg#define VARYING_SLOT_CI VARYING_SLOT_COL0 108848b8605Smrg 109848b8605Smrg 110848b8605Smrgstruct swrast_device_driver; 111848b8605Smrg 112848b8605Smrg 113848b8605Smrg/* These are the public-access functions exported from swrast. 114848b8605Smrg */ 115848b8605Smrg 116848b8605Smrgextern GLboolean 117848b8605Smrg_swrast_CreateContext( struct gl_context *ctx ); 118848b8605Smrg 119848b8605Smrgextern void 120848b8605Smrg_swrast_DestroyContext( struct gl_context *ctx ); 121848b8605Smrg 122848b8605Smrg/* Get a (non-const) reference to the device driver struct for swrast. 123848b8605Smrg */ 124848b8605Smrgextern struct swrast_device_driver * 125848b8605Smrg_swrast_GetDeviceDriverReference( struct gl_context *ctx ); 126848b8605Smrg 127848b8605Smrgextern void 128848b8605Smrg_swrast_Bitmap( struct gl_context *ctx, 129848b8605Smrg GLint px, GLint py, 130848b8605Smrg GLsizei width, GLsizei height, 131848b8605Smrg const struct gl_pixelstore_attrib *unpack, 132848b8605Smrg const GLubyte *bitmap ); 133848b8605Smrg 134848b8605Smrgextern void 135b8e80941Smrg_swrast_CopyPixels(struct gl_context *ctx, 136b8e80941Smrg GLint srcx, GLint srcy, 137b8e80941Smrg GLint destx, GLint desty, 138b8e80941Smrg GLsizei width, GLsizei height, 139b8e80941Smrg GLenum type); 140848b8605Smrg 141848b8605Smrgextern GLboolean 142848b8605Smrgswrast_fast_copy_pixels(struct gl_context *ctx, 143b8e80941Smrg struct gl_framebuffer *srcFb, 144b8e80941Smrg struct gl_framebuffer *dstFb, 145b8e80941Smrg GLint srcX, GLint srcY, GLsizei width, GLsizei height, 146b8e80941Smrg GLint dstX, GLint dstY, GLenum type); 147848b8605Smrg 148848b8605Smrgextern void 149848b8605Smrg_swrast_DrawPixels( struct gl_context *ctx, 150848b8605Smrg GLint x, GLint y, 151848b8605Smrg GLsizei width, GLsizei height, 152848b8605Smrg GLenum format, GLenum type, 153848b8605Smrg const struct gl_pixelstore_attrib *unpack, 154848b8605Smrg const GLvoid *pixels ); 155848b8605Smrg 156848b8605Smrgextern void 157848b8605Smrg_swrast_BlitFramebuffer(struct gl_context *ctx, 158b8e80941Smrg struct gl_framebuffer *readFb, 159b8e80941Smrg struct gl_framebuffer *drawFb, 160848b8605Smrg GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, 161848b8605Smrg GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, 162848b8605Smrg GLbitfield mask, GLenum filter); 163848b8605Smrg 164848b8605Smrgextern void 165848b8605Smrg_swrast_Clear(struct gl_context *ctx, GLbitfield buffers); 166848b8605Smrg 167848b8605Smrg 168848b8605Smrg 169848b8605Smrg/* Reset the stipple counter 170848b8605Smrg */ 171848b8605Smrgextern void 172848b8605Smrg_swrast_ResetLineStipple( struct gl_context *ctx ); 173848b8605Smrg 174848b8605Smrg/** 175848b8605Smrg * Indicates front/back facing for subsequent points/lines when drawing 176848b8605Smrg * unfilled polygons. Needed for two-side stencil. 177848b8605Smrg */ 178848b8605Smrgextern void 179848b8605Smrg_swrast_SetFacing(struct gl_context *ctx, GLuint facing); 180848b8605Smrg 181848b8605Smrg/* These will always render the correct point/line/triangle for the 182848b8605Smrg * current state. 183848b8605Smrg * 184848b8605Smrg * For flatshaded primitives, the provoking vertex is the final one. 185848b8605Smrg */ 186848b8605Smrgextern void 187848b8605Smrg_swrast_Point( struct gl_context *ctx, const SWvertex *v ); 188848b8605Smrg 189848b8605Smrgextern void 190848b8605Smrg_swrast_Line( struct gl_context *ctx, const SWvertex *v0, const SWvertex *v1 ); 191848b8605Smrg 192848b8605Smrgextern void 193848b8605Smrg_swrast_Triangle( struct gl_context *ctx, const SWvertex *v0, 194848b8605Smrg const SWvertex *v1, const SWvertex *v2 ); 195848b8605Smrg 196848b8605Smrgextern void 197848b8605Smrg_swrast_Quad( struct gl_context *ctx, 198848b8605Smrg const SWvertex *v0, const SWvertex *v1, 199848b8605Smrg const SWvertex *v2, const SWvertex *v3); 200848b8605Smrg 201848b8605Smrgextern void 202848b8605Smrg_swrast_flush( struct gl_context *ctx ); 203848b8605Smrg 204848b8605Smrgextern void 205848b8605Smrg_swrast_render_primitive( struct gl_context *ctx, GLenum mode ); 206848b8605Smrg 207848b8605Smrgextern void 208848b8605Smrg_swrast_render_start( struct gl_context *ctx ); 209848b8605Smrg 210848b8605Smrgextern void 211848b8605Smrg_swrast_render_finish( struct gl_context *ctx ); 212848b8605Smrg 213848b8605Smrgextern struct gl_texture_image * 214848b8605Smrg_swrast_new_texture_image( struct gl_context *ctx ); 215848b8605Smrg 216848b8605Smrgextern void 217848b8605Smrg_swrast_delete_texture_image(struct gl_context *ctx, 218848b8605Smrg struct gl_texture_image *texImage); 219848b8605Smrg 220848b8605Smrgextern GLboolean 221848b8605Smrg_swrast_alloc_texture_image_buffer(struct gl_context *ctx, 222848b8605Smrg struct gl_texture_image *texImage); 223848b8605Smrg 224848b8605Smrgextern GLboolean 225848b8605Smrg_swrast_init_texture_image(struct gl_texture_image *texImage); 226848b8605Smrg 227848b8605Smrgextern void 228848b8605Smrg_swrast_free_texture_image_buffer(struct gl_context *ctx, 229848b8605Smrg struct gl_texture_image *texImage); 230848b8605Smrg 231848b8605Smrgextern void 232848b8605Smrg_swrast_map_teximage(struct gl_context *ctx, 233848b8605Smrg struct gl_texture_image *texImage, 234848b8605Smrg GLuint slice, 235848b8605Smrg GLuint x, GLuint y, GLuint w, GLuint h, 236848b8605Smrg GLbitfield mode, 237848b8605Smrg GLubyte **mapOut, 238848b8605Smrg GLint *rowStrideOut); 239848b8605Smrg 240848b8605Smrgextern void 241848b8605Smrg_swrast_unmap_teximage(struct gl_context *ctx, 242848b8605Smrg struct gl_texture_image *texImage, 243848b8605Smrg GLuint slice); 244848b8605Smrg 245848b8605Smrg/* Tell the software rasterizer about core state changes. 246848b8605Smrg */ 247848b8605Smrgextern void 248848b8605Smrg_swrast_InvalidateState( struct gl_context *ctx, GLbitfield new_state ); 249848b8605Smrg 250848b8605Smrg/* Configure software rasterizer to match hardware rasterizer characteristics: 251848b8605Smrg */ 252848b8605Smrgextern void 253848b8605Smrg_swrast_allow_vertex_fog( struct gl_context *ctx, GLboolean value ); 254848b8605Smrg 255848b8605Smrgextern void 256848b8605Smrg_swrast_allow_pixel_fog( struct gl_context *ctx, GLboolean value ); 257848b8605Smrg 258848b8605Smrg/* Debug: 259848b8605Smrg */ 260848b8605Smrgextern void 261848b8605Smrg_swrast_print_vertex( struct gl_context *ctx, const SWvertex *v ); 262848b8605Smrg 263848b8605Smrg 264848b8605Smrg 265848b8605Smrgextern void 266848b8605Smrg_swrast_eject_texture_images(struct gl_context *ctx); 267848b8605Smrg 268848b8605Smrg 269848b8605Smrgextern void 270848b8605Smrg_swrast_render_texture(struct gl_context *ctx, 271848b8605Smrg struct gl_framebuffer *fb, 272848b8605Smrg struct gl_renderbuffer_attachment *att); 273848b8605Smrg 274848b8605Smrgextern void 275848b8605Smrg_swrast_finish_render_texture(struct gl_context *ctx, 276848b8605Smrg struct gl_renderbuffer *rb); 277848b8605Smrg 278848b8605Smrg 279848b8605Smrg/** 280848b8605Smrg * The driver interface for the software rasterizer. 281848b8605Smrg * XXX this may go away. 282848b8605Smrg * We may move these functions to ctx->Driver.RenderStart, RenderEnd. 283848b8605Smrg */ 284848b8605Smrgstruct swrast_device_driver { 285848b8605Smrg /* 286848b8605Smrg * These are called before and after accessing renderbuffers during 287848b8605Smrg * software rasterization. 288848b8605Smrg * 289848b8605Smrg * These are a suitable place for grabbing/releasing hardware locks. 290848b8605Smrg * 291848b8605Smrg * NOTE: The swrast triangle/line/point routines *DO NOT* call 292848b8605Smrg * these functions. Locking in that case must be organized by the 293848b8605Smrg * driver by other mechanisms. 294848b8605Smrg */ 295848b8605Smrg void (*SpanRenderStart)(struct gl_context *ctx); 296848b8605Smrg void (*SpanRenderFinish)(struct gl_context *ctx); 297848b8605Smrg}; 298848b8605Smrg 299848b8605Smrg 300848b8605Smrg 301848b8605Smrg#endif 302