diff options
Diffstat (limited to 'src/mesa/drivers')
62 files changed, 681 insertions, 34853 deletions
diff --git a/src/mesa/drivers/allegro/amesa.c b/src/mesa/drivers/allegro/amesa.c deleted file mode 100644 index 0744677d2b..0000000000 --- a/src/mesa/drivers/allegro/amesa.c +++ /dev/null @@ -1,414 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 3.0 - * Copyright (C) 1995-1998 Brian Paul - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <allegro.h> -#include "main/buffers.h" -#include "main/context.h" -#include "main/imports.h" -#include "main/matrix.h" -#include "main/mtypes.h" -#include "amesa.h" - - -struct amesa_visual - { - GLvisual *GLVisual; /* inherit from GLvisual */ - GLboolean DBFlag; /* double buffered? */ - GLuint Depth; /* bits per pixel ( >= 15 ) */ - }; - - -struct amesa_buffer - { - GLframebuffer *GLBuffer; /* inherit from GLframebuffer */ - GLuint Width, Height; - BITMAP *Screen; - BITMAP *Background; - BITMAP *Active; - }; - - -struct amesa_context - { - GLcontext *GLContext; /* inherit from GLcontext */ - AMesaVisual Visual; - AMesaBuffer Buffer; - GLuint ClearColor; - GLuint CurrentColor; - }; - - -static void setup_dd_pointers(GLcontext *ctx); - - -/**********************************************************************/ -/***** drawing functions *****/ -/**********************************************************************/ - -#define FLIP(context, y) (context->Buffer->Height - (y) - 1) - -#include "allegro/generic.h" -#include "allegro/direct.h" - - -/**********************************************************************/ -/***** 15-bit accelerated drawing funcs *****/ -/**********************************************************************/ - -IMPLEMENT_WRITE_RGBA_SPAN(15, unsigned short) -IMPLEMENT_WRITE_RGB_SPAN(15, unsigned short) -IMPLEMENT_WRITE_MONO_RGBA_SPAN(15, unsigned short) -IMPLEMENT_READ_RGBA_SPAN(15, unsigned short) -IMPLEMENT_WRITE_RGBA_PIXELS(15, unsigned short) -IMPLEMENT_WRITE_MONO_RGBA_PIXELS(15, unsigned short) -IMPLEMENT_READ_RGBA_PIXELS(15, unsigned short) - - -/**********************************************************************/ -/***** 16-bit accelerated drawing funcs *****/ -/**********************************************************************/ - -IMPLEMENT_WRITE_RGBA_SPAN(16, unsigned short) -IMPLEMENT_WRITE_RGB_SPAN(16, unsigned short) -IMPLEMENT_WRITE_MONO_RGBA_SPAN(16, unsigned short) -IMPLEMENT_READ_RGBA_SPAN(16, unsigned short) -IMPLEMENT_WRITE_RGBA_PIXELS(16, unsigned short) -IMPLEMENT_WRITE_MONO_RGBA_PIXELS(16, unsigned short) -IMPLEMENT_READ_RGBA_PIXELS(16, unsigned short) - - -/**********************************************************************/ -/***** 32-bit accelerated drawing funcs *****/ -/**********************************************************************/ - -IMPLEMENT_WRITE_RGBA_SPAN(32, unsigned long) -IMPLEMENT_WRITE_RGB_SPAN(32, unsigned long) -IMPLEMENT_WRITE_MONO_RGBA_SPAN(32, unsigned long) -IMPLEMENT_READ_RGBA_SPAN(32, unsigned long) -IMPLEMENT_WRITE_RGBA_PIXELS(32, unsigned long) -IMPLEMENT_WRITE_MONO_RGBA_PIXELS(32, unsigned long) -IMPLEMENT_READ_RGBA_PIXELS(32, unsigned long) - - -/**********************************************************************/ -/***** Miscellaneous device driver funcs *****/ -/**********************************************************************/ - -static GLboolean set_buffer(GLcontext *ctx, GLframebuffer *buffer, GLuint bit) - { - AMesaContext context = (AMesaContext)(ctx->DriverCtx); - GLboolean ok = GL_TRUE; - - if (bit == DD_FRONT_LEFT_BIT) - context->Buffer->Active = context->Buffer->Screen; - - else if (bit == DD_BACK_LEFT) - { - if (context->Buffer->Background) - context->Buffer->Active = context->Buffer->Background; - else - ok = GL_FALSE; - } - - else - ok = GL_FALSE; - - return ok; - } - - -static void get_buffer_size(GLcontext *ctx, GLuint *width, GLuint *height) - { - AMesaContext context = (AMesaContext)(ctx->DriverCtx); - - *width = context->Buffer->Width; - *height = context->Buffer->Height; - } - - -/** - * We only implement this function as a mechanism to check if the - * framebuffer size has changed (and update corresponding state). - */ -static void viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h) -{ - /* poll for window size change and realloc software Z/stencil/etc if needed */ - GLuint newWidth, newHeight; - GLframebuffer *buffer = ctx->WinSysDrawBuffer; - get_buffer_size( &newWidth, &newHeight ); - if (buffer->Width != newWidth || buffer->Height != newHeight) { - _mesa_resize_framebuffer(ctx, buffer, newWidth, newHeight ); - } - -} - - -/**********************************************************************/ -/**********************************************************************/ - -static void setup_dd_pointers(GLcontext *ctx) - { - AMesaContext context = (AMesaContext)(ctx->DriverCtx); - - /* Initialize all the pointers in the driver struct. Do this whenever */ - /* a new context is made current or we change buffers via set_buffer! */ - - ctx->Driver.UpdateState = setup_dd_pointers; - ctx->Driver.SetBuffer = set_buffer; - ctx->Driver.GetBufferSize = get_buffer_size; - ctx->Driver.Viewport = viewport; - - ctx->Driver.Color = set_color_generic; - ctx->Driver.ClearColor = clear_color_generic; - ctx->Driver.Clear = clear_generic; - ctx->Driver.WriteRGBASpan = write_rgba_span_generic; - ctx->Driver.WriteRGBSpan = write_rgb_span_generic; - ctx->Driver.WriteMonoRGBASpan = write_mono_rgba_span_generic; - ctx->Driver.WriteRGBAPixels = write_rgba_pixels_generic; - ctx->Driver.WriteMonoRGBAPixels = write_mono_rgba_pixels_generic; - ctx->Driver.ReadRGBASpan = read_rgba_span_generic; - ctx->Driver.ReadRGBAPixels = read_rgba_pixels_generic; - - if (context->Buffer->Active != screen) - { - switch (context->Visual->Depth) - { - case 15: - ctx->Driver.WriteRGBASpan = write_rgba_span_15; - ctx->Driver.WriteRGBSpan = write_rgb_span_15; - ctx->Driver.WriteMonoRGBASpan = write_mono_rgba_span_15; - ctx->Driver.WriteRGBAPixels = write_rgba_pixels_15; - ctx->Driver.WriteMonoRGBAPixels = write_mono_rgba_pixels_15; - ctx->Driver.ReadRGBASpan = read_rgba_span_15; - ctx->Driver.ReadRGBAPixels = read_rgba_pixels_15; - break; - - case 16: - ctx->Driver.WriteRGBASpan = write_rgba_span_16; - ctx->Driver.WriteRGBSpan = write_rgb_span_16; - ctx->Driver.WriteMonoRGBASpan = write_mono_rgba_span_16; - ctx->Driver.WriteRGBAPixels = write_rgba_pixels_16; - ctx->Driver.WriteMonoRGBAPixels = write_mono_rgba_pixels_16; - ctx->Driver.ReadRGBASpan = read_rgba_span_16; - ctx->Driver.ReadRGBAPixels = read_rgba_pixels_16; - break; - - case 32: - ctx->Driver.WriteRGBASpan = write_rgba_span_32; - ctx->Driver.WriteRGBSpan = write_rgb_span_32; - ctx->Driver.WriteMonoRGBASpan = write_mono_rgba_span_32; - ctx->Driver.WriteRGBAPixels = write_rgba_pixels_32; - ctx->Driver.WriteMonoRGBAPixels = write_mono_rgba_pixels_32; - ctx->Driver.ReadRGBASpan = read_rgba_span_32; - ctx->Driver.ReadRGBAPixels = read_rgba_pixels_32; - break; - } - } - } - - -/**********************************************************************/ -/***** AMesa Public API Functions *****/ -/**********************************************************************/ - - -AMesaVisual AMesaCreateVisual(GLboolean dbFlag, GLint depth, - GLint depthSize, GLint stencilSize, GLint accumSize) - { - AMesaVisual visual; - GLbyte redBits, greenBits, blueBits; - - visual = (AMesaVisual)calloc(1, sizeof(struct amesa_visual)); - if (!visual) - return NULL; - - switch (depth) - { - case 15: - redBits = 5; - greenBits = 5; - blueBits = 5; - break; - - case 16: - redBits = 5; - greenBits = 6; - blueBits = 5; - break; - - case 24: case 32: - redBits = 8; - greenBits = 8; - blueBits = 8; - break; - - default: - free(visual); - return NULL; - } - - visual->DBFlag = dbFlag; - visual->Depth = depth; - visual->GLVisual = _mesa_create_visual(GL_TRUE, /* rgb mode */ - dbFlag, /* db_flag */ - GL_FALSE, /* stereo */ - redBits, greenBits, blueBits, 8, - 0, /* index bits */ - depthSize, /* depth bits */ - stencilSize,/* stencil bits */ - accumSize, /* accum bits */ - accumSize, /* accum bits */ - accumSize, /* accum bits */ - accumSize, /* accum bits */ - 1 ); - if (!visual->GLVisual) - { - free(visual); - return NULL; - } - - return visual; - } - - -void AMesaDestroyVisual(AMesaVisual visual) - { - _mesa_destroy_visual(visual->GLVisual); - free(visual); - } - - -AMesaBuffer AMesaCreateBuffer(AMesaVisual visual, - GLint width, GLint height) - { - AMesaBuffer buffer; - - buffer = (AMesaBuffer)calloc(1, sizeof(struct amesa_buffer)); - if (!buffer) - return NULL; - - buffer->Screen = NULL; - buffer->Background = NULL; - buffer->Active = NULL; - buffer->Width = width; - buffer->Height = height; - - if (visual->DBFlag) - { - buffer->Background = create_bitmap_ex(visual->Depth, width, height); - if (!buffer->Background) - { - free(buffer); - return NULL; - } - } - - buffer->GLBuffer = _mesa_create_framebuffer(visual->GLVisual); - if (!buffer->GLBuffer) - { - if (buffer->Background) destroy_bitmap(buffer->Background); - free(buffer); - return NULL; - } - - return buffer; - } - - -void AMesaDestroyBuffer(AMesaBuffer buffer) -{ - if (buffer->Screen) destroy_bitmap(buffer->Screen); - if (buffer->Background) destroy_bitmap(buffer->Background); - _mesa_reference_framebuffer(&buffer->GLBuffer, NULL); - free(buffer); -} - - -AMesaContext AMesaCreateContext(AMesaVisual visual, - AMesaContext share) -{ - AMesaContext context; - GLboolean direct = GL_FALSE; - - context = (AMesaContext)calloc(1, sizeof(struct amesa_context)); - if (!context) - return NULL; - - context->Visual = visual; - context->Buffer = NULL; - context->ClearColor = 0; - context->CurrentColor = 0; - context->GLContext = _mesa_create_context(visual->GLVisual, - share ? share->GLContext : NULL, - (void *) context, GL_FALSE ); - if (!context->GLContext) - { - free(context); - return NULL; - } - - return context; -} - - -void AMesaDestroyContext(AMesaContext context) -{ - _mesa_destroy_context(context->GLContext); - free(context); -} - - -GLboolean AMesaMakeCurrent(AMesaContext context, AMesaBuffer buffer) -{ - if (context && buffer) { - set_color_depth(context->Visual->Depth); - if (set_gfx_mode(GFX_AUTODETECT, buffer->Width, buffer->Height, 0, 0) != 0) - return GL_FALSE; - - context->Buffer = buffer; - buffer->Screen = screen; - buffer->Active = buffer->Background ? buffer->Background : screen; - - setup_dd_pointers(context->GLContext); - _mesa_make_current(context->GLContext, buffer->GLBuffer); - } - else { - /* XXX I don't think you want to destroy anything here! */ - destroy_bitmap(context->Buffer->Screen); - context->Buffer->Screen = NULL; - context->Buffer->Active = NULL; - context->Buffer = NULL; - _mesa_make_current(NULL, NULL); - } - - return GL_TRUE; -} - - -void AMesaSwapBuffers(AMesaBuffer buffer) -{ - if (buffer->Background) { - blit(buffer->Background, buffer->Screen, - 0, 0, 0, 0, - buffer->Width, buffer->Height); - } -} diff --git a/src/mesa/drivers/allegro/amesa.h b/src/mesa/drivers/allegro/amesa.h deleted file mode 100644 index 852d34cf4f..0000000000 --- a/src/mesa/drivers/allegro/amesa.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - - -/* Allegro (DJGPP) driver by Bernhard Tschirren (bernie-t@geocities.com) */ - - -#ifndef AMESA_H -#define AMESA_H - - -#define AMESA_MAJOR_VERSION 3 -#define AMESA_MINOR_VERSION 3 - - -typedef struct amesa_visual *AMesaVisual; -typedef struct amesa_buffer *AMesaBuffer; -typedef struct amesa_context *AMesaContext; - - -extern AMesaVisual AMesaCreateVisual(GLboolean dbFlag, GLint depth, - GLint depthSize, - GLint stencilSize, - GLint accumSize); - -extern void AMesaDestroyVisual(AMesaVisual visual); - -extern AMesaBuffer AMesaCreateBuffer(AMesaVisual visual, - GLint width, GLint height); - -extern void AMesaDestroyBuffer(AMesaBuffer buffer); - - -extern AMesaContext AMesaCreateContext(AMesaVisual visual, - AMesaContext sharelist); - -extern void AMesaDestroyContext(AMesaContext context); - -extern GLboolean AMesaMakeCurrent(AMesaContext context, AMesaBuffer buffer); - -extern void AMesaSwapBuffers(AMesaBuffer buffer); - - -#endif /* AMESA_H */ diff --git a/src/mesa/drivers/allegro/direct.h b/src/mesa/drivers/allegro/direct.h deleted file mode 100644 index bd8b5eb49d..0000000000 --- a/src/mesa/drivers/allegro/direct.h +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 3.0 - * Copyright (C) 1995-1998 Brian Paul - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - - -#define DESTINATION(BMP, X, Y, TYPE) \ - ({ \ - BITMAP *_bmp = BMP; \ - \ - (TYPE*)(_bmp->line[_bmp->h - (Y) - 1]) + (X); \ - }) - - -#define IMPLEMENT_WRITE_RGBA_SPAN(DEPTH, TYPE) \ -static void write_rgba_span_##DEPTH (const GLcontext *ctx, \ - GLuint n, GLint x, GLint y, \ - const GLubyte rgba[][4], \ - const GLubyte mask[]) \ - { \ - AMesaContext context = (AMesaContext)(ctx->DriverCtx); \ - TYPE *d = DESTINATION(context->Buffer->Active, x, y, TYPE); \ - \ - if (mask) \ - { \ - while (n--) \ - { \ - if (mask[0]) d[0] = makecol##DEPTH(rgba[0][RCOMP], rgba[0][GCOMP], rgba[0][BCOMP]); \ - d++; rgba++; mask++; \ - } \ - } \ - else \ - { \ - while (n--) \ - { \ - d[0] = makecol##DEPTH(rgba[0][RCOMP], rgba[0][GCOMP], rgba[0][BCOMP]); \ - d++; rgba++; \ - } \ - } \ - } - - -#define IMPLEMENT_WRITE_RGB_SPAN(DEPTH, TYPE) \ -static void write_rgb_span_##DEPTH (const GLcontext *ctx, \ - GLuint n, GLint x, GLint y, \ - const GLubyte rgb[][3], \ - const GLubyte mask[]) \ - { \ - AMesaContext context = (AMesaContext)(ctx->DriverCtx); \ - TYPE *d = DESTINATION(context->Buffer->Active, x, y, TYPE); \ - \ - if (mask) \ - { \ - while (n--) \ - { \ - if (mask[0]) d[0] = makecol##DEPTH(rgb[0][RCOMP], rgb[0][GCOMP], rgb[0][BCOMP]); \ - d++; rgb++; mask++; \ - } \ - } \ - else \ - { \ - while (n--) \ - { \ - d[0] = makecol##DEPTH(rgb[0][RCOMP], rgb[0][GCOMP], rgb[0][BCOMP]); \ - d++; rgb++; \ - } \ - } \ - } - - -#define IMPLEMENT_WRITE_MONO_RGBA_SPAN(DEPTH, TYPE) \ -static void write_mono_rgba_span_##DEPTH (const GLcontext *ctx, \ - GLuint n, GLint x, GLint y, \ - const GLubyte mask[]) \ - { \ - AMesaContext context = (AMesaContext)(ctx->DriverCtx); \ - TYPE color = context->CurrentColor; \ - TYPE *d = DESTINATION(context->Buffer->Active, x, y, TYPE); \ - \ - while (n--) \ - { \ - if (mask[0]) d[0] = color; \ - d++; mask++; \ - } \ - } - - -#define IMPLEMENT_READ_RGBA_SPAN(DEPTH, TYPE) \ -static void read_rgba_span_##DEPTH (const GLcontext *ctx, \ - GLuint n, GLint x, GLint y, \ - GLubyte rgba[][4]) \ - { \ - AMesaContext context = (AMesaContext)(ctx->DriverCtx); \ - BITMAP *bmp = context->Buffer->Active; \ - TYPE *d = DESTINATION(bmp, x, y, TYPE); \ - \ - while (n--) \ - { \ - rgba[0][RCOMP] = getr##DEPTH(d[0]); \ - rgba[0][GCOMP] = getg##DEPTH(d[0]); \ - rgba[0][BCOMP] = getb##DEPTH(d[0]); \ - rgba[0][ACOMP] = 255; \ - \ - d++; rgba++; \ - } \ - } - - -#define IMPLEMENT_WRITE_RGBA_PIXELS(DEPTH, TYPE) \ -static void write_rgba_pixels_##DEPTH (const GLcontext *ctx, \ - GLuint n, \ - const GLint x[], \ - const GLint y[], \ - const GLubyte rgba[][4], \ - const GLubyte mask[]) \ - { \ - AMesaContext context = (AMesaContext)(ctx->DriverCtx); \ - BITMAP *bmp = context->Buffer->Active; \ - \ - while (n--) \ - { \ - if (mask[0]) *DESTINATION(bmp, x[0], y[0], TYPE) = makecol##DEPTH(rgba[0][RCOMP], rgba[0][GCOMP], rgba[0][BCOMP]); \ - rgba++; x++; y++; mask++; \ - } \ - } - - - -#define IMPLEMENT_WRITE_MONO_RGBA_PIXELS(DEPTH, TYPE) \ -static void write_mono_rgba_pixels_##DEPTH (const GLcontext *ctx, \ - GLuint n, \ - const GLint x[], \ - const GLint y[], \ - const GLubyte mask[]) \ - { \ - AMesaContext context = (AMesaContext)(ctx->DriverCtx); \ - TYPE color = context->CurrentColor; \ - BITMAP *bmp = context->Buffer->Active; \ - \ - while (n--) \ - { \ - if (mask[0]) *DESTINATION(bmp, x[0], y[0], TYPE) = color; \ - x++; y++; mask++; \ - } \ - } - - -#define IMPLEMENT_READ_RGBA_PIXELS(DEPTH, TYPE) \ -static void read_rgba_pixels_##DEPTH (const GLcontext *ctx, \ - GLuint n, \ - const GLint x[], \ - const GLint y[], \ - GLubyte rgba[][4], \ - const GLubyte mask[]) \ - { \ - AMesaContext context = (AMesaContext)(ctx->DriverCtx); \ - BITMAP *bmp = context->Buffer->Active; \ - \ - while (n--) \ - { \ - if (mask[0]) \ - { \ - int color = *DESTINATION(bmp, x[0], y[0], TYPE); \ - \ - rgba[0][RCOMP] = getr##DEPTH(color); \ - rgba[0][GCOMP] = getg##DEPTH(color); \ - rgba[0][BCOMP] = getb##DEPTH(color); \ - rgba[0][ACOMP] = 255; \ - } \ - \ - x++; y++; rgba++; mask++; \ - } \ - } - diff --git a/src/mesa/drivers/allegro/generic.h b/src/mesa/drivers/allegro/generic.h deleted file mode 100644 index 4c8af9b95c..0000000000 --- a/src/mesa/drivers/allegro/generic.h +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 3.0 - * Copyright (C) 1995-1998 Brian Paul - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -static void clear_color_generic(GLcontext *ctx, const GLfloat color[4]) - { - AMesaContext context = (AMesaContext)(ctx->DriverCtx); - GLubyte r, g, b; - CLAMPED_FLOAT_TO_UBYTE(r, color[0]); - CLAMPED_FLOAT_TO_UBYTE(g, color[1]); - CLAMPED_FLOAT_TO_UBYTE(b, color[2]); - context->ClearColor = makecol(r, g, b); - } - - -static void set_color_generic(GLcontext *ctx, - GLubyte red, GLubyte green, - GLubyte blue, GLubyte alpha) - { - AMesaContext context = (AMesaContext)(ctx->DriverCtx); - - context->CurrentColor = makecol(red, green, blue); - } - - -static GLbitfield clear_generic(GLcontext *ctx, - GLbitfield mask, GLboolean all, - GLint x, GLint y, - GLint width, GLint height) - { - AMesaContext context = (AMesaContext)(ctx->DriverCtx); - - if (mask & GL_COLOR_BUFFER_BIT) - { - if (all) - clear_to_color(context->Buffer->Active, context->ClearColor); - else - rect(context->Buffer->Active, - x, y, x+width-1, y+height-1, - context->ClearColor); - } - - return mask & (~GL_COLOR_BUFFER_BIT); - } - - -static void write_rgba_span_generic(const GLcontext *ctx, - GLuint n, GLint x, GLint y, - const GLubyte rgba[][4], - const GLubyte mask[]) - { - AMesaContext context = (AMesaContext)(ctx->DriverCtx); - BITMAP *bmp = context->Buffer->Active; - - y = FLIP(context, y); - - if (mask) - { - while (n--) - { - if (mask[0]) putpixel(bmp, x, y, makecol(rgba[0][RCOMP], rgba[0][GCOMP], rgba[0][BCOMP])); - x++; mask++; rgba++; - } - } - else - { - while (n--) - { - putpixel(bmp, x, y, makecol(rgba[0][RCOMP], rgba[0][GCOMP], rgba[0][BCOMP])); - x++; rgba++; - } - } - } - - -static void write_rgb_span_generic(const GLcontext *ctx, - GLuint n, GLint x, GLint y, - const GLubyte rgb[][3], - const GLubyte mask[]) - { - AMesaContext context = (AMesaContext)(ctx->DriverCtx); - BITMAP *bmp = context->Buffer->Active; - - y = FLIP(context, y); - - if (mask) - { - while(n--) - { - if (mask[0]) putpixel(bmp, x, y, makecol(rgb[0][RCOMP], rgb[0][GCOMP], rgb[0][BCOMP])); - x++; mask++; rgb++; - } - } - else - { - while (n--) - { - putpixel(bmp, x, y, makecol(rgb[0][RCOMP], rgb[0][GCOMP], rgb[0][BCOMP])); - x++; rgb++; - } - } - } - - -static void write_mono_rgba_span_generic(const GLcontext *ctx, - GLuint n, GLint x, GLint y, - const GLubyte mask[]) - { - AMesaContext context = (AMesaContext)(ctx->DriverCtx); - BITMAP *bmp = context->Buffer->Active; - int color = context->CurrentColor; - - y = FLIP(context, y); - - if (mask) - { - while(n--) - { - if (mask[0]) putpixel(bmp, x, y, color); - x++; mask++; - } - } - else - { - while(n--) - { - putpixel(bmp, x, y, color); - x++; - } - } - } - - -static void read_rgba_span_generic(const GLcontext *ctx, - GLuint n, GLint x, GLint y, - GLubyte rgba[][4]) - { - AMesaContext context = (AMesaContext)(ctx->DriverCtx); - BITMAP *bmp = context->Buffer->Active; - - y = FLIP(context, y); - - while (n--) - { - int color = getpixel(bmp, x, y); - - rgba[0][RCOMP] = getr(color); - rgba[0][GCOMP] = getg(color); - rgba[0][BCOMP] = getb(color); - rgba[0][ACOMP] = 255; - - x++; rgba++; - } - } - - -static void write_rgba_pixels_generic(const GLcontext *ctx, - GLuint n, - const GLint x[], - const GLint y[], - const GLubyte rgba[][4], - const GLubyte mask[]) - { - AMesaContext context = (AMesaContext)(ctx->DriverCtx); - BITMAP *bmp = context->Buffer->Active; - - while (n--) - { - if (mask[0]) putpixel(bmp, x[0], FLIP(context, y[0]), makecol(rgba[0][RCOMP], rgba[0][GCOMP], rgba[0][BCOMP])); - x++; y++; mask++; - } - } - - -static void write_mono_rgba_pixels_generic(const GLcontext *ctx, - GLuint n, - const GLint x[], - const GLint y[], - const GLubyte mask[]) - { - AMesaContext context = (AMesaContext)(ctx->DriverCtx); - BITMAP *bmp = context->Buffer->Active; - int color = context->CurrentColor; - - while (n--) - { - if (mask[0]) putpixel(bmp, x[0], FLIP(context, y[0]), color); - x++; y++; mask++; - } - } - - -static void read_rgba_pixels_generic(const GLcontext *ctx, - GLuint n, - const GLint x[], - const GLint y[], - GLubyte rgba[][4], - const GLubyte mask[]) - { - AMesaContext context = (AMesaContext)(ctx->DriverCtx); - BITMAP *bmp = context->Buffer->Active; - - while (n--) - { - if (mask[0]) - { - int color = getpixel(bmp, x[0], FLIP(context, y[0])); - - rgba[0][RCOMP] = getr(color); - rgba[0][GCOMP] = getg(color); - rgba[0][BCOMP] = getb(color); - rgba[0][ACOMP] = 255; - } - - x++; y++; mask++; rgba++; - } - } - diff --git a/src/mesa/drivers/d3d/D3DCAPS.CPP b/src/mesa/drivers/d3d/D3DCAPS.CPP deleted file mode 100644 index 80ee91d922..0000000000 --- a/src/mesa/drivers/d3d/D3DCAPS.CPP +++ /dev/null @@ -1,250 +0,0 @@ -/*===========================================================================*/ -/* */ -/* Mesa-3.0 DirectX 6 Driver Build 5 */ -/* */ -/* By Leigh McRae */ -/* */ -/* http://www.altsoftware.com/ */ -/* */ -/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ -/*===========================================================================*/ -#include "D3DHAL.h" -/*===========================================================================*/ -/* Macros. */ -/*===========================================================================*/ -#define SRCBLEND_MAP(gl,d3d,fall) if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwSrcBlendCaps & d3d ) \ - { \ - sprintf( buffer, "SRC Blend: %s -> %s", # gl, # d3d ); \ - DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), buffer )); \ - pShared->dwSrcBlendCaps[index] = d3d; \ - } \ - else \ - { \ - sprintf( buffer, "SRC Blend: %s -> %s", # gl, # fall ); \ - DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), buffer )); \ - pShared->dwSrcBlendCaps[index] = fall; \ - } -#define DSTBLEND_MAP(gl,d3d,fall) if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwDestBlendCaps & d3d ) \ - { \ - sprintf( buffer, "DST Blend: %s -> %s", # gl, # d3d ); \ - DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), buffer )); \ - pShared->dwDestBlendCaps[index] = d3d; \ - } \ - else \ - { \ - sprintf( buffer, "DST Blend: %s -> %s", # gl, # fall ); \ - DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), buffer )); \ - pShared->dwDestBlendCaps[index] = fall; \ - } - -/*===========================================================================*/ -/* I use this function to handle the fact that the D3D texture blending and */ -/* OpenGL texture blending functions don't map one to one. Also there is the*/ -/* problem with cards not supporting all the D3D functions. So I use the CAPS*/ -/* of the card to make a table of functions that will have defaults for the */ -/* unsupported functions. */ -/* So first I fill the table with the fallback function then I check to see */ -/* if the card supports the requested function. If it does I replace the */ -/* default thats already in the array. Now order does matter as I used an */ -/* enum type in D3DShared.h so that the mapping would be a little easier. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -void AlphaBlendTableHAL( PMESAD3DHAL pHAL ) -{ - PMESAD3DSHARED pShared = &pHAL->shared; - int index; - char buffer[128]; - - DPF(( DBG_FUNC, "AlphaBlendTableHAL();" )); - - /* Make the fallback for the Source blend. */ - for( index = 0; index < 14; index++ ) - { - switch( index ) - { - case s_zero: - SRCBLEND_MAP( GL_ZERO, D3DBLEND_ZERO, D3DBLEND_ONE ); - break; - case s_one: - SRCBLEND_MAP( GL_ONE, D3DBLEND_ONE, D3DBLEND_ONE ); - break; - case s_dst_color: - SRCBLEND_MAP( GL_DST_COLOR, D3DBLEND_DESTCOLOR, D3DBLEND_ONE ); - break; - case s_one_minus_dst_color: - SRCBLEND_MAP( GL_ONE_MINUS_DST_COLOR, D3DBLEND_INVDESTCOLOR, D3DBLEND_ONE ); - break; - case s_src_alpha: - SRCBLEND_MAP( GL_SRC_ALPHA, D3DBLEND_SRCALPHA, D3DBLEND_ONE ); - break; - case s_one_minus_src_alpha: - SRCBLEND_MAP( GL_ONE_MINUS_SRC_ALPHA, D3DBLEND_INVSRCALPHA, D3DBLEND_ONE ); - break; - case s_dst_alpha: - SRCBLEND_MAP( GL_DST_ALPHA, D3DBLEND_DESTALPHA, D3DBLEND_ONE ); - break; - case s_one_minus_dst_alpha: - SRCBLEND_MAP( GL_ONE_MINUS_DST_ALPHA, D3DBLEND_INVDESTALPHA, D3DBLEND_ONE ); - break; - case s_src_alpha_saturate: - SRCBLEND_MAP( GL_SRC_ALPHA_SATURATE, D3DBLEND_SRCALPHASAT, D3DBLEND_ONE ); - break; - case s_constant_color: - SRCBLEND_MAP( GL_CONSTANT_COLOR, D3DBLEND_SRCCOLOR, D3DBLEND_ONE ); - break; - case s_one_minus_constant_color: - SRCBLEND_MAP( GL_ONE_MINUS_CONSTANT_COLOR, D3DBLEND_INVSRCCOLOR, D3DBLEND_ONE ); - break; - case s_constant_alpha: - SRCBLEND_MAP( GL_CONSTANT_ALPHA, D3DBLEND_BOTHSRCALPHA, D3DBLEND_ONE ); - break; - case s_one_minus_constant_alpha: - SRCBLEND_MAP( GL_ONE_MINUS_CONSTANT_ALPHA, D3DBLEND_BOTHINVSRCALPHA, D3DBLEND_ONE ); - break; - } - } - - /* Make the fallback for the Destination blend. */ - for( index = 0; index < 14; index++ ) - { - switch( index ) - { - case d_zero: - DSTBLEND_MAP( GL_ZERO, D3DBLEND_ZERO, D3DBLEND_ONE ); - break; - case d_one: - DSTBLEND_MAP( GL_ONE, D3DBLEND_ONE, D3DBLEND_ONE ); - break; - case d_src_color: - DSTBLEND_MAP( GL_SRC_COLOR, D3DBLEND_SRCCOLOR, D3DBLEND_ONE ); - break; - case d_one_minus_src_color: - DSTBLEND_MAP( GL_ONE_MINUS_SRC_COLOR, D3DBLEND_INVSRCCOLOR, D3DBLEND_ONE ); - break; - case d_src_alpha: - DSTBLEND_MAP( GL_SRC_ALPHA, D3DBLEND_SRCALPHA, D3DBLEND_ONE ); - break; - case d_one_minus_src_alpha: - DSTBLEND_MAP( GL_ONE_MINUS_SRC_ALPHA, D3DBLEND_INVSRCALPHA, D3DBLEND_ONE ); - break; - case d_dst_alpha: - DSTBLEND_MAP( GL_DST_ALPHA, D3DBLEND_DESTALPHA, D3DBLEND_ONE ); - break; - case d_one_minus_dst_alpha: - DSTBLEND_MAP( GL_ONE_MINUS_DST_ALPHA, D3DBLEND_INVDESTALPHA, D3DBLEND_ONE ); - break; - case d_constant_color: - DSTBLEND_MAP( GL_CONSTANT_COLOR, D3DBLEND_DESTCOLOR, D3DBLEND_ONE ); - break; - case d_one_minus_constant_color: - DSTBLEND_MAP( GL_ONE_MINUS_CONSTANT_COLOR, D3DBLEND_INVDESTCOLOR, D3DBLEND_ONE ); - break; - case d_constant_alpha: - DSTBLEND_MAP( GL_CONSTANT_ALPHAR, D3DBLEND_BOTHSRCALPHA, D3DBLEND_ONE ); - break; - case d_one_minus_constant_alpha: - DSTBLEND_MAP( GL_ONE_MINUS_CONSTANT_ALPHA, D3DBLEND_BOTHINVSRCALPHA, D3DBLEND_ONE ); - break; - } - } - - /* Make the fallbacks for the texture functions. */ - for( index = 0; index < 4; index++ ) - { - switch( index ) - { - case d3dtblend_decal: - if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_DECAL ) - { - DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_DECAL -> D3DTBLEND_DECAL" )); - pShared->dwTexFunc[index] = D3DTBLEND_DECAL; - } - else - { - if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_MODULATE ) - { - DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_DECAL -> D3DTBLEND_MODULATE" )); - pShared->dwTexFunc[index] = D3DTBLEND_MODULATE; - } - else - { - DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_DECAL -> D3DTBLEND_ADD" )); - pShared->dwTexFunc[index] = D3DTBLEND_ADD; - } - } - break; - case d3dtblend_decalalpha: - if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_DECALALPHA ) - { - DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_DECALALPHA -> D3DTBLEND_DECALALPHA" )); - pShared->dwTexFunc[index] = D3DTBLEND_DECALALPHA; - } - else - { - if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_DECAL ) - { - DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_DECALALPA -> D3DTBLEND_DECAL" )); - pShared->dwTexFunc[index] = D3DTBLEND_DECAL; - } - else - { - DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_DECALALPHA -> D3DTBLEND_ADD" )); - pShared->dwTexFunc[index] = D3DTBLEND_ADD; - } - } - break; - case d3dtblend_modulate: - if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_MODULATE ) - { - DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATE -> D3DTBLEND_MODULATE" )); - pShared->dwTexFunc[index] = D3DTBLEND_MODULATE; - } - else - { - if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_MODULATEALPHA ) - { - DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATE -> D3DTBLEND_MODULATEALPHA" )); - pShared->dwTexFunc[index] = D3DTBLEND_MODULATEALPHA; - } - else if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_DECAL ) - { - DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATE -> D3DTBLEND_DECAL" )); - pShared->dwTexFunc[index] = D3DTBLEND_DECAL; - } - else - { - DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATE -> D3DTBLEND_ADD" )); - pShared->dwTexFunc[index] = D3DTBLEND_ADD; - } - } - break; - case d3dtblend_modulatealpha: - if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_MODULATEALPHA ) - { - DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATEALPHA -> D3DTBLEND_MODULATEALPHA" )); - pShared->dwTexFunc[index] = D3DTBLEND_MODULATEALPHA; - } - else - { - if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_MODULATE ) - { - DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATEALPHA -> D3DTBLEND_MODULATE" )); - pShared->dwTexFunc[index] = D3DTBLEND_MODULATE; - } - else if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_DECAL ) - { - DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATEALPHA -> D3DTBLEND_DECALE" )); - pShared->dwTexFunc[index] = D3DTBLEND_DECAL; - } - else - { - DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATEALPHA -> D3DTBLEND_ADD" )); - pShared->dwTexFunc[index] = D3DTBLEND_ADD; - } - } - break; - } - } -} - diff --git a/src/mesa/drivers/d3d/D3DHAL.H b/src/mesa/drivers/d3d/D3DHAL.H deleted file mode 100644 index 2496d164e5..0000000000 --- a/src/mesa/drivers/d3d/D3DHAL.H +++ /dev/null @@ -1,68 +0,0 @@ -/*===========================================================================*/ -/* */ -/* Mesa-3.0 DirectX 6 Driver */ -/* */ -/* By Leigh McRae */ -/* */ -/* http://www.altsoftware.com/ */ -/* */ -/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ -/*===========================================================================*/ -#ifndef _D3D_HAL_INC -#define _D3D_HAL_INC - -/*===========================================================================*/ -/* Includes. */ -/*===========================================================================*/ -#include <windows.h> -#include <ddraw.h> -#include <d3d.h> -#include <stdlib.h> -#include <time.h> -#include "D3DShared.h" -#include "D3DTextureMgr.h" -#include "Debug.h" -/*===========================================================================*/ -/* Defines. */ -/*===========================================================================*/ -#define DX_RESTORE(ps) if ( (ps) && (ps)->IsLost() ) (ps)->Restore(); -/*===========================================================================*/ -/* Type defines. */ -/*===========================================================================*/ -typedef struct _d3d_hal_struct -{ - MESAD3DSHARED shared; - - GUID guid; - LPDIRECTDRAW lpDD; - LPDIRECTDRAW4 lpDD4; - LPDIRECT3D3 lpD3D3; - LPDIRECT3DDEVICE3 lpD3DDevice; - D3DDEVICEDESC D3DHWDevDesc; - LPDIRECTDRAWSURFACE4 lpDDSPrimary, - lpDDSRender, - lpDDSZbuffer; - LPDIRECT3DVIEWPORT3 lpViewport; - LPDIRECTDRAWCLIPPER lpClipper; - DDPIXELFORMAT ddpf, - ddpfZBuffer; - PTM_OBJECT pTMList; - -} MESAD3DHAL, *PMESAD3DHAL; -/*===========================================================================*/ -/* External function prototypes. */ -/*===========================================================================*/ -extern BOOL InitTMgrHAL( PMESAD3DHAL pHAL ); -extern void TermTMgrHAL( PMESAD3DHAL pHAL ); -extern void AlphaBlendTableHAL( PMESAD3DHAL pHAL ); - -extern void Solve8BitChannelPixelFormat( DDPIXELFORMAT *pddpf, PPIXELINFO pPixel ); -extern char *ErrorStringD3D( HRESULT hr ); -extern void FatalShutDown( PMESAD3DHAL pHAL ); -/*===========================================================================*/ -/* Global variables. */ -/*===========================================================================*/ -extern char *errorMsg; - -#endif - diff --git a/src/mesa/drivers/d3d/D3DInit.cpp b/src/mesa/drivers/d3d/D3DInit.cpp deleted file mode 100644 index e21cd21e25..0000000000 --- a/src/mesa/drivers/d3d/D3DInit.cpp +++ /dev/null @@ -1,891 +0,0 @@ -/*===========================================================================*/ -/* */ -/* Mesa-3.0 DirectX 6 Driver Build 5 */ -/* */ -/* By Leigh McRae */ -/* */ -/* http://www.altsoftware.com/ */ -/* */ -/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ -/*===========================================================================*/ -#include "D3DHAL.h" -/*===========================================================================*/ -/* Local function prototypes. */ -/*===========================================================================*/ -static void DestroyAllSurfaces( PMESAD3DHAL pHAL ); -static void DestroyDevice( PMESAD3DHAL pHAL ); -static void DestroyInterfaces( PMESAD3DHAL pHAL ); - -HRESULT WINAPI EnumSurfacesHook( LPDIRECTDRAWSURFACE4 lpDDS, LPDDSURFACEDESC2 lpDDSDesc, LPVOID pVoid ); -HRESULT CALLBACK EnumZBufferHook( DDPIXELFORMAT* pddpf, VOID *pVoid ); -HRESULT CALLBACK EnumDeviceHook( GUID FAR* lpGuid, LPSTR lpDesc, LPSTR lpName, LPD3DDEVICEDESC lpD3DHWDesc, LPD3DDEVICEDESC lpD3DHELDesc, void *pVoid ); -/*===========================================================================*/ -/* Globals. */ -/*===========================================================================*/ -//char *errorMsg; -/*===========================================================================*/ -/* This function is responable for allocating the actual MESAD3DHAL struct. */ -/* Each Mesa context will have its own MESAD3DHAL struct so its like a mini */ -/* context to some extent. All one time allocations/operations get done here.*/ -/*===========================================================================*/ -/* RETURN: TRUE, FALSE. */ -/*===========================================================================*/ -extern "C" PMESAD3DSHARED InitHAL( HWND hwnd ) -{ - PMESAD3DHAL pHAL; - ULONG rc; - - DPF(( DBG_FUNC, "InitHAL();" )); - DPF(( DBG_CNTX_INFO, "hwnd: %d", hwnd )); - - /* Allocate the structure and zero it out. */ - pHAL = (PMESAD3DHAL)ALLOC( sizeof(MESAD3DHAL) ); - if ( pHAL == NULL ) - { - RIP( pHAL, "InitHAL->", "Memory Allocation" ); - return (PMESAD3DSHARED)NULL; - } - memset( pHAL, 0, sizeof(MESAD3DHAL) ); - - /* Get the texture manager going. */ - rc = InitTMgrHAL( pHAL ); - if ( rc == FALSE ) - { - RIP( pHAL, "InitTMgrHAL->", "Failed" ); - return (PMESAD3DSHARED)NULL; - } - - /* Fill in the window parameters if we can. */ - pHAL->shared.hwnd = hwnd; - - /* Parse the user's enviroment variables to generate a debug mask. */ - ReadDBGEnv(); - - return (PMESAD3DSHARED)pHAL; -} -/*===========================================================================*/ -/* This function will unload all the resources that the MESAD3DHAL struct */ -/* has bound to it. The actual structure itself will be freed. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -extern "C" void TermHAL( PMESAD3DSHARED pShared ) -{ - PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; - - DPF(( DBG_FUNC, "TermHAL();" )); - - /* Check for an empty wrapper structure. */ - if ( pHAL == NULL ) - return; - - /* Kill this texture manager. */ - TermTMgrHAL( pHAL ); - - /* Kill any DDraw stuff if exists. */ - DestroyDevice( pHAL ); - DestroyAllSurfaces( pHAL ); - DestroyInterfaces( pHAL ); - - FREE( pHAL ); -} -/*===========================================================================*/ -/* This function is used to init and resize the rendering surface as the two*/ -/* are almost the same. First the device and all the surfaces are destoryed */ -/* if they already exist. Next we create a OffScreen rendering surface and */ -/* save some pixelformat info to do color convertions. Next we start to take */ -/* care of getting the most out of the hardware. I use bHardware to determine*/ -/* the state of the device we found in the device enumeration. The enum proc*/ -/* will try for hardware first. I next use a bForceSW to make the enum proc */ -/* choose a software device. So I will try some combinations with HW first */ -/* until I feel I have to set the bForceSW and call this function again. If */ -/* this function is called with no width or height then use the internals. */ -/* NOTE: The worst case is that all will be in SW (RGBDevice) and really */ -/* I should forget the whole thing and fall back to a DDraw span type*/ -/* rendering but what is the point. This way I always know I have a */ -/* D3DDevice and that makes things easier. I do impliment the span */ -/* rendering function for stuff that I haven't done support for such */ -/* as points and lines. */ -/*===========================================================================*/ -/* RETURN: TRUE, FALSE */ -/*===========================================================================*/ -extern "C" BOOL CreateHAL( PMESAD3DSHARED pShared ) -{ - PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; - DDSURFACEDESC2 ddsd2; - D3DDEVICEDESC D3DSWDevDesc; - DDSCAPS2 ddscaps; - DWORD dwCoopFlags, - dwWidth, - dwHeight; - ULONG rc; - - DPF(( DBG_FUNC, "CreateHAL();" )); - -#define InitDDSD2(f) memset( &ddsd2, 0, sizeof(DDSURFACEDESC2) ); \ - ddsd2.dwSize = sizeof( DDSURFACEDESC2 ); \ - ddsd2.dwFlags = f; - - if ( pHAL == NULL ) - return FALSE; - - /* Use the internal rectangle struct. */ - dwWidth = pShared->rectW.right - pShared->rectW.left; - dwHeight = pShared->rectW.bottom - pShared->rectW.top; - - DPF(( DBG_CNTX_INFO, "Width: %d Height: %d", dwWidth, dwHeight )); - - /* The dimensions might still be the same so just leave. */ - if ( (dwWidth == pShared->dwWidth) && (dwHeight == pShared->dwHeight) ) - { - DPF(( DBG_CNTX_WARN, "Context size hasn't changed" )); - return TRUE; - } - - /* If one of the dimensions are zero then leave. WM_SIZE should get us back here. */ - if ( (dwWidth == 0) || (dwHeight == 0) ) - return TRUE; - - /* Save the renders dimensions. */ - pShared->dwWidth = dwWidth; - pShared->dwHeight = dwHeight; - - DPF(( DBG_CNTX_INFO, "Creating Context:\n cx:%d cy:%d", pShared->dwWidth, pShared->dwHeight )); - - /*=================================*/ - /* Create all required interfaces. */ - /*=================================*/ - - /* Kill any DDraw stuff if exists. */ - DestroyDevice( pHAL ); - DestroyAllSurfaces( pHAL ); - DestroyInterfaces( pHAL ); - - /* Create a instance of DDraw using the Primary display driver. */ - rc = DirectDrawCreate( NULL, &pHAL->lpDD, NULL ); - if( FAILED(rc) ) - { - RIP( pHAL, "DirectDrawCreate->", ErrorStringD3D(rc) ); - return FALSE; - } - - /* Get the DDraw4 interface. */ - rc = pHAL->lpDD->QueryInterface( IID_IDirectDraw4, (void **)&pHAL->lpDD4 ); - if( FAILED(rc) ) - { - RIP( pHAL, "QueryInterface (IID_IDirectDraw4) ->", ErrorStringD3D(rc) ); - return FALSE; - } - - /* Get the Direct3D3 interface. */ - rc = pHAL->lpDD4->QueryInterface( IID_IDirect3D3, (void **)&pHAL->lpD3D3 ); - if( FAILED(rc) ) - { - RIP( pHAL, "QueryInterface (IID_IDirect3D3) ->", ErrorStringD3D(rc) ); - return FALSE; - } - - /* Set the Cooperative level. NOTE: we need to know if we are FS at this point.*/ - dwCoopFlags = (pShared->bWindow == TRUE) ? DDSCL_NORMAL : (DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); - rc = pHAL->lpDD4->SetCooperativeLevel( pShared->hwnd, dwCoopFlags ); - if ( FAILED(rc) ) - { - RIP( pHAL, "SetCooperativeLevel->", ErrorStringD3D(rc) ); - return FALSE; - } - - /*==================================================================*/ - /* Get the best device we can and note whether its hardware or not. */ - /*==================================================================*/ - pShared->bForceSW = FALSE; - pHAL->lpD3D3->EnumDevices( EnumDeviceHook, (void *)pHAL ); - pShared->bHardware = IsEqualIID( pHAL->guid, IID_IDirect3DHALDevice ); - DPF(( DBG_CNTX_INFO, "bHardware: %s", (pShared->bHardware) ? "TRUE" : "FALSE" )); - DPF(( DBG_CNTX_INFO, "bWindowed: %s", (pShared->bWindow) ? "TRUE" : "FALSE" )); - - /*========================================================================*/ - /* HARDWARE was found. */ - /*========================================================================*/ - if ( pShared->bHardware == TRUE ) - { - /*===================================*/ - /* HARDWARE -> Z-BUFFER. */ - /*===================================*/ - - /* Get a Z-Buffer pixelformat. */ - memset( &ddsd2, 0, sizeof(DDSURFACEDESC2) ); - ddsd2.dwSize = sizeof( DDSURFACEDESC2 ); - rc = pHAL->lpD3D3->EnumZBufferFormats( pHAL->guid, EnumZBufferHook, (VOID*)&ddsd2.ddpfPixelFormat ); - if ( FAILED(rc) ) - { - RIP( pHAL, "EnumZBufferFormatsl->", ErrorStringD3D(rc) ); - return FALSE; - } - - /* Setup our request structure for the Z-buffer surface. */ - ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; - ddsd2.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY; - ddsd2.dwWidth = dwWidth; - ddsd2.dwHeight = dwHeight; - rc = pHAL->lpDD4->CreateSurface( &ddsd2, &pHAL->lpDDSZbuffer, NULL ); - if ( !FAILED(rc) ) - { - DPF(( DBG_CNTX_INFO, "HW ZBuffer" )); - - /*===================================*/ - /* HARDWARE -> Z-BUFFER -> FLIPABLE */ - /*===================================*/ - if ( pShared->bWindow == FALSE ) - { - InitDDSD2( DDSD_CAPS | DDSD_BACKBUFFERCOUNT ); - ddsd2.dwBackBufferCount = 1; - ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; - rc = pHAL->lpDD4->CreateSurface( &ddsd2, &pHAL->lpDDSPrimary, NULL ); - if ( FAILED(rc) ) - { - /* Make sure we try the next fall back. */ - DPF(( DBG_CNTX_WARN, "HW Flip/Complex not available" )); - pHAL->lpDDSPrimary = NULL; - } - else - { - /* Get the back buffer that was created. */ - ddscaps.dwCaps = DDSCAPS_BACKBUFFER; - rc = pHAL->lpDDSPrimary->GetAttachedSurface( &ddscaps, &pHAL->lpDDSRender ); - if ( FAILED(rc) ) - { - DPF(( DBG_CNTX_WARN, "GetAttachedSurface failed -> HW Flip/Complex" )); - - /* Make sure we try the next fall back. */ - pHAL->lpDDSPrimary->Release(); - pHAL->lpDDSPrimary = NULL; - } - else - { - /* I have had problems when a complex surface comes back */ - /* with the back buffer being created in SW. Not sure why */ - /* or how this is possable but I'm checking for it here. */ - memset( &ddsd2, 0, sizeof(DDSURFACEDESC2) ); - ddsd2.dwSize = sizeof( DDSURFACEDESC2 ); - DX_RESTORE( pHAL->lpDDSRender ); - rc = pHAL->lpDDSRender->GetSurfaceDesc( &ddsd2 ); - if ( FAILED(rc) ) - { - RIP( pHAL, "GetSurfaceDesc (RENDER) ->", ErrorStringD3D(rc) ); - return FALSE; - } - - /* If the surface is in VID then we are happy with are Flipable. */ - if ( ddsd2.ddsCaps.dwCaps & DDSCAPS_LOCALVIDMEM ) - { - pShared->bFlipable = TRUE; - DPF(( DBG_CNTX_INFO, "HW Flip/Complex!" )); - } - else - { - /* Kill this setup. */ - pHAL->lpDDSPrimary->Release(); - pHAL->lpDDSPrimary = NULL; - } - } - } - } - - /*===================================*/ - /* HARDWARE -> Z-BUFFER -> BLT */ - /*===================================*/ - if ( pHAL->lpDDSPrimary == NULL ) - { - pShared->bFlipable = FALSE; - - /* Create the Primary (front buffer). */ - InitDDSD2( DDSD_CAPS ); - ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - rc = pHAL->lpDD4->CreateSurface( &ddsd2, &pHAL->lpDDSPrimary, NULL ); - if ( FAILED(rc) ) - { - /* This is an error as we should be able to do this at minimum. */ - RIP( pHAL, "CreateSurface (PRIMARY) ->", ErrorStringD3D(rc) ); - return FALSE; - } - - /* Create the Render (back buffer). */ - InitDDSD2( DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT ); - ddsd2.dwWidth = dwWidth; - ddsd2.dwHeight = dwHeight; - ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE; - rc = pHAL->lpDD4->CreateSurface( &ddsd2, &pHAL->lpDDSRender, NULL ); - if ( FAILED(rc) ) - { - DPF(( DBG_CNTX_WARN, "Failed HW Offscreen surface" )); - - /* Make sure we try the next fall back. */ - pHAL->lpDDSPrimary->Release(); - pHAL->lpDDSPrimary = NULL; - } - else - { - /* Might as well check here too see if this surface is in */ - /* hardware. If nothing else just to be consistant. */ - memset( &ddsd2, 0, sizeof(DDSURFACEDESC2) ); - ddsd2.dwSize = sizeof( DDSURFACEDESC2 ); - DX_RESTORE( pHAL->lpDDSRender ); - rc = pHAL->lpDDSRender->GetSurfaceDesc( &ddsd2 ); - if ( FAILED(rc) ) - { - RIP( pHAL, "GetSurfaceDesc (RENDER) ->", ErrorStringD3D(rc) ); - return FALSE; - } - - /* If the surface is in VID then we are happy. */ - if ( ddsd2.ddsCaps.dwCaps & DDSCAPS_LOCALVIDMEM ) - { - /* Create a clipper object so that DDraw will be able to blt windows that */ - /* have been clipped by the screen or other windows. */ - pHAL->lpDD4->CreateClipper( 0, &pHAL->lpClipper, NULL ); - pHAL->lpClipper->SetHWnd( 0, pShared->hwnd ); - pHAL->lpDDSPrimary->SetClipper( pHAL->lpClipper ); - pHAL->lpClipper->Release(); - DPF(( DBG_CNTX_INFO, "HW RENDER surface" )); - } - else - { - /* Kill this setup. */ - pHAL->lpDDSRender->Release(); - pHAL->lpDDSRender = NULL; - pHAL->lpDDSPrimary->Release(); - pHAL->lpDDSPrimary = NULL; - } - } - } - - /*===================================*/ - /* Create D3DDEVICE -> HARDWARE. */ - /*===================================*/ - if ( pHAL->lpDDSZbuffer && pHAL->lpDDSPrimary && pHAL->lpDDSRender ) - { - DX_RESTORE( pHAL->lpDDSRender ); - DX_RESTORE( pHAL->lpDDSZbuffer ); - - rc = pHAL->lpDDSRender->AddAttachedSurface( pHAL->lpDDSZbuffer ); - if ( FAILED(rc) ) - { - RIP( pHAL, "AddAttachedSurface (ZBUFFER) ->", ErrorStringD3D(rc) ); - return FALSE; - } - - rc = pHAL->lpD3D3->CreateDevice( IID_IDirect3DHALDevice, pHAL->lpDDSRender, &pHAL->lpD3DDevice, NULL ); - if ( rc != D3D_OK ) - { - DPF(( DBG_CNTX_WARN, "Failed HW Device" )); - pHAL->lpD3DDevice = NULL; - } - else - { - DPF(( DBG_CNTX_INFO, "HW Device" )); - } - } - } - } - - /*========================================================================*/ - /* SOFTWARE fallback. */ - /*========================================================================*/ - if ( pHAL->lpD3DDevice == NULL ) - { - DPF(( DBG_CNTX_INFO, "SW fallback :(" )); - - /* Make sure we have no surfaces allocated. Just incase. */ - DestroyAllSurfaces( pHAL ); - - /* Get a software device. */ - pShared->bFlipable = FALSE; - pShared->bForceSW = TRUE; - pHAL->lpD3D3->EnumDevices( EnumDeviceHook, (void *)pHAL ); - pShared->bHardware = IsEqualIID( pHAL->guid, IID_IDirect3DHALDevice ); - - /*===================================*/ - /* SOFTWARE -> Z-BUFFER. */ - /*===================================*/ - - /*===================================*/ - /* SOFTWARE -> Z-BUFFER -> FLIPABLE */ - /*===================================*/ - if ( pShared->bWindow == FALSE ) - { - InitDDSD2( DDSD_CAPS | DDSD_BACKBUFFERCOUNT ); - ddsd2.dwBackBufferCount = 1; - ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; - ddsd2.ddpfPixelFormat.dwSize = sizeof( DDPIXELFORMAT ); - ddsd2.ddpfPixelFormat.dwFlags = (DDPF_RGB | DDPF_ALPHAPIXELS); - rc = pHAL->lpDD4->CreateSurface( &ddsd2, &pHAL->lpDDSPrimary, NULL ); - if ( FAILED(rc) ) - { - DPF(( DBG_CNTX_WARN, "Failed SW Flip/Complex" )); - - /* Make sure we try the next fall back. */ - pHAL->lpDDSPrimary = NULL; - } - else - { - ddscaps.dwCaps = DDSCAPS_BACKBUFFER; - rc = pHAL->lpDDSPrimary->GetAttachedSurface( &ddscaps, &pHAL->lpDDSRender ); - if ( FAILED(rc) ) - { - /* Make sure we try the next fall back. */ - DPF(( DBG_CNTX_WARN, "GetAttachedSurface failed -> SW Flip/Complex" )); - pHAL->lpDDSPrimary->Release(); - pHAL->lpDDSPrimary = NULL; - } - else - { - DPF(( DBG_CNTX_INFO, "SW Flip/Complex" )); - pShared->bFlipable = TRUE; - } - } - } - - /*===================================*/ - /* SOFTWARE -> Z-BUFFER -> BLT */ - /*===================================*/ - if ( pHAL->lpDDSPrimary == NULL ) - { - /* Create the Primary (front buffer). */ - InitDDSD2( DDSD_CAPS ); - ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - rc = pHAL->lpDD4->CreateSurface( &ddsd2, &pHAL->lpDDSPrimary, NULL ); - if ( FAILED(rc) ) - { - /* This is an error as we should be able to do this at minimum. */ - RIP( pHAL, "CreateSurface (PRIMARY) ->", ErrorStringD3D(rc) ); - return FALSE; - } - - /* Create the Render (back buffer). */ - InitDDSD2( DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT ); - ddsd2.dwWidth = dwWidth; - ddsd2.dwHeight = dwHeight; - ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE; - ddsd2.ddpfPixelFormat.dwSize = sizeof( DDPIXELFORMAT ); - ddsd2.ddpfPixelFormat.dwFlags = (DDPF_RGB | DDPF_ALPHAPIXELS); - rc = pHAL->lpDD4->CreateSurface( &ddsd2, &pHAL->lpDDSRender, NULL ); - if ( FAILED(rc) ) - { - /* That was our last hope. */ - RIP( pHAL, "CreateSurface (RENDER) ->", ErrorStringD3D(rc) ); - return FALSE; - } - else - { - DPF(( DBG_CNTX_INFO, "SW RENDER surface" )); - - /* Create a clipper object so that DDraw will be able to blt windows that */ - /* have been clipped by the screen or other windows. */ - pHAL->lpDD4->CreateClipper( 0, &pHAL->lpClipper, NULL ); - pHAL->lpClipper->SetHWnd( 0, pShared->hwnd ); - pHAL->lpDDSPrimary->SetClipper( pHAL->lpClipper ); - pHAL->lpClipper->Release(); - } - } - - /*===================================*/ - /* Create D3DDEVICE -> SOFTWARE. */ - /*===================================*/ - if ( pHAL->lpDDSPrimary && pHAL->lpDDSRender ) - { - DX_RESTORE( pHAL->lpDDSRender ); - rc = pHAL->lpD3D3->CreateDevice( IID_IDirect3DRGBDevice, pHAL->lpDDSRender, &pHAL->lpD3DDevice, NULL ); - if ( rc != D3D_OK ) - { - /* That was our last hope. */ - RIP( pHAL, "CreateDevice (IID_IDirect3DRGBDevice) ->", ErrorStringD3D(rc) ); - return FALSE; - } - - DPF(( DBG_CNTX_INFO, "SW Device" )); - } - } - - /*==============================================================================*/ - /* Get a copy of the render pixelformat so that wgl.c can call GetPixelInfoD3D. */ - /*==============================================================================*/ - memset( &pHAL->ddpf, 0, sizeof(DDPIXELFORMAT) ); - pHAL->ddpf.dwSize = sizeof( DDPIXELFORMAT ); - rc = pHAL->lpDDSRender->GetPixelFormat( &pHAL->ddpf ); - if ( FAILED(rc) ) - { - RIP( pHAL, "GetPixelFormat ->", ErrorStringD3D(rc) ); - return FALSE; - } - DebugPixelFormat( "Using OFFSCREEN", &pHAL->ddpf ); - DebugPixelFormat( "Using ZBUFFER", &ddsd2.ddpfPixelFormat ); - - /* Get a copy of what the D3DDevice supports for later use. */ - memset( &D3DSWDevDesc, 0, sizeof(D3DDEVICEDESC) ); - memset( &pHAL->D3DHWDevDesc, 0, sizeof(D3DDEVICEDESC) ); - D3DSWDevDesc.dwSize = sizeof( D3DDEVICEDESC ); - pHAL->D3DHWDevDesc.dwSize = sizeof( D3DDEVICEDESC ); - rc = pHAL->lpD3DDevice->GetCaps( &pHAL->D3DHWDevDesc, &D3DSWDevDesc ); - if ( FAILED(rc) ) - { - RIP( pHAL, "GetCaps ->", ErrorStringD3D(rc) ); - return FALSE; - } - - /* Get a copy of the pixel convertion stuff for direct buffer access. */ - Solve8BitChannelPixelFormat( &pHAL->ddpf, &pShared->pixel ); - AlphaBlendTableHAL( pHAL ); - - /* We must prime the Begin/End scene for SwapBuffers to work. */ - rc = pHAL->lpD3DDevice->BeginScene(); - if ( FAILED(rc) ) - { - RIP( pHAL, "BeginScene ->", ErrorStringD3D(rc) ); - return FALSE; - } - -#undef InitDDSD2 - - return TRUE; -} -/*===========================================================================*/ -/* This function will make sure a viewport is created and set for the device*/ -/* in the supplied structure. If a rect is supplied then it will be used for*/ -/* the viewport otherwise the current setting in the strucute will be used. */ -/* Note that the rect is relative to the window. So left/top must be 0,0 to */ -/* use the whole window else there is scissoring going down. */ -/*===========================================================================*/ -/* RETURN: TRUE, FALSE. */ -/*===========================================================================*/ -extern "C" BOOL SetViewportHAL( PMESAD3DSHARED pShared, RECT *pRect, float minZ, float maxZ ) -{ - PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; - D3DVIEWPORT2 vdData; - ULONG rc; - POINT pt; - - DPF(( DBG_FUNC, "SetViewportHAL();" )); - - /* Make sure we have enough info. */ - if ( !pHAL || !pHAL->lpDDSPrimary || !pHAL->lpD3DDevice ) - { - DPF(( DBG_CNTX_WARN, "SetViewport() -> NULL Pointer" )); - return FALSE; - } - - /* TODO: this is just a temp fix to stop redundant changes. */ - if ( pRect && - (pShared->rectV.left == pRect->left) && - (pShared->rectV.right == pRect->right) && - (pShared->rectV.top == pRect->top) && - (pShared->rectV.bottom == pRect->bottom) ) - { - DPF(( DBG_CNTX_WARN, "Redundant viewport" )); - return TRUE; - } - - DPF(( DBG_CNTX_INFO, "Current Viewport:" )); - DPF(( DBG_CNTX_INFO, "x: %d y: %d", pShared->rectV.left, pShared->rectV.top )); - DPF(( DBG_CNTX_INFO, "cx: %d cy: %d", (pShared->rectV.right-pShared->rectV.left), (pShared->rectV.bottom-pShared->rectV.top) )); - DPF(( DBG_CNTX_INFO, "New Viewport:" )); - DPF(( DBG_CNTX_INFO, "x: %d y: %d", pRect->left, pRect->top )); - DPF(( DBG_CNTX_INFO, "cx: %d cy: %d", (pRect->right-pRect->left), (pRect->bottom-pRect->top) )); - - /* Update the current viewport rect if one is supplied. */ - if ( pRect ) - memcpy( &pShared->rectV, pRect, sizeof(RECT) ); - - /* Build the request structure. */ - memset( &vdData, 0, sizeof(D3DVIEWPORT2) ); - vdData.dwSize = sizeof(D3DVIEWPORT2); - vdData.dwX = pShared->rectV.left; - vdData.dwY = pShared->rectV.top; - vdData.dwWidth = (pShared->rectV.right - pShared->rectV.left); - vdData.dwHeight = (pShared->rectV.bottom - pShared->rectV.top); - - if ( !vdData.dwWidth || !vdData.dwHeight ) - { - GetClientRect( pShared->hwnd, &pShared->rectW ); - pt.x = pt.y = 0; - ClientToScreen( pShared->hwnd, &pt ); - OffsetRect( &pShared->rectW, pt.x, pt.y); - vdData.dwX = pShared->rectW.left; - vdData.dwY = pShared->rectW.top; - vdData.dwWidth = (pShared->rectW.right - pShared->rectW.left); - vdData.dwHeight = (pShared->rectW.bottom - pShared->rectW.top); - memcpy( &pShared->rectV, &pShared->rectW, sizeof(RECT) ); - } - - // The dvClipX, dvClipY, dvClipWidth, dvClipHeight, dvMinZ, - // and dvMaxZ members define the non-normalized post-perspective - // 3-D view volume which is visible to the viewer. In most cases, - // dvClipX is set to -1.0 and dvClipY is set to the inverse of - // the viewport's aspect ratio on the target surface, which can be - // calculated by dividing the dwHeight member by dwWidth. Similarly, - // the dvClipWidth member is typically 2.0 and dvClipHeight is set - // to twice the aspect ratio set in dwClipY. The dvMinZ and dvMaxZ - // are usually set to 0.0 and 1.0. - vdData.dvClipX = -1.0f; - vdData.dvClipWidth = 2.0f; - vdData.dvClipY = 1.0f; - vdData.dvClipHeight = 2.0f; - vdData.dvMaxZ = maxZ; - vdData.dvMinZ = minZ; - - DPF(( DBG_CNTX_INFO, "zMin: %f zMax: %f", minZ, maxZ )); - - /* I'm going to destroy the viewport everytime as when we size we will */ - /* have a new D3DDevice. As this area doesn't need to be fast... */ - if ( pHAL->lpViewport ) - { - DPF(( DBG_CNTX_INFO, "DeleteViewport" )); - - pHAL->lpD3DDevice->DeleteViewport( pHAL->lpViewport ); - rc = pHAL->lpViewport->Release(); - pHAL->lpViewport = NULL; - } - - rc = pHAL->lpD3D3->CreateViewport( &pHAL->lpViewport, NULL ); - if ( rc != D3D_OK ) - { - DPF(( DBG_CNTX_ERROR, "CreateViewport Failed" )); - return FALSE; - } - - /* Update the device with the new viewport. */ - pHAL->lpD3DDevice->AddViewport( pHAL->lpViewport ); - pHAL->lpViewport->SetViewport2( &vdData ); - pHAL->lpD3DDevice->SetCurrentViewport( pHAL->lpViewport ); - - return TRUE; -} -/*===========================================================================*/ -/* */ -/* */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -HRESULT WINAPI EnumSurfacesHook( LPDIRECTDRAWSURFACE4 lpDDS, LPDDSURFACEDESC2 lpDDSDesc, LPVOID pVoid ) -{ - DDSURFACEDESC2 *pddsd2 = (DDSURFACEDESC2 *)pVoid; - - DPF(( DBG_FUNC, "EnumSurfacesHook();" )); - - if ( (lpDDSDesc->ddpfPixelFormat.dwFlags == pddsd2->ddpfPixelFormat.dwFlags) && (lpDDSDesc->ddsCaps.dwCaps == pddsd2->ddsCaps.dwCaps) ) - { - /* Save the pixelformat now so that we know we have one. */ - memcpy( pddsd2, lpDDSDesc, sizeof(DDSURFACEDESC2) ); - - return D3DENUMRET_CANCEL; - } - - return D3DENUMRET_OK; -} -/*===========================================================================*/ -/* This is the callback proc to get a Z-Buffer. Thats it. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -HRESULT CALLBACK EnumZBufferHook( DDPIXELFORMAT* pddpf, VOID *pVoid ) -{ - DDPIXELFORMAT *pddpfChoice = (DDPIXELFORMAT *)pVoid; - - DPF(( DBG_FUNC, "EnumZBufferHook();" )); - - /* If this is ANY type of depth-buffer, stop. */ - if( pddpf->dwFlags == DDPF_ZBUFFER ) - { - /* Save the pixelformat now so that we know we have one. */ - memcpy( pddpfChoice, pddpf, sizeof(DDPIXELFORMAT) ); - - /* I feel if the hardware supports this low then lets use it. Could get ugly. */ - if( pddpf->dwZBufferBitDepth >= 8 ) - { - return D3DENUMRET_CANCEL; - } - } - - return D3DENUMRET_OK; -} -/*===========================================================================*/ -/* This function handles the callback for the D3DDevice enumeration. Good */ -/* god who's idea was this? The D3D wrapper has two variable related to what*/ -/* kind of device we want and have. First we have a Bool that is set if we */ -/* have allocated a HW device. We always look for the HW device first. The */ -/* other variable is used to force SW. If we have run into a case that we */ -/* want to fallback to SW then we set this. We will fallback if we cannot */ -/* texture in video memory (among others). */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -HRESULT CALLBACK EnumDeviceHook( GUID FAR* lpGuid, LPSTR lpDesc, LPSTR lpName, LPD3DDEVICEDESC lpD3DHWDesc, LPD3DDEVICEDESC lpD3DHELDesc, void *pVoid ) -{ - PMESAD3DHAL pHAL = (PMESAD3DHAL)pVoid; - LPD3DDEVICEDESC pChoice = lpD3DHWDesc; - - DPF(( DBG_FUNC, "EnumDeviceHook();" )); - - /* Determine if which device description is valid. */ - if ( pChoice->dcmColorModel == 0 ) - pChoice = lpD3DHELDesc; - - /* Make sure we always have a GUID. */ - memcpy( &pHAL->guid, lpGuid, sizeof(GUID) ); - - /* This controls whether we will except HW or not. */ - if ( pHAL->shared.bForceSW == TRUE ) - { - return (pChoice == lpD3DHELDesc) ? D3DENUMRET_CANCEL : D3DENUMRET_OK; - } - - /* Always try for hardware. */ - if ( pChoice == lpD3DHWDesc ) - { - return D3DENUMRET_CANCEL; - } - - return D3DENUMRET_OK; -} -/*===========================================================================*/ -/* This function will destroy any and all surfaces that this context has */ -/* allocated. If there is a clipper object then it will also be destoryed as*/ -/* it is part of the Primary Surface. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void DestroyAllSurfaces( PMESAD3DHAL pHAL ) -{ - LONG refCount; - - DPF(( DBG_FUNC, "DestroyAllSurfaces();" )); - - DX_RESTORE( pHAL->lpDDSPrimary ); - DX_RESTORE( pHAL->lpDDSRender ); - DX_RESTORE( pHAL->lpDDSZbuffer); - - if ( pHAL->lpDDSRender ) - { - pHAL->lpDDSRender->Unlock( NULL ); - - /* If this isn't a Flipable surface then we must clean up the render. */ - if ( pHAL->shared.bFlipable == FALSE) - { - if ( pHAL->lpDDSZbuffer ) - { - DPF(( DBG_CNTX_INFO, "Remove attached surfaces from RENDER" )); - pHAL->lpDDSRender->DeleteAttachedSurface( 0, NULL ); - } - - DPF(( DBG_CNTX_INFO, "Release RENDER" )); - refCount = pHAL->lpDDSRender->Release(); - pHAL->lpDDSRender = NULL; - } - } - - if ( pHAL->lpDDSZbuffer ) - { - DPF(( DBG_CNTX_INFO, "Release ZBuffer" )); - pHAL->lpDDSZbuffer->Unlock( NULL ); - refCount = pHAL->lpDDSZbuffer->Release(); - pHAL->lpDDSZbuffer = NULL; - } - - if ( pHAL->lpClipper ) - { - DPF(( DBG_CNTX_INFO, "Release Clipper" )); - refCount = pHAL->lpClipper->Release(); - pHAL->lpClipper = NULL; - } - - if ( pHAL->lpDDSPrimary ) - { - pHAL->lpDDSPrimary->Unlock( NULL ); - - DPF(( DBG_CNTX_INFO, "Release PRIMARY" )); - refCount = pHAL->lpDDSPrimary->Release(); - pHAL->lpDDSPrimary = NULL; - } -} -/*===========================================================================*/ -/* This function will destroy the current D3DDevice and any resources that */ -/* belong to it. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void DestroyDevice( PMESAD3DHAL pHAL ) -{ - LONG refCount; - - DPF(( DBG_FUNC, "DestroyDevice();" )); - - /* Kill the D3D stuff if exists. */ - if ( pHAL->lpViewport ) - { - DPF(( DBG_CNTX_INFO, "Delete Viewport" )); - pHAL->lpD3DDevice->DeleteViewport( pHAL->lpViewport ); - - DPF(( DBG_CNTX_INFO, "Release Viewport" )); - refCount = pHAL->lpViewport->Release(); - pHAL->lpViewport = NULL; - } - - if ( pHAL->lpD3DDevice != NULL ) - { - DPF(( DBG_CNTX_INFO, "Release D3DDevice" )); - refCount = pHAL->lpD3DDevice->EndScene(); - refCount = pHAL->lpD3DDevice->Release(); - pHAL->lpD3DDevice = NULL; - } -} -/*===========================================================================*/ -/* This function will destroy the current D3DDevice and any resources that */ -/* belong to it. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void DestroyInterfaces( PMESAD3DHAL pHAL ) -{ - LONG refCount; - - DPF(( DBG_FUNC, "DestroyInterfaces();" )); - - if ( pHAL->lpD3D3 != NULL ) - { - DPF(( DBG_CNTX_INFO, "Release Direct3D3" )); - refCount = pHAL->lpD3D3->Release(); - pHAL->lpD3D3 = NULL; - } - - if ( pHAL->lpDD4 != NULL ) - { - DPF(( DBG_CNTX_INFO, "Release DDraw4" )); - refCount = pHAL->lpDD4->Release(); - pHAL->lpDD4 = NULL; - } - - if ( pHAL->lpDD != NULL ) - { - DPF(( DBG_CNTX_INFO, "Release DDraw" )); - refCount = pHAL->lpDD->Release(); - pHAL->lpDD = NULL; - } -} -/*===========================================================================*/ -/* This function will first send (not post) a message to the client window */ -/* that this context is using. The client will respond by unbinding itself */ -/* and binding the 'default' context. This allows the API to be supported */ -/* until the window can be destroyed. Finally we post the quit message to */ -/* the client in hopes to end the application. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -void FatalShutDown( PMESAD3DHAL pHAL ) -{ - /* Whip this baby in too try and support the API until we die... */ - if ( pHAL ) - SendMessage( pHAL->shared.hwnd, UM_FATALSHUTDOWN, 0L, 0L ); - - /* Close the client application down. */ - PostQuitMessage( 0 ); -} - diff --git a/src/mesa/drivers/d3d/D3DMESA.H b/src/mesa/drivers/d3d/D3DMESA.H deleted file mode 100644 index 71a7cd8aed..0000000000 --- a/src/mesa/drivers/d3d/D3DMESA.H +++ /dev/null @@ -1,84 +0,0 @@ -/*===========================================================================*/ -/* */ -/* Mesa-3.0 DirectX 6 Driver */ -/* */ -/* By Leigh McRae */ -/* */ -/* http://www.altsoftware.com/ */ -/* */ -/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ -/*===========================================================================*/ -#ifndef D3D_MESA_H -#define D3D_MESA_H -/*===========================================================================*/ -/* Includes. */ -/*===========================================================================*/ -#include <windows.h> -#include <ddraw.h> -#include <d3d.h> -#include "matrix.h" -#include "context.h" -#include "mtypes.h" -#include "vb.h" -#include "D3DShared.h" -#include "Debug.h" -#include "NULLProcs.h" -/*===========================================================================*/ -/* Macros. */ -/*===========================================================================*/ -#define FLIP(h,y) (h-y) -/*===========================================================================*/ -/* Magic numbers. */ -/*===========================================================================*/ -/*===========================================================================*/ -/* Type defines. */ -/*===========================================================================*/ -struct __extensions__ -{ - PROC proc; - char *name; -}; - -typedef GLbitfield (*ClearPROC)( GLcontext *ctx, GLbitfield mask, GLboolean all, GLint x, GLint y, GLint width, GLint height ); -typedef void (*WSpanRGBPROC)( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte rgb[][3], const GLubyte mask[] ); -typedef void (*WSpanRGBAPROC)( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte rgba[][4], const GLubyte mask[] ); -typedef void (*WSpanRGBAMonoPROC)( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte mask[] ); -typedef void (*WPixelsRGBAPROC)( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte rgba[][4], const GLubyte mask[] ); -typedef void (*WPixelsRGBAMonoPROC)( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte mask[] ); -typedef void (*RSpanRGBAPROC)( const GLcontext* ctx, GLuint n, GLint x, GLint y, GLubyte rgba[][4] ); -typedef void (*RPixelsRGBAPROC)( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], GLubyte rgba[][4], const GLubyte mask[] ); - -typedef struct D3D_mesa_context -{ - PMESAD3DSHARED pShared; - - GLcontext *gl_ctx; /* The core GL/Mesa context */ - GLvisual *gl_visual; /* Describes the buffers */ - GLframebuffer *gl_buffer; /* Depth, stencil, accum, etc buffers */ - - HDC hdc; - WNDPROC hOldProc; - - UCHAR rClear, /* Current clear colors. */ - gClear, - bClear, - aClear, - rCurrent, /* Current rendering colors. */ - gCurrent, - bCurrent, - aCurrent; - - struct D3D_mesa_context *next; - -} D3DMESACONTEXT, *PD3DMESACONTEXT; -/*===========================================================================*/ -/* Extern function prototypes. */ -/*===========================================================================*/ -extern void gl_Viewport( GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height ); -/*===========================================================================*/ -/* Global variables. */ -/*===========================================================================*/ -extern D3DTLVERTEX D3DTLVertices[(VB_MAX*6)]; - -#endif - diff --git a/src/mesa/drivers/d3d/D3DRaster.cpp b/src/mesa/drivers/d3d/D3DRaster.cpp deleted file mode 100644 index 41e42ad94c..0000000000 --- a/src/mesa/drivers/d3d/D3DRaster.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/*===========================================================================*/ -/* */ -/* Mesa-3.0 DirectX 6 Driver */ -/* */ -/* By Leigh McRae */ -/* */ -/* http://www.altsoftware.com/ */ -/* */ -/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ -/*===========================================================================*/ -#include "D3DHAL.h" -/*===========================================================================*/ -/* This function clears the context bound to the supplied shared context. */ -/* The function takes the D3D flags D3DCLEAR_TARGET, D3DCLEAR_STENCIL and */ -/* D3DCLEAR_ZBUFFER. Set bAll to TRUE for a full clear else supply the coord*/ -/* of the rect to be cleared relative to the window. The color is always a */ -/* 32bit value (RGBA). Fill in the z-value and stencil if needed. */ -/* */ -/* TODO: this can be redone to be called by Mesa directly. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -extern "C" void ClearHAL( PMESAD3DSHARED pShared, DWORD dwFlags, BOOL bAll, int x, int y, int cx, int cy, DWORD dwColor, float zv, DWORD dwStencil ) -{ - PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; - D3DRECT d3dRect; - -#ifdef D3D_DEBUG - HRESULT rc; - - DPF(( DBG_FUNC, "CleaHAL();" )); - - /* Make sure we have enough info. */ - if ( (pHAL == NULL) || (pHAL->lpViewport == NULL) ) - return; -#endif - - if ( bAll ) - { - /* I assume my viewport is valid. */ - d3dRect.lX1 = pShared->rectV.left; - d3dRect.lY1 = pShared->rectV.top; - d3dRect.lX2 = pShared->rectV.right; - d3dRect.lY2 = pShared->rectV.bottom; - } - else - { - d3dRect.lX1 = pShared->rectV.left + x; - d3dRect.lY1 = pShared->rectV.top + y; - d3dRect.lX2 = d3dRect.lX1 + cx; - d3dRect.lY2 = d3dRect.lY1 + cy; - } - -#ifdef D3D_DEBUG - rc = pHAL->lpViewport->Clear2( 1, &d3dRect, dwFlags, dwColor, zv, dwStencil ); - if ( FAILED(rc) ) - { - RIP( pHAL, "Clear2 ->", ErrorStringD3D(rc) ); - } -#else - pHAL->lpViewport->Clear2( 1, &d3dRect, dwFlags, dwColor, zv, dwStencil ); -#endif -} -/*===========================================================================*/ -/* Well this is the guts of it all. Here we rasterize the primitives that */ -/* are in their final form. OpenGL has done all the lighting, transfomations*/ -/* and clipping at this point. */ -/* */ -/* TODO: I'm not sure if I want to bother to check for errors on this call. */ -/* The overhead kills me... */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -extern "C" void DrawPrimitiveHAL( PMESAD3DSHARED pShared, D3DPRIMITIVETYPE dptPrimitiveType, D3DTLVERTEX *pVertices, DWORD dwCount ) -{ - PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; - -#ifdef D3D_DEBUG - HRESULT rc; - - DPF(( DBG_FUNC, "DrawPrimitveHAL();" )); - - /* Make sure we have enough info. */ - if ( (pHAL == NULL) || (pHAL->lpD3DDevice == NULL) ) - return; - - DPF(( DBG_PRIM_INFO, "DP( %d )", dwCount )); - - rc = pHAL->lpD3DDevice->DrawPrimitive( dptPrimitiveType, - D3DFVF_TLVERTEX, - (LPVOID)pVertices, - dwCount, - (D3DDP_DONOTCLIP | D3DDP_DONOTLIGHT) ); - if ( FAILED(rc) ) - { - RIP( pHAL, "DrawPrimitive ->", ErrorStringD3D(rc) ); - } -#else - pHAL->lpD3DDevice->DrawPrimitive( dptPrimitiveType, - D3DFVF_TLVERTEX, - (LPVOID)pVertices, - dwCount, - (D3DDP_DONOTCLIP | D3DDP_DONOTLIGHT) ); -#endif -} -/*===========================================================================*/ -/* This call will handle the swapping of the buffers. Now I didn't bother */ -/* to support single buffered so this will be used for glFlush() as its all */ -/* the same. So first we do an EndScene as we are always considered to be in*/ -/* a BeginScene because when we leave we do a BeginScene. Now note that when*/ -/* the context is created in the first place we do a BeginScene also just to */ -/* get things going. The call will use either Flip/blt based on the type of */ -/* surface was created for rendering. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -extern "C" void SwapBuffersHAL( PMESAD3DSHARED pShared ) -{ - PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; - -#ifdef D3D_DEBUG - HRESULT rc; - - DPF(( DBG_FUNC, "SwapBuffersHAL();" )); - DPF(( DBG_ALL_PROFILE, "=================SWAP===================" )); - - /* Make sure we have enough info. */ - if ( (pHAL == NULL) || (pHAL->lpD3DDevice == NULL) ) - return; - - /* Make sure we have enough info. */ - if ( pHAL->lpDDSPrimary != NULL ) - { - rc = pHAL->lpD3DDevice->EndScene(); - if ( FAILED(rc) ) - { - RIP( pHAL, "EndScene ->", ErrorStringD3D(rc) ); - } - - if ( pShared->bFlipable ) - { - DPF(( DBG_CNTX_PROFILE, "Swap->FLIP" )); - rc = pHAL->lpDDSPrimary->Flip( NULL, DDFLIP_WAIT ); - } - else - { - DPF(( DBG_CNTX_PROFILE, "Swap->Blt" )); - rc = pHAL->lpDDSPrimary->Blt( &pShared->rectW, pHAL->lpDDSRender, NULL, DDBLT_WAIT, NULL ); - } - if ( FAILED(rc) ) - { - RIP( pHAL, "Blt (RENDER/PRIMARY) ->", ErrorStringD3D(rc) ); - } - - rc = pHAL->lpD3DDevice->BeginScene(); - if ( FAILED(rc) ) - { - RIP( pHAL, "BeginScene ->", ErrorStringD3D(rc) ); - } - } -#else - pHAL->lpD3DDevice->EndScene(); - - if ( pShared->bFlipable ) - pHAL->lpDDSPrimary->Flip( NULL, DDFLIP_WAIT ); - else - pHAL->lpDDSPrimary->Blt( &pShared->rectW, pHAL->lpDDSRender, NULL, DDBLT_WAIT, NULL ); - - pHAL->lpD3DDevice->BeginScene(); - -#endif -} -/*===========================================================================*/ -/* This function is a very thin wrapper for the D3D call 'SetRenderState'. */ -/* Using this function requires all the types to be defined by including the */ -/* D3D header file. */ -/* */ -/* TODO: would be much better to get ride of all these calls per VBRender. */ -/* I feel I should get this call into SetRenderStates() the RenderVB. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -extern "C" void SetStateHAL( PMESAD3DSHARED pShared, DWORD dwType, DWORD dwState ) -{ - PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; - -#ifdef D3D_DEBUG - HRESULT rc; - - DPF(( DBG_FUNC, "SetStateHAL();" )); - - /* Make sure we have enough info. */ - if ( (pHAL == NULL) || (pHAL->lpD3DDevice == NULL) ) - return; - - rc = pHAL->lpD3DDevice->SetRenderState( (D3DRENDERSTATETYPE)dwType, dwState ); - if ( FAILED(rc) ) - { - RIP( pHAL, "SetRenderState ->", ErrorStringD3D(rc) ); - } - -#else - pHAL->lpD3DDevice->SetRenderState( (D3DRENDERSTATETYPE)dwType, dwState ); -#endif -} - - - - - - - - diff --git a/src/mesa/drivers/d3d/D3DShared.h b/src/mesa/drivers/d3d/D3DShared.h deleted file mode 100644 index cc629e2111..0000000000 --- a/src/mesa/drivers/d3d/D3DShared.h +++ /dev/null @@ -1,154 +0,0 @@ -/*===========================================================================*/ -/* */ -/* Mesa-3.0 DirectX 6 Driver */ -/* */ -/* By Leigh McRae */ -/* */ -/* http://www.altsoftware.com/ */ -/* */ -/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ -/*===========================================================================*/ -#ifndef D3D_MESA_ALL_H -#define D3D_MESA_ALL_H - -#ifdef __cplusplus -extern "C" { -#endif - -/*===========================================================================*/ -/* Includes. */ -/*===========================================================================*/ -#include <stdio.h> -#include <string.h> -/*===========================================================================*/ -/* Magic numbers. */ -/*===========================================================================*/ -#define TM_ACTION_LOAD 0x01 -#define TM_ACTION_BIND 0x02 -#define TM_ACTION_UPDATE 0x04 - -#define UM_FATALSHUTDOWN (WM_USER+42) -/*===========================================================================*/ -/* Macros defines. */ -/*===========================================================================*/ -#define ALLOC(cb) malloc( (cb) ) -#define FREE(p) { free( (p) ); (p) = NULL; } -/*===========================================================================*/ -/* Type defines. */ -/*===========================================================================*/ -typedef struct _pixel_convert -{ - int cb, /* Count in bytes of one pixel. */ - rShift, /* Shift count that postions each componet. */ - gShift, - bShift, - aShift; - float rScale, /* Value that scales a color that ranges 0.0 -> 1.0 */ - gScale, /* to this pixel format. */ - bScale, - aScale; - DWORD dwRMask, /* Color mask per component. */ - dwGMask, - dwBMask, - dwAMask; - -} PIXELINFO, *PPIXELINFO; - - -typedef struct _d3d_shared_info -{ - HWND hwnd; - BOOL bWindow, - bFlipable, - bForceSW, - bHardware; - RECT rectW, /* Window size and postion in screen space. */ - rectV; /* Viewport size and postion. */ - DWORD dwWidth, /* Current render size for quick checks. */ - dwHeight; - - PIXELINFO pixel; - DWORD dwSrcBlendCaps[14], /* See D3DCAPS.CPP */ - dwDestBlendCaps[14], - dwTexFunc[4]; - -} MESAD3DSHARED, *PMESAD3DSHARED; - -typedef struct _render_options -{ - BOOL bForceSoftware, /* TODO: Add user switches. */ - bStretchtoPrimary; - -} USER_CTRL, *PUSER_CRTL; - -enum { s_zero = 0, - s_one, - s_dst_color, - s_one_minus_dst_color, - s_src_alpha, - s_one_minus_src_alpha, - s_dst_alpha, - s_one_minus_dst_alpha, - s_src_alpha_saturate, - s_constant_color, - s_one_minus_constant_color, - s_constant_alpha, - s_one_minus_constant_alpha }; - -enum { d_zero = 0, - d_one, - d_src_color, - d_one_minus_src_color, - d_src_alpha, - d_one_minus_src_alpha, - d_dst_alpha, - d_one_minus_dst_alpha, - d_constant_color, - d_one_minus_constant_color, - d_constant_alpha, - d_one_minus_constant_alpha }; - -enum { d3dtblend_decal = 0, - d3dtblend_decalalpha, - d3dtblend_modulate, - d3dtblend_modulatealpha }; - -/*===========================================================================*/ -/* Function prototypes. */ -/*===========================================================================*/ -PMESAD3DSHARED InitHAL( HWND hwnd ); -void TermHAL( PMESAD3DSHARED pShared ); -BOOL CreateHAL( PMESAD3DSHARED pShared ); -BOOL SetViewportHAL( PMESAD3DSHARED pShared, RECT *pRect, float minZ, float maxZ ); - -void ClearHAL( PMESAD3DSHARED pShared, DWORD dwFlags, BOOL bAll, int x, int y, int cx, int cy, DWORD dwColor, float zv, DWORD dwStencil ); -void SetStateHAL( PMESAD3DSHARED pShared, DWORD dwType, DWORD dwState ); -void DrawPrimitiveHAL( PMESAD3DSHARED pShared, D3DPRIMITIVETYPE dptPrimitiveType, D3DTLVERTEX *pVertices, DWORD dwCount ); - -void SwapBuffersHAL( PMESAD3DSHARED pShared ); -DDSURFACEDESC2 *LockHAL( PMESAD3DSHARED pShared, BOOL bBack ); -void UnlockHAL( PMESAD3DSHARED pShared, BOOL bBack ); -void UpdateScreenPosHAL( PMESAD3DSHARED pShared ); -void GetPixelInfoHAL( PMESAD3DSHARED pShared, PPIXELINFO pPixel ); -BOOL CreateTMgrHAL( PMESAD3DSHARED pShared, DWORD dwName, int level, DWORD dwRequestFlags, RECT *rectDirty, DWORD dwWidth, DWORD dwHeight, DWORD dwAction, void *pPixels ); -void DisableTMgrHAL( PMESAD3DSHARED pShared ); - - -int SaveDIBitmap( char *filename, BITMAPINFO *info, void *bits ); -int ARGB_SaveBitmap( char *filename, int width, int height, unsigned char *pARGB ); -int BGRA_SaveBitmap( char *filename, int width, int height, unsigned char *pBGRA ); -int BGR_SaveBitmap( char *filename, int width, int height, unsigned char *pBGR ); -/*===========================================================================*/ -/* Global variables. */ -/*===========================================================================*/ -extern float g_DepthScale, /* Mesa needs to scale Z in SW. The HAL */ - g_MaxDepth; /* doesn't but I wanted SW still to work.*/ - -#ifdef __cplusplus -} -#endif - -#endif - - - diff --git a/src/mesa/drivers/d3d/D3DTEXT.CPP b/src/mesa/drivers/d3d/D3DTEXT.CPP deleted file mode 100644 index 39855b65fa..0000000000 --- a/src/mesa/drivers/d3d/D3DTEXT.CPP +++ /dev/null @@ -1,576 +0,0 @@ -/*===========================================================================*/ -/* */ -/* Mesa-3.0 DirectX 6 Driver */ -/* */ -/* By Leigh McRae */ -/* */ -/* http://www.altsoftware.com/ */ -/* */ -/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ -/*===========================================================================*/ -#include "d3dText.h" - -/*============================================================================= - - 1 - ------ - | | - 6 | | 2 - | 7 | - ------ - | | - 5 | | 3 - | | - ------ - 4 - - TL_0 TR_0 -TLL TL_1 TR_1 TRR - -MLL_0 ML_0 MR_0 MRR_0 -MLL_1 ML_1 MR_1 MRR_1 - -BLL BL_0 BR_0 BRR - BL_1 BR_1 - -=============================================================================*/ - -#define TLL 0 -#define TRR 1 -#define TL_0 2 -#define TL_1 3 -#define TR_0 4 -#define TR_1 5 - -#define MLL_0 6 -#define MLL_1 7 -#define MRR_0 8 -#define MRR_1 9 - -#define ML_0 10 -#define ML_1 11 -#define MR_0 12 -#define MR_1 13 - -#define BL_0 14 -#define BL_1 15 -#define BR_0 16 -#define BR_1 17 -#define BLL 18 -#define BRR 19 - -#define BIT1 0x00000001 -#define BIT2 0x00000002 -#define BIT3 0x00000004 -#define BIT4 0x00000008 -#define BIT5 0x00000010 -#define BIT6 0x00000020 -#define BIT7 0x00000040 - -#define TOP BIT4 -#define MIDDLE BIT7 -#define BOTTOM BIT1 -#define TLEFT BIT5 -#define BLEFT BIT6 -#define LEFT (TLEFT|BLEFT) -#define TRIGHT BIT3 -#define BRIGHT BIT2 -#define RIGHT (TRIGHT|BRIGHT) -#define ALL 0xFFFFFFFF - -/*===========================================================================*/ -/* This is the static array that will map the ASCII value of the character */ -/* being draw to the bit mask that will be scan converted to the LED display.*/ -/*===========================================================================*/ -DWORD textBitMasks[] = -{ - 0xFFFFFFFF, // 000 - 0xFFFFFFFF, // 001 - 0xFFFFFFFF, // 002 - 0xFFFFFFFF, // 003 - 0xFFFFFFFF, // 004 - 0xFFFFFFFF, // 005 - 0xFFFFFFFF, // 006 - 0xFFFFFFFF, // 007 - 0xFFFFFFFF, // 008 - 0xFFFFFFFF, // 009 - 0xFFFFFFFF, // 010 - 0xFFFFFFFF, // 011 - 0xFFFFFFFF, // 012 - 0xFFFFFFFF, // 013 - 0xFFFFFFFF, // 014 - 0xFFFFFFFF, // 015 - 0xFFFFFFFF, // 016 - 0xFFFFFFFF, // 017 - 0xFFFFFFFF, // 018 - 0xFFFFFFFF, // 019 - 0xFFFFFFFF, // 020 - 0xFFFFFFFF, // 021 - 0xFFFFFFFF, // 022 - 0xFFFFFFFF, // 023 - 0xFFFFFFFF, // 024 - 0xFFFFFFFF, // 025 - 0xFFFFFFFF, // 026 - 0xFFFFFFFF, // 027 - 0xFFFFFFFF, // 028 - 0xFFFFFFFF, // 029 - 0xFFFFFFFF, // 030 - 0XFFFFFFFF, // 031 - 0x00000000, // 032 'SPC' - 0xFFFFFFFF, // 033 - 0xFFFFFFFF, // 034 - 0xFFFFFFFF, // 035 - 0xFFFFFFFF, // 036 - 0xFFFFFFFF, // 037 - 0xFFFFFFFF, // 038 - 0xFFFFFFFF, // 039 - 0xFFFFFFFF, // 040 - 0xFFFFFFFF, // 041 - 0xFFFFFFFF, // 042 - 0xFFFFFFFF, // 043 - 0xFFFFFFFF, // 044 - 0xFFFFFFFF, // 045 - 0xFFFFFFFF, // 046 - 0xFFFFFFFF, // 047 - (ALL &~ MIDDLE), // 048 '0' - (RIGHT), // 049 '1' - (ALL &~ TLEFT &~ BRIGHT), // 050 '2' - (ALL &~ LEFT), // 051 '3' - (TLEFT | MIDDLE | RIGHT), // 052 '4' - (ALL &~ TRIGHT &~ BLEFT), // 053 '5' - (ALL &~ TRIGHT), // 054 '6' - (TOP | RIGHT), // 055 '7' - (ALL), // 056 '8' - (ALL &~ BOTTOM &~ BLEFT), // 057 '9' - 0xFFFFFFFF, // 058 - 0xFFFFFFFF, // 059 - 0xFFFFFFFF, // 060 - 0XFFFFFFFF, // 061 - 0xFFFFFFFF, // 062 - 0xFFFFFFFF, // 063 - 0xFFFFFFFF, // 064 - (ALL &~ BOTTOM), // 065 'A' - (ALL), // 066 'B' - (TOP | LEFT | BOTTOM), // 067 'C' - (ALL &~ MIDDLE), // 068 'D' - (ALL &~ RIGHT), // 069 'E' - (LEFT | TOP | MIDDLE), // 070 'F' - 0x00000000, // 071 'G' - (ALL &~ TOP &~ BOTTOM), // 072 'H' - (RIGHT), // 073 'I' - (RIGHT | BOTTOM), // 074 'J' - 0x00000000, // 075 'K' - (LEFT | BOTTOM), // 076 'L' - 0x00000000, // 088 'M' - 0x00000000, // 089 'N' - (ALL &~ MIDDLE), // 090 'O' - (ALL &~ BRIGHT &~ BOTTOM),// 091 'P' - 0x00000000, // 092 'Q' - 0x00000000, // 093 'R' - (ALL &~ TRIGHT &~ BLEFT), // 094 'S' - 0X00000000, // 095 'T' - (LEFT | RIGHT | BOTTOM), // 096 'U' - 0x00000000, // 097 'V' - 0x00000000, // 098 'W' - 0x00000000, // 099 'X' - 0x00000000, // 1000 'Z' - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, // 100 - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, // 104 - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, // 108 - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, // 112 - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, // 116 - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, // 120 - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF // 124 -}; - -#define CT 1.0f -#define CX 7.0f -#define CY 13.0f -#define CM ((CY-(CT*3.0f))/2.0f) - -float lCoords[][2] = -{ - /* Top outsides. */ - { 0, (CY-CT) }, - { CX, (CY-CT) }, - - /* Top Line. */ - { CT, CY }, - { CT, (CY-CT) }, - { (CX-CT), CY }, - { (CX-CT), (CY-CT) }, - - /* Middle outsides. */ - { 0.0f, (CT+CM+CT) }, - { 0.0f, (CT+CM) }, - { CX, (CT+CM+CT) }, - { CX, (CT+CM) }, - - /* Middle Line. */ - { CT, (CT+CM+CT) }, - { CT, (CT+CM) }, - { (CX-CT), (CT+CM+CT) }, - { (CX-CT), (CT+CM) }, - - /* Bottom line. */ - { CT, CT }, - { CT, 0.0f }, - { (CX-CT), CT }, - { (CX-CT), 0.0f }, - - /* Bottom outsides. */ - { 0.0f, CT}, - { CX, CT } -}; - -static int ConvertCharacter( char *c, int cIndex, PD3DFONTMETRICS pfntMetrics ); - -D3DTLVERTEX TextVertices[MAX_VERTICES]; -/*===========================================================================*/ -/* When we attach I will zero out the whole D3D vertex buffer I'm using for */ -/* the text. This way I don't need to set all the redundant values. I also */ -/* set all the oow values to 1 as I will be doing direct rendering. */ -/*===========================================================================*/ -/* RETURN: TRUE, FALSE. */ -/*===========================================================================*/ -extern "C" BOOL InitD3DText( void ) -{ - int index; - - /* Set the D3D Vertex Buffer up once so we don't do redundant changes. */ - memset( &TextVertices[0], 0, sizeof(TextVertices) ); - for( index = 0; index < MAX_VERTICES; index++ ) - TextVertices[index].rhw = D3DVAL( 1.0 ); - - return TRUE; -} -/*===========================================================================*/ -/* This function takes a single character and draw it using the supplied */ -/* fontmetrics structure. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -extern "C" void d3dTextDrawString( char *pszString, int x, int y, PD3DFONTMETRICS pfntMetrics ) -{ - int cIndex, - nIndex, - index; - float cWidth = CX, - cHeight = CY; - - /* Find the max width/height of a character and add the spacing so */ - /* that we can use this value to calculate the x,y of the character.*/ - cWidth = (cWidth * pfntMetrics->fntXScale) + pfntMetrics->fntXSpacing; - cHeight = (cHeight * pfntMetrics->fntYScale) + pfntMetrics->fntYSpacing; - - /* Walk the string. This must be NULL terminated. */ - for( cIndex = 0, nIndex = 0; *pszString; pszString++, cIndex = nIndex, x++ ) - { - /* Convert the character and get the index into the text vertex buffer. */ - nIndex = ConvertCharacter( &pszString[0], cIndex, pfntMetrics ); - if ( (nIndex - cIndex) > 2 ) - { - /* Modify the text vertex buffer based on the fntMetrics structure. */ - for( index = cIndex; index < nIndex; index++ ) - { - /* Scale the character. */ - TextVertices[index].sx *= pfntMetrics->fntXScale; - TextVertices[index].sy *= pfntMetrics->fntYScale; - - /* Move the character. */ - TextVertices[index].sx += (cWidth*x); - TextVertices[index].sy += (cHeight*y); - - /* Set the color. */ - TextVertices[index].color = pfntMetrics->dwColor; - } - } - } - - if ( nIndex < 3 ) - return; - - /* Set the states that slim things down. */ - pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_CULLMODE, D3DCULL_NONE ); - pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID ); - pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ZENABLE, FALSE ); - pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ZWRITEENABLE , FALSE ); - pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ALPHATESTENABLE, FALSE ); - pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, FALSE ); - - /* Blast them baby... */ - pfntMetrics->lpD3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, - D3DFVF_TLVERTEX, - (LPVOID)&TextVertices[0], - nIndex, - (D3DDP_DONOTCLIP | D3DDP_DONOTLIGHT) ); -} -/*===========================================================================*/ -/* This function takes a single character and draw it directly to the screen*/ -/* unsing the supplied fntMetrics structure. The character will be drawn at */ -/* the supplied x,y. The x,y position is relative to the top left and uses */ -/* the spacing in the fntMetrics structure. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -extern "C" void d3dTextDrawCharacter( char *c, int x, int y, PD3DFONTMETRICS pfntMetrics ) -{ - int cIndex = 0, - index; - float cWidth = CX, - cHeight = CY; - - /* Convert the character and get the index into the text vertex buffer. */ - cIndex = ConvertCharacter( c, 0, pfntMetrics ); - if ( cIndex < 3 ) - return; - - /* Find the max width/height of a character and add the spacing so */ - /* that we can use this value to calculate the x,y of the character.*/ - cWidth = (cWidth * pfntMetrics->fntXScale) + pfntMetrics->fntXSpacing; - cHeight = (cHeight * pfntMetrics->fntYScale) + pfntMetrics->fntYSpacing; - - /* Modify the text vertex buffer based on the fntMetrics structure. */ - for( index = 0; index < cIndex; index++ ) - { - /* Scale the character. */ - TextVertices[index].sx *= pfntMetrics->fntXScale; - TextVertices[index].sy *= pfntMetrics->fntYScale; - - /* Move the character. */ - TextVertices[index].sx += (cWidth*x); - TextVertices[index].sy += (cHeight*y); - - /* Set the color. */ - TextVertices[index].color = pfntMetrics->dwColor; - } - - - /* Set the states that slim things down. */ - pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_CULLMODE, D3DCULL_NONE ); - pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID ); - pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ZENABLE, FALSE ); - pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ZWRITEENABLE , FALSE ); - pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ALPHATESTENABLE, FALSE ); - pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, FALSE ); - - /* Blast them baby... */ - pfntMetrics->lpD3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, - D3DFVF_TLVERTEX, - (LPVOID)&TextVertices[0], - cIndex, - (D3DDP_DONOTCLIP | D3DDP_DONOTLIGHT) ); -} -/*===========================================================================*/ -/* This function takes a single character and draw it using the supplied */ -/* fontmetrics structure. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static int ConvertCharacter( char *c, int cIndex, PD3DFONTMETRICS pfntMetrics ) -{ - DWORD asciiChar = (int)(*c); - - /* Handle the TOP line. */ - if ( textBitMasks[asciiChar] & BIT1 ) - { - TextVertices[cIndex].sx = D3DVAL( lCoords[TL_0][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[TL_0][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[TR_0][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[TR_0][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[TR_1][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[TR_1][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[TR_1][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[TR_1][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[TL_1][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[TL_1][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[TL_0][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[TL_0][1] ); - } - - /* Handle the TOP/BOTTOM RIGHT lines. */ - // if ( textBitMasks[index] & (BIT2|BIT3) ) - if ( 1 == 0 ) - { - TextVertices[cIndex].sx = D3DVAL( lCoords[TR_1][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[TR_1][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[TRR][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[TRR][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[BRR][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[BRR][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[BRR][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[BRR][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[BR_0][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[BR_0][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[TR_1][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[TR_1][1] ); - } - else - { - if ( textBitMasks[asciiChar] & BIT2 ) - { - TextVertices[cIndex].sx = D3DVAL( lCoords[TR_1][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[TR_1][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[TRR][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[TRR][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[MRR_0][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[MRR_0][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[MRR_0][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[MRR_0][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[MR_0][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[MR_0][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[TR_1][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[TR_1][1] ); - } - if ( textBitMasks[asciiChar] & BIT3 ) - { - TextVertices[cIndex].sx = D3DVAL( lCoords[MR_1][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[MR_1][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[MRR_1][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[MRR_1][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[BRR][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[BRR][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[BRR][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[BRR][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[BR_0][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[BR_0][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[MR_1][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[MR_1][1] ); - } - } - - /* Handle the TOP/BOTTOM LEFT lines. */ - // if ( textBitMasks[asciiChar] & (BIT5|BIT6) ) - if ( 1 == 0 ) - { - TextVertices[cIndex].sx = D3DVAL( lCoords[TLL][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[TLL][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[TL_1][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[TL_1][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[BL_0][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[BL_0][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[BL_0][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[BL_0][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[BLL][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[BLL][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[TLL][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[TLL][1] ); - } - else - { - if ( textBitMasks[asciiChar] & BIT5 ) - { - TextVertices[cIndex].sx = D3DVAL( lCoords[MLL_1][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[MLL_1][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[ML_1][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[ML_1][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[BL_0][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[BL_0][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[BL_0][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[BL_0][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[BLL][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[BLL][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[MLL_1][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[MLL_1][1] ); - } - if ( textBitMasks[asciiChar] & BIT6 ) - { - TextVertices[cIndex].sx = D3DVAL( lCoords[TLL][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[TLL][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[TL_1][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[TL_1][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[ML_0][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[ML_0][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[ML_0][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[ML_0][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[MLL_0][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[MLL_0][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[TLL][0] ); - TextVertices[cIndex++].sy = D3DVAL( lCoords[TLL][1] ); - } - } - - /* Handle the MIDDLE line. */ - if ( textBitMasks[asciiChar] & BIT7 ) - { - TextVertices[cIndex].sx = D3DVAL( lCoords[ML_0][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[ML_0][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[MR_0][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[MR_0][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[MR_1][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[MR_1][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[MR_1][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[MR_1][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[ML_1][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[ML_1][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[ML_0][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[ML_0][1] ); - } - - /* Handle the BOTTOM line. */ - if ( textBitMasks[asciiChar] & BIT4 ) - { - TextVertices[cIndex].sx = D3DVAL( lCoords[BL_0][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[BL_0][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[BR_0][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[BR_0][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[BR_1][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[BR_1][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[BR_1][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[BR_1][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[BL_1][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[BL_1][1] ); - TextVertices[cIndex].sx = D3DVAL( lCoords[BL_0][0] ); - TextVertices[cIndex++].sy= D3DVAL( lCoords[BL_0][1] ); - } - - return cIndex; -} - -#undef CM -#undef CY -#undef CX -#undef CT - -#undef TLL -#undef TRR -#undef TL_0 -#undef TL_1 -#undef TR_0 -#undef TR_1 - -#undef MLL_0 -#undef MLL_1 -#undef MRR_0 -#undef MRR_1 - -#undef ML_0 -#undef ML_1 -#undef MR_0 -#undef MR_1 - -#undef BL_0 -#undef BL_1 -#undef BR_0 -#undef BR_1 -#undef BLL -#undef BRR - -#undef BIT1 -#undef BIT2 -#undef BIT3 -#undef BIT4 -#undef BIT5 -#undef BIT6 -#undef BIT7 - -#undef TOP -#undef MIDDLE -#undef BOTTOM -#undef TLEFT -#undef BLEFT -#undef LEFT -#undef TRIGHT -#undef BRIGHT -#undef RIGHT -#undef ALL diff --git a/src/mesa/drivers/d3d/D3DTextureMgr.cpp b/src/mesa/drivers/d3d/D3DTextureMgr.cpp deleted file mode 100644 index a6600cab02..0000000000 --- a/src/mesa/drivers/d3d/D3DTextureMgr.cpp +++ /dev/null @@ -1,947 +0,0 @@ -/*===========================================================================*/ -/* */ -/* Mesa-3.0 DirectX 6 Driver */ -/* */ -/* By Leigh McRae */ -/* */ -/* http://www.altsoftware.com/ */ -/* */ -/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ -/*===========================================================================*/ -#include "D3DHAL.h" -/*===========================================================================*/ -/* Local function prototypes. */ -/*===========================================================================*/ -static void UpdateTexture( PTM_OBJECT pTMObj, BOOL bVideo, RECT *pRect, UCHAR *pixels ); -static BOOL LoadTextureInVideo( PMESAD3DHAL pHAL, PTM_OBJECT pTMObj ); -static BOOL FreeTextureMemory( PMESAD3DHAL pHAL, PTM_OBJECT pTMObject ); -static BOOL DestroyTextureObject( PMESAD3DHAL pHAL, PTM_OBJECT pTMObject ); -HRESULT CALLBACK EnumPFHook( LPDDPIXELFORMAT lpDDPixFmt, LPVOID lpContext ); -/*===========================================================================*/ -/* This function will simply set the top of stack to NULL. I only used it */ -/* just incase I want to add something later. */ -/*===========================================================================*/ -/* RETURN: TRUE. */ -/*===========================================================================*/ -BOOL InitTMgrHAL( PMESAD3DHAL pHAL ) -{ - DPF(( DBG_FUNC, "InitTMgrHAL();" )); - - /* Be clean my friend. */ - pHAL->pTMList = NULL; - - return TRUE; -} -/*===========================================================================*/ -/* This function will walk the Texture Managers linked list and destroy all */ -/* surfaces (SYSTEM/VIDEO). The texture objects themselves also will be */ -/* freed. */ -/* NOTE: this is per/context. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -void TermTMgrHAL( PMESAD3DHAL pHAL ) -{ - DPF(( DBG_FUNC, "TermTMgrHAL();" )); - - if ( pHAL && pHAL->pTMList ) - { - /* Destroy the surface and remove the TMO from the stack. */ - while( DestroyTextureObject(pHAL,NULL) ); - - /* Be clean my friend. */ - pHAL->pTMList = NULL; - } -} -/*===========================================================================*/ -/* This function is a HACK as I don't know how I can disable a texture with-*/ -/* out booting it out. Is there know state change? */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -extern "C" void DisableTMgrHAL( PMESAD3DSHARED pShared ) -{ - PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; - - DPF(( DBG_FUNC, "DisableTMgrHAL();" )); - - /* Check too see that we have a valid context. */ - if ( (pHAL == NULL) && (pHAL->lpD3DDevice != NULL) ) - { - DPF(( DBG_TXT_WARN, "Null HAL/Direct3D Device!" )); - return; - } - - // TODO: This is a hack to shut off textures. - pHAL->lpD3DDevice->SetTexture( 0, NULL ); -} -/*===========================================================================*/ -/* This function is the only entry into the TextureManager that Mesa/wgl */ -/* will see. It uses a dwAction to specify what we are doing. I did this as*/ -/* depending on the cards resources the action taken can change. */ -/* When this function is called we will always search the Texture Managers */ -/* linked list (per context remember) and try and find a structure that has */ -/* the same dwName. If we have a match we pull it out of the list and put it*/ -/* at the top of the list (TOL). If we don't find one then we create a struc*/ -/* and put it a TOL. This TOL idea makes for some caching as we will always */ -/* destroy Texture Surfaces from the bottom up... */ -/* All texture objects at this point will create a texture surface in System*/ -/* memory (SMEM). Then we will copy the Mesa texture into the surface using */ -/* the 'pixel' struc to get the translation info. So now this means that all*/ -/* textures that Mesa gives me I will have a Surface with a copy. If Mesa */ -/* changes the texture the I update the surface in (SMEM). */ -/* Now we have a texture struc and a Texture Surface in SMEM. At this point*/ -/* we create another surface on the card (VMEM). Finally we blt from the */ -/* SMEM to the VMEM and set the texture as current. Why do I need two? First*/ -/* this solves square textures. If the cards CAPS is square textures only */ -/* then I change the dimensions of the VMEM surface and the blt solves it for*/ -/* me. Second it saves me from filling D3D textures over and over if the */ -/* card needs to be creating and destroying surfaces because of low memory. */ -/* The surface in SMEM is expected to work always. When a surface has to be*/ -/* created in VMEM then we put it in a loop that tries to create the surface.*/ -/* If we create the surface ok then we brake from the loop. If we fail then */ -/* we will call 'FreeTextureMemory' that will return TRUE/FALSE as to whether*/ -/* memory was freed. If memory was freed then we can try again. If no memory*/ -/* was freed then it just can't fit. */ -/* 'FreeTextureMemory' will find the end of the list and start freeing VMEM */ -/* (never SMEM) surfaces that are not locked. */ -/* BIND - when we bind and there is a texture struct with a texture surface */ -/* in VMEM then we just make it current. If we have a struct and a surface */ -/* in SMEM but no VMEM surface then we create the surface in VMEM and blt */ -/* from the SMEM surface. If we have nothing its just like a creation... */ -/*===========================================================================*/ -/* RETURN: TRUE, FALSE. */ -/*===========================================================================*/ -extern "C" BOOL CreateTMgrHAL( PMESAD3DSHARED pShared, DWORD dwName, int level, DWORD dwRequestFlags, - RECT *rectDirty, DWORD dwWidth, DWORD dwHeight, DWORD dwAction, void *pPixels ) -{ - PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; - PTM_OBJECT pTMObj, - pTemp; - DDSURFACEDESC2 ddsd2; - HRESULT rc; - - - DPF(( DBG_FUNC, "CreateTMgrHAL();" )); - - DPF(( DBG_TXT_INFO, "Texture:" )); - DPF(( DBG_TXT_INFO, "cx: %d cy: %d", dwWidth, dwHeight )); - DPF(( DBG_TXT_INFO, "Rect:" )); - if ( rectDirty ) - { - DPF(( DBG_TXT_INFO, "x0: %d y0: %d", rectDirty->left, rectDirty->top )); - DPF(( DBG_TXT_INFO, "x1: %d y1: %d", rectDirty->right, rectDirty->bottom )); - } - - /* Check too see that we have a valid context. */ - if ( (pHAL == NULL) && (pHAL->lpD3DDevice != NULL) ) - { - DPF(( DBG_TXT_WARN, "Null HAL/Direct3D Device!" )); - return FALSE; - } - - /*=================================================*/ - /* See if we can find this texture object by name. */ - /*=================================================*/ - for( pTMObj = pHAL->pTMList; pTMObj && (pTMObj->dwName != dwName); pTMObj = pTMObj->next ); - - /*=========================================================*/ - /* Allocate a new object if we didn't get a matching name. */ - /*=========================================================*/ - if ( pTMObj == NULL ) - { - pTMObj = (PTM_OBJECT)ALLOC( sizeof(TM_OBJECT) ); - if ( pTMObj == NULL ) - return FALSE; - memset( pTMObj, 0, sizeof(TM_OBJECT) ); - - /* Put the object at the beginning of the list. */ - pTMObj->next = pHAL->pTMList; - if ( pTMObj->next ) - { - pTemp = pTMObj->next; - pTemp->prev = pTMObj; - } - pHAL->pTMList = pTMObj; - } - else - { - /*===============================================================*/ - /* Make some caching happen by pulling this object to the front. */ - /*===============================================================*/ - if ( pHAL->pTMList != pTMObj ) - { - /* Pull the object out of the list. */ - if ( pTMObj->prev ) - { - pTemp = pTMObj->prev; - pTemp->next = pTMObj->next; - } - if ( pTMObj->next ) - { - pTemp = pTMObj->next; - pTemp->prev = pTMObj->prev; - } - - pTMObj->prev = NULL; - pTMObj->next = NULL; - - /* Put the object at the front of the list. */ - pTMObj->next = pHAL->pTMList; - if ( pTMObj->next ) - { - pTemp = pTMObj->next; - pTemp->prev = pTMObj; - } - pHAL->pTMList = pTMObj; - } - } - - /*========================================================*/ - /* If we are doing BIND and the texture is in VID memory. */ - /*========================================================*/ - if ( (dwAction == TM_ACTION_BIND) && pTMObj->lpDDS_Video ) - { - DPF(( DBG_TXT_PROFILE, "Cache HIT (%d)", dwName )); - - /* Make this the current texture. */ - rc = pHAL->lpD3DDevice->SetTexture( 0, pTMObj->lpD3DTexture2 ); - if ( FAILED(rc) ) - { - DPF(( DBG_TXT_WARN, "Failed SetTexture() (%s)", ErrorStringD3D(rc) )); - pHAL->lpD3DDevice->SetTexture( 0, NULL ); - return FALSE; - } - - return TRUE; - } - - /*=================================================================*/ - /* If we are doing BIND and the texture is at least in SYS memory. */ - /*=================================================================*/ - if ( (dwAction == TM_ACTION_BIND) && pTMObj->lpDDS_System ) - { - DPF(( DBG_TXT_PROFILE, "Cache MISS (%d)", dwName )); - - /* Create the texture on the card. */ - rc = LoadTextureInVideo( pHAL, pTMObj ); - if ( rc == FALSE ) - return FALSE; - - /* Make this the current texture. */ - rc = pHAL->lpD3DDevice->SetTexture( 0, pTMObj->lpD3DTexture2 ); - if ( FAILED(rc) ) - { - DPF(( DBG_TXT_WARN, "Failed SetTexture() (%s)", ErrorStringD3D(rc) )); - pHAL->lpD3DDevice->SetTexture( 0, NULL ); - return FALSE; - } - - return TRUE; - } - - /*=========================================================*/ - /* If we are doing UPDATE then try in VID first for speed. */ - /*=========================================================*/ - if ( (dwAction == TM_ACTION_UPDATE) && pTMObj->lpDDS_Video && - !(pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY) ) - { - DPF(( DBG_TXT_INFO, "Fix the SubTexture update Leigh!" )); - - /* Update the texture on the card. */ - UpdateTexture( pTMObj, TRUE, rectDirty, (UCHAR *)pPixels ); - - /* We updated the texture in VID so kill the SYS so we know its dirty. */ - if ( pTMObj->lpDDS_System ) - { - DPF(( DBG_TXT_INFO, "Release texture (SYS)" )); - DX_RESTORE( pTMObj->lpDDS_System ); - pTMObj->lpDDS_System->Release(); - pTMObj->lpDDS_System = NULL; - } - - /* Make this the current texture. */ - rc = pHAL->lpD3DDevice->SetTexture( 0, pTMObj->lpD3DTexture2 ); - if ( FAILED(rc) ) - { - DPF(( DBG_TXT_WARN, "Failed SetTexture() (%s)", ErrorStringD3D(rc) )); - pHAL->lpD3DDevice->SetTexture( 0, NULL ); - return FALSE; - } - - return TRUE; - } - - /*===========================================================*/ - /* If we are doing UPDATE then try in SYS still gives speed. */ - /*===========================================================*/ - if ( (dwAction == TM_ACTION_UPDATE) && pTMObj->lpDDS_System ) - { - DPF(( DBG_TXT_INFO, "Fix the SubTexture update Leigh!" )); - - /* Update the texture in SYS. */ - UpdateTexture( pTMObj, FALSE, NULL, (UCHAR *)pPixels ); - - /* We updated the SYS texture only so now blt to the VID. */ - rc = LoadTextureInVideo( pHAL, pTMObj ); - if ( rc == FALSE ) - return FALSE; - - /* Make this the current texture. */ - rc = pHAL->lpD3DDevice->SetTexture( 0, pTMObj->lpD3DTexture2 ); - if ( FAILED(rc) ) - { - DPF(( DBG_TXT_WARN, "Failed SetTexture() (%s)", ErrorStringD3D(rc) )); - pHAL->lpD3DDevice->SetTexture( 0, NULL ); - return FALSE; - } - - return TRUE; - } - - /* At this point we have a valid Texture Manager Object with updated */ - /* links. We now need to create or update a texture surface that is */ - /* in system memory. Every texture has a copy in system so we can use*/ - /* blt to solve problems with textures allocated on the card (square */ - /* only textures, pixelformats...). */ - - // TODO: make support for update also. Dirty rectangle basicly... - - /* Kill the interface if we have one no matter what. */ - if ( pTMObj->lpD3DTexture2 ) - { - DPF(( DBG_TXT_INFO, "Release Texture2" )); - pTMObj->lpD3DTexture2->Release(); - pTMObj->lpD3DTexture2 = NULL; - } - - /* Kill the system surface. TODO: should try to get the SubIMage going again */ - if ( pTMObj->lpDDS_System ) - { - DPF(( DBG_TXT_INFO, "Release texture (SYS)" )); - DX_RESTORE( pTMObj->lpDDS_System ); - pTMObj->lpDDS_System->Release(); - pTMObj->lpDDS_System = NULL; - } - - /* Kill the Video surface. TODO: need some reuse system... */ - if ( pTMObj->lpDDS_Video ) - { - DPF(( DBG_TXT_INFO, "Release texture (VID)" )); - DX_RESTORE( pTMObj->lpDDS_Video ); - pTMObj->lpDDS_Video->Release(); - pTMObj->lpDDS_Video = NULL; - } - - /*================================================================*/ - /* Translate the the Mesa/OpenGL pixel channels to the D3D flags. */ - /*================================================================*/ - switch( dwRequestFlags ) - { - case GL_ALPHA: - dwRequestFlags = DDPF_ALPHA; - DPF(( DBG_TXT_WARN, "GL_ALPHA not supported!)" )); - return FALSE; - - case GL_INTENSITY: - case GL_LUMINANCE: - DPF(( DBG_TXT_WARN, "GL_INTENSITY/GL_LUMINANCE not supported!)" )); - dwRequestFlags = DDPF_LUMINANCE; - return FALSE; - - case GL_LUMINANCE_ALPHA: - DPF(( DBG_TXT_WARN, "GL_LUMINANCE_ALPHA not supported!)" )); - dwRequestFlags = DDPF_LUMINANCE | DDPF_ALPHAPIXELS; - return FALSE; - - case GL_RGB: - DPF(( DBG_TXT_INFO, "Texture -> GL_RGB" )); - dwRequestFlags = DDPF_RGB; - break; - - case GL_RGBA: - DPF(( DBG_TXT_INFO, "Texture -> GL_RGBA" )); - dwRequestFlags = DDPF_RGB | DDPF_ALPHAPIXELS; - break; - } - - /*==============================*/ - /* Populate the texture object. */ - /*==============================*/ - pTMObj->dwName = dwName; - pTMObj->lpD3DDevice = pHAL->lpD3DDevice; - pTMObj->dwFlags = dwRequestFlags; - if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY ) - { - DPF(( DBG_TXT_INFO, "Convert to Square..." )); - pTMObj->dwSHeight = dwHeight; - pTMObj->dwSWidth = dwWidth; - - /* Shrink non-square textures. */ - pTMObj->dwVHeight = (dwHeight > dwWidth) ? dwWidth : dwHeight; - pTMObj->dwVWidth = (dwHeight > dwWidth) ? dwWidth : dwHeight; - } - else - { - pTMObj->dwSHeight = dwHeight; - pTMObj->dwSWidth = dwWidth; - pTMObj->dwVHeight = dwHeight; - pTMObj->dwVWidth = dwWidth; - } - - /*========================*/ - /* Create SYSTEM surface. */ - /*========================*/ - - /* Request a surface in system memory. */ - memset( &ddsd2, 0, sizeof(DDSURFACEDESC2) ); - ddsd2.dwSize = sizeof( DDSURFACEDESC2 ); - ddsd2.dwWidth = pTMObj->dwSWidth; - ddsd2.dwHeight = pTMObj->dwSHeight; - ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; - ddsd2.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY; - ddsd2.ddsCaps.dwCaps2 = 0L; - memset( &ddsd2.ddpfPixelFormat, 0, sizeof(DDPIXELFORMAT) ); - ddsd2.ddpfPixelFormat.dwSize = sizeof( DDPIXELFORMAT ); - ddsd2.ddpfPixelFormat.dwFlags = dwRequestFlags; - rc = pHAL->lpD3DDevice->EnumTextureFormats( EnumPFHook, &ddsd2.ddpfPixelFormat ); - if ( FAILED(rc) ) - { - RIP( pHAL, "EnumerTextureFormats (SYSTEM)->", ErrorStringD3D(rc) ); - return FALSE; - } - - /* Create the surface using the enumerated pixelformat. */ - rc = pHAL->lpDD4->CreateSurface( &ddsd2, &pTMObj->lpDDS_System, NULL ); - if ( FAILED(rc) ) - { - RIP( pHAL, "CreateSurface (TEXTURE/SYSTEM)->", ErrorStringD3D(rc) ); - return FALSE; - } - - /* Solve the pixel mapping info using the surface pixelformat. */ - Solve8BitChannelPixelFormat( &ddsd2.ddpfPixelFormat, &pTMObj->pixel ); - - /*===================================================================*/ - /* Fill the texture using the PixelInfo structure to do the mapping. */ - /*===================================================================*/ - UpdateTexture( pTMObj, FALSE, NULL, (UCHAR *)pPixels ); - - /*=======================*/ - /* Create VIDEO surface. */ - /*=======================*/ - rc = LoadTextureInVideo( pHAL, pTMObj ); - if ( rc == FALSE ) - return FALSE; - - /* Make this the current texture. */ - rc = pHAL->lpD3DDevice->SetTexture( 0, pTMObj->lpD3DTexture2 ); - if ( FAILED(rc) ) - { - DPF(( DBG_TXT_WARN, "Failed SetTexture() (%s)", ErrorStringD3D(rc) )); - pHAL->lpD3DDevice->SetTexture( 0, NULL ); - return FALSE; - } - - return TRUE; -} -/*===========================================================================*/ -/* This function will handle the creation and destruction of the texture */ -/* surfaces on the card. Using the dw'V'Width/Height dimensions the call */ -/* try and create the texture on the card and keep using FreeTextureMemory */ -/* until the surace can be created. Once the surface is created we get the */ -/* interface that we will use to make it the current texture. I didn't put */ -/* the code to make the texture current in this function as BIND needs to */ -/* use the same code and this function doesn't always get called when we do a*/ -/* bind. */ -/*===========================================================================*/ -/* RETURN: TRUE, FALSE. */ -/*===========================================================================*/ -static BOOL LoadTextureInVideo( PMESAD3DHAL pHAL, PTM_OBJECT pTMObj ) -{ - DDSURFACEDESC2 ddsd2; - HRESULT rc; - - DPF(( DBG_FUNC, "LoadTextureInVideo();" )); - - /* Kill the interface if we have one no matter what. */ - if ( pTMObj->lpD3DTexture2 ) - { - DPF(( DBG_TXT_INFO, "Release Texture2" )); - pTMObj->lpD3DTexture2->Release(); - pTMObj->lpD3DTexture2 = NULL; - } - - /* Kill the Video surface. TODO: need some reuse system... */ - if ( pTMObj->lpDDS_Video ) - { - DPF(( DBG_TXT_INFO, "Release texture (VID)" )); - DX_RESTORE( pTMObj->lpDDS_Video ); - pTMObj->lpDDS_Video->Release(); - pTMObj->lpDDS_Video = NULL; - } - - /* Request a surface in Video memory. */ - memset( &ddsd2, 0, sizeof(DDSURFACEDESC2) ); - ddsd2.dwSize = sizeof( DDSURFACEDESC2 ); - ddsd2.dwWidth = pTMObj->dwVWidth; - ddsd2.dwHeight = pTMObj->dwVHeight; - ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; - ddsd2.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY; - ddsd2.ddsCaps.dwCaps2 = 0L; - memset( &ddsd2.ddpfPixelFormat, 0, sizeof(DDPIXELFORMAT) ); - ddsd2.ddpfPixelFormat.dwSize = sizeof( DDPIXELFORMAT ); - ddsd2.ddpfPixelFormat.dwFlags = pTMObj->dwFlags; - rc = pHAL->lpD3DDevice->EnumTextureFormats( EnumPFHook, &ddsd2.ddpfPixelFormat ); - if ( FAILED(rc) ) - { - RIP( pHAL, "EnumerTextureFormats ->", ErrorStringD3D(rc) ); - return FALSE; - } - - /* Make sure we lock so we don't nuke this texture trying to free memory for it. */ - pTMObj->bLock = TRUE; - - /* Start a loop that will free all textures until we have created the texture */ - /* surface or we can't free up more memory. */ - do - { - /* Try to create the texture surface. */ - rc = pHAL->lpDD4->CreateSurface( &ddsd2, &pTMObj->lpDDS_Video, NULL ); - if ( !FAILED(rc) ) - break; - - DPF(( DBG_TXT_INFO, "Free Texture Memory" )); - - /* DestroyTexture will return TRUE if a surface was freed. */ - } while( FreeTextureMemory(pHAL,NULL) ); - - /* Make sure we unlock or we won't be able to nuke the TMO later. */ - pTMObj->bLock = FALSE; - - /* Did we create a valid texture surface? */ - if ( FAILED(rc) ) - { - DPF(( DBG_TXT_WARN, "Failed to load texture" )); - pHAL->lpD3DDevice->SetTexture( 0, NULL ); - return FALSE; - } - - DX_RESTORE( pTMObj->lpDDS_System ); - DX_RESTORE( pTMObj->lpDDS_Video ); - - DPF(( DBG_TXT_INFO, "Texture Blt SYSTEM -> VID" )); - - /* Now blt the texture in system memory to the card. */ - rc = pTMObj->lpDDS_Video->Blt( NULL, pTMObj->lpDDS_System, NULL, DDBLT_WAIT, NULL ); - if ( FAILED(rc) ) - { - RIP( pHAL, "Blt (TEXTURE) ->", ErrorStringD3D(rc) ); - return FALSE; - } - - /* Get the Texture interface that is used to render with. */ - pTMObj->lpDDS_Video->QueryInterface( IID_IDirect3DTexture2, (void **)&pTMObj->lpD3DTexture2 ); - if ( pTMObj->lpD3DTexture2 == NULL ) - { - DPF(( DBG_TXT_WARN, "Failed QueryTextureInterface" )); - pHAL->lpD3DDevice->SetTexture( 0, NULL ); - return FALSE; - } - - return TRUE; -} -/*===========================================================================*/ -/* If this function gets a texture object struc then we will try and free */ -/* it. If we get a NULL then we will search from the bottom up and free one */ -/* VMEM surface. I can only free when the surface isn't locked and of course*/ -/* there must be a VMEM surface. We never free SMEM surfaces as that isn't */ -/* the point. */ -/* TODO: should have a pointer to the bottom of the stack really. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static BOOL FreeTextureMemory( PMESAD3DHAL pHAL, PTM_OBJECT pTMObject ) -{ - PTM_OBJECT pCurrent; - BOOL bFreed = FALSE; - - DPF(( DBG_FUNC, "FreeTextureMemory();" )); - DPF(( DBG_TXT_WARN, "FREE TEXTURE!" )); - - /* Just to be safe. */ - if ( !pHAL || !pHAL->pTMList ) - { - DPF(( DBG_TXT_WARN, "FreeTextureMemory() -> NULL pHAL/pHAL->pTMList" )); - return FALSE; - } - - /* Free the last texture in the list. */ - if ( pTMObject == NULL ) - { - DPF(( DBG_TXT_INFO, "Free Last texture in cache" )); - - /* Find the last texture object. */ - for( pCurrent = pHAL->pTMList; pCurrent->next; pCurrent = pCurrent->next ); - - /* Now backup until we find a texture on the card. */ - while( pCurrent && (pCurrent->lpDDS_Video == NULL) && (pCurrent->bLock == FALSE) ) - pCurrent = pCurrent->prev; - - /* Didn't find anything. */ - if ( pCurrent == NULL ) - { - DPF(( DBG_TXT_INFO, "No texture memory freed" )); - return FALSE; - } - } - else - { - /* See if we can find this texture object. */ - for( pCurrent = pHAL->pTMList; pCurrent && (pCurrent != pTMObject); pCurrent = pCurrent->next ); - - /* Didn't find anything. */ - if ( pCurrent == NULL ) - { - DPF(( DBG_TXT_INFO, "Requested texture to be freed NOT FOUND" )); - return FALSE; - } - } - - /* Can't free this baby. */ - if ( pCurrent->bLock == TRUE ) - { - DPF(( DBG_TXT_WARN, "Requested texture LOCKED" )); - return FALSE; - } - - /* Free the texture memory. */ - if ( pCurrent->lpD3DTexture2 ) - { - DPF(( DBG_TXT_INFO, "Release Texture2" )); - pCurrent->lpD3DTexture2->Release(); - pCurrent->lpD3DTexture2 = NULL; - bFreed = TRUE; - } - if ( pCurrent->lpDDS_Video ) - { - DPF(( DBG_TXT_INFO, "Release texture (VID):" )); - DPF(( DBG_TXT_INFO, "dwName: %d", pCurrent->dwName )); - DPF(( DBG_TXT_INFO, "cx: %d, cy: %d", pCurrent->dwVWidth, pCurrent->dwVHeight )); - pCurrent->lpDDS_Video->Release(); - pCurrent->lpDDS_Video = NULL; - bFreed = TRUE; - } - - return bFreed; -} -/*===========================================================================*/ -/* This function searches the linked list of texture objects in the supplied*/ -/* D3Dwrapper structure. If it finds a match it will free it and pull it out*/ -/* of the linked list. The function works on the bases of a matching pointer*/ -/* to the object (not matching content). */ -/* If the function gets passed a NULL then we want to free the last texture */ -/* object in the list. Used in a loop to destory all. */ -/*===========================================================================*/ -/* RETURN: TRUE, FALSE. */ -/*===========================================================================*/ -static BOOL DestroyTextureObject( PMESAD3DHAL pHAL, PTM_OBJECT pTMObject ) -{ - PTM_OBJECT pCurrent; - - DPF(( DBG_FUNC, "DestoryTextureObject();" )); - - /* Just to be safe. */ - if ( !pHAL || !pHAL->pTMList ) - { - DPF(( DBG_TXT_WARN, "DestroyTextureObject() -> NULL pHAL/pHAL->pTMList" )); - return FALSE; - } - - /* Free the last texture in the list. */ - if ( pTMObject == NULL ) - { - /* Find the last texture object. */ - for( pCurrent = pHAL->pTMList; pCurrent->next; pCurrent = pCurrent->next ); - } - else - { - /* See if we can find this texture object. */ - for( pCurrent = pHAL->pTMList; pCurrent && (pCurrent != pTMObject); pCurrent = pCurrent->next ); - - /* Didn't find anything. */ - if ( pCurrent == NULL ) - { - DPF(( DBG_TXT_WARN, "No textures to be freed" )); - return FALSE; - } - } - - /* Can't free this baby. */ - if ( pCurrent->bLock == TRUE ) - { - DPF(( DBG_TXT_WARN, "Requested texture to be freed LOCKED" )); - return FALSE; - } - - /* Free the texture memory. */ - if ( pCurrent->lpD3DTexture2 ) - { - DPF(( DBG_TXT_INFO, "Release Texture2" )); - pCurrent->lpD3DTexture2->Release(); - pCurrent->lpD3DTexture2 = NULL; - } - if ( pCurrent->lpDDS_Video ) - { - DPF(( DBG_TXT_INFO, "Release texture (VID):" )); - pCurrent->lpDDS_Video->Release(); - pCurrent->lpDDS_Video = NULL; - } - if ( pCurrent->lpDDS_System ) - { - DPF(( DBG_TXT_INFO, "Release texture (SYS):" )); - pCurrent->lpDDS_System->Release(); - pCurrent->lpDDS_System = NULL; - } - - /* Pull this texture out of the list. */ - if ( pCurrent == pHAL->pTMList ) - pHAL->pTMList = NULL; - if ( pCurrent->prev ) - (pCurrent->prev)->next = pCurrent->next; - if ( pCurrent->next ) - (pCurrent->next)->prev = pCurrent->prev; - FREE( pCurrent ); - - return TRUE; -} -/*===========================================================================*/ -/* This function is the callback function that gets called when we are doing*/ -/* an enumeration of the texture formats supported by this device. The choice*/ -/* is made by checking to see if we have a match with the supplied D3D pixel-*/ -/* format. So the enumeration has to pass a desired D3D PF as the user var. */ -/*===========================================================================*/ -/* RETURN: D3DENUMRET_OK, D3DENUMRET_CANCEL. */ -/*===========================================================================*/ -static void UpdateTexture( PTM_OBJECT pTMObj, BOOL bVideo, RECT *pRect, UCHAR *pixels ) -{ - LPDIRECTDRAWSURFACE4 lpDDS; - DDSURFACEDESC2 ddsd2; - DWORD srcPitch, - dwHeight, - dwWidth, - dwCol, - dwColor; - UCHAR *pSrc, - *pSrcRow, - *pDest, - *pDestRow; - int rc; - - // TODO: Do I need to pass the h/w when its in the object! - DPF(( DBG_FUNC, "UpdateTexture();" )); - - /* Get the surface pointer we are looking for. */ - lpDDS = (bVideo) ? pTMObj->lpDDS_Video : pTMObj->lpDDS_System; - - /*===================================================================*/ - /* Fill the texture using the PixelInfo structure to do the mapping. */ - /*===================================================================*/ - - /* Get the surface pointer. */ - memset( &ddsd2, 0, sizeof(DDSURFACEDESC2) ); - ddsd2.dwSize = sizeof(DDSURFACEDESC2); - rc = lpDDS->Lock( NULL, &ddsd2, DDLOCK_WAIT, NULL ); - if ( FAILED(rc) ) - { - RIP( NULL, "Lock (TEXTURE/SYSTEM)->", ErrorStringD3D(rc) ); - return; - } - - /* For now we are only updating the system surface so use its dimensions. */ - dwWidth = (bVideo) ? pTMObj->dwVWidth : pTMObj->dwSWidth; - dwHeight = (bVideo) ? pTMObj->dwVHeight : pTMObj->dwSHeight; - - /* If we are updating the whole surface then the pDest/pSrc will */ - /* always be the same. */ - if ( pRect == NULL ) - { - pDest = (UCHAR *)ddsd2.lpSurface; - pSrc = pixels; - } - - /* Fill the texture surface based on the pixelformat flags. */ - if ( pTMObj->dwFlags == (DDPF_RGB | DDPF_ALPHAPIXELS) ) - { - srcPitch = dwWidth * 4; - if ( pRect ) - { - pDest = ((UCHAR *)ddsd2.lpSurface) + (pRect->top * ddsd2.lPitch) + (pRect->left * pTMObj->pixel.cb); - pSrc = pixels + (pRect->top * dwWidth * 4) + (pRect->left * 4); - dwHeight = (pRect->bottom - pRect->top); - dwWidth = (pRect->right - pRect->left); - } - - for( pDestRow = pDest, pSrcRow = pSrc; dwHeight > 0; dwHeight--, pDestRow += ddsd2.lPitch, pSrcRow += srcPitch ) - { - for( dwCol = 0, pDest = pDestRow, pSrc = pSrcRow; dwCol < dwWidth; dwCol++ ) - { - dwColor = ( ((DWORD)(*(pSrc ) * pTMObj->pixel.rScale)) << pTMObj->pixel.rShift ); - dwColor |= ( ((DWORD)(*(pSrc+1) * pTMObj->pixel.gScale)) << pTMObj->pixel.gShift ); - dwColor |= ( ((DWORD)(*(pSrc+2) * pTMObj->pixel.bScale)) << pTMObj->pixel.bShift ); - if ( pTMObj->pixel.aScale == -1.0 ) - dwColor |= ( (*(pSrc+3) & 0x80) ? (1 << pTMObj->pixel.aShift) : 0 ); - else - dwColor |= ( ((DWORD)(*(pSrc+3) * pTMObj->pixel.aScale)) << pTMObj->pixel.aShift ); - memcpy( pDest, &dwColor, pTMObj->pixel.cb ); - pDest += pTMObj->pixel.cb; - pSrc += 4; - } - } - } - else if ( pTMObj->dwFlags == DDPF_RGB ) - { - srcPitch = dwWidth * 3; - if ( pRect ) - { - pDest = ((UCHAR *)ddsd2.lpSurface) + (pRect->top * ddsd2.lPitch) + (pRect->left * pTMObj->pixel.cb); - pSrc = pixels + (pRect->top * dwWidth * 3) + (pRect->left * 3); - dwHeight = (pRect->bottom - pRect->top); - dwWidth = (pRect->right - pRect->left); - } - - for( pDestRow = pDest, pSrcRow = pSrc; dwHeight > 0; dwHeight--, pDestRow += ddsd2.lPitch, pSrcRow += srcPitch ) - { - for( dwCol = 0, pDest = pDestRow, pSrc = pSrcRow; dwCol < dwWidth; dwCol++ ) - { - dwColor = ( ((DWORD)(*(pSrc ) * pTMObj->pixel.rScale)) << pTMObj->pixel.rShift ); - dwColor |= ( ((DWORD)(*(pSrc+1) * pTMObj->pixel.gScale)) << pTMObj->pixel.gShift ); - dwColor |= ( ((DWORD)(*(pSrc+2) * pTMObj->pixel.bScale)) << pTMObj->pixel.bShift ); - memcpy( pDest, &dwColor, pTMObj->pixel.cb ); - pDest += pTMObj->pixel.cb; - pSrc += 3; - } - } - } - else if ( pTMObj->dwFlags == (DDPF_LUMINANCE | DDPF_ALPHAPIXELS) ) - { - srcPitch = dwWidth * 2; - if ( pRect ) - { - pDest = ((UCHAR *)ddsd2.lpSurface) + (pRect->top * ddsd2.lPitch) + (pRect->left * pTMObj->pixel.cb); - pSrc = pixels + (pRect->top * dwWidth * 2) + (pRect->left * 2); - dwHeight = (pRect->bottom - pRect->top); - dwWidth = (pRect->right - pRect->left); - } - - for( pDestRow = pDest, pSrcRow = pSrc; dwHeight > 0; dwHeight--, pDestRow += ddsd2.lPitch, pSrcRow += srcPitch ) - { - for( dwCol = 0, pDest = pDestRow, pSrc = pSrcRow; dwCol < dwWidth; dwCol++ ) - { - dwColor = ( ((DWORD)(*(pSrc ) * pTMObj->pixel.rScale)) << pTMObj->pixel.rShift ); - if ( pTMObj->pixel.aScale == -1.0 ) - dwColor |= ( (*(pSrc+1) & 0x80) ? (1 << pTMObj->pixel.aShift) : 0 ); - else - dwColor |= ( ((DWORD)(*(pSrc+1) * pTMObj->pixel.aScale)) << pTMObj->pixel.aShift ); - memcpy( pDest, &dwColor, pTMObj->pixel.cb ); - pDest += pTMObj->pixel.cb; - pSrc += 2; - } - } - } - else if ( pTMObj->dwFlags == DDPF_LUMINANCE ) - { - srcPitch = dwWidth; - if ( pRect ) - { - pDest = ((UCHAR *)ddsd2.lpSurface) + (pRect->top * ddsd2.lPitch) + (pRect->left * pTMObj->pixel.cb); - pSrc = pixels + (pRect->top * dwWidth) + (pRect->left); - dwHeight = (pRect->bottom - pRect->top); - dwWidth = (pRect->right - pRect->left); - } - - for( pDestRow = pDest, pSrcRow = pSrc; dwHeight > 0; dwHeight--, pDestRow += ddsd2.lPitch, pSrcRow += srcPitch ) - { - for( dwCol = 0, pDest = pDestRow, pSrc = pSrcRow; dwCol < dwWidth; dwCol++ ) - { - dwColor = ( ((DWORD)(*pSrc * pTMObj->pixel.rScale)) << pTMObj->pixel.rShift ); - memcpy( pDest, &dwColor, pTMObj->pixel.cb ); - pDest += pTMObj->pixel.cb; - pSrc++; - } - } - } - else if ( pTMObj->dwFlags == DDPF_ALPHAPIXELS ) - { - srcPitch = dwWidth; - if ( pRect ) - { - pDest = ((UCHAR *)ddsd2.lpSurface) + (pRect->top * ddsd2.lPitch) + (pRect->left * pTMObj->pixel.cb); - pSrc = pixels + (pRect->top * dwWidth) + (pRect->left); - dwHeight = (pRect->bottom - pRect->top); - dwWidth = (pRect->right - pRect->left); - } - - for( pDestRow = pDest, pSrcRow = pSrc; dwHeight > 0; dwHeight--, pDestRow += ddsd2.lPitch, pSrcRow += srcPitch ) - { - for( dwCol = 0, pDest = pDestRow, pSrc = pSrcRow; dwCol < dwWidth; dwCol++ ) - { - if ( pTMObj->pixel.aScale == -1.0 ) - dwColor = ( (*pSrc & 0x80) ? (1 << pTMObj->pixel.aShift) : 0 ); - else - dwColor = ( ((DWORD)(*pSrc * pTMObj->pixel.aScale)) << pTMObj->pixel.aShift ); - memcpy( pDest, &dwColor, pTMObj->pixel.cb ); - pDest += pTMObj->pixel.cb; - pSrc++; - } - } - } - - /* Unlock the surface. */ - rc = lpDDS->Unlock( NULL ); - if ( FAILED(rc) ) - { - RIP( NULL, "Unlock (TEXTURE/SYSTEM)->", ErrorStringD3D(rc) ); - } -} -/*===========================================================================*/ -/* This function is the callback function that gets called when we are doing*/ -/* an enumeration of the texture formats supported by this device. The choice*/ -/* is made by checking to see if we have a match with the supplied D3D pixel-*/ -/* format. So the enumeration has to pass a desired D3D PF as the user var. */ -/*===========================================================================*/ -/* RETURN: D3DENUMRET_OK, D3DENUMRET_CANCEL. */ -/*===========================================================================*/ -HRESULT CALLBACK EnumPFHook( LPDDPIXELFORMAT lpDDPixFmt, LPVOID lpContext ) -{ - LPDDPIXELFORMAT lpDDPixFmtRequest = (LPDDPIXELFORMAT)lpContext; - PIXELINFO pixel; - - DPF(( DBG_FUNC, "EnumPFHook();" )); - - if ( lpDDPixFmt->dwFlags == lpDDPixFmtRequest->dwFlags ) - { - /* Are we looking for an alpha channel? */ - if ( lpDDPixFmtRequest->dwFlags & DDPF_ALPHAPIXELS ) - { - /* Try for something that has more then 1bits of Alpha. */ - Solve8BitChannelPixelFormat( lpDDPixFmt, &pixel ); - if ( pixel.aScale == -1.0 ) - { - /* Save this format no matter what as its a match of sorts. */ - memcpy( lpDDPixFmtRequest, lpDDPixFmt, sizeof(DDPIXELFORMAT) ); - return D3DENUMRET_OK; - } - } - - /* Save this format as its a good match. */ - memcpy( lpDDPixFmtRequest, lpDDPixFmt, sizeof(DDPIXELFORMAT) ); - - /* We are happy at this point so lets leave. */ - return D3DENUMRET_CANCEL; - } - - return D3DENUMRET_OK; -} - - diff --git a/src/mesa/drivers/d3d/D3DTextureMgr.h b/src/mesa/drivers/d3d/D3DTextureMgr.h deleted file mode 100644 index 8a64ceaaec..0000000000 --- a/src/mesa/drivers/d3d/D3DTextureMgr.h +++ /dev/null @@ -1,62 +0,0 @@ -/*===========================================================================*/ -/* */ -/* Mesa-3.0 DirectX 6 Driver */ -/* */ -/* By Leigh McRae */ -/* */ -/* http://www.altsoftware.com/ */ -/* */ -/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ -/*===========================================================================*/ -#ifndef _TEXTURE_MGR_INC -#define _TEXTURE_MGR_INC - -/*===========================================================================*/ -/* Includes. */ -/*===========================================================================*/ -#include <windows.h> -#include <ddraw.h> -#include <d3d.h> -#include <stdlib.h> -#include <stdlib.h> -#include "GL/gl.h" -/*========================================================================*/ -/* Defines. */ -/*========================================================================*/ -/*========================================================================*/ -/* Type defines. */ -/*========================================================================*/ -typedef struct _local_texture_object -{ - DWORD dwName, - dwPriority, - dwFlags, - dwSWidth, - dwSHeight, - dwVWidth, - dwVHeight; - BOOL bLock, - bDirty; /* I only update VID on SubImage calls so the system */ - /* texture can get invalid. */ - - LPDIRECT3DDEVICE3 lpD3DDevice; /* If the device changes we must get new handles... */ - LPDIRECTDRAWSURFACE4 lpDDS_System, - lpDDS_Video; - LPDIRECT3DTEXTURE2 lpD3DTexture2; - - PIXELINFO pixel; - - struct _local_texture_object *next; - struct _local_texture_object *prev; - -} TM_OBJECT, *PTM_OBJECT; -/*========================================================================*/ -/* Function prototypes. */ -/*========================================================================*/ -void APIENTRY InitTMD3D( void *pVoid ); -void APIENTRY TermTMD3D( void *pVoid ); -/*========================================================================*/ -/* Global variables declaration. */ -/*========================================================================*/ - -#endif diff --git a/src/mesa/drivers/d3d/D3DUTILS.CPP b/src/mesa/drivers/d3d/D3DUTILS.CPP deleted file mode 100644 index 02664f96e4..0000000000 --- a/src/mesa/drivers/d3d/D3DUTILS.CPP +++ /dev/null @@ -1,638 +0,0 @@ -/*===========================================================================*/ -/* */ -/* Mesa-3.0 DirectX 6 Driver */ -/* */ -/* By Leigh McRae */ -/* */ -/* http://www.altsoftware.com/ */ -/* */ -/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ -/*===========================================================================*/ -#include "D3DHAL.h" -/*===========================================================================*/ -/* Local only functions. */ -/*===========================================================================*/ -static int CountTrailingZeros( DWORD dwMask ); -/*===========================================================================*/ -/* This function is used to get the pointer to the surface and the pitch for*/ -/* the scanline rendering functions. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -extern "C" DDSURFACEDESC2 *LockHAL( PMESAD3DSHARED pShared, BOOL bBack ) -{ - PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; - static DDSURFACEDESC2 ddsd2; - HRESULT rc; - - DPF(( DBG_FUNC, "LockHAL();" )); - - /* Set the request structure up first. */ - memset( &ddsd2, 0, sizeof(DDSURFACEDESC2) ); - ddsd2.dwSize = sizeof(DDSURFACEDESC2); - - /* Make sure we have enough info. */ - if ( pHAL ) - { - rc = pHAL->lpDDSRender->Lock( NULL, &ddsd2, DDLOCK_WAIT, NULL ); - if ( FAILED(rc) ) - { - RIP( pHAL, "Lock (RENDER) ->", ErrorStringD3D(rc) ); - } - } - - return &ddsd2; -} -/*===========================================================================*/ -/* This is just a simple wrapper. I probably don't need to do any error */ -/* checking as the Lock must have worked inorder to get here... */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -extern "C" void UnlockHAL( PMESAD3DSHARED pShared, BOOL bBack ) -{ - PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; - HRESULT rc; - - DPF(( DBG_FUNC, "UnlockHAL();" )); - - /* Make sure we have enough info. */ - if ( pHAL ) - { - rc = pHAL->lpDDSRender->Unlock( NULL ); - if ( FAILED(rc) ) - { - RIP( pHAL, "Unlock (RENDER) ->", ErrorStringD3D(rc) ); - } - } -} -/*===========================================================================*/ -/* This function will track the main/Primary window that will be used as the*/ -/* target for the Blt in SwapBuffers. As a side effect the call will check */ -/* to see if the primary surface is the same size and position as the screen.*/ -/* If they are the same size we will call it fullscreen... */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -extern "C" void UpdateScreenPosHAL( PMESAD3DSHARED pShared ) -{ - PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; - POINT pt; - DWORD dwWidth, dwHeight; - - DPF(( DBG_FUNC, "UpdateScreenPosHAL();" )); - - /* Make sure we have enough info. */ - if ( pHAL != NULL ) - { - /* Update the windows screen position. */ - GetClientRect( pShared->hwnd, &pShared->rectW ); - pt.x = pt.y = 0; - ClientToScreen( pShared->hwnd, &pt ); - OffsetRect( &pShared->rectW, pt.x, pt.y); - - /* Compare the primary to the screen. */ - dwWidth = GetSystemMetrics( SM_CXSCREEN ); - dwHeight = GetSystemMetrics( SM_CYSCREEN ); - if ( (pShared->rectW.left > 0) || (pShared->rectW.top > 0) || - (pShared->rectW.right > dwWidth) || (pShared->rectW.bottom > dwHeight) ) - pShared->bWindow = TRUE; - else - pShared->bWindow = FALSE; - } -} -/*===========================================================================*/ -/* This function will fill in the pixel info structure defined in D3Dshared.*/ -/* Basicly it will take a DirectDraw pixelformat structure and make scaling */ -/* values that will convert from 8bit channels to whatever the supplied ddpf */ -/* uses. Also we will generate shift values that will be used to get move */ -/* each component of the pixel into place. */ -/* I have now added a special case for a 1bit alpha channel. If I find a 1b*/ -/* alpha then I will set the scale to -1.0 which should be unique. Later I */ -/* can check the alpha scale value too see if its -1.0 and thus handle it. I*/ -/* was finding that the case was not working tom my advantage so this is my */ -/* HACK for the day. As a TODO I should work on this... */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -void Solve8BitChannelPixelFormat( DDPIXELFORMAT *pddpf, PPIXELINFO pPixel ) -{ - DPF(( DBG_FUNC, "Solve8BitChannelPixelFromat();" )); - - memset( pPixel, 0, sizeof(PPIXELINFO) ); - - /* Check too see if the color space is valid in the PF. */ - if ( pddpf->dwFlags & DDPF_RGB ) - { - /* Solve the red stuff. */ - pPixel->dwRMask = pddpf->dwRBitMask; - pPixel->rShift = CountTrailingZeros( pPixel->dwRMask ); - pPixel->rScale = (float)0.00392156 * (float)(pPixel->dwRMask >> pPixel->rShift); - - /* Solve the green thingy's. */ - pPixel->dwGMask = pddpf->dwGBitMask; - pPixel->gShift = CountTrailingZeros( pPixel->dwGMask ); - pPixel->gScale = (float)0.00392156 * (float)(pPixel->dwGMask >> pPixel->gShift); - - /* Solve the blues. */ - pPixel->dwBMask = pddpf->dwBBitMask; - pPixel->bShift = CountTrailingZeros( pddpf->dwBBitMask ); - pPixel->bScale = (float)0.00392156 * (float)(pddpf->dwBBitMask >> pPixel->bShift); - } - - /* Do the alpha channel if there is one. */ - if ( pddpf->dwFlags & DDPF_ALPHAPIXELS ) - { - pPixel->dwAMask = pddpf->dwRGBAlphaBitMask; - pPixel->aShift = CountTrailingZeros( pPixel->dwAMask ); - - /* Special case a 1bit alpha. */ - if ( (pPixel->dwAMask >> pPixel->aShift) == 1 ) - pPixel->aScale = -1.0; - else - pPixel->aScale = (float)0.00392156 * (float)(pPixel->dwAMask >> pPixel->aShift); - } - - /* Get the size of the pixel in bytes. Should work as dwRGBBitCount is in a union. */ - pPixel->cb = pddpf->dwRGBBitCount / 8; -} -/*===========================================================================*/ -/* See RETURN :) */ -/*===========================================================================*/ -/* RETURN: number of contiguous zeros starting from the right. */ -/*===========================================================================*/ -static int CountTrailingZeros( DWORD dwMask ) -{ - DWORD Mask; - - if ( dwMask == 0 ) - return 32; - - /* Can't take credit for this one! */ - Mask = dwMask & -(int)dwMask; - return ((Mask & 0xFFFF0000)!=0) << 4 - | ((Mask & 0xFF00FF00)!=0) << 3 - | ((Mask & 0xF0F0F0F0)!=0) << 2 - | ((Mask & 0xCCCCCCCC)!=0) << 1 - | ((Mask & 0xAAAAAAAA)!=0); -} -/*===========================================================================*/ -/* This function will convert the DDraw error code to its macro string. The*/ -/* returned pointer is static so you need not worry about memory managemnet */ -/* but the error message gets written over from call to call... */ -/*===========================================================================*/ -/* RETURN: pointer to the single static buffer that hold the error message. */ -/*===========================================================================*/ -char *ErrorStringD3D( HRESULT hr ) -{ - static char errorString[128]; - - switch( hr ) - { - case DDERR_ALREADYINITIALIZED: - strcpy( errorString, "DDERR_ALREADYINITIALIZED" ); - break; - - case DDERR_CANNOTATTACHSURFACE: - strcpy( errorString, "DDERR_CANNOTATTACHSURFACE" ); - break; - - case DDERR_CANNOTDETACHSURFACE: - strcpy( errorString, "DDERR_CANNOTDETACHSURFACE" ); - break; - - case DDERR_CURRENTLYNOTAVAIL: - strcpy( errorString, "DDERR_CURRENTLYNOTAVAIL" ); - break; - - case DDERR_EXCEPTION: - strcpy( errorString, "DDERR_EXCEPTION" ); - break; - - case DDERR_GENERIC: - strcpy( errorString, "DDERR_GENERIC" ); - break; - - case DDERR_HEIGHTALIGN: - strcpy( errorString, "DDERR_HEIGHTALIGN" ); - break; - - case DDERR_INCOMPATIBLEPRIMARY: - strcpy( errorString, "DDERR_INCOMPATIBLEPRIMARY" ); - break; - - case DDERR_INVALIDCAPS: - strcpy( errorString, "DDERR_INVALIDCAPS" ); - break; - - case DDERR_INVALIDCLIPLIST: - strcpy( errorString, "DDERR_INVALIDCLIPLIST" ); - break; - - case DDERR_INVALIDMODE: - strcpy( errorString, "DDERR_INVALIDMODE" ); - break; - - case DDERR_INVALIDOBJECT: - strcpy( errorString, "DDERR_INVALIDOBJECT" ); - break; - - case DDERR_INVALIDPARAMS: - strcpy( errorString, "DDERR_INVALIDPARAMS" ); - break; - - case DDERR_INVALIDPIXELFORMAT: - strcpy( errorString, "DDERR_INVALIDPIXELFORMAT" ); - break; - - case DDERR_INVALIDRECT: - strcpy( errorString, "DDERR_INVALIDRECT" ); - break; - - case DDERR_LOCKEDSURFACES: - strcpy( errorString, "DDERR_LOCKEDSURFACES" ); - break; - - case DDERR_NO3D: - strcpy( errorString, "DDERR_NO3D" ); - break; - - case DDERR_NOALPHAHW: - strcpy( errorString, "DDERR_NOALPHAHW" ); - break; - - case DDERR_NOCLIPLIST: - strcpy( errorString, "DDERR_NOCLIPLIST" ); - break; - - case DDERR_NOCOLORCONVHW: - strcpy( errorString, "DDERR_NOCOLORCONVHW" ); - break; - - case DDERR_NOCOOPERATIVELEVELSET: - strcpy( errorString, "DDERR_NOCOOPERATIVELEVELSET" ); - break; - - case DDERR_NOCOLORKEY: - strcpy( errorString, "DDERR_NOCOLORKEY" ); - break; - - case DDERR_NOCOLORKEYHW: - strcpy( errorString, "DDERR_NOCOLORKEYHW" ); - break; - - case DDERR_NODIRECTDRAWSUPPORT: - strcpy( errorString, "DDERR_NODIRECTDRAWSUPPORT" ); - break; - - case DDERR_NOEXCLUSIVEMODE: - strcpy( errorString, "DDERR_NOEXCLUSIVEMODE" ); - break; - - case DDERR_NOFLIPHW: - strcpy( errorString, "DDERR_NOFLIPHW" ); - break; - - case DDERR_NOGDI: - strcpy( errorString, "DDERR_NOGDI" ); - break; - - case DDERR_NOMIRRORHW: - strcpy( errorString, "DDERR_NOMIRRORHW" ); - break; - - case DDERR_NOTFOUND: - strcpy( errorString, "DDERR_NOTFOUND" ); - break; - - case DDERR_NOOVERLAYHW: - strcpy( errorString, "DDERR_NOOVERLAYHW" ); - break; - - case DDERR_OVERLAPPINGRECTS: - strcpy( errorString, "DDERR_OVERLAPPINGRECTS" ); - break; - - case DDERR_NORASTEROPHW: - strcpy( errorString, "DDERR_NORASTEROPHW" ); - break; - - case DDERR_NOROTATIONHW: - strcpy( errorString, "DDERR_NOROTATIONHW" ); - break; - - case DDERR_NOSTRETCHHW: - strcpy( errorString, "DDERR_NOSTRETCHHW" ); - break; - - case DDERR_NOT4BITCOLOR: - strcpy( errorString, "DDERR_NOT4BITCOLOR" ); - break; - - case DDERR_NOT4BITCOLORINDEX: - strcpy( errorString, "DDERR_NOT4BITCOLORINDEX" ); - break; - - case DDERR_NOT8BITCOLOR: - strcpy( errorString, "DDERR_NOT8BITCOLOR" ); - break; - - case DDERR_NOTEXTUREHW: - strcpy( errorString, "DDERR_NOTEXTUREHW" ); - break; - - case DDERR_NOVSYNCHW: - strcpy( errorString, "DDERR_NOVSYNCHW" ); - break; - - case DDERR_NOZBUFFERHW: - strcpy( errorString, "DDERR_NOZBUFFERHW" ); - break; - - case DDERR_NOZOVERLAYHW: - strcpy( errorString, "DDERR_NOZOVERLAYHW" ); - break; - - case DDERR_OUTOFCAPS: - strcpy( errorString, "DDERR_OUTOFCAPS" ); - break; - - case DDERR_OUTOFMEMORY: - strcpy( errorString, "DDERR_OUTOFMEMORY" ); - break; - - case DDERR_OUTOFVIDEOMEMORY: - strcpy( errorString, "DDERR_OUTOFVIDEOMEMORY" ); - break; - - case DDERR_OVERLAYCANTCLIP: - strcpy( errorString, "DDERR_OVERLAYCANTCLIP" ); - break; - - case DDERR_OVERLAYCOLORKEYONLYONEACTIVE: - strcpy( errorString, "DDERR_OVERLAYCOLORKEYONLYONEACTIVE" ); - break; - - case DDERR_PALETTEBUSY: - strcpy( errorString, "DDERR_PALETTEBUSY" ); - break; - - case DDERR_COLORKEYNOTSET: - strcpy( errorString, "DDERR_COLORKEYNOTSET" ); - break; - - case DDERR_SURFACEALREADYATTACHED: - strcpy( errorString, "DDERR_SURFACEALREADYATTACHED" ); - break; - - case DDERR_SURFACEALREADYDEPENDENT: - strcpy( errorString, "DDERR_SURFACEALREADYDEPENDENT" ); - break; - - case DDERR_SURFACEBUSY: - strcpy( errorString, "DDERR_SURFACEBUSY" ); - break; - - case DDERR_CANTLOCKSURFACE: - strcpy( errorString, "DDERR_CANTLOCKSURFACE" ); - break; - - case DDERR_SURFACEISOBSCURED: - strcpy( errorString, "DDERR_SURFACEISOBSCURED" ); - break; - - case DDERR_SURFACELOST: - strcpy( errorString, "DDERR_SURFACELOST" ); - break; - - case DDERR_SURFACENOTATTACHED: - strcpy( errorString, "DDERR_SURFACENOTATTACHED" ); - break; - - case DDERR_TOOBIGHEIGHT: - strcpy( errorString, "DDERR_TOOBIGHEIGHT" ); - break; - - case DDERR_TOOBIGSIZE: - strcpy( errorString, "DDERR_TOOBIGSIZE" ); - break; - - case DDERR_TOOBIGWIDTH: - strcpy( errorString, "DDERR_TOOBIGWIDTH" ); - break; - - case DDERR_UNSUPPORTED: - strcpy( errorString, "DDERR_UNSUPPORTED" ); - break; - - case DDERR_UNSUPPORTEDFORMAT: - strcpy( errorString, "DDERR_UNSUPPORTEDFORMAT" ); - break; - - case DDERR_UNSUPPORTEDMASK: - strcpy( errorString, "DDERR_UNSUPPORTEDMASK" ); - break; - - case DDERR_INVALIDSTREAM: - strcpy( errorString, "DDERR_INVALIDSTREAM" ); - break; - - case DDERR_VERTICALBLANKINPROGRESS: - strcpy( errorString, "DDERR_VERTICALBLANKINPROGRESS" ); - break; - - case DDERR_WASSTILLDRAWING: - strcpy( errorString, "DDERR_WASSTILLDRAWING" ); - break; - - case DDERR_XALIGN: - strcpy( errorString, "DDERR_XALIGN" ); - break; - - case DDERR_INVALIDDIRECTDRAWGUID: - strcpy( errorString, "DDERR_INVALIDDIRECTDRAWGUID" ); - break; - - case DDERR_DIRECTDRAWALREADYCREATED: - strcpy( errorString, "DDERR_DIRECTDRAWALREADYCREATED" ); - break; - - case DDERR_NODIRECTDRAWHW: - strcpy( errorString, "DDERR_NODIRECTDRAWHW" ); - break; - - case DDERR_PRIMARYSURFACEALREADYEXISTS: - strcpy( errorString, "DDERR_PRIMARYSURFACEALREADYEXISTS" ); - break; - - case DDERR_NOEMULATION: - strcpy( errorString, "DDERR_NOEMULATION" ); - break; - - case DDERR_REGIONTOOSMALL: - strcpy( errorString, "DDERR_REGIONTOOSMALL" ); - break; - - case DDERR_CLIPPERISUSINGHWND: - strcpy( errorString, "DDERR_CLIPPERISUSINGHWND" ); - break; - - case DDERR_NOCLIPPERATTACHED: - strcpy( errorString, "DDERR_NOCLIPPERATTACHED" ); - break; - - case DDERR_NOHWND: - strcpy( errorString, "DDERR_NOHWND" ); - break; - - case DDERR_HWNDSUBCLASSED: - strcpy( errorString, "DDERR_HWNDSUBCLASSED" ); - break; - - case DDERR_HWNDALREADYSET: - strcpy( errorString, "DDERR_HWNDALREADYSET" ); - break; - - case DDERR_NOPALETTEATTACHED: - strcpy( errorString, "DDERR_NOPALETTEATTACHED" ); - break; - - case DDERR_NOPALETTEHW: - strcpy( errorString, "DDERR_NOPALETTEHW" ); - break; - - case DDERR_BLTFASTCANTCLIP: - strcpy( errorString, "DDERR_BLTFASTCANTCLIP" ); - break; - - case DDERR_NOBLTHW: - strcpy( errorString, "DDERR_NOBLTHW" ); - break; - - case DDERR_NODDROPSHW: - strcpy( errorString, "DDERR_NODDROPSHW" ); - break; - - case DDERR_OVERLAYNOTVISIBLE: - strcpy( errorString, "DDERR_OVERLAYNOTVISIBLE" ); - break; - - case DDERR_NOOVERLAYDEST: - strcpy( errorString, "DDERR_NOOVERLAYDEST" ); - break; - - case DDERR_INVALIDPOSITION: - strcpy( errorString, "DDERR_INVALIDPOSITION" ); - break; - - case DDERR_NOTAOVERLAYSURFACE: - strcpy( errorString, "DDERR_NOTAOVERLAYSURFACE" ); - break; - - case DDERR_EXCLUSIVEMODEALREADYSET: - strcpy( errorString, "DDERR_EXCLUSIVEMODEALREADYSET" ); - break; - - case DDERR_NOTFLIPPABLE: - strcpy( errorString, "DDERR_NOTFLIPPABLE" ); - break; - - case DDERR_CANTDUPLICATE: - strcpy( errorString, "DDERR_CANTDUPLICATE" ); - break; - - case DDERR_NOTLOCKED: - strcpy( errorString, "DDERR_NOTLOCKED" ); - break; - - case DDERR_CANTCREATEDC: - strcpy( errorString, "DDERR_CANTCREATEDC" ); - break; - - case DDERR_NODC: - strcpy( errorString, "DDERR_NODC" ); - break; - - case DDERR_WRONGMODE: - strcpy( errorString, "DDERR_WRONGMODE" ); - break; - - case DDERR_IMPLICITLYCREATED: - strcpy( errorString, "DDERR_IMPLICITLYCREATED" ); - break; - - case DDERR_NOTPALETTIZED: - strcpy( errorString, "DDERR_NOTPALETTIZED" ); - break; - - case DDERR_UNSUPPORTEDMODE: - strcpy( errorString, "DDERR_UNSUPPORTEDMODE" ); - break; - - case DDERR_NOMIPMAPHW: - strcpy( errorString, "DDERR_NOMIPMAPHW" ); - break; - - case DDERR_INVALIDSURFACETYPE: - strcpy( errorString, "DDERR_INVALIDSURFACETYPE" ); - break; - - case DDERR_NOOPTIMIZEHW: - strcpy( errorString, "DDERR_NOOPTIMIZEHW" ); - break; - - case DDERR_NOTLOADED: - strcpy( errorString, "DDERR_NOTLOADED" ); - break; - - case DDERR_NOFOCUSWINDOW: - strcpy( errorString, "DDERR_NOFOCUSWINDOW" ); - break; - - case DDERR_DCALREADYCREATED: - strcpy( errorString, "DDERR_DCALREADYCREATED" ); - break; - - case DDERR_NONONLOCALVIDMEM: - strcpy( errorString, "DDERR_NONONLOCALVIDMEM" ); - break; - - case DDERR_CANTPAGELOCK: - strcpy( errorString, "DDERR_CANTPAGELOCK" ); - break; - - case DDERR_CANTPAGEUNLOCK: - strcpy( errorString, "DDERR_CANTPAGEUNLOCK" ); - break; - - case DDERR_NOTPAGELOCKED: - strcpy( errorString, "DDERR_NOTPAGELOCKED" ); - break; - - case DDERR_MOREDATA: - strcpy( errorString, "DDERR_MOREDATA" ); - break; - - case DDERR_EXPIRED: - strcpy( errorString, "DDERR_EXPIRED" ); - break; - - case DDERR_VIDEONOTACTIVE: - strcpy( errorString, "DDERR_VIDEONOTACTIVE" ); - break; - - case DDERR_DEVICEDOESNTOWNSURFACE: - strcpy( errorString, "DDERR_DEVICEDOESNTOWNSURFACE" ); - break; - - case DDERR_NOTINITIALIZED: - strcpy( errorString, "DDERR_NOTINITIALIZED" ); - break; - - default: - strcpy( errorString, "<unknown error code>" ); - break; - } - - return &errorString[0]; -} diff --git a/src/mesa/drivers/d3d/D3Dvbrender.c b/src/mesa/drivers/d3d/D3Dvbrender.c deleted file mode 100644 index 09857f1dc8..0000000000 --- a/src/mesa/drivers/d3d/D3Dvbrender.c +++ /dev/null @@ -1,2149 +0,0 @@ -/*===========================================================================*/ -/* */ -/* Mesa-3.0 DirectX 6 Driver */ -/* */ -/* By Leigh McRae */ -/* */ -/* http://www.altsoftware.com/ */ -/* */ -/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ -/*===========================================================================*/ -#include <stdio.h> -#include "clip.h" -#include "context.h" -#include "light.h" -#include "lines.h" -#include "macros.h" -#include "matrix.h" -#include "pb.h" -#include "points.h" -#include "mtypes.h" -#include "vb.h" -#include "vbrender.h" -#include "xform.h" -#include "D3DMesa.h" - -static void SetRenderStates( GLcontext *ctx ); -static void DebugRenderStates( GLcontext *ctx, BOOL bForce ); - -static void RenderPointsVB( GLcontext *ctx, GLuint start, GLuint end ); -static void RenderTriangleVB( GLcontext *ctx, GLuint start, GLuint end ); -static void RenderTriangleFanVB( GLcontext *ctx, GLuint start, GLuint end ); -static void RenderTriangleStripVB( GLcontext *ctx, GLuint start, GLuint end ); -static void RenderQuadVB( GLcontext *ctx, GLuint start, GLuint end ); -static void RenderQuad( GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint v4, GLuint pv ); -void RenderOneTriangle( GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint pv ); -void RenderOneLine( GLcontext *ctx, GLuint v1, GLuint v2, GLuint pv ); - -/* I went with a D3D vertex buffer that is 6 times that of the Mesa one */ -/* instead of having the D3D one flush when its full. This way Mesa will*/ -/* handle all the flushing. I need x6 as points can use 4 vertex each. */ -D3DTLVERTEX D3DTLVertices[ (VB_MAX*6) ]; -GLuint VList[VB_SIZE]; -/*===========================================================================*/ -/* Compute Z offsets for a polygon with plane defined by (A,B,C,D) */ -/* D is not needed. TODO: Currently we are calculating this but not using it.*/ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void OffsetPolygon( GLcontext *ctx, GLfloat a, GLfloat b, GLfloat c ) -{ - GLfloat ac, - bc, - m, - offset; - - DPF(( DBG_FUNC, "OffsetPolygon();" )); - - if ( (c < 0.001F) && (c > - 0.001F) ) - { - /* Prevents underflow problems. */ - ctx->PointZoffset = 0.0F; - ctx->LineZoffset = 0.0F; - ctx->PolygonZoffset = 0.0F; - } - else - { - ac = a / c; - bc = b / c; - if ( ac < 0.0F ) - ac = -ac; - if ( bc<0.0F ) - bc = -bc; - m = MAX2( ac, bc ); /* m = sqrt( ac*ac + bc*bc ); */ - - offset = (m * ctx->Polygon.OffsetFactor + ctx->Polygon.OffsetUnits); - ctx->PointZoffset = ctx->Polygon.OffsetPoint ? offset : 0.0F; - ctx->LineZoffset = ctx->Polygon.OffsetLine ? offset : 0.0F; - ctx->PolygonZoffset = ctx->Polygon.OffsetFill ? offset : 0.0F; - } - - DPF(( DBG_PRIM_INFO, "OffsetPolygon: %f", offset )); -} -/*===========================================================================*/ -/* Compute signed area of the n-sided polgyon specified by vertices */ -/* vb->Win[] and vertex list vlist[]. */ -/* A clockwise polygon will return a negative area. A counter-clockwise */ -/* polygon will return a positive area. I have changed this function to */ -/* actually calculate twice the area as its faster and still gives the sign. */ -/*===========================================================================*/ -/* RETURN: signed area of the polgon. */ -/*===========================================================================*/ -static GLfloat PolygonArea( const struct vertex_buffer *vb, GLuint n, const GLuint vlist[] ) -{ - GLfloat area; - GLuint i; - - DPF(( DBG_FUNC, "PolygonArea();" )); - -#define j0 vlist[i] -#define j1 vlist[(i+1)%n] -#define x0 vb->Win[j0][0] -#define y0 vb->Win[j0][1] -#define x1 vb->Win[j1][0] -#define y1 vb->Win[j1][1] - - /* area = sum of trapezoids */ - for( i = 0, area = 0.0; i < n; i++ ) - area += ((x0 - x1) * (y0 + y1)); /* Note: no divide by two here! */ - -#undef x0 -#undef y0 -#undef x1 -#undef y1 -#undef j1 -#undef j0 - - // TODO: I don't see the point or * 0.5 as we just want the sign... - return area; -} -/*===========================================================================*/ -/* Render a polygon that needs clipping on at least one vertex. The function*/ -/* will first clip the polygon to any user clipping planes then clip to the */ -/* viewing volume. The final polygon will be draw as single triangles that */ -/* first need minor proccessing (culling, offset, etc) before we draw the */ -/* polygon as a fan. NOTE: the fan is draw as single triangles as its not */ -/* formed sequentaly in the VB but is in the vlist[]. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void RenderClippedPolygon( GLcontext *ctx, GLuint n, GLuint vlist[] ) -{ - struct vertex_buffer *VB = ctx->VB; - GLfloat (*win)[3] = VB->Win, - *proj = ctx->ProjectionMatrix, - ex, ey, - fx, fy, c, - wInv; - GLuint index, - pv, - facing; - - DPF(( DBG_FUNC, "RenderClippedPolygon();" )); - - DPF(( DBG_PRIM_INFO, "RenderClippedtPolygon( %d )", n )); - - /* Which vertex dictates the color when flat shading. */ - pv = (ctx->Primitive==GL_POLYGON) ? vlist[0] : vlist[n-1]; - - /* Clipping may introduce new vertices. New vertices will be stored in */ - /* the vertex buffer arrays starting with location VB->Free. After we've*/ - /* rendered the polygon, these extra vertices can be overwritten. */ - VB->Free = VB_MAX; - - /* Clip against user clipping planes in eye coord space. */ - if ( ctx->Transform.AnyClip ) - { - n = gl_userclip_polygon( ctx, n, vlist ); - if ( n < 3 ) - return; - - /* Transform vertices from eye to clip coordinates: clip = Proj * eye */ - for( index = 0; index < n; index++ ) - { - TRANSFORM_POINT( VB->Clip[vlist[index]], proj, VB->Eye[vlist[index]] ); - } - } - - /* Clip against view volume in clip coord space */ - n = gl_viewclip_polygon( ctx, n, vlist ); - if ( n < 3 ) - return; - - /* Transform new vertices from clip to ndc to window coords. */ - /* ndc = clip / W window = viewport_mapping(ndc) */ - /* Note that window Z values are scaled to the range of integer */ - /* depth buffer values. */ - - /* Only need to compute window coords for new vertices */ - for( index = VB_MAX; index < VB->Free; index++ ) - { - if ( VB->Clip[index][3] != 0.0F ) - { - wInv = 1.0F / VB->Clip[index][3]; - - win[index][0] = VB->Clip[index][0] * wInv * ctx->Viewport.Sx + ctx->Viewport.Tx; - win[index][1] = VB->Clip[index][1] * wInv * ctx->Viewport.Sy + ctx->Viewport.Ty; - win[index][2] = VB->Clip[index][2] * wInv * ctx->Viewport.Sz + ctx->Viewport.Tz; - } - else - { - /* Can't divide by zero, so... */ - win[index][0] = win[index][1] = win[index][2] = 0.0F; - } - } - - /* Draw filled polygon as a triangle fan */ - for( index = 2; index < n; index++ ) - { - /* Compute orientation of triangle */ - ex = win[vlist[index-1]][0] - win[vlist[0]][0]; - ey = win[vlist[index-1]][1] - win[vlist[0]][1]; - fx = win[vlist[index]][0] - win[vlist[0]][0]; - fy = win[vlist[index]][1] - win[vlist[0]][1]; - c = (ex * fy) - (ey * fx); - - /* polygon is perpindicular to view plane, don't draw it */ - if ( (c == 0.0F) && !ctx->Polygon.Unfilled ) - continue; - - /* Backface culling. */ - facing = (c < 0.0F) ^ ctx->Polygon.FrontBit; - if ( (facing + 1) & ctx->Polygon.CullBits ) - continue; - - if ( ctx->IndirectTriangles & DD_TRI_LIGHT_TWOSIDE ) - { - if ( facing == 1 ) - { - /* use back color */ - VB->Color = VB->Bcolor; - VB->Specular= VB->Bspec; - } - else - { - /* use front color */ - VB->Color = VB->Fcolor; - VB->Specular= VB->Fspec; - } - } - - if ( ctx->IndirectTriangles & DD_TRI_OFFSET ) - { - /* finish computing plane equation of polygon, compute offset */ - GLfloat fz = win[vlist[index]][2] - win[vlist[0]][2]; - GLfloat ez = win[vlist[index-1]][2] - win[vlist[0]][2]; - GLfloat a = (ey * fz) - (ez * fy); - GLfloat b = (ez * fx) - (ex * fz); - OffsetPolygon( ctx, a, b, c ); - } - RenderOneTriangle( ctx, vlist[0], vlist[index-1], vlist[index], pv ); - } -} -/*===========================================================================*/ -/* This function gets called when either the vertex buffer is full or glEnd */ -/* has been called. If the we aren't in rendering mode (FEEDBACK) then I */ -/* pass the vertex buffer back to Mesa to deal with by returning FALSE. */ -/* If I can render the primitive types in the buffer directly then I will */ -/* return TRUE after I render the vertex buffer and reset the vertex buffer. */ -/* */ -/* TODO: I don't handle the special case of when the vertex buffer is full */ -/* and we have a primitive that bounds this buffer and the next one to */ -/* come. I'm not sure right now if Mesa handles this for me... */ -/*===========================================================================*/ -/* RETURN: TRUE, FALSE. */ -/*===========================================================================*/ -GLboolean RenderVertexBuffer( GLcontext *ctx, GLboolean allDone ) -{ - struct vertex_buffer *VB = ctx->VB; - GLuint index, - vlist[VB_SIZE]; - - DPF(( DBG_FUNC, "RenderVertexBuffer();" )); - - /* We only need to hook actual tri's that need rendering. */ - if ( ctx->RenderMode != GL_RENDER ) - { - // (ctx->Visual->AccumBits > 0) ) - // (ctx->Visual->StencilBits > 0) ) - DPF(( DBG_PRIM_INFO, "Passing VB back to Mesa" )); - return FALSE; - } - - /* I'm going to set the states here so that all functions will */ - /* be assured to have the right states. If Mesa's vertex bufefr */ - /* function calls one of my primitive functions (TRI,POINT,LINE) */ - /* it will need the right states. So instead of doing it in the */ - /* primitive function I will always do it here at risk of some */ - /* slow down to some cases... */ - SetRenderStates( ctx ); - - switch( ctx->Primitive ) - { - case GL_POINTS: - DPF(( DBG_PRIM_INFO, "GL_POINTS( %d )", VB->Count )); - RenderPointsVB( ctx, 0, VB->Count ); - break; - - case GL_LINES: - case GL_LINE_STRIP: - case GL_LINE_LOOP: - /* Not supported functions yet so pass back that we failed to */ - /* render the vertex buffer and Mesa will have to do it. */ - DPF(( DBG_PRIM_INFO, "GL_LINE_?( %d )", VB->Count )); - return FALSE; - - case GL_TRIANGLES: - if ( VB->Count < 3 ) - { - DPF(( DBG_PRIM_WARN, "GL_TRIANGLES( %d )", VB->Count )); - return FALSE; - } - - DPF(( DBG_PRIM_INFO, "GL_TRIANGLES( %d )", VB->Count )); - RenderTriangleVB( ctx, 0, VB->Count ); - break; - - case GL_TRIANGLE_STRIP: - if ( VB->Count < 3 ) - { - DPF(( DBG_PRIM_WARN, "GL_TRIANGLE_STRIP( %d )", VB->Count )); - return FALSE; - } - - DPF(( DBG_PRIM_INFO, "GL_TRIANGLE_STRIP( %d )", VB->Count )); - RenderTriangleStripVB( ctx, 0, VB->Count ); - break; - - case GL_TRIANGLE_FAN: - if ( VB->Count < 3 ) - { - DPF(( DBG_PRIM_WARN, "GL_TRIANGLE_FAN( %d )", VB->Count )); - return FALSE; - } - - DPF(( DBG_PRIM_INFO, "GL_TRIANGLE_FAN( %d )", VB->Count )); - RenderTriangleFanVB( ctx, 0, VB->Count ); - break; - - case GL_QUADS: - if ( VB->Count < 4 ) - { - DPF(( DBG_PRIM_WARN, "GL_QUADS( %d )", VB->Count )); - return FALSE; - } - - DPF(( DBG_PRIM_INFO, "GL_QUADS( %d )", VB->Count )); - RenderQuadVB( ctx, 0, VB->Count ); - break; - - case GL_QUAD_STRIP: - if ( VB->Count < 4 ) - { - DPF(( DBG_PRIM_WARN, "GL_QUAD_STRIP( %d )", VB->Count )); - return FALSE; - } - - DPF(( DBG_PRIM_INFO, "GL_QUAD_STRIP( %d )", VB->Count )); - - if ( VB->ClipOrMask ) - { - for( index = 3; index < VB->Count; index += 2 ) - { - if ( VB->ClipMask[index-3] & VB->ClipMask[index-2] & VB->ClipMask[index-1] & VB->ClipMask[index] & CLIP_ALL_BITS ) - { - /* All points clipped by common plane */ - DPF(( DBG_PRIM_WARN, "GL_QUAD_STRIP( %d )", VB->Count )); - continue; - } - else if ( VB->ClipMask[index-3] | VB->ClipMask[index-2] | VB->ClipMask[index-1] | VB->ClipMask[index] ) - { - vlist[0] = index - 3; - vlist[1] = index - 2; - vlist[2] = index; - vlist[3] = index - 1; - RenderClippedPolygon( ctx, 4, vlist ); - } - else - { - RenderQuad( ctx, (index-3), (index-2), index, (index-1), index ); - } - } - } - else - { - /* No clipping needed */ - for( index = 3; index < VB->Count; index += 2 ) - RenderQuad( ctx, (index-3), (index-2), index, (index-1), index ); - } - break; - - case GL_POLYGON: - if ( VB->Count < 3 ) - { - DPF(( DBG_PRIM_WARN, "GL_POLYGON( %d )", VB->Count )); - return FALSE; - } - - DPF(( DBG_PRIM_INFO, "GL_POLYGON( %d )", VB->Count )); - - /* All points clipped by common plane, draw nothing */ - if ( !(VB->ClipAndMask & CLIP_ALL_BITS) ) - RenderTriangleFanVB( ctx, 0, VB->Count ); - break; - - default: - /* should never get here */ - _mesa_problem( ctx, "invalid mode in gl_render_vb" ); - } - - DPF(( DBG_PRIM_INFO, "ResetVB" )); - - /* We return TRUE to indicate we rendered the VB. */ - gl_reset_vb( ctx, allDone ); - return TRUE; -} -/*===========================================================================*/ -/* This function will render the current vertex buffer as triangles. The */ -/* buffer has to be able to be rendered directly. This means that we are */ -/* filled, no offsets, no culling and one sided rendering. Also we must be */ -/* in render mode of course. */ -/* First I will fill the global D3D vertice buffer. Next I will set all the*/ -/* states for D3D based on the current OGL state. Finally I pass the D3D VB */ -/* to the wrapper that call DrawPrimitives. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void RenderTriangleVB( GLcontext *ctx, GLuint start, GLuint end ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - struct vertex_buffer *VB = ctx->VB; - int index, - cVertex, - height = (pContext->pShared->rectW.bottom - pContext->pShared->rectW.top); - DWORD dwPVColor; - GLfloat ex, ey, - fx, fy, c; - GLuint facing; - - DPF(( DBG_FUNC, "RenderTriangleVB" )); - - if ( !VB->ClipOrMask ) - { - DPF(( DBG_PRIM_INFO, "DirectTriangles( %d )", (end-start) )); - for( index = start, cVertex = 0; index < end; ) - { - dwPVColor = (VB->Color[(index+2)][3]<<24) | (VB->Color[(index+2)][0]<<16) | (VB->Color[(index+2)][1]<<8) | VB->Color[(index+2)][2]; - - /*=====================================*/ - /* Populate the the triangle vertices. */ - /*=====================================*/ - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[index][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[index][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[index][2] ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[index][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[index][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? - dwPVColor : - (VB->Color[index][3]<<24) | (VB->Color[index][0]<<16) | (VB->Color[index][1]<<8) | VB->Color[index][2]; - index++; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[index][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[index][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[index][2] ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[index][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[index][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? - dwPVColor : - (VB->Color[index][3]<<24) | (VB->Color[index][0]<<16) | (VB->Color[index][1]<<8) | VB->Color[index][2]; - index++; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[index][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[index][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[index][2] ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[index][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[index][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); - D3DTLVertices[cVertex++].color= dwPVColor; - index++; - } - } - else - { -#define v1 index -#define v2 (index+1) -#define v3 (index+2) - - for( index = start, cVertex = 0; index < end; index += 3 ) - { - if ( VB->ClipMask[v1] & VB->ClipMask[v2] & VB->ClipMask[v3] & CLIP_ALL_BITS ) - { - continue; - } - else if ( VB->ClipMask[v1] | VB->ClipMask[v2] | VB->ClipMask[v3] ) - { - VList[0] = v1; - VList[1] = v2; - VList[2] = v3; - RenderClippedPolygon( ctx, 3, VList ); - continue; - } - - /* Compute orientation of triangle */ - ex = VB->Win[v2][0] - VB->Win[v1][0]; - ey = VB->Win[v2][1] - VB->Win[v1][1]; - fx = VB->Win[v3][0] - VB->Win[v1][0]; - fy = VB->Win[v3][1] - VB->Win[v1][1]; - c = (ex * fy) - (ey * fx); - - /* polygon is perpindicular to view plane, don't draw it */ - if ( (c == 0.0F) && !ctx->Polygon.Unfilled ) - continue; - - /* Backface culling. */ - facing = (c < 0.0F) ^ ctx->Polygon.FrontBit; - if ( (facing + 1) & ctx->Polygon.CullBits ) - continue; - - if ( ctx->IndirectTriangles & DD_TRI_LIGHT_TWOSIDE ) - { - if ( facing == 1 ) - { - /* use back color */ - VB->Color = VB->Bcolor; - VB->Specular= VB->Bspec; - } - else - { - /* use front color */ - VB->Color = VB->Fcolor; - VB->Specular= VB->Fspec; - } - } - - if ( ctx->IndirectTriangles & DD_TRI_OFFSET ) - { - /* Finish computing plane equation of polygon, compute offset */ - GLfloat fz = VB->Win[v3][2] - VB->Win[v1][2]; - GLfloat ez = VB->Win[v2][2] - VB->Win[v1][2]; - GLfloat a = (ey * fz) - (ez * fy); - GLfloat b = (ez * fx) - (ex * fz); - OffsetPolygon( ctx, a, b, c ); - } - - /*=====================================*/ - /* Populate the the triangle vertices. */ - /*=====================================*/ - /* Solve the prevoking vertex color as we need it for the 3rd triangle and flat shading. */ - dwPVColor = (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v1][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v1][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v1][2] + ctx->PolygonZoffset) ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v1][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v1][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? - dwPVColor : - (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v2][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v2][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v2][2] + ctx->PolygonZoffset) ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v2][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v2][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v2][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? - dwPVColor : - (VB->Color[v2][3]<<24) | (VB->Color[v2][0]<<16) | (VB->Color[v2][1]<<8) | VB->Color[v2][2]; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v3][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v3][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v3][2] + ctx->PolygonZoffset) ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v3][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v3][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); - D3DTLVertices[cVertex++].color= dwPVColor; - } -#undef v1 -#undef v2 -#undef v3 - } - - /* Render the converted vertex buffer. */ - if ( cVertex > 2 ) - DrawPrimitiveHAL( pContext->pShared, D3DPT_TRIANGLELIST, &D3DTLVertices[0], cVertex ); -} -/*===========================================================================*/ -/* This function will render the current vertex buffer as a triangle fan. */ -/* The buffer has to be able to be rendered directly. This means that we are*/ -/* filled, no offsets, no culling and one sided rendering. Also we must be */ -/* in render mode of course. */ -/* First I will fill the global D3D vertice buffer. Next I will set all the*/ -/* states for D3D based on the current OGL state. Finally I pass the D3D VB */ -/* to the wrapper that call DrawPrimitives. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void RenderTriangleFanVB( GLcontext *ctx, GLuint start, GLuint end ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - struct vertex_buffer *VB = ctx->VB; - int index, - cVertex, - height = (pContext->pShared->rectW.bottom - pContext->pShared->rectW.top); - GLfloat ex, ey, - fx, fy, c; - GLuint facing; - DWORD dwPVColor; - - DPF(( DBG_FUNC, "RenderTriangleFanVB();" )); - - /* Special case that we can blast the fan without culling, offset, etc... */ - if ( !VB->ClipOrMask && (ctx->Light.ShadeModel != GL_FLAT) ) - { - DPF(( DBG_PRIM_INFO, "DirectTriangles( %d )", (end-start) )); - - /* Seed the the fan. */ - D3DTLVertices[0].sx = D3DVAL( VB->Win[start][0] ); - D3DTLVertices[0].sy = D3DVAL( (height - VB->Win[start][1]) ); - D3DTLVertices[0].sz = D3DVAL( VB->Win[start][2] ); - D3DTLVertices[0].tu = D3DVAL( VB->TexCoord[start][0] ); - D3DTLVertices[0].tv = D3DVAL( VB->TexCoord[start][1] ); - D3DTLVertices[0].rhw = D3DVAL( (1.0 / VB->Clip[start][3]) ); - D3DTLVertices[0].color= (VB->Color[start][3]<<24) | (VB->Color[start][0]<<16) | (VB->Color[start][1]<<8) | VB->Color[start][2]; - - /* Seed the the fan. */ - D3DTLVertices[1].sx = D3DVAL( VB->Win[(start+1)][0] ); - D3DTLVertices[1].sy = D3DVAL( (height - VB->Win[(start+1)][1]) ); - D3DTLVertices[1].sz = D3DVAL( VB->Win[(start+1)][2] ); - D3DTLVertices[1].tu = D3DVAL( VB->TexCoord[(start+1)][0] ); - D3DTLVertices[1].tv = D3DVAL( VB->TexCoord[(start+1)][1] ); - D3DTLVertices[1].rhw = D3DVAL( (1.0 / VB->Clip[(start+1)][3]) ); - D3DTLVertices[1].color= (VB->Color[(start+1)][3]<<24) | (VB->Color[(start+1)][0]<<16) | (VB->Color[(start+1)][1]<<8) | VB->Color[(start+1)][2]; - - for( index = (start+2), cVertex = 2; index < end; index++, cVertex++ ) - { - /*=================================*/ - /* Add the next vertex to the fan. */ - /*=================================*/ - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[index][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[index][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[index][2] ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[index][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[index][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); - D3DTLVertices[cVertex].color = (VB->Color[index][3]<<24) | (VB->Color[index][0]<<16) | (VB->Color[index][1]<<8) | VB->Color[index][2]; - } - - /* Render the converted vertex buffer. */ - if ( cVertex ) - DrawPrimitiveHAL( pContext->pShared, D3DPT_TRIANGLEFAN, &D3DTLVertices[0], cVertex ); - } - else - { -#define v1 start -#define v2 (index-1) -#define v3 index - - for( index = (start+2), cVertex = 0; index < end; index++ ) - { - if ( VB->ClipOrMask ) - { - /* All points clipped by common plane */ - if ( VB->ClipMask[v1] & VB->ClipMask[v2] & VB->ClipMask[v3] & CLIP_ALL_BITS ) - { - continue; - } - else if ( VB->ClipMask[v1] | VB->ClipMask[v2] | VB->ClipMask[v3] ) - { - VList[0] = v1; - VList[1] = v2; - VList[2] = v3; - RenderClippedPolygon( ctx, 3, VList ); - continue; - } - } - - /* Compute orientation of triangle */ - ex = VB->Win[v2][0] - VB->Win[v1][0]; - ey = VB->Win[v2][1] - VB->Win[v1][1]; - fx = VB->Win[v3][0] - VB->Win[v1][0]; - fy = VB->Win[v3][1] - VB->Win[v1][1]; - c = (ex * fy) - (ey * fx); - - /* polygon is perpindicular to view plane, don't draw it */ - if ( (c == 0.0F) && !ctx->Polygon.Unfilled ) - continue; - - /* Backface culling. */ - facing = (c < 0.0F) ^ ctx->Polygon.FrontBit; - if ( (facing + 1) & ctx->Polygon.CullBits ) - continue; - - if ( ctx->IndirectTriangles & DD_TRI_OFFSET ) - { - /* Finish computing plane equation of polygon, compute offset */ - GLfloat fz = VB->Win[v3][2] - VB->Win[v1][2]; - GLfloat ez = VB->Win[v2][2] - VB->Win[v1][2]; - GLfloat a = (ey * fz) - (ez * fy); - GLfloat b = (ez * fx) - (ex * fz); - OffsetPolygon( ctx, a, b, c ); - } - - /*=====================================*/ - /* Populate the the triangle vertices. */ - /*=====================================*/ - dwPVColor = (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v1][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v1][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v1][2] + ctx->PolygonZoffset) ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v1][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v1][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : - (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v2][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v2][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v2][2] + ctx->PolygonZoffset) ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v2][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v2][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v2][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : - (VB->Color[v2][3]<<24) | (VB->Color[v2][0]<<16) | (VB->Color[v2][1]<<8) | VB->Color[v2][2]; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v3][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v3][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v3][2] + ctx->PolygonZoffset) ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v3][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v3][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); - D3DTLVertices[cVertex++].color= dwPVColor; - } - - /* Render the converted vertex buffer. */ - if ( cVertex ) - DrawPrimitiveHAL( pContext->pShared, D3DPT_TRIANGLELIST, &D3DTLVertices[0], cVertex ); -#undef v1 -#undef v2 -#undef v3 - } -} -/*===========================================================================*/ -/* This function will render the current vertex buffer as a triangle strip. */ -/* The buffer has to be able to be rendered directly. This means that we are*/ -/* filled, no offsets, no culling and one sided rendering. Also we must be */ -/* in render mode of course. */ -/* First I will fill the global D3D vertice buffer. Next I will set all the*/ -/* states for D3D based on the current OGL state. Finally I pass the D3D VB */ -/* to the wrapper that call DrawPrimitives. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void RenderTriangleStripVB( GLcontext *ctx, GLuint start, GLuint end ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - struct vertex_buffer *VB = ctx->VB; - int index, - cVertex = 0, - v1, v2, v3, - height = (pContext->pShared->rectW.bottom - pContext->pShared->rectW.top); - GLfloat ex, ey, - fx, fy, c; - GLuint facing; - DWORD dwPVColor; - - DPF(( DBG_FUNC, "RenderTriangleStripVB();" )); - - /* Special case that we can blast the fan without culling, offset, etc... */ - if ( !VB->ClipOrMask && (ctx->Light.ShadeModel != GL_FLAT) ) - { - DPF(( DBG_PRIM_PROFILE, "DirectTriangles" )); - - /* Seed the the strip. */ - D3DTLVertices[0].sx = D3DVAL( VB->Win[start][0] ); - D3DTLVertices[0].sy = D3DVAL( (height - VB->Win[start][1]) ); - D3DTLVertices[0].sz = D3DVAL( VB->Win[start][2] ); - D3DTLVertices[0].tu = D3DVAL( VB->TexCoord[start][0] ); - D3DTLVertices[0].tv = D3DVAL( VB->TexCoord[start][1] ); - D3DTLVertices[0].rhw = D3DVAL( (1.0 / VB->Clip[start][3]) ); - D3DTLVertices[0].color= (VB->Color[start][3]<<24) | (VB->Color[start][0]<<16) | (VB->Color[start][1]<<8) | VB->Color[start][2]; - - /* Seed the the strip. */ - D3DTLVertices[1].sx = D3DVAL( VB->Win[(start+1)][0] ); - D3DTLVertices[1].sy = D3DVAL( (height - VB->Win[(start+1)][1]) ); - D3DTLVertices[1].sz = D3DVAL( VB->Win[(start+1)][2] ); - D3DTLVertices[1].tu = D3DVAL( VB->TexCoord[(start+1)][0] ); - D3DTLVertices[1].tv = D3DVAL( VB->TexCoord[(start+1)][1] ); - D3DTLVertices[1].rhw = D3DVAL( (1.0 / VB->Clip[(start+1)][3]) ); - D3DTLVertices[1].color= (VB->Color[(start+1)][3]<<24) | (VB->Color[(start+1)][0]<<16) | (VB->Color[(start+1)][1]<<8) | VB->Color[(start+1)][2]; - - for( index = (start+2), cVertex = 2; index < end; index++, cVertex++ ) - { - /*===================================*/ - /* Add the next vertex to the strip. */ - /*===================================*/ - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[index][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[index][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[index][2] ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[index][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[index][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); - D3DTLVertices[cVertex].color = (VB->Color[index][3]<<24) | (VB->Color[index][0]<<16) | (VB->Color[index][1]<<8) | VB->Color[index][2]; - } - - /* Render the converted vertex buffer. */ - if ( cVertex ) - DrawPrimitiveHAL( pContext->pShared, D3DPT_TRIANGLESTRIP, &D3DTLVertices[0], cVertex ); - } - else - { - for( index = (start+2); index < end; index++ ) - { - /* We need to switch order so that winding won't be a problem. */ - if ( index & 1 ) - { - v1 = index - 1; - v2 = index - 2; - v3 = index - 0; - } - else - { - v1 = index - 2; - v2 = index - 1; - v3 = index - 0; - } - - /* All vertices clipped by common plane */ - if ( VB->ClipMask[v1] & VB->ClipMask[v2] & VB->ClipMask[v3] & CLIP_ALL_BITS ) - continue; - - /* Check if any vertices need clipping. */ - if ( VB->ClipMask[v1] | VB->ClipMask[v2] | VB->ClipMask[v3] ) - { - VList[0] = v1; - VList[1] = v2; - VList[2] = v3; - RenderClippedPolygon( ctx, 3, VList ); - } - else - { - /* Compute orientation of triangle */ - ex = VB->Win[v2][0] - VB->Win[v1][0]; - ey = VB->Win[v2][1] - VB->Win[v1][1]; - fx = VB->Win[v3][0] - VB->Win[v1][0]; - fy = VB->Win[v3][1] - VB->Win[v1][1]; - c = (ex * fy) - (ey * fx); - - /* Polygon is perpindicular to view plane, don't draw it */ - if ( (c == 0.0F) && !ctx->Polygon.Unfilled ) - continue; - - /* Backface culling. */ - facing = (c < 0.0F) ^ ctx->Polygon.FrontBit; - if ( (facing + 1) & ctx->Polygon.CullBits ) - continue; - - /* Need right color if we have two sided lighting. */ - if ( ctx->IndirectTriangles & DD_TRI_LIGHT_TWOSIDE ) - { - if ( facing == 1 ) - { - /* use back color */ - VB->Color = VB->Bcolor; - VB->Specular= VB->Bspec; - } - else - { - /* use front color */ - VB->Color = VB->Fcolor; - VB->Specular= VB->Fspec; - } - } - - if ( ctx->IndirectTriangles & DD_TRI_OFFSET ) - { - /* Finish computing plane equation of polygon, compute offset */ - GLfloat fz = VB->Win[v3][2] - VB->Win[v1][2]; - GLfloat ez = VB->Win[v2][2] - VB->Win[v1][2]; - GLfloat a = (ey * fz) - (ez * fy); - GLfloat b = (ez * fx) - (ex * fz); - OffsetPolygon( ctx, a, b, c ); - } - /*=====================================*/ - /* Populate the the triangle vertices. */ - /*=====================================*/ - - /* Solve the prevoking vertex color as we need it for the 3rd triangle and flat shading. */ - dwPVColor = (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v1][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v1][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v1][2] + ctx->PolygonZoffset) ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v1][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v1][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? - dwPVColor : - (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v2][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v2][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v2][2] + ctx->PolygonZoffset) ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v2][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v2][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v2][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? - dwPVColor : - (VB->Color[v2][3]<<24) | (VB->Color[v2][0]<<16) | (VB->Color[v2][1]<<8) | VB->Color[v2][2]; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v3][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v3][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v3][2] + ctx->PolygonZoffset) ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v3][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v3][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); - D3DTLVertices[cVertex++].color= dwPVColor; - } - } - - /* Render the converted vertex buffer. */ - if ( cVertex ) - DrawPrimitiveHAL( pContext->pShared, D3DPT_TRIANGLELIST, &D3DTLVertices[0], cVertex ); - } -} -/*===========================================================================*/ -/* This function will render the current vertex buffer as Quads. The buffer*/ -/* has to be able to be rendered directly. This means that we are filled, no*/ -/* offsets, no culling and one sided rendering. Also we must be in render */ -/* mode of cource. */ -/* First I will fill the global D3D vertice buffer. Next I will set all the*/ -/* states for D3D based on the current OGL state. Finally I pass the D3D VB */ -/* to the wrapper that call DrawPrimitives. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void RenderQuadVB( GLcontext *ctx, GLuint start, GLuint end ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - struct vertex_buffer *VB = ctx->VB; - int index, - cVertex, - height = (pContext->pShared->rectW.bottom - pContext->pShared->rectW.top); - DWORD dwPVColor; - GLfloat ex, ey, - fx, fy, c; - GLuint facing; /* 0=front, 1=back */ - - DPF(( DBG_FUNC, "RenderQuadVB();" )); - -#define v1 (index) -#define v2 (index+1) -#define v3 (index+2) -#define v4 (index+3) - - if ( !VB->ClipOrMask ) - { - DPF(( DBG_PRIM_PROFILE, "DirectTriangles" )); - - for( cVertex = 0, index = start; index < end; index += 4 ) - { - if ( ctx->Light.ShadeModel == GL_FLAT ) - dwPVColor = (VB->Color[v4][3]<<24) | (VB->Color[v4][0]<<16) | (VB->Color[v4][1]<<8) | VB->Color[v4][2]; - - /*=====================================*/ - /* Populate the the triangle vertices. */ - /*=====================================*/ - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v1][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v1][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[v1][2] ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v1][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v1][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? - dwPVColor : - (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v2][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v2][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[v2][2] ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v2][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v2][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v2][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? - dwPVColor : - (VB->Color[v2][3]<<24) | (VB->Color[v2][0]<<16) | (VB->Color[v2][1]<<8) | VB->Color[v2][2]; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v3][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v3][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[v3][2] ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v3][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v3][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? - dwPVColor : - (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v1][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v1][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[v1][2] ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v1][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v1][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? - dwPVColor : - (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v3][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v3][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[v3][2] ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v3][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v3][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? - dwPVColor : - (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v4][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v4][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[v4][2] ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v4][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v4][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v4][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? - dwPVColor : - (VB->Color[v4][3]<<24) | (VB->Color[v4][0]<<16) | (VB->Color[v4][1]<<8) | VB->Color[v4][2]; - } - } - else - { - for( cVertex = 0, index = start; index < end; index += 4 ) - { - if ( VB->ClipMask[v1] & VB->ClipMask[v2] & VB->ClipMask[v3] & VB->ClipMask[v4] & CLIP_ALL_BITS ) - { - continue; - } - else if ( VB->ClipMask[v1] | VB->ClipMask[v2] | VB->ClipMask[v3] | VB->ClipMask[v4] ) - { - VList[0] = v1; - VList[1] = v2; - VList[2] = v3; - VList[3] = v4; - RenderClippedPolygon( ctx, 4, VList ); - continue; - } - - /* Compute orientation of triangle */ - ex = VB->Win[v2][0] - VB->Win[v1][0]; - ey = VB->Win[v2][1] - VB->Win[v1][1]; - fx = VB->Win[v3][0] - VB->Win[v1][0]; - fy = VB->Win[v3][1] - VB->Win[v1][1]; - c = (ex * fy) - (ey * fx); - - /* polygon is perpindicular to view plane, don't draw it */ - if ( (c == 0.0F) && !ctx->Polygon.Unfilled ) - continue; - - /* Backface culling. */ - facing = (c < 0.0F) ^ ctx->Polygon.FrontBit; - if ( (facing + 1) & ctx->Polygon.CullBits ) - continue; - - if ( ctx->IndirectTriangles & DD_TRI_LIGHT_TWOSIDE ) - { - if ( facing == 1 ) - { - /* use back color */ - VB->Color = VB->Bcolor; - VB->Specular= VB->Bspec; - } - else - { - /* use front color */ - VB->Color = VB->Fcolor; - VB->Specular= VB->Fspec; - } - } - - if ( ctx->IndirectTriangles & DD_TRI_OFFSET ) - { - /* Finish computing plane equation of polygon, compute offset */ - GLfloat fz = VB->Win[v3][2] - VB->Win[v1][2]; - GLfloat ez = VB->Win[v2][2] - VB->Win[v1][2]; - GLfloat a = (ey * fz) - (ez * fy); - GLfloat b = (ez * fx) - (ex * fz); - OffsetPolygon( ctx, a, b, c ); - } - - if ( ctx->Light.ShadeModel == GL_FLAT ) - dwPVColor = (VB->Color[v4][3]<<24) | (VB->Color[v4][0]<<16) | (VB->Color[v4][1]<<8) | VB->Color[v4][2]; - - /*=====================================*/ - /* Populate the the triangle vertices. */ - /*=====================================*/ - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v1][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v1][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v1][2] + ctx->PolygonZoffset) ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v1][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v1][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? - dwPVColor : - (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v2][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v2][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v2][2] + ctx->PolygonZoffset) ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v2][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v2][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v2][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? - dwPVColor : - (VB->Color[v2][3]<<24) | (VB->Color[v2][0]<<16) | (VB->Color[v2][1]<<8) | VB->Color[v2][2]; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v3][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v3][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v3][2] + ctx->PolygonZoffset) ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v3][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v3][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? - dwPVColor : - (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v1][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v1][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v1][2] + ctx->PolygonZoffset) ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v1][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v1][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? - dwPVColor : - (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v3][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v3][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v3][2] + ctx->PolygonZoffset) ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v3][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v3][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? - dwPVColor : - (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; - - D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v4][0] ); - D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v4][1]) ); - D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v4][2] + ctx->PolygonZoffset) ); - D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v4][0] ); - D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v4][1] ); - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v4][3]) ); - D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? - dwPVColor : - (VB->Color[v4][3]<<24) | (VB->Color[v4][0]<<16) | (VB->Color[v4][1]<<8) | VB->Color[v4][2]; - } - } - -#undef v4 -#undef v3 -#undef v2 -#undef v1 - - /* Render the converted vertex buffer. */ - if ( cVertex ) - DrawPrimitiveHAL( pContext->pShared, D3DPT_TRIANGLELIST, &D3DTLVertices[0], cVertex ); -} -/*===========================================================================*/ -/* */ -/*===========================================================================*/ -/* RETURN: TRUE, FALSE. */ -/*===========================================================================*/ -static void RenderQuad( GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint v4, GLuint pv ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - struct vertex_buffer *VB = ctx->VB; - int height = (pContext->pShared->rectW.bottom - pContext->pShared->rectW.top); - DWORD dwPVColor; - GLfloat ex, ey, - fx, fy, c; - GLuint facing; /* 0=front, 1=back */ - static D3DTLVERTEX TLVertices[6]; - - DPF(( DBG_FUNC, "RenderQuad" )); - DPF(( DBG_PRIM_INFO, "RenderQuad( 1 )" )); - - /* Compute orientation of triangle */ - ex = VB->Win[v2][0] - VB->Win[v1][0]; - ey = VB->Win[v2][1] - VB->Win[v1][1]; - fx = VB->Win[v3][0] - VB->Win[v1][0]; - fy = VB->Win[v3][1] - VB->Win[v1][1]; - c = (ex * fy) - (ey * fx); - - /* polygon is perpindicular to view plane, don't draw it */ - if ( (c == 0.0F) && !ctx->Polygon.Unfilled ) - return; - - /* Backface culling. */ - facing = (c < 0.0F) ^ ctx->Polygon.FrontBit; - if ( (facing + 1) & ctx->Polygon.CullBits ) - return; - - if ( ctx->IndirectTriangles & DD_TRI_LIGHT_TWOSIDE ) - { - if ( facing == 1 ) - { - /* use back color */ - VB->Color = VB->Bcolor; - VB->Specular= VB->Bspec; - } - else - { - /* use front color */ - VB->Color = VB->Fcolor; - VB->Specular= VB->Fspec; - } - } - - if ( ctx->IndirectTriangles & DD_TRI_OFFSET ) - { - /* Finish computing plane equation of polygon, compute offset */ - GLfloat fz = VB->Win[v3][2] - VB->Win[v1][2]; - GLfloat ez = VB->Win[v2][2] - VB->Win[v1][2]; - GLfloat a = (ey * fz) - (ez * fy); - GLfloat b = (ez * fx) - (ex * fz); - OffsetPolygon( ctx, a, b, c ); - } - - if ( ctx->Light.ShadeModel == GL_FLAT ) - dwPVColor = (VB->Color[pv][3]<<24) | (VB->Color[pv][0]<<16) | (VB->Color[pv][1]<<8) | VB->Color[pv][2]; - - /*=====================================*/ - /* Populate the the triangle vertices. */ - /*=====================================*/ - TLVertices[0].sx = D3DVAL( VB->Win[v1][0] ); - TLVertices[0].sy = D3DVAL( (height - VB->Win[v1][1]) ); - TLVertices[0].sz = D3DVAL( (VB->Win[v1][2] + ctx->PolygonZoffset) ); - TLVertices[0].tu = D3DVAL( VB->TexCoord[v1][0] ); - TLVertices[0].tv = D3DVAL( VB->TexCoord[v1][1] ); - TLVertices[0].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); - TLVertices[0].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : - (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; - - TLVertices[1].sx = D3DVAL( VB->Win[v2][0] ); - TLVertices[1].sy = D3DVAL( (height - VB->Win[v2][1]) ); - TLVertices[1].sz = D3DVAL( (VB->Win[v2][2] + ctx->PolygonZoffset) ); - TLVertices[1].tu = D3DVAL( VB->TexCoord[v2][0] ); - TLVertices[1].tv = D3DVAL( VB->TexCoord[v2][1] ); - TLVertices[1].rhw = D3DVAL( (1.0 / VB->Clip[v2][3]) ); - TLVertices[1].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : - (VB->Color[v2][3]<<24) | (VB->Color[v2][0]<<16) | (VB->Color[v2][1]<<8) | VB->Color[v2][2]; - - TLVertices[2].sx = D3DVAL( VB->Win[v3][0] ); - TLVertices[2].sy = D3DVAL( (height - VB->Win[v3][1]) ); - TLVertices[2].sz = D3DVAL( (VB->Win[v3][2] + ctx->PolygonZoffset) ); - TLVertices[2].tu = D3DVAL( VB->TexCoord[v3][0] ); - TLVertices[2].tv = D3DVAL( VB->TexCoord[v3][1] ); - TLVertices[2].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); - TLVertices[2].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : - (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; - - TLVertices[3].sx = D3DVAL( VB->Win[v3][0] ); - TLVertices[3].sy = D3DVAL( (height - VB->Win[v3][1]) ); - TLVertices[3].sz = D3DVAL( (VB->Win[v3][2] + ctx->PolygonZoffset) ); - TLVertices[3].tu = D3DVAL( VB->TexCoord[v3][0] ); - TLVertices[3].tv = D3DVAL( VB->TexCoord[v3][1] ); - TLVertices[3].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); - TLVertices[3].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : - (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; - - TLVertices[4].sx = D3DVAL( VB->Win[v4][0] ); - TLVertices[4].sy = D3DVAL( (height - VB->Win[v4][1]) ); - TLVertices[4].sz = D3DVAL( (VB->Win[v4][2] + ctx->PolygonZoffset) ); - TLVertices[4].tu = D3DVAL( VB->TexCoord[v4][0] ); - TLVertices[4].tv = D3DVAL( VB->TexCoord[v4][1] ); - TLVertices[4].rhw = D3DVAL( (1.0 / VB->Clip[v4][3]) ); - TLVertices[4].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : - (VB->Color[v4][3]<<24) | (VB->Color[v4][0]<<16) | (VB->Color[v4][1]<<8) | VB->Color[v4][2]; - - TLVertices[5].sx = D3DVAL( VB->Win[v1][0] ); - TLVertices[5].sy = D3DVAL( (height - VB->Win[v1][1]) ); - TLVertices[5].sz = D3DVAL( (VB->Win[v1][2] + ctx->PolygonZoffset) ); - TLVertices[5].tu = D3DVAL( VB->TexCoord[v1][0] ); - TLVertices[5].tv = D3DVAL( VB->TexCoord[v1][1] ); - TLVertices[5].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); - TLVertices[5].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : - (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; - - /* Draw the two triangles. */ - DrawPrimitiveHAL( pContext->pShared, D3DPT_TRIANGLELIST, &TLVertices[0], 6 ); -} -/*===========================================================================*/ -/* */ -/*===========================================================================*/ -/* RETURN: TRUE, FALSE. */ -/*===========================================================================*/ -void RenderOneTriangle( GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint pv ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - struct vertex_buffer *VB = ctx->VB; - int height = (pContext->pShared->rectW.bottom - pContext->pShared->rectW.top); - DWORD dwPVColor; - static D3DTLVERTEX TLVertices[3]; - - DPF(( DBG_FUNC, "RenderOneTriangle" )); - DPF(( DBG_PRIM_INFO, "RenderTriangle( 1 )" )); - - /*=====================================*/ - /* Populate the the triangle vertices. */ - /*=====================================*/ - if ( ctx->Light.ShadeModel == GL_FLAT ) - dwPVColor = (VB->Color[pv][3]<<24) | (VB->Color[pv][0]<<16) | (VB->Color[pv][1]<<8) | VB->Color[pv][2]; - - TLVertices[0].sx = D3DVAL( VB->Win[v1][0] ); - TLVertices[0].sy = D3DVAL( (height - VB->Win[v1][1]) ); - TLVertices[0].sz = D3DVAL( (VB->Win[v1][2] + ctx->PolygonZoffset) ); - TLVertices[0].tu = D3DVAL( VB->TexCoord[v1][0] ); - TLVertices[0].tv = D3DVAL( VB->TexCoord[v1][1] ); - TLVertices[0].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); - TLVertices[0].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : - (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; - DPF(( DBG_PRIM_INFO, "V1 -> x:%f y:%f z:%f c:%x", - TLVertices[0].sx, - TLVertices[0].sy, - TLVertices[0].sz, - TLVertices[0].color )); - - TLVertices[1].sx = D3DVAL( VB->Win[v2][0] ); - TLVertices[1].sy = D3DVAL( (height - VB->Win[v2][1]) ); - TLVertices[1].sz = D3DVAL( (VB->Win[v2][2] + ctx->PolygonZoffset) ); - TLVertices[1].tu = D3DVAL( VB->TexCoord[v2][0] ); - TLVertices[1].tv = D3DVAL( VB->TexCoord[v2][1] ); - TLVertices[1].rhw = D3DVAL( (1.0 / VB->Clip[v2][3]) ); - TLVertices[1].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : - (VB->Color[v2][3]<<24) | (VB->Color[v2][0]<<16) | (VB->Color[v2][1]<<8) | VB->Color[v2][2]; - DPF(( DBG_PRIM_INFO, "V2 -> x:%f y:%f z:%f c:%x", - TLVertices[1].sx, - TLVertices[1].sy, - TLVertices[1].sz, - TLVertices[1].color )); - - TLVertices[2].sx = D3DVAL( VB->Win[v3][0] ); - TLVertices[2].sy = D3DVAL( (height - VB->Win[v3][1]) ); - TLVertices[2].sz = D3DVAL( (VB->Win[v3][2] + ctx->PolygonZoffset) ); - TLVertices[2].tu = D3DVAL( VB->TexCoord[v3][0] ); - TLVertices[2].tv = D3DVAL( VB->TexCoord[v3][1] ); - TLVertices[2].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); - TLVertices[2].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : - (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; - DPF(( DBG_PRIM_INFO, "V3 -> x:%f y:%f z:%f c:%x", - TLVertices[2].sx, - TLVertices[2].sy, - TLVertices[2].sz, - TLVertices[2].color )); - - /* Draw the triangle. */ - DrawPrimitiveHAL( pContext->pShared, D3DPT_TRIANGLELIST, &TLVertices[0], 3 ); -} -/*===========================================================================*/ -/* */ -/*===========================================================================*/ -/* RETURN: TRUE, FALSE. */ -/*===========================================================================*/ -void RenderOneLine( GLcontext *ctx, GLuint v1, GLuint v2, GLuint pv ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - struct vertex_buffer *VB = ctx->VB; - int height = (pContext->pShared->rectW.bottom - pContext->pShared->rectW.top); - DWORD dwPVColor; - static D3DTLVERTEX TLVertices[2]; - - DPF(( DBG_FUNC, "RenderOneLine" )); - DPF(( DBG_PRIM_INFO, "RenderLine( 1 )" )); - - if ( VB->MonoColor ) - dwPVColor = (pContext->aCurrent<<24) | (pContext->rCurrent<<16) | (pContext->gCurrent<<8) | pContext->bCurrent; - else - dwPVColor = (VB->Color[pv][3]<<24) | (VB->Color[pv][0]<<16) | (VB->Color[pv][1]<<8) | VB->Color[pv][2]; - - TLVertices[0].sx = D3DVAL( VB->Win[v1][0] ); - TLVertices[0].sy = D3DVAL( (height - VB->Win[v1][1]) ); - TLVertices[0].sz = D3DVAL( (VB->Win[v1][2] + ctx->LineZoffset) ); - TLVertices[0].tu = D3DVAL( VB->TexCoord[v1][0] ); - TLVertices[0].tv = D3DVAL( VB->TexCoord[v1][1] ); - TLVertices[0].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); - TLVertices[0].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : - (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; - - TLVertices[1].sx = D3DVAL( VB->Win[v2][0] ); - TLVertices[1].sy = D3DVAL( (height - VB->Win[v2][1]) ); - TLVertices[1].sz = D3DVAL( (VB->Win[v2][2] + ctx->LineZoffset) ); - TLVertices[1].tu = D3DVAL( VB->TexCoord[v2][0] ); - TLVertices[1].tv = D3DVAL( VB->TexCoord[v2][1] ); - TLVertices[1].rhw = D3DVAL( (1.0 / VB->Clip[v2][3]) ); - TLVertices[1].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : - (VB->Color[v2][3]<<24) | (VB->Color[v2][0]<<16) | (VB->Color[v2][1]<<8) | VB->Color[v2][2]; - - /* Draw line from (x0,y0) to (x1,y1) with current pixel color/index */ - DrawPrimitiveHAL( pContext->pShared, D3DPT_LINELIST, &TLVertices[0], 2 ); -} -/*===========================================================================*/ -/* This function was written to convert points into triangles. I did this */ -/* as all card accelerate triangles and most drivers do this anyway. In hind*/ -/* thought this might be a bad idea as some cards do better. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void RenderPointsVB( GLcontext *ctx, GLuint start, GLuint end ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - struct vertex_buffer *VB = ctx->VB; - struct pixel_buffer *PB = ctx->PB; - GLuint index; - GLfloat radius, z, - xmin, ymin, - xmax, ymax; - GLint cVertex, - height = (pContext->pShared->rectW.bottom - pContext->pShared->rectW.top); - DWORD dwPVColor; - - DPF(( DBG_FUNC, "RenderPointsVB();" )); - - radius = CLAMP( ctx->Point.Size, MIN_POINT_SIZE, MAX_POINT_SIZE ) * 0.5F; - - for( index = start, cVertex = 0; index <= end; index++ ) - { - if ( VB->ClipMask[index] == 0 ) - { - xmin = D3DVAL( VB->Win[index][0] - radius ); - xmax = D3DVAL( VB->Win[index][0] + radius ); - ymin = D3DVAL( height - VB->Win[index][1] - radius ); - ymax = D3DVAL( height - VB->Win[index][1] + radius ); - z = D3DVAL( (VB->Win[index][2] + ctx->PointZoffset) ); - - dwPVColor = (VB->Color[index][3]<<24) | - (VB->Color[index][0]<<16) | - (VB->Color[index][1]<<8) | - VB->Color[index][2]; - - D3DTLVertices[cVertex].sx = xmin; - D3DTLVertices[cVertex].sy = ymax; - D3DTLVertices[cVertex].sz = z; - D3DTLVertices[cVertex].tu = 0.0; - D3DTLVertices[cVertex].tv = 0.0; - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); - D3DTLVertices[cVertex++].color = dwPVColor; - - D3DTLVertices[cVertex].sx = xmin; - D3DTLVertices[cVertex].sy = ymin; - D3DTLVertices[cVertex].sz = z; - D3DTLVertices[cVertex].tu = 0.0; - D3DTLVertices[cVertex].tv = 0.0; - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); - D3DTLVertices[cVertex++].color = dwPVColor; - - D3DTLVertices[cVertex].sx = xmax; - D3DTLVertices[cVertex].sy = ymin; - D3DTLVertices[cVertex].sz = z; - D3DTLVertices[cVertex].tu = 0.0; - D3DTLVertices[cVertex].tv = 0.0; - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); - D3DTLVertices[cVertex++].color = dwPVColor; - - D3DTLVertices[cVertex].sx = xmax; - D3DTLVertices[cVertex].sy = ymin; - D3DTLVertices[cVertex].sz = z; - D3DTLVertices[cVertex].tu = 0.0; - D3DTLVertices[cVertex].tv = 0.0; - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); - D3DTLVertices[cVertex++].color = dwPVColor; - - D3DTLVertices[cVertex].sx = xmax; - D3DTLVertices[cVertex].sy = ymax; - D3DTLVertices[cVertex].sz = z; - D3DTLVertices[cVertex].tu = 0.0; - D3DTLVertices[cVertex].tv = 0.0; - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); - D3DTLVertices[cVertex++].color = dwPVColor; - - D3DTLVertices[cVertex].sx = xmin; - D3DTLVertices[cVertex].sy = ymax; - D3DTLVertices[cVertex].sz = z; - D3DTLVertices[cVertex].tu = 0.0; - D3DTLVertices[cVertex].tv = 0.0; - D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); - D3DTLVertices[cVertex++].color = dwPVColor; - } - } - - /* Render the converted vertex buffer. */ - if ( cVertex ) - DrawPrimitiveHAL( pContext->pShared, D3DPT_TRIANGLELIST, &D3DTLVertices[0], cVertex ); -} -/*===========================================================================*/ -/* This gets call before we render any primitives so that the current OGL */ -/* states will be mapped the D3D context. I'm still not sure how D3D works */ -/* but I'm finding that it doesn't act like a state machine as OGL is. It */ -/* looks like the state gets set back to the defaults after a DrawPrimitives */ -/* or an EndScene. Also I set states that are the default even though this */ -/* is redundant as the defaults seem screwed up. */ -/* TODO: make a batch call. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void SetRenderStates( GLcontext *ctx ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - DWORD dwFunc; - static BOOL bTexture = FALSE; - static int texName = -1; - - DPF(( DBG_FUNC, "SetRenderStates();" )); - - if ( g_DBGMask & DBG_STATES ) - DebugRenderStates( ctx, FALSE ); - - SetStateHAL( pContext->pShared, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE ); - SetStateHAL( pContext->pShared, D3DRENDERSTATE_DITHERENABLE, (ctx->Color.DitherFlag) ? TRUE : FALSE ); - - /*================================================*/ - /* Check too see if there are new TEXTURE states. */ - /*================================================*/ - if ( ctx->Texture._EnabledUnits ) - { - switch( ctx->Texture.Set[ctx->Texture.CurrentSet].EnvMode ) - { - case GL_MODULATE: - if ( ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0][0]->Format == GL_RGBA ) - dwFunc = pContext->pShared->dwTexFunc[d3dtblend_modulatealpha]; - else - dwFunc = pContext->pShared->dwTexFunc[d3dtblend_modulate]; - break; - - case GL_BLEND: - dwFunc = pContext->pShared->dwTexFunc[d3dtblend_decalalpha]; - break; - - case GL_REPLACE: - dwFunc = pContext->pShared->dwTexFunc[d3dtblend_decal]; - break; - - case GL_DECAL: - if ( ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0][0]->Format == GL_RGBA ) - dwFunc = pContext->pShared->dwTexFunc[d3dtblend_decalalpha]; - else - dwFunc = pContext->pShared->dwTexFunc[d3dtblend_decal]; - break; - } - SetStateHAL( pContext->pShared, D3DRENDERSTATE_TEXTUREMAPBLEND, dwFunc ); - - switch( ctx->Texture.Set[ctx->Texture.CurrentSet].Current->MagFilter ) - { - case GL_NEAREST: - dwFunc = D3DFILTER_NEAREST; - break; - case GL_LINEAR: - dwFunc = D3DFILTER_LINEAR; - break; - case GL_NEAREST_MIPMAP_NEAREST: - dwFunc = D3DFILTER_MIPNEAREST; - break; - case GL_LINEAR_MIPMAP_NEAREST: - dwFunc = D3DFILTER_LINEARMIPNEAREST; - break; - case GL_NEAREST_MIPMAP_LINEAR: - dwFunc = D3DFILTER_MIPLINEAR; - break; - case GL_LINEAR_MIPMAP_LINEAR: - dwFunc = D3DFILTER_LINEARMIPLINEAR; - break; - } - SetStateHAL( pContext->pShared, D3DRENDERSTATE_TEXTUREMAG, dwFunc ); - - switch( ctx->Texture.Set[ctx->Texture.CurrentSet].Current->MinFilter ) - { - case GL_NEAREST: - dwFunc = D3DFILTER_NEAREST; - break; - case GL_LINEAR: - dwFunc = D3DFILTER_LINEAR; - break; - case GL_NEAREST_MIPMAP_NEAREST: - dwFunc = D3DFILTER_MIPNEAREST; - break; - case GL_LINEAR_MIPMAP_NEAREST: - dwFunc = D3DFILTER_LINEARMIPNEAREST; - break; - case GL_NEAREST_MIPMAP_LINEAR: - dwFunc = D3DFILTER_MIPLINEAR; - break; - case GL_LINEAR_MIPMAP_LINEAR: - dwFunc = D3DFILTER_LINEARMIPLINEAR; - break; - } - SetStateHAL( pContext->pShared, D3DRENDERSTATE_TEXTUREMIN, dwFunc ); - - /* Another hack to cut down on redundant texture binding. */ - // if ( texName != ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Name ) - // { - texName = ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Name; - CreateTMgrHAL( pContext->pShared, - texName, - 0, - ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0][0]->Format, - (RECT *)NULL, - ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0][0]->Width, - ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0][0]->Height, - TM_ACTION_BIND, - (void *)ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0][0]->Data ); - // } - bTexture = TRUE; - } - else - { - /* This is nasty but should cut down on the number of redundant calls. */ - if ( bTexture == TRUE ) - { - DisableTMgrHAL( pContext->pShared ); - bTexture = FALSE; - } - } - - /*===============================================*/ - /* Check too see if there are new RASTER states. */ - /*===============================================*/ - - // TODO: no concept of front & back. - switch( ctx->Polygon.FrontMode ) - { - case GL_POINT: - SetStateHAL( pContext->pShared, D3DRENDERSTATE_FILLMODE, D3DFILL_POINT ); - break; - case GL_LINE: - SetStateHAL( pContext->pShared, D3DRENDERSTATE_FILLMODE, D3DFILL_WIREFRAME ); - break; - case GL_FILL: - SetStateHAL( pContext->pShared, D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID ); - break; - } - - /*************/ - /* Z-Buffer. */ - /*************/ - if ( ctx->Depth.Test == GL_TRUE ) - { - switch( ctx->Depth.Func ) - { - case GL_NEVER: - dwFunc = D3DCMP_NEVER; - break; - case GL_LESS: - dwFunc = D3DCMP_LESS; - break; - case GL_GEQUAL: - dwFunc = D3DCMP_GREATEREQUAL; - break; - case GL_LEQUAL: - dwFunc = D3DCMP_LESSEQUAL; - break; - case GL_GREATER: - dwFunc = D3DCMP_GREATER; - break; - case GL_NOTEQUAL: - dwFunc = D3DCMP_NOTEQUAL; - break; - case GL_EQUAL: - dwFunc = D3DCMP_EQUAL; - break; - case GL_ALWAYS: - dwFunc = D3DCMP_ALWAYS; - break; - } - SetStateHAL( pContext->pShared, D3DRENDERSTATE_ZFUNC, dwFunc ); - SetStateHAL( pContext->pShared, D3DRENDERSTATE_ZENABLE, TRUE ); - } - else - { - SetStateHAL( pContext->pShared, D3DRENDERSTATE_ZENABLE, FALSE ); - } - - /*******************/ - /* Z-Write Enable. */ - /*******************/ - SetStateHAL( pContext->pShared, D3DRENDERSTATE_ZWRITEENABLE , (ctx->Depth.Mask == GL_TRUE) ? TRUE : FALSE ); - - /***************/ - /* Alpha test. */ - /***************/ - if ( ctx->Color.AlphaEnabled == GL_TRUE ) - { - switch( ctx->Color.AlphaFunc ) - { - case GL_NEVER: - dwFunc = D3DCMP_NEVER; - break; - case GL_LESS: - dwFunc = D3DCMP_LESS; - break; - case GL_GEQUAL: - dwFunc = D3DCMP_GREATEREQUAL; - break; - case GL_LEQUAL: - dwFunc = D3DCMP_LESSEQUAL; - break; - case GL_GREATER: - dwFunc = D3DCMP_GREATER; - break; - case GL_NOTEQUAL: - dwFunc = D3DCMP_NOTEQUAL; - break; - case GL_EQUAL: - dwFunc = D3DCMP_EQUAL; - break; - case GL_ALWAYS: - dwFunc = D3DCMP_ALWAYS; - break; - } - SetStateHAL( pContext->pShared, D3DRENDERSTATE_ALPHAFUNC , dwFunc ); - SetStateHAL( pContext->pShared, D3DRENDERSTATE_ALPHATESTENABLE, TRUE ); - } - else - { - SetStateHAL( pContext->pShared, D3DRENDERSTATE_ALPHATESTENABLE, FALSE ); - } - - /****************/ - /* Alpha blend. */ - /****************/ - if ( ctx->Color.BlendEnabled == GL_TRUE ) - { - switch( ctx->Color.BlendSrc ) - { - case GL_ZERO: - dwFunc = pContext->pShared->dwSrcBlendCaps[s_zero]; - break; - case GL_ONE: - dwFunc = pContext->pShared->dwSrcBlendCaps[s_one]; - break; - case GL_DST_COLOR: - dwFunc = pContext->pShared->dwSrcBlendCaps[s_dst_color]; - break; - case GL_ONE_MINUS_DST_COLOR: - dwFunc = pContext->pShared->dwSrcBlendCaps[s_one_minus_dst_color]; - break; - case GL_SRC_ALPHA: - dwFunc = pContext->pShared->dwSrcBlendCaps[s_src_alpha]; - break; - case GL_ONE_MINUS_SRC_ALPHA: - dwFunc = pContext->pShared->dwSrcBlendCaps[s_one_minus_src_alpha]; - break; - case GL_DST_ALPHA: - dwFunc = pContext->pShared->dwSrcBlendCaps[s_dst_alpha]; - break; - case GL_ONE_MINUS_DST_ALPHA: - dwFunc = pContext->pShared->dwSrcBlendCaps[s_one_minus_dst_alpha]; - break; - case GL_SRC_ALPHA_SATURATE: - dwFunc = pContext->pShared->dwSrcBlendCaps[s_src_alpha_saturate]; - break; - case GL_CONSTANT_COLOR: - dwFunc = pContext->pShared->dwSrcBlendCaps[s_constant_color]; - break; - case GL_ONE_MINUS_CONSTANT_COLOR: - dwFunc = pContext->pShared->dwSrcBlendCaps[s_one_minus_constant_color]; - break; - case GL_CONSTANT_ALPHA: - dwFunc = pContext->pShared->dwSrcBlendCaps[s_constant_alpha]; - break; - case GL_ONE_MINUS_CONSTANT_ALPHA: - dwFunc = pContext->pShared->dwSrcBlendCaps[s_one_minus_constant_alpha]; - break; - } - SetStateHAL( pContext->pShared, D3DRENDERSTATE_SRCBLEND, dwFunc ); - - switch( ctx->Color.BlendDst ) - { - case GL_ZERO: - dwFunc = pContext->pShared->dwDestBlendCaps[d_zero]; - break; - case GL_ONE: - dwFunc = pContext->pShared->dwDestBlendCaps[d_one]; - break; - case GL_SRC_COLOR: - dwFunc = pContext->pShared->dwDestBlendCaps[d_src_color]; - break; - case GL_ONE_MINUS_SRC_COLOR: - dwFunc = pContext->pShared->dwDestBlendCaps[d_one_minus_src_color]; - break; - case GL_SRC_ALPHA: - dwFunc = pContext->pShared->dwDestBlendCaps[d_src_alpha]; - break; - case GL_ONE_MINUS_SRC_ALPHA: - dwFunc = pContext->pShared->dwDestBlendCaps[d_one_minus_src_alpha]; - break; - case GL_DST_ALPHA: - dwFunc = pContext->pShared->dwDestBlendCaps[d_dst_alpha]; - break; - case GL_ONE_MINUS_DST_ALPHA: - dwFunc = pContext->pShared->dwDestBlendCaps[d_one_minus_dst_alpha]; - break; - case GL_CONSTANT_COLOR: - dwFunc = pContext->pShared->dwDestBlendCaps[d_constant_color]; - break; - case GL_ONE_MINUS_CONSTANT_COLOR: - dwFunc = pContext->pShared->dwDestBlendCaps[d_one_minus_constant_color]; - break; - case GL_CONSTANT_ALPHA: - dwFunc = pContext->pShared->dwDestBlendCaps[d_constant_alpha]; - break; - case GL_ONE_MINUS_CONSTANT_ALPHA: - dwFunc = pContext->pShared->dwDestBlendCaps[d_one_minus_constant_alpha]; - break; - } - SetStateHAL( pContext->pShared, D3DRENDERSTATE_DESTBLEND, dwFunc ); - SetStateHAL( pContext->pShared, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE ); - } - else - { - SetStateHAL( pContext->pShared, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE ); - } -} -/*===========================================================================*/ -/* If this function is called it will track the changes to the current */ -/* states that I'm setting in Direct3D. I did this so that the DPF's would */ -/* be under control! */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void DebugRenderStates( GLcontext *ctx, BOOL bForce ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - DWORD dwFunc; - static int dither = -1, - texture = -1, - textName = -1, - textEnv = -1, - textMin = -1, - textMag = -1, - polyMode = -1, - depthTest = -1, - depthFunc = -1, - depthMask = -1, - alphaTest = -1, - alphaFunc = -1, - blend = -1, - blendSrc = -1, - blendDest = -1; - - /* Force a displayed update of all current states. */ - if ( bForce ) - { - dither = texture = textName = textEnv = textMin = textMag = -1; - polyMode = depthTest = depthFunc = depthMask = -1; - alphaTest = alphaFunc = blend = blendSrc = blendDest = -1; - } - - if ( dither != ctx->Color.DitherFlag ) - { - dither = ctx->Color.DitherFlag; - DPF(( 0, "\tDither\t\t%s", (dither) ? "ENABLED" : "--------" )); - } - if ( depthTest != ctx->Depth.Test ) - { - depthTest = ctx->Depth.Test; - DPF(( 0, "\tDepth Test\t%s", (depthTest) ? "ENABLED" : "--------" )); - } - if ( alphaTest != ctx->Color.AlphaEnabled ) - { - alphaTest = ctx->Color.AlphaEnabled; - - DPF(( 0, "\tAlpha Test\t%s", (alphaTest) ? "ENABLED" : "--------" )); - } - if ( blend != ctx->Color.BlendEnabled ) - { - blend = ctx->Color.BlendEnabled; - - DPF(( 0, "\tBlending\t%s", (blend) ? "ENABLED" : "--------" )); - } - - /*================================================*/ - /* Check too see if there are new TEXTURE states. */ - /*================================================*/ - if ( texture != ctx->Texture._EnabledUnits ) - { - texture = ctx->Texture._EnabledUnits; - DPF(( 0, "\tTexture\t\t%s", (texture) ? "ENABLED" : "--------" )); - } - - if ( ctx->Texture.Set[ctx->Texture.CurrentSet].Current ) - { - if ( ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Name != textName ) - { - textName = ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Name; - DPF(( 0, "\tTexture Name:\t%d", textName )); - DPF(( 0, "\tTexture Format:\t%s", - (ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0][0]->Format == GL_RGBA) ? - "GL_RGBA" : "GLRGB" )); - } - - if ( textEnv != ctx->Texture.Set[ctx->Texture.CurrentSet].EnvMode ) - { - textEnv = ctx->Texture.Set[ctx->Texture.CurrentSet].EnvMode; - - switch( textEnv ) - { - case GL_MODULATE: - DPF(( 0, "\tTexture\tMode\tGL_MODULATE" )); - break; - case GL_BLEND: - DPF(( 0, "\tTexture\tMode\tGL_BLEND" )); - break; - case GL_REPLACE: - DPF(( 0, "\tTexture\tMode\tGL_REPLACE" )); - break; - case GL_DECAL: - DPF(( 0, "\tTexture\tMode\tGL_DECAL" )); - break; - } - } - - if ( textMag != ctx->Texture.Set[ctx->Texture.CurrentSet].Current->MagFilter ) - { - textMag = ctx->Texture.Set[ctx->Texture.CurrentSet].Current->MagFilter; - - switch( textMag ) - { - case GL_NEAREST: - DPF(( 0, "\tTexture MAG\tGL_NEAREST" )); - break; - case GL_LINEAR: - DPF(( 0, "\tTexture MAG\tGL_LINEAR" )); - break; - case GL_NEAREST_MIPMAP_NEAREST: - DPF(( 0, "\tTexture MAG\tGL_NEAREST_MIPMAP_NEAREST" )); - break; - case GL_LINEAR_MIPMAP_NEAREST: - DPF(( 0, "\tTexture MAG\tGL_LINEAR_MIPMAP_NEAREST" )); - break; - case GL_NEAREST_MIPMAP_LINEAR: - DPF(( 0, "\tTexture MAG\tGL_NEAREST_MIPMAP_LINEAR" )); - break; - case GL_LINEAR_MIPMAP_LINEAR: - DPF(( 0, "\tTexture MAG\tGL_LINEAR_MIPMAP_LINEAR" )); - break; - } - } - - if ( textMin != ctx->Texture.Set[ctx->Texture.CurrentSet].Current->MinFilter ) - { - textMin = ctx->Texture.Set[ctx->Texture.CurrentSet].Current->MinFilter; - - switch( textMin ) - { - case GL_NEAREST: - DPF(( 0, "\tTexture MIN\tGL_NEAREST" )); - break; - case GL_LINEAR: - DPF(( 0, "\tTexture MIN\tGL_LINEAR" )); - break; - case GL_NEAREST_MIPMAP_NEAREST: - DPF(( 0, "\tTexture MIN\tGL_NEAREST_MIPMAP_NEAREST" )); - break; - case GL_LINEAR_MIPMAP_NEAREST: - DPF(( 0, "\tTexture MIN\tGL_LINEAR_MIPMAP_NEAREST" )); - break; - case GL_NEAREST_MIPMAP_LINEAR: - DPF(( 0, "\tTexture MIN\tGL_LINEAR_MIPMAP_LINEAR" )); - break; - case GL_LINEAR_MIPMAP_LINEAR: - DPF(( 0, "\tTexture MIN\tGL_LINEAR_MIPMAP_LINEAR" )); - break; - } - } - } - - if ( ctx->Polygon.FrontMode != polyMode ) - { - polyMode = ctx->Polygon.FrontMode; - - switch( polyMode ) - { - case GL_POINT: - DPF(( 0, "\tMode\t\tGL_POINT" )); - break; - case GL_LINE: - DPF(( 0, "\tMode\t\tGL_LINE" )); - break; - case GL_FILL: - DPF(( 0, "\tMode\t\tGL_FILL" )); - break; - } - } - - if ( depthFunc != ctx->Depth.Func ) - { - depthFunc = ctx->Depth.Func; - - switch( depthFunc ) - { - case GL_NEVER: - DPF(( 0, "\tDepth Func\tGL_NEVER" )); - break; - case GL_LESS: - DPF(( 0, "\tDepth Func\tGL_LESS" )); - break; - case GL_GEQUAL: - DPF(( 0, "\tDepth Func\tGL_GEQUAL" )); - break; - case GL_LEQUAL: - DPF(( 0, "\tDepth Func\tGL_LEQUAL" )); - break; - case GL_GREATER: - DPF(( 0, "\tDepth Func\tGL_GREATER" )); - break; - case GL_NOTEQUAL: - DPF(( 0, "\tDepth Func\tGL_NOTEQUAL" )); - break; - case GL_EQUAL: - DPF(( 0, "\tDepth Func\tGL_EQUAL" )); - break; - case GL_ALWAYS: - DPF(( 0, "\tDepth Func\tGL_ALWAYS" )); - break; - } - } - - if ( depthMask != ctx->Depth.Mask ) - { - depthMask = ctx->Depth.Mask; - DPF(( 0, "\tZWrite\t\t%s", (depthMask) ? "ENABLED" : "--------" )); - } - - if ( alphaFunc != ctx->Color.AlphaFunc ) - { - alphaFunc = ctx->Color.AlphaFunc; - - switch( alphaFunc ) - { - case GL_NEVER: - DPF(( 0, "\tAlpha Func\tGL_NEVER" )); - break; - case GL_LESS: - DPF(( 0, "\tAlpha Func\tGL_LESS" )); - break; - case GL_GEQUAL: - DPF(( 0, "\tAlpha Func\tGL_GEQUAL" )); - break; - case GL_LEQUAL: - DPF(( 0, "\tAlpha Func\tGL_LEQUAL" )); - break; - case GL_GREATER: - DPF(( 0, "\tAlpha Func\tGL_GREATER" )); - break; - case GL_NOTEQUAL: - DPF(( 0, "\tAlpha Func\tGL_NOTEQUAL" )); - break; - case GL_EQUAL: - DPF(( 0, "\tAlpha Func\tGL_EQUAL" )); - break; - case GL_ALWAYS: - DPF(( 0, "\tAlpha Func\tGL_ALWAYS" )); - break; - } - } - - if ( blendSrc != ctx->Color.BlendSrc ) - { - blendSrc = ctx->Color.BlendSrc; - - switch( blendSrc ) - { - case GL_ZERO: - DPF(( 0, "\tSRC Blend\tGL_ZERO" )); - break; - case GL_ONE: - DPF(( 0, "\tSRC Blend\tGL_ONE" )); - break; - case GL_DST_COLOR: - DPF(( 0, "\tSRC Blend\tGL_DST_COLOR" )); - break; - case GL_ONE_MINUS_DST_COLOR: - DPF(( 0, "\tSRC Blend\tGL_ONE_MINUS_DST_COLOR" )); - break; - case GL_SRC_ALPHA: - DPF(( 0, "\tSRC Blend\tGL_SRC_ALPHA" )); - break; - case GL_ONE_MINUS_SRC_ALPHA: - DPF(( 0, "\tSRC Blend\tGL_MINUS_SRC_ALPHA" )); - break; - case GL_DST_ALPHA: - DPF(( 0, "\tSRC Blend\tGL_DST_ALPHA" )); - break; - case GL_ONE_MINUS_DST_ALPHA: - DPF(( 0, "\tSRC Blend\tGL_ONE_MINUS_DST_ALPHA" )); - break; - case GL_SRC_ALPHA_SATURATE: - DPF(( 0, "\tSRC Blend\tGL_SRC_ALPHA_SATURATE" )); - break; - case GL_CONSTANT_COLOR: - DPF(( 0, "\tSRC Blend\tGL_CONSTANT_COLOR" )); - break; - case GL_ONE_MINUS_CONSTANT_COLOR: - DPF(( 0, "\tSRC Blend\tGL_ONE_MINUS_CONSTANT_COLOR" )); - break; - case GL_CONSTANT_ALPHA: - DPF(( 0, "\tSRC Blend\tGL_CONSTANT_ALPHA" )); - break; - case GL_ONE_MINUS_CONSTANT_ALPHA: - DPF(( 0, "\tSRC Blend\tGL_ONE_MINUS_CONSTANT_ALPHA" )); - break; - } - } - - if ( blendDest != ctx->Color.BlendDst ) - { - blendDest = ctx->Color.BlendDst; - - switch( blendDest ) - { - case GL_ZERO: - DPF(( 0, "\tDST Blend\tGL_ZERO" )); - break; - case GL_ONE: - DPF(( 0, "\tDST Blend\tGL_ONE" )); - break; - case GL_SRC_COLOR: - DPF(( 0, "\tDST Blend\tGL_SRC_COLOR" )); - break; - case GL_ONE_MINUS_SRC_COLOR: - DPF(( 0, "\tDST Blend\tGL_ONE_MINUS_SRC_COLOR" )); - break; - case GL_SRC_ALPHA: - DPF(( 0, "\tDST Blend\tGL_SRC_ALPHA" )); - break; - case GL_ONE_MINUS_SRC_ALPHA: - DPF(( 0, "\tDST Blend\tGL_ONE_MINUS_SRC_ALPHA" )); - break; - case GL_DST_ALPHA: - DPF(( 0, "\tDST Blend\tGL_DST_ALPHA" )); - break; - case GL_ONE_MINUS_DST_ALPHA: - DPF(( 0, "\tDST Blend\tGL_ONE_MINUS_DST_ALPHA" )); - break; - case GL_CONSTANT_COLOR: - DPF(( 0, "\tDST Blend\tGL_CONSTANT_COLOR" )); - break; - case GL_ONE_MINUS_CONSTANT_COLOR: - DPF(( 0, "\tDST Blend\tGL_ONE_MINUS_CONSTANT_COLOR" )); - break; - case GL_CONSTANT_ALPHA: - DPF(( 0, "\tDST Blend\tGL_CONSTANT_ALPHA" )); - break; - case GL_ONE_MINUS_CONSTANT_ALPHA: - DPF(( 0, "\tDST Blend\tGL_ONE_MINUS_CONSTANT_ALPHA" )); - break; - } - } -} diff --git a/src/mesa/drivers/d3d/DDrawPROCS.c b/src/mesa/drivers/d3d/DDrawPROCS.c deleted file mode 100644 index 10dcfdbabb..0000000000 --- a/src/mesa/drivers/d3d/DDrawPROCS.c +++ /dev/null @@ -1,399 +0,0 @@ -/*===========================================================================*/ -/* */ -/* Mesa-3.0 DirectX 6 Driver */ -/* */ -/* By Leigh McRae */ -/* */ -/* http://www.altsoftware.com/ */ -/* */ -/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ -/*===========================================================================*/ -#include "D3DMesa.h" -/*===========================================================================*/ -/* This call will clear the render surface using the pixel info built from */ -/* the surface at creation time. The call uses Lock/Unlock to access the */ -/* surface. The call also special cases a full clear or a dirty rectangle. */ -/* Finally the call returns the new clear mask that reflects that the color */ -/* buffer was cleared. */ -/*===========================================================================*/ -/* RETURN: the original mask with the bits cleared that represents the buffer*/ -/* or buffers we just cleared. */ -/*===========================================================================*/ -GLbitfield ClearBuffers( GLcontext *ctx, GLbitfield mask, GLboolean all, GLint x, GLint y, GLint width, GLint height ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - DDSURFACEDESC2 *pddsd2; - UCHAR *pBuffer, - *pScanLine; - int index, - index2; - DWORD dwColor; - - if ( mask & GL_COLOR_BUFFER_BIT ) - { - /* Lock the surface to get the surface pointer. */ - pddsd2 = LockHAL( pContext->pShared, TRUE ); - - /* Solve the color once only. */ - dwColor = ( ((DWORD)((float)pContext->rClear * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift ); - dwColor |= ( ((DWORD)((float)pContext->gClear * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift ); - dwColor |= ( ((DWORD)((float)pContext->bClear * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift ); - - if ( all ) - { - for( index = 0, pScanLine = (UCHAR *)pddsd2->lpSurface; index < pContext->pShared->dwHeight; index++, pScanLine += pddsd2->lPitch ) - for( pBuffer = pScanLine, index2 = 0; index2 < pContext->pShared->dwWidth; index2++, pBuffer += pContext->pShared->pixel.cb ) - memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); - } - else - { - pScanLine = ((UCHAR *)pddsd2->lpSurface) + - ( (FLIP( pContext->pShared->dwHeight, (y+height)) * pddsd2->lPitch) + (x * pContext->pShared->pixel.cb) ); - - for( index = 0; index < height; index++, pScanLine += pddsd2->lPitch ) - { - for( index2 = 0, pBuffer = pScanLine; index2 < width; index2++, pBuffer += pContext->pShared->pixel.cb ) - memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); - } - } - - UnlockHAL( pContext->pShared, TRUE ); - } - - return (mask & ~GL_COLOR_BUFFER_BIT); -} -/*===========================================================================*/ -/* This proc (as all others) has been written for the general case. I use */ -/* the PIXELINFO structure to pack the pixel from RGB24 to whatever the Off- */ -/* Screen render surface uses. The alpha is ignored as Mesa does it in SW. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -void WSpanRGB( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte rgb[][3], const GLubyte mask[] ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - DDSURFACEDESC2 *pddsd2; - UCHAR *pBuffer; - int index; - DWORD dwColor; - - /* Get the surface pointer and the pitch. */ - pddsd2 = LockHAL( pContext->pShared, TRUE ); - - /* Find the start of the span. Invert y for Windows. */ - pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y) * pddsd2->lPitch) + (x*pContext->pShared->pixel.cb); - - if ( mask ) - { - for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb ) - { - if ( mask[index] ) - { - /* Pack the color components. */ - dwColor = ( ((DWORD)((float)rgb[index][RCOMP] * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift ); - dwColor |= ( ((DWORD)((float)rgb[index][GCOMP] * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift ); - dwColor |= ( ((DWORD)((float)rgb[index][BCOMP] * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift ); - memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); - } - } - } - else - { - for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb ) - { - /* Pack the color components. */ - dwColor = ( ((DWORD)((float)rgb[index][RCOMP] * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift ); - dwColor |= ( ((DWORD)((float)rgb[index][GCOMP] * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift ); - dwColor |= ( ((DWORD)((float)rgb[index][BCOMP] * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift ); - memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); - } - } - - /* Giver back. */ - UnlockHAL( pContext->pShared, TRUE ); -} -/*===========================================================================*/ -/* This proc (as all others) has been written for the general case. I use */ -/* the PIXELINFO structure to pack the pixel from RGB24 to whatever the Off- */ -/* Screen render surface uses. The alpha is ignored as Mesa does it in SW. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -void WSpanRGBA( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte rgba[][4], const GLubyte mask[] ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - DDSURFACEDESC2 *pddsd2; - UCHAR *pBuffer; - int index; - DWORD dwColor; - - /* Get the surface pointer and the pitch. */ - pddsd2 = LockHAL( pContext->pShared, TRUE ); - - /* Find the start of the span. Invert y for Windows. */ - pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y) * pddsd2->lPitch) + (x*pContext->pShared->pixel.cb); - - if ( mask ) - { - for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb ) - { - if ( mask[index] ) - { - /* Pack the color components. */ - dwColor = ( ((DWORD)((float)rgba[index][RCOMP] * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift ); - dwColor |= ( ((DWORD)((float)rgba[index][GCOMP] * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift ); - dwColor |= ( ((DWORD)((float)rgba[index][BCOMP] * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift ); - memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); - } - } - } - else - { - for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb ) - { - /* Pack the color components. */ - dwColor = ( ((DWORD)((float)rgba[index][RCOMP] * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift ); - dwColor |= ( ((DWORD)((float)rgba[index][GCOMP] * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift ); - dwColor |= ( ((DWORD)((float)rgba[index][BCOMP] * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift ); - memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); - } - } - - /* Giver back. */ - UnlockHAL( pContext->pShared, TRUE ); -} -/*===========================================================================*/ -/* This proc (as all others) has been written for the general case. I use */ -/* the PIXELINFO structure to pack the pixel from RGB24 to whatever the Off- */ -/* Screen render surface uses. The color is solved once from the current */ -/* color components. The alpha is ignored as Mesa is doing it in SW. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -void WSpanRGBAMono( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte mask[] ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - DDSURFACEDESC2 *pddsd2; - UCHAR *pBuffer; - int index; - DWORD dwColor; - - /* Lock the surface to get the surface pointer and the pitch. */ - pddsd2 = LockHAL( pContext->pShared, TRUE ); - - /* Solve the color once only. (no alpha) */ - dwColor = ( ((DWORD)((float)pContext->rCurrent * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift ); - dwColor |= ( ((DWORD)((float)pContext->gCurrent * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift ); - dwColor |= ( ((DWORD)((float)pContext->bCurrent * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift ); - - /* Find the start of the span. Invert y for Windows. */ - pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y) * pddsd2->lPitch) + (x*pContext->pShared->pixel.cb); - - if ( mask ) - { - for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb ) - if ( mask[index] ) - memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); - } - else - { - for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb ) - memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); - } - - /* Giver back. */ - UnlockHAL( pContext->pShared, TRUE ); -} -/*===========================================================================*/ -/* This proc (as all others) has been written for the general case. I use */ -/* the PIXELINFO structure to pack the pixel from RGB24 to whatever the Off- */ -/* Screen render surface uses. The alpha is ignored as Mesa does it in SW. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -void WPixelsRGBA( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte rgba[][4], const GLubyte mask[] ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - DDSURFACEDESC2 *pddsd2; - UCHAR *pBuffer; - int index; - DWORD dwColor; - - /* Get the surface pointer and the pitch. */ - pddsd2 = LockHAL( pContext->pShared, TRUE ); - - if ( mask ) - { - for( index = 0; index < n; index++ ) - { - if ( mask[index] ) - { - /* Pack the color components. */ - dwColor = ( ((DWORD)((float)rgba[index][RCOMP] * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift ); - dwColor |= ( ((DWORD)((float)rgba[index][GCOMP] * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift ); - dwColor |= ( ((DWORD)((float)rgba[index][BCOMP] * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift ); - - /* Find the pixel. Invert y for Windows. */ - pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y[index]) * pddsd2->lPitch) + (x[index]*pContext->pShared->pixel.cb); - memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); - } - } - } - else - { - for( index = 0; index < n; index++ ) - { - /* Pack the color components. */ - dwColor = ( ((DWORD)((float)rgba[index][RCOMP] * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift ); - dwColor |= ( ((DWORD)((float)rgba[index][GCOMP] * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift ); - dwColor |= ( ((DWORD)((float)rgba[index][BCOMP] * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift ); - - /* Find the pixel. Invert y for Windows. */ - pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y[index]) * pddsd2->lPitch) + (x[index]*pContext->pShared->pixel.cb); - memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); - } - } - - /* Giver back. */ - UnlockHAL( pContext->pShared, TRUE ); -} -/*===========================================================================*/ -/* This proc (as all others) has been written for the general case. I use */ -/* the PIXELINFO structure to pack the pixel from RGB24 to whatever the Off- */ -/* Screen render surface uses. The color is solved once from the current */ -/* color components. The alpha is ignored as Mesa is doing it in SW. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -void WPixelsRGBAMono( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte mask[] ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - DDSURFACEDESC2 *pddsd2; - UCHAR *pBuffer; - int index; - DWORD dwColor; - - /* Get the surface pointer and the pitch. */ - pddsd2 = LockHAL( pContext->pShared, TRUE ); - - /* Solve the color once only. I don't uses the alpha. */ - dwColor = ( ((DWORD)((float)pContext->rCurrent * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift ); - dwColor |= ( ((DWORD)((float)pContext->gCurrent * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift ); - dwColor |= ( ((DWORD)((float)pContext->bCurrent * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift ); - - if ( mask ) - { - /* We store the surface pointer as a UCHAR so that pixel.cb (count in btyles) will work for all. */ - for( index = 0; index < n; index++ ) - { - if ( mask[index] ) - { - /* Find the pixel. Invert y for Windows. */ - pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y[index]) * pddsd2->lPitch) + (x[index]*pContext->pShared->pixel.cb); - memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); - } - } - } - else - { - /* We store the surface pointer as a UCHAR so that pixel.cb (count in btyles) will work for all. */ - for( index = 0; index < n; index++ ) - { - /* Find the pixel. Invert y for Windows. */ - pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y[index]) * pddsd2->lPitch) + (x[index]*pContext->pShared->pixel.cb); - memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); - } - } - - /* Giver back. */ - UnlockHAL( pContext->pShared, TRUE ); -} -/*===========================================================================*/ -/* This proc isn't written for speed rather its to handle the general case. */ -/* I grab each pixel from the surface and unpack the info using the PIXELINFO*/ -/* structure that was generated from the OffScreen surface pixelformat. The */ -/* function will not fill in the alpha value as Mesa I have Mesa allocate its*/ -/* own alpha channel when the context was created. I did this as I didn't */ -/* feel that it was worth the effort to try and get HW to work (bus bound). */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -void RSpanRGBA( const GLcontext* ctx, GLuint n, GLint x, GLint y, GLubyte rgba[][4] ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - DDSURFACEDESC2 *pddsd2; - UCHAR *pBuffer; - int index; - DWORD *pdwColor; - - /* Get the surface pointer and the pitch. */ - pddsd2 = LockHAL( pContext->pShared, TRUE ); - - /* Find the start of the span. Invert y for Windows. */ - pBuffer = (UCHAR *)pddsd2->lpSurface + - (FLIP(pContext->pShared->dwHeight,y) * pddsd2->lPitch) + - (x*pContext->pShared->pixel.cb); - - /* We store the surface pointer as a UCHAR so that pixel.cb (count in btyles) will work for all. */ - for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb ) - { - pdwColor = (DWORD *)pBuffer; - rgba[index][RCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwRMask) >> pContext->pShared->pixel.rShift) / pContext->pShared->pixel.rScale); - rgba[index][GCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwGMask) >> pContext->pShared->pixel.gShift) / pContext->pShared->pixel.gScale); - rgba[index][BCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwBMask) >> pContext->pShared->pixel.bShift) / pContext->pShared->pixel.bScale); - } - - /* Giver back. */ - UnlockHAL( pContext->pShared, TRUE ); -} -/*===========================================================================*/ -/* This proc isn't written for speed rather its to handle the general case. */ -/* I grab each pixel from the surface and unpack the info using the PIXELINFO*/ -/* structure that was generated from the OffScreen surface pixelformat. The */ -/* function will not fill in the alpha value as Mesa I have Mesa allocate its*/ -/* own alpha channel when the context was created. I did this as I didn't */ -/* feel that it was worth the effort to try and get HW to work (bus bound). */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -void RPixelsRGBA( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], GLubyte rgba[][4], const GLubyte mask[] ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - DDSURFACEDESC2 *pddsd2; - int index; - DWORD *pdwColor; - - /* Get the surface pointer and the pitch. */ - pddsd2 = LockHAL( pContext->pShared, TRUE ); - - if ( mask ) - { - /* We store the surface pointer as a UCHAR so that pixel.cb (count in btyles) will work for all. */ - for( index = 0; index < n; index++ ) - { - if ( mask[index] ) - { - /* Find the start of the pixel. Invert y for Windows. */ - pdwColor = (DWORD *)((UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y[index]) * pddsd2->lPitch) + (x[index]*pContext->pShared->pixel.cb)); - rgba[index][RCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwRMask) >> pContext->pShared->pixel.rShift) / pContext->pShared->pixel.rScale); - rgba[index][GCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwGMask) >> pContext->pShared->pixel.gShift) / pContext->pShared->pixel.gScale); - rgba[index][BCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwBMask) >> pContext->pShared->pixel.bShift) / pContext->pShared->pixel.bScale); - } - } - } - else - { - /* We store the surface pointer as a UCHAR so that pixel.cb (count in btyles) will work for all. */ - for( index = 0; index < n; index++ ) - { - /* Find the start of the pixel. Invert y for Windows. */ - pdwColor = (DWORD *)((UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y[index]) * pddsd2->lPitch) + (x[index]*pContext->pShared->pixel.cb)); - rgba[index][RCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwRMask) >> pContext->pShared->pixel.rShift) / pContext->pShared->pixel.rScale); - rgba[index][GCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwGMask) >> pContext->pShared->pixel.gShift) / pContext->pShared->pixel.gScale); - rgba[index][BCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwBMask) >> pContext->pShared->pixel.bShift) / pContext->pShared->pixel.bScale); - } - } - - /* Giver back. */ - UnlockHAL( pContext->pShared, TRUE ); -} diff --git a/src/mesa/drivers/d3d/DEBUG.C b/src/mesa/drivers/d3d/DEBUG.C deleted file mode 100644 index 79e273903a..0000000000 --- a/src/mesa/drivers/d3d/DEBUG.C +++ /dev/null @@ -1,143 +0,0 @@ -/*===========================================================================*/ -/* */ -/* Mesa-3.0 DirectX 6 Driver */ -/* */ -/* By Leigh McRae */ -/* */ -/* http://www.altsoftware.com/ */ -/* */ -/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ -/*===========================================================================*/ -#include "Debug.h" -/*===========================================================================*/ -/* Global variables. */ -/*===========================================================================*/ -DWORD g_DBGMask = DBG_ALL_ERROR; -/*===========================================================================*/ -/* This is your basic DPF function with printf like support. The function */ -/* also works with a global debug mask variable. I have written support that*/ -/* allows for the user's enviroment variable space to be read and set the */ -/* masks. This is done when the dll starts and is only in the debug version.*/ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -void _cdecl DebugPrint( int mask, char *pszFormat, ... ) -{ - char buffer[512]; - va_list args; - - /* A mask of 0 will always pass. Easy to remeber. */ - if ( (mask == 0) || (mask & g_DBGMask) ) - { - va_start( args, pszFormat ); - - if ( mask & DBG_ALL_ERROR ) - OutputDebugString( "MesaD3D: (ERROR)" ); - else - OutputDebugString( "MesaD3D: " ); - - vsprintf( buffer, pszFormat, args ); - strcat( buffer, "\n" ); - OutputDebugString( buffer ); - - va_end( args ); - } -} -/*===========================================================================*/ -/* This call reads the users enviroment variables and sets any debug mask */ -/* that they have set to TRUE. Now the value must be "TRUE". */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -void ReadDBGEnv( void ) -{ - g_DBGMask = DBG_ALL_ERROR; - -#define IS_VAR_SET(v) if ( getenv( # v ) && !strcmp(getenv( # v ),"TRUE") ) g_DBGMask |= v; - - IS_VAR_SET( DBG_FUNC ); - IS_VAR_SET( DBG_STATES ); - - IS_VAR_SET( DBG_CNTX_INFO ); - IS_VAR_SET( DBG_CNTX_WARN ); - IS_VAR_SET( DBG_CNTX_PROFILE ); - IS_VAR_SET( DBG_CNTX_ERROR ); - IS_VAR_SET( DBG_CNTX_ALL ); - - IS_VAR_SET( DBG_PRIM_INFO ); - IS_VAR_SET( DBG_PRIM_WARN ); - IS_VAR_SET( DBG_PRIM_PROFILE ); - IS_VAR_SET( DBG_PRIM_ERROR ); - IS_VAR_SET( DBG_PRIM_ALL ); - - IS_VAR_SET( DBG_TXT_INFO ); - IS_VAR_SET( DBG_TXT_WARN ); - IS_VAR_SET( DBG_TXT_PROFILE ); - IS_VAR_SET( DBG_TXT_ERROR ); - IS_VAR_SET( DBG_TXT_ALL ); - - IS_VAR_SET( DBG_ALL_INFO ); - IS_VAR_SET( DBG_ALL_WARN ); - IS_VAR_SET( DBG_ALL_PROFILE ); - IS_VAR_SET( DBG_ALL_ERROR ); - IS_VAR_SET( DBG_ALL ); - -#undef IS_VAR_SET -} -/*===========================================================================*/ -/* This function will take a pointer to a DDSURFACEDESC2 structure & display*/ -/* the parsed information using a DPF call. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -void DebugPixelFormat( char *pszSurfaceName, DDPIXELFORMAT *pddpf ) -{ - char buffer[256]; - - /* Parse the flag type and write the string equivalent. */ - if ( pddpf->dwFlags & DDPF_ALPHA ) - strcat( buffer, "DDPF_ALPHA " ); - if ( pddpf->dwFlags & DDPF_ALPHAPIXELS ) - strcat( buffer, "DDPF_ALPHAPIXELS " ); - if ( pddpf->dwFlags & DDPF_ALPHAPREMULT ) - strcat( buffer, "DDPF_ALPHAPREMULT " ); - if ( pddpf->dwFlags & DDPF_BUMPLUMINANCE ) - strcat( buffer, "DDPF_BUMPLUMINANCE " ); - if ( pddpf->dwFlags & DDPF_BUMPDUDV ) - strcat( buffer, "DDPF_BUMPDUDV " ); - if ( pddpf->dwFlags & DDPF_COMPRESSED ) - strcat( buffer, "DDPF_COMPRESSED " ); - if ( pddpf->dwFlags & DDPF_FOURCC ) - strcat( buffer, "DDPF_FOURCC " ); - if ( pddpf->dwFlags & DDPF_LUMINANCE ) - strcat( buffer, "DDPF_LUMINANCE " ); - if ( pddpf->dwFlags & DDPF_PALETTEINDEXED1 ) - strcat( buffer, "DDPF_PALETTEINDEXED1 " ); - if ( pddpf->dwFlags & DDPF_PALETTEINDEXED2 ) - strcat( buffer, "DDPF_PALETTEINDEXED2 " ); - if ( pddpf->dwFlags & DDPF_PALETTEINDEXED4 ) - strcat( buffer, "DDPF_PALETTEINDEXED4 " ); - if ( pddpf->dwFlags & DDPF_PALETTEINDEXED8 ) - strcat( buffer, "DDPF_PALETTEINDEXED8 " ); - if ( pddpf->dwFlags & DDPF_PALETTEINDEXEDTO8 ) - strcat( buffer, "DDPF_PALETTEINDEXEDTO8 " ); - if ( pddpf->dwFlags & DDPF_RGB ) - strcat( buffer, "DDPF_RGB " ); - if ( pddpf->dwFlags & DDPF_RGBTOYUV ) - strcat( buffer, "DDPF_RGBTOYUV " ); - if ( pddpf->dwFlags & DDPF_STENCILBUFFER ) - strcat( buffer, "DDPF_STENCILBUFFER " ); - if ( pddpf->dwFlags & DDPF_YUV ) - strcat( buffer, "DDPF_YUV " ); - if ( pddpf->dwFlags & DDPF_ZBUFFER ) - strcat( buffer, "DDPF_ZBUFFER " ); - if ( pddpf->dwFlags & DDPF_ZPIXELS ) - strcat( buffer, "DDPF_ZPIXELS " ); - - DPF(( (DBG_TXT_INFO|DBG_CNTX_INFO),"%s", buffer )); -} - - - - - diff --git a/src/mesa/drivers/d3d/DEBUG.H b/src/mesa/drivers/d3d/DEBUG.H deleted file mode 100644 index daeeb72278..0000000000 --- a/src/mesa/drivers/d3d/DEBUG.H +++ /dev/null @@ -1,90 +0,0 @@ -/*===========================================================================*/ -/* */ -/* Mesa-3.0 DirectX 6 Driver */ -/* */ -/* By Leigh McRae */ -/* */ -/* http://www.altsoftware.com/ */ -/* */ -/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ -/*===========================================================================*/ -#ifndef _DEBUG_H -#define _DEBUG_H - -#ifdef __cplusplus -extern "C" { -#endif - -/*===========================================================================*/ -/* Includes. */ -/*===========================================================================*/ -#include <stdio.h> -#include <string.h> -#include <ddraw.h> -#include <d3d.h> -#include "D3DShared.h" -/*===========================================================================*/ -/* Magic numbers. */ -/*===========================================================================*/ -/*===========================================================================*/ -/* Macros defines. */ -/*===========================================================================*/ -#define DBG_FUNC 0x00000001 -#define DBG_STATES 0x00000002 - -#define DBG_CNTX_INFO 0x00000010 -#define DBG_CNTX_WARN 0x00000020 -#define DBG_CNTX_PROFILE 0x00000040 -#define DBG_CNTX_ERROR 0x00000080 -#define DBG_CNTX_ALL 0x000000F0 - -#define DBG_PRIM_INFO 0x00000100 -#define DBG_PRIM_WARN 0x00000200 -#define DBG_PRIM_PROFILE 0x00000400 -#define DBG_PRIM_ERROR 0x00000800 -#define DBG_PRIM_ALL 0x00000F00 - -#define DBG_TXT_INFO 0x00001000 -#define DBG_TXT_WARN 0x00002000 -#define DBG_TXT_PROFILE 0x00004000 -#define DBG_TXT_ERROR 0x00008000 -#define DBG_TXT_ALL 0x0000F000 - -#define DBG_ALL_INFO 0x11111110 -#define DBG_ALL_WARN 0x22222220 -#define DBG_ALL_PROFILE 0x44444440 -#define DBG_ALL_ERROR 0x88888880 -#define DBG_ALL 0xFFFFFFFF - -#ifdef D3D_DEBUG -# define DPF(arg) DebugPrint arg -# define RIP(pH,msg,err) OutputDebugString(msg); \ - OutputDebugString(err); \ - OutputDebugString("\n"); \ - FatalShutDown(pH) -#else -# define DPF(arg) -# define RIP(pH,msg,err) FatalShutDown(pH) -#endif -/*===========================================================================*/ -/* Type defines. */ -/*===========================================================================*/ -/*===========================================================================*/ -/* Function prototypes. */ -/*===========================================================================*/ -extern void ReadDBGEnv( void ); -extern void _cdecl DebugPrint( int mask, char *pszFormat, ... ); -extern void DebugPixelFormat( char *pszSurfaceName, DDPIXELFORMAT *pddpf ); -/*===========================================================================*/ -/* Global variables. */ -/*===========================================================================*/ -extern DWORD g_DBGMask; - -#ifdef __cplusplus -} -#endif - -#endif - - - diff --git a/src/mesa/drivers/d3d/DbgEnv.bat b/src/mesa/drivers/d3d/DbgEnv.bat deleted file mode 100644 index acea045856..0000000000 --- a/src/mesa/drivers/d3d/DbgEnv.bat +++ /dev/null @@ -1,25 +0,0 @@ -SET DBG_FUNC=FALSE - -SET DBG_CNTX_INFO=TRUE -SET DBG_CNTX_WARN=TRUE -SET DBG_CNTX_PROFILE=FALSE -SET DBG_CNTX_ERROR=TRUE -SET DBG_CNTX_ALL=TRUE - -SET DBG_PRIM_INFO=FALSE -SET DBG_PRIM_WARN=FALSE -SET DBG_PRIM_PROFILE=FALSE -SET DBG_PRIM_ERROR=TRUE -SET DBG_PRIM_ALL=FALSE - -SET DBG_TXT_INFO=FALSE -SET DBG_TXT_WARN=TRUE -SET DBG_TXT_PROFILE=FALSE -SET DBG_TXT_ERROR=TRUE -SET DBG_TXT_ALL=FALSE - -SET DBG_ALL_INFO=FALSE -SET DBG_ALL_WARN=TRUE -SET DBG_ALL_PROFILE=FALSE -SET DBG_ALL_ERROR=TRUE -SET DBG_ALL=FALSE diff --git a/src/mesa/drivers/d3d/MAKEFILE b/src/mesa/drivers/d3d/MAKEFILE deleted file mode 100644 index 6aa88f3cef..0000000000 --- a/src/mesa/drivers/d3d/MAKEFILE +++ /dev/null @@ -1,101 +0,0 @@ -############################################################################## -# -# Mesa-3.0 Makefile for DirectX 6 Driver -# -# By Leigh McRae -# -# http://www.altsoftware.com/ -# -# Copyright (c) 1999-1998 alt.software inc. All Rights Reserved -############################################################################## -NAME= -TARGET= WGL Driver (D3DHAL) - -D3D_DIR=$(MAKEDIR)\D3D -TARGET_DIR=e:\WinNT\System32 -TEMP_DIR=c:\Temp - -SPACE=- -LINKER=link.exe - -INCLUDE=$(SDKROOT)\include;$(INCLUDE) -LIB=$(SDKROOT)\lib;$(LIB) -############################################################################## -CFLAGS = /c /nologo /W1 /G5 /I..\ /I..\..\Include \ - /D "_WIN32" /D "WIN32" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /D "MESAD3D" -CPPFLAGS= /c /nologo /W1 /G5 /I..\ /I..\..\Include \ - /D "_WIN32" /D "WIN32" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /D "MESAD3D" - -!IF "$(DEBUG)" == "1" - -CFLAGS = /MTd /Od /Z7 /Yd /D "_DEBUG" /D "D3D_DEBUG" $(CFLAGS) -CPPFLAGS = /MTd /Od /Z7 /Yd /D "_DEBUG" /D "D3D_DEBUG" $(CPPFLAGS) -BUILD_TYPE=debug - -!ELSE - -CFLAGS = /MT /Ox /D "NDEBUG" $(CFLAGS) -CPPFLAGS = /MT /Ox /D "NDEBUG" $(CPPFLAGS) -BUILD_TYPE=release - -!ENDIF -############################################################################## -SRCS_WGL = wgl.c D3Dvbrender.c DDrawPROCS.c NULLProcs.c Debug.c -SRCS_HAL = D3DInit.cpp D3DRaster.cpp D3DTextureMgr.cpp D3DUtils.cpp D3DCaps.cpp -OBJS_WGL = $(SRCS_WGL:.c=.obj) -OBJS_HAL = $(SRCS_HAL:.cpp=.obj) - -WINLIBS = kernel32.lib user32.lib gdi32.lib oldnames.lib -DXLIBS = -LIBS = $(WINLIBS) $(DXLIBS) -############################################################################### -# Primary Targets # -############################################################################### - -default: header WGL HAL footer - -all: default - -WGL : $(OBJS_WGL) - -HAL : $(OBJS_HAL) - -install : forceit - @echo $(SPACE) - @echo ======================================== - @echo Install files created. - @echo ======================================== - - -############################################################################### -# Secondary Targets # -############################################################################### - -clean: - @echo ======================================== - @echo Cleaning $(TARGET) - @del *.obj - @del *.dep - @del *.exp - @del *.ncb - @del *.plg - @del *.lib - @echo ======================================== - -header: - @echo ============================================================ - @echo Building $(TARGET) ($(BUILD_TYPE) version) - @echo ============================================================ - @echo $(SPACE) - -footer: - @echo $(SPACE) - @echo ============================================================ - @echo DONE building $(TARGET) ($(BUILD_TYPE) version) - @echo ============================================================ - -forceit: - - - - diff --git a/src/mesa/drivers/d3d/NULLProcs.h b/src/mesa/drivers/d3d/NULLProcs.h deleted file mode 100644 index f0bbd2162d..0000000000 --- a/src/mesa/drivers/d3d/NULLProcs.h +++ /dev/null @@ -1,49 +0,0 @@ -/*===========================================================================*/ -/* */ -/* Mesa-3.0 DirectX 6 Driver */ -/* */ -/* By Leigh McRae */ -/* */ -/* http://www.altsoftware.com/ */ -/* */ -/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ -/*===========================================================================*/ -#ifndef NULL_MESA_PROCS_INC -#define NULL_MESA_PROCS_INC -/*===========================================================================*/ -/* Includes. */ -/*===========================================================================*/ -#include "matrix.h" -#include "context.h" -#include "types.h" -#include "vb.h" -/*===========================================================================*/ -/* Macros. */ -/*===========================================================================*/ -/*===========================================================================*/ -/* Magic numbers. */ -/*===========================================================================*/ -/*===========================================================================*/ -/* Type defines. */ -/*===========================================================================*/ -void NULLSetColor( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a ); -void NULLClearColor( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a ); -GLboolean NULLSetBuffer( GLcontext *ctx, GLenum mode ); -void NULLGetBufferSize( GLcontext *ctx, GLuint *width, GLuint *height ); -GLbitfield NULLClearBuffers( GLcontext *ctx, GLbitfield m, GLboolean a, GLint x, GLint y, GLint w, GLint h ); -void NULLWrSpRGB( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte r[][3], const GLubyte m[] ); -void NULLWrSpRGBA( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte r[][4], const GLubyte m[] ); -void NULLWrSpRGBAMono( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte m[] ); -void NULLWrPiRGBA( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte r[][4], const GLubyte m[] ); -void NULLWrPiRGBAMono( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte m[] ); -void NULLReSpRGBA( const GLcontext* ctx, GLuint n, GLint x, GLint y, GLubyte r[][4] ); -void NULLRePiRGBA( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], GLubyte r[][4], const GLubyte m[] ); -/*===========================================================================*/ -/* Extern function prototypes. */ -/*===========================================================================*/ -/*===========================================================================*/ -/* Global variables. */ -/*===========================================================================*/ - -#endif - diff --git a/src/mesa/drivers/d3d/NullProcs.c b/src/mesa/drivers/d3d/NullProcs.c deleted file mode 100644 index d6fb598074..0000000000 --- a/src/mesa/drivers/d3d/NullProcs.c +++ /dev/null @@ -1,49 +0,0 @@ -/*===========================================================================*/ -/* */ -/* Mesa-3.0 DirectX 6 Driver */ -/* */ -/* By Leigh McRae */ -/* */ -/* http://www.altsoftware.com/ */ -/* */ -/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ -/*===========================================================================*/ -#ifndef NULL_MESA_PROCS_INC -#define NULL_MESA_PROCS_INC -/*===========================================================================*/ -/* Includes. */ -/*===========================================================================*/ -#include "matrix.h" -#include "context.h" -#include "mtypes.h" -#include "vb.h" -/*===========================================================================*/ -/* Macros. */ -/*===========================================================================*/ -/*===========================================================================*/ -/* Magic numbers. */ -/*===========================================================================*/ -/*===========================================================================*/ -/* Type defines. */ -/*===========================================================================*/ -void NULLSetColor( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a ); -void NULLClearColor( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a ); -GLboolean NULLSetBuffer( GLcontext *ctx, GLframebuffer *buffer, GLuint bit ); -void NULLGetBufferSize( GLcontext *ctx, GLuint *width, GLuint *height ); -GLbitfield NULLClearBuffers( GLcontext *ctx, GLbitfield m, GLboolean a, GLint x, GLint y, GLint w, GLint h ); -void NULLWrSpRGB( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte r[][3], const GLubyte m[] ); -void NULLWrSpRGBA( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte r[][4], const GLubyte m[] ); -void NULLWrSpRGBAMono( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte m[] ); -void NULLWrPiRGBA( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte r[][4], const GLubyte m[] ); -void NULLWrPiRGBAMono( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte m[] ); -void NULLReSpRGBA( const GLcontext* ctx, GLuint n, GLint x, GLint y, GLubyte r[][4] ); -void NULLRePiRGBA( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], GLubyte r[][4], const GLubyte m[] ); -/*===========================================================================*/ -/* Extern function prototypes. */ -/*===========================================================================*/ -/*===========================================================================*/ -/* Global variables. */ -/*===========================================================================*/ - -#endif - diff --git a/src/mesa/drivers/d3d/OPENGL32.DEF b/src/mesa/drivers/d3d/OPENGL32.DEF deleted file mode 100644 index bc0304da33..0000000000 --- a/src/mesa/drivers/d3d/OPENGL32.DEF +++ /dev/null @@ -1,442 +0,0 @@ -;=========================================================================== -; -; Mesa-3.0 DirectX 6 Driver -; -; By Leigh McRae -; -; http://www.altsoftware.com/ -; -; Copyright (c) 1999-1998 alt.software inc. All Rights Reserved -;=========================================================================== -NAME OpenGL32.DLL -DESCRIPTION "Mesa-3.0 DX6 Driver Version 0.5" - -EXPORTS - DllMain - glAccum - glAlphaFunc - glAreTexturesResident - glAreTexturesResidentEXT - glArrayElement - glArrayElementEXT - glBegin - glBindTexture - glBindTextureEXT - glBitmap - glBlendColorEXT - glBlendEquationEXT - glBlendFunc - glCallList - glCallLists - glClear - glClearAccum - glClearColor - glClearDepth - glClearIndex - glClearStencil - glClipPlane - glColor3b - glColor3bv - glColor3d - glColor3dv - glColor3f - glColor3fv - glColor3i - glColor3iv - glColor3s - glColor3sv - glColor3ub - glColor3ubv - glColor3ui - glColor3uiv - glColor3us - glColor3usv - glColor4b - glColor4bv - glColor4d - glColor4dv - glColor4f - glColor4fv - glColor4i - glColor4iv - glColor4s - glColor4sv - glColor4ub - glColor4ubv - glColor4ui - glColor4uiv - glColor4us - glColor4usv - glColorMask - glColorMaterial - glColorPointer - glColorPointerEXT - glColorSubTableEXT - glColorTableEXT - glCopyPixels - glCopyTexImage1D - glCopyTexImage2D - glCopyTexSubImage1D - glCopyTexSubImage2D - glCopyTexSubImage3DEXT - glCullFace - glDeleteLists - glDeleteTextures - glDeleteTexturesEXT - glDepthFunc - glDepthMask - glDepthRange - glDisable - glDisableClientState - glDrawArrays - glDrawArraysEXT - glDrawBuffer - glDrawElements - glDrawPixels - glEdgeFlag - glEdgeFlagPointer - glEdgeFlagPointerEXT - glEdgeFlagv - glEnable - glEnableClientState - glEnd - glEndList - glEvalCoord1d - glEvalCoord1dv - glEvalCoord1f - glEvalCoord1fv - glEvalCoord2d - glEvalCoord2dv - glEvalCoord2f - glEvalCoord2fv - glEvalMesh1 - glEvalMesh2 - glEvalPoint1 - glEvalPoint2 - glFeedbackBuffer - glFinish - glFlush - glFogf - glFogfv - glFogi - glFogiv - glFrontFace - glFrustum - glGenLists - glGenTextures - glGenTexturesEXT - glGetBooleanv - glGetClipPlane - glGetColorTableEXT - glGetColorTableParameterfvEXT - glGetColorTableParameterivEXT - glGetDoublev - glGetError - glGetFloatv - glGetIntegerv - glGetLightfv - glGetLightiv - glGetMapdv - glGetMapfv - glGetMapiv - glGetMaterialfv - glGetMaterialiv - glGetPixelMapfv - glGetPixelMapuiv - glGetPixelMapusv - glGetPointerv - glGetPointervEXT - glGetPolygonStipple - glGetString - glGetTexEnvfv - glGetTexEnviv - glGetTexGendv - glGetTexGenfv - glGetTexGeniv - glGetTexImage - glGetTexLevelParameterfv - glGetTexLevelParameteriv - glGetTexParameterfv - glGetTexParameteriv - glHint - glIndexd - glIndexdv - glIndexf - glIndexfv - glIndexi - glIndexiv - glIndexMask - glIndexPointer - glIndexPointerEXT - glIndexs - glIndexsv - glIndexub - glIndexubv - glInitNames - glInterleavedArrays - glIsEnabled - glIsList - glIsTexture - glIsTextureEXT - glLightf - glLightfv - glLighti - glLightiv - glLightModelf - glLightModelfv - glLightModeli - glLightModeliv - glLineStipple - glLineWidth - glListBase - glLoadIdentity - glLoadMatrixd - glLoadMatrixf - glLoadName - glLogicOp - glMap1d - glMap1f - glMap2d - glMap2f - glMapGrid1d - glMapGrid1f - glMapGrid2d - glMapGrid2f - glMaterialf - glMaterialfv - glMateriali - glMaterialiv - glMatrixMode - glMultMatrixd - glMultMatrixf - glNewList - glNormal3b - glNormal3bv - glNormal3d - glNormal3dv - glNormal3f - glNormal3fv - glNormal3i - glNormal3iv - glNormal3s - glNormal3sv - glNormalPointer - glNormalPointerEXT - glOrtho - glPassThrough - glPixelMapfv - glPixelMapuiv - glPixelMapusv - glPixelStoref - glPixelStorei - glPixelTransferf - glPixelTransferi - glPixelZoom - glPointParameterfEXT - glPointParameterfvEXT - glPointSize - glPolygonMode - glPolygonOffset - glPolygonOffsetEXT - glPolygonStipple - glPopAttrib - glPopClientAttrib - glPopMatrix - glPopName - glPrioritizeTextures - glPrioritizeTexturesEXT - glPushAttrib - glPushClientAttrib - glPushMatrix - glPushName - glRasterPos2d - glRasterPos2dv - glRasterPos2f - glRasterPos2fv - glRasterPos2i - glRasterPos2iv - glRasterPos2s - glRasterPos2sv - glRasterPos3d - glRasterPos3dv - glRasterPos3f - glRasterPos3fv - glRasterPos3i - glRasterPos3iv - glRasterPos3s - glRasterPos3sv - glRasterPos4d - glRasterPos4dv - glRasterPos4f - glRasterPos4fv - glRasterPos4i - glRasterPos4iv - glRasterPos4s - glRasterPos4sv - glReadBuffer - glReadPixels - glRectd - glRectdv - glRectf - glRectfv - glRecti - glRectiv - glRects - glRectsv - glRenderMode - glResizeBuffersMESA - glRotated - glRotatef - glScaled - glScalef - glScissor - glSelectBuffer - glShadeModel - glStencilFunc - glStencilMask - glStencilOp - glTexCoord1d - glTexCoord1dv - glTexCoord1f - glTexCoord1fv - glTexCoord1i - glTexCoord1iv - glTexCoord1s - glTexCoord1sv - glTexCoord2d - glTexCoord2dv - glTexCoord2f - glTexCoord2fv - glTexCoord2i - glTexCoord2iv - glTexCoord2s - glTexCoord2sv - glTexCoord3d - glTexCoord3dv - glTexCoord3f - glTexCoord3fv - glTexCoord3i - glTexCoord3iv - glTexCoord3s - glTexCoord3sv - glTexCoord4d - glTexCoord4dv - glTexCoord4f - glTexCoord4fv - glTexCoord4i - glTexCoord4iv - glTexCoord4s - glTexCoord4sv - glTexCoordPointer - glTexCoordPointerEXT - glTexEnvf - glTexEnvfv - glTexEnvi - glTexEnviv - glTexGend - glTexGendv - glTexGenf - glTexGenfv - glTexGeni - glTexGeniv - glTexImage1D - glTexImage2D - glTexImage3DEXT - glTexParameterf - glTexParameterfv - glTexParameteri - glTexParameteriv - glTexSubImage1D - glTexSubImage2D - glTexSubImage3DEXT - glTranslated - glTranslatef - glVertex2d - glVertex2dv - glVertex2f - glVertex2fv - glVertex2i - glVertex2iv - glVertex2s - glVertex2sv - glVertex3d - glVertex3dv - glVertex3f - glVertex3fv - glVertex3i - glVertex3iv - glVertex3s - glVertex3sv - glVertex4d - glVertex4dv - glVertex4f - glVertex4fv - glVertex4i - glVertex4iv - glVertex4s - glVertex4sv - glVertexPointer - glVertexPointerEXT - glViewport - glWindowPos2dMESA - glWindowPos2dvMESA - glWindowPos2fMESA - glWindowPos2fvMESA - glWindowPos2iMESA - glWindowPos2ivMESA - glWindowPos2sMESA - glWindowPos2svMESA - glWindowPos3dMESA - glWindowPos3dvMESA - glWindowPos3fMESA - glWindowPos3fvMESA - glWindowPos3iMESA - glWindowPos3ivMESA - glWindowPos3sMESA - glWindowPos3svMESA - glWindowPos4dMESA - glWindowPos4dvMESA - glWindowPos4fMESA - glWindowPos4fvMESA - glWindowPos4iMESA - glWindowPos4ivMESA - glWindowPos4sMESA - glWindowPos4svMESA -; WMesaCreateContext -; WMesaDestroyContext -; WMesaMakeCurrent -; WMesaPaletteChange -; WMesaSwapBuffers -; OSMesaCreateContext -; OSMesaDestroyContext -; OSMesaMakeCurrent -; OSMesaGetCurrentContext -; OSMesaPixelStore -; OSMesaGetIntegerv -; OSMesaGetDepthBuffer - wglCopyContext - wglCreateContext - wglCreateLayerContext - wglDeleteContext -; wglDescribeLayerPlane - wglGetCurrentContext - wglGetCurrentDC -; wglGetLayerPaletteEntries - wglGetProcAddress - wglMakeCurrent -; wglRealizeLayerPalette -; wglSetLayerPaletteEntries - wglShareLists - wglSwapLayerBuffers - wglUseFontBitmapsA - wglUseFontBitmapsW - wglUseFontOutlinesA - wglUseFontOutlinesW - wglChoosePixelFormat - wglDescribePixelFormat - wglGetPixelFormat - wglSetPixelFormat - wglSwapBuffers - - - diff --git a/src/mesa/drivers/d3d/WGL.C b/src/mesa/drivers/d3d/WGL.C deleted file mode 100644 index 170d094ed4..0000000000 --- a/src/mesa/drivers/d3d/WGL.C +++ /dev/null @@ -1,1262 +0,0 @@ -/*===========================================================================*/ -/* */ -/* Mesa-3.0 Makefile for DirectX 6 */ -/* */ -/* By Leigh McRae */ -/* */ -/* http://www.altsoftware.com/ */ -/* */ -/* Copyright (c) 1998-1997 alt.software inc. All Rights Reserved */ -/*===========================================================================*/ -#include "D3DMesa.h" -/*===========================================================================*/ -/* Window managment. */ -/*===========================================================================*/ -static BOOL InitOpenGL( HINSTANCE hInst ); -static BOOL TermOpenGL( HINSTANCE hInst ); -static BOOL ResizeContext( GLcontext *ctx ); -static BOOL MakeCurrent( D3DMESACONTEXT *pContext ); -static void DestroyContext( D3DMESACONTEXT *pContext ); -static BOOL UnBindWindow( D3DMESACONTEXT *pContext ); -LONG APIENTRY wglMonitorProc( HWND hwnd, UINT message, UINT wParam, LONG lParam ); -/*===========================================================================*/ -/* Mesa hooks. */ -/*===========================================================================*/ -static void SetupDDPointers( GLcontext *ctx ); -static void SetupSWDDPointers( GLcontext *ctx ); -static void SetupHWDDPointers( GLcontext *ctx ); -static void SetupNULLDDPointers( GLcontext *ctx ); -static const char *RendererString( void ); - -/* State Management hooks. */ -static void SetColor( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a ); -static void ClearColor( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a ); -static GLboolean SetBuffer( GLcontext *ctx, GLenum buffer ); - -/* Window Management hooks. */ -static void GetBufferSize( GLcontext *ctx, GLuint *width, GLuint *height ); -static void SetViewport( GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h ); -static void Flush( GLcontext *ctx ); - -/* Span rendering hooks. */ -void WSpanRGB( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte rgb[][3], const GLubyte mask[] ); -void WSpanRGBA( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte rgba[][4], const GLubyte mask[] ); -void WSpanRGBAMono( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte mask[] ); -void WPixelsRGBA( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte rgba[][4], const GLubyte mask[] ); -void WPixelsRGBAMono( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte mask[] ); -void RSpanRGBA( const GLcontext* ctx, GLuint n, GLint x, GLint y, GLubyte rgba[][4] ); -void RPixelsRGBA( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], GLubyte rgba[][4], const GLubyte mask[] ); -GLbitfield ClearBuffers( GLcontext *ctx, GLbitfield mask, GLboolean all, GLint x, GLint y, GLint width, GLint height ); - -/* Primitve rendering hooks. */ -GLboolean RenderVertexBuffer( GLcontext *ctx, GLboolean allDone ); -void RenderOneTriangle( GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint pv ); -void RenderOneLine( GLcontext *ctx, GLuint v1, GLuint v2, GLuint pv ); -GLbitfield ClearBuffersD3D( GLcontext *ctx, GLbitfield mask, GLboolean all, GLint x, GLint y, GLint width, GLint height ); - -/* Texture Management hooks. */ -static void TextureBind( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj ); -static void TextureLoad( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj, GLint level, GLint internalFormat, const struct gl_texture_image *image ); -static void TextureSubImage( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLint internalFormat, const struct gl_texture_image *image ); -/*===========================================================================*/ -/* Global variables. */ -/*===========================================================================*/ -D3DMESACONTEXT *pD3DCurrent, - *pD3DDefault; /* Thin support context. */ - -struct __extensions__ ext[] = { - - { (PROC)glPolygonOffsetEXT, "glPolygonOffsetEXT" }, - { (PROC)glBlendEquationEXT, "glBlendEquationEXT" }, - { (PROC)glBlendColorEXT, "glBlendColorExt" }, - { (PROC)glVertexPointerEXT, "glVertexPointerEXT" }, - { (PROC)glNormalPointerEXT, "glNormalPointerEXT" }, - { (PROC)glColorPointerEXT, "glColorPointerEXT" }, - { (PROC)glIndexPointerEXT, "glIndexPointerEXT" }, - { (PROC)glTexCoordPointerEXT, "glTexCoordPointer" }, - { (PROC)glEdgeFlagPointerEXT, "glEdgeFlagPointerEXT" }, - { (PROC)glGetPointervEXT, "glGetPointervEXT" }, - { (PROC)glArrayElementEXT, "glArrayElementEXT" }, - { (PROC)glDrawArraysEXT, "glDrawArrayEXT" }, - { (PROC)glAreTexturesResidentEXT, "glAreTexturesResidentEXT" }, - { (PROC)glBindTextureEXT, "glBindTextureEXT" }, - { (PROC)glDeleteTexturesEXT, "glDeleteTexturesEXT" }, - { (PROC)glGenTexturesEXT, "glGenTexturesEXT" }, - { (PROC)glIsTextureEXT, "glIsTextureEXT" }, - { (PROC)glPrioritizeTexturesEXT, "glPrioritizeTexturesEXT" }, - { (PROC)glCopyTexSubImage3DEXT, "glCopyTexSubImage3DEXT" }, - { (PROC)glTexImage3DEXT, "glTexImage3DEXT" }, - { (PROC)glTexSubImage3DEXT, "glTexSubImage3DEXT" }, -}; - -int qt_ext = sizeof(ext) / sizeof(ext[0]); -float g_DepthScale, - g_MaxDepth; -/*===========================================================================*/ -/* When a process loads this DLL we will setup the linked list for context */ -/* management and create a default context that will support the API until */ -/* the user creates and binds thier own. This THIN default context is useful*/ -/* to have around. */ -/* When the process terminates we will clean up all resources here. */ -/*===========================================================================*/ -/* RETURN: TRUE, FALSE. */ -/*===========================================================================*/ -BOOL APIENTRY DllMain( HINSTANCE hInst, DWORD reason, LPVOID reserved ) -{ - switch( reason ) - { - case DLL_PROCESS_ATTACH: - return InitOpenGL( hInst ); - - case DLL_PROCESS_DETACH: - return TermOpenGL( hInst ); - } - - return TRUE; -} -/*===========================================================================*/ -/* The first thing we do when this dll is hit is connect to the dll that has*/ -/* handles all the DirectX 6 rendering. I decided to use another dll as DX6 */ -/* is all C++ and Mesa-3.0 is C (thats a good thing). This way I can write */ -/* the DX6 in C++ and Mesa-3.0 in C without having to worry about linkage. */ -/* I feel this is easy and better then using static wrappers as it is likely */ -/* faster and it allows me to just develope the one without compiling the */ -/* other. */ -/* NOTE that at this point we don't have much other than a very thin context*/ -/* that will support the API calls only to the point of not causing the app */ -/* to crash from the API table being empty. */ -/*===========================================================================*/ -/* RETURN: TRUE, FALSE. */ -/*===========================================================================*/ -static BOOL InitOpenGL( HINSTANCE hInst ) -{ - /* Allocate and clear the default context. */ - pD3DDefault = (PD3DMESACONTEXT)ALLOC( sizeof(D3DMESACONTEXT) ); - if ( pD3DDefault == NULL ) - return FALSE; - memset( pD3DDefault, 0, sizeof(D3DMESACONTEXT) ); - - /* Clear the D3D vertex buffer so that values not used will be zero. This */ - /* save me from some redundant work. */ - memset( &D3DTLVertices, 0, sizeof(D3DTLVertices) ); - - /* Update the link. We uses a circular list so that it is easy to */ - /* add and search. This context will also be used for head and tail.*/ - pD3DDefault->next = pD3DDefault; - - /*========================================================================*/ - /* Do all core Mesa stuff. */ - /*========================================================================*/ - pD3DDefault->gl_visual = _mesa_create_visual( TRUE, - FALSE, /* db_flag */ - GL_FALSE, /* stereo */ - 8,8,8,8, /* r, g, b, a bits */ - 0, /* index bits */ - 16, /* depth_bits */ - 8, /* stencil_bits */ - 8,8,8,8, /* accum_bits */ - 1 ); - - if ( pD3DDefault->gl_visual == NULL) - { - FREE( pD3DDefault ); - return FALSE; - } - - /* Allocate a new Mesa context */ - pD3DDefault->gl_ctx = _mesa_create_context( pD3DDefault->gl_visual, NULL, pD3DDefault, GL_TRUE ); - if ( pD3DDefault->gl_ctx == NULL ) - { - _mesa_destroy_visual( pD3DDefault->gl_visual ); - FREE( pD3DDefault ); - return FALSE; - } - - /* Allocate a new Mesa frame buffer */ - pD3DDefault->gl_buffer = _mesa_create_framebuffer( pD3DDefault->gl_visual ); - if ( pD3DDefault->gl_buffer == NULL ) - { - _mesa_destroy_visual( pD3DDefault->gl_visual ); - _mesa_destroy_context( pD3DDefault->gl_ctx ); - FREE( pD3DDefault ); - return FALSE; - } - SetupDDPointers( pD3DDefault->gl_ctx ); - _mesa_make_current( pD3DDefault->gl_ctx, pD3DDefault->gl_buffer ); - - return TRUE; -} -/*===========================================================================*/ -/* This function will create a new D3D context but will not create the D3D */ -/* surfaces or even an instance of D3D (see at GetBufferSize). The only stuff*/ -/* done here is the internal Mesa stuff and some Win32 handles. */ -/*===========================================================================*/ -/* RETURN: casted pointer to the context, NULL. */ -/*===========================================================================*/ -HGLRC APIENTRY wglCreateContext( HDC hdc ) -{ - D3DMESACONTEXT *pNewContext; - DWORD dwCoopFlags = DDSCL_NORMAL; - RECT rectClient; - POINT pt; - - /* ALLOC and clear the new context. */ - pNewContext = (PD3DMESACONTEXT)ALLOC( sizeof(D3DMESACONTEXT) ); - if ( pNewContext == NULL ) - { - SetLastError( 0 ); - return (HGLRC)NULL; - } - memset( pNewContext, 0, sizeof(D3DMESACONTEXT) ); - - /*========================================================================*/ - /* Do all core Mesa stuff. */ - /*========================================================================*/ - - /* TODO: support more then one visual. */ - pNewContext->gl_visual = _mesa_create_visual( TRUE, - TRUE, /* db_flag */ - GL_FALSE, /* stereo */ - 8,8,8,8, /* r, g, b, a bits */ - 0, /* index bits */ - 16, /* depth_bits */ - 8, /* stencil_bits */ - 16,16,16,16,/* accum_bits */ - 1 ); - if ( pNewContext->gl_visual == NULL) - { - FREE( pNewContext ); - SetLastError( 0 ); - return (HGLRC)NULL; - } - - /* Allocate a new Mesa context */ - pNewContext->gl_ctx = _mesa_create_context( pNewContext->gl_visual, NULL, pNewContext, GL_TRUE ); - if ( pNewContext->gl_ctx == NULL ) - { - _mesa_destroy_visual( pNewContext->gl_visual ); - FREE( pNewContext ); - SetLastError( 0 ); - return (HGLRC)NULL; - } - - /* Allocate a new Mesa frame buffer */ - pNewContext->gl_buffer = _mesa_create_framebuffer( pNewContext->gl_visual ); - if ( pNewContext->gl_buffer == NULL ) - { - _mesa_destroy_visual( pNewContext->gl_visual ); - _mesa_destroy_context( pNewContext->gl_ctx ); - FREE( pNewContext ); - SetLastError( 0 ); - return (HGLRC)NULL; - } - - /*========================================================================*/ - /* Do all the driver stuff. */ - /*========================================================================*/ - pNewContext->hdc = hdc; - pNewContext->next = pD3DDefault->next; - pD3DDefault->next = pNewContext; /* Add to circular list. */ - - /* Create the HAL for the new context. */ - pNewContext->pShared = InitHAL( WindowFromDC(hdc) ); - - return (HGLRC)pNewContext; -} -/*===========================================================================*/ -/* This is a wrapper function that is supported by MakeCurrent. */ -/*===========================================================================*/ -/* RETURN: TRUE, FALSE. */ -/*===========================================================================*/ -BOOL APIENTRY wglMakeCurrent( HDC hdc, HGLRC hglrc ) -{ - return MakeCurrent((D3DMESACONTEXT *)hglrc); -} -/*===========================================================================*/ -/* MakeCurrent will unbind whatever context is current (if any) & then bind */ -/* the supplied context. A context that is bound has it's window proc hooked*/ -/* with the wglMonitorProc and the context pointer is saved in pD3DCurrent. */ -/* Once the context is bound we update the Mesa-3.0 hooks (SetDDPointers) and*/ -/* the viewport (Mesa-.30 and DX6). */ -/* */ -/* TODO: this function can't fail. */ -/*===========================================================================*/ -/* RETURN: TRUE */ -/*===========================================================================*/ -static BOOL MakeCurrent( D3DMESACONTEXT *pContext ) -{ - D3DMESACONTEXT *pNext; - - /*====================================================================*/ - /* This is a special case that is a request to have no context bound. */ - /*====================================================================*/ - if ( pContext == NULL ) - { - /* Walk the whole list. We start and end at the Default context. */ - for( pNext = pD3DDefault->next; pNext != pD3DDefault; pNext = pNext->next ) - UnBindWindow( pNext ); - - return TRUE; - } - - /*=================================================*/ - /* Make for a fast redundant use of this function. */ - /*=================================================*/ - if ( pD3DCurrent == pContext ) - return TRUE; - - /*=============================*/ - /* Unbind the current context. */ - /*=============================*/ - UnBindWindow( pD3DCurrent ); - - /*=====================================*/ - /* Let Mesa-3.0 we have a new context. */ - /*=====================================*/ - SetupDDPointers( pContext->gl_ctx ); - _mesa_make_current( pContext->gl_ctx, pContext->gl_buffer ); - - /* We are done so set the internal current context. */ - if ( pContext != pD3DDefault ) - { - ResizeContext( pContext->gl_ctx ); - pContext->hOldProc = (WNDPROC)GetWindowLong( pContext->pShared->hwnd, GWL_WNDPROC ); - SetWindowLong( pContext->pShared->hwnd, GWL_WNDPROC, (LONG)wglMonitorProc ); - } - pD3DCurrent = pContext; - - return TRUE; -} -/*===========================================================================*/ -/* This function will only return the current window size. I have re-done */ -/* this function so that it doesn't check the current size and react to it as*/ -/* I should be able to have all the react code in the WM_SIZE message. The */ -/* old version would check the current window size and create/resize the HAL */ -/* surfaces if they have changed. I needed to delay the creation if the */ -/* surfaces because sometimes I wouldn't have a window size so this is where */ -/* I delayed it. If you are reading this then all went ok! */ -/* The default context will return a zero sized window and I'm not sure if */ -/* this is ok at this point (TODO). */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void GetBufferSize( GLcontext *ctx, GLuint *width, GLuint *height ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - - /* Fall through for the default because that is one of the uses for it. */ - if ( pContext == pD3DDefault ) - { - *width = 0; - *height = 0; - } - else - { - *width = pContext->pShared->dwWidth; - *height = pContext->pShared->dwHeight; - } -} -/*===========================================================================*/ -/* */ -/* */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static BOOL ResizeContext( GLcontext *ctx ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx, - *pCurrentTemp; - RECT rectClient; - POINT pt; - DWORD dwWidth, - dwHeight; - static BOOL bDDrawLock = FALSE; - - /* Make sure we have some values. */ - if ( (pContext->hdc == NULL ) || - (pContext->pShared->hwnd != WindowFromDC(pContext->hdc)) || - (pContext == pD3DDefault) ) - return FALSE; - - /* Having problems with DDraw sending resize messages before I was done. */ - if( bDDrawLock == TRUE ) - return FALSE; - - // TODO: don't think I need this anymore. - pCurrentTemp = pD3DCurrent; - pD3DCurrent = pD3DDefault; - bDDrawLock = TRUE; - - /* Get the current window dimentions. */ - UpdateScreenPosHAL( pContext->pShared ); - dwWidth = pContext->pShared->rectW.right - pContext->pShared->rectW.left; - dwHeight = pContext->pShared->rectW.bottom - pContext->pShared->rectW.top; - - /* Is the size of the OffScreen Render different? */ - if ( (dwWidth != pContext->pShared->dwWidth) || (dwHeight != pContext->pShared->dwHeight) ) - { - /* Create all the D3D surfaces and device. */ - CreateHAL( pContext->pShared ); - - /* I did this so that software rendering would still work as */ - /* I don't need to scale the z values twice. */ - g_DepthScale = (pContext->pShared->bHardware) ? 1.0 : ((float)0x00FFFFFF); - g_MaxDepth = (pContext->pShared->bHardware) ? 1.0 : ((float)0x00FFFFFF); - gl_DepthRange( pContext->gl_ctx, ctx->Viewport.Near, ctx->Viewport.Far ); - - /* Make sure we have a viewport. */ - gl_Viewport( pContext->gl_ctx, 0, 0, dwWidth, dwHeight ); - - /* Update Mesa as we might have changed from SW <-> HW. */ - SetupDDPointers( pContext->gl_ctx ); - _mesa_make_current( pContext->gl_ctx, pContext->gl_buffer ); - - /* If we are in HW we need to load the current texture if there is one already. */ - // if ( (ctx->Texture.Set[ctx->Texture.CurrentSet].Current != NULL) && - // (pContext->pShared->bHardware == TRUE) ) - // { - // CreateTMgrHAL( pContext->pShared, - // ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Name, - // 0, - // ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0]->Format, - // (RECT *)NULL, - // ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0]->Width, - // ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0]->Height, - // TM_ACTION_BIND, - // (void *)ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0]->Data ); - // } - } - - // TODO: don't think I need this anymore. - pD3DCurrent = pCurrentTemp; - bDDrawLock = FALSE; - - return TRUE; -} - -/*===========================================================================* -/* This function will Blt the render buffer to the PRIMARY surface. I repeat*/ -/* this code for the other SwapBuffer like functions and the flush (didn't */ -/* want the function calling overhead). Thsi could have been a macro... */ -/* */ -/* TODO: there are some problems with viewport/scissoring. */ -/*===========================================================================*/ -/* RETURN: TRUE, FALSE. */ -/*===========================================================================*/ -BOOL APIENTRY wglSwapBuffers( HDC hdc ) -{ - /* Fall through for the default because that is one of the uses for it. */ - if ( pD3DCurrent == pD3DDefault ) - return FALSE; - - SwapBuffersHAL( pD3DCurrent->pShared ); - - return TRUE; -} -/*===========================================================================*/ -/* Same as wglSwapBuffers. */ -/*===========================================================================*/ -/* RETURN: TRUE, FALSE. */ -/*===========================================================================*/ -BOOL APIENTRY SwapBuffers( HDC hdc ) -{ - /* Fall through for the default because that is one of the uses for it. */ - if ( pD3DCurrent == pD3DDefault ) - return FALSE; - - SwapBuffersHAL( pD3DCurrent->pShared ); - - return TRUE; -} -/*===========================================================================*/ -/* This should be ok as none of the SwapBuffers will cause a redundant Blt */ -/* as none of my Swap functions will call flush. This should also allow */ -/* sinlge buffered applications to work (not really worried though). Some */ -/* applications may flush then swap but then this is there fault IMHO. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void Flush( GLcontext *ctx ) -{ - /* Fall through for the default because that is one of the uses for it. */ - if ( pD3DCurrent == pD3DDefault ) - return; - - SwapBuffersHAL( pD3DCurrent->pShared ); -} -/*===========================================================================*/ -/* For now this function will ignore the supplied PF. If I'm going to allow */ -/* the user to choice the mode and device at startup I'm going to have to do */ -/* something different. */ -/* */ -/* TODO: use the linked list of modes to build a pixel format to be returned */ -/* to the caller. */ -/*===========================================================================*/ -/* RETURN: 1. */ -/*===========================================================================*/ -int APIENTRY wglChoosePixelFormat( HDC hdc, CONST PIXELFORMATDESCRIPTOR *ppfd ) -{ - return 1; -} -/*===========================================================================*/ -/* See wglChoosePixelFormat. */ -/*===========================================================================*/ -/* RETURN: 1. */ -/*===========================================================================*/ -int APIENTRY ChoosePixelFormat( HDC hdc, CONST PIXELFORMATDESCRIPTOR *ppfd ) -{ - return wglChoosePixelFormat(hdc,ppfd); -} -/*===========================================================================*/ -/* This function (for now) returns a static PF everytime. This is just to */ -/* allow things to continue. */ -/*===========================================================================*/ -/* RETURN: 1. */ -/*===========================================================================*/ -int APIENTRY wglDescribePixelFormat( HDC hdc, int iPixelFormat, UINT nBytes, LPPIXELFORMATDESCRIPTOR ppfd ) -{ - static PIXELFORMATDESCRIPTOR pfd = - { - sizeof(PIXELFORMATDESCRIPTOR), /* size */ - 1, /* version */ - PFD_SUPPORT_OPENGL | - PFD_DRAW_TO_WINDOW | - PFD_DOUBLEBUFFER, /* support double-buffering */ - PFD_TYPE_RGBA, /* color type */ - 16, /* prefered color depth */ - 0, 0, 0, 0, 0, 0, /* color bits (ignored) */ - 0, /* no alpha buffer */ - 0, /* alpha bits (ignored) */ - 0, /* no accumulation buffer */ - 0, 0, 0, 0, /* accum bits (ignored) */ - 16, /* depth buffer */ - 0, /* no stencil buffer */ - 0, /* no auxiliary buffers */ - PFD_MAIN_PLANE, /* main layer */ - 0, /* reserved */ - 0, 0, 0, /* no layer, visible, damage masks */ - }; - - /* Return the address of this static PF if one was requested. */ - if ( ppfd != NULL ) - memcpy( ppfd, &pfd, sizeof(PIXELFORMATDESCRIPTOR) ); - - return 1; -} -/*===========================================================================*/ -/* See wglDescribePixelFormat. */ -/*===========================================================================*/ -/* RETURN: 1. */ -/*===========================================================================*/ -int APIENTRY DescribePixelFormat( HDC hdc, int iPixelFormat, UINT nBytes, LPPIXELFORMATDESCRIPTOR ppfd ) -{ - return wglDescribePixelFormat(hdc,iPixelFormat,nBytes,ppfd); -} -/*===========================================================================*/ -/* This function will always return 1 for now. Just to allow for support. */ -/*===========================================================================*/ -/* RETURN: 1. */ -/*===========================================================================*/ -int APIENTRY wglGetPixelFormat( HDC hdc ) -{ - return 1; -} -/*===========================================================================*/ -/* See wglGetPixelFormat. */ -/*===========================================================================*/ -/* RETURN: 1. */ -/*===========================================================================*/ -int APIENTRY GetPixelFormat( HDC hdc ) -{ - return wglGetPixelFormat(hdc); -} -/*===========================================================================*/ -/* This will aways work for now. */ -/*===========================================================================*/ -/* RETURN: TRUE. */ -/*===========================================================================*/ -BOOL APIENTRY wglSetPixelFormat( HDC hdc, int iPixelFormat, CONST PIXELFORMATDESCRIPTOR *ppfd ) -{ - return TRUE; -} -/*===========================================================================*/ -/* See wglSetPixelFormat. */ -/*===========================================================================*/ -/* RETURN: TRUE, FALSE. */ -/*===========================================================================*/ -BOOL APIENTRY SetPixelFormat( HDC hdc, int iPixelFormat, CONST PIXELFORMATDESCRIPTOR *ppfd ) -{ - return wglSetPixelFormat(hdc,iPixelFormat,ppfd); -} -/*===========================================================================*/ -/* This is a wrapper function that is supported by my own internal function.*/ -/* that takes my own D3D Mesa context structure. This so I can reuse the */ -/* function (no need for speed). */ -/*===========================================================================*/ -/* RETURN: TRUE. */ -/*===========================================================================*/ -BOOL APIENTRY wglDeleteContext( HGLRC hglrc ) -{ - DestroyContext( (D3DMESACONTEXT *)hglrc ); - - return TRUE; -} -/*===========================================================================*/ -/* Simple getter function that uses a cast. */ -/*===========================================================================*/ -/* RETURN: casted pointer to the context, NULL. */ -/*===========================================================================*/ -HGLRC APIENTRY wglGetCurrentContext( VOID ) -{ - return (pD3DCurrent) ? (HGLRC)pD3DCurrent : (HGLRC)NULL; -} -/*===========================================================================*/ -/* No support. */ -/*===========================================================================*/ -/* RETURN: FALSE. */ -/*===========================================================================*/ -BOOL APIENTRY wglCopyContext( HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask ) -{ - SetLastError( 0 ); - return FALSE; -} -/*===========================================================================*/ -/* No support. */ -/*===========================================================================*/ -/* RETURN: NULL. */ -/*===========================================================================*/ -HGLRC APIENTRY wglCreateLayerContext( HDC hdc,int iLayerPlane ) -{ - SetLastError( 0 ); - return (HGLRC)NULL; -} -/*===========================================================================*/ -/* Simple getter function. */ -/*===========================================================================*/ -/* RETURN: FALSE. */ -/*===========================================================================*/ -HDC APIENTRY wglGetCurrentDC( VOID ) -{ - return (pD3DCurrent) ? pD3DCurrent->hdc : (HDC)NULL; -} -/*===========================================================================*/ -/* Simply call that searches the supported extensions for a match & returns */ -/* the pointer to the function that lends support. */ -/*===========================================================================*/ -/* RETURN: pointer to API call, NULL. */ -/*===========================================================================*/ -PROC APIENTRY wglGetProcAddress( LPCSTR lpszProc ) -{ - int index; - - for( index = 0; index < qt_ext; index++ ) - if( !strcmp(lpszProc,ext[index].name) ) - return ext[index].proc; - - SetLastError( 0 ); - return NULL; -} -/*===========================================================================*/ -/* No support. */ -/*===========================================================================*/ -/* RETURN: FALSE. */ -/*===========================================================================*/ -BOOL APIENTRY wglShareLists( HGLRC hglrc1, HGLRC hglrc2 ) -{ - SetLastError( 0 ); - return FALSE; -} -/*===========================================================================*/ -/* No support. */ -/*===========================================================================*/ -/* RETURN: FALSE. */ -/*===========================================================================*/ -BOOL APIENTRY wglUseFontBitmaps( HDC fontDevice, DWORD firstChar, DWORD numChars, DWORD listBase ) -{ - SetLastError( 0 ); - return FALSE; -} -/*===========================================================================*/ -/* No support. */ -/*===========================================================================*/ -/* RETURN: FALSE. */ -/*===========================================================================*/ -BOOL APIENTRY wglUseFontBitmapsW( HDC hdc,DWORD first,DWORD count,DWORD listBase ) -{ - SetLastError( 0 ); - return FALSE; -} -/*===========================================================================*/ -/* No support. */ -/*===========================================================================*/ -/* RETURN: FALSE. */ -/*===========================================================================*/ -BOOL APIENTRY wglUseFontOutlinesA( HDC hdc, DWORD first, DWORD count, DWORD listBase, FLOAT deviation, FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT lpgmf ) -{ - SetLastError( 0 ); - return FALSE; -} -/*===========================================================================*/ -/* No support. */ -/*===========================================================================*/ -/* RETURN: FALSE. */ -/*===========================================================================*/ -BOOL APIENTRY wglUseFontOutlinesW( HDC hdc,DWORD first,DWORD count, DWORD listBase,FLOAT deviation, FLOAT extrusion,int format, LPGLYPHMETRICSFLOAT lpgmf ) -{ - SetLastError( 0 ); - return FALSE ; -} -/*===========================================================================*/ -/* No support. */ -/*===========================================================================*/ -/* RETURN: FALSE. */ -/*===========================================================================*/ -BOOL APIENTRY wglSwapLayerBuffers( HDC hdc, UINT fuPlanes ) -{ - SetLastError( 0 ); - return FALSE; -} -/*===========================================================================*/ -/* This function will be hooked into the window that has been bound. Right */ -/* now it is used to track the window size and position. Also the we clean */ -/* up the currrent context when the window is close/destroyed. */ -/* */ -/* TODO: there might be something wrong here as some games (Heretic II) don't*/ -/* track the window quit right. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -LONG APIENTRY wglMonitorProc( HWND hwnd, UINT message, UINT wParam, LONG lParam ) -{ - WNDPROC hOldProc; - GLint width, - height; - - switch( message ) - { -// case WM_PAINT: -// break; -// case WM_ACTIVATE: -// break; -// case WM_SHOWWINDOW: -// break; - - case UM_FATALSHUTDOWN: - /* Support the API until we die... */ - MakeCurrent( pD3DDefault ); - break; - - case WM_MOVE: - case WM_DISPLAYCHANGE: - case WM_SIZE: - ResizeContext( pD3DCurrent->gl_ctx ); - break; - - case WM_CLOSE: - case WM_DESTROY: - /* Support the API until we die... */ - hOldProc = pD3DCurrent->hOldProc; - DestroyContext( pD3DCurrent ); - return (hOldProc)(hwnd,message,wParam,lParam); - } - - return (pD3DCurrent->hOldProc)(hwnd,message,wParam,lParam); -} - -/**********************************************************************/ -/***** Miscellaneous device driver funcs *****/ -/**********************************************************************/ - -/*===========================================================================*/ -/* Not reacting to this as I'm only supporting drawing to the back buffer */ -/* right now. */ -/*===========================================================================*/ -/* RETURN: TRUE. */ -/*===========================================================================*/ -static GLboolean SetBuffer( GLcontext *ctx, GLenum buffer ) -{ - if (buffer == GL_BACK_LEFT) - return GL_TRUE; - else - return GL_FALSE; -} -/*===========================================================================*/ -/* This proc will be called by Mesa when the viewport has been set. So if */ -/* we have a context and it isn't the default then we should let D3D know of */ -/* the change. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void SetViewport( GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - RECT rect; - - /* Make sure we can set a viewport. */ - if ( pContext->pShared && (pContext != pD3DDefault) ) - { - // TODO: might be needed. - UpdateScreenPosHAL( pContext->pShared ); - rect.left = x; - rect.right = x + w; - rect.top = y; - rect.bottom = y + h; - - // TODO: shared struct should make this call smaller - SetViewportHAL( pContext->pShared, &rect, 0.0F, 1.0F ); - } -} -/*===========================================================================*/ -/* This function could be better I guess but I decided just to grab the four*/ -/* components and store then seperately. Makes it easier to use IMHO. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void ClearColor( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - - pContext->aClear = a; - pContext->bClear = b; - pContext->gClear = g; - pContext->rClear = r; -} -/*===========================================================================*/ -/* This function could be better I guess but I decided just to grab the four*/ -/* components and store then seperately. Makes it easier to use IMHO. */ -/* (is there an echo in here?) */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void SetColor( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - - pContext->aCurrent = a; - pContext->bCurrent = b; - pContext->gCurrent = g; - pContext->rCurrent = r; -} -/*===========================================================================*/ -/* */ -/* */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static const char *RendererString( void ) -{ - static char pszRender[64]; - - strcpy( pszRender, "altD3D " ); - - if ( pD3DCurrent->pShared->bHardware ) - strcat( pszRender, "(HW)"); - else - strcat( pszRender, "(SW)"); - - return (const char *)pszRender; -} -/*===========================================================================*/ -/* This function will choose which set of pointers Mesa will use based on */ -/* whether we hard using hardware or software. I have added another set of */ -/* pointers that will do nothing but stop the API from crashing. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void SetupDDPointers( GLcontext *ctx ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - - // TODO: write a generic NULL support for the span render. - if ( pContext->pShared && pContext->pShared->bHardware ) - { - ctx->Driver.UpdateState = SetupHWDDPointers; - } - else if ( pContext == pD3DDefault ) - { - ctx->Driver.UpdateState = SetupNULLDDPointers; - } - else - { - ctx->Driver.UpdateState = SetupSWDDPointers; - } -} -/*===========================================================================*/ -/* This function will populate all the Mesa driver hooks. This version of */ -/* hooks will do nothing but support the API when we don't have a valid */ -/* context bound. This is mostly for applications that don't behave right */ -/* and also to help exit as clean as possable when we have a FatalError. */ -/*===========================================================================*/ -/* RETURN: pointer to the specific function. */ -/*===========================================================================*/ -static void SetupNULLDDPointers( GLcontext *ctx ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - - /* Initialize all the pointers in the DD struct. Do this whenever */ - /* a new context is made current or we change buffers via set_buffer! */ - ctx->Driver.UpdateState = SetupNULLDDPointers; - - /* State management hooks. */ - ctx->Driver.Color = NULLSetColor; - ctx->Driver.ClearColor = NULLClearColor; - ctx->Driver.Clear = NULLClearBuffers; - ctx->Driver.SetBuffer = NULLSetBuffer; - - /* Window management hooks. */ - ctx->Driver.GetBufferSize = NULLGetBufferSize; - - /* Primitive rendering hooks. */ - ctx->Driver.TriangleFunc = NULL; - ctx->Driver.RenderVB = NULL; - - /* Pixel/span writing functions: */ - ctx->Driver.WriteRGBASpan = NULLWrSpRGBA; - ctx->Driver.WriteRGBSpan = NULLWrSpRGB; - ctx->Driver.WriteMonoRGBASpan = NULLWrSpRGBAMono; - ctx->Driver.WriteRGBAPixels = NULLWrPiRGBA; - ctx->Driver.WriteMonoRGBAPixels = NULLWrPiRGBAMono; - - /* Pixel/span reading functions: */ - ctx->Driver.ReadRGBASpan = NULLReSpRGBA; - ctx->Driver.ReadRGBAPixels = NULLRePiRGBA; - - /* Misc. hooks. */ - ctx->Driver.RendererString = RendererString; -} -/*===========================================================================*/ -/* This function will populate all the Mesa driver hooks. There are two of */ -/* these functions. One if we have hardware support and one is there is only*/ -/* software. These functions will be called by Mesa and by the wgl.c when we*/ -/* have resized (or created) the buffers. The thing is that if a window gets*/ -/* resized we may loose hardware support or gain it... */ -/*===========================================================================*/ -/* RETURN: pointer to the specific function. */ -/*===========================================================================*/ -static void SetupSWDDPointers( GLcontext *ctx ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - - /* Initialize all the pointers in the DD struct. Do this whenever */ - /* a new context is made current or we change buffers via set_buffer! */ - ctx->Driver.UpdateState = SetupSWDDPointers; - - /* State management hooks. */ - ctx->Driver.Color = SetColor; - ctx->Driver.ClearColor = ClearColor; - ctx->Driver.Clear = ClearBuffers; - ctx->Driver.SetBuffer = SetBuffer; - - /* Window management hooks. */ - ctx->Driver.GetBufferSize = GetBufferSize; - ctx->Driver.Viewport = SetViewport; - - /* Primitive rendering hooks. */ - ctx->Driver.TriangleFunc = NULL; - ctx->Driver.RenderVB = NULL; - - /* Texture management hooks. */ - - /* Pixel/span writing functions: */ - ctx->Driver.WriteRGBASpan = WSpanRGBA; - ctx->Driver.WriteRGBSpan = WSpanRGB; - ctx->Driver.WriteMonoRGBASpan = WSpanRGBAMono; - ctx->Driver.WriteRGBAPixels = WPixelsRGBA; - ctx->Driver.WriteMonoRGBAPixels = WPixelsRGBAMono; - - /* Pixel/span reading functions: */ - ctx->Driver.ReadRGBASpan = RSpanRGBA; - ctx->Driver.ReadRGBAPixels = RPixelsRGBA; - - /* Misc. hooks. */ - ctx->Driver.Flush = Flush; - ctx->Driver.RendererString = RendererString; -} -/*===========================================================================*/ -/* This function will populate all the Mesa driver hooks. There are two of */ -/* these functions. One if we have hardware support and one is there is only*/ -/* software. These functions will be called by Mesa and by the wgl.c when we*/ -/* have resized (or created) the buffers. The thing is that if a window gets*/ -/* resized we may loose hardware support or gain it... */ -/*===========================================================================*/ -/* RETURN: pointer to the specific function. */ -/*===========================================================================*/ -static void SetupHWDDPointers( GLcontext *ctx ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - - /* Initialize all the pointers in the DD struct. Do this whenever */ - /* a new context is made current or we change buffers via set_buffer! */ - ctx->Driver.UpdateState = SetupHWDDPointers; - - /* State management hooks. */ - ctx->Driver.Color = SetColor; - ctx->Driver.ClearColor = ClearColor; - ctx->Driver.Clear = ClearBuffersD3D; - ctx->Driver.SetBuffer = SetBuffer; - - /* Window management hooks. */ - ctx->Driver.GetBufferSize = GetBufferSize; - ctx->Driver.Viewport = SetViewport; - - /* Primitive rendering hooks. */ - ctx->Driver.TriangleFunc = RenderOneTriangle; - ctx->Driver.LineFunc = RenderOneLine; - ctx->Driver.RenderVB = RenderVertexBuffer; - - /* Pixel/span writing functions: */ - ctx->Driver.WriteRGBASpan = WSpanRGBA; - ctx->Driver.WriteRGBSpan = WSpanRGB; - ctx->Driver.WriteMonoRGBASpan = WSpanRGBAMono; - ctx->Driver.WriteRGBAPixels = WPixelsRGBA; - ctx->Driver.WriteMonoRGBAPixels = WPixelsRGBAMono; - - /* Pixel/span reading functions: */ - ctx->Driver.ReadRGBASpan = RSpanRGBA; - ctx->Driver.ReadRGBAPixels = RPixelsRGBA; - - /* Texture management hooks. */ - // ctx->Driver.BindTexture = TextureBind; - ctx->Driver.TexImage = TextureLoad; - ctx->Driver.TexSubImage = TextureSubImage; - - /* Misc. hooks. */ - ctx->Driver.Flush = Flush; - ctx->Driver.RendererString = RendererString; -} -/*===========================================================================*/ -/* This function will release all resources used by the DLL. Every context */ -/* will be clobbered by releaseing all driver desources and then freeing the */ -/* context memory. Most all the work is done in DestroyContext. */ -/*===========================================================================*/ -/* RETURN: TRUE. */ -/*===========================================================================*/ -static BOOL TermOpenGL( HINSTANCE hInst ) -{ - D3DMESACONTEXT *pTmp, - *pNext; - - /* Just incase we are still getting paint msg. */ - MakeCurrent( pD3DDefault ); - - /* Walk the list until we get back to the default context. */ - for( pTmp = pD3DDefault->next; pTmp != pD3DDefault; pTmp = pNext ) - { - pNext = pTmp->next; - DestroyContext( pTmp ); - } - DestroyContext( pD3DDefault ); - - return TRUE; -} -/*===========================================================================*/ -/* This function is an internal function that will clean up all the Mesa */ -/* context bound to this D3D context. Also any D3D stuff that this context */ -/* uses will be unloaded. */ -/*===========================================================================*/ -/* RETURN: TRUE, FALSE. */ -/*===========================================================================*/ -static void DestroyContext( D3DMESACONTEXT *pContext ) -{ - D3DMESACONTEXT *pTmp; - - /* Walk the list until we find the context before this one. */ - for( pTmp = pD3DDefault; pTmp && (pTmp->next != pContext); pTmp = pTmp->next ) - if ( pTmp == pTmp->next ) - break; - - /* If we never found it it must already be deleted. */ - if ( pTmp->next != pContext ) - return; - - /* Make sure we are not using this context. */ - if ( pContext == pD3DCurrent ) - MakeCurrent( pD3DDefault ); - - /* Free the Mesa stuff. */ - if ( pContext->gl_visual ) - { - _mesa_destroy_visual( pContext->gl_visual ); - pContext->gl_visual = NULL; - } - if ( pContext->gl_buffer ) - { - _mesa_destroy_framebuffer( pContext->gl_buffer ); - pContext->gl_buffer = NULL; - } - if ( pContext->gl_ctx ) - { - _mesa_destroy_context( pContext->gl_ctx ); - pContext->gl_ctx = NULL; - } - - /* Now dump the D3D. */ - if ( pContext->pShared ) - TermHAL( pContext->pShared ); - - /* Update the previous context's link. */ - pTmp->next = pContext->next; - - /* Gonzo. */ - FREE( pContext ); -} -/*===========================================================================*/ -/* This function will pull the supplied context away from Win32. Basicly it*/ -/* will remove the hook from the window Proc. */ -/* */ -/* TODO: might want to serialize this stuff... */ -/*===========================================================================*/ -/* RETURN: TRUE, FALSE. */ -/*===========================================================================*/ -static BOOL UnBindWindow( D3DMESACONTEXT *pContext ) -{ - if ( pContext == NULL ) - return FALSE; - - if ( pContext == pD3DDefault ) - return TRUE; - - /* Make sure we always have a context bound. */ - if ( pContext == pD3DCurrent ) - pD3DCurrent = pD3DDefault; - - SetWindowLong( pContext->pShared->hwnd, GWL_WNDPROC, (LONG)pContext->hOldProc ); - pContext->hOldProc = NULL; - - return TRUE; -} -/*===========================================================================*/ -/* There are two cases that allow for a faster clear when we know that the */ -/* whole buffer is cleared and that there is no clipping. */ -/*===========================================================================*/ -/* RETURN: the original mask with the bits cleared that represents the buffer* -/* or buffers we just cleared. */ -/*===========================================================================*/ -GLbitfield ClearBuffersD3D( GLcontext *ctx, GLbitfield mask, GLboolean all, GLint x, GLint y, GLint width, GLint height ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - DWORD dwFlags = 0; - - if ( mask & GL_COLOR_BUFFER_BIT ) - { - dwFlags |= D3DCLEAR_TARGET; - mask &= ~GL_COLOR_BUFFER_BIT; - } - if ( mask & GL_DEPTH_BUFFER_BIT ) - { - dwFlags |= D3DCLEAR_ZBUFFER; - mask &= ~GL_DEPTH_BUFFER_BIT; - } - if ( dwFlags == 0 ) - return mask; - - ClearHAL( pContext->pShared, - dwFlags, - all, - x, y, - width, height, - ((pContext->aClear<<24) | (pContext->rClear<<16) | (pContext->gClear<<8) | (pContext->bClear)), - ctx->Depth.Clear, - 0 ); - - return mask; -} - - - -/*===========================================================================*/ -/* TEXTURE MANAGER: ok here is how I did textures. Mesa-3.0 will keep track*/ -/* of all the textures for us. So this means that at anytime we can go to */ -/* the Mesa context and get the current texture. With this in mind this is */ -/* what I did. I really don't care about what textures get or are loaded */ -/* until I actually have to draw a tri that is textured. At this point I */ -/* must have the texture so I demand the texture by destorying all other */ -/* texture surfaces if need be and load the current one. This allows for the*/ -/* best preformance on low memory cards as time is not wasted loading and */ -/* unload textures. */ -/*===========================================================================*/ - - - - - -/*===========================================================================*/ -/* TextureLoad will try and create a D3D surface from the supplied texture */ -/* object if its level 0 (first). The surface will be fully filled with the */ -/* texture. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void TextureLoad( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj, GLint level, GLint internalFormat, const struct gl_texture_image *image ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - - /* TODO: only doing first LOD. */ - if ( (ctx->DriverCtx == NULL) || (level != 0) ) - return; - - CreateTMgrHAL( pContext->pShared, - tObj->Name, - level, - tObj->Image[level]->Format, - (RECT *)NULL, - tObj->Image[level]->Width, - tObj->Image[level]->Height, - TM_ACTION_LOAD, - (void *)tObj->Image[level]->Data ); -} -/*===========================================================================*/ -/* TextureBind make sure that the texture is on the card. Thats it. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void TextureBind( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - - /* TODO: only doing first LOD. */ - if ( (tObj->Image[0] == NULL) || (ctx->DriverCtx == NULL) ) - return; - - CreateTMgrHAL( pContext->pShared, - tObj->Name, - 0, - tObj->Image[0]->Format, - (RECT *)NULL, - tObj->Image[0]->Width, - tObj->Image[0]->Height, - TM_ACTION_BIND, - (void *)tObj->Image[0]->Data ); -} -/*===========================================================================*/ -/* TextureSubImage will make sure that the texture being updated is updated */ -/* if its on the card. */ -/*===========================================================================*/ -/* RETURN: */ -/*===========================================================================*/ -static void TextureSubImage( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLint internalFormat, const struct gl_texture_image *image ) -{ - D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; - RECT rect; - - /* TODO: only doing first LOD. */ - if ( (ctx->DriverCtx == NULL) || (level > 0) ) - return; - - /* Create a dirty rectangle structure. */ - rect.left = xoffset; - rect.right = xoffset + width; - rect.top = yoffset; - rect.bottom = yoffset + height; - - CreateTMgrHAL( pContext->pShared, - tObj->Name, - 0, - tObj->Image[0]->Format, - &rect, - tObj->Image[0]->Width, - tObj->Image[0]->Height, - TM_ACTION_UPDATE, - (void *)tObj->Image[0]->Data ); -} - diff --git a/src/mesa/drivers/d3d/d3dText.h b/src/mesa/drivers/d3d/d3dText.h deleted file mode 100644 index 9ff0650518..0000000000 --- a/src/mesa/drivers/d3d/d3dText.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef D3D_TEXT_H -#define D3D_TEXT_H - - -#ifdef __cplusplus -extern "C" { -#endif - -/*===========================================================================*/ -/* Includes. */ -/*===========================================================================*/ -#include <windows.h> -#include <ddraw.h> -#include <d3d.h> -/*===========================================================================*/ -/* Magic numbers. */ -/*===========================================================================*/ -#define D3DLTEXT_BITSUSED 0xFFFFFFFF -#define MAX_VERTICES 700 // (14*40) 14 per character, 40 characters -/*===========================================================================*/ -/* Macros defines. */ -/*===========================================================================*/ -/*===========================================================================*/ -/* Type defines. */ -/*===========================================================================*/ -typedef struct _d3dText_metrics -{ - float fntYScale, - fntXScale; - - int fntXSpacing, - fntYSpacing; - - DWORD dwColor; - LPDIRECT3DDEVICE3 lpD3DDevice; - -} D3DFONTMETRICS, *PD3DFONTMETRICS; -/*===========================================================================*/ -/* Function prototypes. */ -/*===========================================================================*/ -extern BOOL InitD3DText( void ); -extern void d3dTextDrawCharacter( char *c, int x, int y, PD3DFONTMETRICS pfntMetrics ); -extern void d3dTextDrawString( char *pszString, int x, int y, PD3DFONTMETRICS pfntMetrics ); -/*===========================================================================*/ -/* Global variables. */ -/*===========================================================================*/ - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/src/mesa/drivers/dri/common/drirenderbuffer.c b/src/mesa/drivers/dri/common/drirenderbuffer.c index 4e7e92c82b..16b45e99f8 100644 --- a/src/mesa/drivers/dri/common/drirenderbuffer.c +++ b/src/mesa/drivers/dri/common/drirenderbuffer.c @@ -60,14 +60,6 @@ driNewRenderbuffer(gl_format format, GLvoid *addr, { driRenderbuffer *drb; - assert(format == GL_RGBA || - format == GL_RGB5 || - format == GL_RGBA8 || - format == GL_DEPTH_COMPONENT16 || - format == GL_DEPTH_COMPONENT24 || - format == GL_DEPTH_COMPONENT32 || - format == GL_STENCIL_INDEX8_EXT); - assert(cpp > 0); assert(pitch > 0); diff --git a/src/mesa/drivers/dri/r300/Lindent b/src/mesa/drivers/dri/r300/Lindent index 7d8d8896e3..7d8d8896e3 100755..100644 --- a/src/mesa/drivers/dri/r300/Lindent +++ b/src/mesa/drivers/dri/r300/Lindent diff --git a/src/mesa/drivers/dri/r300/compiler/SConscript b/src/mesa/drivers/dri/r300/compiler/SConscript index 46075a8aee..46075a8aee 100755..100644 --- a/src/mesa/drivers/dri/r300/compiler/SConscript +++ b/src/mesa/drivers/dri/r300/compiler/SConscript diff --git a/src/mesa/drivers/dri/r600/Lindent b/src/mesa/drivers/dri/r600/Lindent index 7d8d8896e3..7d8d8896e3 100755..100644 --- a/src/mesa/drivers/dri/r600/Lindent +++ b/src/mesa/drivers/dri/r600/Lindent diff --git a/src/mesa/drivers/dri/radeon/radeon_lighting.c b/src/mesa/drivers/dri/radeon/radeon_lighting.c new file mode 100644 index 0000000000..ba444f2b10 --- /dev/null +++ b/src/mesa/drivers/dri/radeon/radeon_lighting.c @@ -0,0 +1,681 @@ +/* + * Copyright 2000, 2001 VA Linux Systems Inc., Fremont, California. + * + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Keith Whitwell <keith@tungstengraphics.com> + */ + +#include "main/glheader.h" +#include "main/imports.h" +#include "api_arrayelt.h" +/* #include "mmath.h" */ +#include "main/enums.h" +#include "colormac.h" + + +#include "radeon_context.h" +#include "radeon_ioctl.h" +#include "radeon_state.h" +#include "radeon_tcl.h" +#include "radeon_tex.h" +#include "radeon_vtxfmt.h" + + + +/* ============================================================= + * Materials + */ + + +/* Update on colormaterial, material emmissive/ambient, + * lightmodel.globalambient + */ +void update_global_ambient( GLcontext *ctx ) +{ + radeonContextPtr rmesa = RADEON_CONTEXT(ctx); + float *fcmd = (float *)RADEON_DB_STATE( glt ); + + /* Need to do more if both emmissive & ambient are PREMULT: + */ + if ((rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] & + ((3 << RADEON_EMISSIVE_SOURCE_SHIFT) | + (3 << RADEON_AMBIENT_SOURCE_SHIFT))) == 0) + { + COPY_3V( &fcmd[GLT_RED], + ctx->Light.Material[0].Emission); + ACC_SCALE_3V( &fcmd[GLT_RED], + ctx->Light.Model.Ambient, + ctx->Light.Material[0].Ambient); + } + else + { + COPY_3V( &fcmd[GLT_RED], ctx->Light.Model.Ambient ); + } + + RADEON_DB_STATECHANGE(rmesa, &rmesa->hw.glt); +} + +/* Update on change to + * - light[p].colors + * - light[p].enabled + * - material, + * - colormaterial enabled + * - colormaterial bitmask + */ +void update_light_colors( GLcontext *ctx, GLuint p ) +{ + struct gl_light *l = &ctx->Light.Light[p]; + +/* fprintf(stderr, "%s\n", __FUNCTION__); */ + + if (l->Enabled) { + radeonContextPtr rmesa = RADEON_CONTEXT(ctx); + float *fcmd = (float *)RADEON_DB_STATE( lit[p] ); + GLuint bitmask = ctx->Light.ColorMaterialBitmask; + struct gl_material *mat = &ctx->Light.Material[0]; + + COPY_4V( &fcmd[LIT_AMBIENT_RED], l->Ambient ); + COPY_4V( &fcmd[LIT_DIFFUSE_RED], l->Diffuse ); + COPY_4V( &fcmd[LIT_SPECULAR_RED], l->Specular ); + + if (!ctx->Light.ColorMaterialEnabled) + bitmask = 0; + + if ((bitmask & FRONT_AMBIENT_BIT) == 0) + SELF_SCALE_3V( &fcmd[LIT_AMBIENT_RED], mat->Ambient ); + + if ((bitmask & FRONT_DIFFUSE_BIT) == 0) + SELF_SCALE_3V( &fcmd[LIT_DIFFUSE_RED], mat->Diffuse ); + + if ((bitmask & FRONT_SPECULAR_BIT) == 0) + SELF_SCALE_3V( &fcmd[LIT_SPECULAR_RED], mat->Specular ); + + RADEON_DB_STATECHANGE( rmesa, &rmesa->hw.lit[p] ); + } +} + +/* Also fallback for asym colormaterial mode in twoside lighting... + */ +void check_twoside_fallback( GLcontext *ctx ) +{ + GLboolean fallback = GL_FALSE; + + if (ctx->Light.Enabled && ctx->Light.Model.TwoSide) { + if (memcmp( &ctx->Light.Material[0], + &ctx->Light.Material[1], + sizeof(struct gl_material)) != 0) + fallback = GL_TRUE; + else if (ctx->Light.ColorMaterialEnabled && + (ctx->Light.ColorMaterialBitmask & BACK_MATERIAL_BITS) != + ((ctx->Light.ColorMaterialBitmask & FRONT_MATERIAL_BITS)<<1)) + fallback = GL_TRUE; + } + + TCL_FALLBACK( ctx, RADEON_TCL_FALLBACK_LIGHT_TWOSIDE, fallback ); +} + +void radeonColorMaterial( GLcontext *ctx, GLenum face, GLenum mode ) +{ + if (ctx->Light.ColorMaterialEnabled) { + radeonContextPtr rmesa = RADEON_CONTEXT(ctx); + GLuint light_model_ctl = rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL]; + GLuint mask = ctx->Light.ColorMaterialBitmask; + + /* Default to PREMULT: + */ + light_model_ctl &= ~((3 << RADEON_EMISSIVE_SOURCE_SHIFT) | + (3 << RADEON_AMBIENT_SOURCE_SHIFT) | + (3 << RADEON_DIFFUSE_SOURCE_SHIFT) | + (3 << RADEON_SPECULAR_SOURCE_SHIFT)); + + if (mask & FRONT_EMISSION_BIT) { + light_model_ctl |= (RADEON_LM_SOURCE_VERTEX_DIFFUSE << + RADEON_EMISSIVE_SOURCE_SHIFT); + } + + if (mask & FRONT_AMBIENT_BIT) { + light_model_ctl |= (RADEON_LM_SOURCE_VERTEX_DIFFUSE << + RADEON_AMBIENT_SOURCE_SHIFT); + } + + if (mask & FRONT_DIFFUSE_BIT) { + light_model_ctl |= (RADEON_LM_SOURCE_VERTEX_DIFFUSE << + RADEON_DIFFUSE_SOURCE_SHIFT); + } + + if (mask & FRONT_SPECULAR_BIT) { + light_model_ctl |= (RADEON_LM_SOURCE_VERTEX_DIFFUSE << + RADEON_SPECULAR_SOURCE_SHIFT); + } + + if (light_model_ctl != rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL]) { + GLuint p; + + RADEON_STATECHANGE( rmesa, tcl ); + rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] = light_model_ctl; + + for (p = 0 ; p < MAX_LIGHTS; p++) + update_light_colors( ctx, p ); + update_global_ambient( ctx ); + } + } + + check_twoside_fallback( ctx ); +} + +void radeonUpdateMaterial( GLcontext *ctx ) +{ + radeonContextPtr rmesa = RADEON_CONTEXT(ctx); + GLfloat *fcmd = (GLfloat *)RADEON_DB_STATE( mtl ); + GLuint p; + GLuint mask = ~0; + + if (ctx->Light.ColorMaterialEnabled) + mask &= ~ctx->Light.ColorMaterialBitmask; + + if (RADEON_DEBUG & RADEON_STATE) + fprintf(stderr, "%s\n", __FUNCTION__); + + + if (mask & FRONT_EMISSION_BIT) { + fcmd[MTL_EMMISSIVE_RED] = ctx->Light.Material[0].Emission[0]; + fcmd[MTL_EMMISSIVE_GREEN] = ctx->Light.Material[0].Emission[1]; + fcmd[MTL_EMMISSIVE_BLUE] = ctx->Light.Material[0].Emission[2]; + fcmd[MTL_EMMISSIVE_ALPHA] = ctx->Light.Material[0].Emission[3]; + } + if (mask & FRONT_AMBIENT_BIT) { + fcmd[MTL_AMBIENT_RED] = ctx->Light.Material[0].Ambient[0]; + fcmd[MTL_AMBIENT_GREEN] = ctx->Light.Material[0].Ambient[1]; + fcmd[MTL_AMBIENT_BLUE] = ctx->Light.Material[0].Ambient[2]; + fcmd[MTL_AMBIENT_ALPHA] = ctx->Light.Material[0].Ambient[3]; + } + if (mask & FRONT_DIFFUSE_BIT) { + fcmd[MTL_DIFFUSE_RED] = ctx->Light.Material[0].Diffuse[0]; + fcmd[MTL_DIFFUSE_GREEN] = ctx->Light.Material[0].Diffuse[1]; + fcmd[MTL_DIFFUSE_BLUE] = ctx->Light.Material[0].Diffuse[2]; + fcmd[MTL_DIFFUSE_ALPHA] = ctx->Light.Material[0].Diffuse[3]; + } + if (mask & FRONT_SPECULAR_BIT) { + fcmd[MTL_SPECULAR_RED] = ctx->Light.Material[0].Specular[0]; + fcmd[MTL_SPECULAR_GREEN] = ctx->Light.Material[0].Specular[1]; + fcmd[MTL_SPECULAR_BLUE] = ctx->Light.Material[0].Specular[2]; + fcmd[MTL_SPECULAR_ALPHA] = ctx->Light.Material[0].Specular[3]; + } + if (mask & FRONT_SHININESS_BIT) { + fcmd[MTL_SHININESS] = ctx->Light.Material[0].Shininess; + } + + if (RADEON_DB_STATECHANGE( rmesa, &rmesa->hw.mtl )) { + for (p = 0 ; p < MAX_LIGHTS; p++) + update_light_colors( ctx, p ); + + check_twoside_fallback( ctx ); + update_global_ambient( ctx ); + } + else if (RADEON_DEBUG & (RADEON_PRIMS|DEBUG_STATE)) + fprintf(stderr, "%s: Elided noop material call\n", __FUNCTION__); +} + +/* _NEW_LIGHT + * _NEW_MODELVIEW + * _MESA_NEW_NEED_EYE_COORDS + * + * Uses derived state from mesa: + * _VP_inf_norm + * _h_inf_norm + * _Position + * _NormSpotDirection + * _ModelViewInvScale + * _NeedEyeCoords + * _EyeZDir + * + * which are calculated in light.c and are correct for the current + * lighting space (model or eye), hence dependencies on _NEW_MODELVIEW + * and _MESA_NEW_NEED_EYE_COORDS. + */ +void radeonUpdateLighting( GLcontext *ctx ) +{ + radeonContextPtr rmesa = RADEON_CONTEXT(ctx); + + /* Have to check these, or have an automatic shortcircuit mechanism + * to remove noop statechanges. (Or just do a better job on the + * front end). + */ + { + GLuint tmp = rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL]; + + if (ctx->_NeedEyeCoords) + tmp &= ~RADEON_LIGHT_IN_MODELSPACE; + else + tmp |= RADEON_LIGHT_IN_MODELSPACE; + + + /* Leave this test disabled: (unexplained q3 lockup) (even with + new packets) + */ + if (tmp != rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL]) + { + RADEON_STATECHANGE( rmesa, tcl ); + rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] = tmp; + } + } + + { + GLfloat *fcmd = (GLfloat *)RADEON_DB_STATE( eye ); + fcmd[EYE_X] = ctx->_EyeZDir[0]; + fcmd[EYE_Y] = ctx->_EyeZDir[1]; + fcmd[EYE_Z] = - ctx->_EyeZDir[2]; + fcmd[EYE_RESCALE_FACTOR] = ctx->_ModelViewInvScale; + RADEON_DB_STATECHANGE( rmesa, &rmesa->hw.eye ); + } + + +/* RADEON_STATECHANGE( rmesa, glt ); */ + + if (ctx->Light.Enabled) { + GLint p; + for (p = 0 ; p < MAX_LIGHTS; p++) { + if (ctx->Light.Light[p].Enabled) { + struct gl_light *l = &ctx->Light.Light[p]; + GLfloat *fcmd = (GLfloat *)RADEON_DB_STATE( lit[p] ); + + if (l->EyePosition[3] == 0.0) { + COPY_3FV( &fcmd[LIT_POSITION_X], l->_VP_inf_norm ); + COPY_3FV( &fcmd[LIT_DIRECTION_X], l->_h_inf_norm ); + fcmd[LIT_POSITION_W] = 0; + fcmd[LIT_DIRECTION_W] = 0; + } else { + COPY_4V( &fcmd[LIT_POSITION_X], l->_Position ); + fcmd[LIT_DIRECTION_X] = -l->_NormSpotDirection[0]; + fcmd[LIT_DIRECTION_Y] = -l->_NormSpotDirection[1]; + fcmd[LIT_DIRECTION_Z] = -l->_NormSpotDirection[2]; + fcmd[LIT_DIRECTION_W] = 0; + } + + RADEON_DB_STATECHANGE( rmesa, &rmesa->hw.lit[p] ); + } + } + } +} + + +void radeonLightfv( GLcontext *ctx, GLenum light, + GLenum pname, const GLfloat *params ) +{ + radeonContextPtr rmesa = RADEON_CONTEXT(ctx); + GLint p = light - GL_LIGHT0; + struct gl_light *l = &ctx->Light.Light[p]; + GLfloat *fcmd = (GLfloat *)rmesa->hw.lit[p].cmd; + + + switch (pname) { + case GL_AMBIENT: + case GL_DIFFUSE: + case GL_SPECULAR: + update_light_colors( ctx, p ); + break; + + case GL_SPOT_DIRECTION: + /* picked up in update_light */ + break; + + case GL_POSITION: { + /* positions picked up in update_light, but can do flag here */ + GLuint flag = (p&1)? RADEON_LIGHT_1_IS_LOCAL : RADEON_LIGHT_0_IS_LOCAL; + GLuint idx = TCL_PER_LIGHT_CTL_0 + p/2; + + RADEON_STATECHANGE(rmesa, tcl); + if (l->EyePosition[3] != 0.0F) + rmesa->hw.tcl.cmd[idx] |= flag; + else + rmesa->hw.tcl.cmd[idx] &= ~flag; + break; + } + + case GL_SPOT_EXPONENT: + RADEON_STATECHANGE(rmesa, lit[p]); + fcmd[LIT_SPOT_EXPONENT] = params[0]; + break; + + case GL_SPOT_CUTOFF: { + GLuint flag = (p&1) ? RADEON_LIGHT_1_IS_SPOT : RADEON_LIGHT_0_IS_SPOT; + GLuint idx = TCL_PER_LIGHT_CTL_0 + p/2; + + RADEON_STATECHANGE(rmesa, lit[p]); + fcmd[LIT_SPOT_CUTOFF] = l->_CosCutoff; + + RADEON_STATECHANGE(rmesa, tcl); + if (l->SpotCutoff != 180.0F) + rmesa->hw.tcl.cmd[idx] |= flag; + else + rmesa->hw.tcl.cmd[idx] &= ~flag; + break; + } + + case GL_CONSTANT_ATTENUATION: + RADEON_STATECHANGE(rmesa, lit[p]); + fcmd[LIT_ATTEN_CONST] = params[0]; + break; + case GL_LINEAR_ATTENUATION: + RADEON_STATECHANGE(rmesa, lit[p]); + fcmd[LIT_ATTEN_LINEAR] = params[0]; + break; + case GL_QUADRATIC_ATTENUATION: + RADEON_STATECHANGE(rmesa, lit[p]); + fcmd[LIT_ATTEN_QUADRATIC] = params[0]; + break; + default: + return; + } + +} + + + + +void radeonLightModelfv( GLcontext *ctx, GLenum pname, + const GLfloat *param ) +{ + radeonContextPtr rmesa = RADEON_CONTEXT(ctx); + + switch (pname) { + case GL_LIGHT_MODEL_AMBIENT: + update_global_ambient( ctx ); + break; + + case GL_LIGHT_MODEL_LOCAL_VIEWER: + RADEON_STATECHANGE( rmesa, tcl ); + if (ctx->Light.Model.LocalViewer) + rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] |= RADEON_LOCAL_VIEWER; + else + rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] &= ~RADEON_LOCAL_VIEWER; + break; + + case GL_LIGHT_MODEL_TWO_SIDE: + RADEON_STATECHANGE( rmesa, tcl ); + if (ctx->Light.Model.TwoSide) + rmesa->hw.tcl.cmd[TCL_UCP_VERT_BLEND_CTL] |= RADEON_LIGHT_TWOSIDE; + else + rmesa->hw.tcl.cmd[TCL_UCP_VERT_BLEND_CTL] &= ~RADEON_LIGHT_TWOSIDE; + + check_twoside_fallback( ctx ); + +#if _HAVE_SWTNL + if (rmesa->TclFallback) { + radeonChooseRenderState( ctx ); + radeonChooseVertexState( ctx ); + } +#endif + break; + + case GL_LIGHT_MODEL_COLOR_CONTROL: + radeonUpdateSpecular(ctx); + + RADEON_STATECHANGE( rmesa, tcl ); + if (ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR) + rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] &= + ~RADEON_DIFFUSE_SPECULAR_COMBINE; + else + rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] |= + RADEON_DIFFUSE_SPECULAR_COMBINE; + break; + + default: + break; + } +} + + +/* ============================================================= + * Fog + */ + + +static void radeonFogfv( GLcontext *ctx, GLenum pname, const GLfloat *param ) +{ + radeonContextPtr rmesa = RADEON_CONTEXT(ctx); + union { int i; float f; } c, d; + GLchan col[4]; + + c.i = rmesa->hw.fog.cmd[FOG_C]; + d.i = rmesa->hw.fog.cmd[FOG_D]; + + switch (pname) { + case GL_FOG_MODE: + if (!ctx->Fog.Enabled) + return; + RADEON_STATECHANGE(rmesa, tcl); + rmesa->hw.tcl.cmd[TCL_UCP_VERT_BLEND_CTL] &= ~RADEON_TCL_FOG_MASK; + switch (ctx->Fog.Mode) { + case GL_LINEAR: + rmesa->hw.tcl.cmd[TCL_UCP_VERT_BLEND_CTL] |= RADEON_TCL_FOG_LINEAR; + if (ctx->Fog.Start == ctx->Fog.End) { + c.f = 1.0F; + d.f = 1.0F; + } + else { + c.f = ctx->Fog.End/(ctx->Fog.End-ctx->Fog.Start); + d.f = 1.0/(ctx->Fog.End-ctx->Fog.Start); + } + break; + case GL_EXP: + rmesa->hw.tcl.cmd[TCL_UCP_VERT_BLEND_CTL] |= RADEON_TCL_FOG_EXP; + c.f = 0.0; + d.f = ctx->Fog.Density; + break; + case GL_EXP2: + rmesa->hw.tcl.cmd[TCL_UCP_VERT_BLEND_CTL] |= RADEON_TCL_FOG_EXP2; + c.f = 0.0; + d.f = -(ctx->Fog.Density * ctx->Fog.Density); + break; + default: + return; + } + break; + case GL_FOG_DENSITY: + switch (ctx->Fog.Mode) { + case GL_EXP: + c.f = 0.0; + d.f = ctx->Fog.Density; + break; + case GL_EXP2: + c.f = 0.0; + d.f = -(ctx->Fog.Density * ctx->Fog.Density); + break; + default: + break; + } + break; + case GL_FOG_START: + case GL_FOG_END: + if (ctx->Fog.Mode == GL_LINEAR) { + if (ctx->Fog.Start == ctx->Fog.End) { + c.f = 1.0F; + d.f = 1.0F; + } else { + c.f = ctx->Fog.End/(ctx->Fog.End-ctx->Fog.Start); + d.f = 1.0/(ctx->Fog.End-ctx->Fog.Start); + } + } + break; + case GL_FOG_COLOR: + RADEON_STATECHANGE( rmesa, ctx ); + UNCLAMPED_FLOAT_TO_RGB_CHAN( col, ctx->Fog.Color ); + rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] = + radeonPackColor( 4, col[0], col[1], col[2], 0 ); + break; + case GL_FOG_COORDINATE_SOURCE_EXT: + /* What to do? + */ + break; + default: + return; + } + + if (c.i != rmesa->hw.fog.cmd[FOG_C] || d.i != rmesa->hw.fog.cmd[FOG_D]) { + RADEON_STATECHANGE( rmesa, fog ); + rmesa->hw.fog.cmd[FOG_C] = c.i; + rmesa->hw.fog.cmd[FOG_D] = d.i; + } +} + +/* Examine lighting and texture state to determine if separate specular + * should be enabled. + */ +void radeonUpdateSpecular( GLcontext *ctx ) +{ + radeonContextPtr rmesa = RADEON_CONTEXT(ctx); + GLuint p = rmesa->hw.ctx.cmd[CTX_PP_CNTL]; + + if (NEED_SECONDARY_COLOR(ctx)) { + p |= RADEON_SPECULAR_ENABLE; + } else { + p &= ~RADEON_SPECULAR_ENABLE; + } + + if ( rmesa->hw.ctx.cmd[CTX_PP_CNTL] != p ) { + RADEON_STATECHANGE( rmesa, ctx ); + rmesa->hw.ctx.cmd[CTX_PP_CNTL] = p; + } + + /* Bizzare: have to leave lighting enabled to get fog. + */ + RADEON_STATECHANGE( rmesa, tcl ); + if ((ctx->Light.Enabled && + ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)) { + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXSEL] |= RADEON_TCL_COMPUTE_SPECULAR; + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXSEL] |= RADEON_TCL_COMPUTE_DIFFUSE; + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT] |= RADEON_TCL_VTX_PK_SPEC; + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT] |= RADEON_TCL_VTX_PK_DIFFUSE; + rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] |= RADEON_LIGHTING_ENABLE; + } + else if (ctx->Fog.Enabled) { + if (ctx->Light.Enabled) { + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXSEL] |= RADEON_TCL_COMPUTE_SPECULAR; + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXSEL] |= RADEON_TCL_COMPUTE_DIFFUSE; + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT] |= RADEON_TCL_VTX_PK_SPEC; + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT] |= RADEON_TCL_VTX_PK_DIFFUSE; + rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] |= RADEON_LIGHTING_ENABLE; + } else { + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXSEL] |= RADEON_TCL_COMPUTE_SPECULAR; + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXSEL] &= ~RADEON_TCL_COMPUTE_DIFFUSE; + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT] |= RADEON_TCL_VTX_PK_SPEC; + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT] |= RADEON_TCL_VTX_PK_DIFFUSE; + rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] |= RADEON_LIGHTING_ENABLE; + } + } + else if (ctx->Light.Enabled) { + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXSEL] &= ~RADEON_TCL_COMPUTE_SPECULAR; + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXSEL] |= RADEON_TCL_COMPUTE_DIFFUSE; + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT] &= ~RADEON_TCL_VTX_PK_SPEC; + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT] |= RADEON_TCL_VTX_PK_DIFFUSE; + rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] |= RADEON_LIGHTING_ENABLE; + } else if (ctx->Fog.ColorSumEnabled ) { + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXSEL] &= ~RADEON_TCL_COMPUTE_SPECULAR; + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXSEL] &= ~RADEON_TCL_COMPUTE_DIFFUSE; + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT] |= RADEON_TCL_VTX_PK_SPEC; + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT] |= RADEON_TCL_VTX_PK_DIFFUSE; + rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] &= ~RADEON_LIGHTING_ENABLE; + } else { + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXSEL] &= ~RADEON_TCL_COMPUTE_SPECULAR; + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXSEL] &= ~RADEON_TCL_COMPUTE_DIFFUSE; + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT] &= ~RADEON_TCL_VTX_PK_SPEC; + rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT] |= RADEON_TCL_VTX_PK_DIFFUSE; + rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] &= ~RADEON_LIGHTING_ENABLE; + } + +#if _HAVE_SWTNL + /* Update vertex/render formats + */ + if (rmesa->TclFallback) { + radeonChooseRenderState( ctx ); + radeonChooseVertexState( ctx ); + } +#endif +} + + + +static void radeonLightingSpaceChange( GLcontext *ctx ) +{ + radeonContextPtr rmesa = RADEON_CONTEXT(ctx); + GLboolean tmp; + RADEON_STATECHANGE( rmesa, tcl ); + + if (RADEON_DEBUG & RADEON_STATE) + fprintf(stderr, "%s %d\n", __FUNCTION__, ctx->_NeedEyeCoords); + + if (ctx->_NeedEyeCoords) + tmp = ctx->Transform.RescaleNormals; + else + tmp = !ctx->Transform.RescaleNormals; + + if ( tmp ) { + rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] |= RADEON_RESCALE_NORMALS; + } else { + rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] &= ~RADEON_RESCALE_NORMALS; + } +} + +void radeonInitLightStateFuncs( GLcontext *ctx ) +{ + radeonContextPtr rmesa = RADEON_CONTEXT(ctx); + int i; + + ctx->Driver.LightModelfv = radeonLightModelfv; + ctx->Driver.Lightfv = radeonLightfv; + ctx->Driver.Fogfv = radeonFogfv; + ctx->Driver.LightingSpaceChange = radeonLightingSpaceChange; + + for (i = 0 ; i < 8; i++) { + struct gl_light *l = &ctx->Light.Light[i]; + GLenum p = GL_LIGHT0 + i; + *(float *)&(rmesa->hw.lit[i].cmd[LIT_RANGE_CUTOFF]) = FLT_MAX; + + ctx->Driver.Lightfv( ctx, p, GL_AMBIENT, l->Ambient ); + ctx->Driver.Lightfv( ctx, p, GL_DIFFUSE, l->Diffuse ); + ctx->Driver.Lightfv( ctx, p, GL_SPECULAR, l->Specular ); + ctx->Driver.Lightfv( ctx, p, GL_POSITION, 0 ); + ctx->Driver.Lightfv( ctx, p, GL_SPOT_DIRECTION, 0 ); + ctx->Driver.Lightfv( ctx, p, GL_SPOT_EXPONENT, &l->SpotExponent ); + ctx->Driver.Lightfv( ctx, p, GL_SPOT_CUTOFF, &l->SpotCutoff ); + ctx->Driver.Lightfv( ctx, p, GL_CONSTANT_ATTENUATION, + &l->ConstantAttenuation ); + ctx->Driver.Lightfv( ctx, p, GL_LINEAR_ATTENUATION, + &l->LinearAttenuation ); + ctx->Driver.Lightfv( ctx, p, GL_QUADRATIC_ATTENUATION, + &l->QuadraticAttenuation ); + } + + ctx->Driver.LightModelfv( ctx, GL_LIGHT_MODEL_AMBIENT, + ctx->Light.Model.Ambient ); + + ctx->Driver.Fogfv( ctx, GL_FOG_MODE, 0 ); + ctx->Driver.Fogfv( ctx, GL_FOG_DENSITY, &ctx->Fog.Density ); + ctx->Driver.Fogfv( ctx, GL_FOG_START, &ctx->Fog.Start ); + ctx->Driver.Fogfv( ctx, GL_FOG_END, &ctx->Fog.End ); + ctx->Driver.Fogfv( ctx, GL_FOG_COLOR, ctx->Fog.Color ); + ctx->Driver.Fogfv( ctx, GL_FOG_COORDINATE_SOURCE_EXT, 0 ); +} diff --git a/src/mesa/drivers/windows/gldirect/dx7/gld_driver_dx7.c b/src/mesa/drivers/windows/gldirect/dx7/gld_driver_dx7.c deleted file mode 100644 index d5fa642800..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx7/gld_driver_dx7.c +++ /dev/null @@ -1,1196 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: Driver interface code to Mesa -* -****************************************************************************/ - -//#include <windows.h> -#include "dglcontext.h" -#include "ddlog.h" -#include "gld_dx7.h" - -#include "glheader.h" -#include "context.h" -#include "colormac.h" -#include "depth.h" -#include "extensions.h" -#include "macros.h" -#include "matrix.h" -// #include "mem.h" -//#include "mmath.h" -#include "mtypes.h" -#include "texformat.h" -#include "teximage.h" -#include "texstore.h" -#include "vbo/vbo.h" -#include "swrast_setup/swrast_setup.h" -#include "swrast_setup/ss_context.h" -#include "tnl/tnl.h" -#include "tnl/t_context.h" -#include "tnl/t_pipeline.h" - -extern BOOL dglSwapBuffers(HDC hDC); - -// HACK: Hack the _33 member of the OpenGL perspective projection matrix -const float _fPersp_33 = 1.6f; - -//--------------------------------------------------------------------------- -// Internal functions -//--------------------------------------------------------------------------- - -void _gld_mesa_warning( - __GLcontext *gc, - char *str) -{ - // Intercept Mesa's internal warning mechanism - gldLogPrintf(GLDLOG_WARN, "Mesa warning: %s", str); -} - -//--------------------------------------------------------------------------- - -void _gld_mesa_fatal( - __GLcontext *gc, - char *str) -{ - // Intercept Mesa's internal fatal-message mechanism - gldLogPrintf(GLDLOG_CRITICAL, "Mesa FATAL: %s", str); - - // Mesa calls abort(0) here. - ddlogClose(); - exit(0); -} - -//--------------------------------------------------------------------------- - -D3DSTENCILOP _gldConvertStencilOp( - GLenum StencilOp) -{ - // Used by Stencil: pass, fail and zfail - - switch (StencilOp) { - case GL_KEEP: - return D3DSTENCILOP_KEEP; - case GL_ZERO: - return D3DSTENCILOP_ZERO; - case GL_REPLACE: - return D3DSTENCILOP_REPLACE; - case GL_INCR: - return D3DSTENCILOP_INCRSAT; - case GL_DECR: - return D3DSTENCILOP_DECRSAT; - case GL_INVERT: - return D3DSTENCILOP_INVERT; - case GL_INCR_WRAP_EXT: // GL_EXT_stencil_wrap - return D3DSTENCILOP_INCR; - case GL_DECR_WRAP_EXT: // GL_EXT_stencil_wrap - return D3DSTENCILOP_DECR; - } - -#ifdef _DEBUG - gldLogMessage(GLDLOG_ERROR, "_gldConvertStencilOp: Unknown StencilOp\n"); -#endif - - return D3DSTENCILOP_KEEP; -} - -//--------------------------------------------------------------------------- - -D3DCMPFUNC _gldConvertCompareFunc( - GLenum CmpFunc) -{ - // Used for Alpha func, depth func and stencil func. - - switch (CmpFunc) { - case GL_NEVER: - return D3DCMP_NEVER; - case GL_LESS: - return D3DCMP_LESS; - case GL_EQUAL: - return D3DCMP_EQUAL; - case GL_LEQUAL: - return D3DCMP_LESSEQUAL; - case GL_GREATER: - return D3DCMP_GREATER; - case GL_NOTEQUAL: - return D3DCMP_NOTEQUAL; - case GL_GEQUAL: - return D3DCMP_GREATEREQUAL; - case GL_ALWAYS: - return D3DCMP_ALWAYS; - }; - -#ifdef _DEBUG - gldLogMessage(GLDLOG_ERROR, "_gldConvertCompareFunc: Unknown CompareFunc\n"); -#endif - - return D3DCMP_ALWAYS; -} - -//--------------------------------------------------------------------------- - -D3DBLEND _gldConvertBlendFunc( - GLenum blend, - GLenum DefaultBlend) -{ - switch (blend) { - case GL_ZERO: - return D3DBLEND_ZERO; - case GL_ONE: - return D3DBLEND_ONE; - case GL_DST_COLOR: - return D3DBLEND_DESTCOLOR; - case GL_SRC_COLOR: - return D3DBLEND_SRCCOLOR; - case GL_ONE_MINUS_DST_COLOR: - return D3DBLEND_INVDESTCOLOR; - case GL_ONE_MINUS_SRC_COLOR: - return D3DBLEND_INVSRCCOLOR; - case GL_SRC_ALPHA: - return D3DBLEND_SRCALPHA; - case GL_ONE_MINUS_SRC_ALPHA: - return D3DBLEND_INVSRCALPHA; - case GL_DST_ALPHA: - return D3DBLEND_DESTALPHA; - case GL_ONE_MINUS_DST_ALPHA: - return D3DBLEND_INVDESTALPHA; - case GL_SRC_ALPHA_SATURATE: - return D3DBLEND_SRCALPHASAT; - } - -#ifdef _DEBUG - gldLogMessage(GLDLOG_ERROR, "_gldConvertBlendFunc: Unknown BlendFunc\n"); -#endif - - return DefaultBlend; -} - -//--------------------------------------------------------------------------- -// Misc. functions -//--------------------------------------------------------------------------- - -void gld_Noop_DX7( - GLcontext *ctx) -{ -#ifdef _DEBUG - gldLogMessage(GLDLOG_ERROR, "gld_Noop called!\n"); -#endif -} - -//--------------------------------------------------------------------------- - -void gld_Error_DX7( - GLcontext *ctx) -{ -#ifdef _DEBUG - // Quite useless. -// gldLogMessage(GLDLOG_ERROR, "ctx->Driver.Error called!\n"); -#endif -} - -//--------------------------------------------------------------------------- -// Required Mesa functions -//--------------------------------------------------------------------------- - -static GLboolean gld_set_draw_buffer_DX7( - GLcontext *ctx, - GLenum mode) -{ - (void) ctx; - if ((mode==GL_FRONT_LEFT) || (mode == GL_BACK_LEFT)) { - return GL_TRUE; - } - else { - return GL_FALSE; - } -} - -//--------------------------------------------------------------------------- - -static void gld_set_read_buffer_DX7( - GLcontext *ctx, - GLframebuffer *buffer, - GLenum mode) -{ - /* separate read buffer not supported */ -/* - ASSERT(buffer == ctx->DrawBuffer); - ASSERT(mode == GL_FRONT_LEFT); -*/ -} - -//--------------------------------------------------------------------------- - -void gld_Clear_DX7( - GLcontext *ctx, - GLbitfield mask, - GLboolean all, - GLint x, - GLint y, - GLint width, - GLint height) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - DWORD dwFlags = 0; - D3DCOLOR Color = 0; - float Z = 0.0f; - DWORD Stencil = 0; - D3DRECT d3dClearRect; - - // TODO: Colourmask - const GLuint *colorMask = (GLuint *) &ctx->Color.ColorMask; - - if (!gld->pDev) - return; - - if (mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT)) { - GLubyte col[4]; - CLAMPED_FLOAT_TO_UBYTE(col[0], ctx->Color.ClearColor[0]); - CLAMPED_FLOAT_TO_UBYTE(col[1], ctx->Color.ClearColor[1]); - CLAMPED_FLOAT_TO_UBYTE(col[2], ctx->Color.ClearColor[2]); - CLAMPED_FLOAT_TO_UBYTE(col[3], ctx->Color.ClearColor[3]); - dwFlags |= D3DCLEAR_TARGET; - Color = D3DCOLOR_RGBA(col[0], col[1], col[2], col[3]); -// ctx->Color.ClearColor[1], -// ctx->Color.ClearColor[2], -// ctx->Color.ClearColor[3]); - } - - if (mask & DD_DEPTH_BIT) { - // D3D7 will fail the Clear call if we try and clear a - // depth buffer and we haven't created one. - // Also, some apps try and clear a depth buffer, - // when a depth buffer hasn't been requested by the app. - if (ctx->Visual.depthBits == 0) { - mask &= ~DD_DEPTH_BIT; // Remove depth bit from mask - } else { - dwFlags |= D3DCLEAR_ZBUFFER; - Z = ctx->Depth.Clear; - } - } - - if (mask & DD_STENCIL_BIT) { - if (ctx->Visual.stencilBits == 0) { - // No stencil bits in depth buffer - mask &= ~DD_STENCIL_BIT; // Remove stencil bit from mask - } else { - dwFlags |= D3DCLEAR_STENCIL; - Stencil = ctx->Stencil.Clear; - } - } - - // Some apps do really weird things with the rect, such as Quake3. - if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0)) { - all = GL_TRUE; - } - - if (!all) { - // Calculate clear subrect - d3dClearRect.x1 = x; - d3dClearRect.y1 = gldCtx->dwHeight - (y + height); - d3dClearRect.x2 = x + width; - d3dClearRect.y2 = d3dClearRect.y1 + height; - } - - // dwFlags will be zero if there's nothing to clear - if (dwFlags) { - _GLD_DX7_DEV(Clear( - gld->pDev, - all ? 0 : 1, - all ? NULL : &d3dClearRect, - dwFlags, - Color, Z, Stencil)); - } - - if (mask & DD_ACCUM_BIT) { - // Clear accumulation buffer - } -} - -//--------------------------------------------------------------------------- - -// Mesa 5: Parameter change -static void gld_buffer_size_DX7( -// GLcontext *ctx, - GLframebuffer *fb, - GLuint *width, - GLuint *height) -{ -// GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - - *width = fb->Width; // gldCtx->dwWidth; - *height = fb->Height; // gldCtx->dwHeight; -} - -//--------------------------------------------------------------------------- - -static void gld_Finish_DX7( - GLcontext *ctx) -{ -} - -//--------------------------------------------------------------------------- - -static void gld_Flush_DX7( - GLcontext *ctx) -{ - GLD_context *gld = GLD_GET_CONTEXT(ctx); - - // TODO: Detect apps that glFlush() then SwapBuffers() ? - - if (gld->EmulateSingle) { - // Emulating a single-buffered context. - // [Direct3D doesn't allow rendering to front buffer] - dglSwapBuffers(gld->hDC); - } -} - -//--------------------------------------------------------------------------- - -void gld_NEW_STENCIL( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - // Two-sided stencil. New for Mesa 5 - const GLuint uiFace = 0UL; - - struct gl_stencil_attrib *pStencil = &ctx->Stencil; - - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILENABLE, pStencil->Enabled ? TRUE : FALSE)); - if (pStencil->Enabled) { - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILFUNC, _gldConvertCompareFunc(pStencil->Function[uiFace]))); - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILREF, pStencil->Ref[uiFace])); - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILMASK, pStencil->ValueMask[uiFace])); - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILWRITEMASK, pStencil->WriteMask[uiFace])); - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILFAIL, _gldConvertStencilOp(pStencil->FailFunc[uiFace]))); - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILZFAIL, _gldConvertStencilOp(pStencil->ZFailFunc[uiFace]))); - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILPASS, _gldConvertStencilOp(pStencil->ZPassFunc[uiFace]))); - } -} - -//--------------------------------------------------------------------------- - -void gld_NEW_COLOR( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - DWORD dwFlags = 0; - D3DBLEND src; - D3DBLEND dest; - - // Alpha func - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ALPHAFUNC, _gldConvertCompareFunc(ctx->Color.AlphaFunc))); - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ALPHAREF, (DWORD)ctx->Color.AlphaRef)); - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ALPHATESTENABLE, ctx->Color.AlphaEnabled)); - - // Blend func - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ALPHABLENDENABLE, ctx->Color.BlendEnabled)); - src = _gldConvertBlendFunc(ctx->Color.BlendSrcRGB, GL_ONE); - dest = _gldConvertBlendFunc(ctx->Color.BlendDstRGB, GL_ZERO); - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_SRCBLEND, src)); - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_DESTBLEND, dest)); - -/* - // Color mask - unsupported by DX7 - if (ctx->Color.ColorMask[0]) dwFlags |= D3DCOLORWRITEENABLE_RED; - if (ctx->Color.ColorMask[1]) dwFlags |= D3DCOLORWRITEENABLE_GREEN; - if (ctx->Color.ColorMask[2]) dwFlags |= D3DCOLORWRITEENABLE_BLUE; - if (ctx->Color.ColorMask[3]) dwFlags |= D3DCOLORWRITEENABLE_ALPHA; - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_COLORWRITEENABLE, dwFlags)); -*/ -} - -//--------------------------------------------------------------------------- - -void gld_NEW_DEPTH( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ZENABLE, ctx->Depth.Test ? D3DZB_TRUE : D3DZB_FALSE)); - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ZFUNC, _gldConvertCompareFunc(ctx->Depth.Func))); - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ZWRITEENABLE, ctx->Depth.Mask ? TRUE : FALSE)); -} - -//--------------------------------------------------------------------------- - -void gld_NEW_POLYGON( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - D3DFILLMODE d3dFillMode = D3DFILL_SOLID; - D3DCULL d3dCullMode = D3DCULL_NONE; - int iOffset = 0; - - // Fillmode - switch (ctx->Polygon.FrontMode) { - case GL_POINT: - d3dFillMode = D3DFILL_POINT; - break; - case GL_LINE: - d3dFillMode = D3DFILL_WIREFRAME; - break; - case GL_FILL: - d3dFillMode = D3DFILL_SOLID; - break; - } - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FILLMODE, d3dFillMode)); - - if (ctx->Polygon.CullFlag) { - switch (ctx->Polygon.CullFaceMode) { - case GL_BACK: - if (ctx->Polygon.FrontFace == GL_CCW) - d3dCullMode = D3DCULL_CW; - else - d3dCullMode = D3DCULL_CCW; - break; - case GL_FRONT: - if (ctx->Polygon.FrontFace == GL_CCW) - d3dCullMode = D3DCULL_CCW; - else - d3dCullMode = D3DCULL_CW; - break; - case GL_FRONT_AND_BACK: - d3dCullMode = D3DCULL_NONE; - break; - default: - break; - } - } else { - d3dCullMode = D3DCULL_NONE; - } -// d3dCullMode = D3DCULL_NONE; // TODO: DEBUGGING - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_CULLMODE, d3dCullMode)); - - // Polygon offset - // ZBIAS ranges from 0 to 16 and can only move towards the viewer - // Mesa5: ctx->Polygon._OffsetAny removed - if (ctx->Polygon.OffsetFill) { - iOffset = (int)ctx->Polygon.OffsetUnits; - if (iOffset < 0) - iOffset = -iOffset; - else - iOffset = 0; // D3D can't push away - } - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ZBIAS, iOffset)); -} - -//--------------------------------------------------------------------------- - -void gld_NEW_FOG( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - D3DCOLOR d3dFogColour; - D3DFOGMODE d3dFogMode = D3DFOG_LINEAR; - - // TODO: Fog is calculated seperately in the Mesa pipeline - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGENABLE, FALSE)); - return; - - // Fog enable - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGENABLE, ctx->Fog.Enabled)); - if (!ctx->Fog.Enabled) { - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGTABLEMODE, D3DFOG_NONE)); - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGVERTEXMODE, D3DFOG_NONE)); - return; // If disabled, don't bother setting any fog state - } - - // Fog colour - d3dFogColour = D3DCOLOR_COLORVALUE( ctx->Fog.Color[0], - ctx->Fog.Color[1], - ctx->Fog.Color[2], - ctx->Fog.Color[3]); - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGCOLOR, d3dFogColour)); - - // Fog density - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGDENSITY, *((DWORD*) (&ctx->Fog.Density)))); - - // Fog start - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGSTART, *((DWORD*) (&ctx->Fog.Start)))); - - // Fog end - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGEND, *((DWORD*) (&ctx->Fog.End)))); - - // Fog mode - switch (ctx->Fog.Mode) { - case GL_LINEAR: - d3dFogMode = D3DFOG_LINEAR; - break; - case GL_EXP: - d3dFogMode = D3DFOG_EXP; - break; - case GL_EXP2: - d3dFogMode = D3DFOG_EXP2; - break; - } - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGTABLEMODE, d3dFogMode)); - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGVERTEXMODE, D3DFOG_NONE)); -} - -//--------------------------------------------------------------------------- - -void gld_NEW_LIGHT( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - DWORD dwSpecularEnable; - - // Shademode - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_SHADEMODE, (ctx->Light.ShadeModel == GL_SMOOTH) ? D3DSHADE_GOURAUD : D3DSHADE_FLAT)); - - // Separate specular colour - if (ctx->Light.Enabled) - dwSpecularEnable = (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) ? TRUE: FALSE; - else - dwSpecularEnable = FALSE; - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_SPECULARENABLE, dwSpecularEnable)); -} - -//--------------------------------------------------------------------------- - -void gld_NEW_MODELVIEW( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - D3DMATRIX m; - //GLfloat *pM = ctx->ModelView.m; - // Mesa5: Model-view is now a stack - GLfloat *pM = ctx->ModelviewMatrixStack.Top->m; - m._11 = pM[0]; - m._12 = pM[1]; - m._13 = pM[2]; - m._14 = pM[3]; - m._21 = pM[4]; - m._22 = pM[5]; - m._23 = pM[6]; - m._24 = pM[7]; - m._31 = pM[8]; - m._32 = pM[9]; - m._33 = pM[10]; - m._34 = pM[11]; - m._41 = pM[12]; - m._42 = pM[13]; - m._43 = pM[14]; - m._44 = pM[15]; -/* m[0][0] = pM[0]; - m[0][1] = pM[1]; - m[0][2] = pM[2]; - m[0][3] = pM[3]; - m[1][0] = pM[4]; - m[1][1] = pM[5]; - m[1][2] = pM[6]; - m[1][3] = pM[7]; - m[2][0] = pM[8]; - m[2][1] = pM[9]; - m[2][2] = pM[10]; - m[2][3] = pM[11]; - m[3][0] = pM[12]; - m[3][1] = pM[13]; - m[3][2] = pM[14]; - m[3][3] = pM[15];*/ - - gld->matModelView = m; -} - -//--------------------------------------------------------------------------- - -void gld_NEW_PROJECTION( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - D3DMATRIX m; - //GLfloat *pM = ctx->ProjectionMatrix.m; - // Mesa 5: Now a stack - GLfloat *pM = ctx->ProjectionMatrixStack.Top->m; - m._11 = pM[0]; - m._12 = pM[1]; - m._13 = pM[2]; - m._14 = pM[3]; - - m._21 = pM[4]; - m._22 = pM[5]; - m._23 = pM[6]; - m._24 = pM[7]; - - m._31 = pM[8]; - m._32 = pM[9]; - m._33 = pM[10] / _fPersp_33; // / 1.6f; - m._34 = pM[11]; - - m._41 = pM[12]; - m._42 = pM[13]; - m._43 = pM[14] / 2.0f; - m._44 = pM[15]; - - gld->matProjection = m; -} - -//--------------------------------------------------------------------------- -/* -void gldFrustumHook_DX7( - GLdouble left, - GLdouble right, - GLdouble bottom, - GLdouble top, - GLdouble nearval, - GLdouble farval) -{ - GET_CURRENT_CONTEXT(ctx); - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - // Pass values on to Mesa first (in case we mess with them) - _mesa_Frustum(left, right, bottom, top, nearval, farval); - - _fPersp_33 = farval / (nearval - farval); - -// ddlogPrintf(GLDLOG_SYSTEM, "Frustum: %f", farval/nearval); -} - -//--------------------------------------------------------------------------- - -void gldOrthoHook_DX7( - GLdouble left, - GLdouble right, - GLdouble bottom, - GLdouble top, - GLdouble nearval, - GLdouble farval) -{ - GET_CURRENT_CONTEXT(ctx); - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - // Pass values on to Mesa first (in case we mess with them) - _mesa_Ortho(left, right, bottom, top, nearval, farval); - - _fPersp_33 = 1.6f; - -// ddlogPrintf(GLDLOG_SYSTEM, "Ortho: %f", farval/nearval); -} -*/ -//--------------------------------------------------------------------------- - -void gld_NEW_VIEWPORT( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - D3DVIEWPORT7 d3dvp; -// GLint x, y; -// GLsizei w, h; - - // Set depth range - _GLD_DX7_DEV(GetViewport(gld->pDev, &d3dvp)); - // D3D can't do Quake1/Quake2 z-trick - if (ctx->Viewport.Near <= ctx->Viewport.Far) { - d3dvp.dvMinZ = ctx->Viewport.Near; - d3dvp.dvMaxZ = ctx->Viewport.Far; - } else { - d3dvp.dvMinZ = ctx->Viewport.Far; - d3dvp.dvMaxZ = ctx->Viewport.Near; - } -/* x = ctx->Viewport.X; - y = ctx->Viewport.Y; - w = ctx->Viewport.Width; - h = ctx->Viewport.Height; - if (x < 0) x = 0; - if (y < 0) y = 0; - if (w > gldCtx->dwWidth) w = gldCtx->dwWidth; - if (h > gldCtx->dwHeight) h = gldCtx->dwHeight; - // Ditto for D3D viewport dimensions - if (w+x > gldCtx->dwWidth) w = gldCtx->dwWidth-x; - if (h+y > gldCtx->dwHeight) h = gldCtx->dwHeight-y; - d3dvp.X = x; - d3dvp.Y = gldCtx->dwHeight - (y + h); - d3dvp.Width = w; - d3dvp.Height = h;*/ - _GLD_DX7_DEV(SetViewport(gld->pDev, &d3dvp)); - -// gld->fFlipWindowY = (float)gldCtx->dwHeight; -} - -//--------------------------------------------------------------------------- - -__inline BOOL _gldAnyEvalEnabled( - GLcontext *ctx) -{ - struct gl_eval_attrib *eval = &ctx->Eval; - - if ((eval->AutoNormal) || - (eval->Map1Color4) || - (eval->Map1Index) || - (eval->Map1Normal) || - (eval->Map1TextureCoord1) || - (eval->Map1TextureCoord2) || - (eval->Map1TextureCoord3) || - (eval->Map1TextureCoord4) || - (eval->Map1Vertex3) || - (eval->Map1Vertex4) || - (eval->Map2Color4) || - (eval->Map2Index) || - (eval->Map2Normal) || - (eval->Map2TextureCoord1) || - (eval->Map2TextureCoord2) || - (eval->Map2TextureCoord3) || - (eval->Map2TextureCoord4) || - (eval->Map2Vertex3) || - (eval->Map2Vertex4) - ) - return TRUE; - - return FALSE; -} - -//--------------------------------------------------------------------------- - -BOOL _gldChooseInternalPipeline( - GLcontext *ctx, - GLD_driver_dx7 *gld) -{ -// return TRUE; // DEBUGGING: ALWAYS USE MESA -// return FALSE; // DEBUGGING: ALWAYS USE D3D - - if ((glb.dwTnL == GLDS_TNL_MESA) || (gld->bHasHWTnL == FALSE)) - { - gld->PipelineUsage.qwMesa.QuadPart++; - return TRUE; // Force Mesa TnL - } - - if ((ctx->Light.Enabled) || - (1) || - (ctx->Texture._TexGenEnabled) || - (ctx->Texture._TexMatEnabled) || -// (ctx->Transform._AnyClip) || - (ctx->Scissor.Enabled) || - _gldAnyEvalEnabled(ctx) // Put this last so we can early-out - ) - { - gld->PipelineUsage.qwMesa.QuadPart++; - return TRUE; - } - - gld->PipelineUsage.qwD3DFVF.QuadPart++; - return FALSE; - -/* // Force Mesa pipeline? - if (glb.dwTnL == GLDS_TNL_MESA) { - gld->PipelineUsage.dwMesa.QuadPart++; - return GLD_PIPELINE_MESA; - } - - // Test for functionality not exposed in the D3D pathways - if ((ctx->Texture._GenFlags)) { - gld->PipelineUsage.dwMesa.QuadPart++; - return GLD_PIPELINE_MESA; - } - - // Now decide if vertex shader can be used. - // If two sided lighting is enabled then we must either - // use Mesa TnL or the vertex shader - if (ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) { - if (gld->VStwosidelight.hShader && !ctx->Fog.Enabled) { - // Use Vertex Shader - gld->PipelineUsage.dwD3D2SVS.QuadPart++; - return GLD_PIPELINE_D3D_VS_TWOSIDE; - } else { - // Use Mesa TnL - gld->PipelineUsage.dwMesa.QuadPart++; - return GLD_PIPELINE_MESA; - } - } - - // Must be D3D fixed-function pipeline - gld->PipelineUsage.dwD3DFVF.QuadPart++; - return GLD_PIPELINE_D3D_FVF; -*/ -} - -//--------------------------------------------------------------------------- - -void gld_update_state_DX7( - GLcontext *ctx, - GLuint new_state) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - TNLcontext *tnl = TNL_CONTEXT(ctx); - GLD_pb_dx7 *gldPB; - - if (!gld || !gld->pDev) - return; - - _swsetup_InvalidateState( ctx, new_state ); - _vbo_InvalidateState( ctx, new_state ); - _tnl_InvalidateState( ctx, new_state ); - - // SetupIndex will be used in the pipelines for choosing setup function - if ((ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE | DD_SEPARATE_SPECULAR)) || - (ctx->Fog.Enabled)) - { - if (ctx->_TriangleCaps & DD_FLATSHADE) - gld->iSetupFunc = GLD_SI_FLAT_EXTRAS; - else - gld->iSetupFunc = GLD_SI_SMOOTH_EXTRAS; - } else { - if (ctx->_TriangleCaps & DD_FLATSHADE) - gld->iSetupFunc = GLD_SI_FLAT; // Setup flat shade + texture - else - gld->iSetupFunc = GLD_SI_SMOOTH; // Setup smooth shade + texture - } - - gld->bUseMesaTnL = _gldChooseInternalPipeline(ctx, gld); - if (gld->bUseMesaTnL) { - gldPB = &gld->PB2d; - // DX7 Does not implement D3DRS_SOFTWAREVERTEXPROCESSING -// _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_SOFTWAREVERTEXPROCESSING, TRUE)); - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_CLIPPING, FALSE)); -// _GLD_DX7_DEV(SetVertexShader(gld->pDev, gldPB->dwFVF)); - } else { - gldPB = &gld->PB3d; - _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_CLIPPING, TRUE)); -// if (gld->TnLPipeline == GLD_PIPELINE_D3D_VS_TWOSIDE) { -// _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_SOFTWAREVERTEXPROCESSING, !gld->VStwosidelight.bHardware)); -// _GLD_DX7_DEV(SetVertexShader(gld->pDev, gld->VStwosidelight.hShader)); -// } else { - // DX7 Does not implement D3DRS_SOFTWAREVERTEXPROCESSING -// _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_SOFTWAREVERTEXPROCESSING, !gld->bHasHWTnL)); -// _GLD_DX7_DEV(SetVertexShader(gld->pDev, gldPB->dwFVF)); -// } - } - -#define _GLD_TEST_STATE(a) \ - if (new_state & (a)) { \ - gld##a(ctx); \ - new_state &= ~(a); \ - } - -#define _GLD_TEST_STATE_DX7(a) \ - if (new_state & (a)) { \ - gld##a##_DX7(ctx); \ - new_state &= ~(a); \ - } - -#define _GLD_IGNORE_STATE(a) new_state &= ~(a); - -// if (!gld->bUseMesaTnL) { - // Not required if Mesa is doing the TnL. - // Problem: If gld->bUseMesaTnL is TRUE when these are signaled, - // then we'll miss updating the D3D TnL pipeline. - // Therefore, don't test for gld->bUseMesaTnL - _GLD_TEST_STATE(_NEW_MODELVIEW); - _GLD_TEST_STATE(_NEW_PROJECTION); -// } - - _GLD_TEST_STATE_DX7(_NEW_TEXTURE); // extern, so guard with _DX7 - _GLD_TEST_STATE(_NEW_COLOR); - _GLD_TEST_STATE(_NEW_DEPTH); - _GLD_TEST_STATE(_NEW_POLYGON); - _GLD_TEST_STATE(_NEW_STENCIL); - _GLD_TEST_STATE(_NEW_FOG); - _GLD_TEST_STATE(_NEW_LIGHT); - _GLD_TEST_STATE(_NEW_VIEWPORT); - - _GLD_IGNORE_STATE(_NEW_TRANSFORM); - - -// Stubs for future use. -/* _GLD_TEST_STATE(_NEW_TEXTURE_MATRIX); - _GLD_TEST_STATE(_NEW_COLOR_MATRIX); - _GLD_TEST_STATE(_NEW_ACCUM); - _GLD_TEST_STATE(_NEW_EVAL); - _GLD_TEST_STATE(_NEW_HINT); - _GLD_TEST_STATE(_NEW_LINE); - _GLD_TEST_STATE(_NEW_PIXEL); - _GLD_TEST_STATE(_NEW_POINT); - _GLD_TEST_STATE(_NEW_POLYGONSTIPPLE); - _GLD_TEST_STATE(_NEW_SCISSOR); - _GLD_TEST_STATE(_NEW_PACKUNPACK); - _GLD_TEST_STATE(_NEW_ARRAY); - _GLD_TEST_STATE(_NEW_RENDERMODE); - _GLD_TEST_STATE(_NEW_BUFFERS); - _GLD_TEST_STATE(_NEW_MULTISAMPLE); -*/ - -// For debugging. -#if 0 -#define _GLD_TEST_UNHANDLED_STATE(a) \ - if (new_state & (a)) { \ - gldLogMessage(GLDLOG_ERROR, "Unhandled " #a "\n"); \ - } - _GLD_TEST_UNHANDLED_STATE(_NEW_TEXTURE_MATRIX); - _GLD_TEST_UNHANDLED_STATE(_NEW_COLOR_MATRIX); - _GLD_TEST_UNHANDLED_STATE(_NEW_ACCUM); - _GLD_TEST_UNHANDLED_STATE(_NEW_EVAL); - _GLD_TEST_UNHANDLED_STATE(_NEW_HINT); - _GLD_TEST_UNHANDLED_STATE(_NEW_LINE); - _GLD_TEST_UNHANDLED_STATE(_NEW_PIXEL); - _GLD_TEST_UNHANDLED_STATE(_NEW_POINT); - _GLD_TEST_UNHANDLED_STATE(_NEW_POLYGONSTIPPLE); - _GLD_TEST_UNHANDLED_STATE(_NEW_SCISSOR); - _GLD_TEST_UNHANDLED_STATE(_NEW_PACKUNPACK); - _GLD_TEST_UNHANDLED_STATE(_NEW_ARRAY); - _GLD_TEST_UNHANDLED_STATE(_NEW_RENDERMODE); - _GLD_TEST_UNHANDLED_STATE(_NEW_BUFFERS); - _GLD_TEST_UNHANDLED_STATE(_NEW_MULTISAMPLE); -#undef _GLD_UNHANDLED_STATE -#endif - -#undef _GLD_TEST_STATE -} - -//--------------------------------------------------------------------------- -// Viewport -//--------------------------------------------------------------------------- - -void gld_Viewport_DX7( - GLcontext *ctx, - GLint x, - GLint y, - GLsizei w, - GLsizei h) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - D3DVIEWPORT7 d3dvp; - - if (!gld || !gld->pDev) - return; - - // This is a hack. When the app is minimized, Mesa passes - // w=1 and h=1 for viewport dimensions. Without this test - // we get a GPF in gld_wgl_resize_buffers(). - if ((w==1) && (h==1)) - return; - - // Call ResizeBuffersMESA. This function will early-out - // if no resize is needed. - //ctx->Driver.ResizeBuffersMESA(ctx); - // Mesa 5: Changed parameters - ctx->Driver.ResizeBuffers(gldCtx->glBuffer); - -#if 0 - ddlogPrintf(GLDLOG_SYSTEM, ">> Viewport x=%d y=%d w=%d h=%d", x,y,w,h); -#endif - - // ** D3D viewport must not be outside the render target surface ** - // Sanity check the GL viewport dimensions - if (x < 0) x = 0; - if (y < 0) y = 0; - if (w > gldCtx->dwWidth) w = gldCtx->dwWidth; - if (h > gldCtx->dwHeight) h = gldCtx->dwHeight; - // Ditto for D3D viewport dimensions - if (w+x > gldCtx->dwWidth) w = gldCtx->dwWidth-x; - if (h+y > gldCtx->dwHeight) h = gldCtx->dwHeight-y; - - d3dvp.dwX = x; - d3dvp.dwY = gldCtx->dwHeight - (y + h); - d3dvp.dwWidth = w; - d3dvp.dwHeight = h; - if (ctx->Viewport.Near <= ctx->Viewport.Far) { - d3dvp.dvMinZ = ctx->Viewport.Near; - d3dvp.dvMaxZ = ctx->Viewport.Far; - } else { - d3dvp.dvMinZ = ctx->Viewport.Far; - d3dvp.dvMaxZ = ctx->Viewport.Near; - } - - // TODO: DEBUGGING -// d3dvp.MinZ = 0.0f; -// d3dvp.MaxZ = 1.0f; - - _GLD_DX7_DEV(SetViewport(gld->pDev, &d3dvp)); - -} - -//--------------------------------------------------------------------------- - -extern BOOL dglWglResizeBuffers(GLcontext *ctx, BOOL bDefaultDriver); - -// Mesa 5: Parameter change -void gldResizeBuffers_DX7( -// GLcontext *ctx) - GLframebuffer *fb) -{ - GET_CURRENT_CONTEXT(ctx); - dglWglResizeBuffers(ctx, TRUE); -} - -//--------------------------------------------------------------------------- -#ifdef _DEBUG -// This is only for debugging. -// To use, plug into ctx->Driver.Enable pointer below. -void gld_Enable( - GLcontext *ctx, - GLenum e, - GLboolean b) -{ - char buf[1024]; - sprintf(buf, "Enable: %s (%s)\n", _mesa_lookup_enum_by_nr(e), b?"TRUE":"FALSE"); - ddlogMessage(DDLOG_SYSTEM, buf); -} -#endif -//--------------------------------------------------------------------------- -// Driver pointer setup -//--------------------------------------------------------------------------- - -extern const GLubyte* _gldGetStringGeneric(GLcontext*, GLenum); - -void gldSetupDriverPointers_DX7( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - TNLcontext *tnl = TNL_CONTEXT(ctx); - - // Mandatory functions - ctx->Driver.GetString = _gldGetStringGeneric; - ctx->Driver.UpdateState = gld_update_state_DX7; - ctx->Driver.Clear = gld_Clear_DX7; - ctx->Driver.DrawBuffer = gld_set_draw_buffer_DX7; - ctx->Driver.GetBufferSize = gld_buffer_size_DX7; - ctx->Driver.Finish = gld_Finish_DX7; - ctx->Driver.Flush = gld_Flush_DX7; - ctx->Driver.Error = gld_Error_DX7; - - // Hardware accumulation buffer - ctx->Driver.Accum = NULL; // TODO: gld_Accum; - - // Bitmap functions - ctx->Driver.CopyPixels = gld_CopyPixels_DX7; - ctx->Driver.DrawPixels = gld_DrawPixels_DX7; - ctx->Driver.ReadPixels = gld_ReadPixels_DX7; - ctx->Driver.Bitmap = gld_Bitmap_DX7; - - // Buffer resize - ctx->Driver.ResizeBuffers = gldResizeBuffers_DX7; - - // Texture image functions - ctx->Driver.ChooseTextureFormat = gld_ChooseTextureFormat_DX7; - ctx->Driver.TexImage1D = gld_TexImage1D_DX7; - ctx->Driver.TexImage2D = gld_TexImage2D_DX7; - ctx->Driver.TexImage3D = _mesa_store_teximage3d; - ctx->Driver.TexSubImage1D = gld_TexSubImage1D_DX7; - ctx->Driver.TexSubImage2D = gld_TexSubImage2D_DX7; - ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; - - ctx->Driver.CopyTexImage1D = gldCopyTexImage1D_DX7; //NULL; - ctx->Driver.CopyTexImage2D = gldCopyTexImage2D_DX7; //NULL; - ctx->Driver.CopyTexSubImage1D = gldCopyTexSubImage1D_DX7; //NULL; - ctx->Driver.CopyTexSubImage2D = gldCopyTexSubImage2D_DX7; //NULL; - ctx->Driver.CopyTexSubImage3D = gldCopyTexSubImage3D_DX7; - ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; - - // Texture object functions - ctx->Driver.BindTexture = NULL; - ctx->Driver.NewTextureObject = NULL; // Not yet implemented by Mesa!; - ctx->Driver.DeleteTexture = gld_DeleteTexture_DX7; - ctx->Driver.PrioritizeTexture = NULL; - - // Imaging functionality - ctx->Driver.CopyColorTable = NULL; - ctx->Driver.CopyColorSubTable = NULL; - ctx->Driver.CopyConvolutionFilter1D = NULL; - ctx->Driver.CopyConvolutionFilter2D = NULL; - - // State changing functions - ctx->Driver.AlphaFunc = NULL; //gld_AlphaFunc; - ctx->Driver.BlendFuncSeparate = NULL; //gld_BlendFunc; - ctx->Driver.ClearColor = NULL; //gld_ClearColor; - ctx->Driver.ClearDepth = NULL; //gld_ClearDepth; - ctx->Driver.ClearStencil = NULL; //gld_ClearStencil; - ctx->Driver.ColorMask = NULL; //gld_ColorMask; - ctx->Driver.CullFace = NULL; //gld_CullFace; - ctx->Driver.ClipPlane = NULL; //gld_ClipPlane; - ctx->Driver.FrontFace = NULL; //gld_FrontFace; - ctx->Driver.DepthFunc = NULL; //gld_DepthFunc; - ctx->Driver.DepthMask = NULL; //gld_DepthMask; - ctx->Driver.DepthRange = NULL; - ctx->Driver.Enable = NULL; //gld_Enable; - ctx->Driver.Fogfv = NULL; //gld_Fogfv; - ctx->Driver.Hint = NULL; //gld_Hint; - ctx->Driver.Lightfv = NULL; //gld_Lightfv; - ctx->Driver.LightModelfv = NULL; //gld_LightModelfv; - ctx->Driver.LineStipple = NULL; //gld_LineStipple; - ctx->Driver.LineWidth = NULL; //gld_LineWidth; - ctx->Driver.LogicOpcode = NULL; //gld_LogicOpcode; - ctx->Driver.PointParameterfv = NULL; //gld_PointParameterfv; - ctx->Driver.PointSize = NULL; //gld_PointSize; - ctx->Driver.PolygonMode = NULL; //gld_PolygonMode; - ctx->Driver.PolygonOffset = NULL; //gld_PolygonOffset; - ctx->Driver.PolygonStipple = NULL; //gld_PolygonStipple; - ctx->Driver.RenderMode = NULL; //gld_RenderMode; - ctx->Driver.Scissor = NULL; //gld_Scissor; - ctx->Driver.ShadeModel = NULL; //gld_ShadeModel; - ctx->Driver.StencilFunc = NULL; //gld_StencilFunc; - ctx->Driver.StencilMask = NULL; //gld_StencilMask; - ctx->Driver.StencilOp = NULL; //gld_StencilOp; - ctx->Driver.TexGen = NULL; //gld_TexGen; - ctx->Driver.TexEnv = NULL; - ctx->Driver.TexParameter = NULL; - ctx->Driver.TextureMatrix = NULL; //gld_TextureMatrix; - ctx->Driver.Viewport = gld_Viewport_DX7; - - _swsetup_Wakeup(ctx); - - tnl->Driver.RunPipeline = _tnl_run_pipeline; - tnl->Driver.Render.ResetLineStipple = gld_ResetLineStipple_DX7; - tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon; - tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine; - - // Hook into glFrustum() and glOrtho() -// ctx->Exec->Frustum = gldFrustumHook_DX7; -// ctx->Exec->Ortho = gldOrthoHook_DX7; - -} - -//--------------------------------------------------------------------------- diff --git a/src/mesa/drivers/windows/gldirect/dx7/gld_dx7.h b/src/mesa/drivers/windows/gldirect/dx7/gld_dx7.h deleted file mode 100644 index b5a491e41b..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx7/gld_dx7.h +++ /dev/null @@ -1,292 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: GLDirect Direct3D 7.0a header file -* -****************************************************************************/ - -#ifndef _GLD_DX7_H -#define _GLD_DX7_H - -//--------------------------------------------------------------------------- -// Windows includes -//--------------------------------------------------------------------------- - -#define DIRECTDRAW_VERSION 0x0700 -#define DIRECT3D_VERSION 0x0700 -#include <d3d.h> -#include <d3dx.h> - -// Typedef for obtaining function from d3d7.dll -//typedef IDirect3D7* (WINAPI *FNDIRECT3DCREATE7) (UINT); - - -//--------------------------------------------------------------------------- -// Defines -//--------------------------------------------------------------------------- - -#ifdef _DEBUG -// Debug build tests the return value of D3D calls -#define _GLD_TEST_HRESULT(h) \ -{ \ - HRESULT _hr = (h); \ - if (FAILED(_hr)) { \ - gldLogError(GLDLOG_ERROR, #h, _hr); \ - } \ -} -#define _GLD_DX7(func) _GLD_TEST_HRESULT(IDirect3D7_##func##) -#define _GLD_DX7_DEV(func) _GLD_TEST_HRESULT(IDirect3DDevice7_##func##) -#define _GLD_DX7_VB(func) _GLD_TEST_HRESULT(IDirect3DVertexBuffer7_##func##) -#define _GLD_DX7_TEX(func) _GLD_TEST_HRESULT(IDirectDrawSurface7_##func##) -#else -#define _GLD_DX7(func) IDirect3D7_##func -#define _GLD_DX7_DEV(func) IDirect3DDevice7_##func -#define _GLD_DX7_VB(func) IDirect3DVertexBuffer7_##func -#define _GLD_DX7_TEX(func) IDirectDrawSurface7_##func -#endif - -#define SAFE_RELEASE(p) \ -{ \ - if (p) { \ - (p)->lpVtbl->Release(p); \ - (p) = NULL; \ - } \ -} - -#define SAFE_RELEASE_VB7(p) \ -{ \ - if (p) { \ - IDirect3DVertexBuffer7_Release((p)); \ - (p) = NULL; \ - } \ -} - -#define SAFE_RELEASE_SURFACE7(p) \ -{ \ - if (p) { \ - IDirectDrawSurface7_Release((p)); \ - (p) = NULL; \ - } \ -} - -// Emulate some DX8 defines -#define D3DCOLOR_ARGB(a,r,g,b) ((D3DCOLOR)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff))) -#define D3DCOLOR_RGBA(r,g,b,a) D3DCOLOR_ARGB(a,r,g,b) -#define D3DCOLOR_COLORVALUE(r,g,b,a) D3DCOLOR_RGBA((DWORD)((r)*255.f),(DWORD)((g)*255.f),(DWORD)((b)*255.f),(DWORD)((a)*255.f)) - - -// Setup index. -enum { - GLD_SI_FLAT = 0, - GLD_SI_SMOOTH = 1, - GLD_SI_FLAT_EXTRAS = 2, - GLD_SI_SMOOTH_EXTRAS = 3, -}; - -//--------------------------------------------------------------------------- -// Vertex definitions for Fixed-Function pipeline -//--------------------------------------------------------------------------- - -// -// NOTE: If the number of texture units is altered then most of -// the texture code will need to be revised. -// - -#define GLD_MAX_TEXTURE_UNITS_DX7 2 - -// -// 2D vertex transformed by Mesa -// -#define GLD_FVF_2D_VERTEX ( D3DFVF_XYZRHW | \ - D3DFVF_DIFFUSE | \ - D3DFVF_SPECULAR | \ - D3DFVF_TEX2) -typedef struct { - FLOAT x, y; // 2D raster coords - FLOAT sz; // Screen Z (depth) - FLOAT rhw; // Reciprocal homogenous W - DWORD diffuse; // Diffuse colour - DWORD specular; // For separate-specular support - FLOAT t0_u, t0_v; // 1st set of texture coords - FLOAT t1_u, t1_v; // 2nd set of texture coords -} GLD_2D_VERTEX; - - -// -// 3D vertex transformed by Direct3D -// -#define GLD_FVF_3D_VERTEX ( D3DFVF_XYZ | \ - D3DFVF_DIFFUSE | \ - D3DFVF_TEX2) - -typedef struct { - D3DXVECTOR3 Position; // XYZ Vector in object space - D3DCOLOR Diffuse; // Diffuse colour - D3DXVECTOR2 TexUnit0; // Texture unit 0 - D3DXVECTOR2 TexUnit1; // Texture unit 1 -} GLD_3D_VERTEX; - -//--------------------------------------------------------------------------- -// Structs -//--------------------------------------------------------------------------- - -// This keeps a count of how many times we choose each individual internal -// pathway. Useful for seeing if a certain pathway was ever used by an app, and -// how much each pathway is biased. -// Zero the members at context creation and dump stats at context deletion. -typedef struct { - // Note: DWORD is probably too small - ULARGE_INTEGER qwMesa; // Mesa TnL pipeline - ULARGE_INTEGER qwD3DFVF; // Direct3D Fixed-Function pipeline -} GLD_pipeline_usage; - -// GLDirect Primitive Buffer (points, lines, triangles and quads) -typedef struct { - // Data for IDirect3D7::CreateVertexBuffer() - DWORD dwStride; // Stride of vertex - DWORD dwCreateFlags; // Create flags - DWORD dwFVF; // Direct3D Flexible Vertex Format - - IDirect3DVertexBuffer7 *pVB; // Holds points, lines, tris and quads. - - // Point list is assumed to be at start of buffer - DWORD iFirstLine; // Index of start of line list - DWORD iFirstTriangle; // Index of start of triangle list - - BYTE *pPoints; // Pointer to next free point - BYTE *pLines; // Pointer to next free line - BYTE *pTriangles; // Pointer to next free triangle - - DWORD nPoints; // Number of points ready to render - DWORD nLines; // Number of lines ready to render - DWORD nTriangles; // Number of triangles ready to render -} GLD_pb_dx7; - -// GLDirect DX7 driver data -typedef struct { - // GLDirect vars - BOOL bDoublebuffer; // Doublebuffer (otherwise single-buffered) - BOOL bDepthStencil; // Depth buffer needed (stencil optional) - D3DX_SURFACEFORMAT RenderFormat; // Format of back/front buffer - D3DX_SURFACEFORMAT DepthFormat; // Format of depth/stencil - - // Direct3D vars - DDCAPS ddCaps; - D3DDEVICEDESC7 d3dCaps; - BOOL bHasHWTnL; // Device has Hardware Transform/Light? - ID3DXContext *pD3DXContext; // Base D3DX context - IDirectDraw7 *pDD; // DirectDraw7 interface - IDirect3D7 *pD3D; // Base Direct3D7 interface - IDirect3DDevice7 *pDev; // Direct3D7 Device interface - GLD_pb_dx7 PB2d; // Vertices transformed by Mesa - GLD_pb_dx7 PB3d; // Vertices transformed by Direct3D - D3DPRIMITIVETYPE d3dpt; // Current Direct3D primitive type - D3DMATRIX matProjection; // Projection matrix for D3D TnL - D3DMATRIX matModelView; // Model/View matrix for D3D TnL - int iSetupFunc; // Which setup functions to use - BOOL bUseMesaTnL; // Whether to use Mesa or D3D for TnL - - GLD_pipeline_usage PipelineUsage; -} GLD_driver_dx7; - -#define GLD_GET_DX7_DRIVER(c) (GLD_driver_dx7*)(c)->glPriv - -//--------------------------------------------------------------------------- -// Function prototypes -//--------------------------------------------------------------------------- - -PROC gldGetProcAddress_DX7(LPCSTR a); -void gldEnableExtensions_DX7(GLcontext *ctx); -void gldInstallPipeline_DX7(GLcontext *ctx); -void gldSetupDriverPointers_DX7(GLcontext *ctx); -void gldResizeBuffers_DX7(GLframebuffer *fb); - - -// Texture functions - -void gldCopyTexImage1D_DX7(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border); -void gldCopyTexImage2D_DX7(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); -void gldCopyTexSubImage1D_DX7(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width ); -void gldCopyTexSubImage2D_DX7(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height ); -void gldCopyTexSubImage3D_DX7(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height ); - -void gld_NEW_TEXTURE_DX7(GLcontext *ctx); -void gld_DrawPixels_DX7(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, const GLvoid *pixels); -void gld_ReadPixels_DX7(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, GLvoid *dest); -void gld_CopyPixels_DX7(GLcontext *ctx, GLint srcx, GLint srcy, GLsizei width, GLsizei height, GLint dstx, GLint dsty, GLenum type); -void gld_Bitmap_DX7(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap); -const struct gl_texture_format* gld_ChooseTextureFormat_DX7(GLcontext *ctx, GLint internalFormat, GLenum srcFormat, GLenum srcType); -void gld_TexImage2D_DX7(GLcontext *ctx, GLenum target, GLint level, GLint internalFormat, GLint width, GLint height, GLint border, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *tObj, struct gl_texture_image *texImage); -void gld_TexImage1D_DX7(GLcontext *ctx, GLenum target, GLint level, GLint internalFormat, GLint width, GLint border, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage ); -void gld_TexSubImage2D_DX7( GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage ); -void gld_TexSubImage1D_DX7(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage); -void gld_DeleteTexture_DX7(GLcontext *ctx, struct gl_texture_object *tObj); -void gld_ResetLineStipple_DX7(GLcontext *ctx); - -// 2D primitive functions - -void gld_Points2D_DX7(GLcontext *ctx, GLuint first, GLuint last); - -void gld_Line2DFlat_DX7(GLcontext *ctx, GLuint v0, GLuint v1); -void gld_Line2DSmooth_DX7(GLcontext *ctx, GLuint v0, GLuint v1); - -void gld_Triangle2DFlat_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Triangle2DSmooth_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Triangle2DFlatExtras_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Triangle2DSmoothExtras_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); - -void gld_Quad2DFlat_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -void gld_Quad2DSmooth_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -void gld_Quad2DFlatExtras_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -void gld_Quad2DSmoothExtras_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); - -// 3D primitive functions - -void gld_Points3D_DX7(GLcontext *ctx, GLuint first, GLuint last); -void gld_Line3DFlat_DX7(GLcontext *ctx, GLuint v0, GLuint v1); -void gld_Triangle3DFlat_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Quad3DFlat_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -void gld_Line3DSmooth_DX7(GLcontext *ctx, GLuint v0, GLuint v1); -void gld_Triangle3DSmooth_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Quad3DSmooth_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); - -// Primitive functions for Two-sided-lighting Vertex Shader - -void gld_Points2DTwoside_DX7(GLcontext *ctx, GLuint first, GLuint last); -void gld_Line2DFlatTwoside_DX7(GLcontext *ctx, GLuint v0, GLuint v1); -void gld_Line2DSmoothTwoside_DX7(GLcontext *ctx, GLuint v0, GLuint v1); -void gld_Triangle2DFlatTwoside_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Triangle2DSmoothTwoside_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Quad2DFlatTwoside_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -void gld_Quad2DSmoothTwoside_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); - -#endif diff --git a/src/mesa/drivers/windows/gldirect/dx7/gld_dxerr7.h b/src/mesa/drivers/windows/gldirect/dx7/gld_dxerr7.h deleted file mode 100644 index df6fceb43e..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx7/gld_dxerr7.h +++ /dev/null @@ -1,77 +0,0 @@ -/*==========================================================================; - * - * - * File: dxerr8.h - * Content: DirectX Error Library Include File - * - ****************************************************************************/ - -#ifndef _GLD_DXERR7_H_ -#define _GLD_DXERR7_H_ - - -#include <d3d.h> - -// -// DXGetErrorString8 -// -// Desc: Converts an DirectX HRESULT to a string -// -// Args: HRESULT hr Can be any error code from -// DPLAY D3D8 D3DX8 DMUSIC DSOUND -// -// Return: Converted string -// -const char* __stdcall DXGetErrorString8A(HRESULT hr); -const WCHAR* __stdcall DXGetErrorString8W(HRESULT hr); - -#ifdef UNICODE - #define DXGetErrorString8 DXGetErrorString8W -#else - #define DXGetErrorString8 DXGetErrorString8A -#endif - - -// -// DXTrace -// -// Desc: Outputs a formatted error message to the debug stream -// -// Args: CHAR* strFile The current file, typically passed in using the -// __FILE__ macro. -// DWORD dwLine The current line number, typically passed in using the -// __LINE__ macro. -// HRESULT hr An HRESULT that will be traced to the debug stream. -// CHAR* strMsg A string that will be traced to the debug stream (may be NULL) -// BOOL bPopMsgBox If TRUE, then a message box will popup also containing the passed info. -// -// Return: The hr that was passed in. -// -//HRESULT __stdcall DXTraceA( char* strFile, DWORD dwLine, HRESULT hr, char* strMsg, BOOL bPopMsgBox = FALSE ); -//HRESULT __stdcall DXTraceW( char* strFile, DWORD dwLine, HRESULT hr, WCHAR* strMsg, BOOL bPopMsgBox = FALSE ); -HRESULT __stdcall DXTraceA( char* strFile, DWORD dwLine, HRESULT hr, char* strMsg, BOOL bPopMsgBox); -HRESULT __stdcall DXTraceW( char* strFile, DWORD dwLine, HRESULT hr, WCHAR* strMsg, BOOL bPopMsgBox); - -#ifdef UNICODE - #define DXTrace DXTraceW -#else - #define DXTrace DXTraceA -#endif - - -// -// Helper macros -// -#if defined(DEBUG) | defined(_DEBUG) - #define DXTRACE_MSG(str) DXTrace( __FILE__, (DWORD)__LINE__, 0, str, FALSE ) - #define DXTRACE_ERR(str,hr) DXTrace( __FILE__, (DWORD)__LINE__, hr, str, TRUE ) - #define DXTRACE_ERR_NOMSGBOX(str,hr) DXTrace( __FILE__, (DWORD)__LINE__, hr, str, FALSE ) -#else - #define DXTRACE_MSG(str) (0L) - #define DXTRACE_ERR(str,hr) (hr) - #define DXTRACE_ERR_NOMSGBOX(str,hr) (hr) -#endif - - -#endif - diff --git a/src/mesa/drivers/windows/gldirect/dx7/gld_ext_dx7.c b/src/mesa/drivers/windows/gldirect/dx7/gld_ext_dx7.c deleted file mode 100644 index ba60980bbe..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx7/gld_ext_dx7.c +++ /dev/null @@ -1,346 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: GL extensions -* -****************************************************************************/ - -//#include "../GLDirect.h" -//#include "../gld_log.h" -//#include "../gld_settings.h" - -#include <windows.h> -#define GL_GLEXT_PROTOTYPES -#include <GL/gl.h> -#include <GL/glext.h> - -//#include "ddlog.h" -//#include "gld_dx8.h" - -#include "glheader.h" -#include "context.h" -#include "colormac.h" -#include "depth.h" -#include "extensions.h" -#include "macros.h" -#include "matrix.h" -// #include "mem.h" -//#include "mmath.h" -#include "mtypes.h" -#include "texformat.h" -#include "texstore.h" -#include "vbo/vbo.h" -#include "swrast_setup/swrast_setup.h" -#include "swrast_setup/ss_context.h" -#include "tnl/tnl.h" -#include "tnl/t_context.h" -#include "tnl/t_pipeline.h" - -#include "dglcontext.h" -#include "extensions.h" - -// For some reason this is not defined in an above header... -extern void _mesa_enable_imaging_extensions(GLcontext *ctx); - -//--------------------------------------------------------------------------- -// Hack for the SGIS_multitexture extension that was removed from Mesa -// NOTE: SGIS_multitexture enums also clash with GL_SGIX_async_pixel - - // NOTE: Quake2 ran *slower* with this enabled, so I've - // disabled it for now. - // To enable, uncomment: - // _mesa_add_extension(ctx, GL_TRUE, szGL_SGIS_multitexture, 0); - -//--------------------------------------------------------------------------- - -enum { - /* Quake2 GL_SGIS_multitexture */ - GL_SELECTED_TEXTURE_SGIS = 0x835B, - GL_SELECTED_TEXTURE_COORD_SET_SGIS = 0x835C, - GL_MAX_TEXTURES_SGIS = 0x835D, - GL_TEXTURE0_SGIS = 0x835E, - GL_TEXTURE1_SGIS = 0x835F, - GL_TEXTURE2_SGIS = 0x8360, - GL_TEXTURE3_SGIS = 0x8361, - GL_TEXTURE_COORD_SET_SOURCE_SGIS = 0x8363, -}; - -//--------------------------------------------------------------------------- - -void APIENTRY gldSelectTextureSGIS( - GLenum target) -{ - GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS); - glActiveTextureARB(ARB_target); -} - -//--------------------------------------------------------------------------- - -void APIENTRY gldMTexCoord2fSGIS( - GLenum target, - GLfloat s, - GLfloat t) -{ - GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS); - glMultiTexCoord2fARB(ARB_target, s, t); -} - -//--------------------------------------------------------------------------- - -void APIENTRY gldMTexCoord2fvSGIS( - GLenum target, - const GLfloat *v) -{ - GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS); - glMultiTexCoord2fvARB(ARB_target, v); -} - -//--------------------------------------------------------------------------- -// Extensions -//--------------------------------------------------------------------------- - -typedef struct { - PROC proc; - char *name; -} GLD_extension; - -GLD_extension GLD_extList[] = { -#ifdef GL_EXT_polygon_offset - { (PROC)glPolygonOffsetEXT, "glPolygonOffsetEXT" }, -#endif - { (PROC)glBlendEquationEXT, "glBlendEquationEXT" }, - { (PROC)glBlendColorEXT, "glBlendColorExt" }, - { (PROC)glVertexPointerEXT, "glVertexPointerEXT" }, - { (PROC)glNormalPointerEXT, "glNormalPointerEXT" }, - { (PROC)glColorPointerEXT, "glColorPointerEXT" }, - { (PROC)glIndexPointerEXT, "glIndexPointerEXT" }, - { (PROC)glTexCoordPointerEXT, "glTexCoordPointer" }, - { (PROC)glEdgeFlagPointerEXT, "glEdgeFlagPointerEXT" }, - { (PROC)glGetPointervEXT, "glGetPointervEXT" }, - { (PROC)glArrayElementEXT, "glArrayElementEXT" }, - { (PROC)glDrawArraysEXT, "glDrawArrayEXT" }, - { (PROC)glAreTexturesResidentEXT, "glAreTexturesResidentEXT" }, - { (PROC)glBindTextureEXT, "glBindTextureEXT" }, - { (PROC)glDeleteTexturesEXT, "glDeleteTexturesEXT" }, - { (PROC)glGenTexturesEXT, "glGenTexturesEXT" }, - { (PROC)glIsTextureEXT, "glIsTextureEXT" }, - { (PROC)glPrioritizeTexturesEXT, "glPrioritizeTexturesEXT" }, - { (PROC)glCopyTexSubImage3DEXT, "glCopyTexSubImage3DEXT" }, - { (PROC)glTexImage3DEXT, "glTexImage3DEXT" }, - { (PROC)glTexSubImage3DEXT, "glTexSubImage3DEXT" }, - { (PROC)glPointParameterfEXT, "glPointParameterfEXT" }, - { (PROC)glPointParameterfvEXT, "glPointParameterfvEXT" }, - - { (PROC)glLockArraysEXT, "glLockArraysEXT" }, - { (PROC)glUnlockArraysEXT, "glUnlockArraysEXT" }, - { NULL, "\0" } -}; - -GLD_extension GLD_multitexList[] = { -/* - { (PROC)glMultiTexCoord1dSGIS, "glMTexCoord1dSGIS" }, - { (PROC)glMultiTexCoord1dvSGIS, "glMTexCoord1dvSGIS" }, - { (PROC)glMultiTexCoord1fSGIS, "glMTexCoord1fSGIS" }, - { (PROC)glMultiTexCoord1fvSGIS, "glMTexCoord1fvSGIS" }, - { (PROC)glMultiTexCoord1iSGIS, "glMTexCoord1iSGIS" }, - { (PROC)glMultiTexCoord1ivSGIS, "glMTexCoord1ivSGIS" }, - { (PROC)glMultiTexCoord1sSGIS, "glMTexCoord1sSGIS" }, - { (PROC)glMultiTexCoord1svSGIS, "glMTexCoord1svSGIS" }, - { (PROC)glMultiTexCoord2dSGIS, "glMTexCoord2dSGIS" }, - { (PROC)glMultiTexCoord2dvSGIS, "glMTexCoord2dvSGIS" }, - { (PROC)glMultiTexCoord2fSGIS, "glMTexCoord2fSGIS" }, - { (PROC)glMultiTexCoord2fvSGIS, "glMTexCoord2fvSGIS" }, - { (PROC)glMultiTexCoord2iSGIS, "glMTexCoord2iSGIS" }, - { (PROC)glMultiTexCoord2ivSGIS, "glMTexCoord2ivSGIS" }, - { (PROC)glMultiTexCoord2sSGIS, "glMTexCoord2sSGIS" }, - { (PROC)glMultiTexCoord2svSGIS, "glMTexCoord2svSGIS" }, - { (PROC)glMultiTexCoord3dSGIS, "glMTexCoord3dSGIS" }, - { (PROC)glMultiTexCoord3dvSGIS, "glMTexCoord3dvSGIS" }, - { (PROC)glMultiTexCoord3fSGIS, "glMTexCoord3fSGIS" }, - { (PROC)glMultiTexCoord3fvSGIS, "glMTexCoord3fvSGIS" }, - { (PROC)glMultiTexCoord3iSGIS, "glMTexCoord3iSGIS" }, - { (PROC)glMultiTexCoord3ivSGIS, "glMTexCoord3ivSGIS" }, - { (PROC)glMultiTexCoord3sSGIS, "glMTexCoord3sSGIS" }, - { (PROC)glMultiTexCoord3svSGIS, "glMTexCoord3svSGIS" }, - { (PROC)glMultiTexCoord4dSGIS, "glMTexCoord4dSGIS" }, - { (PROC)glMultiTexCoord4dvSGIS, "glMTexCoord4dvSGIS" }, - { (PROC)glMultiTexCoord4fSGIS, "glMTexCoord4fSGIS" }, - { (PROC)glMultiTexCoord4fvSGIS, "glMTexCoord4fvSGIS" }, - { (PROC)glMultiTexCoord4iSGIS, "glMTexCoord4iSGIS" }, - { (PROC)glMultiTexCoord4ivSGIS, "glMTexCoord4ivSGIS" }, - { (PROC)glMultiTexCoord4sSGIS, "glMTexCoord4sSGIS" }, - { (PROC)glMultiTexCoord4svSGIS, "glMTexCoord4svSGIS" }, - { (PROC)glMultiTexCoordPointerSGIS, "glMTexCoordPointerSGIS" }, - { (PROC)glSelectTextureSGIS, "glSelectTextureSGIS" }, - { (PROC)glSelectTextureCoordSetSGIS, "glSelectTextureCoordSetSGIS" }, -*/ - { (PROC)glActiveTextureARB, "glActiveTextureARB" }, - { (PROC)glClientActiveTextureARB, "glClientActiveTextureARB" }, - { (PROC)glMultiTexCoord1dARB, "glMultiTexCoord1dARB" }, - { (PROC)glMultiTexCoord1dvARB, "glMultiTexCoord1dvARB" }, - { (PROC)glMultiTexCoord1fARB, "glMultiTexCoord1fARB" }, - { (PROC)glMultiTexCoord1fvARB, "glMultiTexCoord1fvARB" }, - { (PROC)glMultiTexCoord1iARB, "glMultiTexCoord1iARB" }, - { (PROC)glMultiTexCoord1ivARB, "glMultiTexCoord1ivARB" }, - { (PROC)glMultiTexCoord1sARB, "glMultiTexCoord1sARB" }, - { (PROC)glMultiTexCoord1svARB, "glMultiTexCoord1svARB" }, - { (PROC)glMultiTexCoord2dARB, "glMultiTexCoord2dARB" }, - { (PROC)glMultiTexCoord2dvARB, "glMultiTexCoord2dvARB" }, - { (PROC)glMultiTexCoord2fARB, "glMultiTexCoord2fARB" }, - { (PROC)glMultiTexCoord2fvARB, "glMultiTexCoord2fvARB" }, - { (PROC)glMultiTexCoord2iARB, "glMultiTexCoord2iARB" }, - { (PROC)glMultiTexCoord2ivARB, "glMultiTexCoord2ivARB" }, - { (PROC)glMultiTexCoord2sARB, "glMultiTexCoord2sARB" }, - { (PROC)glMultiTexCoord2svARB, "glMultiTexCoord2svARB" }, - { (PROC)glMultiTexCoord3dARB, "glMultiTexCoord3dARB" }, - { (PROC)glMultiTexCoord3dvARB, "glMultiTexCoord3dvARB" }, - { (PROC)glMultiTexCoord3fARB, "glMultiTexCoord3fARB" }, - { (PROC)glMultiTexCoord3fvARB, "glMultiTexCoord3fvARB" }, - { (PROC)glMultiTexCoord3iARB, "glMultiTexCoord3iARB" }, - { (PROC)glMultiTexCoord3ivARB, "glMultiTexCoord3ivARB" }, - { (PROC)glMultiTexCoord3sARB, "glMultiTexCoord3sARB" }, - { (PROC)glMultiTexCoord3svARB, "glMultiTexCoord3svARB" }, - { (PROC)glMultiTexCoord4dARB, "glMultiTexCoord4dARB" }, - { (PROC)glMultiTexCoord4dvARB, "glMultiTexCoord4dvARB" }, - { (PROC)glMultiTexCoord4fARB, "glMultiTexCoord4fARB" }, - { (PROC)glMultiTexCoord4fvARB, "glMultiTexCoord4fvARB" }, - { (PROC)glMultiTexCoord4iARB, "glMultiTexCoord4iARB" }, - { (PROC)glMultiTexCoord4ivARB, "glMultiTexCoord4ivARB" }, - { (PROC)glMultiTexCoord4sARB, "glMultiTexCoord4sARB" }, - { (PROC)glMultiTexCoord4svARB, "glMultiTexCoord4svARB" }, - - // Descent3 doesn't use correct string, hence this hack - { (PROC)glMultiTexCoord4fARB, "glMultiTexCoord4f" }, - - // Quake2 SGIS multitexture - { (PROC)gldSelectTextureSGIS, "glSelectTextureSGIS" }, - { (PROC)gldMTexCoord2fSGIS, "glMTexCoord2fSGIS" }, - { (PROC)gldMTexCoord2fvSGIS, "glMTexCoord2fvSGIS" }, - - { NULL, "\0" } -}; - -//--------------------------------------------------------------------------- - -PROC gldGetProcAddress_DX( - LPCSTR a) -{ - int i; - PROC proc = NULL; - - for (i=0; GLD_extList[i].proc; i++) { - if (!strcmp(a, GLD_extList[i].name)) { - proc = GLD_extList[i].proc; - break; - } - } - - if (glb.bMultitexture) { - for (i=0; GLD_multitexList[i].proc; i++) { - if (!strcmp(a, GLD_multitexList[i].name)) { - proc = GLD_multitexList[i].proc; - break; - } - } - } - - gldLogPrintf(GLDLOG_INFO, "GetProcAddress: %s (%s)", a, proc ? "OK" : "Failed"); - - return proc; -} - -//--------------------------------------------------------------------------- - -void gldEnableExtensions_DX7( - GLcontext *ctx) -{ - GLuint i; - - // Mesa enables some extensions by default. - // This table decides which ones we want to switch off again. - - // NOTE: GL_EXT_compiled_vertex_array appears broken. - - const char *gld_disable_extensions[] = { -// "GL_ARB_transpose_matrix", -// "GL_EXT_compiled_vertex_array", -// "GL_EXT_polygon_offset", -// "GL_EXT_rescale_normal", - "GL_EXT_texture3D", -// "GL_NV_texgen_reflection", - "GL_EXT_abgr", - "GL_EXT_bgra", - NULL - }; - - const char *gld_multitex_extensions[] = { - "GL_ARB_multitexture", // Quake 3 - NULL - }; - - // Quake 2 engines - const char *szGL_SGIS_multitexture = "GL_SGIS_multitexture"; - - const char *gld_enable_extensions[] = { - "GL_EXT_texture_env_add", // Quake 3 - "GL_ARB_texture_env_add", // Quake 3 - NULL - }; - - for (i=0; gld_disable_extensions[i]; i++) { - _mesa_disable_extension(ctx, gld_disable_extensions[i]); - } - - for (i=0; gld_enable_extensions[i]; i++) { - _mesa_enable_extension(ctx, gld_enable_extensions[i]); - } - - if (glb.bMultitexture) { - for (i=0; gld_multitex_extensions[i]; i++) { - _mesa_enable_extension(ctx, gld_multitex_extensions[i]); - } - - // GL_SGIS_multitexture - // NOTE: Quake2 ran *slower* with this enabled, so I've - // disabled it for now. - // Fair bit slower on GeForce256, - // Much slower on 3dfx Voodoo5 5500. -// _mesa_add_extension(ctx, GL_TRUE, szGL_SGIS_multitexture, 0); - - } - - _mesa_enable_imaging_extensions(ctx); - _mesa_enable_1_3_extensions(ctx); - _mesa_enable_1_4_extensions(ctx); -} - -//--------------------------------------------------------------------------- diff --git a/src/mesa/drivers/windows/gldirect/dx7/gld_pipeline_dx7.c b/src/mesa/drivers/windows/gldirect/dx7/gld_pipeline_dx7.c deleted file mode 100644 index 9ccec69b98..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx7/gld_pipeline_dx7.c +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: Mesa transformation pipeline with GLDirect fastpath -* -****************************************************************************/ - -//#include "../GLDirect.h" - -#include "dglcontext.h" -#include "ddlog.h" -#include "gld_dx7.h" - -#include "tnl/tnl.h" -#include "tnl/t_context.h" -#include "tnl/t_pipeline.h" - -//--------------------------------------------------------------------------- - -extern struct tnl_pipeline_stage _gld_d3d_render_stage; -extern struct tnl_pipeline_stage _gld_mesa_render_stage; - -static const struct tnl_pipeline_stage *gld_pipeline[] = { - &_gld_d3d_render_stage, // Direct3D TnL - &_tnl_vertex_transform_stage, - &_tnl_normal_transform_stage, - &_tnl_lighting_stage, - &_tnl_fog_coordinate_stage, /* TODO: Omit fog stage. ??? */ - &_tnl_texgen_stage, - &_tnl_texture_transform_stage, - &_tnl_point_attenuation_stage, - &_gld_mesa_render_stage, // Mesa TnL, D3D rendering - 0, -}; - -//--------------------------------------------------------------------------- - -void gldInstallPipeline_DX7( - GLcontext *ctx) -{ - // Remove any existing pipeline stages, - // then install GLDirect pipeline stages. - - _tnl_destroy_pipeline(ctx); - _tnl_install_pipeline(ctx, gld_pipeline); -} - -//--------------------------------------------------------------------------- diff --git a/src/mesa/drivers/windows/gldirect/dx7/gld_primitive_dx7.c b/src/mesa/drivers/windows/gldirect/dx7/gld_primitive_dx7.c deleted file mode 100644 index c99ba0bba5..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx7/gld_primitive_dx7.c +++ /dev/null @@ -1,1448 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: Primitive (points/lines/tris/quads) rendering -* -****************************************************************************/ - -//#include "../GLDirect.h" - -//#include "gld_dx8.h" - -#include "dglcontext.h" -#include "ddlog.h" -#include "gld_dx7.h" - -#include "glheader.h" -#include "context.h" -#include "colormac.h" -#include "depth.h" -#include "extensions.h" -#include "macros.h" -#include "matrix.h" -// #include "mem.h" -//#include "mmath.h" -#include "mtypes.h" -#include "texformat.h" -#include "texstore.h" -#include "vbo/vbo.h" -#include "swrast/swrast.h" -#include "swrast_setup/swrast_setup.h" -#include "swrast_setup/ss_context.h" -#include "swrast/s_context.h" -#include "swrast/s_depth.h" -#include "swrast/s_lines.h" -#include "swrast/s_triangle.h" -#include "swrast/s_trispan.h" -#include "tnl/tnl.h" -#include "tnl/t_context.h" -#include "tnl/t_pipeline.h" - -// Disable compiler complaints about unreferenced local variables -#pragma warning (disable:4101) - -//--------------------------------------------------------------------------- -// Helper defines for primitives -//--------------------------------------------------------------------------- - -//static const float ooZ = 1.0f / 65536.0f; // One over Z - -#define GLD_COLOUR (D3DCOLOR_RGBA(swv->color[0], swv->color[1], swv->color[2], swv->color[3])) -#define GLD_SPECULAR (D3DCOLOR_RGBA(swv->specular[0], swv->specular[1], swv->specular[2], swv->specular[3])) -#define GLD_FLIP_Y(y) (gldCtx->dwHeight - (y)) - -//--------------------------------------------------------------------------- -// 2D vertex setup -//--------------------------------------------------------------------------- - -#define GLD_SETUP_2D_VARS_POINTS \ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); \ - GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pPoints; \ - SScontext *ss = SWSETUP_CONTEXT(ctx); \ - SWvertex *swv; \ - DWORD dwSpecularColour; \ - DWORD dwFlatColour - -#define GLD_SETUP_2D_VARS_LINES \ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); \ - GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pLines; \ - SScontext *ss = SWSETUP_CONTEXT(ctx); \ - SWvertex *swv; \ - DWORD dwSpecularColour; \ - DWORD dwFlatColour - -#define GLD_SETUP_2D_VARS_TRIANGLES \ - BOOL bFog = ctx->Fog.Enabled; \ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); \ - GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pTriangles; \ - SScontext *ss = SWSETUP_CONTEXT(ctx); \ - SWvertex *swv; \ - DWORD dwSpecularColour; \ - DWORD dwFlatColour; \ - GLuint facing = 0; \ - struct vertex_buffer *VB; \ - GLchan (*vbcolor)[4]; \ - GLchan (*vbspec)[4] - -#define GLD_SETUP_GET_SWVERT(s) \ - swv = &ss->verts[##s] - -#define GLD_SETUP_2D_VERTEX \ - pV->x = swv->win[0]; \ - pV->y = GLD_FLIP_Y(swv->win[1]); \ - pV->rhw = swv->win[3] - -#define GLD_SETUP_SMOOTH_COLOUR \ - pV->diffuse = GLD_COLOUR - -#define GLD_SETUP_GET_FLAT_COLOUR \ - dwFlatColour = GLD_COLOUR -#define GLD_SETUP_GET_FLAT_FOG_COLOUR \ - dwFlatColour = _gldComputeFog(ctx, swv) - -#define GLD_SETUP_USE_FLAT_COLOUR \ - pV->diffuse = dwFlatColour - -#define GLD_SETUP_GET_FLAT_SPECULAR \ - dwSpecularColour= GLD_SPECULAR - -#define GLD_SETUP_USE_FLAT_SPECULAR \ - pV->specular = dwSpecularColour - -#define GLD_SETUP_DEPTH \ - pV->sz = swv->win[2] / ctx->DepthMaxF -// pV->z = swv->win[2] * ooZ; - -#define GLD_SETUP_SPECULAR \ - pV->specular = GLD_SPECULAR - -#define GLD_SETUP_FOG \ - pV->diffuse = _gldComputeFog(ctx, swv) - -#define GLD_SETUP_TEX0 \ - pV->t0_u = swv->texcoord[0][0]; \ - pV->t0_v = swv->texcoord[0][1] - -#define GLD_SETUP_TEX1 \ - pV->t1_u = swv->texcoord[1][0]; \ - pV->t1_v = swv->texcoord[1][1] - -#define GLD_SETUP_LIGHTING(v) \ - if (facing == 1) { \ - pV->diffuse = D3DCOLOR_RGBA(vbcolor[##v][0], vbcolor[##v][1], vbcolor[##v][2], vbcolor[##v][3]); \ - if (vbspec) { \ - pV->specular = D3DCOLOR_RGBA(vbspec[##v][0], vbspec[##v][1], vbspec[##v][2], vbspec[##v][3]); \ - } \ - } else { \ - if (bFog) \ - GLD_SETUP_FOG; \ - else \ - GLD_SETUP_SMOOTH_COLOUR; \ - GLD_SETUP_SPECULAR; \ - } - -#define GLD_SETUP_GET_FLAT_LIGHTING(v) \ - if (facing == 1) { \ - dwFlatColour = D3DCOLOR_RGBA(vbcolor[##v][0], vbcolor[##v][1], vbcolor[##v][2], vbcolor[##v][3]); \ - if (vbspec) { \ - dwSpecularColour = D3DCOLOR_RGBA(vbspec[##v][0], vbspec[##v][1], vbspec[##v][2], vbspec[##v][3]); \ - } \ - } - -#define GLD_SETUP_TWOSIDED_LIGHTING \ - /* Two-sided lighting */ \ - if (ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) { \ - SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts; \ - SWvertex *v[3]; \ - GLfloat ex,ey,fx,fy,cc; \ - /* Get vars for later */ \ - VB = &TNL_CONTEXT(ctx)->vb; \ - vbcolor = (GLchan (*)[4])VB->ColorPtr[1]->data; \ - if (VB->SecondaryColorPtr[1]) { \ - vbspec = (GLchan (*)[4])VB->SecondaryColorPtr[1]->data; \ - } else { \ - vbspec = NULL; \ - } \ - v[0] = &verts[v0]; \ - v[1] = &verts[v1]; \ - v[2] = &verts[v2]; \ - ex = v[0]->win[0] - v[2]->win[0]; \ - ey = v[0]->win[1] - v[2]->win[1]; \ - fx = v[1]->win[0] - v[2]->win[0]; \ - fy = v[1]->win[1] - v[2]->win[1]; \ - cc = ex*fy - ey*fx; \ - facing = (cc < 0.0) ^ ctx->Polygon._FrontBit; \ - } - -//--------------------------------------------------------------------------- -// 3D vertex setup -//--------------------------------------------------------------------------- - -#define GLD_SETUP_3D_VARS_POINTS \ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); \ - GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pPoints; \ - TNLcontext *tnl = TNL_CONTEXT(ctx); \ - struct vertex_buffer *VB = &tnl->vb; \ - GLfloat (*p4f)[4]; \ - GLfloat (*tc)[4]; \ - DWORD dwColor; - -#define GLD_SETUP_3D_VARS_LINES \ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); \ - GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pLines; \ - TNLcontext *tnl = TNL_CONTEXT(ctx); \ - struct vertex_buffer *VB = &tnl->vb; \ - GLfloat (*p4f)[4]; \ - GLfloat (*tc)[4]; \ - DWORD dwColor; - -#define GLD_SETUP_3D_VARS_TRIANGLES \ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); \ - GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pTriangles; \ - TNLcontext *tnl = TNL_CONTEXT(ctx); \ - struct vertex_buffer *VB = &tnl->vb; \ - GLfloat (*p4f)[4]; \ - GLfloat (*tc)[4]; \ - DWORD dwColor; - -#define GLD_SETUP_3D_VERTEX(v) \ - p4f = VB->ObjPtr->data; \ - pV->Position.x = p4f[##v][0]; \ - pV->Position.y = p4f[##v][1]; \ - pV->Position.z = p4f[##v][2]; - -#define GLD_SETUP_SMOOTH_COLOUR_3D(v) \ - p4f = (GLfloat (*)[4])VB->ColorPtr[0]->data; \ - pV->Diffuse = D3DCOLOR_COLORVALUE(p4f[##v][0], p4f[##v][1], p4f[##v][2], p4f[##v][3]); - - -#define GLD_SETUP_GET_FLAT_COLOUR_3D(v) \ - p4f = (GLfloat (*)[4])VB->ColorPtr[0]->data; \ - dwColor = D3DCOLOR_COLORVALUE(p4f[##v][0], p4f[##v][1], p4f[##v][2], p4f[##v][3]); - -#define GLD_SETUP_USE_FLAT_COLOUR_3D \ - pV->Diffuse = dwColor; - -#define GLD_SETUP_TEX0_3D(v) \ - if (VB->TexCoordPtr[0]) { \ - tc = VB->TexCoordPtr[0]->data; \ - pV->TexUnit0.x = tc[##v][0]; \ - pV->TexUnit0.y = tc[##v][1]; \ - } - -#define GLD_SETUP_TEX1_3D(v) \ - if (VB->TexCoordPtr[1]) { \ - tc = VB->TexCoordPtr[1]->data; \ - pV->TexUnit1.x = tc[##v][0]; \ - pV->TexUnit1.y = tc[##v][1]; \ - } - -//--------------------------------------------------------------------------- -// Helper functions -//--------------------------------------------------------------------------- - -__inline DWORD _gldComputeFog( - GLcontext *ctx, - SWvertex *swv) -{ - // Full fog calculation. - // Based on Mesa code. - - GLchan rFog, gFog, bFog; - GLchan fR, fG, fB; - const GLfloat f = swv->fog; - const GLfloat g = 1.0 - f; - - UNCLAMPED_FLOAT_TO_CHAN(rFog, ctx->Fog.Color[RCOMP]); - UNCLAMPED_FLOAT_TO_CHAN(gFog, ctx->Fog.Color[GCOMP]); - UNCLAMPED_FLOAT_TO_CHAN(bFog, ctx->Fog.Color[BCOMP]); - fR = f * swv->color[0] + g * rFog; - fG = f * swv->color[1] + g * gFog; - fB = f * swv->color[2] + g * bFog; - return D3DCOLOR_RGBA(fR, fG, fB, swv->color[3]); -} - -//--------------------------------------------------------------------------- - -void gld_ResetLineStipple_DX7( - GLcontext *ctx) -{ - // TODO: Fake stipple with a 32x32 texture. -} - -//--------------------------------------------------------------------------- -// 2D (post-transformed) primitives -//--------------------------------------------------------------------------- - -void gld_Points2D_DX7( - GLcontext *ctx, - GLuint first, - GLuint last) -{ - GLD_SETUP_2D_VARS_POINTS; - - unsigned i; - struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; - - // _Size is already clamped to MaxPointSize and MinPointSize - // Not supported by DX7 -// IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_POINTSIZE, *((DWORD*)&ctx->Point._Size)); - - if (VB->Elts) { - for (i=first; i<last; i++, pV++) { - if (VB->ClipMask[VB->Elts[i]] == 0) { -// _swrast_Point( ctx, &verts[VB->Elts[i]] ); - GLD_SETUP_GET_SWVERT(VB->Elts[i]); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_SPECULAR; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - } - } - } else { - GLD_SETUP_GET_SWVERT(first); - for (i=first; i<last; i++, swv++, pV++) { - if (VB->ClipMask[i] == 0) { -// _swrast_Point( ctx, &verts[i] ); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_SPECULAR; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - } - } - } - - gld->PB2d.pPoints = (BYTE*)pV; - gld->PB2d.nPoints += (last-first); -} - -//--------------------------------------------------------------------------- - -void gld_Line2DFlat_DX7( - GLcontext *ctx, - GLuint v0, - GLuint v1) -{ - GLD_SETUP_2D_VARS_LINES; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_GET_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_GET_FLAT_SPECULAR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - gld->PB2d.pLines = (BYTE*)pV; - gld->PB2d.nLines++; -} - -//--------------------------------------------------------------------------- - -void gld_Line2DSmooth_DX7( - GLcontext *ctx, - GLuint v0, - GLuint v1) -{ - GLD_SETUP_2D_VARS_LINES; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_SPECULAR; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_SPECULAR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - gld->PB2d.pLines = (BYTE*)pV; - gld->PB2d.nLines++; -} - -//--------------------------------------------------------------------------- - -void gld_Triangle2DFlat_DX7( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_GET_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_COLOUR; - pV++;; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles++; -} - -//--------------------------------------------------------------------------- - -void gld_Triangle2DSmooth_DX7( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2) -{ - - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles++; -} - -//--------------------------------------------------------------------------- - -void gld_Triangle2DFlatExtras_DX7( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_TWOSIDED_LIGHTING(v2); - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - if (bFog) - GLD_SETUP_GET_FLAT_FOG_COLOUR; - else - GLD_SETUP_GET_FLAT_COLOUR; - GLD_SETUP_GET_FLAT_SPECULAR; - GLD_SETUP_GET_FLAT_LIGHTING(v2); - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles++; -} - -//--------------------------------------------------------------------------- - -void gld_Triangle2DSmoothExtras_DX7( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_TWOSIDED_LIGHTING(v0); - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v0); - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v1); - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v2); - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles++; -} - -//--------------------------------------------------------------------------- - -void gld_Quad2DFlat_DX7( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2, - GLuint v3) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_GET_SWVERT(v3); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_GET_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - GLD_SETUP_GET_SWVERT(v3); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles += 2; -} - -//--------------------------------------------------------------------------- - -void gld_Quad2DSmooth_DX7( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2, - GLuint v3) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v3); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles += 2; -} - -//--------------------------------------------------------------------------- - -void gld_Quad2DFlatExtras_DX7( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2, - GLuint v3) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_TWOSIDED_LIGHTING(v3); - - GLD_SETUP_GET_SWVERT(v3); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - if (bFog) - GLD_SETUP_GET_FLAT_FOG_COLOUR; - else - GLD_SETUP_GET_FLAT_COLOUR; - GLD_SETUP_GET_FLAT_SPECULAR; - GLD_SETUP_GET_FLAT_LIGHTING(v3); - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v3); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles += 2; -} - -//--------------------------------------------------------------------------- - -void gld_Quad2DSmoothExtras_DX7( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2, - GLuint v3) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_TWOSIDED_LIGHTING(v0); - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v0); - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v1); - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v2); - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v2); - pV++; - - GLD_SETUP_GET_SWVERT(v3); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v3); - pV++; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v0); - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles += 2; -} - -//--------------------------------------------------------------------------- -// 3D (pre-transformed) primitives -//--------------------------------------------------------------------------- - -void gld_Points3D_DX7( - GLcontext *ctx, - GLuint first, - GLuint last) -{ - GLD_SETUP_3D_VARS_POINTS - - unsigned i; -// struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; - - // _Size is already clamped to MaxPointSize and MinPointSize - // Not supported by DX7 -// IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_POINTSIZE, *((DWORD*)&ctx->Point._Size)); - - if (VB->Elts) { - for (i=first; i<last; i++, pV++) { - if (VB->ClipMask[VB->Elts[i]] == 0) { -// _swrast_Point( ctx, &verts[VB->Elts[i]] ); -// GLD_SETUP_GET_SWVERT(VB->Elts[i]); - GLD_SETUP_3D_VERTEX(VB->Elts[i]) - GLD_SETUP_SMOOTH_COLOUR_3D(i) - GLD_SETUP_TEX0_3D(i) - GLD_SETUP_TEX1_3D(i) - } - } - } else { -// GLD_SETUP_GET_SWVERT(first); - for (i=first; i<last; i++, pV++) { - if (VB->ClipMask[i] == 0) { -// _swrast_Point( ctx, &verts[i] ); - GLD_SETUP_3D_VERTEX(i) - GLD_SETUP_SMOOTH_COLOUR_3D(i) - GLD_SETUP_TEX0_3D(i) - GLD_SETUP_TEX1_3D(i) - } - } - } -/* - for (i=first; i<last; i++, pV++) { - GLD_SETUP_3D_VERTEX(i) - GLD_SETUP_SMOOTH_COLOUR_3D(i) - GLD_SETUP_TEX0_3D(i) - GLD_SETUP_TEX1_3D(i) - } -*/ - gld->PB3d.pPoints = (BYTE*)pV; - gld->PB3d.nPoints += (last-first); -} - -//--------------------------------------------------------------------------- -// Line functions -//--------------------------------------------------------------------------- - -void gld_Line3DFlat_DX7( - GLcontext *ctx, - GLuint v0, - GLuint v1) -{ - GLD_SETUP_3D_VARS_LINES - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_GET_FLAT_COLOUR_3D(v1) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - pV++; - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - pV++; - - gld->PB3d.pLines = (BYTE*)pV; - gld->PB3d.nLines++; -} - -//--------------------------------------------------------------------------- - -void gld_Line3DSmooth_DX7( - GLcontext *ctx, - GLuint v0, - GLuint v1) -{ - GLD_SETUP_3D_VARS_LINES - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_SMOOTH_COLOUR_3D(v1) - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - pV++; - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_SMOOTH_COLOUR_3D(v0) - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - pV++; - - gld->PB3d.pLines = (BYTE*)pV; - gld->PB3d.nLines++; -} - -//--------------------------------------------------------------------------- -// Triangle functions -//--------------------------------------------------------------------------- - -void gld_Triangle3DFlat_DX7( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2) -{ - GLD_SETUP_3D_VARS_TRIANGLES - - GLD_SETUP_3D_VERTEX(v2) - GLD_SETUP_TEX0_3D(v2) - GLD_SETUP_TEX1_3D(v2) - GLD_SETUP_GET_FLAT_COLOUR_3D(v2) - GLD_SETUP_USE_FLAT_COLOUR_3D - pV++; - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - GLD_SETUP_USE_FLAT_COLOUR_3D - pV++; - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - GLD_SETUP_USE_FLAT_COLOUR_3D - pV++; - - gld->PB3d.pTriangles = (BYTE*)pV; - gld->PB3d.nTriangles++; -} - -//--------------------------------------------------------------------------- - -void gld_Triangle3DSmooth_DX7( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2) -{ - GLD_SETUP_3D_VARS_TRIANGLES - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_SMOOTH_COLOUR_3D(v0) - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - pV++; - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_SMOOTH_COLOUR_3D(v1) - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - pV++; - - GLD_SETUP_3D_VERTEX(v2) - GLD_SETUP_SMOOTH_COLOUR_3D(v2) - GLD_SETUP_TEX0_3D(v2) - GLD_SETUP_TEX1_3D(v2) - pV++; - - gld->PB3d.pTriangles = (BYTE*)pV; - gld->PB3d.nTriangles++; -} - -//--------------------------------------------------------------------------- -// Quad functions -//--------------------------------------------------------------------------- - -void gld_Quad3DFlat_DX7( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2, - GLuint v3) -{ - GLD_SETUP_3D_VARS_TRIANGLES - - GLD_SETUP_3D_VERTEX(v3) - GLD_SETUP_GET_FLAT_COLOUR_3D(v3) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v3) - GLD_SETUP_TEX1_3D(v3) - pV++; - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - pV++; - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - pV++; - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - pV++; - - GLD_SETUP_3D_VERTEX(v2) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v2) - GLD_SETUP_TEX1_3D(v2) - pV++; - - GLD_SETUP_3D_VERTEX(v3) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v3) - GLD_SETUP_TEX1_3D(v3) - pV++; - - gld->PB3d.pTriangles = (BYTE*)pV; - gld->PB3d.nTriangles += 2; -} - -//--------------------------------------------------------------------------- - -void gld_Quad3DSmooth_DX7( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2, - GLuint v3) -{ - GLD_SETUP_3D_VARS_TRIANGLES - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_SMOOTH_COLOUR_3D(v0) - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - pV++; - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_SMOOTH_COLOUR_3D(v1) - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - pV++; - - GLD_SETUP_3D_VERTEX(v2) - GLD_SETUP_SMOOTH_COLOUR_3D(v2) - GLD_SETUP_TEX0_3D(v2) - GLD_SETUP_TEX1_3D(v2) - pV++; - - GLD_SETUP_3D_VERTEX(v2) - GLD_SETUP_SMOOTH_COLOUR_3D(v2) - GLD_SETUP_TEX0_3D(v2) - GLD_SETUP_TEX1_3D(v2) - pV++; - - GLD_SETUP_3D_VERTEX(v3) - GLD_SETUP_SMOOTH_COLOUR_3D(v3) - GLD_SETUP_TEX0_3D(v3) - GLD_SETUP_TEX1_3D(v3) - pV++; - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_SMOOTH_COLOUR_3D(v0) - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - pV++; - - gld->PB3d.pTriangles = (BYTE*)pV; - gld->PB3d.nTriangles += 2; -} - -//--------------------------------------------------------------------------- -// Vertex setup for two-sided-lighting vertex shader -//--------------------------------------------------------------------------- - -/* - -void gld_Points2DTwoside_DX8(GLcontext *ctx, GLuint first, GLuint last) -{ - // NOTE: Two-sided lighting does not apply to Points -} - -//--------------------------------------------------------------------------- - -void gld_Line2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1) -{ - // NOTE: Two-sided lighting does not apply to Lines -} - -//--------------------------------------------------------------------------- - -void gld_Line2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1) -{ - // NOTE: Two-sided lighting does not apply to Lines -} - -//--------------------------------------------------------------------------- - -void gld_Triangle2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2) -{ -} - -//--------------------------------------------------------------------------- - -void gld_Triangle2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles; - SScontext *ss = SWSETUP_CONTEXT(ctx); - SWvertex *swv; - DWORD dwSpecularColour; - DWORD dwFlatColour; - GLuint facing = 0; - struct vertex_buffer *VB; - GLchan (*vbcolor)[4]; - GLchan (*vbspec)[4]; - - // Reciprocal of DepthMax - const float ooDepthMax = 1.0f / ctx->DepthMaxF; - - // 1st vert - swv = &ss->verts[v0]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 2nd vert - swv = &ss->verts[v1]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 3rd vert - swv = &ss->verts[v2]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - gld->PBtwosidelight.pTriangles = (BYTE*)pV; - gld->PBtwosidelight.nTriangles++; -} - -//--------------------------------------------------------------------------- - -void gld_Quad2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles; - SScontext *ss = SWSETUP_CONTEXT(ctx); - SWvertex *swv; - DWORD dwSpecularColour; - DWORD dwFlatColour; - GLuint facing = 0; - struct vertex_buffer *VB; - GLchan (*vbcolor)[4]; - GLchan (*vbspec)[4]; - - // Reciprocal of DepthMax - const float ooDepthMax = 1.0f / ctx->DepthMaxF; - - // 1st vert - swv = &ss->verts[v0]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 2nd vert - swv = &ss->verts[v1]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 3rd vert - swv = &ss->verts[v2]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 4th vert - swv = &ss->verts[v2]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 5th vert - swv = &ss->verts[v3]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 6th vert - swv = &ss->verts[v0]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - gld->PBtwosidelight.pTriangles = (BYTE*)pV; - gld->PBtwosidelight.nTriangles += 2; -} - -//--------------------------------------------------------------------------- - -void gld_Quad2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles; - SScontext *ss = SWSETUP_CONTEXT(ctx); - SWvertex *swv; - DWORD dwSpecularColour; - DWORD dwFlatColour; - GLuint facing = 0; - struct vertex_buffer *VB; - GLchan (*vbcolor)[4]; - GLchan (*vbspec)[4]; - - // Reciprocal of DepthMax - const float ooDepthMax = 1.0f / ctx->DepthMaxF; - - // 1st vert - swv = &ss->verts[v0]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 2nd vert - swv = &ss->verts[v1]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 3rd vert - swv = &ss->verts[v2]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 4th vert - swv = &ss->verts[v2]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 5th vert - swv = &ss->verts[v3]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 6th vert - swv = &ss->verts[v0]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - gld->PBtwosidelight.pTriangles = (BYTE*)pV; - gld->PBtwosidelight.nTriangles += 2; -} - -//--------------------------------------------------------------------------- - -*/ diff --git a/src/mesa/drivers/windows/gldirect/dx7/gld_texture_dx7.c b/src/mesa/drivers/windows/gldirect/dx7/gld_texture_dx7.c deleted file mode 100644 index bbe673516d..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx7/gld_texture_dx7.c +++ /dev/null @@ -1,2196 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: Texture / Bitmap functions -* -****************************************************************************/ - -#include "dglcontext.h" -#include "ddlog.h" -#include "gld_dx7.h" - -//#include <d3dx8tex.h> - -#include "texformat.h" -#include "colormac.h" -#include "texstore.h" -#include "image.h" -// #include "mem.h" - -//--------------------------------------------------------------------------- - -#define GLD_FLIP_HEIGHT(y,h) (gldCtx->dwHeight - (y) - (h)) - -D3DX_SURFACEFORMAT _gldD3DXFormatFromSurface(IDirectDrawSurface7 *pSurface); - -//--------------------------------------------------------------------------- -// 1D texture fetch -//--------------------------------------------------------------------------- - -#define CHAN_SRC( t, i, j, k, sz ) \ - ((GLchan *)(t)->Data + (i) * (sz)) -#define UBYTE_SRC( t, i, j, k, sz ) \ - ((GLubyte *)(t)->Data + (i) * (sz)) -#define USHORT_SRC( t, i, j, k ) \ - ((GLushort *)(t)->Data + (i)) -#define FLOAT_SRC( t, i, j, k ) \ - ((GLfloat *)(t)->Data + (i)) - -//--------------------------------------------------------------------------- - -static void gld_fetch_1d_texel_X8R8G8B8( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); - GLchan *rgba = (GLchan *)texel; - rgba[RCOMP] = src[2]; - rgba[GCOMP] = src[1]; - rgba[BCOMP] = src[0]; - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_1d_texel_f_X8R8G8B8( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); - texel[RCOMP] = CHAN_TO_FLOAT(src[0]); - texel[GCOMP] = CHAN_TO_FLOAT(src[1]); - texel[BCOMP] = CHAN_TO_FLOAT(src[2]); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_1d_texel_X1R5G5B5( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLchan *rgba = (GLchan *) texel; GLushort s = *src; - rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0xf8) * 255 / 0xf8 ); - rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0xf8) * 255 / 0xf8 ); - rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf8) * 255 / 0xf8 ); - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_1d_texel_f_X1R5G5B5( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLushort s = *src; - texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0xf8) * 255 / 0xf8 ); - texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0xf8) * 255 / 0xf8 ); - texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf8) * 255 / 0xf8 ); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_1d_texel_X4R4G4B4( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLchan *rgba = (GLchan *) texel; GLushort s = *src; - rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf ); - rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf ); - rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf ); - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_1d_texel_f_X4R4G4B4( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLushort s = *src; - texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf ); - texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf ); - texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf ); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -#undef CHAN_SRC -#undef UBYTE_SRC -#undef USHORT_SRC -#undef FLOAT_SRC - -//--------------------------------------------------------------------------- -// 2D texture fetch -//--------------------------------------------------------------------------- - -#define CHAN_SRC( t, i, j, k, sz ) \ - ((GLchan *)(t)->Data + ((t)->Width * (j) + (i)) * (sz)) -#define UBYTE_SRC( t, i, j, k, sz ) \ - ((GLubyte *)(t)->Data + ((t)->Width * (j) + (i)) * (sz)) -#define USHORT_SRC( t, i, j, k ) \ - ((GLushort *)(t)->Data + ((t)->Width * (j) + (i))) -#define FLOAT_SRC( t, i, j, k ) \ - ((GLfloat *)(t)->Data + ((t)->Width * (j) + (i))) - -//--------------------------------------------------------------------------- - -static void gld_fetch_2d_texel_X8R8G8B8( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); - GLchan *rgba = (GLchan *)texel; - rgba[RCOMP] = src[2]; - rgba[GCOMP] = src[1]; - rgba[BCOMP] = src[0]; - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_2d_texel_f_X8R8G8B8( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); - texel[RCOMP] = CHAN_TO_FLOAT(src[0]); - texel[GCOMP] = CHAN_TO_FLOAT(src[1]); - texel[BCOMP] = CHAN_TO_FLOAT(src[2]); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_2d_texel_X1R5G5B5( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLchan *rgba = (GLchan *) texel; GLushort s = *src; - rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0xf8) * 255 / 0xf8 ); - rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0xf8) * 255 / 0xf8 ); - rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf8) * 255 / 0xf8 ); - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_2d_texel_f_X1R5G5B5( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLushort s = *src; - texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0xf8) * 255 / 0xf8 ); - texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0xf8) * 255 / 0xf8 ); - texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf8) * 255 / 0xf8 ); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_2d_texel_X4R4G4B4( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLchan *rgba = (GLchan *) texel; GLushort s = *src; - rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf ); - rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf ); - rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf ); - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_2d_texel_f_X4R4G4B4( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLushort s = *src; - texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf ); - texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf ); - texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf ); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -#undef CHAN_SRC -#undef UBYTE_SRC -#undef USHORT_SRC -#undef FLOAT_SRC - -//--------------------------------------------------------------------------- -// 3D texture fetch -//--------------------------------------------------------------------------- - -#define CHAN_SRC( t, i, j, k, sz ) \ - (GLchan *)(t)->Data + (((t)->Height * (k) + (j)) * \ - (t)->Width + (i)) * (sz) -#define UBYTE_SRC( t, i, j, k, sz ) \ - ((GLubyte *)(t)->Data + (((t)->Height * (k) + (j)) * \ - (t)->Width + (i)) * (sz)) -#define USHORT_SRC( t, i, j, k ) \ - ((GLushort *)(t)->Data + (((t)->Height * (k) + (j)) * \ - (t)->Width + (i))) -#define FLOAT_SRC( t, i, j, k ) \ - ((GLfloat *)(t)->Data + (((t)->Height * (k) + (j)) * \ - (t)->Width + (i))) - -//--------------------------------------------------------------------------- - -static void gld_fetch_3d_texel_X8R8G8B8( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); - GLchan *rgba = (GLchan *)texel; - rgba[RCOMP] = src[2]; - rgba[GCOMP] = src[1]; - rgba[BCOMP] = src[0]; - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_3d_texel_f_X8R8G8B8( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); - texel[RCOMP] = CHAN_TO_FLOAT(src[0]); - texel[GCOMP] = CHAN_TO_FLOAT(src[1]); - texel[BCOMP] = CHAN_TO_FLOAT(src[2]); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_3d_texel_X1R5G5B5( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLchan *rgba = (GLchan *) texel; GLushort s = *src; - rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0xf8) * 255 / 0xf8 ); - rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0xf8) * 255 / 0xf8 ); - rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf8) * 255 / 0xf8 ); - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_3d_texel_f_X1R5G5B5( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLushort s = *src; - texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0xf8) * 255 / 0xf8 ); - texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0xf8) * 255 / 0xf8 ); - texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf8) * 255 / 0xf8 ); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_3d_texel_X4R4G4B4( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLchan *rgba = (GLchan *) texel; GLushort s = *src; - rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf ); - rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf ); - rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf ); - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_3d_texel_f_X4R4G4B4( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLushort s = *src; - texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf ); - texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf ); - texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf ); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -#undef CHAN_SRC -#undef UBYTE_SRC -#undef USHORT_SRC -#undef FLOAT_SRC - -//--------------------------------------------------------------------------- -// Direct3D texture formats that have no Mesa equivalent -//--------------------------------------------------------------------------- - -const struct gl_texture_format _gld_texformat_X8R8G8B8 = { - MESA_FORMAT_ARGB8888, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 8, /* RedBits */ - 8, /* GreenBits */ - 8, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 4, /* TexelBytes */ - _mesa_texstore_argb8888, /* StoreTexImageFunc */ - gld_fetch_1d_texel_X8R8G8B8, /* FetchTexel1D */ - gld_fetch_2d_texel_X8R8G8B8, /* FetchTexel2D */ - gld_fetch_3d_texel_X8R8G8B8, /* FetchTexel3D */ - gld_fetch_1d_texel_f_X8R8G8B8, /* FetchTexel1Df */ - gld_fetch_2d_texel_f_X8R8G8B8, /* FetchTexel2Df */ - gld_fetch_3d_texel_f_X8R8G8B8, /* FetchTexel3Df */ -}; - -const struct gl_texture_format _gld_texformat_X1R5G5B5 = { - MESA_FORMAT_ARGB1555, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 5, /* RedBits */ - 5, /* GreenBits */ - 5, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 2, /* TexelBytes */ - _mesa_texstore_argb1555, /* StoreTexImageFunc */ - gld_fetch_1d_texel_X1R5G5B5, /* FetchTexel1D */ - gld_fetch_2d_texel_X1R5G5B5, /* FetchTexel2D */ - gld_fetch_3d_texel_X1R5G5B5, /* FetchTexel3D */ - gld_fetch_1d_texel_f_X1R5G5B5, /* FetchTexel1Df */ - gld_fetch_2d_texel_f_X1R5G5B5, /* FetchTexel2Df */ - gld_fetch_3d_texel_f_X1R5G5B5, /* FetchTexel3Df */ -}; - -const struct gl_texture_format _gld_texformat_X4R4G4B4 = { - MESA_FORMAT_ARGB4444, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 4, /* RedBits */ - 4, /* GreenBits */ - 4, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 2, /* TexelBytes */ - _mesa_texstore_argb4444, /* StoreTexImageFunc */ - gld_fetch_1d_texel_X4R4G4B4, /* FetchTexel1D */ - gld_fetch_2d_texel_X4R4G4B4, /* FetchTexel2D */ - gld_fetch_3d_texel_X4R4G4B4, /* FetchTexel3D */ - gld_fetch_1d_texel_f_X4R4G4B4, /* FetchTexel1Df */ - gld_fetch_2d_texel_f_X4R4G4B4, /* FetchTexel2Df */ - gld_fetch_3d_texel_f_X4R4G4B4, /* FetchTexel3Df */ -}; - -//--------------------------------------------------------------------------- -// Texture unit constants -//--------------------------------------------------------------------------- - -// List of possible combinations of texture environments. -// Example: GLD_TEXENV_MODULATE_RGBA means -// GL_MODULATE, GL_RGBA base internal format. -#define GLD_TEXENV_DECAL_RGB 0 -#define GLD_TEXENV_DECAL_RGBA 1 -#define GLD_TEXENV_DECAL_ALPHA 2 -#define GLD_TEXENV_REPLACE_RGB 3 -#define GLD_TEXENV_REPLACE_RGBA 4 -#define GLD_TEXENV_REPLACE_ALPHA 5 -#define GLD_TEXENV_MODULATE_RGB 6 -#define GLD_TEXENV_MODULATE_RGBA 7 -#define GLD_TEXENV_MODULATE_ALPHA 8 -#define GLD_TEXENV_BLEND_RGB 9 -#define GLD_TEXENV_BLEND_RGBA 10 -#define GLD_TEXENV_BLEND_ALPHA 11 -#define GLD_TEXENV_ADD_RGB 12 -#define GLD_TEXENV_ADD_RGBA 13 -#define GLD_TEXENV_ADD_ALPHA 14 - -// Per-stage (i.e. per-unit) texture environment -typedef struct { - DWORD ColorArg1; // Colour argument 1 - D3DTEXTUREOP ColorOp; // Colour operation - DWORD ColorArg2; // Colour argument 2 - DWORD AlphaArg1; // Alpha argument 1 - D3DTEXTUREOP AlphaOp; // Alpha operation - DWORD AlphaArg2; // Alpha argument 2 -} GLD_texenv; - -// TODO: Do we really need to set ARG1 and ARG2 every time? -// They seem to always be TEXTURE and CURRENT respectively. - -// C = Colour out -// A = Alpha out -// Ct = Colour from Texture -// Cf = Colour from fragment (diffuse) -// At = Alpha from Texture -// Af = Alpha from fragment (diffuse) -// Cc = GL_TEXTURE_ENV_COLOUR (GL_BLEND) -const GLD_texenv gldTexEnv[] = { - // DECAL_RGB: C=Ct, A=Af - {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - // DECAL_RGBA: C=Cf(1-At)+CtAt, A=Af - {D3DTA_TEXTURE, D3DTOP_BLENDTEXTUREALPHA, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - // DECAL_ALPHA: <undefined> use DECAL_RGB - {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - - // REPLACE_RGB: C=Ct, A=Af - {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - // REPLACE_RGBA: C=Ct, A=At - {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT}, - // REPLACE_ALPHA: C=Cf, A=At - {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT}, - - // MODULATE_RGB: C=CfCt, A=Af - {D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - // MODULATE_RGBA: C=CfCt, A=AfAt - {D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, - // MODULATE_ALPHA: C=Cf, A=AfAt - {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, - - // - // DX7 Does not support D3DTOP_LERP - // Emulate(?) via D3DTOP_ADDSMOOTH - // -#if 0 - // BLEND_RGB: C=Cf(1-Ct)+CcCt, A=Af - {D3DTA_TEXTURE, D3DTOP_LERP, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - // BLEND_RGBA: C=Cf(1-Ct)+CcCt, A=AfAt - {D3DTA_TEXTURE, D3DTOP_LERP, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, -#else - // BLEND_RGB: C=Cf(1-Ct)+CcCt, A=Af - {D3DTA_TEXTURE, D3DTOP_ADDSMOOTH, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - // BLEND_RGBA: C=Cf(1-Ct)+CcCt, A=AfAt - {D3DTA_TEXTURE, D3DTOP_ADDSMOOTH, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, -#endif - // BLEND_ALPHA: C=Cf, A=AfAt - {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, - - // ADD_RGB: C=Cf+Ct, A=Af - {D3DTA_TEXTURE, D3DTOP_ADD, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - // ADD_RGBA: C=Cf+Ct, A=AfAt - {D3DTA_TEXTURE, D3DTOP_ADD, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, - // ADD_ALPHA: C=Cf, A=AfAt - {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, -}; - -//--------------------------------------------------------------------------- - -D3DTEXTUREADDRESS _gldConvertWrap( - GLenum wrap) -{ -// ASSERT(wrap==GL_CLAMP || wrap==GL_REPEAT); - return (wrap == GL_CLAMP) ? D3DTADDRESS_CLAMP : D3DTADDRESS_WRAP; -} - -//--------------------------------------------------------------------------- - -D3DTEXTUREMAGFILTER _gldConvertMagFilter( - GLenum magfilter) -{ - ASSERT(magfilter==GL_LINEAR || magfilter==GL_NEAREST); - return (magfilter == GL_LINEAR) ? D3DTFG_LINEAR : D3DTFG_POINT; -} - -//--------------------------------------------------------------------------- - -void _gldConvertMinFilter( - GLenum minfilter, - D3DTEXTUREMINFILTER *min_filter, - D3DTEXTUREMIPFILTER *mip_filter) -{ - switch (minfilter) { - case GL_NEAREST: - *min_filter = D3DTFN_POINT; - *mip_filter = D3DTFP_NONE; - break; - case GL_LINEAR: - *min_filter = D3DTFN_LINEAR; - *mip_filter = D3DTFP_NONE; - break; - case GL_NEAREST_MIPMAP_NEAREST: - *min_filter = D3DTFN_POINT; - *mip_filter = D3DTFP_POINT; - break; - case GL_LINEAR_MIPMAP_NEAREST: - *min_filter = D3DTFN_LINEAR; - *mip_filter = D3DTFP_POINT; - break; - case GL_NEAREST_MIPMAP_LINEAR: - *min_filter = D3DTFN_POINT; - *mip_filter = D3DTFP_LINEAR; - break; - case GL_LINEAR_MIPMAP_LINEAR: - *min_filter = D3DTFN_LINEAR; - *mip_filter = D3DTFP_LINEAR; - break; - default: - ASSERT(0); - } -} - -//--------------------------------------------------------------------------- - -D3DX_SURFACEFORMAT _gldGLFormatToD3DFormat( - GLenum internalFormat) -{ - switch (internalFormat) { - case GL_INTENSITY: - case GL_INTENSITY4: - case GL_INTENSITY8: - case GL_INTENSITY12: - case GL_INTENSITY16: - // LUNIMANCE != INTENSITY, but D3D doesn't have I8 textures - return D3DX_SF_L8; - case 1: - case GL_LUMINANCE: - case GL_LUMINANCE4: - case GL_LUMINANCE8: - case GL_LUMINANCE12: - case GL_LUMINANCE16: - return D3DX_SF_L8; - case GL_ALPHA: - case GL_ALPHA4: - case GL_ALPHA8: - case GL_ALPHA12: - case GL_ALPHA16: - return D3DX_SF_A8; - case GL_COLOR_INDEX: - case GL_COLOR_INDEX1_EXT: - case GL_COLOR_INDEX2_EXT: - case GL_COLOR_INDEX4_EXT: - case GL_COLOR_INDEX8_EXT: - case GL_COLOR_INDEX12_EXT: - case GL_COLOR_INDEX16_EXT: - return D3DX_SF_X8R8G8B8; - case 2: - case GL_LUMINANCE_ALPHA: - case GL_LUMINANCE4_ALPHA4: - case GL_LUMINANCE6_ALPHA2: - case GL_LUMINANCE8_ALPHA8: - case GL_LUMINANCE12_ALPHA4: - case GL_LUMINANCE12_ALPHA12: - case GL_LUMINANCE16_ALPHA16: - return D3DX_SF_A8L8; - case GL_R3_G3_B2: - // TODO: Mesa does not support RGB332 internally - return D3DX_SF_X4R4G4B4; //D3DFMT_R3G3B2; - case GL_RGB4: - return D3DX_SF_X4R4G4B4; - case GL_RGB5: - return D3DX_SF_R5G5B5; - case 3: - case GL_RGB: - case GL_RGB8: - case GL_RGB10: - case GL_RGB12: - case GL_RGB16: - return D3DX_SF_R8G8B8; - case GL_RGBA4: - return D3DX_SF_A4R4G4B4; - case 4: - case GL_RGBA: - case GL_RGBA2: - case GL_RGBA8: - case GL_RGB10_A2: - case GL_RGBA12: - case GL_RGBA16: - return D3DX_SF_A8R8G8B8; - case GL_RGB5_A1: - return D3DX_SF_A1R5G5B5; - } - - ASSERT(0); - - // Return an acceptable default - return D3DX_SF_A8R8G8B8; -} - -//--------------------------------------------------------------------------- - -GLenum _gldDecodeBaseFormat( - IDirectDrawSurface7 *pTex) -{ - // Examine Direct3D texture and return base OpenGL internal texture format - // NOTE: We can't use any base format info from Mesa because D3D might have - // used a different texture format when we used D3DXCreateTexture(). - - // Base internal format is one of (Red Book p355): - // GL_ALPHA, - // GL_LUMINANCE, - // GL_LUMINANCE_ALPHA, - // GL_INTENSITY, - // GL_RGB, - // GL_RGBA - - // NOTE: INTENSITY not used (not supported by Direct3D) - // LUMINANCE has same texture functions as RGB - // LUMINANCE_ALPHA has same texture functions as RGBA - - // TODO: cache format instead of using GetLevelDesc() -// D3DSURFACE_DESC desc; -// _GLD_DX7_TEX(GetLevelDesc(pTex, 0, &desc)); - - D3DX_SURFACEFORMAT sf; - - sf = _gldD3DXFormatFromSurface(pTex); - - switch (sf) { - case D3DX_SF_R8G8B8: - case D3DX_SF_X8R8G8B8: - case D3DX_SF_R5G6B5: - case D3DX_SF_R5G5B5: - case D3DX_SF_R3G3B2: - case D3DX_SF_X4R4G4B4: - case D3DX_SF_PALETTE8: - case D3DX_SF_L8: - return GL_RGB; - case D3DX_SF_A8R8G8B8: - case D3DX_SF_A1R5G5B5: - case D3DX_SF_A4R4G4B4: -// case D3DX_SF_A8R3G3B2: // Unsupported by DX7 -// case D3DX_SF_A8P8: // Unsupported by DX7 - case D3DX_SF_A8L8: -// case D3DX_SF_A4L4: // Unsupported by DX7 - return GL_RGBA; - case D3DX_SF_A8: - return GL_ALPHA; - // Compressed texture formats. Need to check these... - case D3DX_SF_DXT1: - return GL_RGBA; -// case D3DX_SF_DXT2: // Unsupported by DX7 - return GL_RGB; - case D3DX_SF_DXT3: - return GL_RGBA; -// case D3DX_SF_DXT4: // Unsupported by DX7 - return GL_RGB; - case D3DX_SF_DXT5: - return GL_RGBA; - } - - // Fell through. Return arbitary default. - ASSERT(0); // BANG! - return GL_RGBA; -} - -//--------------------------------------------------------------------------- - -const struct gl_texture_format* _gldMesaFormatForD3DFormat( - D3DX_SURFACEFORMAT d3dfmt) -{ - switch (d3dfmt) { - case D3DX_SF_A8R8G8B8: - return &_mesa_texformat_argb8888; - case D3DX_SF_R8G8B8: - return &_mesa_texformat_rgb888; - case D3DX_SF_R5G6B5: - return &_mesa_texformat_rgb565; - case D3DX_SF_A4R4G4B4: - return &_mesa_texformat_argb4444; - case D3DX_SF_A1R5G5B5: - return &_mesa_texformat_argb1555; - case D3DX_SF_A8L8: - return &_mesa_texformat_al88; - case D3DX_SF_R3G3B2: - return &_mesa_texformat_rgb332; - case D3DX_SF_A8: - return &_mesa_texformat_a8; - case D3DX_SF_L8: - return &_mesa_texformat_l8; - case D3DX_SF_X8R8G8B8: - return &_gld_texformat_X8R8G8B8; - case D3DX_SF_R5G5B5: - return &_gld_texformat_X1R5G5B5; - case D3DX_SF_X4R4G4B4: - return &_gld_texformat_X4R4G4B4; - } - - // If we reach here then we've made an error somewhere else - // by allowing a format that is not supported. - ASSERT(0); - - return NULL; // Shut up compiler warning -} - -//--------------------------------------------------------------------------- - -D3DX_SURFACEFORMAT _gldD3DXFormatFromSurface( - IDirectDrawSurface7 *pSurface) -{ - DDPIXELFORMAT ddpf; - - ddpf.dwSize = sizeof(ddpf); - - // Obtain pixel format of surface - _GLD_DX7_TEX(GetPixelFormat(pSurface, &ddpf)); - // Decode to D3DX surface format - return D3DXMakeSurfaceFormat(&ddpf); -} - -//--------------------------------------------------------------------------- - -void _gldClearSurface( - IDirectDrawSurface *pSurface, - D3DCOLOR dwColour) -{ - DDBLTFX bltFX; // Used for colour fill - - // Initialise struct - bltFX.dwSize = sizeof(bltFX); - // Set clear colour - bltFX.dwFillColor = dwColour; - // Clear surface. HW accelerated if available. - IDirectDrawSurface7_Blt(pSurface, NULL, NULL, NULL, DDBLT_COLORFILL, &bltFX); -} - -//--------------------------------------------------------------------------- -// Copy* functions -//--------------------------------------------------------------------------- - -void gldCopyTexImage1D_DX7( - GLcontext *ctx, - GLenum target, GLint level, - GLenum internalFormat, - GLint x, GLint y, - GLsizei width, GLint border ) -{ - // TODO -} - -//--------------------------------------------------------------------------- - -void gldCopyTexImage2D_DX7( - GLcontext *ctx, - GLenum target, - GLint level, - GLenum internalFormat, - GLint x, - GLint y, - GLsizei width, - GLsizei height, - GLint border) -{ - // TODO -} - -//--------------------------------------------------------------------------- - -void gldCopyTexSubImage1D_DX7( - GLcontext *ctx, - GLenum target, GLint level, - GLint xoffset, GLint x, GLint y, GLsizei width ) -{ - // TODO -} - -//--------------------------------------------------------------------------- - -void gldCopyTexSubImage2D_DX7( - GLcontext *ctx, - GLenum target, - GLint level, - GLint xoffset, - GLint yoffset, - GLint x, - GLint y, - GLsizei width, - GLsizei height) -{ - // TODO -} - -//--------------------------------------------------------------------------- - -void gldCopyTexSubImage3D_DX7( - GLcontext *ctx, - GLenum target, - GLint level, - GLint xoffset, - GLint yoffset, - GLint zoffset, - GLint x, - GLint y, - GLsizei width, - GLsizei height ) -{ - // TODO ? -} - -//--------------------------------------------------------------------------- -// Bitmap/Pixel functions -//--------------------------------------------------------------------------- - -#define GLD_FLIP_Y(y) (gldCtx->dwHeight - (y)) - -#define _GLD_FVF_IMAGE (D3DFVF_XYZRHW | D3DFVF_TEX1) - -typedef struct { - FLOAT x, y; // 2D raster coords - FLOAT z; // depth value - FLOAT rhw; // reciprocal homogenous W (always 1.0f) - FLOAT tu, tv; // texture coords -} _GLD_IMAGE_VERTEX; - -//--------------------------------------------------------------------------- - -HRESULT _gldDrawPixels( - GLcontext *ctx, - BOOL bChromakey, // Alpha test for glBitmap() images - GLint x, // GL x position - GLint y, // GL y position (needs flipping) - GLsizei width, // Width of input image - GLsizei height, // Height of input image - IDirectDrawSurface7 *pImage) -{ - // - // Draw input image as texture implementing PixelZoom and clipping. - // Any fragment operations currently enabled will be used. - // - - // NOTE: This DX7 version does not create a new texture in which - // to copy the input image, as the image is already a texture. - - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - DDSURFACEDESC2 ddsd; - _GLD_IMAGE_VERTEX v[4]; - - float ZoomWidth, ZoomHeight; - float ScaleWidth, ScaleHeight; - - // Fixup for rasterisation rules - const float cfEpsilon = 1.0f / (float)height; - - // - // Set up the quad like this (ascii-art ahead!) - // - // 3--2 - // | | - // 0--1 - // - // - - // Set depth - v[0].z = v[1].z = v[2].z = v[3].z = ctx->Current.RasterPos[2]; - // Set Reciprocal Homogenous W - v[0].rhw = v[1].rhw = v[2].rhw = v[3].rhw = 1.0f; - - // Set texcoords - // Examine texture size - if different to input width and height - // then we'll need to munge the texcoords to fit. - ddsd.dwSize = sizeof(DDSURFACEDESC2); - IDirectDrawSurface7_GetSurfaceDesc(pImage, &ddsd); - ScaleWidth = (float)width / (float)ddsd.dwWidth; - ScaleHeight = (float)height / (float)ddsd.dwHeight; - v[0].tu = 0.0f; v[0].tv = 0.0f; - v[1].tu = ScaleWidth; v[1].tv = 0.0f; - v[2].tu = ScaleWidth; v[2].tv = ScaleHeight; - v[3].tu = 0.0f; v[3].tv = ScaleHeight; - - // Set raster positions - ZoomWidth = (float)width * ctx->Pixel.ZoomX; - ZoomHeight = (float)height * ctx->Pixel.ZoomY; - - v[0].x = x; v[0].y = GLD_FLIP_Y(y+cfEpsilon); - v[1].x = x+ZoomWidth; v[1].y = GLD_FLIP_Y(y+cfEpsilon); - v[2].x = x+ZoomWidth; v[2].y = GLD_FLIP_Y(y+ZoomHeight+cfEpsilon); - v[3].x = x; v[3].y = GLD_FLIP_Y(y+ZoomHeight+cfEpsilon); - - // Draw image with full HW acceleration - // NOTE: Be nice to use a State Block for all this state... - IDirect3DDevice7_SetTexture(gld->pDev, 0, pImage); - IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE); - IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_CLIPPING, TRUE); - IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_MINFILTER, D3DTFN_POINT); - IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_MIPFILTER, D3DTFP_POINT); - IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_MAGFILTER, D3DTFG_POINT); - IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); - IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); - IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); - IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - // Ensure texture unit 1 is disabled - IDirect3DDevice7_SetTextureStageState(gld->pDev, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); - IDirect3DDevice7_SetTextureStageState(gld->pDev, 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); - - // - // Emulate Chromakey with an Alpha Test. - // [Alpha Test is more widely supported anyway] - // - if (bChromakey) { - // Switch on alpha testing - IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_ALPHATESTENABLE, TRUE); - // Fragment passes is alpha is greater than reference value - IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_ALPHAFUNC, D3DCMP_GREATER); - // Set alpha reference value between Bitmap alpha values of - // zero (transparent) and one (opaque). - IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_ALPHAREF, 0x7f); - } - - IDirect3DDevice7_DrawPrimitive(gld->pDev, D3DPT_TRIANGLEFAN, _GLD_FVF_IMAGE, &v, 4, 0); - - // Reset state to before we messed it up - FLUSH_VERTICES(ctx, _NEW_ALL); - - return S_OK; -} - -//--------------------------------------------------------------------------- - -void gld_DrawPixels_DX7( - GLcontext *ctx, - GLint x, GLint y, GLsizei width, GLsizei height, - GLenum format, GLenum type, - const struct gl_pixelstore_attrib *unpack, - const GLvoid *pixels ) -{ - GLD_context *gldCtx; - GLD_driver_dx7 *gld; - - IDirectDrawSurface7 *pImage; - HRESULT hr; - DDSURFACEDESC2 ddsd; - DWORD dwFlags; - D3DX_SURFACEFORMAT sf; - DWORD dwMipmaps; - - const struct gl_texture_format *MesaFormat; - - MesaFormat = _mesa_choose_tex_format(ctx, format, format, type); - - gldCtx = GLD_GET_CONTEXT(ctx); - gld = GLD_GET_DX7_DRIVER(gldCtx); - - dwFlags = D3DX_TEXTURE_NOMIPMAP; - sf = D3DX_SF_A8R8G8B8; - dwMipmaps = 1; - - hr = D3DXCreateTexture( - gld->pDev, - &dwFlags, - &width, &height, - &sf, // format - NULL, // palette - &pImage, // Output texture - &dwMipmaps); - if (FAILED(hr)) { - return; - } - - // D3DXCreateTexture() may not clear the texture is creates. - _gldClearSurface(pImage, 0); - - // - // Use Mesa to fill in image - // - - // Lock all of surface - ddsd.dwSize = sizeof(DDSURFACEDESC2); - dwFlags = DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT; - hr = IDirectDrawSurface7_Lock(pImage, NULL, &ddsd, dwFlags, NULL); - if (FAILED(hr)) { - SAFE_RELEASE_SURFACE7(pImage); - return; - } - - // unpack image, apply transfer ops and store directly in texture - MesaFormat->StoreImage( - ctx, - 2, - GL_RGBA, - &_mesa_texformat_argb8888, - ddsd.lpSurface, - width, height, 1, 0, 0, 0, - ddsd.lPitch, - 0, /* dstImageStride */ - format, type, pixels, unpack); - - IDirectDrawSurface7_Unlock(pImage, NULL); - - _gldDrawPixels(ctx, FALSE, x, y, width, height, pImage); - - SAFE_RELEASE_SURFACE7(pImage); -} - -//--------------------------------------------------------------------------- - -void gld_ReadPixels_DX7( - GLcontext *ctx, - GLint x, GLint y, GLsizei width, GLsizei height, - GLenum format, GLenum type, - const struct gl_pixelstore_attrib *pack, - GLvoid *dest) -{ -// TODO -#if 0 - GLD_context *gldCtx; - GLD_driver_dx7 *gld; - - IDirect3DSurface8 *pBackbuffer = NULL; - IDirect3DSurface8 *pNativeImage = NULL; - IDirect3DSurface8 *pCanonicalImage = NULL; - - D3DSURFACE_DESC d3dsd; - RECT rcSrc; // Source rect - POINT ptDst; // Dest point - HRESULT hr; - D3DLOCKED_RECT d3dLockedRect; - struct gl_pixelstore_attrib srcPacking; - int i; - GLint DstRowStride; - const struct gl_texture_format *MesaFormat; - - switch (format) { - case GL_STENCIL_INDEX: - case GL_DEPTH_COMPONENT: - return; - } - - MesaFormat = _mesa_choose_tex_format(ctx, format, format, type); - DstRowStride = _mesa_image_row_stride(pack, width, format, type); - - gldCtx = GLD_GET_CONTEXT(ctx); - gld = GLD_GET_DX7_DRIVER(gldCtx); - - // Get backbuffer - hr = IDirect3DDevice8_GetBackBuffer( - gld->pDev, - 0, // First backbuffer - D3DBACKBUFFER_TYPE_MONO, - &pBackbuffer); - if (FAILED(hr)) - return; - - // Get backbuffer description - hr = IDirect3DSurface8_GetDesc(pBackbuffer, &d3dsd); - if (FAILED(hr)) { - goto gld_ReadPixels_DX7_return; - } - - // Create a surface compatible with backbuffer - hr = IDirect3DDevice8_CreateImageSurface( - gld->pDev, - width, - height, - d3dsd.Format, - &pNativeImage); - if (FAILED(hr)) { - goto gld_ReadPixels_DX7_return; - } - - // Compute source rect and dest point - SetRect(&rcSrc, 0, 0, width, height); - OffsetRect(&rcSrc, x, GLD_FLIP_HEIGHT(y, height)); - ptDst.x = ptDst.y = 0; - - // Get source pixels. - // - // This intermediate surface ensure that we can use CopyRects() - // instead of relying on D3DXLoadSurfaceFromSurface(), which may - // try and lock the backbuffer. This way seems safer. - // - hr = IDirect3DDevice8_CopyRects( - gld->pDev, - pBackbuffer, - &rcSrc, - 1, - pNativeImage, - &ptDst); - if (FAILED(hr)) { - goto gld_ReadPixels_DX7_return; - } - - // Create an RGBA8888 surface - hr = IDirect3DDevice8_CreateImageSurface( - gld->pDev, - width, - height, - D3DFMT_A8R8G8B8, - &pCanonicalImage); - if (FAILED(hr)) { - goto gld_ReadPixels_DX7_return; - } - - // Convert to RGBA8888 - hr = D3DXLoadSurfaceFromSurface( - pCanonicalImage, // Dest surface - NULL, NULL, // Dest palette, RECT - pNativeImage, // Src surface - NULL, NULL, // Src palette, RECT - D3DX_FILTER_NONE, // Filter - 0); // Colourkey - if (FAILED(hr)) { - goto gld_ReadPixels_DX7_return; - } - - srcPacking.Alignment = 1; - srcPacking.ImageHeight = height; - srcPacking.LsbFirst = GL_FALSE; - srcPacking.RowLength = 0; - srcPacking.SkipImages = 0; - srcPacking.SkipPixels = 0; - srcPacking.SkipRows = 0; - srcPacking.SwapBytes = GL_FALSE; - - // Lock all of image - hr = IDirect3DSurface8_LockRect(pCanonicalImage, &d3dLockedRect, NULL, 0); - if (FAILED(hr)) { - goto gld_ReadPixels_DX7_return; - } - - // We need to flip the data. Yuck. - // Perhaps Mesa has a span packer we can use in future... - for (i=0; i<height; i++) { - BYTE *pDestRow = (BYTE*)_mesa_image_address(2,pack, dest, width, height, format, type, 0, i, 0); - BYTE *pSrcRow = (BYTE*)d3dLockedRect.pBits + (d3dLockedRect.Pitch * (height-i-1)); - texImage->TexFormat->StoreImage( - ctx, - 2, - GL_RGBA, // base format - MesaFormat, // dst format - pDestRow, // dest addr - width, 1, 1, 0, 0, 0, // src x,y,z & dst offsets x,y,z - DstRowStride, // dst row stride - 0, // dstImageStride - GL_BGRA, // src format - GL_UNSIGNED_BYTE, // src type - pSrcRow, // src addr - &srcPacking); // packing params of source image - } - - IDirect3DSurface8_UnlockRect(pCanonicalImage); - -gld_ReadPixels_DX7_return: - SAFE_RELEASE_SURFACE8(pCanonicalImage); - SAFE_RELEASE_SURFACE8(pNativeImage); - SAFE_RELEASE_SURFACE8(pBackbuffer); -#endif -} - -//--------------------------------------------------------------------------- - -void gld_CopyPixels_DX7( - GLcontext *ctx, - GLint srcx, - GLint srcy, - GLsizei width, - GLsizei height, - GLint dstx, - GLint dsty, - GLenum type) -{ -// TODO -#if 0 - // - // NOTE: Not allowed to copy vidmem to vidmem! - // Therefore we use an intermediate image surface. - // - - GLD_context *gldCtx; - GLD_driver_dx7 *gld; - - IDirect3DSurface8 *pBackbuffer; - D3DSURFACE_DESC d3dsd; - IDirect3DSurface8 *pImage; - RECT rcSrc; // Source rect - POINT ptDst; // Dest point - HRESULT hr; - - // Only backbuffer - if (type != GL_COLOR) - return; - - gldCtx = GLD_GET_CONTEXT(ctx); - gld = GLD_GET_DX7_DRIVER(gldCtx); - - // Get backbuffer - hr = IDirect3DDevice8_GetBackBuffer( - gld->pDev, - 0, // First backbuffer - D3DBACKBUFFER_TYPE_MONO, - &pBackbuffer); - if (FAILED(hr)) - return; - - // Get backbuffer description - hr = IDirect3DSurface8_GetDesc(pBackbuffer, &d3dsd); - if (FAILED(hr)) { - IDirect3DSurface8_Release(pBackbuffer); - return; - } - - // Create a surface compatible with backbuffer - hr = IDirect3DDevice8_CreateImageSurface( - gld->pDev, - width, - height, - d3dsd.Format, - &pImage); - if (FAILED(hr)) { - IDirect3DSurface8_Release(pBackbuffer); - return; - } - - // Compute source rect and dest point - SetRect(&rcSrc, 0, 0, width, height); - OffsetRect(&rcSrc, srcx, GLD_FLIP_HEIGHT(srcy, height)); - ptDst.x = ptDst.y = 0; - - // Get source pixels - hr = IDirect3DDevice8_CopyRects( - gld->pDev, - pBackbuffer, - &rcSrc, - 1, - pImage, - &ptDst); - IDirect3DSurface8_Release(pBackbuffer); - if (FAILED(hr)) { - IDirect3DSurface8_Release(pImage); - return; - } - - _gldDrawPixels(ctx, FALSE, dstx, dsty, width, height, pImage); - - IDirect3DSurface8_Release(pImage); -#endif -} - -//--------------------------------------------------------------------------- - -void gld_Bitmap_DX7( - GLcontext *ctx, - GLint x, - GLint y, - GLsizei width, - GLsizei height, - const struct gl_pixelstore_attrib *unpack, - const GLubyte *bitmap) -{ - GLD_context *gldCtx; - GLD_driver_dx7 *gld; - - IDirectDrawSurface7 *pImage; // Bitmap texture - HRESULT hr; - BYTE *pTempBitmap; // Pointer to unpacked bitmap - D3DCOLOR clBitmapOne; // Opaque bitmap colour - D3DCOLOR clBitmapZero; // Transparent bitmap colour - D3DCOLOR *pBits; // Pointer to texture surface - const GLubyte *src; - int i, j, k; - - DDSURFACEDESC2 ddsd; // Surface desc returned by lock call - DWORD dwFlags; - D3DX_SURFACEFORMAT sf; - DWORD dwMipmaps; - - // Keep a copy of width/height as D3DXCreateTexture() call may alter input dimensions - GLsizei dwWidth = width; - GLsizei dwHeight = height; - - gldCtx = GLD_GET_CONTEXT(ctx); - gld = GLD_GET_DX7_DRIVER(gldCtx); - - // Bail if no bitmap (only raster pos is updated) - if ((bitmap == NULL) && (width==0) && (height==0)) - return; - - // - // TODO: Detect conditions when created texture (pImage) is non-pow2. - // Texture coords may need to be adjusted to compensate. - // - - clBitmapZero = D3DCOLOR_RGBA(0,0,0,0); // NOTE: Alpha is Zero - clBitmapOne = D3DCOLOR_COLORVALUE( - ctx->Current.RasterColor[0], - ctx->Current.RasterColor[1], - ctx->Current.RasterColor[2], - 1.0f); // NOTE: Alpha is One - - // Use Mesa to unpack bitmap into a canonical format - pTempBitmap = _mesa_unpack_bitmap(width, height, bitmap, unpack); - if (pTempBitmap == NULL) - return; - - // Flags for texture creation - dwFlags = D3DX_TEXTURE_NOMIPMAP; - sf = D3DX_SF_A8R8G8B8; - dwMipmaps = 1; - - // Create a D3D texture to hold the bitmap - hr = D3DXCreateTexture( - gld->pDev, - &dwFlags, - &dwWidth, &dwHeight, - &sf, // format - NULL, // palette - &pImage, // Output texture - &dwMipmaps); - if (FAILED(hr)) { - FREE(pTempBitmap); - return; - } - - // D3DXCreateTexture may return a texture bigger than we asked for - // (i.e. padded to POW2) so let's clear the entire image bitmap. - // Additional: Looks like this is not strictly necessary. -// _gldClearSurface(pImage, clBitmapZero); - - ddsd.dwSize = sizeof(DDSURFACEDESC2); - dwFlags = DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT; - hr = IDirectDrawSurface7_Lock(pImage, NULL, &ddsd, dwFlags, NULL); - if (FAILED(hr)) { - FREE(pTempBitmap); - SAFE_RELEASE_SURFACE7(pImage); - return; - } - -#if 0 - // DEBUG CODE - if (!(width==ddsd.dwWidth && height==ddsd.dwHeight)) - ddlogPrintf(GLDLOG_WARN, "gld_Bitmap: In=%d,%d / Tex=%d,%d", width,height,ddsd.dwWidth,ddsd.dwHeight); -#endif - -#if 0 - // DEBUG CODE - ddlogPrintf(GLDLOG_SYSTEM, "gld_Bitmap: In=%d,%d / Tex=%d,%d", width,height,ddsd.dwWidth,ddsd.dwHeight); - ddlogPrintf(GLDLOG_SYSTEM, "gld_Bitmap: bpp=%d", ddsd.ddpfPixelFormat.dwRGBBitCount); -#endif - - // Cast texel pointer to texture surface. - // We can do this because we used D3DX_SF_A8R8G8B8 as the format - pBits = (D3DCOLOR*)ddsd.lpSurface; - - - // Copy from the input bitmap into the texture - for (i=0; i<height; i++) { - GLubyte byte; - pBits = (D3DCOLOR*)((BYTE*)ddsd.lpSurface + (i*ddsd.lPitch)); - src = (const GLubyte *) _mesa_image_address(2, - &ctx->DefaultPacking, pTempBitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, - 0, i, 0); - for (j=0; j<(width>>3); j++) { - byte = *src++; - for (k=0; k<8; k++) { - *pBits++ = (byte & 128) ? clBitmapOne : clBitmapZero; - byte <<= 1; - } - } - // Fill remaining bits from bitmap - if (width & 7) { - byte = *src; - for (k=0; k<(width & 7); k++) { - *pBits++ = (byte & 128) ? clBitmapOne : clBitmapZero; - byte <<= 1; - } - } - } - - // We're done with the unpacked bitmap - FREE(pTempBitmap); - - // Finished with texture surface - unlock it - IDirectDrawSurface7_Unlock(pImage, NULL); - - // Use internal function to draw bitmap onto rendertarget - _gldDrawPixels(ctx, TRUE, x, y, width, height, pImage); - - // We're done with the bitmap texure - release it - IDirectDrawSurface7_Release(pImage); -} - -//--------------------------------------------------------------------------- -// Texture functions -//--------------------------------------------------------------------------- - -void _gldAllocateTexture( - GLcontext *ctx, - struct gl_texture_object *tObj, - struct gl_texture_image *texImage) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - HRESULT hr; - IDirectDrawSurface7 *pTex; - D3DX_SURFACEFORMAT d3dFormat; - DWORD dwFlags; - DWORD dwMipmaps; - DWORD dwWidth, dwHeight; - - if (!tObj || !texImage) - return; - - pTex = (IDirectDrawSurface7*)tObj->DriverData; - if (pTex) { - // Decide whether we can keep existing D3D texture - // by examining top-level surface. - DDSURFACEDESC2 ddsd; - ddsd.dwSize = sizeof(DDSURFACEDESC2); - _GLD_DX7_TEX(GetSurfaceDesc(pTex, &ddsd)); - // Release existing texture if not compatible - if ((ddsd.dwWidth == texImage->Width) || - (ddsd.dwHeight == texImage->Height)) - { - return; // Keep the existing texture - } - tObj->DriverData = NULL; - _GLD_DX7_TEX(Release(pTex)); - } - - dwFlags = (glb.bUseMipmaps) ? 0 : D3DX_TEXTURE_NOMIPMAP; - dwMipmaps = (glb.bUseMipmaps) ? D3DX_DEFAULT : 1; - dwWidth = texImage->Width; - dwHeight = texImage->Height; - - d3dFormat = _gldGLFormatToD3DFormat(texImage->IntFormat); - hr = D3DXCreateTexture( - gld->pDev, - &dwFlags, - &dwWidth, - &dwHeight, - &d3dFormat, - NULL, - &pTex, - &dwMipmaps); - if (FAILED(hr)) { - gldLogError(GLDLOG_ERROR, "AllocateTexture failed", hr); - } - tObj->DriverData = pTex; -} - -//--------------------------------------------------------------------------- - -const struct gl_texture_format* gld_ChooseTextureFormat_DX7( - GLcontext *ctx, - GLint internalFormat, - GLenum srcFormat, - GLenum srcType) -{ - // [Based on mesa_choose_tex_format()] - // - // We will choose only texture formats that are supported - // by Direct3D. If the hardware doesn't support a particular - // texture format, then the D3DX texture calls that we use - // will automatically use a HW supported format. - // - // The most critical aim is to reduce copying; if we can use - // texture-image data directly then it will be a big performance assist. - // - - switch (internalFormat) { - case GL_INTENSITY: - case GL_INTENSITY4: - case GL_INTENSITY8: - case GL_INTENSITY12: - case GL_INTENSITY16: - return &_mesa_texformat_l8; // D3DFMT_L8 - case 1: - case GL_LUMINANCE: - case GL_LUMINANCE4: - case GL_LUMINANCE8: - case GL_LUMINANCE12: - case GL_LUMINANCE16: - return &_mesa_texformat_l8; // D3DFMT_L8 - case GL_ALPHA: - case GL_ALPHA4: - case GL_ALPHA8: - case GL_ALPHA12: - case GL_ALPHA16: - return &_mesa_texformat_a8; // D3DFMT_A8 - case GL_COLOR_INDEX: - case GL_COLOR_INDEX1_EXT: - case GL_COLOR_INDEX2_EXT: - case GL_COLOR_INDEX4_EXT: - case GL_COLOR_INDEX8_EXT: - case GL_COLOR_INDEX12_EXT: - case GL_COLOR_INDEX16_EXT: - return &_mesa_texformat_rgb565; // D3DFMT_R5G6B5 - // Mesa will convert this for us later... - // return &_mesa_texformat_ci8; // D3DFMT_R5G6B5 - case 2: - case GL_LUMINANCE_ALPHA: - case GL_LUMINANCE4_ALPHA4: - case GL_LUMINANCE6_ALPHA2: - case GL_LUMINANCE8_ALPHA8: - case GL_LUMINANCE12_ALPHA4: - case GL_LUMINANCE12_ALPHA12: - case GL_LUMINANCE16_ALPHA16: - return &_mesa_texformat_al88; // D3DFMT_A8L8 - case GL_R3_G3_B2: - return &_mesa_texformat_rgb332; // D3DFMT_R3G3B2 - case GL_RGB4: - case GL_RGBA4: - case GL_RGBA2: - return &_mesa_texformat_argb4444; // D3DFMT_A4R4G4B4 - case 3: - case GL_RGB: - case GL_RGB5: - case GL_RGB8: - case GL_RGB10: - case GL_RGB12: - case GL_RGB16: - return &_mesa_texformat_rgb565; - case 4: - case GL_RGBA: - case GL_RGBA8: - case GL_RGB10_A2: - case GL_RGBA12: - case GL_RGBA16: - return &_mesa_texformat_argb8888; - case GL_RGB5_A1: - return &_mesa_texformat_argb1555; - default: - _mesa_problem(NULL, "unexpected format in fxDDChooseTextureFormat"); - return NULL; - } -} - -//--------------------------------------------------------------------------- - -/* -// Safer(?), slower version. -void gld_TexImage2D_DX7( - GLcontext *ctx, - GLenum target, - GLint level, - GLint internalFormat, - GLint width, - GLint height, - GLint border, - GLenum format, - GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *tObj, - struct gl_texture_image *texImage) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - IDirect3DTexture8 *pTex; - IDirect3DSurface8 *pSurface; - RECT rcSrcRect; - HRESULT hr; - GLint texelBytes = 4; - GLvoid *tempImage; - - if (!tObj || !texImage) - return; - - if (level == 0) { - _gldAllocateTexture(ctx, tObj, texImage); - } - - pTex = (IDirect3DTexture8*)tObj->DriverData; - if (!pTex) - return; // Texture has not been created - if (level >= IDirect3DTexture8_GetLevelCount(pTex)) - return; // Level does not exist - hr = IDirect3DTexture8_GetSurfaceLevel(pTex, level, &pSurface); - if (FAILED(hr)) - return; // Surface level doesn't exist (or just a plain error) - - tempImage = MALLOC(width * height * texelBytes); - if (!tempImage) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); - IDirect3DSurface8_Release(pSurface); - return; - } - // unpack image, apply transfer ops and store in tempImage - texImage->TexFormat->StoreImage(ctx, 2, texImage->Format, - &_mesa_texformat_argb8888, // dest format - tempImage, - width, height, 1, 0, 0, 0, - width * texelBytes, - 0, // dstImageStride - format, type, pixels, packing); - - SetRect(&rcSrcRect, 0, 0, width, height); - D3DXLoadSurfaceFromMemory( - pSurface, - NULL, - NULL, - tempImage, - D3DFMT_A8R8G8B8, - width * texelBytes, - NULL, - &rcSrcRect, - D3DX_FILTER_NONE, - 0); - - FREE(tempImage); - IDirect3DSurface8_Release(pSurface); -} -*/ - -//--------------------------------------------------------------------------- - -// Faster, more efficient version. -// Copies subimage straight to dest texture -void gld_TexImage2D_DX7( - GLcontext *ctx, - GLenum target, - GLint level, - GLint internalFormat, - GLint width, - GLint height, - GLint border, - GLenum format, - GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *tObj, - struct gl_texture_image *texImage) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - IDirectDrawSurface7 *pTex = NULL; - IDirectDrawSurface7 *pSurface = NULL; - HRESULT hr; - DDSURFACEDESC2 ddsd; - int i; - DDSCAPS2 ddsCaps; - - if (!tObj || !texImage) - return; - - // GLQUAKE FIX - // Test for input alpha data with non-alpha internalformat - if (((internalFormat==3) || (internalFormat==GL_RGB)) && (format==GL_RGBA)) { - // Input format has alpha, but a non-alpha format has been requested. - texImage->IntFormat = GL_RGBA; - internalFormat = GL_RGBA; - } - - if (level == 0) { - _gldAllocateTexture(ctx, tObj, texImage); - } - - pTex = (IDirectDrawSurface7*)tObj->DriverData; - if (!pTex) { - ASSERT(0); - return; // Texture has not been created - } - - pSurface = pTex; - if (level != 0) { - ddsd.dwSize = sizeof(ddsd); - _GLD_DX7_TEX(GetSurfaceDesc(pTex, &ddsd)); - if ((level > 0) && (level >= ddsd.dwMipMapCount)) - return; // Level does not exist - ZeroMemory(&ddsCaps, sizeof(ddsCaps)); - for (i=0; i<level; i++) { - ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP; - hr = IDirectDrawSurface7_GetAttachedSurface( - pSurface, - &ddsCaps, - &pSurface); - if (SUCCEEDED(hr)) { - IDirectDrawSurface7_Release(pSurface); - } else { - ; - } - } - } - - // Lock all of surface - ddsd.dwSize = sizeof(ddsd); - hr = IDirectDrawSurface7_Lock(pSurface, NULL, &ddsd, 0, 0); - if (FAILED(hr)) { - IDirectDrawSurface7_Release(pSurface); - return; - } - - // unpack image, apply transfer ops and store directly in texture - texImage->TexFormat->StoreImage( - ctx, - 2, - texImage->Format, - //_gldMesaFormatForD3DFormat(d3dsd.Format), - _gldMesaFormatForD3DFormat(_gldD3DXFormatFromSurface(pSurface)), - ddsd.lpSurface, - width, height, 1, 0, 0, 0, - ddsd.lPitch, - 0, // dstImageStride - format, type, pixels, packing); - - IDirectDrawSurface7_Unlock(pSurface, NULL); -} - -//--------------------------------------------------------------------------- - -void gld_TexImage1D_DX7(GLcontext *ctx, GLenum target, GLint level, - GLint internalFormat, - GLint width, GLint border, - GLenum format, GLenum type, const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage ) -{ - // A 1D texture is a 2D texture with a height of zero - gld_TexImage2D_DX7(ctx, target, level, internalFormat, width, 1, border, format, type, pixels, packing, texObj, texImage); -} - -//--------------------------------------------------------------------------- - -/* -void gld_TexSubImage2D( GLcontext *ctx, GLenum target, GLint level, - GLint xoffset, GLint yoffset, - GLsizei width, GLsizei height, - GLenum format, GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *tObj, - struct gl_texture_image *texImage ) -{ - GLD_GET_CONTEXT - IDirect3DTexture8 *pTex; - IDirect3DSurface8 *pSurface; - D3DFORMAT d3dFormat; - HRESULT hr; - GLint texelBytes = 4; - GLvoid *tempImage; - RECT rcSrcRect; - RECT rcDstRect; - - if (!tObj || !texImage) - return; - - pTex = (IDirect3DTexture8*)tObj->DriverData; - if (!pTex) - return; // Texture has not been created - if (level >= _GLD_DX8_TEX(GetLevelCount(pTex)) - return; // Level does not exist - hr = _GLD_DX8_TEX(GetSurfaceLevel(pTex, level, &pSurface); - if (FAILED(hr)) - return; // Surface level doesn't exist (or just a plain error) - - d3dFormat = _gldGLFormatToD3DFormat(texImage->Format); - tempImage = MALLOC(width * height * texelBytes); - if (!tempImage) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); - IDirect3DSurface8_Release(pSurface); - return; - } - - // unpack image, apply transfer ops and store in tempImage - texImage->TexFormat->StoreImage(ctx, 2, texImage->Format, - &_mesa_texformat_argb8888, // dest format - tempImage, - width, height, 1, 0, 0, 0, - width * texelBytes, - 0, // dstImageStride - format, type, pixels, packing); - - // Source rectangle is whole of input image - SetRect(&rcSrcRect, 0, 0, width, height); - - // Dest rectangle must be offset to dest image - SetRect(&rcDstRect, 0, 0, width, height); - OffsetRect(&rcDstRect, xoffset, yoffset); - - D3DXLoadSurfaceFromMemory( - pSurface, - NULL, - &rcDstRect, - tempImage, - D3DFMT_A8R8G8B8, - width * texelBytes, - NULL, - &rcSrcRect, - D3DX_FILTER_NONE, - 0); - - FREE(tempImage); - IDirect3DSurface8_Release(pSurface); -} -*/ - -//--------------------------------------------------------------------------- - -// Faster, more efficient version. -// Copies subimage straight to dest texture -void gld_TexSubImage2D_DX7( GLcontext *ctx, GLenum target, GLint level, - GLint xoffset, GLint yoffset, - GLsizei width, GLsizei height, - GLenum format, GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *tObj, - struct gl_texture_image *texImage ) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - IDirectDrawSurface7 *pTex; - IDirectDrawSurface7 *pSurface; - HRESULT hr; - RECT rcDstRect; - DDSURFACEDESC2 ddsd; - int i; - DDSCAPS2 ddsCaps; - - if (!tObj || !texImage) - return; - - pTex = (IDirectDrawSurface7*)tObj->DriverData; - if (!pTex) - return; // Texture has not been created - - __try { - - ddsd.dwSize = sizeof(ddsd); - _GLD_DX7_TEX(GetSurfaceDesc(pTex, &ddsd)); - if ((level > 0) && (level >= ddsd.dwMipMapCount)) - return; // Level does not exist - - ZeroMemory(&ddsCaps, sizeof(ddsCaps)); - pSurface = pTex; - for (i=0; i<level; i++) { - ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP; - hr = IDirectDrawSurface7_GetAttachedSurface( - pSurface, - &ddsCaps, - &pSurface); - if(SUCCEEDED(hr)) { - IDirectDrawSurface7_Release(pSurface); - } else { - return; - } - } - - // Dest rectangle must be offset to dest image - SetRect(&rcDstRect, 0, 0, width, height); - OffsetRect(&rcDstRect, xoffset, yoffset); - - // Lock sub-rect of surface - hr = IDirectDrawSurface7_Lock(pSurface, &rcDstRect, &ddsd, 0, 0); - if (FAILED(hr)) { - IDirectDrawSurface7_Release(pSurface); - return; - } - - // unpack image, apply transfer ops and store directly in texture - texImage->TexFormat->StoreImage(ctx, 2, texImage->Format, - _gldMesaFormatForD3DFormat(_gldD3DXFormatFromSurface(pSurface)), - ddsd.lpSurface, - width, height, 1, - 0, 0, 0, // NOTE: d3dLockedRect.pBits is already offset!!! - ddsd.lPitch, - 0, // dstImageStride - format, type, pixels, packing); - - - IDirectDrawSurface7_Unlock(pSurface, &rcDstRect); - } - __except(EXCEPTION_EXECUTE_HANDLER) { - ; - } -} - -//--------------------------------------------------------------------------- - -void gld_TexSubImage1D_DX7( GLcontext *ctx, GLenum target, GLint level, - GLint xoffset, GLsizei width, - GLenum format, GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage ) -{ - gld_TexSubImage2D_DX7(ctx, target, level, xoffset, 0, width, 1, format, type, pixels, packing, texObj, texImage); -} - -//--------------------------------------------------------------------------- - -void gld_DeleteTexture_DX7( - GLcontext *ctx, - struct gl_texture_object *tObj) -{ - GLD_context *gld = (GLD_context*)(ctx->DriverCtx); - - __try { - - if (tObj) { - IDirectDrawSurface7 *pTex = (IDirectDrawSurface7*)tObj->DriverData; - if (pTex) { -/* // Make sure texture is not bound to a stage before releasing it - for (int i=0; i<MAX_TEXTURE_UNITS; i++) { - if (gld->CurrentTexture[i] == pTex) { - gld->pDev->SetTexture(i, NULL); - gld->CurrentTexture[i] = NULL; - } - }*/ - _GLD_DX7_TEX(Release(pTex)); - tObj->DriverData = NULL; - } - } - - } - __except(EXCEPTION_EXECUTE_HANDLER) { - ; - } -} - -//--------------------------------------------------------------------------- - -__inline void _gldSetColorOps( - const GLD_driver_dx7 *gld, - GLuint unit, - DWORD ColorArg1, - D3DTEXTUREOP ColorOp, - DWORD ColorArg2) -{ - _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLORARG1, ColorArg1)); - _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLOROP, ColorOp)); - _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLORARG2, ColorArg2)); -} - -//--------------------------------------------------------------------------- - -__inline void _gldSetAlphaOps( - const GLD_driver_dx7 *gld, - GLuint unit, - DWORD AlphaArg1, - D3DTEXTUREOP AlphaOp, - DWORD AlphaArg2) -{ - _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ALPHAARG1, AlphaArg1)); - _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ALPHAOP, AlphaOp)); - _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ALPHAARG2, AlphaArg2)); -} - -//--------------------------------------------------------------------------- - -void gldUpdateTextureUnit( - GLcontext *ctx, - GLuint unit, - BOOL bPassThrough) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - D3DTEXTUREMINFILTER minfilter; - D3DTEXTUREMIPFILTER mipfilter; - GLenum BaseFormat; - DWORD dwColorArg0; - int iTexEnv = 0; - GLD_texenv *pTexenv; - - // NOTE: If bPassThrough is FALSE then texture stage can be - // disabled otherwise it must pass-through it's current fragment. - - const struct gl_texture_unit *pUnit = &ctx->Texture.Unit[unit]; - const struct gl_texture_object *tObj = pUnit->_Current; - - IDirectDrawSurface7 *pTex = NULL; - if (tObj) { - pTex = (IDirectDrawSurface7*)tObj->DriverData; - } - - __try { - - // Enable texturing if unit is enabled and a valid D3D texture exists - // Mesa 5: TEXTUREn_x altered to TEXTURE_nD_BIT - //if (pTex && (pUnit->Enabled & (TEXTURE0_1D | TEXTURE0_2D))) { - if (pTex && (pUnit->_ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT))) { - // Enable texturing - _GLD_DX7_DEV(SetTexture(gld->pDev, unit, pTex)); - } else { - // Disable texturing, then return - _GLD_DX7_DEV(SetTexture(gld->pDev, unit, NULL)); - if (bPassThrough) { - _gldSetColorOps(gld, unit, D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_DIFFUSE); - _gldSetAlphaOps(gld, unit, D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_DIFFUSE); - } else { - _gldSetColorOps(gld, unit, D3DTA_TEXTURE, D3DTOP_DISABLE, D3DTA_DIFFUSE); - _gldSetAlphaOps(gld, unit, D3DTA_TEXTURE, D3DTOP_DISABLE, D3DTA_DIFFUSE); - } - return; - } - - // Texture parameters - _gldConvertMinFilter(tObj->MinFilter, &minfilter, &mipfilter); - _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_MINFILTER, minfilter)); - _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_MIPFILTER, mipfilter)); - _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_MAGFILTER, _gldConvertMagFilter(tObj->MagFilter))); - _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ADDRESSU, _gldConvertWrap(tObj->WrapS))); - _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ADDRESSV, _gldConvertWrap(tObj->WrapT))); - - // Texture priority - _GLD_DX7_TEX(SetPriority(pTex, (DWORD)(tObj->Priority*65535.0f))); - - // Texture environment - // TODO: Examine input texture for alpha and use specific alpha/non-alpha ops. - // See Page 355 of the Red Book. - BaseFormat = _gldDecodeBaseFormat(pTex); - - switch (BaseFormat) { - case GL_RGB: - iTexEnv = 0; - break; - case GL_RGBA: - iTexEnv = 1; - break; - case GL_ALPHA: - iTexEnv = 2; - break; - } - - switch (pUnit->EnvMode) { - case GL_DECAL: - iTexEnv += 0; - break; - case GL_REPLACE: - iTexEnv += 3; - break; - case GL_MODULATE: - iTexEnv += 6; - break; - case GL_BLEND: - // Set blend colour - // Unsupported by DX7 -// dwColorArg0 = D3DCOLOR_COLORVALUE(pUnit->EnvColor[0], pUnit->EnvColor[1], pUnit->EnvColor[2], pUnit->EnvColor[3]); -// _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLORARG0, dwColorArg0)); -// gldLogMessage(GLDLOG_WARN, "GL_BLEND\n"); - iTexEnv += 9; - break; - case GL_ADD: - iTexEnv += 12; - break; - } - pTexenv = (GLD_texenv*)&gldTexEnv[iTexEnv]; - _gldSetColorOps(gld, unit, pTexenv->ColorArg1, pTexenv->ColorOp, pTexenv->ColorArg2); - _gldSetAlphaOps(gld, unit, pTexenv->AlphaArg1, pTexenv->AlphaOp, pTexenv->AlphaArg2); - - } - __except(EXCEPTION_EXECUTE_HANDLER) { - ; - } -} - -//--------------------------------------------------------------------------- - -void gld_NEW_TEXTURE_DX7( - GLcontext *ctx) -{ - // TODO: Support for three (ATI Radeon) or more (nVidia GeForce3) texture units - - BOOL bUnit0Enabled; - BOOL bUnit1Enabled; - - if (!ctx) - return; // Sanity check - - if (ctx->Const.MaxTextureUnits == 1) { - gldUpdateTextureUnit(ctx, 0, TRUE); - return; - } - - // - // NOTE: THE FOLLOWING RELATES TO TWO TEXTURE UNITS, AND TWO ONLY!! - // - - // Mesa 5: Texture Units altered - bUnit0Enabled = (ctx->Texture.Unit[0]._ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT)) ? TRUE : FALSE; - bUnit1Enabled = (ctx->Texture.Unit[1]._ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT)) ? TRUE : FALSE; - - // If Unit0 is disabled and Unit1 is enabled then we must pass-though - gldUpdateTextureUnit(ctx, 0, (!bUnit0Enabled && bUnit1Enabled) ? TRUE : FALSE); - // We can always disable the last texture unit - gldUpdateTextureUnit(ctx, 1, FALSE); - -#ifdef _DEBUG - { - // Find out whether device supports current renderstates - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - DWORD dwPasses; - _GLD_DX7_DEV(ValidateDevice(gld->pDev, &dwPasses)); -#if 0 - if (FAILED(hr)) { - gldLogError(GLDLOG_ERROR, "ValidateDevice failed", hr); - } -#endif - if (dwPasses != 1) { - gldLogMessage(GLDLOG_ERROR, "ValidateDevice: Can't do in one pass\n"); - } - } -#endif -}; - -//--------------------------------------------------------------------------- diff --git a/src/mesa/drivers/windows/gldirect/dx7/gld_vb_d3d_render_dx7.c b/src/mesa/drivers/windows/gldirect/dx7/gld_vb_d3d_render_dx7.c deleted file mode 100644 index a85620dde8..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx7/gld_vb_d3d_render_dx7.c +++ /dev/null @@ -1,257 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: GLDirect fastpath pipeline stage -* -****************************************************************************/ - -//--------------------------------------------------------------------------- - -//#include "../GLDirect.h" -//#include "../gld_log.h" -//#include "gld_dx8.h" - -#include "dglcontext.h" -#include "ddlog.h" -#include "gld_dx7.h" - -//--------------------------------------------------------------------------- - -#include "glheader.h" -#include "context.h" -#include "macros.h" -// #include "mem.h" -#include "mtypes.h" -//#include "mmath.h" - -#include "math/m_matrix.h" -#include "math/m_xform.h" - -#include "tnl/t_pipeline.h" - -//--------------------------------------------------------------------------- -/* -__inline void _gldSetVertexShaderConstants( - GLcontext *ctx, - GLD_driver_dx8 *gld) -{ - D3DXMATRIX mat, matView, matProj; - GLfloat *pM; - - // Mesa 5: Altered to a Stack - //pM = ctx->ModelView.m; - pM = ctx->ModelviewMatrixStack.Top->m; - matView._11 = pM[0]; - matView._12 = pM[1]; - matView._13 = pM[2]; - matView._14 = pM[3]; - matView._21 = pM[4]; - matView._22 = pM[5]; - matView._23 = pM[6]; - matView._24 = pM[7]; - matView._31 = pM[8]; - matView._32 = pM[9]; - matView._33 = pM[10]; - matView._34 = pM[11]; - matView._41 = pM[12]; - matView._42 = pM[13]; - matView._43 = pM[14]; - matView._44 = pM[15]; - - // Mesa 5: Altered to a Stack - //pM = ctx->ProjectionMatrix.m; - pM = ctx->ProjectionMatrixStack.Top->m; - matProj._11 = pM[0]; - matProj._12 = pM[1]; - matProj._13 = pM[2]; - matProj._14 = pM[3]; - matProj._21 = pM[4]; - matProj._22 = pM[5]; - matProj._23 = pM[6]; - matProj._24 = pM[7]; - matProj._31 = pM[8]; - matProj._32 = pM[9]; - matProj._33 = pM[10]; - matProj._34 = pM[11]; - matProj._41 = pM[12]; - matProj._42 = pM[13]; - matProj._43 = pM[14]; - matProj._44 = pM[15]; - - D3DXMatrixMultiply( &mat, &matView, &matProj ); - D3DXMatrixTranspose( &mat, &mat ); - - _GLD_DX8_DEV(SetVertexShaderConstant(gld->pDev, 0, &mat, 4)); -} -*/ -//--------------------------------------------------------------------------- - -static GLboolean gld_d3d_render_stage_run( - GLcontext *ctx, - struct tnl_pipeline_stage *stage) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - TNLcontext *tnl; - struct vertex_buffer *VB; - tnl_render_func *tab; - GLint pass; - GLD_pb_dx7 *gldPB = &gld->PB3d; - DWORD dwFlags; - -/* - static int count = 0; - count++; - if (count != 2) - return GL_FALSE; -*/ - // The "check" function should disable this stage, - // but we'll test gld->bUseMesaTnL anyway. - if (gld->bUseMesaTnL) { - // Do nothing in this stage, but continue pipeline - return GL_TRUE; - } - - tnl = TNL_CONTEXT(ctx); - VB = &tnl->vb; - pass = 0; - - tnl->Driver.Render.Start( ctx ); - -#if 0 - // For debugging: Useful to see if an app passes colour data in - // an unusual format. - switch (VB->ColorPtr[0]->Type) { - case GL_FLOAT: - ddlogMessage(GLDLOG_SYSTEM, "ColorPtr: GL_FLOAT\n"); - break; - case GL_UNSIGNED_BYTE: - ddlogMessage(GLDLOG_SYSTEM, "ColorPtr: GL_UNSIGNED_BYTE\n"); - break; - default: - ddlogMessage(GLDLOG_SYSTEM, "ColorPtr: *?*\n"); - break; - } -#endif - - tnl->Driver.Render.Points = gld_Points3D_DX7; - if (ctx->_TriangleCaps & DD_FLATSHADE) { - tnl->Driver.Render.Line = gld_Line3DFlat_DX7; - tnl->Driver.Render.Triangle = gld_Triangle3DFlat_DX7; - tnl->Driver.Render.Quad = gld_Quad3DFlat_DX7; - } else { - tnl->Driver.Render.Line = gld_Line3DSmooth_DX7; - tnl->Driver.Render.Triangle = gld_Triangle3DSmooth_DX7; - tnl->Driver.Render.Quad = gld_Quad3DSmooth_DX7; - } - -// _GLD_DX7_VB(Lock(gldPB->pVB, 0, 0, &gldPB->pPoints, D3DLOCK_DISCARD)); - dwFlags = DDLOCK_DISCARDCONTENTS | DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR | DDLOCK_WRITEONLY; - _GLD_DX7_VB(Lock(gldPB->pVB, dwFlags, &gldPB->pPoints, NULL)); - gldPB->nPoints = gldPB->nLines = gldPB->nTriangles = 0; - // Allocate primitive pointers - // gldPB->pPoints is always first - gldPB->pLines = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstLine); - gldPB->pTriangles = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstTriangle); - - ASSERT(tnl->Driver.Render.BuildVertices); - ASSERT(tnl->Driver.Render.PrimitiveNotify); - ASSERT(tnl->Driver.Render.Points); - ASSERT(tnl->Driver.Render.Line); - ASSERT(tnl->Driver.Render.Triangle); - ASSERT(tnl->Driver.Render.Quad); - ASSERT(tnl->Driver.Render.ResetLineStipple); - ASSERT(tnl->Driver.Render.Interp); - ASSERT(tnl->Driver.Render.CopyPV); - ASSERT(tnl->Driver.Render.ClippedLine); - ASSERT(tnl->Driver.Render.ClippedPolygon); - ASSERT(tnl->Driver.Render.Finish); - - tab = (VB->Elts ? tnl->Driver.Render.PrimTabElts : tnl->Driver.Render.PrimTabVerts); - - do { - GLuint i, length, flags = 0; - for (i = 0 ; !(flags & PRIM_END) ; i += length) - { - flags = VB->Primitive[i].mode; - length= VB->Primitive[i].count; - ASSERT(length || (flags & PRIM_END)); - ASSERT((flags & PRIM_MODE_MASK) <= GL_POLYGON+1); - if (length) - tab[flags & PRIM_MODE_MASK]( ctx, i, i + length, flags ); - } - } while (tnl->Driver.Render.Multipass && - tnl->Driver.Render.Multipass( ctx, ++pass )); - - _GLD_DX7_VB(Unlock(gldPB->pVB)); - -// _GLD_DX7_DEV(SetStreamSource(gld->pDev, 0, gldPB->pVB, gldPB->dwStride)); - - _GLD_DX7_DEV(SetTransform(gld->pDev, D3DTRANSFORMSTATE_PROJECTION, &gld->matProjection)); - _GLD_DX7_DEV(SetTransform(gld->pDev, D3DTRANSFORMSTATE_WORLD, &gld->matModelView)); - - if (gldPB->nPoints) { -// _GLD_DX7_DEV(DrawPrimitive(gld->pDev, D3DPT_POINTLIST, 0, gldPB->nPoints)); - _GLD_DX7_DEV(DrawPrimitiveVB(gld->pDev, D3DPT_POINTLIST, gldPB->pVB, 0, gldPB->nPoints, 0)); - gldPB->nPoints = 0; - } - - if (gldPB->nLines) { -// _GLD_DX7_DEV(DrawPrimitive(gld->pDev, D3DPT_LINELIST, gldPB->iFirstLine, gldPB->nLines)); - _GLD_DX7_DEV(DrawPrimitiveVB(gld->pDev, D3DPT_LINELIST, gldPB->pVB, gldPB->iFirstLine, gldPB->nLines, 0)); - gldPB->nLines = 0; - } - - if (gldPB->nTriangles) { -// _GLD_DX7_DEV(DrawPrimitive(gld->pDev, D3DPT_TRIANGLELIST, gldPB->iFirstTriangle, gldPB->nTriangles)); - _GLD_DX7_DEV(DrawPrimitiveVB(gld->pDev, D3DPT_TRIANGLELIST, gldPB->pVB, gldPB->iFirstTriangle, gldPB->nTriangles, 0)); - gldPB->nTriangles = 0; - } - - return GL_FALSE; /* finished the pipe */ -} - - -//--------------------------------------------------------------------------- - -const struct tnl_pipeline_stage _gld_d3d_render_stage = -{ - "gld_d3d_render_stage", - NULL, - NULL, - NULL, - NULL, - gld_d3d_render_stage_run /* run */ -}; - -//--------------------------------------------------------------------------- diff --git a/src/mesa/drivers/windows/gldirect/dx7/gld_vb_mesa_render_dx7.c b/src/mesa/drivers/windows/gldirect/dx7/gld_vb_mesa_render_dx7.c deleted file mode 100644 index 72e5e1308c..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx7/gld_vb_mesa_render_dx7.c +++ /dev/null @@ -1,422 +0,0 @@ - -/* - * Mesa 3-D graphics library - * Version: 3.5 - * - * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Authors: - * Keith Whitwell <keithw@valinux.com> - */ - - -/* - * Render whole vertex buffers, including projection of vertices from - * clip space and clipping of primitives. - * - * This file makes calls to project vertices and to the point, line - * and triangle rasterizers via the function pointers: - * - * context->Driver.Render.* - * - */ - - -//--------------------------------------------------------------------------- - -//#include "../GLDirect.h" -//#include "../gld_log.h" -//#include "gld_dx8.h" - -#include "dglcontext.h" -#include "ddlog.h" -#include "gld_dx7.h" - -//--------------------------------------------------------------------------- - -#include "glheader.h" -#include "context.h" -#include "macros.h" -// #include "mem.h" -#include "mtypes.h" -//#include "mmath.h" - -#include "math/m_matrix.h" -#include "math/m_xform.h" - -#include "tnl/t_pipeline.h" - -/**********************************************************************/ -/* Clip single primitives */ -/**********************************************************************/ - - -#if defined(USE_IEEE) -#define NEGATIVE(x) (GET_FLOAT_BITS(x) & (1<<31)) -//#define DIFFERENT_SIGNS(x,y) ((GET_FLOAT_BITS(x) ^ GET_FLOAT_BITS(y)) & (1<<31)) -#else -#define NEGATIVE(x) (x < 0) -//#define DIFFERENT_SIGNS(x,y) (x * y <= 0 && x - y != 0) -/* Could just use (x*y<0) except for the flatshading requirements. - * Maybe there's a better way? - */ -#endif - - -#define W(i) coord[i][3] -#define Z(i) coord[i][2] -#define Y(i) coord[i][1] -#define X(i) coord[i][0] -#define SIZE 4 -#define TAG(x) x##_4 -#include "tnl/t_vb_cliptmp.h" - - - -/**********************************************************************/ -/* Clip and render whole begin/end objects */ -/**********************************************************************/ - -#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED) -#define EDGEFLAG_GET(idx) VB->EdgeFlag[idx] -#define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val - - -/* Vertices, with the possibility of clipping. - */ -#define RENDER_POINTS( start, count ) \ - tnl->Driver.Render.Points( ctx, start, count ) - -#define RENDER_LINE( v1, v2 ) \ -do { \ - GLubyte c1 = mask[v1], c2 = mask[v2]; \ - GLubyte ormask = c1|c2; \ - if (!ormask) \ - LineFunc( ctx, v1, v2 ); \ - else if (!(c1 & c2 & 0x3f)) \ - clip_line_4( ctx, v1, v2, ormask ); \ -} while (0) - -#define RENDER_TRI( v1, v2, v3 ) \ -do { \ - GLubyte c1 = mask[v1], c2 = mask[v2], c3 = mask[v3]; \ - GLubyte ormask = c1|c2|c3; \ - if (!ormask) \ - TriangleFunc( ctx, v1, v2, v3 ); \ - else if (!(c1 & c2 & c3 & 0x3f)) \ - clip_tri_4( ctx, v1, v2, v3, ormask ); \ -} while (0) - -#define RENDER_QUAD( v1, v2, v3, v4 ) \ -do { \ - GLubyte c1 = mask[v1], c2 = mask[v2]; \ - GLubyte c3 = mask[v3], c4 = mask[v4]; \ - GLubyte ormask = c1|c2|c3|c4; \ - if (!ormask) \ - QuadFunc( ctx, v1, v2, v3, v4 ); \ - else if (!(c1 & c2 & c3 & c4 & 0x3f)) \ - clip_quad_4( ctx, v1, v2, v3, v4, ormask ); \ -} while (0) - - -#define LOCAL_VARS \ - TNLcontext *tnl = TNL_CONTEXT(ctx); \ - struct vertex_buffer *VB = &tnl->vb; \ - const GLuint * const elt = VB->Elts; \ - const GLubyte *mask = VB->ClipMask; \ - const GLuint sz = VB->ClipPtr->size; \ - const tnl_line_func LineFunc = tnl->Driver.Render.Line; \ - const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \ - const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \ - const GLboolean stipple = ctx->Line.StippleFlag; \ - (void) (LineFunc && TriangleFunc && QuadFunc); \ - (void) elt; (void) mask; (void) sz; (void) stipple; - -#define TAG(x) clip_##x##_verts -#define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x ) -#define RESET_STIPPLE if (stipple) tnl->Driver.Render.ResetLineStipple( ctx ) -#define PRESERVE_VB_DEFS -#include "tnl/t_vb_rendertmp.h" - - - -/* Elts, with the possibility of clipping. - */ -#undef ELT -#undef TAG -#define ELT(x) elt[x] -#define TAG(x) clip_##x##_elts -#include "tnl/t_vb_rendertmp.h" - -/* TODO: do this for all primitives, verts and elts: - */ -static void clip_elt_triangles( GLcontext *ctx, - GLuint start, - GLuint count, - GLuint flags ) -{ - TNLcontext *tnl = TNL_CONTEXT(ctx); - tnl_render_func render_tris = tnl->Driver.Render.PrimTabElts[GL_TRIANGLES]; - struct vertex_buffer *VB = &tnl->vb; - const GLuint * const elt = VB->Elts; - GLubyte *mask = VB->ClipMask; - GLuint last = count-2; - GLuint j; - (void) flags; - - tnl->Driver.Render.PrimitiveNotify( ctx, GL_TRIANGLES ); - - for (j=start; j < last; j+=3 ) { - GLubyte c1 = mask[elt[j]]; - GLubyte c2 = mask[elt[j+1]]; - GLubyte c3 = mask[elt[j+2]]; - GLubyte ormask = c1|c2|c3; - if (ormask) { - if (start < j) - render_tris( ctx, start, j, 0 ); - if (!(c1&c2&c3&0x3f)) - clip_tri_4( ctx, elt[j], elt[j+1], elt[j+2], ormask ); - start = j+3; - } - } - - if (start < j) - render_tris( ctx, start, j, 0 ); -} - -/**********************************************************************/ -/* Render whole begin/end objects */ -/**********************************************************************/ - -#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED) -#define EDGEFLAG_GET(idx) VB->EdgeFlag[idx] -#define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val - - -/* Vertices, no clipping. - */ -#define RENDER_POINTS( start, count ) \ - tnl->Driver.Render.Points( ctx, start, count ) - -#define RENDER_LINE( v1, v2 ) \ - LineFunc( ctx, v1, v2 ) - -#define RENDER_TRI( v1, v2, v3 ) \ - TriangleFunc( ctx, v1, v2, v3 ) - -#define RENDER_QUAD( v1, v2, v3, v4 ) \ - QuadFunc( ctx, v1, v2, v3, v4 ) - -#define TAG(x) _gld_tnl_##x##_verts - -#define LOCAL_VARS \ - TNLcontext *tnl = TNL_CONTEXT(ctx); \ - struct vertex_buffer *VB = &tnl->vb; \ - const GLuint * const elt = VB->Elts; \ - const tnl_line_func LineFunc = tnl->Driver.Render.Line; \ - const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \ - const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \ - (void) (LineFunc && TriangleFunc && QuadFunc); \ - (void) elt; - -#define RESET_STIPPLE tnl->Driver.Render.ResetLineStipple( ctx ) -#define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x ) -#define RENDER_TAB_QUALIFIER -#define PRESERVE_VB_DEFS -#include "tnl/t_vb_rendertmp.h" - - -/* Elts, no clipping. - */ -#undef ELT -#define TAG(x) _gld_tnl_##x##_elts -#define ELT(x) elt[x] -#include "tnl/t_vb_rendertmp.h" - - -/**********************************************************************/ -/* Helper functions for drivers */ -/**********************************************************************/ -/* -void _tnl_RenderClippedPolygon( GLcontext *ctx, const GLuint *elts, GLuint n ) -{ - TNLcontext *tnl = TNL_CONTEXT(ctx); - struct vertex_buffer *VB = &tnl->vb; - GLuint *tmp = VB->Elts; - - VB->Elts = (GLuint *)elts; - tnl->Driver.Render.PrimTabElts[GL_POLYGON]( ctx, 0, n, PRIM_BEGIN|PRIM_END ); - VB->Elts = tmp; -} - -void _tnl_RenderClippedLine( GLcontext *ctx, GLuint ii, GLuint jj ) -{ - TNLcontext *tnl = TNL_CONTEXT(ctx); - tnl->Driver.Render.Line( ctx, ii, jj ); -} -*/ - - -/**********************************************************************/ -/* Clip and render whole vertex buffers */ -/**********************************************************************/ - -tnl_points_func _gldSetupPoints[4] = { - gld_Points2D_DX7, - gld_Points2D_DX7, - gld_Points2D_DX7, - gld_Points2D_DX7 -}; -tnl_line_func _gldSetupLine[4] = { - gld_Line2DFlat_DX7, - gld_Line2DSmooth_DX7, - gld_Line2DFlat_DX7, - gld_Line2DSmooth_DX7, -}; -tnl_triangle_func _gldSetupTriangle[4] = { - gld_Triangle2DFlat_DX7, - gld_Triangle2DSmooth_DX7, - gld_Triangle2DFlatExtras_DX7, - gld_Triangle2DSmoothExtras_DX7 -}; -tnl_quad_func _gldSetupQuad[4] = { - gld_Quad2DFlat_DX7, - gld_Quad2DSmooth_DX7, - gld_Quad2DFlatExtras_DX7, - gld_Quad2DSmoothExtras_DX7 -}; - -//--------------------------------------------------------------------------- - -static GLboolean _gld_mesa_render_stage_run( - GLcontext *ctx, - struct tnl_pipeline_stage *stage) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); - - TNLcontext *tnl = TNL_CONTEXT(ctx); - struct vertex_buffer *VB = &tnl->vb; - tnl_render_func *tab; - GLint pass = 0; - GLD_pb_dx7 *gldPB; - DWORD dwFlags; - - /* Allow the drivers to lock before projected verts are built so - * that window coordinates are guarenteed not to change before - * rendering. - */ - ASSERT(tnl->Driver.Render.Start); - - tnl->Driver.Render.Start( ctx ); - - gldPB = &gld->PB2d; - tnl->Driver.Render.Points = _gldSetupPoints[gld->iSetupFunc]; - tnl->Driver.Render.Line = _gldSetupLine[gld->iSetupFunc]; - tnl->Driver.Render.Triangle = _gldSetupTriangle[gld->iSetupFunc]; - tnl->Driver.Render.Quad = _gldSetupQuad[gld->iSetupFunc]; - - dwFlags = DDLOCK_DISCARDCONTENTS | DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR | DDLOCK_WRITEONLY; - _GLD_DX7_VB(Lock(gldPB->pVB, dwFlags, &gldPB->pPoints, NULL)); - gldPB->nPoints = gldPB->nLines = gldPB->nTriangles = 0; - - // Allocate primitive pointers - gldPB->pPoints is always first - gldPB->pLines = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstLine); - gldPB->pTriangles = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstTriangle); - - ASSERT(tnl->Driver.Render.BuildVertices); - ASSERT(tnl->Driver.Render.PrimitiveNotify); - ASSERT(tnl->Driver.Render.Points); - ASSERT(tnl->Driver.Render.Line); - ASSERT(tnl->Driver.Render.Triangle); - ASSERT(tnl->Driver.Render.Quad); - ASSERT(tnl->Driver.Render.ResetLineStipple); - ASSERT(tnl->Driver.Render.Interp); - ASSERT(tnl->Driver.Render.CopyPV); - ASSERT(tnl->Driver.Render.ClippedLine); - ASSERT(tnl->Driver.Render.ClippedPolygon); - ASSERT(tnl->Driver.Render.Finish); - - tnl->Driver.Render.BuildVertices( ctx, 0, VB->Count, ~0 ); - - if (VB->ClipOrMask) { - tab = VB->Elts ? clip_render_tab_elts : clip_render_tab_verts; - clip_render_tab_elts[GL_TRIANGLES] = clip_elt_triangles; - } - else { - tab = (VB->Elts ? - tnl->Driver.Render.PrimTabElts : - tnl->Driver.Render.PrimTabVerts); - } - - do { - GLuint i, length, flags = 0; - for (i = 0 ; !(flags & PRIM_END) ; i += length) { - flags = VB->Primitive[i].mode; - length= VB->Primitive[i].count; - ASSERT(length || (flags & PRIM_END)); - ASSERT((flags & PRIM_MODE_MASK) <= GL_POLYGON+1); - if (length) - tab[flags & PRIM_MODE_MASK]( ctx, i, i + length, flags ); - } - } while (tnl->Driver.Render.Multipass && - tnl->Driver.Render.Multipass( ctx, ++pass )); - - -// tnl->Driver.Render.Finish( ctx ); - - _GLD_DX7_VB(Unlock(gldPB->pVB)); - - if (gldPB->nPoints) { - _GLD_DX7_DEV(DrawPrimitiveVB(gld->pDev, D3DPT_POINTLIST, gldPB->pVB, 0, gldPB->nPoints, 0)); - gldPB->nPoints = 0; - } - - if (gldPB->nLines) { - _GLD_DX7_DEV(DrawPrimitiveVB(gld->pDev, D3DPT_LINELIST, gldPB->pVB, gldPB->iFirstLine, gldPB->nLines*2, 0)); - gldPB->nLines = 0; - } - - if (gldPB->nTriangles) { - _GLD_DX7_DEV(DrawPrimitiveVB(gld->pDev, D3DPT_TRIANGLELIST, gldPB->pVB, gldPB->iFirstTriangle, gldPB->nTriangles*3, 0)); - gldPB->nTriangles = 0; - } - - return GL_FALSE; /* finished the pipe */ -} - - -/**********************************************************************/ -/* Render pipeline stage */ -/**********************************************************************/ - - - -const struct tnl_pipeline_stage _gld_mesa_render_stage = -{ - "gld_mesa_render_stage", - NULL, - NULL, - NULL, - NULL, - _gld_mesa_render_stage_run /* run */ -}; - -//--------------------------------------------------------------------------- diff --git a/src/mesa/drivers/windows/gldirect/dx7/gld_wgl_dx7.c b/src/mesa/drivers/windows/gldirect/dx7/gld_wgl_dx7.c deleted file mode 100644 index fa44a952a0..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx7/gld_wgl_dx7.c +++ /dev/null @@ -1,1613 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: GLDirect Direct3D 8.x WGL (WindowsGL) -* -****************************************************************************/ - -#include "dglcontext.h" -#include "gld_driver.h" -//#include "gld_dxerr8.h" -#include "gld_dx7.h" - -#include "tnl/tnl.h" -#include "tnl/t_context.h" - -// Copied from dglcontect.c -#define GLDERR_NONE 0 -#define GLDERR_MEM 1 -#define GLDERR_DDRAW 2 -#define GLDERR_D3D 3 -#define GLDERR_BPP 4 -#define GLDERR_DDS 5 -// This external var keeps track of any error -extern int nContextError; - -// Uncomment this for persistant resources -//#define _GLD_PERSISTANT - -#define DDLOG_CRITICAL_OR_WARN DDLOG_CRITICAL - -extern void _gld_mesa_warning(GLcontext *, char *); -extern void _gld_mesa_fatal(GLcontext *, char *); - -//--------------------------------------------------------------------------- - -static char szColorDepthWarning[] = -"GLDirect does not support the current desktop\n\ -color depth.\n\n\ -You may need to change the display resolution to\n\ -16 bits per pixel or higher color depth using\n\ -the Windows Display Settings control panel\n\ -before running this OpenGL application.\n"; - -// The only depth-stencil formats currently supported by Direct3D -// Surface Format Depth Stencil Total Bits -// D3DFMT_D32 32 - 32 -// D3DFMT_D15S1 15 1 16 -// D3DFMT_D24S8 24 8 32 -// D3DFMT_D16 16 - 16 -// D3DFMT_D24X8 24 - 32 -// D3DFMT_D24X4S4 24 4 32 - -// This pixel format will be used as a template when compiling the list -// of pixel formats supported by the hardware. Many fields will be -// filled in at runtime. -// PFD flag defaults are upgraded to match ChoosePixelFormat() -- DaveM -static DGL_pixelFormat pfTemplateHW = -{ - { - sizeof(PIXELFORMATDESCRIPTOR), // Size of the data structure - 1, // Structure version - should be 1 - // Flags: - PFD_DRAW_TO_WINDOW | // The buffer can draw to a window or device surface. - PFD_DRAW_TO_BITMAP | // The buffer can draw to a bitmap. (DaveM) - PFD_SUPPORT_GDI | // The buffer supports GDI drawing. (DaveM) - PFD_SUPPORT_OPENGL | // The buffer supports OpenGL drawing. - PFD_DOUBLEBUFFER | // The buffer is double-buffered. - 0, // Placeholder for easy commenting of above flags - PFD_TYPE_RGBA, // Pixel type RGBA. - 16, // Total colour bitplanes (excluding alpha bitplanes) - 5, 0, // Red bits, shift - 5, 0, // Green bits, shift - 5, 0, // Blue bits, shift - 0, 0, // Alpha bits, shift (destination alpha) - 0, // Accumulator bits (total) - 0, 0, 0, 0, // Accumulator bits: Red, Green, Blue, Alpha - 0, // Depth bits - 0, // Stencil bits - 0, // Number of auxiliary buffers - 0, // Layer type - 0, // Specifies the number of overlay and underlay planes. - 0, // Layer mask - 0, // Specifies the transparent color or index of an underlay plane. - 0 // Damage mask - }, - D3DX_SF_UNKNOWN, // No depth/stencil buffer -}; - -//--------------------------------------------------------------------------- -// Vertex Shaders -//--------------------------------------------------------------------------- -/* -// Vertex Shader Declaration -static DWORD dwTwoSidedLightingDecl[] = -{ - D3DVSD_STREAM(0), - D3DVSD_REG(0, D3DVSDT_FLOAT3), // XYZ position - D3DVSD_REG(1, D3DVSDT_FLOAT3), // XYZ normal - D3DVSD_REG(2, D3DVSDT_D3DCOLOR), // Diffuse color - D3DVSD_REG(3, D3DVSDT_D3DCOLOR), // Specular color - D3DVSD_REG(4, D3DVSDT_FLOAT2), // 2D texture unit 0 - D3DVSD_REG(5, D3DVSDT_FLOAT2), // 2D texture unit 1 - D3DVSD_END() -}; - -// Vertex Shader for two-sided lighting -static char *szTwoSidedLightingVS = -// This is a test shader! -"vs.1.0\n" -"m4x4 oPos,v0,c0\n" -"mov oD0,v2\n" -"mov oD1,v3\n" -"mov oT0,v4\n" -"mov oT1,v5\n" -; -*/ -//--------------------------------------------------------------------------- -//--------------------------------------------------------------------------- - -typedef struct { -// HINSTANCE hD3D8DLL; // Handle to d3d8.dll -// FNDIRECT3DCREATE7 fnDirect3DCreate7; // Direct3DCreate8 function prototype -// BOOL bDirect3D; // Persistant Direct3D7 exists -// BOOL bDirect3DDevice; // Persistant Direct3DDevice7 exists -// IDirect3D7 *pD3D; // Persistant Direct3D7 -// IDirect3DDevice7 *pDev; // Persistant Direct3DDevice7 - BOOL bD3DXStarted; -} GLD_dx7_globals; - -// These are "global" to all DX7 contexts. KeithH -static GLD_dx7_globals dx7Globals; - -// Added for correct clipping of multiple open windows. (DaveM) -LPDIRECTDRAWSURFACE7 lpDDSPrimary = NULL; -LPDIRECTDRAWCLIPPER lpDDClipper = NULL; - -//--------------------------------------------------------------------------- -//--------------------------------------------------------------------------- - -BOOL gldGetDXErrorString_DX( - HRESULT hr, - char *buf, - int nBufSize) -{ - // - // Return a string describing the input HRESULT error code - // - - D3DXGetErrorString(hr, nBufSize, buf); - return TRUE; -} - -//--------------------------------------------------------------------------- -// -// DX7 does not support multisample -/* -static D3DMULTISAMPLE_TYPE _gldGetDeviceMultiSampleType( - IDirect3D8 *pD3D8, - D3DFORMAT SurfaceFormat, - D3DDEVTYPE d3dDevType, - BOOL Windowed) -{ - int i; - HRESULT hr; - - if (glb.dwMultisample == GLDS_MULTISAMPLE_NONE) - return D3DMULTISAMPLE_NONE; - - if (glb.dwMultisample == GLDS_MULTISAMPLE_FASTEST) { - // Find fastest multisample - for (i=2; i<17; i++) { - hr = IDirect3D8_CheckDeviceMultiSampleType( - pD3D8, - glb.dwAdapter, - d3dDevType, - SurfaceFormat, - Windowed, - (D3DMULTISAMPLE_TYPE)i); - if (SUCCEEDED(hr)) { - return (D3DMULTISAMPLE_TYPE)i; - } - } - } else { - // Find nicest multisample - for (i=16; i>1; i--) { - hr = IDirect3D8_CheckDeviceMultiSampleType( - pD3D8, - glb.dwAdapter, - d3dDevType, - SurfaceFormat, - Windowed, - (D3DMULTISAMPLE_TYPE)i); - if (SUCCEEDED(hr)) { - return (D3DMULTISAMPLE_TYPE)i; - } - } - } - - // Nothing found - return default - return D3DMULTISAMPLE_NONE; -} -*/ -//--------------------------------------------------------------------------- - -void _gldDestroyPrimitiveBuffer( - GLD_pb_dx7 *gldVB) -{ - SAFE_RELEASE(gldVB->pVB); - - // Sanity check... - gldVB->nLines = gldVB->nPoints = gldVB->nTriangles = 0; -} - -//--------------------------------------------------------------------------- - -HRESULT _gldCreatePrimitiveBuffer( - GLcontext *ctx, - GLD_driver_dx7 *lpCtx, - GLD_pb_dx7 *gldVB) -{ - HRESULT hResult; - char *szCreateVertexBufferFailed = "CreateVertexBuffer failed"; - DWORD dwMaxVertices; // Max number of vertices in vertex buffer - DWORD dwVBSize; // Total size of vertex buffer - D3DVERTEXBUFFERDESC vbdesc; - - // If CVA (Compiled Vertex Array) is used by an OpenGL app, then we - // will need enough vertices to cater for Mesa::Const.MaxArrayLockSize. - // We'll use IMM_SIZE if it's larger (which it should not be). - dwMaxVertices = MAX_ARRAY_LOCK_SIZE; - - // Max vertex buffer size limited in DX7. (DaveM) - if (dwMaxVertices*9 > D3DMAXNUMVERTICES) - dwMaxVertices = D3DMAXNUMVERTICES/9; - - // Now calculate how many vertices to allow for in total - // 1 per point, 2 per line, 6 per quad = 9 - dwVBSize = dwMaxVertices * 9 * gldVB->dwStride; - - vbdesc.dwSize = sizeof(vbdesc); - vbdesc.dwCaps = gldVB->dwCreateFlags; - vbdesc.dwFVF = gldVB->dwFVF; - vbdesc.dwNumVertices = dwMaxVertices * 9; - -/* hResult = IDirect3DDevice8_CreateVertexBuffer( - lpCtx->pDev, - dwVBSize, -RAgldVB->dwUsage, - gldVB->dwFVF, - gldVB->dwPool, - &gldVB->pVB);*/ - hResult = IDirect3D7_CreateVertexBuffer( - lpCtx->pD3D, - &vbdesc, - &gldVB->pVB, - 0); - if (FAILED(hResult)) { - ddlogMessage(DDLOG_CRITICAL_OR_WARN, szCreateVertexBufferFailed); - return hResult; - } - - gldVB->nLines = gldVB->nPoints = gldVB->nTriangles = 0; - gldVB->pPoints = gldVB->pLines = gldVB->pTriangles = NULL; - gldVB->iFirstLine = dwMaxVertices; // Index of first line in VB - gldVB->iFirstTriangle = dwMaxVertices*3; // Index of first triangle in VB - - return S_OK; -} - -//--------------------------------------------------------------------------- -// Function: _gldCreateVertexShaders -// Create DX8 Vertex Shaders. -//--------------------------------------------------------------------------- -/* -void _gldCreateVertexShaders( - GLD_driver_dx8 *gld) -{ - DWORD dwFlags; - LPD3DXBUFFER pVSOpcodeBuffer; // Vertex Shader opcode buffer - HRESULT hr; - -#ifdef _DEBUG - dwFlags = D3DXASM_DEBUG; -#else - dwFlags = 0; // D3DXASM_SKIPVALIDATION; -#endif - - ddlogMessage(DDLOG_INFO, "Creating shaders...\n"); - - // Init the shader handle - gld->VStwosidelight.hShader = 0; - - if (gld->d3dCaps8.MaxStreams == 0) { - // Lame DX8 driver doesn't support streams - // Not fatal, as defaults will be used - ddlogMessage(DDLOG_WARN, "Driver doesn't support Vertex Shaders (MaxStreams==0)\n"); - return; - } - - // ** THIS DISABLES VERTEX SHADER SUPPORT ** -// return; - // ** THIS DISABLES VERTEX SHADER SUPPORT ** - - // - // Two-sided lighting - // - -#if 0 - // - // DEBUGGING: Load shader from a text file - // - { - LPD3DXBUFFER pVSErrorBuffer; // Vertex Shader error buffer - hr = D3DXAssembleShaderFromFile( - "twoside.vsh", - dwFlags, - NULL, // No constants - &pVSOpcodeBuffer, - &pVSErrorBuffer); - if (pVSErrorBuffer && pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)) - ddlogMessage(DDLOG_INFO, pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)); - SAFE_RELEASE(pVSErrorBuffer); - } -#else - { - LPD3DXBUFFER pVSErrorBuffer; // Vertex Shader error buffer - // Assemble ascii shader text into shader opcodes - hr = D3DXAssembleShader( - szTwoSidedLightingVS, - strlen(szTwoSidedLightingVS), - dwFlags, - NULL, // No constants - &pVSOpcodeBuffer, - &pVSErrorBuffer); - if (pVSErrorBuffer && pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)) - ddlogMessage(DDLOG_INFO, pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)); - SAFE_RELEASE(pVSErrorBuffer); - } -#endif - if (FAILED(hr)) { - ddlogError(DDLOG_WARN, "AssembleShader failed", hr); - SAFE_RELEASE(pVSOpcodeBuffer); - return; - } - -// This is for debugging. Remove to enable vertex shaders in HW -#define _GLD_FORCE_SW_VS 0 - - if (_GLD_FORCE_SW_VS) { - // _GLD_FORCE_SW_VS should be disabled for Final Release - ddlogMessage(DDLOG_SYSTEM, "[Forcing shaders in SW]\n"); - } - - // Try and create shader in hardware. - // NOTE: The D3D Ref device appears to succeed when trying to - // create the device in hardware, but later complains - // when trying to set it with SetVertexShader(). Go figure. - if (_GLD_FORCE_SW_VS || glb.dwDriver == GLDS_DRIVER_REF) { - // Don't try and create a hardware shader with the Ref device - hr = E_FAIL; // COM error/fail result - } else { - gld->VStwosidelight.bHardware = TRUE; - hr = IDirect3DDevice8_CreateVertexShader( - gld->pDev, - dwTwoSidedLightingDecl, - pVSOpcodeBuffer->lpVtbl->GetBufferPointer(pVSOpcodeBuffer), - &gld->VStwosidelight.hShader, - 0); - } - if (FAILED(hr)) { - ddlogMessage(DDLOG_INFO, "... HW failed, trying SW...\n"); - // Failed. Try and create shader for software processing - hr = IDirect3DDevice8_CreateVertexShader( - gld->pDev, - dwTwoSidedLightingDecl, - pVSOpcodeBuffer->lpVtbl->GetBufferPointer(pVSOpcodeBuffer), - &gld->VStwosidelight.hShader, - D3DUSAGE_SOFTWAREPROCESSING); - if (FAILED(hr)) { - gld->VStwosidelight.hShader = 0; // Sanity check - ddlogError(DDLOG_WARN, "CreateVertexShader failed", hr); - return; - } - // Succeeded, but for software processing - gld->VStwosidelight.bHardware = FALSE; - } - - SAFE_RELEASE(pVSOpcodeBuffer); - - ddlogMessage(DDLOG_INFO, "... OK\n"); -} - -//--------------------------------------------------------------------------- - -void _gldDestroyVertexShaders( - GLD_driver_dx8 *gld) -{ - if (gld->VStwosidelight.hShader) { - IDirect3DDevice8_DeleteVertexShader(gld->pDev, gld->VStwosidelight.hShader); - gld->VStwosidelight.hShader = 0; - } -} -*/ -//--------------------------------------------------------------------------- - -BOOL gldCreateDrawable_DX( - DGL_ctx *ctx, -// BOOL bDefaultDriver, - BOOL bDirectDrawPersistant, - BOOL bPersistantBuffers) -{ - // - // bDirectDrawPersistant: applies to IDirect3D8 - // bPersistantBuffers: applies to IDirect3DDevice8 - // - -// D3DDEVTYPE d3dDevType; -// D3DPRESENT_PARAMETERS d3dpp; -// D3DDISPLAYMODE d3ddm; -// DWORD dwBehaviourFlags; -// D3DADAPTER_IDENTIFIER8 d3dIdent; - - HRESULT hr; - GLD_driver_dx7 *lpCtx = NULL; - D3DX_VIDMODEDESC d3ddm; - - // Parameters for D3DXCreateContextEx - // These will be different for fullscreen and windowed - DWORD dwDeviceIndex; - DWORD dwFlags; - HWND hwnd; - HWND hwndFocus; - DWORD numColorBits; - DWORD numAlphaBits; - DWORD numDepthBits; - DWORD numStencilBits; - DWORD numBackBuffers; - DWORD dwWidth; - DWORD dwHeight; - DWORD refreshRate; - - // Error if context is NULL. - if (ctx == NULL) - return FALSE; - - if (ctx->glPriv) { - lpCtx = ctx->glPriv; - // Release any existing interfaces (in reverse order) - SAFE_RELEASE(lpCtx->pDev); - SAFE_RELEASE(lpCtx->pD3D); - lpCtx->pD3DXContext->lpVtbl->Release(lpCtx->pD3DXContext); - lpCtx->pD3DXContext = NULL; - } else { - lpCtx = (GLD_driver_dx7*)malloc(sizeof(GLD_driver_dx7)); - ZeroMemory(lpCtx, sizeof(lpCtx)); - } - -// d3dDevType = (glb.dwDriver == GLDS_DRIVER_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; - // Use REF device if requested. Otherwise D3DX_DEFAULT will choose highest level - // of HW acceleration. - dwDeviceIndex = (glb.dwDriver == GLDS_DRIVER_REF) ? D3DX_HWLEVEL_REFERENCE : D3DX_DEFAULT; - - // TODO: Check this -// if (bDefaultDriver) -// d3dDevType = D3DDEVTYPE_REF; - -#ifdef _GLD_PERSISTANT - // Use persistant interface if needed - if (bDirectDrawPersistant && dx7Globals.bDirect3D) { - lpCtx->pD3D = dx7Globals.pD3D; - IDirect3D7_AddRef(lpCtx->pD3D); - goto SkipDirectDrawCreate; - } -#endif -/* - // Create Direct3D7 object - lpCtx->pD3D = dx7Globals.fnDirect3DCreate8(D3D_SDK_VERSION_DX8_SUPPORT_WIN95); - if (lpCtx->pD3D == NULL) { - MessageBox(NULL, "Unable to initialize Direct3D8", "GLDirect", MB_OK); - ddlogMessage(DDLOG_CRITICAL_OR_WARN, "Unable to create Direct3D8 interface"); - nContextError = GLDERR_D3D; - goto return_with_error; - } -*/ - -#ifdef _GLD_PERSISTANT - // Cache Direct3D interface for subsequent GLRCs - if (bDirectDrawPersistant && !dx8Globals.bDirect3D) { - dx7Globals.pD3D = lpCtx->pD3D; - IDirect3D7_AddRef(dx7Globals.pD3D); - dx7Globals.bDirect3D = TRUE; - } -SkipDirectDrawCreate: -#endif -/* - // Get the display mode so we can make a compatible backbuffer - hResult = IDirect3D8_GetAdapterDisplayMode(lpCtx->pD3D, glb.dwAdapter, &d3ddm); - if (FAILED(hResult)) { - nContextError = GLDERR_D3D; - goto return_with_error; - } -*/ - -#if 0 - // Get device caps - hResult = IDirect3D8_GetDeviceCaps(lpCtx->pD3D, glb.dwAdapter, d3dDevType, &lpCtx->d3dCaps8); - if (FAILED(hResult)) { - ddlogError(DDLOG_CRITICAL_OR_WARN, "IDirect3D8_GetDeviceCaps failed", hResult); - nContextError = GLDERR_D3D; - goto return_with_error; - } - - // Check for hardware transform & lighting - lpCtx->bHasHWTnL = lpCtx->d3dCaps8.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ? TRUE : FALSE; - - // If this flag is present then we can't default to Mesa - // SW rendering between BeginScene() and EndScene(). - if (lpCtx->d3dCaps8.Caps2 & D3DCAPS2_NO2DDURING3DSCENE) { - ddlogMessage(DDLOG_WARN, - "Warning : No 2D allowed during 3D scene.\n"); - } -#endif - - // - // Create the Direct3D context - // - -#ifdef _GLD_PERSISTANT - // Re-use original IDirect3DDevice if persistant buffers exist. - // Note that we test for persistant IDirect3D8 as well - // bDirectDrawPersistant == persistant IDirect3D8 (DirectDraw8 does not exist) - if (bDirectDrawPersistant && bPersistantBuffers && dx7Globals.pD3D && dx7Globals.pDev) { - lpCtx->pDev = dx7Globals.pDev; - IDirect3DDevice7_AddRef(dx7Globals.pDev); - goto skip_direct3ddevice_create; - } -#endif -/* - // Clear the presentation parameters (sets all members to zero) - ZeroMemory(&d3dpp, sizeof(d3dpp)); - - // Recommended by MS; needed for MultiSample. - // Be careful if altering this for FullScreenBlit - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - - d3dpp.BackBufferFormat = d3ddm.Format; - d3dpp.BackBufferCount = 1; - d3dpp.MultiSampleType = _gldGetDeviceMultiSampleType(lpCtx->pD3D, d3ddm.Format, d3dDevType, !ctx->bFullscreen); - d3dpp.AutoDepthStencilFormat = ctx->lpPF->dwDriverData; - d3dpp.EnableAutoDepthStencil = (d3dpp.AutoDepthStencilFormat == D3DFMT_UNKNOWN) ? FALSE : TRUE; - - if (ctx->bFullscreen) { - ddlogWarnOption(FALSE); // Don't popup any messages in fullscreen - d3dpp.Windowed = FALSE; - d3dpp.BackBufferWidth = d3ddm.Width; - d3dpp.BackBufferHeight = d3ddm.Height; - d3dpp.hDeviceWindow = ctx->hWnd; - d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; - - // Support for vertical retrace synchronisation. - // Set default presentation interval in case caps bits are missing - d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; - if (glb.bWaitForRetrace) { - if (lpCtx->d3dCaps8.PresentationIntervals & D3DPRESENT_INTERVAL_ONE) - d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE; - } else { - if (lpCtx->d3dCaps8.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) - d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; - } - } else { - ddlogWarnOption(glb.bMessageBoxWarnings); // OK to popup messages - d3dpp.Windowed = TRUE; - d3dpp.BackBufferWidth = ctx->dwWidth; - d3dpp.BackBufferHeight = ctx->dwHeight; - d3dpp.hDeviceWindow = ctx->hWnd; - d3dpp.FullScreen_RefreshRateInHz = 0; - // FullScreen_PresentationInterval must be default for Windowed mode - d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; - } - - // Decide if we can use hardware TnL - dwBehaviourFlags = (lpCtx->bHasHWTnL) ? - D3DCREATE_MIXED_VERTEXPROCESSING : D3DCREATE_SOFTWARE_VERTEXPROCESSING; - // Add flag to tell D3D to be thread-safe - if (glb.bMultiThreaded) - dwBehaviourFlags |= D3DCREATE_MULTITHREADED; - hResult = IDirect3D8_CreateDevice(lpCtx->pD3D, - glb.dwAdapter, - d3dDevType, - ctx->hWnd, - dwBehaviourFlags, - &d3dpp, - &lpCtx->pDev); - if (FAILED(hResult)) { - ddlogError(DDLOG_CRITICAL_OR_WARN, "IDirect3D8_CreateDevice failed", hResult); - nContextError = GLDERR_D3D; - goto return_with_error; - } -*/ - - // Create D3DX context - if (ctx->bFullscreen) { - // - // FULLSCREEN - // - - // Get display mode - D3DXGetCurrentVideoMode(D3DX_DEFAULT, &d3ddm); - - // Fullscreen Parameters - dwFlags = D3DX_CONTEXT_FULLSCREEN; - hwnd = ctx->hWnd; - hwndFocus = ctx->hWnd; - numColorBits = ctx->lpPF->pfd.cColorBits; - numAlphaBits = ctx->lpPF->pfd.cAlphaBits; - numDepthBits = ctx->lpPF->pfd.cDepthBits + ctx->lpPF->pfd.cStencilBits; - numStencilBits = ctx->lpPF->pfd.cStencilBits; - numBackBuffers = D3DX_DEFAULT; // Default is 1 backbuffer - dwWidth = d3ddm.width; - dwHeight = d3ddm.height; - refreshRate = d3ddm.refreshRate; // D3DX_DEFAULT; - } else { - // - // WINDOWED - // - - // Windowed Parameters - dwFlags = 0; // No flags means "windowed" - hwnd = ctx->hWnd; - hwndFocus = (HWND)D3DX_DEFAULT; - numColorBits = D3DX_DEFAULT; // Use Desktop depth - numAlphaBits = ctx->lpPF->pfd.cAlphaBits; - numDepthBits = ctx->lpPF->pfd.cDepthBits + ctx->lpPF->pfd.cStencilBits; - numStencilBits = ctx->lpPF->pfd.cStencilBits; - numBackBuffers = D3DX_DEFAULT; // Default is 1 backbuffer - dwWidth = ctx->dwWidth; - dwHeight = ctx->dwHeight; - refreshRate = D3DX_DEFAULT; - } - hr = D3DXCreateContextEx(dwDeviceIndex, dwFlags, hwnd, hwndFocus, - numColorBits, numAlphaBits, numDepthBits, numStencilBits, - numBackBuffers, - dwWidth, dwHeight, refreshRate, - &lpCtx->pD3DXContext); - if (FAILED(hr)) { - ddlogError(DDLOG_CRITICAL_OR_WARN, "D3DXCreateContextEx failed", hr); - nContextError = GLDERR_D3D; - goto return_with_error; - } - - // Obtain D3D7 interfaces from ID3DXContext -// lpCtx->pDD = ID3DXContext_GetDD(lpCtx->pD3DXContext); - lpCtx->pDD = lpCtx->pD3DXContext->lpVtbl->GetDD(lpCtx->pD3DXContext); - if (lpCtx->pDD == NULL) - goto return_with_error; - lpCtx->pD3D = lpCtx->pD3DXContext->lpVtbl->GetD3D(lpCtx->pD3DXContext); - if (lpCtx->pD3D == NULL) - goto return_with_error; - lpCtx->pDev = lpCtx->pD3DXContext->lpVtbl->GetD3DDevice(lpCtx->pD3DXContext); - if (lpCtx->pDev == NULL) - goto return_with_error; - - // Need to manage clipper manually for multiple windows - // since DX7 D3DX utility lib does not appear to do that. (DaveM) - if (!ctx->bFullscreen) { - // Get primary surface too - lpDDSPrimary = lpCtx->pD3DXContext->lpVtbl->GetPrimary(lpCtx->pD3DXContext); - if (lpDDSPrimary == NULL) { - ddlogPrintf(DDLOG_WARN, "GetPrimary"); - goto return_with_error; - } - // Create clipper for correct window updates - if (IDirectDraw7_CreateClipper(lpCtx->pDD, 0, &lpDDClipper, NULL) != DD_OK) { - ddlogPrintf(DDLOG_WARN, "CreateClipper"); - goto return_with_error; - } - // Set the window that the clipper belongs to - if (IDirectDrawClipper_SetHWnd(lpDDClipper, 0, hwnd) != DD_OK) { - ddlogPrintf(DDLOG_WARN, "SetHWnd"); - goto return_with_error; - } - // Attach the clipper to the primary surface - if (IDirectDrawSurface7_SetClipper(lpDDSPrimary, lpDDClipper) != DD_OK) { - ddlogPrintf(DDLOG_WARN, "SetClipper"); - goto return_with_error; - } - } - - // Get device caps - IDirect3DDevice7_GetCaps(lpCtx->pDev, &lpCtx->d3dCaps); - - // Determine HW TnL - lpCtx->bHasHWTnL = lpCtx->d3dCaps.dwDevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ? TRUE : FALSE; - -#ifdef _GLD_PERSISTANT - if (bDirectDrawPersistant && bPersistantBuffers && dx7Globals.pD3D) { - dx7Globals.pDev = lpCtx->pDev; - dx7Globals.bDirect3DDevice = TRUE; - } -#endif - -#if 0 - // Dump some useful stats - hResult = IDirect3D8_GetAdapterIdentifier( - lpCtx->pD3D, - glb.dwAdapter, - D3DENUM_NO_WHQL_LEVEL, // Avoids 1 to 2 second delay - &d3dIdent); - if (SUCCEEDED(hResult)) { - ddlogPrintf(DDLOG_INFO, "[Driver Description: %s]", &d3dIdent.Description); - ddlogPrintf(DDLOG_INFO, "[Driver file: %s %d.%d.%02d.%d]", - d3dIdent.Driver, - HIWORD(d3dIdent.DriverVersion.HighPart), - LOWORD(d3dIdent.DriverVersion.HighPart), - HIWORD(d3dIdent.DriverVersion.LowPart), - LOWORD(d3dIdent.DriverVersion.LowPart)); - ddlogPrintf(DDLOG_INFO, "[VendorId: 0x%X, DeviceId: 0x%X, SubSysId: 0x%X, Revision: 0x%X]", - d3dIdent.VendorId, d3dIdent.DeviceId, d3dIdent.SubSysId, d3dIdent.Revision); - } -#endif - - // Init projection matrix for D3D TnL - D3DXMatrixIdentity((D3DXMATRIX*)&lpCtx->matProjection); - lpCtx->matModelView = lpCtx->matProjection; -// gld->bUseMesaProjection = TRUE; - -skip_direct3ddevice_create: - - // Create buffers to hold primitives - lpCtx->PB2d.dwFVF = GLD_FVF_2D_VERTEX; -// lpCtx->PB2d.dwPool = D3DPOOL_SYSTEMMEM; - lpCtx->PB2d.dwStride = sizeof(GLD_2D_VERTEX); - lpCtx->PB2d.dwCreateFlags = D3DVBCAPS_DONOTCLIP | - D3DVBCAPS_SYSTEMMEMORY | - D3DVBCAPS_WRITEONLY; - hr = _gldCreatePrimitiveBuffer(ctx->glCtx, lpCtx, &lpCtx->PB2d); - if (FAILED(hr)) - goto return_with_error; - - lpCtx->PB3d.dwFVF = GLD_FVF_3D_VERTEX; -// lpCtx->PB3d.dwPool = D3DPOOL_DEFAULT; - lpCtx->PB3d.dwStride = sizeof(GLD_3D_VERTEX); - lpCtx->PB3d.dwCreateFlags = D3DVBCAPS_WRITEONLY; - - hr = _gldCreatePrimitiveBuffer(ctx->glCtx, lpCtx, &lpCtx->PB3d); - if (FAILED(hr)) - goto return_with_error; - - // Zero the pipeline usage counters - lpCtx->PipelineUsage.qwMesa.QuadPart = -// lpCtx->PipelineUsage.dwD3D2SVS.QuadPart = - lpCtx->PipelineUsage.qwD3DFVF.QuadPart = 0; - - // Assign drawable to GL private - ctx->glPriv = lpCtx; - return TRUE; - -return_with_error: - // Clean up and bail - _gldDestroyPrimitiveBuffer(&lpCtx->PB3d); - _gldDestroyPrimitiveBuffer(&lpCtx->PB2d); - - SAFE_RELEASE(lpCtx->pDev); - SAFE_RELEASE(lpCtx->pD3D); - //SAFE_RELEASE(lpCtx->pD3DXContext); - lpCtx->pD3DXContext->lpVtbl->Release(lpCtx->pD3DXContext); - return FALSE; -} - -//--------------------------------------------------------------------------- - -BOOL gldResizeDrawable_DX( - DGL_ctx *ctx, - BOOL bDefaultDriver, - BOOL bPersistantInterface, - BOOL bPersistantBuffers) -{ - GLD_driver_dx7 *gld = NULL; -// D3DDEVTYPE d3dDevType; -// D3DPRESENT_PARAMETERS d3dpp; -// D3DDISPLAYMODE d3ddm; - D3DX_VIDMODEDESC d3ddm; - HRESULT hr; - DWORD dwWidth, dwHeight; - - // Error if context is NULL. - if (ctx == NULL) - return FALSE; - - gld = ctx->glPriv; - if (gld == NULL) - return FALSE; - - if (ctx->bSceneStarted) { - IDirect3DDevice7_EndScene(gld->pDev); - ctx->bSceneStarted = FALSE; - } -/* - d3dDevType = (glb.dwDriver == GLDS_DRIVER_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; - if (!bDefaultDriver) - d3dDevType = D3DDEVTYPE_REF; // Force Direct3D Reference Rasterise (software) - - // Get the display mode so we can make a compatible backbuffer - hResult = IDirect3D8_GetAdapterDisplayMode(gld->pD3D, glb.dwAdapter, &d3ddm); - if (FAILED(hResult)) { - nContextError = GLDERR_D3D; -// goto return_with_error; - return FALSE; - } -*/ - // Release objects before Reset() - _gldDestroyPrimitiveBuffer(&gld->PB3d); - _gldDestroyPrimitiveBuffer(&gld->PB2d); - -/* - // Clear the presentation parameters (sets all members to zero) - ZeroMemory(&d3dpp, sizeof(d3dpp)); - - // Recommended by MS; needed for MultiSample. - // Be careful if altering this for FullScreenBlit - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - - d3dpp.BackBufferFormat = d3ddm.Format; - d3dpp.BackBufferCount = 1; - d3dpp.MultiSampleType = _gldGetDeviceMultiSampleType(gld->pD3D, d3ddm.Format, d3dDevType, !ctx->bFullscreen); - d3dpp.AutoDepthStencilFormat = ctx->lpPF->dwDriverData; - d3dpp.EnableAutoDepthStencil = (d3dpp.AutoDepthStencilFormat == D3DFMT_UNKNOWN) ? FALSE : TRUE; - - // TODO: Sync to refresh - - if (ctx->bFullscreen) { - ddlogWarnOption(FALSE); // Don't popup any messages in fullscreen - d3dpp.Windowed = FALSE; - d3dpp.BackBufferWidth = d3ddm.Width; - d3dpp.BackBufferHeight = d3ddm.Height; - d3dpp.hDeviceWindow = ctx->hWnd; - d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; - d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; - // Get better benchmark results? KeithH -// d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_UNLIMITED; - } else { - ddlogWarnOption(glb.bMessageBoxWarnings); // OK to popup messages - d3dpp.Windowed = TRUE; - d3dpp.BackBufferWidth = ctx->dwWidth; - d3dpp.BackBufferHeight = ctx->dwHeight; - d3dpp.hDeviceWindow = ctx->hWnd; - d3dpp.FullScreen_RefreshRateInHz = 0; - d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; - } - hResult = IDirect3DDevice8_Reset(gld->pDev, &d3dpp); - if (FAILED(hResult)) { - ddlogError(DDLOG_CRITICAL_OR_WARN, "dglResize: Reset failed", hResult); - return FALSE; - //goto cleanup_and_return_with_error; - } -*/ - // Obtain dimensions of 'window' - if (ctx->bFullscreen) { - D3DXGetCurrentVideoMode(D3DX_DEFAULT, &d3ddm); - dwWidth = d3ddm.width; - dwHeight = d3ddm.height; - } else { - dwWidth = ctx->dwWidth; - dwHeight = ctx->dwHeight; - } - - // Resize context - hr = gld->pD3DXContext->lpVtbl->Resize(gld->pD3DXContext, dwWidth, dwHeight); - if (FAILED(hr)) { - ddlogError(DDLOG_CRITICAL_OR_WARN, "gldResizeDrawable_DX: Resize failed", hr); - return FALSE; - } - - // Clear the resized surface (DaveM) - { - D3DVIEWPORT7 vp1, vp2; - IDirect3DDevice7_GetViewport(gld->pDev, &vp1); - IDirect3DDevice7_GetViewport(gld->pDev, &vp2); - vp2.dwX = 0; - vp2.dwY = 0; - vp2.dwWidth = dwWidth; - vp2.dwHeight = dwHeight; - IDirect3DDevice7_SetViewport(gld->pDev, &vp2); - hr = gld->pD3DXContext->lpVtbl->Clear(gld->pD3DXContext, D3DCLEAR_TARGET); - if (FAILED(hr)) - ddlogError(DDLOG_WARN, "gldResizeDrawable_DX: Clear failed", hr); - IDirect3DDevice7_SetViewport(gld->pDev, &vp1); - } - - // - // Recreate objects - // - _gldCreatePrimitiveBuffer(ctx->glCtx, gld, &gld->PB2d); - _gldCreatePrimitiveBuffer(ctx->glCtx, gld, &gld->PB3d); - - // Signal a complete state update - ctx->glCtx->Driver.UpdateState(ctx->glCtx, _NEW_ALL); - - // Begin a new scene - IDirect3DDevice7_BeginScene(gld->pDev); - ctx->bSceneStarted = TRUE; - - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldDestroyDrawable_DX( - DGL_ctx *ctx) -{ - GLD_driver_dx7 *lpCtx = NULL; - - // Error if context is NULL. - if (!ctx) - return FALSE; - - // Error if the drawable does not exist. - if (!ctx->glPriv) - return FALSE; - - lpCtx = ctx->glPriv; - -#ifdef _DEBUG - // Dump out stats - ddlogPrintf(DDLOG_SYSTEM, "Usage: M:0x%X%X, D:0x%X%X", - lpCtx->PipelineUsage.qwMesa.HighPart, - lpCtx->PipelineUsage.qwMesa.LowPart, - lpCtx->PipelineUsage.qwD3DFVF.HighPart, - lpCtx->PipelineUsage.qwD3DFVF.LowPart); -#endif - - // Destroy Primtive Buffers - _gldDestroyPrimitiveBuffer(&lpCtx->PB3d); - _gldDestroyPrimitiveBuffer(&lpCtx->PB2d); - - // Release DX interfaces (in reverse order) - SAFE_RELEASE(lpCtx->pDev); - SAFE_RELEASE(lpCtx->pD3D); - //SAFE_RELEASE(lpCtx->pD3DXContext); - lpCtx->pD3DXContext->lpVtbl->Release(lpCtx->pD3DXContext); - - // Free the private drawable data - free(ctx->glPriv); - ctx->glPriv = NULL; - - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldCreatePrivateGlobals_DX(void) -{ -/* - ZeroMemory(&dx7Globals, sizeof(dx7Globals)); - - // Load d3d8.dll - dx8Globals.hD3D8DLL = LoadLibrary("D3D8.DLL"); - if (dx8Globals.hD3D8DLL == NULL) - return FALSE; - - // Now try and obtain Direct3DCreate8 - dx8Globals.fnDirect3DCreate8 = (FNDIRECT3DCREATE8)GetProcAddress(dx8Globals.hD3D8DLL, "Direct3DCreate8"); - if (dx8Globals.fnDirect3DCreate8 == NULL) { - FreeLibrary(dx8Globals.hD3D8DLL); - return FALSE; - } -*/ - - // Initialise D3DX - return FAILED(D3DXInitialize()) ? FALSE : TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldDestroyPrivateGlobals_DX(void) -{ -/* - if (dx7Globals.bDirect3DDevice) { - SAFE_RELEASE(dx7Globals.pDev); - dx7Globals.bDirect3DDevice = FALSE; - } - if (dx7Globals.bDirect3D) { - SAFE_RELEASE(dx7Globals.pD3D); - dx7Globals.bDirect3D = FALSE; - } - - FreeLibrary(dx8Globals.hD3D8DLL); - dx8Globals.hD3D8DLL = NULL; - dx8Globals.fnDirect3DCreate8 = NULL; -*/ - return FAILED(D3DXUninitialize()) ? FALSE : TRUE; -} - -//--------------------------------------------------------------------------- - -static void _BitsFromDisplayFormat( - D3DX_SURFACEFORMAT fmt, - BYTE *cColorBits, - BYTE *cRedBits, - BYTE *cGreenBits, - BYTE *cBlueBits, - BYTE *cAlphaBits) -{ - switch (fmt) { -/* case D3DX_SF_X1R5G5B5: - *cColorBits = 16; - *cRedBits = 5; - *cGreenBits = 5; - *cBlueBits = 5; - *cAlphaBits = 0; - return;*/ - case D3DX_SF_R5G5B5: - *cColorBits = 16; - *cRedBits = 5; - *cGreenBits = 5; - *cBlueBits = 5; - *cAlphaBits = 0; - return; - case D3DX_SF_R5G6B5: - *cColorBits = 16; - *cRedBits = 5; - *cGreenBits = 6; - *cBlueBits = 5; - *cAlphaBits = 0; - return; - case D3DX_SF_X8R8G8B8: - *cColorBits = 32; - *cRedBits = 8; - *cGreenBits = 8; - *cBlueBits = 8; - *cAlphaBits = 0; - return; - case D3DX_SF_A8R8G8B8: - *cColorBits = 32; - *cRedBits = 8; - *cGreenBits = 8; - *cBlueBits = 8; - *cAlphaBits = 8; - return; - } - - // Should not get here! - *cColorBits = 32; - *cRedBits = 8; - *cGreenBits = 8; - *cBlueBits = 8; - *cAlphaBits = 0; -} - -//--------------------------------------------------------------------------- - -static void _BitsFromDepthStencilFormat( - D3DX_SURFACEFORMAT fmt, - BYTE *cDepthBits, - BYTE *cStencilBits) -{ - // NOTE: GL expects either 32 or 16 as depth bits. - switch (fmt) { - case D3DX_SF_Z16S0: - *cDepthBits = 16; - *cStencilBits = 0; - return; - case D3DX_SF_Z32S0: - *cDepthBits = 32; - *cStencilBits = 0; - return; - case D3DX_SF_Z15S1: - *cDepthBits = 15; - *cStencilBits = 1; - return; - case D3DX_SF_Z24S8: - *cDepthBits = 24; - *cStencilBits = 8; - return; - case D3DX_SF_S1Z15: - *cDepthBits = 15; - *cStencilBits = 1; - return; - case D3DX_SF_S8Z24: - *cDepthBits = 24; - *cStencilBits = 8; - return; - } -} - -//--------------------------------------------------------------------------- -/* -BOOL GLD_CheckDepthStencilMatch( - DWORD dwDeviceIndex, - D3DX_SURFACEFORMAT sfWant) -{ - // Emulate function built in to DX9 - D3DX_SURFACEFORMAT sfFound; - int i; - int nFormats = D3DXGetMaxSurfaceFormats(dwDeviceIndex, NULL, D3DX_SC_DEPTHBUFFER); - if (nFormats) { - for (i=0; i<nFormats; i++) { - D3DXGetSurfaceFormat(dwDeviceIndex, NULL, D3DX_SC_DEPTHBUFFER, i, &sfFound); } - if (sfFound == sfWant) - return TRUE; - } - - return FALSE; -} -*/ -//--------------------------------------------------------------------------- - -D3DX_SURFACEFORMAT _gldFindCompatibleDepthStencilFormat( - DWORD dwDeviceIndex) -{ - // Jump through some hoops... - - ID3DXContext *pD3DXContext = NULL; - IDirectDrawSurface7 *pZBuffer = NULL; - DDPIXELFORMAT ddpf; - HWND hWnd; - - // Get an HWND - use Desktop's - hWnd = GetDesktopWindow(); - - // Create a fully specified default context. - D3DXCreateContextEx(dwDeviceIndex, 0, hWnd, (HWND)D3DX_DEFAULT, - D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, - D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, - &pD3DXContext); - - // Obtain depth buffer that was created in context - pZBuffer = pD3DXContext->lpVtbl->GetZBuffer(pD3DXContext); - - // Get pixel format of depth buffer - ddpf.dwSize = sizeof(ddpf); - pZBuffer->lpVtbl->GetPixelFormat(pZBuffer, &ddpf); - // Done with surface - release it - pZBuffer->lpVtbl->Release(pZBuffer); - - // Done with D3DX context - pD3DXContext->lpVtbl->Release(pD3DXContext); - - // Convert and return - return D3DXMakeSurfaceFormat(&ddpf); -} - -//--------------------------------------------------------------------------- - -BOOL gldBuildPixelformatList_DX(void) -{ - D3DX_DEVICEDESC d3dxdd; - D3DX_VIDMODEDESC d3ddm; - D3DX_SURFACEFORMAT fmt[64]; // 64 should be enough... - DWORD dwDeviceIndex; - DWORD surfClassFlags; -// IDirect3D7 *pD3D = NULL; - HRESULT hr; - int nSupportedFormats = 0; // Total formats - int nDepthOnlyFormats = 0; - int nDepthStencilFormats = 0; - int i; - DGL_pixelFormat *pPF; - BYTE cColorBits, cRedBits, cGreenBits, cBlueBits, cAlphaBits; -// char buf[128]; -// char cat[8]; - - // Direct3D (SW or HW) - // These are arranged so that 'best' pixelformat - // is higher in the list (for ChoosePixelFormat). -/* const D3DFORMAT DepthStencil[4] = { - D3DX_SF_Z16S0, //D3DX_SF_D16, - D3DX_SF_Z15S1, //D3DX_SF_D15S1, - D3DX_SF_Z32S0, //D3DX_SF_D32, - D3DX_SF_Z24S8, //D3DX_SF_D24S8, - //D3DX_SF_D24X8, - //D3DX_SF_D24X4S4, - };*/ - - // Dump DX version - ddlogMessage(GLDLOG_SYSTEM, "DirectX Version : 7.0\n"); - - // Release any existing pixelformat list - if (glb.lpPF) { - free(glb.lpPF); - } - - glb.nPixelFormatCount = 0; - glb.lpPF = NULL; - - // - // Pixelformats for Direct3D (SW or HW) rendering - // - - dwDeviceIndex = (glb.dwDriver == GLDS_DRIVER_REF) ? D3DX_HWLEVEL_REFERENCE : D3DX_DEFAULT; - - // Dump description - D3DXGetDeviceDescription(dwDeviceIndex, &d3dxdd); - ddlogPrintf(GLDLOG_SYSTEM, "Device: %s", d3dxdd.driverDesc); - - // Get display mode - D3DXGetCurrentVideoMode(D3DX_DEFAULT, &d3ddm); - -#if 0 - // Phooey - this don't work... -/* - // Since D3DXGetMaxSurfaceFormats() can lie to us, we'll need a workaround. - // Explicitly test for matching depth/stencil to display bpp. - if (d3ddm.bpp <= 16) { - if (GLD_CheckDepthStencilMatch(dwDeviceIndex, D3DX_SF_Z16S0)) - fmt[nSupportedFormats++] = D3DX_SF_Z16S0; - if (GLD_CheckDepthStencilMatch(dwDeviceIndex, D3DX_SF_Z15S1)) - fmt[nSupportedFormats++] = D3DX_SF_Z15S1; - if (GLD_CheckDepthStencilMatch(dwDeviceIndex, D3DX_SF_S1Z15)) - fmt[nSupportedFormats++] = D3DX_SF_S1Z15; - // Didn't find anything? Try default - if (nSupportedFormats == 0) { - if (GLD_CheckDepthStencilMatch(dwDeviceIndex, D3DX_SF_Z32S0)) - fmt[nSupportedFormats++] = D3DX_SF_Z32S0; - } - } else { - if (GLD_CheckDepthStencilMatch(dwDeviceIndex, D3DX_SF_Z32S0)) - fmt[nSupportedFormats++] = D3DX_SF_Z32S0; - if (GLD_CheckDepthStencilMatch(dwDeviceIndex, D3DX_SF_Z24S8)) - fmt[nSupportedFormats++] = D3DX_SF_Z24S8; - if (GLD_CheckDepthStencilMatch(dwDeviceIndex, D3DX_SF_S8Z24)) - fmt[nSupportedFormats++] = D3DX_SF_S8Z24; - // Didn't find anything? Try default - if (nSupportedFormats == 0) { - if (GLD_CheckDepthStencilMatch(dwDeviceIndex, D3DX_SF_Z16S0)) - fmt[nSupportedFormats++] = D3DX_SF_Z16S0; - } - } -*/ - // Go the Whole Hog... - fmt[nSupportedFormats++] = _gldFindCompatibleDepthStencilFormat(dwDeviceIndex); -#else - // - // Depth buffer formats WITHOUT stencil - // - surfClassFlags = D3DX_SC_DEPTHBUFFER; - nDepthOnlyFormats = D3DXGetMaxSurfaceFormats(dwDeviceIndex, NULL, surfClassFlags); - // - // Depth buffer formats WITH stencil - // - surfClassFlags = D3DX_SC_DEPTHBUFFER | D3DX_SC_STENCILBUFFER; - nDepthStencilFormats = D3DXGetMaxSurfaceFormats(dwDeviceIndex, NULL, surfClassFlags); - - // Work out how many formats we have in total - if ((nDepthOnlyFormats + nDepthStencilFormats) == 0) - return FALSE; // Bail: no compliant pixelformats - - // Get depth buffer formats WITHOUT stencil - surfClassFlags = D3DX_SC_DEPTHBUFFER; - for (i=0; i<nDepthOnlyFormats; i++) { - D3DXGetSurfaceFormat(dwDeviceIndex, NULL, surfClassFlags, i, &fmt[nSupportedFormats++]); - } - // NOTE: For some reason we already get stencil formats when only specifying D3DX_SC_DEPTHBUFFER - /* - // Get depth buffer formats WITH stencil - surfClassFlags = D3DX_SC_DEPTHBUFFER | D3DX_SC_STENCILBUFFER; - for (i=0; i<nDepthStencilFormats; i++) { - D3DXGetSurfaceFormat(dwDeviceIndex, NULL, surfClassFlags, i, &fmt[nSupportedFormats++]); - } - */ -#endif - - // Total count of pixelformats is: - // (nSupportedFormats+1)*2 - glb.lpPF = (DGL_pixelFormat *)calloc((nSupportedFormats)*2, sizeof(DGL_pixelFormat)); - glb.nPixelFormatCount = (nSupportedFormats)*2; - if (glb.lpPF == NULL) { - glb.nPixelFormatCount = 0; - return FALSE; - } - - // Get a copy of pointer that we can alter - pPF = glb.lpPF; - - // Cache colour bits from display format -// _BitsFromDisplayFormat(d3ddm.Format, &cColorBits, &cRedBits, &cGreenBits, &cBlueBits, &cAlphaBits); - // Get display mode - D3DXGetCurrentVideoMode(D3DX_DEFAULT, &d3ddm); - cColorBits = d3ddm.bpp; - cAlphaBits = 0; - switch (d3ddm.bpp) { - case 15: - cRedBits = 5; cGreenBits = 5; cBlueBits = 5; - break; - case 16: - cRedBits = 5; cGreenBits = 6; cBlueBits = 5; - break; - case 24: - case 32: - cRedBits = 8; cGreenBits = 8; cBlueBits = 8; - break; - default: - cRedBits = 5; cGreenBits = 5; cBlueBits = 5; - } - - // - // Add single-buffer formats - // - -/* // Single-buffer, no depth-stencil buffer - memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); - pPF->pfd.dwFlags &= ~PFD_DOUBLEBUFFER; // Remove doublebuffer flag - pPF->pfd.cColorBits = cColorBits; - pPF->pfd.cRedBits = cRedBits; - pPF->pfd.cGreenBits = cGreenBits; - pPF->pfd.cBlueBits = cBlueBits; - pPF->pfd.cAlphaBits = cAlphaBits; - pPF->pfd.cDepthBits = 0; - pPF->pfd.cStencilBits = 0; - pPF->dwDriverData = D3DX_SF_UNKNOWN; - pPF++;*/ - - for (i=0; i<nSupportedFormats; i++, pPF++) { - memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); - pPF->pfd.dwFlags &= ~PFD_DOUBLEBUFFER; // Remove doublebuffer flag - pPF->pfd.cColorBits = cColorBits; - pPF->pfd.cRedBits = cRedBits; - pPF->pfd.cGreenBits = cGreenBits; - pPF->pfd.cBlueBits = cBlueBits; - pPF->pfd.cAlphaBits = cAlphaBits; - _BitsFromDepthStencilFormat(fmt[i], &pPF->pfd.cDepthBits, &pPF->pfd.cStencilBits); - pPF->dwDriverData = fmt[i]; - } - - // - // Add double-buffer formats - // - -/* memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); - pPF->pfd.cColorBits = cColorBits; - pPF->pfd.cRedBits = cRedBits; - pPF->pfd.cGreenBits = cGreenBits; - pPF->pfd.cBlueBits = cBlueBits; - pPF->pfd.cAlphaBits = cAlphaBits; - pPF->pfd.cDepthBits = 0; - pPF->pfd.cStencilBits = 0; - pPF->dwDriverData = D3DX_SF_UNKNOWN; - pPF++;*/ - - for (i=0; i<nSupportedFormats; i++, pPF++) { - memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); - pPF->pfd.cColorBits = cColorBits; - pPF->pfd.cRedBits = cRedBits; - pPF->pfd.cGreenBits = cGreenBits; - pPF->pfd.cBlueBits = cBlueBits; - pPF->pfd.cAlphaBits = cAlphaBits; - _BitsFromDepthStencilFormat(fmt[i], &pPF->pfd.cDepthBits, &pPF->pfd.cStencilBits); - pPF->dwDriverData = fmt[i]; - } - - // Popup warning message if non RGB color mode - { - // This is a hack. KeithH - HDC hdcDesktop = GetDC(NULL); - DWORD dwDisplayBitDepth = GetDeviceCaps(hdcDesktop, BITSPIXEL); - ReleaseDC(0, hdcDesktop); - if (dwDisplayBitDepth <= 8) { - ddlogPrintf(DDLOG_WARN, "Current Color Depth %d bpp is not supported", dwDisplayBitDepth); - MessageBox(NULL, szColorDepthWarning, "GLDirect", MB_OK | MB_ICONWARNING); - } - } - - // Mark list as 'current' - glb.bPixelformatsDirty = FALSE; - - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldInitialiseMesa_DX( - DGL_ctx *lpCtx) -{ - GLD_driver_dx7 *gld = NULL; - int MaxTextureSize, TextureLevels; - BOOL bSoftwareTnL; - - if (lpCtx == NULL) - return FALSE; - - gld = lpCtx->glPriv; - if (gld == NULL) - return FALSE; - - if (glb.bMultitexture) { - lpCtx->glCtx->Const.MaxTextureUnits = gld->d3dCaps.wMaxSimultaneousTextures; - // Only support MAX_TEXTURE_UNITS texture units. - // ** If this is altered then the FVF formats must be reviewed **. - if (lpCtx->glCtx->Const.MaxTextureUnits > GLD_MAX_TEXTURE_UNITS_DX7) - lpCtx->glCtx->Const.MaxTextureUnits = GLD_MAX_TEXTURE_UNITS_DX7; - } else { - // Multitexture override - lpCtx->glCtx->Const.MaxTextureUnits = 1; - } - - lpCtx->glCtx->Const.MaxDrawBuffers = 1; - - // max texture size -// MaxTextureSize = min(gld->d3dCaps8.MaxTextureHeight, gld->d3dCaps8.MaxTextureWidth); - MaxTextureSize = min(gld->d3dCaps.dwMaxTextureHeight, gld->d3dCaps.dwMaxTextureWidth); - if (MaxTextureSize == 0) - MaxTextureSize = 256; // Sanity check - - // - // HACK!! - if (MaxTextureSize > 1024) - MaxTextureSize = 1024; // HACK - CLAMP TO 1024 - // HACK!! - // - - // TODO: Check this again for Mesa 5 - // Got to set MAX_TEXTURE_SIZE as max levels. - // Who thought this stupid idea up? ;) - TextureLevels = 0; - // Calculate power-of-two. - while (MaxTextureSize) { - TextureLevels++; - MaxTextureSize >>= 1; - } - lpCtx->glCtx->Const.MaxTextureLevels = (TextureLevels) ? TextureLevels : 8; - - // Defaults - IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_LIGHTING, FALSE); - IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE); - IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_DITHERENABLE, TRUE); - IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_SHADEMODE, D3DSHADE_GOURAUD); - - // Set texture coord set to be used with each stage - IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_TEXCOORDINDEX, 0); - IDirect3DDevice7_SetTextureStageState(gld->pDev, 1, D3DTSS_TEXCOORDINDEX, 1); - - // Set up Depth buffer - IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_ZENABLE, - (lpCtx->lpPF->dwDriverData!=D3DX_SF_UNKNOWN) ? D3DZB_TRUE : D3DZB_FALSE); - - // Set the view matrix - { - D3DXMATRIX vm; -#if 1 - D3DXMatrixIdentity(&vm); -#else - D3DXVECTOR3 Eye(0.0f, 0.0f, 0.0f); - D3DXVECTOR3 At(0.0f, 0.0f, -1.0f); - D3DXVECTOR3 Up(0.0f, 1.0f, 0.0f); - D3DXMatrixLookAtRH(&vm, &Eye, &At, &Up); - vm._31 = -vm._31; - vm._32 = -vm._32; - vm._33 = -vm._33; - vm._34 = -vm._34; -#endif - IDirect3DDevice7_SetTransform(gld->pDev, D3DTRANSFORMSTATE_VIEW, &vm); - } - -// DX7 does not support D3DRS_SOFTWAREVERTEXPROCESSING -/* - if (gld->bHasHWTnL) { - if (glb.dwTnL == GLDS_TNL_DEFAULT) - bSoftwareTnL = FALSE; // HW TnL - else { - bSoftwareTnL = ((glb.dwTnL == GLDS_TNL_MESA) || (glb.dwTnL == GLDS_TNL_D3DSW)) ? TRUE : FALSE; - } - } else { - // No HW TnL, so no choice possible - bSoftwareTnL = TRUE; - } - IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, bSoftwareTnL); -*/ - -// Dump this in a Release build as well, now. -//#ifdef _DEBUG - ddlogPrintf(DDLOG_INFO, "HW TnL: %s", -// gld->bHasHWTnL ? (bSoftwareTnL ? "Disabled" : "Enabled") : "Unavailable"); - gld->bHasHWTnL ? "Enabled" : "Unavailable"); -//#endif - - // Set up interfaces to Mesa - gldEnableExtensions_DX7(lpCtx->glCtx); - gldInstallPipeline_DX7(lpCtx->glCtx); - gldSetupDriverPointers_DX7(lpCtx->glCtx); - - // Signal a complete state update - lpCtx->glCtx->Driver.UpdateState(lpCtx->glCtx, _NEW_ALL); - - // Start a scene - IDirect3DDevice7_BeginScene(gld->pDev); - lpCtx->bSceneStarted = TRUE; - - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldSwapBuffers_DX( - DGL_ctx *ctx, - HDC hDC, - HWND hWnd) -{ - HRESULT hr; - GLD_driver_dx7 *gld = NULL; - DWORD dwFlags; - - if (ctx == NULL) - return FALSE; - - gld = ctx->glPriv; - if (gld == NULL) - return FALSE; - - - // End the scene if one is started - if (ctx->bSceneStarted) { - IDirect3DDevice7_EndScene(gld->pDev); - ctx->bSceneStarted = FALSE; - } - - // Needed by D3DX for MDI multi-window apps (DaveM) - if (lpDDClipper) - IDirectDrawClipper_SetHWnd(lpDDClipper, 0, hWnd); - - // Swap the buffers. hWnd may override the hWnd used for CreateDevice() -// hr = IDirect3DDevice8_Present(gld->pDev, NULL, NULL, hWnd, NULL); - - // Set refresh sync flag - dwFlags = glb.bWaitForRetrace ? 0 : D3DX_UPDATE_NOVSYNC; - // Render and show frame - hr = gld->pD3DXContext->lpVtbl->UpdateFrame(gld->pD3DXContext, dwFlags); - if (FAILED(hr)) - ddlogError(DDLOG_WARN, "gldSwapBuffers_DX: UpdateFrame", hr); - - if (hr == DDERR_SURFACELOST) { - hr = gld->pD3DXContext->lpVtbl->RestoreSurfaces(gld->pD3DXContext); - if (FAILED(hr)) - ddlogError(DDLOG_WARN, "gldSwapBuffers_DX: RestoreSurfaces", hr); - } - -exit_swap: - // Begin a new scene - IDirect3DDevice7_BeginScene(gld->pDev); - ctx->bSceneStarted = TRUE; - - return (FAILED(hr)) ? FALSE : TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldGetDisplayMode_DX( - DGL_ctx *ctx, - GLD_displayMode *glddm) -{ -// D3DDISPLAYMODE d3ddm; - D3DX_VIDMODEDESC d3ddm; - HRESULT hr; - GLD_driver_dx7 *lpCtx = NULL; - BYTE cColorBits, cRedBits, cGreenBits, cBlueBits, cAlphaBits; - - if ((glddm == NULL) || (ctx == NULL)) - return FALSE; - - lpCtx = ctx->glPriv; - if (lpCtx == NULL) - return FALSE; - - if (lpCtx->pD3D == NULL) - return FALSE; - -// hr = IDirect3D8_GetAdapterDisplayMode(lpCtx->pD3D, glb.dwAdapter, &d3ddm); - hr = D3DXGetCurrentVideoMode(D3DX_DEFAULT, &d3ddm); - if (FAILED(hr)) - return FALSE; - - // Get info from the display format -// _BitsFromDisplayFormat(d3ddm.Format, -// &cColorBits, &cRedBits, &cGreenBits, &cBlueBits, &cAlphaBits); - - glddm->Width = d3ddm.width; - glddm->Height = d3ddm.height; - glddm->BPP = d3ddm.bpp; - glddm->Refresh = d3ddm.refreshRate; - - return TRUE; -} - -//--------------------------------------------------------------------------- - diff --git a/src/mesa/drivers/windows/gldirect/dx8/gld_driver_dx8.c b/src/mesa/drivers/windows/gldirect/dx8/gld_driver_dx8.c deleted file mode 100644 index 7afa9190cd..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx8/gld_driver_dx8.c +++ /dev/null @@ -1,1176 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: Driver interface code to Mesa -* -****************************************************************************/ - -//#include <windows.h> -#include "dglcontext.h" -#include "ddlog.h" -#include "gld_dx8.h" - -#include "glheader.h" -#include "context.h" -#include "colormac.h" -#include "depth.h" -#include "extensions.h" -#include "macros.h" -#include "matrix.h" -// #include "mem.h" -//#include "mmath.h" -#include "mtypes.h" -#include "texformat.h" -#include "teximage.h" -#include "texstore.h" -#include "vbo/vbo.h" -#include "swrast_setup/swrast_setup.h" -#include "swrast_setup/ss_context.h" -#include "tnl/tnl.h" -#include "tnl/t_context.h" -#include "tnl/t_pipeline.h" - -extern BOOL dglSwapBuffers(HDC hDC); - -// HACK: Hack the _33 member of the OpenGL perspective projection matrix -const float _fPersp_33 = 1.6f; - -//--------------------------------------------------------------------------- -// Internal functions -//--------------------------------------------------------------------------- - -void _gld_mesa_warning( - __GLcontext *gc, - char *str) -{ - // Intercept Mesa's internal warning mechanism - gldLogPrintf(GLDLOG_WARN, "Mesa warning: %s", str); -} - -//--------------------------------------------------------------------------- - -void _gld_mesa_fatal( - __GLcontext *gc, - char *str) -{ - // Intercept Mesa's internal fatal-message mechanism - gldLogPrintf(GLDLOG_CRITICAL, "Mesa FATAL: %s", str); - - // Mesa calls abort(0) here. - ddlogClose(); - exit(0); -} - -//--------------------------------------------------------------------------- - -D3DSTENCILOP _gldConvertStencilOp( - GLenum StencilOp) -{ - // Used by Stencil: pass, fail and zfail - - switch (StencilOp) { - case GL_KEEP: - return D3DSTENCILOP_KEEP; - case GL_ZERO: - return D3DSTENCILOP_ZERO; - case GL_REPLACE: - return D3DSTENCILOP_REPLACE; - case GL_INCR: - return D3DSTENCILOP_INCRSAT; - case GL_DECR: - return D3DSTENCILOP_DECRSAT; - case GL_INVERT: - return D3DSTENCILOP_INVERT; - case GL_INCR_WRAP_EXT: // GL_EXT_stencil_wrap - return D3DSTENCILOP_INCR; - case GL_DECR_WRAP_EXT: // GL_EXT_stencil_wrap - return D3DSTENCILOP_DECR; - } - -#ifdef _DEBUG - gldLogMessage(GLDLOG_ERROR, "_gldConvertStencilOp: Unknown StencilOp\n"); -#endif - - return D3DSTENCILOP_KEEP; -} - -//--------------------------------------------------------------------------- - -D3DCMPFUNC _gldConvertCompareFunc( - GLenum CmpFunc) -{ - // Used for Alpha func, depth func and stencil func. - - switch (CmpFunc) { - case GL_NEVER: - return D3DCMP_NEVER; - case GL_LESS: - return D3DCMP_LESS; - case GL_EQUAL: - return D3DCMP_EQUAL; - case GL_LEQUAL: - return D3DCMP_LESSEQUAL; - case GL_GREATER: - return D3DCMP_GREATER; - case GL_NOTEQUAL: - return D3DCMP_NOTEQUAL; - case GL_GEQUAL: - return D3DCMP_GREATEREQUAL; - case GL_ALWAYS: - return D3DCMP_ALWAYS; - }; - -#ifdef _DEBUG - gldLogMessage(GLDLOG_ERROR, "_gldConvertCompareFunc: Unknown CompareFunc\n"); -#endif - - return D3DCMP_ALWAYS; -} - -//--------------------------------------------------------------------------- - -D3DBLEND _gldConvertBlendFunc( - GLenum blend, - GLenum DefaultBlend) -{ - switch (blend) { - case GL_ZERO: - return D3DBLEND_ZERO; - case GL_ONE: - return D3DBLEND_ONE; - case GL_DST_COLOR: - return D3DBLEND_DESTCOLOR; - case GL_SRC_COLOR: - return D3DBLEND_SRCCOLOR; - case GL_ONE_MINUS_DST_COLOR: - return D3DBLEND_INVDESTCOLOR; - case GL_ONE_MINUS_SRC_COLOR: - return D3DBLEND_INVSRCCOLOR; - case GL_SRC_ALPHA: - return D3DBLEND_SRCALPHA; - case GL_ONE_MINUS_SRC_ALPHA: - return D3DBLEND_INVSRCALPHA; - case GL_DST_ALPHA: - return D3DBLEND_DESTALPHA; - case GL_ONE_MINUS_DST_ALPHA: - return D3DBLEND_INVDESTALPHA; - case GL_SRC_ALPHA_SATURATE: - return D3DBLEND_SRCALPHASAT; - } - -#ifdef _DEBUG - gldLogMessage(GLDLOG_ERROR, "_gldConvertBlendFunc: Unknown BlendFunc\n"); -#endif - - return DefaultBlend; -} - -//--------------------------------------------------------------------------- -// Misc. functions -//--------------------------------------------------------------------------- - -void gld_Noop_DX8( - GLcontext *ctx) -{ -#ifdef _DEBUG - gldLogMessage(GLDLOG_ERROR, "gld_Noop called!\n"); -#endif -} - -//--------------------------------------------------------------------------- - -void gld_Error_DX8( - GLcontext *ctx) -{ -#ifdef _DEBUG - // Quite useless. -// gldLogMessage(GLDLOG_ERROR, "ctx->Driver.Error called!\n"); -#endif -} - -//--------------------------------------------------------------------------- -// Required Mesa functions -//--------------------------------------------------------------------------- - -static GLboolean gld_set_draw_buffer_DX8( - GLcontext *ctx, - GLenum mode) -{ - (void) ctx; - if ((mode==GL_FRONT_LEFT) || (mode == GL_BACK_LEFT)) { - return GL_TRUE; - } - else { - return GL_FALSE; - } -} - -//--------------------------------------------------------------------------- - -static void gld_set_read_buffer_DX8( - GLcontext *ctx, - GLframebuffer *buffer, - GLenum mode) -{ - /* separate read buffer not supported */ -/* - ASSERT(buffer == ctx->DrawBuffer); - ASSERT(mode == GL_FRONT_LEFT); -*/ -} - -//--------------------------------------------------------------------------- - -void gld_Clear_DX8( - GLcontext *ctx, - GLbitfield mask, - GLboolean all, - GLint x, - GLint y, - GLint width, - GLint height) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - DWORD dwFlags = 0; - D3DCOLOR Color = 0; - float Z = 0.0f; - DWORD Stencil = 0; - D3DRECT d3dClearRect; - - // TODO: Colourmask - const GLuint *colorMask = (GLuint *) &ctx->Color.ColorMask; - - if (!gld->pDev) - return; - - if (mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT)) { - GLubyte col[4]; - CLAMPED_FLOAT_TO_UBYTE(col[0], ctx->Color.ClearColor[0]); - CLAMPED_FLOAT_TO_UBYTE(col[1], ctx->Color.ClearColor[1]); - CLAMPED_FLOAT_TO_UBYTE(col[2], ctx->Color.ClearColor[2]); - CLAMPED_FLOAT_TO_UBYTE(col[3], ctx->Color.ClearColor[3]); - dwFlags |= D3DCLEAR_TARGET; - Color = D3DCOLOR_RGBA(col[0], col[1], col[2], col[3]); -// ctx->Color.ClearColor[1], -// ctx->Color.ClearColor[2], -// ctx->Color.ClearColor[3]); - } - - if (mask & DD_DEPTH_BIT) { - // D3D8 will fail the Clear call if we try and clear a - // depth buffer and we haven't created one. - // Also, some apps try and clear a depth buffer, - // when a depth buffer hasn't been requested by the app. - if (ctx->Visual.depthBits == 0) { - mask &= ~DD_DEPTH_BIT; // Remove depth bit from mask - } else { - dwFlags |= D3DCLEAR_ZBUFFER; - Z = ctx->Depth.Clear; - } - } - - if (mask & DD_STENCIL_BIT) { - if (ctx->Visual.stencilBits == 0) { - // No stencil bits in depth buffer - mask &= ~DD_STENCIL_BIT; // Remove stencil bit from mask - } else { - dwFlags |= D3DCLEAR_STENCIL; - Stencil = ctx->Stencil.Clear; - } - } - - // Some apps do really weird things with the rect, such as Quake3. - if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0)) { - all = GL_TRUE; - } - - if (!all) { - // Calculate clear subrect - d3dClearRect.x1 = x; - d3dClearRect.y1 = gldCtx->dwHeight - (y + height); - d3dClearRect.x2 = x + width; - d3dClearRect.y2 = d3dClearRect.y1 + height; - } - - // dwFlags will be zero if there's nothing to clear - if (dwFlags) { - _GLD_DX8_DEV(Clear( - gld->pDev, - all ? 0 : 1, - all ? NULL : &d3dClearRect, - dwFlags, - Color, Z, Stencil)); - } - - if (mask & DD_ACCUM_BIT) { - // Clear accumulation buffer - } -} - -//--------------------------------------------------------------------------- - -// Mesa 5: Parameter change -static void gld_buffer_size_DX8( -// GLcontext *ctx, - GLframebuffer *fb, - GLuint *width, - GLuint *height) -{ -// GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - - *width = fb->Width; // gldCtx->dwWidth; - *height = fb->Height; // gldCtx->dwHeight; -} - -//--------------------------------------------------------------------------- - -static void gld_Finish_DX8( - GLcontext *ctx) -{ -} - -//--------------------------------------------------------------------------- - -static void gld_Flush_DX8( - GLcontext *ctx) -{ - GLD_context *gld = GLD_GET_CONTEXT(ctx); - - // TODO: Detect apps that glFlush() then SwapBuffers() ? - - if (gld->EmulateSingle) { - // Emulating a single-buffered context. - // [Direct3D doesn't allow rendering to front buffer] - dglSwapBuffers(gld->hDC); - } -} - -//--------------------------------------------------------------------------- - -void gld_NEW_STENCIL( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - // Two-sided stencil. New for Mesa 5 - const GLuint uiFace = 0UL; - - struct gl_stencil_attrib *pStencil = &ctx->Stencil; - - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILENABLE, pStencil->Enabled ? TRUE : FALSE)); - if (pStencil->Enabled) { - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILFUNC, _gldConvertCompareFunc(pStencil->Function[uiFace]))); - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILREF, pStencil->Ref[uiFace])); - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILMASK, pStencil->ValueMask[uiFace])); - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILWRITEMASK, pStencil->WriteMask[uiFace])); - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILFAIL, _gldConvertStencilOp(pStencil->FailFunc[uiFace]))); - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILZFAIL, _gldConvertStencilOp(pStencil->ZFailFunc[uiFace]))); - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILPASS, _gldConvertStencilOp(pStencil->ZPassFunc[uiFace]))); - } -} - -//--------------------------------------------------------------------------- - -void gld_NEW_COLOR( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - DWORD dwFlags = 0; - D3DBLEND src; - D3DBLEND dest; - - // Alpha func - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ALPHAFUNC, _gldConvertCompareFunc(ctx->Color.AlphaFunc))); - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ALPHAREF, (DWORD)ctx->Color.AlphaRef)); - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ALPHATESTENABLE, ctx->Color.AlphaEnabled)); - - // Blend func - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ALPHABLENDENABLE, ctx->Color.BlendEnabled)); - src = _gldConvertBlendFunc(ctx->Color.BlendSrcRGB, GL_ONE); - dest = _gldConvertBlendFunc(ctx->Color.BlendDstRGB, GL_ZERO); - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_SRCBLEND, src)); - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_DESTBLEND, dest)); - - // Color mask - if (ctx->Color.ColorMask[0]) dwFlags |= D3DCOLORWRITEENABLE_RED; - if (ctx->Color.ColorMask[1]) dwFlags |= D3DCOLORWRITEENABLE_GREEN; - if (ctx->Color.ColorMask[2]) dwFlags |= D3DCOLORWRITEENABLE_BLUE; - if (ctx->Color.ColorMask[3]) dwFlags |= D3DCOLORWRITEENABLE_ALPHA; - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_COLORWRITEENABLE, dwFlags)); -} - -//--------------------------------------------------------------------------- - -void gld_NEW_DEPTH( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ZENABLE, ctx->Depth.Test ? D3DZB_TRUE : D3DZB_FALSE)); - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ZFUNC, _gldConvertCompareFunc(ctx->Depth.Func))); - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ZWRITEENABLE, ctx->Depth.Mask ? TRUE : FALSE)); -} - -//--------------------------------------------------------------------------- - -void gld_NEW_POLYGON( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - D3DFILLMODE d3dFillMode = D3DFILL_SOLID; - D3DCULL d3dCullMode = D3DCULL_NONE; - int iOffset = 0; - - // Fillmode - switch (ctx->Polygon.FrontMode) { - case GL_POINT: - d3dFillMode = D3DFILL_POINT; - break; - case GL_LINE: - d3dFillMode = D3DFILL_WIREFRAME; - break; - case GL_FILL: - d3dFillMode = D3DFILL_SOLID; - break; - } - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FILLMODE, d3dFillMode)); - - if (ctx->Polygon.CullFlag) { - switch (ctx->Polygon.CullFaceMode) { - case GL_BACK: - if (ctx->Polygon.FrontFace == GL_CCW) - d3dCullMode = D3DCULL_CW; - else - d3dCullMode = D3DCULL_CCW; - break; - case GL_FRONT: - if (ctx->Polygon.FrontFace == GL_CCW) - d3dCullMode = D3DCULL_CCW; - else - d3dCullMode = D3DCULL_CW; - break; - case GL_FRONT_AND_BACK: - d3dCullMode = D3DCULL_NONE; - break; - default: - break; - } - } else { - d3dCullMode = D3DCULL_NONE; - } -// d3dCullMode = D3DCULL_NONE; // TODO: DEBUGGING - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_CULLMODE, d3dCullMode)); - - // Polygon offset - // ZBIAS ranges from 0 to 16 and can only move towards the viewer - // Mesa5: ctx->Polygon._OffsetAny removed - if (ctx->Polygon.OffsetFill) { - iOffset = (int)ctx->Polygon.OffsetUnits; - if (iOffset < 0) - iOffset = -iOffset; - else - iOffset = 0; // D3D can't push away - } - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ZBIAS, iOffset)); -} - -//--------------------------------------------------------------------------- - -void gld_NEW_FOG( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - D3DCOLOR d3dFogColour; - D3DFOGMODE d3dFogMode = D3DFOG_LINEAR; - - // TODO: Fog is calculated seperately in the Mesa pipeline - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGENABLE, FALSE)); - return; - - // Fog enable - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGENABLE, ctx->Fog.Enabled)); - if (!ctx->Fog.Enabled) { - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGTABLEMODE, D3DFOG_NONE)); - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGVERTEXMODE, D3DFOG_NONE)); - return; // If disabled, don't bother setting any fog state - } - - // Fog colour - d3dFogColour = D3DCOLOR_COLORVALUE( ctx->Fog.Color[0], - ctx->Fog.Color[1], - ctx->Fog.Color[2], - ctx->Fog.Color[3]); - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGCOLOR, d3dFogColour)); - - // Fog density - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGDENSITY, *((DWORD*) (&ctx->Fog.Density)))); - - // Fog start - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGSTART, *((DWORD*) (&ctx->Fog.Start)))); - - // Fog end - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGEND, *((DWORD*) (&ctx->Fog.End)))); - - // Fog mode - switch (ctx->Fog.Mode) { - case GL_LINEAR: - d3dFogMode = D3DFOG_LINEAR; - break; - case GL_EXP: - d3dFogMode = D3DFOG_EXP; - break; - case GL_EXP2: - d3dFogMode = D3DFOG_EXP2; - break; - } - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGTABLEMODE, d3dFogMode)); - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGVERTEXMODE, D3DFOG_NONE)); -} - -//--------------------------------------------------------------------------- - -void gld_NEW_LIGHT( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - DWORD dwSpecularEnable; - - // Shademode - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_SHADEMODE, (ctx->Light.ShadeModel == GL_SMOOTH) ? D3DSHADE_GOURAUD : D3DSHADE_FLAT)); - - // Separate specular colour - if (ctx->Light.Enabled) - dwSpecularEnable = (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) ? TRUE: FALSE; - else - dwSpecularEnable = FALSE; - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_SPECULARENABLE, dwSpecularEnable)); -} - -//--------------------------------------------------------------------------- - -void gld_NEW_MODELVIEW( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - D3DMATRIX m; - //GLfloat *pM = ctx->ModelView.m; - // Mesa5: Model-view is now a stack - GLfloat *pM = ctx->ModelviewMatrixStack.Top->m; - m._11 = pM[0]; - m._12 = pM[1]; - m._13 = pM[2]; - m._14 = pM[3]; - m._21 = pM[4]; - m._22 = pM[5]; - m._23 = pM[6]; - m._24 = pM[7]; - m._31 = pM[8]; - m._32 = pM[9]; - m._33 = pM[10]; - m._34 = pM[11]; - m._41 = pM[12]; - m._42 = pM[13]; - m._43 = pM[14]; - m._44 = pM[15]; - - gld->matModelView = m; -} - -//--------------------------------------------------------------------------- - -void gld_NEW_PROJECTION( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - D3DMATRIX m; - //GLfloat *pM = ctx->ProjectionMatrix.m; - // Mesa 5: Now a stack - GLfloat *pM = ctx->ProjectionMatrixStack.Top->m; - m._11 = pM[0]; - m._12 = pM[1]; - m._13 = pM[2]; - m._14 = pM[3]; - - m._21 = pM[4]; - m._22 = pM[5]; - m._23 = pM[6]; - m._24 = pM[7]; - - m._31 = pM[8]; - m._32 = pM[9]; - m._33 = pM[10] / _fPersp_33; // / 1.6f; - m._34 = pM[11]; - - m._41 = pM[12]; - m._42 = pM[13]; - m._43 = pM[14] / 2.0f; - m._44 = pM[15]; - - gld->matProjection = m; -} - -//--------------------------------------------------------------------------- -/* -void gldFrustumHook_DX8( - GLdouble left, - GLdouble right, - GLdouble bottom, - GLdouble top, - GLdouble nearval, - GLdouble farval) -{ - GET_CURRENT_CONTEXT(ctx); - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - // Pass values on to Mesa first (in case we mess with them) - _mesa_Frustum(left, right, bottom, top, nearval, farval); - - _fPersp_33 = farval / (nearval - farval); - -// ddlogPrintf(GLDLOG_SYSTEM, "Frustum: %f", farval/nearval); -} - -//--------------------------------------------------------------------------- - -void gldOrthoHook_DX8( - GLdouble left, - GLdouble right, - GLdouble bottom, - GLdouble top, - GLdouble nearval, - GLdouble farval) -{ - GET_CURRENT_CONTEXT(ctx); - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - // Pass values on to Mesa first (in case we mess with them) - _mesa_Ortho(left, right, bottom, top, nearval, farval); - - _fPersp_33 = 1.6f; - -// ddlogPrintf(GLDLOG_SYSTEM, "Ortho: %f", farval/nearval); -} -*/ -//--------------------------------------------------------------------------- - -void gld_NEW_VIEWPORT( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - D3DVIEWPORT8 d3dvp; -// GLint x, y; -// GLsizei w, h; - - // Set depth range - _GLD_DX8_DEV(GetViewport(gld->pDev, &d3dvp)); - // D3D can't do Quake1/Quake2 z-trick - if (ctx->Viewport.Near <= ctx->Viewport.Far) { - d3dvp.MinZ = ctx->Viewport.Near; - d3dvp.MaxZ = ctx->Viewport.Far; - } else { - d3dvp.MinZ = ctx->Viewport.Far; - d3dvp.MaxZ = ctx->Viewport.Near; - } -/* x = ctx->Viewport.X; - y = ctx->Viewport.Y; - w = ctx->Viewport.Width; - h = ctx->Viewport.Height; - if (x < 0) x = 0; - if (y < 0) y = 0; - if (w > gldCtx->dwWidth) w = gldCtx->dwWidth; - if (h > gldCtx->dwHeight) h = gldCtx->dwHeight; - // Ditto for D3D viewport dimensions - if (w+x > gldCtx->dwWidth) w = gldCtx->dwWidth-x; - if (h+y > gldCtx->dwHeight) h = gldCtx->dwHeight-y; - d3dvp.X = x; - d3dvp.Y = gldCtx->dwHeight - (y + h); - d3dvp.Width = w; - d3dvp.Height = h;*/ - _GLD_DX8_DEV(SetViewport(gld->pDev, &d3dvp)); - -// gld->fFlipWindowY = (float)gldCtx->dwHeight; -} - -//--------------------------------------------------------------------------- - -__inline BOOL _gldAnyEvalEnabled( - GLcontext *ctx) -{ - struct gl_eval_attrib *eval = &ctx->Eval; - - if ((eval->AutoNormal) || - (eval->Map1Color4) || - (eval->Map1Index) || - (eval->Map1Normal) || - (eval->Map1TextureCoord1) || - (eval->Map1TextureCoord2) || - (eval->Map1TextureCoord3) || - (eval->Map1TextureCoord4) || - (eval->Map1Vertex3) || - (eval->Map1Vertex4) || - (eval->Map2Color4) || - (eval->Map2Index) || - (eval->Map2Normal) || - (eval->Map2TextureCoord1) || - (eval->Map2TextureCoord2) || - (eval->Map2TextureCoord3) || - (eval->Map2TextureCoord4) || - (eval->Map2Vertex3) || - (eval->Map2Vertex4) - ) - return TRUE; - - return FALSE; -} - -//--------------------------------------------------------------------------- - -BOOL _gldChooseInternalPipeline( - GLcontext *ctx, - GLD_driver_dx8 *gld) -{ -// return TRUE; // DEBUGGING: ALWAYS USE MESA -// return FALSE; // DEBUGGING: ALWAYS USE D3D - - if ((glb.dwTnL == GLDS_TNL_MESA) || (gld->bHasHWTnL == FALSE)) - { - gld->PipelineUsage.qwMesa.QuadPart++; - return TRUE; // Force Mesa TnL - } - - if ((ctx->Light.Enabled) || - (1) || - (ctx->Texture._TexGenEnabled) || - (ctx->Texture._TexMatEnabled) || -// (ctx->Transform._AnyClip) || - (ctx->Scissor.Enabled) || - _gldAnyEvalEnabled(ctx) // Put this last so we can early-out - ) - { - gld->PipelineUsage.qwMesa.QuadPart++; - return TRUE; - } - - gld->PipelineUsage.qwD3DFVF.QuadPart++; - return FALSE; - -/* // Force Mesa pipeline? - if (glb.dwTnL == GLDS_TNL_MESA) { - gld->PipelineUsage.dwMesa.QuadPart++; - return GLD_PIPELINE_MESA; - } - - // Test for functionality not exposed in the D3D pathways - if ((ctx->Texture._GenFlags)) { - gld->PipelineUsage.dwMesa.QuadPart++; - return GLD_PIPELINE_MESA; - } - - // Now decide if vertex shader can be used. - // If two sided lighting is enabled then we must either - // use Mesa TnL or the vertex shader - if (ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) { - if (gld->VStwosidelight.hShader && !ctx->Fog.Enabled) { - // Use Vertex Shader - gld->PipelineUsage.dwD3D2SVS.QuadPart++; - return GLD_PIPELINE_D3D_VS_TWOSIDE; - } else { - // Use Mesa TnL - gld->PipelineUsage.dwMesa.QuadPart++; - return GLD_PIPELINE_MESA; - } - } - - // Must be D3D fixed-function pipeline - gld->PipelineUsage.dwD3DFVF.QuadPart++; - return GLD_PIPELINE_D3D_FVF; -*/ -} - -//--------------------------------------------------------------------------- - -void gld_update_state_DX8( - GLcontext *ctx, - GLuint new_state) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - TNLcontext *tnl = TNL_CONTEXT(ctx); - GLD_pb_dx8 *gldPB; - - if (!gld || !gld->pDev) - return; - - _swsetup_InvalidateState( ctx, new_state ); - _vbo_InvalidateState( ctx, new_state ); - _tnl_InvalidateState( ctx, new_state ); - - // SetupIndex will be used in the pipelines for choosing setup function - if ((ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE | DD_SEPARATE_SPECULAR)) || - (ctx->Fog.Enabled)) - { - if (ctx->_TriangleCaps & DD_FLATSHADE) - gld->iSetupFunc = GLD_SI_FLAT_EXTRAS; - else - gld->iSetupFunc = GLD_SI_SMOOTH_EXTRAS; - } else { - if (ctx->_TriangleCaps & DD_FLATSHADE) - gld->iSetupFunc = GLD_SI_FLAT; // Setup flat shade + texture - else - gld->iSetupFunc = GLD_SI_SMOOTH; // Setup smooth shade + texture - } - - gld->bUseMesaTnL = _gldChooseInternalPipeline(ctx, gld); - if (gld->bUseMesaTnL) { - gldPB = &gld->PB2d; - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, TRUE)); - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_CLIPPING, FALSE)); - _GLD_DX8_DEV(SetVertexShader(gld->pDev, gldPB->dwFVF)); - } else { - gldPB = &gld->PB3d; - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_CLIPPING, TRUE)); -// if (gld->TnLPipeline == GLD_PIPELINE_D3D_VS_TWOSIDE) { -// _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, !gld->VStwosidelight.bHardware)); -// _GLD_DX8_DEV(SetVertexShader(gld->pDev, gld->VStwosidelight.hShader)); -// } else { - _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, !gld->bHasHWTnL)); - _GLD_DX8_DEV(SetVertexShader(gld->pDev, gldPB->dwFVF)); -// } - } - -#define _GLD_TEST_STATE(a) \ - if (new_state & (a)) { \ - gld##a(ctx); \ - new_state &= ~(a); \ - } - -#define _GLD_TEST_STATE_DX8(a) \ - if (new_state & (a)) { \ - gld##a##_DX8(ctx); \ - new_state &= ~(a); \ - } - -#define _GLD_IGNORE_STATE(a) new_state &= ~(a); - -// if (!gld->bUseMesaTnL) { - // Not required if Mesa is doing the TnL. - // Problem: If gld->bUseMesaTnL is TRUE when these are signaled, - // then we'll miss updating the D3D TnL pipeline. - // Therefore, don't test for gld->bUseMesaTnL - _GLD_TEST_STATE(_NEW_MODELVIEW); - _GLD_TEST_STATE(_NEW_PROJECTION); -// } - - _GLD_TEST_STATE_DX8(_NEW_TEXTURE); // extern, so guard with _DX8 - _GLD_TEST_STATE(_NEW_COLOR); - _GLD_TEST_STATE(_NEW_DEPTH); - _GLD_TEST_STATE(_NEW_POLYGON); - _GLD_TEST_STATE(_NEW_STENCIL); - _GLD_TEST_STATE(_NEW_FOG); - _GLD_TEST_STATE(_NEW_LIGHT); - _GLD_TEST_STATE(_NEW_VIEWPORT); - - _GLD_IGNORE_STATE(_NEW_TRANSFORM); - - -// Stubs for future use. -/* _GLD_TEST_STATE(_NEW_TEXTURE_MATRIX); - _GLD_TEST_STATE(_NEW_COLOR_MATRIX); - _GLD_TEST_STATE(_NEW_ACCUM); - _GLD_TEST_STATE(_NEW_EVAL); - _GLD_TEST_STATE(_NEW_HINT); - _GLD_TEST_STATE(_NEW_LINE); - _GLD_TEST_STATE(_NEW_PIXEL); - _GLD_TEST_STATE(_NEW_POINT); - _GLD_TEST_STATE(_NEW_POLYGONSTIPPLE); - _GLD_TEST_STATE(_NEW_SCISSOR); - _GLD_TEST_STATE(_NEW_PACKUNPACK); - _GLD_TEST_STATE(_NEW_ARRAY); - _GLD_TEST_STATE(_NEW_RENDERMODE); - _GLD_TEST_STATE(_NEW_BUFFERS); - _GLD_TEST_STATE(_NEW_MULTISAMPLE); -*/ - -// For debugging. -#if 0 -#define _GLD_TEST_UNHANDLED_STATE(a) \ - if (new_state & (a)) { \ - gldLogMessage(GLDLOG_ERROR, "Unhandled " #a "\n"); \ - } - _GLD_TEST_UNHANDLED_STATE(_NEW_TEXTURE_MATRIX); - _GLD_TEST_UNHANDLED_STATE(_NEW_COLOR_MATRIX); - _GLD_TEST_UNHANDLED_STATE(_NEW_ACCUM); - _GLD_TEST_UNHANDLED_STATE(_NEW_EVAL); - _GLD_TEST_UNHANDLED_STATE(_NEW_HINT); - _GLD_TEST_UNHANDLED_STATE(_NEW_LINE); - _GLD_TEST_UNHANDLED_STATE(_NEW_PIXEL); - _GLD_TEST_UNHANDLED_STATE(_NEW_POINT); - _GLD_TEST_UNHANDLED_STATE(_NEW_POLYGONSTIPPLE); - _GLD_TEST_UNHANDLED_STATE(_NEW_SCISSOR); - _GLD_TEST_UNHANDLED_STATE(_NEW_PACKUNPACK); - _GLD_TEST_UNHANDLED_STATE(_NEW_ARRAY); - _GLD_TEST_UNHANDLED_STATE(_NEW_RENDERMODE); - _GLD_TEST_UNHANDLED_STATE(_NEW_BUFFERS); - _GLD_TEST_UNHANDLED_STATE(_NEW_MULTISAMPLE); -#undef _GLD_UNHANDLED_STATE -#endif - -#undef _GLD_TEST_STATE -} - -//--------------------------------------------------------------------------- -// Viewport -//--------------------------------------------------------------------------- - -void gld_Viewport_DX8( - GLcontext *ctx, - GLint x, - GLint y, - GLsizei w, - GLsizei h) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - D3DVIEWPORT8 d3dvp; - - if (!gld || !gld->pDev) - return; - - // This is a hack. When the app is minimized, Mesa passes - // w=1 and h=1 for viewport dimensions. Without this test - // we get a GPF in gld_wgl_resize_buffers(). - if ((w==1) && (h==1)) - return; - - // Call ResizeBuffersMESA. This function will early-out - // if no resize is needed. - //ctx->Driver.ResizeBuffersMESA(ctx); - // Mesa 5: Changed parameters - ctx->Driver.ResizeBuffers(gldCtx->glBuffer); - -#if 0 - ddlogPrintf(GLDLOG_SYSTEM, ">> Viewport x=%d y=%d w=%d h=%d", x,y,w,h); -#endif - - // ** D3D viewport must not be outside the render target surface ** - // Sanity check the GL viewport dimensions - if (x < 0) x = 0; - if (y < 0) y = 0; - if (w > gldCtx->dwWidth) w = gldCtx->dwWidth; - if (h > gldCtx->dwHeight) h = gldCtx->dwHeight; - // Ditto for D3D viewport dimensions - if (w+x > gldCtx->dwWidth) w = gldCtx->dwWidth-x; - if (h+y > gldCtx->dwHeight) h = gldCtx->dwHeight-y; - - d3dvp.X = x; - d3dvp.Y = gldCtx->dwHeight - (y + h); - d3dvp.Width = w; - d3dvp.Height = h; - if (ctx->Viewport.Near <= ctx->Viewport.Far) { - d3dvp.MinZ = ctx->Viewport.Near; - d3dvp.MaxZ = ctx->Viewport.Far; - } else { - d3dvp.MinZ = ctx->Viewport.Far; - d3dvp.MaxZ = ctx->Viewport.Near; - } - - // TODO: DEBUGGING -// d3dvp.MinZ = 0.0f; -// d3dvp.MaxZ = 1.0f; - - _GLD_DX8_DEV(SetViewport(gld->pDev, &d3dvp)); - -} - -//--------------------------------------------------------------------------- - -extern BOOL dglWglResizeBuffers(GLcontext *ctx, BOOL bDefaultDriver); - -// Mesa 5: Parameter change -void gldResizeBuffers_DX8( -// GLcontext *ctx) - GLframebuffer *fb) -{ - GET_CURRENT_CONTEXT(ctx); - dglWglResizeBuffers(ctx, TRUE); -} - -//--------------------------------------------------------------------------- -#ifdef _DEBUG -// This is only for debugging. -// To use, plug into ctx->Driver.Enable pointer below. -void gld_Enable( - GLcontext *ctx, - GLenum e, - GLboolean b) -{ - char buf[1024]; - sprintf(buf, "Enable: %s (%s)\n", _mesa_lookup_enum_by_nr(e), b?"TRUE":"FALSE"); - ddlogMessage(DDLOG_SYSTEM, buf); -} -#endif -//--------------------------------------------------------------------------- -// Driver pointer setup -//--------------------------------------------------------------------------- - -extern const GLubyte* _gldGetStringGeneric(GLcontext*, GLenum); - -void gldSetupDriverPointers_DX8( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - TNLcontext *tnl = TNL_CONTEXT(ctx); - - // Mandatory functions - ctx->Driver.GetString = _gldGetStringGeneric; - ctx->Driver.UpdateState = gld_update_state_DX8; - ctx->Driver.Clear = gld_Clear_DX8; - ctx->Driver.DrawBuffer = gld_set_draw_buffer_DX8; - ctx->Driver.GetBufferSize = gld_buffer_size_DX8; - ctx->Driver.Finish = gld_Finish_DX8; - ctx->Driver.Flush = gld_Flush_DX8; - ctx->Driver.Error = gld_Error_DX8; - - // Hardware accumulation buffer - ctx->Driver.Accum = NULL; // TODO: gld_Accum; - - // Bitmap functions - ctx->Driver.CopyPixels = gld_CopyPixels_DX8; - ctx->Driver.DrawPixels = gld_DrawPixels_DX8; - ctx->Driver.ReadPixels = gld_ReadPixels_DX8; - ctx->Driver.Bitmap = gld_Bitmap_DX8; - - // Buffer resize - ctx->Driver.ResizeBuffers = gldResizeBuffers_DX8; - - // Texture image functions - ctx->Driver.ChooseTextureFormat = gld_ChooseTextureFormat_DX8; - ctx->Driver.TexImage1D = gld_TexImage1D_DX8; - ctx->Driver.TexImage2D = gld_TexImage2D_DX8; - ctx->Driver.TexImage3D = _mesa_store_teximage3d; - ctx->Driver.TexSubImage1D = gld_TexSubImage1D_DX8; - ctx->Driver.TexSubImage2D = gld_TexSubImage2D_DX8; - ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; - - ctx->Driver.CopyTexImage1D = gldCopyTexImage1D_DX8; //NULL; - ctx->Driver.CopyTexImage2D = gldCopyTexImage2D_DX8; //NULL; - ctx->Driver.CopyTexSubImage1D = gldCopyTexSubImage1D_DX8; //NULL; - ctx->Driver.CopyTexSubImage2D = gldCopyTexSubImage2D_DX8; //NULL; - ctx->Driver.CopyTexSubImage3D = gldCopyTexSubImage3D_DX8; - ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; - - // Texture object functions - ctx->Driver.BindTexture = NULL; - ctx->Driver.NewTextureObject = NULL; // Not yet implemented by Mesa!; - ctx->Driver.DeleteTexture = gld_DeleteTexture_DX8; - ctx->Driver.PrioritizeTexture = NULL; - - // Imaging functionality - ctx->Driver.CopyColorTable = NULL; - ctx->Driver.CopyColorSubTable = NULL; - ctx->Driver.CopyConvolutionFilter1D = NULL; - ctx->Driver.CopyConvolutionFilter2D = NULL; - - // State changing functions - ctx->Driver.AlphaFunc = NULL; //gld_AlphaFunc; - ctx->Driver.BlendFuncSeparate = NULL; //gld_BlendFunc; - ctx->Driver.ClearColor = NULL; //gld_ClearColor; - ctx->Driver.ClearDepth = NULL; //gld_ClearDepth; - ctx->Driver.ClearStencil = NULL; //gld_ClearStencil; - ctx->Driver.ColorMask = NULL; //gld_ColorMask; - ctx->Driver.CullFace = NULL; //gld_CullFace; - ctx->Driver.ClipPlane = NULL; //gld_ClipPlane; - ctx->Driver.FrontFace = NULL; //gld_FrontFace; - ctx->Driver.DepthFunc = NULL; //gld_DepthFunc; - ctx->Driver.DepthMask = NULL; //gld_DepthMask; - ctx->Driver.DepthRange = NULL; - ctx->Driver.Enable = NULL; //gld_Enable; - ctx->Driver.Fogfv = NULL; //gld_Fogfv; - ctx->Driver.Hint = NULL; //gld_Hint; - ctx->Driver.Lightfv = NULL; //gld_Lightfv; - ctx->Driver.LightModelfv = NULL; //gld_LightModelfv; - ctx->Driver.LineStipple = NULL; //gld_LineStipple; - ctx->Driver.LineWidth = NULL; //gld_LineWidth; - ctx->Driver.LogicOpcode = NULL; //gld_LogicOpcode; - ctx->Driver.PointParameterfv = NULL; //gld_PointParameterfv; - ctx->Driver.PointSize = NULL; //gld_PointSize; - ctx->Driver.PolygonMode = NULL; //gld_PolygonMode; - ctx->Driver.PolygonOffset = NULL; //gld_PolygonOffset; - ctx->Driver.PolygonStipple = NULL; //gld_PolygonStipple; - ctx->Driver.RenderMode = NULL; //gld_RenderMode; - ctx->Driver.Scissor = NULL; //gld_Scissor; - ctx->Driver.ShadeModel = NULL; //gld_ShadeModel; - ctx->Driver.StencilFunc = NULL; //gld_StencilFunc; - ctx->Driver.StencilMask = NULL; //gld_StencilMask; - ctx->Driver.StencilOp = NULL; //gld_StencilOp; - ctx->Driver.TexGen = NULL; //gld_TexGen; - ctx->Driver.TexEnv = NULL; - ctx->Driver.TexParameter = NULL; - ctx->Driver.TextureMatrix = NULL; //gld_TextureMatrix; - ctx->Driver.Viewport = gld_Viewport_DX8; - - _swsetup_Wakeup(ctx); - - tnl->Driver.RunPipeline = _tnl_run_pipeline; - tnl->Driver.Render.ResetLineStipple = gld_ResetLineStipple_DX8; - tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon; - tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine; - - // Hook into glFrustum() and glOrtho() -// ctx->Exec->Frustum = gldFrustumHook_DX8; -// ctx->Exec->Ortho = gldOrthoHook_DX8; - -} - -//--------------------------------------------------------------------------- diff --git a/src/mesa/drivers/windows/gldirect/dx8/gld_dx8.h b/src/mesa/drivers/windows/gldirect/dx8/gld_dx8.h deleted file mode 100644 index 7efec7cae8..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx8/gld_dx8.h +++ /dev/null @@ -1,324 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: GLDirect Direct3D 8.0 header file -* -****************************************************************************/ - -#ifndef _GLD_DX8_H -#define _GLD_DX8_H - -//--------------------------------------------------------------------------- -// Windows includes -//--------------------------------------------------------------------------- - -//#ifndef STRICT -//#define STRICT -//#endif - -//#define WIN32_LEAN_AND_MEAN -//#include <windows.h> -#include <d3d8.h> -#include <d3dx8.h> - -// MS screwed up with the DX8.1 SDK - there's no compile-time -// method of compiling for 8.0 via the 8.1 SDK unless you -// "make sure you don't use any 8.1 interfaces". -// We CAN use 8.1 D3DX static functions, though - just not new 8.1 interfaces. -// -// D3D_SDK_VERSION is 120 for 8.0 (supported by Windows 95). -// D3D_SDK_VERSION is 220 for 8.1 (NOT supported by Windows 95). -// -#define D3D_SDK_VERSION_DX8_SUPPORT_WIN95 120 - -// Typedef for obtaining function from d3d8.dll -typedef IDirect3D8* (WINAPI *FNDIRECT3DCREATE8) (UINT); - - -//--------------------------------------------------------------------------- -// Defines -//--------------------------------------------------------------------------- - -#ifdef _DEBUG -#define _GLD_TEST_HRESULT(h) \ -{ \ - HRESULT _hr = (h); \ - if (FAILED(_hr)) { \ - gldLogError(GLDLOG_ERROR, #h, _hr); \ - } \ -} -#define _GLD_DX8(func) _GLD_TEST_HRESULT(IDirect3D8_##func##) -#define _GLD_DX8_DEV(func) _GLD_TEST_HRESULT(IDirect3DDevice8_##func##) -#define _GLD_DX8_VB(func) _GLD_TEST_HRESULT(IDirect3DVertexBuffer8_##func##) -#define _GLD_DX8_TEX(func) _GLD_TEST_HRESULT(IDirect3DTexture8_##func##) -#else -#define _GLD_DX8(func) IDirect3D8_##func -#define _GLD_DX8_DEV(func) IDirect3DDevice8_##func -#define _GLD_DX8_VB(func) IDirect3DVertexBuffer8_##func -#define _GLD_DX8_TEX(func) IDirect3DTexture8_##func -#endif - -#define SAFE_RELEASE(p) \ -{ \ - if (p) { \ - (p)->lpVtbl->Release(p); \ - (p) = NULL; \ - } \ -} - -#define SAFE_RELEASE_VB8(p) \ -{ \ - if (p) { \ - IDirect3DVertexBuffer8_Release((p)); \ - (p) = NULL; \ - } \ -} - -#define SAFE_RELEASE_SURFACE8(p) \ -{ \ - if (p) { \ - IDirect3DSurface8_Release((p)); \ - (p) = NULL; \ - } \ -} - -// Setup index. -enum { - GLD_SI_FLAT = 0, - GLD_SI_SMOOTH = 1, - GLD_SI_FLAT_EXTRAS = 2, - GLD_SI_SMOOTH_EXTRAS = 3, -}; -/* -// Internal pipeline -typedef enum { - GLD_PIPELINE_MESA = 0, // Mesa pipeline - GLD_PIPELINE_D3D_FVF = 1, // Direct3D Fixed-function pipeline - GLD_PIPELINE_D3D_VS_TWOSIDE = 2 // Direct3D two-sided-lighting vertex shader -} GLD_tnl_pipeline; -*/ -//--------------------------------------------------------------------------- -// Vertex definitions for Fixed-Function pipeline -//--------------------------------------------------------------------------- - -// -// NOTE: If the number of texture units is altered then most of -// the texture code will need to be revised. -// - -#define GLD_MAX_TEXTURE_UNITS_DX8 2 - -// -// 2D vertex transformed by Mesa -// -#define GLD_FVF_2D_VERTEX ( D3DFVF_XYZRHW | \ - D3DFVF_DIFFUSE | \ - D3DFVF_SPECULAR | \ - D3DFVF_TEX2) -typedef struct { - FLOAT x, y; // 2D raster coords - FLOAT sz; // Screen Z (depth) - FLOAT rhw; // Reciprocal homogenous W - DWORD diffuse; // Diffuse colour - DWORD specular; // For separate-specular support - FLOAT t0_u, t0_v; // 1st set of texture coords - FLOAT t1_u, t1_v; // 2nd set of texture coords -} GLD_2D_VERTEX; - - -// -// 3D vertex transformed by Direct3D -// -#define GLD_FVF_3D_VERTEX ( D3DFVF_XYZ | \ - D3DFVF_DIFFUSE | \ - D3DFVF_TEX2) - -typedef struct { - D3DXVECTOR3 Position; // XYZ Vector in object space - D3DCOLOR Diffuse; // Diffuse colour - D3DXVECTOR2 TexUnit0; // Texture unit 0 - D3DXVECTOR2 TexUnit1; // Texture unit 1 -} GLD_3D_VERTEX; - -//--------------------------------------------------------------------------- -// Vertex Shaders -//--------------------------------------------------------------------------- -/* -// DX8 Vertex Shader -typedef struct { - DWORD hShader; // If NULL, shader is invalid and cannot be used - BOOL bHardware; // If TRUE then shader was created for hardware, - // otherwise shader was created for software. -} GLD_vertexShader; -*/ -//--------------------------------------------------------------------------- -// Structs -//--------------------------------------------------------------------------- - -// This keeps a count of how many times we choose each individual internal -// pathway. Useful for seeing if a certain pathway was ever used by an app, and -// how much each pathway is biased. -// Zero the members at context creation and dump stats at context deletion. -typedef struct { - // Note: DWORD is probably too small - ULARGE_INTEGER qwMesa; // Mesa TnL pipeline - ULARGE_INTEGER qwD3DFVF; // Direct3D Fixed-Function pipeline -// ULARGE_INTEGER dwD3D2SVS; // Direct3D Two-Sided Vertex Shader pipeline -} GLD_pipeline_usage; - -// GLDirect Primitive Buffer (points, lines, triangles and quads) -typedef struct { - // Data for IDirect3DDevice8::CreateVertexBuffer() - DWORD dwStride; // Stride of vertex - DWORD dwUsage; // Usage flags - DWORD dwFVF; // Direct3D Flexible Vertex Format - DWORD dwPool; // Pool flags - - IDirect3DVertexBuffer8 *pVB; // Holds points, lines, tris and quads. - - // Point list is assumed to be at start of buffer - DWORD iFirstLine; // Index of start of line list - DWORD iFirstTriangle; // Index of start of triangle list - - BYTE *pPoints; // Pointer to next free point - BYTE *pLines; // Pointer to next free line - BYTE *pTriangles; // Pointer to next free triangle - - DWORD nPoints; // Number of points ready to render - DWORD nLines; // Number of lines ready to render - DWORD nTriangles; // Number of triangles ready to render -} GLD_pb_dx8; - -// GLDirect DX8 driver data -typedef struct { - // GLDirect vars - BOOL bDoublebuffer; // Doublebuffer (otherwise single-buffered) - BOOL bDepthStencil; // Depth buffer needed (stencil optional) - D3DFORMAT RenderFormat; // Format of back/front buffer - D3DFORMAT DepthFormat; // Format of depth/stencil -// float fFlipWindowY; // Value for flipping viewport Y coord - - // Direct3D vars - D3DCAPS8 d3dCaps8; - BOOL bHasHWTnL; // Device has Hardware Transform/Light? - IDirect3D8 *pD3D; // Base Direct3D8 interface - IDirect3DDevice8 *pDev; // Direct3D8 Device interface - GLD_pb_dx8 PB2d; // Vertices transformed by Mesa - GLD_pb_dx8 PB3d; // Vertices transformed by Direct3D - D3DPRIMITIVETYPE d3dpt; // Current Direct3D primitive type - D3DXMATRIX matProjection; // Projection matrix for D3D TnL - D3DXMATRIX matModelView; // Model/View matrix for D3D TnL - int iSetupFunc; // Which setup functions to use - BOOL bUseMesaTnL; // Whether to use Mesa or D3D for TnL - - // Direct3D vars for two-sided lighting -// GLD_vertexShader VStwosidelight; // Vertex Shader for two-sided lighting -// D3DXMATRIX matWorldViewProj;// World/View/Projection matrix for shaders - - -// GLD_tnl_pipeline TnLPipeline; // Index of current internal pipeline - GLD_pipeline_usage PipelineUsage; -} GLD_driver_dx8; - -#define GLD_GET_DX8_DRIVER(c) (GLD_driver_dx8*)(c)->glPriv - -//--------------------------------------------------------------------------- -// Function prototypes -//--------------------------------------------------------------------------- - -PROC gldGetProcAddress_DX8(LPCSTR a); -void gldEnableExtensions_DX8(GLcontext *ctx); -void gldInstallPipeline_DX8(GLcontext *ctx); -void gldSetupDriverPointers_DX8(GLcontext *ctx); -//void gldResizeBuffers_DX8(GLcontext *ctx); -void gldResizeBuffers_DX8(GLframebuffer *fb); - - -// Texture functions - -void gldCopyTexImage1D_DX8(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border); -void gldCopyTexImage2D_DX8(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); -void gldCopyTexSubImage1D_DX8(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width ); -void gldCopyTexSubImage2D_DX8(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height ); -void gldCopyTexSubImage3D_DX8(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height ); - -void gld_NEW_TEXTURE_DX8(GLcontext *ctx); -void gld_DrawPixels_DX8(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, const GLvoid *pixels); -void gld_ReadPixels_DX8(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, GLvoid *dest); -void gld_CopyPixels_DX8(GLcontext *ctx, GLint srcx, GLint srcy, GLsizei width, GLsizei height, GLint dstx, GLint dsty, GLenum type); -void gld_Bitmap_DX8(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap); -const struct gl_texture_format* gld_ChooseTextureFormat_DX8(GLcontext *ctx, GLint internalFormat, GLenum srcFormat, GLenum srcType); -void gld_TexImage2D_DX8(GLcontext *ctx, GLenum target, GLint level, GLint internalFormat, GLint width, GLint height, GLint border, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *tObj, struct gl_texture_image *texImage); -void gld_TexImage1D_DX8(GLcontext *ctx, GLenum target, GLint level, GLint internalFormat, GLint width, GLint border, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage ); -void gld_TexSubImage2D_DX8( GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage ); -void gld_TexSubImage1D_DX8(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage); -void gld_DeleteTexture_DX8(GLcontext *ctx, struct gl_texture_object *tObj); -void gld_ResetLineStipple_DX8(GLcontext *ctx); - -// 2D primitive functions - -void gld_Points2D_DX8(GLcontext *ctx, GLuint first, GLuint last); - -void gld_Line2DFlat_DX8(GLcontext *ctx, GLuint v0, GLuint v1); -void gld_Line2DSmooth_DX8(GLcontext *ctx, GLuint v0, GLuint v1); - -void gld_Triangle2DFlat_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Triangle2DSmooth_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Triangle2DFlatExtras_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Triangle2DSmoothExtras_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); - -void gld_Quad2DFlat_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -void gld_Quad2DSmooth_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -void gld_Quad2DFlatExtras_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -void gld_Quad2DSmoothExtras_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); - -// 3D primitive functions - -void gld_Points3D_DX8(GLcontext *ctx, GLuint first, GLuint last); -void gld_Line3DFlat_DX8(GLcontext *ctx, GLuint v0, GLuint v1); -void gld_Triangle3DFlat_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Quad3DFlat_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -void gld_Line3DSmooth_DX8(GLcontext *ctx, GLuint v0, GLuint v1); -void gld_Triangle3DSmooth_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Quad3DSmooth_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); - -// Primitive functions for Two-sided-lighting Vertex Shader - -void gld_Points2DTwoside_DX8(GLcontext *ctx, GLuint first, GLuint last); -void gld_Line2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1); -void gld_Line2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1); -void gld_Triangle2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Triangle2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Quad2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -void gld_Quad2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); - -#endif diff --git a/src/mesa/drivers/windows/gldirect/dx8/gld_dxerr8.h b/src/mesa/drivers/windows/gldirect/dx8/gld_dxerr8.h deleted file mode 100644 index f8e92b936e..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx8/gld_dxerr8.h +++ /dev/null @@ -1,77 +0,0 @@ -/*==========================================================================; - * - * - * File: dxerr8.h - * Content: DirectX Error Library Include File - * - ****************************************************************************/ - -#ifndef _GLD_DXERR8_H_ -#define _GLD_DXERR8_H_ - - -#include <d3d8.h> - -// -// DXGetErrorString8 -// -// Desc: Converts an DirectX HRESULT to a string -// -// Args: HRESULT hr Can be any error code from -// DPLAY D3D8 D3DX8 DMUSIC DSOUND -// -// Return: Converted string -// -const char* __stdcall DXGetErrorString8A(HRESULT hr); -const WCHAR* __stdcall DXGetErrorString8W(HRESULT hr); - -#ifdef UNICODE - #define DXGetErrorString8 DXGetErrorString8W -#else - #define DXGetErrorString8 DXGetErrorString8A -#endif - - -// -// DXTrace -// -// Desc: Outputs a formatted error message to the debug stream -// -// Args: CHAR* strFile The current file, typically passed in using the -// __FILE__ macro. -// DWORD dwLine The current line number, typically passed in using the -// __LINE__ macro. -// HRESULT hr An HRESULT that will be traced to the debug stream. -// CHAR* strMsg A string that will be traced to the debug stream (may be NULL) -// BOOL bPopMsgBox If TRUE, then a message box will popup also containing the passed info. -// -// Return: The hr that was passed in. -// -//HRESULT __stdcall DXTraceA( char* strFile, DWORD dwLine, HRESULT hr, char* strMsg, BOOL bPopMsgBox = FALSE ); -//HRESULT __stdcall DXTraceW( char* strFile, DWORD dwLine, HRESULT hr, WCHAR* strMsg, BOOL bPopMsgBox = FALSE ); -HRESULT __stdcall DXTraceA( char* strFile, DWORD dwLine, HRESULT hr, char* strMsg, BOOL bPopMsgBox); -HRESULT __stdcall DXTraceW( char* strFile, DWORD dwLine, HRESULT hr, WCHAR* strMsg, BOOL bPopMsgBox); - -#ifdef UNICODE - #define DXTrace DXTraceW -#else - #define DXTrace DXTraceA -#endif - - -// -// Helper macros -// -#if defined(DEBUG) | defined(_DEBUG) - #define DXTRACE_MSG(str) DXTrace( __FILE__, (DWORD)__LINE__, 0, str, FALSE ) - #define DXTRACE_ERR(str,hr) DXTrace( __FILE__, (DWORD)__LINE__, hr, str, TRUE ) - #define DXTRACE_ERR_NOMSGBOX(str,hr) DXTrace( __FILE__, (DWORD)__LINE__, hr, str, FALSE ) -#else - #define DXTRACE_MSG(str) (0L) - #define DXTRACE_ERR(str,hr) (hr) - #define DXTRACE_ERR_NOMSGBOX(str,hr) (hr) -#endif - - -#endif - diff --git a/src/mesa/drivers/windows/gldirect/dx8/gld_ext_dx8.c b/src/mesa/drivers/windows/gldirect/dx8/gld_ext_dx8.c deleted file mode 100644 index b51bba9b3c..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx8/gld_ext_dx8.c +++ /dev/null @@ -1,344 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: GL extensions -* -****************************************************************************/ - -//#include "../GLDirect.h" -//#include "../gld_log.h" -//#include "../gld_settings.h" - -#include <windows.h> -#define GL_GLEXT_PROTOTYPES -#include <GL/gl.h> -#include <GL/glext.h> - -//#include "ddlog.h" -//#include "gld_dx8.h" - -#include "glheader.h" -#include "context.h" -#include "colormac.h" -#include "depth.h" -#include "extensions.h" -#include "macros.h" -#include "matrix.h" -// #include "mem.h" -//#include "mmath.h" -#include "mtypes.h" -#include "texformat.h" -#include "texstore.h" -#include "vbo/vbo.h" -#include "swrast_setup/swrast_setup.h" -#include "swrast_setup/ss_context.h" -#include "tnl/tnl.h" -#include "tnl/t_context.h" -#include "tnl/t_pipeline.h" - -#include "dglcontext.h" -#include "extensions.h" - -// For some reason this is not defined in an above header... -extern void _mesa_enable_imaging_extensions(GLcontext *ctx); - -//--------------------------------------------------------------------------- -// Hack for the SGIS_multitexture extension that was removed from Mesa -// NOTE: SGIS_multitexture enums also clash with GL_SGIX_async_pixel - - // NOTE: Quake2 ran *slower* with this enabled, so I've - // disabled it for now. - // To enable, uncomment: - // _mesa_add_extension(ctx, GL_TRUE, szGL_SGIS_multitexture, 0); - -//--------------------------------------------------------------------------- - -enum { - /* Quake2 GL_SGIS_multitexture */ - GL_SELECTED_TEXTURE_SGIS = 0x835B, - GL_SELECTED_TEXTURE_COORD_SET_SGIS = 0x835C, - GL_MAX_TEXTURES_SGIS = 0x835D, - GL_TEXTURE0_SGIS = 0x835E, - GL_TEXTURE1_SGIS = 0x835F, - GL_TEXTURE2_SGIS = 0x8360, - GL_TEXTURE3_SGIS = 0x8361, - GL_TEXTURE_COORD_SET_SOURCE_SGIS = 0x8363, -}; - -//--------------------------------------------------------------------------- - -void APIENTRY gldSelectTextureSGIS( - GLenum target) -{ - GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS); - glActiveTextureARB(ARB_target); -} - -//--------------------------------------------------------------------------- - -void APIENTRY gldMTexCoord2fSGIS( - GLenum target, - GLfloat s, - GLfloat t) -{ - GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS); - glMultiTexCoord2fARB(ARB_target, s, t); -} - -//--------------------------------------------------------------------------- - -void APIENTRY gldMTexCoord2fvSGIS( - GLenum target, - const GLfloat *v) -{ - GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS); - glMultiTexCoord2fvARB(ARB_target, v); -} - -//--------------------------------------------------------------------------- -// Extensions -//--------------------------------------------------------------------------- - -typedef struct { - PROC proc; - char *name; -} GLD_extension; - -GLD_extension GLD_extList[] = { -#ifdef GL_EXT_polygon_offset - { (PROC)glPolygonOffsetEXT, "glPolygonOffsetEXT" }, -#endif - { (PROC)glBlendEquationEXT, "glBlendEquationEXT" }, - { (PROC)glBlendColorEXT, "glBlendColorExt" }, - { (PROC)glVertexPointerEXT, "glVertexPointerEXT" }, - { (PROC)glNormalPointerEXT, "glNormalPointerEXT" }, - { (PROC)glColorPointerEXT, "glColorPointerEXT" }, - { (PROC)glIndexPointerEXT, "glIndexPointerEXT" }, - { (PROC)glTexCoordPointerEXT, "glTexCoordPointer" }, - { (PROC)glEdgeFlagPointerEXT, "glEdgeFlagPointerEXT" }, - { (PROC)glGetPointervEXT, "glGetPointervEXT" }, - { (PROC)glArrayElementEXT, "glArrayElementEXT" }, - { (PROC)glDrawArraysEXT, "glDrawArrayEXT" }, - { (PROC)glAreTexturesResidentEXT, "glAreTexturesResidentEXT" }, - { (PROC)glBindTextureEXT, "glBindTextureEXT" }, - { (PROC)glDeleteTexturesEXT, "glDeleteTexturesEXT" }, - { (PROC)glGenTexturesEXT, "glGenTexturesEXT" }, - { (PROC)glIsTextureEXT, "glIsTextureEXT" }, - { (PROC)glPrioritizeTexturesEXT, "glPrioritizeTexturesEXT" }, - { (PROC)glCopyTexSubImage3DEXT, "glCopyTexSubImage3DEXT" }, - { (PROC)glTexImage3DEXT, "glTexImage3DEXT" }, - { (PROC)glTexSubImage3DEXT, "glTexSubImage3DEXT" }, - { (PROC)glPointParameterfEXT, "glPointParameterfEXT" }, - { (PROC)glPointParameterfvEXT, "glPointParameterfvEXT" }, - - { (PROC)glLockArraysEXT, "glLockArraysEXT" }, - { (PROC)glUnlockArraysEXT, "glUnlockArraysEXT" }, - { NULL, "\0" } -}; - -GLD_extension GLD_multitexList[] = { -/* - { (PROC)glMultiTexCoord1dSGIS, "glMTexCoord1dSGIS" }, - { (PROC)glMultiTexCoord1dvSGIS, "glMTexCoord1dvSGIS" }, - { (PROC)glMultiTexCoord1fSGIS, "glMTexCoord1fSGIS" }, - { (PROC)glMultiTexCoord1fvSGIS, "glMTexCoord1fvSGIS" }, - { (PROC)glMultiTexCoord1iSGIS, "glMTexCoord1iSGIS" }, - { (PROC)glMultiTexCoord1ivSGIS, "glMTexCoord1ivSGIS" }, - { (PROC)glMultiTexCoord1sSGIS, "glMTexCoord1sSGIS" }, - { (PROC)glMultiTexCoord1svSGIS, "glMTexCoord1svSGIS" }, - { (PROC)glMultiTexCoord2dSGIS, "glMTexCoord2dSGIS" }, - { (PROC)glMultiTexCoord2dvSGIS, "glMTexCoord2dvSGIS" }, - { (PROC)glMultiTexCoord2fSGIS, "glMTexCoord2fSGIS" }, - { (PROC)glMultiTexCoord2fvSGIS, "glMTexCoord2fvSGIS" }, - { (PROC)glMultiTexCoord2iSGIS, "glMTexCoord2iSGIS" }, - { (PROC)glMultiTexCoord2ivSGIS, "glMTexCoord2ivSGIS" }, - { (PROC)glMultiTexCoord2sSGIS, "glMTexCoord2sSGIS" }, - { (PROC)glMultiTexCoord2svSGIS, "glMTexCoord2svSGIS" }, - { (PROC)glMultiTexCoord3dSGIS, "glMTexCoord3dSGIS" }, - { (PROC)glMultiTexCoord3dvSGIS, "glMTexCoord3dvSGIS" }, - { (PROC)glMultiTexCoord3fSGIS, "glMTexCoord3fSGIS" }, - { (PROC)glMultiTexCoord3fvSGIS, "glMTexCoord3fvSGIS" }, - { (PROC)glMultiTexCoord3iSGIS, "glMTexCoord3iSGIS" }, - { (PROC)glMultiTexCoord3ivSGIS, "glMTexCoord3ivSGIS" }, - { (PROC)glMultiTexCoord3sSGIS, "glMTexCoord3sSGIS" }, - { (PROC)glMultiTexCoord3svSGIS, "glMTexCoord3svSGIS" }, - { (PROC)glMultiTexCoord4dSGIS, "glMTexCoord4dSGIS" }, - { (PROC)glMultiTexCoord4dvSGIS, "glMTexCoord4dvSGIS" }, - { (PROC)glMultiTexCoord4fSGIS, "glMTexCoord4fSGIS" }, - { (PROC)glMultiTexCoord4fvSGIS, "glMTexCoord4fvSGIS" }, - { (PROC)glMultiTexCoord4iSGIS, "glMTexCoord4iSGIS" }, - { (PROC)glMultiTexCoord4ivSGIS, "glMTexCoord4ivSGIS" }, - { (PROC)glMultiTexCoord4sSGIS, "glMTexCoord4sSGIS" }, - { (PROC)glMultiTexCoord4svSGIS, "glMTexCoord4svSGIS" }, - { (PROC)glMultiTexCoordPointerSGIS, "glMTexCoordPointerSGIS" }, - { (PROC)glSelectTextureSGIS, "glSelectTextureSGIS" }, - { (PROC)glSelectTextureCoordSetSGIS, "glSelectTextureCoordSetSGIS" }, -*/ - { (PROC)glActiveTextureARB, "glActiveTextureARB" }, - { (PROC)glClientActiveTextureARB, "glClientActiveTextureARB" }, - { (PROC)glMultiTexCoord1dARB, "glMultiTexCoord1dARB" }, - { (PROC)glMultiTexCoord1dvARB, "glMultiTexCoord1dvARB" }, - { (PROC)glMultiTexCoord1fARB, "glMultiTexCoord1fARB" }, - { (PROC)glMultiTexCoord1fvARB, "glMultiTexCoord1fvARB" }, - { (PROC)glMultiTexCoord1iARB, "glMultiTexCoord1iARB" }, - { (PROC)glMultiTexCoord1ivARB, "glMultiTexCoord1ivARB" }, - { (PROC)glMultiTexCoord1sARB, "glMultiTexCoord1sARB" }, - { (PROC)glMultiTexCoord1svARB, "glMultiTexCoord1svARB" }, - { (PROC)glMultiTexCoord2dARB, "glMultiTexCoord2dARB" }, - { (PROC)glMultiTexCoord2dvARB, "glMultiTexCoord2dvARB" }, - { (PROC)glMultiTexCoord2fARB, "glMultiTexCoord2fARB" }, - { (PROC)glMultiTexCoord2fvARB, "glMultiTexCoord2fvARB" }, - { (PROC)glMultiTexCoord2iARB, "glMultiTexCoord2iARB" }, - { (PROC)glMultiTexCoord2ivARB, "glMultiTexCoord2ivARB" }, - { (PROC)glMultiTexCoord2sARB, "glMultiTexCoord2sARB" }, - { (PROC)glMultiTexCoord2svARB, "glMultiTexCoord2svARB" }, - { (PROC)glMultiTexCoord3dARB, "glMultiTexCoord3dARB" }, - { (PROC)glMultiTexCoord3dvARB, "glMultiTexCoord3dvARB" }, - { (PROC)glMultiTexCoord3fARB, "glMultiTexCoord3fARB" }, - { (PROC)glMultiTexCoord3fvARB, "glMultiTexCoord3fvARB" }, - { (PROC)glMultiTexCoord3iARB, "glMultiTexCoord3iARB" }, - { (PROC)glMultiTexCoord3ivARB, "glMultiTexCoord3ivARB" }, - { (PROC)glMultiTexCoord3sARB, "glMultiTexCoord3sARB" }, - { (PROC)glMultiTexCoord3svARB, "glMultiTexCoord3svARB" }, - { (PROC)glMultiTexCoord4dARB, "glMultiTexCoord4dARB" }, - { (PROC)glMultiTexCoord4dvARB, "glMultiTexCoord4dvARB" }, - { (PROC)glMultiTexCoord4fARB, "glMultiTexCoord4fARB" }, - { (PROC)glMultiTexCoord4fvARB, "glMultiTexCoord4fvARB" }, - { (PROC)glMultiTexCoord4iARB, "glMultiTexCoord4iARB" }, - { (PROC)glMultiTexCoord4ivARB, "glMultiTexCoord4ivARB" }, - { (PROC)glMultiTexCoord4sARB, "glMultiTexCoord4sARB" }, - { (PROC)glMultiTexCoord4svARB, "glMultiTexCoord4svARB" }, - - // Descent3 doesn't use correct string, hence this hack - { (PROC)glMultiTexCoord4fARB, "glMultiTexCoord4f" }, - - // Quake2 SGIS multitexture - { (PROC)gldSelectTextureSGIS, "glSelectTextureSGIS" }, - { (PROC)gldMTexCoord2fSGIS, "glMTexCoord2fSGIS" }, - { (PROC)gldMTexCoord2fvSGIS, "glMTexCoord2fvSGIS" }, - - { NULL, "\0" } -}; - -//--------------------------------------------------------------------------- - -PROC gldGetProcAddress_DX( - LPCSTR a) -{ - int i; - PROC proc = NULL; - - for (i=0; GLD_extList[i].proc; i++) { - if (!strcmp(a, GLD_extList[i].name)) { - proc = GLD_extList[i].proc; - break; - } - } - - if (glb.bMultitexture) { - for (i=0; GLD_multitexList[i].proc; i++) { - if (!strcmp(a, GLD_multitexList[i].name)) { - proc = GLD_multitexList[i].proc; - break; - } - } - } - - gldLogPrintf(GLDLOG_INFO, "GetProcAddress: %s (%s)", a, proc ? "OK" : "Failed"); - - return proc; -} - -//--------------------------------------------------------------------------- - -void gldEnableExtensions_DX8( - GLcontext *ctx) -{ - GLuint i; - - // Mesa enables some extensions by default. - // This table decides which ones we want to switch off again. - - // NOTE: GL_EXT_compiled_vertex_array appears broken. - - const char *gld_disable_extensions[] = { -// "GL_ARB_transpose_matrix", -// "GL_EXT_compiled_vertex_array", -// "GL_EXT_polygon_offset", -// "GL_EXT_rescale_normal", - "GL_EXT_texture3D", -// "GL_NV_texgen_reflection", - NULL - }; - - const char *gld_multitex_extensions[] = { - "GL_ARB_multitexture", // Quake 3 - NULL - }; - - // Quake 2 engines - const char *szGL_SGIS_multitexture = "GL_SGIS_multitexture"; - - const char *gld_enable_extensions[] = { - "GL_EXT_texture_env_add", // Quake 3 - "GL_ARB_texture_env_add", // Quake 3 - NULL - }; - - for (i=0; gld_disable_extensions[i]; i++) { - _mesa_disable_extension(ctx, gld_disable_extensions[i]); - } - - for (i=0; gld_enable_extensions[i]; i++) { - _mesa_enable_extension(ctx, gld_enable_extensions[i]); - } - - if (glb.bMultitexture) { - for (i=0; gld_multitex_extensions[i]; i++) { - _mesa_enable_extension(ctx, gld_multitex_extensions[i]); - } - - // GL_SGIS_multitexture - // NOTE: Quake2 ran *slower* with this enabled, so I've - // disabled it for now. - // Fair bit slower on GeForce256, - // Much slower on 3dfx Voodoo5 5500. -// _mesa_add_extension(ctx, GL_TRUE, szGL_SGIS_multitexture, 0); - - } - - _mesa_enable_imaging_extensions(ctx); - _mesa_enable_1_3_extensions(ctx); - _mesa_enable_1_4_extensions(ctx); -} - -//--------------------------------------------------------------------------- diff --git a/src/mesa/drivers/windows/gldirect/dx8/gld_pipeline_dx8.c b/src/mesa/drivers/windows/gldirect/dx8/gld_pipeline_dx8.c deleted file mode 100644 index 2baea57443..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx8/gld_pipeline_dx8.c +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: Mesa transformation pipeline with GLDirect fastpath -* -****************************************************************************/ - -//#include "../GLDirect.h" - -#include "dglcontext.h" -#include "ddlog.h" -#include "gld_dx8.h" - -#include "tnl/tnl.h" -#include "tnl/t_context.h" -#include "tnl/t_pipeline.h" - -//--------------------------------------------------------------------------- - -extern struct tnl_pipeline_stage _gld_d3d_render_stage; -extern struct tnl_pipeline_stage _gld_mesa_render_stage; - -static const struct tnl_pipeline_stage *gld_pipeline[] = { - &_gld_d3d_render_stage, // Direct3D TnL - &_tnl_vertex_transform_stage, - &_tnl_normal_transform_stage, - &_tnl_lighting_stage, - &_tnl_fog_coordinate_stage, /* TODO: Omit fog stage. ??? */ - &_tnl_texgen_stage, - &_tnl_texture_transform_stage, - &_tnl_point_attenuation_stage, - &_gld_mesa_render_stage, // Mesa TnL, D3D rendering - 0, -}; - -//--------------------------------------------------------------------------- - -void gldInstallPipeline_DX8( - GLcontext *ctx) -{ - // Remove any existing pipeline stages, - // then install GLDirect pipeline stages. - - _tnl_destroy_pipeline(ctx); - _tnl_install_pipeline(ctx, gld_pipeline); -} - -//--------------------------------------------------------------------------- diff --git a/src/mesa/drivers/windows/gldirect/dx8/gld_primitive_dx8.c b/src/mesa/drivers/windows/gldirect/dx8/gld_primitive_dx8.c deleted file mode 100644 index a5b5462f03..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx8/gld_primitive_dx8.c +++ /dev/null @@ -1,1446 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: Primitive (points/lines/tris/quads) rendering -* -****************************************************************************/ - -//#include "../GLDirect.h" - -//#include "gld_dx8.h" - -#include "dglcontext.h" -#include "ddlog.h" -#include "gld_dx8.h" - -#include "glheader.h" -#include "context.h" -#include "colormac.h" -#include "depth.h" -#include "extensions.h" -#include "macros.h" -#include "matrix.h" -// #include "mem.h" -//#include "mmath.h" -#include "mtypes.h" -#include "texformat.h" -#include "texstore.h" -#include "vbo/vbo.h" -#include "swrast/swrast.h" -#include "swrast_setup/swrast_setup.h" -#include "swrast_setup/ss_context.h" -#include "swrast/s_context.h" -#include "swrast/s_depth.h" -#include "swrast/s_lines.h" -#include "swrast/s_triangle.h" -#include "swrast/s_trispan.h" -#include "tnl/tnl.h" -#include "tnl/t_context.h" -#include "tnl/t_pipeline.h" - -// Disable compiler complaints about unreferenced local variables -#pragma warning (disable:4101) - -//--------------------------------------------------------------------------- -// Helper defines for primitives -//--------------------------------------------------------------------------- - -//static const float ooZ = 1.0f / 65536.0f; // One over Z - -#define GLD_COLOUR (D3DCOLOR_RGBA(swv->color[0], swv->color[1], swv->color[2], swv->color[3])) -#define GLD_SPECULAR (D3DCOLOR_RGBA(swv->specular[0], swv->specular[1], swv->specular[2], swv->specular[3])) -#define GLD_FLIP_Y(y) (gldCtx->dwHeight - (y)) - -//--------------------------------------------------------------------------- -// 2D vertex setup -//--------------------------------------------------------------------------- - -#define GLD_SETUP_2D_VARS_POINTS \ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); \ - GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pPoints; \ - SScontext *ss = SWSETUP_CONTEXT(ctx); \ - SWvertex *swv; \ - DWORD dwSpecularColour; \ - DWORD dwFlatColour - -#define GLD_SETUP_2D_VARS_LINES \ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); \ - GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pLines; \ - SScontext *ss = SWSETUP_CONTEXT(ctx); \ - SWvertex *swv; \ - DWORD dwSpecularColour; \ - DWORD dwFlatColour - -#define GLD_SETUP_2D_VARS_TRIANGLES \ - BOOL bFog = ctx->Fog.Enabled; \ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); \ - GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pTriangles; \ - SScontext *ss = SWSETUP_CONTEXT(ctx); \ - SWvertex *swv; \ - DWORD dwSpecularColour; \ - DWORD dwFlatColour; \ - GLuint facing = 0; \ - struct vertex_buffer *VB; \ - GLchan (*vbcolor)[4]; \ - GLchan (*vbspec)[4] - -#define GLD_SETUP_GET_SWVERT(s) \ - swv = &ss->verts[##s] - -#define GLD_SETUP_2D_VERTEX \ - pV->x = swv->win[0]; \ - pV->y = GLD_FLIP_Y(swv->win[1]); \ - pV->rhw = swv->win[3] - -#define GLD_SETUP_SMOOTH_COLOUR \ - pV->diffuse = GLD_COLOUR - -#define GLD_SETUP_GET_FLAT_COLOUR \ - dwFlatColour = GLD_COLOUR -#define GLD_SETUP_GET_FLAT_FOG_COLOUR \ - dwFlatColour = _gldComputeFog(ctx, swv) - -#define GLD_SETUP_USE_FLAT_COLOUR \ - pV->diffuse = dwFlatColour - -#define GLD_SETUP_GET_FLAT_SPECULAR \ - dwSpecularColour= GLD_SPECULAR - -#define GLD_SETUP_USE_FLAT_SPECULAR \ - pV->specular = dwSpecularColour - -#define GLD_SETUP_DEPTH \ - pV->sz = swv->win[2] / ctx->DepthMaxF -// pV->z = swv->win[2] * ooZ; - -#define GLD_SETUP_SPECULAR \ - pV->specular = GLD_SPECULAR - -#define GLD_SETUP_FOG \ - pV->diffuse = _gldComputeFog(ctx, swv) - -#define GLD_SETUP_TEX0 \ - pV->t0_u = swv->texcoord[0][0]; \ - pV->t0_v = swv->texcoord[0][1] - -#define GLD_SETUP_TEX1 \ - pV->t1_u = swv->texcoord[1][0]; \ - pV->t1_v = swv->texcoord[1][1] - -#define GLD_SETUP_LIGHTING(v) \ - if (facing == 1) { \ - pV->diffuse = D3DCOLOR_RGBA(vbcolor[##v][0], vbcolor[##v][1], vbcolor[##v][2], vbcolor[##v][3]); \ - if (vbspec) { \ - pV->specular = D3DCOLOR_RGBA(vbspec[##v][0], vbspec[##v][1], vbspec[##v][2], vbspec[##v][3]); \ - } \ - } else { \ - if (bFog) \ - GLD_SETUP_FOG; \ - else \ - GLD_SETUP_SMOOTH_COLOUR; \ - GLD_SETUP_SPECULAR; \ - } - -#define GLD_SETUP_GET_FLAT_LIGHTING(v) \ - if (facing == 1) { \ - dwFlatColour = D3DCOLOR_RGBA(vbcolor[##v][0], vbcolor[##v][1], vbcolor[##v][2], vbcolor[##v][3]); \ - if (vbspec) { \ - dwSpecularColour = D3DCOLOR_RGBA(vbspec[##v][0], vbspec[##v][1], vbspec[##v][2], vbspec[##v][3]); \ - } \ - } - -#define GLD_SETUP_TWOSIDED_LIGHTING \ - /* Two-sided lighting */ \ - if (ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) { \ - SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts; \ - SWvertex *v[3]; \ - GLfloat ex,ey,fx,fy,cc; \ - /* Get vars for later */ \ - VB = &TNL_CONTEXT(ctx)->vb; \ - vbcolor = (GLchan (*)[4])VB->ColorPtr[1]->data; \ - if (VB->SecondaryColorPtr[1]) { \ - vbspec = (GLchan (*)[4])VB->SecondaryColorPtr[1]->data; \ - } else { \ - vbspec = NULL; \ - } \ - v[0] = &verts[v0]; \ - v[1] = &verts[v1]; \ - v[2] = &verts[v2]; \ - ex = v[0]->win[0] - v[2]->win[0]; \ - ey = v[0]->win[1] - v[2]->win[1]; \ - fx = v[1]->win[0] - v[2]->win[0]; \ - fy = v[1]->win[1] - v[2]->win[1]; \ - cc = ex*fy - ey*fx; \ - facing = (cc < 0.0) ^ ctx->Polygon._FrontBit; \ - } - -//--------------------------------------------------------------------------- -// 3D vertex setup -//--------------------------------------------------------------------------- - -#define GLD_SETUP_3D_VARS_POINTS \ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); \ - GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pPoints; \ - TNLcontext *tnl = TNL_CONTEXT(ctx); \ - struct vertex_buffer *VB = &tnl->vb; \ - GLfloat (*p4f)[4]; \ - GLfloat (*tc)[4]; \ - DWORD dwColor; - -#define GLD_SETUP_3D_VARS_LINES \ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); \ - GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pLines; \ - TNLcontext *tnl = TNL_CONTEXT(ctx); \ - struct vertex_buffer *VB = &tnl->vb; \ - GLfloat (*p4f)[4]; \ - GLfloat (*tc)[4]; \ - DWORD dwColor; - -#define GLD_SETUP_3D_VARS_TRIANGLES \ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); \ - GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pTriangles; \ - TNLcontext *tnl = TNL_CONTEXT(ctx); \ - struct vertex_buffer *VB = &tnl->vb; \ - GLfloat (*p4f)[4]; \ - GLfloat (*tc)[4]; \ - DWORD dwColor; - -#define GLD_SETUP_3D_VERTEX(v) \ - p4f = VB->ObjPtr->data; \ - pV->Position.x = p4f[##v][0]; \ - pV->Position.y = p4f[##v][1]; \ - pV->Position.z = p4f[##v][2]; - -#define GLD_SETUP_SMOOTH_COLOUR_3D(v) \ - p4f = (GLfloat (*)[4])VB->ColorPtr[0]->data; \ - pV->Diffuse = D3DCOLOR_COLORVALUE(p4f[##v][0], p4f[##v][1], p4f[##v][2], p4f[##v][3]); - - -#define GLD_SETUP_GET_FLAT_COLOUR_3D(v) \ - p4f = (GLfloat (*)[4])VB->ColorPtr[0]->data; \ - dwColor = D3DCOLOR_COLORVALUE(p4f[##v][0], p4f[##v][1], p4f[##v][2], p4f[##v][3]); - -#define GLD_SETUP_USE_FLAT_COLOUR_3D \ - pV->Diffuse = dwColor; - -#define GLD_SETUP_TEX0_3D(v) \ - if (VB->TexCoordPtr[0]) { \ - tc = VB->TexCoordPtr[0]->data; \ - pV->TexUnit0.x = tc[##v][0]; \ - pV->TexUnit0.y = tc[##v][1]; \ - } - -#define GLD_SETUP_TEX1_3D(v) \ - if (VB->TexCoordPtr[1]) { \ - tc = VB->TexCoordPtr[1]->data; \ - pV->TexUnit1.x = tc[##v][0]; \ - pV->TexUnit1.y = tc[##v][1]; \ - } - -//--------------------------------------------------------------------------- -// Helper functions -//--------------------------------------------------------------------------- - -__inline DWORD _gldComputeFog( - GLcontext *ctx, - SWvertex *swv) -{ - // Full fog calculation. - // Based on Mesa code. - - GLchan rFog, gFog, bFog; - GLchan fR, fG, fB; - const GLfloat f = swv->fog; - const GLfloat g = 1.0f - f; - - UNCLAMPED_FLOAT_TO_CHAN(rFog, ctx->Fog.Color[RCOMP]); - UNCLAMPED_FLOAT_TO_CHAN(gFog, ctx->Fog.Color[GCOMP]); - UNCLAMPED_FLOAT_TO_CHAN(bFog, ctx->Fog.Color[BCOMP]); - fR = f * swv->color[0] + g * rFog; - fG = f * swv->color[1] + g * gFog; - fB = f * swv->color[2] + g * bFog; - return D3DCOLOR_RGBA(fR, fG, fB, swv->color[3]); -} - -//--------------------------------------------------------------------------- - -void gld_ResetLineStipple_DX8( - GLcontext *ctx) -{ - // TODO: Fake stipple with a 32x32 texture. -} - -//--------------------------------------------------------------------------- -// 2D (post-transformed) primitives -//--------------------------------------------------------------------------- - -void gld_Points2D_DX8( - GLcontext *ctx, - GLuint first, - GLuint last) -{ - GLD_SETUP_2D_VARS_POINTS; - - unsigned i; - struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; - - // _Size is already clamped to MaxPointSize and MinPointSize - IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_POINTSIZE, *((DWORD*)&ctx->Point._Size)); - - if (VB->Elts) { - for (i=first; i<last; i++, pV++) { - if (VB->ClipMask[VB->Elts[i]] == 0) { -// _swrast_Point( ctx, &verts[VB->Elts[i]] ); - GLD_SETUP_GET_SWVERT(VB->Elts[i]); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_SPECULAR; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - } - } - } else { - GLD_SETUP_GET_SWVERT(first); - for (i=first; i<last; i++, swv++, pV++) { - if (VB->ClipMask[i] == 0) { -// _swrast_Point( ctx, &verts[i] ); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_SPECULAR; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - } - } - } - - gld->PB2d.pPoints = (BYTE*)pV; - gld->PB2d.nPoints += (last-first); -} - -//--------------------------------------------------------------------------- - -void gld_Line2DFlat_DX8( - GLcontext *ctx, - GLuint v0, - GLuint v1) -{ - GLD_SETUP_2D_VARS_LINES; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_GET_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_GET_FLAT_SPECULAR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - gld->PB2d.pLines = (BYTE*)pV; - gld->PB2d.nLines++; -} - -//--------------------------------------------------------------------------- - -void gld_Line2DSmooth_DX8( - GLcontext *ctx, - GLuint v0, - GLuint v1) -{ - GLD_SETUP_2D_VARS_LINES; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_SPECULAR; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_SPECULAR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - gld->PB2d.pLines = (BYTE*)pV; - gld->PB2d.nLines++; -} - -//--------------------------------------------------------------------------- - -void gld_Triangle2DFlat_DX8( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_GET_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_COLOUR; - pV++;; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles++; -} - -//--------------------------------------------------------------------------- - -void gld_Triangle2DSmooth_DX8( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2) -{ - - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles++; -} - -//--------------------------------------------------------------------------- - -void gld_Triangle2DFlatExtras_DX8( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_TWOSIDED_LIGHTING(v2); - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - if (bFog) - GLD_SETUP_GET_FLAT_FOG_COLOUR; - else - GLD_SETUP_GET_FLAT_COLOUR; - GLD_SETUP_GET_FLAT_SPECULAR; - GLD_SETUP_GET_FLAT_LIGHTING(v2); - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles++; -} - -//--------------------------------------------------------------------------- - -void gld_Triangle2DSmoothExtras_DX8( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_TWOSIDED_LIGHTING(v0); - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v0); - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v1); - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v2); - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles++; -} - -//--------------------------------------------------------------------------- - -void gld_Quad2DFlat_DX8( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2, - GLuint v3) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_GET_SWVERT(v3); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_GET_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - GLD_SETUP_GET_SWVERT(v3); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles += 2; -} - -//--------------------------------------------------------------------------- - -void gld_Quad2DSmooth_DX8( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2, - GLuint v3) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v3); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles += 2; -} - -//--------------------------------------------------------------------------- - -void gld_Quad2DFlatExtras_DX8( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2, - GLuint v3) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_TWOSIDED_LIGHTING(v3); - - GLD_SETUP_GET_SWVERT(v3); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - if (bFog) - GLD_SETUP_GET_FLAT_FOG_COLOUR; - else - GLD_SETUP_GET_FLAT_COLOUR; - GLD_SETUP_GET_FLAT_SPECULAR; - GLD_SETUP_GET_FLAT_LIGHTING(v3); - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v3); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles += 2; -} - -//--------------------------------------------------------------------------- - -void gld_Quad2DSmoothExtras_DX8( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2, - GLuint v3) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_TWOSIDED_LIGHTING(v0); - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v0); - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v1); - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v2); - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v2); - pV++; - - GLD_SETUP_GET_SWVERT(v3); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v3); - pV++; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v0); - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles += 2; -} - -//--------------------------------------------------------------------------- -// 3D (pre-transformed) primitives -//--------------------------------------------------------------------------- - -void gld_Points3D_DX8( - GLcontext *ctx, - GLuint first, - GLuint last) -{ - GLD_SETUP_3D_VARS_POINTS - - unsigned i; -// struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; - - // _Size is already clamped to MaxPointSize and MinPointSize - IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_POINTSIZE, *((DWORD*)&ctx->Point._Size)); - - if (VB->Elts) { - for (i=first; i<last; i++, pV++) { - if (VB->ClipMask[VB->Elts[i]] == 0) { -// _swrast_Point( ctx, &verts[VB->Elts[i]] ); -// GLD_SETUP_GET_SWVERT(VB->Elts[i]); - GLD_SETUP_3D_VERTEX(VB->Elts[i]) - GLD_SETUP_SMOOTH_COLOUR_3D(i) - GLD_SETUP_TEX0_3D(i) - GLD_SETUP_TEX1_3D(i) - } - } - } else { -// GLD_SETUP_GET_SWVERT(first); - for (i=first; i<last; i++, pV++) { - if (VB->ClipMask[i] == 0) { -// _swrast_Point( ctx, &verts[i] ); - GLD_SETUP_3D_VERTEX(i) - GLD_SETUP_SMOOTH_COLOUR_3D(i) - GLD_SETUP_TEX0_3D(i) - GLD_SETUP_TEX1_3D(i) - } - } - } -/* - for (i=first; i<last; i++, pV++) { - GLD_SETUP_3D_VERTEX(i) - GLD_SETUP_SMOOTH_COLOUR_3D(i) - GLD_SETUP_TEX0_3D(i) - GLD_SETUP_TEX1_3D(i) - } -*/ - gld->PB3d.pPoints = (BYTE*)pV; - gld->PB3d.nPoints += (last-first); -} - -//--------------------------------------------------------------------------- -// Line functions -//--------------------------------------------------------------------------- - -void gld_Line3DFlat_DX8( - GLcontext *ctx, - GLuint v0, - GLuint v1) -{ - GLD_SETUP_3D_VARS_LINES - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_GET_FLAT_COLOUR_3D(v1) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - pV++; - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - pV++; - - gld->PB3d.pLines = (BYTE*)pV; - gld->PB3d.nLines++; -} - -//--------------------------------------------------------------------------- - -void gld_Line3DSmooth_DX8( - GLcontext *ctx, - GLuint v0, - GLuint v1) -{ - GLD_SETUP_3D_VARS_LINES - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_SMOOTH_COLOUR_3D(v1) - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - pV++; - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_SMOOTH_COLOUR_3D(v0) - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - pV++; - - gld->PB3d.pLines = (BYTE*)pV; - gld->PB3d.nLines++; -} - -//--------------------------------------------------------------------------- -// Triangle functions -//--------------------------------------------------------------------------- - -void gld_Triangle3DFlat_DX8( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2) -{ - GLD_SETUP_3D_VARS_TRIANGLES - - GLD_SETUP_3D_VERTEX(v2) - GLD_SETUP_TEX0_3D(v2) - GLD_SETUP_TEX1_3D(v2) - GLD_SETUP_GET_FLAT_COLOUR_3D(v2) - GLD_SETUP_USE_FLAT_COLOUR_3D - pV++; - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - GLD_SETUP_USE_FLAT_COLOUR_3D - pV++; - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - GLD_SETUP_USE_FLAT_COLOUR_3D - pV++; - - gld->PB3d.pTriangles = (BYTE*)pV; - gld->PB3d.nTriangles++; -} - -//--------------------------------------------------------------------------- - -void gld_Triangle3DSmooth_DX8( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2) -{ - GLD_SETUP_3D_VARS_TRIANGLES - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_SMOOTH_COLOUR_3D(v0) - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - pV++; - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_SMOOTH_COLOUR_3D(v1) - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - pV++; - - GLD_SETUP_3D_VERTEX(v2) - GLD_SETUP_SMOOTH_COLOUR_3D(v2) - GLD_SETUP_TEX0_3D(v2) - GLD_SETUP_TEX1_3D(v2) - pV++; - - gld->PB3d.pTriangles = (BYTE*)pV; - gld->PB3d.nTriangles++; -} - -//--------------------------------------------------------------------------- -// Quad functions -//--------------------------------------------------------------------------- - -void gld_Quad3DFlat_DX8( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2, - GLuint v3) -{ - GLD_SETUP_3D_VARS_TRIANGLES - - GLD_SETUP_3D_VERTEX(v3) - GLD_SETUP_GET_FLAT_COLOUR_3D(v3) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v3) - GLD_SETUP_TEX1_3D(v3) - pV++; - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - pV++; - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - pV++; - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - pV++; - - GLD_SETUP_3D_VERTEX(v2) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v2) - GLD_SETUP_TEX1_3D(v2) - pV++; - - GLD_SETUP_3D_VERTEX(v3) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v3) - GLD_SETUP_TEX1_3D(v3) - pV++; - - gld->PB3d.pTriangles = (BYTE*)pV; - gld->PB3d.nTriangles += 2; -} - -//--------------------------------------------------------------------------- - -void gld_Quad3DSmooth_DX8( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2, - GLuint v3) -{ - GLD_SETUP_3D_VARS_TRIANGLES - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_SMOOTH_COLOUR_3D(v0) - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - pV++; - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_SMOOTH_COLOUR_3D(v1) - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - pV++; - - GLD_SETUP_3D_VERTEX(v2) - GLD_SETUP_SMOOTH_COLOUR_3D(v2) - GLD_SETUP_TEX0_3D(v2) - GLD_SETUP_TEX1_3D(v2) - pV++; - - GLD_SETUP_3D_VERTEX(v2) - GLD_SETUP_SMOOTH_COLOUR_3D(v2) - GLD_SETUP_TEX0_3D(v2) - GLD_SETUP_TEX1_3D(v2) - pV++; - - GLD_SETUP_3D_VERTEX(v3) - GLD_SETUP_SMOOTH_COLOUR_3D(v3) - GLD_SETUP_TEX0_3D(v3) - GLD_SETUP_TEX1_3D(v3) - pV++; - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_SMOOTH_COLOUR_3D(v0) - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - pV++; - - gld->PB3d.pTriangles = (BYTE*)pV; - gld->PB3d.nTriangles += 2; -} - -//--------------------------------------------------------------------------- -// Vertex setup for two-sided-lighting vertex shader -//--------------------------------------------------------------------------- - -/* - -void gld_Points2DTwoside_DX8(GLcontext *ctx, GLuint first, GLuint last) -{ - // NOTE: Two-sided lighting does not apply to Points -} - -//--------------------------------------------------------------------------- - -void gld_Line2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1) -{ - // NOTE: Two-sided lighting does not apply to Lines -} - -//--------------------------------------------------------------------------- - -void gld_Line2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1) -{ - // NOTE: Two-sided lighting does not apply to Lines -} - -//--------------------------------------------------------------------------- - -void gld_Triangle2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2) -{ -} - -//--------------------------------------------------------------------------- - -void gld_Triangle2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles; - SScontext *ss = SWSETUP_CONTEXT(ctx); - SWvertex *swv; - DWORD dwSpecularColour; - DWORD dwFlatColour; - GLuint facing = 0; - struct vertex_buffer *VB; - GLchan (*vbcolor)[4]; - GLchan (*vbspec)[4]; - - // Reciprocal of DepthMax - const float ooDepthMax = 1.0f / ctx->DepthMaxF; - - // 1st vert - swv = &ss->verts[v0]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 2nd vert - swv = &ss->verts[v1]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 3rd vert - swv = &ss->verts[v2]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - gld->PBtwosidelight.pTriangles = (BYTE*)pV; - gld->PBtwosidelight.nTriangles++; -} - -//--------------------------------------------------------------------------- - -void gld_Quad2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles; - SScontext *ss = SWSETUP_CONTEXT(ctx); - SWvertex *swv; - DWORD dwSpecularColour; - DWORD dwFlatColour; - GLuint facing = 0; - struct vertex_buffer *VB; - GLchan (*vbcolor)[4]; - GLchan (*vbspec)[4]; - - // Reciprocal of DepthMax - const float ooDepthMax = 1.0f / ctx->DepthMaxF; - - // 1st vert - swv = &ss->verts[v0]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 2nd vert - swv = &ss->verts[v1]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 3rd vert - swv = &ss->verts[v2]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 4th vert - swv = &ss->verts[v2]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 5th vert - swv = &ss->verts[v3]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 6th vert - swv = &ss->verts[v0]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - gld->PBtwosidelight.pTriangles = (BYTE*)pV; - gld->PBtwosidelight.nTriangles += 2; -} - -//--------------------------------------------------------------------------- - -void gld_Quad2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles; - SScontext *ss = SWSETUP_CONTEXT(ctx); - SWvertex *swv; - DWORD dwSpecularColour; - DWORD dwFlatColour; - GLuint facing = 0; - struct vertex_buffer *VB; - GLchan (*vbcolor)[4]; - GLchan (*vbspec)[4]; - - // Reciprocal of DepthMax - const float ooDepthMax = 1.0f / ctx->DepthMaxF; - - // 1st vert - swv = &ss->verts[v0]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 2nd vert - swv = &ss->verts[v1]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 3rd vert - swv = &ss->verts[v2]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 4th vert - swv = &ss->verts[v2]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 5th vert - swv = &ss->verts[v3]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 6th vert - swv = &ss->verts[v0]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - gld->PBtwosidelight.pTriangles = (BYTE*)pV; - gld->PBtwosidelight.nTriangles += 2; -} - -//--------------------------------------------------------------------------- - -*/ diff --git a/src/mesa/drivers/windows/gldirect/dx8/gld_texture_dx8.c b/src/mesa/drivers/windows/gldirect/dx8/gld_texture_dx8.c deleted file mode 100644 index f24b3cfb74..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx8/gld_texture_dx8.c +++ /dev/null @@ -1,2046 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: Texture / Bitmap functions -* -****************************************************************************/ - -#include "dglcontext.h" -#include "ddlog.h" -#include "gld_dx8.h" - -#include <d3dx8tex.h> - -#include "texformat.h" -#include "colormac.h" -#include "texstore.h" -#include "image.h" -// #include "mem.h" - -//--------------------------------------------------------------------------- - -#define GLD_FLIP_HEIGHT(y,h) (gldCtx->dwHeight - (y) - (h)) - -//--------------------------------------------------------------------------- -// 1D texture fetch -//--------------------------------------------------------------------------- - -#define CHAN_SRC( t, i, j, k, sz ) \ - ((GLchan *)(t)->Data + (i) * (sz)) -#define UBYTE_SRC( t, i, j, k, sz ) \ - ((GLubyte *)(t)->Data + (i) * (sz)) -#define USHORT_SRC( t, i, j, k ) \ - ((GLushort *)(t)->Data + (i)) -#define FLOAT_SRC( t, i, j, k ) \ - ((GLfloat *)(t)->Data + (i)) - -//--------------------------------------------------------------------------- - -static void gld_fetch_1d_texel_X8R8G8B8( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); - GLchan *rgba = (GLchan *)texel; - rgba[RCOMP] = src[2]; - rgba[GCOMP] = src[1]; - rgba[BCOMP] = src[0]; - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_1d_texel_f_X8R8G8B8( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); - texel[RCOMP] = CHAN_TO_FLOAT(src[0]); - texel[GCOMP] = CHAN_TO_FLOAT(src[1]); - texel[BCOMP] = CHAN_TO_FLOAT(src[2]); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_1d_texel_X1R5G5B5( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLchan *rgba = (GLchan *) texel; GLushort s = *src; - rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0xf8) * 255 / 0xf8 ); - rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0xf8) * 255 / 0xf8 ); - rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf8) * 255 / 0xf8 ); - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_1d_texel_f_X1R5G5B5( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLushort s = *src; - texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0xf8) * 255 / 0xf8 ); - texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0xf8) * 255 / 0xf8 ); - texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf8) * 255 / 0xf8 ); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_1d_texel_X4R4G4B4( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLchan *rgba = (GLchan *) texel; GLushort s = *src; - rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf ); - rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf ); - rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf ); - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_1d_texel_f_X4R4G4B4( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLushort s = *src; - texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf ); - texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf ); - texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf ); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -#undef CHAN_SRC -#undef UBYTE_SRC -#undef USHORT_SRC -#undef FLOAT_SRC - -//--------------------------------------------------------------------------- -// 2D texture fetch -//--------------------------------------------------------------------------- - -#define CHAN_SRC( t, i, j, k, sz ) \ - ((GLchan *)(t)->Data + ((t)->Width * (j) + (i)) * (sz)) -#define UBYTE_SRC( t, i, j, k, sz ) \ - ((GLubyte *)(t)->Data + ((t)->Width * (j) + (i)) * (sz)) -#define USHORT_SRC( t, i, j, k ) \ - ((GLushort *)(t)->Data + ((t)->Width * (j) + (i))) -#define FLOAT_SRC( t, i, j, k ) \ - ((GLfloat *)(t)->Data + ((t)->Width * (j) + (i))) - -//--------------------------------------------------------------------------- - -static void gld_fetch_2d_texel_X8R8G8B8( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); - GLchan *rgba = (GLchan *)texel; - rgba[RCOMP] = src[2]; - rgba[GCOMP] = src[1]; - rgba[BCOMP] = src[0]; - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_2d_texel_f_X8R8G8B8( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); - texel[RCOMP] = CHAN_TO_FLOAT(src[0]); - texel[GCOMP] = CHAN_TO_FLOAT(src[1]); - texel[BCOMP] = CHAN_TO_FLOAT(src[2]); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_2d_texel_X1R5G5B5( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLchan *rgba = (GLchan *) texel; GLushort s = *src; - rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0xf8) * 255 / 0xf8 ); - rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0xf8) * 255 / 0xf8 ); - rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf8) * 255 / 0xf8 ); - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_2d_texel_f_X1R5G5B5( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLushort s = *src; - texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0xf8) * 255 / 0xf8 ); - texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0xf8) * 255 / 0xf8 ); - texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf8) * 255 / 0xf8 ); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_2d_texel_X4R4G4B4( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLchan *rgba = (GLchan *) texel; GLushort s = *src; - rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf ); - rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf ); - rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf ); - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_2d_texel_f_X4R4G4B4( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLushort s = *src; - texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf ); - texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf ); - texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf ); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -#undef CHAN_SRC -#undef UBYTE_SRC -#undef USHORT_SRC -#undef FLOAT_SRC - -//--------------------------------------------------------------------------- -// 3D texture fetch -//--------------------------------------------------------------------------- - -#define CHAN_SRC( t, i, j, k, sz ) \ - (GLchan *)(t)->Data + (((t)->Height * (k) + (j)) * \ - (t)->Width + (i)) * (sz) -#define UBYTE_SRC( t, i, j, k, sz ) \ - ((GLubyte *)(t)->Data + (((t)->Height * (k) + (j)) * \ - (t)->Width + (i)) * (sz)) -#define USHORT_SRC( t, i, j, k ) \ - ((GLushort *)(t)->Data + (((t)->Height * (k) + (j)) * \ - (t)->Width + (i))) -#define FLOAT_SRC( t, i, j, k ) \ - ((GLfloat *)(t)->Data + (((t)->Height * (k) + (j)) * \ - (t)->Width + (i))) - -//--------------------------------------------------------------------------- - -static void gld_fetch_3d_texel_X8R8G8B8( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); - GLchan *rgba = (GLchan *)texel; - rgba[RCOMP] = src[2]; - rgba[GCOMP] = src[1]; - rgba[BCOMP] = src[0]; - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_3d_texel_f_X8R8G8B8( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); - texel[RCOMP] = CHAN_TO_FLOAT(src[0]); - texel[GCOMP] = CHAN_TO_FLOAT(src[1]); - texel[BCOMP] = CHAN_TO_FLOAT(src[2]); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_3d_texel_X1R5G5B5( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLchan *rgba = (GLchan *) texel; GLushort s = *src; - rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0xf8) * 255 / 0xf8 ); - rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0xf8) * 255 / 0xf8 ); - rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf8) * 255 / 0xf8 ); - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_3d_texel_f_X1R5G5B5( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLushort s = *src; - texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0xf8) * 255 / 0xf8 ); - texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0xf8) * 255 / 0xf8 ); - texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf8) * 255 / 0xf8 ); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_3d_texel_X4R4G4B4( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLchan *rgba = (GLchan *) texel; GLushort s = *src; - rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf ); - rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf ); - rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf ); - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_3d_texel_f_X4R4G4B4( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLushort s = *src; - texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf ); - texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf ); - texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf ); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -#undef CHAN_SRC -#undef UBYTE_SRC -#undef USHORT_SRC -#undef FLOAT_SRC - -//--------------------------------------------------------------------------- -// Direct3D texture formats that have no Mesa equivalent -//--------------------------------------------------------------------------- - -const struct gl_texture_format _gld_texformat_X8R8G8B8 = { - MESA_FORMAT_ARGB8888, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 8, /* RedBits */ - 8, /* GreenBits */ - 8, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 4, /* TexelBytes */ - _mesa_texstore_argb8888, /* StoreTexImageFunc */ - gld_fetch_1d_texel_X8R8G8B8, /* FetchTexel1D */ - gld_fetch_2d_texel_X8R8G8B8, /* FetchTexel2D */ - gld_fetch_3d_texel_X8R8G8B8, /* FetchTexel3D */ - gld_fetch_1d_texel_f_X8R8G8B8, /* FetchTexel1Df */ - gld_fetch_2d_texel_f_X8R8G8B8, /* FetchTexel2Df */ - gld_fetch_3d_texel_f_X8R8G8B8, /* FetchTexel3Df */ -}; - -const struct gl_texture_format _gld_texformat_X1R5G5B5 = { - MESA_FORMAT_ARGB1555, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 5, /* RedBits */ - 5, /* GreenBits */ - 5, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 2, /* TexelBytes */ - _mesa_texstore_argb1555, /* StoreTexImageFunc */ - gld_fetch_1d_texel_X1R5G5B5, /* FetchTexel1D */ - gld_fetch_2d_texel_X1R5G5B5, /* FetchTexel2D */ - gld_fetch_3d_texel_X1R5G5B5, /* FetchTexel3D */ - gld_fetch_1d_texel_f_X1R5G5B5, /* FetchTexel1Df */ - gld_fetch_2d_texel_f_X1R5G5B5, /* FetchTexel2Df */ - gld_fetch_3d_texel_f_X1R5G5B5, /* FetchTexel3Df */ -}; - -const struct gl_texture_format _gld_texformat_X4R4G4B4 = { - MESA_FORMAT_ARGB4444, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 4, /* RedBits */ - 4, /* GreenBits */ - 4, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 2, /* TexelBytes */ - _mesa_texstore_argb4444, /* StoreTexImageFunc */ - gld_fetch_1d_texel_X4R4G4B4, /* FetchTexel1D */ - gld_fetch_2d_texel_X4R4G4B4, /* FetchTexel2D */ - gld_fetch_3d_texel_X4R4G4B4, /* FetchTexel3D */ - gld_fetch_1d_texel_f_X4R4G4B4, /* FetchTexel1Df */ - gld_fetch_2d_texel_f_X4R4G4B4, /* FetchTexel2Df */ - gld_fetch_3d_texel_f_X4R4G4B4, /* FetchTexel3Df */ -}; - -//--------------------------------------------------------------------------- -// Texture unit constants -//--------------------------------------------------------------------------- - -// List of possible combinations of texture environments. -// Example: GLD_TEXENV_MODULATE_RGBA means -// GL_MODULATE, GL_RGBA base internal format. -#define GLD_TEXENV_DECAL_RGB 0 -#define GLD_TEXENV_DECAL_RGBA 1 -#define GLD_TEXENV_DECAL_ALPHA 2 -#define GLD_TEXENV_REPLACE_RGB 3 -#define GLD_TEXENV_REPLACE_RGBA 4 -#define GLD_TEXENV_REPLACE_ALPHA 5 -#define GLD_TEXENV_MODULATE_RGB 6 -#define GLD_TEXENV_MODULATE_RGBA 7 -#define GLD_TEXENV_MODULATE_ALPHA 8 -#define GLD_TEXENV_BLEND_RGB 9 -#define GLD_TEXENV_BLEND_RGBA 10 -#define GLD_TEXENV_BLEND_ALPHA 11 -#define GLD_TEXENV_ADD_RGB 12 -#define GLD_TEXENV_ADD_RGBA 13 -#define GLD_TEXENV_ADD_ALPHA 14 - -// Per-stage (i.e. per-unit) texture environment -typedef struct { - DWORD ColorArg1; // Colour argument 1 - D3DTEXTUREOP ColorOp; // Colour operation - DWORD ColorArg2; // Colour argument 2 - DWORD AlphaArg1; // Alpha argument 1 - D3DTEXTUREOP AlphaOp; // Alpha operation - DWORD AlphaArg2; // Alpha argument 2 -} GLD_texenv; - -// TODO: Do we really need to set ARG1 and ARG2 every time? -// They seem to always be TEXTURE and CURRENT respectively. - -// C = Colour out -// A = Alpha out -// Ct = Colour from Texture -// Cf = Colour from fragment (diffuse) -// At = Alpha from Texture -// Af = Alpha from fragment (diffuse) -// Cc = GL_TEXTURE_ENV_COLOUR (GL_BLEND) -const GLD_texenv gldTexEnv[] = { - // DECAL_RGB: C=Ct, A=Af - {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - // DECAL_RGBA: C=Cf(1-At)+CtAt, A=Af - {D3DTA_TEXTURE, D3DTOP_BLENDTEXTUREALPHA, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - // DECAL_ALPHA: <undefined> use DECAL_RGB - {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - - // REPLACE_RGB: C=Ct, A=Af - {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - // REPLACE_RGBA: C=Ct, A=At - {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT}, - // REPLACE_ALPHA: C=Cf, A=At - {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT}, - - // MODULATE_RGB: C=CfCt, A=Af - {D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - // MODULATE_RGBA: C=CfCt, A=AfAt - {D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, - // MODULATE_ALPHA: C=Cf, A=AfAt - {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, - - // BLEND_RGB: C=Cf(1-Ct)+CcCt, A=Af - {D3DTA_TEXTURE, D3DTOP_LERP, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - // BLEND_RGBA: C=Cf(1-Ct)+CcCt, A=AfAt - {D3DTA_TEXTURE, D3DTOP_LERP, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, - // BLEND_ALPHA: C=Cf, A=AfAt - {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, - - // ADD_RGB: C=Cf+Ct, A=Af - {D3DTA_TEXTURE, D3DTOP_ADD, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - // ADD_RGBA: C=Cf+Ct, A=AfAt - {D3DTA_TEXTURE, D3DTOP_ADD, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, - // ADD_ALPHA: C=Cf, A=AfAt - {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, -}; - -//--------------------------------------------------------------------------- - -D3DTEXTUREADDRESS _gldConvertWrap( - GLenum wrap) -{ - return (wrap == GL_CLAMP) ? D3DTADDRESS_CLAMP : D3DTADDRESS_WRAP; -} - -//--------------------------------------------------------------------------- - -D3DTEXTUREFILTERTYPE _gldConvertMagFilter( - GLenum magfilter) -{ - return (magfilter == GL_LINEAR) ? D3DTEXF_LINEAR : D3DTEXF_POINT; -} - -//--------------------------------------------------------------------------- - -void _gldConvertMinFilter( - GLenum minfilter, - D3DTEXTUREFILTERTYPE *min_filter, - D3DTEXTUREFILTERTYPE *mip_filter) -{ - switch (minfilter) { - case GL_NEAREST: - *min_filter = D3DTEXF_POINT; - *mip_filter = D3DTEXF_NONE; - break; - case GL_LINEAR: - *min_filter = D3DTEXF_LINEAR; - *mip_filter = D3DTEXF_NONE; - break; - case GL_NEAREST_MIPMAP_NEAREST: - *min_filter = D3DTEXF_POINT; - *mip_filter = D3DTEXF_POINT; - break; - case GL_LINEAR_MIPMAP_NEAREST: - *min_filter = D3DTEXF_LINEAR; - *mip_filter = D3DTEXF_POINT; - break; - case GL_NEAREST_MIPMAP_LINEAR: - *min_filter = D3DTEXF_POINT; - *mip_filter = D3DTEXF_LINEAR; - break; - case GL_LINEAR_MIPMAP_LINEAR: - *min_filter = D3DTEXF_LINEAR; - *mip_filter = D3DTEXF_LINEAR; - break; - } -} - -//--------------------------------------------------------------------------- - -D3DFORMAT _gldGLFormatToD3DFormat( - GLenum internalFormat) -{ - switch (internalFormat) { - case GL_INTENSITY: - case GL_INTENSITY4: - case GL_INTENSITY8: - case GL_INTENSITY12: - case GL_INTENSITY16: - // LUNIMANCE != INTENSITY, but D3D doesn't have I8 textures - return D3DFMT_L8; - case 1: - case GL_LUMINANCE: - case GL_LUMINANCE4: - case GL_LUMINANCE8: - case GL_LUMINANCE12: - case GL_LUMINANCE16: - return D3DFMT_L8; - case GL_ALPHA: - case GL_ALPHA4: - case GL_ALPHA8: - case GL_ALPHA12: - case GL_ALPHA16: - return D3DFMT_A8; - case GL_COLOR_INDEX: - case GL_COLOR_INDEX1_EXT: - case GL_COLOR_INDEX2_EXT: - case GL_COLOR_INDEX4_EXT: - case GL_COLOR_INDEX8_EXT: - case GL_COLOR_INDEX12_EXT: - case GL_COLOR_INDEX16_EXT: - return D3DFMT_X8R8G8B8; - case 2: - case GL_LUMINANCE_ALPHA: - case GL_LUMINANCE4_ALPHA4: - case GL_LUMINANCE6_ALPHA2: - case GL_LUMINANCE8_ALPHA8: - case GL_LUMINANCE12_ALPHA4: - case GL_LUMINANCE12_ALPHA12: - case GL_LUMINANCE16_ALPHA16: - return D3DFMT_A8L8; - case GL_R3_G3_B2: - // TODO: Mesa does not support RGB332 internally - return D3DFMT_X4R4G4B4; //D3DFMT_R3G3B2; - case GL_RGB4: - return D3DFMT_X4R4G4B4; - case GL_RGB5: - return D3DFMT_X1R5G5B5; - case 3: - case GL_RGB: - case GL_RGB8: - case GL_RGB10: - case GL_RGB12: - case GL_RGB16: - return D3DFMT_R8G8B8; - case GL_RGBA4: - return D3DFMT_A4R4G4B4; - case 4: - case GL_RGBA: - case GL_RGBA2: - case GL_RGBA8: - case GL_RGB10_A2: - case GL_RGBA12: - case GL_RGBA16: - return D3DFMT_A8R8G8B8; - case GL_RGB5_A1: - return D3DFMT_A1R5G5B5; - } - - // Return an acceptable default - return D3DFMT_A8R8G8B8; -} - -//--------------------------------------------------------------------------- - -GLenum _gldDecodeBaseFormat( - IDirect3DTexture8 *pTex) -{ - // Examine Direct3D texture and return base OpenGL internal texture format - // NOTE: We can't use any base format info from Mesa because D3D might have - // used a different texture format when we used D3DXCreateTexture(). - - // Base internal format is one of (Red Book p355): - // GL_ALPHA, - // GL_LUMINANCE, - // GL_LUMINANCE_ALPHA, - // GL_INTENSITY, - // GL_RGB, - // GL_RGBA - - // NOTE: INTENSITY not used (not supported by Direct3D) - // LUMINANCE has same texture functions as RGB - // LUMINANCE_ALPHA has same texture functions as RGBA - - // TODO: cache format instead of using GetLevelDesc() - D3DSURFACE_DESC desc; - _GLD_DX8_TEX(GetLevelDesc(pTex, 0, &desc)); - - switch (desc.Format) { - case D3DFMT_R8G8B8: - case D3DFMT_X8R8G8B8: - case D3DFMT_R5G6B5: - case D3DFMT_X1R5G5B5: - case D3DFMT_R3G3B2: - case D3DFMT_X4R4G4B4: - case D3DFMT_P8: - case D3DFMT_L8: - return GL_RGB; - case D3DFMT_A8R8G8B8: - case D3DFMT_A1R5G5B5: - case D3DFMT_A4R4G4B4: - case D3DFMT_A8R3G3B2: - case D3DFMT_A8P8: - case D3DFMT_A8L8: - case D3DFMT_A4L4: - return GL_RGBA; - case D3DFMT_A8: - return GL_ALPHA; - // Compressed texture formats. Need to check these... - case D3DFMT_DXT1: - return GL_RGBA; - case D3DFMT_DXT2: - return GL_RGB; - case D3DFMT_DXT3: - return GL_RGBA; - case D3DFMT_DXT4: - return GL_RGB; - case D3DFMT_DXT5: - return GL_RGBA; - } - - // Fell through. Return arbitary default. - return GL_RGBA; -} - -//--------------------------------------------------------------------------- - -const struct gl_texture_format* _gldMesaFormatForD3DFormat( - D3DFORMAT d3dfmt) -{ - switch (d3dfmt) { - case D3DFMT_A8R8G8B8: - return &_mesa_texformat_argb8888; - case D3DFMT_R8G8B8: - return &_mesa_texformat_rgb888; - case D3DFMT_R5G6B5: - return &_mesa_texformat_rgb565; - case D3DFMT_A4R4G4B4: - return &_mesa_texformat_argb4444; - case D3DFMT_A1R5G5B5: - return &_mesa_texformat_argb1555; - case D3DFMT_A8L8: - return &_mesa_texformat_al88; - case D3DFMT_R3G3B2: - return &_mesa_texformat_rgb332; - case D3DFMT_A8: - return &_mesa_texformat_a8; - case D3DFMT_L8: - return &_mesa_texformat_l8; - case D3DFMT_X8R8G8B8: - return &_gld_texformat_X8R8G8B8; - case D3DFMT_X1R5G5B5: - return &_gld_texformat_X1R5G5B5; - case D3DFMT_X4R4G4B4: - return &_gld_texformat_X4R4G4B4; - } - - // If we reach here then we've made an error somewhere else - // by allowing a format that is not supported. - assert(0); - - return NULL; // Shut up compiler warning -} - -//--------------------------------------------------------------------------- -// Copy* functions -//--------------------------------------------------------------------------- - -void gldCopyTexImage1D_DX8( - GLcontext *ctx, - GLenum target, GLint level, - GLenum internalFormat, - GLint x, GLint y, - GLsizei width, GLint border ) -{ - // TODO -} - -//--------------------------------------------------------------------------- - -void gldCopyTexImage2D_DX8( - GLcontext *ctx, - GLenum target, - GLint level, - GLenum internalFormat, - GLint x, - GLint y, - GLsizei width, - GLsizei height, - GLint border) -{ - // TODO -} - -//--------------------------------------------------------------------------- - -void gldCopyTexSubImage1D_DX8( - GLcontext *ctx, - GLenum target, GLint level, - GLint xoffset, GLint x, GLint y, GLsizei width ) -{ - // TODO -} - -//--------------------------------------------------------------------------- - -void gldCopyTexSubImage2D_DX8( - GLcontext *ctx, - GLenum target, - GLint level, - GLint xoffset, - GLint yoffset, - GLint x, - GLint y, - GLsizei width, - GLsizei height) -{ - // TODO -} - -//--------------------------------------------------------------------------- - -void gldCopyTexSubImage3D_DX8( - GLcontext *ctx, - GLenum target, - GLint level, - GLint xoffset, - GLint yoffset, - GLint zoffset, - GLint x, - GLint y, - GLsizei width, - GLsizei height ) -{ - // TODO ? -} - -//--------------------------------------------------------------------------- -// Bitmap/Pixel functions -//--------------------------------------------------------------------------- - -#define GLD_FLIP_Y(y) (gldCtx->dwHeight - (y)) - -#define _GLD_FVF_IMAGE (D3DFVF_XYZRHW | D3DFVF_TEX1) - -typedef struct { - FLOAT x, y; // 2D raster coords - FLOAT z; // depth value - FLOAT rhw; // reciprocal homogenous W (always 1.0f) - FLOAT tu, tv; // texture coords -} _GLD_IMAGE_VERTEX; - -//--------------------------------------------------------------------------- - -HRESULT _gldDrawPixels( - GLcontext *ctx, - BOOL bChromakey, // Alpha test for glBitmap() images - GLint x, // GL x position - GLint y, // GL y position (needs flipping) - GLsizei width, // Width of input image - GLsizei height, // Height of input image - IDirect3DSurface8 *pImage) -{ - // - // Draw input image as texture implementing PixelZoom and clipping. - // Any fragment operations currently enabled will be used. - // - - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - IDirect3DTexture8 *pTexture; - D3DSURFACE_DESC d3dsd; - IDirect3DSurface8 *pSurface; - _GLD_IMAGE_VERTEX v[4]; - HRESULT hr; - - float ZoomWidth, ZoomHeight; - float ScaleWidth, ScaleHeight; - - // Create a texture to hold image - hr = D3DXCreateTexture( - gld->pDev, - width, height, - 1, // miplevels - 0, // usage - D3DFMT_A8R8G8B8, // format - D3DPOOL_MANAGED, // pool - &pTexture); - if (FAILED(hr)) - return hr; - - hr = IDirect3DTexture8_GetSurfaceLevel(pTexture, 0, &pSurface); - if (FAILED(hr)) { - IDirect3DTexture8_Release(pTexture); - return hr; - } - - // Copy image into texture - hr = D3DXLoadSurfaceFromSurface( - pSurface, NULL, NULL, // Dest surface - pImage, NULL, NULL, // Src surface - D3DX_FILTER_NONE, - 0); - IDirect3DSurface8_Release(pSurface); - if (FAILED(hr)) { - IDirect3DTexture8_Release(pTexture); - return hr; - } - - // - // Set up the quad like this (ascii-art ahead!) - // - // 3--2 - // | | - // 0--1 - // - // - - // Set depth - v[0].z = v[1].z = v[2].z = v[3].z = ctx->Current.RasterPos[2]; - // Set Reciprocal Homogenous W - v[0].rhw = v[1].rhw = v[2].rhw = v[3].rhw = 1.0f; - - // Set texcoords - // Examine texture size - if different to input width and height - // then we'll need to munge the texcoords to fit. - IDirect3DTexture8_GetLevelDesc(pTexture, 0, &d3dsd); - ScaleWidth = (float)width / (float)d3dsd.Width; - ScaleHeight = (float)height / (float)d3dsd.Height; - v[0].tu = 0.0f; v[0].tv = 0.0f; - v[1].tu = ScaleWidth; v[1].tv = 0.0f; - v[2].tu = ScaleWidth; v[2].tv = ScaleHeight; - v[3].tu = 0.0f; v[3].tv = ScaleHeight; - - // Set raster positions - ZoomWidth = (float)width * ctx->Pixel.ZoomX; - ZoomHeight = (float)height * ctx->Pixel.ZoomY; - - v[0].x = x; v[0].y = GLD_FLIP_Y(y); - v[1].x = x+ZoomWidth; v[1].y = GLD_FLIP_Y(y); - v[2].x = x+ZoomWidth; v[2].y = GLD_FLIP_Y(y+ZoomHeight); - v[3].x = x; v[3].y = GLD_FLIP_Y(y+ZoomHeight); - - // Draw image with full HW acceleration - // NOTE: Be nice to use a State Block for all this state... - IDirect3DDevice8_SetTexture(gld->pDev, 0, pTexture); - IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_CULLMODE, D3DCULL_NONE); - IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_CLIPPING, TRUE); - IDirect3DDevice8_SetTextureStageState(gld->pDev, 0, D3DTSS_MINFILTER, D3DTEXF_POINT); - IDirect3DDevice8_SetTextureStageState(gld->pDev, 0, D3DTSS_MIPFILTER, D3DTEXF_POINT); - IDirect3DDevice8_SetTextureStageState(gld->pDev, 0, D3DTSS_MAGFILTER, D3DTEXF_POINT); - IDirect3DDevice8_SetTextureStageState(gld->pDev, 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); - IDirect3DDevice8_SetTextureStageState(gld->pDev, 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); - IDirect3DDevice8_SetTextureStageState(gld->pDev, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); - IDirect3DDevice8_SetTextureStageState(gld->pDev, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - IDirect3DDevice8_SetTextureStageState(gld->pDev, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - IDirect3DDevice8_SetTextureStageState(gld->pDev, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - IDirect3DDevice8_SetTextureStageState(gld->pDev, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); - IDirect3DDevice8_SetTextureStageState(gld->pDev, 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); - IDirect3DDevice8_SetVertexShader(gld->pDev, _GLD_FVF_IMAGE); - - // - // Emulate Chromakey with an Alpha Test. - // [Alpha Test is more widely supported anyway] - // - if (bChromakey) { - // Switch on alpha testing - IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_ALPHATESTENABLE, TRUE); - // Fragment passes is alpha is greater than reference value - IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_ALPHAFUNC, D3DCMP_GREATER); - // Set alpha reference value between Bitmap alpha values of - // zero (transparent) and one (opaque). - IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_ALPHAREF, 0x7f); - } - - IDirect3DDevice8_DrawPrimitiveUP(gld->pDev, D3DPT_TRIANGLEFAN, 2, &v, sizeof(_GLD_IMAGE_VERTEX)); - - // Release texture - IDirect3DDevice8_SetTexture(gld->pDev, 0, NULL); - IDirect3DTexture8_Release(pTexture); - - // Reset state to before we messed it up - FLUSH_VERTICES(ctx, _NEW_ALL); - - return S_OK; -} - -//--------------------------------------------------------------------------- - -void gld_DrawPixels_DX8( - GLcontext *ctx, - GLint x, GLint y, GLsizei width, GLsizei height, - GLenum format, GLenum type, - const struct gl_pixelstore_attrib *unpack, - const GLvoid *pixels ) -{ - GLD_context *gldCtx; - GLD_driver_dx8 *gld; - - IDirect3DSurface8 *pImage; - HRESULT hr; - D3DLOCKED_RECT d3dLockedRect; - - const struct gl_texture_format *MesaFormat; - - gldCtx = GLD_GET_CONTEXT(ctx); - gld = GLD_GET_DX8_DRIVER(gldCtx); - - hr = IDirect3DDevice8_CreateImageSurface( - gld->pDev, - width, - height, - D3DFMT_A8R8G8B8, - &pImage); - if (FAILED(hr)) { - return; - } - - // - // Use Mesa to fill in image - // - - // Lock all of surface - hr = IDirect3DSurface8_LockRect(pImage, &d3dLockedRect, NULL, 0); - if (FAILED(hr)) { - IDirect3DSurface8_Release(pImage); - return; - } - - MesaFormat = _mesa_choose_tex_format(ctx, format, format, type); - - // unpack image, apply transfer ops and store directly in texture - MesaFormat->StoreImage( - ctx, - 2, - GL_RGBA, - &_mesa_texformat_argb8888, - d3dLockedRect.pBits, - width, height, 1, 0, 0, 0, - d3dLockedRect.Pitch, - 0, /* dstImageStride */ - format, type, pixels, unpack); - - IDirect3DSurface8_UnlockRect(pImage); - - _gldDrawPixels(ctx, FALSE, x, y, width, height, pImage); - - IDirect3DSurface8_Release(pImage); -} - -//--------------------------------------------------------------------------- - -void gld_ReadPixels_DX8( - GLcontext *ctx, - GLint x, GLint y, GLsizei width, GLsizei height, - GLenum format, GLenum type, - const struct gl_pixelstore_attrib *pack, - GLvoid *dest) -{ - - GLD_context *gldCtx; - GLD_driver_dx8 *gld; - - IDirect3DSurface8 *pBackbuffer = NULL; - IDirect3DSurface8 *pNativeImage = NULL; - IDirect3DSurface8 *pCanonicalImage = NULL; - - D3DSURFACE_DESC d3dsd; - RECT rcSrc; // Source rect - POINT ptDst; // Dest point - HRESULT hr; - D3DLOCKED_RECT d3dLockedRect; - struct gl_pixelstore_attrib srcPacking; - int i; - GLint DstRowStride; - const struct gl_texture_format *MesaFormat; - - switch (format) { - case GL_STENCIL_INDEX: - case GL_DEPTH_COMPONENT: - return; - } - - MesaFormat = _mesa_choose_tex_format(ctx, format, format, type); - DstRowStride = _mesa_image_row_stride(pack, width, format, type); - - gldCtx = GLD_GET_CONTEXT(ctx); - gld = GLD_GET_DX8_DRIVER(gldCtx); - - // Get backbuffer - hr = IDirect3DDevice8_GetBackBuffer( - gld->pDev, - 0, // First backbuffer - D3DBACKBUFFER_TYPE_MONO, - &pBackbuffer); - if (FAILED(hr)) - return; - - // Get backbuffer description - hr = IDirect3DSurface8_GetDesc(pBackbuffer, &d3dsd); - if (FAILED(hr)) { - goto gld_ReadPixels_DX8_return; - } - - // Create a surface compatible with backbuffer - hr = IDirect3DDevice8_CreateImageSurface( - gld->pDev, - width, - height, - d3dsd.Format, - &pNativeImage); - if (FAILED(hr)) { - goto gld_ReadPixels_DX8_return; - } - - // Compute source rect and dest point - SetRect(&rcSrc, 0, 0, width, height); - OffsetRect(&rcSrc, x, GLD_FLIP_HEIGHT(y, height)); - ptDst.x = ptDst.y = 0; - - // Get source pixels. - // - // This intermediate surface ensure that we can use CopyRects() - // instead of relying on D3DXLoadSurfaceFromSurface(), which may - // try and lock the backbuffer. This way seems safer. - // - hr = IDirect3DDevice8_CopyRects( - gld->pDev, - pBackbuffer, - &rcSrc, - 1, - pNativeImage, - &ptDst); - if (FAILED(hr)) { - goto gld_ReadPixels_DX8_return; - } - - // Create an RGBA8888 surface - hr = IDirect3DDevice8_CreateImageSurface( - gld->pDev, - width, - height, - D3DFMT_A8R8G8B8, - &pCanonicalImage); - if (FAILED(hr)) { - goto gld_ReadPixels_DX8_return; - } - - // Convert to RGBA8888 - hr = D3DXLoadSurfaceFromSurface( - pCanonicalImage, // Dest surface - NULL, NULL, // Dest palette, RECT - pNativeImage, // Src surface - NULL, NULL, // Src palette, RECT - D3DX_FILTER_NONE, // Filter - 0); // Colourkey - if (FAILED(hr)) { - goto gld_ReadPixels_DX8_return; - } - - srcPacking.Alignment = 1; - srcPacking.ImageHeight = height; - srcPacking.LsbFirst = GL_FALSE; - srcPacking.RowLength = 0; - srcPacking.SkipImages = 0; - srcPacking.SkipPixels = 0; - srcPacking.SkipRows = 0; - srcPacking.SwapBytes = GL_FALSE; - - // Lock all of image - hr = IDirect3DSurface8_LockRect(pCanonicalImage, &d3dLockedRect, NULL, 0); - if (FAILED(hr)) { - goto gld_ReadPixels_DX8_return; - } - - // We need to flip the data. Yuck. - // Perhaps Mesa has a span packer we can use in future... - for (i=0; i<height; i++) { - BYTE *pDestRow = (BYTE*)_mesa_image_address(2,pack, dest, width, height, format, type, 0, i, 0); - BYTE *pSrcRow = (BYTE*)d3dLockedRect.pBits + (d3dLockedRect.Pitch * (height-i-1)); - MesaFormat->StoreImage( - ctx, - 2, - GL_RGBA, // base format - MesaFormat, // dst format - pDestRow, // dest addr - width, 1, 1, 0, 0, 0, // src x,y,z & dst offsets x,y,z - DstRowStride, // dst row stride - 0, // dstImageStride - GL_BGRA, // src format - GL_UNSIGNED_BYTE, // src type - pSrcRow, // src addr - &srcPacking); // packing params of source image - } - - IDirect3DSurface8_UnlockRect(pCanonicalImage); - -gld_ReadPixels_DX8_return: - SAFE_RELEASE_SURFACE8(pCanonicalImage); - SAFE_RELEASE_SURFACE8(pNativeImage); - SAFE_RELEASE_SURFACE8(pBackbuffer); -} - -//--------------------------------------------------------------------------- - -void gld_CopyPixels_DX8( - GLcontext *ctx, - GLint srcx, - GLint srcy, - GLsizei width, - GLsizei height, - GLint dstx, - GLint dsty, - GLenum type) -{ - // - // NOTE: Not allowed to copy vidmem to vidmem! - // Therefore we use an intermediate image surface. - // - - GLD_context *gldCtx; - GLD_driver_dx8 *gld; - - IDirect3DSurface8 *pBackbuffer; - D3DSURFACE_DESC d3dsd; - IDirect3DSurface8 *pImage; - RECT rcSrc; // Source rect - POINT ptDst; // Dest point - HRESULT hr; - - // Only backbuffer - if (type != GL_COLOR) - return; - - gldCtx = GLD_GET_CONTEXT(ctx); - gld = GLD_GET_DX8_DRIVER(gldCtx); - - // Get backbuffer - hr = IDirect3DDevice8_GetBackBuffer( - gld->pDev, - 0, // First backbuffer - D3DBACKBUFFER_TYPE_MONO, - &pBackbuffer); - if (FAILED(hr)) - return; - - // Get backbuffer description - hr = IDirect3DSurface8_GetDesc(pBackbuffer, &d3dsd); - if (FAILED(hr)) { - IDirect3DSurface8_Release(pBackbuffer); - return; - } - - // Create a surface compatible with backbuffer - hr = IDirect3DDevice8_CreateImageSurface( - gld->pDev, - width, - height, - d3dsd.Format, - &pImage); - if (FAILED(hr)) { - IDirect3DSurface8_Release(pBackbuffer); - return; - } - - // Compute source rect and dest point - SetRect(&rcSrc, 0, 0, width, height); - OffsetRect(&rcSrc, srcx, GLD_FLIP_HEIGHT(srcy, height)); - ptDst.x = ptDst.y = 0; - - // Get source pixels - hr = IDirect3DDevice8_CopyRects( - gld->pDev, - pBackbuffer, - &rcSrc, - 1, - pImage, - &ptDst); - IDirect3DSurface8_Release(pBackbuffer); - if (FAILED(hr)) { - IDirect3DSurface8_Release(pImage); - return; - } - - _gldDrawPixels(ctx, FALSE, dstx, dsty, width, height, pImage); - - IDirect3DSurface8_Release(pImage); -} - -//--------------------------------------------------------------------------- - -void gld_Bitmap_DX8( - GLcontext *ctx, - GLint x, - GLint y, - GLsizei width, - GLsizei height, - const struct gl_pixelstore_attrib *unpack, - const GLubyte *bitmap) -{ - GLD_context *gldCtx; - GLD_driver_dx8 *gld; - - IDirect3DSurface8 *pImage; - HRESULT hr; - D3DLOCKED_RECT d3dLockedRect; - BYTE *pTempBitmap; - D3DCOLOR clBitmapOne, clBitmapZero; - D3DCOLOR *pBits; - const GLubyte *src; - int i, j, k; - - gldCtx = GLD_GET_CONTEXT(ctx); - gld = GLD_GET_DX8_DRIVER(gldCtx); - - clBitmapZero = D3DCOLOR_RGBA(0,0,0,0); // NOTE: Alpha is Zero - clBitmapOne = D3DCOLOR_COLORVALUE( - ctx->Current.RasterColor[0], - ctx->Current.RasterColor[1], - ctx->Current.RasterColor[2], - 1.0f); // NOTE: Alpha is One - - hr = IDirect3DDevice8_CreateImageSurface( - gld->pDev, - width, - height, - D3DFMT_A8R8G8B8, - &pImage); - if (FAILED(hr)) { - return; - } - - // Lock all of surface - hr = IDirect3DSurface8_LockRect(pImage, &d3dLockedRect, NULL, 0); - if (FAILED(hr)) { - IDirect3DSurface8_Release(pImage); - return; - } - - pTempBitmap = _mesa_unpack_bitmap(width, height, bitmap, unpack); - if (pTempBitmap == NULL) { - IDirect3DSurface8_Release(pImage); - return; - } - - pBits = (D3DCOLOR*)d3dLockedRect.pBits; - - for (i=0; i<height; i++) { - GLubyte byte; - pBits = (D3DCOLOR*)((BYTE*)d3dLockedRect.pBits + (i*d3dLockedRect.Pitch)); - src = (const GLubyte *) _mesa_image_address(2, - &ctx->DefaultPacking, pTempBitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, - 0, i, 0); - for (j=0; j<(width>>3); j++) { - byte = *src++; - for (k=0; k<8; k++) { - *pBits++ = (byte & 128) ? clBitmapOne : clBitmapZero; - byte <<= 1; - } - } - // Fill remaining bits from bitmap - if (width & 7) { - byte = *src; - for (k=0; k<(width & 7); k++) { - *pBits++ = (byte & 128) ? clBitmapOne : clBitmapZero; - byte <<= 1; - } - } - } - - FREE(pTempBitmap); - -/* - // unpack image, apply transfer ops and store directly in texture - texImage->TexFormat->StoreImage( - ctx, - 2, - GL_BITMAP, - &_mesa_texformat_argb8888, - d3dLockedRect.pBits, - width, height, 1, 0, 0, 0, - d3dLockedRect.Pitch, - 0, // dstImageStride - GL_BITMAP, GL_COLOR_INDEX, bitmap, unpack); -*/ - IDirect3DSurface8_UnlockRect(pImage); - - _gldDrawPixels(ctx, TRUE, x, y, width, height, pImage); - - IDirect3DSurface8_Release(pImage); -} - -//--------------------------------------------------------------------------- -// Texture functions -//--------------------------------------------------------------------------- - -void _gldAllocateTexture( - GLcontext *ctx, - struct gl_texture_object *tObj, - struct gl_texture_image *texImage) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - IDirect3DTexture8 *pTex; - D3DFORMAT d3dFormat; - - if (!tObj || !texImage) - return; - - pTex = (IDirect3DTexture8*)tObj->DriverData; - if (pTex) { - // Decide whether we can keep existing D3D texture - // by examining top-level surface. - D3DSURFACE_DESC d3dsd; - _GLD_DX8_TEX(GetLevelDesc(pTex, 0, &d3dsd)); - // Release existing texture if not compatible - if ((d3dsd.Width == texImage->Width) || - (d3dsd.Height == texImage->Height)) - { - return; // Keep the existing texture - } - tObj->DriverData = NULL; - _GLD_DX8_TEX(Release(pTex)); - } - - d3dFormat = _gldGLFormatToD3DFormat(texImage->IntFormat); - D3DXCreateTexture( - gld->pDev, - texImage->Width, - texImage->Height, - // TODO: Re-evaluate mipmapping - (glb.bUseMipmaps) ? D3DX_DEFAULT : 1, - 0, // Usage - d3dFormat, - D3DPOOL_MANAGED, - &pTex); - tObj->DriverData = pTex; -} - -//--------------------------------------------------------------------------- - -const struct gl_texture_format* gld_ChooseTextureFormat_DX8( - GLcontext *ctx, - GLint internalFormat, - GLenum srcFormat, - GLenum srcType) -{ - // [Based on mesa_choose_tex_format()] - // - // We will choose only texture formats that are supported - // by Direct3D. If the hardware doesn't support a particular - // texture format, then the D3DX texture calls that we use - // will automatically use a HW supported format. - // - // The most critical aim is to reduce copying; if we can use - // texture-image data directly then it will be a big performance assist. - // - - switch (internalFormat) { - case GL_INTENSITY: - case GL_INTENSITY4: - case GL_INTENSITY8: - case GL_INTENSITY12: - case GL_INTENSITY16: - return &_mesa_texformat_l8; // D3DFMT_L8 - case 1: - case GL_LUMINANCE: - case GL_LUMINANCE4: - case GL_LUMINANCE8: - case GL_LUMINANCE12: - case GL_LUMINANCE16: - return &_mesa_texformat_l8; // D3DFMT_L8 - case GL_ALPHA: - case GL_ALPHA4: - case GL_ALPHA8: - case GL_ALPHA12: - case GL_ALPHA16: - return &_mesa_texformat_a8; // D3DFMT_A8 - case GL_COLOR_INDEX: - case GL_COLOR_INDEX1_EXT: - case GL_COLOR_INDEX2_EXT: - case GL_COLOR_INDEX4_EXT: - case GL_COLOR_INDEX8_EXT: - case GL_COLOR_INDEX12_EXT: - case GL_COLOR_INDEX16_EXT: - return &_mesa_texformat_rgb565; // D3DFMT_R5G6B5 - // Mesa will convert this for us later... - // return &_mesa_texformat_ci8; // D3DFMT_R5G6B5 - case 2: - case GL_LUMINANCE_ALPHA: - case GL_LUMINANCE4_ALPHA4: - case GL_LUMINANCE6_ALPHA2: - case GL_LUMINANCE8_ALPHA8: - case GL_LUMINANCE12_ALPHA4: - case GL_LUMINANCE12_ALPHA12: - case GL_LUMINANCE16_ALPHA16: - return &_mesa_texformat_al88; // D3DFMT_A8L8 - case GL_R3_G3_B2: - return &_mesa_texformat_rgb332; // D3DFMT_R3G3B2 - case GL_RGB4: - case GL_RGBA4: - case GL_RGBA2: - return &_mesa_texformat_argb4444; // D3DFMT_A4R4G4B4 - case 3: - case GL_RGB: - case GL_RGB5: - case GL_RGB8: - case GL_RGB10: - case GL_RGB12: - case GL_RGB16: - return &_mesa_texformat_rgb565; - case 4: - case GL_RGBA: - case GL_RGBA8: - case GL_RGB10_A2: - case GL_RGBA12: - case GL_RGBA16: - return &_mesa_texformat_argb8888; - case GL_RGB5_A1: - return &_mesa_texformat_argb1555; - default: - _mesa_problem(NULL, "unexpected format in fxDDChooseTextureFormat"); - return NULL; - } -} - -//--------------------------------------------------------------------------- - -/* -// Safer(?), slower version. -void gld_TexImage2D_DX8( - GLcontext *ctx, - GLenum target, - GLint level, - GLint internalFormat, - GLint width, - GLint height, - GLint border, - GLenum format, - GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *tObj, - struct gl_texture_image *texImage) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - IDirect3DTexture8 *pTex; - IDirect3DSurface8 *pSurface; - RECT rcSrcRect; - HRESULT hr; - GLint texelBytes = 4; - GLvoid *tempImage; - - if (!tObj || !texImage) - return; - - if (level == 0) { - _gldAllocateTexture(ctx, tObj, texImage); - } - - pTex = (IDirect3DTexture8*)tObj->DriverData; - if (!pTex) - return; // Texture has not been created - if (level >= IDirect3DTexture8_GetLevelCount(pTex)) - return; // Level does not exist - hr = IDirect3DTexture8_GetSurfaceLevel(pTex, level, &pSurface); - if (FAILED(hr)) - return; // Surface level doesn't exist (or just a plain error) - - tempImage = MALLOC(width * height * texelBytes); - if (!tempImage) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); - IDirect3DSurface8_Release(pSurface); - return; - } - // unpack image, apply transfer ops and store in tempImage - texImage->TexFormat->StoreImage(ctx, 2, texImage->Format, - &_mesa_texformat_argb8888, // dest format - tempImage, - width, height, 1, 0, 0, 0, - width * texelBytes, - 0, // dstImageStride - format, type, pixels, packing); - - SetRect(&rcSrcRect, 0, 0, width, height); - D3DXLoadSurfaceFromMemory( - pSurface, - NULL, - NULL, - tempImage, - D3DFMT_A8R8G8B8, - width * texelBytes, - NULL, - &rcSrcRect, - D3DX_FILTER_NONE, - 0); - - FREE(tempImage); - IDirect3DSurface8_Release(pSurface); -} -*/ - -//--------------------------------------------------------------------------- - -// Faster, more efficient version. -// Copies subimage straight to dest texture -void gld_TexImage2D_DX8( - GLcontext *ctx, - GLenum target, - GLint level, - GLint internalFormat, - GLint width, - GLint height, - GLint border, - GLenum format, - GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *tObj, - struct gl_texture_image *texImage) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - IDirect3DTexture8 *pTex; - IDirect3DSurface8 *pSurface; - HRESULT hr; - D3DLOCKED_RECT d3dLockedRect; - D3DSURFACE_DESC d3dsd; - - if (!tObj || !texImage) - return; - - // GLQUAKE FIX - // Test for input alpha data with non-alpha internalformat - if (((internalFormat==3) || (internalFormat==GL_RGB)) && (format==GL_RGBA)) { - // Input format has alpha, but a non-alpha format has been requested. - texImage->IntFormat = GL_RGBA; - internalFormat = GL_RGBA; - } - - if (level == 0) { - _gldAllocateTexture(ctx, tObj, texImage); - } - - pTex = (IDirect3DTexture8*)tObj->DriverData; - if (!pTex) - return; // Texture has not been created - if (level >= IDirect3DTexture8_GetLevelCount(pTex)) - return; // Level does not exist - hr = IDirect3DTexture8_GetSurfaceLevel(pTex, level, &pSurface); - if (FAILED(hr)) - return; // Surface level doesn't exist (or just a plain error) - - IDirect3DSurface8_GetDesc(pSurface, &d3dsd); - - // Lock all of surface - hr = IDirect3DSurface8_LockRect(pSurface, &d3dLockedRect, NULL, 0); - if (FAILED(hr)) { - IDirect3DSurface8_Release(pSurface); - return; - } - - // unpack image, apply transfer ops and store directly in texture - texImage->TexFormat->StoreImage( - ctx, - 2, - texImage->Format, - _gldMesaFormatForD3DFormat(d3dsd.Format), - d3dLockedRect.pBits, - width, height, 1, 0, 0, 0, - d3dLockedRect.Pitch, - 0, // dstImageStride - format, type, pixels, packing); - - IDirect3DSurface8_UnlockRect(pSurface); - IDirect3DSurface8_Release(pSurface); -} - -//--------------------------------------------------------------------------- - -void gld_TexImage1D_DX8(GLcontext *ctx, GLenum target, GLint level, - GLint internalFormat, - GLint width, GLint border, - GLenum format, GLenum type, const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage ) -{ - // A 1D texture is a 2D texture with a height of zero - gld_TexImage2D_DX8(ctx, target, level, internalFormat, width, 1, border, format, type, pixels, packing, texObj, texImage); -} - -//--------------------------------------------------------------------------- - -/* -void gld_TexSubImage2D( GLcontext *ctx, GLenum target, GLint level, - GLint xoffset, GLint yoffset, - GLsizei width, GLsizei height, - GLenum format, GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *tObj, - struct gl_texture_image *texImage ) -{ - GLD_GET_CONTEXT - IDirect3DTexture8 *pTex; - IDirect3DSurface8 *pSurface; - D3DFORMAT d3dFormat; - HRESULT hr; - GLint texelBytes = 4; - GLvoid *tempImage; - RECT rcSrcRect; - RECT rcDstRect; - - if (!tObj || !texImage) - return; - - pTex = (IDirect3DTexture8*)tObj->DriverData; - if (!pTex) - return; // Texture has not been created - if (level >= _GLD_DX8_TEX(GetLevelCount(pTex)) - return; // Level does not exist - hr = _GLD_DX8_TEX(GetSurfaceLevel(pTex, level, &pSurface); - if (FAILED(hr)) - return; // Surface level doesn't exist (or just a plain error) - - d3dFormat = _gldGLFormatToD3DFormat(texImage->Format); - tempImage = MALLOC(width * height * texelBytes); - if (!tempImage) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); - IDirect3DSurface8_Release(pSurface); - return; - } - - // unpack image, apply transfer ops and store in tempImage - texImage->TexFormat->StoreImage(ctx, 2, texImage->Format, - &_mesa_texformat_argb8888, // dest format - tempImage, - width, height, 1, 0, 0, 0, - width * texelBytes, - 0, // dstImageStride - format, type, pixels, packing); - - // Source rectangle is whole of input image - SetRect(&rcSrcRect, 0, 0, width, height); - - // Dest rectangle must be offset to dest image - SetRect(&rcDstRect, 0, 0, width, height); - OffsetRect(&rcDstRect, xoffset, yoffset); - - D3DXLoadSurfaceFromMemory( - pSurface, - NULL, - &rcDstRect, - tempImage, - D3DFMT_A8R8G8B8, - width * texelBytes, - NULL, - &rcSrcRect, - D3DX_FILTER_NONE, - 0); - - FREE(tempImage); - IDirect3DSurface8_Release(pSurface); -} -*/ - -//--------------------------------------------------------------------------- - -// Faster, more efficient version. -// Copies subimage straight to dest texture -void gld_TexSubImage2D_DX8( GLcontext *ctx, GLenum target, GLint level, - GLint xoffset, GLint yoffset, - GLsizei width, GLsizei height, - GLenum format, GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *tObj, - struct gl_texture_image *texImage ) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - IDirect3DTexture8 *pTex; - IDirect3DSurface8 *pSurface; - HRESULT hr; - RECT rcDstRect; - D3DLOCKED_RECT d3dLockedRect; - D3DSURFACE_DESC d3dsd; - - if (!tObj || !texImage) - return; - - pTex = (IDirect3DTexture8*)tObj->DriverData; - if (!pTex) - return; // Texture has not been created - if (level >= IDirect3DTexture8_GetLevelCount(pTex)) - return; // Level does not exist - hr = IDirect3DTexture8_GetSurfaceLevel(pTex, level, &pSurface); - if (FAILED(hr)) - return; // Surface level doesn't exist (or just a plain error) - - IDirect3DSurface8_GetDesc(pSurface, &d3dsd); - - // Dest rectangle must be offset to dest image - SetRect(&rcDstRect, 0, 0, width, height); - OffsetRect(&rcDstRect, xoffset, yoffset); - - // Lock sub-rect of surface - hr = IDirect3DSurface8_LockRect(pSurface, &d3dLockedRect, &rcDstRect, 0); - if (FAILED(hr)) { - IDirect3DSurface8_Release(pSurface); - return; - } - - // unpack image, apply transfer ops and store directly in texture - texImage->TexFormat->StoreImage(ctx, 2, texImage->Format, - _gldMesaFormatForD3DFormat(d3dsd.Format), - d3dLockedRect.pBits, - width, height, 1, - 0, 0, 0, // NOTE: d3dLockedRect.pBits is already offset!!! - d3dLockedRect.Pitch, - 0, // dstImageStride - format, type, pixels, packing); - - - IDirect3DSurface8_UnlockRect(pSurface); - IDirect3DSurface8_Release(pSurface); -} - -//--------------------------------------------------------------------------- - -void gld_TexSubImage1D_DX8( GLcontext *ctx, GLenum target, GLint level, - GLint xoffset, GLsizei width, - GLenum format, GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage ) -{ - gld_TexSubImage2D_DX8(ctx, target, level, xoffset, 0, width, 1, format, type, pixels, packing, texObj, texImage); -} - -//--------------------------------------------------------------------------- - -void gld_DeleteTexture_DX8( - GLcontext *ctx, - struct gl_texture_object *tObj) -{ - GLD_context *gld = (GLD_context*)(ctx->DriverCtx); - - if (tObj) { - IDirect3DTexture8 *pTex = (IDirect3DTexture8*)tObj->DriverData; - if (pTex) { -/* // Make sure texture is not bound to a stage before releasing it - for (int i=0; i<MAX_TEXTURE_UNITS; i++) { - if (gld->CurrentTexture[i] == pTex) { - gld->pDev->SetTexture(i, NULL); - gld->CurrentTexture[i] = NULL; - } - }*/ - _GLD_DX8_TEX(Release(pTex)); - tObj->DriverData = NULL; - } - } -} - -//--------------------------------------------------------------------------- - -__inline void _gldSetColorOps( - const GLD_driver_dx8 *gld, - GLuint unit, - DWORD ColorArg1, - D3DTEXTUREOP ColorOp, - DWORD ColorArg2) -{ - _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLORARG1, ColorArg1)); - _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLOROP, ColorOp)); - _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLORARG2, ColorArg2)); -} - -//--------------------------------------------------------------------------- - -__inline void _gldSetAlphaOps( - const GLD_driver_dx8 *gld, - GLuint unit, - DWORD AlphaArg1, - D3DTEXTUREOP AlphaOp, - DWORD AlphaArg2) -{ - _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ALPHAARG1, AlphaArg1)); - _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ALPHAOP, AlphaOp)); - _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ALPHAARG2, AlphaArg2)); -} - -//--------------------------------------------------------------------------- - -void gldUpdateTextureUnit( - GLcontext *ctx, - GLuint unit, - BOOL bPassThrough) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - D3DTEXTUREFILTERTYPE minfilter; - D3DTEXTUREFILTERTYPE mipfilter; - GLenum BaseFormat; - DWORD dwColorArg0; - int iTexEnv = 0; - GLD_texenv *pTexenv; - - // NOTE: If bPassThrough is FALSE then texture stage can be - // disabled otherwise it must pass-through it's current fragment. - - const struct gl_texture_unit *pUnit = &ctx->Texture.Unit[unit]; - const struct gl_texture_object *tObj = pUnit->_Current; - - IDirect3DTexture8 *pTex = NULL; - if (tObj) { - pTex = (IDirect3DTexture8*)tObj->DriverData; - } - - // Enable texturing if unit is enabled and a valid D3D texture exists - // Mesa 5: TEXTUREn_x altered to TEXTURE_nD_BIT - //if (pTex && (pUnit->Enabled & (TEXTURE0_1D | TEXTURE0_2D))) { - if (pTex && (pUnit->_ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT))) { - // Enable texturing - _GLD_DX8_DEV(SetTexture(gld->pDev, unit, pTex)); - } else { - // Disable texturing, then return - _GLD_DX8_DEV(SetTexture(gld->pDev, unit, NULL)); - if (bPassThrough) { - _gldSetColorOps(gld, unit, D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_DIFFUSE); - _gldSetAlphaOps(gld, unit, D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_DIFFUSE); - } else { - _gldSetColorOps(gld, unit, D3DTA_TEXTURE, D3DTOP_DISABLE, D3DTA_DIFFUSE); - _gldSetAlphaOps(gld, unit, D3DTA_TEXTURE, D3DTOP_DISABLE, D3DTA_DIFFUSE); - } - return; - } - - // Texture parameters - _gldConvertMinFilter(tObj->MinFilter, &minfilter, &mipfilter); - _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_MINFILTER, minfilter)); - _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_MIPFILTER, mipfilter)); - _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_MAGFILTER, _gldConvertMagFilter(tObj->MagFilter))); - _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ADDRESSU, _gldConvertWrap(tObj->WrapS))); - _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ADDRESSV, _gldConvertWrap(tObj->WrapT))); - - // Texture priority - _GLD_DX8_TEX(SetPriority(pTex, (DWORD)(tObj->Priority*65535.0f))); - - // Texture environment - // TODO: Examine input texture for alpha and use specific alpha/non-alpha ops. - // See Page 355 of the Red Book. - BaseFormat = _gldDecodeBaseFormat(pTex); - - switch (BaseFormat) { - case GL_RGB: - iTexEnv = 0; - break; - case GL_RGBA: - iTexEnv = 1; - break; - case GL_ALPHA: - iTexEnv = 2; - break; - } - - switch (pUnit->EnvMode) { - case GL_DECAL: - iTexEnv += 0; - break; - case GL_REPLACE: - iTexEnv += 3; - break; - case GL_MODULATE: - iTexEnv += 6; - break; - case GL_BLEND: - // Set blend colour - dwColorArg0 = D3DCOLOR_COLORVALUE(pUnit->EnvColor[0], pUnit->EnvColor[1], pUnit->EnvColor[2], pUnit->EnvColor[3]); - _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLORARG0, dwColorArg0)); - iTexEnv += 9; - break; - case GL_ADD: - iTexEnv += 12; - break; - } - pTexenv = (GLD_texenv*)&gldTexEnv[iTexEnv]; - _gldSetColorOps(gld, unit, pTexenv->ColorArg1, pTexenv->ColorOp, pTexenv->ColorArg2); - _gldSetAlphaOps(gld, unit, pTexenv->AlphaArg1, pTexenv->AlphaOp, pTexenv->AlphaArg2); -} - -//--------------------------------------------------------------------------- - -void gld_NEW_TEXTURE_DX8( - GLcontext *ctx) -{ - // TODO: Support for three (ATI Radeon) or more (nVidia GeForce3) texture units - - BOOL bUnit0Enabled; - BOOL bUnit1Enabled; - - if (!ctx) - return; // Sanity check - - if (ctx->Const.MaxTextureUnits == 1) { - gldUpdateTextureUnit(ctx, 0, TRUE); - return; - } - - // - // NOTE: THE FOLLOWING RELATES TO TWO TEXTURE UNITS, AND TWO ONLY!! - // - - // Mesa 5: Texture Units altered - //bUnit0Enabled = (ctx->Texture._ReallyEnabled & (TEXTURE0_1D | TEXTURE0_2D)) ? TRUE : FALSE; - //bUnit1Enabled = (ctx->Texture._ReallyEnabled & (TEXTURE1_1D | TEXTURE1_2D)) ? TRUE : FALSE; - bUnit0Enabled = (ctx->Texture.Unit[0]._ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT)) ? TRUE : FALSE; - bUnit1Enabled = (ctx->Texture.Unit[1]._ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT)) ? TRUE : FALSE; - - // If Unit0 is disabled and Unit1 is enabled then we must pass-though - gldUpdateTextureUnit(ctx, 0, (!bUnit0Enabled && bUnit1Enabled) ? TRUE : FALSE); - // We can always disable the last texture unit - gldUpdateTextureUnit(ctx, 1, FALSE); - -#ifdef _DEBUG - { - // Find out whether device supports current renderstates - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); -// GLD_context *gld = GLD_GET_CONTEXT(ctx); - - DWORD dwPasses; - _GLD_DX8_DEV(ValidateDevice(gld->pDev, &dwPasses)); -// if (FAILED(hr)) { -// gldLogError(GLDLOG_ERROR, "ValidateDevice failed", hr); -// } - if (dwPasses != 1) { - gldLogMessage(GLDLOG_ERROR, "ValidateDevice: Can't do in one pass\n"); - } - } -#endif -}; - -//--------------------------------------------------------------------------- diff --git a/src/mesa/drivers/windows/gldirect/dx8/gld_vb_d3d_render_dx8.c b/src/mesa/drivers/windows/gldirect/dx8/gld_vb_d3d_render_dx8.c deleted file mode 100644 index cafbf4f5c5..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx8/gld_vb_d3d_render_dx8.c +++ /dev/null @@ -1,249 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: GLDirect fastpath pipeline stage -* -****************************************************************************/ - -//--------------------------------------------------------------------------- - -//#include "../GLDirect.h" -//#include "../gld_log.h" -//#include "gld_dx8.h" - -#include "dglcontext.h" -#include "ddlog.h" -#include "gld_dx8.h" - -//--------------------------------------------------------------------------- - -#include "glheader.h" -#include "context.h" -#include "macros.h" -// #include "mem.h" -#include "mtypes.h" -//#include "mmath.h" - -#include "math/m_matrix.h" -#include "math/m_xform.h" - -#include "tnl/t_pipeline.h" - -//--------------------------------------------------------------------------- - -__inline void _gldSetVertexShaderConstants( - GLcontext *ctx, - GLD_driver_dx8 *gld) -{ - D3DXMATRIX mat, matView, matProj; - GLfloat *pM; - - // Mesa 5: Altered to a Stack - //pM = ctx->ModelView.m; - pM = ctx->ModelviewMatrixStack.Top->m; - matView._11 = pM[0]; - matView._12 = pM[1]; - matView._13 = pM[2]; - matView._14 = pM[3]; - matView._21 = pM[4]; - matView._22 = pM[5]; - matView._23 = pM[6]; - matView._24 = pM[7]; - matView._31 = pM[8]; - matView._32 = pM[9]; - matView._33 = pM[10]; - matView._34 = pM[11]; - matView._41 = pM[12]; - matView._42 = pM[13]; - matView._43 = pM[14]; - matView._44 = pM[15]; - - // Mesa 5: Altered to a Stack - //pM = ctx->ProjectionMatrix.m; - pM = ctx->ProjectionMatrixStack.Top->m; - matProj._11 = pM[0]; - matProj._12 = pM[1]; - matProj._13 = pM[2]; - matProj._14 = pM[3]; - matProj._21 = pM[4]; - matProj._22 = pM[5]; - matProj._23 = pM[6]; - matProj._24 = pM[7]; - matProj._31 = pM[8]; - matProj._32 = pM[9]; - matProj._33 = pM[10]; - matProj._34 = pM[11]; - matProj._41 = pM[12]; - matProj._42 = pM[13]; - matProj._43 = pM[14]; - matProj._44 = pM[15]; - - D3DXMatrixMultiply( &mat, &matView, &matProj ); - D3DXMatrixTranspose( &mat, &mat ); - - _GLD_DX8_DEV(SetVertexShaderConstant(gld->pDev, 0, &mat, 4)); -} - -//--------------------------------------------------------------------------- - -static GLboolean gld_d3d_render_stage_run( - GLcontext *ctx, - struct tnl_pipeline_stage *stage) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - TNLcontext *tnl; - struct vertex_buffer *VB; - tnl_render_func *tab; - GLint pass; - GLD_pb_dx8 *gldPB = &gld->PB3d; -/* - static int count = 0; - count++; - if (count != 2) - return GL_FALSE; -*/ - // The "check" function should disable this stage, - // but we'll test gld->bUseMesaTnL anyway. - if (gld->bUseMesaTnL) { - // Do nothing in this stage, but continue pipeline - return GL_TRUE; - } - - tnl = TNL_CONTEXT(ctx); - VB = &tnl->vb; - pass = 0; - - tnl->Driver.Render.Start( ctx ); - -#if 0 - // For debugging: Useful to see if an app passes colour data in - // an unusual format. - switch (VB->ColorPtr[0]->Type) { - case GL_FLOAT: - ddlogMessage(GLDLOG_SYSTEM, "ColorPtr: GL_FLOAT\n"); - break; - case GL_UNSIGNED_BYTE: - ddlogMessage(GLDLOG_SYSTEM, "ColorPtr: GL_UNSIGNED_BYTE\n"); - break; - default: - ddlogMessage(GLDLOG_SYSTEM, "ColorPtr: *?*\n"); - break; - } -#endif - - tnl->Driver.Render.Points = gld_Points3D_DX8; - if (ctx->_TriangleCaps & DD_FLATSHADE) { - tnl->Driver.Render.Line = gld_Line3DFlat_DX8; - tnl->Driver.Render.Triangle = gld_Triangle3DFlat_DX8; - tnl->Driver.Render.Quad = gld_Quad3DFlat_DX8; - } else { - tnl->Driver.Render.Line = gld_Line3DSmooth_DX8; - tnl->Driver.Render.Triangle = gld_Triangle3DSmooth_DX8; - tnl->Driver.Render.Quad = gld_Quad3DSmooth_DX8; - } - - _GLD_DX8_VB(Lock(gldPB->pVB, 0, 0, &gldPB->pPoints, D3DLOCK_DISCARD)); - gldPB->nPoints = gldPB->nLines = gldPB->nTriangles = 0; - // Allocate primitive pointers - // gldPB->pPoints is always first - gldPB->pLines = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstLine); - gldPB->pTriangles = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstTriangle); - - ASSERT(tnl->Driver.Render.BuildVertices); - ASSERT(tnl->Driver.Render.PrimitiveNotify); - ASSERT(tnl->Driver.Render.Points); - ASSERT(tnl->Driver.Render.Line); - ASSERT(tnl->Driver.Render.Triangle); - ASSERT(tnl->Driver.Render.Quad); - ASSERT(tnl->Driver.Render.ResetLineStipple); - ASSERT(tnl->Driver.Render.Interp); - ASSERT(tnl->Driver.Render.CopyPV); - ASSERT(tnl->Driver.Render.ClippedLine); - ASSERT(tnl->Driver.Render.ClippedPolygon); - ASSERT(tnl->Driver.Render.Finish); - - tab = (VB->Elts ? tnl->Driver.Render.PrimTabElts : tnl->Driver.Render.PrimTabVerts); - - do { - GLuint i, length, flags = 0; - for (i = 0 ; !(flags & PRIM_END) ; i += length) - { - flags = VB->Primitive[i].mode; - length= VB->Primitive[i].count; - ASSERT(length || (flags & PRIM_END)); - ASSERT((flags & PRIM_MODE_MASK) <= GL_POLYGON+1); - if (length) - tab[flags & PRIM_MODE_MASK]( ctx, i, i + length, flags ); - } - } while (tnl->Driver.Render.Multipass && - tnl->Driver.Render.Multipass( ctx, ++pass )); - - _GLD_DX8_VB(Unlock(gldPB->pVB)); - - _GLD_DX8_DEV(SetStreamSource(gld->pDev, 0, gldPB->pVB, gldPB->dwStride)); - - _GLD_DX8_DEV(SetTransform(gld->pDev, D3DTS_PROJECTION, &gld->matProjection)); - _GLD_DX8_DEV(SetTransform(gld->pDev, D3DTS_WORLD, &gld->matModelView)); - - if (gldPB->nPoints) { - _GLD_DX8_DEV(DrawPrimitive(gld->pDev, D3DPT_POINTLIST, 0, gldPB->nPoints)); - gldPB->nPoints = 0; - } - - if (gldPB->nLines) { - _GLD_DX8_DEV(DrawPrimitive(gld->pDev, D3DPT_LINELIST, gldPB->iFirstLine, gldPB->nLines)); - gldPB->nLines = 0; - } - - if (gldPB->nTriangles) { - _GLD_DX8_DEV(DrawPrimitive(gld->pDev, D3DPT_TRIANGLELIST, gldPB->iFirstTriangle, gldPB->nTriangles)); - gldPB->nTriangles = 0; - } - - return GL_FALSE; /* finished the pipe */ -} - -//--------------------------------------------------------------------------- - -const struct tnl_pipeline_stage _gld_d3d_render_stage = -{ - "gld_d3d_render_stage", - NULL, - NULL, - NULL, - NULL, - gld_d3d_render_stage_run /* run */ -}; - -//--------------------------------------------------------------------------- diff --git a/src/mesa/drivers/windows/gldirect/dx8/gld_vb_mesa_render_dx8.c b/src/mesa/drivers/windows/gldirect/dx8/gld_vb_mesa_render_dx8.c deleted file mode 100644 index 9ab562010c..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx8/gld_vb_mesa_render_dx8.c +++ /dev/null @@ -1,448 +0,0 @@ - -/* - * Mesa 3-D graphics library - * Version: 3.5 - * - * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Authors: - * Keith Whitwell <keithw@valinux.com> - */ - - -/* - * Render whole vertex buffers, including projection of vertices from - * clip space and clipping of primitives. - * - * This file makes calls to project vertices and to the point, line - * and triangle rasterizers via the function pointers: - * - * context->Driver.Render.* - * - */ - - -//--------------------------------------------------------------------------- - -//#include "../GLDirect.h" -//#include "../gld_log.h" -//#include "gld_dx8.h" - -#include "dglcontext.h" -#include "ddlog.h" -#include "gld_dx8.h" - -//--------------------------------------------------------------------------- - -#include "glheader.h" -#include "context.h" -#include "macros.h" -// #include "mem.h" -#include "mtypes.h" -//#include "mmath.h" - -#include "math/m_matrix.h" -#include "math/m_xform.h" - -#include "tnl/t_pipeline.h" - -/**********************************************************************/ -/* Clip single primitives */ -/**********************************************************************/ - - -#if defined(USE_IEEE) -#define NEGATIVE(x) (GET_FLOAT_BITS(x) & (1<<31)) -//#define DIFFERENT_SIGNS(x,y) ((GET_FLOAT_BITS(x) ^ GET_FLOAT_BITS(y)) & (1<<31)) -#else -#define NEGATIVE(x) (x < 0) -//#define DIFFERENT_SIGNS(x,y) (x * y <= 0 && x - y != 0) -/* Could just use (x*y<0) except for the flatshading requirements. - * Maybe there's a better way? - */ -#endif - - -#define W(i) coord[i][3] -#define Z(i) coord[i][2] -#define Y(i) coord[i][1] -#define X(i) coord[i][0] -#define SIZE 4 -#define TAG(x) x##_4 -#include "tnl/t_vb_cliptmp.h" - - - -/**********************************************************************/ -/* Clip and render whole begin/end objects */ -/**********************************************************************/ - -#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED) -#define EDGEFLAG_GET(idx) VB->EdgeFlag[idx] -#define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val - - -/* Vertices, with the possibility of clipping. - */ -#define RENDER_POINTS( start, count ) \ - tnl->Driver.Render.Points( ctx, start, count ) - -#define RENDER_LINE( v1, v2 ) \ -do { \ - GLubyte c1 = mask[v1], c2 = mask[v2]; \ - GLubyte ormask = c1|c2; \ - if (!ormask) \ - LineFunc( ctx, v1, v2 ); \ - else if (!(c1 & c2 & 0x3f)) \ - clip_line_4( ctx, v1, v2, ormask ); \ -} while (0) - -#define RENDER_TRI( v1, v2, v3 ) \ -do { \ - GLubyte c1 = mask[v1], c2 = mask[v2], c3 = mask[v3]; \ - GLubyte ormask = c1|c2|c3; \ - if (!ormask) \ - TriangleFunc( ctx, v1, v2, v3 ); \ - else if (!(c1 & c2 & c3 & 0x3f)) \ - clip_tri_4( ctx, v1, v2, v3, ormask ); \ -} while (0) - -#define RENDER_QUAD( v1, v2, v3, v4 ) \ -do { \ - GLubyte c1 = mask[v1], c2 = mask[v2]; \ - GLubyte c3 = mask[v3], c4 = mask[v4]; \ - GLubyte ormask = c1|c2|c3|c4; \ - if (!ormask) \ - QuadFunc( ctx, v1, v2, v3, v4 ); \ - else if (!(c1 & c2 & c3 & c4 & 0x3f)) \ - clip_quad_4( ctx, v1, v2, v3, v4, ormask ); \ -} while (0) - - -#define LOCAL_VARS \ - TNLcontext *tnl = TNL_CONTEXT(ctx); \ - struct vertex_buffer *VB = &tnl->vb; \ - const GLuint * const elt = VB->Elts; \ - const GLubyte *mask = VB->ClipMask; \ - const GLuint sz = VB->ClipPtr->size; \ - const tnl_line_func LineFunc = tnl->Driver.Render.Line; \ - const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \ - const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \ - const GLboolean stipple = ctx->Line.StippleFlag; \ - (void) (LineFunc && TriangleFunc && QuadFunc); \ - (void) elt; (void) mask; (void) sz; (void) stipple; - -#define TAG(x) clip_##x##_verts -#define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x ) -#define RESET_STIPPLE if (stipple) tnl->Driver.Render.ResetLineStipple( ctx ) -#define PRESERVE_VB_DEFS -#include "tnl/t_vb_rendertmp.h" - - - -/* Elts, with the possibility of clipping. - */ -#undef ELT -#undef TAG -#define ELT(x) elt[x] -#define TAG(x) clip_##x##_elts -#include "tnl/t_vb_rendertmp.h" - -/* TODO: do this for all primitives, verts and elts: - */ -static void clip_elt_triangles( GLcontext *ctx, - GLuint start, - GLuint count, - GLuint flags ) -{ - TNLcontext *tnl = TNL_CONTEXT(ctx); - tnl_render_func render_tris = tnl->Driver.Render.PrimTabElts[GL_TRIANGLES]; - struct vertex_buffer *VB = &tnl->vb; - const GLuint * const elt = VB->Elts; - GLubyte *mask = VB->ClipMask; - GLuint last = count-2; - GLuint j; - (void) flags; - - tnl->Driver.Render.PrimitiveNotify( ctx, GL_TRIANGLES ); - - for (j=start; j < last; j+=3 ) { - GLubyte c1 = mask[elt[j]]; - GLubyte c2 = mask[elt[j+1]]; - GLubyte c3 = mask[elt[j+2]]; - GLubyte ormask = c1|c2|c3; - if (ormask) { - if (start < j) - render_tris( ctx, start, j, 0 ); - if (!(c1&c2&c3&0x3f)) - clip_tri_4( ctx, elt[j], elt[j+1], elt[j+2], ormask ); - start = j+3; - } - } - - if (start < j) - render_tris( ctx, start, j, 0 ); -} - -/**********************************************************************/ -/* Render whole begin/end objects */ -/**********************************************************************/ - -#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED) -#define EDGEFLAG_GET(idx) VB->EdgeFlag[idx] -#define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val - - -/* Vertices, no clipping. - */ -#define RENDER_POINTS( start, count ) \ - tnl->Driver.Render.Points( ctx, start, count ) - -#define RENDER_LINE( v1, v2 ) \ - LineFunc( ctx, v1, v2 ) - -#define RENDER_TRI( v1, v2, v3 ) \ - TriangleFunc( ctx, v1, v2, v3 ) - -#define RENDER_QUAD( v1, v2, v3, v4 ) \ - QuadFunc( ctx, v1, v2, v3, v4 ) - -#define TAG(x) _gld_tnl_##x##_verts - -#define LOCAL_VARS \ - TNLcontext *tnl = TNL_CONTEXT(ctx); \ - struct vertex_buffer *VB = &tnl->vb; \ - const GLuint * const elt = VB->Elts; \ - const tnl_line_func LineFunc = tnl->Driver.Render.Line; \ - const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \ - const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \ - (void) (LineFunc && TriangleFunc && QuadFunc); \ - (void) elt; - -#define RESET_STIPPLE tnl->Driver.Render.ResetLineStipple( ctx ) -#define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x ) -#define RENDER_TAB_QUALIFIER -#define PRESERVE_VB_DEFS -#include "tnl/t_vb_rendertmp.h" - - -/* Elts, no clipping. - */ -#undef ELT -#define TAG(x) _gld_tnl_##x##_elts -#define ELT(x) elt[x] -#include "tnl/t_vb_rendertmp.h" - - -/**********************************************************************/ -/* Helper functions for drivers */ -/**********************************************************************/ -/* -void _tnl_RenderClippedPolygon( GLcontext *ctx, const GLuint *elts, GLuint n ) -{ - TNLcontext *tnl = TNL_CONTEXT(ctx); - struct vertex_buffer *VB = &tnl->vb; - GLuint *tmp = VB->Elts; - - VB->Elts = (GLuint *)elts; - tnl->Driver.Render.PrimTabElts[GL_POLYGON]( ctx, 0, n, PRIM_BEGIN|PRIM_END ); - VB->Elts = tmp; -} - -void _tnl_RenderClippedLine( GLcontext *ctx, GLuint ii, GLuint jj ) -{ - TNLcontext *tnl = TNL_CONTEXT(ctx); - tnl->Driver.Render.Line( ctx, ii, jj ); -} -*/ - - -/**********************************************************************/ -/* Clip and render whole vertex buffers */ -/**********************************************************************/ - -tnl_points_func _gldSetupPoints[4] = { - gld_Points2D_DX8, - gld_Points2D_DX8, - gld_Points2D_DX8, - gld_Points2D_DX8 -}; -tnl_line_func _gldSetupLine[4] = { - gld_Line2DFlat_DX8, - gld_Line2DSmooth_DX8, - gld_Line2DFlat_DX8, - gld_Line2DSmooth_DX8, -}; -tnl_triangle_func _gldSetupTriangle[4] = { - gld_Triangle2DFlat_DX8, - gld_Triangle2DSmooth_DX8, - gld_Triangle2DFlatExtras_DX8, - gld_Triangle2DSmoothExtras_DX8 -}; -tnl_quad_func _gldSetupQuad[4] = { - gld_Quad2DFlat_DX8, - gld_Quad2DSmooth_DX8, - gld_Quad2DFlatExtras_DX8, - gld_Quad2DSmoothExtras_DX8 -}; - -//--------------------------------------------------------------------------- - -static GLboolean _gld_mesa_render_stage_run( - GLcontext *ctx, - struct tnl_pipeline_stage *stage) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); - - TNLcontext *tnl = TNL_CONTEXT(ctx); - struct vertex_buffer *VB = &tnl->vb; - tnl_render_func *tab; - GLint pass = 0; - GLD_pb_dx8 *gldPB; - - /* Allow the drivers to lock before projected verts are built so - * that window coordinates are guarenteed not to change before - * rendering. - */ - ASSERT(tnl->Driver.Render.Start); - - tnl->Driver.Render.Start( ctx ); - - // NOTE: Setting D3DRS_SOFTWAREVERTEXPROCESSING for a mixed-mode device resets - // stream, indices and shader to default values of NULL or 0. -/* if ((ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) && - gld->VStwosidelight.hShader && - !ctx->Fog.Enabled) - { - IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, !gld->VStwosidelight.bHardware); - _GLD_DX8_DEV(SetVertexShader(gld->pDev, gld->VStwosidelight.hShader)); - gldPB = &gld->PBtwosidelight; - tnl->Driver.Render.Points = gld_Points2DTwoside_DX8; - if (ctx->_TriangleCaps & DD_FLATSHADE) { - tnl->Driver.Render.Line = gld_Line2DFlatTwoside_DX8; - tnl->Driver.Render.Triangle = gld_Triangle2DFlatTwoside_DX8; - tnl->Driver.Render.Quad = gld_Quad2DFlatTwoside_DX8; - } else { - tnl->Driver.Render.Line = gld_Line2DSmoothTwoside_DX8; - tnl->Driver.Render.Triangle = gld_Triangle2DSmoothTwoside_DX8; - tnl->Driver.Render.Quad = gld_Quad2DSmoothTwoside_DX8; - } - } else {*/ - IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, TRUE); - gldPB = &gld->PB2d; - _GLD_DX8_DEV(SetVertexShader(gld->pDev, gldPB->dwFVF)); - tnl->Driver.Render.Points = _gldSetupPoints[gld->iSetupFunc]; - tnl->Driver.Render.Line = _gldSetupLine[gld->iSetupFunc]; - tnl->Driver.Render.Triangle = _gldSetupTriangle[gld->iSetupFunc]; - tnl->Driver.Render.Quad = _gldSetupQuad[gld->iSetupFunc]; -// } - - _GLD_DX8_VB(Lock(gldPB->pVB, 0, 0, &gldPB->pPoints, D3DLOCK_DISCARD)); - gldPB->nPoints = gldPB->nLines = gldPB->nTriangles = 0; - // Allocate primitive pointers - // gldPB->pPoints is always first - gldPB->pLines = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstLine); - gldPB->pTriangles = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstTriangle); - - ASSERT(tnl->Driver.Render.BuildVertices); - ASSERT(tnl->Driver.Render.PrimitiveNotify); - ASSERT(tnl->Driver.Render.Points); - ASSERT(tnl->Driver.Render.Line); - ASSERT(tnl->Driver.Render.Triangle); - ASSERT(tnl->Driver.Render.Quad); - ASSERT(tnl->Driver.Render.ResetLineStipple); - ASSERT(tnl->Driver.Render.Interp); - ASSERT(tnl->Driver.Render.CopyPV); - ASSERT(tnl->Driver.Render.ClippedLine); - ASSERT(tnl->Driver.Render.ClippedPolygon); - ASSERT(tnl->Driver.Render.Finish); - - tnl->Driver.Render.BuildVertices( ctx, 0, VB->Count, ~0 ); - - if (VB->ClipOrMask) { - tab = VB->Elts ? clip_render_tab_elts : clip_render_tab_verts; - clip_render_tab_elts[GL_TRIANGLES] = clip_elt_triangles; - } - else { - tab = (VB->Elts ? - tnl->Driver.Render.PrimTabElts : - tnl->Driver.Render.PrimTabVerts); - } - - do { - GLuint i, length, flags = 0; - for (i = 0 ; !(flags & PRIM_END) ; i += length) { - flags = VB->Primitive[i].mode; - length= VB->Primitive[i].count; - ASSERT(length || (flags & PRIM_END)); - ASSERT((flags & PRIM_MODE_MASK) <= GL_POLYGON+1); - if (length) - tab[flags & PRIM_MODE_MASK]( ctx, i, i + length, flags ); - } - } while (tnl->Driver.Render.Multipass && - tnl->Driver.Render.Multipass( ctx, ++pass )); - - -// tnl->Driver.Render.Finish( ctx ); - - _GLD_DX8_VB(Unlock(gldPB->pVB)); - - _GLD_DX8_DEV(SetStreamSource(gld->pDev, 0, gldPB->pVB, gldPB->dwStride)); - - if (gldPB->nPoints) { - _GLD_DX8_DEV(DrawPrimitive(gld->pDev, D3DPT_POINTLIST, 0, gldPB->nPoints)); - gldPB->nPoints = 0; - } - - if (gldPB->nLines) { - _GLD_DX8_DEV(DrawPrimitive(gld->pDev, D3DPT_LINELIST, gldPB->iFirstLine, gldPB->nLines)); - gldPB->nLines = 0; - } - - if (gldPB->nTriangles) { - _GLD_DX8_DEV(DrawPrimitive(gld->pDev, D3DPT_TRIANGLELIST, gldPB->iFirstTriangle, gldPB->nTriangles)); - gldPB->nTriangles = 0; - } - - return GL_FALSE; /* finished the pipe */ -} - - -/**********************************************************************/ -/* Render pipeline stage */ -/**********************************************************************/ - - - - -//--------------------------------------------------------------------------- - -const struct tnl_pipeline_stage _gld_mesa_render_stage = -{ - "gld_mesa_render_stage", - NULL, - NULL, - NULL, - NULL, - _gld_mesa_render_stage_run /* run */ -}; - -//--------------------------------------------------------------------------- diff --git a/src/mesa/drivers/windows/gldirect/dx8/gld_wgl_dx8.c b/src/mesa/drivers/windows/gldirect/dx8/gld_wgl_dx8.c deleted file mode 100644 index 011d810e97..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx8/gld_wgl_dx8.c +++ /dev/null @@ -1,1336 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: GLDirect Direct3D 8.x WGL (WindowsGL) -* -****************************************************************************/ - -#include "dglcontext.h" -#include "gld_driver.h" -#include "gld_dxerr8.h" -#include "gld_dx8.h" - -#include "tnl/tnl.h" -#include "tnl/t_context.h" - -// Copied from dglcontect.c -#define GLDERR_NONE 0 -#define GLDERR_MEM 1 -#define GLDERR_DDRAW 2 -#define GLDERR_D3D 3 -#define GLDERR_BPP 4 -#define GLDERR_DDS 5 -// This external var keeps track of any error -extern int nContextError; - -#define DDLOG_CRITICAL_OR_WARN DDLOG_CRITICAL - -extern void _gld_mesa_warning(GLcontext *, char *); -extern void _gld_mesa_fatal(GLcontext *, char *); - -//--------------------------------------------------------------------------- - -static char szColorDepthWarning[] = -"GLDirect does not support the current desktop\n\ -color depth.\n\n\ -You may need to change the display resolution to\n\ -16 bits per pixel or higher color depth using\n\ -the Windows Display Settings control panel\n\ -before running this OpenGL application.\n"; - -// The only depth-stencil formats currently supported by Direct3D -// Surface Format Depth Stencil Total Bits -// D3DFMT_D32 32 - 32 -// D3DFMT_D15S1 15 1 16 -// D3DFMT_D24S8 24 8 32 -// D3DFMT_D16 16 - 16 -// D3DFMT_D24X8 24 - 32 -// D3DFMT_D24X4S4 24 4 32 - -// This pixel format will be used as a template when compiling the list -// of pixel formats supported by the hardware. Many fields will be -// filled in at runtime. -// PFD flag defaults are upgraded to match ChoosePixelFormat() -- DaveM -static DGL_pixelFormat pfTemplateHW = -{ - { - sizeof(PIXELFORMATDESCRIPTOR), // Size of the data structure - 1, // Structure version - should be 1 - // Flags: - PFD_DRAW_TO_WINDOW | // The buffer can draw to a window or device surface. - PFD_DRAW_TO_BITMAP | // The buffer can draw to a bitmap. (DaveM) - PFD_SUPPORT_GDI | // The buffer supports GDI drawing. (DaveM) - PFD_SUPPORT_OPENGL | // The buffer supports OpenGL drawing. - PFD_DOUBLEBUFFER | // The buffer is double-buffered. - 0, // Placeholder for easy commenting of above flags - PFD_TYPE_RGBA, // Pixel type RGBA. - 16, // Total colour bitplanes (excluding alpha bitplanes) - 5, 0, // Red bits, shift - 5, 0, // Green bits, shift - 5, 0, // Blue bits, shift - 0, 0, // Alpha bits, shift (destination alpha) - 0, // Accumulator bits (total) - 0, 0, 0, 0, // Accumulator bits: Red, Green, Blue, Alpha - 0, // Depth bits - 0, // Stencil bits - 0, // Number of auxiliary buffers - 0, // Layer type - 0, // Specifies the number of overlay and underlay planes. - 0, // Layer mask - 0, // Specifies the transparent color or index of an underlay plane. - 0 // Damage mask - }, - D3DFMT_UNKNOWN, // No depth/stencil buffer -}; - -//--------------------------------------------------------------------------- -// Vertex Shaders -//--------------------------------------------------------------------------- - -// Vertex Shader Declaration -static DWORD dwTwoSidedLightingDecl[] = -{ - D3DVSD_STREAM(0), - D3DVSD_REG(0, D3DVSDT_FLOAT3), // XYZ position - D3DVSD_REG(1, D3DVSDT_FLOAT3), // XYZ normal - D3DVSD_REG(2, D3DVSDT_D3DCOLOR), // Diffuse color - D3DVSD_REG(3, D3DVSDT_D3DCOLOR), // Specular color - D3DVSD_REG(4, D3DVSDT_FLOAT2), // 2D texture unit 0 - D3DVSD_REG(5, D3DVSDT_FLOAT2), // 2D texture unit 1 - D3DVSD_END() -}; - -// Vertex Shader for two-sided lighting -static char *szTwoSidedLightingVS = -// This is a test shader! -"vs.1.0\n" -"m4x4 oPos,v0,c0\n" -"mov oD0,v2\n" -"mov oD1,v3\n" -"mov oT0,v4\n" -"mov oT1,v5\n" -; - -//--------------------------------------------------------------------------- -//--------------------------------------------------------------------------- - -typedef struct { - HINSTANCE hD3D8DLL; // Handle to d3d8.dll - FNDIRECT3DCREATE8 fnDirect3DCreate8; // Direct3DCreate8 function prototype - BOOL bDirect3D; // Persistant Direct3D8 exists - BOOL bDirect3DDevice; // Persistant Direct3DDevice8 exists - IDirect3D8 *pD3D; // Persistant Direct3D8 - IDirect3DDevice8 *pDev; // Persistant Direct3DDevice8 -} GLD_dx8_globals; - -// These are "global" to all DX8 contexts. KeithH -static GLD_dx8_globals dx8Globals; - -//--------------------------------------------------------------------------- -//--------------------------------------------------------------------------- - -BOOL gldGetDXErrorString_DX( - HRESULT hr, - char *buf, - int nBufSize) -{ - // - // Return a string describing the input HRESULT error code - // - - D3DXGetErrorString(hr, buf, nBufSize); - return TRUE; -} - -//--------------------------------------------------------------------------- - -static D3DMULTISAMPLE_TYPE _gldGetDeviceMultiSampleType( - IDirect3D8 *pD3D8, - D3DFORMAT SurfaceFormat, - D3DDEVTYPE d3dDevType, - BOOL Windowed) -{ - int i; - HRESULT hr; - - if (glb.dwMultisample == GLDS_MULTISAMPLE_NONE) - return D3DMULTISAMPLE_NONE; - - if (glb.dwMultisample == GLDS_MULTISAMPLE_FASTEST) { - // Find fastest multisample - for (i=2; i<17; i++) { - hr = IDirect3D8_CheckDeviceMultiSampleType( - pD3D8, - glb.dwAdapter, - d3dDevType, - SurfaceFormat, - Windowed, - (D3DMULTISAMPLE_TYPE)i); - if (SUCCEEDED(hr)) { - return (D3DMULTISAMPLE_TYPE)i; - } - } - } else { - // Find nicest multisample - for (i=16; i>1; i--) { - hr = IDirect3D8_CheckDeviceMultiSampleType( - pD3D8, - glb.dwAdapter, - d3dDevType, - SurfaceFormat, - Windowed, - (D3DMULTISAMPLE_TYPE)i); - if (SUCCEEDED(hr)) { - return (D3DMULTISAMPLE_TYPE)i; - } - } - } - - // Nothing found - return default - return D3DMULTISAMPLE_NONE; -} - -//--------------------------------------------------------------------------- - -void _gldDestroyPrimitiveBuffer( - GLD_pb_dx8 *gldVB) -{ - SAFE_RELEASE(gldVB->pVB); - - // Sanity check... - gldVB->nLines = gldVB->nPoints = gldVB->nTriangles = 0; -} - -//--------------------------------------------------------------------------- - -HRESULT _gldCreatePrimitiveBuffer( - GLcontext *ctx, - GLD_driver_dx8 *lpCtx, - GLD_pb_dx8 *gldVB) -{ - HRESULT hResult; - char *szCreateVertexBufferFailed = "CreateVertexBuffer failed"; - DWORD dwMaxVertices; // Max number of vertices in vertex buffer - DWORD dwVBSize; // Total size of vertex buffer - - // If CVA (Compiled Vertex Array) is used by an OpenGL app, then we - // will need enough vertices to cater for Mesa::Const.MaxArrayLockSize. - // We'll use IMM_SIZE if it's larger (which it should not be). - dwMaxVertices = MAX_ARRAY_LOCK_SIZE; - - // Now calculate how many vertices to allow for in total - // 1 per point, 2 per line, 6 per quad = 9 - dwVBSize = dwMaxVertices * 9 * gldVB->dwStride; - - hResult = IDirect3DDevice8_CreateVertexBuffer( - lpCtx->pDev, - dwVBSize, - gldVB->dwUsage, - gldVB->dwFVF, - gldVB->dwPool, - &gldVB->pVB); - if (FAILED(hResult)) { - ddlogMessage(DDLOG_CRITICAL_OR_WARN, szCreateVertexBufferFailed); - return hResult; - } - - gldVB->nLines = gldVB->nPoints = gldVB->nTriangles = 0; - gldVB->pPoints = gldVB->pLines = gldVB->pTriangles = NULL; - gldVB->iFirstLine = dwMaxVertices; // Index of first line in VB - gldVB->iFirstTriangle = dwMaxVertices*3; // Index of first triangle in VB - - return S_OK; -} - -//--------------------------------------------------------------------------- -// Function: _gldCreateVertexShaders -// Create DX8 Vertex Shaders. -//--------------------------------------------------------------------------- -/* -void _gldCreateVertexShaders( - GLD_driver_dx8 *gld) -{ - DWORD dwFlags; - LPD3DXBUFFER pVSOpcodeBuffer; // Vertex Shader opcode buffer - HRESULT hr; - -#ifdef _DEBUG - dwFlags = D3DXASM_DEBUG; -#else - dwFlags = 0; // D3DXASM_SKIPVALIDATION; -#endif - - ddlogMessage(DDLOG_INFO, "Creating shaders...\n"); - - // Init the shader handle - gld->VStwosidelight.hShader = 0; - - if (gld->d3dCaps8.MaxStreams == 0) { - // Lame DX8 driver doesn't support streams - // Not fatal, as defaults will be used - ddlogMessage(DDLOG_WARN, "Driver doesn't support Vertex Shaders (MaxStreams==0)\n"); - return; - } - - // ** THIS DISABLES VERTEX SHADER SUPPORT ** -// return; - // ** THIS DISABLES VERTEX SHADER SUPPORT ** - - // - // Two-sided lighting - // - -#if 0 - // - // DEBUGGING: Load shader from a text file - // - { - LPD3DXBUFFER pVSErrorBuffer; // Vertex Shader error buffer - hr = D3DXAssembleShaderFromFile( - "twoside.vsh", - dwFlags, - NULL, // No constants - &pVSOpcodeBuffer, - &pVSErrorBuffer); - if (pVSErrorBuffer && pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)) - ddlogMessage(DDLOG_INFO, pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)); - SAFE_RELEASE(pVSErrorBuffer); - } -#else - { - LPD3DXBUFFER pVSErrorBuffer; // Vertex Shader error buffer - // Assemble ascii shader text into shader opcodes - hr = D3DXAssembleShader( - szTwoSidedLightingVS, - strlen(szTwoSidedLightingVS), - dwFlags, - NULL, // No constants - &pVSOpcodeBuffer, - &pVSErrorBuffer); - if (pVSErrorBuffer && pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)) - ddlogMessage(DDLOG_INFO, pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)); - SAFE_RELEASE(pVSErrorBuffer); - } -#endif - if (FAILED(hr)) { - ddlogError(DDLOG_WARN, "AssembleShader failed", hr); - SAFE_RELEASE(pVSOpcodeBuffer); - return; - } - -// This is for debugging. Remove to enable vertex shaders in HW -#define _GLD_FORCE_SW_VS 0 - - if (_GLD_FORCE_SW_VS) { - // _GLD_FORCE_SW_VS should be disabled for Final Release - ddlogMessage(DDLOG_SYSTEM, "[Forcing shaders in SW]\n"); - } - - // Try and create shader in hardware. - // NOTE: The D3D Ref device appears to succeed when trying to - // create the device in hardware, but later complains - // when trying to set it with SetVertexShader(). Go figure. - if (_GLD_FORCE_SW_VS || glb.dwDriver == GLDS_DRIVER_REF) { - // Don't try and create a hardware shader with the Ref device - hr = E_FAIL; // COM error/fail result - } else { - gld->VStwosidelight.bHardware = TRUE; - hr = IDirect3DDevice8_CreateVertexShader( - gld->pDev, - dwTwoSidedLightingDecl, - pVSOpcodeBuffer->lpVtbl->GetBufferPointer(pVSOpcodeBuffer), - &gld->VStwosidelight.hShader, - 0); - } - if (FAILED(hr)) { - ddlogMessage(DDLOG_INFO, "... HW failed, trying SW...\n"); - // Failed. Try and create shader for software processing - hr = IDirect3DDevice8_CreateVertexShader( - gld->pDev, - dwTwoSidedLightingDecl, - pVSOpcodeBuffer->lpVtbl->GetBufferPointer(pVSOpcodeBuffer), - &gld->VStwosidelight.hShader, - D3DUSAGE_SOFTWAREPROCESSING); - if (FAILED(hr)) { - gld->VStwosidelight.hShader = 0; // Sanity check - ddlogError(DDLOG_WARN, "CreateVertexShader failed", hr); - return; - } - // Succeeded, but for software processing - gld->VStwosidelight.bHardware = FALSE; - } - - SAFE_RELEASE(pVSOpcodeBuffer); - - ddlogMessage(DDLOG_INFO, "... OK\n"); -} - -//--------------------------------------------------------------------------- - -void _gldDestroyVertexShaders( - GLD_driver_dx8 *gld) -{ - if (gld->VStwosidelight.hShader) { - IDirect3DDevice8_DeleteVertexShader(gld->pDev, gld->VStwosidelight.hShader); - gld->VStwosidelight.hShader = 0; - } -} -*/ -//--------------------------------------------------------------------------- - -LPVOID lpOpaque1 = NULL; -LPVOID lpOpaque2 = NULL; - -BOOL gldCreateDrawable_DX( - DGL_ctx *ctx, -// BOOL bDefaultDriver, - BOOL bDirectDrawPersistant, - BOOL bPersistantBuffers) -{ - // - // bDirectDrawPersistant: applies to IDirect3D8 - // bPersistantBuffers: applies to IDirect3DDevice8 - // - - HRESULT hResult; - GLD_driver_dx8 *lpCtx = NULL; - D3DDEVTYPE d3dDevType; - D3DPRESENT_PARAMETERS d3dpp; - D3DDISPLAYMODE d3ddm; - DWORD dwBehaviourFlags; - D3DADAPTER_IDENTIFIER8 d3dIdent; - - // Error if context is NULL. - if (ctx == NULL) - return FALSE; - - if (ctx->glPriv) { - lpCtx = ctx->glPriv; - // Release any existing interfaces - SAFE_RELEASE(lpCtx->pDev); - SAFE_RELEASE(lpCtx->pD3D); - } else { - lpCtx = (GLD_driver_dx8*)malloc(sizeof(GLD_driver_dx8)); - ZeroMemory(lpCtx, sizeof(lpCtx)); - } - - d3dDevType = (glb.dwDriver == GLDS_DRIVER_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; - // TODO: Check this -// if (bDefaultDriver) -// d3dDevType = D3DDEVTYPE_REF; - - // Use persistant interface if needed - if (bDirectDrawPersistant && dx8Globals.bDirect3D) { - lpCtx->pD3D = dx8Globals.pD3D; - IDirect3D8_AddRef(lpCtx->pD3D); - goto SkipDirectDrawCreate; - } - - // Create Direct3D8 object - lpCtx->pD3D = dx8Globals.fnDirect3DCreate8(D3D_SDK_VERSION_DX8_SUPPORT_WIN95); - if (lpCtx->pD3D == NULL) { - MessageBox(NULL, "Unable to initialize Direct3D8", "GLDirect", MB_OK); - ddlogMessage(DDLOG_CRITICAL_OR_WARN, "Unable to create Direct3D8 interface"); - nContextError = GLDERR_D3D; - goto return_with_error; - } - - // Cache Direct3D interface for subsequent GLRCs - if (bDirectDrawPersistant && !dx8Globals.bDirect3D) { - dx8Globals.pD3D = lpCtx->pD3D; - IDirect3D8_AddRef(dx8Globals.pD3D); - dx8Globals.bDirect3D = TRUE; - } -SkipDirectDrawCreate: - - // Get the display mode so we can make a compatible backbuffer - hResult = IDirect3D8_GetAdapterDisplayMode(lpCtx->pD3D, glb.dwAdapter, &d3ddm); - if (FAILED(hResult)) { - nContextError = GLDERR_D3D; - goto return_with_error; - } - - // Get device caps - hResult = IDirect3D8_GetDeviceCaps(lpCtx->pD3D, glb.dwAdapter, d3dDevType, &lpCtx->d3dCaps8); - if (FAILED(hResult)) { - ddlogError(DDLOG_CRITICAL_OR_WARN, "IDirect3D8_GetDeviceCaps failed", hResult); - nContextError = GLDERR_D3D; - goto return_with_error; - } - - // Check for hardware transform & lighting - lpCtx->bHasHWTnL = lpCtx->d3dCaps8.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ? TRUE : FALSE; - - // If this flag is present then we can't default to Mesa - // SW rendering between BeginScene() and EndScene(). - if (lpCtx->d3dCaps8.Caps2 & D3DCAPS2_NO2DDURING3DSCENE) { - ddlogMessage(DDLOG_WARN, - "Warning : No 2D allowed during 3D scene.\n"); - } - - // - // Create the Direct3D context - // - - // Re-use original IDirect3DDevice if persistant buffers exist. - // Note that we test for persistant IDirect3D8 as well - // bDirectDrawPersistant == persistant IDirect3D8 (DirectDraw8 does not exist) - if (bDirectDrawPersistant && bPersistantBuffers && dx8Globals.pD3D && dx8Globals.pDev) { - lpCtx->pDev = dx8Globals.pDev; - IDirect3DDevice8_AddRef(dx8Globals.pDev); - goto skip_direct3ddevice_create; - } - - // Clear the presentation parameters (sets all members to zero) - ZeroMemory(&d3dpp, sizeof(d3dpp)); - - // Recommended by MS; needed for MultiSample. - // Be careful if altering this for FullScreenBlit - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - - d3dpp.BackBufferFormat = d3ddm.Format; - d3dpp.BackBufferCount = 1; - d3dpp.MultiSampleType = _gldGetDeviceMultiSampleType(lpCtx->pD3D, d3ddm.Format, d3dDevType, !ctx->bFullscreen); - d3dpp.AutoDepthStencilFormat = ctx->lpPF->dwDriverData; - d3dpp.EnableAutoDepthStencil = (d3dpp.AutoDepthStencilFormat == D3DFMT_UNKNOWN) ? FALSE : TRUE; - - if (ctx->bFullscreen) { - ddlogWarnOption(FALSE); // Don't popup any messages in fullscreen - d3dpp.Windowed = FALSE; - d3dpp.BackBufferWidth = d3ddm.Width; - d3dpp.BackBufferHeight = d3ddm.Height; - d3dpp.hDeviceWindow = ctx->hWnd; - d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; - - // Support for vertical retrace synchronisation. - // Set default presentation interval in case caps bits are missing - d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; - if (glb.bWaitForRetrace) { - if (lpCtx->d3dCaps8.PresentationIntervals & D3DPRESENT_INTERVAL_ONE) - d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE; - } else { - if (lpCtx->d3dCaps8.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) - d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; - } - } else { - ddlogWarnOption(glb.bMessageBoxWarnings); // OK to popup messages - d3dpp.Windowed = TRUE; - d3dpp.BackBufferWidth = ctx->dwWidth; - d3dpp.BackBufferHeight = ctx->dwHeight; - d3dpp.hDeviceWindow = ctx->hWnd; - d3dpp.FullScreen_RefreshRateInHz = 0; - // FullScreen_PresentationInterval must be default for Windowed mode - d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; - } - - // Decide if we can use hardware TnL - dwBehaviourFlags = (lpCtx->bHasHWTnL) ? - D3DCREATE_MIXED_VERTEXPROCESSING : D3DCREATE_SOFTWARE_VERTEXPROCESSING; - // Add flag to tell D3D to be thread-safe - if (glb.bMultiThreaded) - dwBehaviourFlags |= D3DCREATE_MULTITHREADED; - // Add flag to tell D3D to be FPU-safe - if (!glb.bFastFPU) - dwBehaviourFlags |= D3DCREATE_FPU_PRESERVE; - hResult = IDirect3D8_CreateDevice(lpCtx->pD3D, - glb.dwAdapter, - d3dDevType, - ctx->hWnd, - dwBehaviourFlags, - &d3dpp, - &lpCtx->pDev); - if (FAILED(hResult)) { - ddlogError(DDLOG_CRITICAL_OR_WARN, "IDirect3D8_CreateDevice failed", hResult); - nContextError = GLDERR_D3D; - goto return_with_error; - } - - if (bDirectDrawPersistant && bPersistantBuffers && dx8Globals.pD3D) { - dx8Globals.pDev = lpCtx->pDev; - dx8Globals.bDirect3DDevice = TRUE; - } - -/* - // See if DDraw interfaces are available (DaveM) - hResult = IDirect3D8_QueryInterface(lpCtx->pDev, - &IID_IDirectDraw7, (LPVOID*)&lpOpaque1); - if (FAILED(hResult) || lpOpaque1 == NULL) { - ddlogMessage(DDLOG_INFO, "DirectDraw QueryInterface unavailable\n"); - } - - hResult = IDirect3DDevice8_QueryInterface(lpCtx->pDev, - &IID_IDirectDrawSurface7, (LPVOID*)&lpOpaque2); - if (FAILED(hResult) || lpOpaque2 == NULL) { - ddlogMessage(DDLOG_INFO, "DirectDrawSurface QueryInterface unavialable\n"); - } -*/ - // Dump some useful stats - hResult = IDirect3D8_GetAdapterIdentifier( - lpCtx->pD3D, - glb.dwAdapter, - D3DENUM_NO_WHQL_LEVEL, // Avoids 1 to 2 second delay - &d3dIdent); - if (SUCCEEDED(hResult)) { - ddlogPrintf(DDLOG_INFO, "[Driver Description: %s]", &d3dIdent.Description); - ddlogPrintf(DDLOG_INFO, "[Driver file: %s %d.%d.%02d.%d]", - d3dIdent.Driver, - HIWORD(d3dIdent.DriverVersion.HighPart), - LOWORD(d3dIdent.DriverVersion.HighPart), - HIWORD(d3dIdent.DriverVersion.LowPart), - LOWORD(d3dIdent.DriverVersion.LowPart)); - ddlogPrintf(DDLOG_INFO, "[VendorId: 0x%X, DeviceId: 0x%X, SubSysId: 0x%X, Revision: 0x%X]", - d3dIdent.VendorId, d3dIdent.DeviceId, d3dIdent.SubSysId, d3dIdent.Revision); - } - - // Init projection matrix for D3D TnL - D3DXMatrixIdentity(&lpCtx->matProjection); - lpCtx->matModelView = lpCtx->matProjection; -// gld->bUseMesaProjection = TRUE; - -skip_direct3ddevice_create: - - // Create buffers to hold primitives - lpCtx->PB2d.dwFVF = GLD_FVF_2D_VERTEX; - lpCtx->PB2d.dwPool = D3DPOOL_SYSTEMMEM; - lpCtx->PB2d.dwStride = sizeof(GLD_2D_VERTEX); - lpCtx->PB2d.dwUsage = D3DUSAGE_DONOTCLIP | - D3DUSAGE_DYNAMIC | - D3DUSAGE_SOFTWAREPROCESSING | - D3DUSAGE_WRITEONLY; - hResult = _gldCreatePrimitiveBuffer(ctx->glCtx, lpCtx, &lpCtx->PB2d); - if (FAILED(hResult)) - goto return_with_error; - - lpCtx->PB3d.dwFVF = GLD_FVF_3D_VERTEX; - lpCtx->PB3d.dwPool = D3DPOOL_DEFAULT; - lpCtx->PB3d.dwStride = sizeof(GLD_3D_VERTEX); - lpCtx->PB3d.dwUsage = D3DUSAGE_DYNAMIC | - D3DUSAGE_SOFTWAREPROCESSING | - D3DUSAGE_WRITEONLY; - hResult = _gldCreatePrimitiveBuffer(ctx->glCtx, lpCtx, &lpCtx->PB3d); - if (FAILED(hResult)) - goto return_with_error; - -/* // NOTE: A FVF code of zero indicates a non-FVF vertex buffer (for vertex shaders) - lpCtx->PBtwosidelight.dwFVF = 0; //GLD_FVF_TWOSIDED_VERTEX; - lpCtx->PBtwosidelight.dwPool = D3DPOOL_DEFAULT; - lpCtx->PBtwosidelight.dwStride = sizeof(GLD_TWOSIDED_VERTEX); - lpCtx->PBtwosidelight.dwUsage = D3DUSAGE_DONOTCLIP | - D3DUSAGE_DYNAMIC | - D3DUSAGE_SOFTWAREPROCESSING | - D3DUSAGE_WRITEONLY; - hResult = _gldCreatePrimitiveBuffer(ctx->glCtx, lpCtx, &lpCtx->PBtwosidelight); - if (FAILED(hResult)) - goto return_with_error;*/ - - // Now try and create the DX8 Vertex Shaders -// _gldCreateVertexShaders(lpCtx); - - // Zero the pipeline usage counters - lpCtx->PipelineUsage.qwMesa.QuadPart = -// lpCtx->PipelineUsage.dwD3D2SVS.QuadPart = - lpCtx->PipelineUsage.qwD3DFVF.QuadPart = 0; - - // Assign drawable to GL private - ctx->glPriv = lpCtx; - return TRUE; - -return_with_error: - // Clean up and bail - -// _gldDestroyVertexShaders(lpCtx); - -// _gldDestroyPrimitiveBuffer(&lpCtx->PBtwosidelight); - _gldDestroyPrimitiveBuffer(&lpCtx->PB3d); - _gldDestroyPrimitiveBuffer(&lpCtx->PB2d); - - SAFE_RELEASE(lpCtx->pDev); - SAFE_RELEASE(lpCtx->pD3D); - return FALSE; -} - -//--------------------------------------------------------------------------- - -BOOL gldResizeDrawable_DX( - DGL_ctx *ctx, - BOOL bDefaultDriver, - BOOL bPersistantInterface, - BOOL bPersistantBuffers) -{ - GLD_driver_dx8 *gld = NULL; - D3DDEVTYPE d3dDevType; - D3DPRESENT_PARAMETERS d3dpp; - D3DDISPLAYMODE d3ddm; - HRESULT hResult; - - // Error if context is NULL. - if (ctx == NULL) - return FALSE; - - gld = ctx->glPriv; - if (gld == NULL) - return FALSE; - - if (ctx->bSceneStarted) { - IDirect3DDevice8_EndScene(gld->pDev); - ctx->bSceneStarted = FALSE; - } - - d3dDevType = (glb.dwDriver == GLDS_DRIVER_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; - if (!bDefaultDriver) - d3dDevType = D3DDEVTYPE_REF; // Force Direct3D Reference Rasterise (software) - - // Get the display mode so we can make a compatible backbuffer - hResult = IDirect3D8_GetAdapterDisplayMode(gld->pD3D, glb.dwAdapter, &d3ddm); - if (FAILED(hResult)) { - nContextError = GLDERR_D3D; -// goto return_with_error; - return FALSE; - } - - // Destroy DX8 Vertex Shaders before Reset() -// _gldDestroyVertexShaders(gld); - - // Release POOL_DEFAULT objects before Reset() - if (gld->PB2d.dwPool == D3DPOOL_DEFAULT) - _gldDestroyPrimitiveBuffer(&gld->PB2d); - if (gld->PB3d.dwPool == D3DPOOL_DEFAULT) - _gldDestroyPrimitiveBuffer(&gld->PB3d); -// if (gld->PBtwosidelight.dwPool == D3DPOOL_DEFAULT) -// _gldDestroyPrimitiveBuffer(&gld->PBtwosidelight); - - // Clear the presentation parameters (sets all members to zero) - ZeroMemory(&d3dpp, sizeof(d3dpp)); - - // Recommended by MS; needed for MultiSample. - // Be careful if altering this for FullScreenBlit - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - - d3dpp.BackBufferFormat = d3ddm.Format; - d3dpp.BackBufferCount = 1; - d3dpp.MultiSampleType = _gldGetDeviceMultiSampleType(gld->pD3D, d3ddm.Format, d3dDevType, !ctx->bFullscreen); - d3dpp.AutoDepthStencilFormat = ctx->lpPF->dwDriverData; - d3dpp.EnableAutoDepthStencil = (d3dpp.AutoDepthStencilFormat == D3DFMT_UNKNOWN) ? FALSE : TRUE; - - // TODO: Sync to refresh - - if (ctx->bFullscreen) { - ddlogWarnOption(FALSE); // Don't popup any messages in fullscreen - d3dpp.Windowed = FALSE; - d3dpp.BackBufferWidth = d3ddm.Width; - d3dpp.BackBufferHeight = d3ddm.Height; - d3dpp.hDeviceWindow = ctx->hWnd; - d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; - d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; - // Get better benchmark results? KeithH -// d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_UNLIMITED; - } else { - ddlogWarnOption(glb.bMessageBoxWarnings); // OK to popup messages - d3dpp.Windowed = TRUE; - d3dpp.BackBufferWidth = ctx->dwWidth; - d3dpp.BackBufferHeight = ctx->dwHeight; - d3dpp.hDeviceWindow = ctx->hWnd; - d3dpp.FullScreen_RefreshRateInHz = 0; - d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; - } - hResult = IDirect3DDevice8_Reset(gld->pDev, &d3dpp); - if (FAILED(hResult)) { - ddlogError(DDLOG_CRITICAL_OR_WARN, "dglResize: Reset failed", hResult); - return FALSE; - //goto cleanup_and_return_with_error; - } - - // Explicitly Clear resized surfaces (DaveM) - { - D3DVIEWPORT8 d3dvp1, d3dvp2; - IDirect3DDevice8_GetViewport(gld->pDev, &d3dvp1); - IDirect3DDevice8_GetViewport(gld->pDev, &d3dvp2); - d3dvp1.X = 0; - d3dvp1.Y = 0; - d3dvp1.Width = ctx->dwWidth; - d3dvp1.Height = ctx->dwHeight; - IDirect3DDevice8_SetViewport(gld->pDev, &d3dvp1); - IDirect3DDevice8_Clear(gld->pDev,0,NULL,D3DCLEAR_TARGET,0,0,0); - IDirect3DDevice8_SetViewport(gld->pDev, &d3dvp2); - } - - // - // Recreate POOL_DEFAULT objects - // - if (gld->PB2d.dwPool == D3DPOOL_DEFAULT) { - _gldCreatePrimitiveBuffer(ctx->glCtx, gld, &gld->PB2d); - } - if (gld->PB3d.dwPool == D3DPOOL_DEFAULT) { - _gldCreatePrimitiveBuffer(ctx->glCtx, gld, &gld->PB3d); - } -// if (gld->PBtwosidelight.dwPool == D3DPOOL_DEFAULT) { -// _gldCreatePrimitiveBuffer(ctx->glCtx, gld, &gld->PB2d); -// } - - // Recreate DX8 Vertex Shaders -// _gldCreateVertexShaders(gld); - - // Signal a complete state update - ctx->glCtx->Driver.UpdateState(ctx->glCtx, _NEW_ALL); - - // Begin a new scene - IDirect3DDevice8_BeginScene(gld->pDev); - ctx->bSceneStarted = TRUE; - - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldDestroyDrawable_DX( - DGL_ctx *ctx) -{ - GLD_driver_dx8 *lpCtx = NULL; - - // Error if context is NULL. - if (!ctx) - return FALSE; - - // Error if the drawable does not exist. - if (!ctx->glPriv) - return FALSE; - - lpCtx = ctx->glPriv; - -#ifdef _DEBUG - // Dump out stats - ddlogPrintf(DDLOG_SYSTEM, "Usage: M:0x%X%X, D:0x%X%X", - lpCtx->PipelineUsage.qwMesa.HighPart, - lpCtx->PipelineUsage.qwMesa.LowPart, - lpCtx->PipelineUsage.qwD3DFVF.HighPart, - lpCtx->PipelineUsage.qwD3DFVF.LowPart); -#endif - -// _gldDestroyVertexShaders(lpCtx); - -// _gldDestroyPrimitiveBuffer(&lpCtx->PBtwosidelight); - _gldDestroyPrimitiveBuffer(&lpCtx->PB3d); - _gldDestroyPrimitiveBuffer(&lpCtx->PB2d); - - SAFE_RELEASE(lpCtx->pDev); - SAFE_RELEASE(lpCtx->pD3D); - - // Free the private drawable data - free(ctx->glPriv); - ctx->glPriv = NULL; - - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldCreatePrivateGlobals_DX(void) -{ - ZeroMemory(&dx8Globals, sizeof(dx8Globals)); - - // Load d3d8.dll - dx8Globals.hD3D8DLL = LoadLibrary("D3D8.DLL"); - if (dx8Globals.hD3D8DLL == NULL) - return FALSE; - - // Now try and obtain Direct3DCreate8 - dx8Globals.fnDirect3DCreate8 = (FNDIRECT3DCREATE8)GetProcAddress(dx8Globals.hD3D8DLL, "Direct3DCreate8"); - if (dx8Globals.fnDirect3DCreate8 == NULL) { - FreeLibrary(dx8Globals.hD3D8DLL); - return FALSE; - } - - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldDestroyPrivateGlobals_DX(void) -{ - if (dx8Globals.bDirect3DDevice) { - SAFE_RELEASE(dx8Globals.pDev); - dx8Globals.bDirect3DDevice = FALSE; - } - if (dx8Globals.bDirect3D) { - SAFE_RELEASE(dx8Globals.pD3D); - dx8Globals.bDirect3D = FALSE; - } - - FreeLibrary(dx8Globals.hD3D8DLL); - dx8Globals.hD3D8DLL = NULL; - dx8Globals.fnDirect3DCreate8 = NULL; - - return TRUE; -} - -//--------------------------------------------------------------------------- - -static void _BitsFromDisplayFormat( - D3DFORMAT fmt, - BYTE *cColorBits, - BYTE *cRedBits, - BYTE *cGreenBits, - BYTE *cBlueBits, - BYTE *cAlphaBits) -{ - switch (fmt) { - case D3DFMT_X1R5G5B5: - *cColorBits = 16; - *cRedBits = 5; - *cGreenBits = 5; - *cBlueBits = 5; - *cAlphaBits = 0; - return; - case D3DFMT_R5G6B5: - *cColorBits = 16; - *cRedBits = 5; - *cGreenBits = 6; - *cBlueBits = 5; - *cAlphaBits = 0; - return; - case D3DFMT_X8R8G8B8: - *cColorBits = 32; - *cRedBits = 8; - *cGreenBits = 8; - *cBlueBits = 8; - *cAlphaBits = 0; - return; - case D3DFMT_A8R8G8B8: - *cColorBits = 32; - *cRedBits = 8; - *cGreenBits = 8; - *cBlueBits = 8; - *cAlphaBits = 8; - return; - } - - // Should not get here! - *cColorBits = 32; - *cRedBits = 8; - *cGreenBits = 8; - *cBlueBits = 8; - *cAlphaBits = 0; -} - -//--------------------------------------------------------------------------- - -static void _BitsFromDepthStencilFormat( - D3DFORMAT fmt, - BYTE *cDepthBits, - BYTE *cStencilBits) -{ - // NOTE: GL expects either 32 or 16 as depth bits. - switch (fmt) { - case D3DFMT_D32: - *cDepthBits = 32; - *cStencilBits = 0; - return; - case D3DFMT_D15S1: - *cDepthBits = 16; - *cStencilBits = 1; - return; - case D3DFMT_D24S8: - *cDepthBits = 32; - *cStencilBits = 8; - return; - case D3DFMT_D16: - *cDepthBits = 16; - *cStencilBits = 0; - return; - case D3DFMT_D24X8: - *cDepthBits = 32; - *cStencilBits = 0; - return; - case D3DFMT_D24X4S4: - *cDepthBits = 32; - *cStencilBits = 4; - return; - } -} - -//--------------------------------------------------------------------------- - -BOOL gldBuildPixelformatList_DX(void) -{ - D3DDISPLAYMODE d3ddm; - D3DFORMAT fmt[6]; - IDirect3D8 *pD3D = NULL; - HRESULT hr; - int nSupportedFormats = 0; - int i; - DGL_pixelFormat *pPF; - BYTE cColorBits, cRedBits, cGreenBits, cBlueBits, cAlphaBits; -// char buf[128]; -// char cat[8]; - - // Direct3D (SW or HW) - // These are arranged so that 'best' pixelformat - // is higher in the list (for ChoosePixelFormat). - const D3DFORMAT DepthStencil[6] = { - D3DFMT_D15S1, - D3DFMT_D16, - D3DFMT_D24X8, - D3DFMT_D24X4S4, - D3DFMT_D24S8, - D3DFMT_D32, - }; - - // Dump DX version - ddlogMessage(GLDLOG_SYSTEM, "DirectX Version : 8.0\n"); - - // Release any existing pixelformat list - if (glb.lpPF) { - free(glb.lpPF); - } - - glb.nPixelFormatCount = 0; - glb.lpPF = NULL; - - // - // Pixelformats for Direct3D (SW or HW) rendering - // - - // Get a Direct3D 8.0 interface - pD3D = dx8Globals.fnDirect3DCreate8(D3D_SDK_VERSION_DX8_SUPPORT_WIN95); - if (!pD3D) { - return FALSE; - } - - // We will use the display mode format when finding compliant - // rendertarget/depth-stencil surfaces. - hr = IDirect3D8_GetAdapterDisplayMode(pD3D, glb.dwAdapter, &d3ddm); - if (FAILED(hr)) { - IDirect3D8_Release(pD3D); - return FALSE; - } - - // Run through the possible formats and detect supported formats - for (i=0; i<6; i++) { - hr = IDirect3D8_CheckDeviceFormat( - pD3D, - glb.dwAdapter, - glb.dwDriver==GLDS_DRIVER_HAL ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF, - d3ddm.Format, - D3DUSAGE_DEPTHSTENCIL, - D3DRTYPE_SURFACE, - DepthStencil[i]); - if (FAILED(hr)) - // A failure here is not fatal. - continue; - - // Verify that the depth format is compatible. - hr = IDirect3D8_CheckDepthStencilMatch( - pD3D, - glb.dwAdapter, - glb.dwDriver==GLDS_DRIVER_HAL ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF, - d3ddm.Format, - d3ddm.Format, - DepthStencil[i]); - if (FAILED(hr)) - // A failure here is not fatal, just means depth-stencil - // format is not compatible with this display mode. - continue; - - fmt[nSupportedFormats++] = DepthStencil[i]; - } - - IDirect3D8_Release(pD3D); - - if (nSupportedFormats == 0) - return FALSE; // Bail: no compliant pixelformats - - // Total count of pixelformats is: - // (nSupportedFormats+1)*2 - glb.lpPF = (DGL_pixelFormat *)calloc((nSupportedFormats)*2, sizeof(DGL_pixelFormat)); - glb.nPixelFormatCount = (nSupportedFormats)*2; - if (glb.lpPF == NULL) { - glb.nPixelFormatCount = 0; - return FALSE; - } - - // Get a copy of pointer that we can alter - pPF = glb.lpPF; - - // Cache colour bits from display format - _BitsFromDisplayFormat(d3ddm.Format, &cColorBits, &cRedBits, &cGreenBits, &cBlueBits, &cAlphaBits); - - // - // Add single-buffer formats - // - - // Single-buffer, no depth-stencil buffer -/* memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); - pPF->pfd.dwFlags &= ~PFD_DOUBLEBUFFER; // Remove doublebuffer flag - pPF->pfd.cColorBits = cColorBits; - pPF->pfd.cRedBits = cRedBits; - pPF->pfd.cGreenBits = cGreenBits; - pPF->pfd.cBlueBits = cBlueBits; - pPF->pfd.cAlphaBits = cAlphaBits; - pPF->pfd.cDepthBits = 0; - pPF->pfd.cStencilBits = 0; - pPF->dwDriverData = D3DFMT_UNKNOWN; - pPF++;*/ - - for (i=0; i<nSupportedFormats; i++, pPF++) { - memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); - pPF->pfd.dwFlags &= ~PFD_DOUBLEBUFFER; // Remove doublebuffer flag - pPF->pfd.cColorBits = cColorBits; - pPF->pfd.cRedBits = cRedBits; - pPF->pfd.cGreenBits = cGreenBits; - pPF->pfd.cBlueBits = cBlueBits; - pPF->pfd.cAlphaBits = cAlphaBits; - _BitsFromDepthStencilFormat(fmt[i], &pPF->pfd.cDepthBits, &pPF->pfd.cStencilBits); - pPF->dwDriverData = fmt[i]; - } - - // - // Add double-buffer formats - // - -/* memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); - pPF->pfd.cColorBits = cColorBits; - pPF->pfd.cRedBits = cRedBits; - pPF->pfd.cGreenBits = cGreenBits; - pPF->pfd.cBlueBits = cBlueBits; - pPF->pfd.cAlphaBits = cAlphaBits; - pPF->pfd.cDepthBits = 0; - pPF->pfd.cStencilBits = 0; - pPF->dwDriverData = D3DFMT_UNKNOWN; - pPF++;*/ - - for (i=0; i<nSupportedFormats; i++, pPF++) { - memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); - pPF->pfd.cColorBits = cColorBits; - pPF->pfd.cRedBits = cRedBits; - pPF->pfd.cGreenBits = cGreenBits; - pPF->pfd.cBlueBits = cBlueBits; - pPF->pfd.cAlphaBits = cAlphaBits; - _BitsFromDepthStencilFormat(fmt[i], &pPF->pfd.cDepthBits, &pPF->pfd.cStencilBits); - pPF->dwDriverData = fmt[i]; - } - - // Popup warning message if non RGB color mode - { - // This is a hack. KeithH - HDC hdcDesktop = GetDC(NULL); - DWORD dwDisplayBitDepth = GetDeviceCaps(hdcDesktop, BITSPIXEL); - ReleaseDC(0, hdcDesktop); - if (dwDisplayBitDepth <= 8) { - ddlogPrintf(DDLOG_WARN, "Current Color Depth %d bpp is not supported", dwDisplayBitDepth); - MessageBox(NULL, szColorDepthWarning, "GLDirect", MB_OK | MB_ICONWARNING); - } - } - - // Mark list as 'current' - glb.bPixelformatsDirty = FALSE; - - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldInitialiseMesa_DX( - DGL_ctx *lpCtx) -{ - GLD_driver_dx8 *gld = NULL; - int MaxTextureSize, TextureLevels; - BOOL bSoftwareTnL; - - if (lpCtx == NULL) - return FALSE; - - gld = lpCtx->glPriv; - if (gld == NULL) - return FALSE; - - if (glb.bMultitexture) { - lpCtx->glCtx->Const.MaxTextureUnits = gld->d3dCaps8.MaxSimultaneousTextures; - // Only support MAX_TEXTURE_UNITS texture units. - // ** If this is altered then the FVF formats must be reviewed **. - if (lpCtx->glCtx->Const.MaxTextureUnits > GLD_MAX_TEXTURE_UNITS_DX8) - lpCtx->glCtx->Const.MaxTextureUnits = GLD_MAX_TEXTURE_UNITS_DX8; - } else { - // Multitexture override - lpCtx->glCtx->Const.MaxTextureUnits = 1; - } - - // max texture size - MaxTextureSize = min(gld->d3dCaps8.MaxTextureHeight, gld->d3dCaps8.MaxTextureWidth); - if (MaxTextureSize == 0) - MaxTextureSize = 256; // Sanity check - - // - // HACK!! - if (MaxTextureSize > 1024) - MaxTextureSize = 1024; // HACK - CLAMP TO 1024 - // HACK!! - // - - // Got to set MAX_TEXTURE_SIZE as max levels. - // Who thought this stupid idea up? ;) - TextureLevels = 0; - // Calculate power-of-two. - while (MaxTextureSize) { - TextureLevels++; - MaxTextureSize >>= 1; - } - lpCtx->glCtx->Const.MaxTextureLevels = (TextureLevels) ? TextureLevels : 8; - lpCtx->glCtx->Const.MaxDrawBuffers = 1; - - IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_LIGHTING, FALSE); - IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_CULLMODE, D3DCULL_NONE); - IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_DITHERENABLE, TRUE); - IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SHADEMODE, D3DSHADE_GOURAUD); - - IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_ZENABLE, - (lpCtx->lpPF->dwDriverData!=D3DFMT_UNKNOWN) ? D3DZB_TRUE : D3DZB_FALSE); - - // Set the view matrix - { - D3DXMATRIX vm; -#if 1 - D3DXMatrixIdentity(&vm); -#else - D3DXVECTOR3 Eye(0.0f, 0.0f, 0.0f); - D3DXVECTOR3 At(0.0f, 0.0f, -1.0f); - D3DXVECTOR3 Up(0.0f, 1.0f, 0.0f); - D3DXMatrixLookAtRH(&vm, &Eye, &At, &Up); - vm._31 = -vm._31; - vm._32 = -vm._32; - vm._33 = -vm._33; - vm._34 = -vm._34; -#endif - IDirect3DDevice8_SetTransform(gld->pDev, D3DTS_VIEW, &vm); - } - - if (gld->bHasHWTnL) { - if (glb.dwTnL == GLDS_TNL_DEFAULT) - bSoftwareTnL = FALSE; // HW TnL - else { - bSoftwareTnL = ((glb.dwTnL == GLDS_TNL_MESA) || (glb.dwTnL == GLDS_TNL_D3DSW)) ? TRUE : FALSE; - } - } else { - // No HW TnL, so no choice possible - bSoftwareTnL = TRUE; - } - IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, bSoftwareTnL); - -// Dump this in a Release build as well, now. -//#ifdef _DEBUG - ddlogPrintf(DDLOG_INFO, "HW TnL: %s", - gld->bHasHWTnL ? (bSoftwareTnL ? "Disabled" : "Enabled") : "Unavailable"); -//#endif - - gldEnableExtensions_DX8(lpCtx->glCtx); - gldInstallPipeline_DX8(lpCtx->glCtx); - gldSetupDriverPointers_DX8(lpCtx->glCtx); - - // Signal a complete state update - lpCtx->glCtx->Driver.UpdateState(lpCtx->glCtx, _NEW_ALL); - - // Start a scene - IDirect3DDevice8_BeginScene(gld->pDev); - lpCtx->bSceneStarted = TRUE; - - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldSwapBuffers_DX( - DGL_ctx *ctx, - HDC hDC, - HWND hWnd) -{ - HRESULT hr; - GLD_driver_dx8 *gld = NULL; - - if (ctx == NULL) - return FALSE; - - gld = ctx->glPriv; - if (gld == NULL) - return FALSE; - - if (ctx->bSceneStarted) { - IDirect3DDevice8_EndScene(gld->pDev); - ctx->bSceneStarted = FALSE; - } - - // Swap the buffers. hWnd may override the hWnd used for CreateDevice() - hr = IDirect3DDevice8_Present(gld->pDev, NULL, NULL, hWnd, NULL); - - IDirect3DDevice8_BeginScene(gld->pDev); - ctx->bSceneStarted = TRUE; - - return (FAILED(hr)) ? FALSE : TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldGetDisplayMode_DX( - DGL_ctx *ctx, - GLD_displayMode *glddm) -{ - D3DDISPLAYMODE d3ddm; - HRESULT hr; - GLD_driver_dx8 *lpCtx = NULL; - BYTE cColorBits, cRedBits, cGreenBits, cBlueBits, cAlphaBits; - - if ((glddm == NULL) || (ctx == NULL)) - return FALSE; - - lpCtx = ctx->glPriv; - if (lpCtx == NULL) - return FALSE; - - if (lpCtx->pD3D == NULL) - return FALSE; - - hr = IDirect3D8_GetAdapterDisplayMode(lpCtx->pD3D, glb.dwAdapter, &d3ddm); - if (FAILED(hr)) - return FALSE; - - // Get info from the display format - _BitsFromDisplayFormat(d3ddm.Format, - &cColorBits, &cRedBits, &cGreenBits, &cBlueBits, &cAlphaBits); - - glddm->Width = d3ddm.Width; - glddm->Height = d3ddm.Height; - glddm->BPP = cColorBits; - glddm->Refresh = d3ddm.RefreshRate; - - return TRUE; -} - -//--------------------------------------------------------------------------- - diff --git a/src/mesa/drivers/windows/gldirect/dx9/gld_driver_dx9.c b/src/mesa/drivers/windows/gldirect/dx9/gld_driver_dx9.c deleted file mode 100644 index c191564d6e..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx9/gld_driver_dx9.c +++ /dev/null @@ -1,1206 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: Driver interface code to Mesa -* -****************************************************************************/ - -//#include <windows.h> -#include "dglcontext.h" -#include "ddlog.h" -#include "gld_dx9.h" - -#include "glheader.h" -#include "context.h" -#include "colormac.h" -#include "depth.h" -#include "extensions.h" -#include "macros.h" -#include "matrix.h" -// #include "mem.h" -//#include "mmath.h" -#include "mtypes.h" -#include "texformat.h" -#include "teximage.h" -#include "texstore.h" -#include "vbo/vbo.h" -#include "swrast_setup/swrast_setup.h" -#include "swrast_setup/ss_context.h" -#include "tnl/tnl.h" -#include "tnl/t_context.h" -#include "tnl/t_pipeline.h" - -extern BOOL dglSwapBuffers(HDC hDC); - -// HACK: Hack the _33 member of the OpenGL perspective projection matrix -const float _fPersp_33 = 1.6f; - -//--------------------------------------------------------------------------- -// Internal functions -//--------------------------------------------------------------------------- - -void _gld_mesa_warning( - __GLcontext *gc, - char *str) -{ - // Intercept Mesa's internal warning mechanism - gldLogPrintf(GLDLOG_WARN, "Mesa warning: %s", str); -} - -//--------------------------------------------------------------------------- - -void _gld_mesa_fatal( - __GLcontext *gc, - char *str) -{ - // Intercept Mesa's internal fatal-message mechanism - gldLogPrintf(GLDLOG_CRITICAL, "Mesa FATAL: %s", str); - - // Mesa calls abort(0) here. - ddlogClose(); - exit(0); -} - -//--------------------------------------------------------------------------- - -D3DSTENCILOP _gldConvertStencilOp( - GLenum StencilOp) -{ - // Used by Stencil: pass, fail and zfail - - switch (StencilOp) { - case GL_KEEP: - return D3DSTENCILOP_KEEP; - case GL_ZERO: - return D3DSTENCILOP_ZERO; - case GL_REPLACE: - return D3DSTENCILOP_REPLACE; - case GL_INCR: - return D3DSTENCILOP_INCRSAT; - case GL_DECR: - return D3DSTENCILOP_DECRSAT; - case GL_INVERT: - return D3DSTENCILOP_INVERT; - case GL_INCR_WRAP_EXT: // GL_EXT_stencil_wrap - return D3DSTENCILOP_INCR; - case GL_DECR_WRAP_EXT: // GL_EXT_stencil_wrap - return D3DSTENCILOP_DECR; - } - -#ifdef _DEBUG - gldLogMessage(GLDLOG_ERROR, "_gldConvertStencilOp: Unknown StencilOp\n"); -#endif - - return D3DSTENCILOP_KEEP; -} - -//--------------------------------------------------------------------------- - -D3DCMPFUNC _gldConvertCompareFunc( - GLenum CmpFunc) -{ - // Used for Alpha func, depth func and stencil func. - - switch (CmpFunc) { - case GL_NEVER: - return D3DCMP_NEVER; - case GL_LESS: - return D3DCMP_LESS; - case GL_EQUAL: - return D3DCMP_EQUAL; - case GL_LEQUAL: - return D3DCMP_LESSEQUAL; - case GL_GREATER: - return D3DCMP_GREATER; - case GL_NOTEQUAL: - return D3DCMP_NOTEQUAL; - case GL_GEQUAL: - return D3DCMP_GREATEREQUAL; - case GL_ALWAYS: - return D3DCMP_ALWAYS; - }; - -#ifdef _DEBUG - gldLogMessage(GLDLOG_ERROR, "_gldConvertCompareFunc: Unknown CompareFunc\n"); -#endif - - return D3DCMP_ALWAYS; -} - -//--------------------------------------------------------------------------- - -D3DBLEND _gldConvertBlendFunc( - GLenum blend, - GLenum DefaultBlend) -{ - switch (blend) { - case GL_ZERO: - return D3DBLEND_ZERO; - case GL_ONE: - return D3DBLEND_ONE; - case GL_DST_COLOR: - return D3DBLEND_DESTCOLOR; - case GL_SRC_COLOR: - return D3DBLEND_SRCCOLOR; - case GL_ONE_MINUS_DST_COLOR: - return D3DBLEND_INVDESTCOLOR; - case GL_ONE_MINUS_SRC_COLOR: - return D3DBLEND_INVSRCCOLOR; - case GL_SRC_ALPHA: - return D3DBLEND_SRCALPHA; - case GL_ONE_MINUS_SRC_ALPHA: - return D3DBLEND_INVSRCALPHA; - case GL_DST_ALPHA: - return D3DBLEND_DESTALPHA; - case GL_ONE_MINUS_DST_ALPHA: - return D3DBLEND_INVDESTALPHA; - case GL_SRC_ALPHA_SATURATE: - return D3DBLEND_SRCALPHASAT; - } - -#ifdef _DEBUG - gldLogMessage(GLDLOG_ERROR, "_gldConvertBlendFunc: Unknown BlendFunc\n"); -#endif - - return DefaultBlend; -} - -//--------------------------------------------------------------------------- -// Misc. functions -//--------------------------------------------------------------------------- - -void gld_Noop_DX9( - GLcontext *ctx) -{ -#ifdef _DEBUG - gldLogMessage(GLDLOG_ERROR, "gld_Noop called!\n"); -#endif -} - -//--------------------------------------------------------------------------- - -void gld_Error_DX9( - GLcontext *ctx) -{ -#ifdef _DEBUG - // Quite useless. -// gldLogMessage(GLDLOG_ERROR, "ctx->Driver.Error called!\n"); -#endif -} - -//--------------------------------------------------------------------------- -// Required Mesa functions -//--------------------------------------------------------------------------- - -static GLboolean gld_set_draw_buffer_DX9( - GLcontext *ctx, - GLenum mode) -{ - (void) ctx; - if ((mode==GL_FRONT_LEFT) || (mode == GL_BACK_LEFT)) { - return GL_TRUE; - } - else { - return GL_FALSE; - } -} - -//--------------------------------------------------------------------------- - -static void gld_set_read_buffer_DX9( - GLcontext *ctx, - GLframebuffer *buffer, - GLenum mode) -{ - /* separate read buffer not supported */ -/* - ASSERT(buffer == ctx->DrawBuffer); - ASSERT(mode == GL_FRONT_LEFT); -*/ -} - -//--------------------------------------------------------------------------- - -void gld_Clear_DX9( - GLcontext *ctx, - GLbitfield mask, - GLboolean all, - GLint x, - GLint y, - GLint width, - GLint height) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - DWORD dwFlags = 0; - D3DCOLOR Color = 0; - float Z = 0.0f; - DWORD Stencil = 0; - D3DRECT d3dClearRect; - - // TODO: Colourmask - const GLuint *colorMask = (GLuint *) &ctx->Color.ColorMask; - - if (!gld->pDev) - return; - - if (mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT)) { - GLubyte col[4]; - CLAMPED_FLOAT_TO_UBYTE(col[0], ctx->Color.ClearColor[0]); - CLAMPED_FLOAT_TO_UBYTE(col[1], ctx->Color.ClearColor[1]); - CLAMPED_FLOAT_TO_UBYTE(col[2], ctx->Color.ClearColor[2]); - CLAMPED_FLOAT_TO_UBYTE(col[3], ctx->Color.ClearColor[3]); - dwFlags |= D3DCLEAR_TARGET; - Color = D3DCOLOR_RGBA(col[0], col[1], col[2], col[3]); - } - - if (mask & DD_DEPTH_BIT) { - // D3D8 will fail the Clear call if we try and clear a - // depth buffer and we haven't created one. - // Also, some apps try and clear a depth buffer, - // when a depth buffer hasn't been requested by the app. - if (ctx->Visual.depthBits == 0) { - mask &= ~DD_DEPTH_BIT; // Remove depth bit from mask - } else { - dwFlags |= D3DCLEAR_ZBUFFER; - Z = ctx->Depth.Clear; - } - } - - if (mask & DD_STENCIL_BIT) { - if (ctx->Visual.stencilBits == 0) { - // No stencil bits in depth buffer - mask &= ~DD_STENCIL_BIT; // Remove stencil bit from mask - } else { - dwFlags |= D3DCLEAR_STENCIL; - Stencil = ctx->Stencil.Clear; - } - } - - // Some apps do really weird things with the rect, such as Quake3. - if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0)) { - all = GL_TRUE; - } - - if (!all) { - // Calculate clear subrect - d3dClearRect.x1 = x; - d3dClearRect.y1 = gldCtx->dwHeight - (y + height); - d3dClearRect.x2 = x + width; - d3dClearRect.y2 = d3dClearRect.y1 + height; -// gldLogPrintf(GLDLOG_INFO, "Rect %d,%d %d,%d", x,y,width,height); - } - - // dwFlags will be zero if there's nothing to clear - if (dwFlags) { - _GLD_DX9_DEV(Clear( - gld->pDev, - all ? 0 : 1, - all ? NULL : &d3dClearRect, - dwFlags, - Color, Z, Stencil)); - } - - if (mask & DD_ACCUM_BIT) { - // Clear accumulation buffer - } -} - -//--------------------------------------------------------------------------- - -// Mesa 5: Parameter change -static void gld_buffer_size_DX9( -// GLcontext *ctx, - GLframebuffer *fb, - GLuint *width, - GLuint *height) -{ -// GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - - *width = fb->Width; // gldCtx->dwWidth; - *height = fb->Height; // gldCtx->dwHeight; -} - -//--------------------------------------------------------------------------- - -static void gld_Finish_DX9( - GLcontext *ctx) -{ -} - -//--------------------------------------------------------------------------- - -static void gld_Flush_DX9( - GLcontext *ctx) -{ - GLD_context *gld = GLD_GET_CONTEXT(ctx); - - // TODO: Detect apps that glFlush() then SwapBuffers() ? - - if (gld->EmulateSingle) { - // Emulating a single-buffered context. - // [Direct3D doesn't allow rendering to front buffer] - dglSwapBuffers(gld->hDC); - } -} - -//--------------------------------------------------------------------------- - -void gld_NEW_STENCIL( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - // Two-sided stencil. New for Mesa 5 - const GLuint uiFace = 0UL; - - struct gl_stencil_attrib *pStencil = &ctx->Stencil; - - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_STENCILENABLE, pStencil->Enabled ? TRUE : FALSE)); - if (pStencil->Enabled) { - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_STENCILFUNC, _gldConvertCompareFunc(pStencil->Function[uiFace]))); - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_STENCILREF, pStencil->Ref[uiFace])); - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_STENCILMASK, pStencil->ValueMask[uiFace])); - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_STENCILWRITEMASK, pStencil->WriteMask[uiFace])); - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_STENCILFAIL, _gldConvertStencilOp(pStencil->FailFunc[uiFace]))); - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_STENCILZFAIL, _gldConvertStencilOp(pStencil->ZFailFunc[uiFace]))); - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_STENCILPASS, _gldConvertStencilOp(pStencil->ZPassFunc[uiFace]))); - } -} - -//--------------------------------------------------------------------------- - -void gld_NEW_COLOR( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - DWORD dwFlags = 0; - D3DBLEND src; - D3DBLEND dest; - - // Alpha func - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_ALPHAFUNC, _gldConvertCompareFunc(ctx->Color.AlphaFunc))); - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_ALPHAREF, (DWORD)ctx->Color.AlphaRef)); - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_ALPHATESTENABLE, ctx->Color.AlphaEnabled)); - - // Blend func - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_ALPHABLENDENABLE, ctx->Color.BlendEnabled)); - src = _gldConvertBlendFunc(ctx->Color.BlendSrcRGB, GL_ONE); - dest = _gldConvertBlendFunc(ctx->Color.BlendDstRGB, GL_ZERO); - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_SRCBLEND, src)); - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_DESTBLEND, dest)); - - // Color mask - if (ctx->Color.ColorMask[0]) dwFlags |= D3DCOLORWRITEENABLE_RED; - if (ctx->Color.ColorMask[1]) dwFlags |= D3DCOLORWRITEENABLE_GREEN; - if (ctx->Color.ColorMask[2]) dwFlags |= D3DCOLORWRITEENABLE_BLUE; - if (ctx->Color.ColorMask[3]) dwFlags |= D3DCOLORWRITEENABLE_ALPHA; - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_COLORWRITEENABLE, dwFlags)); -} - -//--------------------------------------------------------------------------- - -void gld_NEW_DEPTH( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_ZENABLE, ctx->Depth.Test ? D3DZB_TRUE : D3DZB_FALSE)); - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_ZFUNC, _gldConvertCompareFunc(ctx->Depth.Func))); - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_ZWRITEENABLE, ctx->Depth.Mask ? TRUE : FALSE)); -} - -//--------------------------------------------------------------------------- - -void gld_NEW_POLYGON( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - D3DFILLMODE d3dFillMode = D3DFILL_SOLID; - D3DCULL d3dCullMode = D3DCULL_NONE; - float fOffset = 0; // Changed from int to float for DX9 - - // Fillmode - switch (ctx->Polygon.FrontMode) { - case GL_POINT: - d3dFillMode = D3DFILL_POINT; - break; - case GL_LINE: - d3dFillMode = D3DFILL_WIREFRAME; - break; - case GL_FILL: - d3dFillMode = D3DFILL_SOLID; - break; - } - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FILLMODE, d3dFillMode)); - - if (ctx->Polygon.CullFlag) { - switch (ctx->Polygon.CullFaceMode) { - case GL_BACK: - if (ctx->Polygon.FrontFace == GL_CCW) - d3dCullMode = D3DCULL_CW; - else - d3dCullMode = D3DCULL_CCW; - break; - case GL_FRONT: - if (ctx->Polygon.FrontFace == GL_CCW) - d3dCullMode = D3DCULL_CCW; - else - d3dCullMode = D3DCULL_CW; - break; - case GL_FRONT_AND_BACK: - d3dCullMode = D3DCULL_NONE; - break; - default: - break; - } - } else { - d3dCullMode = D3DCULL_NONE; - } -// d3dCullMode = D3DCULL_NONE; // FOR DEBUGGING - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_CULLMODE, d3dCullMode)); - - // Polygon offset - // ZBIAS ranges from 0 to 16 and can only move towards the viewer - // Mesa5: ctx->Polygon._OffsetAny removed - if (ctx->Polygon.OffsetFill) { - fOffset = ctx->Polygon.OffsetUnits; -// if (iOffset < 0.0f) -// iOffset = -iOffset; -// else -// iOffset = 0.0f; // D3D can't push away - } - // NOTE: SetRenderState() required a DWORD, so need to cast - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_DEPTHBIAS, *((DWORD*)&fOffset))); -} - -//--------------------------------------------------------------------------- - -void gld_NEW_FOG( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - D3DCOLOR d3dFogColour; - D3DFOGMODE d3dFogMode = D3DFOG_LINEAR; - - // TODO: Fog is calculated seperately in the Mesa pipeline - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGENABLE, FALSE)); - return; - - // Fog enable - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGENABLE, ctx->Fog.Enabled)); - if (!ctx->Fog.Enabled) { - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGTABLEMODE, D3DFOG_NONE)); - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGVERTEXMODE, D3DFOG_NONE)); - return; // If disabled, don't bother setting any fog state - } - - // Fog colour - d3dFogColour = D3DCOLOR_COLORVALUE( ctx->Fog.Color[0], - ctx->Fog.Color[1], - ctx->Fog.Color[2], - ctx->Fog.Color[3]); - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGCOLOR, d3dFogColour)); - - // Fog density - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGDENSITY, *((DWORD*) (&ctx->Fog.Density)))); - - // Fog start - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGSTART, *((DWORD*) (&ctx->Fog.Start)))); - - // Fog end - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGEND, *((DWORD*) (&ctx->Fog.End)))); - - // Fog mode - switch (ctx->Fog.Mode) { - case GL_LINEAR: - d3dFogMode = D3DFOG_LINEAR; - break; - case GL_EXP: - d3dFogMode = D3DFOG_EXP; - break; - case GL_EXP2: - d3dFogMode = D3DFOG_EXP2; - break; - } - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGTABLEMODE, d3dFogMode)); - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGVERTEXMODE, D3DFOG_NONE)); -} - -//--------------------------------------------------------------------------- - -void gld_NEW_LIGHT( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - DWORD dwSpecularEnable; - - // Shademode - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_SHADEMODE, (ctx->Light.ShadeModel == GL_SMOOTH) ? D3DSHADE_GOURAUD : D3DSHADE_FLAT)); - - // Separate specular colour - if (ctx->Light.Enabled) - dwSpecularEnable = (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) ? TRUE: FALSE; - else - dwSpecularEnable = FALSE; - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_SPECULARENABLE, dwSpecularEnable)); -} - -//--------------------------------------------------------------------------- - -void gld_NEW_MODELVIEW( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - D3DMATRIX m; - //GLfloat *pM = ctx->ModelView.m; - // Mesa5: Model-view is now a stack - GLfloat *pM = ctx->ModelviewMatrixStack.Top->m; - m._11 = pM[0]; - m._12 = pM[1]; - m._13 = pM[2]; - m._14 = pM[3]; - m._21 = pM[4]; - m._22 = pM[5]; - m._23 = pM[6]; - m._24 = pM[7]; - m._31 = pM[8]; - m._32 = pM[9]; - m._33 = pM[10]; - m._34 = pM[11]; - m._41 = pM[12]; - m._42 = pM[13]; - m._43 = pM[14]; - m._44 = pM[15]; - - gld->matModelView = m; -} - -//--------------------------------------------------------------------------- - -void gld_NEW_PROJECTION( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - D3DMATRIX m; - //GLfloat *pM = ctx->ProjectionMatrix.m; - // Mesa 5: Now a stack - GLfloat *pM = ctx->ProjectionMatrixStack.Top->m; - m._11 = pM[0]; - m._12 = pM[1]; - m._13 = pM[2]; - m._14 = pM[3]; - - m._21 = pM[4]; - m._22 = pM[5]; - m._23 = pM[6]; - m._24 = pM[7]; - - m._31 = pM[8]; - m._32 = pM[9]; - m._33 = pM[10] / _fPersp_33; // / 1.6f; - m._34 = pM[11]; - - m._41 = pM[12]; - m._42 = pM[13]; - m._43 = pM[14] / 2.0f; - m._44 = pM[15]; - - gld->matProjection = m; -} - -//--------------------------------------------------------------------------- -/* -void gldFrustumHook_DX9( - GLdouble left, - GLdouble right, - GLdouble bottom, - GLdouble top, - GLdouble nearval, - GLdouble farval) -{ - GET_CURRENT_CONTEXT(ctx); - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - // Pass values on to Mesa first (in case we mess with them) - _mesa_Frustum(left, right, bottom, top, nearval, farval); - - _fPersp_33 = farval / (nearval - farval); - -// ddlogPrintf(GLDLOG_SYSTEM, "Frustum: %f", farval/nearval); -} - -//--------------------------------------------------------------------------- - -void gldOrthoHook_DX9( - GLdouble left, - GLdouble right, - GLdouble bottom, - GLdouble top, - GLdouble nearval, - GLdouble farval) -{ - GET_CURRENT_CONTEXT(ctx); - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - // Pass values on to Mesa first (in case we mess with them) - _mesa_Ortho(left, right, bottom, top, nearval, farval); - - _fPersp_33 = 1.6f; - -// ddlogPrintf(GLDLOG_SYSTEM, "Ortho: %f", farval/nearval); -} -*/ -//--------------------------------------------------------------------------- - -void gld_NEW_VIEWPORT( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - D3DVIEWPORT9 d3dvp; -// GLint x, y; -// GLsizei w, h; - - // Set depth range - _GLD_DX9_DEV(GetViewport(gld->pDev, &d3dvp)); - // D3D can't do Quake1/Quake2 z-trick - if (ctx->Viewport.Near <= ctx->Viewport.Far) { - d3dvp.MinZ = ctx->Viewport.Near; - d3dvp.MaxZ = ctx->Viewport.Far; - } else { - d3dvp.MinZ = ctx->Viewport.Far; - d3dvp.MaxZ = ctx->Viewport.Near; - } -/* x = ctx->Viewport.X; - y = ctx->Viewport.Y; - w = ctx->Viewport.Width; - h = ctx->Viewport.Height; - if (x < 0) x = 0; - if (y < 0) y = 0; - if (w > gldCtx->dwWidth) w = gldCtx->dwWidth; - if (h > gldCtx->dwHeight) h = gldCtx->dwHeight; - // Ditto for D3D viewport dimensions - if (w+x > gldCtx->dwWidth) w = gldCtx->dwWidth-x; - if (h+y > gldCtx->dwHeight) h = gldCtx->dwHeight-y; - d3dvp.X = x; - d3dvp.Y = gldCtx->dwHeight - (y + h); - d3dvp.Width = w; - d3dvp.Height = h;*/ - _GLD_DX9_DEV(SetViewport(gld->pDev, &d3dvp)); - -// gld->fFlipWindowY = (float)gldCtx->dwHeight; -} - -//--------------------------------------------------------------------------- - -void gld_NEW_SCISSOR( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - // Bail if IHV driver cannot scissor - if (!gld->bCanScissor) - return; - - // Set scissor rect - if (ctx->Scissor.Enabled) { - RECT rcRect; - // Keep in mind that RECT's need an extra row and column - rcRect.left = ctx->Scissor.X; - rcRect.right = ctx->Scissor.X + ctx->Scissor.Width; // + 1; - rcRect.top = gldCtx->dwHeight - (ctx->Scissor.Y + ctx->Scissor.Height); - rcRect.bottom = rcRect.top + ctx->Scissor.Height; - IDirect3DDevice9_SetScissorRect(gld->pDev, &rcRect); - } - - // Enable/disable scissor as required - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_SCISSORTESTENABLE, ctx->Scissor.Enabled)); -} - -//--------------------------------------------------------------------------- - -__inline BOOL _gldAnyEvalEnabled( - GLcontext *ctx) -{ - struct gl_eval_attrib *eval = &ctx->Eval; - - if ((eval->AutoNormal) || - (eval->Map1Color4) || - (eval->Map1Index) || - (eval->Map1Normal) || - (eval->Map1TextureCoord1) || - (eval->Map1TextureCoord2) || - (eval->Map1TextureCoord3) || - (eval->Map1TextureCoord4) || - (eval->Map1Vertex3) || - (eval->Map1Vertex4) || - (eval->Map2Color4) || - (eval->Map2Index) || - (eval->Map2Normal) || - (eval->Map2TextureCoord1) || - (eval->Map2TextureCoord2) || - (eval->Map2TextureCoord3) || - (eval->Map2TextureCoord4) || - (eval->Map2Vertex3) || - (eval->Map2Vertex4) - ) - return TRUE; - - return FALSE; -} - -//--------------------------------------------------------------------------- - -BOOL _gldChooseInternalPipeline( - GLcontext *ctx, - GLD_driver_dx9 *gld) -{ -// return TRUE; // DEBUGGING: ALWAYS USE MESA -// return FALSE; // DEBUGGING: ALWAYS USE D3D - - if ((glb.dwTnL == GLDS_TNL_MESA) || (gld->bHasHWTnL == FALSE)) - { - gld->PipelineUsage.qwMesa.QuadPart++; - return TRUE; // Force Mesa TnL - } - - if ((ctx->Light.Enabled) || - (1) || - (ctx->Texture._TexGenEnabled) || - (ctx->Texture._TexMatEnabled) || -// (ctx->Transform._AnyClip) || - (ctx->Scissor.Enabled) || - _gldAnyEvalEnabled(ctx) // Put this last so we can early-out - ) - { - gld->PipelineUsage.qwMesa.QuadPart++; - return TRUE; - } - - gld->PipelineUsage.qwD3DFVF.QuadPart++; - return FALSE; - -/* // Force Mesa pipeline? - if (glb.dwTnL == GLDS_TNL_MESA) { - gld->PipelineUsage.dwMesa.QuadPart++; - return GLD_PIPELINE_MESA; - } - - // Test for functionality not exposed in the D3D pathways - if ((ctx->Texture._GenFlags)) { - gld->PipelineUsage.dwMesa.QuadPart++; - return GLD_PIPELINE_MESA; - } - - // Now decide if vertex shader can be used. - // If two sided lighting is enabled then we must either - // use Mesa TnL or the vertex shader - if (ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) { - if (gld->VStwosidelight.hShader && !ctx->Fog.Enabled) { - // Use Vertex Shader - gld->PipelineUsage.dwD3D2SVS.QuadPart++; - return GLD_PIPELINE_D3D_VS_TWOSIDE; - } else { - // Use Mesa TnL - gld->PipelineUsage.dwMesa.QuadPart++; - return GLD_PIPELINE_MESA; - } - } - - // Must be D3D fixed-function pipeline - gld->PipelineUsage.dwD3DFVF.QuadPart++; - return GLD_PIPELINE_D3D_FVF; -*/ -} - -//--------------------------------------------------------------------------- - -void gld_update_state_DX9( - GLcontext *ctx, - GLuint new_state) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - TNLcontext *tnl = TNL_CONTEXT(ctx); - GLD_pb_dx9 *gldPB; - - if (!gld || !gld->pDev) - return; - - _swsetup_InvalidateState( ctx, new_state ); - _vbo_InvalidateState( ctx, new_state ); - _tnl_InvalidateState( ctx, new_state ); - - // SetupIndex will be used in the pipelines for choosing setup function - if ((ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE | DD_SEPARATE_SPECULAR)) || - (ctx->Fog.Enabled)) - { - if (ctx->_TriangleCaps & DD_FLATSHADE) - gld->iSetupFunc = GLD_SI_FLAT_EXTRAS; - else - gld->iSetupFunc = GLD_SI_SMOOTH_EXTRAS; - } else { - if (ctx->_TriangleCaps & DD_FLATSHADE) - gld->iSetupFunc = GLD_SI_FLAT; // Setup flat shade + texture - else - gld->iSetupFunc = GLD_SI_SMOOTH; // Setup smooth shade + texture - } - - gld->bUseMesaTnL = _gldChooseInternalPipeline(ctx, gld); - if (gld->bUseMesaTnL) { - gldPB = &gld->PB2d; - _GLD_DX9_DEV(SetSoftwareVertexProcessing(gld->pDev, TRUE)); - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_CLIPPING, FALSE)); - _GLD_DX9_DEV(SetVertexShader(gld->pDev, NULL)); - _GLD_DX9_DEV(SetFVF(gld->pDev, gldPB->dwFVF)); - } else { - gldPB = &gld->PB3d; - _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_CLIPPING, TRUE)); -// if (gld->TnLPipeline == GLD_PIPELINE_D3D_VS_TWOSIDE) { -// _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, !gld->VStwosidelight.bHardware)); -// _GLD_DX9_DEV(SetVertexShader(gld->pDev, gld->VStwosidelight.hShader)); -// } else { -// _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, !gld->bHasHWTnL)); - _GLD_DX9_DEV(SetSoftwareVertexProcessing(gld->pDev, !gld->bHasHWTnL)); - _GLD_DX9_DEV(SetVertexShader(gld->pDev, NULL)); - _GLD_DX9_DEV(SetFVF(gld->pDev, gldPB->dwFVF)); -// } - } - -#define _GLD_TEST_STATE(a) \ - if (new_state & (a)) { \ - gld##a(ctx); \ - new_state &= ~(a); \ - } - -#define _GLD_TEST_STATE_DX9(a) \ - if (new_state & (a)) { \ - gld##a##_DX9(ctx); \ - new_state &= ~(a); \ - } - -#define _GLD_IGNORE_STATE(a) new_state &= ~(a); - -// if (!gld->bUseMesaTnL) { - // Not required if Mesa is doing the TnL. - // Problem: If gld->bUseMesaTnL is TRUE when these are signaled, - // then we'll miss updating the D3D TnL pipeline. - // Therefore, don't test for gld->bUseMesaTnL - _GLD_TEST_STATE(_NEW_MODELVIEW); - _GLD_TEST_STATE(_NEW_PROJECTION); -// } - - _GLD_TEST_STATE_DX9(_NEW_TEXTURE); // extern, so guard with _DX9 - _GLD_TEST_STATE(_NEW_COLOR); - _GLD_TEST_STATE(_NEW_DEPTH); - _GLD_TEST_STATE(_NEW_POLYGON); - _GLD_TEST_STATE(_NEW_STENCIL); - _GLD_TEST_STATE(_NEW_FOG); - _GLD_TEST_STATE(_NEW_LIGHT); - _GLD_TEST_STATE(_NEW_VIEWPORT); - - _GLD_IGNORE_STATE(_NEW_TRANSFORM); - - // Scissor Test: New for DX9 - _GLD_TEST_STATE(_NEW_SCISSOR); - -// Stubs for future use. -/* _GLD_TEST_STATE(_NEW_TEXTURE_MATRIX); - _GLD_TEST_STATE(_NEW_COLOR_MATRIX); - _GLD_TEST_STATE(_NEW_ACCUM); - _GLD_TEST_STATE(_NEW_EVAL); - _GLD_TEST_STATE(_NEW_HINT); - _GLD_TEST_STATE(_NEW_LINE); - _GLD_TEST_STATE(_NEW_PIXEL); - _GLD_TEST_STATE(_NEW_POINT); - _GLD_TEST_STATE(_NEW_POLYGONSTIPPLE); - _GLD_TEST_STATE(_NEW_PACKUNPACK); - _GLD_TEST_STATE(_NEW_ARRAY); - _GLD_TEST_STATE(_NEW_RENDERMODE); - _GLD_TEST_STATE(_NEW_BUFFERS); - _GLD_TEST_STATE(_NEW_MULTISAMPLE); -*/ - -// For debugging. -#if 0 -#define _GLD_TEST_UNHANDLED_STATE(a) \ - if (new_state & (a)) { \ - gldLogMessage(GLDLOG_ERROR, "Unhandled " #a "\n"); \ - } - _GLD_TEST_UNHANDLED_STATE(_NEW_TEXTURE_MATRIX); - _GLD_TEST_UNHANDLED_STATE(_NEW_COLOR_MATRIX); - _GLD_TEST_UNHANDLED_STATE(_NEW_ACCUM); - _GLD_TEST_UNHANDLED_STATE(_NEW_EVAL); - _GLD_TEST_UNHANDLED_STATE(_NEW_HINT); - _GLD_TEST_UNHANDLED_STATE(_NEW_LINE); - _GLD_TEST_UNHANDLED_STATE(_NEW_PIXEL); - _GLD_TEST_UNHANDLED_STATE(_NEW_POINT); - _GLD_TEST_UNHANDLED_STATE(_NEW_POLYGONSTIPPLE); -// _GLD_TEST_UNHANDLED_STATE(_NEW_SCISSOR); - _GLD_TEST_UNHANDLED_STATE(_NEW_PACKUNPACK); - _GLD_TEST_UNHANDLED_STATE(_NEW_ARRAY); - _GLD_TEST_UNHANDLED_STATE(_NEW_RENDERMODE); - _GLD_TEST_UNHANDLED_STATE(_NEW_BUFFERS); - _GLD_TEST_UNHANDLED_STATE(_NEW_MULTISAMPLE); -#undef _GLD_UNHANDLED_STATE -#endif - -#undef _GLD_TEST_STATE -} - -//--------------------------------------------------------------------------- -// Viewport -//--------------------------------------------------------------------------- - -void gld_Viewport_DX9( - GLcontext *ctx, - GLint x, - GLint y, - GLsizei w, - GLsizei h) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - D3DVIEWPORT9 d3dvp; - - if (!gld || !gld->pDev) - return; - - // This is a hack. When the app is minimized, Mesa passes - // w=1 and h=1 for viewport dimensions. Without this test - // we get a GPF in gld_wgl_resize_buffers(). - if ((w==1) && (h==1)) - return; - - // Call ResizeBuffersMESA. This function will early-out - // if no resize is needed. - //ctx->Driver.ResizeBuffersMESA(ctx); - // Mesa 5: Changed parameters - ctx->Driver.ResizeBuffers(gldCtx->glBuffer); - -#if 0 - ddlogPrintf(GLDLOG_SYSTEM, ">> Viewport x=%d y=%d w=%d h=%d", x,y,w,h); -#endif - - // ** D3D viewport must not be outside the render target surface ** - // Sanity check the GL viewport dimensions - if (x < 0) x = 0; - if (y < 0) y = 0; - if (w > gldCtx->dwWidth) w = gldCtx->dwWidth; - if (h > gldCtx->dwHeight) h = gldCtx->dwHeight; - // Ditto for D3D viewport dimensions - if (w+x > gldCtx->dwWidth) w = gldCtx->dwWidth-x; - if (h+y > gldCtx->dwHeight) h = gldCtx->dwHeight-y; - - d3dvp.X = x; - d3dvp.Y = gldCtx->dwHeight - (y + h); - d3dvp.Width = w; - d3dvp.Height = h; - if (ctx->Viewport.Near <= ctx->Viewport.Far) { - d3dvp.MinZ = ctx->Viewport.Near; - d3dvp.MaxZ = ctx->Viewport.Far; - } else { - d3dvp.MinZ = ctx->Viewport.Far; - d3dvp.MaxZ = ctx->Viewport.Near; - } - - // TODO: DEBUGGING -// d3dvp.MinZ = 0.0f; -// d3dvp.MaxZ = 1.0f; - - _GLD_DX9_DEV(SetViewport(gld->pDev, &d3dvp)); - -} - -//--------------------------------------------------------------------------- - -extern BOOL dglWglResizeBuffers(GLcontext *ctx, BOOL bDefaultDriver); - -// Mesa 5: Parameter change -void gldResizeBuffers_DX9( -// GLcontext *ctx) - GLframebuffer *fb) -{ - GET_CURRENT_CONTEXT(ctx); - dglWglResizeBuffers(ctx, TRUE); -} - -//--------------------------------------------------------------------------- -#ifdef _DEBUG -// This is only for debugging. -// To use, plug into ctx->Driver.Enable pointer below. -void gld_Enable( - GLcontext *ctx, - GLenum e, - GLboolean b) -{ - char buf[1024]; - sprintf(buf, "Enable: %s (%s)\n", _mesa_lookup_enum_by_nr(e), b?"TRUE":"FALSE"); - ddlogMessage(DDLOG_SYSTEM, buf); -} -#endif -//--------------------------------------------------------------------------- -// Driver pointer setup -//--------------------------------------------------------------------------- - -extern const GLubyte* _gldGetStringGeneric(GLcontext*, GLenum); - -void gldSetupDriverPointers_DX9( - GLcontext *ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - TNLcontext *tnl = TNL_CONTEXT(ctx); - - // Mandatory functions - ctx->Driver.GetString = _gldGetStringGeneric; - ctx->Driver.UpdateState = gld_update_state_DX9; - ctx->Driver.Clear = gld_Clear_DX9; - ctx->Driver.DrawBuffer = gld_set_draw_buffer_DX9; - ctx->Driver.GetBufferSize = gld_buffer_size_DX9; - ctx->Driver.Finish = gld_Finish_DX9; - ctx->Driver.Flush = gld_Flush_DX9; - ctx->Driver.Error = gld_Error_DX9; - - // Hardware accumulation buffer - ctx->Driver.Accum = NULL; // TODO: gld_Accum; - - // Bitmap functions - ctx->Driver.CopyPixels = gld_CopyPixels_DX9; - ctx->Driver.DrawPixels = gld_DrawPixels_DX9; - ctx->Driver.ReadPixels = gld_ReadPixels_DX9; - ctx->Driver.Bitmap = gld_Bitmap_DX9; - - // Buffer resize - ctx->Driver.ResizeBuffers = gldResizeBuffers_DX9; - - // Texture image functions - ctx->Driver.ChooseTextureFormat = gld_ChooseTextureFormat_DX9; - ctx->Driver.TexImage1D = gld_TexImage1D_DX9; - ctx->Driver.TexImage2D = gld_TexImage2D_DX9; - ctx->Driver.TexImage3D = _mesa_store_teximage3d; - ctx->Driver.TexSubImage1D = gld_TexSubImage1D_DX9; - ctx->Driver.TexSubImage2D = gld_TexSubImage2D_DX9; - ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; - - ctx->Driver.CopyTexImage1D = gldCopyTexImage1D_DX9; //NULL; - ctx->Driver.CopyTexImage2D = gldCopyTexImage2D_DX9; //NULL; - ctx->Driver.CopyTexSubImage1D = gldCopyTexSubImage1D_DX9; //NULL; - ctx->Driver.CopyTexSubImage2D = gldCopyTexSubImage2D_DX9; //NULL; - ctx->Driver.CopyTexSubImage3D = gldCopyTexSubImage3D_DX9; - ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; - - // Texture object functions - ctx->Driver.BindTexture = NULL; - ctx->Driver.NewTextureObject = NULL; // Not yet implemented by Mesa!; - ctx->Driver.DeleteTexture = gld_DeleteTexture_DX9; - ctx->Driver.PrioritizeTexture = NULL; - - // Imaging functionality - ctx->Driver.CopyColorTable = NULL; - ctx->Driver.CopyColorSubTable = NULL; - ctx->Driver.CopyConvolutionFilter1D = NULL; - ctx->Driver.CopyConvolutionFilter2D = NULL; - - // State changing functions - ctx->Driver.AlphaFunc = NULL; //gld_AlphaFunc; - ctx->Driver.BlendFuncSeparate = NULL; //gld_BlendFunc; - ctx->Driver.ClearColor = NULL; //gld_ClearColor; - ctx->Driver.ClearDepth = NULL; //gld_ClearDepth; - ctx->Driver.ClearStencil = NULL; //gld_ClearStencil; - ctx->Driver.ColorMask = NULL; //gld_ColorMask; - ctx->Driver.CullFace = NULL; //gld_CullFace; - ctx->Driver.ClipPlane = NULL; //gld_ClipPlane; - ctx->Driver.FrontFace = NULL; //gld_FrontFace; - ctx->Driver.DepthFunc = NULL; //gld_DepthFunc; - ctx->Driver.DepthMask = NULL; //gld_DepthMask; - ctx->Driver.DepthRange = NULL; - ctx->Driver.Enable = NULL; //gld_Enable; - ctx->Driver.Fogfv = NULL; //gld_Fogfv; - ctx->Driver.Hint = NULL; //gld_Hint; - ctx->Driver.Lightfv = NULL; //gld_Lightfv; - ctx->Driver.LightModelfv = NULL; //gld_LightModelfv; - ctx->Driver.LineStipple = NULL; //gld_LineStipple; - ctx->Driver.LineWidth = NULL; //gld_LineWidth; - ctx->Driver.LogicOpcode = NULL; //gld_LogicOpcode; - ctx->Driver.PointParameterfv = NULL; //gld_PointParameterfv; - ctx->Driver.PointSize = NULL; //gld_PointSize; - ctx->Driver.PolygonMode = NULL; //gld_PolygonMode; - ctx->Driver.PolygonOffset = NULL; //gld_PolygonOffset; - ctx->Driver.PolygonStipple = NULL; //gld_PolygonStipple; - ctx->Driver.RenderMode = NULL; //gld_RenderMode; - ctx->Driver.Scissor = NULL; //gld_Scissor; - ctx->Driver.ShadeModel = NULL; //gld_ShadeModel; - ctx->Driver.StencilFunc = NULL; //gld_StencilFunc; - ctx->Driver.StencilMask = NULL; //gld_StencilMask; - ctx->Driver.StencilOp = NULL; //gld_StencilOp; - ctx->Driver.TexGen = NULL; //gld_TexGen; - ctx->Driver.TexEnv = NULL; - ctx->Driver.TexParameter = NULL; - ctx->Driver.TextureMatrix = NULL; //gld_TextureMatrix; - ctx->Driver.Viewport = gld_Viewport_DX9; - - _swsetup_Wakeup(ctx); - - tnl->Driver.RunPipeline = _tnl_run_pipeline; - tnl->Driver.Render.ResetLineStipple = gld_ResetLineStipple_DX9; - tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon; - tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine; - - // Hook into glFrustum() and glOrtho() -// ctx->Exec->Frustum = gldFrustumHook_DX9; -// ctx->Exec->Ortho = gldOrthoHook_DX9; - -} - -//--------------------------------------------------------------------------- diff --git a/src/mesa/drivers/windows/gldirect/dx9/gld_dx9.h b/src/mesa/drivers/windows/gldirect/dx9/gld_dx9.h deleted file mode 100644 index aec40ac9dd..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx9/gld_dx9.h +++ /dev/null @@ -1,327 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: GLDirect Direct3D 9.0 header file -* -****************************************************************************/ - -#ifndef _GLD_DX9_H -#define _GLD_DX9_H - -//--------------------------------------------------------------------------- -// Windows includes -//--------------------------------------------------------------------------- - -//#ifndef STRICT -//#define STRICT -//#endif - -//#define WIN32_LEAN_AND_MEAN -//#include <windows.h> -#include <d3d9.h> -#include <d3dx9.h> - -// MS screwed up with the DX8.1 SDK - there's no compile-time -// method of compiling for 8.0 via the 8.1 SDK unless you -// "make sure you don't use any 8.1 interfaces". -// We CAN use 8.1 D3DX static functions, though - just not new 8.1 interfaces. -// -// D3D_SDK_VERSION is 120 for 8.0 (supported by Windows 95). -// D3D_SDK_VERSION is 220 for 8.1 (NOT supported by Windows 95). -// -//#define D3D_SDK_VERSION_DX9_SUPPORT_WIN95 120 -//#define D3D_SDK_VERSION_DX91 220 - -// Typedef for obtaining function from d3d8.dll -typedef IDirect3D9* (WINAPI *FNDIRECT3DCREATE9) (UINT); - - -//--------------------------------------------------------------------------- -// Defines -//--------------------------------------------------------------------------- - -#ifdef _DEBUG -#define _GLD_TEST_HRESULT(h) \ -{ \ - HRESULT _hr = (h); \ - if (FAILED(_hr)) { \ - gldLogError(GLDLOG_ERROR, #h, _hr); \ - } \ -} -#define _GLD_DX9(func) _GLD_TEST_HRESULT(IDirect3D9_##func##) -#define _GLD_DX9_DEV(func) _GLD_TEST_HRESULT(IDirect3DDevice9_##func##) -#define _GLD_DX9_VB(func) _GLD_TEST_HRESULT(IDirect3DVertexBuffer9_##func##) -#define _GLD_DX9_TEX(func) _GLD_TEST_HRESULT(IDirect3DTexture9_##func##) -#else -#define _GLD_DX9(func) IDirect3D9_##func -#define _GLD_DX9_DEV(func) IDirect3DDevice9_##func -#define _GLD_DX9_VB(func) IDirect3DVertexBuffer9_##func -#define _GLD_DX9_TEX(func) IDirect3DTexture9_##func -#endif - -#define SAFE_RELEASE(p) \ -{ \ - if (p) { \ - (p)->lpVtbl->Release(p); \ - (p) = NULL; \ - } \ -} - -#define SAFE_RELEASE_VB9(p) \ -{ \ - if (p) { \ - IDirect3DVertexBuffer9_Release((p)); \ - (p) = NULL; \ - } \ -} - -#define SAFE_RELEASE_SURFACE9(p) \ -{ \ - if (p) { \ - IDirect3DSurface9_Release((p)); \ - (p) = NULL; \ - } \ -} - -// Setup index. -enum { - GLD_SI_FLAT = 0, - GLD_SI_SMOOTH = 1, - GLD_SI_FLAT_EXTRAS = 2, - GLD_SI_SMOOTH_EXTRAS = 3, -}; -/* -// Internal pipeline -typedef enum { - GLD_PIPELINE_MESA = 0, // Mesa pipeline - GLD_PIPELINE_D3D_FVF = 1, // Direct3D Fixed-function pipeline - GLD_PIPELINE_D3D_VS_TWOSIDE = 2 // Direct3D two-sided-lighting vertex shader -} GLD_tnl_pipeline; -*/ -//--------------------------------------------------------------------------- -// Vertex definitions for Fixed-Function pipeline -//--------------------------------------------------------------------------- - -// -// NOTE: If the number of texture units is altered then most of -// the texture code will need to be revised. -// - -#define GLD_MAX_TEXTURE_UNITS_DX9 2 - -// -// 2D vertex transformed by Mesa -// -#define GLD_FVF_2D_VERTEX ( D3DFVF_XYZRHW | \ - D3DFVF_DIFFUSE | \ - D3DFVF_SPECULAR | \ - D3DFVF_TEX2) -typedef struct { - FLOAT x, y; // 2D raster coords - FLOAT sz; // Screen Z (depth) - FLOAT rhw; // Reciprocal homogenous W - DWORD diffuse; // Diffuse colour - DWORD specular; // For separate-specular support - FLOAT t0_u, t0_v; // 1st set of texture coords - FLOAT t1_u, t1_v; // 2nd set of texture coords -} GLD_2D_VERTEX; - - -// -// 3D vertex transformed by Direct3D -// -#define GLD_FVF_3D_VERTEX ( D3DFVF_XYZ | \ - D3DFVF_DIFFUSE | \ - D3DFVF_TEX2) - -typedef struct { - D3DXVECTOR3 Position; // XYZ Vector in object space - D3DCOLOR Diffuse; // Diffuse colour - D3DXVECTOR2 TexUnit0; // Texture unit 0 - D3DXVECTOR2 TexUnit1; // Texture unit 1 -} GLD_3D_VERTEX; - -//--------------------------------------------------------------------------- -// Vertex Shaders -//--------------------------------------------------------------------------- -/* -// DX8 Vertex Shader -typedef struct { - DWORD hShader; // If NULL, shader is invalid and cannot be used - BOOL bHardware; // If TRUE then shader was created for hardware, - // otherwise shader was created for software. -} GLD_vertexShader; -*/ -//--------------------------------------------------------------------------- -// Structs -//--------------------------------------------------------------------------- - -// This keeps a count of how many times we choose each individual internal -// pathway. Useful for seeing if a certain pathway was ever used by an app, and -// how much each pathway is biased. -// Zero the members at context creation and dump stats at context deletion. -typedef struct { - // Note: DWORD is probably too small - ULARGE_INTEGER qwMesa; // Mesa TnL pipeline - ULARGE_INTEGER qwD3DFVF; // Direct3D Fixed-Function pipeline -// ULARGE_INTEGER dwD3D2SVS; // Direct3D Two-Sided Vertex Shader pipeline -} GLD_pipeline_usage; - -// GLDirect Primitive Buffer (points, lines, triangles and quads) -typedef struct { - // Data for IDirect3DDevice9::CreateVertexBuffer() - DWORD dwStride; // Stride of vertex - DWORD dwUsage; // Usage flags - DWORD dwFVF; // Direct3D Flexible Vertex Format - DWORD dwPool; // Pool flags - - IDirect3DVertexBuffer9 *pVB; // Holds points, lines, tris and quads. - - // Point list is assumed to be at start of buffer - DWORD iFirstLine; // Index of start of line list - DWORD iFirstTriangle; // Index of start of triangle list - - BYTE *pPoints; // Pointer to next free point - BYTE *pLines; // Pointer to next free line - BYTE *pTriangles; // Pointer to next free triangle - - DWORD nPoints; // Number of points ready to render - DWORD nLines; // Number of lines ready to render - DWORD nTriangles; // Number of triangles ready to render -} GLD_pb_dx9; - -// GLDirect DX9 driver data -typedef struct { - // GLDirect vars - BOOL bDoublebuffer; // Doublebuffer (otherwise single-buffered) - BOOL bDepthStencil; // Depth buffer needed (stencil optional) - D3DFORMAT RenderFormat; // Format of back/front buffer - D3DFORMAT DepthFormat; // Format of depth/stencil -// float fFlipWindowY; // Value for flipping viewport Y coord - - // Direct3D vars - D3DCAPS9 d3dCaps9; - BOOL bHasHWTnL; // Device has Hardware Transform/Light? - IDirect3D9 *pD3D; // Base Direct3D9 interface - IDirect3DDevice9 *pDev; // Direct3D9 Device interface - GLD_pb_dx9 PB2d; // Vertices transformed by Mesa - GLD_pb_dx9 PB3d; // Vertices transformed by Direct3D - D3DPRIMITIVETYPE d3dpt; // Current Direct3D primitive type - D3DXMATRIX matProjection; // Projection matrix for D3D TnL - D3DXMATRIX matModelView; // Model/View matrix for D3D TnL - int iSetupFunc; // Which setup functions to use - BOOL bUseMesaTnL; // Whether to use Mesa or D3D for TnL - - // Direct3D vars for two-sided lighting -// GLD_vertexShader VStwosidelight; // Vertex Shader for two-sided lighting -// D3DXMATRIX matWorldViewProj;// World/View/Projection matrix for shaders - - -// GLD_tnl_pipeline TnLPipeline; // Index of current internal pipeline - GLD_pipeline_usage PipelineUsage; - - BOOL bCanScissor; // Scissor test - new for DX9 -} GLD_driver_dx9; - -#define GLD_GET_DX9_DRIVER(c) (GLD_driver_dx9*)(c)->glPriv - -//--------------------------------------------------------------------------- -// Function prototypes -//--------------------------------------------------------------------------- - -PROC gldGetProcAddress_DX9(LPCSTR a); -void gldEnableExtensions_DX9(GLcontext *ctx); -void gldInstallPipeline_DX9(GLcontext *ctx); -void gldSetupDriverPointers_DX9(GLcontext *ctx); -//void gldResizeBuffers_DX9(GLcontext *ctx); -void gldResizeBuffers_DX9(GLframebuffer *fb); - - -// Texture functions - -void gldCopyTexImage1D_DX9(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border); -void gldCopyTexImage2D_DX9(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); -void gldCopyTexSubImage1D_DX9(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width ); -void gldCopyTexSubImage2D_DX9(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height ); -void gldCopyTexSubImage3D_DX9(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height ); - -void gld_NEW_TEXTURE_DX9(GLcontext *ctx); -void gld_DrawPixels_DX9(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, const GLvoid *pixels); -void gld_ReadPixels_DX9(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, GLvoid *dest); -void gld_CopyPixels_DX9(GLcontext *ctx, GLint srcx, GLint srcy, GLsizei width, GLsizei height, GLint dstx, GLint dsty, GLenum type); -void gld_Bitmap_DX9(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap); -const struct gl_texture_format* gld_ChooseTextureFormat_DX9(GLcontext *ctx, GLint internalFormat, GLenum srcFormat, GLenum srcType); -void gld_TexImage2D_DX9(GLcontext *ctx, GLenum target, GLint level, GLint internalFormat, GLint width, GLint height, GLint border, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *tObj, struct gl_texture_image *texImage); -void gld_TexImage1D_DX9(GLcontext *ctx, GLenum target, GLint level, GLint internalFormat, GLint width, GLint border, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage ); -void gld_TexSubImage2D_DX9( GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage ); -void gld_TexSubImage1D_DX9(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage); -void gld_DeleteTexture_DX9(GLcontext *ctx, struct gl_texture_object *tObj); -void gld_ResetLineStipple_DX9(GLcontext *ctx); - -// 2D primitive functions - -void gld_Points2D_DX9(GLcontext *ctx, GLuint first, GLuint last); - -void gld_Line2DFlat_DX9(GLcontext *ctx, GLuint v0, GLuint v1); -void gld_Line2DSmooth_DX9(GLcontext *ctx, GLuint v0, GLuint v1); - -void gld_Triangle2DFlat_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Triangle2DSmooth_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Triangle2DFlatExtras_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Triangle2DSmoothExtras_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); - -void gld_Quad2DFlat_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -void gld_Quad2DSmooth_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -void gld_Quad2DFlatExtras_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -void gld_Quad2DSmoothExtras_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); - -// 3D primitive functions - -void gld_Points3D_DX9(GLcontext *ctx, GLuint first, GLuint last); -void gld_Line3DFlat_DX9(GLcontext *ctx, GLuint v0, GLuint v1); -void gld_Triangle3DFlat_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Quad3DFlat_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -void gld_Line3DSmooth_DX9(GLcontext *ctx, GLuint v0, GLuint v1); -void gld_Triangle3DSmooth_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Quad3DSmooth_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); - -// Primitive functions for Two-sided-lighting Vertex Shader - -void gld_Points2DTwoside_DX9(GLcontext *ctx, GLuint first, GLuint last); -void gld_Line2DFlatTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1); -void gld_Line2DSmoothTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1); -void gld_Triangle2DFlatTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Triangle2DSmoothTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); -void gld_Quad2DFlatTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -void gld_Quad2DSmoothTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); - -#endif diff --git a/src/mesa/drivers/windows/gldirect/dx9/gld_dxerr9.h b/src/mesa/drivers/windows/gldirect/dx9/gld_dxerr9.h deleted file mode 100644 index 1d6b7b1c76..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx9/gld_dxerr9.h +++ /dev/null @@ -1,77 +0,0 @@ -/*==========================================================================; - * - * - * File: dxerr9.h - * Content: DirectX Error Library Include File - * - ****************************************************************************/ - -#ifndef _GLD_DXERR9_H_ -#define _GLD_DXERR9_H_ - - -#include <d3d9.h> - -// -// DXGetErrorString9 -// -// Desc: Converts an DirectX HRESULT to a string -// -// Args: HRESULT hr Can be any error code from -// DPLAY D3D8 D3DX8 DMUSIC DSOUND -// -// Return: Converted string -// -const char* __stdcall DXGetErrorString9A(HRESULT hr); -const WCHAR* __stdcall DXGetErrorString9W(HRESULT hr); - -#ifdef UNICODE - #define DXGetErrorString9 DXGetErrorString9W -#else - #define DXGetErrorString9 DXGetErrorString9A -#endif - - -// -// DXTrace -// -// Desc: Outputs a formatted error message to the debug stream -// -// Args: CHAR* strFile The current file, typically passed in using the -// __FILE__ macro. -// DWORD dwLine The current line number, typically passed in using the -// __LINE__ macro. -// HRESULT hr An HRESULT that will be traced to the debug stream. -// CHAR* strMsg A string that will be traced to the debug stream (may be NULL) -// BOOL bPopMsgBox If TRUE, then a message box will popup also containing the passed info. -// -// Return: The hr that was passed in. -// -//HRESULT __stdcall DXTraceA( char* strFile, DWORD dwLine, HRESULT hr, char* strMsg, BOOL bPopMsgBox = FALSE ); -//HRESULT __stdcall DXTraceW( char* strFile, DWORD dwLine, HRESULT hr, WCHAR* strMsg, BOOL bPopMsgBox = FALSE ); -HRESULT __stdcall DXTraceA( char* strFile, DWORD dwLine, HRESULT hr, char* strMsg, BOOL bPopMsgBox); -HRESULT __stdcall DXTraceW( char* strFile, DWORD dwLine, HRESULT hr, WCHAR* strMsg, BOOL bPopMsgBox); - -#ifdef UNICODE - #define DXTrace DXTraceW -#else - #define DXTrace DXTraceA -#endif - - -// -// Helper macros -// -#if defined(DEBUG) | defined(_DEBUG) - #define DXTRACE_MSG(str) DXTrace( __FILE__, (DWORD)__LINE__, 0, str, FALSE ) - #define DXTRACE_ERR(str,hr) DXTrace( __FILE__, (DWORD)__LINE__, hr, str, TRUE ) - #define DXTRACE_ERR_NOMSGBOX(str,hr) DXTrace( __FILE__, (DWORD)__LINE__, hr, str, FALSE ) -#else - #define DXTRACE_MSG(str) (0L) - #define DXTRACE_ERR(str,hr) (hr) - #define DXTRACE_ERR_NOMSGBOX(str,hr) (hr) -#endif - - -#endif - diff --git a/src/mesa/drivers/windows/gldirect/dx9/gld_ext_dx9.c b/src/mesa/drivers/windows/gldirect/dx9/gld_ext_dx9.c deleted file mode 100644 index e8c73a6ff8..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx9/gld_ext_dx9.c +++ /dev/null @@ -1,344 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: GL extensions -* -****************************************************************************/ - -//#include "../GLDirect.h" -//#include "../gld_log.h" -//#include "../gld_settings.h" - -#include <windows.h> -#define GL_GLEXT_PROTOTYPES -#include <GL/gl.h> -#include <GL/glext.h> - -//#include "ddlog.h" -//#include "gld_dx8.h" - -#include "glheader.h" -#include "context.h" -#include "colormac.h" -#include "depth.h" -#include "extensions.h" -#include "macros.h" -#include "matrix.h" -// #include "mem.h" -//#include "mmath.h" -#include "mtypes.h" -#include "texformat.h" -#include "texstore.h" -#include "vbo/vbo.h" -#include "swrast_setup/swrast_setup.h" -#include "swrast_setup/ss_context.h" -#include "tnl/tnl.h" -#include "tnl/t_context.h" -#include "tnl/t_pipeline.h" - -#include "dglcontext.h" -#include "extensions.h" - -// For some reason this is not defined in an above header... -extern void _mesa_enable_imaging_extensions(GLcontext *ctx); - -//--------------------------------------------------------------------------- -// Hack for the SGIS_multitexture extension that was removed from Mesa -// NOTE: SGIS_multitexture enums also clash with GL_SGIX_async_pixel - - // NOTE: Quake2 ran *slower* with this enabled, so I've - // disabled it for now. - // To enable, uncomment: - // _mesa_add_extension(ctx, GL_TRUE, szGL_SGIS_multitexture, 0); - -//--------------------------------------------------------------------------- - -enum { - /* Quake2 GL_SGIS_multitexture */ - GL_SELECTED_TEXTURE_SGIS = 0x835B, - GL_SELECTED_TEXTURE_COORD_SET_SGIS = 0x835C, - GL_MAX_TEXTURES_SGIS = 0x835D, - GL_TEXTURE0_SGIS = 0x835E, - GL_TEXTURE1_SGIS = 0x835F, - GL_TEXTURE2_SGIS = 0x8360, - GL_TEXTURE3_SGIS = 0x8361, - GL_TEXTURE_COORD_SET_SOURCE_SGIS = 0x8363, -}; - -//--------------------------------------------------------------------------- - -void APIENTRY gldSelectTextureSGIS( - GLenum target) -{ - GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS); - glActiveTextureARB(ARB_target); -} - -//--------------------------------------------------------------------------- - -void APIENTRY gldMTexCoord2fSGIS( - GLenum target, - GLfloat s, - GLfloat t) -{ - GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS); - glMultiTexCoord2fARB(ARB_target, s, t); -} - -//--------------------------------------------------------------------------- - -void APIENTRY gldMTexCoord2fvSGIS( - GLenum target, - const GLfloat *v) -{ - GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS); - glMultiTexCoord2fvARB(ARB_target, v); -} - -//--------------------------------------------------------------------------- -// Extensions -//--------------------------------------------------------------------------- - -typedef struct { - PROC proc; - char *name; -} GLD_extension; - -GLD_extension GLD_extList[] = { -#ifdef GL_EXT_polygon_offset - { (PROC)glPolygonOffsetEXT, "glPolygonOffsetEXT" }, -#endif - { (PROC)glBlendEquationEXT, "glBlendEquationEXT" }, - { (PROC)glBlendColorEXT, "glBlendColorExt" }, - { (PROC)glVertexPointerEXT, "glVertexPointerEXT" }, - { (PROC)glNormalPointerEXT, "glNormalPointerEXT" }, - { (PROC)glColorPointerEXT, "glColorPointerEXT" }, - { (PROC)glIndexPointerEXT, "glIndexPointerEXT" }, - { (PROC)glTexCoordPointerEXT, "glTexCoordPointer" }, - { (PROC)glEdgeFlagPointerEXT, "glEdgeFlagPointerEXT" }, - { (PROC)glGetPointervEXT, "glGetPointervEXT" }, - { (PROC)glArrayElementEXT, "glArrayElementEXT" }, - { (PROC)glDrawArraysEXT, "glDrawArrayEXT" }, - { (PROC)glAreTexturesResidentEXT, "glAreTexturesResidentEXT" }, - { (PROC)glBindTextureEXT, "glBindTextureEXT" }, - { (PROC)glDeleteTexturesEXT, "glDeleteTexturesEXT" }, - { (PROC)glGenTexturesEXT, "glGenTexturesEXT" }, - { (PROC)glIsTextureEXT, "glIsTextureEXT" }, - { (PROC)glPrioritizeTexturesEXT, "glPrioritizeTexturesEXT" }, - { (PROC)glCopyTexSubImage3DEXT, "glCopyTexSubImage3DEXT" }, - { (PROC)glTexImage3DEXT, "glTexImage3DEXT" }, - { (PROC)glTexSubImage3DEXT, "glTexSubImage3DEXT" }, - { (PROC)glPointParameterfEXT, "glPointParameterfEXT" }, - { (PROC)glPointParameterfvEXT, "glPointParameterfvEXT" }, - - { (PROC)glLockArraysEXT, "glLockArraysEXT" }, - { (PROC)glUnlockArraysEXT, "glUnlockArraysEXT" }, - { NULL, "\0" } -}; - -GLD_extension GLD_multitexList[] = { -/* - { (PROC)glMultiTexCoord1dSGIS, "glMTexCoord1dSGIS" }, - { (PROC)glMultiTexCoord1dvSGIS, "glMTexCoord1dvSGIS" }, - { (PROC)glMultiTexCoord1fSGIS, "glMTexCoord1fSGIS" }, - { (PROC)glMultiTexCoord1fvSGIS, "glMTexCoord1fvSGIS" }, - { (PROC)glMultiTexCoord1iSGIS, "glMTexCoord1iSGIS" }, - { (PROC)glMultiTexCoord1ivSGIS, "glMTexCoord1ivSGIS" }, - { (PROC)glMultiTexCoord1sSGIS, "glMTexCoord1sSGIS" }, - { (PROC)glMultiTexCoord1svSGIS, "glMTexCoord1svSGIS" }, - { (PROC)glMultiTexCoord2dSGIS, "glMTexCoord2dSGIS" }, - { (PROC)glMultiTexCoord2dvSGIS, "glMTexCoord2dvSGIS" }, - { (PROC)glMultiTexCoord2fSGIS, "glMTexCoord2fSGIS" }, - { (PROC)glMultiTexCoord2fvSGIS, "glMTexCoord2fvSGIS" }, - { (PROC)glMultiTexCoord2iSGIS, "glMTexCoord2iSGIS" }, - { (PROC)glMultiTexCoord2ivSGIS, "glMTexCoord2ivSGIS" }, - { (PROC)glMultiTexCoord2sSGIS, "glMTexCoord2sSGIS" }, - { (PROC)glMultiTexCoord2svSGIS, "glMTexCoord2svSGIS" }, - { (PROC)glMultiTexCoord3dSGIS, "glMTexCoord3dSGIS" }, - { (PROC)glMultiTexCoord3dvSGIS, "glMTexCoord3dvSGIS" }, - { (PROC)glMultiTexCoord3fSGIS, "glMTexCoord3fSGIS" }, - { (PROC)glMultiTexCoord3fvSGIS, "glMTexCoord3fvSGIS" }, - { (PROC)glMultiTexCoord3iSGIS, "glMTexCoord3iSGIS" }, - { (PROC)glMultiTexCoord3ivSGIS, "glMTexCoord3ivSGIS" }, - { (PROC)glMultiTexCoord3sSGIS, "glMTexCoord3sSGIS" }, - { (PROC)glMultiTexCoord3svSGIS, "glMTexCoord3svSGIS" }, - { (PROC)glMultiTexCoord4dSGIS, "glMTexCoord4dSGIS" }, - { (PROC)glMultiTexCoord4dvSGIS, "glMTexCoord4dvSGIS" }, - { (PROC)glMultiTexCoord4fSGIS, "glMTexCoord4fSGIS" }, - { (PROC)glMultiTexCoord4fvSGIS, "glMTexCoord4fvSGIS" }, - { (PROC)glMultiTexCoord4iSGIS, "glMTexCoord4iSGIS" }, - { (PROC)glMultiTexCoord4ivSGIS, "glMTexCoord4ivSGIS" }, - { (PROC)glMultiTexCoord4sSGIS, "glMTexCoord4sSGIS" }, - { (PROC)glMultiTexCoord4svSGIS, "glMTexCoord4svSGIS" }, - { (PROC)glMultiTexCoordPointerSGIS, "glMTexCoordPointerSGIS" }, - { (PROC)glSelectTextureSGIS, "glSelectTextureSGIS" }, - { (PROC)glSelectTextureCoordSetSGIS, "glSelectTextureCoordSetSGIS" }, -*/ - { (PROC)glActiveTextureARB, "glActiveTextureARB" }, - { (PROC)glClientActiveTextureARB, "glClientActiveTextureARB" }, - { (PROC)glMultiTexCoord1dARB, "glMultiTexCoord1dARB" }, - { (PROC)glMultiTexCoord1dvARB, "glMultiTexCoord1dvARB" }, - { (PROC)glMultiTexCoord1fARB, "glMultiTexCoord1fARB" }, - { (PROC)glMultiTexCoord1fvARB, "glMultiTexCoord1fvARB" }, - { (PROC)glMultiTexCoord1iARB, "glMultiTexCoord1iARB" }, - { (PROC)glMultiTexCoord1ivARB, "glMultiTexCoord1ivARB" }, - { (PROC)glMultiTexCoord1sARB, "glMultiTexCoord1sARB" }, - { (PROC)glMultiTexCoord1svARB, "glMultiTexCoord1svARB" }, - { (PROC)glMultiTexCoord2dARB, "glMultiTexCoord2dARB" }, - { (PROC)glMultiTexCoord2dvARB, "glMultiTexCoord2dvARB" }, - { (PROC)glMultiTexCoord2fARB, "glMultiTexCoord2fARB" }, - { (PROC)glMultiTexCoord2fvARB, "glMultiTexCoord2fvARB" }, - { (PROC)glMultiTexCoord2iARB, "glMultiTexCoord2iARB" }, - { (PROC)glMultiTexCoord2ivARB, "glMultiTexCoord2ivARB" }, - { (PROC)glMultiTexCoord2sARB, "glMultiTexCoord2sARB" }, - { (PROC)glMultiTexCoord2svARB, "glMultiTexCoord2svARB" }, - { (PROC)glMultiTexCoord3dARB, "glMultiTexCoord3dARB" }, - { (PROC)glMultiTexCoord3dvARB, "glMultiTexCoord3dvARB" }, - { (PROC)glMultiTexCoord3fARB, "glMultiTexCoord3fARB" }, - { (PROC)glMultiTexCoord3fvARB, "glMultiTexCoord3fvARB" }, - { (PROC)glMultiTexCoord3iARB, "glMultiTexCoord3iARB" }, - { (PROC)glMultiTexCoord3ivARB, "glMultiTexCoord3ivARB" }, - { (PROC)glMultiTexCoord3sARB, "glMultiTexCoord3sARB" }, - { (PROC)glMultiTexCoord3svARB, "glMultiTexCoord3svARB" }, - { (PROC)glMultiTexCoord4dARB, "glMultiTexCoord4dARB" }, - { (PROC)glMultiTexCoord4dvARB, "glMultiTexCoord4dvARB" }, - { (PROC)glMultiTexCoord4fARB, "glMultiTexCoord4fARB" }, - { (PROC)glMultiTexCoord4fvARB, "glMultiTexCoord4fvARB" }, - { (PROC)glMultiTexCoord4iARB, "glMultiTexCoord4iARB" }, - { (PROC)glMultiTexCoord4ivARB, "glMultiTexCoord4ivARB" }, - { (PROC)glMultiTexCoord4sARB, "glMultiTexCoord4sARB" }, - { (PROC)glMultiTexCoord4svARB, "glMultiTexCoord4svARB" }, - - // Descent3 doesn't use correct string, hence this hack - { (PROC)glMultiTexCoord4fARB, "glMultiTexCoord4f" }, - - // Quake2 SGIS multitexture - { (PROC)gldSelectTextureSGIS, "glSelectTextureSGIS" }, - { (PROC)gldMTexCoord2fSGIS, "glMTexCoord2fSGIS" }, - { (PROC)gldMTexCoord2fvSGIS, "glMTexCoord2fvSGIS" }, - - { NULL, "\0" } -}; - -//--------------------------------------------------------------------------- - -PROC gldGetProcAddress_DX( - LPCSTR a) -{ - int i; - PROC proc = NULL; - - for (i=0; GLD_extList[i].proc; i++) { - if (!strcmp(a, GLD_extList[i].name)) { - proc = GLD_extList[i].proc; - break; - } - } - - if (glb.bMultitexture) { - for (i=0; GLD_multitexList[i].proc; i++) { - if (!strcmp(a, GLD_multitexList[i].name)) { - proc = GLD_multitexList[i].proc; - break; - } - } - } - - gldLogPrintf(GLDLOG_INFO, "GetProcAddress: %s (%s)", a, proc ? "OK" : "Failed"); - - return proc; -} - -//--------------------------------------------------------------------------- - -void gldEnableExtensions_DX9( - GLcontext *ctx) -{ - GLuint i; - - // Mesa enables some extensions by default. - // This table decides which ones we want to switch off again. - - // NOTE: GL_EXT_compiled_vertex_array appears broken. - - const char *gld_disable_extensions[] = { -// "GL_ARB_transpose_matrix", -// "GL_EXT_compiled_vertex_array", -// "GL_EXT_polygon_offset", -// "GL_EXT_rescale_normal", - "GL_EXT_texture3D", -// "GL_NV_texgen_reflection", - NULL - }; - - const char *gld_multitex_extensions[] = { - "GL_ARB_multitexture", // Quake 3 - NULL - }; - - // Quake 2 engines - const char *szGL_SGIS_multitexture = "GL_SGIS_multitexture"; - - const char *gld_enable_extensions[] = { - "GL_EXT_texture_env_add", // Quake 3 - "GL_ARB_texture_env_add", // Quake 3 - NULL - }; - - for (i=0; gld_disable_extensions[i]; i++) { - _mesa_disable_extension(ctx, gld_disable_extensions[i]); - } - - for (i=0; gld_enable_extensions[i]; i++) { - _mesa_enable_extension(ctx, gld_enable_extensions[i]); - } - - if (glb.bMultitexture) { - for (i=0; gld_multitex_extensions[i]; i++) { - _mesa_enable_extension(ctx, gld_multitex_extensions[i]); - } - - // GL_SGIS_multitexture - // NOTE: Quake2 ran *slower* with this enabled, so I've - // disabled it for now. - // Fair bit slower on GeForce256, - // Much slower on 3dfx Voodoo5 5500. -// _mesa_add_extension(ctx, GL_TRUE, szGL_SGIS_multitexture, 0); - - } - - _mesa_enable_imaging_extensions(ctx); - _mesa_enable_1_3_extensions(ctx); - _mesa_enable_1_4_extensions(ctx); -} - -//--------------------------------------------------------------------------- diff --git a/src/mesa/drivers/windows/gldirect/dx9/gld_pipeline_dx9.c b/src/mesa/drivers/windows/gldirect/dx9/gld_pipeline_dx9.c deleted file mode 100644 index 2b272aa628..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx9/gld_pipeline_dx9.c +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: Mesa transformation pipeline with GLDirect fastpath -* -****************************************************************************/ - -//#include "../GLDirect.h" - -#include "dglcontext.h" -#include "ddlog.h" -#include "gld_dx9.h" - -#include "tnl/tnl.h" -#include "tnl/t_context.h" -#include "tnl/t_pipeline.h" - -//--------------------------------------------------------------------------- - -extern struct tnl_pipeline_stage _gld_d3d_render_stage; -extern struct tnl_pipeline_stage _gld_mesa_render_stage; - -static const struct tnl_pipeline_stage *gld_pipeline[] = { - &_gld_d3d_render_stage, // Direct3D TnL - &_tnl_vertex_transform_stage, - &_tnl_normal_transform_stage, - &_tnl_lighting_stage, - &_tnl_fog_coordinate_stage, /* TODO: Omit fog stage. ??? */ - &_tnl_texgen_stage, - &_tnl_texture_transform_stage, - &_tnl_point_attenuation_stage, - &_gld_mesa_render_stage, // Mesa TnL, D3D rendering - 0, -}; - -//--------------------------------------------------------------------------- - -void gldInstallPipeline_DX9( - GLcontext *ctx) -{ - // Remove any existing pipeline stages, - // then install GLDirect pipeline stages. - - _tnl_destroy_pipeline(ctx); - _tnl_install_pipeline(ctx, gld_pipeline); -} - -//--------------------------------------------------------------------------- diff --git a/src/mesa/drivers/windows/gldirect/dx9/gld_primitive_dx9.c b/src/mesa/drivers/windows/gldirect/dx9/gld_primitive_dx9.c deleted file mode 100644 index 403a9d5f86..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx9/gld_primitive_dx9.c +++ /dev/null @@ -1,1446 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: Primitive (points/lines/tris/quads) rendering -* -****************************************************************************/ - -//#include "../GLDirect.h" - -//#include "gld_dx8.h" - -#include "dglcontext.h" -#include "ddlog.h" -#include "gld_dx9.h" - -#include "glheader.h" -#include "context.h" -#include "colormac.h" -#include "depth.h" -#include "extensions.h" -#include "macros.h" -#include "matrix.h" -// #include "mem.h" -//#include "mmath.h" -#include "mtypes.h" -#include "texformat.h" -#include "texstore.h" -#include "vbo/vbo.h" -#include "swrast/swrast.h" -#include "swrast_setup/swrast_setup.h" -#include "swrast_setup/ss_context.h" -#include "swrast/s_context.h" -#include "swrast/s_depth.h" -#include "swrast/s_lines.h" -#include "swrast/s_triangle.h" -#include "swrast/s_trispan.h" -#include "tnl/tnl.h" -#include "tnl/t_context.h" -#include "tnl/t_pipeline.h" - -// Disable compiler complaints about unreferenced local variables -#pragma warning (disable:4101) - -//--------------------------------------------------------------------------- -// Helper defines for primitives -//--------------------------------------------------------------------------- - -//static const float ooZ = 1.0f / 65536.0f; // One over Z - -#define GLD_COLOUR (D3DCOLOR_RGBA(swv->color[0], swv->color[1], swv->color[2], swv->color[3])) -#define GLD_SPECULAR (D3DCOLOR_RGBA(swv->specular[0], swv->specular[1], swv->specular[2], swv->specular[3])) -#define GLD_FLIP_Y(y) (gldCtx->dwHeight - (y)) - -//--------------------------------------------------------------------------- -// 2D vertex setup -//--------------------------------------------------------------------------- - -#define GLD_SETUP_2D_VARS_POINTS \ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); \ - GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pPoints; \ - SScontext *ss = SWSETUP_CONTEXT(ctx); \ - SWvertex *swv; \ - DWORD dwSpecularColour; \ - DWORD dwFlatColour - -#define GLD_SETUP_2D_VARS_LINES \ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); \ - GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pLines; \ - SScontext *ss = SWSETUP_CONTEXT(ctx); \ - SWvertex *swv; \ - DWORD dwSpecularColour; \ - DWORD dwFlatColour - -#define GLD_SETUP_2D_VARS_TRIANGLES \ - BOOL bFog = ctx->Fog.Enabled; \ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); \ - GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pTriangles; \ - SScontext *ss = SWSETUP_CONTEXT(ctx); \ - SWvertex *swv; \ - DWORD dwSpecularColour; \ - DWORD dwFlatColour; \ - GLuint facing = 0; \ - struct vertex_buffer *VB; \ - GLchan (*vbcolor)[4]; \ - GLchan (*vbspec)[4] - -#define GLD_SETUP_GET_SWVERT(s) \ - swv = &ss->verts[##s] - -#define GLD_SETUP_2D_VERTEX \ - pV->x = swv->win[0]; \ - pV->y = GLD_FLIP_Y(swv->win[1]); \ - pV->rhw = swv->win[3] - -#define GLD_SETUP_SMOOTH_COLOUR \ - pV->diffuse = GLD_COLOUR - -#define GLD_SETUP_GET_FLAT_COLOUR \ - dwFlatColour = GLD_COLOUR -#define GLD_SETUP_GET_FLAT_FOG_COLOUR \ - dwFlatColour = _gldComputeFog(ctx, swv) - -#define GLD_SETUP_USE_FLAT_COLOUR \ - pV->diffuse = dwFlatColour - -#define GLD_SETUP_GET_FLAT_SPECULAR \ - dwSpecularColour= GLD_SPECULAR - -#define GLD_SETUP_USE_FLAT_SPECULAR \ - pV->specular = dwSpecularColour - -#define GLD_SETUP_DEPTH \ - pV->sz = swv->win[2] / ctx->DepthMaxF -// pV->z = swv->win[2] * ooZ; - -#define GLD_SETUP_SPECULAR \ - pV->specular = GLD_SPECULAR - -#define GLD_SETUP_FOG \ - pV->diffuse = _gldComputeFog(ctx, swv) - -#define GLD_SETUP_TEX0 \ - pV->t0_u = swv->texcoord[0][0]; \ - pV->t0_v = swv->texcoord[0][1] - -#define GLD_SETUP_TEX1 \ - pV->t1_u = swv->texcoord[1][0]; \ - pV->t1_v = swv->texcoord[1][1] - -#define GLD_SETUP_LIGHTING(v) \ - if (facing == 1) { \ - pV->diffuse = D3DCOLOR_RGBA(vbcolor[##v][0], vbcolor[##v][1], vbcolor[##v][2], vbcolor[##v][3]); \ - if (vbspec) { \ - pV->specular = D3DCOLOR_RGBA(vbspec[##v][0], vbspec[##v][1], vbspec[##v][2], vbspec[##v][3]); \ - } \ - } else { \ - if (bFog) \ - GLD_SETUP_FOG; \ - else \ - GLD_SETUP_SMOOTH_COLOUR; \ - GLD_SETUP_SPECULAR; \ - } - -#define GLD_SETUP_GET_FLAT_LIGHTING(v) \ - if (facing == 1) { \ - dwFlatColour = D3DCOLOR_RGBA(vbcolor[##v][0], vbcolor[##v][1], vbcolor[##v][2], vbcolor[##v][3]); \ - if (vbspec) { \ - dwSpecularColour = D3DCOLOR_RGBA(vbspec[##v][0], vbspec[##v][1], vbspec[##v][2], vbspec[##v][3]); \ - } \ - } - -#define GLD_SETUP_TWOSIDED_LIGHTING \ - /* Two-sided lighting */ \ - if (ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) { \ - SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts; \ - SWvertex *v[3]; \ - GLfloat ex,ey,fx,fy,cc; \ - /* Get vars for later */ \ - VB = &TNL_CONTEXT(ctx)->vb; \ - vbcolor = (GLchan (*)[4])VB->ColorPtr[1]->data; \ - if (VB->SecondaryColorPtr[1]) { \ - vbspec = (GLchan (*)[4])VB->SecondaryColorPtr[1]->data; \ - } else { \ - vbspec = NULL; \ - } \ - v[0] = &verts[v0]; \ - v[1] = &verts[v1]; \ - v[2] = &verts[v2]; \ - ex = v[0]->win[0] - v[2]->win[0]; \ - ey = v[0]->win[1] - v[2]->win[1]; \ - fx = v[1]->win[0] - v[2]->win[0]; \ - fy = v[1]->win[1] - v[2]->win[1]; \ - cc = ex*fy - ey*fx; \ - facing = (cc < 0.0) ^ ctx->Polygon._FrontBit; \ - } - -//--------------------------------------------------------------------------- -// 3D vertex setup -//--------------------------------------------------------------------------- - -#define GLD_SETUP_3D_VARS_POINTS \ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); \ - GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pPoints; \ - TNLcontext *tnl = TNL_CONTEXT(ctx); \ - struct vertex_buffer *VB = &tnl->vb; \ - GLfloat (*p4f)[4]; \ - GLfloat (*tc)[4]; \ - DWORD dwColor; - -#define GLD_SETUP_3D_VARS_LINES \ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); \ - GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pLines; \ - TNLcontext *tnl = TNL_CONTEXT(ctx); \ - struct vertex_buffer *VB = &tnl->vb; \ - GLfloat (*p4f)[4]; \ - GLfloat (*tc)[4]; \ - DWORD dwColor; - -#define GLD_SETUP_3D_VARS_TRIANGLES \ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); \ - GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pTriangles; \ - TNLcontext *tnl = TNL_CONTEXT(ctx); \ - struct vertex_buffer *VB = &tnl->vb; \ - GLfloat (*p4f)[4]; \ - GLfloat (*tc)[4]; \ - DWORD dwColor; - -#define GLD_SETUP_3D_VERTEX(v) \ - p4f = VB->ObjPtr->data; \ - pV->Position.x = p4f[##v][0]; \ - pV->Position.y = p4f[##v][1]; \ - pV->Position.z = p4f[##v][2]; - -#define GLD_SETUP_SMOOTH_COLOUR_3D(v) \ - p4f = (GLfloat (*)[4])VB->ColorPtr[0]->data; \ - pV->Diffuse = D3DCOLOR_COLORVALUE(p4f[##v][0], p4f[##v][1], p4f[##v][2], p4f[##v][3]); - - -#define GLD_SETUP_GET_FLAT_COLOUR_3D(v) \ - p4f = (GLfloat (*)[4])VB->ColorPtr[0]->data; \ - dwColor = D3DCOLOR_COLORVALUE(p4f[##v][0], p4f[##v][1], p4f[##v][2], p4f[##v][3]); - -#define GLD_SETUP_USE_FLAT_COLOUR_3D \ - pV->Diffuse = dwColor; - -#define GLD_SETUP_TEX0_3D(v) \ - if (VB->TexCoordPtr[0]) { \ - tc = VB->TexCoordPtr[0]->data; \ - pV->TexUnit0.x = tc[##v][0]; \ - pV->TexUnit0.y = tc[##v][1]; \ - } - -#define GLD_SETUP_TEX1_3D(v) \ - if (VB->TexCoordPtr[1]) { \ - tc = VB->TexCoordPtr[1]->data; \ - pV->TexUnit1.x = tc[##v][0]; \ - pV->TexUnit1.y = tc[##v][1]; \ - } - -//--------------------------------------------------------------------------- -// Helper functions -//--------------------------------------------------------------------------- - -__inline DWORD _gldComputeFog( - GLcontext *ctx, - SWvertex *swv) -{ - // Full fog calculation. - // Based on Mesa code. - - GLchan rFog, gFog, bFog; - GLchan fR, fG, fB; - const GLfloat f = swv->fog; - const GLfloat g = 1.0 - f; - - UNCLAMPED_FLOAT_TO_CHAN(rFog, ctx->Fog.Color[RCOMP]); - UNCLAMPED_FLOAT_TO_CHAN(gFog, ctx->Fog.Color[GCOMP]); - UNCLAMPED_FLOAT_TO_CHAN(bFog, ctx->Fog.Color[BCOMP]); - fR = f * swv->color[0] + g * rFog; - fG = f * swv->color[1] + g * gFog; - fB = f * swv->color[2] + g * bFog; - return D3DCOLOR_RGBA(fR, fG, fB, swv->color[3]); -} - -//--------------------------------------------------------------------------- - -void gld_ResetLineStipple_DX9( - GLcontext *ctx) -{ - // TODO: Fake stipple with a 32x32 texture. -} - -//--------------------------------------------------------------------------- -// 2D (post-transformed) primitives -//--------------------------------------------------------------------------- - -void gld_Points2D_DX9( - GLcontext *ctx, - GLuint first, - GLuint last) -{ - GLD_SETUP_2D_VARS_POINTS; - - unsigned i; - struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; - - // _Size is already clamped to MaxPointSize and MinPointSize - IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_POINTSIZE, *((DWORD*)&ctx->Point._Size)); - - if (VB->Elts) { - for (i=first; i<last; i++, pV++) { - if (VB->ClipMask[VB->Elts[i]] == 0) { -// _swrast_Point( ctx, &verts[VB->Elts[i]] ); - GLD_SETUP_GET_SWVERT(VB->Elts[i]); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_SPECULAR; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - } - } - } else { - GLD_SETUP_GET_SWVERT(first); - for (i=first; i<last; i++, swv++, pV++) { - if (VB->ClipMask[i] == 0) { -// _swrast_Point( ctx, &verts[i] ); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_SPECULAR; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - } - } - } - - gld->PB2d.pPoints = (BYTE*)pV; - gld->PB2d.nPoints += (last-first); -} - -//--------------------------------------------------------------------------- - -void gld_Line2DFlat_DX9( - GLcontext *ctx, - GLuint v0, - GLuint v1) -{ - GLD_SETUP_2D_VARS_LINES; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_GET_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_GET_FLAT_SPECULAR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - gld->PB2d.pLines = (BYTE*)pV; - gld->PB2d.nLines++; -} - -//--------------------------------------------------------------------------- - -void gld_Line2DSmooth_DX9( - GLcontext *ctx, - GLuint v0, - GLuint v1) -{ - GLD_SETUP_2D_VARS_LINES; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_SPECULAR; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_SPECULAR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - gld->PB2d.pLines = (BYTE*)pV; - gld->PB2d.nLines++; -} - -//--------------------------------------------------------------------------- - -void gld_Triangle2DFlat_DX9( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_GET_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_COLOUR; - pV++;; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles++; -} - -//--------------------------------------------------------------------------- - -void gld_Triangle2DSmooth_DX9( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2) -{ - - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles++; -} - -//--------------------------------------------------------------------------- - -void gld_Triangle2DFlatExtras_DX9( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_TWOSIDED_LIGHTING(v2); - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - if (bFog) - GLD_SETUP_GET_FLAT_FOG_COLOUR; - else - GLD_SETUP_GET_FLAT_COLOUR; - GLD_SETUP_GET_FLAT_SPECULAR; - GLD_SETUP_GET_FLAT_LIGHTING(v2); - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles++; -} - -//--------------------------------------------------------------------------- - -void gld_Triangle2DSmoothExtras_DX9( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_TWOSIDED_LIGHTING(v0); - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v0); - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v1); - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v2); - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles++; -} - -//--------------------------------------------------------------------------- - -void gld_Quad2DFlat_DX9( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2, - GLuint v3) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_GET_SWVERT(v3); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_GET_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - GLD_SETUP_GET_SWVERT(v3); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles += 2; -} - -//--------------------------------------------------------------------------- - -void gld_Quad2DSmooth_DX9( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2, - GLuint v3) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v3); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_SMOOTH_COLOUR; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles += 2; -} - -//--------------------------------------------------------------------------- - -void gld_Quad2DFlatExtras_DX9( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2, - GLuint v3) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_TWOSIDED_LIGHTING(v3); - - GLD_SETUP_GET_SWVERT(v3); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - if (bFog) - GLD_SETUP_GET_FLAT_FOG_COLOUR; - else - GLD_SETUP_GET_FLAT_COLOUR; - GLD_SETUP_GET_FLAT_SPECULAR; - GLD_SETUP_GET_FLAT_LIGHTING(v3); - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - GLD_SETUP_GET_SWVERT(v3); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_USE_FLAT_COLOUR; - GLD_SETUP_USE_FLAT_SPECULAR; - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles += 2; -} - -//--------------------------------------------------------------------------- - -void gld_Quad2DSmoothExtras_DX9( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2, - GLuint v3) -{ - GLD_SETUP_2D_VARS_TRIANGLES; - - GLD_SETUP_TWOSIDED_LIGHTING(v0); - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v0); - pV++; - - GLD_SETUP_GET_SWVERT(v1); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v1); - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v2); - pV++; - - GLD_SETUP_GET_SWVERT(v2); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v2); - pV++; - - GLD_SETUP_GET_SWVERT(v3); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v3); - pV++; - - GLD_SETUP_GET_SWVERT(v0); - GLD_SETUP_2D_VERTEX; - GLD_SETUP_DEPTH; - GLD_SETUP_TEX0; - GLD_SETUP_TEX1; - GLD_SETUP_LIGHTING(v0); - pV++; - - gld->PB2d.pTriangles = (BYTE*)pV; - gld->PB2d.nTriangles += 2; -} - -//--------------------------------------------------------------------------- -// 3D (pre-transformed) primitives -//--------------------------------------------------------------------------- - -void gld_Points3D_DX9( - GLcontext *ctx, - GLuint first, - GLuint last) -{ - GLD_SETUP_3D_VARS_POINTS - - unsigned i; -// struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; - - // _Size is already clamped to MaxPointSize and MinPointSize - IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_POINTSIZE, *((DWORD*)&ctx->Point._Size)); - - if (VB->Elts) { - for (i=first; i<last; i++, pV++) { - if (VB->ClipMask[VB->Elts[i]] == 0) { -// _swrast_Point( ctx, &verts[VB->Elts[i]] ); -// GLD_SETUP_GET_SWVERT(VB->Elts[i]); - GLD_SETUP_3D_VERTEX(VB->Elts[i]) - GLD_SETUP_SMOOTH_COLOUR_3D(i) - GLD_SETUP_TEX0_3D(i) - GLD_SETUP_TEX1_3D(i) - } - } - } else { -// GLD_SETUP_GET_SWVERT(first); - for (i=first; i<last; i++, pV++) { - if (VB->ClipMask[i] == 0) { -// _swrast_Point( ctx, &verts[i] ); - GLD_SETUP_3D_VERTEX(i) - GLD_SETUP_SMOOTH_COLOUR_3D(i) - GLD_SETUP_TEX0_3D(i) - GLD_SETUP_TEX1_3D(i) - } - } - } -/* - for (i=first; i<last; i++, pV++) { - GLD_SETUP_3D_VERTEX(i) - GLD_SETUP_SMOOTH_COLOUR_3D(i) - GLD_SETUP_TEX0_3D(i) - GLD_SETUP_TEX1_3D(i) - } -*/ - gld->PB3d.pPoints = (BYTE*)pV; - gld->PB3d.nPoints += (last-first); -} - -//--------------------------------------------------------------------------- -// Line functions -//--------------------------------------------------------------------------- - -void gld_Line3DFlat_DX9( - GLcontext *ctx, - GLuint v0, - GLuint v1) -{ - GLD_SETUP_3D_VARS_LINES - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_GET_FLAT_COLOUR_3D(v1) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - pV++; - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - pV++; - - gld->PB3d.pLines = (BYTE*)pV; - gld->PB3d.nLines++; -} - -//--------------------------------------------------------------------------- - -void gld_Line3DSmooth_DX9( - GLcontext *ctx, - GLuint v0, - GLuint v1) -{ - GLD_SETUP_3D_VARS_LINES - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_SMOOTH_COLOUR_3D(v1) - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - pV++; - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_SMOOTH_COLOUR_3D(v0) - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - pV++; - - gld->PB3d.pLines = (BYTE*)pV; - gld->PB3d.nLines++; -} - -//--------------------------------------------------------------------------- -// Triangle functions -//--------------------------------------------------------------------------- - -void gld_Triangle3DFlat_DX9( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2) -{ - GLD_SETUP_3D_VARS_TRIANGLES - - GLD_SETUP_3D_VERTEX(v2) - GLD_SETUP_TEX0_3D(v2) - GLD_SETUP_TEX1_3D(v2) - GLD_SETUP_GET_FLAT_COLOUR_3D(v2) - GLD_SETUP_USE_FLAT_COLOUR_3D - pV++; - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - GLD_SETUP_USE_FLAT_COLOUR_3D - pV++; - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - GLD_SETUP_USE_FLAT_COLOUR_3D - pV++; - - gld->PB3d.pTriangles = (BYTE*)pV; - gld->PB3d.nTriangles++; -} - -//--------------------------------------------------------------------------- - -void gld_Triangle3DSmooth_DX9( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2) -{ - GLD_SETUP_3D_VARS_TRIANGLES - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_SMOOTH_COLOUR_3D(v0) - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - pV++; - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_SMOOTH_COLOUR_3D(v1) - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - pV++; - - GLD_SETUP_3D_VERTEX(v2) - GLD_SETUP_SMOOTH_COLOUR_3D(v2) - GLD_SETUP_TEX0_3D(v2) - GLD_SETUP_TEX1_3D(v2) - pV++; - - gld->PB3d.pTriangles = (BYTE*)pV; - gld->PB3d.nTriangles++; -} - -//--------------------------------------------------------------------------- -// Quad functions -//--------------------------------------------------------------------------- - -void gld_Quad3DFlat_DX9( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2, - GLuint v3) -{ - GLD_SETUP_3D_VARS_TRIANGLES - - GLD_SETUP_3D_VERTEX(v3) - GLD_SETUP_GET_FLAT_COLOUR_3D(v3) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v3) - GLD_SETUP_TEX1_3D(v3) - pV++; - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - pV++; - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - pV++; - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - pV++; - - GLD_SETUP_3D_VERTEX(v2) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v2) - GLD_SETUP_TEX1_3D(v2) - pV++; - - GLD_SETUP_3D_VERTEX(v3) - GLD_SETUP_USE_FLAT_COLOUR_3D - GLD_SETUP_TEX0_3D(v3) - GLD_SETUP_TEX1_3D(v3) - pV++; - - gld->PB3d.pTriangles = (BYTE*)pV; - gld->PB3d.nTriangles += 2; -} - -//--------------------------------------------------------------------------- - -void gld_Quad3DSmooth_DX9( - GLcontext *ctx, - GLuint v0, - GLuint v1, - GLuint v2, - GLuint v3) -{ - GLD_SETUP_3D_VARS_TRIANGLES - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_SMOOTH_COLOUR_3D(v0) - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - pV++; - - GLD_SETUP_3D_VERTEX(v1) - GLD_SETUP_SMOOTH_COLOUR_3D(v1) - GLD_SETUP_TEX0_3D(v1) - GLD_SETUP_TEX1_3D(v1) - pV++; - - GLD_SETUP_3D_VERTEX(v2) - GLD_SETUP_SMOOTH_COLOUR_3D(v2) - GLD_SETUP_TEX0_3D(v2) - GLD_SETUP_TEX1_3D(v2) - pV++; - - GLD_SETUP_3D_VERTEX(v2) - GLD_SETUP_SMOOTH_COLOUR_3D(v2) - GLD_SETUP_TEX0_3D(v2) - GLD_SETUP_TEX1_3D(v2) - pV++; - - GLD_SETUP_3D_VERTEX(v3) - GLD_SETUP_SMOOTH_COLOUR_3D(v3) - GLD_SETUP_TEX0_3D(v3) - GLD_SETUP_TEX1_3D(v3) - pV++; - - GLD_SETUP_3D_VERTEX(v0) - GLD_SETUP_SMOOTH_COLOUR_3D(v0) - GLD_SETUP_TEX0_3D(v0) - GLD_SETUP_TEX1_3D(v0) - pV++; - - gld->PB3d.pTriangles = (BYTE*)pV; - gld->PB3d.nTriangles += 2; -} - -//--------------------------------------------------------------------------- -// Vertex setup for two-sided-lighting vertex shader -//--------------------------------------------------------------------------- - -/* - -void gld_Points2DTwoside_DX9(GLcontext *ctx, GLuint first, GLuint last) -{ - // NOTE: Two-sided lighting does not apply to Points -} - -//--------------------------------------------------------------------------- - -void gld_Line2DFlatTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1) -{ - // NOTE: Two-sided lighting does not apply to Lines -} - -//--------------------------------------------------------------------------- - -void gld_Line2DSmoothTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1) -{ - // NOTE: Two-sided lighting does not apply to Lines -} - -//--------------------------------------------------------------------------- - -void gld_Triangle2DFlatTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2) -{ -} - -//--------------------------------------------------------------------------- - -void gld_Triangle2DSmoothTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles; - SScontext *ss = SWSETUP_CONTEXT(ctx); - SWvertex *swv; - DWORD dwSpecularColour; - DWORD dwFlatColour; - GLuint facing = 0; - struct vertex_buffer *VB; - GLchan (*vbcolor)[4]; - GLchan (*vbspec)[4]; - - // Reciprocal of DepthMax - const float ooDepthMax = 1.0f / ctx->DepthMaxF; - - // 1st vert - swv = &ss->verts[v0]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 2nd vert - swv = &ss->verts[v1]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 3rd vert - swv = &ss->verts[v2]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - gld->PBtwosidelight.pTriangles = (BYTE*)pV; - gld->PBtwosidelight.nTriangles++; -} - -//--------------------------------------------------------------------------- - -void gld_Quad2DFlatTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles; - SScontext *ss = SWSETUP_CONTEXT(ctx); - SWvertex *swv; - DWORD dwSpecularColour; - DWORD dwFlatColour; - GLuint facing = 0; - struct vertex_buffer *VB; - GLchan (*vbcolor)[4]; - GLchan (*vbspec)[4]; - - // Reciprocal of DepthMax - const float ooDepthMax = 1.0f / ctx->DepthMaxF; - - // 1st vert - swv = &ss->verts[v0]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 2nd vert - swv = &ss->verts[v1]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 3rd vert - swv = &ss->verts[v2]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 4th vert - swv = &ss->verts[v2]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 5th vert - swv = &ss->verts[v3]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 6th vert - swv = &ss->verts[v0]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - gld->PBtwosidelight.pTriangles = (BYTE*)pV; - gld->PBtwosidelight.nTriangles += 2; -} - -//--------------------------------------------------------------------------- - -void gld_Quad2DSmoothTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles; - SScontext *ss = SWSETUP_CONTEXT(ctx); - SWvertex *swv; - DWORD dwSpecularColour; - DWORD dwFlatColour; - GLuint facing = 0; - struct vertex_buffer *VB; - GLchan (*vbcolor)[4]; - GLchan (*vbspec)[4]; - - // Reciprocal of DepthMax - const float ooDepthMax = 1.0f / ctx->DepthMaxF; - - // 1st vert - swv = &ss->verts[v0]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 2nd vert - swv = &ss->verts[v1]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 3rd vert - swv = &ss->verts[v2]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 4th vert - swv = &ss->verts[v2]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 5th vert - swv = &ss->verts[v3]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - // 6th vert - swv = &ss->verts[v0]; - pV->Position.x = swv->win[0]; - pV->Position.y = GLD_FLIP_Y(swv->win[1]); - pV->Position.z = swv->win[2] * ooDepthMax; - pV->Position.w = swv->win[3]; - pV->TexUnit0.x = swv->texcoord[0][0]; - pV->TexUnit0.y = swv->texcoord[0][1]; - pV->TexUnit1.x = swv->texcoord[1][0]; - pV->TexUnit1.y = swv->texcoord[1][1]; - pV->FrontDiffuse = GLD_COLOUR; - pV->FrontSpecular = GLD_SPECULAR; - pV++; - - gld->PBtwosidelight.pTriangles = (BYTE*)pV; - gld->PBtwosidelight.nTriangles += 2; -} - -//--------------------------------------------------------------------------- - -*/ diff --git a/src/mesa/drivers/windows/gldirect/dx9/gld_texture_dx9.c b/src/mesa/drivers/windows/gldirect/dx9/gld_texture_dx9.c deleted file mode 100644 index 5a82235616..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx9/gld_texture_dx9.c +++ /dev/null @@ -1,2104 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: Texture / Bitmap functions -* -****************************************************************************/ - -#include "dglcontext.h" -#include "ddlog.h" -#include "gld_dx9.h" - -#include <d3dx9tex.h> - -#include "texformat.h" -#include "colormac.h" -#include "texstore.h" -#include "image.h" -// #include "mem.h" - -//--------------------------------------------------------------------------- - -#define GLD_FLIP_HEIGHT(y,h) (gldCtx->dwHeight - (y) - (h)) - -//--------------------------------------------------------------------------- -// 1D texture fetch -//--------------------------------------------------------------------------- - -#define CHAN_SRC( t, i, j, k, sz ) \ - ((GLchan *)(t)->Data + (i) * (sz)) -#define UBYTE_SRC( t, i, j, k, sz ) \ - ((GLubyte *)(t)->Data + (i) * (sz)) -#define USHORT_SRC( t, i, j, k ) \ - ((GLushort *)(t)->Data + (i)) -#define FLOAT_SRC( t, i, j, k ) \ - ((GLfloat *)(t)->Data + (i)) - -//--------------------------------------------------------------------------- - -static void gld_fetch_1d_texel_X8R8G8B8( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); - GLchan *rgba = (GLchan *)texel; - rgba[RCOMP] = src[2]; - rgba[GCOMP] = src[1]; - rgba[BCOMP] = src[0]; - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_1d_texel_f_X8R8G8B8( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); - texel[RCOMP] = CHAN_TO_FLOAT(src[0]); - texel[GCOMP] = CHAN_TO_FLOAT(src[1]); - texel[BCOMP] = CHAN_TO_FLOAT(src[2]); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_1d_texel_X1R5G5B5( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLchan *rgba = (GLchan *) texel; GLushort s = *src; - rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0xf8) * 255 / 0xf8 ); - rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0xf8) * 255 / 0xf8 ); - rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf8) * 255 / 0xf8 ); - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_1d_texel_f_X1R5G5B5( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLushort s = *src; - texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0xf8) * 255 / 0xf8 ); - texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0xf8) * 255 / 0xf8 ); - texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf8) * 255 / 0xf8 ); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_1d_texel_X4R4G4B4( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLchan *rgba = (GLchan *) texel; GLushort s = *src; - rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf ); - rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf ); - rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf ); - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_1d_texel_f_X4R4G4B4( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLushort s = *src; - texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf ); - texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf ); - texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf ); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -#undef CHAN_SRC -#undef UBYTE_SRC -#undef USHORT_SRC -#undef FLOAT_SRC - -//--------------------------------------------------------------------------- -// 2D texture fetch -//--------------------------------------------------------------------------- - -#define CHAN_SRC( t, i, j, k, sz ) \ - ((GLchan *)(t)->Data + ((t)->Width * (j) + (i)) * (sz)) -#define UBYTE_SRC( t, i, j, k, sz ) \ - ((GLubyte *)(t)->Data + ((t)->Width * (j) + (i)) * (sz)) -#define USHORT_SRC( t, i, j, k ) \ - ((GLushort *)(t)->Data + ((t)->Width * (j) + (i))) -#define FLOAT_SRC( t, i, j, k ) \ - ((GLfloat *)(t)->Data + ((t)->Width * (j) + (i))) - -//--------------------------------------------------------------------------- - -static void gld_fetch_2d_texel_X8R8G8B8( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); - GLchan *rgba = (GLchan *)texel; - rgba[RCOMP] = src[2]; - rgba[GCOMP] = src[1]; - rgba[BCOMP] = src[0]; - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_2d_texel_f_X8R8G8B8( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); - texel[RCOMP] = CHAN_TO_FLOAT(src[0]); - texel[GCOMP] = CHAN_TO_FLOAT(src[1]); - texel[BCOMP] = CHAN_TO_FLOAT(src[2]); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_2d_texel_X1R5G5B5( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLchan *rgba = (GLchan *) texel; GLushort s = *src; - rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0xf8) * 255 / 0xf8 ); - rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0xf8) * 255 / 0xf8 ); - rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf8) * 255 / 0xf8 ); - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_2d_texel_f_X1R5G5B5( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLushort s = *src; - texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0xf8) * 255 / 0xf8 ); - texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0xf8) * 255 / 0xf8 ); - texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf8) * 255 / 0xf8 ); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_2d_texel_X4R4G4B4( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLchan *rgba = (GLchan *) texel; GLushort s = *src; - rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf ); - rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf ); - rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf ); - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_2d_texel_f_X4R4G4B4( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLushort s = *src; - texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf ); - texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf ); - texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf ); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -#undef CHAN_SRC -#undef UBYTE_SRC -#undef USHORT_SRC -#undef FLOAT_SRC - -//--------------------------------------------------------------------------- -// 3D texture fetch -//--------------------------------------------------------------------------- - -#define CHAN_SRC( t, i, j, k, sz ) \ - (GLchan *)(t)->Data + (((t)->Height * (k) + (j)) * \ - (t)->Width + (i)) * (sz) -#define UBYTE_SRC( t, i, j, k, sz ) \ - ((GLubyte *)(t)->Data + (((t)->Height * (k) + (j)) * \ - (t)->Width + (i)) * (sz)) -#define USHORT_SRC( t, i, j, k ) \ - ((GLushort *)(t)->Data + (((t)->Height * (k) + (j)) * \ - (t)->Width + (i))) -#define FLOAT_SRC( t, i, j, k ) \ - ((GLfloat *)(t)->Data + (((t)->Height * (k) + (j)) * \ - (t)->Width + (i))) - -//--------------------------------------------------------------------------- - -static void gld_fetch_3d_texel_X8R8G8B8( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); - GLchan *rgba = (GLchan *)texel; - rgba[RCOMP] = src[2]; - rgba[GCOMP] = src[1]; - rgba[BCOMP] = src[0]; - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_3d_texel_f_X8R8G8B8( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); - texel[RCOMP] = CHAN_TO_FLOAT(src[0]); - texel[GCOMP] = CHAN_TO_FLOAT(src[1]); - texel[BCOMP] = CHAN_TO_FLOAT(src[2]); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_3d_texel_X1R5G5B5( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLchan *rgba = (GLchan *) texel; GLushort s = *src; - rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0xf8) * 255 / 0xf8 ); - rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0xf8) * 255 / 0xf8 ); - rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf8) * 255 / 0xf8 ); - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_3d_texel_f_X1R5G5B5( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLushort s = *src; - texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0xf8) * 255 / 0xf8 ); - texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0xf8) * 255 / 0xf8 ); - texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf8) * 255 / 0xf8 ); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_3d_texel_X4R4G4B4( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLchan *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLchan *rgba = (GLchan *) texel; GLushort s = *src; - rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf ); - rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf ); - rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf ); - rgba[ACOMP] = CHAN_MAX; -} - -//--------------------------------------------------------------------------- - -static void gld_fetch_3d_texel_f_X4R4G4B4( - const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - const GLushort *src = USHORT_SRC( texImage, i, j, k ); - GLushort s = *src; - texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf ); - texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf ); - texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf ); - texel[ACOMP] = 1.f; -} - -//--------------------------------------------------------------------------- - -#undef CHAN_SRC -#undef UBYTE_SRC -#undef USHORT_SRC -#undef FLOAT_SRC - -//--------------------------------------------------------------------------- -// Direct3D texture formats that have no Mesa equivalent -//--------------------------------------------------------------------------- - -const struct gl_texture_format _gld_texformat_X8R8G8B8 = { - MESA_FORMAT_ARGB8888, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 8, /* RedBits */ - 8, /* GreenBits */ - 8, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 4, /* TexelBytes */ - _mesa_texstore_argb8888, /* StoreTexImageFunc */ - gld_fetch_1d_texel_X8R8G8B8, /* FetchTexel1D */ - gld_fetch_2d_texel_X8R8G8B8, /* FetchTexel2D */ - gld_fetch_3d_texel_X8R8G8B8, /* FetchTexel3D */ - gld_fetch_1d_texel_f_X8R8G8B8, /* FetchTexel1Df */ - gld_fetch_2d_texel_f_X8R8G8B8, /* FetchTexel2Df */ - gld_fetch_3d_texel_f_X8R8G8B8, /* FetchTexel3Df */ -}; - -const struct gl_texture_format _gld_texformat_X1R5G5B5 = { - MESA_FORMAT_ARGB1555, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 5, /* RedBits */ - 5, /* GreenBits */ - 5, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 2, /* TexelBytes */ - _mesa_texstore_argb1555, /* StoreTexImageFunc */ - gld_fetch_1d_texel_X1R5G5B5, /* FetchTexel1D */ - gld_fetch_2d_texel_X1R5G5B5, /* FetchTexel2D */ - gld_fetch_3d_texel_X1R5G5B5, /* FetchTexel3D */ - gld_fetch_1d_texel_f_X1R5G5B5, /* FetchTexel1Df */ - gld_fetch_2d_texel_f_X1R5G5B5, /* FetchTexel2Df */ - gld_fetch_3d_texel_f_X1R5G5B5, /* FetchTexel3Df */ -}; - -const struct gl_texture_format _gld_texformat_X4R4G4B4 = { - MESA_FORMAT_ARGB4444, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 4, /* RedBits */ - 4, /* GreenBits */ - 4, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 2, /* TexelBytes */ - _mesa_texstore_argb4444, /* StoreTexImageFunc */ - gld_fetch_1d_texel_X4R4G4B4, /* FetchTexel1D */ - gld_fetch_2d_texel_X4R4G4B4, /* FetchTexel2D */ - gld_fetch_3d_texel_X4R4G4B4, /* FetchTexel3D */ - gld_fetch_1d_texel_f_X4R4G4B4, /* FetchTexel1Df */ - gld_fetch_2d_texel_f_X4R4G4B4, /* FetchTexel2Df */ - gld_fetch_3d_texel_f_X4R4G4B4, /* FetchTexel3Df */ -}; - -//--------------------------------------------------------------------------- -// Texture unit constants -//--------------------------------------------------------------------------- - -// List of possible combinations of texture environments. -// Example: GLD_TEXENV_MODULATE_RGBA means -// GL_MODULATE, GL_RGBA base internal format. -#define GLD_TEXENV_DECAL_RGB 0 -#define GLD_TEXENV_DECAL_RGBA 1 -#define GLD_TEXENV_DECAL_ALPHA 2 -#define GLD_TEXENV_REPLACE_RGB 3 -#define GLD_TEXENV_REPLACE_RGBA 4 -#define GLD_TEXENV_REPLACE_ALPHA 5 -#define GLD_TEXENV_MODULATE_RGB 6 -#define GLD_TEXENV_MODULATE_RGBA 7 -#define GLD_TEXENV_MODULATE_ALPHA 8 -#define GLD_TEXENV_BLEND_RGB 9 -#define GLD_TEXENV_BLEND_RGBA 10 -#define GLD_TEXENV_BLEND_ALPHA 11 -#define GLD_TEXENV_ADD_RGB 12 -#define GLD_TEXENV_ADD_RGBA 13 -#define GLD_TEXENV_ADD_ALPHA 14 - -// Per-stage (i.e. per-unit) texture environment -typedef struct { - DWORD ColorArg1; // Colour argument 1 - D3DTEXTUREOP ColorOp; // Colour operation - DWORD ColorArg2; // Colour argument 2 - DWORD AlphaArg1; // Alpha argument 1 - D3DTEXTUREOP AlphaOp; // Alpha operation - DWORD AlphaArg2; // Alpha argument 2 -} GLD_texenv; - -// TODO: Do we really need to set ARG1 and ARG2 every time? -// They seem to always be TEXTURE and CURRENT respectively. - -// C = Colour out -// A = Alpha out -// Ct = Colour from Texture -// Cf = Colour from fragment (diffuse) -// At = Alpha from Texture -// Af = Alpha from fragment (diffuse) -// Cc = GL_TEXTURE_ENV_COLOUR (GL_BLEND) -const GLD_texenv gldTexEnv[] = { - // DECAL_RGB: C=Ct, A=Af - {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - // DECAL_RGBA: C=Cf(1-At)+CtAt, A=Af - {D3DTA_TEXTURE, D3DTOP_BLENDTEXTUREALPHA, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - // DECAL_ALPHA: <undefined> use DECAL_RGB - {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - - // REPLACE_RGB: C=Ct, A=Af - {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - // REPLACE_RGBA: C=Ct, A=At - {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT}, - // REPLACE_ALPHA: C=Cf, A=At - {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT}, - - // MODULATE_RGB: C=CfCt, A=Af - {D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - // MODULATE_RGBA: C=CfCt, A=AfAt - {D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, - // MODULATE_ALPHA: C=Cf, A=AfAt - {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, - - // BLEND_RGB: C=Cf(1-Ct)+CcCt, A=Af - {D3DTA_TEXTURE, D3DTOP_LERP, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - // BLEND_RGBA: C=Cf(1-Ct)+CcCt, A=AfAt - {D3DTA_TEXTURE, D3DTOP_LERP, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, - // BLEND_ALPHA: C=Cf, A=AfAt - {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, - - // ADD_RGB: C=Cf+Ct, A=Af - {D3DTA_TEXTURE, D3DTOP_ADD, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, - // ADD_RGBA: C=Cf+Ct, A=AfAt - {D3DTA_TEXTURE, D3DTOP_ADD, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, - // ADD_ALPHA: C=Cf, A=AfAt - {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, - D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, -}; - -//--------------------------------------------------------------------------- - -D3DTEXTUREADDRESS _gldConvertWrap( - GLenum wrap) -{ - return (wrap == GL_CLAMP) ? D3DTADDRESS_CLAMP : D3DTADDRESS_WRAP; -} - -//--------------------------------------------------------------------------- - -D3DTEXTUREFILTERTYPE _gldConvertMagFilter( - GLenum magfilter) -{ - return (magfilter == GL_LINEAR) ? D3DTEXF_LINEAR : D3DTEXF_POINT; -} - -//--------------------------------------------------------------------------- - -void _gldConvertMinFilter( - GLenum minfilter, - D3DTEXTUREFILTERTYPE *min_filter, - D3DTEXTUREFILTERTYPE *mip_filter) -{ - switch (minfilter) { - case GL_NEAREST: - *min_filter = D3DTEXF_POINT; - *mip_filter = D3DTEXF_NONE; - break; - case GL_LINEAR: - *min_filter = D3DTEXF_LINEAR; - *mip_filter = D3DTEXF_NONE; - break; - case GL_NEAREST_MIPMAP_NEAREST: - *min_filter = D3DTEXF_POINT; - *mip_filter = D3DTEXF_POINT; - break; - case GL_LINEAR_MIPMAP_NEAREST: - *min_filter = D3DTEXF_LINEAR; - *mip_filter = D3DTEXF_POINT; - break; - case GL_NEAREST_MIPMAP_LINEAR: - *min_filter = D3DTEXF_POINT; - *mip_filter = D3DTEXF_LINEAR; - break; - case GL_LINEAR_MIPMAP_LINEAR: - *min_filter = D3DTEXF_LINEAR; - *mip_filter = D3DTEXF_LINEAR; - break; - } -} - -//--------------------------------------------------------------------------- - -D3DFORMAT _gldGLFormatToD3DFormat( - GLenum internalFormat) -{ - switch (internalFormat) { - case GL_INTENSITY: - case GL_INTENSITY4: - case GL_INTENSITY8: - case GL_INTENSITY12: - case GL_INTENSITY16: - // LUNIMANCE != INTENSITY, but D3D doesn't have I8 textures - return D3DFMT_L8; - case 1: - case GL_LUMINANCE: - case GL_LUMINANCE4: - case GL_LUMINANCE8: - case GL_LUMINANCE12: - case GL_LUMINANCE16: - return D3DFMT_L8; - case GL_ALPHA: - case GL_ALPHA4: - case GL_ALPHA8: - case GL_ALPHA12: - case GL_ALPHA16: - return D3DFMT_A8; - case GL_COLOR_INDEX: - case GL_COLOR_INDEX1_EXT: - case GL_COLOR_INDEX2_EXT: - case GL_COLOR_INDEX4_EXT: - case GL_COLOR_INDEX8_EXT: - case GL_COLOR_INDEX12_EXT: - case GL_COLOR_INDEX16_EXT: - return D3DFMT_X8R8G8B8; - case 2: - case GL_LUMINANCE_ALPHA: - case GL_LUMINANCE4_ALPHA4: - case GL_LUMINANCE6_ALPHA2: - case GL_LUMINANCE8_ALPHA8: - case GL_LUMINANCE12_ALPHA4: - case GL_LUMINANCE12_ALPHA12: - case GL_LUMINANCE16_ALPHA16: - return D3DFMT_A8L8; - case GL_R3_G3_B2: - // TODO: Mesa does not support RGB332 internally - return D3DFMT_X4R4G4B4; //D3DFMT_R3G3B2; - case GL_RGB4: - return D3DFMT_X4R4G4B4; - case GL_RGB5: - return D3DFMT_X1R5G5B5; - case 3: - case GL_RGB: - case GL_RGB8: - case GL_RGB10: - case GL_RGB12: - case GL_RGB16: - return D3DFMT_R8G8B8; - case GL_RGBA4: - return D3DFMT_A4R4G4B4; - case 4: - case GL_RGBA: - case GL_RGBA2: - case GL_RGBA8: - case GL_RGB10_A2: - case GL_RGBA12: - case GL_RGBA16: - return D3DFMT_A8R8G8B8; - case GL_RGB5_A1: - return D3DFMT_A1R5G5B5; - } - - // Return an acceptable default - return D3DFMT_A8R8G8B8; -} - -//--------------------------------------------------------------------------- - -GLenum _gldDecodeBaseFormat( - IDirect3DTexture9 *pTex) -{ - // Examine Direct3D texture and return base OpenGL internal texture format - // NOTE: We can't use any base format info from Mesa because D3D might have - // used a different texture format when we used D3DXCreateTexture(). - - // Base internal format is one of (Red Book p355): - // GL_ALPHA, - // GL_LUMINANCE, - // GL_LUMINANCE_ALPHA, - // GL_INTENSITY, - // GL_RGB, - // GL_RGBA - - // NOTE: INTENSITY not used (not supported by Direct3D) - // LUMINANCE has same texture functions as RGB - // LUMINANCE_ALPHA has same texture functions as RGBA - - // TODO: cache format instead of using GetLevelDesc() - D3DSURFACE_DESC desc; - _GLD_DX9_TEX(GetLevelDesc(pTex, 0, &desc)); - - switch (desc.Format) { - case D3DFMT_R8G8B8: - case D3DFMT_X8R8G8B8: - case D3DFMT_R5G6B5: - case D3DFMT_X1R5G5B5: - case D3DFMT_R3G3B2: - case D3DFMT_X4R4G4B4: - case D3DFMT_P8: - case D3DFMT_L8: - return GL_RGB; - case D3DFMT_A8R8G8B8: - case D3DFMT_A1R5G5B5: - case D3DFMT_A4R4G4B4: - case D3DFMT_A8R3G3B2: - case D3DFMT_A8P8: - case D3DFMT_A8L8: - case D3DFMT_A4L4: - return GL_RGBA; - case D3DFMT_A8: - return GL_ALPHA; - // Compressed texture formats. Need to check these... - case D3DFMT_DXT1: - return GL_RGBA; - case D3DFMT_DXT2: - return GL_RGB; - case D3DFMT_DXT3: - return GL_RGBA; - case D3DFMT_DXT4: - return GL_RGB; - case D3DFMT_DXT5: - return GL_RGBA; - } - - // Fell through. Return arbitary default. - return GL_RGBA; -} - -//--------------------------------------------------------------------------- - -const struct gl_texture_format* _gldMesaFormatForD3DFormat( - D3DFORMAT d3dfmt) -{ - switch (d3dfmt) { - case D3DFMT_A8R8G8B8: - return &_mesa_texformat_argb8888; - case D3DFMT_R8G8B8: - return &_mesa_texformat_rgb888; - case D3DFMT_R5G6B5: - return &_mesa_texformat_rgb565; - case D3DFMT_A4R4G4B4: - return &_mesa_texformat_argb4444; - case D3DFMT_A1R5G5B5: - return &_mesa_texformat_argb1555; - case D3DFMT_A8L8: - return &_mesa_texformat_al88; - case D3DFMT_R3G3B2: - return &_mesa_texformat_rgb332; - case D3DFMT_A8: - return &_mesa_texformat_a8; - case D3DFMT_L8: - return &_mesa_texformat_l8; - case D3DFMT_X8R8G8B8: - return &_gld_texformat_X8R8G8B8; - case D3DFMT_X1R5G5B5: - return &_gld_texformat_X1R5G5B5; - case D3DFMT_X4R4G4B4: - return &_gld_texformat_X4R4G4B4; - } - - // If we reach here then we've made an error somewhere else - // by allowing a format that is not supported. - assert(0); - - return NULL; // Shut up compiler warning -} - -//--------------------------------------------------------------------------- -// Copy* functions -//--------------------------------------------------------------------------- - -void gldCopyTexImage1D_DX9( - GLcontext *ctx, - GLenum target, GLint level, - GLenum internalFormat, - GLint x, GLint y, - GLsizei width, GLint border ) -{ - // TODO -} - -//--------------------------------------------------------------------------- - -void gldCopyTexImage2D_DX9( - GLcontext *ctx, - GLenum target, - GLint level, - GLenum internalFormat, - GLint x, - GLint y, - GLsizei width, - GLsizei height, - GLint border) -{ - // TODO -} - -//--------------------------------------------------------------------------- - -void gldCopyTexSubImage1D_DX9( - GLcontext *ctx, - GLenum target, GLint level, - GLint xoffset, GLint x, GLint y, GLsizei width ) -{ - // TODO -} - -//--------------------------------------------------------------------------- - -void gldCopyTexSubImage2D_DX9( - GLcontext *ctx, - GLenum target, - GLint level, - GLint xoffset, - GLint yoffset, - GLint x, - GLint y, - GLsizei width, - GLsizei height) -{ - // TODO -} - -//--------------------------------------------------------------------------- - -void gldCopyTexSubImage3D_DX9( - GLcontext *ctx, - GLenum target, - GLint level, - GLint xoffset, - GLint yoffset, - GLint zoffset, - GLint x, - GLint y, - GLsizei width, - GLsizei height ) -{ - // TODO ? -} - -//--------------------------------------------------------------------------- -// Bitmap/Pixel functions -//--------------------------------------------------------------------------- - -#define GLD_FLIP_Y(y) (gldCtx->dwHeight - (y)) - -#define _GLD_FVF_IMAGE (D3DFVF_XYZRHW | D3DFVF_TEX1) - -typedef struct { - FLOAT x, y; // 2D raster coords - FLOAT z; // depth value - FLOAT rhw; // reciprocal homogenous W (always 1.0f) - FLOAT tu, tv; // texture coords -} _GLD_IMAGE_VERTEX; - -//--------------------------------------------------------------------------- - -HRESULT _gldDrawPixels( - GLcontext *ctx, - BOOL bChromakey, // Alpha test for glBitmap() images - GLint x, // GL x position - GLint y, // GL y position (needs flipping) - GLsizei width, // Width of input image - GLsizei height, // Height of input image - IDirect3DSurface9 *pImage) -{ - // - // Draw input image as texture implementing PixelZoom and clipping. - // Any fragment operations currently enabled will be used. - // - - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - IDirect3DTexture9 *pTexture; - D3DSURFACE_DESC d3dsd; - IDirect3DSurface9 *pSurface; - _GLD_IMAGE_VERTEX v[4]; - HRESULT hr; - - float ZoomWidth, ZoomHeight; - float ScaleWidth, ScaleHeight; - - // Create a texture to hold image - hr = D3DXCreateTexture( - gld->pDev, - width, height, - 1, // miplevels - 0, // usage - D3DFMT_A8R8G8B8, // format - D3DPOOL_MANAGED, // pool - &pTexture); - if (FAILED(hr)) - return hr; - - hr = IDirect3DTexture9_GetSurfaceLevel(pTexture, 0, &pSurface); - if (FAILED(hr)) { - IDirect3DTexture9_Release(pTexture); - return hr; - } - - // Copy image into texture - hr = D3DXLoadSurfaceFromSurface( - pSurface, NULL, NULL, // Dest surface - pImage, NULL, NULL, // Src surface - D3DX_FILTER_NONE, - 0); - IDirect3DSurface9_Release(pSurface); - if (FAILED(hr)) { - IDirect3DTexture9_Release(pTexture); - return hr; - } - - // - // Set up the quad like this (ascii-art ahead!) - // - // 3--2 - // | | - // 0--1 - // - // - - // Set depth - v[0].z = v[1].z = v[2].z = v[3].z = ctx->Current.RasterPos[2]; - // Set Reciprocal Homogenous W - v[0].rhw = v[1].rhw = v[2].rhw = v[3].rhw = 1.0f; - - // Set texcoords - // Examine texture size - if different to input width and height - // then we'll need to munge the texcoords to fit. - IDirect3DTexture9_GetLevelDesc(pTexture, 0, &d3dsd); - ScaleWidth = (float)width / (float)d3dsd.Width; - ScaleHeight = (float)height / (float)d3dsd.Height; - v[0].tu = 0.0f; v[0].tv = 0.0f; - v[1].tu = ScaleWidth; v[1].tv = 0.0f; - v[2].tu = ScaleWidth; v[2].tv = ScaleHeight; - v[3].tu = 0.0f; v[3].tv = ScaleHeight; - - // Set raster positions - ZoomWidth = (float)width * ctx->Pixel.ZoomX; - ZoomHeight = (float)height * ctx->Pixel.ZoomY; - - v[0].x = x; v[0].y = GLD_FLIP_Y(y); - v[1].x = x+ZoomWidth; v[1].y = GLD_FLIP_Y(y); - v[2].x = x+ZoomWidth; v[2].y = GLD_FLIP_Y(y+ZoomHeight); - v[3].x = x; v[3].y = GLD_FLIP_Y(y+ZoomHeight); - - // Draw image with full HW acceleration - // NOTE: Be nice to use a State Block for all this state... - IDirect3DDevice9_SetTexture(gld->pDev, 0, pTexture); - IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_CULLMODE, D3DCULL_NONE); - IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_CLIPPING, TRUE); - -// IDirect3DDevice9_SetTextureStageState(gld->pDev, 0, D3DTSS_MINFILTER, D3DTEXF_POINT); -// IDirect3DDevice9_SetTextureStageState(gld->pDev, 0, D3DTSS_MIPFILTER, D3DTEXF_POINT); -// IDirect3DDevice9_SetTextureStageState(gld->pDev, 0, D3DTSS_MAGFILTER, D3DTEXF_POINT); -// IDirect3DDevice9_SetTextureStageState(gld->pDev, 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); -// IDirect3DDevice9_SetTextureStageState(gld->pDev, 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); - IDirect3DDevice9_SetSamplerState(gld->pDev, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT); - IDirect3DDevice9_SetSamplerState(gld->pDev, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT); - IDirect3DDevice9_SetSamplerState(gld->pDev, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); - IDirect3DDevice9_SetSamplerState(gld->pDev, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); - IDirect3DDevice9_SetSamplerState(gld->pDev, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); - - IDirect3DDevice9_SetTextureStageState(gld->pDev, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); - IDirect3DDevice9_SetTextureStageState(gld->pDev, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - IDirect3DDevice9_SetTextureStageState(gld->pDev, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(gld->pDev, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(gld->pDev, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); - IDirect3DDevice9_SetTextureStageState(gld->pDev, 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); - - IDirect3DDevice9_SetVertexShader(gld->pDev, NULL); - IDirect3DDevice9_SetFVF(gld->pDev, _GLD_FVF_IMAGE); - - // - // Emulate Chromakey with an Alpha Test. - // [Alpha Test is more widely supported anyway] - // - if (bChromakey) { - // Switch on alpha testing - IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_ALPHATESTENABLE, TRUE); - // Fragment passes is alpha is greater than reference value - IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_ALPHAFUNC, D3DCMP_GREATER); - // Set alpha reference value between Bitmap alpha values of - // zero (transparent) and one (opaque). - IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_ALPHAREF, 0x7f); - } - - IDirect3DDevice9_DrawPrimitiveUP(gld->pDev, D3DPT_TRIANGLEFAN, 2, &v, sizeof(_GLD_IMAGE_VERTEX)); - - // Release texture - IDirect3DDevice9_SetTexture(gld->pDev, 0, NULL); - IDirect3DTexture9_Release(pTexture); - - // Reset state to before we messed it up - FLUSH_VERTICES(ctx, _NEW_ALL); - - return S_OK; -} - -//--------------------------------------------------------------------------- - -void gld_DrawPixels_DX9( - GLcontext *ctx, - GLint x, GLint y, GLsizei width, GLsizei height, - GLenum format, GLenum type, - const struct gl_pixelstore_attrib *unpack, - const GLvoid *pixels ) -{ - GLD_context *gldCtx; - GLD_driver_dx9 *gld; - - IDirect3DSurface9 *pImage; - HRESULT hr; - D3DLOCKED_RECT d3dLockedRect; - - const struct gl_texture_format *MesaFormat; - - MesaFormat = _mesa_choose_tex_format(ctx, format, format, type); - - // Mesa does not currently handle this format. - if (format == GL_BGR) - return; - - gldCtx = GLD_GET_CONTEXT(ctx); - gld = GLD_GET_DX9_DRIVER(gldCtx); - - hr = IDirect3DDevice9_CreateOffscreenPlainSurface( - gld->pDev, - width, - height, - D3DFMT_A8R8G8B8, - D3DPOOL_SCRATCH, - &pImage, - NULL); - if (FAILED(hr)) { - return; - } - - // - // Use Mesa to fill in image - // - - // Lock all of surface - hr = IDirect3DSurface9_LockRect(pImage, &d3dLockedRect, NULL, 0); - if (FAILED(hr)) { - IDirect3DSurface9_Release(pImage); - return; - } - - // unpack image, apply transfer ops and store directly in texture - MesaFormat->StoreImage( - ctx, - 2, - GL_RGBA, - &_mesa_texformat_argb8888, - d3dLockedRect.pBits, - width, height, 1, 0, 0, 0, - d3dLockedRect.Pitch, - 0, /* dstImageStride */ - format, type, pixels, unpack); - - IDirect3DSurface9_UnlockRect(pImage); - - _gldDrawPixels(ctx, FALSE, x, y, width, height, pImage); - - IDirect3DSurface9_Release(pImage); -} - -//--------------------------------------------------------------------------- - -void gld_ReadPixels_DX9( - GLcontext *ctx, - GLint x, GLint y, GLsizei width, GLsizei height, - GLenum format, GLenum type, - const struct gl_pixelstore_attrib *pack, - GLvoid *dest) -{ - - GLD_context *gldCtx; - GLD_driver_dx9 *gld; - - IDirect3DSurface9 *pBackbuffer = NULL; - IDirect3DSurface9 *pNativeImage = NULL; - IDirect3DSurface9 *pCanonicalImage = NULL; - - D3DSURFACE_DESC d3dsd; - RECT rcSrc; // Source rect - POINT ptDst; // Dest point - HRESULT hr; - D3DLOCKED_RECT d3dLockedRect; - struct gl_pixelstore_attrib srcPacking; - int i; - GLint DstRowStride; - const struct gl_texture_format *MesaFormat; - - switch (format) { - case GL_STENCIL_INDEX: - case GL_DEPTH_COMPONENT: - return; - } - - MesaFormat = _mesa_choose_tex_format(ctx, format, format, type); - DstRowStride = _mesa_image_row_stride(pack, width, format, type); - - gldCtx = GLD_GET_CONTEXT(ctx); - gld = GLD_GET_DX9_DRIVER(gldCtx); - - // Get backbuffer - hr = IDirect3DDevice9_GetBackBuffer( - gld->pDev, - 0, // First swapchain - 0, // First backbuffer - D3DBACKBUFFER_TYPE_MONO, - &pBackbuffer); - if (FAILED(hr)) - return; - - // Get backbuffer description - hr = IDirect3DSurface9_GetDesc(pBackbuffer, &d3dsd); - if (FAILED(hr)) { - goto gld_ReadPixels_DX9_return; - } - - // Create a surface compatible with backbuffer - hr = IDirect3DDevice9_CreateOffscreenPlainSurface( - gld->pDev, - width, - height, - d3dsd.Format, - D3DPOOL_SCRATCH, - &pNativeImage, - NULL); - if (FAILED(hr)) { - goto gld_ReadPixels_DX9_return; - } - - // Compute source rect and dest point - SetRect(&rcSrc, 0, 0, width, height); - OffsetRect(&rcSrc, x, GLD_FLIP_HEIGHT(y, height)); - ptDst.x = ptDst.y = 0; - - // Get source pixels. - // - // This intermediate surface ensure that we can use CopyRects() - // instead of relying on D3DXLoadSurfaceFromSurface(), which may - // try and lock the backbuffer. This way seems safer. - // - // CopyRects has been removed for DX9. - // -/* hr = IDirect3DDevice9_CopyRects( - gld->pDev, - pBackbuffer, - &rcSrc, - 1, - pNativeImage, - &ptDst);*/ - hr = D3DXLoadSurfaceFromSurface( - pNativeImage, // Dest surface - NULL, // Dest palette - &rcSrc, // Dest rect - pBackbuffer, // Src surface - NULL, // Src palette - &rcSrc, // Src rect - D3DX_FILTER_NONE, // Filter - 0 // Colorkey (0=no colorkey) - ); - if (FAILED(hr)) { - goto gld_ReadPixels_DX9_return; - } - - // Create an RGBA8888 surface - hr = IDirect3DDevice9_CreateOffscreenPlainSurface( - gld->pDev, - width, - height, - D3DFMT_A8R8G8B8, - D3DPOOL_SCRATCH, - &pCanonicalImage, - NULL); - if (FAILED(hr)) { - goto gld_ReadPixels_DX9_return; - } - - // Convert to RGBA8888 - hr = D3DXLoadSurfaceFromSurface( - pCanonicalImage, // Dest surface - NULL, NULL, // Dest palette, RECT - pNativeImage, // Src surface - NULL, NULL, // Src palette, RECT - D3DX_FILTER_NONE, // Filter - 0); // Colourkey - if (FAILED(hr)) { - goto gld_ReadPixels_DX9_return; - } - - srcPacking.Alignment = 1; - srcPacking.ImageHeight = height; - srcPacking.LsbFirst = GL_FALSE; - srcPacking.RowLength = 0; - srcPacking.SkipImages = 0; - srcPacking.SkipPixels = 0; - srcPacking.SkipRows = 0; - srcPacking.SwapBytes = GL_FALSE; - - // Lock all of image - hr = IDirect3DSurface9_LockRect(pCanonicalImage, &d3dLockedRect, NULL, 0); - if (FAILED(hr)) { - goto gld_ReadPixels_DX9_return; - } - - // We need to flip the data. Yuck. - // Perhaps Mesa has a span packer we can use in future... - for (i=0; i<height; i++) { - BYTE *pDestRow = (BYTE*)_mesa_image_address(2,pack, dest, width, height, format, type, 0, i, 0); - BYTE *pSrcRow = (BYTE*)d3dLockedRect.pBits + (d3dLockedRect.Pitch * (height-i-1)); - MesaFormat->StoreImage( - ctx, - 2, - GL_RGBA, // base format - MesaFormat, // dst format - pDestRow, // dest addr - width, 1, 1, 0, 0, 0, // src x,y,z & dst offsets x,y,z - DstRowStride, // dst row stride - 0, // dstImageStride - GL_BGRA, // src format - GL_UNSIGNED_BYTE, // src type - pSrcRow, // src addr - &srcPacking); // packing params of source image - } - - IDirect3DSurface9_UnlockRect(pCanonicalImage); - -gld_ReadPixels_DX9_return: - SAFE_RELEASE_SURFACE9(pCanonicalImage); - SAFE_RELEASE_SURFACE9(pNativeImage); - SAFE_RELEASE_SURFACE9(pBackbuffer); -} - -//--------------------------------------------------------------------------- - -void gld_CopyPixels_DX9( - GLcontext *ctx, - GLint srcx, - GLint srcy, - GLsizei width, - GLsizei height, - GLint dstx, - GLint dsty, - GLenum type) -{ - // - // NOTE: Not allowed to copy vidmem to vidmem! - // Therefore we use an intermediate image surface. - // - - GLD_context *gldCtx; - GLD_driver_dx9 *gld; - - IDirect3DSurface9 *pBackbuffer; - D3DSURFACE_DESC d3dsd; - IDirect3DSurface9 *pImage; - RECT rcSrc; // Source rect - POINT ptDst; // Dest point - HRESULT hr; - - // Only backbuffer - if (type != GL_COLOR) - return; - - gldCtx = GLD_GET_CONTEXT(ctx); - gld = GLD_GET_DX9_DRIVER(gldCtx); - - // Get backbuffer - hr = IDirect3DDevice9_GetBackBuffer( - gld->pDev, - 0, // First swapchain - 0, // First backbuffer - D3DBACKBUFFER_TYPE_MONO, - &pBackbuffer); - if (FAILED(hr)) - return; - - // Get backbuffer description - hr = IDirect3DSurface9_GetDesc(pBackbuffer, &d3dsd); - if (FAILED(hr)) { - IDirect3DSurface9_Release(pBackbuffer); - return; - } - - // Create a surface compatible with backbuffer - hr = IDirect3DDevice9_CreateOffscreenPlainSurface( - gld->pDev, - width, - height, - d3dsd.Format, - D3DPOOL_SCRATCH, - &pImage, - NULL); - if (FAILED(hr)) { - IDirect3DSurface9_Release(pBackbuffer); - return; - } - - // Compute source rect and dest point - SetRect(&rcSrc, 0, 0, width, height); - OffsetRect(&rcSrc, srcx, GLD_FLIP_HEIGHT(srcy, height)); - ptDst.x = ptDst.y = 0; - - // Get source pixels -/* hr = IDirect3DDevice8_CopyRects( - gld->pDev, - pBackbuffer, - &rcSrc, - 1, - pImage, - &ptDst);*/ - hr = D3DXLoadSurfaceFromSurface( - pImage, // Dest surface - NULL, // Dest palette - &rcSrc, // Dest rect - pBackbuffer, // Src surface - NULL, // Src palette - &rcSrc, // Src rect - D3DX_FILTER_NONE, // Filter - 0 // Colorkey (0=no colorkey) - ); - IDirect3DSurface9_Release(pBackbuffer); - if (FAILED(hr)) { - IDirect3DSurface9_Release(pImage); - return; - } - - _gldDrawPixels(ctx, FALSE, dstx, dsty, width, height, pImage); - - IDirect3DSurface9_Release(pImage); -} - -//--------------------------------------------------------------------------- - -void gld_Bitmap_DX9( - GLcontext *ctx, - GLint x, - GLint y, - GLsizei width, - GLsizei height, - const struct gl_pixelstore_attrib *unpack, - const GLubyte *bitmap) -{ - GLD_context *gldCtx; - GLD_driver_dx9 *gld; - - IDirect3DSurface9 *pImage; - HRESULT hr; - D3DLOCKED_RECT d3dLockedRect; - BYTE *pTempBitmap; - D3DCOLOR clBitmapOne, clBitmapZero; - D3DCOLOR *pBits; - const GLubyte *src; - int i, j, k; - - gldCtx = GLD_GET_CONTEXT(ctx); - gld = GLD_GET_DX9_DRIVER(gldCtx); - - // A NULL bitmap is valid, but merely advances the raster position - if ((bitmap == NULL) || (width == 0) || (height == 0)) - return; - - clBitmapZero = D3DCOLOR_RGBA(0,0,0,0); // NOTE: Alpha is Zero - clBitmapOne = D3DCOLOR_COLORVALUE( - ctx->Current.RasterColor[0], - ctx->Current.RasterColor[1], - ctx->Current.RasterColor[2], - 1.0f); // NOTE: Alpha is One - - hr = IDirect3DDevice9_CreateOffscreenPlainSurface( - gld->pDev, - width, - height, - D3DFMT_A8R8G8B8, - D3DPOOL_SCRATCH, - &pImage, - NULL); - if (FAILED(hr)) { - return; - } - - // Lock all of surface - hr = IDirect3DSurface9_LockRect(pImage, &d3dLockedRect, NULL, 0); - if (FAILED(hr)) { - IDirect3DSurface9_Release(pImage); - return; - } - - pTempBitmap = _mesa_unpack_bitmap(width, height, bitmap, unpack); - if (pTempBitmap == NULL) { - IDirect3DSurface9_Release(pImage); - return; - } - - pBits = (D3DCOLOR*)d3dLockedRect.pBits; - - for (i=0; i<height; i++) { - GLubyte byte; - pBits = (D3DCOLOR*)((BYTE*)d3dLockedRect.pBits + (i*d3dLockedRect.Pitch)); - src = (const GLubyte *) _mesa_image_address(2, - &ctx->DefaultPacking, pTempBitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, - 0, i, 0); - for (j=0; j<(width>>3); j++) { - byte = *src++; - for (k=0; k<8; k++) { - *pBits++ = (byte & 128) ? clBitmapOne : clBitmapZero; - byte <<= 1; - } - } - // Fill remaining bits from bitmap - if (width & 7) { - byte = *src; - for (k=0; k<(width & 7); k++) { - *pBits++ = (byte & 128) ? clBitmapOne : clBitmapZero; - byte <<= 1; - } - } - } - - FREE(pTempBitmap); - -/* - // unpack image, apply transfer ops and store directly in texture - texImage->TexFormat->StoreImage( - ctx, - 2, - GL_BITMAP, - &_mesa_texformat_argb8888, - d3dLockedRect.pBits, - width, height, 1, 0, 0, 0, - d3dLockedRect.Pitch, - 0, // dstImageStride - GL_BITMAP, GL_COLOR_INDEX, bitmap, unpack); -*/ - IDirect3DSurface9_UnlockRect(pImage); - - _gldDrawPixels(ctx, TRUE, x, y, width, height, pImage); - - IDirect3DSurface9_Release(pImage); -} - -//--------------------------------------------------------------------------- -// Texture functions -//--------------------------------------------------------------------------- - -void _gldAllocateTexture( - GLcontext *ctx, - struct gl_texture_object *tObj, - struct gl_texture_image *texImage) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - IDirect3DTexture9 *pTex; - D3DFORMAT d3dFormat; - - if (!tObj || !texImage) - return; - - pTex = (IDirect3DTexture9*)tObj->DriverData; - if (pTex) { - // Decide whether we can keep existing D3D texture - // by examining top-level surface. - D3DSURFACE_DESC d3dsd; - _GLD_DX9_TEX(GetLevelDesc(pTex, 0, &d3dsd)); - // Release existing texture if not compatible - if ((d3dsd.Width == texImage->Width) || - (d3dsd.Height == texImage->Height)) - { - return; // Keep the existing texture - } - tObj->DriverData = NULL; - _GLD_DX9_TEX(Release(pTex)); - } - - d3dFormat = _gldGLFormatToD3DFormat(texImage->IntFormat); - D3DXCreateTexture( - gld->pDev, - texImage->Width, - texImage->Height, - // TODO: Re-evaluate mipmapping - (glb.bUseMipmaps) ? D3DX_DEFAULT : 1, - 0, // Usage - d3dFormat, - D3DPOOL_MANAGED, - &pTex); - tObj->DriverData = pTex; -} - -//--------------------------------------------------------------------------- - -const struct gl_texture_format* gld_ChooseTextureFormat_DX9( - GLcontext *ctx, - GLint internalFormat, - GLenum srcFormat, - GLenum srcType) -{ - // [Based on mesa_choose_tex_format()] - // - // We will choose only texture formats that are supported - // by Direct3D. If the hardware doesn't support a particular - // texture format, then the D3DX texture calls that we use - // will automatically use a HW supported format. - // - // The most critical aim is to reduce copying; if we can use - // texture-image data directly then it will be a big performance assist. - // - - switch (internalFormat) { - case GL_INTENSITY: - case GL_INTENSITY4: - case GL_INTENSITY8: - case GL_INTENSITY12: - case GL_INTENSITY16: - return &_mesa_texformat_l8; // D3DFMT_L8 - case 1: - case GL_LUMINANCE: - case GL_LUMINANCE4: - case GL_LUMINANCE8: - case GL_LUMINANCE12: - case GL_LUMINANCE16: - return &_mesa_texformat_l8; // D3DFMT_L8 - case GL_ALPHA: - case GL_ALPHA4: - case GL_ALPHA8: - case GL_ALPHA12: - case GL_ALPHA16: - return &_mesa_texformat_a8; // D3DFMT_A8 - case GL_COLOR_INDEX: - case GL_COLOR_INDEX1_EXT: - case GL_COLOR_INDEX2_EXT: - case GL_COLOR_INDEX4_EXT: - case GL_COLOR_INDEX8_EXT: - case GL_COLOR_INDEX12_EXT: - case GL_COLOR_INDEX16_EXT: - return &_mesa_texformat_rgb565; // D3DFMT_R5G6B5 - // Mesa will convert this for us later... - // return &_mesa_texformat_ci8; // D3DFMT_R5G6B5 - case 2: - case GL_LUMINANCE_ALPHA: - case GL_LUMINANCE4_ALPHA4: - case GL_LUMINANCE6_ALPHA2: - case GL_LUMINANCE8_ALPHA8: - case GL_LUMINANCE12_ALPHA4: - case GL_LUMINANCE12_ALPHA12: - case GL_LUMINANCE16_ALPHA16: - return &_mesa_texformat_al88; // D3DFMT_A8L8 - case GL_R3_G3_B2: - return &_mesa_texformat_rgb332; // D3DFMT_R3G3B2 - case GL_RGB4: - case GL_RGBA4: - case GL_RGBA2: - return &_mesa_texformat_argb4444; // D3DFMT_A4R4G4B4 - case 3: - case GL_RGB: - case GL_RGB5: - case GL_RGB8: - case GL_RGB10: - case GL_RGB12: - case GL_RGB16: - return &_mesa_texformat_rgb565; - case 4: - case GL_RGBA: - case GL_RGBA8: - case GL_RGB10_A2: - case GL_RGBA12: - case GL_RGBA16: - return &_mesa_texformat_argb8888; - case GL_RGB5_A1: - return &_mesa_texformat_argb1555; - default: - _mesa_problem(NULL, "unexpected format in fxDDChooseTextureFormat"); - return NULL; - } -} - -//--------------------------------------------------------------------------- - -/* -// Safer(?), slower version. -void gld_TexImage2D_DX9( - GLcontext *ctx, - GLenum target, - GLint level, - GLint internalFormat, - GLint width, - GLint height, - GLint border, - GLenum format, - GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *tObj, - struct gl_texture_image *texImage) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - IDirect3DTexture9 *pTex; - IDirect3DSurface9 *pSurface; - RECT rcSrcRect; - HRESULT hr; - GLint texelBytes = 4; - GLvoid *tempImage; - - if (!tObj || !texImage) - return; - - if (level == 0) { - _gldAllocateTexture(ctx, tObj, texImage); - } - - pTex = (IDirect3DTexture9*)tObj->DriverData; - if (!pTex) - return; // Texture has not been created - if (level >= IDirect3DTexture9_GetLevelCount(pTex)) - return; // Level does not exist - hr = IDirect3DTexture9_GetSurfaceLevel(pTex, level, &pSurface); - if (FAILED(hr)) - return; // Surface level doesn't exist (or just a plain error) - - tempImage = MALLOC(width * height * texelBytes); - if (!tempImage) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); - IDirect3DSurface9_Release(pSurface); - return; - } - // unpack image, apply transfer ops and store in tempImage - texImage->TexFormat->StoreImage(ctx, 2, texImage->Format, - &_mesa_texformat_argb8888, // dest format - tempImage, - width, height, 1, 0, 0, 0, - width * texelBytes, - 0, // dstImageStride - format, type, pixels, packing); - - SetRect(&rcSrcRect, 0, 0, width, height); - D3DXLoadSurfaceFromMemory( - pSurface, - NULL, - NULL, - tempImage, - D3DFMT_A8R8G8B8, - width * texelBytes, - NULL, - &rcSrcRect, - D3DX_FILTER_NONE, - 0); - - FREE(tempImage); - IDirect3DSurface9_Release(pSurface); -} -*/ - -//--------------------------------------------------------------------------- - -// Faster, more efficient version. -// Copies subimage straight to dest texture -void gld_TexImage2D_DX9( - GLcontext *ctx, - GLenum target, - GLint level, - GLint internalFormat, - GLint width, - GLint height, - GLint border, - GLenum format, - GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *tObj, - struct gl_texture_image *texImage) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - IDirect3DTexture9 *pTex; - IDirect3DSurface9 *pSurface; - HRESULT hr; - D3DLOCKED_RECT d3dLockedRect; - D3DSURFACE_DESC d3dsd; - - if (!tObj || !texImage) - return; - - // GLQUAKE FIX - // Test for input alpha data with non-alpha internalformat - if (((internalFormat==3) || (internalFormat==GL_RGB)) && (format==GL_RGBA)) { - // Input format has alpha, but a non-alpha format has been requested. - texImage->IntFormat = GL_RGBA; - internalFormat = GL_RGBA; - } - - if (level == 0) { - _gldAllocateTexture(ctx, tObj, texImage); - } - - pTex = (IDirect3DTexture9*)tObj->DriverData; - if (!pTex) - return; // Texture has not been created - if (level >= IDirect3DTexture9_GetLevelCount(pTex)) - return; // Level does not exist - hr = IDirect3DTexture9_GetSurfaceLevel(pTex, level, &pSurface); - if (FAILED(hr)) - return; // Surface level doesn't exist (or just a plain error) - - IDirect3DSurface9_GetDesc(pSurface, &d3dsd); - - // Lock all of surface - hr = IDirect3DSurface9_LockRect(pSurface, &d3dLockedRect, NULL, 0); - if (FAILED(hr)) { - IDirect3DSurface9_Release(pSurface); - return; - } - - // unpack image, apply transfer ops and store directly in texture - texImage->TexFormat->StoreImage( - ctx, - 2, - texImage->Format, - _gldMesaFormatForD3DFormat(d3dsd.Format), - d3dLockedRect.pBits, - width, height, 1, 0, 0, 0, - d3dLockedRect.Pitch, - 0, // dstImageStride - format, type, pixels, packing); - - IDirect3DSurface9_UnlockRect(pSurface); - IDirect3DSurface9_Release(pSurface); -} - -//--------------------------------------------------------------------------- - -void gld_TexImage1D_DX9(GLcontext *ctx, GLenum target, GLint level, - GLint internalFormat, - GLint width, GLint border, - GLenum format, GLenum type, const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage ) -{ - // A 1D texture is a 2D texture with a height of zero - gld_TexImage2D_DX9(ctx, target, level, internalFormat, width, 1, border, format, type, pixels, packing, texObj, texImage); -} - -//--------------------------------------------------------------------------- - -/* -void gld_TexSubImage2D( GLcontext *ctx, GLenum target, GLint level, - GLint xoffset, GLint yoffset, - GLsizei width, GLsizei height, - GLenum format, GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *tObj, - struct gl_texture_image *texImage ) -{ - GLD_GET_CONTEXT - IDirect3DTexture9 *pTex; - IDirect3DSurface9 *pSurface; - D3DFORMAT d3dFormat; - HRESULT hr; - GLint texelBytes = 4; - GLvoid *tempImage; - RECT rcSrcRect; - RECT rcDstRect; - - if (!tObj || !texImage) - return; - - pTex = (IDirect3DTexture9*)tObj->DriverData; - if (!pTex) - return; // Texture has not been created - if (level >= _GLD_DX9_TEX(GetLevelCount(pTex)) - return; // Level does not exist - hr = _GLD_DX9_TEX(GetSurfaceLevel(pTex, level, &pSurface); - if (FAILED(hr)) - return; // Surface level doesn't exist (or just a plain error) - - d3dFormat = _gldGLFormatToD3DFormat(texImage->Format); - tempImage = MALLOC(width * height * texelBytes); - if (!tempImage) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); - IDirect3DSurface9_Release(pSurface); - return; - } - - // unpack image, apply transfer ops and store in tempImage - texImage->TexFormat->StoreImage(ctx, 2, texImage->Format, - &_mesa_texformat_argb8888, // dest format - tempImage, - width, height, 1, 0, 0, 0, - width * texelBytes, - 0, // dstImageStride - format, type, pixels, packing); - - // Source rectangle is whole of input image - SetRect(&rcSrcRect, 0, 0, width, height); - - // Dest rectangle must be offset to dest image - SetRect(&rcDstRect, 0, 0, width, height); - OffsetRect(&rcDstRect, xoffset, yoffset); - - D3DXLoadSurfaceFromMemory( - pSurface, - NULL, - &rcDstRect, - tempImage, - D3DFMT_A8R8G8B8, - width * texelBytes, - NULL, - &rcSrcRect, - D3DX_FILTER_NONE, - 0); - - FREE(tempImage); - IDirect3DSurface9_Release(pSurface); -} -*/ - -//--------------------------------------------------------------------------- - -// Faster, more efficient version. -// Copies subimage straight to dest texture -void gld_TexSubImage2D_DX9( GLcontext *ctx, GLenum target, GLint level, - GLint xoffset, GLint yoffset, - GLsizei width, GLsizei height, - GLenum format, GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *tObj, - struct gl_texture_image *texImage ) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - IDirect3DTexture9 *pTex; - IDirect3DSurface9 *pSurface; - HRESULT hr; - RECT rcDstRect; - D3DLOCKED_RECT d3dLockedRect; - D3DSURFACE_DESC d3dsd; - - if (!tObj || !texImage) - return; - - pTex = (IDirect3DTexture9*)tObj->DriverData; - if (!pTex) - return; // Texture has not been created - if (level >= IDirect3DTexture9_GetLevelCount(pTex)) - return; // Level does not exist - hr = IDirect3DTexture9_GetSurfaceLevel(pTex, level, &pSurface); - if (FAILED(hr)) - return; // Surface level doesn't exist (or just a plain error) - - IDirect3DSurface9_GetDesc(pSurface, &d3dsd); - - // Dest rectangle must be offset to dest image - SetRect(&rcDstRect, 0, 0, width, height); - OffsetRect(&rcDstRect, xoffset, yoffset); - - // Lock sub-rect of surface - hr = IDirect3DSurface9_LockRect(pSurface, &d3dLockedRect, &rcDstRect, 0); - if (FAILED(hr)) { - IDirect3DSurface9_Release(pSurface); - return; - } - - // unpack image, apply transfer ops and store directly in texture - texImage->TexFormat->StoreImage(ctx, 2, texImage->Format, - _gldMesaFormatForD3DFormat(d3dsd.Format), - d3dLockedRect.pBits, - width, height, 1, - 0, 0, 0, // NOTE: d3dLockedRect.pBits is already offset!!! - d3dLockedRect.Pitch, - 0, // dstImageStride - format, type, pixels, packing); - - - IDirect3DSurface9_UnlockRect(pSurface); - IDirect3DSurface9_Release(pSurface); -} - -//--------------------------------------------------------------------------- - -void gld_TexSubImage1D_DX9( GLcontext *ctx, GLenum target, GLint level, - GLint xoffset, GLsizei width, - GLenum format, GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage ) -{ - gld_TexSubImage2D_DX9(ctx, target, level, xoffset, 0, width, 1, format, type, pixels, packing, texObj, texImage); -} - -//--------------------------------------------------------------------------- - -void gld_DeleteTexture_DX9( - GLcontext *ctx, - struct gl_texture_object *tObj) -{ - GLD_context *gld = (GLD_context*)(ctx->DriverCtx); - - if (tObj) { - IDirect3DTexture9 *pTex = (IDirect3DTexture9*)tObj->DriverData; - if (pTex) { -/* // Make sure texture is not bound to a stage before releasing it - for (int i=0; i<MAX_TEXTURE_UNITS; i++) { - if (gld->CurrentTexture[i] == pTex) { - gld->pDev->SetTexture(i, NULL); - gld->CurrentTexture[i] = NULL; - } - }*/ - _GLD_DX9_TEX(Release(pTex)); - tObj->DriverData = NULL; - } - } -} - -//--------------------------------------------------------------------------- - -__inline void _gldSetColorOps( - const GLD_driver_dx9 *gld, - GLuint unit, - DWORD ColorArg1, - D3DTEXTUREOP ColorOp, - DWORD ColorArg2) -{ - _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLORARG1, ColorArg1)); - _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLOROP, ColorOp)); - _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLORARG2, ColorArg2)); -} - -//--------------------------------------------------------------------------- - -__inline void _gldSetAlphaOps( - const GLD_driver_dx9 *gld, - GLuint unit, - DWORD AlphaArg1, - D3DTEXTUREOP AlphaOp, - DWORD AlphaArg2) -{ - _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ALPHAARG1, AlphaArg1)); - _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ALPHAOP, AlphaOp)); - _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ALPHAARG2, AlphaArg2)); -} - -//--------------------------------------------------------------------------- - -void gldUpdateTextureUnit( - GLcontext *ctx, - GLuint unit, - BOOL bPassThrough) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - D3DTEXTUREFILTERTYPE minfilter; - D3DTEXTUREFILTERTYPE mipfilter; - GLenum BaseFormat; - DWORD dwColorArg0; - int iTexEnv = 0; - GLD_texenv *pTexenv; - - // NOTE: If bPassThrough is FALSE then texture stage can be - // disabled otherwise it must pass-through it's current fragment. - - const struct gl_texture_unit *pUnit = &ctx->Texture.Unit[unit]; - const struct gl_texture_object *tObj = pUnit->_Current; - - IDirect3DTexture9 *pTex = NULL; - if (tObj) { - pTex = (IDirect3DTexture9*)tObj->DriverData; - } - - // Enable texturing if unit is enabled and a valid D3D texture exists - // Mesa 5: TEXTUREn_x altered to TEXTURE_nD_BIT - //if (pTex && (pUnit->Enabled & (TEXTURE0_1D | TEXTURE0_2D))) { - if (pTex && (pUnit->_ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT))) { - // Enable texturing - _GLD_DX9_DEV(SetTexture(gld->pDev, unit, pTex)); - } else { - // Disable texturing, then return - _GLD_DX9_DEV(SetTexture(gld->pDev, unit, NULL)); - if (bPassThrough) { - _gldSetColorOps(gld, unit, D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_DIFFUSE); - _gldSetAlphaOps(gld, unit, D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_DIFFUSE); - } else { - _gldSetColorOps(gld, unit, D3DTA_TEXTURE, D3DTOP_DISABLE, D3DTA_DIFFUSE); - _gldSetAlphaOps(gld, unit, D3DTA_TEXTURE, D3DTOP_DISABLE, D3DTA_DIFFUSE); - } - return; - } - - // Texture parameters - _gldConvertMinFilter(tObj->MinFilter, &minfilter, &mipfilter); -// _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_MINFILTER, minfilter)); -// _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_MIPFILTER, mipfilter)); -// _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_MAGFILTER, _gldConvertMagFilter(tObj->MagFilter))); -// _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ADDRESSU, _gldConvertWrap(tObj->WrapS))); -// _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ADDRESSV, _gldConvertWrap(tObj->WrapT))); - _GLD_DX9_DEV(SetSamplerState(gld->pDev, unit, D3DSAMP_MINFILTER, minfilter)); - _GLD_DX9_DEV(SetSamplerState(gld->pDev, unit, D3DSAMP_MIPFILTER, mipfilter)); - _GLD_DX9_DEV(SetSamplerState(gld->pDev, unit, D3DSAMP_MAGFILTER, _gldConvertMagFilter(tObj->MagFilter))); - _GLD_DX9_DEV(SetSamplerState(gld->pDev, unit, D3DSAMP_ADDRESSU, _gldConvertWrap(tObj->WrapS))); - _GLD_DX9_DEV(SetSamplerState(gld->pDev, unit, D3DSAMP_ADDRESSV, _gldConvertWrap(tObj->WrapT))); - - // Texture priority - _GLD_DX9_TEX(SetPriority(pTex, (DWORD)(tObj->Priority*65535.0f))); - - // Texture environment - // TODO: Examine input texture for alpha and use specific alpha/non-alpha ops. - // See Page 355 of the Red Book. - BaseFormat = _gldDecodeBaseFormat(pTex); - - switch (BaseFormat) { - case GL_RGB: - iTexEnv = 0; - break; - case GL_RGBA: - iTexEnv = 1; - break; - case GL_ALPHA: - iTexEnv = 2; - break; - } - - switch (pUnit->EnvMode) { - case GL_DECAL: - iTexEnv += 0; - break; - case GL_REPLACE: - iTexEnv += 3; - break; - case GL_MODULATE: - iTexEnv += 6; - break; - case GL_BLEND: - // Set blend colour - dwColorArg0 = D3DCOLOR_COLORVALUE(pUnit->EnvColor[0], pUnit->EnvColor[1], pUnit->EnvColor[2], pUnit->EnvColor[3]); - _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLORARG0, dwColorArg0)); - iTexEnv += 9; - break; - case GL_ADD: - iTexEnv += 12; - break; - } - pTexenv = (GLD_texenv*)&gldTexEnv[iTexEnv]; - _gldSetColorOps(gld, unit, pTexenv->ColorArg1, pTexenv->ColorOp, pTexenv->ColorArg2); - _gldSetAlphaOps(gld, unit, pTexenv->AlphaArg1, pTexenv->AlphaOp, pTexenv->AlphaArg2); -} - -//--------------------------------------------------------------------------- - -void gld_NEW_TEXTURE_DX9( - GLcontext *ctx) -{ - // TODO: Support for three (ATI Radeon) or more (nVidia GeForce3) texture units - - BOOL bUnit0Enabled; - BOOL bUnit1Enabled; - - if (!ctx) - return; // Sanity check - - if (ctx->Const.MaxTextureUnits == 1) { - gldUpdateTextureUnit(ctx, 0, TRUE); - return; - } - - // - // NOTE: THE FOLLOWING RELATES TO TWO TEXTURE UNITS, AND TWO ONLY!! - // - - // Mesa 5: Texture Units altered - //bUnit0Enabled = (ctx->Texture._ReallyEnabled & (TEXTURE0_1D | TEXTURE0_2D)) ? TRUE : FALSE; - //bUnit1Enabled = (ctx->Texture._ReallyEnabled & (TEXTURE1_1D | TEXTURE1_2D)) ? TRUE : FALSE; - bUnit0Enabled = (ctx->Texture.Unit[0]._ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT)) ? TRUE : FALSE; - bUnit1Enabled = (ctx->Texture.Unit[1]._ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT)) ? TRUE : FALSE; - - // If Unit0 is disabled and Unit1 is enabled then we must pass-though - gldUpdateTextureUnit(ctx, 0, (!bUnit0Enabled && bUnit1Enabled) ? TRUE : FALSE); - // We can always disable the last texture unit - gldUpdateTextureUnit(ctx, 1, FALSE); - -#ifdef _DEBUG -#if 0 - { - // Find out whether device supports current renderstates - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); -// GLD_context *gld = GLD_GET_CONTEXT(ctx); - - DWORD dwPasses; - _GLD_DX9_DEV(ValidateDevice(gld->pDev, &dwPasses)); -// if (FAILED(hr)) { -// gldLogError(GLDLOG_ERROR, "ValidateDevice failed", hr); -// } - if (dwPasses != 1) { - gldLogMessage(GLDLOG_ERROR, "ValidateDevice: Can't do in one pass\n"); - } - } -#endif -#endif -}; - -//--------------------------------------------------------------------------- diff --git a/src/mesa/drivers/windows/gldirect/dx9/gld_vb_d3d_render_dx9.c b/src/mesa/drivers/windows/gldirect/dx9/gld_vb_d3d_render_dx9.c deleted file mode 100644 index 4fa6bcaf1a..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx9/gld_vb_d3d_render_dx9.c +++ /dev/null @@ -1,263 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: GLDirect fastpath pipeline stage -* -****************************************************************************/ - -//--------------------------------------------------------------------------- - -//#include "../GLDirect.h" -//#include "../gld_log.h" -//#include "gld_dx8.h" - -#include "dglcontext.h" -#include "ddlog.h" -#include "gld_dx9.h" - -//--------------------------------------------------------------------------- - -#include "glheader.h" -#include "context.h" -#include "macros.h" -// #include "mem.h" -#include "mtypes.h" -//#include "mmath.h" - -#include "math/m_matrix.h" -#include "math/m_xform.h" - -#include "tnl/t_pipeline.h" - -//--------------------------------------------------------------------------- - -__inline void _gldSetVertexShaderConstants( - GLcontext *ctx, - GLD_driver_dx9 *gld) -{ - D3DXMATRIX mat, matView, matProj; - GLfloat *pM; - - // Mesa 5: Altered to a Stack - //pM = ctx->ModelView.m; - pM = ctx->ModelviewMatrixStack.Top->m; - matView._11 = pM[0]; - matView._12 = pM[1]; - matView._13 = pM[2]; - matView._14 = pM[3]; - matView._21 = pM[4]; - matView._22 = pM[5]; - matView._23 = pM[6]; - matView._24 = pM[7]; - matView._31 = pM[8]; - matView._32 = pM[9]; - matView._33 = pM[10]; - matView._34 = pM[11]; - matView._41 = pM[12]; - matView._42 = pM[13]; - matView._43 = pM[14]; - matView._44 = pM[15]; - - // Mesa 5: Altered to a Stack - //pM = ctx->ProjectionMatrix.m; - pM = ctx->ProjectionMatrixStack.Top->m; - matProj._11 = pM[0]; - matProj._12 = pM[1]; - matProj._13 = pM[2]; - matProj._14 = pM[3]; - matProj._21 = pM[4]; - matProj._22 = pM[5]; - matProj._23 = pM[6]; - matProj._24 = pM[7]; - matProj._31 = pM[8]; - matProj._32 = pM[9]; - matProj._33 = pM[10]; - matProj._34 = pM[11]; - matProj._41 = pM[12]; - matProj._42 = pM[13]; - matProj._43 = pM[14]; - matProj._44 = pM[15]; - - D3DXMatrixMultiply( &mat, &matView, &matProj ); - D3DXMatrixTranspose( &mat, &mat ); - - _GLD_DX9_DEV(SetVertexShaderConstantF(gld->pDev, 0, (float*)&mat, 4)); -} - -//--------------------------------------------------------------------------- - -static GLboolean gld_d3d_render_stage_run( - GLcontext *ctx, - struct tnl_pipeline_stage *stage) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - TNLcontext *tnl; - struct vertex_buffer *VB; - tnl_render_func *tab; - GLint pass; - GLD_pb_dx9 *gldPB = &gld->PB3d; -/* - static int count = 0; - count++; - if (count != 2) - return GL_FALSE; -*/ - // The "check" function should disable this stage, - // but we'll test gld->bUseMesaTnL anyway. - if (gld->bUseMesaTnL) { - // Do nothing in this stage, but continue pipeline - return GL_TRUE; - } - - tnl = TNL_CONTEXT(ctx); - VB = &tnl->vb; - pass = 0; - - tnl->Driver.Render.Start( ctx ); - -#if 0 - // For debugging: Useful to see if an app passes colour data in - // an unusual format. - switch (VB->ColorPtr[0]->Type) { - case GL_FLOAT: - ddlogMessage(GLDLOG_SYSTEM, "ColorPtr: GL_FLOAT\n"); - break; - case GL_UNSIGNED_BYTE: - ddlogMessage(GLDLOG_SYSTEM, "ColorPtr: GL_UNSIGNED_BYTE\n"); - break; - default: - ddlogMessage(GLDLOG_SYSTEM, "ColorPtr: *?*\n"); - break; - } -#endif - - tnl->Driver.Render.Points = gld_Points3D_DX9; - if (ctx->_TriangleCaps & DD_FLATSHADE) { - tnl->Driver.Render.Line = gld_Line3DFlat_DX9; - tnl->Driver.Render.Triangle = gld_Triangle3DFlat_DX9; - tnl->Driver.Render.Quad = gld_Quad3DFlat_DX9; - } else { - tnl->Driver.Render.Line = gld_Line3DSmooth_DX9; - tnl->Driver.Render.Triangle = gld_Triangle3DSmooth_DX9; - tnl->Driver.Render.Quad = gld_Quad3DSmooth_DX9; - } - - _GLD_DX9_VB(Lock(gldPB->pVB, 0, 0, &gldPB->pPoints, D3DLOCK_DISCARD)); - gldPB->nPoints = gldPB->nLines = gldPB->nTriangles = 0; - // Allocate primitive pointers - // gldPB->pPoints is always first - gldPB->pLines = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstLine); - gldPB->pTriangles = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstTriangle); - - ASSERT(tnl->Driver.Render.BuildVertices); - ASSERT(tnl->Driver.Render.PrimitiveNotify); - ASSERT(tnl->Driver.Render.Points); - ASSERT(tnl->Driver.Render.Line); - ASSERT(tnl->Driver.Render.Triangle); - ASSERT(tnl->Driver.Render.Quad); - ASSERT(tnl->Driver.Render.ResetLineStipple); - ASSERT(tnl->Driver.Render.Interp); - ASSERT(tnl->Driver.Render.CopyPV); - ASSERT(tnl->Driver.Render.ClippedLine); - ASSERT(tnl->Driver.Render.ClippedPolygon); - ASSERT(tnl->Driver.Render.Finish); - - tab = (VB->Elts ? tnl->Driver.Render.PrimTabElts : tnl->Driver.Render.PrimTabVerts); - - do { - GLuint i, length, flags = 0; - for (i = 0 ; !(flags & PRIM_END) ; i += length) - { - flags = VB->Primitive[i].mode; - length= VB->Primitive[i].count; - ASSERT(length || (flags & PRIM_END)); - ASSERT((flags & PRIM_MODE_MASK) <= GL_POLYGON+1); - if (length) - tab[flags & PRIM_MODE_MASK]( ctx, i, i + length, flags ); - } - } while (tnl->Driver.Render.Multipass && - tnl->Driver.Render.Multipass( ctx, ++pass )); - - _GLD_DX9_VB(Unlock(gldPB->pVB)); - - _GLD_DX9_DEV(SetStreamSource(gld->pDev, 0, gldPB->pVB, 0, gldPB->dwStride)); - - _GLD_DX9_DEV(SetTransform(gld->pDev, D3DTS_PROJECTION, &gld->matProjection)); - _GLD_DX9_DEV(SetTransform(gld->pDev, D3DTS_WORLD, &gld->matModelView)); - - if (gldPB->nPoints) { - _GLD_DX9_DEV(DrawPrimitive(gld->pDev, D3DPT_POINTLIST, 0, gldPB->nPoints)); - gldPB->nPoints = 0; - } - - if (gldPB->nLines) { - _GLD_DX9_DEV(DrawPrimitive(gld->pDev, D3DPT_LINELIST, gldPB->iFirstLine, gldPB->nLines)); - gldPB->nLines = 0; - } - - if (gldPB->nTriangles) { - _GLD_DX9_DEV(DrawPrimitive(gld->pDev, D3DPT_TRIANGLELIST, gldPB->iFirstTriangle, gldPB->nTriangles)); - gldPB->nTriangles = 0; - } - - return GL_FALSE; /* finished the pipe */ -} - -//--------------------------------------------------------------------------- - -static void gld_d3d_render_stage_check( - GLcontext *ctx, - struct tnl_pipeline_stage *stage) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - // Is this thread safe? - stage->active = (gld->bUseMesaTnL) ? GL_FALSE : GL_TRUE; - return; -} - - -//--------------------------------------------------------------------------- - -const struct tnl_pipeline_stage _gld_d3d_render_stage = -{ - "gld_d3d_render_stage", - NULL, - NULL, - NULL, - NULL, - gld_d3d_render_stage_run /* run */ -}; - -//--------------------------------------------------------------------------- diff --git a/src/mesa/drivers/windows/gldirect/dx9/gld_vb_mesa_render_dx9.c b/src/mesa/drivers/windows/gldirect/dx9/gld_vb_mesa_render_dx9.c deleted file mode 100644 index 64acab2d2a..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx9/gld_vb_mesa_render_dx9.c +++ /dev/null @@ -1,443 +0,0 @@ - -/* - * Mesa 3-D graphics library - * Version: 3.5 - * - * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Authors: - * Keith Whitwell <keithw@valinux.com> - */ - - -/* - * Render whole vertex buffers, including projection of vertices from - * clip space and clipping of primitives. - * - * This file makes calls to project vertices and to the point, line - * and triangle rasterizers via the function pointers: - * - * context->Driver.Render.* - * - */ - - -//--------------------------------------------------------------------------- - -#include "dglcontext.h" -#include "ddlog.h" -#include "gld_dx9.h" - -//--------------------------------------------------------------------------- - -#include "glheader.h" -#include "context.h" -#include "macros.h" -#include "mtypes.h" -//#include "mmath.h" - -#include "math/m_matrix.h" -#include "math/m_xform.h" - -#include "tnl/t_pipeline.h" - -/**********************************************************************/ -/* Clip single primitives */ -/**********************************************************************/ - - -#if defined(USE_IEEE) -#define NEGATIVE(x) (GET_FLOAT_BITS(x) & (1<<31)) -//#define DIFFERENT_SIGNS(x,y) ((GET_FLOAT_BITS(x) ^ GET_FLOAT_BITS(y)) & (1<<31)) -#else -#define NEGATIVE(x) (x < 0) -//#define DIFFERENT_SIGNS(x,y) (x * y <= 0 && x - y != 0) -/* Could just use (x*y<0) except for the flatshading requirements. - * Maybe there's a better way? - */ -#endif - - -#define W(i) coord[i][3] -#define Z(i) coord[i][2] -#define Y(i) coord[i][1] -#define X(i) coord[i][0] -#define SIZE 4 -#define TAG(x) x##_4 -#include "tnl/t_vb_cliptmp.h" - - - -/**********************************************************************/ -/* Clip and render whole begin/end objects */ -/**********************************************************************/ - -#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED) -#define EDGEFLAG_GET(idx) VB->EdgeFlag[idx] -#define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val - - -/* Vertices, with the possibility of clipping. - */ -#define RENDER_POINTS( start, count ) \ - tnl->Driver.Render.Points( ctx, start, count ) - -#define RENDER_LINE( v1, v2 ) \ -do { \ - GLubyte c1 = mask[v1], c2 = mask[v2]; \ - GLubyte ormask = c1|c2; \ - if (!ormask) \ - LineFunc( ctx, v1, v2 ); \ - else if (!(c1 & c2 & 0x3f)) \ - clip_line_4( ctx, v1, v2, ormask ); \ -} while (0) - -#define RENDER_TRI( v1, v2, v3 ) \ -do { \ - GLubyte c1 = mask[v1], c2 = mask[v2], c3 = mask[v3]; \ - GLubyte ormask = c1|c2|c3; \ - if (!ormask) \ - TriangleFunc( ctx, v1, v2, v3 ); \ - else if (!(c1 & c2 & c3 & 0x3f)) \ - clip_tri_4( ctx, v1, v2, v3, ormask ); \ -} while (0) - -#define RENDER_QUAD( v1, v2, v3, v4 ) \ -do { \ - GLubyte c1 = mask[v1], c2 = mask[v2]; \ - GLubyte c3 = mask[v3], c4 = mask[v4]; \ - GLubyte ormask = c1|c2|c3|c4; \ - if (!ormask) \ - QuadFunc( ctx, v1, v2, v3, v4 ); \ - else if (!(c1 & c2 & c3 & c4 & 0x3f)) \ - clip_quad_4( ctx, v1, v2, v3, v4, ormask ); \ -} while (0) - - -#define LOCAL_VARS \ - TNLcontext *tnl = TNL_CONTEXT(ctx); \ - struct vertex_buffer *VB = &tnl->vb; \ - const GLuint * const elt = VB->Elts; \ - const GLubyte *mask = VB->ClipMask; \ - const GLuint sz = VB->ClipPtr->size; \ - const tnl_line_func LineFunc = tnl->Driver.Render.Line; \ - const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \ - const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \ - const GLboolean stipple = ctx->Line.StippleFlag; \ - (void) (LineFunc && TriangleFunc && QuadFunc); \ - (void) elt; (void) mask; (void) sz; (void) stipple; - -#define TAG(x) clip_##x##_verts -#define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x ) -#define RESET_STIPPLE if (stipple) tnl->Driver.Render.ResetLineStipple( ctx ) -#define PRESERVE_VB_DEFS -#include "tnl/t_vb_rendertmp.h" - - - -/* Elts, with the possibility of clipping. - */ -#undef ELT -#undef TAG -#define ELT(x) elt[x] -#define TAG(x) clip_##x##_elts -#include "tnl/t_vb_rendertmp.h" - -/* TODO: do this for all primitives, verts and elts: - */ -static void clip_elt_triangles( GLcontext *ctx, - GLuint start, - GLuint count, - GLuint flags ) -{ - TNLcontext *tnl = TNL_CONTEXT(ctx); - tnl_render_func render_tris = tnl->Driver.Render.PrimTabElts[GL_TRIANGLES]; - struct vertex_buffer *VB = &tnl->vb; - const GLuint * const elt = VB->Elts; - GLubyte *mask = VB->ClipMask; - GLuint last = count-2; - GLuint j; - (void) flags; - - tnl->Driver.Render.PrimitiveNotify( ctx, GL_TRIANGLES ); - - for (j=start; j < last; j+=3 ) { - GLubyte c1 = mask[elt[j]]; - GLubyte c2 = mask[elt[j+1]]; - GLubyte c3 = mask[elt[j+2]]; - GLubyte ormask = c1|c2|c3; - if (ormask) { - if (start < j) - render_tris( ctx, start, j, 0 ); - if (!(c1&c2&c3&0x3f)) - clip_tri_4( ctx, elt[j], elt[j+1], elt[j+2], ormask ); - start = j+3; - } - } - - if (start < j) - render_tris( ctx, start, j, 0 ); -} - -/**********************************************************************/ -/* Render whole begin/end objects */ -/**********************************************************************/ - -#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED) -#define EDGEFLAG_GET(idx) VB->EdgeFlag[idx] -#define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val - - -/* Vertices, no clipping. - */ -#define RENDER_POINTS( start, count ) \ - tnl->Driver.Render.Points( ctx, start, count ) - -#define RENDER_LINE( v1, v2 ) \ - LineFunc( ctx, v1, v2 ) - -#define RENDER_TRI( v1, v2, v3 ) \ - TriangleFunc( ctx, v1, v2, v3 ) - -#define RENDER_QUAD( v1, v2, v3, v4 ) \ - QuadFunc( ctx, v1, v2, v3, v4 ) - -#define TAG(x) _gld_tnl_##x##_verts - -#define LOCAL_VARS \ - TNLcontext *tnl = TNL_CONTEXT(ctx); \ - struct vertex_buffer *VB = &tnl->vb; \ - const GLuint * const elt = VB->Elts; \ - const tnl_line_func LineFunc = tnl->Driver.Render.Line; \ - const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \ - const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \ - (void) (LineFunc && TriangleFunc && QuadFunc); \ - (void) elt; - -#define RESET_STIPPLE tnl->Driver.Render.ResetLineStipple( ctx ) -#define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x ) -#define RENDER_TAB_QUALIFIER -#define PRESERVE_VB_DEFS -#include "tnl/t_vb_rendertmp.h" - - -/* Elts, no clipping. - */ -#undef ELT -#define TAG(x) _gld_tnl_##x##_elts -#define ELT(x) elt[x] -#include "tnl/t_vb_rendertmp.h" - - -/**********************************************************************/ -/* Helper functions for drivers */ -/**********************************************************************/ -/* -void _tnl_RenderClippedPolygon( GLcontext *ctx, const GLuint *elts, GLuint n ) -{ - TNLcontext *tnl = TNL_CONTEXT(ctx); - struct vertex_buffer *VB = &tnl->vb; - GLuint *tmp = VB->Elts; - - VB->Elts = (GLuint *)elts; - tnl->Driver.Render.PrimTabElts[GL_POLYGON]( ctx, 0, n, PRIM_BEGIN|PRIM_END ); - VB->Elts = tmp; -} - -void _tnl_RenderClippedLine( GLcontext *ctx, GLuint ii, GLuint jj ) -{ - TNLcontext *tnl = TNL_CONTEXT(ctx); - tnl->Driver.Render.Line( ctx, ii, jj ); -} -*/ - - -/**********************************************************************/ -/* Clip and render whole vertex buffers */ -/**********************************************************************/ - -tnl_points_func _gldSetupPoints[4] = { - gld_Points2D_DX9, - gld_Points2D_DX9, - gld_Points2D_DX9, - gld_Points2D_DX9 -}; -tnl_line_func _gldSetupLine[4] = { - gld_Line2DFlat_DX9, - gld_Line2DSmooth_DX9, - gld_Line2DFlat_DX9, - gld_Line2DSmooth_DX9, -}; -tnl_triangle_func _gldSetupTriangle[4] = { - gld_Triangle2DFlat_DX9, - gld_Triangle2DSmooth_DX9, - gld_Triangle2DFlatExtras_DX9, - gld_Triangle2DSmoothExtras_DX9 -}; -tnl_quad_func _gldSetupQuad[4] = { - gld_Quad2DFlat_DX9, - gld_Quad2DSmooth_DX9, - gld_Quad2DFlatExtras_DX9, - gld_Quad2DSmoothExtras_DX9 -}; - -//--------------------------------------------------------------------------- - -static GLboolean _gld_mesa_render_stage_run( - GLcontext *ctx, - struct tnl_pipeline_stage *stage) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); - - TNLcontext *tnl = TNL_CONTEXT(ctx); - struct vertex_buffer *VB = &tnl->vb; - tnl_render_func *tab; - GLint pass = 0; - GLD_pb_dx9 *gldPB; - - /* Allow the drivers to lock before projected verts are built so - * that window coordinates are guarenteed not to change before - * rendering. - */ - ASSERT(tnl->Driver.Render.Start); - - tnl->Driver.Render.Start( ctx ); - - // NOTE: Setting D3DRS_SOFTWAREVERTEXPROCESSING for a mixed-mode device resets - // stream, indices and shader to default values of NULL or 0. -/* if ((ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) && - gld->VStwosidelight.hShader && - !ctx->Fog.Enabled) - { - IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, !gld->VStwosidelight.bHardware); - _GLD_DX9_DEV(SetVertexShader(gld->pDev, gld->VStwosidelight.hShader)); - gldPB = &gld->PBtwosidelight; - tnl->Driver.Render.Points = gld_Points2DTwoside_DX9; - if (ctx->_TriangleCaps & DD_FLATSHADE) { - tnl->Driver.Render.Line = gld_Line2DFlatTwoside_DX9; - tnl->Driver.Render.Triangle = gld_Triangle2DFlatTwoside_DX9; - tnl->Driver.Render.Quad = gld_Quad2DFlatTwoside_DX9; - } else { - tnl->Driver.Render.Line = gld_Line2DSmoothTwoside_DX9; - tnl->Driver.Render.Triangle = gld_Triangle2DSmoothTwoside_DX9; - tnl->Driver.Render.Quad = gld_Quad2DSmoothTwoside_DX9; - } - } else {*/ -// IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, TRUE); - IDirect3DDevice9_SetSoftwareVertexProcessing(gld->pDev, TRUE); - gldPB = &gld->PB2d; - _GLD_DX9_DEV(SetVertexShader(gld->pDev, NULL)); - _GLD_DX9_DEV(SetFVF(gld->pDev, gldPB->dwFVF)); - tnl->Driver.Render.Points = _gldSetupPoints[gld->iSetupFunc]; - tnl->Driver.Render.Line = _gldSetupLine[gld->iSetupFunc]; - tnl->Driver.Render.Triangle = _gldSetupTriangle[gld->iSetupFunc]; - tnl->Driver.Render.Quad = _gldSetupQuad[gld->iSetupFunc]; -// } - - _GLD_DX9_VB(Lock(gldPB->pVB, 0, 0, &gldPB->pPoints, D3DLOCK_DISCARD)); - gldPB->nPoints = gldPB->nLines = gldPB->nTriangles = 0; - // Allocate primitive pointers - // gldPB->pPoints is always first - gldPB->pLines = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstLine); - gldPB->pTriangles = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstTriangle); - - ASSERT(tnl->Driver.Render.BuildVertices); - ASSERT(tnl->Driver.Render.PrimitiveNotify); - ASSERT(tnl->Driver.Render.Points); - ASSERT(tnl->Driver.Render.Line); - ASSERT(tnl->Driver.Render.Triangle); - ASSERT(tnl->Driver.Render.Quad); - ASSERT(tnl->Driver.Render.ResetLineStipple); - ASSERT(tnl->Driver.Render.Interp); - ASSERT(tnl->Driver.Render.CopyPV); - ASSERT(tnl->Driver.Render.ClippedLine); - ASSERT(tnl->Driver.Render.ClippedPolygon); - ASSERT(tnl->Driver.Render.Finish); - - tnl->Driver.Render.BuildVertices( ctx, 0, VB->Count, ~0 ); - - if (VB->ClipOrMask) { - tab = VB->Elts ? clip_render_tab_elts : clip_render_tab_verts; - clip_render_tab_elts[GL_TRIANGLES] = clip_elt_triangles; - } - else { - tab = (VB->Elts ? - tnl->Driver.Render.PrimTabElts : - tnl->Driver.Render.PrimTabVerts); - } - - do { - GLuint i, length, flags = 0; - for (i = 0 ; !(flags & PRIM_END) ; i += length) { - flags = VB->Primitive[i].mode; - length= VB->Primitive[i].count; - ASSERT(length || (flags & PRIM_END)); - ASSERT((flags & PRIM_MODE_MASK) <= GL_POLYGON+1); - if (length) - tab[flags & PRIM_MODE_MASK]( ctx, i, i + length, flags ); - } - } while (tnl->Driver.Render.Multipass && - tnl->Driver.Render.Multipass( ctx, ++pass )); - - -// tnl->Driver.Render.Finish( ctx ); - - _GLD_DX9_VB(Unlock(gldPB->pVB)); - - _GLD_DX9_DEV(SetStreamSource(gld->pDev, 0, gldPB->pVB, 0, gldPB->dwStride)); - - if (gldPB->nPoints) { - _GLD_DX9_DEV(DrawPrimitive(gld->pDev, D3DPT_POINTLIST, 0, gldPB->nPoints)); - gldPB->nPoints = 0; - } - - if (gldPB->nLines) { - _GLD_DX9_DEV(DrawPrimitive(gld->pDev, D3DPT_LINELIST, gldPB->iFirstLine, gldPB->nLines)); - gldPB->nLines = 0; - } - - if (gldPB->nTriangles) { - _GLD_DX9_DEV(DrawPrimitive(gld->pDev, D3DPT_TRIANGLELIST, gldPB->iFirstTriangle, gldPB->nTriangles)); - gldPB->nTriangles = 0; - } - - return GL_FALSE; /* finished the pipe */ -} - - -/**********************************************************************/ -/* Render pipeline stage */ -/**********************************************************************/ - - - - -const struct tnl_pipeline_stage _gld_mesa_render_stage = -{ - "gld_mesa_render_stage", - NULL, - NULL, - NULL, - NULL, - _gld_mesa_render_stage_run /* run */ -}; - -//--------------------------------------------------------------------------- diff --git a/src/mesa/drivers/windows/gldirect/dx9/gld_wgl_dx9.c b/src/mesa/drivers/windows/gldirect/dx9/gld_wgl_dx9.c deleted file mode 100644 index a03b865bb4..0000000000 --- a/src/mesa/drivers/windows/gldirect/dx9/gld_wgl_dx9.c +++ /dev/null @@ -1,1346 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: GLDirect Direct3D 8.x WGL (WindowsGL) -* -****************************************************************************/ - -#include "dglcontext.h" -#include "gld_driver.h" -#include "gld_dxerr9.h" -#include "gld_dx9.h" - -#include "tnl/tnl.h" -#include "tnl/t_context.h" - -// Copied from dglcontect.c -#define GLDERR_NONE 0 -#define GLDERR_MEM 1 -#define GLDERR_DDRAW 2 -#define GLDERR_D3D 3 -#define GLDERR_BPP 4 -#define GLDERR_DDS 5 -// This external var keeps track of any error -extern int nContextError; - -#define DDLOG_CRITICAL_OR_WARN DDLOG_CRITICAL - -extern void _gld_mesa_warning(GLcontext *, char *); -extern void _gld_mesa_fatal(GLcontext *, char *); - -//--------------------------------------------------------------------------- - -static char szColorDepthWarning[] = -"GLDirect does not support the current desktop\n\ -color depth.\n\n\ -You may need to change the display resolution to\n\ -16 bits per pixel or higher color depth using\n\ -the Windows Display Settings control panel\n\ -before running this OpenGL application.\n"; - -// The only depth-stencil formats currently supported by Direct3D -// Surface Format Depth Stencil Total Bits -// D3DFMT_D32 32 - 32 -// D3DFMT_D15S1 15 1 16 -// D3DFMT_D24S8 24 8 32 -// D3DFMT_D16 16 - 16 -// D3DFMT_D24X8 24 - 32 -// D3DFMT_D24X4S4 24 4 32 - -// This pixel format will be used as a template when compiling the list -// of pixel formats supported by the hardware. Many fields will be -// filled in at runtime. -// PFD flag defaults are upgraded to match ChoosePixelFormat() -- DaveM -static DGL_pixelFormat pfTemplateHW = -{ - { - sizeof(PIXELFORMATDESCRIPTOR), // Size of the data structure - 1, // Structure version - should be 1 - // Flags: - PFD_DRAW_TO_WINDOW | // The buffer can draw to a window or device surface. - PFD_DRAW_TO_BITMAP | // The buffer can draw to a bitmap. (DaveM) - PFD_SUPPORT_GDI | // The buffer supports GDI drawing. (DaveM) - PFD_SUPPORT_OPENGL | // The buffer supports OpenGL drawing. - PFD_DOUBLEBUFFER | // The buffer is double-buffered. - 0, // Placeholder for easy commenting of above flags - PFD_TYPE_RGBA, // Pixel type RGBA. - 16, // Total colour bitplanes (excluding alpha bitplanes) - 5, 0, // Red bits, shift - 5, 0, // Green bits, shift - 5, 0, // Blue bits, shift - 0, 0, // Alpha bits, shift (destination alpha) - 0, // Accumulator bits (total) - 0, 0, 0, 0, // Accumulator bits: Red, Green, Blue, Alpha - 0, // Depth bits - 0, // Stencil bits - 0, // Number of auxiliary buffers - 0, // Layer type - 0, // Specifies the number of overlay and underlay planes. - 0, // Layer mask - 0, // Specifies the transparent color or index of an underlay plane. - 0 // Damage mask - }, - D3DFMT_UNKNOWN, // No depth/stencil buffer -}; - -//--------------------------------------------------------------------------- -// Vertex Shaders -//--------------------------------------------------------------------------- -/* -// Vertex Shader Declaration -static DWORD dwTwoSidedLightingDecl[] = -{ - D3DVSD_STREAM(0), - D3DVSD_REG(0, D3DVSDT_FLOAT3), // XYZ position - D3DVSD_REG(1, D3DVSDT_FLOAT3), // XYZ normal - D3DVSD_REG(2, D3DVSDT_D3DCOLOR), // Diffuse color - D3DVSD_REG(3, D3DVSDT_D3DCOLOR), // Specular color - D3DVSD_REG(4, D3DVSDT_FLOAT2), // 2D texture unit 0 - D3DVSD_REG(5, D3DVSDT_FLOAT2), // 2D texture unit 1 - D3DVSD_END() -}; - -// Vertex Shader for two-sided lighting -static char *szTwoSidedLightingVS = -// This is a test shader! -"vs.1.0\n" -"m4x4 oPos,v0,c0\n" -"mov oD0,v2\n" -"mov oD1,v3\n" -"mov oT0,v4\n" -"mov oT1,v5\n" -; -*/ -//--------------------------------------------------------------------------- -//--------------------------------------------------------------------------- - -typedef struct { - HINSTANCE hD3D9DLL; // Handle to d3d9.dll - FNDIRECT3DCREATE9 fnDirect3DCreate9; // Direct3DCreate9 function prototype - BOOL bDirect3D; // Persistant Direct3D9 exists - BOOL bDirect3DDevice; // Persistant Direct3DDevice9 exists - IDirect3D9 *pD3D; // Persistant Direct3D9 - IDirect3DDevice9 *pDev; // Persistant Direct3DDevice9 -} GLD_dx9_globals; - -// These are "global" to all DX9 contexts. KeithH -static GLD_dx9_globals dx9Globals; - -//--------------------------------------------------------------------------- -//--------------------------------------------------------------------------- - -BOOL gldGetDXErrorString_DX( - HRESULT hr, - char *buf, - int nBufSize) -{ - // - // Return a string describing the input HRESULT error code - // - - const char *pStr = DXGetErrorString9(hr); - - if (pStr == NULL) - return FALSE; - - if (strlen(pStr) > nBufSize) - strncpy(buf, pStr, nBufSize); - else - strcpy(buf, pStr); - -// D3DXGetErrorString(hr, buf, nBufSize); - - return TRUE; -} - -//--------------------------------------------------------------------------- - -static D3DMULTISAMPLE_TYPE _gldGetDeviceMultiSampleType( - IDirect3D9 *pD3D9, - D3DFORMAT SurfaceFormat, - D3DDEVTYPE d3dDevType, - BOOL Windowed) -{ - int i; - HRESULT hr; - - if (glb.dwMultisample == GLDS_MULTISAMPLE_NONE) - return D3DMULTISAMPLE_NONE; - - if (glb.dwMultisample == GLDS_MULTISAMPLE_FASTEST) { - // Find fastest multisample - for (i=2; i<17; i++) { - hr = IDirect3D9_CheckDeviceMultiSampleType( - pD3D9, - glb.dwAdapter, - d3dDevType, - SurfaceFormat, - Windowed, - (D3DMULTISAMPLE_TYPE)i, - NULL); - if (SUCCEEDED(hr)) { - return (D3DMULTISAMPLE_TYPE)i; - } - } - } else { - // Find nicest multisample - for (i=16; i>1; i--) { - hr = IDirect3D9_CheckDeviceMultiSampleType( - pD3D9, - glb.dwAdapter, - d3dDevType, - SurfaceFormat, - Windowed, - (D3DMULTISAMPLE_TYPE)i, - NULL); - if (SUCCEEDED(hr)) { - return (D3DMULTISAMPLE_TYPE)i; - } - } - } - - // Nothing found - return default - return D3DMULTISAMPLE_NONE; -} - -//--------------------------------------------------------------------------- - -void _gldDestroyPrimitiveBuffer( - GLD_pb_dx9 *gldVB) -{ - SAFE_RELEASE(gldVB->pVB); - - // Sanity check... - gldVB->nLines = gldVB->nPoints = gldVB->nTriangles = 0; -} - -//--------------------------------------------------------------------------- - -HRESULT _gldCreatePrimitiveBuffer( - GLcontext *ctx, - GLD_driver_dx9 *lpCtx, - GLD_pb_dx9 *gldVB) -{ - HRESULT hResult; - char *szCreateVertexBufferFailed = "CreateVertexBuffer failed"; - DWORD dwMaxVertices; // Max number of vertices in vertex buffer - DWORD dwVBSize; // Total size of vertex buffer - - // If CVA (Compiled Vertex Array) is used by an OpenGL app, then we - // will need enough vertices to cater for Mesa::Const.MaxArrayLockSize. - // We'll use IMM_SIZE if it's larger (which it should not be). - dwMaxVertices = MAX_ARRAY_LOCK_SIZE; - - // Now calculate how many vertices to allow for in total - // 1 per point, 2 per line, 6 per quad = 9 - dwVBSize = dwMaxVertices * 9 * gldVB->dwStride; - - hResult = IDirect3DDevice9_CreateVertexBuffer( - lpCtx->pDev, - dwVBSize, - gldVB->dwUsage, - gldVB->dwFVF, - gldVB->dwPool, - &gldVB->pVB, - NULL); - if (FAILED(hResult)) { - ddlogMessage(DDLOG_CRITICAL_OR_WARN, szCreateVertexBufferFailed); - return hResult; - } - - gldVB->nLines = gldVB->nPoints = gldVB->nTriangles = 0; - gldVB->pPoints = gldVB->pLines = gldVB->pTriangles = NULL; - gldVB->iFirstLine = dwMaxVertices; // Index of first line in VB - gldVB->iFirstTriangle = dwMaxVertices*3; // Index of first triangle in VB - - return S_OK; -} - -//--------------------------------------------------------------------------- -// Function: _gldCreateVertexShaders -// Create DX9 Vertex Shaders. -//--------------------------------------------------------------------------- -/* -void _gldCreateVertexShaders( - GLD_driver_dx9 *gld) -{ - DWORD dwFlags; - LPD3DXBUFFER pVSOpcodeBuffer; // Vertex Shader opcode buffer - HRESULT hr; - -#ifdef _DEBUG - dwFlags = D3DXASM_DEBUG; -#else - dwFlags = 0; // D3DXASM_SKIPVALIDATION; -#endif - - ddlogMessage(DDLOG_INFO, "Creating shaders...\n"); - - // Init the shader handle - gld->VStwosidelight.hShader = 0; - - if (gld->d3dCaps8.MaxStreams == 0) { - // Lame DX8 driver doesn't support streams - // Not fatal, as defaults will be used - ddlogMessage(DDLOG_WARN, "Driver doesn't support Vertex Shaders (MaxStreams==0)\n"); - return; - } - - // ** THIS DISABLES VERTEX SHADER SUPPORT ** -// return; - // ** THIS DISABLES VERTEX SHADER SUPPORT ** - - // - // Two-sided lighting - // - -#if 0 - // - // DEBUGGING: Load shader from a text file - // - { - LPD3DXBUFFER pVSErrorBuffer; // Vertex Shader error buffer - hr = D3DXAssembleShaderFromFile( - "twoside.vsh", - dwFlags, - NULL, // No constants - &pVSOpcodeBuffer, - &pVSErrorBuffer); - if (pVSErrorBuffer && pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)) - ddlogMessage(DDLOG_INFO, pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)); - SAFE_RELEASE(pVSErrorBuffer); - } -#else - { - LPD3DXBUFFER pVSErrorBuffer; // Vertex Shader error buffer - // Assemble ascii shader text into shader opcodes - hr = D3DXAssembleShader( - szTwoSidedLightingVS, - strlen(szTwoSidedLightingVS), - dwFlags, - NULL, // No constants - &pVSOpcodeBuffer, - &pVSErrorBuffer); - if (pVSErrorBuffer && pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)) - ddlogMessage(DDLOG_INFO, pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)); - SAFE_RELEASE(pVSErrorBuffer); - } -#endif - if (FAILED(hr)) { - ddlogError(DDLOG_WARN, "AssembleShader failed", hr); - SAFE_RELEASE(pVSOpcodeBuffer); - return; - } - -// This is for debugging. Remove to enable vertex shaders in HW -#define _GLD_FORCE_SW_VS 0 - - if (_GLD_FORCE_SW_VS) { - // _GLD_FORCE_SW_VS should be disabled for Final Release - ddlogMessage(DDLOG_SYSTEM, "[Forcing shaders in SW]\n"); - } - - // Try and create shader in hardware. - // NOTE: The D3D Ref device appears to succeed when trying to - // create the device in hardware, but later complains - // when trying to set it with SetVertexShader(). Go figure. - if (_GLD_FORCE_SW_VS || glb.dwDriver == GLDS_DRIVER_REF) { - // Don't try and create a hardware shader with the Ref device - hr = E_FAIL; // COM error/fail result - } else { - gld->VStwosidelight.bHardware = TRUE; - hr = IDirect3DDevice8_CreateVertexShader( - gld->pDev, - dwTwoSidedLightingDecl, - pVSOpcodeBuffer->lpVtbl->GetBufferPointer(pVSOpcodeBuffer), - &gld->VStwosidelight.hShader, - 0); - } - if (FAILED(hr)) { - ddlogMessage(DDLOG_INFO, "... HW failed, trying SW...\n"); - // Failed. Try and create shader for software processing - hr = IDirect3DDevice8_CreateVertexShader( - gld->pDev, - dwTwoSidedLightingDecl, - pVSOpcodeBuffer->lpVtbl->GetBufferPointer(pVSOpcodeBuffer), - &gld->VStwosidelight.hShader, - D3DUSAGE_SOFTWAREPROCESSING); - if (FAILED(hr)) { - gld->VStwosidelight.hShader = 0; // Sanity check - ddlogError(DDLOG_WARN, "CreateVertexShader failed", hr); - return; - } - // Succeeded, but for software processing - gld->VStwosidelight.bHardware = FALSE; - } - - SAFE_RELEASE(pVSOpcodeBuffer); - - ddlogMessage(DDLOG_INFO, "... OK\n"); -} - -//--------------------------------------------------------------------------- - -void _gldDestroyVertexShaders( - GLD_driver_dx9 *gld) -{ - if (gld->VStwosidelight.hShader) { - IDirect3DDevice8_DeleteVertexShader(gld->pDev, gld->VStwosidelight.hShader); - gld->VStwosidelight.hShader = 0; - } -} -*/ -//--------------------------------------------------------------------------- - -BOOL gldCreateDrawable_DX( - DGL_ctx *ctx, -// BOOL bDefaultDriver, - BOOL bDirectDrawPersistant, - BOOL bPersistantBuffers) -{ - // - // bDirectDrawPersistant: applies to IDirect3D9 - // bPersistantBuffers: applies to IDirect3DDevice9 - // - - HRESULT hResult; - GLD_driver_dx9 *lpCtx = NULL; - D3DDEVTYPE d3dDevType; - D3DPRESENT_PARAMETERS d3dpp; - D3DDISPLAYMODE d3ddm; - DWORD dwBehaviourFlags; - D3DADAPTER_IDENTIFIER9 d3dIdent; - - // Error if context is NULL. - if (ctx == NULL) - return FALSE; - - if (ctx->glPriv) { - lpCtx = ctx->glPriv; - // Release any existing interfaces - SAFE_RELEASE(lpCtx->pDev); - SAFE_RELEASE(lpCtx->pD3D); - } else { - lpCtx = (GLD_driver_dx9*)malloc(sizeof(GLD_driver_dx9)); - ZeroMemory(lpCtx, sizeof(lpCtx)); - } - - d3dDevType = (glb.dwDriver == GLDS_DRIVER_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; - // TODO: Check this -// if (bDefaultDriver) -// d3dDevType = D3DDEVTYPE_REF; - - // Use persistant interface if needed - if (bDirectDrawPersistant && dx9Globals.bDirect3D) { - lpCtx->pD3D = dx9Globals.pD3D; - IDirect3D9_AddRef(lpCtx->pD3D); - goto SkipDirectDrawCreate; - } - - // Create Direct3D9 object - lpCtx->pD3D = dx9Globals.fnDirect3DCreate9(D3D_SDK_VERSION); - if (lpCtx->pD3D == NULL) { - MessageBox(NULL, "Unable to initialize Direct3D9", "GLDirect", MB_OK); - ddlogMessage(DDLOG_CRITICAL_OR_WARN, "Unable to create Direct3D9 interface"); - nContextError = GLDERR_D3D; - goto return_with_error; - } - - // Cache Direct3D interface for subsequent GLRCs - if (bDirectDrawPersistant && !dx9Globals.bDirect3D) { - dx9Globals.pD3D = lpCtx->pD3D; - IDirect3D9_AddRef(dx9Globals.pD3D); - dx9Globals.bDirect3D = TRUE; - } -SkipDirectDrawCreate: - - // Get the display mode so we can make a compatible backbuffer - hResult = IDirect3D9_GetAdapterDisplayMode(lpCtx->pD3D, glb.dwAdapter, &d3ddm); - if (FAILED(hResult)) { - nContextError = GLDERR_D3D; - goto return_with_error; - } - - // Get device caps - hResult = IDirect3D9_GetDeviceCaps(lpCtx->pD3D, glb.dwAdapter, d3dDevType, &lpCtx->d3dCaps9); - if (FAILED(hResult)) { - ddlogError(DDLOG_CRITICAL_OR_WARN, "IDirect3D9_GetDeviceCaps failed", hResult); - nContextError = GLDERR_D3D; - goto return_with_error; - } - - // Check for hardware transform & lighting - lpCtx->bHasHWTnL = lpCtx->d3dCaps9.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ? TRUE : FALSE; - -/* - // - // GONE FOR DX9? - // - // If this flag is present then we can't default to Mesa - // SW rendering between BeginScene() and EndScene(). - if (lpCtx->d3dCaps9.Caps2 & D3DCAPS2_NO2DDURING3DSCENE) { - ddlogMessage(DDLOG_WARN, - "Warning : No 2D allowed during 3D scene.\n"); - } -*/ - - // - // Create the Direct3D context - // - - // Re-use original IDirect3DDevice if persistant buffers exist. - // Note that we test for persistant IDirect3D9 as well - // bDirectDrawPersistant == persistant IDirect3D9 (DirectDraw9 does not exist) - if (bDirectDrawPersistant && bPersistantBuffers && dx9Globals.pD3D && dx9Globals.pDev) { - lpCtx->pDev = dx9Globals.pDev; - IDirect3DDevice9_AddRef(dx9Globals.pDev); - goto skip_direct3ddevice_create; - } - - // Clear the presentation parameters (sets all members to zero) - ZeroMemory(&d3dpp, sizeof(d3dpp)); - - // Recommended by MS; needed for MultiSample. - // Be careful if altering this for FullScreenBlit - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - - d3dpp.BackBufferFormat = d3ddm.Format; - d3dpp.BackBufferCount = 2; //1; - d3dpp.MultiSampleType = _gldGetDeviceMultiSampleType(lpCtx->pD3D, d3ddm.Format, d3dDevType, !ctx->bFullscreen); - d3dpp.AutoDepthStencilFormat = ctx->lpPF->dwDriverData; - d3dpp.EnableAutoDepthStencil = (d3dpp.AutoDepthStencilFormat == D3DFMT_UNKNOWN) ? FALSE : TRUE; - - if (ctx->bFullscreen) { - ddlogWarnOption(FALSE); // Don't popup any messages in fullscreen - d3dpp.Windowed = FALSE; - d3dpp.BackBufferWidth = d3ddm.Width; - d3dpp.BackBufferHeight = d3ddm.Height; - d3dpp.hDeviceWindow = ctx->hWnd; - d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; - - // Support for vertical retrace synchronisation. - // Set default presentation interval in case caps bits are missing - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; - if (glb.bWaitForRetrace) { - if (lpCtx->d3dCaps9.PresentationIntervals & D3DPRESENT_INTERVAL_ONE) - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; - } else { - if (lpCtx->d3dCaps9.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; - } - } else { - ddlogWarnOption(glb.bMessageBoxWarnings); // OK to popup messages - d3dpp.Windowed = TRUE; - d3dpp.BackBufferWidth = ctx->dwWidth; - d3dpp.BackBufferHeight = ctx->dwHeight; - d3dpp.hDeviceWindow = ctx->hWnd; - d3dpp.FullScreen_RefreshRateInHz = 0; - // PresentationInterval Windowed mode is optional now in DX9 (DaveM) - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; - if (glb.bWaitForRetrace) { - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; - } else { - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; - } - } - - // Decide if we can use hardware TnL - dwBehaviourFlags = (lpCtx->bHasHWTnL) ? - D3DCREATE_MIXED_VERTEXPROCESSING : D3DCREATE_SOFTWARE_VERTEXPROCESSING; - // Add flag to tell D3D to be thread-safe - if (glb.bMultiThreaded) - dwBehaviourFlags |= D3DCREATE_MULTITHREADED; - // Add flag to tell D3D to be FPU-safe - if (!glb.bFastFPU) - dwBehaviourFlags |= D3DCREATE_FPU_PRESERVE; - hResult = IDirect3D9_CreateDevice(lpCtx->pD3D, - glb.dwAdapter, - d3dDevType, - ctx->hWnd, - dwBehaviourFlags, - &d3dpp, - &lpCtx->pDev); - if (FAILED(hResult)) { - ddlogError(DDLOG_CRITICAL_OR_WARN, "IDirect3D9_CreateDevice failed", hResult); - nContextError = GLDERR_D3D; - goto return_with_error; - } - - if (bDirectDrawPersistant && bPersistantBuffers && dx9Globals.pD3D) { - dx9Globals.pDev = lpCtx->pDev; - dx9Globals.bDirect3DDevice = TRUE; - } - - // Dump some useful stats - hResult = IDirect3D9_GetAdapterIdentifier( - lpCtx->pD3D, - glb.dwAdapter, - 0, // No WHQL detection (avoid few seconds delay) - &d3dIdent); - if (SUCCEEDED(hResult)) { - ddlogPrintf(DDLOG_INFO, "[Driver Description: %s]", &d3dIdent.Description); - ddlogPrintf(DDLOG_INFO, "[Driver file: %s %d.%d.%02d.%d]", - d3dIdent.Driver, - HIWORD(d3dIdent.DriverVersion.HighPart), - LOWORD(d3dIdent.DriverVersion.HighPart), - HIWORD(d3dIdent.DriverVersion.LowPart), - LOWORD(d3dIdent.DriverVersion.LowPart)); - ddlogPrintf(DDLOG_INFO, "[VendorId: 0x%X, DeviceId: 0x%X, SubSysId: 0x%X, Revision: 0x%X]", - d3dIdent.VendorId, d3dIdent.DeviceId, d3dIdent.SubSysId, d3dIdent.Revision); - } - - // Test to see if IHV driver exposes Scissor Test (new for DX9) - lpCtx->bCanScissor = lpCtx->d3dCaps9.RasterCaps & D3DPRASTERCAPS_SCISSORTEST; - ddlogPrintf(DDLOG_INFO, "Can Scissor: %s", lpCtx->bCanScissor ? "Yes" : "No"); - - // Init projection matrix for D3D TnL - D3DXMatrixIdentity(&lpCtx->matProjection); - lpCtx->matModelView = lpCtx->matProjection; -// gld->bUseMesaProjection = TRUE; - -skip_direct3ddevice_create: - - // Create buffers to hold primitives - lpCtx->PB2d.dwFVF = GLD_FVF_2D_VERTEX; - lpCtx->PB2d.dwPool = D3DPOOL_SYSTEMMEM; - lpCtx->PB2d.dwStride = sizeof(GLD_2D_VERTEX); - lpCtx->PB2d.dwUsage = D3DUSAGE_DONOTCLIP | - D3DUSAGE_DYNAMIC | - D3DUSAGE_SOFTWAREPROCESSING | - D3DUSAGE_WRITEONLY; - hResult = _gldCreatePrimitiveBuffer(ctx->glCtx, lpCtx, &lpCtx->PB2d); - if (FAILED(hResult)) - goto return_with_error; - - lpCtx->PB3d.dwFVF = GLD_FVF_3D_VERTEX; - lpCtx->PB3d.dwPool = D3DPOOL_DEFAULT; - lpCtx->PB3d.dwStride = sizeof(GLD_3D_VERTEX); - lpCtx->PB3d.dwUsage = D3DUSAGE_DYNAMIC | -//DaveM D3DUSAGE_SOFTWAREPROCESSING | - D3DUSAGE_WRITEONLY; - hResult = _gldCreatePrimitiveBuffer(ctx->glCtx, lpCtx, &lpCtx->PB3d); - if (FAILED(hResult)) - goto return_with_error; - -/* // NOTE: A FVF code of zero indicates a non-FVF vertex buffer (for vertex shaders) - lpCtx->PBtwosidelight.dwFVF = 0; //GLD_FVF_TWOSIDED_VERTEX; - lpCtx->PBtwosidelight.dwPool = D3DPOOL_DEFAULT; - lpCtx->PBtwosidelight.dwStride = sizeof(GLD_TWOSIDED_VERTEX); - lpCtx->PBtwosidelight.dwUsage = D3DUSAGE_DONOTCLIP | - D3DUSAGE_DYNAMIC | - D3DUSAGE_SOFTWAREPROCESSING | - D3DUSAGE_WRITEONLY; - hResult = _gldCreatePrimitiveBuffer(ctx->glCtx, lpCtx, &lpCtx->PBtwosidelight); - if (FAILED(hResult)) - goto return_with_error;*/ - - // Now try and create the DX9 Vertex Shaders -// _gldCreateVertexShaders(lpCtx); - - // Zero the pipeline usage counters - lpCtx->PipelineUsage.qwMesa.QuadPart = -// lpCtx->PipelineUsage.dwD3D2SVS.QuadPart = - lpCtx->PipelineUsage.qwD3DFVF.QuadPart = 0; - - // Assign drawable to GL private - ctx->glPriv = lpCtx; - return TRUE; - -return_with_error: - // Clean up and bail - -// _gldDestroyVertexShaders(lpCtx); - -// _gldDestroyPrimitiveBuffer(&lpCtx->PBtwosidelight); - _gldDestroyPrimitiveBuffer(&lpCtx->PB3d); - _gldDestroyPrimitiveBuffer(&lpCtx->PB2d); - - SAFE_RELEASE(lpCtx->pDev); - SAFE_RELEASE(lpCtx->pD3D); - return FALSE; -} - -//--------------------------------------------------------------------------- - -BOOL gldResizeDrawable_DX( - DGL_ctx *ctx, - BOOL bDefaultDriver, - BOOL bPersistantInterface, - BOOL bPersistantBuffers) -{ - GLD_driver_dx9 *gld = NULL; - D3DDEVTYPE d3dDevType; - D3DPRESENT_PARAMETERS d3dpp; - D3DDISPLAYMODE d3ddm; - HRESULT hResult; - - // Error if context is NULL. - if (ctx == NULL) - return FALSE; - - gld = ctx->glPriv; - if (gld == NULL) - return FALSE; - - if (ctx->bSceneStarted) { - IDirect3DDevice9_EndScene(gld->pDev); - ctx->bSceneStarted = FALSE; - } - - d3dDevType = (glb.dwDriver == GLDS_DRIVER_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; - if (!bDefaultDriver) - d3dDevType = D3DDEVTYPE_REF; // Force Direct3D Reference Rasterise (software) - - // Get the display mode so we can make a compatible backbuffer - hResult = IDirect3D9_GetAdapterDisplayMode(gld->pD3D, glb.dwAdapter, &d3ddm); - if (FAILED(hResult)) { - nContextError = GLDERR_D3D; -// goto return_with_error; - return FALSE; - } - - // Destroy DX9 Vertex Shaders before Reset() -// _gldDestroyVertexShaders(gld); - - // Release POOL_DEFAULT objects before Reset() - if (gld->PB2d.dwPool == D3DPOOL_DEFAULT) - _gldDestroyPrimitiveBuffer(&gld->PB2d); - if (gld->PB3d.dwPool == D3DPOOL_DEFAULT) - _gldDestroyPrimitiveBuffer(&gld->PB3d); -// if (gld->PBtwosidelight.dwPool == D3DPOOL_DEFAULT) -// _gldDestroyPrimitiveBuffer(&gld->PBtwosidelight); - - // Clear the presentation parameters (sets all members to zero) - ZeroMemory(&d3dpp, sizeof(d3dpp)); - - // Recommended by MS; needed for MultiSample. - // Be careful if altering this for FullScreenBlit - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - - d3dpp.BackBufferFormat = d3ddm.Format; - d3dpp.BackBufferCount = 1; - d3dpp.MultiSampleType = _gldGetDeviceMultiSampleType(gld->pD3D, d3ddm.Format, d3dDevType, !ctx->bFullscreen); - d3dpp.AutoDepthStencilFormat = ctx->lpPF->dwDriverData; - d3dpp.EnableAutoDepthStencil = (d3dpp.AutoDepthStencilFormat == D3DFMT_UNKNOWN) ? FALSE : TRUE; - - // TODO: Sync to refresh - - if (ctx->bFullscreen) { - ddlogWarnOption(FALSE); // Don't popup any messages in fullscreen - d3dpp.Windowed = FALSE; - d3dpp.BackBufferWidth = d3ddm.Width; - d3dpp.BackBufferHeight = d3ddm.Height; - d3dpp.hDeviceWindow = ctx->hWnd; - d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; - // Get better benchmark results? KeithH -// d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_UNLIMITED; - } else { - ddlogWarnOption(glb.bMessageBoxWarnings); // OK to popup messages - d3dpp.Windowed = TRUE; - d3dpp.BackBufferWidth = ctx->dwWidth; - d3dpp.BackBufferHeight = ctx->dwHeight; - d3dpp.hDeviceWindow = ctx->hWnd; - d3dpp.FullScreen_RefreshRateInHz = 0; - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; - } - hResult = IDirect3DDevice9_Reset(gld->pDev, &d3dpp); - if (FAILED(hResult)) { - ddlogError(DDLOG_CRITICAL_OR_WARN, "dglResize: Reset failed", hResult); - return FALSE; - //goto cleanup_and_return_with_error; - } - - // - // Recreate POOL_DEFAULT objects - // - if (gld->PB2d.dwPool == D3DPOOL_DEFAULT) { - _gldCreatePrimitiveBuffer(ctx->glCtx, gld, &gld->PB2d); - } - if (gld->PB3d.dwPool == D3DPOOL_DEFAULT) { - _gldCreatePrimitiveBuffer(ctx->glCtx, gld, &gld->PB3d); - } -// if (gld->PBtwosidelight.dwPool == D3DPOOL_DEFAULT) { -// _gldCreatePrimitiveBuffer(ctx->glCtx, gld, &gld->PB2d); -// } - - // Recreate DX9 Vertex Shaders -// _gldCreateVertexShaders(gld); - - // Signal a complete state update - ctx->glCtx->Driver.UpdateState(ctx->glCtx, _NEW_ALL); - - // Begin a new scene - IDirect3DDevice9_BeginScene(gld->pDev); - ctx->bSceneStarted = TRUE; - - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldDestroyDrawable_DX( - DGL_ctx *ctx) -{ - GLD_driver_dx9 *lpCtx = NULL; - - // Error if context is NULL. - if (!ctx) - return FALSE; - - // Error if the drawable does not exist. - if (!ctx->glPriv) - return FALSE; - - lpCtx = ctx->glPriv; - -#ifdef _DEBUG - // Dump out stats - ddlogPrintf(DDLOG_SYSTEM, "Usage: M:0x%X%X, D:0x%X%X", - lpCtx->PipelineUsage.qwMesa.HighPart, - lpCtx->PipelineUsage.qwMesa.LowPart, - lpCtx->PipelineUsage.qwD3DFVF.HighPart, - lpCtx->PipelineUsage.qwD3DFVF.LowPart); -#endif - -// _gldDestroyVertexShaders(lpCtx); - -// _gldDestroyPrimitiveBuffer(&lpCtx->PBtwosidelight); - _gldDestroyPrimitiveBuffer(&lpCtx->PB3d); - _gldDestroyPrimitiveBuffer(&lpCtx->PB2d); - - SAFE_RELEASE(lpCtx->pDev); - SAFE_RELEASE(lpCtx->pD3D); - - // Free the private drawable data - free(ctx->glPriv); - ctx->glPriv = NULL; - - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldCreatePrivateGlobals_DX(void) -{ - ZeroMemory(&dx9Globals, sizeof(dx9Globals)); - - // Load d3d9.dll - dx9Globals.hD3D9DLL = LoadLibrary("D3D9.DLL"); - if (dx9Globals.hD3D9DLL == NULL) - return FALSE; - - // Now try and obtain Direct3DCreate9 - dx9Globals.fnDirect3DCreate9 = (FNDIRECT3DCREATE9)GetProcAddress(dx9Globals.hD3D9DLL, "Direct3DCreate9"); - if (dx9Globals.fnDirect3DCreate9 == NULL) { - FreeLibrary(dx9Globals.hD3D9DLL); - return FALSE; - } - - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldDestroyPrivateGlobals_DX(void) -{ - if (dx9Globals.bDirect3DDevice) { - SAFE_RELEASE(dx9Globals.pDev); - dx9Globals.bDirect3DDevice = FALSE; - } - if (dx9Globals.bDirect3D) { - SAFE_RELEASE(dx9Globals.pD3D); - dx9Globals.bDirect3D = FALSE; - } - - FreeLibrary(dx9Globals.hD3D9DLL); - dx9Globals.hD3D9DLL = NULL; - dx9Globals.fnDirect3DCreate9 = NULL; - - return TRUE; -} - -//--------------------------------------------------------------------------- - -static void _BitsFromDisplayFormat( - D3DFORMAT fmt, - BYTE *cColorBits, - BYTE *cRedBits, - BYTE *cGreenBits, - BYTE *cBlueBits, - BYTE *cAlphaBits) -{ - switch (fmt) { - case D3DFMT_X1R5G5B5: - *cColorBits = 16; - *cRedBits = 5; - *cGreenBits = 5; - *cBlueBits = 5; - *cAlphaBits = 0; - return; - case D3DFMT_R5G6B5: - *cColorBits = 16; - *cRedBits = 5; - *cGreenBits = 6; - *cBlueBits = 5; - *cAlphaBits = 0; - return; - case D3DFMT_X8R8G8B8: - *cColorBits = 32; - *cRedBits = 8; - *cGreenBits = 8; - *cBlueBits = 8; - *cAlphaBits = 0; - return; - case D3DFMT_A8R8G8B8: - *cColorBits = 32; - *cRedBits = 8; - *cGreenBits = 8; - *cBlueBits = 8; - *cAlphaBits = 8; - return; - } - - // Should not get here! - *cColorBits = 32; - *cRedBits = 8; - *cGreenBits = 8; - *cBlueBits = 8; - *cAlphaBits = 0; -} - -//--------------------------------------------------------------------------- - -static void _BitsFromDepthStencilFormat( - D3DFORMAT fmt, - BYTE *cDepthBits, - BYTE *cStencilBits) -{ - // NOTE: GL expects either 32 or 16 as depth bits. - switch (fmt) { - case D3DFMT_D32: - *cDepthBits = 32; - *cStencilBits = 0; - return; - case D3DFMT_D15S1: - *cDepthBits = 16; - *cStencilBits = 1; - return; - case D3DFMT_D24S8: - *cDepthBits = 32; - *cStencilBits = 8; - return; - case D3DFMT_D16: - *cDepthBits = 16; - *cStencilBits = 0; - return; - case D3DFMT_D24X8: - *cDepthBits = 32; - *cStencilBits = 0; - return; - case D3DFMT_D24X4S4: - *cDepthBits = 32; - *cStencilBits = 4; - return; - } -} - -//--------------------------------------------------------------------------- - -BOOL gldBuildPixelformatList_DX(void) -{ - D3DDISPLAYMODE d3ddm; - D3DFORMAT fmt[6]; - IDirect3D9 *pD3D = NULL; - HRESULT hr; - int nSupportedFormats = 0; - int i; - DGL_pixelFormat *pPF; - BYTE cColorBits, cRedBits, cGreenBits, cBlueBits, cAlphaBits; -// char buf[128]; -// char cat[8]; - - // Direct3D (SW or HW) - // These are arranged so that 'best' pixelformat - // is higher in the list (for ChoosePixelFormat). - const D3DFORMAT DepthStencil[6] = { -// New order: increaing Z, then increasing stencil - D3DFMT_D15S1, - D3DFMT_D16, - D3DFMT_D24X4S4, - D3DFMT_D24X8, - D3DFMT_D24S8, - D3DFMT_D32, - }; - - // Dump DX version - ddlogMessage(GLDLOG_SYSTEM, "DirectX Version : 9.0\n"); - - // Release any existing pixelformat list - if (glb.lpPF) { - free(glb.lpPF); - } - - glb.nPixelFormatCount = 0; - glb.lpPF = NULL; - - // - // Pixelformats for Direct3D (SW or HW) rendering - // - - // Get a Direct3D 9.0 interface - pD3D = dx9Globals.fnDirect3DCreate9(D3D_SDK_VERSION); - if (!pD3D) { - return FALSE; - } - - // We will use the display mode format when finding compliant - // rendertarget/depth-stencil surfaces. - hr = IDirect3D9_GetAdapterDisplayMode(pD3D, glb.dwAdapter, &d3ddm); - if (FAILED(hr)) { - IDirect3D9_Release(pD3D); - return FALSE; - } - - // Run through the possible formats and detect supported formats - for (i=0; i<6; i++) { - hr = IDirect3D9_CheckDeviceFormat( - pD3D, - glb.dwAdapter, - glb.dwDriver==GLDS_DRIVER_HAL ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF, - d3ddm.Format, - D3DUSAGE_DEPTHSTENCIL, - D3DRTYPE_SURFACE, - DepthStencil[i]); - if (FAILED(hr)) - // A failure here is not fatal. - continue; - - // Verify that the depth format is compatible. - hr = IDirect3D9_CheckDepthStencilMatch( - pD3D, - glb.dwAdapter, - glb.dwDriver==GLDS_DRIVER_HAL ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF, - d3ddm.Format, - d3ddm.Format, - DepthStencil[i]); - if (FAILED(hr)) - // A failure here is not fatal, just means depth-stencil - // format is not compatible with this display mode. - continue; - - fmt[nSupportedFormats++] = DepthStencil[i]; - } - - IDirect3D9_Release(pD3D); - - if (nSupportedFormats == 0) - return FALSE; // Bail: no compliant pixelformats - - // Total count of pixelformats is: - // (nSupportedFormats+1)*2 - // UPDATED: nSupportedFormats*2 - glb.lpPF = (DGL_pixelFormat *)calloc(nSupportedFormats*2, sizeof(DGL_pixelFormat)); - glb.nPixelFormatCount = nSupportedFormats*2; - if (glb.lpPF == NULL) { - glb.nPixelFormatCount = 0; - return FALSE; - } - - // Get a copy of pointer that we can alter - pPF = glb.lpPF; - - // Cache colour bits from display format - _BitsFromDisplayFormat(d3ddm.Format, &cColorBits, &cRedBits, &cGreenBits, &cBlueBits, &cAlphaBits); - - // - // Add single-buffer formats - // -/* - // NOTE: No longer returning pixelformats that don't contain depth - // Single-buffer, no depth-stencil buffer - memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); - pPF->pfd.dwFlags &= ~PFD_DOUBLEBUFFER; // Remove doublebuffer flag - pPF->pfd.cColorBits = cColorBits; - pPF->pfd.cRedBits = cRedBits; - pPF->pfd.cGreenBits = cGreenBits; - pPF->pfd.cBlueBits = cBlueBits; - pPF->pfd.cAlphaBits = cAlphaBits; - pPF->pfd.cDepthBits = 0; - pPF->pfd.cStencilBits = 0; - pPF->dwDriverData = D3DFMT_UNKNOWN; - pPF++; -*/ - for (i=0; i<nSupportedFormats; i++, pPF++) { - memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); - pPF->pfd.dwFlags &= ~PFD_DOUBLEBUFFER; // Remove doublebuffer flag - pPF->pfd.cColorBits = cColorBits; - pPF->pfd.cRedBits = cRedBits; - pPF->pfd.cGreenBits = cGreenBits; - pPF->pfd.cBlueBits = cBlueBits; - pPF->pfd.cAlphaBits = cAlphaBits; - _BitsFromDepthStencilFormat(fmt[i], &pPF->pfd.cDepthBits, &pPF->pfd.cStencilBits); - pPF->dwDriverData = fmt[i]; - } - - // - // Add double-buffer formats - // - - // NOTE: No longer returning pixelformats that don't contain depth -/* - memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); - pPF->pfd.cColorBits = cColorBits; - pPF->pfd.cRedBits = cRedBits; - pPF->pfd.cGreenBits = cGreenBits; - pPF->pfd.cBlueBits = cBlueBits; - pPF->pfd.cAlphaBits = cAlphaBits; - pPF->pfd.cDepthBits = 0; - pPF->pfd.cStencilBits = 0; - pPF->dwDriverData = D3DFMT_UNKNOWN; - pPF++; -*/ - for (i=0; i<nSupportedFormats; i++, pPF++) { - memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); - pPF->pfd.cColorBits = cColorBits; - pPF->pfd.cRedBits = cRedBits; - pPF->pfd.cGreenBits = cGreenBits; - pPF->pfd.cBlueBits = cBlueBits; - pPF->pfd.cAlphaBits = cAlphaBits; - _BitsFromDepthStencilFormat(fmt[i], &pPF->pfd.cDepthBits, &pPF->pfd.cStencilBits); - pPF->dwDriverData = fmt[i]; - } - - // Popup warning message if non RGB color mode - { - // This is a hack. KeithH - HDC hdcDesktop = GetDC(NULL); - DWORD dwDisplayBitDepth = GetDeviceCaps(hdcDesktop, BITSPIXEL); - ReleaseDC(0, hdcDesktop); - if (dwDisplayBitDepth <= 8) { - ddlogPrintf(DDLOG_WARN, "Current Color Depth %d bpp is not supported", dwDisplayBitDepth); - MessageBox(NULL, szColorDepthWarning, "GLDirect", MB_OK | MB_ICONWARNING); - } - } - - // Mark list as 'current' - glb.bPixelformatsDirty = FALSE; - - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldInitialiseMesa_DX( - DGL_ctx *lpCtx) -{ - GLD_driver_dx9 *gld = NULL; - int MaxTextureSize, TextureLevels; - BOOL bSoftwareTnL; - - if (lpCtx == NULL) - return FALSE; - - gld = lpCtx->glPriv; - if (gld == NULL) - return FALSE; - - if (glb.bMultitexture) { - lpCtx->glCtx->Const.MaxTextureUnits = gld->d3dCaps9.MaxSimultaneousTextures; - // Only support MAX_TEXTURE_UNITS texture units. - // ** If this is altered then the FVF formats must be reviewed **. - if (lpCtx->glCtx->Const.MaxTextureUnits > GLD_MAX_TEXTURE_UNITS_DX9) - lpCtx->glCtx->Const.MaxTextureUnits = GLD_MAX_TEXTURE_UNITS_DX9; - } else { - // Multitexture override - lpCtx->glCtx->Const.MaxTextureUnits = 1; - } - - // max texture size - MaxTextureSize = min(gld->d3dCaps9.MaxTextureHeight, gld->d3dCaps9.MaxTextureWidth); - if (MaxTextureSize == 0) - MaxTextureSize = 256; // Sanity check - - // - // HACK!! - if (MaxTextureSize > 1024) - MaxTextureSize = 1024; // HACK - CLAMP TO 1024 - // HACK!! - // - - // Got to set MAX_TEXTURE_SIZE as max levels. - // Who thought this stupid idea up? ;) - TextureLevels = 0; - // Calculate power-of-two. - while (MaxTextureSize) { - TextureLevels++; - MaxTextureSize >>= 1; - } - lpCtx->glCtx->Const.MaxTextureLevels = (TextureLevels) ? TextureLevels : 8; - lpCtx->glCtx->Const.MaxDrawBuffers = 1; - - IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_LIGHTING, FALSE); - IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_CULLMODE, D3DCULL_NONE); - IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_DITHERENABLE, TRUE); - IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_SHADEMODE, D3DSHADE_GOURAUD); - - IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_ZENABLE, - (lpCtx->lpPF->dwDriverData!=D3DFMT_UNKNOWN) ? D3DZB_TRUE : D3DZB_FALSE); - - // Set the view matrix - { - D3DXMATRIX vm; -#if 1 - D3DXMatrixIdentity(&vm); -#else - D3DXVECTOR3 Eye(0.0f, 0.0f, 0.0f); - D3DXVECTOR3 At(0.0f, 0.0f, -1.0f); - D3DXVECTOR3 Up(0.0f, 1.0f, 0.0f); - D3DXMatrixLookAtRH(&vm, &Eye, &At, &Up); - vm._31 = -vm._31; - vm._32 = -vm._32; - vm._33 = -vm._33; - vm._34 = -vm._34; -#endif - IDirect3DDevice9_SetTransform(gld->pDev, D3DTS_VIEW, &vm); - } - - if (gld->bHasHWTnL) { - if (glb.dwTnL == GLDS_TNL_DEFAULT) - bSoftwareTnL = FALSE; // HW TnL - else { - bSoftwareTnL = ((glb.dwTnL == GLDS_TNL_MESA) || (glb.dwTnL == GLDS_TNL_D3DSW)) ? TRUE : FALSE; - } - } else { - // No HW TnL, so no choice possible - bSoftwareTnL = TRUE; - } -// IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, bSoftwareTnL); - IDirect3DDevice9_SetSoftwareVertexProcessing(gld->pDev, bSoftwareTnL); - -// Dump this in a Release build as well, now. -//#ifdef _DEBUG - ddlogPrintf(DDLOG_INFO, "HW TnL: %s", - gld->bHasHWTnL ? (bSoftwareTnL ? "Disabled" : "Enabled") : "Unavailable"); -//#endif - - gldEnableExtensions_DX9(lpCtx->glCtx); - gldInstallPipeline_DX9(lpCtx->glCtx); - gldSetupDriverPointers_DX9(lpCtx->glCtx); - - // Signal a complete state update - lpCtx->glCtx->Driver.UpdateState(lpCtx->glCtx, _NEW_ALL); - - // Start a scene - IDirect3DDevice9_BeginScene(gld->pDev); - lpCtx->bSceneStarted = TRUE; - - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldSwapBuffers_DX( - DGL_ctx *ctx, - HDC hDC, - HWND hWnd) -{ - HRESULT hr; - GLD_driver_dx9 *gld = NULL; - - if (ctx == NULL) - return FALSE; - - gld = ctx->glPriv; - if (gld == NULL) - return FALSE; - - if (ctx->bSceneStarted) { - IDirect3DDevice9_EndScene(gld->pDev); - ctx->bSceneStarted = FALSE; - } - - // Swap the buffers. hWnd may override the hWnd used for CreateDevice() - hr = IDirect3DDevice9_Present(gld->pDev, NULL, NULL, hWnd, NULL); - -exit_swap: - - IDirect3DDevice9_BeginScene(gld->pDev); - ctx->bSceneStarted = TRUE; - -// Debugging code -#ifdef _DEBUG -// ddlogMessage(GLDLOG_WARN, "SwapBuffers\n"); -#endif - - return (FAILED(hr)) ? FALSE : TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldGetDisplayMode_DX( - DGL_ctx *ctx, - GLD_displayMode *glddm) -{ - D3DDISPLAYMODE d3ddm; - HRESULT hr; - GLD_driver_dx9 *lpCtx = NULL; - BYTE cColorBits, cRedBits, cGreenBits, cBlueBits, cAlphaBits; - - if ((glddm == NULL) || (ctx == NULL)) - return FALSE; - - lpCtx = ctx->glPriv; - if (lpCtx == NULL) - return FALSE; - - if (lpCtx->pD3D == NULL) - return FALSE; - - hr = IDirect3D9_GetAdapterDisplayMode(lpCtx->pD3D, glb.dwAdapter, &d3ddm); - if (FAILED(hr)) - return FALSE; - - // Get info from the display format - _BitsFromDisplayFormat(d3ddm.Format, - &cColorBits, &cRedBits, &cGreenBits, &cBlueBits, &cAlphaBits); - - glddm->Width = d3ddm.Width; - glddm->Height = d3ddm.Height; - glddm->BPP = cColorBits; - glddm->Refresh = d3ddm.RefreshRate; - - return TRUE; -} - -//--------------------------------------------------------------------------- - diff --git a/src/mesa/drivers/windows/gldirect/mesasw/colors.h b/src/mesa/drivers/windows/gldirect/mesasw/colors.h deleted file mode 100644 index 9c1f2a0540..0000000000 --- a/src/mesa/drivers/windows/gldirect/mesasw/colors.h +++ /dev/null @@ -1,520 +0,0 @@ -/* File name : colors.h - * Version : 2.3 - * - * Header file for display driver for Mesa 2.3 under - * Windows95 and WindowsNT - * This file defines macros and global variables needed - * for converting color format - * - * Copyright (C) 1996- Li Wei - * Address : Institute of Artificial Intelligence - * : & Robotics - * : Xi'an Jiaotong University - * Email : liwei@aiar.xjtu.edu.cn - * Web page : http://sun.aiar.xjtu.edu.cn - * - * This file and its associations are partially based on the - * Windows NT driver for Mesa, written by Mark Leaming - * (mark@rsinc.com). - */ - -/* - * Macros for pixel format defined - */ - -/* - * Revision 1.1 2004/04/20 11:13:11 alanh - * add SciTech's GLDirect driver for Windows. - * - * This code is donated to Mesa which allows the usage of - * a Direct3D layer (DX7, DX8, DX9 or complete software fallback). - * - * No build system exists for this code yet, that will come..... - * - * Revision 1.1.1.1 1999/08/19 00:55:42 jtg - * Imported sources - * - * Revision 1.2 1999/01/03 03:08:57 brianp - * Ted Jump's changes - * - * Revision 1.1 1999/01/03 03:08:12 brianp - * Initial revision - * - * Revision 2.0.2 1997/4/30 15:58:00 CST by Li Wei(liwei@aiar.xjtu.edu.cn) - * Add LUTs need for dithering - */ - -/* - * Revision 1.1 2004/04/20 11:13:11 alanh - * add SciTech's GLDirect driver for Windows. - * - * This code is donated to Mesa which allows the usage of - * a Direct3D layer (DX7, DX8, DX9 or complete software fallback). - * - * No build system exists for this code yet, that will come..... - * - * Revision 1.1.1.1 1999/08/19 00:55:42 jtg - * Imported sources - * - * Revision 1.2 1999/01/03 03:08:57 brianp - * Ted Jump's changes - * - * Revision 1.1 1999/01/03 03:08:12 brianp - * Initial revision - * - * Revision 2.0.1 1997/4/29 15:52:00 CST by Li Wei(liwei@aiar.xjtu.edu.cn) - * Add BGR8 Macro - */ - -/* - * Revision 1.1 2004/04/20 11:13:11 alanh - * add SciTech's GLDirect driver for Windows. - * - * This code is donated to Mesa which allows the usage of - * a Direct3D layer (DX7, DX8, DX9 or complete software fallback). - * - * No build system exists for this code yet, that will come..... - * - * Revision 1.1.1.1 1999/08/19 00:55:42 jtg - * Imported sources - * - * Revision 1.2 1999/01/03 03:08:57 brianp - * Ted Jump's changes - * - * Revision 1.1 1999/01/03 03:08:12 brianp - * Initial revision - * - * Revision 2.0 1996/11/15 10:55:00 CST by Li Wei(liwei@aiar.xjtu.edu.cn) - * Initial revision - */ -/* Values for wmesa->pixelformat: */ - -#define PF_8A8B8G8R 3 /* 32-bit TrueColor: 8-A, 8-B, 8-G, 8-R */ -#define PF_8R8G8B 4 /* 32-bit TrueColor: 8-R, 8-G, 8-B */ -#define PF_5R6G5B 5 /* 16-bit TrueColor: 5-R, 6-G, 5-B bits */ -#define PF_DITHER8 6 /* Dithered RGB using a lookup table */ -#define PF_LOOKUP 7 /* Undithered RGB using a lookup table */ -#define PF_GRAYSCALE 10 /* Grayscale or StaticGray */ -#define PF_BADFORMAT 11 -#define PF_INDEX8 12 - -char ColorMap16[] = { -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03, -0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04, -0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05, -0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06, -0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07, -0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08, -0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09, -0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A, -0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B, -0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C, -0x0D,0x0D,0x0D,0x0D,0x0D,0x0D,0x0D,0x0D, -0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E, -0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F, -0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, -0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, -0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13, -0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14, -0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15, -0x16,0x16,0x16,0x16,0x16,0x16,0x16,0x16, -0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17, -0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, -0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19, -0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A, -0x1B,0x1B,0x1B,0x1B,0x1B,0x1B,0x1B,0x1B, -0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C, -0x1D,0x1D,0x1D,0x1D,0x1D,0x1D,0x1D,0x1D, -0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E, -0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}; - -#define BGR8(r,g,b) (unsigned)(((BYTE)(b & 0xc0 | (g & 0xe0)>>2 | (r & 0xe0)>>5))) -#ifdef DDRAW -#define BGR16(r,g,b) ((WORD)(((BYTE)(ColorMap16[b]) | ((BYTE)(g&0xfc) << 3)) | (((WORD)(BYTE)(ColorMap16[r])) << 11))) -#else -#define BGR16(r,g,b) ((WORD)(((BYTE)(ColorMap16[b]) | ((BYTE)(ColorMap16[g]) << 5)) | (((WORD)(BYTE)(ColorMap16[r])) << 10))) -#endif -#define BGR24(r,g,b) (unsigned long)(((DWORD)(((BYTE)(b)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(r))<<16))) << 8) -#define BGR32(r,g,b) (unsigned long)((DWORD)(((BYTE)(b)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(r))<<16))) - - - -/* - * If pixelformat==PF_8A8B8G8R: - */ -#define PACK_8A8B8G8R( R, G, B, A ) \ - ( ((A) << 24) | ((B) << 16) | ((G) << 8) | (R) ) - - -/* - * If pixelformat==PF_8R8G8B: - */ -#define PACK_8R8G8B( R, G, B) ( ((R) << 16) | ((G) << 8) | (B) ) - - -/* - * If pixelformat==PF_5R6G5B: - */ - - -#ifdef DDRAW -#define PACK_5R6G5B( R, G, B) ((WORD)(((BYTE)(ColorMap16[B]) | ((BYTE)(G&0xfc) << 3)) | (((WORD)(BYTE)(ColorMap16[R])) << 11))) -#else -#define PACK_5R6G5B( R, G, B) ((WORD)(((BYTE)(ColorMap16[B]) | ((BYTE)(ColorMap16[G]) << 5)) | (((WORD)(BYTE)(ColorMap16[R])) << 10))) -#endif -/*---------------------------------------------------------------------------- - -Division lookup tables. These tables compute 0-255 divided by 51 and -modulo 51. These tables could approximate gamma correction. - -*/ - -char unsigned const aDividedBy51Rounded[256] = -{ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, -}; - -char unsigned const aDividedBy51[256] = -{ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, -}; - -char unsigned const aModulo51[256] = -{ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, - 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, - 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, - 44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, - 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, - 49, 50, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, - 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, - 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3, - 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, - 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0, -}; - -/*---------------------------------------------------------------------------- - -Multiplication LUTs. These compute 0-5 times 6 and 36. - -*/ - -char unsigned const aTimes6[6] = -{ - 0, 6, 12, 18, 24, 30 -}; - -char unsigned const aTimes36[6] = -{ - 0, 36, 72, 108, 144, 180 -}; - - -/*---------------------------------------------------------------------------- - -Dither matrices for 8 bit to 2.6 bit halftones. - -*/ - -char unsigned const aHalftone16x16[256] = -{ - 0, 44, 9, 41, 3, 46, 12, 43, 1, 44, 10, 41, 3, 46, 12, 43, - 34, 16, 25, 19, 37, 18, 28, 21, 35, 16, 26, 19, 37, 18, 28, 21, - 38, 6, 47, 3, 40, 9, 50, 6, 38, 7, 47, 4, 40, 9, 49, 6, - 22, 28, 13, 31, 25, 31, 15, 34, 22, 29, 13, 32, 24, 31, 15, 34, - 2, 46, 12, 43, 1, 45, 10, 42, 2, 45, 11, 42, 1, 45, 11, 42, - 37, 18, 27, 21, 35, 17, 26, 20, 36, 17, 27, 20, 36, 17, 26, 20, - 40, 8, 49, 5, 38, 7, 48, 4, 39, 8, 48, 5, 39, 7, 48, 4, - 24, 30, 15, 33, 23, 29, 13, 32, 23, 30, 14, 33, 23, 29, 14, 32, - 2, 46, 12, 43, 0, 44, 10, 41, 3, 47, 12, 44, 0, 44, 10, 41, - 37, 18, 27, 21, 35, 16, 25, 19, 37, 19, 28, 22, 35, 16, 25, 19, - 40, 9, 49, 5, 38, 7, 47, 4, 40, 9, 50, 6, 38, 6, 47, 3, - 24, 30, 15, 34, 22, 29, 13, 32, 25, 31, 15, 34, 22, 28, 13, 31, - 1, 45, 11, 42, 2, 46, 11, 42, 1, 45, 10, 41, 2, 46, 11, 43, - 36, 17, 26, 20, 36, 17, 27, 21, 35, 16, 26, 20, 36, 18, 27, 21, - 39, 8, 48, 4, 39, 8, 49, 5, 38, 7, 48, 4, 39, 8, 49, 5, - 23, 29, 14, 33, 24, 30, 14, 33, 23, 29, 13, 32, 24, 30, 14, 33, -}; - -char unsigned const aHalftone8x8[64] = -{ - 0, 38, 9, 47, 2, 40, 11, 50, - 25, 12, 35, 22, 27, 15, 37, 24, - 6, 44, 3, 41, 8, 47, 5, 43, - 31, 19, 28, 15, 34, 21, 31, 18, - 1, 39, 11, 49, 0, 39, 10, 48, - 27, 14, 36, 23, 26, 13, 35, 23, - 7, 46, 4, 43, 7, 45, 3, 42, - 33, 20, 30, 17, 32, 19, 29, 16, -}; - -char unsigned const aHalftone4x4_1[16] = -{ - 0, 25, 6, 31, - 38, 12, 44, 19, - 9, 35, 3, 28, - 47, 22, 41, 15 -}; - -char unsigned const aHalftone4x4_2[16] = -{ - 41, 3, 9, 28, - 35, 15, 22, 47, - 6, 25, 38, 0, - 19, 44, 31, 12 -}; - -/*************************************************************************** - aWinGHalftoneTranslation - - Translates a 2.6 bit-per-pixel halftoned representation into the - slightly rearranged WinG Halftone Palette. -*/ - -char unsigned const aWinGHalftoneTranslation[216] = -{ - 0, - 29, - 30, - 31, - 32, - 249, - 33, - 34, - 35, - 36, - 37, - 38, - 39, - 40, - 41, - 42, - 43, - 44, - 45, - 46, - 47, - 48, - 49, - 50, - 51, - 52, - 53, - 54, - 55, - 56, - 250, - 250, - 57, - 58, - 59, - 251, - 60, - 61, - 62, - 63, - 64, - 65, - 66, - 67, - 68, - 69, - 70, - 71, - 72, - 73, - 74, - 75, - 76, - 77, - 78, - 79, - 80, - 81, - 82, - 83, - 84, - 85, - 86, - 87, - 88, - 89, - 250, - 90, - 91, - 92, - 93, - 94, - 95, - 96, - 97, - 98, - 99, - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - 110, - 111, - 227, - 112, - 113, - 114, - 115, - 116, - 117, - 118, - 119, - 151, - 120, - 121, - 122, - 123, - 124, - 228, - 125, - 126, - 229, - 133, - 162, - 135, - 131, - 132, - 137, - 166, - 134, - 140, - 130, - 136, - 143, - 138, - 139, - 174, - 141, - 142, - 177, - 129, - 144, - 145, - 146, - 147, - 148, - 149, - 150, - 157, - 152, - 153, - 154, - 155, - 156, - 192, - 158, - 159, - 160, - 161, - 196, - 163, - 164, - 165, - 127, - 199, - 167, - 168, - 169, - 170, - 171, - 172, - 173, - 207, - 175, - 176, - 210, - 178, - 179, - 180, - 181, - 182, - 183, - 184, - 185, - 186, - 187, - 188, - 189, - 190, - 191, - 224, - 193, - 194, - 195, - 252, - 252, - 197, - 198, - 128, - 253, - 252, - 200, - 201, - 202, - 203, - 204, - 205, - 206, - 230, - 208, - 209, - 231, - 211, - 212, - 213, - 214, - 215, - 216, - 217, - 218, - 219, - 220, - 221, - 222, - 254, - 223, - 232, - 225, - 226, - 255, -}; diff --git a/src/mesa/drivers/windows/gldirect/mesasw/gld_wgl_mesasw.c b/src/mesa/drivers/windows/gldirect/mesasw/gld_wgl_mesasw.c deleted file mode 100644 index 7ac425a109..0000000000 --- a/src/mesa/drivers/windows/gldirect/mesasw/gld_wgl_mesasw.c +++ /dev/null @@ -1,1698 +0,0 @@ -/**************************************************************************** -* -* Mesa 3-D graphics library -* Direct3D Driver Interface -* -* ======================================================================== -* -* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -* -* ====================================================================== -* -* Language: ANSI C -* Environment: Windows 9x/2000/XP/XBox (Win32) -* -* Description: Mesa Software WGL (WindowsGL) -* -****************************************************************************/ - -#include <windows.h> -#define GL_GLEXT_PROTOTYPES -#include <GL/gl.h> -#include <GL/glext.h> - -#include "glheader.h" -#include "colors.h" -#include "context.h" -#include "colormac.h" -#include "dd.h" -#include "depth.h" -#include "extensions.h" -#include "macros.h" -#include "matrix.h" -// #include "mem.h" -//#include "mmath.h" -#include "mtypes.h" -#include "texformat.h" -#include "texstore.h" -#include "teximage.h" -#include "vbo/vbo.h" -#include "swrast/swrast.h" -#include "swrast_setup/swrast_setup.h" -#include "swrast/s_context.h" -#include "swrast/s_depth.h" -#include "swrast/s_lines.h" -#include "swrast/s_triangle.h" -#include "swrast/s_trispan.h" -#include "tnl/tnl.h" -#include "tnl/t_context.h" -#include "tnl/t_pipeline.h" - -#include "dglcontext.h" -#include "gld_driver.h" - -//--------------------------------------------------------------------------- -//--------------------------------------------------------------------------- - -DGL_pixelFormat pfTemplateMesaSW = -{ - { - sizeof(PIXELFORMATDESCRIPTOR), // Size of the data structure - 1, // Structure version - should be 1 - // Flags: - PFD_DRAW_TO_WINDOW | // The buffer can draw to a window or device surface. - PFD_DRAW_TO_BITMAP | // The buffer can draw to a bitmap. (DaveM) - PFD_SUPPORT_GDI | // The buffer supports GDI drawing. (DaveM) - PFD_SUPPORT_OPENGL | // The buffer supports OpenGL drawing. - PFD_DOUBLEBUFFER | // The buffer is double-buffered. - 0, // Placeholder for easy commenting of above flags - PFD_TYPE_RGBA, // Pixel type RGBA. - 32, // Total colour bitplanes (excluding alpha bitplanes) - 8, 0, // Red bits, shift - 8, 8, // Green bits, shift - 8, 16, // Blue bits, shift - 8, 24, // Alpha bits, shift (destination alpha) - 64, // Accumulator bits (total) - 16, 16, 16, 16, // Accumulator bits: Red, Green, Blue, Alpha - 16, // Depth bits - 8, // Stencil bits - 0, // Number of auxiliary buffers - 0, // Layer type - 0, // Specifies the number of overlay and underlay planes. - 0, // Layer mask - 0, // Specifies the transparent color or index of an underlay plane. - 0 // Damage mask - }, - 0, // Unused -}; - -//--------------------------------------------------------------------------- -// Extensions -//--------------------------------------------------------------------------- - -typedef struct { - PROC proc; - char *name; -} GLD_extension; - -static GLD_extension GLD_extList[] = { -#ifdef GL_EXT_polygon_offset - { (PROC)glPolygonOffsetEXT, "glPolygonOffsetEXT" }, -#endif - { (PROC)glBlendEquationEXT, "glBlendEquationEXT" }, - { (PROC)glBlendColorEXT, "glBlendColorExt" }, - { (PROC)glVertexPointerEXT, "glVertexPointerEXT" }, - { (PROC)glNormalPointerEXT, "glNormalPointerEXT" }, - { (PROC)glColorPointerEXT, "glColorPointerEXT" }, - { (PROC)glIndexPointerEXT, "glIndexPointerEXT" }, - { (PROC)glTexCoordPointerEXT, "glTexCoordPointer" }, - { (PROC)glEdgeFlagPointerEXT, "glEdgeFlagPointerEXT" }, - { (PROC)glGetPointervEXT, "glGetPointervEXT" }, - { (PROC)glArrayElementEXT, "glArrayElementEXT" }, - { (PROC)glDrawArraysEXT, "glDrawArrayEXT" }, - { (PROC)glAreTexturesResidentEXT, "glAreTexturesResidentEXT" }, - { (PROC)glBindTextureEXT, "glBindTextureEXT" }, - { (PROC)glDeleteTexturesEXT, "glDeleteTexturesEXT" }, - { (PROC)glGenTexturesEXT, "glGenTexturesEXT" }, - { (PROC)glIsTextureEXT, "glIsTextureEXT" }, - { (PROC)glPrioritizeTexturesEXT, "glPrioritizeTexturesEXT" }, - { (PROC)glCopyTexSubImage3DEXT, "glCopyTexSubImage3DEXT" }, - { (PROC)glTexImage3DEXT, "glTexImage3DEXT" }, - { (PROC)glTexSubImage3DEXT, "glTexSubImage3DEXT" }, - { (PROC)glPointParameterfEXT, "glPointParameterfEXT" }, - { (PROC)glPointParameterfvEXT, "glPointParameterfvEXT" }, - { (PROC)glLockArraysEXT, "glLockArraysEXT" }, - { (PROC)glUnlockArraysEXT, "glUnlockArraysEXT" }, - { NULL, "\0" } -}; - -//--------------------------------------------------------------------------- -// WMesa Internal Functions -//--------------------------------------------------------------------------- - -#define PAGE_FILE 0xffffffff - -#define REDBITS 0x03 -#define REDSHIFT 0x00 -#define GREENBITS 0x03 -#define GREENSHIFT 0x03 -#define BLUEBITS 0x02 -#define BLUESHIFT 0x06 - -typedef struct _dibSection { - HDC hDC; - HANDLE hFileMap; - BOOL fFlushed; - LPVOID base; -} WMDIBSECTION, *PWMDIBSECTION; - -typedef struct wmesa_context { - HWND Window; - HDC hDC; - HPALETTE hPalette; - HPALETTE hOldPalette; - HPEN hPen; - HPEN hOldPen; - HCURSOR hOldCursor; - COLORREF crColor; - // 3D projection stuff - RECT drawRect; - UINT uiDIBoffset; - // OpenGL stuff - HPALETTE hGLPalette; - GLuint width; - GLuint height; - GLuint ScanWidth; - GLboolean db_flag; //* double buffered? - GLboolean rgb_flag; //* RGB mode? - GLboolean dither_flag; //* use dither when 256 color mode for RGB? - GLuint depth; //* bits per pixel (1, 8, 24, etc) - ULONG pixel; // current color index or RGBA pixel value - ULONG clearpixel; //* pixel for clearing the color buffers - PBYTE ScreenMem; // WinG memory - BITMAPINFO *IndexFormat; - HPALETTE hPal; // Current Palette - HPALETTE hPalHalfTone; - - - WMDIBSECTION dib; - BITMAPINFO bmi; - HBITMAP hbmDIB; - HBITMAP hOldBitmap; - HBITMAP Old_Compat_BM; - HBITMAP Compat_BM; // Bitmap for double buffering - PBYTE pbPixels; - int nColors; - BYTE cColorBits; - int pixelformat; - - RECT rectOffScreen; - RECT rectSurface; -// HWND hwnd; - DWORD pitch; - PBYTE addrOffScreen; - - // We always double-buffer, for performance reasons, but - // we need to know which of SwapBuffers() or glFlush() to - // handle. If we're emulating, then we update on Flush(), - // otherwise we update on SwapBufers(). KeithH - BOOL bEmulateSingleBuffer; -} WMesaContext, *PWMC; - -#define GLD_GET_WMESA_DRIVER(c) (WMesaContext*)(c)->glPriv - -// TODO: -GLint stereo_flag = 0 ; - -/* If we are double-buffering, we want to get the DC for the - * off-screen DIB, otherwise the DC for the window. - */ -#define DD_GETDC ((Current->db_flag) ? Current->dib.hDC : Current->hDC ) -#define DD_RELEASEDC - -#define FLIP(Y) (Current->height-(Y)-1) - -struct DISPLAY_OPTIONS { - int stereo; - int fullScreen; - int mode; - int bpp; -}; - -struct DISPLAY_OPTIONS displayOptions; - -//--------------------------------------------------------------------------- - -static unsigned char threeto8[8] = { - 0, 0111>>1, 0222>>1, 0333>>1, 0444>>1, 0555>>1, 0666>>1, 0377 -}; - -static unsigned char twoto8[4] = { - 0, 0x55, 0xaa, 0xff -}; - -static unsigned char oneto8[2] = { - 0, 255 -}; - -//--------------------------------------------------------------------------- - -BYTE DITHER_RGB_2_8BIT( int red, int green, int blue, int pixel, int scanline) -{ - char unsigned redtemp, greentemp, bluetemp, paletteindex; - - //*** now, look up each value in the halftone matrix - //*** using an 8x8 ordered dither. - redtemp = aDividedBy51[red] - + (aModulo51[red] > aHalftone8x8[(pixel%8)*8 - + scanline%8]); - greentemp = aDividedBy51[(char unsigned)green] - + (aModulo51[green] > aHalftone8x8[ - (pixel%8)*8 + scanline%8]); - bluetemp = aDividedBy51[(char unsigned)blue] - + (aModulo51[blue] > aHalftone8x8[ - (pixel%8)*8 +scanline%8]); - - //*** recombine the halftoned rgb values into a palette index - paletteindex = - redtemp + aTimes6[greentemp] + aTimes36[bluetemp]; - - //*** and translate through the wing halftone palette - //*** translation vector to give the correct value. - return aWinGHalftoneTranslation[paletteindex]; -} - -//--------------------------------------------------------------------------- - -static unsigned char componentFromIndex(UCHAR i, UINT nbits, UINT shift) -{ - unsigned char val; - - val = i >> shift; - switch (nbits) { - - case 1: - val &= 0x1; - return oneto8[val]; - - case 2: - val &= 0x3; - return twoto8[val]; - - case 3: - val &= 0x7; - return threeto8[val]; - - default: - return 0; - } -} - -//--------------------------------------------------------------------------- - - -void wmSetPixel(PWMC pwc, int iScanLine, int iPixel, BYTE r, BYTE g, BYTE b) -{ - WMesaContext *Current = pwc; - - // Test for invalid scanline parameter. KeithH - if ((iScanLine < 0) || (iScanLine >= pwc->height)) - return; - - if (Current->db_flag) { - LPBYTE lpb = pwc->pbPixels; - UINT nBypp = pwc->cColorBits >> 3; - UINT nOffset = iPixel % nBypp; - - lpb += pwc->ScanWidth * iScanLine; - lpb += iPixel * nBypp; - - if(nBypp == 1){ - if(pwc->dither_flag) - *lpb = DITHER_RGB_2_8BIT(r,g,b,iScanLine,iPixel); - else - *lpb = BGR8(r,g,b); - } - else if(nBypp == 2) - *((LPWORD)lpb) = BGR16(r,g,b); - else if (nBypp == 3) - *((LPDWORD)lpb) = BGR24(r,g,b); - else if (nBypp == 4) - *((LPDWORD)lpb) = BGR32(r,g,b); - } - else{ - SetPixel(Current->hDC, iPixel, iScanLine, RGB(r,g,b)); - } -} - -//--------------------------------------------------------------------------- - -void wmCreateDIBSection( - HDC hDC, - PWMC pwc, // handle of device context - CONST BITMAPINFO *pbmi, // bitmap size, format, and color data - UINT iUsage // color data type indicator: RGB values or palette indices - ) -{ - DWORD dwSize = 0; - DWORD dwScanWidth; - UINT nBypp = pwc->cColorBits / 8; - HDC hic; - - dwScanWidth = (((pwc->ScanWidth * nBypp)+ 3) & ~3); - - pwc->ScanWidth =pwc->pitch = dwScanWidth; - - if (stereo_flag) - pwc->ScanWidth = 2* pwc->pitch; - - dwSize = sizeof(BITMAPINFO) + (dwScanWidth * pwc->height); - - pwc->dib.hFileMap = CreateFileMapping((HANDLE)PAGE_FILE, - NULL, - PAGE_READWRITE | SEC_COMMIT, - 0, - dwSize, - NULL); - - if (!pwc->dib.hFileMap) - return; - - pwc->dib.base = MapViewOfFile(pwc->dib.hFileMap, - FILE_MAP_ALL_ACCESS, - 0, - 0, - 0); - - if(!pwc->dib.base){ - CloseHandle(pwc->dib.hFileMap); - return; - } - - - CopyMemory(pwc->dib.base, pbmi, sizeof(BITMAPINFO)); - - hic = CreateIC("display", NULL, NULL, NULL); - pwc->dib.hDC = CreateCompatibleDC(hic); - - - pwc->hbmDIB = CreateDIBSection(hic, - &(pwc->bmi), - (iUsage ? DIB_PAL_COLORS : DIB_RGB_COLORS), - &(pwc->pbPixels), - pwc->dib.hFileMap, - 0); - pwc->ScreenMem = pwc->addrOffScreen = pwc->pbPixels; - pwc->hOldBitmap = SelectObject(pwc->dib.hDC, pwc->hbmDIB); - - DeleteDC(hic); - - return; - -} - -//--------------------------------------------------------------------------- - -void wmCreatePalette( PWMC pwdc ) -{ - /* Create a compressed and re-expanded 3:3:2 palette */ - int i; - LOGPALETTE *pPal; - BYTE rb, rs, gb, gs, bb, bs; - - pwdc->nColors = 0x100; - - pPal = (PLOGPALETTE)malloc(sizeof(LOGPALETTE) + - pwdc->nColors * sizeof(PALETTEENTRY)); - memset( pPal, 0, sizeof(LOGPALETTE) + pwdc->nColors * sizeof(PALETTEENTRY) ); - - pPal->palVersion = 0x300; - - rb = REDBITS; - rs = REDSHIFT; - gb = GREENBITS; - gs = GREENSHIFT; - bb = BLUEBITS; - bs = BLUESHIFT; - - if (pwdc->db_flag) { - - /* Need to make two palettes: one for the screen DC and one for the DIB. */ - pPal->palNumEntries = pwdc->nColors; - for (i = 0; i < pwdc->nColors; i++) { - pPal->palPalEntry[i].peRed = componentFromIndex( i, rb, rs ); - pPal->palPalEntry[i].peGreen = componentFromIndex( i, gb, gs ); - pPal->palPalEntry[i].peBlue = componentFromIndex( i, bb, bs ); - pPal->palPalEntry[i].peFlags = 0; - } - pwdc->hGLPalette = CreatePalette( pPal ); - pwdc->hPalette = CreatePalette( pPal ); - } - - else { - pPal->palNumEntries = pwdc->nColors; - for (i = 0; i < pwdc->nColors; i++) { - pPal->palPalEntry[i].peRed = componentFromIndex( i, rb, rs ); - pPal->palPalEntry[i].peGreen = componentFromIndex( i, gb, gs ); - pPal->palPalEntry[i].peBlue = componentFromIndex( i, bb, bs ); - pPal->palPalEntry[i].peFlags = 0; - } - pwdc->hGLPalette = CreatePalette( pPal ); - } - - free(pPal); - -} - -//--------------------------------------------------------------------------- - -/* This function sets the color table of a DIB section - * to match that of the destination DC - */ -BOOL wmSetDibColors(PWMC pwc) -{ - RGBQUAD *pColTab, *pRGB; - PALETTEENTRY *pPal, *pPE; - int i, nColors; - BOOL bRet=TRUE; - DWORD dwErr=0; - - /* Build a color table in the DIB that maps to the - * selected palette in the DC. - */ - nColors = 1 << pwc->cColorBits; - pPal = (PALETTEENTRY *)malloc( nColors * sizeof(PALETTEENTRY)); - memset( pPal, 0, nColors * sizeof(PALETTEENTRY) ); - GetPaletteEntries( pwc->hGLPalette, 0, nColors, pPal ); - pColTab = (RGBQUAD *)malloc( nColors * sizeof(RGBQUAD)); - for (i = 0, pRGB = pColTab, pPE = pPal; i < nColors; i++, pRGB++, pPE++) { - pRGB->rgbRed = pPE->peRed; - pRGB->rgbGreen = pPE->peGreen; - pRGB->rgbBlue = pPE->peBlue; - } - if(pwc->db_flag) - bRet = SetDIBColorTable(pwc->dib.hDC, 0, nColors, pColTab ); - - if(!bRet) - dwErr = GetLastError(); - - free( pColTab ); - free( pPal ); - - return bRet; -} - -//--------------------------------------------------------------------------- - -static void wmSetPixelFormat( PWMC wc, HDC hDC) -{ - if(wc->rgb_flag) - wc->cColorBits = GetDeviceCaps(hDC, BITSPIXEL); - else - wc->cColorBits = 8; - switch(wc->cColorBits){ - case 8: - if(wc->dither_flag != GL_TRUE) - wc->pixelformat = PF_INDEX8; - else - wc->pixelformat = PF_DITHER8; - break; - case 16: - wc->pixelformat = PF_5R6G5B; - break; - case 32: - wc->pixelformat = PF_8R8G8B; - break; - default: - wc->pixelformat = PF_BADFORMAT; - } -} - -//--------------------------------------------------------------------------- - -/* - * This function creates the DIB section that is used for combined - * GL and GDI calls - */ -BOOL wmCreateBackingStore(PWMC pwc, long lxSize, long lySize) -{ - HDC hdc = pwc->hDC; - LPBITMAPINFO pbmi = &(pwc->bmi); - int iUsage; - - pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - pbmi->bmiHeader.biWidth = lxSize; - pbmi->bmiHeader.biHeight= -lySize; - pbmi->bmiHeader.biPlanes = 1; - if(pwc->rgb_flag) - pbmi->bmiHeader.biBitCount = GetDeviceCaps(pwc->hDC, BITSPIXEL); - else - pbmi->bmiHeader.biBitCount = 8; - pbmi->bmiHeader.biCompression = BI_RGB; - pbmi->bmiHeader.biSizeImage = 0; - pbmi->bmiHeader.biXPelsPerMeter = 0; - pbmi->bmiHeader.biYPelsPerMeter = 0; - pbmi->bmiHeader.biClrUsed = 0; - pbmi->bmiHeader.biClrImportant = 0; - - iUsage = (pbmi->bmiHeader.biBitCount <= 8) ? DIB_PAL_COLORS : DIB_RGB_COLORS; - - pwc->cColorBits = pbmi->bmiHeader.biBitCount; - pwc->ScanWidth = pwc->pitch = lxSize; - pwc->width = lxSize; - pwc->height = lySize; - - wmCreateDIBSection(hdc, pwc, pbmi, iUsage); - - if ((iUsage == DIB_PAL_COLORS) && !(pwc->hGLPalette)) { - wmCreatePalette( pwc ); - wmSetDibColors( pwc ); - } - wmSetPixelFormat(pwc, pwc->hDC); - return TRUE; -} - -//--------------------------------------------------------------------------- - -/* - * Free up the dib section that was created - */ -BOOL wmDeleteBackingStore(PWMC pwc) -{ - SelectObject(pwc->dib.hDC, pwc->hOldBitmap); - DeleteDC(pwc->dib.hDC); - DeleteObject(pwc->hbmDIB); - UnmapViewOfFile(pwc->dib.base); - CloseHandle(pwc->dib.hFileMap); - return TRUE; -} - -//--------------------------------------------------------------------------- - -/* - * Blit memory DC to screen DC - */ -BOOL wmFlush(PWMC pwc, HDC hDC) -{ - BOOL bRet = 0; - DWORD dwErr = 0; - -// Now using bEmulateSingleBuffer in the calling function. KeithH - -// if(pwc->db_flag){ - bRet = BitBlt(hDC, 0, 0, pwc->width, pwc->height, - pwc->dib.hDC, 0, 0, SRCCOPY); -// } - - return bRet; - -} - -//--------------------------------------------------------------------------- -// Support Functions -//--------------------------------------------------------------------------- - -static void flush(GLcontext* ctx) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); -/* - if((Current->rgb_flag &&!(Current->db_flag)) - ||(!Current->rgb_flag)) - { - wmFlush(Current, Current->hDC); - } -*/ - // Only flush if we're not in double-buffer mode. KeithH - // The demo fractal.c calls glutSwapBuffers() then glFlush()! - if (Current->bEmulateSingleBuffer) { - wmFlush(Current, Current->hDC); - } -} - - -//--------------------------------------------------------------------------- - - -/* - * Set the color index used to clear the color buffer. - */ -static void clear_index(GLcontext* ctx, GLuint index) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); - Current->clearpixel = index; -} - - - -//--------------------------------------------------------------------------- - -/* - * Set the color used to clear the color buffer. - */ -//static void clear_color( GLcontext* ctx, const GLchan color[4] ) -// Changed for Mesa 5.x. KeithH -static void clear_color( - GLcontext* ctx, - const GLfloat color[4]) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); - GLubyte col[4]; - CLAMPED_FLOAT_TO_UBYTE(col[0], color[0]); - CLAMPED_FLOAT_TO_UBYTE(col[1], color[1]); - CLAMPED_FLOAT_TO_UBYTE(col[2], color[2]); - Current->clearpixel = RGB(col[0], col[1], col[2]); -} - - -//--------------------------------------------------------------------------- - - -/* - * Clear the specified region of the color buffer using the clear color - * or index as specified by one of the two functions above. - * - * This procedure clears either the front and/or the back COLOR buffers. - * Only the "left" buffer is cleared since we are not stereo. - * Clearing of the other non-color buffers is left to the swrast. - * We also only clear the color buffers if the color masks are all 1's. - * Otherwise, we let swrast do it. - */ - -static clear(GLcontext* ctx, GLbitfield mask, - GLboolean all, GLint x, GLint y, GLint width, GLint height) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); - DWORD dwColor; - WORD wColor; - BYTE bColor; - LPDWORD lpdw = (LPDWORD)Current->pbPixels; - LPWORD lpw = (LPWORD)Current->pbPixels; - LPBYTE lpb = Current->pbPixels; - int lines; - const GLuint *colorMask = (GLuint *) &ctx->Color.ColorMask; - - if (all){ - x=y=0; - width=Current->width; - height=Current->height; - } - - - /* sanity check - can't have right(stereo) buffers */ - assert((mask & (DD_FRONT_RIGHT_BIT | DD_BACK_RIGHT_BIT)) == 0); - - /* clear alpha */ - if ((mask & (DD_FRONT_LEFT_BIT | DD_BACK_RIGHT_BIT)) && - ctx->DrawBuffer->UseSoftwareAlphaBuffers && - ctx->Color.ColorMask[ACOMP]) { - _swrast_clear_alpha_buffers( ctx ); - } - - if (*colorMask == 0xffffffff && ctx->Color.IndexMask == 0xffffffff) { - if (mask & DD_BACK_LEFT_BIT) { - /* Double-buffering - clear back buffer */ - UINT nBypp = Current->cColorBits / 8; - int i = 0; - int iSize = 0; - - assert(Current->db_flag==GL_TRUE); /* we'd better be double buffer */ - if(nBypp ==1 ){ - iSize = Current->width/4; - bColor = BGR8(GetRValue(Current->clearpixel), - GetGValue(Current->clearpixel), - GetBValue(Current->clearpixel)); - wColor = MAKEWORD(bColor,bColor); - dwColor = MAKELONG(wColor, wColor); - } - if(nBypp == 2){ - iSize = Current->width / 2; - wColor = BGR16(GetRValue(Current->clearpixel), - GetGValue(Current->clearpixel), - GetBValue(Current->clearpixel)); - dwColor = MAKELONG(wColor, wColor); - } - else if(nBypp == 4){ - iSize = Current->width; - dwColor = BGR32(GetRValue(Current->clearpixel), - GetGValue(Current->clearpixel), - GetBValue(Current->clearpixel)); - } - - /* clear a line */ - while(i < iSize){ - *lpdw = dwColor; - lpdw++; - i++; - } - - /* This is the 24bit case */ - if (nBypp == 3) { - iSize = Current->width *3/4; - dwColor = BGR24(GetRValue(Current->clearpixel), - GetGValue(Current->clearpixel), - GetBValue(Current->clearpixel)); - while(i < iSize){ - *lpdw = dwColor; - lpb += nBypp; - lpdw = (LPDWORD)lpb; - i++; - } - } - - i = 0; - if (stereo_flag) - lines = height /2; - else - lines = height; - /* copy cleared line to other lines in buffer */ - do { - memcpy(lpb, Current->pbPixels, iSize*4); - lpb += Current->ScanWidth; - i++; - } - while (i<lines-1); - mask &= ~DD_BACK_LEFT_BIT; - } /* double-buffer */ - - if (mask & DD_FRONT_LEFT_BIT) { - /* single-buffer */ - HDC DC=DD_GETDC; - HPEN Pen=CreatePen(PS_SOLID,1,Current->clearpixel); - HBRUSH Brush=CreateSolidBrush(Current->clearpixel); - HPEN Old_Pen=SelectObject(DC,Pen); - HBRUSH Old_Brush=SelectObject(DC,Brush); - Rectangle(DC,x,y,x+width,y+height); - SelectObject(DC,Old_Pen); - SelectObject(DC,Old_Brush); - DeleteObject(Pen); - DeleteObject(Brush); - DD_RELEASEDC; - mask &= ~DD_FRONT_LEFT_BIT; - } /* single-buffer */ - } /* if masks are all 1's */ - - /* Call swrast if there is anything left to clear (like DEPTH) */ - if (mask) - _swrast_Clear( ctx, mask, all, x, y, width, height ); -} - - -//--------------------------------------------------------------------------- - - -static void enable( GLcontext* ctx, GLenum pname, GLboolean enable ) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); - - if (!Current) - return; - - if (pname == GL_DITHER) { - if(enable == GL_FALSE){ - Current->dither_flag = GL_FALSE; - if(Current->cColorBits == 8) - Current->pixelformat = PF_INDEX8; - } - else{ - if (Current->rgb_flag && Current->cColorBits == 8){ - Current->pixelformat = PF_DITHER8; - Current->dither_flag = GL_TRUE; - } - else - Current->dither_flag = GL_FALSE; - } - } -} - -//--------------------------------------------------------------------------- - -static GLboolean set_draw_buffer( GLcontext* ctx, GLenum mode ) -{ - /* TODO: this could be better */ - if (mode==GL_FRONT_LEFT || mode==GL_BACK_LEFT) { - return GL_TRUE; - } - else { - return GL_FALSE; - } -} - -//--------------------------------------------------------------------------- - - -static void set_read_buffer(GLcontext *ctx, GLframebuffer *colorBuffer, - GLenum buffer ) -{ - /* XXX todo */ - return; -} - - -//--------------------------------------------------------------------------- - - -/* Return characteristics of the output buffer. */ -//static void buffer_size( GLcontext* ctx, GLuint *width, GLuint *height ) -// Altered for Mesa 5.x. KeithH -static void buffer_size( - GLframebuffer *buffer, - GLuint *width, - GLuint *height) -{ - // For some reason the context is not passed into this function. - // Therefore we have to explicitly retrieve it. - GET_CURRENT_CONTEXT(ctx); - - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); - int New_Size; - RECT CR; - - GetClientRect(Current->Window,&CR); - - *width=CR.right; - *height=CR.bottom; - - New_Size=((*width)!=Current->width) || ((*height)!=Current->height); - - if (New_Size){ - Current->width=*width; - Current->height=*height; - Current->ScanWidth=Current->width; - if ((Current->ScanWidth%sizeof(long))!=0) - Current->ScanWidth+=(sizeof(long)-(Current->ScanWidth%sizeof(long))); - - if (Current->db_flag){ - if (Current->rgb_flag==GL_TRUE && Current->dither_flag!=GL_TRUE){ - wmDeleteBackingStore(Current); - wmCreateBackingStore(Current, Current->width, Current->height); - } - } - - } -} - - - -/**********************************************************************/ -/***** Accelerated point, line, polygon rendering *****/ -/**********************************************************************/ - -/* Accelerated routines are not implemented in 4.0. See OSMesa for ideas. */ - -static void fast_rgb_points( GLcontext* ctx, GLuint first, GLuint last ) -{ -} - -//--------------------------------------------------------------------------- - -/* Return pointer to accelerated points function */ -extern tnl_points_func choose_points_function( GLcontext* ctx ) -{ - return NULL; -} - -//--------------------------------------------------------------------------- - -static void fast_flat_rgb_line( GLcontext* ctx, GLuint v0, - GLuint v1, GLuint pv ) -{ -} - -//--------------------------------------------------------------------------- - -static tnl_line_func choose_line_function( GLcontext* ctx ) -{ -} - - -/**********************************************************************/ -/***** Span-based pixel drawing *****/ -/**********************************************************************/ - - -/* Write a horizontal span of 32-bit color-index pixels with a boolean mask. */ -static void write_ci32_span( const GLcontext* ctx, - GLuint n, GLint x, GLint y, - const GLuint index[], - const GLubyte mask[] ) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); - GLuint i; - PBYTE Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x; - assert(Current->rgb_flag==GL_FALSE); - for (i=0; i<n; i++) - if (mask[i]) - Mem[i]=index[i]; -} - - -//--------------------------------------------------------------------------- - -/* Write a horizontal span of 8-bit color-index pixels with a boolean mask. */ -static void write_ci8_span( const GLcontext* ctx, - GLuint n, GLint x, GLint y, - const GLubyte index[], - const GLubyte mask[] ) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); - GLuint i; - PBYTE Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x; - assert(Current->rgb_flag==GL_FALSE); - for (i=0; i<n; i++) - if (mask[i]) - Mem[i]=index[i]; -} - - -//--------------------------------------------------------------------------- - - -/* - * Write a horizontal span of pixels with a boolean mask. The current - * color index is used for all pixels. - */ -static void write_mono_ci_span(const GLcontext* ctx, - GLuint n,GLint x,GLint y, - GLuint colorIndex, const GLubyte mask[]) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); - GLuint i; - BYTE *Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x; - assert(Current->rgb_flag==GL_FALSE); - for (i=0; i<n; i++) - if (mask[i]) - Mem[i]=colorIndex; -} - -//--------------------------------------------------------------------------- - -/* - * To improve the performance of this routine, frob the data into an actual - * scanline and call bitblt on the complete scan line instead of SetPixel. - */ - -/* Write a horizontal span of RGBA color pixels with a boolean mask. */ -static void write_rgba_span( const GLcontext* ctx, GLuint n, GLint x, GLint y, - const GLubyte rgba[][4], const GLubyte mask[] ) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); - PWMC pwc = Current; - - if (pwc->rgb_flag==GL_TRUE) - { - GLuint i; - HDC DC=DD_GETDC; - y=FLIP(y); - if (mask) { - for (i=0; i<n; i++) - if (mask[i]) - wmSetPixel(pwc, y, x + i, - rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]); - } - else { - for (i=0; i<n; i++) - wmSetPixel(pwc, y, x + i, - rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ); - } - DD_RELEASEDC; - } - else - { - GLuint i; - BYTE *Mem=Current->ScreenMem+y*Current->ScanWidth+x; - y = FLIP(y); - if (mask) { - for (i=0; i<n; i++) - if (mask[i]) - Mem[i] = GetNearestPaletteIndex(Current->hPal, - RGB(rgba[i][RCOMP], - rgba[i][GCOMP], - rgba[i][BCOMP])); - } - else { - for (i=0; i<n; i++) - Mem[i] = GetNearestPaletteIndex(Current->hPal, - RGB(rgba[i][RCOMP], - rgba[i][GCOMP], - rgba[i][BCOMP])); - } - } -} - -//--------------------------------------------------------------------------- - -/* Write a horizontal span of RGB color pixels with a boolean mask. */ -static void write_rgb_span( const GLcontext* ctx, - GLuint n, GLint x, GLint y, - const GLubyte rgb[][3], const GLubyte mask[] ) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); - PWMC pwc = Current; - - if (pwc->rgb_flag==GL_TRUE) - { - GLuint i; - HDC DC=DD_GETDC; - y=FLIP(y); - if (mask) { - for (i=0; i<n; i++) - if (mask[i]) - wmSetPixel(pwc, y, x + i, - rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]); - } - else { - for (i=0; i<n; i++) - wmSetPixel(pwc, y, x + i, - rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ); - } - DD_RELEASEDC; - } - else - { - GLuint i; - BYTE *Mem=Current->ScreenMem+y*Current->ScanWidth+x; - y = FLIP(y); - if (mask) { - for (i=0; i<n; i++) - if (mask[i]) - Mem[i] = GetNearestPaletteIndex(Current->hPal, - RGB(rgb[i][RCOMP], - rgb[i][GCOMP], - rgb[i][BCOMP])); - } - else { - for (i=0; i<n; i++) - Mem[i] = GetNearestPaletteIndex(Current->hPal, - RGB(rgb[i][RCOMP], - rgb[i][GCOMP], - rgb[i][BCOMP])); - } - } -} - -//--------------------------------------------------------------------------- - -/* - * Write a horizontal span of pixels with a boolean mask. The current color - * is used for all pixels. - */ -static void write_mono_rgba_span( const GLcontext* ctx, - GLuint n, GLint x, GLint y, - const GLchan color[4], const GLubyte mask[]) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); - ULONG pixel = RGB( color[RCOMP], color[GCOMP], color[BCOMP] ); - GLuint i; - HDC DC=DD_GETDC; - PWMC pwc = Current; - assert(Current->rgb_flag==GL_TRUE); - y=FLIP(y); - if(Current->rgb_flag==GL_TRUE){ - for (i=0; i<n; i++) - if (mask[i]) - wmSetPixel(pwc,y,x+i,color[RCOMP], color[GCOMP], color[BCOMP]); - } - else { - for (i=0; i<n; i++) - if (mask[i]) - SetPixel(DC, y, x+i, pixel); - } - DD_RELEASEDC; -} - - - -/**********************************************************************/ -/***** Array-based pixel drawing *****/ -/**********************************************************************/ - - -/* Write an array of 32-bit index pixels with a boolean mask. */ -static void write_ci32_pixels( const GLcontext* ctx, - GLuint n, const GLint x[], const GLint y[], - const GLuint index[], const GLubyte mask[] ) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); - GLuint i; - assert(Current->rgb_flag==GL_FALSE); - for (i=0; i<n; i++) { - if (mask[i]) { - BYTE *Mem=Current->ScreenMem+FLIP(y[i])*Current->ScanWidth+x[i]; - *Mem = index[i]; - } - } -} - - -//--------------------------------------------------------------------------- - - -/* - * Write an array of pixels with a boolean mask. The current color - * index is used for all pixels. - */ -static void write_mono_ci_pixels( const GLcontext* ctx, - GLuint n, - const GLint x[], const GLint y[], - GLuint colorIndex, const GLubyte mask[] ) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); - GLuint i; - assert(Current->rgb_flag==GL_FALSE); - for (i=0; i<n; i++) { - if (mask[i]) { - BYTE *Mem=Current->ScreenMem+FLIP(y[i])*Current->ScanWidth+x[i]; - *Mem = colorIndex; - } - } -} - - -//--------------------------------------------------------------------------- - - -/* Write an array of RGBA pixels with a boolean mask. */ -static void write_rgba_pixels( const GLcontext* ctx, - GLuint n, const GLint x[], const GLint y[], - const GLubyte rgba[][4], const GLubyte mask[] ) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); - GLuint i; - PWMC pwc = Current; - HDC DC=DD_GETDC; - assert(Current->rgb_flag==GL_TRUE); - for (i=0; i<n; i++) - if (mask[i]) - wmSetPixel(pwc, FLIP(y[i]), x[i], - rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]); - DD_RELEASEDC; -} - - -//--------------------------------------------------------------------------- - - -/* - * Write an array of pixels with a boolean mask. The current color - * is used for all pixels. - */ -static void write_mono_rgba_pixels( const GLcontext* ctx, - GLuint n, - const GLint x[], const GLint y[], - const GLchan color[4], - const GLubyte mask[] ) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); - GLuint i; - PWMC pwc = Current; - HDC DC=DD_GETDC; - assert(Current->rgb_flag==GL_TRUE); - for (i=0; i<n; i++) - if (mask[i]) - wmSetPixel(pwc, FLIP(y[i]),x[i],color[RCOMP], - color[GCOMP], color[BCOMP]); - DD_RELEASEDC; -} - -/**********************************************************************/ -/***** Read spans/arrays of pixels *****/ -/**********************************************************************/ - -/* Read a horizontal span of color-index pixels. */ -static void read_ci32_span( const GLcontext* ctx, GLuint n, GLint x, GLint y, - GLuint index[]) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); - GLuint i; - BYTE *Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x; - assert(Current->rgb_flag==GL_FALSE); - for (i=0; i<n; i++) - index[i]=Mem[i]; -} - -//--------------------------------------------------------------------------- - -/* Read an array of color index pixels. */ -static void read_ci32_pixels( const GLcontext* ctx, - GLuint n, const GLint x[], const GLint y[], - GLuint indx[], const GLubyte mask[] ) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); - GLuint i; - assert(Current->rgb_flag==GL_FALSE); - for (i=0; i<n; i++) { - if (mask[i]) { - indx[i]=*(Current->ScreenMem+FLIP(y[i])*Current->ScanWidth+x[i]); - } - } -} - -//--------------------------------------------------------------------------- - -/* Read a horizontal span of color pixels. */ -static void read_rgba_span( const GLcontext* ctx, - GLuint n, GLint x, GLint y, - GLubyte rgba[][4] ) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); - UINT i; - COLORREF Color; - HDC DC=DD_GETDC; - assert(Current->rgb_flag==GL_TRUE); - y = Current->height - y - 1; - for (i=0; i<n; i++) { - Color=GetPixel(DC,x+i,y); - rgba[i][RCOMP] = GetRValue(Color); - rgba[i][GCOMP] = GetGValue(Color); - rgba[i][BCOMP] = GetBValue(Color); - rgba[i][ACOMP] = 255; - } - DD_RELEASEDC; -} - -//--------------------------------------------------------------------------- - -/* Read an array of color pixels. */ -static void read_rgba_pixels( const GLcontext* ctx, - GLuint n, const GLint x[], const GLint y[], - GLubyte rgba[][4], const GLubyte mask[] ) -{ - GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); - WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); - GLuint i; - COLORREF Color; - HDC DC=DD_GETDC; - assert(Current->rgb_flag==GL_TRUE); - for (i=0; i<n; i++) { - if (mask[i]) { - GLint y2 = Current->height - y[i] - 1; - Color=GetPixel(DC,x[i],y2); - rgba[i][RCOMP] = GetRValue(Color); - rgba[i][GCOMP] = GetGValue(Color); - rgba[i][BCOMP] = GetBValue(Color); - rgba[i][ACOMP] = 255; - } - } - DD_RELEASEDC; -} - -//--------------------------------------------------------------------------- - -static void wmesa_update_state( - GLcontext *ctx, - GLuint new_state) -{ - _swrast_InvalidateState( ctx, new_state ); - _swsetup_InvalidateState( ctx, new_state ); - _vbo_InvalidateState( ctx, new_state ); - _tnl_InvalidateState( ctx, new_state ); -} - -//--------------------------------------------------------------------------- - -static void wmesa_viewport( - GLcontext *ctx, - GLint x, - GLint y, - GLsizei w, - GLsizei h) -{ -// ctx->Driver.ResizeBuffersMESA(ctx); -} - -//--------------------------------------------------------------------------- - -static void wmesa_update_state_first_time( - GLcontext *ctx, - GLuint new_state) -{ - struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference( ctx ); - TNLcontext *tnl = TNL_CONTEXT(ctx); - - _mesa_init_driver_functions(&ctx->Driver); - - /* - * XXX these function pointers could be initialized just once during - * context creation since they don't depend on any state changes. - * kws - This is true - this function gets called a lot and it - * would be good to minimize setting all this when not needed. - */ - // Good idea, so I'll do it. KeithH. :-) - - ctx->Driver.GetString = _gldGetStringGeneric; - ctx->Driver.UpdateState = wmesa_update_state; - ctx->Driver.DrawBuffer = set_draw_buffer; - ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; - ctx->Driver.GetBufferSize = buffer_size; - - ctx->Driver.Viewport = wmesa_viewport; - - ctx->Driver.Clear = clear; - - ctx->Driver.Flush = flush; - ctx->Driver.ClearIndex = clear_index; - ctx->Driver.ClearColor = clear_color; - ctx->Driver.Enable = enable; - - - // Does not apply for Mesa 5.x - //ctx->Driver.BaseCompressedTexFormat = _mesa_base_compressed_texformat; - //ctx->Driver.CompressedTextureSize = _mesa_compressed_texture_size; - //ctx->Driver.GetCompressedTexImage = _mesa_get_compressed_teximage; - - swdd->SetBuffer = set_read_buffer; - - - /* Pixel/span writing functions: */ - swdd->WriteRGBASpan = write_rgba_span; - swdd->WriteRGBSpan = write_rgb_span; - swdd->WriteMonoRGBASpan = write_mono_rgba_span; - swdd->WriteRGBAPixels = write_rgba_pixels; - swdd->WriteMonoRGBAPixels = write_mono_rgba_pixels; - swdd->WriteCI32Span = write_ci32_span; - swdd->WriteCI8Span = write_ci8_span; - swdd->WriteMonoCISpan = write_mono_ci_span; - swdd->WriteCI32Pixels = write_ci32_pixels; - swdd->WriteMonoCIPixels = write_mono_ci_pixels; - - swdd->ReadCI32Span = read_ci32_span; - swdd->ReadRGBASpan = read_rgba_span; - swdd->ReadCI32Pixels = read_ci32_pixels; - swdd->ReadRGBAPixels = read_rgba_pixels; - - - tnl->Driver.RunPipeline = _tnl_run_pipeline; - - wmesa_update_state(ctx, new_state); -} - -//--------------------------------------------------------------------------- -// Driver interface functions -//--------------------------------------------------------------------------- - -BOOL gldCreateDrawable_MesaSW( - DGL_ctx *pCtx, - BOOL bPersistantInterface, - BOOL bPersistantBuffers) -{ - WMesaContext *c; - GLboolean true_color_flag; - GLboolean rgb_flag = GL_TRUE; - GLboolean db_flag = GL_TRUE; - - if (pCtx == NULL) - return FALSE; - - c = (struct wmesa_context * ) calloc(1,sizeof(struct wmesa_context)); - if (!c) - return FALSE; - - pCtx->glPriv = c; - - c->hDC = pCtx->hDC; - c->Window = pCtx->hWnd; - - true_color_flag = GetDeviceCaps(pCtx->hDC, BITSPIXEL) > 8; - - -#ifdef DITHER - if ((true_color_flag==GL_FALSE) && (rgb_flag == GL_TRUE)){ - c->dither_flag = GL_TRUE; - c->hPalHalfTone = WinGCreateHalftonePalette(); - } - else - c->dither_flag = GL_FALSE; -#else - c->dither_flag = GL_FALSE; -#endif - - - if (rgb_flag==GL_FALSE) - { - c->rgb_flag = GL_FALSE; -#if 0 - /* Old WinG stuff???? */ - c->db_flag = db_flag =GL_TRUE; /* WinG requires double buffering */ - printf("Single buffer is not supported in color index mode, ", - "setting to double buffer.\n"); -#endif - } - else - { - c->rgb_flag = GL_TRUE; - } - -// db_flag = pCtx->lpPF->pfd.dwFlags & PFD_DOUBLEBUFFER ? GL_TRUE : GL_FALSE; - db_flag = GL_TRUE; // Force double-buffer - if (db_flag) { - c->db_flag = 1; - /* Double buffered */ - { - wmCreateBackingStore(c, pCtx->dwWidth, pCtx->dwHeight); - - } - } else { - /* Single Buffered */ - if (c->rgb_flag) - c->db_flag = 0; - } - - c->bEmulateSingleBuffer = (pCtx->lpPF->pfd.dwFlags & PFD_DOUBLEBUFFER) - ? FALSE : TRUE; - - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldResizeDrawable_MesaSW( - DGL_ctx *ctx, - BOOL bDefaultDriver, - BOOL bPersistantInterface, - BOOL bPersistantBuffers) -{ - WMesaContext *c; - - if (ctx == NULL) - return FALSE; - - c = ctx->glPriv; - if (c == NULL) - return FALSE; - - c->hDC = ctx->hDC; - c->Window = ctx->hWnd; -// c->width = ctx->dwWidth; -// c->height = ctx->dwHeight; - - if (c->db_flag) { - wmDeleteBackingStore(c); - wmCreateBackingStore(c, ctx->dwWidth, ctx->dwHeight); - } - - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldDestroyDrawable_MesaSW( - DGL_ctx *ctx) -{ - WMesaContext *c; - - if (ctx == NULL) - return FALSE; - - c = ctx->glPriv; - if (c == NULL) - return FALSE; - - if (c->hPalHalfTone != NULL) - DeleteObject(c->hPalHalfTone); - - if (c->db_flag) - wmDeleteBackingStore(c); - - free(c); - - ctx->glPriv = NULL; - - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldCreatePrivateGlobals_MesaSW(void) -{ - // Mesa Software driver needs no private globals - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldDestroyPrivateGlobals_MesaSW(void) -{ - // Mesa Software driver needs no private globals - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldBuildPixelformatList_MesaSW(void) -{ - // Release any existing pixelformat list - if (glb.lpPF) { - free(glb.lpPF); - } - - glb.nPixelFormatCount = 0; - glb.lpPF = NULL; - - glb.lpPF = (DGL_pixelFormat *)calloc(2, sizeof(DGL_pixelFormat)); - if (glb.lpPF == NULL) - return FALSE; - // Single-buffered - memcpy(&glb.lpPF[0], &pfTemplateMesaSW, sizeof(DGL_pixelFormat)); - glb.lpPF[0].pfd.dwFlags &= ~PFD_DOUBLEBUFFER; // Remove doublebuffer flag - // Double-buffered - memcpy(&glb.lpPF[1], &pfTemplateMesaSW, sizeof(DGL_pixelFormat)); - glb.nPixelFormatCount = 2; - - // Mark list as 'current' - glb.bPixelformatsDirty = FALSE; - - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldInitialiseMesa_MesaSW( - DGL_ctx *gld) -{ - GLcontext *ctx; - - if (gld == NULL) - return FALSE; - - ctx = gld->glCtx; - - // Set max texture size to 256 - ctx->Const.MaxTextureLevels = 8; - - // Multitexture enable/disable - ctx->Const.MaxTextureUnits = (glb.bMultitexture) ? MAX_TEXTURE_UNITS : 1; - - /* Initialize the software rasterizer and helper modules.*/ - - // Added this to force max texture diminsion to 256. KeithH - ctx->Const.MaxTextureLevels = 8; - ctx->Const.MaxDrawBuffers = 1; - - _mesa_enable_sw_extensions(ctx); - _mesa_enable_imaging_extensions(ctx); - _mesa_enable_1_3_extensions(ctx); - -// _swrast_CreateContext( ctx ); -// _vbo_CreateContext( ctx ); -// _tnl_CreateContext( ctx ); -// _swsetup_CreateContext( ctx ); - - _swsetup_Wakeup( ctx ); - - wmesa_update_state_first_time(ctx, ~0); - - return TRUE; -} - -//--------------------------------------------------------------------------- - -BOOL gldSwapBuffers_MesaSW( - DGL_ctx *ctx, - HDC hDC, - HWND hWnd) -{ - WMesaContext *c; - - if (ctx == NULL) - return FALSE; - - c = ctx->glPriv; - if (c == NULL) - return FALSE; - - /* If we're swapping the buffer associated with the current context - * we have to flush any pending rendering commands first. - */ - - // Altered to respect bEmulateSingleBuffer. KeithH -// if (c->db_flag) - if (!c->bEmulateSingleBuffer) - wmFlush(c, hDC); - - return TRUE; -} - -//--------------------------------------------------------------------------- - -PROC gldGetProcAddress_MesaSW( - LPCSTR a) -{ - int i; - PROC proc = NULL; - - for (i=0; GLD_extList[i].proc; i++) { - if (!strcmp(a, GLD_extList[i].name)) { - proc = GLD_extList[i].proc; - break; - } - } - - gldLogPrintf(GLDLOG_INFO, "GetProcAddress: %s (%s)", a, proc ? "OK" : "Failed"); - - return proc; -} - -//--------------------------------------------------------------------------- - -BOOL gldGetDisplayMode_MesaSW( - DGL_ctx *ctx, - GLD_displayMode *glddm) -{ - HDC hdcDesktop; - - if (glddm == NULL) - return FALSE; - - // - // A bit hacky... KeithH - // - - hdcDesktop = GetDC(NULL); - glddm->Width = GetDeviceCaps(hdcDesktop, HORZRES); - glddm->Height = GetDeviceCaps(hdcDesktop, VERTRES); - glddm->BPP = GetDeviceCaps(hdcDesktop, BITSPIXEL); - glddm->Refresh = 0; - ReleaseDC(0, hdcDesktop); - - return TRUE; -} - -//--------------------------------------------------------------------------- - |