Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 1 | /*
|
| 2 | * Mesa 3-D graphics library
|
| 3 | * Version: 4.0
|
| 4 | *
|
| 5 | * Copyright (C) 1999 Brian Paul All Rights Reserved.
|
| 6 | *
|
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a
|
| 8 | * copy of this software and associated documentation files (the "Software"),
|
| 9 | * to deal in the Software without restriction, including without limitation
|
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
| 11 | * and/or sell copies of the Software, and to permit persons to whom the
|
| 12 | * Software is furnished to do so, subject to the following conditions:
|
| 13 | *
|
| 14 | * The above copyright notice and this permission notice shall be included
|
| 15 | * in all copies or substantial portions of the Software.
|
| 16 | *
|
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
| 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
| 20 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
| 21 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 23 | */
|
| 24 |
|
| 25 | /*
|
Brian Paul | 6c921af | 2002-04-01 17:01:33 +0000 | [diff] [blame] | 26 | * DOS/DJGPP device driver v1.0 for Mesa 4.0
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 27 | *
|
| 28 | * Copyright (C) 2002 - Borca Daniel
|
| 29 | * Email : dborca@yahoo.com
|
| 30 | * Web : http://www.geocities.com/dborca
|
| 31 | */
|
| 32 |
|
| 33 |
|
| 34 | #ifdef PC_HEADER
|
| 35 | #include "all.h"
|
| 36 | #else
|
| 37 | #include "glheader.h"
|
| 38 | #include "context.h"
|
| 39 | #include "GL/dmesa.h"
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 40 | #include "extensions.h"
|
Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 41 | #inlcude "imports.h"
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 42 | #include "macros.h"
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 43 | #include "matrix.h"
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 44 | #include "mmath.h"
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 45 | #include "texformat.h"
|
| 46 | #include "texstore.h"
|
| 47 | #include "array_cache/acache.h"
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 48 | #include "swrast/s_context.h"
|
| 49 | #include "swrast/s_depth.h"
|
| 50 | #include "swrast/s_lines.h"
|
| 51 | #include "swrast/s_triangle.h"
|
| 52 | #include "swrast/s_trispan.h"
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 53 | #include "swrast/swrast.h"
|
| 54 | #include "swrast_setup/swrast_setup.h"
|
| 55 | #include "tnl/tnl.h"
|
| 56 | #include "tnl/t_context.h"
|
| 57 | #include "tnl/t_pipeline.h"
|
| 58 | #endif
|
| 59 |
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 60 | #include "video.h"
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 61 |
|
| 62 |
|
| 63 |
|
| 64 | /*
|
| 65 | * In C++ terms, this class derives from the GLvisual class.
|
| 66 | * Add system-specific fields to it.
|
| 67 | */
|
| 68 | struct dmesa_visual {
|
| 69 | GLvisual *gl_visual;
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 70 | GLboolean db_flag; /* double buffered? */
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 71 | GLboolean rgb_flag; /* RGB mode? */
|
| 72 | GLuint depth; /* bits per pixel (1, 8, 24, etc) */
|
| 73 | };
|
| 74 |
|
| 75 | /*
|
| 76 | * In C++ terms, this class derives from the GLframebuffer class.
|
| 77 | * Add system-specific fields to it.
|
| 78 | */
|
| 79 | struct dmesa_buffer {
|
Brian Paul | 6c921af | 2002-04-01 17:01:33 +0000 | [diff] [blame] | 80 | GLframebuffer gl_buffer; /* The depth, stencil, accum, etc buffers */
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 81 | void *the_window; /* your window handle, etc */
|
| 82 |
|
Brian Paul | 6c921af | 2002-04-01 17:01:33 +0000 | [diff] [blame] | 83 | int bypp; /* bytes per pixel */
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 84 | int xpos, ypos; /* position */
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 85 | int width, height; /* size in pixels */
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 86 | int bwidth, len; /* bytes in a line, then total */
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 87 | };
|
| 88 |
|
| 89 | /*
|
| 90 | * In C++ terms, this class derives from the GLcontext class.
|
| 91 | * Add system-specific fields to it.
|
| 92 | */
|
| 93 | struct dmesa_context {
|
| 94 | GLcontext *gl_ctx; /* the core library context */
|
| 95 | DMesaVisual visual;
|
| 96 | DMesaBuffer Buffer;
|
| 97 | GLuint ClearColor;
|
| 98 | /* etc... */
|
| 99 | };
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 | static void dmesa_update_state (GLcontext *ctx, GLuint new_state);
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 | /**********************************************************************/
|
| 108 | /***** Read/Write pixels *****/
|
| 109 | /**********************************************************************/
|
| 110 |
|
| 111 |
|
| 112 |
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 113 | #define FLIP(y) (c->Buffer->height - (y) - 1)
|
| 114 | #define FLIP2(y) (h - (y) - 1)
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 115 |
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 116 |
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 117 |
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 118 | static void write_rgba_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,
|
| 119 | const GLubyte rgba[][4], const GLubyte mask[])
|
| 120 | {
|
| 121 | DMesaContext c = (DMesaContext)ctx->DriverCtx;
|
| 122 | void *b = c->Buffer->the_window;
|
| 123 | GLuint i, offset;
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 124 |
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 125 | offset = c->Buffer->width * FLIP(y) + x;
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 126 | if (mask) {
|
| 127 | /* draw some pixels */
|
| 128 | for (i=0; i<n; i++, offset++) {
|
| 129 | if (mask[i]) {
|
| 130 | vl_putpixel(b, offset, vl_mixrgba(rgba[i]));
|
| 131 | }
|
| 132 | }
|
| 133 | } else {
|
| 134 | /* draw all pixels */
|
| 135 | for (i=0; i<n; i++, offset++) {
|
| 136 | vl_putpixel(b, offset, vl_mixrgba(rgba[i]));
|
| 137 | }
|
| 138 | }
|
| 139 | }
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 140 |
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 141 | static void write_rgb_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,
|
| 142 | const GLubyte rgb[][3], const GLubyte mask[])
|
| 143 | {
|
| 144 | DMesaContext c = (DMesaContext)ctx->DriverCtx;
|
| 145 | void *b = c->Buffer->the_window;
|
| 146 | GLuint i, offset;
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 147 |
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 148 | offset = c->Buffer->width * FLIP(y) + x;
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 149 | if (mask) {
|
| 150 | /* draw some pixels */
|
| 151 | for (i=0; i<n; i++, offset++) {
|
| 152 | if (mask[i]) {
|
| 153 | vl_putpixel(b, offset, vl_mixrgb(rgb[i]));
|
| 154 | }
|
| 155 | }
|
| 156 | } else {
|
| 157 | /* draw all pixels */
|
| 158 | for (i=0; i<n; i++, offset++) {
|
| 159 | vl_putpixel(b, offset, vl_mixrgb(rgb[i]));
|
| 160 | }
|
| 161 | }
|
| 162 | }
|
| 163 |
|
| 164 | static void write_mono_rgba_span (const GLcontext *ctx,
|
| 165 | GLuint n, GLint x, GLint y,
|
| 166 | const GLchan color[4], const GLubyte mask[])
|
| 167 | {
|
| 168 | DMesaContext c = (DMesaContext)ctx->DriverCtx;
|
| 169 | void *b = c->Buffer->the_window;
|
| 170 | GLuint i, offset, rgba = vl_mixrgba(color);
|
| 171 |
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 172 | offset = c->Buffer->width * FLIP(y) + x;
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 173 | if (mask) {
|
| 174 | /* draw some pixels */
|
| 175 | for (i=0; i<n; i++, offset++) {
|
| 176 | if (mask[i]) {
|
| 177 | vl_putpixel(b, offset, rgba);
|
| 178 | }
|
| 179 | }
|
| 180 | } else {
|
| 181 | /* draw all pixels */
|
| 182 | for (i=0; i<n; i++, offset++) {
|
| 183 | vl_putpixel(b, offset, rgba);
|
| 184 | }
|
| 185 | }
|
| 186 | }
|
| 187 |
|
| 188 | static void read_rgba_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,
|
| 189 | GLubyte rgba[][4])
|
| 190 | {
|
| 191 | DMesaContext c = (DMesaContext)ctx->DriverCtx;
|
| 192 | void *b = c->Buffer->the_window;
|
| 193 | GLuint i, offset;
|
| 194 |
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 195 | offset = c->Buffer->width * FLIP(y) + x;
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 196 | /* read all pixels */
|
| 197 | for (i=0; i<n; i++, offset++) {
|
| 198 | vl_getrgba(b, offset, rgba[i]);
|
| 199 | }
|
| 200 | }
|
| 201 |
|
| 202 | static void write_rgba_pixels (const GLcontext *ctx,
|
| 203 | GLuint n, const GLint x[], const GLint y[],
|
| 204 | const GLubyte rgba[][4], const GLubyte mask[])
|
| 205 | {
|
| 206 | DMesaContext c = (DMesaContext)ctx->DriverCtx;
|
| 207 | void *b = c->Buffer->the_window;
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 208 | GLuint i, w = c->Buffer->width, h = c->Buffer->height;
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 209 |
|
| 210 | if (mask) {
|
| 211 | /* draw some pixels */
|
| 212 | for (i=0; i<n; i++) {
|
| 213 | if (mask[i]) {
|
| 214 | vl_putpixel(b, FLIP2(y[i])*w + x[i], vl_mixrgba(rgba[i]));
|
| 215 | }
|
| 216 | }
|
| 217 | } else {
|
| 218 | /* draw all pixels */
|
| 219 | for (i=0; i<n; i++) {
|
| 220 | vl_putpixel(b, FLIP2(y[i])*w + x[i], vl_mixrgba(rgba[i]));
|
| 221 | }
|
| 222 | }
|
| 223 | }
|
| 224 |
|
| 225 | static void write_mono_rgba_pixels (const GLcontext *ctx,
|
| 226 | GLuint n, const GLint x[], const GLint y[],
|
| 227 | const GLchan color[4], const GLubyte mask[])
|
| 228 | {
|
| 229 | DMesaContext c = (DMesaContext)ctx->DriverCtx;
|
| 230 | void *b = c->Buffer->the_window;
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 231 | GLuint i, w = c->Buffer->width, h = c->Buffer->height, rgba = vl_mixrgba(color);
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 232 |
|
| 233 | if (mask) {
|
| 234 | /* draw some pixels */
|
| 235 | for (i=0; i<n; i++) {
|
| 236 | if (mask[i]) {
|
| 237 | vl_putpixel(b, FLIP2(y[i])*w + x[i], rgba);
|
| 238 | }
|
| 239 | }
|
| 240 | } else {
|
| 241 | /* draw all pixels */
|
| 242 | for (i=0; i<n; i++) {
|
| 243 | vl_putpixel(b, FLIP2(y[i])*w + x[i], rgba);
|
| 244 | }
|
| 245 | }
|
| 246 | }
|
| 247 |
|
| 248 | static void read_rgba_pixels (const GLcontext *ctx,
|
| 249 | GLuint n, const GLint x[], const GLint y[],
|
| 250 | GLubyte rgba[][4], const GLubyte mask[])
|
| 251 | {
|
| 252 | DMesaContext c = (DMesaContext)ctx->DriverCtx;
|
| 253 | void *b = c->Buffer->the_window;
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 254 | GLuint i, w = c->Buffer->width, h = c->Buffer->height;
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 255 |
|
| 256 | if (mask) {
|
| 257 | /* read some pixels */
|
| 258 | for (i=0; i<n; i++) {
|
| 259 | if (mask[i]) {
|
| 260 | vl_getrgba(b, FLIP2(y[i])*w + x[i], rgba[i]);
|
| 261 | }
|
| 262 | }
|
| 263 | } else {
|
| 264 | /* read all pixels */
|
| 265 | for (i=0; i<n; i++) {
|
| 266 | vl_getrgba(b, FLIP2(y[i])*w + x[i], rgba[i]);
|
| 267 | }
|
| 268 | }
|
| 269 | }
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 | /**********************************************************************/
|
| 274 | /***** Optimized triangle rendering *****/
|
| 275 | /**********************************************************************/
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 | /*
|
| 280 | * flat, NON-depth-buffered, triangle.
|
| 281 | */
|
| 282 | static void tri_rgb_flat (GLcontext *ctx,
|
| 283 | const SWvertex *v0,
|
| 284 | const SWvertex *v1,
|
| 285 | const SWvertex *v2)
|
| 286 | {
|
| 287 | DMesaContext c = (DMesaContext)ctx->DriverCtx;
|
| 288 | void *b = c->Buffer->the_window;
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 289 | GLuint w = c->Buffer->width, h = c->Buffer->height;
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 290 |
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 291 | #define SETUP_CODE GLuint rgb = vl_mixrgb(v2->color);
|
| 292 |
|
| 293 | #define RENDER_SPAN(span) \
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 294 | GLuint i, offset = FLIP2(span.y)*w + span.x; \
|
| 295 | for (i = 0; i < span.count; i++, offset++) { \
|
| 296 | vl_putpixel(b, offset, rgb); \
|
| 297 | }
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 298 |
|
| 299 | #include "swrast/s_tritemp.h"
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 300 | }
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 | /*
|
| 305 | * flat, depth-buffered, triangle.
|
| 306 | */
|
| 307 | static void tri_rgb_flat_z (GLcontext *ctx,
|
| 308 | const SWvertex *v0,
|
| 309 | const SWvertex *v1,
|
| 310 | const SWvertex *v2)
|
| 311 | {
|
| 312 | DMesaContext c = (DMesaContext)ctx->DriverCtx;
|
| 313 | void *b = c->Buffer->the_window;
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 314 | GLuint w = c->Buffer->width, h = c->Buffer->height;
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 315 |
|
| 316 | #define INTERP_Z 1
|
| 317 | #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
|
| 318 | #define SETUP_CODE GLuint rgb = vl_mixrgb(v2->color);
|
| 319 |
|
| 320 | #define RENDER_SPAN(span) \
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 321 | GLuint i, offset = FLIP2(span.y)*w + span.x; \
|
| 322 | for (i = 0; i < span.count; i++, offset++) { \
|
| 323 | const DEPTH_TYPE z = FixedToDepth(span.z); \
|
| 324 | if (z < zRow[i]) { \
|
| 325 | vl_putpixel(b, offset, rgb); \
|
| 326 | zRow[i] = z; \
|
| 327 | } \
|
| 328 | span.z += span.zStep; \
|
| 329 | }
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 330 |
|
| 331 | #include "swrast/s_tritemp.h"
|
| 332 | }
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 | /*
|
| 337 | * smooth, NON-depth-buffered, triangle.
|
| 338 | */
|
| 339 | static void tri_rgb_smooth (GLcontext *ctx,
|
| 340 | const SWvertex *v0,
|
| 341 | const SWvertex *v1,
|
| 342 | const SWvertex *v2)
|
| 343 | {
|
| 344 | DMesaContext c = (DMesaContext)ctx->DriverCtx;
|
| 345 | void *b = c->Buffer->the_window;
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 346 | GLuint w = c->Buffer->width, h = c->Buffer->height;
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 347 |
|
| 348 | #define INTERP_RGB 1
|
| 349 | #define RENDER_SPAN(span) \
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 350 | GLuint i, offset = FLIP2(span.y)*w + span.x; \
|
| 351 | for (i = 0; i < span.count; i++, offset++) { \
|
| 352 | unsigned char rgb[3]; \
|
| 353 | rgb[0] = FixedToInt(span.red); \
|
| 354 | rgb[1] = FixedToInt(span.green); \
|
| 355 | rgb[2] = FixedToInt(span.blue); \
|
| 356 | vl_putpixel(b, offset, vl_mixrgb(rgb)); \
|
| 357 | span.red += span.redStep; \
|
| 358 | span.green += span.greenStep; \
|
| 359 | span.blue += span.blueStep; \
|
| 360 | }
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 361 |
|
| 362 | #include "swrast/s_tritemp.h"
|
| 363 | }
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 | /*
|
| 368 | * smooth, depth-buffered, triangle.
|
| 369 | */
|
| 370 | static void tri_rgb_smooth_z (GLcontext *ctx,
|
| 371 | const SWvertex *v0,
|
| 372 | const SWvertex *v1,
|
| 373 | const SWvertex *v2)
|
| 374 | {
|
| 375 | DMesaContext c = (DMesaContext)ctx->DriverCtx;
|
| 376 | void *b = c->Buffer->the_window;
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 377 | GLuint w = c->Buffer->width, h = c->Buffer->height;
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 378 |
|
| 379 | #define INTERP_Z 1
|
| 380 | #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
|
| 381 | #define INTERP_RGB 1
|
| 382 |
|
| 383 | #define RENDER_SPAN(span) \
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 384 | GLuint i, offset = FLIP2(span.y)*w + span.x; \
|
| 385 | for (i = 0; i < span.count; i++, offset++) { \
|
| 386 | const DEPTH_TYPE z = FixedToDepth(span.z); \
|
| 387 | if (z < zRow[i]) { \
|
| 388 | unsigned char rgb[3]; \
|
| 389 | rgb[0] = FixedToInt(span.red); \
|
| 390 | rgb[1] = FixedToInt(span.green); \
|
| 391 | rgb[2] = FixedToInt(span.blue); \
|
| 392 | vl_putpixel(b, offset, vl_mixrgb(rgb)); \
|
| 393 | zRow[i] = z; \
|
| 394 | } \
|
| 395 | span.red += span.redStep; \
|
| 396 | span.green += span.greenStep; \
|
| 397 | span.blue += span.blueStep; \
|
| 398 | span.z += span.zStep; \
|
| 399 | }
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 400 |
|
| 401 | #include "swrast/s_tritemp.h"
|
| 402 | }
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 | /*
|
| 407 | * Analyze context state to see if we can provide a fast triangle function
|
| 408 | * Otherwise, return NULL.
|
| 409 | */
|
| 410 | static swrast_tri_func dmesa_choose_tri_function (GLcontext *ctx)
|
| 411 | {
|
| 412 | const SWcontext *swrast = SWRAST_CONTEXT(ctx);
|
| 413 |
|
| 414 | if (ctx->RenderMode != GL_RENDER) return (swrast_tri_func) NULL;
|
| 415 | if (ctx->Polygon.SmoothFlag) return (swrast_tri_func) NULL;
|
| 416 | if (ctx->Texture._ReallyEnabled) return (swrast_tri_func) NULL;
|
| 417 |
|
| 418 | if (ctx->Light.ShadeModel==GL_SMOOTH
|
| 419 | && swrast->_RasterMask==DEPTH_BIT
|
| 420 | && ctx->Depth.Func==GL_LESS
|
| 421 | && ctx->Depth.Mask==GL_TRUE
|
| 422 | && ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS
|
| 423 | && ctx->Polygon.StippleFlag==GL_FALSE) {
|
| 424 | return tri_rgb_smooth_z;
|
| 425 | }
|
| 426 | if (ctx->Light.ShadeModel==GL_FLAT
|
| 427 | && swrast->_RasterMask==DEPTH_BIT
|
| 428 | && ctx->Depth.Func==GL_LESS
|
| 429 | && ctx->Depth.Mask==GL_TRUE
|
| 430 | && ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS
|
| 431 | && ctx->Polygon.StippleFlag==GL_FALSE) {
|
| 432 | return tri_rgb_flat_z;
|
| 433 | }
|
| 434 | if (swrast->_RasterMask==0 /* no depth test */
|
| 435 | && ctx->Light.ShadeModel==GL_SMOOTH
|
| 436 | && ctx->Polygon.StippleFlag==GL_FALSE) {
|
| 437 | return tri_rgb_smooth;
|
| 438 | }
|
| 439 | if (swrast->_RasterMask==0 /* no depth test */
|
| 440 | && ctx->Light.ShadeModel==GL_FLAT
|
| 441 | && ctx->Polygon.StippleFlag==GL_FALSE) {
|
| 442 | return tri_rgb_flat;
|
| 443 | }
|
| 444 |
|
| 445 | return (swrast_tri_func)NULL;
|
| 446 | }
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 | /* Override for the swrast triangle-selection function. Try to use one
|
| 451 | * of our internal line functions, otherwise fall back to the
|
| 452 | * standard swrast functions.
|
| 453 | */
|
| 454 | static void dmesa_choose_tri (GLcontext *ctx)
|
| 455 | {
|
| 456 | SWcontext *swrast = SWRAST_CONTEXT(ctx);
|
| 457 |
|
| 458 | if (!(swrast->Triangle=dmesa_choose_tri_function(ctx)))
|
| 459 | _swrast_choose_triangle(ctx);
|
| 460 | }
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 461 |
|
| 462 |
|
| 463 |
|
| 464 | /**********************************************************************/
|
| 465 | /***** Miscellaneous device driver funcs *****/
|
| 466 | /**********************************************************************/
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 | static void clear_color (GLcontext *ctx, const GLchan color[4])
|
| 471 | {
|
| 472 | DMesaContext c = (DMesaContext)ctx->DriverCtx;
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 473 | c->ClearColor = vl_mixrgba(color);
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 474 | }
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 | static void clear (GLcontext *ctx, GLbitfield mask, GLboolean all,
|
| 479 | GLint x, GLint y, GLint width, GLint height)
|
| 480 | {
|
| 481 | DMesaContext c = (DMesaContext)ctx->DriverCtx;
|
| 482 | const GLuint *colorMask = (GLuint *)&ctx->Color.ColorMask;
|
| 483 | DMesaBuffer b = c->Buffer;
|
| 484 |
|
| 485 | /*
|
| 486 | * Clear the specified region of the buffers indicated by 'mask'
|
| 487 | * using the clear color or index as specified by one of the two
|
| 488 | * functions above.
|
| 489 | * If all==GL_TRUE, clear whole buffer, else just clear region defined
|
| 490 | * by x,y,width,height
|
| 491 | */
|
| 492 |
|
| 493 | /* we can't handle color or index masking */
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 494 | if (*colorMask==0xffffffff) {
|
| 495 | if (mask & DD_BACK_LEFT_BIT) {
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 496 | if (all) {
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 497 | vl_clear(b->the_window, b->len, c->ClearColor);
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 498 | } else {
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 499 | vl_rect(b->the_window, x, y, width, height, c->ClearColor);
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 500 | }
|
| 501 | mask &= ~DD_BACK_LEFT_BIT;
|
| 502 | }
|
| 503 | }
|
| 504 |
|
| 505 | if (mask) {
|
| 506 | _swrast_Clear(ctx, mask, all, x, y, width, height);
|
| 507 | }
|
| 508 | }
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 | /*
|
| 513 | * Set the current reading buffer.
|
| 514 | */
|
| 515 | static void set_read_buffer (GLcontext *ctx, GLframebuffer *buffer,
|
| 516 | GLenum mode)
|
| 517 | {
|
| 518 | /*
|
| 519 | DMesaContext c = (DMesaContext)ctx->DriverCtx;
|
| 520 | dmesa_update_state(ctx);
|
| 521 | */
|
| 522 | }
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 | /*
|
| 527 | * Set the destination/draw buffer.
|
| 528 | */
|
Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame^] | 529 | static void set_draw_buffer (GLcontext *ctx, GLenum mode)
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 530 | {
|
Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame^] | 531 | /*
|
| 532 | XXX this has to be fixed
|
| 533 | */
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 534 | }
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 | /*
|
| 539 | * Return the width and height of the current buffer.
|
| 540 | * If anything special has to been done when the buffer/window is
|
| 541 | * resized, do it now.
|
| 542 | */
|
Brian Paul | 6c921af | 2002-04-01 17:01:33 +0000 | [diff] [blame] | 543 | static void get_buffer_size (GLframebuffer *buffer, GLuint *width, GLuint *height)
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 544 | {
|
Brian Paul | 6c921af | 2002-04-01 17:01:33 +0000 | [diff] [blame] | 545 | DMesaBuffer b = (DMesaBuffer)buffer;
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 546 |
|
Brian Paul | 6c921af | 2002-04-01 17:01:33 +0000 | [diff] [blame] | 547 | *width = b->width;
|
| 548 | *height = b->height;
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 549 | }
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 | static const GLubyte* get_string (GLcontext *ctx, GLenum name)
|
| 554 | {
|
| 555 | switch (name) {
|
| 556 | case GL_RENDERER:
|
Brian Paul | 6c921af | 2002-04-01 17:01:33 +0000 | [diff] [blame] | 557 | return (const GLubyte *)"Mesa DOS\0DJGPP port (c) Borca Daniel 31-mar-2002";
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 558 | default:
|
| 559 | return NULL;
|
| 560 | }
|
| 561 | }
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 | /**********************************************************************/
|
| 566 | /***** Miscellaneous device driver funcs *****/
|
| 567 | /***** Note that these functions are mandatory *****/
|
| 568 | /**********************************************************************/
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 | /* OPTIONAL FUNCTION: implements glFinish if possible */
|
| 573 | static void finish (GLcontext *ctx)
|
| 574 | {
|
| 575 | /*
|
| 576 | DMesaContext c = (DMesaContext)ctx->DriverCtx;
|
| 577 | */
|
| 578 | }
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 | /* OPTIONAL FUNCTION: implements glFlush if possible */
|
| 583 | static void flush (GLcontext *ctx)
|
| 584 | {
|
| 585 | /*
|
| 586 | DMesaContext c = (DMesaContext)ctx->DriverCtx;
|
| 587 | */
|
| 588 | }
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 | /**********************************************************************/
|
| 593 | /**********************************************************************/
|
| 594 |
|
| 595 |
|
| 596 |
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 597 | #define DMESA_NEW_TRIANGLE (_NEW_POLYGON | \
|
| 598 | _NEW_TEXTURE | \
|
| 599 | _NEW_LIGHT | \
|
| 600 | _NEW_DEPTH | \
|
| 601 | _NEW_RENDERMODE | \
|
| 602 | _SWRAST_NEW_RASTERMASK)
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 | /* Extend the software rasterizer with our line and triangle
|
| 607 | * functions.
|
| 608 | */
|
| 609 | static void dmesa_register_swrast_functions (GLcontext *ctx)
|
| 610 | {
|
| 611 | SWcontext *swrast = SWRAST_CONTEXT(ctx);
|
| 612 |
|
| 613 | swrast->choose_triangle = dmesa_choose_tri;
|
| 614 |
|
| 615 | swrast->invalidate_triangle |= DMESA_NEW_TRIANGLE;
|
| 616 | }
|
| 617 |
|
| 618 |
|
| 619 |
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 620 | /* Setup pointers and other driver state that is constant for the life
|
| 621 | * of a context.
|
| 622 | */
|
| 623 | void dmesa_init_pointers (GLcontext *ctx)
|
| 624 | {
|
| 625 | TNLcontext *tnl;
|
| 626 |
|
| 627 | ctx->Driver.UpdateState = dmesa_update_state;
|
| 628 |
|
| 629 | ctx->Driver.GetString = get_string;
|
| 630 | ctx->Driver.GetBufferSize = get_buffer_size;
|
| 631 | ctx->Driver.Flush = flush;
|
| 632 | ctx->Driver.Finish = finish;
|
| 633 |
|
| 634 | /* Software rasterizer pixel paths:
|
| 635 | */
|
| 636 | ctx->Driver.Accum = _swrast_Accum;
|
| 637 | ctx->Driver.Bitmap = _swrast_Bitmap;
|
| 638 | ctx->Driver.Clear = clear;
|
Brian Paul | 6c921af | 2002-04-01 17:01:33 +0000 | [diff] [blame] | 639 | ctx->Driver.ResizeBuffers = _swrast_alloc_buffers;
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 640 | ctx->Driver.CopyPixels = _swrast_CopyPixels;
|
| 641 | ctx->Driver.DrawPixels = _swrast_DrawPixels;
|
| 642 | ctx->Driver.ReadPixels = _swrast_ReadPixels;
|
| 643 |
|
| 644 | /* Software texture functions:
|
| 645 | */
|
| 646 | ctx->Driver.ChooseTextureFormat = _mesa_choose_tex_format;
|
| 647 | ctx->Driver.TexImage1D = _mesa_store_teximage1d;
|
| 648 | ctx->Driver.TexImage2D = _mesa_store_teximage2d;
|
| 649 | ctx->Driver.TexImage3D = _mesa_store_teximage3d;
|
| 650 | ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d;
|
| 651 | ctx->Driver.TexSubImage2D = _mesa_store_texsubimage2d;
|
| 652 | ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d;
|
| 653 | ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage;
|
| 654 |
|
| 655 | ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d;
|
| 656 | ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d;
|
| 657 | ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d;
|
| 658 | ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d;
|
| 659 | ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d;
|
| 660 |
|
| 661 | ctx->Driver.BaseCompressedTexFormat = _mesa_base_compressed_texformat;
|
| 662 | ctx->Driver.CompressedTextureSize = _mesa_compressed_texture_size;
|
| 663 | ctx->Driver.GetCompressedTexImage = _mesa_get_compressed_teximage;
|
| 664 |
|
| 665 | /* Swrast hooks for imaging extensions:
|
| 666 | */
|
| 667 | ctx->Driver.CopyColorTable = _swrast_CopyColorTable;
|
| 668 | ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable;
|
| 669 | ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
|
| 670 | ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
|
| 671 |
|
| 672 | /* Statechange callbacks:
|
| 673 | */
|
| 674 | ctx->Driver.SetDrawBuffer = set_draw_buffer;
|
| 675 | ctx->Driver.ClearColor = clear_color;
|
| 676 |
|
| 677 | /* Initialize the TNL driver interface:
|
| 678 | */
|
| 679 | tnl = TNL_CONTEXT(ctx);
|
| 680 | tnl->Driver.RunPipeline = _tnl_run_pipeline;
|
| 681 |
|
| 682 | /* Install swsetup for tnl->Driver.Render.*:
|
| 683 | */
|
| 684 | _swsetup_Wakeup(ctx);
|
| 685 | }
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 | static void dmesa_update_state (GLcontext *ctx, GLuint new_state)
|
| 690 | {
|
| 691 | DMesaContext c = (DMesaContext)ctx->DriverCtx;
|
| 692 | struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
|
| 693 |
|
| 694 | /* Initialize all the pointers in the DD struct. Do this whenever */
|
| 695 | /* a new context is made current or we change buffers via set_buffer! */
|
| 696 |
|
| 697 | _swrast_InvalidateState(ctx, new_state);
|
| 698 | _swsetup_InvalidateState(ctx, new_state);
|
| 699 | _ac_InvalidateState(ctx, new_state);
|
| 700 | _tnl_InvalidateState(ctx, new_state);
|
| 701 |
|
| 702 | swdd->SetReadBuffer = set_read_buffer;
|
| 703 |
|
| 704 | /* RGB(A) span/pixel functions */
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 705 | swdd->WriteRGBASpan = write_rgba_span;
|
| 706 | swdd->WriteRGBSpan = write_rgb_span;
|
| 707 | swdd->WriteMonoRGBASpan = write_mono_rgba_span;
|
| 708 | swdd->WriteRGBAPixels = write_rgba_pixels;
|
| 709 | swdd->WriteMonoRGBAPixels = write_mono_rgba_pixels;
|
| 710 | swdd->ReadRGBASpan = read_rgba_span;
|
| 711 | swdd->ReadRGBAPixels = read_rgba_pixels;
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 712 | }
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 | /**********************************************************************/
|
| 717 | /***** DMesa Public API Functions *****/
|
| 718 | /**********************************************************************/
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 | /*
|
| 723 | * The exact arguments to this function will depend on your window system
|
| 724 | */
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 725 | DMesaVisual DMesaCreateVisual (GLint width, GLint height, GLint colDepth,
|
| 726 | GLboolean dbFlag, GLint depthSize,
|
| 727 | GLint stencilSize,
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 728 | GLint accumSize)
|
| 729 | {
|
| 730 | DMesaVisual v;
|
| 731 | GLint redBits, greenBits, blueBits, alphaBits;
|
| 732 |
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 733 | if (!dbFlag) {
|
| 734 | return NULL;
|
| 735 | }
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 736 | alphaBits = 0;
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 737 | switch (colDepth) {
|
| 738 | case 15:
|
| 739 | redBits = 5;
|
| 740 | greenBits = 5;
|
| 741 | blueBits = 5;
|
| 742 | break;
|
| 743 | case 16:
|
| 744 | redBits = 5;
|
| 745 | greenBits = 6;
|
| 746 | blueBits = 5;
|
| 747 | break;
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 748 | case 32:
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 749 | alphaBits = 8;
|
| 750 | case 24:
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 751 | redBits = 8;
|
| 752 | greenBits = 8;
|
| 753 | blueBits = 8;
|
| 754 | break;
|
| 755 | default:
|
| 756 | return NULL;
|
| 757 | }
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 758 |
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 759 | if (vl_video_init(width, height, colDepth)!=0) {
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 760 | return NULL;
|
| 761 | }
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 762 |
|
| 763 | if ((v=(DMesaVisual)calloc(1, sizeof(struct dmesa_visual)))!=NULL) {
|
| 764 | /* Create core visual */
|
| 765 | v->gl_visual = _mesa_create_visual(colDepth>8, /* rgb */
|
| 766 | dbFlag,
|
| 767 | GL_FALSE, /* stereo */
|
| 768 | redBits,
|
| 769 | greenBits,
|
| 770 | blueBits,
|
| 771 | alphaBits,
|
| 772 | 0, /* indexBits */
|
| 773 | depthSize,
|
| 774 | stencilSize,
|
| 775 | accumSize, /* accumRed */
|
| 776 | accumSize, /* accumGreen */
|
| 777 | accumSize, /* accumBlue */
|
| 778 | alphaBits?accumSize:0, /* accumAlpha */
|
| 779 | 1); /* numSamples */
|
| 780 |
|
| 781 | v->depth = colDepth;
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 782 | v->db_flag = dbFlag;
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 783 | }
|
| 784 |
|
| 785 | return v;
|
| 786 | }
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 | void DMesaDestroyVisual (DMesaVisual v)
|
| 791 | {
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 792 | vl_video_exit(!0);
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 793 | _mesa_destroy_visual(v->gl_visual);
|
| 794 | free(v);
|
| 795 | }
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 | DMesaBuffer DMesaCreateBuffer (DMesaVisual visual,
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 800 | GLint xpos, GLint ypos,
|
| 801 | GLint width, GLint height)
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 802 | {
|
| 803 | DMesaBuffer b;
|
| 804 |
|
| 805 | if ((b=(DMesaBuffer)calloc(1, sizeof(struct dmesa_buffer)))!=NULL) {
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 806 |
|
Brian Paul | 6c921af | 2002-04-01 17:01:33 +0000 | [diff] [blame] | 807 | _mesa_initialize_framebuffer(&b->gl_buffer,
|
| 808 | visual->gl_visual,
|
| 809 | visual->gl_visual->depthBits > 0,
|
| 810 | visual->gl_visual->stencilBits > 0,
|
| 811 | visual->gl_visual->accumRedBits > 0,
|
| 812 | visual->gl_visual->alphaBits > 0);
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 813 | b->xpos = xpos;
|
| 814 | b->ypos = ypos;
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 815 | b->width = width;
|
| 816 | b->height = height;
|
Brian Paul | 6c921af | 2002-04-01 17:01:33 +0000 | [diff] [blame] | 817 | b->bypp = (visual->depth+7)/8;
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 818 | }
|
| 819 |
|
| 820 | return b;
|
| 821 | }
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 | void DMesaDestroyBuffer (DMesaBuffer b)
|
| 826 | {
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 827 | free(b->the_window);
|
Brian Paul | 6c921af | 2002-04-01 17:01:33 +0000 | [diff] [blame] | 828 | _mesa_free_framebuffer_data(&b->gl_buffer);
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 829 | free(b);
|
| 830 | }
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 | DMesaContext DMesaCreateContext (DMesaVisual visual,
|
| 835 | DMesaContext share)
|
| 836 | {
|
| 837 | DMesaContext c;
|
| 838 | GLboolean direct = GL_FALSE;
|
| 839 |
|
| 840 | if ((c=(DMesaContext)calloc(1, sizeof(struct dmesa_context)))!=NULL) {
|
Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 841 | __GLimports imports;
|
| 842 | _mesa_init_default_imports( &imports, (void *) c);
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 843 | c->gl_ctx = _mesa_create_context(visual->gl_visual,
|
| 844 | share ? share->gl_ctx : NULL,
|
Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 845 | &imports);
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 846 |
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 847 | _mesa_enable_sw_extensions(c->gl_ctx);
|
| 848 | _mesa_enable_1_3_extensions(c->gl_ctx);
|
| 849 |
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 850 | /* you probably have to do a bunch of other initializations here. */
|
| 851 | c->visual = visual;
|
| 852 |
|
| 853 | /* Initialize the software rasterizer and helper modules.
|
| 854 | */
|
| 855 | _swrast_CreateContext(c->gl_ctx);
|
| 856 | _ac_CreateContext(c->gl_ctx);
|
| 857 | _tnl_CreateContext(c->gl_ctx);
|
| 858 | _swsetup_CreateContext(c->gl_ctx);
|
| 859 | dmesa_init_pointers(c->gl_ctx);
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 860 | dmesa_register_swrast_functions(c->gl_ctx);
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 861 | }
|
| 862 |
|
| 863 | return c;
|
| 864 | }
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 | void DMesaDestroyContext (DMesaContext c)
|
| 869 | {
|
| 870 | _mesa_destroy_context(c->gl_ctx);
|
| 871 | free(c);
|
| 872 | }
|
| 873 |
|
| 874 |
|
| 875 |
|
Brian Paul | 6c921af | 2002-04-01 17:01:33 +0000 | [diff] [blame] | 876 | GLboolean DMesaViewport (DMesaBuffer b,
|
| 877 | GLint xpos, GLint ypos,
|
| 878 | GLint width, GLint height)
|
| 879 | {
|
| 880 | void *new_window;
|
| 881 |
|
| 882 | if ((new_window=vl_sync_buffer(b->the_window, xpos, ypos, width, height))==NULL) {
|
| 883 | return GL_FALSE;
|
| 884 | } else {
|
| 885 | b->the_window = new_window;
|
| 886 | b->xpos = xpos;
|
| 887 | b->ypos = ypos;
|
| 888 | b->width = width;
|
| 889 | b->height = height;
|
| 890 | b->bwidth = width * b->bypp;
|
| 891 | b->len = b->bwidth * height;
|
| 892 | return GL_TRUE;
|
| 893 | }
|
| 894 | }
|
| 895 |
|
| 896 |
|
| 897 |
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 898 | /*
|
| 899 | * Make the specified context and buffer the current one.
|
| 900 | */
|
| 901 | GLboolean DMesaMakeCurrent (DMesaContext c, DMesaBuffer b)
|
| 902 | {
|
| 903 | if (c&&b) {
|
Brian Paul | 6c921af | 2002-04-01 17:01:33 +0000 | [diff] [blame] | 904 | if (!DMesaViewport(b, b->xpos, b->ypos, b->width, b->height)) {
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 905 | return GL_FALSE;
|
| 906 | }
|
| 907 |
|
Brian Paul | e0193a9 | 2002-02-23 17:11:27 +0000 | [diff] [blame] | 908 | c->Buffer = b;
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 909 |
|
| 910 | dmesa_update_state(c->gl_ctx, 0);
|
Brian Paul | 6c921af | 2002-04-01 17:01:33 +0000 | [diff] [blame] | 911 | _mesa_make_current(c->gl_ctx, &b->gl_buffer);
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 912 | if (c->gl_ctx->Viewport.Width==0) {
|
| 913 | /* initialize viewport to window size */
|
Brian Paul | 6c921af | 2002-04-01 17:01:33 +0000 | [diff] [blame] | 914 | _mesa_Viewport(0, 0, b->width, b->height);
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 915 | }
|
| 916 | } else {
|
| 917 | /* Detach */
|
| 918 | _mesa_make_current(NULL, NULL);
|
| 919 | }
|
| 920 |
|
| 921 | return GL_TRUE;
|
| 922 | }
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 | void DMesaSwapBuffers (DMesaBuffer b)
|
| 927 | {
|
| 928 | /* copy/swap back buffer to front if applicable */
|
Brian Paul | b43a828 | 2002-03-08 19:27:17 +0000 | [diff] [blame] | 929 | vl_flip(b->the_window, b->bwidth, b->height);
|
Brian Paul | db41d2e | 2002-02-12 03:24:56 +0000 | [diff] [blame] | 930 | }
|