diff options
Diffstat (limited to 'src/mesa/drivers')
148 files changed, 0 insertions, 67815 deletions
diff --git a/src/mesa/drivers/allegro/amesa.c b/src/mesa/drivers/allegro/amesa.c deleted file mode 100644 index cb46efa56ac..00000000000 --- a/src/mesa/drivers/allegro/amesa.c +++ /dev/null @@ -1,404 +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 "buffers.h"
-#include "context.h"
-#include "imports.h"
-#include "matrix.h"
-#include "mtypes.h" -#include "GL/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;
- }
-
-
-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 */
- _mesa_ResizeBuffersMESA();
-}
-
-
-/**********************************************************************/
-/**********************************************************************/
-
-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_destroy_framebuffer(buffer->GLBuffer);
- 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/direct.h b/src/mesa/drivers/allegro/direct.h deleted file mode 100644 index 3998fc19d7b..00000000000 --- 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 cbdf5ff2b3a..00000000000 --- 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 cd95ef0f1ee..00000000000 --- 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 5295520d7be..00000000000 --- 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 ba7891612e4..00000000000 --- 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 074ceca816a..00000000000 --- 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 004bb773603..00000000000 --- 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 cc629e21111..00000000000 --- 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 e6ff8645611..00000000000 --- 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 ac9d2621fcc..00000000000 --- 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 f4a4154917a..00000000000 --- 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 c13d89cd711..00000000000 --- 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 09857f1dc8d..00000000000 --- 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 a02a89debbb..00000000000 --- 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 dfa524bf314..00000000000 --- 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 76122b91210..00000000000 --- 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 40858e66844..00000000000 --- 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 ad1d40dc27b..00000000000 --- 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 f0bbd2162dd..00000000000 --- 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 d6fb598074b..00000000000 --- 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 b32bd1fef81..00000000000 --- 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 e3b95e1de72..00000000000 --- 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 9ff0650518b..00000000000 --- 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/xmlpool/Makefile b/src/mesa/drivers/dri/common/xmlpool/Makefile deleted file mode 100644 index ef94541c374..00000000000 --- a/src/mesa/drivers/dri/common/xmlpool/Makefile +++ /dev/null @@ -1,96 +0,0 @@ -# Convenient makefile for managing translations. - -# Prerequisites: -# - GNU gettext -# - Python - -# Adding new translations -# ----------------------- - -# To start working on a new translation edit the POS=... line -# below. If you want to add for example a french translation, add -# fr.po. - -# Then run "make po" to generate a fresh .po file from translatable -# strings in t_options.h. Now you can edit the new .po file (fr.po in -# the example above) to translate the strings. Please make sure that -# your editor encodes the file in UTF-8. - -# Updating existing translations -# ------------------------------ - -# Run "make po" to update .po files with new translatable strings from -# t_options.h. Now you can edit the .po files you're interested -# in. Please make sure that your editor encodes the file in UTF-8. - -# Updating options.h -# ------------------ - -# Finally run "make" to generate options.h from t_options.h with all -# translations. Now you can rebuild the drivers. Any common options -# used by the drivers will have option descriptions with the latest -# translations. - -# Publishing translations -# ----------------------- - -# To get your translation(s) into Mesa CVS, please send me your -# <lang>.po file. - -# More information: -# - info gettext - -# The set of supported languages. Add languages as needed. -POS=de.po es.po nl.po fr.po - -# -# Don't change anything below, unless you know what you're doing. -# -LANGS=$(POS:%.po=%) -MOS=$(POS:%.po=%/LC_MESSAGES/options.mo) -POT=xmlpool.pot - -.PHONY: all clean pot po mo - -all: options.h - -# Only intermediate files are cleaned up. options.h is not deleted because -# it's in CVS. -clean: - rm -f $(POT) *~ - rm -rf $(LANGS) - -# Default target options.h -options.h: t_options.h mo - python gen_xmlpool.py $(LANGS) > options.h - -# Update .mo files from the corresponding .po files. -mo: - @for mo in $(MOS); do \ - lang=$${mo%%/*}; \ - echo "Updating $$mo from $$lang.po."; \ - mkdir -p $${mo%/*}; \ - msgfmt -o $$mo $$lang.po; \ - done - -# Use this target to create or update .po files with new messages in -# driconf.py. -po: $(POS) - -pot: $(POT) - -# Extract message catalog from driconf.py. -$(POT): t_options.h - xgettext -L C --from-code utf-8 -o $(POT) t_options.h - -# Create or update a .po file for a specific language. -%.po: $(POT) - @if [ -f $@ ]; then \ - echo "Merging new strings from $(POT) into $@."; \ - mv $@ $@~; \ - msgmerge -o $@ $@~ $(POT); \ - else \ - echo "Initializing $@ from $(POT)."; \ - msginit -i $(POT) -o $@~ --locale=$*; \ - sed -e 's/charset=.*\\n/charset=UTF-8\\n/' $@~ > $@; \ - fi diff --git a/src/mesa/drivers/dri/common/xmlpool/gen_xmlpool.py b/src/mesa/drivers/dri/common/xmlpool/gen_xmlpool.py deleted file mode 100644 index 7398c4cd0b2..00000000000 --- a/src/mesa/drivers/dri/common/xmlpool/gen_xmlpool.py +++ /dev/null @@ -1,191 +0,0 @@ -#!/usr/bin/python - -import sys -import gettext -import re - -# List of supported languages -languages = sys.argv[1:] - -# Escape special characters in C strings -def escapeCString (s): - escapeSeqs = {'\a' : '\\a', '\b' : '\\b', '\f' : '\\f', '\n' : '\\n', - '\r' : '\\r', '\t' : '\\t', '\v' : '\\v', '\\' : '\\\\'} - # " -> '' is a hack. Quotes (") aren't possible in XML attributes. - # Better use Unicode characters for typographic quotes in option - # descriptions and translations. - i = 0 - r = '' - while i < len(s): - # Special case: escape double quote with \u201c or \u201d, depending - # on whether it's an open or close quote. This is needed because plain - # double quotes are not possible in XML attributes. - if s[i] == '"': - if i == len(s)-1 or s[i+1].isspace(): - # close quote - q = u'\u201c' - else: - # open quote - q = u'\u201d' - r = r + q - elif escapeSeqs.has_key(s[i]): - r = r + escapeSeqs[s[i]] - else: - r = r + s[i] - i = i + 1 - return r - -# Expand escape sequences in C strings (needed for gettext lookup) -def expandCString (s): - escapeSeqs = {'a' : '\a', 'b' : '\b', 'f' : '\f', 'n' : '\n', - 'r' : '\r', 't' : '\t', 'v' : '\v', - '"' : '"', '\\' : '\\'} - i = 0 - escape = False - hexa = False - octa = False - num = 0 - digits = 0 - r = '' - while i < len(s): - if not escape: - if s[i] == '\\': - escape = True - else: - r = r + s[i] - elif hexa: - if (s[i] >= '0' and s[i] <= '9') or \ - (s[i] >= 'a' and s[i] <= 'f') or \ - (s[i] >= 'A' and s[i] <= 'F'): - num = num * 16 + int(s[i],16) - digits = digits + 1 - else: - digits = 2 - if digits >= 2: - hexa = False - escape = False - r = r + chr(num) - elif octa: - if s[i] >= '0' and s[i] <= '7': - num = num * 8 + int(s[i],8) - digits = digits + 1 - else: - digits = 3 - if digits >= 3: - octa = False - escape = False - r = r + chr(num) - else: - if escapeSeqs.has_key(s[i]): - r = r + escapeSeqs[s[i]] - escape = False - elif s[i] >= '0' and s[i] <= '7': - octa = True - num = int(s[i],8) - if num <= 3: - digits = 1 - else: - digits = 2 - elif s[i] == 'x' or s[i] == 'X': - hexa = True - num = 0 - digits = 0 - else: - r = r + s[i] - escape = False - i = i + 1 - return r - -# Expand matches. The first match is always a DESC or DESC_BEGIN match. -# Subsequent matches are ENUM matches. -# -# DESC, DESC_BEGIN format: \1 \2=<lang> \3 \4=gettext(" \5=<text> \6=") \7 -# ENUM format: \1 \2=gettext(" \3=<text> \4=") \5 -def expandMatches (matches, translations, end=None): - assert len(matches) > 0 - nTranslations = len(translations) - i = 0 - # Expand the description+enums for all translations - for lang,trans in translations: - i = i + 1 - # Make sure that all but the last line of a simple description - # are extended with a backslash. - suffix = '' - if len(matches) == 1 and i < len(translations) and \ - not matches[0].expand (r'\7').endswith('\\'): - suffix = ' \\' - # Expand the description line. Need to use ugettext in order to allow - # non-ascii unicode chars in the original English descriptions. - text = escapeCString (trans.ugettext (unicode (expandCString ( - matches[0].expand (r'\5')), "utf-8"))).encode("utf-8") - print matches[0].expand (r'\1' + lang + r'\3"' + text + r'"\7') + suffix - # Expand any subsequent enum lines - for match in matches[1:]: - text = escapeCString (trans.ugettext (unicode (expandCString ( - match.expand (r'\3')), "utf-8"))).encode("utf-8") - print match.expand (r'\1"' + text + r'"\5') - - # Expand description end - if end: - print end, - -# Compile a list of translation classes to all supported languages. -# The first translation is always a NullTranslations. -translations = [("en", gettext.NullTranslations())] -for lang in languages: - try: - trans = gettext.translation ("options", ".", [lang]) - except IOError: - sys.stderr.write ("Warning: language '%s' not found.\n" % lang) - continue - translations.append ((lang, trans)) - -# Regular expressions: -reLibintl_h = re.compile (r'#\s*include\s*<libintl.h>') -reDESC = re.compile (r'(\s*DRI_CONF_DESC\s*\(\s*)([a-z]+)(\s*,\s*)(gettext\s*\(\s*")(.*)("\s*\))(\s*\)[ \t]*\\?)$') -reDESC_BEGIN = re.compile (r'(\s*DRI_CONF_DESC_BEGIN\s*\(\s*)([a-z]+)(\s*,\s*)(gettext\s*\(\s*")(.*)("\s*\))(\s*\)[ \t]*\\?)$') -reENUM = re.compile (r'(\s*DRI_CONF_ENUM\s*\([^,]+,\s*)(gettext\s*\(\s*")(.*)("\s*\))(\s*\)[ \t]*\\?)$') -reDESC_END = re.compile (r'\s*DRI_CONF_DESC_END') - -# Print a header -print \ -"/***********************************************************************\n" \ -" *** THIS FILE IS GENERATED AUTOMATICALLY. DON'T EDIT! ***\n" \ -" ***********************************************************************/" - -# Process the options template and generate options.h with all -# translations. -template = file ("t_options.h", "r") -descMatches = [] -for line in template: - if len(descMatches) > 0: - matchENUM = reENUM .match (line) - matchDESC_END = reDESC_END.match (line) - if matchENUM: - descMatches.append (matchENUM) - elif matchDESC_END: - expandMatches (descMatches, translations, line) - descMatches = [] - else: - sys.stderr.write ( - "Warning: unexpected line inside description dropped:\n%s\n" \ - % line) - continue - if reLibintl_h.search (line): - # Ignore (comment out) #include <libintl.h> - print "/* %s * commented out by gen_xmlpool.py */" % line - continue - matchDESC = reDESC .match (line) - matchDESC_BEGIN = reDESC_BEGIN.match (line) - if matchDESC: - assert len(descMatches) == 0 - expandMatches ([matchDESC], translations) - elif matchDESC_BEGIN: - assert len(descMatches) == 0 - descMatches = [matchDESC_BEGIN] - else: - print line, - -if len(descMatches) > 0: - sys.stderr.write ("Warning: unterminated description at end of file.\n") - expandMatches (descMatches, translations) diff --git a/src/mesa/drivers/dri/dri_client/Makefile b/src/mesa/drivers/dri/dri_client/Makefile deleted file mode 100644 index 9ab60cdaf80..00000000000 --- a/src/mesa/drivers/dri/dri_client/Makefile +++ /dev/null @@ -1,60 +0,0 @@ -# src/mesa/drivers/dri/gamma/Makefile - -TOP = ../../../../.. -include $(TOP)/configs/current - -# Get rid of this: -# -DEFINES += -DGLX_DIRECT_RENDERING - -C_SOURCES = \ - xf86drm.c \ - xf86drmHash.c \ - xf86drmRandom.c \ - xf86drmSL.c \ - - - -OBJECTS = $(C_SOURCES:.c=.o) - -INCLUDES = \ - -I$(TOP)/include \ - -I$(DRM_SOURCE_PATH)/shared-core \ - -I$(TOP)/include/GL/internal \ - -I$(TOP)/src/mesa \ - -I$(TOP)/src/mesa/main \ - -I$(TOP)/src/mesa/glapi \ - -Iimports - - -##### RULES ##### - -.c.o: - $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@ - - -##### TARGETS ##### - -default: depend dri.a - - -# Run 'make dep' to update the dependencies if you change -# what's included by any source file. -depend: $(C_SOURCES) $(ASM_SOURCES) - touch depend - $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) \ - $(C_SOURCES) $(ASM_SOURCES) - - -dri.a: $(OBJECTS) - rm -f $@ - ar rcv $@ $(OBJECTS) - ranlib $@ - -# Remove .o and backup files -clean: - -rm -f *.o */*.o *~ *.so *.a depend depend.bak - -install: - -include depend diff --git a/src/mesa/drivers/dri/dri_client/imports/xf86drm.h b/src/mesa/drivers/dri/dri_client/imports/xf86drm.h deleted file mode 100644 index d3d78eb84e8..00000000000 --- a/src/mesa/drivers/dri/dri_client/imports/xf86drm.h +++ /dev/null @@ -1,636 +0,0 @@ -/** - * \file xf86drm.h - * OS-independent header for DRM user-level library interface. - * - * \author Rickard E. (Rik) Faith <[email protected]> - */ - -/* - * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas. - * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, 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 - * 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 (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 NONINFRINGEMENT. IN NO EVENT SHALL - * PRECISION INSIGHT 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. - * - */ - -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86drm.h,v 1.26 2003/08/16 19:26:37 dawes Exp $ */ - -#ifndef _XF86DRM_H_ -#define _XF86DRM_H_ - -#include <drm.h> - - /* Defaults, if nothing set in xf86config */ -#define DRM_DEV_UID 0 -#define DRM_DEV_GID 0 -/* Default /dev/dri directory permissions 0755 */ -#define DRM_DEV_DIRMODE \ - (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) -#define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) - -#define DRM_DIR_NAME "/dev/dri" -#define DRM_DEV_NAME "%s/card%d" -#define DRM_PROC_NAME "/proc/dri/" /* For backward Linux compatibility */ - -#define DRM_ERR_NO_DEVICE (-1001) -#define DRM_ERR_NO_ACCESS (-1002) -#define DRM_ERR_NOT_ROOT (-1003) -#define DRM_ERR_INVALID (-1004) -#define DRM_ERR_NO_FD (-1005) - -#define DRM_AGP_NO_HANDLE 0 - -typedef unsigned int drmSize, *drmSizePtr; /**< For mapped regions */ -typedef void *drmAddress, **drmAddressPtr; /**< For mapped regions */ - -/** - * Driver version information. - * - * \sa drmGetVersion() and drmSetVersion(). - */ -typedef struct _drmVersion { - int version_major; /**< Major version */ - int version_minor; /**< Minor version */ - int version_patchlevel; /**< Patch level */ - int name_len; /**< Length of name buffer */ - char *name; /**< Name of driver */ - int date_len; /**< Length of date buffer */ - char *date; /**< User-space buffer to hold date */ - int desc_len; /**< Length of desc buffer */ - char *desc; /**< User-space buffer to hold desc */ -} drmVersion, *drmVersionPtr; - -typedef struct _drmStats { - unsigned long count; /**< Number of data */ - struct { - unsigned long value; /**< Value from kernel */ - const char *long_format; /**< Suggested format for long_name */ - const char *long_name; /**< Long name for value */ - const char *rate_format; /**< Suggested format for rate_name */ - const char *rate_name; /**< Short name for value per second */ - int isvalue; /**< True if value (vs. counter) */ - const char *mult_names; /**< Multiplier names (e.g., "KGM") */ - int mult; /**< Multiplier value (e.g., 1024) */ - int verbose; /**< Suggest only in verbose output */ - } data[15]; -} drmStatsT; - - - /* All of these enums *MUST* match with the - kernel implementation -- so do *NOT* - change them! (The drmlib implementation - will just copy the flags instead of - translating them.) */ -typedef enum { - DRM_FRAME_BUFFER = 0, /**< WC, no caching, no core dump */ - DRM_REGISTERS = 1, /**< no caching, no core dump */ - DRM_SHM = 2, /**< shared, cached */ - DRM_AGP = 3, /**< AGP/GART */ - DRM_SCATTER_GATHER = 4 /**< PCI scatter/gather */ -} drmMapType; - -typedef enum { - DRM_RESTRICTED = 0x0001, /**< Cannot be mapped to client-virtual */ - DRM_READ_ONLY = 0x0002, /**< Read-only in client-virtual */ - DRM_LOCKED = 0x0004, /**< Physical pages locked */ - DRM_KERNEL = 0x0008, /**< Kernel requires access */ - DRM_WRITE_COMBINING = 0x0010, /**< Use write-combining, if available */ - DRM_CONTAINS_LOCK = 0x0020, /**< SHM page that contains lock */ - DRM_REMOVABLE = 0x0040 /**< Removable mapping */ -} drmMapFlags; - -/** - * \warning These values *MUST* match drm.h - */ -typedef enum { - /** \name Flags for DMA buffer dispatch */ - /*@{*/ - DRM_DMA_BLOCK = 0x01, /**< - * Block until buffer dispatched. - * - * \note the buffer may not yet have been - * processed by the hardware -- getting a - * hardware lock with the hardware quiescent - * will ensure that the buffer has been - * processed. - */ - DRM_DMA_WHILE_LOCKED = 0x02, /**< Dispatch while lock held */ - DRM_DMA_PRIORITY = 0x04, /**< High priority dispatch */ - /*@}*/ - - /** \name Flags for DMA buffer request */ - /*@{*/ - DRM_DMA_WAIT = 0x10, /**< Wait for free buffers */ - DRM_DMA_SMALLER_OK = 0x20, /**< Smaller-than-requested buffers OK */ - DRM_DMA_LARGER_OK = 0x40 /**< Larger-than-requested buffers OK */ - /*@}*/ -} drmDMAFlags; - -typedef enum { - DRM_PAGE_ALIGN = 0x01, - DRM_AGP_BUFFER = 0x02, - DRM_SG_BUFFER = 0x04 -} drmBufDescFlags; - -typedef enum { - DRM_LOCK_READY = 0x01, /**< Wait until hardware is ready for DMA */ - DRM_LOCK_QUIESCENT = 0x02, /**< Wait until hardware quiescent */ - DRM_LOCK_FLUSH = 0x04, /**< Flush this context's DMA queue first */ - DRM_LOCK_FLUSH_ALL = 0x08, /**< Flush all DMA queues first */ - /* These *HALT* flags aren't supported yet - -- they will be used to support the - full-screen DGA-like mode. */ - DRM_HALT_ALL_QUEUES = 0x10, /**< Halt all current and future queues */ - DRM_HALT_CUR_QUEUES = 0x20 /**< Halt all current queues */ -} drmLockFlags; - -typedef enum { - DRM_CONTEXT_PRESERVED = 0x01, /**< This context is preserved and - never swapped. */ - DRM_CONTEXT_2DONLY = 0x02 /**< This context is for 2D rendering only. */ -} drm_context_tFlags, *drm_context_tFlagsPtr; - -typedef struct _drmBufDesc { - int count; /**< Number of buffers of this size */ - int size; /**< Size in bytes */ - int low_mark; /**< Low water mark */ - int high_mark; /**< High water mark */ -} drmBufDesc, *drmBufDescPtr; - -typedef struct _drmBufInfo { - int count; /**< Number of buffers described in list */ - drmBufDescPtr list; /**< List of buffer descriptions */ -} drmBufInfo, *drmBufInfoPtr; - -typedef struct _drmBuf { - int idx; /**< Index into the master buffer list */ - int total; /**< Buffer size */ - int used; /**< Amount of buffer in use (for DMA) */ - drmAddress address; /**< Address */ -} drmBuf, *drmBufPtr; - -/** - * Buffer mapping information. - * - * Used by drmMapBufs() and drmUnmapBufs() to store information about the - * mapped buffers. - */ -typedef struct _drmBufMap { - int count; /**< Number of buffers mapped */ - drmBufPtr list; /**< Buffers */ -} drmBufMap, *drmBufMapPtr; - -typedef struct _drmLock { - volatile unsigned int lock; - char padding[60]; - /* This is big enough for most current (and future?) architectures: - DEC Alpha: 32 bytes - Intel Merced: ? - Intel P5/PPro/PII/PIII: 32 bytes - Intel StrongARM: 32 bytes - Intel i386/i486: 16 bytes - MIPS: 32 bytes (?) - Motorola 68k: 16 bytes - Motorola PowerPC: 32 bytes - Sun SPARC: 32 bytes - */ -} drmLock, *drmLockPtr; - -/** - * Indices here refer to the offset into - * list in drmBufInfo - */ -typedef struct _drmDMAReq { - drm_context_t context; /**< Context handle */ - int send_count; /**< Number of buffers to send */ - int *send_list; /**< List of handles to buffers */ - int *send_sizes; /**< Lengths of data to send, in bytes */ - drmDMAFlags flags; /**< Flags */ - int request_count; /**< Number of buffers requested */ - int request_size; /**< Desired size of buffers requested */ - int *request_list; /**< Buffer information */ - int *request_sizes; /**< Minimum acceptable sizes */ - int granted_count; /**< Number of buffers granted at this size */ -} drmDMAReq, *drmDMAReqPtr; - -typedef struct _drmRegion { - drm_handle_t handle; - unsigned int offset; - drmSize size; - drmAddress map; -} drmRegion, *drmRegionPtr; - -typedef struct _drmTextureRegion { - unsigned char next; - unsigned char prev; - unsigned char in_use; - unsigned char padding; /**< Explicitly pad this out */ - unsigned int age; -} drmTextureRegion, *drmTextureRegionPtr; - - -typedef enum { - DRM_VBLANK_ABSOLUTE = 0x0, /**< Wait for specific vblank sequence number */ - DRM_VBLANK_RELATIVE = 0x1, /**< Wait for given number of vblanks */ - DRM_VBLANK_SIGNAL = 0x40000000 /* Send signal instead of blocking */ -} drmVBlankSeqType; - -typedef struct _drmVBlankReq { - drmVBlankSeqType type; - unsigned int sequence; - unsigned long signal; -} drmVBlankReq, *drmVBlankReqPtr; - -typedef struct _drmVBlankReply { - drmVBlankSeqType type; - unsigned int sequence; - long tval_sec; - long tval_usec; -} drmVBlankReply, *drmVBlankReplyPtr; - -typedef union _drmVBlank { - drmVBlankReq request; - drmVBlankReply reply; -} drmVBlank, *drmVBlankPtr; - -typedef struct _drmSetVersion { - int drm_di_major; - int drm_di_minor; - int drm_dd_major; - int drm_dd_minor; -} drmSetVersion, *drmSetVersionPtr; - - -#define __drm_dummy_lock(lock) (*(__volatile__ unsigned int *)lock) - -#define DRM_LOCK_HELD 0x80000000 /**< Hardware lock is held */ -#define DRM_LOCK_CONT 0x40000000 /**< Hardware lock is contended */ - -#if defined(__GNUC__) && (__GNUC__ >= 2) -# if defined(__i386) || defined(__amd64__) - /* Reflect changes here to drmP.h */ -#define DRM_CAS(lock,old,new,__ret) \ - do { \ - int __dummy; /* Can't mark eax as clobbered */ \ - __asm__ __volatile__( \ - "lock ; cmpxchg %4,%1\n\t" \ - "setnz %0" \ - : "=d" (__ret), \ - "=m" (__drm_dummy_lock(lock)), \ - "=a" (__dummy) \ - : "2" (old), \ - "r" (new)); \ - } while (0) - -#elif defined(__alpha__) - -#define DRM_CAS(lock, old, new, ret) \ - do { \ - int old32; \ - int cur32; \ - __asm__ __volatile__( \ - " mb\n" \ - " zap %4, 0xF0, %0\n" \ - " ldl_l %1, %2\n" \ - " zap %1, 0xF0, %1\n" \ - " cmpeq %0, %1, %1\n" \ - " beq %1, 1f\n" \ - " bis %5, %5, %1\n" \ - " stl_c %1, %2\n" \ - "1: xor %1, 1, %1\n" \ - " stl %1, %3" \ - : "+r" (old32), \ - "+&r" (cur32), \ - "=m" (__drm_dummy_lock(lock)),\ - "=m" (ret) \ - : "r" (old), \ - "r" (new)); \ - } while(0) - -#elif defined(__sparc__) - -#define DRM_CAS(lock,old,new,__ret) \ -do { register unsigned int __old __asm("o0"); \ - register unsigned int __new __asm("o1"); \ - register volatile unsigned int *__lock __asm("o2"); \ - __old = old; \ - __new = new; \ - __lock = (volatile unsigned int *)lock; \ - __asm__ __volatile__( \ - /*"cas [%2], %3, %0"*/ \ - ".word 0xd3e29008\n\t" \ - /*"membar #StoreStore | #StoreLoad"*/ \ - ".word 0x8143e00a" \ - : "=&r" (__new) \ - : "0" (__new), \ - "r" (__lock), \ - "r" (__old) \ - : "memory"); \ - __ret = (__new != __old); \ -} while(0) - -#elif defined(__ia64__) - -#ifdef __INTEL_COMPILER -/* this currently generates bad code (missing stop bits)... */ -#include <ia64intrin.h> - -#define DRM_CAS(lock,old,new,__ret) \ - do { \ - unsigned long __result, __old = (old) & 0xffffffff; \ - __mf(); \ - __result = _InterlockedCompareExchange_acq(&__drm_dummy_lock(lock), (new), __old);\ - __ret = (__result) != (__old); \ -/* __ret = (__sync_val_compare_and_swap(&__drm_dummy_lock(lock), \ - (old), (new)) \ - != (old)); */\ - } while (0) - -#else -#define DRM_CAS(lock,old,new,__ret) \ - do { \ - unsigned int __result, __old = (old); \ - __asm__ __volatile__( \ - "mf\n" \ - "mov ar.ccv=%2\n" \ - ";;\n" \ - "cmpxchg4.acq %0=%1,%3,ar.ccv" \ - : "=r" (__result), "=m" (__drm_dummy_lock(lock)) \ - : "r" ((unsigned long)__old), "r" (new) \ - : "memory"); \ - __ret = (__result) != (__old); \ - } while (0) - -#endif - -#elif defined(__powerpc__) - -#define DRM_CAS(lock,old,new,__ret) \ - do { \ - __asm__ __volatile__( \ - "sync;" \ - "0: lwarx %0,0,%1;" \ - " xor. %0,%3,%0;" \ - " bne 1f;" \ - " stwcx. %2,0,%1;" \ - " bne- 0b;" \ - "1: " \ - "sync;" \ - : "=&r"(__ret) \ - : "r"(lock), "r"(new), "r"(old) \ - : "cr0", "memory"); \ - } while (0) - -#endif /* architecture */ -#endif /* __GNUC__ >= 2 */ - -#ifndef DRM_CAS -#define DRM_CAS(lock,old,new,ret) do { ret=1; } while (0) /* FAST LOCK FAILS */ -#endif - -#if defined(__alpha__) || defined(__powerpc__) -#define DRM_CAS_RESULT(_result) int _result -#else -#define DRM_CAS_RESULT(_result) char _result -#endif - -#define DRM_LIGHT_LOCK(fd,lock,context) \ - do { \ - DRM_CAS_RESULT(__ret); \ - DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \ - if (__ret) drmGetLock(fd,context,0); \ - } while(0) - - /* This one counts fast locks -- for - benchmarking only. */ -#define DRM_LIGHT_LOCK_COUNT(fd,lock,context,count) \ - do { \ - DRM_CAS_RESULT(__ret); \ - DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \ - if (__ret) drmGetLock(fd,context,0); \ - else ++count; \ - } while(0) - -#define DRM_LOCK(fd,lock,context,flags) \ - do { \ - if (flags) drmGetLock(fd,context,flags); \ - else DRM_LIGHT_LOCK(fd,lock,context); \ - } while(0) - -#define DRM_UNLOCK(fd,lock,context) \ - do { \ - DRM_CAS_RESULT(__ret); \ - DRM_CAS(lock,DRM_LOCK_HELD|context,context,__ret); \ - if (__ret) drmUnlock(fd,context); \ - } while(0) - - /* Simple spin locks */ -#define DRM_SPINLOCK(spin,val) \ - do { \ - DRM_CAS_RESULT(__ret); \ - do { \ - DRM_CAS(spin,0,val,__ret); \ - if (__ret) while ((spin)->lock); \ - } while (__ret); \ - } while(0) - -#define DRM_SPINLOCK_TAKE(spin,val) \ - do { \ - DRM_CAS_RESULT(__ret); \ - int cur; \ - do { \ - cur = (*spin).lock; \ - DRM_CAS(spin,cur,val,__ret); \ - } while (__ret); \ - } while(0) - -#define DRM_SPINLOCK_COUNT(spin,val,count,__ret) \ - do { \ - int __i; \ - __ret = 1; \ - for (__i = 0; __ret && __i < count; __i++) { \ - DRM_CAS(spin,0,val,__ret); \ - if (__ret) for (;__i < count && (spin)->lock; __i++); \ - } \ - } while(0) - -#define DRM_SPINUNLOCK(spin,val) \ - do { \ - DRM_CAS_RESULT(__ret); \ - if ((*spin).lock == val) { /* else server stole lock */ \ - do { \ - DRM_CAS(spin,val,0,__ret); \ - } while (__ret); \ - } \ - } while(0) - -/* General user-level programmer's API: unprivileged */ -extern int drmAvailable(void); -extern int drmOpen(const char *name, const char *busid); -extern int drmClose(int fd); -extern drmVersionPtr drmGetVersion(int fd); -extern drmVersionPtr drmGetLibVersion(int fd); -extern void drmFreeVersion(drmVersionPtr); -extern int drmGetMagic(int fd, drm_magic_t * magic); -extern char *drmGetBusid(int fd); -extern int drmGetInterruptFromBusID(int fd, int busnum, int devnum, - int funcnum); -extern int drmGetMap(int fd, int idx, drm_handle_t *offset, - drmSize *size, drmMapType *type, - drmMapFlags *flags, drm_handle_t *handle, - int *mtrr); -extern int drmGetClient(int fd, int idx, int *auth, int *pid, - int *uid, unsigned long *magic, - unsigned long *iocs); -extern int drmGetStats(int fd, drmStatsT *stats); -extern int drmSetInterfaceVersion(int fd, drmSetVersion *version); -extern int drmCommandNone(int fd, unsigned long drmCommandIndex); -extern int drmCommandRead(int fd, unsigned long drmCommandIndex, - void *data, unsigned long size); -extern int drmCommandWrite(int fd, unsigned long drmCommandIndex, - void *data, unsigned long size); -extern int drmCommandWriteRead(int fd, unsigned long drmCommandIndex, - void *data, unsigned long size); - -/* General user-level programmer's API: X server (root) only */ -extern void drmFreeBusid(const char *busid); -extern int drmSetBusid(int fd, const char *busid); -extern int drmAuthMagic(int fd, drm_magic_t magic); -extern int drmAddMap(int fd, - drm_handle_t offset, - drmSize size, - drmMapType type, - drmMapFlags flags, - drm_handle_t * handle); -extern int drmRmMap(int fd, drm_handle_t handle); -extern int drmAddContextPrivateMapping(int fd, drm_context_t ctx_id, - drm_handle_t handle); - -extern int drmAddBufs(int fd, int count, int size, - drmBufDescFlags flags, - int agp_offset); -extern int drmMarkBufs(int fd, double low, double high); -extern int drmCreateContext(int fd, drm_context_t * handle); -extern int drmSetContextFlags(int fd, drm_context_t context, - drm_context_tFlags flags); -extern int drmGetContextFlags(int fd, drm_context_t context, - drm_context_tFlagsPtr flags); -extern int drmAddContextTag(int fd, drm_context_t context, void *tag); -extern int drmDelContextTag(int fd, drm_context_t context); -extern void *drmGetContextTag(int fd, drm_context_t context); -extern drm_context_t * drmGetReservedContextList(int fd, int *count); -extern void drmFreeReservedContextList(drm_context_t *); -extern int drmSwitchToContext(int fd, drm_context_t context); -extern int drmDestroyContext(int fd, drm_context_t handle); -extern int drmCreateDrawable(int fd, drm_drawable_t * handle); -extern int drmDestroyDrawable(int fd, drm_drawable_t handle); -extern int drmCtlInstHandler(int fd, int irq); -extern int drmCtlUninstHandler(int fd); -extern int drmInstallSIGIOHandler(int fd, - void (*f)(int fd, - void *oldctx, - void *newctx)); -extern int drmRemoveSIGIOHandler(int fd); - -/* General user-level programmer's API: authenticated client and/or X */ -extern int drmMap(int fd, - drm_handle_t handle, - drmSize size, - drmAddressPtr address); -extern int drmUnmap(drmAddress address, drmSize size); -extern drmBufInfoPtr drmGetBufInfo(int fd); -extern drmBufMapPtr drmMapBufs(int fd); -extern int drmUnmapBufs(drmBufMapPtr bufs); -extern int drmDMA(int fd, drmDMAReqPtr request); -extern int drmFreeBufs(int fd, int count, int *list); -extern int drmGetLock(int fd, - drm_context_t context, - drmLockFlags flags); -extern int drmUnlock(int fd, drm_context_t context); -extern int drmFinish(int fd, int context, drmLockFlags flags); -extern int drmGetContextPrivateMapping(int fd, drm_context_t ctx_id, - drm_handle_t * handle); - -/* AGP/GART support: X server (root) only */ -extern int drmAgpAcquire(int fd); -extern int drmAgpRelease(int fd); -extern int drmAgpEnable(int fd, unsigned long mode); -extern int drmAgpAlloc(int fd, unsigned long size, - unsigned long type, unsigned long *address, - unsigned long *handle); -extern int drmAgpFree(int fd, unsigned long handle); -extern int drmAgpBind(int fd, unsigned long handle, - unsigned long offset); -extern int drmAgpUnbind(int fd, unsigned long handle); - -/* AGP/GART info: authenticated client and/or X */ -extern int drmAgpVersionMajor(int fd); -extern int drmAgpVersionMinor(int fd); -extern unsigned long drmAgpGetMode(int fd); -extern unsigned long drmAgpBase(int fd); /* Physical location */ -extern unsigned long drmAgpSize(int fd); /* Bytes */ -extern unsigned long drmAgpMemoryUsed(int fd); -extern unsigned long drmAgpMemoryAvail(int fd); -extern unsigned int drmAgpVendorId(int fd); -extern unsigned int drmAgpDeviceId(int fd); - -/* PCI scatter/gather support: X server (root) only */ -extern int drmScatterGatherAlloc(int fd, unsigned long size, - unsigned long *handle); -extern int drmScatterGatherFree(int fd, unsigned long handle); - -extern int drmWaitVBlank(int fd, drmVBlankPtr vbl); - -/* Support routines */ -extern int drmError(int err, const char *label); -extern void *drmMalloc(int size); -extern void drmFree(void *pt); - -/* Hash table routines */ -extern void *drmHashCreate(void); -extern int drmHashDestroy(void *t); -extern int drmHashLookup(void *t, unsigned long key, void **value); -extern int drmHashInsert(void *t, unsigned long key, void *value); -extern int drmHashDelete(void *t, unsigned long key); -extern int drmHashFirst(void *t, unsigned long *key, void **value); -extern int drmHashNext(void *t, unsigned long *key, void **value); - -/* PRNG routines */ -extern void *drmRandomCreate(unsigned long seed); -extern int drmRandomDestroy(void *state); -extern unsigned long drmRandom(void *state); -extern double drmRandomDouble(void *state); - -/* Skip list routines */ - -extern void *drmSLCreate(void); -extern int drmSLDestroy(void *l); -extern int drmSLLookup(void *l, unsigned long key, void **value); -extern int drmSLInsert(void *l, unsigned long key, void *value); -extern int drmSLDelete(void *l, unsigned long key); -extern int drmSLNext(void *l, unsigned long *key, void **value); -extern int drmSLFirst(void *l, unsigned long *key, void **value); -extern void drmSLDump(void *l); -extern int drmSLLookupNeighbors(void *l, unsigned long key, - unsigned long *prev_key, void **prev_value, - unsigned long *next_key, void **next_value); - -#endif diff --git a/src/mesa/drivers/dri/dri_client/xf86drm.c b/src/mesa/drivers/dri/dri_client/xf86drm.c deleted file mode 100644 index dba0f98deba..00000000000 --- a/src/mesa/drivers/dri/dri_client/xf86drm.c +++ /dev/null @@ -1,2333 +0,0 @@ -/** - * \file xf86drm.c - * User-level interface to DRM device - * - * \author Rickard E. (Rik) Faith <[email protected]> - * \author Kevin E. Martin <[email protected]> - */ - -/* - * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. - * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, 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 - * 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 (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 NONINFRINGEMENT. IN NO EVENT SHALL - * PRECISION INSIGHT 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. - */ - -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drm.c,v 1.36 2003/08/24 17:35:35 tsi Exp $ */ - -#ifdef XFree86Server -# include "xf86.h" -# include "xf86_OSproc.h" -# include "drm.h" -# include "xf86_ansic.h" -# define _DRM_MALLOC xalloc -# define _DRM_FREE xfree -# ifndef XFree86LOADER -# include <sys/mman.h> -# endif -#else -# include <stdio.h> -# include <stdlib.h> -# include <unistd.h> -# include <string.h> -# include <ctype.h> -# include <fcntl.h> -# include <errno.h> -# include <signal.h> -# include <sys/types.h> -# include <sys/stat.h> -# define stat_t struct stat -# include <sys/ioctl.h> -# include <sys/mman.h> -# include <sys/time.h> -# include <stdarg.h> -# ifdef DRM_USE_MALLOC -# define _DRM_MALLOC malloc -# define _DRM_FREE free -# else -# include <X11/Xlibint.h> -# define _DRM_MALLOC Xmalloc -# define _DRM_FREE Xfree -# endif -# include "drm.h" -#endif - -/* No longer needed with CVS kernel modules on alpha -#if defined(__alpha__) && defined(__linux__) -extern unsigned long _bus_base(void); -#define BUS_BASE _bus_base() -#endif -*/ - -/* Not all systems have MAP_FAILED defined */ -#ifndef MAP_FAILED -#define MAP_FAILED ((void *)-1) -#endif - -#include "xf86drm.h" - -#ifdef __FreeBSD__ -#define DRM_MAJOR 145 -#endif - -#ifdef __NetBSD__ -#define DRM_MAJOR 34 -#endif - -# ifdef __OpenBSD__ -# define DRM_MAJOR 81 -# endif - -#ifndef DRM_MAJOR -#define DRM_MAJOR 226 /* Linux */ -#endif - -#ifndef DRM_MAX_MINOR -#define DRM_MAX_MINOR 16 -#endif - -#ifdef __linux__ -#include <sys/sysmacros.h> /* for makedev() */ -#endif - -#ifndef makedev - /* This definition needs to be changed on - some systems if dev_t is a structure. - If there is a header file we can get it - from, there would be best. */ -#define makedev(x,y) ((dev_t)(((x) << 8) | (y))) -#endif - -#define DRM_MSG_VERBOSITY 3 - -/** - * Output a message to stderr. - * - * \param format printf() like format string. - * - * \internal - * This function is a wrapper around vfprintf(). - */ -static void -drmMsg(const char *format, ...) -{ - va_list ap; - -#ifndef XFree86Server - const char *env; - if ((env = getenv("LIBGL_DEBUG")) && strstr(env, "verbose")) -#endif - { - va_start(ap, format); -#ifdef XFree86Server - xf86VDrvMsgVerb(-1, X_NONE, DRM_MSG_VERBOSITY, format, ap); -#else - vfprintf(stderr, format, ap); -#endif - va_end(ap); - } -} - -static void *drmHashTable = NULL; /* Context switch callbacks */ - -typedef struct drmHashEntry { - int fd; - void (*f)(int, void *, void *); - void *tagTable; -} drmHashEntry; - -void *drmMalloc(int size) -{ - void *pt; - if ((pt = _DRM_MALLOC(size))) memset(pt, 0, size); - return pt; -} - -void drmFree(void *pt) -{ - if (pt) _DRM_FREE(pt); -} - -/* drmStrdup can't use strdup(3), since it doesn't call _DRM_MALLOC... */ -static char *drmStrdup(const char *s) -{ - char *retval = NULL; - - if (s) { - retval = _DRM_MALLOC(strlen(s)+1); - strcpy(retval, s); - } - return retval; -} - - -static unsigned long drmGetKeyFromFd(int fd) -{ - stat_t st; - - st.st_rdev = 0; - fstat(fd, &st); - return st.st_rdev; -} - -static drmHashEntry *drmGetEntry(int fd) -{ - unsigned long key = drmGetKeyFromFd(fd); - void *value; - drmHashEntry *entry; - - if (!drmHashTable) drmHashTable = drmHashCreate(); - - if (drmHashLookup(drmHashTable, key, &value)) { - entry = drmMalloc(sizeof(*entry)); - entry->fd = fd; - entry->f = NULL; - entry->tagTable = drmHashCreate(); - drmHashInsert(drmHashTable, key, entry); - } else { - entry = value; - } - return entry; -} - -/** - * Compare two busid strings - * - * \param first - * \param second - * - * \return 1 if matched. - * - * \internal - * This function compares two bus ID strings. It understands the older - * PCI:b:d:f format and the newer pci:oooo:bb:dd.f format. In the format, o is - * domain, b is bus, d is device, f is function. - */ -static int drmMatchBusID(const char *id1, const char *id2) -{ - /* First, check if the IDs are exactly the same */ - if (strcasecmp(id1, id2) == 0) - return 1; - - /* Try to match old/new-style PCI bus IDs. */ - if (strncasecmp(id1, "pci", 3) == 0) { - int o1, b1, d1, f1; - int o2, b2, d2, f2; - int ret; - - ret = sscanf(id1, "pci:%04x:%02x:%02x.%d", &o1, &b1, &d1, &f1); - if (ret != 4) { - o1 = 0; - ret = sscanf(id1, "PCI:%d:%d:%d", &b1, &d1, &f1); - if (ret != 3) - return 0; - } - - ret = sscanf(id2, "pci:%04x:%02x:%02x.%d", &o2, &b2, &d2, &f2); - if (ret != 4) { - o2 = 0; - ret = sscanf(id2, "PCI:%d:%d:%d", &b2, &d2, &f2); - if (ret != 3) - return 0; - } - - if ((o1 != o2) || (b1 != b2) || (d1 != d2) || (f1 != f2)) - return 0; - else - return 1; - } - return 0; -} - -/** - * Open the DRM device, creating it if necessary. - * - * \param dev major and minor numbers of the device. - * \param minor minor number of the device. - * - * \return a file descriptor on success, or a negative value on error. - * - * \internal - * Assembles the device name from \p minor and opens it, creating the device - * special file node with the major and minor numbers specified by \p dev and - * parent directory if necessary and was called by root. - */ -static int drmOpenDevice(long dev, int minor) -{ - stat_t st; - char buf[64]; - int fd; - mode_t devmode = DRM_DEV_MODE; - int isroot = !geteuid(); -#if defined(XFree86Server) - uid_t user = DRM_DEV_UID; - gid_t group = DRM_DEV_GID; -#endif - - sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, minor); - drmMsg("drmOpenDevice: node name is %s\n", buf); - -#if defined(XFree86Server) - devmode = xf86ConfigDRI.mode ? xf86ConfigDRI.mode : DRM_DEV_MODE; - devmode &= ~(S_IXUSR|S_IXGRP|S_IXOTH); - group = (xf86ConfigDRI.group >= 0) ? xf86ConfigDRI.group : DRM_DEV_GID; -#endif - - if (stat(DRM_DIR_NAME, &st)) { - if (!isroot) return DRM_ERR_NOT_ROOT; - mkdir(DRM_DIR_NAME, DRM_DEV_DIRMODE); - chown(DRM_DIR_NAME, 0, 0); /* root:root */ - chmod(DRM_DIR_NAME, DRM_DEV_DIRMODE); - } - - /* Check if the device node exists and create it if necessary. */ - if (stat(buf, &st)) { - if (!isroot) return DRM_ERR_NOT_ROOT; - remove(buf); - mknod(buf, S_IFCHR | devmode, dev); - } -#if defined(XFree86Server) - chown(buf, user, group); - chmod(buf, devmode); -#endif - - fd = open(buf, O_RDWR, 0); - drmMsg("drmOpenDevice: open result is %d, (%s)\n", - fd, fd < 0 ? strerror(errno) : "OK"); - if (fd >= 0) return fd; - - /* Check if the device node is not what we expect it to be, and recreate it - * and try again if so. - */ - if (st.st_rdev != dev) { - if (!isroot) return DRM_ERR_NOT_ROOT; - remove(buf); - mknod(buf, S_IFCHR | devmode, dev); -#if defined(XFree86Server) - chown(buf, user, group); - chmod(buf, devmode); -#endif - } - fd = open(buf, O_RDWR, 0); - drmMsg("drmOpenDevice: open result is %d, (%s)\n", - fd, fd < 0 ? strerror(errno) : "OK"); - if (fd >= 0) return fd; - - drmMsg("drmOpenDevice: Open failed\n"); - remove(buf); - return -errno; -} - - -/** - * Open the DRM device - * - * \param minor device minor number. - * \param create allow to create the device if set. - * - * \return a file descriptor on success, or a negative value on error. - * - * \internal - * Calls drmOpenDevice() if \p create is set, otherwise assembles the device - * name from \p minor and opens it. - */ -static int drmOpenMinor(int minor, int create) -{ - int fd; - char buf[64]; - - if (create) return drmOpenDevice(makedev(DRM_MAJOR, minor), minor); - - sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, minor); - if ((fd = open(buf, O_RDWR, 0)) >= 0) return fd; - return -errno; -} - - -/** - * Determine whether the DRM kernel driver has been loaded. - * - * \return 1 if the DRM driver is loaded, 0 otherwise. - * - * \internal - * Determine the presence of the kernel driver by attempting to open the 0 - * minor and get version information. For backward compatibility with older - * Linux implementations, /proc/dri is also checked. - */ -int drmAvailable(void) -{ - drmVersionPtr version; - int retval = 0; - int fd; - - if ((fd = drmOpenMinor(0, 1)) < 0) { -#ifdef __linux__ - /* Try proc for backward Linux compatibility */ - if (!access("/proc/dri/0", R_OK)) return 1; -#endif - return 0; - } - - if ((version = drmGetVersion(fd))) { - retval = 1; - drmFreeVersion(version); - } - close(fd); - - return retval; -} - - -/** - * Open the device by bus ID. - * - * \param busid bus ID. - * - * \return a file descriptor on success, or a negative value on error. - * - * \internal - * This function attempts to open every possible minor (up to DRM_MAX_MINOR), - * comparing the device bus ID with the one supplied. - * - * \sa drmOpenMinor() and drmGetBusid(). - */ -static int drmOpenByBusid(const char *busid) -{ - int i; - int fd; - const char *buf; - drmSetVersion sv; - - drmMsg("drmOpenByBusid: Searching for BusID %s\n", busid); - for (i = 0; i < DRM_MAX_MINOR; i++) { - fd = drmOpenMinor(i, 1); - drmMsg("drmOpenByBusid: drmOpenMinor returns %d\n", fd); - if (fd >= 0) { - sv.drm_di_major = 1; - sv.drm_di_minor = 1; - sv.drm_dd_major = -1; /* Don't care */ - drmSetInterfaceVersion(fd, &sv); - buf = drmGetBusid(fd); - drmMsg("drmOpenByBusid: drmGetBusid reports %s\n", buf); - if (buf && drmMatchBusID(buf, busid)) { - drmFreeBusid(buf); - return fd; - } - if (buf) drmFreeBusid(buf); - close(fd); - } - } - return -1; -} - - -/** - * Open the device by name. - * - * \param name driver name. - * - * \return a file descriptor on success, or a negative value on error. - * - * \internal - * This function opens the first minor number that matches the driver name and - * isn't already in use. If it's in use it then it will already have a bus ID - * assigned. - * - * \sa drmOpenMinor(), drmGetVersion() and drmGetBusid(). - */ -static int drmOpenByName(const char *name) -{ - int i; - int fd; - drmVersionPtr version; - char * id; - - if (!drmAvailable()) { -#if !defined(XFree86Server) - return -1; -#else - /* try to load the kernel module now */ - if (!xf86LoadKernelModule(name)) { - ErrorF("[drm] failed to load kernel module \"%s\"\n", - name); - return -1; - } -#endif - } - - /* - * Open the first minor number that matches the driver name and isn't - * already in use. If it's in use it will have a busid assigned already. - */ - for (i = 0; i < DRM_MAX_MINOR; i++) { - if ((fd = drmOpenMinor(i, 1)) >= 0) { - if ((version = drmGetVersion(fd))) { - if (!strcmp(version->name, name)) { - drmFreeVersion(version); - id = drmGetBusid(fd); - drmMsg("drmGetBusid returned '%s'\n", id ? id : "NULL"); - if (!id || !*id) { - if (id) { - drmFreeBusid(id); - } - return fd; - } else { - drmFreeBusid(id); - } - } else { - drmFreeVersion(version); - } - } - close(fd); - } - } - -#ifdef __linux__ - /* Backward-compatibility /proc support */ - for (i = 0; i < 8; i++) { - char proc_name[64], buf[512]; - char *driver, *pt, *devstring; - int retcode; - - sprintf(proc_name, "/proc/dri/%d/name", i); - if ((fd = open(proc_name, 0, 0)) >= 0) { - retcode = read(fd, buf, sizeof(buf)-1); - close(fd); - if (retcode) { - buf[retcode-1] = '\0'; - for (driver = pt = buf; *pt && *pt != ' '; ++pt) - ; - if (*pt) { /* Device is next */ - *pt = '\0'; - if (!strcmp(driver, name)) { /* Match */ - for (devstring = ++pt; *pt && *pt != ' '; ++pt) - ; - if (*pt) { /* Found busid */ - return drmOpenByBusid(++pt); - } else { /* No busid */ - return drmOpenDevice(strtol(devstring, NULL, 0),i); - } - } - } - } - } - } -#endif - - return -1; -} - - -/** - * Open the DRM device. - * - * Looks up the specified name and bus ID, and opens the device found. The - * entry in /dev/dri is created if necessary and if called by root. - * - * \param name driver name. Not referenced if bus ID is supplied. - * \param busid bus ID. Zero if not known. - * - * \return a file descriptor on success, or a negative value on error. - * - * \internal - * It calls drmOpenByBusid() if \p busid is specified or drmOpenByName() - * otherwise. - */ -int drmOpen(const char *name, const char *busid) -{ -#ifdef XFree86Server - if (!drmAvailable() && name != NULL) { - /* try to load the kernel */ - if (!xf86LoadKernelModule(name)) { - ErrorF("[drm] failed to load kernel module \"%s\"\n", - name); - return -1; - } - } -#endif - - if (busid) { - int fd; - - fd = drmOpenByBusid(busid); - if (fd >= 0) - return fd; - } - if (name) - return drmOpenByName(name); - return -1; -} - - -/** - * Free the version information returned by drmGetVersion(). - * - * \param v pointer to the version information. - * - * \internal - * It frees the memory pointed by \p %v as well as all the non-null strings - * pointers in it. - */ -void drmFreeVersion(drmVersionPtr v) -{ - if (!v) return; - if (v->name) drmFree(v->name); - if (v->date) drmFree(v->date); - if (v->desc) drmFree(v->desc); - drmFree(v); -} - - -/** - * Free the non-public version information returned by the kernel. - * - * \param v pointer to the version information. - * - * \internal - * Used by drmGetVersion() to free the memory pointed by \p %v as well as all - * the non-null strings pointers in it. - */ -static void drmFreeKernelVersion(drm_version_t *v) -{ - if (!v) return; - if (v->name) drmFree(v->name); - if (v->date) drmFree(v->date); - if (v->desc) drmFree(v->desc); - drmFree(v); -} - - -/** - * Copy version information. - * - * \param d destination pointer. - * \param s source pointer. - * - * \internal - * Used by drmGetVersion() to translate the information returned by the ioctl - * interface in a private structure into the public structure counterpart. - */ -static void drmCopyVersion(drmVersionPtr d, const drm_version_t *s) -{ - d->version_major = s->version_major; - d->version_minor = s->version_minor; - d->version_patchlevel = s->version_patchlevel; - d->name_len = s->name_len; - d->name = drmStrdup(s->name); - d->date_len = s->date_len; - d->date = drmStrdup(s->date); - d->desc_len = s->desc_len; - d->desc = drmStrdup(s->desc); -} - - -/** - * Query the driver version information. - * - * \param fd file descriptor. - * - * \return pointer to a drmVersion structure which should be freed with - * drmFreeVersion(). - * - * \note Similar information is available via /proc/dri. - * - * \internal - * It gets the version information via successive DRM_IOCTL_VERSION ioctls, - * first with zeros to get the string lengths, and then the actually strings. - * It also null-terminates them since they might not be already. - */ -drmVersionPtr drmGetVersion(int fd) -{ - drmVersionPtr retval; - drm_version_t *version = drmMalloc(sizeof(*version)); - - /* First, get the lengths */ - version->name_len = 0; - version->name = NULL; - version->date_len = 0; - version->date = NULL; - version->desc_len = 0; - version->desc = NULL; - - if (ioctl(fd, DRM_IOCTL_VERSION, version)) { - drmFreeKernelVersion(version); - return NULL; - } - - /* Now, allocate space and get the data */ - if (version->name_len) - version->name = drmMalloc(version->name_len + 1); - if (version->date_len) - version->date = drmMalloc(version->date_len + 1); - if (version->desc_len) - version->desc = drmMalloc(version->desc_len + 1); - - if (ioctl(fd, DRM_IOCTL_VERSION, version)) { - drmMsg("DRM_IOCTL_VERSION: %s\n", strerror(errno)); - drmFreeKernelVersion(version); - return NULL; - } - - /* The results might not be null-terminated - strings, so terminate them. */ - - if (version->name_len) version->name[version->name_len] = '\0'; - if (version->date_len) version->date[version->date_len] = '\0'; - if (version->desc_len) version->desc[version->desc_len] = '\0'; - - /* Now, copy it all back into the - client-visible data structure... */ - retval = drmMalloc(sizeof(*retval)); - drmCopyVersion(retval, version); - drmFreeKernelVersion(version); - return retval; -} - - -/** - * Get version information for the DRM user space library. - * - * This version number is driver independent. - * - * \param fd file descriptor. - * - * \return version information. - * - * \internal - * This function allocates and fills a drm_version structure with a hard coded - * version number. - */ -drmVersionPtr drmGetLibVersion(int fd) -{ - drm_version_t *version = drmMalloc(sizeof(*version)); - - /* Version history: - * revision 1.0.x = original DRM interface with no drmGetLibVersion - * entry point and many drm<Device> extensions - * revision 1.1.x = added drmCommand entry points for device extensions - * added drmGetLibVersion to identify libdrm.a version - * revision 1.2.x = added drmSetInterfaceVersion - * modified drmOpen to handle both busid and name - */ - version->version_major = 1; - version->version_minor = 2; - version->version_patchlevel = 0; - - return (drmVersionPtr)version; -} - - -/** - * Free the bus ID information. - * - * \param busid bus ID information string as given by drmGetBusid(). - * - * \internal - * This function is just frees the memory pointed by \p busid. - */ -void drmFreeBusid(const char *busid) -{ - drmFree((void *)busid); -} - - -/** - * Get the bus ID of the device. - * - * \param fd file descriptor. - * - * \return bus ID string. - * - * \internal - * This function gets the bus ID via successive DRM_IOCTL_GET_UNIQUE ioctls to - * get the string length and data, passing the arguments in a drm_unique - * structure. - */ -char *drmGetBusid(int fd) -{ - drm_unique_t u; - - u.unique_len = 0; - u.unique = NULL; - - if (ioctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) return NULL; - u.unique = drmMalloc(u.unique_len + 1); - if (ioctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) return NULL; - u.unique[u.unique_len] = '\0'; - - return u.unique; -} - - -/** - * Set the bus ID of the device. - * - * \param fd file descriptor. - * \param busid bus ID string. - * - * \return zero on success, negative on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_SET_UNIQUE ioctl, passing - * the arguments in a drm_unique structure. - */ -int drmSetBusid(int fd, const char *busid) -{ - drm_unique_t u; - - u.unique = (char *)busid; - u.unique_len = strlen(busid); - - if (ioctl(fd, DRM_IOCTL_SET_UNIQUE, &u)) { - return -errno; - } - return 0; -} - -int drmGetMagic(int fd, drm_magic_t * magic) -{ - drm_auth_t auth; - - *magic = 0; - if (ioctl(fd, DRM_IOCTL_GET_MAGIC, &auth)) return -errno; - *magic = auth.magic; - return 0; -} - -int drmAuthMagic(int fd, drm_magic_t magic) -{ - drm_auth_t auth; - - auth.magic = magic; - if (ioctl(fd, DRM_IOCTL_AUTH_MAGIC, &auth)) return -errno; - return 0; -} - -/** - * Specifies a range of memory that is available for mapping by a - * non-root process. - * - * \param fd file descriptor. - * \param offset usually the physical address. The actual meaning depends of - * the \p type parameter. See below. - * \param size of the memory in bytes. - * \param type type of the memory to be mapped. - * \param flags combination of several flags to modify the function actions. - * \param handle will be set to a value that may be used as the offset - * parameter for mmap(). - * - * \return zero on success or a negative value on error. - * - * \par Mapping the frame buffer - * For the frame buffer - * - \p offset will be the physical address of the start of the frame buffer, - * - \p size will be the size of the frame buffer in bytes, and - * - \p type will be DRM_FRAME_BUFFER. - * - * \par - * The area mapped will be uncached. If MTRR support is available in the - * kernel, the frame buffer area will be set to write combining. - * - * \par Mapping the MMIO register area - * For the MMIO register area, - * - \p offset will be the physical address of the start of the register area, - * - \p size will be the size of the register area bytes, and - * - \p type will be DRM_REGISTERS. - * \par - * The area mapped will be uncached. - * - * \par Mapping the SAREA - * For the SAREA, - * - \p offset will be ignored and should be set to zero, - * - \p size will be the desired size of the SAREA in bytes, - * - \p type will be DRM_SHM. - * - * \par - * A shared memory area of the requested size will be created and locked in - * kernel memory. This area may be mapped into client-space by using the handle - * returned. - * - * \note May only be called by root. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_ADD_MAP ioctl, passing - * the arguments in a drm_map structure. - */ -int drmAddMap(int fd, - drm_handle_t offset, - drmSize size, - drmMapType type, - drmMapFlags flags, - drm_handle_t * handle) -{ - drm_map_t map; - - map.offset = offset; -/* No longer needed with CVS kernel modules on alpha -#ifdef __alpha__ - if (type != DRM_SHM) - map.offset += BUS_BASE; -#endif -*/ - map.size = size; - map.handle = 0; - map.type = type; - map.flags = flags; - if (ioctl(fd, DRM_IOCTL_ADD_MAP, &map)) return -errno; - if (handle) *handle = (drm_handle_t)map.handle; - return 0; -} - -int drmRmMap(int fd, drm_handle_t handle) -{ - drm_map_t map; - - map.handle = (void *)handle; - - if(ioctl(fd, DRM_IOCTL_RM_MAP, &map)) return -errno; - return 0; -} - -/** - * Make buffers available for DMA transfers. - * - * \param fd file descriptor. - * \param count number of buffers. - * \param size size of each buffer. - * \param flags buffer allocation flags. - * \param agp_offset offset in the AGP aperture - * - * \return number of buffers allocated, negative on error. - * - * \internal - * This function is a wrapper around DRM_IOCTL_ADD_BUFS ioctl. - * - * \sa drm_buf_desc. - */ -int drmAddBufs(int fd, int count, int size, drmBufDescFlags flags, - int agp_offset) -{ - drm_buf_desc_t request; - - request.count = count; - request.size = size; - request.low_mark = 0; - request.high_mark = 0; - request.flags = flags; - request.agp_start = agp_offset; - - if (ioctl(fd, DRM_IOCTL_ADD_BUFS, &request)) return -errno; - return request.count; -} - -int drmMarkBufs(int fd, double low, double high) -{ - drm_buf_info_t info; - int i; - - info.count = 0; - info.list = NULL; - - if (ioctl(fd, DRM_IOCTL_INFO_BUFS, &info)) return -EINVAL; - - if (!info.count) return -EINVAL; - - if (!(info.list = drmMalloc(info.count * sizeof(*info.list)))) - return -ENOMEM; - - if (ioctl(fd, DRM_IOCTL_INFO_BUFS, &info)) { - int retval = -errno; - drmFree(info.list); - return retval; - } - - for (i = 0; i < info.count; i++) { - info.list[i].low_mark = low * info.list[i].count; - info.list[i].high_mark = high * info.list[i].count; - if (ioctl(fd, DRM_IOCTL_MARK_BUFS, &info.list[i])) { - int retval = -errno; - drmFree(info.list); - return retval; - } - } - drmFree(info.list); - - return 0; -} - -/** - * Free buffers. - * - * \param fd file descriptor. - * \param count number of buffers to free. - * \param list list of buffers to be freed. - * - * \return zero on success, or a negative value on failure. - * - * \note This function is primarily used for debugging. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_FREE_BUFS ioctl, passing - * the arguments in a drm_buf_free structure. - */ -int drmFreeBufs(int fd, int count, int *list) -{ - drm_buf_free_t request; - - request.count = count; - request.list = list; - if (ioctl(fd, DRM_IOCTL_FREE_BUFS, &request)) return -errno; - return 0; -} - - -/** - * Close the device. - * - * \param fd file descriptor. - * - * \internal - * This function closes the file descriptor. - */ -int drmClose(int fd) -{ - unsigned long key = drmGetKeyFromFd(fd); - drmHashEntry *entry = drmGetEntry(fd); - - drmHashDestroy(entry->tagTable); - entry->fd = 0; - entry->f = NULL; - entry->tagTable = NULL; - - drmHashDelete(drmHashTable, key); - drmFree(entry); - - return close(fd); -} - - -/** - * Map a region of memory. - * - * \param fd file descriptor. - * \param handle handle returned by drmAddMap(). - * \param size size in bytes. Must match the size used by drmAddMap(). - * \param address will contain the user-space virtual address where the mapping - * begins. - * - * \return zero on success, or a negative value on failure. - * - * \internal - * This function is a wrapper for mmap(). - */ -int drmMap(int fd, - drm_handle_t handle, - drmSize size, - drmAddressPtr address) -{ - static unsigned long pagesize_mask = 0; - - if (fd < 0) return -EINVAL; - - if (!pagesize_mask) - pagesize_mask = getpagesize() - 1; - - size = (size + pagesize_mask) & ~pagesize_mask; - - *address = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, handle); - if (*address == MAP_FAILED) return -errno; - return 0; -} - - -/** - * Unmap mappings obtained with drmMap(). - * - * \param address address as given by drmMap(). - * \param size size in bytes. Must match the size used by drmMap(). - * - * \return zero on success, or a negative value on failure. - * - * \internal - * This function is a wrapper for unmap(). - */ -int drmUnmap(drmAddress address, drmSize size) -{ - return munmap(address, size); -} - -drmBufInfoPtr drmGetBufInfo(int fd) -{ - drm_buf_info_t info; - drmBufInfoPtr retval; - int i; - - info.count = 0; - info.list = NULL; - - if (ioctl(fd, DRM_IOCTL_INFO_BUFS, &info)) return NULL; - - if (info.count) { - if (!(info.list = drmMalloc(info.count * sizeof(*info.list)))) - return NULL; - - if (ioctl(fd, DRM_IOCTL_INFO_BUFS, &info)) { - drmFree(info.list); - return NULL; - } - /* Now, copy it all back into the - client-visible data structure... */ - retval = drmMalloc(sizeof(*retval)); - retval->count = info.count; - retval->list = drmMalloc(info.count * sizeof(*retval->list)); - for (i = 0; i < info.count; i++) { - retval->list[i].count = info.list[i].count; - retval->list[i].size = info.list[i].size; - retval->list[i].low_mark = info.list[i].low_mark; - retval->list[i].high_mark = info.list[i].high_mark; - } - drmFree(info.list); - return retval; - } - return NULL; -} - -/** - * Map all DMA buffers into client-virtual space. - * - * \param fd file descriptor. - * - * \return a pointer to a ::drmBufMap structure. - * - * \note The client may not use these buffers until obtaining buffer indices - * with drmDMA(). - * - * \internal - * This function calls the DRM_IOCTL_MAP_BUFS ioctl and copies the returned - * information about the buffers in a drm_buf_map structure into the - * client-visible data structures. - */ -drmBufMapPtr drmMapBufs(int fd) -{ - drm_buf_map_t bufs; - drmBufMapPtr retval; - int i; - - bufs.count = 0; - bufs.list = NULL; - bufs.virtual = NULL; - if (ioctl(fd, DRM_IOCTL_MAP_BUFS, &bufs)) return NULL; - - if (!bufs.count) return NULL; - - if (!(bufs.list = drmMalloc(bufs.count * sizeof(*bufs.list)))) - return NULL; - - if (ioctl(fd, DRM_IOCTL_MAP_BUFS, &bufs)) { - drmFree(bufs.list); - return NULL; - } - /* Now, copy it all back into the - client-visible data structure... */ - retval = drmMalloc(sizeof(*retval)); - retval->count = bufs.count; - retval->list = drmMalloc(bufs.count * sizeof(*retval->list)); - for (i = 0; i < bufs.count; i++) { - retval->list[i].idx = bufs.list[i].idx; - retval->list[i].total = bufs.list[i].total; - retval->list[i].used = 0; - retval->list[i].address = bufs.list[i].address; - } - - drmFree(bufs.list); - - return retval; -} - - -/** - * Unmap buffers allocated with drmMapBufs(). - * - * \return zero on success, or negative value on failure. - * - * \internal - * Calls munmap() for every buffer stored in \p bufs and frees the - * memory allocated by drmMapBufs(). - */ -int drmUnmapBufs(drmBufMapPtr bufs) -{ - int i; - - for (i = 0; i < bufs->count; i++) { - munmap(bufs->list[i].address, bufs->list[i].total); - } - - drmFree(bufs->list); - drmFree(bufs); - - return 0; -} - - -#define DRM_DMA_RETRY 16 - -/** - * Reserve DMA buffers. - * - * \param fd file descriptor. - * \param request - * - * \return zero on success, or a negative value on failure. - * - * \internal - * Assemble the arguments into a drm_dma structure and keeps issuing the - * DRM_IOCTL_DMA ioctl until success or until maximum number of retries. - */ -int drmDMA(int fd, drmDMAReqPtr request) -{ - drm_dma_t dma; - int ret, i = 0; - - /* Copy to hidden structure */ - dma.context = request->context; - dma.send_count = request->send_count; - dma.send_indices = request->send_list; - dma.send_sizes = request->send_sizes; - dma.flags = request->flags; - dma.request_count = request->request_count; - dma.request_size = request->request_size; - dma.request_indices = request->request_list; - dma.request_sizes = request->request_sizes; - dma.granted_count = 0; - - do { - ret = ioctl( fd, DRM_IOCTL_DMA, &dma ); - } while ( ret && errno == EAGAIN && i++ < DRM_DMA_RETRY ); - - if ( ret == 0 ) { - request->granted_count = dma.granted_count; - return 0; - } else { - return -errno; - } -} - - -/** - * Obtain heavyweight hardware lock. - * - * \param fd file descriptor. - * \param context context. - * \param flags flags that determine the sate of the hardware when the function - * returns. - * - * \return always zero. - * - * \internal - * This function translates the arguments into a drm_lock structure and issue - * the DRM_IOCTL_LOCK ioctl until the lock is successfully acquired. - */ -int drmGetLock(int fd, drm_context_t context, drmLockFlags flags) -{ - drm_lock_t lock; - - lock.context = context; - lock.flags = 0; - if (flags & DRM_LOCK_READY) lock.flags |= _DRM_LOCK_READY; - if (flags & DRM_LOCK_QUIESCENT) lock.flags |= _DRM_LOCK_QUIESCENT; - if (flags & DRM_LOCK_FLUSH) lock.flags |= _DRM_LOCK_FLUSH; - if (flags & DRM_LOCK_FLUSH_ALL) lock.flags |= _DRM_LOCK_FLUSH_ALL; - if (flags & DRM_HALT_ALL_QUEUES) lock.flags |= _DRM_HALT_ALL_QUEUES; - if (flags & DRM_HALT_CUR_QUEUES) lock.flags |= _DRM_HALT_CUR_QUEUES; - - while (ioctl(fd, DRM_IOCTL_LOCK, &lock)) - ; - return 0; -} - -/** - * Release the hardware lock. - * - * \param fd file descriptor. - * \param context context. - * - * \return zero on success, or a negative value on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_UNLOCK ioctl, passing the - * argument in a drm_lock structure. - */ -int drmUnlock(int fd, drm_context_t context) -{ - drm_lock_t lock; - - lock.context = context; - lock.flags = 0; - return ioctl(fd, DRM_IOCTL_UNLOCK, &lock); -} - -drm_context_t * drmGetReservedContextList(int fd, int *count) -{ - drm_ctx_res_t res; - drm_ctx_t *list; - drm_context_t * retval; - int i; - - res.count = 0; - res.contexts = NULL; - if (ioctl(fd, DRM_IOCTL_RES_CTX, &res)) return NULL; - - if (!res.count) return NULL; - - if (!(list = drmMalloc(res.count * sizeof(*list)))) return NULL; - if (!(retval = drmMalloc(res.count * sizeof(*retval)))) { - drmFree(list); - return NULL; - } - - res.contexts = list; - if (ioctl(fd, DRM_IOCTL_RES_CTX, &res)) return NULL; - - for (i = 0; i < res.count; i++) retval[i] = list[i].handle; - drmFree(list); - - *count = res.count; - return retval; -} - -void drmFreeReservedContextList(drm_context_t * pt) -{ - drmFree(pt); -} - -/** - * Create context. - * - * Used by the X server during GLXContext initialization. This causes - * per-context kernel-level resources to be allocated. - * - * \param fd file descriptor. - * \param handle is set on success. To be used by the client when requesting DMA - * dispatch with drmDMA(). - * - * \return zero on success, or a negative value on failure. - * - * \note May only be called by root. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_ADD_CTX ioctl, passing the - * argument in a drm_ctx structure. - */ -int drmCreateContext(int fd, drm_context_t * handle) -{ - drm_ctx_t ctx; - - ctx.flags = 0; /* Modified with functions below */ - if (ioctl(fd, DRM_IOCTL_ADD_CTX, &ctx)) return -errno; - *handle = ctx.handle; - return 0; -} - -int drmSwitchToContext(int fd, drm_context_t context) -{ - drm_ctx_t ctx; - - ctx.handle = context; - if (ioctl(fd, DRM_IOCTL_SWITCH_CTX, &ctx)) return -errno; - return 0; -} - -int drmSetContextFlags(int fd, drm_context_t context, drm_context_tFlags flags) -{ - drm_ctx_t ctx; - - /* Context preserving means that no context - switched are done between DMA buffers - from one context and the next. This is - suitable for use in the X server (which - promises to maintain hardware context, - or in the client-side library when - buffers are swapped on behalf of two - threads. */ - ctx.handle = context; - ctx.flags = 0; - if (flags & DRM_CONTEXT_PRESERVED) ctx.flags |= _DRM_CONTEXT_PRESERVED; - if (flags & DRM_CONTEXT_2DONLY) ctx.flags |= _DRM_CONTEXT_2DONLY; - if (ioctl(fd, DRM_IOCTL_MOD_CTX, &ctx)) return -errno; - return 0; -} - -int drmGetContextFlags(int fd, drm_context_t context, drm_context_tFlagsPtr flags) -{ - drm_ctx_t ctx; - - ctx.handle = context; - if (ioctl(fd, DRM_IOCTL_GET_CTX, &ctx)) return -errno; - *flags = 0; - if (ctx.flags & _DRM_CONTEXT_PRESERVED) *flags |= DRM_CONTEXT_PRESERVED; - if (ctx.flags & _DRM_CONTEXT_2DONLY) *flags |= DRM_CONTEXT_2DONLY; - return 0; -} - -/** - * Destroy context. - * - * Free any kernel-level resources allocated with drmCreateContext() associated - * with the context. - * - * \param fd file descriptor. - * \param handle handle given by drmCreateContext(). - * - * \return zero on success, or a negative value on failure. - * - * \note May only be called by root. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_RM_CTX ioctl, passing the - * argument in a drm_ctx structure. - */ -int drmDestroyContext(int fd, drm_context_t handle) -{ - drm_ctx_t ctx; - ctx.handle = handle; - if (ioctl(fd, DRM_IOCTL_RM_CTX, &ctx)) return -errno; - return 0; -} - -int drmCreateDrawable(int fd, drm_drawable_t * handle) -{ - drm_draw_t draw; - if (ioctl(fd, DRM_IOCTL_ADD_DRAW, &draw)) return -errno; - *handle = draw.handle; - return 0; -} - -int drmDestroyDrawable(int fd, drm_drawable_t handle) -{ - drm_draw_t draw; - draw.handle = handle; - if (ioctl(fd, DRM_IOCTL_RM_DRAW, &draw)) return -errno; - return 0; -} - -/** - * Acquire the AGP device. - * - * Must be called before any of the other AGP related calls. - * - * \param fd file descriptor. - * - * \return zero on success, or a negative value on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_AGP_ACQUIRE ioctl. - */ -int drmAgpAcquire(int fd) -{ - if (ioctl(fd, DRM_IOCTL_AGP_ACQUIRE, NULL)) return -errno; - return 0; -} - - -/** - * Release the AGP device. - * - * \param fd file descriptor. - * - * \return zero on success, or a negative value on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_AGP_RELEASE ioctl. - */ -int drmAgpRelease(int fd) -{ - if (ioctl(fd, DRM_IOCTL_AGP_RELEASE, NULL)) return -errno; - return 0; -} - - -/** - * Set the AGP mode. - * - * \param fd file descriptor. - * \param mode AGP mode. - * - * \return zero on success, or a negative value on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_AGP_ENABLE ioctl, passing the - * argument in a drm_agp_mode structure. - */ -int drmAgpEnable(int fd, unsigned long mode) -{ - drm_agp_mode_t m; - - m.mode = mode; - if (ioctl(fd, DRM_IOCTL_AGP_ENABLE, &m)) return -errno; - return 0; -} - - -/** - * Allocate a chunk of AGP memory. - * - * \param fd file descriptor. - * \param size requested memory size in bytes. Will be rounded to page boundary. - * \param type type of memory to allocate. - * \param address if not zero, will be set to the physical address of the - * allocated memory. - * \param handle on success will be set to a handle of the allocated memory. - * - * \return zero on success, or a negative value on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_AGP_ALLOC ioctl, passing the - * arguments in a drm_agp_buffer structure. - */ -int drmAgpAlloc(int fd, unsigned long size, unsigned long type, - unsigned long *address, unsigned long *handle) -{ - drm_agp_buffer_t b; - - *handle = DRM_AGP_NO_HANDLE; - b.size = size; - b.handle = 0; - b.type = type; - if (ioctl(fd, DRM_IOCTL_AGP_ALLOC, &b)) return -errno; - if (address != 0UL) *address = b.physical; - *handle = b.handle; - return 0; -} - - -/** - * Free a chunk of AGP memory. - * - * \param fd file descriptor. - * \param handle handle to the allocated memory, as given by drmAgpAllocate(). - * - * \return zero on success, or a negative value on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_AGP_FREE ioctl, passing the - * argument in a drm_agp_buffer structure. - */ -int drmAgpFree(int fd, unsigned long handle) -{ - drm_agp_buffer_t b; - - b.size = 0; - b.handle = handle; - if (ioctl(fd, DRM_IOCTL_AGP_FREE, &b)) return -errno; - return 0; -} - - -/** - * Bind a chunk of AGP memory. - * - * \param fd file descriptor. - * \param handle handle to the allocated memory, as given by drmAgpAllocate(). - * \param offset offset in bytes. It will round to page boundary. - * - * \return zero on success, or a negative value on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_AGP_BIND ioctl, passing the - * argument in a drm_agp_binding structure. - */ -int drmAgpBind(int fd, unsigned long handle, unsigned long offset) -{ - drm_agp_binding_t b; - - b.handle = handle; - b.offset = offset; - if (ioctl(fd, DRM_IOCTL_AGP_BIND, &b)) return -errno; - return 0; -} - - -/** - * Unbind a chunk of AGP memory. - * - * \param fd file descriptor. - * \param handle handle to the allocated memory, as given by drmAgpAllocate(). - * - * \return zero on success, or a negative value on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_AGP_UNBIND ioctl, passing - * the argument in a drm_agp_binding structure. - */ -int drmAgpUnbind(int fd, unsigned long handle) -{ - drm_agp_binding_t b; - - b.handle = handle; - b.offset = 0; - if (ioctl(fd, DRM_IOCTL_AGP_UNBIND, &b)) return -errno; - return 0; -} - - -/** - * Get AGP driver major version number. - * - * \param fd file descriptor. - * - * \return major version number on success, or a negative value on failure.. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the - * necessary information in a drm_agp_info structure. - */ -int drmAgpVersionMajor(int fd) -{ - drm_agp_info_t i; - - if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return -errno; - return i.agp_version_major; -} - - -/** - * Get AGP driver minor version number. - * - * \param fd file descriptor. - * - * \return minor version number on success, or a negative value on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the - * necessary information in a drm_agp_info structure. - */ -int drmAgpVersionMinor(int fd) -{ - drm_agp_info_t i; - - if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return -errno; - return i.agp_version_minor; -} - - -/** - * Get AGP mode. - * - * \param fd file descriptor. - * - * \return mode on success, or zero on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the - * necessary information in a drm_agp_info structure. - */ -unsigned long drmAgpGetMode(int fd) -{ - drm_agp_info_t i; - - if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0; - return i.mode; -} - - -/** - * Get AGP aperture base. - * - * \param fd file descriptor. - * - * \return aperture base on success, zero on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the - * necessary information in a drm_agp_info structure. - */ -unsigned long drmAgpBase(int fd) -{ - drm_agp_info_t i; - - if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0; - return i.aperture_base; -} - - -/** - * Get AGP aperture size. - * - * \param fd file descriptor. - * - * \return aperture size on success, zero on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the - * necessary information in a drm_agp_info structure. - */ -unsigned long drmAgpSize(int fd) -{ - drm_agp_info_t i; - - if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0; - return i.aperture_size; -} - - -/** - * Get used AGP memory. - * - * \param fd file descriptor. - * - * \return memory used on success, or zero on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the - * necessary information in a drm_agp_info structure. - */ -unsigned long drmAgpMemoryUsed(int fd) -{ - drm_agp_info_t i; - - if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0; - return i.memory_used; -} - - -/** - * Get available AGP memory. - * - * \param fd file descriptor. - * - * \return memory available on success, or zero on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the - * necessary information in a drm_agp_info structure. - */ -unsigned long drmAgpMemoryAvail(int fd) -{ - drm_agp_info_t i; - - if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0; - return i.memory_allowed; -} - - -/** - * Get hardware vendor ID. - * - * \param fd file descriptor. - * - * \return vendor ID on success, or zero on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the - * necessary information in a drm_agp_info structure. - */ -unsigned int drmAgpVendorId(int fd) -{ - drm_agp_info_t i; - - if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0; - return i.id_vendor; -} - - -/** - * Get hardware device ID. - * - * \param fd file descriptor. - * - * \return zero on success, or zero on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the - * necessary information in a drm_agp_info structure. - */ -unsigned int drmAgpDeviceId(int fd) -{ - drm_agp_info_t i; - - if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0; - return i.id_device; -} - -int drmScatterGatherAlloc(int fd, unsigned long size, unsigned long *handle) -{ - drm_scatter_gather_t sg; - - *handle = 0; - sg.size = size; - sg.handle = 0; - if (ioctl(fd, DRM_IOCTL_SG_ALLOC, &sg)) return -errno; - *handle = sg.handle; - return 0; -} - -int drmScatterGatherFree(int fd, unsigned long handle) -{ - drm_scatter_gather_t sg; - - sg.size = 0; - sg.handle = handle; - if (ioctl(fd, DRM_IOCTL_SG_FREE, &sg)) return -errno; - return 0; -} - -/** - * Wait for VBLANK. - * - * \param fd file descriptor. - * \param vbl pointer to a drmVBlank structure. - * - * \return zero on success, or a negative value on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_WAIT_VBLANK ioctl. - */ -int drmWaitVBlank(int fd, drmVBlankPtr vbl) -{ - int ret; - - do { - ret = ioctl(fd, DRM_IOCTL_WAIT_VBLANK, vbl); - vbl->request.type &= ~DRM_VBLANK_RELATIVE; - } while (ret && errno == EINTR); - - return ret; -} - -int drmError(int err, const char *label) -{ - switch (err) { - case DRM_ERR_NO_DEVICE: fprintf(stderr, "%s: no device\n", label); break; - case DRM_ERR_NO_ACCESS: fprintf(stderr, "%s: no access\n", label); break; - case DRM_ERR_NOT_ROOT: fprintf(stderr, "%s: not root\n", label); break; - case DRM_ERR_INVALID: fprintf(stderr, "%s: invalid args\n", label);break; - default: - if (err < 0) err = -err; - fprintf( stderr, "%s: error %d (%s)\n", label, err, strerror(err) ); - break; - } - - return 1; -} - -/** - * Install IRQ handler. - * - * \param fd file descriptor. - * \param irq IRQ number. - * - * \return zero on success, or a negative value on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_CONTROL ioctl, passing the - * argument in a drm_control structure. - */ -int drmCtlInstHandler(int fd, int irq) -{ - drm_control_t ctl; - - ctl.func = DRM_INST_HANDLER; - ctl.irq = irq; - if (ioctl(fd, DRM_IOCTL_CONTROL, &ctl)) return -errno; - return 0; -} - - -/** - * Uninstall IRQ handler. - * - * \param fd file descriptor. - * - * \return zero on success, or a negative value on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_CONTROL ioctl, passing the - * argument in a drm_control structure. - */ -int drmCtlUninstHandler(int fd) -{ - drm_control_t ctl; - - ctl.func = DRM_UNINST_HANDLER; - ctl.irq = 0; - if (ioctl(fd, DRM_IOCTL_CONTROL, &ctl)) return -errno; - return 0; -} - -int drmFinish(int fd, int context, drmLockFlags flags) -{ - drm_lock_t lock; - - lock.context = context; - lock.flags = 0; - if (flags & DRM_LOCK_READY) lock.flags |= _DRM_LOCK_READY; - if (flags & DRM_LOCK_QUIESCENT) lock.flags |= _DRM_LOCK_QUIESCENT; - if (flags & DRM_LOCK_FLUSH) lock.flags |= _DRM_LOCK_FLUSH; - if (flags & DRM_LOCK_FLUSH_ALL) lock.flags |= _DRM_LOCK_FLUSH_ALL; - if (flags & DRM_HALT_ALL_QUEUES) lock.flags |= _DRM_HALT_ALL_QUEUES; - if (flags & DRM_HALT_CUR_QUEUES) lock.flags |= _DRM_HALT_CUR_QUEUES; - if (ioctl(fd, DRM_IOCTL_FINISH, &lock)) return -errno; - return 0; -} - -/** - * Get IRQ from bus ID. - * - * \param fd file descriptor. - * \param busnum bus number. - * \param devnum device number. - * \param funcnum function number. - * - * \return IRQ number on success, or a negative value on failure. - * - * \internal - * This function is a wrapper around the DRM_IOCTL_IRQ_BUSID ioctl, passing the - * arguments in a drm_irq_busid structure. - */ -int drmGetInterruptFromBusID(int fd, int busnum, int devnum, int funcnum) -{ - drm_irq_busid_t p; - - p.busnum = busnum; - p.devnum = devnum; - p.funcnum = funcnum; - if (ioctl(fd, DRM_IOCTL_IRQ_BUSID, &p)) return -errno; - return p.irq; -} - -int drmAddContextTag(int fd, drm_context_t context, void *tag) -{ - drmHashEntry *entry = drmGetEntry(fd); - - if (drmHashInsert(entry->tagTable, context, tag)) { - drmHashDelete(entry->tagTable, context); - drmHashInsert(entry->tagTable, context, tag); - } - return 0; -} - -int drmDelContextTag(int fd, drm_context_t context) -{ - drmHashEntry *entry = drmGetEntry(fd); - - return drmHashDelete(entry->tagTable, context); -} - -void *drmGetContextTag(int fd, drm_context_t context) -{ - drmHashEntry *entry = drmGetEntry(fd); - void *value; - - if (drmHashLookup(entry->tagTable, context, &value)) return NULL; - - return value; -} - -int drmAddContextPrivateMapping(int fd, drm_context_t ctx_id, drm_handle_t handle) -{ - drm_ctx_priv_map_t map; - - map.ctx_id = ctx_id; - map.handle = (void *)handle; - - if (ioctl(fd, DRM_IOCTL_SET_SAREA_CTX, &map)) return -errno; - return 0; -} - -int drmGetContextPrivateMapping(int fd, drm_context_t ctx_id, drm_handle_t * handle) -{ - drm_ctx_priv_map_t map; - - map.ctx_id = ctx_id; - - if (ioctl(fd, DRM_IOCTL_GET_SAREA_CTX, &map)) return -errno; - if (handle) *handle = (drm_handle_t)map.handle; - - return 0; -} - -int drmGetMap(int fd, int idx, drm_handle_t *offset, drmSize *size, - drmMapType *type, drmMapFlags *flags, drm_handle_t *handle, - int *mtrr) -{ - drm_map_t map; - - map.offset = idx; - if (ioctl(fd, DRM_IOCTL_GET_MAP, &map)) return -errno; - *offset = map.offset; - *size = map.size; - *type = map.type; - *flags = map.flags; - *handle = (unsigned long)map.handle; - *mtrr = map.mtrr; - return 0; -} - -int drmGetClient(int fd, int idx, int *auth, int *pid, int *uid, - unsigned long *magic, unsigned long *iocs) -{ - drm_client_t client; - - client.idx = idx; - if (ioctl(fd, DRM_IOCTL_GET_CLIENT, &client)) return -errno; - *auth = client.auth; - *pid = client.pid; - *uid = client.uid; - *magic = client.magic; - *iocs = client.iocs; - return 0; -} - -int drmGetStats(int fd, drmStatsT *stats) -{ - drm_stats_t s; - int i; - - if (ioctl(fd, DRM_IOCTL_GET_STATS, &s)) return -errno; - - stats->count = 0; - memset(stats, 0, sizeof(*stats)); - if (s.count > sizeof(stats->data)/sizeof(stats->data[0])) - return -1; - -#define SET_VALUE \ - stats->data[i].long_format = "%-20.20s"; \ - stats->data[i].rate_format = "%8.8s"; \ - stats->data[i].isvalue = 1; \ - stats->data[i].verbose = 0 - -#define SET_COUNT \ - stats->data[i].long_format = "%-20.20s"; \ - stats->data[i].rate_format = "%5.5s"; \ - stats->data[i].isvalue = 0; \ - stats->data[i].mult_names = "kgm"; \ - stats->data[i].mult = 1000; \ - stats->data[i].verbose = 0 - -#define SET_BYTE \ - stats->data[i].long_format = "%-20.20s"; \ - stats->data[i].rate_format = "%5.5s"; \ - stats->data[i].isvalue = 0; \ - stats->data[i].mult_names = "KGM"; \ - stats->data[i].mult = 1024; \ - stats->data[i].verbose = 0 - - - stats->count = s.count; - for (i = 0; i < s.count; i++) { - stats->data[i].value = s.data[i].value; - switch (s.data[i].type) { - case _DRM_STAT_LOCK: - stats->data[i].long_name = "Lock"; - stats->data[i].rate_name = "Lock"; - SET_VALUE; - break; - case _DRM_STAT_OPENS: - stats->data[i].long_name = "Opens"; - stats->data[i].rate_name = "O"; - SET_COUNT; - stats->data[i].verbose = 1; - break; - case _DRM_STAT_CLOSES: - stats->data[i].long_name = "Closes"; - stats->data[i].rate_name = "Lock"; - SET_COUNT; - stats->data[i].verbose = 1; - break; - case _DRM_STAT_IOCTLS: - stats->data[i].long_name = "Ioctls"; - stats->data[i].rate_name = "Ioc/s"; - SET_COUNT; - break; - case _DRM_STAT_LOCKS: - stats->data[i].long_name = "Locks"; - stats->data[i].rate_name = "Lck/s"; - SET_COUNT; - break; - case _DRM_STAT_UNLOCKS: - stats->data[i].long_name = "Unlocks"; - stats->data[i].rate_name = "Unl/s"; - SET_COUNT; - break; - case _DRM_STAT_IRQ: - stats->data[i].long_name = "IRQs"; - stats->data[i].rate_name = "IRQ/s"; - SET_COUNT; - break; - case _DRM_STAT_PRIMARY: - stats->data[i].long_name = "Primary Bytes"; - stats->data[i].rate_name = "PB/s"; - SET_BYTE; - break; - case _DRM_STAT_SECONDARY: - stats->data[i].long_name = "Secondary Bytes"; - stats->data[i].rate_name = "SB/s"; - SET_BYTE; - break; - case _DRM_STAT_DMA: - stats->data[i].long_name = "DMA"; - stats->data[i].rate_name = "DMA/s"; - SET_COUNT; - break; - case _DRM_STAT_SPECIAL: - stats->data[i].long_name = "Special DMA"; - stats->data[i].rate_name = "dma/s"; - SET_COUNT; - break; - case _DRM_STAT_MISSED: - stats->data[i].long_name = "Miss"; - stats->data[i].rate_name = "Ms/s"; - SET_COUNT; - break; - case _DRM_STAT_VALUE: - stats->data[i].long_name = "Value"; - stats->data[i].rate_name = "Value"; - SET_VALUE; - break; - case _DRM_STAT_BYTE: - stats->data[i].long_name = "Bytes"; - stats->data[i].rate_name = "B/s"; - SET_BYTE; - break; - case _DRM_STAT_COUNT: - default: - stats->data[i].long_name = "Count"; - stats->data[i].rate_name = "Cnt/s"; - SET_COUNT; - break; - } - } - return 0; -} - -/** - * Issue a set-version ioctl. - * - * \param fd file descriptor. - * \param drmCommandIndex command index - * \param data source pointer of the data to be read and written. - * \param size size of the data to be read and written. - * - * \return zero on success, or a negative value on failure. - * - * \internal - * It issues a read-write ioctl given by - * \code DRM_COMMAND_BASE + drmCommandIndex \endcode. - */ -int drmSetInterfaceVersion(int fd, drmSetVersion *version ) -{ - int retcode = 0; - drm_set_version_t sv; - - sv.drm_di_major = version->drm_di_major; - sv.drm_di_minor = version->drm_di_minor; - sv.drm_dd_major = version->drm_dd_major; - sv.drm_dd_minor = version->drm_dd_minor; - - if (ioctl(fd, DRM_IOCTL_SET_VERSION, &sv)) { - retcode = -errno; - } - - version->drm_di_major = sv.drm_di_major; - version->drm_di_minor = sv.drm_di_minor; - version->drm_dd_major = sv.drm_dd_major; - version->drm_dd_minor = sv.drm_dd_minor; - - return retcode; -} - -/** - * Send a device-specific command. - * - * \param fd file descriptor. - * \param drmCommandIndex command index - * - * \return zero on success, or a negative value on failure. - * - * \internal - * It issues a ioctl given by - * \code DRM_COMMAND_BASE + drmCommandIndex \endcode. - */ -int drmCommandNone(int fd, unsigned long drmCommandIndex) -{ - void *data = NULL; /* dummy */ - unsigned long request; - - request = DRM_IO( DRM_COMMAND_BASE + drmCommandIndex); - - if (ioctl(fd, request, data)) { - return -errno; - } - return 0; -} - - -/** - * Send a device-specific read command. - * - * \param fd file descriptor. - * \param drmCommandIndex command index - * \param data destination pointer of the data to be read. - * \param size size of the data to be read. - * - * \return zero on success, or a negative value on failure. - * - * \internal - * It issues a read ioctl given by - * \code DRM_COMMAND_BASE + drmCommandIndex \endcode. - */ -int drmCommandRead(int fd, unsigned long drmCommandIndex, - void *data, unsigned long size ) -{ - unsigned long request; - - request = DRM_IOC( DRM_IOC_READ, DRM_IOCTL_BASE, - DRM_COMMAND_BASE + drmCommandIndex, size); - - if (ioctl(fd, request, data)) { - return -errno; - } - return 0; -} - - -/** - * Send a device-specific write command. - * - * \param fd file descriptor. - * \param drmCommandIndex command index - * \param data source pointer of the data to be written. - * \param size size of the data to be written. - * - * \return zero on success, or a negative value on failure. - * - * \internal - * It issues a write ioctl given by - * \code DRM_COMMAND_BASE + drmCommandIndex \endcode. - */ -int drmCommandWrite(int fd, unsigned long drmCommandIndex, - void *data, unsigned long size ) -{ - unsigned long request; - - request = DRM_IOC( DRM_IOC_WRITE, DRM_IOCTL_BASE, - DRM_COMMAND_BASE + drmCommandIndex, size); - - if (ioctl(fd, request, data)) { - return -errno; - } - return 0; -} - - -/** - * Send a device-specific read-write command. - * - * \param fd file descriptor. - * \param drmCommandIndex command index - * \param data source pointer of the data to be read and written. - * \param size size of the data to be read and written. - * - * \return zero on success, or a negative value on failure. - * - * \internal - * It issues a read-write ioctl given by - * \code DRM_COMMAND_BASE + drmCommandIndex \endcode. - */ -int drmCommandWriteRead(int fd, unsigned long drmCommandIndex, - void *data, unsigned long size ) -{ - unsigned long request; - - request = DRM_IOC( DRM_IOC_READ|DRM_IOC_WRITE, DRM_IOCTL_BASE, - DRM_COMMAND_BASE + drmCommandIndex, size); - - if (ioctl(fd, request, data)) { - return -errno; - } - return 0; -} - -#if defined(XFree86Server) -static void drmSIGIOHandler(int interrupt, void *closure) -{ - unsigned long key; - void *value; - ssize_t count; - drm_ctx_t ctx; - typedef void (*_drmCallback)(int, void *, void *); - char buf[256]; - drm_context_t old; - drm_context_t new; - void *oldctx; - void *newctx; - char *pt; - drmHashEntry *entry; - - if (!drmHashTable) return; - if (drmHashFirst(drmHashTable, &key, &value)) { - entry = value; - do { -#if 0 - fprintf(stderr, "Trying %d\n", entry->fd); -#endif - if ((count = read(entry->fd, buf, sizeof(buf))) > 0) { - buf[count] = '\0'; -#if 0 - fprintf(stderr, "Got %s\n", buf); -#endif - - for (pt = buf; *pt != ' '; ++pt); /* Find first space */ - ++pt; - old = strtol(pt, &pt, 0); - new = strtol(pt, NULL, 0); - oldctx = drmGetContextTag(entry->fd, old); - newctx = drmGetContextTag(entry->fd, new); -#if 0 - fprintf(stderr, "%d %d %p %p\n", old, new, oldctx, newctx); -#endif - ((_drmCallback)entry->f)(entry->fd, oldctx, newctx); - ctx.handle = new; - ioctl(entry->fd, DRM_IOCTL_NEW_CTX, &ctx); - } - } while (drmHashNext(drmHashTable, &key, &value)); - } -} - -int drmInstallSIGIOHandler(int fd, void (*f)(int, void *, void *)) -{ - drmHashEntry *entry; - - entry = drmGetEntry(fd); - entry->f = f; - - return xf86InstallSIGIOHandler(fd, drmSIGIOHandler, 0); -} - -int drmRemoveSIGIOHandler(int fd) -{ - drmHashEntry *entry = drmGetEntry(fd); - - entry->f = NULL; - - return xf86RemoveSIGIOHandler(fd); -} -#endif diff --git a/src/mesa/drivers/dri/dri_client/xf86drmHash.c b/src/mesa/drivers/dri/dri_client/xf86drmHash.c deleted file mode 100644 index 5f89d540dc2..00000000000 --- a/src/mesa/drivers/dri/dri_client/xf86drmHash.c +++ /dev/null @@ -1,433 +0,0 @@ -/* xf86drmHash.c -- Small hash table support for integer -> integer mapping - * Created: Sun Apr 18 09:35:45 1999 by [email protected] - * - * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. - * 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 (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 NONINFRINGEMENT. IN NO EVENT SHALL - * PRECISION INSIGHT 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: Rickard E. (Rik) Faith <[email protected]> - * - * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmHash.c,v 1.4 2001/03/21 18:08:54 dawes Exp $ - * - * DESCRIPTION - * - * This file contains a straightforward implementation of a fixed-sized - * hash table using self-organizing linked lists [Knuth73, pp. 398-399] for - * collision resolution. There are two potentially interesting things - * about this implementation: - * - * 1) The table is power-of-two sized. Prime sized tables are more - * traditional, but do not have a significant advantage over power-of-two - * sized table, especially when double hashing is not used for collision - * resolution. - * - * 2) The hash computation uses a table of random integers [Hanson97, - * pp. 39-41]. - * - * FUTURE ENHANCEMENTS - * - * With a table size of 512, the current implementation is sufficient for a - * few hundred keys. Since this is well above the expected size of the - * tables for which this implementation was designed, the implementation of - * dynamic hash tables was postponed until the need arises. A common (and - * naive) approach to dynamic hash table implementation simply creates a - * new hash table when necessary, rehashes all the data into the new table, - * and destroys the old table. The approach in [Larson88] is superior in - * two ways: 1) only a portion of the table is expanded when needed, - * distributing the expansion cost over several insertions, and 2) portions - * of the table can be locked, enabling a scalable thread-safe - * implementation. - * - * REFERENCES - * - * [Hanson97] David R. Hanson. C Interfaces and Implementations: - * Techniques for Creating Reusable Software. Reading, Massachusetts: - * Addison-Wesley, 1997. - * - * [Knuth73] Donald E. Knuth. The Art of Computer Programming. Volume 3: - * Sorting and Searching. Reading, Massachusetts: Addison-Wesley, 1973. - * - * [Larson88] Per-Ake Larson. "Dynamic Hash Tables". CACM 31(4), April - * 1988, pp. 446-457. - * - */ - -#define HASH_MAIN 0 - -#if HASH_MAIN -# include <stdio.h> -# include <stdlib.h> -#else -# include "xf86drm.h" -# ifdef XFree86LOADER -# include "xf86.h" -# include "xf86_ansic.h" -# else -# include <stdio.h> -# include <stdlib.h> -# endif -#endif - -#define HASH_MAGIC 0xdeadbeef -#define HASH_DEBUG 0 -#define HASH_SIZE 512 /* Good for about 100 entries */ - /* If you change this value, you probably - have to change the HashHash hashing - function! */ - -#if HASH_MAIN -#define HASH_ALLOC malloc -#define HASH_FREE free -#define HASH_RANDOM_DECL -#define HASH_RANDOM_INIT(seed) srandom(seed) -#define HASH_RANDOM random() -#else -#define HASH_ALLOC drmMalloc -#define HASH_FREE drmFree -#define HASH_RANDOM_DECL void *state -#define HASH_RANDOM_INIT(seed) state = drmRandomCreate(seed) -#define HASH_RANDOM drmRandom(state) - -#endif - -typedef struct HashBucket { - unsigned long key; - void *value; - struct HashBucket *next; -} HashBucket, *HashBucketPtr; - -typedef struct HashTable { - unsigned long magic; - unsigned long entries; - unsigned long hits; /* At top of linked list */ - unsigned long partials; /* Not at top of linked list */ - unsigned long misses; /* Not in table */ - HashBucketPtr buckets[HASH_SIZE]; - int p0; - HashBucketPtr p1; -} HashTable, *HashTablePtr; - -#if HASH_MAIN -extern void *drmHashCreate(void); -extern int drmHashDestroy(void *t); -extern int drmHashLookup(void *t, unsigned long key, unsigned long *value); -extern int drmHashInsert(void *t, unsigned long key, unsigned long value); -extern int drmHashDelete(void *t, unsigned long key); -#endif - -static unsigned long HashHash(unsigned long key) -{ - unsigned long hash = 0; - unsigned long tmp = key; - static int init = 0; - static unsigned long scatter[256]; - int i; - - if (!init) { - HASH_RANDOM_DECL; - HASH_RANDOM_INIT(37); - for (i = 0; i < 256; i++) scatter[i] = HASH_RANDOM; - ++init; - } - - while (tmp) { - hash = (hash << 1) + scatter[tmp & 0xff]; - tmp >>= 8; - } - - hash %= HASH_SIZE; -#if HASH_DEBUG - printf( "Hash(%d) = %d\n", key, hash); -#endif - return hash; -} - -void *drmHashCreate(void) -{ - HashTablePtr table; - int i; - - table = HASH_ALLOC(sizeof(*table)); - if (!table) return NULL; - table->magic = HASH_MAGIC; - table->entries = 0; - table->hits = 0; - table->partials = 0; - table->misses = 0; - - for (i = 0; i < HASH_SIZE; i++) table->buckets[i] = NULL; - return table; -} - -int drmHashDestroy(void *t) -{ - HashTablePtr table = (HashTablePtr)t; - HashBucketPtr bucket; - HashBucketPtr next; - int i; - - if (table->magic != HASH_MAGIC) return -1; /* Bad magic */ - - for (i = 0; i < HASH_SIZE; i++) { - for (bucket = table->buckets[i]; bucket;) { - next = bucket->next; - HASH_FREE(bucket); - bucket = next; - } - } - HASH_FREE(table); - return 0; -} - -/* Find the bucket and organize the list so that this bucket is at the - top. */ - -static HashBucketPtr HashFind(HashTablePtr table, - unsigned long key, unsigned long *h) -{ - unsigned long hash = HashHash(key); - HashBucketPtr prev = NULL; - HashBucketPtr bucket; - - if (h) *h = hash; - - for (bucket = table->buckets[hash]; bucket; bucket = bucket->next) { - if (bucket->key == key) { - if (prev) { - /* Organize */ - prev->next = bucket->next; - bucket->next = table->buckets[hash]; - table->buckets[hash] = bucket; - ++table->partials; - } else { - ++table->hits; - } - return bucket; - } - prev = bucket; - } - ++table->misses; - return NULL; -} - -int drmHashLookup(void *t, unsigned long key, void **value) -{ - HashTablePtr table = (HashTablePtr)t; - HashBucketPtr bucket; - - if (!table || table->magic != HASH_MAGIC) return -1; /* Bad magic */ - - bucket = HashFind(table, key, NULL); - if (!bucket) return 1; /* Not found */ - *value = bucket->value; - return 0; /* Found */ -} - -int drmHashInsert(void *t, unsigned long key, void *value) -{ - HashTablePtr table = (HashTablePtr)t; - HashBucketPtr bucket; - unsigned long hash; - - if (table->magic != HASH_MAGIC) return -1; /* Bad magic */ - - if (HashFind(table, key, &hash)) return 1; /* Already in table */ - - bucket = HASH_ALLOC(sizeof(*bucket)); - if (!bucket) return -1; /* Error */ - bucket->key = key; - bucket->value = value; - bucket->next = table->buckets[hash]; - table->buckets[hash] = bucket; -#if HASH_DEBUG - printf("Inserted %d at %d/%p\n", key, hash, bucket); -#endif - return 0; /* Added to table */ -} - -int drmHashDelete(void *t, unsigned long key) -{ - HashTablePtr table = (HashTablePtr)t; - unsigned long hash; - HashBucketPtr bucket; - - if (table->magic != HASH_MAGIC) return -1; /* Bad magic */ - - bucket = HashFind(table, key, &hash); - - if (!bucket) return 1; /* Not found */ - - table->buckets[hash] = bucket->next; - HASH_FREE(bucket); - return 0; -} - -int drmHashNext(void *t, unsigned long *key, void **value) -{ - HashTablePtr table = (HashTablePtr)t; - - for (; table->p0 < HASH_SIZE; - ++table->p0, table->p1 = table->buckets[table->p0]) { - if (table->p1) { - *key = table->p1->key; - *value = table->p1->value; - table->p1 = table->p1->next; - return 1; - } - } - return 0; -} - -int drmHashFirst(void *t, unsigned long *key, void **value) -{ - HashTablePtr table = (HashTablePtr)t; - - if (table->magic != HASH_MAGIC) return -1; /* Bad magic */ - - table->p0 = 0; - table->p1 = table->buckets[0]; - return drmHashNext(table, key, value); -} - -#if HASH_MAIN -#define DIST_LIMIT 10 -static int dist[DIST_LIMIT]; - -static void clear_dist(void) { - int i; - - for (i = 0; i < DIST_LIMIT; i++) dist[i] = 0; -} - -static int count_entries(HashBucketPtr bucket) -{ - int count = 0; - - for (; bucket; bucket = bucket->next) ++count; - return count; -} - -static void update_dist(int count) -{ - if (count >= DIST_LIMIT) ++dist[DIST_LIMIT-1]; - else ++dist[count]; -} - -static void compute_dist(HashTablePtr table) -{ - int i; - HashBucketPtr bucket; - - printf("Entries = %ld, hits = %ld, partials = %ld, misses = %ld\n", - table->entries, table->hits, table->partials, table->misses); - clear_dist(); - for (i = 0; i < HASH_SIZE; i++) { - bucket = table->buckets[i]; - update_dist(count_entries(bucket)); - } - for (i = 0; i < DIST_LIMIT; i++) { - if (i != DIST_LIMIT-1) printf("%5d %10d\n", i, dist[i]); - else printf("other %10d\n", dist[i]); - } -} - -static void check_table(HashTablePtr table, - unsigned long key, unsigned long value) -{ - unsigned long retval = 0; - int retcode = drmHashLookup(table, key, &retval); - - switch (retcode) { - case -1: - printf("Bad magic = 0x%08lx:" - " key = %lu, expected = %lu, returned = %lu\n", - table->magic, key, value, retval); - break; - case 1: - printf("Not found: key = %lu, expected = %lu returned = %lu\n", - key, value, retval); - break; - case 0: - if (value != retval) - printf("Bad value: key = %lu, expected = %lu, returned = %lu\n", - key, value, retval); - break; - default: - printf("Bad retcode = %d: key = %lu, expected = %lu, returned = %lu\n", - retcode, key, value, retval); - break; - } -} - -int main(void) -{ - HashTablePtr table; - int i; - - printf("\n***** 256 consecutive integers ****\n"); - table = drmHashCreate(); - for (i = 0; i < 256; i++) drmHashInsert(table, i, i); - for (i = 0; i < 256; i++) check_table(table, i, i); - for (i = 256; i >= 0; i--) check_table(table, i, i); - compute_dist(table); - drmHashDestroy(table); - - printf("\n***** 1024 consecutive integers ****\n"); - table = drmHashCreate(); - for (i = 0; i < 1024; i++) drmHashInsert(table, i, i); - for (i = 0; i < 1024; i++) check_table(table, i, i); - for (i = 1024; i >= 0; i--) check_table(table, i, i); - compute_dist(table); - drmHashDestroy(table); - - printf("\n***** 1024 consecutive page addresses (4k pages) ****\n"); - table = drmHashCreate(); - for (i = 0; i < 1024; i++) drmHashInsert(table, i*4096, i); - for (i = 0; i < 1024; i++) check_table(table, i*4096, i); - for (i = 1024; i >= 0; i--) check_table(table, i*4096, i); - compute_dist(table); - drmHashDestroy(table); - - printf("\n***** 1024 random integers ****\n"); - table = drmHashCreate(); - srandom(0xbeefbeef); - for (i = 0; i < 1024; i++) drmHashInsert(table, random(), i); - srandom(0xbeefbeef); - for (i = 0; i < 1024; i++) check_table(table, random(), i); - srandom(0xbeefbeef); - for (i = 0; i < 1024; i++) check_table(table, random(), i); - compute_dist(table); - drmHashDestroy(table); - - printf("\n***** 5000 random integers ****\n"); - table = drmHashCreate(); - srandom(0xbeefbeef); - for (i = 0; i < 5000; i++) drmHashInsert(table, random(), i); - srandom(0xbeefbeef); - for (i = 0; i < 5000; i++) check_table(table, random(), i); - srandom(0xbeefbeef); - for (i = 0; i < 5000; i++) check_table(table, random(), i); - compute_dist(table); - drmHashDestroy(table); - - return 0; -} -#endif diff --git a/src/mesa/drivers/dri/dri_client/xf86drmRandom.c b/src/mesa/drivers/dri/dri_client/xf86drmRandom.c deleted file mode 100644 index cca831d7517..00000000000 --- a/src/mesa/drivers/dri/dri_client/xf86drmRandom.c +++ /dev/null @@ -1,217 +0,0 @@ -/* xf86drmRandom.c -- "Minimal Standard" PRNG Implementation - * Created: Mon Apr 19 08:28:13 1999 by [email protected] - * - * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. - * 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 (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 NONINFRINGEMENT. IN NO EVENT SHALL - * PRECISION INSIGHT 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: Rickard E. (Rik) Faith <[email protected]> - * - * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmRandom.c,v 1.4 2000/06/17 00:03:34 martin Exp $ - * - * DESCRIPTION - * - * This file contains a simple, straightforward implementation of the Park - * & Miller "Minimal Standard" PRNG [PM88, PMS93], which is a Lehmer - * multiplicative linear congruential generator (MLCG) with a period of - * 2^31-1. - * - * This implementation is intended to provide a reliable, portable PRNG - * that is suitable for testing a hash table implementation and for - * implementing skip lists. - * - * FUTURE ENHANCEMENTS - * - * If initial seeds are not selected randomly, two instances of the PRNG - * can be correlated. [Knuth81, pp. 32-33] describes a shuffling technique - * that can eliminate this problem. - * - * If PRNGs are used for simulation, the period of the current - * implementation may be too short. [LE88] discusses methods of combining - * MLCGs to produce much longer periods, and suggests some alternative - * values for A and M. [LE90 and Sch92] also provide information on - * long-period PRNGs. - * - * REFERENCES - * - * [Knuth81] Donald E. Knuth. The Art of Computer Programming. Volume 2: - * Seminumerical Algorithms. Reading, Massachusetts: Addison-Wesley, 1981. - * - * [LE88] Pierre L'Ecuyer. "Efficient and Portable Combined Random Number - * Generators". CACM 31(6), June 1988, pp. 742-774. - * - * [LE90] Pierre L'Ecuyer. "Random Numbers for Simulation". CACM 33(10, - * October 1990, pp. 85-97. - * - * [PM88] Stephen K. Park and Keith W. Miller. "Random Number Generators: - * Good Ones are Hard to Find". CACM 31(10), October 1988, pp. 1192-1201. - * - * [Sch92] Bruce Schneier. "Pseudo-Ransom Sequence Generator for 32-Bit - * CPUs". Dr. Dobb's Journal 17(2), February 1992, pp. 34, 37-38, 40. - * - * [PMS93] Stephen K. Park, Keith W. Miller, and Paul K. Stockmeyer. In - * "Technical Correspondence: Remarks on Choosing and Implementing Random - * Number Generators". CACM 36(7), July 1993, pp. 105-110. - * - */ - -#define RANDOM_MAIN 0 - -#if RANDOM_MAIN -# include <stdio.h> -# include <stdlib.h> -#else -# include "xf86drm.h" -# ifdef XFree86LOADER -# include "xf86.h" -# include "xf86_ansic.h" -# else -# include <stdio.h> -# include <stdlib.h> -# endif -#endif - -#define RANDOM_MAGIC 0xfeedbeef -#define RANDOM_DEBUG 0 - -#if RANDOM_MAIN -#define RANDOM_ALLOC malloc -#define RANDOM_FREE free -#else -#define RANDOM_ALLOC drmMalloc -#define RANDOM_FREE drmFree -#endif - -typedef struct RandomState { - unsigned long magic; - unsigned long a; - unsigned long m; - unsigned long q; /* m div a */ - unsigned long r; /* m mod a */ - unsigned long check; - long seed; -} RandomState; - -#if RANDOM_MAIN -extern void *drmRandomCreate(unsigned long seed); -extern int drmRandomDestroy(void *state); -extern unsigned long drmRandom(void *state); -extern double drmRandomDouble(void *state); -#endif - -void *drmRandomCreate(unsigned long seed) -{ - RandomState *state; - - state = RANDOM_ALLOC(sizeof(*state)); - if (!state) return NULL; - state->magic = RANDOM_MAGIC; -#if 0 - /* Park & Miller, October 1988 */ - state->a = 16807; - state->m = 2147483647; - state->check = 1043618065; /* After 10000 iterations */ -#else - /* Park, Miller, and Stockmeyer, July 1993 */ - state->a = 48271; - state->m = 2147483647; - state->check = 399268537; /* After 10000 iterations */ -#endif - state->q = state->m / state->a; - state->r = state->m % state->a; - - state->seed = seed; - /* Check for illegal boundary conditions, - and choose closest legal value. */ - if (state->seed <= 0) state->seed = 1; - if (state->seed >= state->m) state->seed = state->m - 1; - - return state; -} - -int drmRandomDestroy(void *state) -{ - RANDOM_FREE(state); - return 0; -} - -unsigned long drmRandom(void *state) -{ - RandomState *s = (RandomState *)state; - long hi; - long lo; - - hi = s->seed / s->q; - lo = s->seed % s->q; - s->seed = s->a * lo - s->r * hi; - if (s->seed <= 0) s->seed += s->m; - - return s->seed; -} - -double drmRandomDouble(void *state) -{ - RandomState *s = (RandomState *)state; - - return (double)drmRandom(state)/(double)s->m; -} - -#if RANDOM_MAIN -static void check_period(long seed) -{ - unsigned long count = 0; - unsigned long initial; - void *state; - - state = drmRandomCreate(seed); - initial = drmRandom(state); - ++count; - while (initial != drmRandom(state)) { - if (!++count) break; - } - printf("With seed of %10ld, period = %10lu (0x%08lx)\n", - seed, count, count); - drmRandomDestroy(state); -} - -int main(void) -{ - RandomState *state; - int i; - unsigned long rand; - - state = drmRandomCreate(1); - for (i = 0; i < 10000; i++) { - rand = drmRandom(state); - } - printf("After 10000 iterations: %lu (%lu expected): %s\n", - rand, state->check, - rand - state->check ? "*INCORRECT*" : "CORRECT"); - drmRandomDestroy(state); - - printf("Checking periods...\n"); - check_period(1); - check_period(2); - check_period(31415926); - - return 0; -} -#endif diff --git a/src/mesa/drivers/dri/dri_client/xf86drmSL.c b/src/mesa/drivers/dri/dri_client/xf86drmSL.c deleted file mode 100644 index a9d64c920f0..00000000000 --- a/src/mesa/drivers/dri/dri_client/xf86drmSL.c +++ /dev/null @@ -1,488 +0,0 @@ -/* xf86drmSL.c -- Skip list support - * Created: Mon May 10 09:28:13 1999 by [email protected] - * - * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. - * 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 (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 NONINFRINGEMENT. IN NO EVENT SHALL - * PRECISION INSIGHT 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: Rickard E. (Rik) Faith <[email protected]> - * - * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmSL.c,v 1.3 2000/06/17 00:03:34 martin Exp $ - * - * DESCRIPTION - * - * This file contains a straightforward skip list implementation.n - * - * FUTURE ENHANCEMENTS - * - * REFERENCES - * - * [Pugh90] William Pugh. Skip Lists: A Probabilistic Alternative to - * Balanced Trees. CACM 33(6), June 1990, pp. 668-676. - * - */ - -#define SL_MAIN 0 - -#if SL_MAIN -# include <stdio.h> -# include <stdlib.h> -# include <sys/time.h> -#else -# include "xf86drm.h" -# ifdef XFree86LOADER -# include "xf86.h" -# include "xf86_ansic.h" -# else -# include <stdio.h> -# include <stdlib.h> -# endif -#endif - -#define SL_LIST_MAGIC 0xfacade00LU -#define SL_ENTRY_MAGIC 0x00fab1edLU -#define SL_FREED_MAGIC 0xdecea5edLU -#define SL_MAX_LEVEL 16 -#define SL_DEBUG 0 -#define SL_RANDOM_SEED 0xc01055a1LU - -#if SL_MAIN -#define SL_ALLOC malloc -#define SL_FREE free -#define SL_RANDOM_DECL static int state = 0; -#define SL_RANDOM_INIT(seed) if (!state) { srandom(seed); ++state; } -#define SL_RANDOM random() -#else -#define SL_ALLOC drmMalloc -#define SL_FREE drmFree -#define SL_RANDOM_DECL static void *state = NULL -#define SL_RANDOM_INIT(seed) if (!state) state = drmRandomCreate(seed) -#define SL_RANDOM drmRandom(state) - -#endif - -typedef struct SLEntry { - unsigned long magic; /* SL_ENTRY_MAGIC */ - unsigned long key; - void *value; - int levels; - struct SLEntry *forward[1]; /* variable sized array */ -} SLEntry, *SLEntryPtr; - -typedef struct SkipList { - unsigned long magic; /* SL_LIST_MAGIC */ - int level; - int count; - SLEntryPtr head; - SLEntryPtr p0; /* Position for iteration */ -} SkipList, *SkipListPtr; - -#if SL_MAIN -extern void *drmSLCreate(void); -extern int drmSLDestroy(void *l); -extern int drmSLLookup(void *l, unsigned long key, void **value); -extern int drmSLInsert(void *l, unsigned long key, void *value); -extern int drmSLDelete(void *l, unsigned long key); -extern int drmSLNext(void *l, unsigned long *key, void **value); -extern int drmSLFirst(void *l, unsigned long *key, void **value); -extern void drmSLDump(void *l); -extern int drmSLLookupNeighbors(void *l, unsigned long key, - unsigned long *prev_key, void **prev_value, - unsigned long *next_key, void **next_value); -#endif - -static SLEntryPtr SLCreateEntry(int max_level, unsigned long key, void *value) -{ - SLEntryPtr entry; - - if (max_level < 0 || max_level > SL_MAX_LEVEL) max_level = SL_MAX_LEVEL; - - entry = SL_ALLOC(sizeof(*entry) - + (max_level + 1) * sizeof(entry->forward[0])); - if (!entry) return NULL; - entry->magic = SL_ENTRY_MAGIC; - entry->key = key; - entry->value = value; - entry->levels = max_level + 1; - - return entry; -} - -static int SLRandomLevel(void) -{ - int level = 1; - SL_RANDOM_DECL; - - SL_RANDOM_INIT(SL_RANDOM_SEED); - - while ((SL_RANDOM & 0x01) && level < SL_MAX_LEVEL) ++level; - return level; -} - -void *drmSLCreate(void) -{ - SkipListPtr list; - int i; - - list = SL_ALLOC(sizeof(*list)); - if (!list) return NULL; - list->magic = SL_LIST_MAGIC; - list->level = 0; - list->head = SLCreateEntry(SL_MAX_LEVEL, 0, NULL); - list->count = 0; - - for (i = 0; i <= SL_MAX_LEVEL; i++) list->head->forward[i] = NULL; - - return list; -} - -int drmSLDestroy(void *l) -{ - SkipListPtr list = (SkipListPtr)l; - SLEntryPtr entry; - SLEntryPtr next; - - if (list->magic != SL_LIST_MAGIC) return -1; /* Bad magic */ - - for (entry = list->head; entry; entry = next) { - if (entry->magic != SL_ENTRY_MAGIC) return -1; /* Bad magic */ - next = entry->forward[0]; - entry->magic = SL_FREED_MAGIC; - SL_FREE(entry); - } - - list->magic = SL_FREED_MAGIC; - SL_FREE(list); - return 0; -} - -static SLEntryPtr SLLocate(void *l, unsigned long key, SLEntryPtr *update) -{ - SkipListPtr list = (SkipListPtr)l; - SLEntryPtr entry; - int i; - - if (list->magic != SL_LIST_MAGIC) return NULL; - - for (i = list->level, entry = list->head; i >= 0; i--) { - while (entry->forward[i] && entry->forward[i]->key < key) - entry = entry->forward[i]; - update[i] = entry; - } - - return entry->forward[0]; -} - -int drmSLInsert(void *l, unsigned long key, void *value) -{ - SkipListPtr list = (SkipListPtr)l; - SLEntryPtr entry; - SLEntryPtr update[SL_MAX_LEVEL + 1]; - int level; - int i; - - if (list->magic != SL_LIST_MAGIC) return -1; /* Bad magic */ - - entry = SLLocate(list, key, update); - - if (entry && entry->key == key) return 1; /* Already in list */ - - - level = SLRandomLevel(); - if (level > list->level) { - level = ++list->level; - update[level] = list->head; - } - - entry = SLCreateEntry(level, key, value); - - /* Fix up forward pointers */ - for (i = 0; i <= level; i++) { - entry->forward[i] = update[i]->forward[i]; - update[i]->forward[i] = entry; - } - - ++list->count; - return 0; /* Added to table */ -} - -int drmSLDelete(void *l, unsigned long key) -{ - SkipListPtr list = (SkipListPtr)l; - SLEntryPtr update[SL_MAX_LEVEL + 1]; - SLEntryPtr entry; - int i; - - if (list->magic != SL_LIST_MAGIC) return -1; /* Bad magic */ - - entry = SLLocate(list, key, update); - - if (!entry || entry->key != key) return 1; /* Not found */ - - /* Fix up forward pointers */ - for (i = 0; i <= list->level; i++) { - if (update[i]->forward[i] == entry) - update[i]->forward[i] = entry->forward[i]; - } - - entry->magic = SL_FREED_MAGIC; - SL_FREE(entry); - - while (list->level && !list->head->forward[list->level]) --list->level; - --list->count; - return 0; -} - -int drmSLLookup(void *l, unsigned long key, void **value) -{ - SkipListPtr list = (SkipListPtr)l; - SLEntryPtr update[SL_MAX_LEVEL + 1]; - SLEntryPtr entry; - - entry = SLLocate(list, key, update); - - if (entry && entry->key == key) { - *value = entry; - return 0; - } - *value = NULL; - return -1; -} - -int drmSLLookupNeighbors(void *l, unsigned long key, - unsigned long *prev_key, void **prev_value, - unsigned long *next_key, void **next_value) -{ - SkipListPtr list = (SkipListPtr)l; - SLEntryPtr update[SL_MAX_LEVEL + 1]; - SLEntryPtr entry; - int retcode = 0; - - entry = SLLocate(list, key, update); - - *prev_key = *next_key = key; - *prev_value = *next_value = NULL; - - if (update[0]) { - *prev_key = update[0]->key; - *prev_value = update[0]->value; - ++retcode; - if (update[0]->forward[0]) { - *next_key = update[0]->forward[0]->key; - *next_value = update[0]->forward[0]->value; - ++retcode; - } - } - return retcode; -} - -int drmSLNext(void *l, unsigned long *key, void **value) -{ - SkipListPtr list = (SkipListPtr)l; - SLEntryPtr entry; - - if (list->magic != SL_LIST_MAGIC) return -1; /* Bad magic */ - - entry = list->p0; - - if (entry) { - list->p0 = entry->forward[0]; - *key = entry->key; - *value = entry->value; - return 1; - } - list->p0 = NULL; - return 0; -} - -int drmSLFirst(void *l, unsigned long *key, void **value) -{ - SkipListPtr list = (SkipListPtr)l; - - if (list->magic != SL_LIST_MAGIC) return -1; /* Bad magic */ - - list->p0 = list->head->forward[0]; - return drmSLNext(list, key, value); -} - -/* Dump internal data structures for debugging. */ -void drmSLDump(void *l) -{ - SkipListPtr list = (SkipListPtr)l; - SLEntryPtr entry; - int i; - - if (list->magic != SL_LIST_MAGIC) { - printf("Bad magic: 0x%08lx (expected 0x%08lx)\n", - list->magic, SL_LIST_MAGIC); - return; - } - - printf("Level = %d, count = %d\n", list->level, list->count); - for (entry = list->head; entry; entry = entry->forward[0]) { - if (entry->magic != SL_ENTRY_MAGIC) { - printf("Bad magic: 0x%08lx (expected 0x%08lx)\n", - list->magic, SL_ENTRY_MAGIC); - } - printf("\nEntry %p <0x%08lx, %p> has %2d levels\n", - entry, entry->key, entry->value, entry->levels); - for (i = 0; i < entry->levels; i++) { - if (entry->forward[i]) { - printf(" %2d: %p <0x%08lx, %p>\n", - i, - entry->forward[i], - entry->forward[i]->key, - entry->forward[i]->value); - } else { - printf(" %2d: %p\n", i, entry->forward[i]); - } - } - } -} - -#if SL_MAIN -static void print(SkipListPtr list) -{ - unsigned long key; - void *value; - - if (drmSLFirst(list, &key, &value)) { - do { - printf("key = %5lu, value = %p\n", key, value); - } while (drmSLNext(list, &key, &value)); - } -} - -static double do_time(int size, int iter) -{ - SkipListPtr list; - int i, j; - unsigned long keys[1000000]; - unsigned long previous; - unsigned long key; - void *value; - struct timeval start, stop; - double usec; - SL_RANDOM_DECL; - - SL_RANDOM_INIT(12345); - - list = drmSLCreate(); - - for (i = 0; i < size; i++) { - keys[i] = SL_RANDOM; - drmSLInsert(list, keys[i], NULL); - } - - previous = 0; - if (drmSLFirst(list, &key, &value)) { - do { - if (key <= previous) { - printf( "%lu !< %lu\n", previous, key); - } - previous = key; - } while (drmSLNext(list, &key, &value)); - } - - gettimeofday(&start, NULL); - for (j = 0; j < iter; j++) { - for (i = 0; i < size; i++) { - if (drmSLLookup(list, keys[i], &value)) - printf("Error %lu %d\n", keys[i], i); - } - } - gettimeofday(&stop, NULL); - - usec = (double)(stop.tv_sec * 1000000 + stop.tv_usec - - start.tv_sec * 1000000 - start.tv_usec) / (size * iter); - - printf("%0.2f microseconds for list length %d\n", usec, size); - - drmSLDestroy(list); - - return usec; -} - -static void print_neighbors(void *list, unsigned long key) -{ - unsigned long prev_key = 0; - unsigned long next_key = 0; - void *prev_value; - void *next_value; - int retval; - - retval = drmSLLookupNeighbors(list, key, - &prev_key, &prev_value, - &next_key, &next_value); - printf("Neighbors of %5lu: %d %5lu %5lu\n", - key, retval, prev_key, next_key); -} - -int main(void) -{ - SkipListPtr list; - double usec, usec2, usec3, usec4; - - list = drmSLCreate(); - printf( "list at %p\n", list); - - print(list); - printf("\n==============================\n\n"); - - drmSLInsert(list, 123, NULL); - drmSLInsert(list, 213, NULL); - drmSLInsert(list, 50, NULL); - print(list); - printf("\n==============================\n\n"); - - print_neighbors(list, 0); - print_neighbors(list, 50); - print_neighbors(list, 51); - print_neighbors(list, 123); - print_neighbors(list, 200); - print_neighbors(list, 213); - print_neighbors(list, 256); - printf("\n==============================\n\n"); - - drmSLDelete(list, 50); - print(list); - printf("\n==============================\n\n"); - - drmSLDump(list); - drmSLDestroy(list); - printf("\n==============================\n\n"); - - usec = do_time(100, 10000); - usec2 = do_time(1000, 500); - printf("Table size increased by %0.2f, search time increased by %0.2f\n", - 1000.0/100.0, usec2 / usec); - - usec3 = do_time(10000, 50); - printf("Table size increased by %0.2f, search time increased by %0.2f\n", - 10000.0/100.0, usec3 / usec); - - usec4 = do_time(100000, 4); - printf("Table size increased by %0.2f, search time increased by %0.2f\n", - 100000.0/100.0, usec4 / usec); - - return 0; -} -#endif diff --git a/src/mesa/drivers/dri/i915-tex/Makefile b/src/mesa/drivers/dri/i915-tex/Makefile deleted file mode 100644 index fff8e9a1179..00000000000 --- a/src/mesa/drivers/dri/i915-tex/Makefile +++ /dev/null @@ -1,78 +0,0 @@ - -TOP = ../../../../.. -include $(TOP)/configs/current - -LIBNAME = i915_dri.so - -DRIVER_SOURCES = \ - i830_context.c \ - i830_metaops.c \ - i830_state.c \ - i830_texblend.c \ - i830_tex.c \ - i830_texstate.c \ - i830_vtbl.c \ - intel_render.c \ - intel_regions.c \ - intel_buffer_objects.c \ - intel_batchbuffer.c \ - intel_mipmap_tree.c \ - i915_tex_layout.c \ - intel_tex_image.c \ - intel_tex_subimage.c \ - intel_tex_copy.c \ - intel_tex_validate.c \ - intel_tex_format.c \ - intel_tex.c \ - intel_pixel.c \ - intel_pixel_copy.c \ - intel_pixel_read.c \ - intel_pixel_draw.c \ - intel_buffers.c \ - intel_blit.c \ - i915_tex.c \ - i915_texstate.c \ - i915_context.c \ - i915_debug.c \ - i915_fragprog.c \ - i915_metaops.c \ - i915_program.c \ - i915_state.c \ - i915_texprog.c \ - i915_vtbl.c \ - intel_context.c \ - intel_ioctl.c \ -<<<<<<< Makefile - intel_pixel.c \ - intel_render.c \ - intel_rotate.c \ -======= ->>>>>>> 1.3.4.11 - intel_screen.c \ - intel_span.c \ - intel_state.c \ -<<<<<<< Makefile - intel_tex.c \ - intel_texmem.c \ - intel_tris.c -======= - intel_tris.c \ - intel_fbo.c \ - intel_depthstencil.c \ - intel_bufmgr.c - - ->>>>>>> 1.3.4.11 - -C_SOURCES = \ - $(COMMON_SOURCES) \ - $(MINIGLX_SOURCES) \ - $(DRIVER_SOURCES) - -ASM_SOURCES = - - - -include ../Makefile.template - -symlinks: diff --git a/src/mesa/drivers/dri/i915-tex/i830_context.c b/src/mesa/drivers/dri/i915-tex/i830_context.c deleted file mode 100644 index a1cb25ca4e4..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i830_context.c +++ /dev/null @@ -1,120 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "i830_context.h" -#include "imports.h" -#include "texmem.h" -#include "intel_tex.h" -#include "tnl/tnl.h" -#include "tnl/t_vertex.h" -#include "tnl/t_context.h" -#include "utils.h" - -/*************************************** - * Mesa's Driver Functions - ***************************************/ - -static const struct dri_extension i830_extensions[] = -{ - { "GL_ARB_texture_env_crossbar", NULL }, - { NULL, NULL } -}; - - -static void i830InitDriverFunctions( struct dd_function_table *functions ) -{ - intelInitDriverFunctions( functions ); - i830InitStateFuncs( functions ); - i830InitTextureFuncs( functions ); -} - - -GLboolean i830CreateContext( const __GLcontextModes *mesaVis, - __DRIcontextPrivate *driContextPriv, - void *sharedContextPrivate) -{ - struct dd_function_table functions; - struct i830_context *i830 = CALLOC_STRUCT(i830_context); - struct intel_context *intel = &i830->intel; - GLcontext *ctx = &intel->ctx; - GLuint i; - if (!i830) return GL_FALSE; - - i830InitVtbl( i830 ); - i830InitDriverFunctions( &functions ); - - if (!intelInitContext( intel, mesaVis, driContextPriv, - sharedContextPrivate, &functions )) { - FREE(i830); - return GL_FALSE; - } - - intel->ctx.Const.MaxTextureUnits = I830_TEX_UNITS; - intel->ctx.Const.MaxTextureImageUnits = I830_TEX_UNITS; - intel->ctx.Const.MaxTextureCoordUnits = I830_TEX_UNITS; - - /* Advertise the full hardware capabilities. The new memory - * manager should cope much better with overload situations: - */ -<<<<<<< i830_context.c - intel->ctx.Const.MaxTextureUnits = I830_TEX_UNITS; - i = driQueryOptioni( &intel->intelScreen->optionCache, "allow_large_textures"); - driCalculateMaxTextureLevels( intel->texture_heaps, - intel->nr_heaps, - &intel->ctx.Const, - 4, - 11, /* max 2D texture size is 2048x2048 */ - 8, /* max 3D texture size is 256^3 */ - 10, /* max CUBE texture size is 1024x1024 */ - 11, /* max RECT. supported */ - 12, - GL_FALSE, - i ); -======= - ctx->Const.MaxTextureLevels = 12; - ctx->Const.Max3DTextureLevels = 9; - ctx->Const.MaxCubeTextureLevels = 11; - ctx->Const.MaxTextureRectSize = (1<<11); - ctx->Const.MaxTextureUnits = I830_TEX_UNITS; ->>>>>>> 1.11.2.2 - - _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12, - 18 * sizeof(GLfloat) ); - - intel->verts = TNL_CONTEXT(ctx)->clipspace.vertex_buf; - - driInitExtensions( ctx, i830_extensions, GL_FALSE ); - - i830InitState( i830 ); - i830InitMetaFuncs( i830 ); - - _tnl_allow_vertex_fog( ctx, 1 ); - _tnl_allow_pixel_fog( ctx, 0 ); - - return GL_TRUE; -} - diff --git a/src/mesa/drivers/dri/i915-tex/i830_context.h b/src/mesa/drivers/dri/i915-tex/i830_context.h deleted file mode 100644 index 34b4d07602d..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i830_context.h +++ /dev/null @@ -1,217 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#ifndef I830CONTEXT_INC -#define I830CONTEXT_INC - -#include "intel_context.h" - -#define I830_FALLBACK_TEXTURE 0x1000 -#define I830_FALLBACK_COLORMASK 0x2000 -#define I830_FALLBACK_STENCIL 0x4000 -#define I830_FALLBACK_STIPPLE 0x8000 -#define I830_FALLBACK_LOGICOP 0x10000 - -#define I830_UPLOAD_CTX 0x1 -#define I830_UPLOAD_BUFFERS 0x2 -#define I830_UPLOAD_STIPPLE 0x4 -#define I830_UPLOAD_INVARIENT 0x8 -#define I830_UPLOAD_TEX(i) (0x10<<(i)) -#define I830_UPLOAD_TEXBLEND(i) (0x100<<(i)) -#define I830_UPLOAD_TEX_ALL (0x0f0) -#define I830_UPLOAD_TEXBLEND_ALL (0xf00) - -/* State structure offsets - these will probably disappear. - */ -#define I830_DESTREG_CBUFADDR0 0 -#define I830_DESTREG_CBUFADDR1 1 -#define I830_DESTREG_DBUFADDR0 2 -#define I830_DESTREG_DBUFADDR1 3 -#define I830_DESTREG_DV0 4 -#define I830_DESTREG_DV1 5 -#define I830_DESTREG_SENABLE 6 -#define I830_DESTREG_SR0 7 -#define I830_DESTREG_SR1 8 -#define I830_DESTREG_SR2 9 -#define I830_DEST_SETUP_SIZE 10 - -#define I830_CTXREG_STATE1 0 -#define I830_CTXREG_STATE2 1 -#define I830_CTXREG_STATE3 2 -#define I830_CTXREG_STATE4 3 -#define I830_CTXREG_STATE5 4 -#define I830_CTXREG_IALPHAB 5 -#define I830_CTXREG_STENCILTST 6 -#define I830_CTXREG_ENABLES_1 7 -#define I830_CTXREG_ENABLES_2 8 -#define I830_CTXREG_AA 9 -#define I830_CTXREG_FOGCOLOR 10 -#define I830_CTXREG_BLENDCOLOR0 11 -#define I830_CTXREG_BLENDCOLOR1 12 -#define I830_CTXREG_VF 13 -#define I830_CTXREG_VF2 14 -#define I830_CTXREG_MCSB0 15 -#define I830_CTXREG_MCSB1 16 -#define I830_CTX_SETUP_SIZE 17 - -#define I830_STPREG_ST0 0 -#define I830_STPREG_ST1 1 -#define I830_STP_SETUP_SIZE 2 - -#define I830_TEXREG_TM0LI 0 /* load immediate 2 texture map n */ -#define I830_TEXREG_TM0S1 1 -#define I830_TEXREG_TM0S2 2 -#define I830_TEXREG_TM0S3 3 -#define I830_TEXREG_TM0S4 4 -#define I830_TEXREG_MCS 5 /* _3DSTATE_MAP_COORD_SETS */ -#define I830_TEXREG_CUBE 6 /* _3DSTATE_MAP_SUBE */ -#define I830_TEX_SETUP_SIZE 7 - -#define I830_TEXBLEND_SIZE 12 /* (4 args + op) * 2 + COLOR_FACTOR */ - -struct i830_texture_object -{ - struct intel_texture_object intel; - GLuint Setup[I830_TEX_SETUP_SIZE]; -}; - -#define I830_TEX_UNITS 4 - -struct i830_hw_state { - GLuint Ctx[I830_CTX_SETUP_SIZE]; - GLuint Buffer[I830_DEST_SETUP_SIZE]; - GLuint Stipple[I830_STP_SETUP_SIZE]; - GLuint Tex[I830_TEX_UNITS][I830_TEX_SETUP_SIZE]; - GLuint TexBlend[I830_TEX_UNITS][I830_TEXBLEND_SIZE]; - GLuint TexBlendWordsUsed[I830_TEX_UNITS]; - - struct intel_region *draw_region; - struct intel_region *depth_region; - - /* Regions aren't actually that appropriate here as the memory may - * be from a PBO or FBO. Just use the buffer id. Will have to do - * this for draw and depth for FBO's... - */ - GLuint tex_buffer[I830_TEX_UNITS]; - GLuint tex_offset[I830_TEX_UNITS]; - - GLuint emitted; /* I810_UPLOAD_* */ - GLuint active; -}; - -struct i830_context -{ - struct intel_context intel; - - GLuint lodbias_tm0s3[MAX_TEXTURE_UNITS]; - GLuint last_index; - - struct i830_hw_state meta, initial, state, *current; -}; - - - - -#define I830_STATECHANGE(i830, flag) \ -do { \ - INTEL_FIREVERTICES( &i830->intel ); \ - i830->state.emitted &= ~flag; \ -} while (0) - -#define I830_ACTIVESTATE(i830, flag, mode) \ -do { \ - INTEL_FIREVERTICES( &i830->intel ); \ - if (mode) \ - i830->state.active |= flag; \ - else \ - i830->state.active &= ~flag; \ -} while (0) - -/* i830_vtbl.c - */ -extern void -i830InitVtbl( struct i830_context *i830 ); - -/* i830_context.c - */ -extern GLboolean -i830CreateContext( const __GLcontextModes *mesaVis, - __DRIcontextPrivate *driContextPriv, - void *sharedContextPrivate); - -/* i830_tex.c, i830_texstate.c - */ -extern void -i830UpdateTextureState( struct intel_context *intel ); - -extern void -i830InitTextureFuncs( struct dd_function_table *functions ); - -/* i830_texblend.c - */ -extern GLuint i830SetTexEnvCombine(struct i830_context *i830, - const struct gl_tex_env_combine_state * combine, GLint blendUnit, - GLuint texel_op, GLuint *state, const GLfloat *factor ); - -extern void -i830EmitTextureBlend( struct i830_context *i830 ); - - -/* i830_state.c - */ -extern void -i830InitStateFuncs( struct dd_function_table *functions ); - -extern void -i830EmitState( struct i830_context *i830 ); - -extern void -i830InitState( struct i830_context *i830 ); - -/* i830_metaops.c - */ -extern void -i830InitMetaFuncs( struct i830_context *i830 ); - -<<<<<<< i830_context.h -extern void -i830RotateWindow(intelContextPtr intel, __DRIdrawablePrivate *dPriv, - GLuint srcBuf); -======= -/*====================================================================== - * Inline conversion functions. These are better-typed than the - * macros used previously: - */ -static INLINE struct i830_context * -i830_context( GLcontext *ctx ) -{ - return (struct i830_context *)ctx; -} ->>>>>>> 1.4.12.3 - -#endif - diff --git a/src/mesa/drivers/dri/i915-tex/i830_metaops.c b/src/mesa/drivers/dri/i915-tex/i830_metaops.c deleted file mode 100644 index 1213f8ab47b..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i830_metaops.c +++ /dev/null @@ -1,910 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "glheader.h" -#include "enums.h" -#include "mtypes.h" -#include "macros.h" -#include "utils.h" - -#include "intel_screen.h" -#include "intel_batchbuffer.h" -#include "intel_ioctl.h" -#include "intel_regions.h" - -#include "i830_context.h" -#include "i830_reg.h" - -/* A large amount of state doesn't need to be uploaded. - */ -#define ACTIVE (I830_UPLOAD_INVARIENT | \ - I830_UPLOAD_CTX | \ - I830_UPLOAD_BUFFERS | \ - I830_UPLOAD_STIPPLE | \ - I830_UPLOAD_TEXBLEND(0) | \ - I830_UPLOAD_TEX(0)) - - -#define SET_STATE( i830, STATE ) \ -do { \ - assert(!i830->intel.prim.flush); \ - i830->current->emitted = 0; \ - i830->current = &i830->STATE; \ - i830->current->emitted = 0; \ -} while (0) - - -static void set_no_stencil_write( struct intel_context *intel ) -{ - struct i830_context *i830 = i830_context(&intel->ctx); - - /* ctx->Driver.Enable( ctx, GL_STENCIL_TEST, GL_FALSE ) - */ - i830->meta.Ctx[I830_CTXREG_ENABLES_1] &= ~ENABLE_STENCIL_TEST; - i830->meta.Ctx[I830_CTXREG_ENABLES_2] &= ~ENABLE_STENCIL_WRITE; - i830->meta.Ctx[I830_CTXREG_ENABLES_1] |= DISABLE_STENCIL_TEST; - i830->meta.Ctx[I830_CTXREG_ENABLES_2] |= DISABLE_STENCIL_WRITE; - - i830->meta.emitted &= ~I830_UPLOAD_CTX; -} - -static void set_no_depth_write( struct intel_context *intel ) -{ - struct i830_context *i830 = i830_context(&intel->ctx); - - /* ctx->Driver.Enable( ctx, GL_DEPTH_TEST, GL_FALSE ) - */ - i830->meta.Ctx[I830_CTXREG_ENABLES_1] &= ~ENABLE_DIS_DEPTH_TEST_MASK; - i830->meta.Ctx[I830_CTXREG_ENABLES_2] &= ~ENABLE_DIS_DEPTH_WRITE_MASK; - i830->meta.Ctx[I830_CTXREG_ENABLES_1] |= DISABLE_DEPTH_TEST; - i830->meta.Ctx[I830_CTXREG_ENABLES_2] |= DISABLE_DEPTH_WRITE; - - i830->meta.emitted &= ~I830_UPLOAD_CTX; -} - -/* Set depth unit to replace. - */ -static void set_depth_replace( struct intel_context *intel ) -{ - struct i830_context *i830 = i830_context(&intel->ctx); - - /* ctx->Driver.Enable( ctx, GL_DEPTH_TEST, GL_FALSE ) - * ctx->Driver.DepthMask( ctx, GL_TRUE ) - */ - i830->meta.Ctx[I830_CTXREG_ENABLES_1] &= ~ENABLE_DIS_DEPTH_TEST_MASK; - i830->meta.Ctx[I830_CTXREG_ENABLES_2] &= ~ENABLE_DIS_DEPTH_WRITE_MASK; - i830->meta.Ctx[I830_CTXREG_ENABLES_1] |= ENABLE_DEPTH_TEST; - i830->meta.Ctx[I830_CTXREG_ENABLES_2] |= ENABLE_DEPTH_WRITE; - - /* ctx->Driver.DepthFunc( ctx, GL_ALWAYS ) - */ - i830->meta.Ctx[I830_CTXREG_STATE3] &= ~DEPTH_TEST_FUNC_MASK; - i830->meta.Ctx[I830_CTXREG_STATE3] |= (ENABLE_DEPTH_TEST_FUNC | - DEPTH_TEST_FUNC(COMPAREFUNC_ALWAYS)); - - i830->meta.emitted &= ~I830_UPLOAD_CTX; -} - - -/* Set stencil unit to replace always with the reference value. - */ -static void set_stencil_replace( struct intel_context *intel, - GLuint s_mask, - GLuint s_clear) -{ - struct i830_context *i830 = i830_context(&intel->ctx); - - /* ctx->Driver.Enable( ctx, GL_STENCIL_TEST, GL_TRUE ) - */ - i830->meta.Ctx[I830_CTXREG_ENABLES_1] |= ENABLE_STENCIL_TEST; - i830->meta.Ctx[I830_CTXREG_ENABLES_2] |= ENABLE_STENCIL_WRITE; - - /* ctx->Driver.StencilMask( ctx, s_mask ) - */ - i830->meta.Ctx[I830_CTXREG_STATE4] &= ~MODE4_ENABLE_STENCIL_WRITE_MASK; - i830->meta.Ctx[I830_CTXREG_STATE4] |= (ENABLE_STENCIL_WRITE_MASK | - STENCIL_WRITE_MASK((s_mask&0xff))); - - /* ctx->Driver.StencilOp( ctx, GL_REPLACE, GL_REPLACE, GL_REPLACE ) - */ - i830->meta.Ctx[I830_CTXREG_STENCILTST] &= ~(STENCIL_OPS_MASK); - i830->meta.Ctx[I830_CTXREG_STENCILTST] |= - (ENABLE_STENCIL_PARMS | - STENCIL_FAIL_OP(STENCILOP_REPLACE) | - STENCIL_PASS_DEPTH_FAIL_OP(STENCILOP_REPLACE) | - STENCIL_PASS_DEPTH_PASS_OP(STENCILOP_REPLACE)); - - /* ctx->Driver.StencilFunc( ctx, GL_ALWAYS, s_clear, ~0 ) - */ - i830->meta.Ctx[I830_CTXREG_STATE4] &= ~MODE4_ENABLE_STENCIL_TEST_MASK; - i830->meta.Ctx[I830_CTXREG_STATE4] |= (ENABLE_STENCIL_TEST_MASK | - STENCIL_TEST_MASK(0xff)); - - i830->meta.Ctx[I830_CTXREG_STENCILTST] &= ~(STENCIL_REF_VALUE_MASK | - ENABLE_STENCIL_TEST_FUNC_MASK); - i830->meta.Ctx[I830_CTXREG_STENCILTST] |= - (ENABLE_STENCIL_REF_VALUE | - ENABLE_STENCIL_TEST_FUNC | - STENCIL_REF_VALUE((s_clear&0xff)) | - STENCIL_TEST_FUNC(COMPAREFUNC_ALWAYS)); - - - - i830->meta.emitted &= ~I830_UPLOAD_CTX; -} - - -static void set_color_mask( struct intel_context *intel, GLboolean state ) -{ - struct i830_context *i830 = i830_context(&intel->ctx); - - const GLuint mask = ((1 << WRITEMASK_RED_SHIFT) | - (1 << WRITEMASK_GREEN_SHIFT) | - (1 << WRITEMASK_BLUE_SHIFT) | - (1 << WRITEMASK_ALPHA_SHIFT)); - - i830->meta.Ctx[I830_CTXREG_ENABLES_2] &= ~mask; - - if (state) { - i830->meta.Ctx[I830_CTXREG_ENABLES_2] |= - (i830->state.Ctx[I830_CTXREG_ENABLES_2] & mask); - } - - i830->meta.emitted &= ~I830_UPLOAD_CTX; -} - -/* Installs a one-stage passthrough texture blend pipeline. Is there - * more that can be done to turn off texturing? - */ -static void set_no_texture( struct intel_context *intel ) -{ - struct i830_context *i830 = i830_context(&intel->ctx); - static const struct gl_tex_env_combine_state comb = { - GL_NONE, GL_NONE, - { GL_TEXTURE, 0, 0, }, { GL_TEXTURE, 0, 0, }, - { GL_SRC_COLOR, 0, 0 }, { GL_SRC_ALPHA, 0, 0 }, - 0, 0, 0, 0 - }; - - i830->meta.TexBlendWordsUsed[0] = - i830SetTexEnvCombine( i830, & comb, 0, TEXBLENDARG_TEXEL0, - i830->meta.TexBlend[0], NULL); - - i830->meta.TexBlend[0][0] |= TEXOP_LAST_STAGE; - i830->meta.emitted &= ~I830_UPLOAD_TEXBLEND(0); -} - -/* Set up a single element blend stage for 'replace' texturing with no - * funny ops. - */ -<<<<<<< i830_metaops.c -static void enable_texture_blend_replace( i830ContextPtr i830 ) -======= -static void set_texture_blend_replace( struct intel_context *intel ) ->>>>>>> 1.6.2.9 -{ - struct i830_context *i830 = i830_context(&intel->ctx); - static const struct gl_tex_env_combine_state comb = { - GL_REPLACE, GL_REPLACE, -<<<<<<< i830_metaops.c - { GL_TEXTURE, GL_TEXTURE, GL_TEXTURE }, { GL_TEXTURE, GL_TEXTURE, GL_TEXTURE, }, - { GL_SRC_COLOR, GL_SRC_COLOR, GL_SRC_COLOR }, { GL_SRC_ALPHA, GL_SRC_ALPHA, GL_SRC_ALPHA }, -======= - { GL_TEXTURE, GL_TEXTURE, GL_TEXTURE, }, { GL_TEXTURE, GL_TEXTURE, GL_TEXTURE, }, - { GL_SRC_COLOR, GL_SRC_COLOR, GL_SRC_COLOR }, { GL_SRC_ALPHA, GL_SRC_ALPHA, GL_SRC_ALPHA }, ->>>>>>> 1.6.2.9 - 0, 0, 1, 1 - }; - - i830->meta.TexBlendWordsUsed[0] = - i830SetTexEnvCombine( i830, & comb, 0, TEXBLENDARG_TEXEL0, - i830->meta.TexBlend[0], NULL); - - i830->meta.TexBlend[0][0] |= TEXOP_LAST_STAGE; - i830->meta.emitted &= ~I830_UPLOAD_TEXBLEND(0); - -/* fprintf(stderr, "%s: TexBlendWordsUsed[0]: %d\n", */ -/* __FUNCTION__, i830->meta.TexBlendWordsUsed[0]); */ -} - - - -/* Set up an arbitary piece of memory as a rectangular texture - * (including the front or back buffer). - */ -<<<<<<< i830_metaops.c -static void set_tex_rect_source( i830ContextPtr i830, - GLuint offset, - GLuint width, - GLuint height, - GLuint pitch, /* in bytes */ - GLuint textureFormat ) -======= -static GLboolean set_tex_rect_source( struct intel_context *intel, - GLuint buffer, - GLuint offset, - GLuint pitch, - GLuint height, - GLenum format, - GLenum type) ->>>>>>> 1.6.2.9 -{ - struct i830_context *i830 = i830_context(&intel->ctx); - GLuint *setup = i830->meta.Tex[0]; - GLint numLevels = 1; - GLuint textureFormat; - GLuint cpp; - - /* A full implementation of this would do the upload through - * glTexImage2d, and get all the conversion operations at that - * point. We are restricted, but still at least have access to the - * fragment program swizzle. - */ - switch (format) { - case GL_BGRA: - switch (type) { - case GL_UNSIGNED_INT_8_8_8_8_REV: - case GL_UNSIGNED_BYTE: - textureFormat = (MAPSURF_32BIT | MT_32BIT_ARGB8888); - cpp = 4; - break; - default: - return GL_FALSE; - } - break; - case GL_RGBA: - switch (type) { - case GL_UNSIGNED_INT_8_8_8_8_REV: - case GL_UNSIGNED_BYTE: - textureFormat = (MAPSURF_32BIT | MT_32BIT_ABGR8888); - cpp = 4; - break; - default: - return GL_FALSE; - } - break; - case GL_BGR: - switch (type) { - case GL_UNSIGNED_SHORT_5_6_5_REV: - textureFormat = (MAPSURF_16BIT | MT_16BIT_RGB565); - cpp = 2; - break; - default: - return GL_FALSE; - } - break; - case GL_RGB: - switch (type) { - case GL_UNSIGNED_SHORT_5_6_5: - textureFormat = (MAPSURF_16BIT | MT_16BIT_RGB565); - cpp = 2; - break; - default: - return GL_FALSE; - } - break; - -<<<<<<< i830_metaops.c -/* fprintf(stderr, "%s: offset: %x w: %d h: %d pitch %d format %x\n", */ -/* __FUNCTION__, offset, width, height, pitch, textureFormat ); */ -======= - default: - return GL_FALSE; - } - - i830->meta.tex_buffer[0] = buffer; - i830->meta.tex_offset[0] = offset; ->>>>>>> 1.6.2.9 - - setup[I830_TEXREG_TM0LI] = (_3DSTATE_LOAD_STATE_IMMEDIATE_2 | - (LOAD_TEXTURE_MAP0 << 0) | 4); - setup[I830_TEXREG_TM0S1] = (((height - 1) << TM0S1_HEIGHT_SHIFT) | - ((pitch - 1) << TM0S1_WIDTH_SHIFT) | - textureFormat); - setup[I830_TEXREG_TM0S2] = (((((pitch * cpp) / 4) - 1) << TM0S2_PITCH_SHIFT) | - TM0S2_CUBE_FACE_ENA_MASK); - - setup[I830_TEXREG_TM0S3] = ( (((numLevels - 1)*4) << TM0S3_MIN_MIP_SHIFT) | - (FILTER_NEAREST << TM0S3_MIN_FILTER_SHIFT) | - (MIPFILTER_NONE << TM0S3_MIP_FILTER_SHIFT) | - (FILTER_NEAREST << TM0S3_MAG_FILTER_SHIFT)); - - setup[I830_TEXREG_CUBE] = (_3DSTATE_MAP_CUBE | MAP_UNIT(0)); - - setup[I830_TEXREG_MCS] = (_3DSTATE_MAP_COORD_SET_CMD | - MAP_UNIT(0) | - ENABLE_TEXCOORD_PARAMS | - TEXCOORDS_ARE_IN_TEXELUNITS | - TEXCOORDTYPE_CARTESIAN | - ENABLE_ADDR_V_CNTL | - TEXCOORD_ADDR_V_MODE(TEXCOORDMODE_WRAP) | - ENABLE_ADDR_U_CNTL | - TEXCOORD_ADDR_U_MODE(TEXCOORDMODE_WRAP)); - - i830->meta.emitted &= ~I830_UPLOAD_TEX(0); - return GL_TRUE; -} - - -<<<<<<< i830_metaops.c -/* Select between front and back draw buffers. - */ -static void set_draw_region( i830ContextPtr i830, - const intelRegion *region ) -{ - i830->meta.Buffer[I830_DESTREG_CBUFADDR1] = - (BUF_3D_ID_COLOR_BACK | BUF_3D_PITCH(region->pitch) | BUF_3D_USE_FENCE); - i830->meta.Buffer[I830_DESTREG_CBUFADDR2] = region->offset; - i830->meta.emitted &= ~I830_UPLOAD_BUFFERS; -} - -/* Setup an arbitary draw format, useful for targeting - * texture or agp memory. - */ -#if 0 -static void set_draw_format( i830ContextPtr i830, - GLuint format, - GLuint depth_format) -{ - i830->meta.Buffer[I830_DESTREG_DV1] = (DSTORG_HORT_BIAS(0x8) | /* .5 */ - DSTORG_VERT_BIAS(0x8) | /* .5 */ - format | - DEPTH_IS_Z | - depth_format); -} -#endif - - -static void set_vertex_format( i830ContextPtr i830 ) -======= -static void set_vertex_format( struct intel_context *intel ) ->>>>>>> 1.6.2.9 -{ - struct i830_context *i830 = i830_context(&intel->ctx); - i830->meta.Ctx[I830_CTXREG_VF] = (_3DSTATE_VFT0_CMD | - VFT0_TEX_COUNT(1) | - VFT0_DIFFUSE | - VFT0_XYZ); - i830->meta.Ctx[I830_CTXREG_VF2] = (_3DSTATE_VFT1_CMD | - VFT1_TEX0_FMT(TEXCOORDFMT_2D) | - VFT1_TEX1_FMT(TEXCOORDFMT_2D) | - VFT1_TEX2_FMT(TEXCOORDFMT_2D) | - VFT1_TEX3_FMT(TEXCOORDFMT_2D)); - i830->meta.emitted &= ~I830_UPLOAD_CTX; -} - - -static void meta_import_pixel_state( struct intel_context *intel ) -{ - struct i830_context *i830 = i830_context(&intel->ctx); - - i830->meta.Ctx[I830_CTXREG_STATE1] = i830->state.Ctx[I830_CTXREG_STATE1]; - i830->meta.Ctx[I830_CTXREG_STATE2] = i830->state.Ctx[I830_CTXREG_STATE2]; - i830->meta.Ctx[I830_CTXREG_STATE3] = i830->state.Ctx[I830_CTXREG_STATE3]; - i830->meta.Ctx[I830_CTXREG_STATE4] = i830->state.Ctx[I830_CTXREG_STATE4]; - i830->meta.Ctx[I830_CTXREG_STATE5] = i830->state.Ctx[I830_CTXREG_STATE5]; - i830->meta.Ctx[I830_CTXREG_IALPHAB] = i830->state.Ctx[I830_CTXREG_IALPHAB]; - i830->meta.Ctx[I830_CTXREG_STENCILTST] = i830->state.Ctx[I830_CTXREG_STENCILTST]; - i830->meta.Ctx[I830_CTXREG_ENABLES_1] = i830->state.Ctx[I830_CTXREG_ENABLES_1]; - i830->meta.Ctx[I830_CTXREG_ENABLES_2] = i830->state.Ctx[I830_CTXREG_ENABLES_2]; - i830->meta.Ctx[I830_CTXREG_AA] = i830->state.Ctx[I830_CTXREG_AA]; - i830->meta.Ctx[I830_CTXREG_FOGCOLOR] = i830->state.Ctx[I830_CTXREG_FOGCOLOR]; - i830->meta.Ctx[I830_CTXREG_BLENDCOLOR0] = i830->state.Ctx[I830_CTXREG_BLENDCOLOR0]; - i830->meta.Ctx[I830_CTXREG_BLENDCOLOR1] = i830->state.Ctx[I830_CTXREG_BLENDCOLOR1]; - i830->meta.Ctx[I830_CTXREG_MCSB0] = i830->state.Ctx[I830_CTXREG_MCSB0]; - i830->meta.Ctx[I830_CTXREG_MCSB1] = i830->state.Ctx[I830_CTXREG_MCSB1]; - -<<<<<<< i830_metaops.c -/* fprintf(stderr, "%s: %f,%f-%f,%f 0x%x%x%x%x %f,%f-%f,%f\n", */ -/* __FUNCTION__, */ -/* x0,y0,x1,y1,red,green,blue,alpha,s0,t0,s1,t1); */ - - - /* initial vertex, left bottom */ - tmp.v.x = x0; - tmp.v.y = y0; - tmp.v.z = 1.0; - tmp.v.w = 1.0; - tmp.v.color.red = red; - tmp.v.color.green = green; - tmp.v.color.blue = blue; - tmp.v.color.alpha = alpha; - tmp.v.specular.red = 0; - tmp.v.specular.green = 0; - tmp.v.specular.blue = 0; - tmp.v.specular.alpha = 0; - tmp.v.u0 = s0; - tmp.v.v0 = t0; - for (i = 0 ; i < 8 ; i++) - vb[i] = tmp.ui[i]; - - /* right bottom */ - vb += 8; - tmp.v.x = x1; - tmp.v.u0 = s1; - for (i = 0 ; i < 8 ; i++) - vb[i] = tmp.ui[i]; - - /* right top */ - vb += 8; - tmp.v.y = y1; - tmp.v.v0 = t1; - for (i = 0 ; i < 8 ; i++) - vb[i] = tmp.ui[i]; - - /* left top */ - vb += 8; - tmp.v.x = x0; - tmp.v.u0 = s0; - for (i = 0 ; i < 8 ; i++) - vb[i] = tmp.ui[i]; - -/* fprintf(stderr, "%s: DV1: %x\n", */ -/* __FUNCTION__, i830->meta.Buffer[I830_DESTREG_DV1]); */ -} - -static void draw_poly(i830ContextPtr i830, - GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha, - GLuint numVerts, - GLfloat verts[][2], - GLfloat texcoords[][2]) -{ - GLuint vertex_size = 8; - GLuint *vb = intelEmitInlinePrimitiveLocked( &i830->intel, - PRIM3D_TRIFAN, - numVerts * vertex_size, - vertex_size ); - intelVertex tmp; - int i, k; - - /* initial constant vertex fields */ - tmp.v.z = 1.0; - tmp.v.w = 1.0; - tmp.v.color.red = red; - tmp.v.color.green = green; - tmp.v.color.blue = blue; - tmp.v.color.alpha = alpha; - tmp.v.specular.red = 0; - tmp.v.specular.green = 0; - tmp.v.specular.blue = 0; - tmp.v.specular.alpha = 0; - - for (k = 0; k < numVerts; k++) { - tmp.v.x = verts[k][0]; - tmp.v.y = verts[k][1]; - tmp.v.u0 = texcoords[k][0]; - tmp.v.v0 = texcoords[k][1]; - - for (i = 0 ; i < vertex_size ; i++) - vb[i] = tmp.ui[i]; - - vb += vertex_size; - } -} - -void -i830ClearWithTris(intelContextPtr intel, GLbitfield mask, - GLboolean all, - GLint cx, GLint cy, GLint cw, GLint ch) -{ - i830ContextPtr i830 = I830_CONTEXT( intel ); - __DRIdrawablePrivate *dPriv = intel->driDrawable; - intelScreenPrivate *screen = intel->intelScreen; - int x0, y0, x1, y1; - - INTEL_FIREVERTICES(intel); - SET_STATE( i830, meta ); - set_initial_state( i830 ); -/* set_no_texture( i830 ); */ - set_vertex_format( i830 ); - - LOCK_HARDWARE(intel); - - if(!all) { - x0 = cx; - y0 = cy; - x1 = x0 + cw; - y1 = y0 + ch; - } else { - x0 = 0; - y0 = 0; - x1 = x0 + dPriv->w; - y1 = y0 + dPriv->h; - } -======= ->>>>>>> 1.6.2.9 - - i830->meta.Ctx[I830_CTXREG_STATE3] &= ~CULLMODE_MASK; - i830->meta.Stipple[I830_STPREG_ST1] &= ~ST1_ENABLE; - i830->meta.emitted &= ~I830_UPLOAD_CTX; - -<<<<<<< i830_metaops.c - if(mask & BUFFER_BIT_FRONT_LEFT) { - set_no_depth_stencil_write( i830 ); - set_color_mask( i830, GL_TRUE ); - set_draw_region( i830, &screen->front ); - draw_quad(i830, x0, x1, y0, y1, - intel->clear_red, intel->clear_green, - intel->clear_blue, intel->clear_alpha, - 0, 0, 0, 0); - } -======= ->>>>>>> 1.6.2.9 - -<<<<<<< i830_metaops.c - if(mask & BUFFER_BIT_BACK_LEFT) { - set_no_depth_stencil_write( i830 ); - set_color_mask( i830, GL_TRUE ); - set_draw_region( i830, &screen->back ); - - draw_quad(i830, x0, x1, y0, y1, - intel->clear_red, intel->clear_green, - intel->clear_blue, intel->clear_alpha, - 0, 0, 0, 0); - } - - if(mask & BUFFER_BIT_STENCIL) { - set_stencil_replace( i830, - intel->ctx.Stencil.WriteMask[0], - intel->ctx.Stencil.Clear); - - set_color_mask( i830, GL_FALSE ); - set_draw_region( i830, &screen->front ); - draw_quad( i830, x0, x1, y0, y1, 0, 0, 0, 0, 0, 0, 0, 0 ); - } - - UNLOCK_HARDWARE(intel); - - INTEL_FIREVERTICES(intel); - SET_STATE( i830, state ); -======= - i830->meta.Buffer[I830_DESTREG_SENABLE] = i830->state.Buffer[I830_DESTREG_SENABLE]; - i830->meta.Buffer[I830_DESTREG_SR1] = i830->state.Buffer[I830_DESTREG_SR1]; - i830->meta.Buffer[I830_DESTREG_SR2] = i830->state.Buffer[I830_DESTREG_SR2]; - i830->meta.emitted &= ~I830_UPLOAD_BUFFERS; ->>>>>>> 1.6.2.9 -} - - -<<<<<<< i830_metaops.c -#if 0 -======= - -/* Select between front and back draw buffers. - */ -static void meta_draw_region( struct intel_context *intel, - struct intel_region *draw_region, - struct intel_region *depth_region ) -{ - struct i830_context *i830 = i830_context(&intel->ctx); - GLuint format; - GLuint depth_format = DEPTH_FRMT_16_FIXED; ->>>>>>> 1.6.2.9 - - intel_region_release(intel, &i830->meta.draw_region); - intel_region_reference(&i830->meta.draw_region, draw_region); - -<<<<<<< i830_metaops.c - - enable_texture_blend_replace( i830 ); - - - /* Set the 3d engine to draw into the agp memory - */ - - set_draw_region( i830, destOffset ); - set_draw_format( i830, destFormat, depthFormat ); - - - /* Draw a single quad, no cliprects: - */ - i830->intel.numClipRects = 1; - i830->intel.pClipRects = &tmp; - i830->intel.pClipRects[0].x1 = 0; - i830->intel.pClipRects[0].y1 = 0; - i830->intel.pClipRects[0].x2 = width; - i830->intel.pClipRects[0].y2 = height; -======= - intel_region_release(intel, &i830->meta.depth_region); - intel_region_reference(&i830->meta.depth_region, depth_region); ->>>>>>> 1.6.2.9 - - /* XXX FBO: grab code from i915 meta_draw_region */ - - /* XXX: 555 support? - */ - if (draw_region->cpp == 2) - format = DV_PF_565; - else - format = DV_PF_8888; - - if (depth_region) { - if (depth_region->cpp == 2) - depth_format = DEPTH_FRMT_16_FIXED; - else - depth_format = DEPTH_FRMT_24_FIXED_8_OTHER; - } - -<<<<<<< i830_metaops.c - /* Todo -- don't want to clobber all the drawing state like we do - * for readpixels -- most of this state can be handled just fine. - */ - if ( ctx->_ImageTransferState || - unpack->SwapBytes || - unpack->LsbFirst || - ctx->Color.AlphaEnabled || - ctx->Depth.Test || - ctx->Fog.Enabled || - ctx->Scissor.Enabled || - ctx->Stencil.Enabled || - !ctx->Color.ColorMask[0] || - !ctx->Color.ColorMask[1] || - !ctx->Color.ColorMask[2] || - !ctx->Color.ColorMask[3] || - ctx->Color.ColorLogicOpEnabled || - ctx->Texture._EnabledUnits || - ctx->Depth.OcclusionTest) { - fprintf(stderr, "%s: other tests failed\n", __FUNCTION__); - return GL_FALSE; - } -======= - i830->meta.Buffer[I830_DESTREG_DV1] = (DSTORG_HORT_BIAS(0x8) | /* .5 */ - DSTORG_VERT_BIAS(0x8) | /* .5 */ - format | - DEPTH_IS_Z | - depth_format); ->>>>>>> 1.6.2.9 - - i830->meta.emitted &= ~I830_UPLOAD_BUFFERS; -} - - -/* Operations where the 3D engine is decoupled temporarily from the - * current GL state and used for other purposes than simply rendering - * incoming triangles. - */ -static void install_meta_state( struct intel_context *intel ) -{ - struct i830_context *i830 = i830_context(&intel->ctx); - memcpy(&i830->meta, &i830->initial, sizeof(i830->meta) ); - - i830->meta.active = ACTIVE; - i830->meta.emitted = 0; - - SET_STATE(i830, meta); - set_vertex_format(intel); - set_no_texture(intel); -} - -static void leave_meta_state( struct intel_context *intel ) -{ - struct i830_context *i830 = i830_context(&intel->ctx); - intel_region_release(intel, &i830->meta.draw_region); - intel_region_release(intel, &i830->meta.depth_region); -/* intel_region_release(intel, &i830->meta.tex_region[0]); */ - SET_STATE(i830, state); -} - - - -void i830InitMetaFuncs( struct i830_context *i830 ) -{ - i830->intel.vtbl.install_meta_state = install_meta_state; - i830->intel.vtbl.leave_meta_state = leave_meta_state; - i830->intel.vtbl.meta_no_depth_write = set_no_depth_write; - i830->intel.vtbl.meta_no_stencil_write = set_no_stencil_write; - i830->intel.vtbl.meta_stencil_replace = set_stencil_replace; - i830->intel.vtbl.meta_depth_replace = set_depth_replace; - i830->intel.vtbl.meta_color_mask = set_color_mask; - i830->intel.vtbl.meta_no_texture = set_no_texture; - i830->intel.vtbl.meta_texture_blend_replace = set_texture_blend_replace; - i830->intel.vtbl.meta_tex_rect_source = set_tex_rect_source; - i830->intel.vtbl.meta_draw_region = meta_draw_region; - i830->intel.vtbl.meta_import_pixel_state = meta_import_pixel_state; -} - - - - -<<<<<<< i830_metaops.c - /* Set the pixel image up as a rectangular texture. - */ - set_tex_rect_source( i830, - src_offset, - width, - height, - pitch, /* XXXX!!!! -- /2 sometimes */ - textureFormat ); - - - enable_texture_blend_replace( i830 ); - - - /* Draw to the current draw buffer: - */ - set_draw_offset( i830, dst_offset ); - - /* Draw a quad, use regular cliprects - */ -/* fprintf(stderr, "x: %d y: %d width %d height %d\n", x, y, width, height); */ - - draw_quad( i830, - x, x+width, y, y+height, - 0, 255, 0, 0, - 0, width, 0, height ); - - intelWindowMoved( intel ); - } - UNLOCK_HARDWARE( intel ); - intelFinish( ctx ); /* required by GL */ - - SET_STATE(i830, state); - - return GL_TRUE; -} -======= ->>>>>>> 1.6.2.9 - -#endif - -/** - * Copy the window contents named by dPriv to the rotated (or reflected) - * color buffer. - * srcBuf is BUFFER_BIT_FRONT_LEFT or BUFFER_BIT_BACK_LEFT to indicate the source. - */ -void -i830RotateWindow(intelContextPtr intel, __DRIdrawablePrivate *dPriv, - GLuint srcBuf) -{ - i830ContextPtr i830 = I830_CONTEXT( intel ); - intelScreenPrivate *screen = intel->intelScreen; - const GLuint cpp = screen->cpp; - drm_clip_rect_t fullRect; - GLuint textureFormat, srcOffset, srcPitch; - const drm_clip_rect_t *clipRects; - int numClipRects; - int i; - - int xOrig, yOrig; - int origNumClipRects; - drm_clip_rect_t *origRects; - - /* - * set up hardware state - */ - intelFlush( &intel->ctx ); - - SET_STATE( i830, meta ); - set_initial_state( i830 ); - set_no_texture( i830 ); - set_vertex_format( i830 ); - set_no_depth_stencil_write( i830 ); - set_color_mask( i830, GL_FALSE ); - - LOCK_HARDWARE(intel); - - /* save current drawing origin and cliprects (restored at end) */ - xOrig = intel->drawX; - yOrig = intel->drawY; - origNumClipRects = intel->numClipRects; - origRects = intel->pClipRects; - - if (!intel->numClipRects) - goto done; - - /* - * set drawing origin, cliprects for full-screen access to rotated screen - */ - fullRect.x1 = 0; - fullRect.y1 = 0; - fullRect.x2 = screen->rotatedWidth; - fullRect.y2 = screen->rotatedHeight; - intel->drawX = 0; - intel->drawY = 0; - intel->numClipRects = 1; - intel->pClipRects = &fullRect; - - set_draw_region( i830, &screen->rotated ); - - if (cpp == 4) - textureFormat = MAPSURF_32BIT | MT_32BIT_ARGB8888; - else - textureFormat = MAPSURF_16BIT | MT_16BIT_RGB565; - - if (srcBuf == BUFFER_BIT_FRONT_LEFT) { - srcPitch = screen->front.pitch; /* in bytes */ - srcOffset = screen->front.offset; /* bytes */ - clipRects = dPriv->pClipRects; - numClipRects = dPriv->numClipRects; - } - else { - srcPitch = screen->back.pitch; /* in bytes */ - srcOffset = screen->back.offset; /* bytes */ - clipRects = dPriv->pBackClipRects; - numClipRects = dPriv->numBackClipRects; - } - - /* set the whole screen up as a texture to avoid alignment issues */ - set_tex_rect_source(i830, - srcOffset, - screen->width, - screen->height, - srcPitch, - textureFormat); - - enable_texture_blend_replace(i830); - - /* - * loop over the source window's cliprects - */ - for (i = 0; i < numClipRects; i++) { - int srcX0 = clipRects[i].x1; - int srcY0 = clipRects[i].y1; - int srcX1 = clipRects[i].x2; - int srcY1 = clipRects[i].y2; - GLfloat verts[4][2], tex[4][2]; - int j; - - /* build vertices for four corners of clip rect */ - verts[0][0] = srcX0; verts[0][1] = srcY0; - verts[1][0] = srcX1; verts[1][1] = srcY0; - verts[2][0] = srcX1; verts[2][1] = srcY1; - verts[3][0] = srcX0; verts[3][1] = srcY1; - - /* .. and texcoords */ - tex[0][0] = srcX0; tex[0][1] = srcY0; - tex[1][0] = srcX1; tex[1][1] = srcY0; - tex[2][0] = srcX1; tex[2][1] = srcY1; - tex[3][0] = srcX0; tex[3][1] = srcY1; - - /* transform coords to rotated screen coords */ - - for (j = 0; j < 4; j++) { - matrix23TransformCoordf(&screen->rotMatrix, - &verts[j][0], &verts[j][1]); - } - - /* draw polygon to map source image to dest region */ - draw_poly(i830, 255, 255, 255, 255, 4, verts, tex); - - } /* cliprect loop */ - - assert(!intel->prim.flush); - intelFlushBatchLocked( intel, GL_FALSE, GL_FALSE, GL_FALSE ); - - done: - /* restore original drawing origin and cliprects */ - intel->drawX = xOrig; - intel->drawY = yOrig; - intel->numClipRects = origNumClipRects; - intel->pClipRects = origRects; - - UNLOCK_HARDWARE(intel); - - SET_STATE( i830, state ); -} - diff --git a/src/mesa/drivers/dri/i915-tex/i830_reg.h b/src/mesa/drivers/dri/i915-tex/i830_reg.h deleted file mode 100644 index ff08683d7e3..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i830_reg.h +++ /dev/null @@ -1,641 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - - -#ifndef _I830_REG_H_ -#define _I830_REG_H_ - - -#include "intel_reg.h" - -#define I830_SET_FIELD( var, mask, value ) (var &= ~(mask), var |= value) - -#define _3DSTATE_AA_CMD (CMD_3D | (0x06<<24)) -#define AA_LINE_ECAAR_WIDTH_ENABLE (1<<16) -#define AA_LINE_ECAAR_WIDTH_0_5 0 -#define AA_LINE_ECAAR_WIDTH_1_0 (1<<14) -#define AA_LINE_ECAAR_WIDTH_2_0 (2<<14) -#define AA_LINE_ECAAR_WIDTH_4_0 (3<<14) -#define AA_LINE_REGION_WIDTH_ENABLE (1<<8) -#define AA_LINE_REGION_WIDTH_0_5 0 -#define AA_LINE_REGION_WIDTH_1_0 (1<<6) -#define AA_LINE_REGION_WIDTH_2_0 (2<<6) -#define AA_LINE_REGION_WIDTH_4_0 (3<<6) -#define AA_LINE_ENABLE ((1<<1) | 1) -#define AA_LINE_DISABLE (1<<1) - -#define _3DSTATE_BUF_INFO_CMD (CMD_3D | (0x1d<<24) | (0x8e<<16) | 1) -/* Dword 1 */ -#define BUF_3D_ID_COLOR_BACK (0x3<<24) -#define BUF_3D_ID_DEPTH (0x7<<24) -#define BUF_3D_USE_FENCE (1<<23) -#define BUF_3D_TILED_SURFACE (1<<22) -#define BUF_3D_TILE_WALK_X 0 -#define BUF_3D_TILE_WALK_Y (1<<21) -#define BUF_3D_PITCH(x) (((x)/4)<<2) -/* Dword 2 */ -#define BUF_3D_ADDR(x) ((x) & ~0x3) - - -#define _3DSTATE_COLOR_FACTOR_CMD (CMD_3D | (0x1d<<24) | (0x1<<16)) - -#define _3DSTATE_COLOR_FACTOR_N_CMD(stage) (CMD_3D | (0x1d<<24) | \ - ((0x90+(stage))<<16)) - -#define _3DSTATE_CONST_BLEND_COLOR_CMD (CMD_3D | (0x1d<<24) | (0x88<<16)) - -#define _3DSTATE_DFLT_DIFFUSE_CMD (CMD_3D | (0x1d<<24) | (0x99<<16)) - -#define _3DSTATE_DFLT_SPEC_CMD (CMD_3D | (0x1d<<24) | (0x9a<<16)) - -#define _3DSTATE_DFLT_Z_CMD (CMD_3D | (0x1d<<24) | (0x98<<16)) - - -#define _3DSTATE_DST_BUF_VARS_CMD (CMD_3D | (0x1d<<24) | (0x85<<16)) -/* Dword 1 */ -#define DSTORG_HORT_BIAS(x) ((x)<<20) -#define DSTORG_VERT_BIAS(x) ((x)<<16) -#define COLOR_4_2_2_CHNL_WRT_ALL 0 -#define COLOR_4_2_2_CHNL_WRT_Y (1<<12) -#define COLOR_4_2_2_CHNL_WRT_CR (2<<12) -#define COLOR_4_2_2_CHNL_WRT_CB (3<<12) -#define COLOR_4_2_2_CHNL_WRT_CRCB (4<<12) -#define COLR_BUF_8BIT 0 -#define COLR_BUF_RGB555 (1<<8) -#define COLR_BUF_RGB565 (2<<8) -#define COLR_BUF_ARGB8888 (3<<8) -#define DEPTH_IS_Z 0 -#define DEPTH_IS_W (1<<6) -#define DEPTH_FRMT_16_FIXED 0 -#define DEPTH_FRMT_16_FLOAT (1<<2) -#define DEPTH_FRMT_24_FIXED_8_OTHER (2<<2) -#define DEPTH_FRMT_24_FLOAT_8_OTHER (3<<2) -#define VERT_LINE_STRIDE_1 (1<<1) -#define VERT_LINE_STRIDE_0 0 -#define VERT_LINE_STRIDE_OFS_1 1 -#define VERT_LINE_STRIDE_OFS_0 0 - - -#define _3DSTATE_DRAW_RECT_CMD (CMD_3D|(0x1d<<24)|(0x80<<16)|3) -/* Dword 1 */ -#define DRAW_RECT_DIS_DEPTH_OFS (1<<30) -#define DRAW_DITHER_OFS_X(x) ((x)<<26) -#define DRAW_DITHER_OFS_Y(x) ((x)<<24) -/* Dword 2 */ -#define DRAW_YMIN(x) ((x)<<16) -#define DRAW_XMIN(x) (x) -/* Dword 3 */ -#define DRAW_YMAX(x) ((x)<<16) -#define DRAW_XMAX(x) (x) -/* Dword 4 */ -#define DRAW_YORG(x) ((x)<<16) -#define DRAW_XORG(x) (x) - - -#define _3DSTATE_ENABLES_1_CMD (CMD_3D|(0x3<<24)) -#define ENABLE_LOGIC_OP_MASK ((1<<23)|(1<<22)) -#define ENABLE_LOGIC_OP ((1<<23)|(1<<22)) -#define DISABLE_LOGIC_OP (1<<23) -#define ENABLE_STENCIL_TEST ((1<<21)|(1<<20)) -#define DISABLE_STENCIL_TEST (1<<21) -#define ENABLE_DEPTH_BIAS ((1<<11)|(1<<10)) -#define DISABLE_DEPTH_BIAS (1<<11) -#define ENABLE_SPEC_ADD_MASK ((1<<9)|(1<<8)) -#define ENABLE_SPEC_ADD ((1<<9)|(1<<8)) -#define DISABLE_SPEC_ADD (1<<9) -#define ENABLE_DIS_FOG_MASK ((1<<7)|(1<<6)) -#define ENABLE_FOG ((1<<7)|(1<<6)) -#define DISABLE_FOG (1<<7) -#define ENABLE_DIS_ALPHA_TEST_MASK ((1<<5)|(1<<4)) -#define ENABLE_ALPHA_TEST ((1<<5)|(1<<4)) -#define DISABLE_ALPHA_TEST (1<<5) -#define ENABLE_DIS_CBLEND_MASK ((1<<3)|(1<<2)) -#define ENABLE_COLOR_BLEND ((1<<3)|(1<<2)) -#define DISABLE_COLOR_BLEND (1<<3) -#define ENABLE_DIS_DEPTH_TEST_MASK ((1<<1)|1) -#define ENABLE_DEPTH_TEST ((1<<1)|1) -#define DISABLE_DEPTH_TEST (1<<1) - -/* _3DSTATE_ENABLES_2, p138 */ -#define _3DSTATE_ENABLES_2_CMD (CMD_3D|(0x4<<24)) -#define ENABLE_STENCIL_WRITE ((1<<21)|(1<<20)) -#define DISABLE_STENCIL_WRITE (1<<21) -#define ENABLE_TEX_CACHE ((1<<17)|(1<<16)) -#define DISABLE_TEX_CACHE (1<<17) -#define ENABLE_DITHER ((1<<9)|(1<<8)) -#define DISABLE_DITHER (1<<9) -#define ENABLE_COLOR_MASK (1<<10) -#define WRITEMASK_ALPHA (1<<7) -#define WRITEMASK_ALPHA_SHIFT 7 -#define WRITEMASK_RED (1<<6) -#define WRITEMASK_RED_SHIFT 6 -#define WRITEMASK_GREEN (1<<5) -#define WRITEMASK_GREEN_SHIFT 5 -#define WRITEMASK_BLUE (1<<4) -#define WRITEMASK_BLUE_SHIFT 4 -#define WRITEMASK_MASK ((1<<4)|(1<<5)|(1<<6)|(1<<7)) -#define ENABLE_COLOR_WRITE ((1<<3)|(1<<2)) -#define DISABLE_COLOR_WRITE (1<<3) -#define ENABLE_DIS_DEPTH_WRITE_MASK 0x3 -#define ENABLE_DEPTH_WRITE ((1<<1)|1) -#define DISABLE_DEPTH_WRITE (1<<1) - -/* _3DSTATE_FOG_COLOR, p139 */ -#define _3DSTATE_FOG_COLOR_CMD (CMD_3D|(0x15<<24)) -#define FOG_COLOR_RED(x) ((x)<<16) -#define FOG_COLOR_GREEN(x) ((x)<<8) -#define FOG_COLOR_BLUE(x) (x) - -/* _3DSTATE_FOG_MODE, p140 */ -#define _3DSTATE_FOG_MODE_CMD (CMD_3D|(0x1d<<24)|(0x89<<16)|2) -/* Dword 1 */ -#define FOGFUNC_ENABLE (1<<31) -#define FOGFUNC_VERTEX 0 -#define FOGFUNC_PIXEL_EXP (1<<28) -#define FOGFUNC_PIXEL_EXP2 (2<<28) -#define FOGFUNC_PIXEL_LINEAR (3<<28) -#define FOGSRC_INDEX_Z (1<<27) -#define FOGSRC_INDEX_W ((1<<27)|(1<<25)) -#define FOG_LINEAR_CONST (1<<24) -#define FOG_CONST_1(x) ((x)<<4) -#define ENABLE_FOG_DENSITY (1<<23) -/* Dword 2 */ -#define FOG_CONST_2(x) (x) -/* Dword 3 */ -#define FOG_DENSITY(x) (x) - -/* _3DSTATE_INDEPENDENT_ALPHA_BLEND, p142 */ -#define _3DSTATE_INDPT_ALPHA_BLEND_CMD (CMD_3D|(0x0b<<24)) -#define ENABLE_INDPT_ALPHA_BLEND ((1<<23)|(1<<22)) -#define DISABLE_INDPT_ALPHA_BLEND (1<<23) -#define ALPHA_BLENDFUNC_MASK 0x3f0000 -#define ENABLE_ALPHA_BLENDFUNC (1<<21) -#define ABLENDFUNC_ADD 0 -#define ABLENDFUNC_SUB (1<<16) -#define ABLENDFUNC_RVSE_SUB (2<<16) -#define ABLENDFUNC_MIN (3<<16) -#define ABLENDFUNC_MAX (4<<16) -#define SRC_DST_ABLEND_MASK 0xfff -#define ENABLE_SRC_ABLEND_FACTOR (1<<11) -#define SRC_ABLEND_FACT(x) ((x)<<6) -#define ENABLE_DST_ABLEND_FACTOR (1<<5) -#define DST_ABLEND_FACT(x) (x) - - -/* _3DSTATE_MAP_BLEND_ARG, p152 */ -#define _3DSTATE_MAP_BLEND_ARG_CMD(stage) (CMD_3D|(0x0e<<24)|((stage)<<20)) - -#define TEXPIPE_COLOR 0 -#define TEXPIPE_ALPHA (1<<18) -#define TEXPIPE_KILL (2<<18) -#define TEXBLEND_ARG0 0 -#define TEXBLEND_ARG1 (1<<15) -#define TEXBLEND_ARG2 (2<<15) -#define TEXBLEND_ARG3 (3<<15) -#define TEXBLENDARG_MODIFY_PARMS (1<<6) -#define TEXBLENDARG_REPLICATE_ALPHA (1<<5) -#define TEXBLENDARG_INV_ARG (1<<4) -#define TEXBLENDARG_ONE 0 -#define TEXBLENDARG_FACTOR 0x01 -#define TEXBLENDARG_ACCUM 0x02 -#define TEXBLENDARG_DIFFUSE 0x03 -#define TEXBLENDARG_SPEC 0x04 -#define TEXBLENDARG_CURRENT 0x05 -#define TEXBLENDARG_TEXEL0 0x06 -#define TEXBLENDARG_TEXEL1 0x07 -#define TEXBLENDARG_TEXEL2 0x08 -#define TEXBLENDARG_TEXEL3 0x09 -#define TEXBLENDARG_FACTOR_N 0x0e - -/* _3DSTATE_MAP_BLEND_OP, p155 */ -#define _3DSTATE_MAP_BLEND_OP_CMD(stage) (CMD_3D|(0x0d<<24)|((stage)<<20)) -#if 0 -# define TEXPIPE_COLOR 0 -# define TEXPIPE_ALPHA (1<<18) -# define TEXPIPE_KILL (2<<18) -#endif -#define ENABLE_TEXOUTPUT_WRT_SEL (1<<17) -#define TEXOP_OUTPUT_CURRENT 0 -#define TEXOP_OUTPUT_ACCUM (1<<15) -#define ENABLE_TEX_CNTRL_STAGE ((1<<12)|(1<<11)) -#define DISABLE_TEX_CNTRL_STAGE (1<<12) -#define TEXOP_SCALE_SHIFT 9 -#define TEXOP_SCALE_1X (0 << TEXOP_SCALE_SHIFT) -#define TEXOP_SCALE_2X (1 << TEXOP_SCALE_SHIFT) -#define TEXOP_SCALE_4X (2 << TEXOP_SCALE_SHIFT) -#define TEXOP_MODIFY_PARMS (1<<8) -#define TEXOP_LAST_STAGE (1<<7) -#define TEXBLENDOP_KILLPIXEL 0x02 -#define TEXBLENDOP_ARG1 0x01 -#define TEXBLENDOP_ARG2 0x02 -#define TEXBLENDOP_MODULATE 0x03 -#define TEXBLENDOP_ADD 0x06 -#define TEXBLENDOP_ADDSIGNED 0x07 -#define TEXBLENDOP_BLEND 0x08 -#define TEXBLENDOP_BLEND_AND_ADD 0x09 -#define TEXBLENDOP_SUBTRACT 0x0a -#define TEXBLENDOP_DOT3 0x0b -#define TEXBLENDOP_DOT4 0x0c -#define TEXBLENDOP_MODULATE_AND_ADD 0x0d -#define TEXBLENDOP_MODULATE_2X_AND_ADD 0x0e -#define TEXBLENDOP_MODULATE_4X_AND_ADD 0x0f - -/* _3DSTATE_MAP_BUMP_TABLE, p160 TODO */ -/* _3DSTATE_MAP_COLOR_CHROMA_KEY, p161 TODO */ - -#define _3DSTATE_MAP_COORD_TRANSFORM ((3<<29)|(0x1d<<24)|(0x8c<<16)) -#define DISABLE_TEX_TRANSFORM (1<<28) -#define TEXTURE_SET(x) (x<<29) - -#define _3DSTATE_VERTEX_TRANSFORM ((3<<29)|(0x1d<<24)|(0x8b<<16)) -#define DISABLE_VIEWPORT_TRANSFORM (1<<31) -#define DISABLE_PERSPECTIVE_DIVIDE (1<<29) - - -/* _3DSTATE_MAP_COORD_SET_BINDINGS, p162 */ -#define _3DSTATE_MAP_COORD_SETBIND_CMD (CMD_3D|(0x1d<<24)|(0x02<<16)) -#define TEXBIND_MASK3 ((1<<15)|(1<<14)|(1<<13)|(1<<12)) -#define TEXBIND_MASK2 ((1<<11)|(1<<10)|(1<<9)|(1<<8)) -#define TEXBIND_MASK1 ((1<<7)|(1<<6)|(1<<5)|(1<<4)) -#define TEXBIND_MASK0 ((1<<3)|(1<<2)|(1<<1)|1) - -#define TEXBIND_SET3(x) ((x)<<12) -#define TEXBIND_SET2(x) ((x)<<8) -#define TEXBIND_SET1(x) ((x)<<4) -#define TEXBIND_SET0(x) (x) - -#define TEXCOORDSRC_KEEP 0 -#define TEXCOORDSRC_DEFAULT 0x01 -#define TEXCOORDSRC_VTXSET_0 0x08 -#define TEXCOORDSRC_VTXSET_1 0x09 -#define TEXCOORDSRC_VTXSET_2 0x0a -#define TEXCOORDSRC_VTXSET_3 0x0b -#define TEXCOORDSRC_VTXSET_4 0x0c -#define TEXCOORDSRC_VTXSET_5 0x0d -#define TEXCOORDSRC_VTXSET_6 0x0e -#define TEXCOORDSRC_VTXSET_7 0x0f - -#define MAP_UNIT(unit) ((unit)<<16) -#define MAP_UNIT_MASK (0x7<<16) - -/* _3DSTATE_MAP_COORD_SETS, p164 */ -#define _3DSTATE_MAP_COORD_SET_CMD (CMD_3D|(0x1c<<24)|(0x01<<19)) -#define ENABLE_TEXCOORD_PARAMS (1<<15) -#define TEXCOORDS_ARE_NORMAL (1<<14) -#define TEXCOORDS_ARE_IN_TEXELUNITS 0 -#define TEXCOORDTYPE_CARTESIAN 0 -#define TEXCOORDTYPE_HOMOGENEOUS (1<<11) -#define TEXCOORDTYPE_VECTOR (2<<11) -#define TEXCOORDTYPE_MASK (0x7<<11) -#define ENABLE_ADDR_V_CNTL (1<<7) -#define ENABLE_ADDR_U_CNTL (1<<3) -#define TEXCOORD_ADDR_V_MODE(x) ((x)<<4) -#define TEXCOORD_ADDR_U_MODE(x) (x) -#define TEXCOORDMODE_WRAP 0 -#define TEXCOORDMODE_MIRROR 1 -#define TEXCOORDMODE_CLAMP 2 -#define TEXCOORDMODE_WRAP_SHORTEST 3 -#define TEXCOORDMODE_CLAMP_BORDER 4 -#define TEXCOORD_ADDR_V_MASK 0x70 -#define TEXCOORD_ADDR_U_MASK 0x7 - -/* _3DSTATE_MAP_CUBE, p168 TODO */ -#define _3DSTATE_MAP_CUBE (CMD_3D|(0x1c<<24)|(0x0a<<19)) -#define CUBE_NEGX_ENABLE (1<<5) -#define CUBE_POSX_ENABLE (1<<4) -#define CUBE_NEGY_ENABLE (1<<3) -#define CUBE_POSY_ENABLE (1<<2) -#define CUBE_NEGZ_ENABLE (1<<1) -#define CUBE_POSZ_ENABLE (1<<0) - - -/* _3DSTATE_MODES_1, p190 */ -#define _3DSTATE_MODES_1_CMD (CMD_3D|(0x08<<24)) -#define BLENDFUNC_MASK 0x3f0000 -#define ENABLE_COLR_BLND_FUNC (1<<21) -#define BLENDFUNC_ADD 0 -#define BLENDFUNC_SUB (1<<16) -#define BLENDFUNC_RVRSE_SUB (2<<16) -#define BLENDFUNC_MIN (3<<16) -#define BLENDFUNC_MAX (4<<16) -#define SRC_DST_BLND_MASK 0xfff -#define ENABLE_SRC_BLND_FACTOR (1<<11) -#define ENABLE_DST_BLND_FACTOR (1<<5) -#define SRC_BLND_FACT(x) ((x)<<6) -#define DST_BLND_FACT(x) (x) - - -/* _3DSTATE_MODES_2, p192 */ -#define _3DSTATE_MODES_2_CMD (CMD_3D|(0x0f<<24)) -#define ENABLE_GLOBAL_DEPTH_BIAS (1<<22) -#define GLOBAL_DEPTH_BIAS(x) ((x)<<14) -#define ENABLE_ALPHA_TEST_FUNC (1<<13) -#define ENABLE_ALPHA_REF_VALUE (1<<8) -#define ALPHA_TEST_FUNC(x) ((x)<<9) -#define ALPHA_REF_VALUE(x) (x) - -#define ALPHA_TEST_REF_MASK 0x3fff - -/* _3DSTATE_MODES_3, p193 */ -#define _3DSTATE_MODES_3_CMD (CMD_3D|(0x02<<24)) -#define DEPTH_TEST_FUNC_MASK 0x1f0000 -#define ENABLE_DEPTH_TEST_FUNC (1<<20) -/* Uses COMPAREFUNC */ -#define DEPTH_TEST_FUNC(x) ((x)<<16) -#define ENABLE_ALPHA_SHADE_MODE (1<<11) -#define ENABLE_FOG_SHADE_MODE (1<<9) -#define ENABLE_SPEC_SHADE_MODE (1<<7) -#define ENABLE_COLOR_SHADE_MODE (1<<5) -#define ALPHA_SHADE_MODE(x) ((x)<<10) -#define FOG_SHADE_MODE(x) ((x)<<8) -#define SPEC_SHADE_MODE(x) ((x)<<6) -#define COLOR_SHADE_MODE(x) ((x)<<4) -#define CULLMODE_MASK 0xf -#define ENABLE_CULL_MODE (1<<3) -#define CULLMODE_BOTH 0 -#define CULLMODE_NONE 1 -#define CULLMODE_CW 2 -#define CULLMODE_CCW 3 - -#define SHADE_MODE_LINEAR 0 -#define SHADE_MODE_FLAT 0x1 - -/* _3DSTATE_MODES_4, p195 */ -#define _3DSTATE_MODES_4_CMD (CMD_3D|(0x16<<24)) -#define ENABLE_LOGIC_OP_FUNC (1<<23) -#define LOGIC_OP_FUNC(x) ((x)<<18) -#define LOGICOP_MASK ((1<<18)|(1<<19)|(1<<20)|(1<<21)) -#define LOGICOP_CLEAR 0 -#define LOGICOP_NOR 0x1 -#define LOGICOP_AND_INV 0x2 -#define LOGICOP_COPY_INV 0x3 -#define LOGICOP_AND_RVRSE 0x4 -#define LOGICOP_INV 0x5 -#define LOGICOP_XOR 0x6 -#define LOGICOP_NAND 0x7 -#define LOGICOP_AND 0x8 -#define LOGICOP_EQUIV 0x9 -#define LOGICOP_NOOP 0xa -#define LOGICOP_OR_INV 0xb -#define LOGICOP_COPY 0xc -#define LOGICOP_OR_RVRSE 0xd -#define LOGICOP_OR 0xe -#define LOGICOP_SET 0xf -#define MODE4_ENABLE_STENCIL_TEST_MASK ((1<<17)|(0xff00)) -#define ENABLE_STENCIL_TEST_MASK (1<<17) -#define STENCIL_TEST_MASK(x) (((x)&0xff)<<8) -#define MODE4_ENABLE_STENCIL_WRITE_MASK ((1<<16)|(0x00ff)) -#define ENABLE_STENCIL_WRITE_MASK (1<<16) -#define STENCIL_WRITE_MASK(x) ((x)&0xff) - -/* _3DSTATE_MODES_5, p196 */ -#define _3DSTATE_MODES_5_CMD (CMD_3D|(0x0c<<24)) -#define ENABLE_SPRITE_POINT_TEX (1<<23) -#define SPRITE_POINT_TEX_ON (1<<22) -#define SPRITE_POINT_TEX_OFF 0 -#define FLUSH_RENDER_CACHE (1<<18) -#define FLUSH_TEXTURE_CACHE (1<<16) -#define FIXED_LINE_WIDTH_MASK 0xfc00 -#define ENABLE_FIXED_LINE_WIDTH (1<<15) -#define FIXED_LINE_WIDTH(x) ((x)<<10) -#define FIXED_POINT_WIDTH_MASK 0x3ff -#define ENABLE_FIXED_POINT_WIDTH (1<<9) -#define FIXED_POINT_WIDTH(x) (x) - -/* _3DSTATE_RASTERIZATION_RULES, p198 */ -#define _3DSTATE_RASTER_RULES_CMD (CMD_3D|(0x07<<24)) -#define ENABLE_POINT_RASTER_RULE (1<<15) -#define OGL_POINT_RASTER_RULE (1<<13) -#define ENABLE_LINE_STRIP_PROVOKE_VRTX (1<<8) -#define ENABLE_TRI_FAN_PROVOKE_VRTX (1<<5) -#define ENABLE_TRI_STRIP_PROVOKE_VRTX (1<<2) -#define LINE_STRIP_PROVOKE_VRTX(x) ((x)<<6) -#define TRI_FAN_PROVOKE_VRTX(x) ((x)<<3) -#define TRI_STRIP_PROVOKE_VRTX(x) (x) - -/* _3DSTATE_SCISSOR_ENABLE, p200 */ -#define _3DSTATE_SCISSOR_ENABLE_CMD (CMD_3D|(0x1c<<24)|(0x10<<19)) -#define ENABLE_SCISSOR_RECT ((1<<1) | 1) -#define DISABLE_SCISSOR_RECT (1<<1) - -/* _3DSTATE_SCISSOR_RECTANGLE_0, p201 */ -#define _3DSTATE_SCISSOR_RECT_0_CMD (CMD_3D|(0x1d<<24)|(0x81<<16)|1) -/* Dword 1 */ -#define SCISSOR_RECT_0_YMIN(x) ((x)<<16) -#define SCISSOR_RECT_0_XMIN(x) (x) -/* Dword 2 */ -#define SCISSOR_RECT_0_YMAX(x) ((x)<<16) -#define SCISSOR_RECT_0_XMAX(x) (x) - -/* _3DSTATE_STENCIL_TEST, p202 */ -#define _3DSTATE_STENCIL_TEST_CMD (CMD_3D|(0x09<<24)) -#define ENABLE_STENCIL_PARMS (1<<23) -#define STENCIL_OPS_MASK (0xffc000) -#define STENCIL_FAIL_OP(x) ((x)<<20) -#define STENCIL_PASS_DEPTH_FAIL_OP(x) ((x)<<17) -#define STENCIL_PASS_DEPTH_PASS_OP(x) ((x)<<14) - -#define ENABLE_STENCIL_TEST_FUNC_MASK ((1<<13)|(1<<12)|(1<<11)|(1<<10)|(1<<9)) -#define ENABLE_STENCIL_TEST_FUNC (1<<13) -/* Uses COMPAREFUNC */ -#define STENCIL_TEST_FUNC(x) ((x)<<9) -#define STENCIL_REF_VALUE_MASK ((1<<8)|0xff) -#define ENABLE_STENCIL_REF_VALUE (1<<8) -#define STENCIL_REF_VALUE(x) (x) - -/* _3DSTATE_VERTEX_FORMAT, p204 */ -#define _3DSTATE_VFT0_CMD (CMD_3D|(0x05<<24)) -#define VFT0_POINT_WIDTH (1<<12) -#define VFT0_TEX_COUNT_MASK (7<<8) -#define VFT0_TEX_COUNT_SHIFT 8 -#define VFT0_TEX_COUNT(x) ((x)<<8) -#define VFT0_SPEC (1<<7) -#define VFT0_DIFFUSE (1<<6) -#define VFT0_DEPTH_OFFSET (1<<5) -#define VFT0_XYZ (1<<1) -#define VFT0_XYZW (2<<1) -#define VFT0_XY (3<<1) -#define VFT0_XYW (4<<1) -#define VFT0_XYZW_MASK (7<<1) - -/* _3DSTATE_VERTEX_FORMAT_2, p206 */ -#define _3DSTATE_VFT1_CMD (CMD_3D|(0x0a<<24)) -#define VFT1_TEX7_FMT(x) ((x)<<14) -#define VFT1_TEX6_FMT(x) ((x)<<12) -#define VFT1_TEX5_FMT(x) ((x)<<10) -#define VFT1_TEX4_FMT(x) ((x)<<8) -#define VFT1_TEX3_FMT(x) ((x)<<6) -#define VFT1_TEX2_FMT(x) ((x)<<4) -#define VFT1_TEX1_FMT(x) ((x)<<2) -#define VFT1_TEX0_FMT(x) (x) -#define VFT1_TEX0_MASK 3 -#define VFT1_TEX1_SHIFT 2 -#define TEXCOORDFMT_2D 0 -#define TEXCOORDFMT_3D 1 -#define TEXCOORDFMT_4D 2 -#define TEXCOORDFMT_1D 3 - -/*New stuff picked up along the way */ - -#define MLC_LOD_BIAS_MASK ((1<<7)-1) - - -/* _3DSTATE_VERTEX_TRANSFORM, p207 */ -#define _3DSTATE_VERTEX_TRANS_CMD (CMD_3D|(0x1d<<24)|(0x8b<<16)|0) -#define _3DSTATE_VERTEX_TRANS_MTX_CMD (CMD_3D|(0x1d<<24)|(0x8b<<16)|6) -/* Dword 1 */ -#define ENABLE_VIEWPORT_TRANSFORM ((1<<31)|(1<<30)) -#define DISABLE_VIEWPORT_TRANSFORM (1<<31) -#define ENABLE_PERSP_DIVIDE ((1<<29)|(1<<28)) -#define DISABLE_PERSP_DIVIDE (1<<29) -#define VRTX_TRANS_LOAD_MATRICES 0x7421 -#define VRTX_TRANS_NO_LOAD_MATRICES 0x0000 -/* Dword 2 -> 7 are matrix elements */ - -/* _3DSTATE_W_STATE, p209 */ -#define _3DSTATE_W_STATE_CMD (CMD_3D|(0x1d<<24)|(0x8d<<16)|1) -/* Dword 1 */ -#define MAGIC_W_STATE_DWORD1 0x00000008 -/* Dword 2 */ -#define WFAR_VALUE(x) (x) - - -/* Stipple command, carried over from the i810, apparently: - */ -#define _3DSTATE_STIPPLE ((0x3<<29)|(0x1d<<24)|(0x83<<16)) -#define ST1_ENABLE (1<<16) -#define ST1_MASK (0xffff) - - - -#define _3DSTATE_LOAD_STATE_IMMEDIATE_2 ((0x3<<29)|(0x1d<<24)|(0x03<<16)) -#define LOAD_TEXTURE_MAP0 (1<<11) -#define LOAD_GLOBAL_COLOR_FACTOR (1<<6) - -#define TM0S0_ADDRESS_MASK 0xfffffffc -#define TM0S0_USE_FENCE (1<<1) - -#define TM0S1_HEIGHT_SHIFT 21 -#define TM0S1_WIDTH_SHIFT 10 -#define TM0S1_PALETTE_SELECT (1<<9) -#define TM0S1_MAPSURF_FORMAT_MASK (0x7 << 6) -#define TM0S1_MAPSURF_FORMAT_SHIFT 6 -#define MAPSURF_8BIT_INDEXED (0<<6) -#define MAPSURF_8BIT (1<<6) -#define MAPSURF_16BIT (2<<6) -#define MAPSURF_32BIT (3<<6) -#define MAPSURF_411 (4<<6) -#define MAPSURF_422 (5<<6) -#define MAPSURF_COMPRESSED (6<<6) -#define MAPSURF_4BIT_INDEXED (7<<6) -#define TM0S1_MT_FORMAT_MASK (0x7 << 3) -#define TM0S1_MT_FORMAT_SHIFT 3 -#define MT_4BIT_IDX_ARGB8888 (7<<3) /* SURFACE_4BIT_INDEXED */ -#define MT_8BIT_IDX_RGB565 (0<<3) /* SURFACE_8BIT_INDEXED */ -#define MT_8BIT_IDX_ARGB1555 (1<<3) -#define MT_8BIT_IDX_ARGB4444 (2<<3) -#define MT_8BIT_IDX_AY88 (3<<3) -#define MT_8BIT_IDX_ABGR8888 (4<<3) -#define MT_8BIT_IDX_BUMP_88DVDU (5<<3) -#define MT_8BIT_IDX_BUMP_655LDVDU (6<<3) -#define MT_8BIT_IDX_ARGB8888 (7<<3) -#define MT_8BIT_I8 (0<<3) /* SURFACE_8BIT */ -#define MT_8BIT_L8 (1<<3) -#define MT_16BIT_RGB565 (0<<3) /* SURFACE_16BIT */ -#define MT_16BIT_ARGB1555 (1<<3) -#define MT_16BIT_ARGB4444 (2<<3) -#define MT_16BIT_AY88 (3<<3) -#define MT_16BIT_DIB_ARGB1555_8888 (4<<3) -#define MT_16BIT_BUMP_88DVDU (5<<3) -#define MT_16BIT_BUMP_655LDVDU (6<<3) -#define MT_16BIT_DIB_RGB565_8888 (7<<3) -#define MT_32BIT_ARGB8888 (0<<3) /* SURFACE_32BIT */ -#define MT_32BIT_ABGR8888 (1<<3) -#define MT_32BIT_BUMP_XLDVDU_8888 (6<<3) -#define MT_32BIT_DIB_8888 (7<<3) -#define MT_411_YUV411 (0<<3) /* SURFACE_411 */ -#define MT_422_YCRCB_SWAPY (0<<3) /* SURFACE_422 */ -#define MT_422_YCRCB_NORMAL (1<<3) -#define MT_422_YCRCB_SWAPUV (2<<3) -#define MT_422_YCRCB_SWAPUVY (3<<3) -#define MT_COMPRESS_DXT1 (0<<3) /* SURFACE_COMPRESSED */ -#define MT_COMPRESS_DXT2_3 (1<<3) -#define MT_COMPRESS_DXT4_5 (2<<3) -#define MT_COMPRESS_FXT1 (3<<3) -#define TM0S1_COLORSPACE_CONVERSION (1 << 2) -#define TM0S1_TILED_SURFACE (1 << 1) -#define TM0S1_TILE_WALK (1 << 0) - -#define TM0S2_PITCH_SHIFT 21 -#define TM0S2_CUBE_FACE_ENA_SHIFT 15 -#define TM0S2_CUBE_FACE_ENA_MASK (1<<15) -#define TM0S2_MAP_FORMAT (1<<14) -#define TM0S2_VERTICAL_LINE_STRIDE (1<<13) -#define TM0S2_VERITCAL_LINE_STRIDE_OFF (1<<12) -#define TM0S2_OUTPUT_CHAN_SHIFT 10 -#define TM0S2_OUTPUT_CHAN_MASK (3<<10) - -#define TM0S3_MIP_FILTER_MASK (0x3<<30) -#define TM0S3_MIP_FILTER_SHIFT 30 -#define MIPFILTER_NONE 0 -#define MIPFILTER_NEAREST 1 -#define MIPFILTER_LINEAR 3 -#define TM0S3_MAG_FILTER_MASK (0x3<<28) -#define TM0S3_MAG_FILTER_SHIFT 28 -#define TM0S3_MIN_FILTER_MASK (0x3<<26) -#define TM0S3_MIN_FILTER_SHIFT 26 -#define FILTER_NEAREST 0 -#define FILTER_LINEAR 1 -#define FILTER_ANISOTROPIC 2 - -#define TM0S3_LOD_BIAS_SHIFT 17 -#define TM0S3_LOD_BIAS_MASK (0x1ff<<17) -#define TM0S3_MAX_MIP_SHIFT 9 -#define TM0S3_MAX_MIP_MASK (0xff<<9) -#define TM0S3_MIN_MIP_SHIFT 3 -#define TM0S3_MIN_MIP_MASK (0x3f<<3) -#define TM0S3_KILL_PIXEL (1<<2) -#define TM0S3_KEYED_FILTER (1<<1) -#define TM0S3_CHROMA_KEY (1<<0) - - -/* _3DSTATE_MAP_TEXEL_STREAM, p188 */ -#define _3DSTATE_MAP_TEX_STREAM_CMD (CMD_3D|(0x1c<<24)|(0x05<<19)) -#define DISABLE_TEX_STREAM_BUMP (1<<12) -#define ENABLE_TEX_STREAM_BUMP ((1<<12)|(1<<11)) -#define TEX_MODIFY_UNIT_0 0 -#define TEX_MODIFY_UNIT_1 (1<<8) -#define ENABLE_TEX_STREAM_COORD_SET (1<<7) -#define TEX_STREAM_COORD_SET(x) ((x)<<4) -#define ENABLE_TEX_STREAM_MAP_IDX (1<<3) -#define TEX_STREAM_MAP_IDX(x) (x) - - -#define MI_FLUSH ((0<<29)|(4<<23)) -#define FLUSH_MAP_CACHE (1<<0) - -#endif diff --git a/src/mesa/drivers/dri/i915-tex/i830_state.c b/src/mesa/drivers/dri/i915-tex/i830_state.c deleted file mode 100644 index 7a514c33468..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i830_state.c +++ /dev/null @@ -1,1101 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - - -#include "glheader.h" -#include "context.h" -#include "macros.h" -#include "enums.h" -#include "dd.h" - -#include "texmem.h" - -#include "intel_screen.h" -#include "intel_batchbuffer.h" -#include "intel_fbo.h" - -#include "i830_context.h" -#include "i830_reg.h" - -static void -i830StencilFuncSeparate(GLcontext *ctx, GLenum face, GLenum func, GLint ref, - GLuint mask) -{ - struct i830_context *i830 = i830_context(ctx); - int test = intel_translate_compare_func(func); - - mask = mask & 0xff; - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s : func: %s, ref : 0x%x, mask: 0x%x\n", __FUNCTION__, - _mesa_lookup_enum_by_nr(func), ref, mask); - - - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - i830->state.Ctx[I830_CTXREG_STATE4] &= ~MODE4_ENABLE_STENCIL_TEST_MASK; - i830->state.Ctx[I830_CTXREG_STATE4] |= (ENABLE_STENCIL_TEST_MASK | - STENCIL_TEST_MASK(mask)); - i830->state.Ctx[I830_CTXREG_STENCILTST] &= ~(STENCIL_REF_VALUE_MASK | - ENABLE_STENCIL_TEST_FUNC_MASK); - i830->state.Ctx[I830_CTXREG_STENCILTST] |= (ENABLE_STENCIL_REF_VALUE | - ENABLE_STENCIL_TEST_FUNC | - STENCIL_REF_VALUE(ref) | - STENCIL_TEST_FUNC(test)); -} - -static void -i830StencilMaskSeparate(GLcontext *ctx, GLenum face, GLuint mask) -{ - struct i830_context *i830 = i830_context(ctx); - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s : mask 0x%x\n", __FUNCTION__, mask); - - mask = mask & 0xff; - - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - i830->state.Ctx[I830_CTXREG_STATE4] &= ~MODE4_ENABLE_STENCIL_WRITE_MASK; - i830->state.Ctx[I830_CTXREG_STATE4] |= (ENABLE_STENCIL_WRITE_MASK | - STENCIL_WRITE_MASK(mask)); -} - -static void -i830StencilOpSeparate(GLcontext *ctx, GLenum face, GLenum fail, GLenum zfail, - GLenum zpass) -{ - struct i830_context *i830 = i830_context(ctx); - int fop, dfop, dpop; - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s: fail : %s, zfail: %s, zpass : %s\n", __FUNCTION__, - _mesa_lookup_enum_by_nr(fail), - _mesa_lookup_enum_by_nr(zfail), - _mesa_lookup_enum_by_nr(zpass)); - - fop = 0; dfop = 0; dpop = 0; - - switch(fail) { - case GL_KEEP: - fop = STENCILOP_KEEP; - break; - case GL_ZERO: - fop = STENCILOP_ZERO; - break; - case GL_REPLACE: - fop = STENCILOP_REPLACE; - break; - case GL_INCR: - fop = STENCILOP_INCRSAT; - break; - case GL_DECR: - fop = STENCILOP_DECRSAT; - break; - case GL_INCR_WRAP: - fop = STENCILOP_INCR; - break; - case GL_DECR_WRAP: - fop = STENCILOP_DECR; - break; - case GL_INVERT: - fop = STENCILOP_INVERT; - break; - default: - break; - } - switch(zfail) { - case GL_KEEP: - dfop = STENCILOP_KEEP; - break; - case GL_ZERO: - dfop = STENCILOP_ZERO; - break; - case GL_REPLACE: - dfop = STENCILOP_REPLACE; - break; - case GL_INCR: - dfop = STENCILOP_INCRSAT; - break; - case GL_DECR: - dfop = STENCILOP_DECRSAT; - break; - case GL_INCR_WRAP: - dfop = STENCILOP_INCR; - break; - case GL_DECR_WRAP: - dfop = STENCILOP_DECR; - break; - case GL_INVERT: - dfop = STENCILOP_INVERT; - break; - default: - break; - } - switch(zpass) { - case GL_KEEP: - dpop = STENCILOP_KEEP; - break; - case GL_ZERO: - dpop = STENCILOP_ZERO; - break; - case GL_REPLACE: - dpop = STENCILOP_REPLACE; - break; - case GL_INCR: - dpop = STENCILOP_INCRSAT; - break; - case GL_DECR: - dpop = STENCILOP_DECRSAT; - break; - case GL_INCR_WRAP: - dpop = STENCILOP_INCR; - break; - case GL_DECR_WRAP: - dpop = STENCILOP_DECR; - break; - case GL_INVERT: - dpop = STENCILOP_INVERT; - break; - default: - break; - } - - - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - i830->state.Ctx[I830_CTXREG_STENCILTST] &= ~(STENCIL_OPS_MASK); - i830->state.Ctx[I830_CTXREG_STENCILTST] |= (ENABLE_STENCIL_PARMS | - STENCIL_FAIL_OP(fop) | - STENCIL_PASS_DEPTH_FAIL_OP(dfop) | - STENCIL_PASS_DEPTH_PASS_OP(dpop)); -} - -static void i830AlphaFunc(GLcontext *ctx, GLenum func, GLfloat ref) -{ - struct i830_context *i830 = i830_context(ctx); - int test = intel_translate_compare_func(func); - GLubyte refByte; - GLuint refInt; - - UNCLAMPED_FLOAT_TO_UBYTE(refByte, ref); - refInt = (GLuint)refByte; - - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - i830->state.Ctx[I830_CTXREG_STATE2] &= ~ALPHA_TEST_REF_MASK; - i830->state.Ctx[I830_CTXREG_STATE2] |= (ENABLE_ALPHA_TEST_FUNC | - ENABLE_ALPHA_REF_VALUE | - ALPHA_TEST_FUNC(test) | - ALPHA_REF_VALUE(refInt)); -} - -/** - * Makes sure that the proper enables are set for LogicOp, Independant Alpha - * Blend, and Blending. It needs to be called from numerous places where we - * could change the LogicOp or Independant Alpha Blend without subsequent - * calls to glEnable. - * - * \todo - * This function is substantially different from the old i830-specific driver. - * I'm not sure which is correct. - */ -static void i830EvalLogicOpBlendState(GLcontext *ctx) -{ - struct i830_context *i830 = i830_context(ctx); - - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - - if (ctx->Color._LogicOpEnabled) { - i830->state.Ctx[I830_CTXREG_ENABLES_1] &= ~(ENABLE_COLOR_BLEND | - ENABLE_LOGIC_OP_MASK); - i830->state.Ctx[I830_CTXREG_ENABLES_1] |= (DISABLE_COLOR_BLEND | - ENABLE_LOGIC_OP); - } else if (ctx->Color.BlendEnabled) { - i830->state.Ctx[I830_CTXREG_ENABLES_1] &= ~(ENABLE_COLOR_BLEND | - ENABLE_LOGIC_OP_MASK); - i830->state.Ctx[I830_CTXREG_ENABLES_1] |= (ENABLE_COLOR_BLEND | - DISABLE_LOGIC_OP); - } else { - i830->state.Ctx[I830_CTXREG_ENABLES_1] &= ~(ENABLE_COLOR_BLEND | - ENABLE_LOGIC_OP_MASK); - i830->state.Ctx[I830_CTXREG_ENABLES_1] |= (DISABLE_COLOR_BLEND | - DISABLE_LOGIC_OP); - } -} - -static void i830BlendColor(GLcontext *ctx, const GLfloat color[4]) -{ - struct i830_context *i830 = i830_context(ctx); - GLubyte r, g, b, a; - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s\n", __FUNCTION__); - - UNCLAMPED_FLOAT_TO_UBYTE(r, color[RCOMP]); - UNCLAMPED_FLOAT_TO_UBYTE(g, color[GCOMP]); - UNCLAMPED_FLOAT_TO_UBYTE(b, color[BCOMP]); - UNCLAMPED_FLOAT_TO_UBYTE(a, color[ACOMP]); - - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - i830->state.Ctx[I830_CTXREG_BLENDCOLOR1] = (a<<24) | (r<<16) | (g<<8) | b; -} - -/** - * Sets both the blend equation (called "function" in i830 docs) and the - * blend function (called "factor" in i830 docs). This is done in a single - * function because some blend equations (i.e., \c GL_MIN and \c GL_MAX) - * change the interpretation of the blend function. - */ -static void i830_set_blend_state( GLcontext * ctx ) -{ - struct i830_context *i830 = i830_context(ctx); - int funcA; - int funcRGB; - int eqnA; - int eqnRGB; - int iab; - int s1; - - - funcRGB = SRC_BLND_FACT( intel_translate_blend_factor( ctx->Color.BlendSrcRGB ) ) - | DST_BLND_FACT( intel_translate_blend_factor( ctx->Color.BlendDstRGB ) ); - - switch(ctx->Color.BlendEquationRGB) { - case GL_FUNC_ADD: - eqnRGB = BLENDFUNC_ADD; - break; - case GL_MIN: - eqnRGB = BLENDFUNC_MIN; - funcRGB = SRC_BLND_FACT(BLENDFACT_ONE) | DST_BLND_FACT(BLENDFACT_ONE); - break; - case GL_MAX: - eqnRGB = BLENDFUNC_MAX; - funcRGB = SRC_BLND_FACT(BLENDFACT_ONE) | DST_BLND_FACT(BLENDFACT_ONE); - break; - case GL_FUNC_SUBTRACT: - eqnRGB = BLENDFUNC_SUB; - break; - case GL_FUNC_REVERSE_SUBTRACT: - eqnRGB = BLENDFUNC_RVRSE_SUB; - break; - default: - fprintf( stderr, "[%s:%u] Invalid RGB blend equation (0x%04x).\n", - __FUNCTION__, __LINE__, ctx->Color.BlendEquationRGB ); - return; - } - - - funcA = SRC_ABLEND_FACT( intel_translate_blend_factor( ctx->Color.BlendSrcA ) ) - | DST_ABLEND_FACT( intel_translate_blend_factor( ctx->Color.BlendDstA ) ); - - switch(ctx->Color.BlendEquationA) { - case GL_FUNC_ADD: - eqnA = BLENDFUNC_ADD; - break; - case GL_MIN: - eqnA = BLENDFUNC_MIN; - funcA = SRC_BLND_FACT(BLENDFACT_ONE) | DST_BLND_FACT(BLENDFACT_ONE); - break; - case GL_MAX: - eqnA = BLENDFUNC_MAX; - funcA = SRC_BLND_FACT(BLENDFACT_ONE) | DST_BLND_FACT(BLENDFACT_ONE); - break; - case GL_FUNC_SUBTRACT: - eqnA = BLENDFUNC_SUB; - break; - case GL_FUNC_REVERSE_SUBTRACT: - eqnA = BLENDFUNC_RVRSE_SUB; - break; - default: - fprintf( stderr, "[%s:%u] Invalid alpha blend equation (0x%04x).\n", - __FUNCTION__, __LINE__, ctx->Color.BlendEquationA ); - return; - } - - iab = eqnA | funcA - | _3DSTATE_INDPT_ALPHA_BLEND_CMD - | ENABLE_SRC_ABLEND_FACTOR | ENABLE_DST_ABLEND_FACTOR - | ENABLE_ALPHA_BLENDFUNC; - s1 = eqnRGB | funcRGB - | _3DSTATE_MODES_1_CMD - | ENABLE_SRC_BLND_FACTOR | ENABLE_DST_BLND_FACTOR - | ENABLE_COLR_BLND_FUNC; - - if ( (eqnA | funcA) != (eqnRGB | funcRGB) ) - iab |= ENABLE_INDPT_ALPHA_BLEND; - else - iab |= DISABLE_INDPT_ALPHA_BLEND; - - if (iab != i830->state.Ctx[I830_CTXREG_IALPHAB] || - s1 != i830->state.Ctx[I830_CTXREG_STATE1]) { - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - i830->state.Ctx[I830_CTXREG_IALPHAB] = iab; - i830->state.Ctx[I830_CTXREG_STATE1] = s1; - } - - /* This will catch a logicop blend equation. It will also ensure - * independant alpha blend is really in the correct state (either enabled - * or disabled) if blending is already enabled. - */ - - i830EvalLogicOpBlendState(ctx); - - if (0) { - fprintf(stderr, "[%s:%u] STATE1: 0x%08x IALPHAB: 0x%08x blend is %sabled\n", - __FUNCTION__, __LINE__, - i830->state.Ctx[I830_CTXREG_STATE1], - i830->state.Ctx[I830_CTXREG_IALPHAB], - (ctx->Color.BlendEnabled) ? "en" : "dis"); - } -} - - -static void i830BlendEquationSeparate(GLcontext *ctx, GLenum modeRGB, - GLenum modeA) -{ - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s -> %s, %s\n", __FUNCTION__, - _mesa_lookup_enum_by_nr(modeRGB), - _mesa_lookup_enum_by_nr(modeA)); - - (void) modeRGB; - (void) modeA; - i830_set_blend_state( ctx ); -} - - -static void i830BlendFuncSeparate(GLcontext *ctx, GLenum sfactorRGB, - GLenum dfactorRGB, GLenum sfactorA, - GLenum dfactorA ) -{ - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s -> RGB(%s, %s) A(%s, %s)\n", __FUNCTION__, - _mesa_lookup_enum_by_nr(sfactorRGB), - _mesa_lookup_enum_by_nr(dfactorRGB), - _mesa_lookup_enum_by_nr(sfactorA), - _mesa_lookup_enum_by_nr(dfactorA)); - - (void) sfactorRGB; - (void) dfactorRGB; - (void) sfactorA; - (void) dfactorA; - i830_set_blend_state( ctx ); -} - - - -static void i830DepthFunc(GLcontext *ctx, GLenum func) -{ - struct i830_context *i830 = i830_context(ctx); - int test = intel_translate_compare_func(func); - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s\n", __FUNCTION__); - - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - i830->state.Ctx[I830_CTXREG_STATE3] &= ~DEPTH_TEST_FUNC_MASK; - i830->state.Ctx[I830_CTXREG_STATE3] |= (ENABLE_DEPTH_TEST_FUNC | - DEPTH_TEST_FUNC(test)); -} - -static void i830DepthMask(GLcontext *ctx, GLboolean flag) -{ - struct i830_context *i830 = i830_context(ctx); - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s flag (%d)\n", __FUNCTION__, flag); - - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - - i830->state.Ctx[I830_CTXREG_ENABLES_2] &= ~ENABLE_DIS_DEPTH_WRITE_MASK; - - if (flag && ctx->Depth.Test) - i830->state.Ctx[I830_CTXREG_ENABLES_2] |= ENABLE_DEPTH_WRITE; - else - i830->state.Ctx[I830_CTXREG_ENABLES_2] |= DISABLE_DEPTH_WRITE; -} - -/* ============================================================= - * Polygon stipple - * - * The i830 supports a 4x4 stipple natively, GL wants 32x32. - * Fortunately stipple is usually a repeating pattern. - */ -static void i830PolygonStipple( GLcontext *ctx, const GLubyte *mask ) -{ - struct i830_context *i830 = i830_context(ctx); - const GLubyte *m = mask; - GLubyte p[4]; - int i,j,k; - int active = (ctx->Polygon.StippleFlag && - i830->intel.reduced_primitive == GL_TRIANGLES); - GLuint newMask; - - if (active) { - I830_STATECHANGE(i830, I830_UPLOAD_STIPPLE); - i830->state.Stipple[I830_STPREG_ST1] &= ~ST1_ENABLE; - } - - p[0] = mask[12] & 0xf; p[0] |= p[0] << 4; - p[1] = mask[8] & 0xf; p[1] |= p[1] << 4; - p[2] = mask[4] & 0xf; p[2] |= p[2] << 4; - p[3] = mask[0] & 0xf; p[3] |= p[3] << 4; - - for (k = 0 ; k < 8 ; k++) - for (j = 3 ; j >= 0; j--) - for (i = 0 ; i < 4 ; i++, m++) - if (*m != p[j]) { - i830->intel.hw_stipple = 0; - return; - } - - newMask = (((p[0] & 0xf) << 0) | - ((p[1] & 0xf) << 4) | - ((p[2] & 0xf) << 8) | - ((p[3] & 0xf) << 12)); - - - if (newMask == 0xffff || newMask == 0x0) { - /* this is needed to make conform pass */ - i830->intel.hw_stipple = 0; - return; - } - - i830->state.Stipple[I830_STPREG_ST1] &= ~0xffff; - i830->state.Stipple[I830_STPREG_ST1] |= newMask; - i830->intel.hw_stipple = 1; - - if (active) - i830->state.Stipple[I830_STPREG_ST1] |= ST1_ENABLE; -} - - -/* ============================================================= - * Hardware clipping - */ -static void i830Scissor(GLcontext *ctx, GLint x, GLint y, - GLsizei w, GLsizei h) -{ - struct i830_context *i830 = i830_context(ctx); - int x1, y1, x2, y2; - - if (!ctx->DrawBuffer) - return; - - x1 = x; - y1 = ctx->DrawBuffer->Height - (y + h); - x2 = x + w - 1; - y2 = y1 + h - 1; - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "[%s] x(%d) y(%d) w(%d) h(%d)\n", __FUNCTION__, - x, y, w, h); - - x1 = CLAMP(x1, 0, ctx->DrawBuffer->Width - 1); - y1 = CLAMP(y1, 0, ctx->DrawBuffer->Height - 1); - x2 = CLAMP(x2, 0, ctx->DrawBuffer->Width - 1); - y2 = CLAMP(y2, 0, ctx->DrawBuffer->Height - 1); - - I830_STATECHANGE(i830, I830_UPLOAD_BUFFERS); - i830->state.Buffer[I830_DESTREG_SR1] = (y1 << 16) | (x1 & 0xffff); - i830->state.Buffer[I830_DESTREG_SR2] = (y2 << 16) | (x2 & 0xffff); -} - -static void i830LogicOp(GLcontext *ctx, GLenum opcode) -{ - struct i830_context *i830 = i830_context(ctx); - int tmp = intel_translate_logic_op( opcode ); - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s\n", __FUNCTION__); - - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - i830->state.Ctx[I830_CTXREG_STATE4] &= ~LOGICOP_MASK; - i830->state.Ctx[I830_CTXREG_STATE4] |= LOGIC_OP_FUNC(tmp); -} - - - -static void i830CullFaceFrontFace(GLcontext *ctx, GLenum unused) -{ - struct i830_context *i830 = i830_context(ctx); - GLuint mode; - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s\n", __FUNCTION__); - - if (!ctx->Polygon.CullFlag) { - mode = CULLMODE_NONE; - } - else if (ctx->Polygon.CullFaceMode != GL_FRONT_AND_BACK) { - mode = CULLMODE_CW; - - if (ctx->Polygon.CullFaceMode == GL_FRONT) - mode ^= (CULLMODE_CW ^ CULLMODE_CCW); - if (ctx->Polygon.FrontFace != GL_CCW) - mode ^= (CULLMODE_CW ^ CULLMODE_CCW); - } - else { - mode = CULLMODE_BOTH; - } - - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - i830->state.Ctx[I830_CTXREG_STATE3] &= ~CULLMODE_MASK; - i830->state.Ctx[I830_CTXREG_STATE3] |= ENABLE_CULL_MODE | mode; -} - -static void i830LineWidth( GLcontext *ctx, GLfloat widthf ) -{ - struct i830_context *i830 = i830_context( ctx ); - int width; - int state5; - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s\n", __FUNCTION__); - - width = (int)(widthf * 2); - CLAMP_SELF(width, 1, 15); - - state5 = i830->state.Ctx[I830_CTXREG_STATE5] & ~FIXED_LINE_WIDTH_MASK; - state5 |= (ENABLE_FIXED_LINE_WIDTH | FIXED_LINE_WIDTH(width)); - - if (state5 != i830->state.Ctx[I830_CTXREG_STATE5]) { - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - i830->state.Ctx[I830_CTXREG_STATE5] = state5; - } -} - -static void i830PointSize(GLcontext *ctx, GLfloat size) -{ - struct i830_context *i830 = i830_context(ctx); - GLint point_size = (int)size; - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s\n", __FUNCTION__); - - CLAMP_SELF(point_size, 1, 256); - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - i830->state.Ctx[I830_CTXREG_STATE5] &= ~FIXED_POINT_WIDTH_MASK; - i830->state.Ctx[I830_CTXREG_STATE5] |= (ENABLE_FIXED_POINT_WIDTH | - FIXED_POINT_WIDTH(point_size)); -} - - -/* ============================================================= - * Color masks - */ - -static void i830ColorMask(GLcontext *ctx, - GLboolean r, GLboolean g, - GLboolean b, GLboolean a) -{ - struct i830_context *i830 = i830_context( ctx ); - GLuint tmp = 0; - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s r(%d) g(%d) b(%d) a(%d)\n", __FUNCTION__, r, g, b, a); - - tmp = ((i830->state.Ctx[I830_CTXREG_ENABLES_2] & ~WRITEMASK_MASK) | - ENABLE_COLOR_MASK | - ENABLE_COLOR_WRITE | - ((!r) << WRITEMASK_RED_SHIFT) | - ((!g) << WRITEMASK_GREEN_SHIFT) | - ((!b) << WRITEMASK_BLUE_SHIFT) | - ((!a) << WRITEMASK_ALPHA_SHIFT)); - - if (tmp != i830->state.Ctx[I830_CTXREG_ENABLES_2]) { - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - i830->state.Ctx[I830_CTXREG_ENABLES_2] = tmp; - } -} - -static void update_specular( GLcontext *ctx ) -{ - struct i830_context *i830 = i830_context( ctx ); - - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - i830->state.Ctx[I830_CTXREG_ENABLES_1] &= ~ENABLE_SPEC_ADD_MASK; - - if (NEED_SECONDARY_COLOR(ctx)) - i830->state.Ctx[I830_CTXREG_ENABLES_1] |= ENABLE_SPEC_ADD; - else - i830->state.Ctx[I830_CTXREG_ENABLES_1] |= DISABLE_SPEC_ADD; -} - -static void i830LightModelfv(GLcontext *ctx, GLenum pname, - const GLfloat *param) -{ - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s\n", __FUNCTION__); - - if (pname == GL_LIGHT_MODEL_COLOR_CONTROL) { - update_specular( ctx ); - } -} - -/* In Mesa 3.5 we can reliably do native flatshading. - */ -static void i830ShadeModel(GLcontext *ctx, GLenum mode) -{ - struct i830_context *i830 = i830_context(ctx); - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - - -#define SHADE_MODE_MASK ((1<<10)|(1<<8)|(1<<6)|(1<<4)) - - i830->state.Ctx[I830_CTXREG_STATE3] &= ~SHADE_MODE_MASK; - - if (mode == GL_FLAT) { - i830->state.Ctx[I830_CTXREG_STATE3] |= (ALPHA_SHADE_MODE(SHADE_MODE_FLAT) | - FOG_SHADE_MODE(SHADE_MODE_FLAT) | - SPEC_SHADE_MODE(SHADE_MODE_FLAT) | - COLOR_SHADE_MODE(SHADE_MODE_FLAT)); - } else { - i830->state.Ctx[I830_CTXREG_STATE3] |= (ALPHA_SHADE_MODE(SHADE_MODE_LINEAR) | - FOG_SHADE_MODE(SHADE_MODE_LINEAR) | - SPEC_SHADE_MODE(SHADE_MODE_LINEAR) | - COLOR_SHADE_MODE(SHADE_MODE_LINEAR)); - } -} - -/* ============================================================= - * Fog - */ -static void i830Fogfv(GLcontext *ctx, GLenum pname, const GLfloat *param) -{ - struct i830_context *i830 = i830_context(ctx); - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s\n", __FUNCTION__); - - if (pname == GL_FOG_COLOR) { - GLuint color = (((GLubyte)(ctx->Fog.Color[0]*255.0F) << 16) | - ((GLubyte)(ctx->Fog.Color[1]*255.0F) << 8) | - ((GLubyte)(ctx->Fog.Color[2]*255.0F) << 0)); - - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - i830->state.Ctx[I830_CTXREG_FOGCOLOR] = (_3DSTATE_FOG_COLOR_CMD | color); - } -} - -/* ============================================================= - */ - -static void i830Enable(GLcontext *ctx, GLenum cap, GLboolean state) -{ - struct i830_context *i830 = i830_context(ctx); - - switch(cap) { - case GL_LIGHTING: - case GL_COLOR_SUM: - update_specular( ctx ); - break; - - case GL_ALPHA_TEST: - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - i830->state.Ctx[I830_CTXREG_ENABLES_1] &= ~ENABLE_DIS_ALPHA_TEST_MASK; - if (state) - i830->state.Ctx[I830_CTXREG_ENABLES_1] |= ENABLE_ALPHA_TEST; - else - i830->state.Ctx[I830_CTXREG_ENABLES_1] |= DISABLE_ALPHA_TEST; - - break; - - case GL_BLEND: - i830EvalLogicOpBlendState(ctx); - break; - - case GL_COLOR_LOGIC_OP: - i830EvalLogicOpBlendState(ctx); - - /* Logicop doesn't seem to work at 16bpp: - */ - if (i830->intel.intelScreen->cpp == 2) - FALLBACK( &i830->intel, I830_FALLBACK_LOGICOP, state ); - break; - - case GL_DITHER: - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - i830->state.Ctx[I830_CTXREG_ENABLES_2] &= ~ENABLE_DITHER; - - if (state) - i830->state.Ctx[I830_CTXREG_ENABLES_2] |= ENABLE_DITHER; - else - i830->state.Ctx[I830_CTXREG_ENABLES_2] |= DISABLE_DITHER; - break; - - case GL_DEPTH_TEST: - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - i830->state.Ctx[I830_CTXREG_ENABLES_1] &= ~ENABLE_DIS_DEPTH_TEST_MASK; - - if (state) - i830->state.Ctx[I830_CTXREG_ENABLES_1] |= ENABLE_DEPTH_TEST; - else - i830->state.Ctx[I830_CTXREG_ENABLES_1] |= DISABLE_DEPTH_TEST; - - /* Also turn off depth writes when GL_DEPTH_TEST is disabled: - */ - i830DepthMask( ctx, ctx->Depth.Mask ); - break; - - case GL_SCISSOR_TEST: - I830_STATECHANGE(i830, I830_UPLOAD_BUFFERS); - - if (state) - i830->state.Buffer[I830_DESTREG_SENABLE] = - (_3DSTATE_SCISSOR_ENABLE_CMD | - ENABLE_SCISSOR_RECT); - else - i830->state.Buffer[I830_DESTREG_SENABLE] = - (_3DSTATE_SCISSOR_ENABLE_CMD | - DISABLE_SCISSOR_RECT); - - break; - - case GL_LINE_SMOOTH: - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - - i830->state.Ctx[I830_CTXREG_AA] &= ~AA_LINE_ENABLE; - if (state) - i830->state.Ctx[I830_CTXREG_AA] |= AA_LINE_ENABLE; - else - i830->state.Ctx[I830_CTXREG_AA] |= AA_LINE_DISABLE; - break; - - case GL_FOG: - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - i830->state.Ctx[I830_CTXREG_ENABLES_1] &= ~ENABLE_DIS_FOG_MASK; - if (state) - i830->state.Ctx[I830_CTXREG_ENABLES_1] |= ENABLE_FOG; - else - i830->state.Ctx[I830_CTXREG_ENABLES_1] |= DISABLE_FOG; - break; - - case GL_CULL_FACE: - i830CullFaceFrontFace(ctx, 0); - break; - - case GL_TEXTURE_2D: - break; - - case GL_STENCIL_TEST: - { - GLboolean hw_stencil = GL_FALSE; - if (ctx->DrawBuffer) { - struct intel_renderbuffer *irbStencil - = intel_get_renderbuffer(ctx->DrawBuffer, BUFFER_STENCIL); - hw_stencil = (irbStencil && irbStencil->region); - } - if (hw_stencil) { - I830_STATECHANGE(i830, I830_UPLOAD_CTX); - - if (state) { - i830->state.Ctx[I830_CTXREG_ENABLES_1] |= ENABLE_STENCIL_TEST; - i830->state.Ctx[I830_CTXREG_ENABLES_2] |= ENABLE_STENCIL_WRITE; - } else { - i830->state.Ctx[I830_CTXREG_ENABLES_1] &= ~ENABLE_STENCIL_TEST; - i830->state.Ctx[I830_CTXREG_ENABLES_2] &= ~ENABLE_STENCIL_WRITE; - i830->state.Ctx[I830_CTXREG_ENABLES_1] |= DISABLE_STENCIL_TEST; - i830->state.Ctx[I830_CTXREG_ENABLES_2] |= DISABLE_STENCIL_WRITE; - } - } else { - FALLBACK( &i830->intel, I830_FALLBACK_STENCIL, state ); - } - } - break; - - case GL_POLYGON_STIPPLE: - /* The stipple command worked on my 855GM box, but not my 845G. - * I'll do more testing later to find out exactly which hardware - * supports it. Disabled for now. - */ - if (i830->intel.hw_stipple && - i830->intel.reduced_primitive == GL_TRIANGLES) - { - I830_STATECHANGE(i830, I830_UPLOAD_STIPPLE); - i830->state.Stipple[I830_STPREG_ST1] &= ~ST1_ENABLE; - if (state) - i830->state.Stipple[I830_STPREG_ST1] |= ST1_ENABLE; - } - break; - - default: - ; - } -} - - -static void i830_init_packets( struct i830_context *i830 ) -{ - intelScreenPrivate *screen = i830->intel.intelScreen; - - /* Zero all state */ - memset(&i830->state, 0, sizeof(i830->state)); - - /* Set default blend state */ - i830->state.TexBlend[0][0] = (_3DSTATE_MAP_BLEND_OP_CMD(0) | - TEXPIPE_COLOR | - ENABLE_TEXOUTPUT_WRT_SEL | - TEXOP_OUTPUT_CURRENT | - DISABLE_TEX_CNTRL_STAGE | - TEXOP_SCALE_1X | - TEXOP_MODIFY_PARMS | - TEXOP_LAST_STAGE | - TEXBLENDOP_ARG1); - i830->state.TexBlend[0][1] = (_3DSTATE_MAP_BLEND_OP_CMD(0) | - TEXPIPE_ALPHA | - ENABLE_TEXOUTPUT_WRT_SEL | - TEXOP_OUTPUT_CURRENT | - TEXOP_SCALE_1X | - TEXOP_MODIFY_PARMS | - TEXBLENDOP_ARG1); - i830->state.TexBlend[0][2] = (_3DSTATE_MAP_BLEND_ARG_CMD(0) | - TEXPIPE_COLOR | - TEXBLEND_ARG1 | - TEXBLENDARG_MODIFY_PARMS | - TEXBLENDARG_DIFFUSE); - i830->state.TexBlend[0][3] = (_3DSTATE_MAP_BLEND_ARG_CMD(0) | - TEXPIPE_ALPHA | - TEXBLEND_ARG1 | - TEXBLENDARG_MODIFY_PARMS | - TEXBLENDARG_DIFFUSE); - - i830->state.TexBlendWordsUsed[0] = 4; - - - i830->state.Ctx[I830_CTXREG_VF] = 0; - i830->state.Ctx[I830_CTXREG_VF2] = 0; - - i830->state.Ctx[I830_CTXREG_AA] = (_3DSTATE_AA_CMD | - AA_LINE_ECAAR_WIDTH_ENABLE | - AA_LINE_ECAAR_WIDTH_1_0 | - AA_LINE_REGION_WIDTH_ENABLE | - AA_LINE_REGION_WIDTH_1_0 | - AA_LINE_DISABLE); - - i830->state.Ctx[I830_CTXREG_ENABLES_1] = (_3DSTATE_ENABLES_1_CMD | - DISABLE_LOGIC_OP | - DISABLE_STENCIL_TEST | - DISABLE_DEPTH_BIAS | - DISABLE_SPEC_ADD | - DISABLE_FOG | - DISABLE_ALPHA_TEST | - DISABLE_COLOR_BLEND | - DISABLE_DEPTH_TEST); - -#if 000 /* XXX all the stencil enable state is set in i830Enable(), right? */ - if (i830->intel.hw_stencil) { - i830->state.Ctx[I830_CTXREG_ENABLES_2] = (_3DSTATE_ENABLES_2_CMD | - ENABLE_STENCIL_WRITE | - ENABLE_TEX_CACHE | - ENABLE_DITHER | - ENABLE_COLOR_MASK | - /* set no color comps disabled */ - ENABLE_COLOR_WRITE | - ENABLE_DEPTH_WRITE); - } else -#endif - { - i830->state.Ctx[I830_CTXREG_ENABLES_2] = (_3DSTATE_ENABLES_2_CMD | - DISABLE_STENCIL_WRITE | - ENABLE_TEX_CACHE | - ENABLE_DITHER | - ENABLE_COLOR_MASK | - /* set no color comps disabled */ - ENABLE_COLOR_WRITE | - ENABLE_DEPTH_WRITE); - } - - i830->state.Ctx[I830_CTXREG_STATE1] = (_3DSTATE_MODES_1_CMD | - ENABLE_COLR_BLND_FUNC | - BLENDFUNC_ADD | - ENABLE_SRC_BLND_FACTOR | - SRC_BLND_FACT(BLENDFACT_ONE) | - ENABLE_DST_BLND_FACTOR | - DST_BLND_FACT(BLENDFACT_ZERO) ); - - i830->state.Ctx[I830_CTXREG_STATE2] = (_3DSTATE_MODES_2_CMD | - ENABLE_GLOBAL_DEPTH_BIAS | - GLOBAL_DEPTH_BIAS(0) | - ENABLE_ALPHA_TEST_FUNC | - ALPHA_TEST_FUNC(COMPAREFUNC_ALWAYS) | - ALPHA_REF_VALUE(0) ); - - i830->state.Ctx[I830_CTXREG_STATE3] = (_3DSTATE_MODES_3_CMD | - ENABLE_DEPTH_TEST_FUNC | - DEPTH_TEST_FUNC(COMPAREFUNC_LESS) | - ENABLE_ALPHA_SHADE_MODE | - ALPHA_SHADE_MODE(SHADE_MODE_LINEAR) | - ENABLE_FOG_SHADE_MODE | - FOG_SHADE_MODE(SHADE_MODE_LINEAR) | - ENABLE_SPEC_SHADE_MODE | - SPEC_SHADE_MODE(SHADE_MODE_LINEAR) | - ENABLE_COLOR_SHADE_MODE | - COLOR_SHADE_MODE(SHADE_MODE_LINEAR) | - ENABLE_CULL_MODE | - CULLMODE_NONE); - - i830->state.Ctx[I830_CTXREG_STATE4] = (_3DSTATE_MODES_4_CMD | - ENABLE_LOGIC_OP_FUNC | - LOGIC_OP_FUNC(LOGICOP_COPY) | - ENABLE_STENCIL_TEST_MASK | - STENCIL_TEST_MASK(0xff) | - ENABLE_STENCIL_WRITE_MASK | - STENCIL_WRITE_MASK(0xff)); - - i830->state.Ctx[I830_CTXREG_STENCILTST] = (_3DSTATE_STENCIL_TEST_CMD | - ENABLE_STENCIL_PARMS | - STENCIL_FAIL_OP(STENCILOP_KEEP) | - STENCIL_PASS_DEPTH_FAIL_OP(STENCILOP_KEEP) | - STENCIL_PASS_DEPTH_PASS_OP(STENCILOP_KEEP) | - ENABLE_STENCIL_TEST_FUNC | - STENCIL_TEST_FUNC(COMPAREFUNC_ALWAYS) | - ENABLE_STENCIL_REF_VALUE | - STENCIL_REF_VALUE(0) ); - - i830->state.Ctx[I830_CTXREG_STATE5] = (_3DSTATE_MODES_5_CMD | - FLUSH_TEXTURE_CACHE | - ENABLE_SPRITE_POINT_TEX | - SPRITE_POINT_TEX_OFF | - ENABLE_FIXED_LINE_WIDTH | - FIXED_LINE_WIDTH(0x2) | /* 1.0 */ - ENABLE_FIXED_POINT_WIDTH | - FIXED_POINT_WIDTH(1) ); - - i830->state.Ctx[I830_CTXREG_IALPHAB] = (_3DSTATE_INDPT_ALPHA_BLEND_CMD | - DISABLE_INDPT_ALPHA_BLEND | - ENABLE_ALPHA_BLENDFUNC | - ABLENDFUNC_ADD); - - i830->state.Ctx[I830_CTXREG_FOGCOLOR] = (_3DSTATE_FOG_COLOR_CMD | - FOG_COLOR_RED(0) | - FOG_COLOR_GREEN(0) | - FOG_COLOR_BLUE(0)); - - i830->state.Ctx[I830_CTXREG_BLENDCOLOR0] = _3DSTATE_CONST_BLEND_COLOR_CMD; - i830->state.Ctx[I830_CTXREG_BLENDCOLOR1] = 0; - - i830->state.Ctx[I830_CTXREG_MCSB0] = _3DSTATE_MAP_COORD_SETBIND_CMD; - i830->state.Ctx[I830_CTXREG_MCSB1] = (TEXBIND_SET3(TEXCOORDSRC_VTXSET_3) | - TEXBIND_SET2(TEXCOORDSRC_VTXSET_2) | - TEXBIND_SET1(TEXCOORDSRC_VTXSET_1) | - TEXBIND_SET0(TEXCOORDSRC_VTXSET_0)); - - - i830->state.Stipple[I830_STPREG_ST0] = _3DSTATE_STIPPLE; - - i830->state.Buffer[I830_DESTREG_CBUFADDR0] = _3DSTATE_BUF_INFO_CMD; - i830->state.Buffer[I830_DESTREG_CBUFADDR1] = - (BUF_3D_ID_COLOR_BACK | - BUF_3D_PITCH(screen->front.pitch) | /* pitch in bytes */ - BUF_3D_USE_FENCE); - - - i830->state.Buffer[I830_DESTREG_DBUFADDR0] = _3DSTATE_BUF_INFO_CMD; - i830->state.Buffer[I830_DESTREG_DBUFADDR1] = - (BUF_3D_ID_DEPTH | -<<<<<<< i830_state.c - BUF_3D_PITCH(screen->depth.pitch) | /* pitch in bytes */ -======= - BUF_3D_PITCH(screen->depth.pitch * screen->cpp) | /* XXX FBO fix */ ->>>>>>> 1.7.2.6 - BUF_3D_USE_FENCE); -/* i830->state.Buffer[I830_DESTREG_DBUFADDR2] = screen->depth.offset; */ - - - i830->state.Buffer[I830_DESTREG_DV0] = _3DSTATE_DST_BUF_VARS_CMD; - - switch (screen->fbFormat) { - case DV_PF_565: - i830->state.Buffer[I830_DESTREG_DV1] = (DSTORG_HORT_BIAS(0x8) | /* .5 */ - DSTORG_VERT_BIAS(0x8) | /* .5 */ - screen->fbFormat | - DEPTH_IS_Z | - DEPTH_FRMT_16_FIXED); - break; - case DV_PF_8888: - i830->state.Buffer[I830_DESTREG_DV1] = (DSTORG_HORT_BIAS(0x8) | /* .5 */ - DSTORG_VERT_BIAS(0x8) | /* .5 */ - screen->fbFormat | - DEPTH_IS_Z | - DEPTH_FRMT_24_FIXED_8_OTHER); - break; - } - - i830->state.Buffer[I830_DESTREG_SENABLE] = (_3DSTATE_SCISSOR_ENABLE_CMD | - DISABLE_SCISSOR_RECT); - i830->state.Buffer[I830_DESTREG_SR0] = _3DSTATE_SCISSOR_RECT_0_CMD; - i830->state.Buffer[I830_DESTREG_SR1] = 0; - i830->state.Buffer[I830_DESTREG_SR2] = 0; -} - - -void i830InitStateFuncs( struct dd_function_table *functions ) -{ - functions->AlphaFunc = i830AlphaFunc; - functions->BlendColor = i830BlendColor; - functions->BlendEquationSeparate = i830BlendEquationSeparate; - functions->BlendFuncSeparate = i830BlendFuncSeparate; - functions->ColorMask = i830ColorMask; - functions->CullFace = i830CullFaceFrontFace; - functions->DepthFunc = i830DepthFunc; - functions->DepthMask = i830DepthMask; - functions->Enable = i830Enable; - functions->Fogfv = i830Fogfv; - functions->FrontFace = i830CullFaceFrontFace; - functions->LightModelfv = i830LightModelfv; - functions->LineWidth = i830LineWidth; - functions->LogicOpcode = i830LogicOp; - functions->PointSize = i830PointSize; - functions->PolygonStipple = i830PolygonStipple; - functions->Scissor = i830Scissor; - functions->ShadeModel = i830ShadeModel; - functions->StencilFuncSeparate = i830StencilFuncSeparate; - functions->StencilMaskSeparate = i830StencilMaskSeparate; - functions->StencilOpSeparate = i830StencilOpSeparate; -} - -void i830InitState( struct i830_context *i830 ) -{ - GLcontext *ctx = &i830->intel.ctx; - - i830_init_packets( i830 ); - - intelInitState( ctx ); - - memcpy( &i830->initial, &i830->state, sizeof(i830->state) ); - - i830->current = &i830->state; - i830->state.emitted = 0; - i830->state.active = (I830_UPLOAD_INVARIENT | - I830_UPLOAD_TEXBLEND(0) | - I830_UPLOAD_STIPPLE | - I830_UPLOAD_CTX | - I830_UPLOAD_BUFFERS); -} - - - - - diff --git a/src/mesa/drivers/dri/i915-tex/i830_tex.c b/src/mesa/drivers/dri/i915-tex/i830_tex.c deleted file mode 100644 index 4c5fb3e69f6..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i830_tex.c +++ /dev/null @@ -1,106 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "glheader.h" -#include "mtypes.h" -#include "imports.h" -#include "simple_list.h" -#include "enums.h" -#include "image.h" -#include "texstore.h" -#include "texformat.h" -#include "texmem.h" -#include "swrast/swrast.h" - -#include "mm.h" - -#include "intel_ioctl.h" - -#include "i830_context.h" -#include "i830_reg.h" - - - -static void i830TexEnv( GLcontext *ctx, GLenum target, - GLenum pname, const GLfloat *param ) -{ - - switch (pname) { - case GL_TEXTURE_ENV_COLOR: - case GL_TEXTURE_ENV_MODE: - case GL_COMBINE_RGB: - case GL_COMBINE_ALPHA: - case GL_SOURCE0_RGB: - case GL_SOURCE1_RGB: - case GL_SOURCE2_RGB: - case GL_SOURCE0_ALPHA: - case GL_SOURCE1_ALPHA: - case GL_SOURCE2_ALPHA: - case GL_OPERAND0_RGB: - case GL_OPERAND1_RGB: - case GL_OPERAND2_RGB: - case GL_OPERAND0_ALPHA: - case GL_OPERAND1_ALPHA: - case GL_OPERAND2_ALPHA: - case GL_RGB_SCALE: - case GL_ALPHA_SCALE: - break; - - case GL_TEXTURE_LOD_BIAS: { - struct i830_context *i830 = i830_context( ctx ); - GLuint unit = ctx->Texture.CurrentUnit; - int b = (int) ((*param) * 16.0); - if (b > 63) b = 63; - if (b < -64) b = -64; - I830_STATECHANGE(i830, I830_UPLOAD_TEX(unit)); - i830->lodbias_tm0s3[unit] = ((b << TM0S3_LOD_BIAS_SHIFT) & TM0S3_LOD_BIAS_MASK); - break; - } - - default: - break; - } -} - -static void i830BindTexture( GLcontext *ctx, GLenum target, - struct gl_texture_object *texObj ) -{ - i830TextureObjectPtr tex; - - if (!texObj->DriverData) - i830AllocTexObj( texObj ); - - tex = (i830TextureObjectPtr)texObj->DriverData; -} - - - -void i830InitTextureFuncs( struct dd_function_table *functions ) -{ - functions->BindTexture = i830BindTexture; - functions->TexEnv = i830TexEnv; -} diff --git a/src/mesa/drivers/dri/i915-tex/i830_texblend.c b/src/mesa/drivers/dri/i915-tex/i830_texblend.c deleted file mode 100644 index 4c1bee58d8e..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i830_texblend.c +++ /dev/null @@ -1,465 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "glheader.h" -#include "macros.h" -#include "mtypes.h" -#include "simple_list.h" -#include "enums.h" -#include "texformat.h" -#include "texstore.h" - -#include "mm.h" - -#include "intel_screen.h" -#include "intel_ioctl.h" -#include "intel_tex.h" - -#include "i830_context.h" -#include "i830_reg.h" - - -/* ================================================================ - * Texture combine functions - */ -static GLuint pass_through( GLuint *state, GLuint blendUnit ) -{ - state[0] = (_3DSTATE_MAP_BLEND_OP_CMD(blendUnit) | - TEXPIPE_COLOR | - ENABLE_TEXOUTPUT_WRT_SEL | - TEXOP_OUTPUT_CURRENT | - DISABLE_TEX_CNTRL_STAGE | - TEXOP_SCALE_1X | - TEXOP_MODIFY_PARMS | - TEXBLENDOP_ARG1); - state[1] = (_3DSTATE_MAP_BLEND_OP_CMD(blendUnit) | - TEXPIPE_ALPHA | - ENABLE_TEXOUTPUT_WRT_SEL | - TEXOP_OUTPUT_CURRENT | - TEXOP_SCALE_1X | - TEXOP_MODIFY_PARMS | - TEXBLENDOP_ARG1); - state[2] = (_3DSTATE_MAP_BLEND_ARG_CMD(blendUnit) | - TEXPIPE_COLOR | - TEXBLEND_ARG1 | - TEXBLENDARG_MODIFY_PARMS | - TEXBLENDARG_CURRENT); - state[3] = (_3DSTATE_MAP_BLEND_ARG_CMD(blendUnit) | - TEXPIPE_ALPHA | - TEXBLEND_ARG1 | - TEXBLENDARG_MODIFY_PARMS | - TEXBLENDARG_CURRENT); - - return 4; -} - -static GLuint emit_factor( GLuint blendUnit, GLuint *state, GLuint count, - const GLfloat *factor ) -{ - GLubyte r, g, b, a; - GLuint col; - - if (0) - fprintf(stderr, "emit constant %d: %.2f %.2f %.2f %.2f\n", - blendUnit, factor[0], factor[1], factor[2], factor[3]); - - UNCLAMPED_FLOAT_TO_UBYTE(r, factor[0]); - UNCLAMPED_FLOAT_TO_UBYTE(g, factor[1]); - UNCLAMPED_FLOAT_TO_UBYTE(b, factor[2]); - UNCLAMPED_FLOAT_TO_UBYTE(a, factor[3]); - - col = ((a << 24) | (r << 16) | (g << 8) | b); - - state[count++] = _3DSTATE_COLOR_FACTOR_N_CMD(blendUnit); - state[count++] = col; - - return count; -} - - -static INLINE GLuint GetTexelOp(GLint unit) -{ - switch(unit) { - case 0: return TEXBLENDARG_TEXEL0; - case 1: return TEXBLENDARG_TEXEL1; - case 2: return TEXBLENDARG_TEXEL2; - case 3: return TEXBLENDARG_TEXEL3; - default: return TEXBLENDARG_TEXEL0; - } -} - - -/** - * Calculate the hardware instuctions to setup the current texture enviromnemt - * settings. Since \c gl_texture_unit::_CurrentCombine is used, both - * "classic" texture enviroments and GL_ARB_texture_env_combine type texture - * environments are treated identically. - * - * \todo - * This function should return \c GLboolean. When \c GL_FALSE is returned, - * it means that an environment is selected that the hardware cannot do. This - * is the way the Radeon and R200 drivers work. - * - * \todo - * Looking at i830_3d_regs.h, it seems the i830 can do part of - * GL_ATI_texture_env_combine3. It can handle using \c GL_ONE and - * \c GL_ZERO as combine inputs (which the code already supports). It can - * also handle the \c GL_MODULATE_ADD_ATI mode. Is it worth investigating - * partial support for the extension? - */ -GLuint -i830SetTexEnvCombine(struct i830_context *i830, - const struct gl_tex_env_combine_state * combine, - GLint blendUnit, - GLuint texel_op, - GLuint *state, - const GLfloat *factor ) -{ - const GLuint numColorArgs = combine->_NumArgsRGB; - const GLuint numAlphaArgs = combine->_NumArgsA; - - GLuint blendop; - GLuint ablendop; - GLuint args_RGB[3]; - GLuint args_A[3]; - GLuint rgb_shift; - GLuint alpha_shift; - GLboolean need_factor = 0; - int i; - unsigned used; - static const GLuint tex_blend_rgb[3] = { - TEXPIPE_COLOR | TEXBLEND_ARG1 | TEXBLENDARG_MODIFY_PARMS, - TEXPIPE_COLOR | TEXBLEND_ARG2 | TEXBLENDARG_MODIFY_PARMS, - TEXPIPE_COLOR | TEXBLEND_ARG0 | TEXBLENDARG_MODIFY_PARMS, - }; - static const GLuint tex_blend_a[3] = { - TEXPIPE_ALPHA | TEXBLEND_ARG1 | TEXBLENDARG_MODIFY_PARMS, - TEXPIPE_ALPHA | TEXBLEND_ARG2 | TEXBLENDARG_MODIFY_PARMS, - TEXPIPE_ALPHA | TEXBLEND_ARG0 | TEXBLENDARG_MODIFY_PARMS, - }; - - if(INTEL_DEBUG&DEBUG_TEXTURE) - fprintf(stderr, "%s\n", __FUNCTION__); - - - /* The EXT version of the DOT3 extension does not support the - * scale factor, but the ARB version (and the version in OpenGL - * 1.3) does. - */ - switch (combine->ModeRGB) { - case GL_DOT3_RGB_EXT: - alpha_shift = combine->ScaleShiftA; - rgb_shift = 0; - break; - - case GL_DOT3_RGBA_EXT: - alpha_shift = 0; - rgb_shift = 0; - break; - - default: - rgb_shift = combine->ScaleShiftRGB; - alpha_shift = combine->ScaleShiftA; - break; - } - - - switch(combine->ModeRGB) { - case GL_REPLACE: - blendop = TEXBLENDOP_ARG1; - break; - case GL_MODULATE: - blendop = TEXBLENDOP_MODULATE; - break; - case GL_ADD: - blendop = TEXBLENDOP_ADD; - break; - case GL_ADD_SIGNED: - blendop = TEXBLENDOP_ADDSIGNED; - break; - case GL_INTERPOLATE: - blendop = TEXBLENDOP_BLEND; - break; - case GL_SUBTRACT: - blendop = TEXBLENDOP_SUBTRACT; - break; - case GL_DOT3_RGB_EXT: - case GL_DOT3_RGB: - blendop = TEXBLENDOP_DOT3; - break; - case GL_DOT3_RGBA_EXT: - case GL_DOT3_RGBA: - blendop = TEXBLENDOP_DOT3; - break; - default: - return pass_through( state, blendUnit ); - } - - blendop |= (rgb_shift << TEXOP_SCALE_SHIFT); - - - /* Handle RGB args */ - for(i = 0; i < 3; i++) { - switch(combine->SourceRGB[i]) { - case GL_TEXTURE: - args_RGB[i] = texel_op; - break; - case GL_TEXTURE0: - case GL_TEXTURE1: - case GL_TEXTURE2: - case GL_TEXTURE3: - args_RGB[i] = GetTexelOp( combine->SourceRGB[i] - GL_TEXTURE0 ); - break; - case GL_CONSTANT: - args_RGB[i] = TEXBLENDARG_FACTOR_N; - need_factor = 1; - break; - case GL_PRIMARY_COLOR: - args_RGB[i] = TEXBLENDARG_DIFFUSE; - break; - case GL_PREVIOUS: - args_RGB[i] = TEXBLENDARG_CURRENT; - break; - default: - return pass_through( state, blendUnit ); - } - - switch(combine->OperandRGB[i]) { - case GL_SRC_COLOR: - args_RGB[i] |= 0; - break; - case GL_ONE_MINUS_SRC_COLOR: - args_RGB[i] |= TEXBLENDARG_INV_ARG; - break; - case GL_SRC_ALPHA: - args_RGB[i] |= TEXBLENDARG_REPLICATE_ALPHA; - break; - case GL_ONE_MINUS_SRC_ALPHA: - args_RGB[i] |= (TEXBLENDARG_REPLICATE_ALPHA | - TEXBLENDARG_INV_ARG); - break; - default: - return pass_through( state, blendUnit ); - } - } - - - /* Need to knobble the alpha calculations of TEXBLENDOP_DOT4 to - * match the spec. Can't use DOT3 as it won't propogate values - * into alpha as required: - * - * Note - the global factor is set up with alpha == .5, so - * the alpha part of the DOT4 calculation should be zero. - */ - if ( combine->ModeRGB == GL_DOT3_RGBA_EXT || - combine->ModeRGB == GL_DOT3_RGBA ) { - ablendop = TEXBLENDOP_DOT4; - args_A[0] = TEXBLENDARG_FACTOR; /* the global factor */ - args_A[1] = TEXBLENDARG_FACTOR; - args_A[2] = TEXBLENDARG_FACTOR; - } - else { - switch(combine->ModeA) { - case GL_REPLACE: - ablendop = TEXBLENDOP_ARG1; - break; - case GL_MODULATE: - ablendop = TEXBLENDOP_MODULATE; - break; - case GL_ADD: - ablendop = TEXBLENDOP_ADD; - break; - case GL_ADD_SIGNED: - ablendop = TEXBLENDOP_ADDSIGNED; - break; - case GL_INTERPOLATE: - ablendop = TEXBLENDOP_BLEND; - break; - case GL_SUBTRACT: - ablendop = TEXBLENDOP_SUBTRACT; - break; - default: - return pass_through( state, blendUnit ); - } - - - ablendop |= (alpha_shift << TEXOP_SCALE_SHIFT); - - /* Handle A args */ - for(i = 0; i < 3; i++) { - switch(combine->SourceA[i]) { - case GL_TEXTURE: - args_A[i] = texel_op; - break; - case GL_TEXTURE0: - case GL_TEXTURE1: - case GL_TEXTURE2: - case GL_TEXTURE3: - args_A[i] = GetTexelOp( combine->SourceA[i] - GL_TEXTURE0 ); - break; - case GL_CONSTANT: - args_A[i] = TEXBLENDARG_FACTOR_N; - need_factor = 1; - break; - case GL_PRIMARY_COLOR: - args_A[i] = TEXBLENDARG_DIFFUSE; - break; - case GL_PREVIOUS: - args_A[i] = TEXBLENDARG_CURRENT; - break; - default: - return pass_through( state, blendUnit ); - } - - switch(combine->OperandA[i]) { - case GL_SRC_ALPHA: - args_A[i] |= 0; - break; - case GL_ONE_MINUS_SRC_ALPHA: - args_A[i] |= TEXBLENDARG_INV_ARG; - break; - default: - return pass_through( state, blendUnit ); - } - } - } - - - - /* Native Arg1 == Arg0 in GL_EXT_texture_env_combine spec */ - /* Native Arg2 == Arg1 in GL_EXT_texture_env_combine spec */ - /* Native Arg0 == Arg2 in GL_EXT_texture_env_combine spec */ - - /* When we render we need to figure out which is the last really enabled - * tex unit, and put last stage on it - */ - - - /* Build color & alpha pipelines */ - - used = 0; - state[used++] = (_3DSTATE_MAP_BLEND_OP_CMD(blendUnit) | - TEXPIPE_COLOR | - ENABLE_TEXOUTPUT_WRT_SEL | - TEXOP_OUTPUT_CURRENT | - DISABLE_TEX_CNTRL_STAGE | - TEXOP_MODIFY_PARMS | - blendop); - state[used++] = (_3DSTATE_MAP_BLEND_OP_CMD(blendUnit) | - TEXPIPE_ALPHA | - ENABLE_TEXOUTPUT_WRT_SEL | - TEXOP_OUTPUT_CURRENT | - TEXOP_MODIFY_PARMS | - ablendop); - - for ( i = 0 ; i < numColorArgs ; i++ ) { - state[used++] = (_3DSTATE_MAP_BLEND_ARG_CMD(blendUnit) | - tex_blend_rgb[i] | args_RGB[i]); - } - - for ( i = 0 ; i < numAlphaArgs ; i++ ) { - state[used++] = (_3DSTATE_MAP_BLEND_ARG_CMD(blendUnit) | - tex_blend_a[i] | args_A[i]); - } - - - if (need_factor) - return emit_factor( blendUnit, state, used, factor ); - else - return used; -} - - -static void emit_texblend( struct i830_context *i830, GLuint unit, GLuint blendUnit, - GLboolean last_stage ) -{ - struct gl_texture_unit *texUnit = &i830->intel.ctx.Texture.Unit[unit]; - GLuint tmp[I830_TEXBLEND_SIZE], tmp_sz; - - - if (0) fprintf(stderr, "%s unit %d\n", __FUNCTION__, unit); - - /* Update i830->state.TexBlend - */ - tmp_sz = i830SetTexEnvCombine(i830, texUnit->_CurrentCombine, blendUnit, - GetTexelOp(unit), tmp, - texUnit->EnvColor ); - - if (last_stage) - tmp[0] |= TEXOP_LAST_STAGE; - - if (tmp_sz != i830->state.TexBlendWordsUsed[blendUnit] || - memcmp( tmp, i830->state.TexBlend[blendUnit], tmp_sz * sizeof(GLuint))) { - - I830_STATECHANGE( i830, I830_UPLOAD_TEXBLEND(blendUnit) ); - memcpy( i830->state.TexBlend[blendUnit], tmp, tmp_sz * sizeof(GLuint)); - i830->state.TexBlendWordsUsed[blendUnit] = tmp_sz; - } - - I830_ACTIVESTATE(i830, I830_UPLOAD_TEXBLEND(blendUnit), GL_TRUE); -} - -static void emit_passthrough( struct i830_context *i830 ) -{ - GLuint tmp[I830_TEXBLEND_SIZE], tmp_sz; - GLuint unit = 0; - - tmp_sz = pass_through( tmp, unit ); - tmp[0] |= TEXOP_LAST_STAGE; - - if (tmp_sz != i830->state.TexBlendWordsUsed[unit] || - memcmp( tmp, i830->state.TexBlend[unit], tmp_sz * sizeof(GLuint))) { - - I830_STATECHANGE( i830, I830_UPLOAD_TEXBLEND(unit) ); - memcpy( i830->state.TexBlend[unit], tmp, tmp_sz * sizeof(GLuint)); - i830->state.TexBlendWordsUsed[unit] = tmp_sz; - } - - I830_ACTIVESTATE(i830, I830_UPLOAD_TEXBLEND(unit), GL_TRUE); -} - -void i830EmitTextureBlend( struct i830_context *i830 ) -{ - GLcontext *ctx = &i830->intel.ctx; - GLuint unit, last_stage = 0, blendunit = 0; - - I830_ACTIVESTATE(i830, I830_UPLOAD_TEXBLEND_ALL, GL_FALSE); - - if (ctx->Texture._EnabledUnits) { - for (unit = 0 ; unit < ctx->Const.MaxTextureUnits ; unit++) - if (ctx->Texture.Unit[unit]._ReallyEnabled) - last_stage = unit; - - for (unit = 0 ; unit < ctx->Const.MaxTextureUnits ; unit++) - if (ctx->Texture.Unit[unit]._ReallyEnabled) - emit_texblend( i830, unit, blendunit++, last_stage == unit ); - } - else { - emit_passthrough( i830 ); - } -} - diff --git a/src/mesa/drivers/dri/i915-tex/i830_texstate.c b/src/mesa/drivers/dri/i915-tex/i830_texstate.c deleted file mode 100644 index dc9aca80fa9..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i830_texstate.c +++ /dev/null @@ -1,321 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "glheader.h" -#include "macros.h" -#include "mtypes.h" -#include "simple_list.h" -#include "enums.h" -#include "texformat.h" -#include "texstore.h" - -#include "mm.h" - -#include "intel_screen.h" -#include "intel_ioctl.h" -#include "intel_tex.h" -#include "intel_mipmap_tree.h" -#include "intel_regions.h" - -#include "i830_context.h" -#include "i830_reg.h" - - - -static GLuint translate_texture_format( GLuint mesa_format ) -{ - switch (mesa_format) { - case MESA_FORMAT_L8: - return MAPSURF_8BIT | MT_8BIT_L8; - case MESA_FORMAT_I8: - return MAPSURF_8BIT | MT_8BIT_I8; - case MESA_FORMAT_A8: - return MAPSURF_8BIT | MT_8BIT_I8; /* Kludge! */ - case MESA_FORMAT_AL88: - return MAPSURF_16BIT | MT_16BIT_AY88; - case MESA_FORMAT_RGB565: - return MAPSURF_16BIT | MT_16BIT_RGB565; - case MESA_FORMAT_ARGB1555: - return MAPSURF_16BIT | MT_16BIT_ARGB1555; - case MESA_FORMAT_ARGB4444: - return MAPSURF_16BIT | MT_16BIT_ARGB4444; - case MESA_FORMAT_ARGB8888: - return MAPSURF_32BIT | MT_32BIT_ARGB8888; - case MESA_FORMAT_YCBCR_REV: - return (MAPSURF_422 | MT_422_YCRCB_NORMAL); - case MESA_FORMAT_YCBCR: - return (MAPSURF_422 | MT_422_YCRCB_SWAPY); - case MESA_FORMAT_RGB_FXT1: - case MESA_FORMAT_RGBA_FXT1: - return (MAPSURF_COMPRESSED | MT_COMPRESS_FXT1); - case MESA_FORMAT_RGBA_DXT1: - case MESA_FORMAT_RGB_DXT1: - return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT1); - case MESA_FORMAT_RGBA_DXT3: - return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT2_3); - case MESA_FORMAT_RGBA_DXT5: - return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT4_5); - default: - fprintf(stderr, "%s: bad image format %x\n", __FUNCTION__, - mesa_format); - abort(); - return 0; - } -} - - - - -/* The i915 (and related graphics cores) do not support GL_CLAMP. The - * Intel drivers for "other operating systems" implement GL_CLAMP as - * GL_CLAMP_TO_EDGE, so the same is done here. - */ -static GLuint translate_wrap_mode( GLenum wrap ) -{ - switch( wrap ) { - case GL_REPEAT: - return TEXCOORDMODE_WRAP; - case GL_CLAMP: - case GL_CLAMP_TO_EDGE: - return TEXCOORDMODE_CLAMP; /* not really correct */ - case GL_CLAMP_TO_BORDER: - return TEXCOORDMODE_CLAMP_BORDER; - case GL_MIRRORED_REPEAT: - return TEXCOORDMODE_MIRROR; - default: - return TEXCOORDMODE_WRAP; - } -} - - -/* Recalculate all state from scratch. Perhaps not the most - * efficient, but this has gotten complex enough that we need - * something which is understandable and reliable. - */ -static GLboolean i830_update_tex_unit( struct intel_context *intel, - GLuint unit, - GLuint ss3 ) -{ - GLcontext *ctx = &intel->ctx; - struct i830_context *i830 = i830_context(ctx); - struct gl_texture_object *tObj = ctx->Texture.Unit[unit]._Current; - struct intel_texture_object *intelObj = intel_texture_object(tObj); - struct gl_texture_image *firstImage; - GLuint *state = i830->state.Tex[unit]; - - memset(state, 0, sizeof(state)); - - if (!intel_finalize_mipmap_tree(intel, unit)) - return GL_FALSE; - - /* Get first image here, since intelObj->firstLevel will get set in - * the intel_finalize_mipmap_tree() call above. - */ - firstImage = tObj->Image[0][intelObj->firstLevel]; - - i830->state.tex_buffer[unit] = intelObj->mt->region->buffer; - i830->state.tex_offset[unit] = intel_miptree_image_offset(intelObj->mt, 0, - intelObj->firstLevel); - - - state[I830_TEXREG_TM0LI] = (_3DSTATE_LOAD_STATE_IMMEDIATE_2 | - (LOAD_TEXTURE_MAP0 << unit) | 4); - -/* state[I830_TEXREG_TM0S0] = (TM0S0_USE_FENCE | */ -/* t->intel.TextureOffset); */ - - - state[I830_TEXREG_TM0S1] = - (((firstImage->Height - 1) << TM0S1_HEIGHT_SHIFT) | - ((firstImage->Width - 1) << TM0S1_WIDTH_SHIFT) | - translate_texture_format( firstImage->TexFormat->MesaFormat)); - - state[I830_TEXREG_TM0S2] = - (((((intelObj->mt->pitch * intelObj->mt->cpp) / 4) - 1) << TM0S2_PITCH_SHIFT) | - TM0S2_CUBE_FACE_ENA_MASK); - - { - if (tObj->Target == GL_TEXTURE_CUBE_MAP) - state[I830_TEXREG_CUBE] = (_3DSTATE_MAP_CUBE | MAP_UNIT(unit) | - CUBE_NEGX_ENABLE | - CUBE_POSX_ENABLE | - CUBE_NEGY_ENABLE | - CUBE_POSY_ENABLE | - CUBE_NEGZ_ENABLE | - CUBE_POSZ_ENABLE); - else - state[I830_TEXREG_CUBE] = (_3DSTATE_MAP_CUBE | MAP_UNIT(unit)); - } - - - - - { - GLuint minFilt, mipFilt, magFilt; - - switch (tObj->MinFilter) { - case GL_NEAREST: - minFilt = FILTER_NEAREST; - mipFilt = MIPFILTER_NONE; - break; - case GL_LINEAR: - minFilt = FILTER_LINEAR; - mipFilt = MIPFILTER_NONE; - break; - case GL_NEAREST_MIPMAP_NEAREST: - minFilt = FILTER_NEAREST; - mipFilt = MIPFILTER_NEAREST; - break; - case GL_LINEAR_MIPMAP_NEAREST: - minFilt = FILTER_LINEAR; - mipFilt = MIPFILTER_NEAREST; - break; - case GL_NEAREST_MIPMAP_LINEAR: - minFilt = FILTER_NEAREST; - mipFilt = MIPFILTER_LINEAR; - break; - case GL_LINEAR_MIPMAP_LINEAR: - minFilt = FILTER_LINEAR; - mipFilt = MIPFILTER_LINEAR; - break; - default: - return GL_FALSE; - } - - if ( tObj->MaxAnisotropy > 1.0 ) { - minFilt = FILTER_ANISOTROPIC; - magFilt = FILTER_ANISOTROPIC; - } - else { - switch (tObj->MagFilter) { - case GL_NEAREST: - magFilt = FILTER_NEAREST; - break; - case GL_LINEAR: - magFilt = FILTER_LINEAR; - break; - default: - return GL_FALSE; - } - } - - state[I830_TEXREG_TM0S3] = i830->lodbias_tm0s3[unit]; - -#if 0 - /* YUV conversion: - */ - if (firstImage->TexFormat->MesaFormat == MESA_FORMAT_YCBCR || - firstImage->TexFormat->MesaFormat == MESA_FORMAT_YCBCR_REV) - state[I830_TEXREG_TM0S3] |= SS2_COLORSPACE_CONVERSION; -#endif - - state[I830_TEXREG_TM0S3] |= ((intelObj->lastLevel - - intelObj->firstLevel)*4) << TM0S3_MIN_MIP_SHIFT; - - state[I830_TEXREG_TM0S3] |= ((minFilt << TM0S3_MIN_FILTER_SHIFT) | - (mipFilt << TM0S3_MIP_FILTER_SHIFT) | - (magFilt << TM0S3_MAG_FILTER_SHIFT)); - } - - { - GLenum ws = tObj->WrapS; - GLenum wt = tObj->WrapT; - - - /* 3D textures not available on i830 - */ - if (tObj->Target == GL_TEXTURE_3D) - return GL_FALSE; - - state[I830_TEXREG_MCS] = (_3DSTATE_MAP_COORD_SET_CMD | - MAP_UNIT(unit) | - ENABLE_TEXCOORD_PARAMS | - ss3 | - ENABLE_ADDR_V_CNTL | - TEXCOORD_ADDR_V_MODE(translate_wrap_mode(wt)) | - ENABLE_ADDR_U_CNTL | - TEXCOORD_ADDR_U_MODE(translate_wrap_mode(ws))); - } - - - state[I830_TEXREG_TM0S4] = INTEL_PACKCOLOR8888(tObj->_BorderChan[0], - tObj->_BorderChan[1], - tObj->_BorderChan[2], - tObj->_BorderChan[3]); - - - I830_ACTIVESTATE(i830, I830_UPLOAD_TEX(unit), GL_TRUE); - /* memcmp was already disabled, but definitely won't work as the - * region might now change and that wouldn't be detected: - */ - I830_STATECHANGE( i830, I830_UPLOAD_TEX(unit) ); - return GL_TRUE; -} - - - - -void i830UpdateTextureState( struct intel_context *intel ) -{ - struct i830_context *i830 = i830_context(&intel->ctx); - GLboolean ok = GL_TRUE; - GLuint i; - - for (i = 0 ; i < I830_TEX_UNITS && ok ; i++) { - switch (intel->ctx.Texture.Unit[i]._ReallyEnabled) { - case TEXTURE_1D_BIT: - case TEXTURE_2D_BIT: - case TEXTURE_CUBE_BIT: - ok = i830_update_tex_unit( intel, i, TEXCOORDS_ARE_NORMAL ); - break; - case TEXTURE_RECT_BIT: - ok = i830_update_tex_unit( intel, i, TEXCOORDS_ARE_IN_TEXELUNITS ); - break; - case 0: - if (i830->state.active & I830_UPLOAD_TEX(i)) - I830_ACTIVESTATE(i830, I830_UPLOAD_TEX(i), GL_FALSE); - break; - case TEXTURE_3D_BIT: - default: - ok = GL_FALSE; - break; - } - } - - FALLBACK( intel, I830_FALLBACK_TEXTURE, !ok ); - - if (ok) - i830EmitTextureBlend( i830 ); -} - - - - - - - - diff --git a/src/mesa/drivers/dri/i915-tex/i830_vtbl.c b/src/mesa/drivers/dri/i915-tex/i830_vtbl.c deleted file mode 100644 index 6d4d2c8dace..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i830_vtbl.c +++ /dev/null @@ -1,585 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - - -#include "i830_context.h" -#include "i830_reg.h" - -#include "intel_batchbuffer.h" -#include "intel_regions.h" - -#include "tnl/t_context.h" -#include "tnl/t_vertex.h" - -static GLboolean i830_check_vertex_size( struct intel_context *intel, - GLuint expected ); - -#define SZ_TO_HW(sz) ((sz-2)&0x3) -#define EMIT_SZ(sz) (EMIT_1F + (sz) - 1) -#define EMIT_ATTR( ATTR, STYLE, V0 ) \ -do { \ - intel->vertex_attrs[intel->vertex_attr_count].attrib = (ATTR); \ - intel->vertex_attrs[intel->vertex_attr_count].format = (STYLE); \ - intel->vertex_attr_count++; \ - v0 |= V0; \ -} while (0) - -#define EMIT_PAD( N ) \ -do { \ - intel->vertex_attrs[intel->vertex_attr_count].attrib = 0; \ - intel->vertex_attrs[intel->vertex_attr_count].format = EMIT_PAD; \ - intel->vertex_attrs[intel->vertex_attr_count].offset = (N); \ - intel->vertex_attr_count++; \ -} while (0) - - -#define VRTX_TEX_SET_FMT(n, x) ((x)<<((n)*2)) -#define TEXBIND_SET(n, x) ((x)<<((n)*4)) - -static void i830_render_start( struct intel_context *intel ) -{ - GLcontext *ctx = &intel->ctx; - struct i830_context *i830 = i830_context(ctx); - TNLcontext *tnl = TNL_CONTEXT(ctx); - struct vertex_buffer *VB = &tnl->vb; - GLuint index = tnl->render_inputs; - GLuint v0 = _3DSTATE_VFT0_CMD; - GLuint v2 = _3DSTATE_VFT1_CMD; - GLuint mcsb1 = 0; - - /* Important: - */ - VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr; - intel->vertex_attr_count = 0; - - /* EMIT_ATTR's must be in order as they tell t_vertex.c how to - * build up a hardware vertex. - */ - if (index & _TNL_BITS_TEX_ANY) { - EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, VFT0_XYZW ); - intel->coloroffset = 4; - } - else { - EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_3F_VIEWPORT, VFT0_XYZ ); - intel->coloroffset = 3; - } - - if (index & _TNL_BIT_POINTSIZE) { - EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F, VFT0_POINT_WIDTH ); - } - - EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA, VFT0_DIFFUSE ); - - intel->specoffset = 0; - if (index & (_TNL_BIT_COLOR1|_TNL_BIT_FOG)) { - if (index & _TNL_BIT_COLOR1) { - intel->specoffset = intel->coloroffset + 1; - EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, VFT0_SPEC ); - } - else - EMIT_PAD( 3 ); - - if (index & _TNL_BIT_FOG) - EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, VFT0_SPEC ); - else - EMIT_PAD( 1 ); - } - - if (index & _TNL_BITS_TEX_ANY) { - int i, count = 0; - - for (i = 0; i < I830_TEX_UNITS; i++) { - if (index & _TNL_BIT_TEX(i)) { - GLuint sz = VB->TexCoordPtr[i]->size; - GLuint emit; - GLuint mcs = (i830->state.Tex[i][I830_TEXREG_MCS] & - ~TEXCOORDTYPE_MASK); - - switch (sz) { - case 1: - case 2: - emit = EMIT_2F; - sz = 2; - mcs |= TEXCOORDTYPE_CARTESIAN; - break; - case 3: - emit = EMIT_3F; - sz = 3; - mcs |= TEXCOORDTYPE_VECTOR; - break; - case 4: - emit = EMIT_3F_XYW; - sz = 3; - mcs |= TEXCOORDTYPE_HOMOGENEOUS; - break; - default: - continue; - }; - - - EMIT_ATTR( _TNL_ATTRIB_TEX0+i, emit, 0 ); - v2 |= VRTX_TEX_SET_FMT(count, SZ_TO_HW(sz)); - mcsb1 |= (count+8)<<(i*4); - - if (mcs != i830->state.Tex[i][I830_TEXREG_MCS]) { - I830_STATECHANGE(i830, I830_UPLOAD_TEX(i)); - i830->state.Tex[i][I830_TEXREG_MCS] = mcs; - } - - count++; - } - } - - v0 |= VFT0_TEX_COUNT(count); - } - - /* Only need to change the vertex emit code if there has been a - * statechange to a new hardware vertex format: - */ - if (v0 != i830->state.Ctx[I830_CTXREG_VF] || - v2 != i830->state.Ctx[I830_CTXREG_VF2] || - mcsb1 != i830->state.Ctx[I830_CTXREG_MCSB1] || - index != i830->last_index) { - int k; - - I830_STATECHANGE( i830, I830_UPLOAD_CTX ); - - /* Must do this *after* statechange, so as not to affect - * buffered vertices reliant on the old state: - */ - intel->vertex_size = - _tnl_install_attrs( ctx, - intel->vertex_attrs, - intel->vertex_attr_count, - intel->ViewportMatrix.m, 0 ); - - intel->vertex_size >>= 2; - - i830->state.Ctx[I830_CTXREG_VF] = v0; - i830->state.Ctx[I830_CTXREG_VF2] = v2; - i830->state.Ctx[I830_CTXREG_MCSB1] = mcsb1; - i830->last_index = index; - - k = i830_check_vertex_size( intel, intel->vertex_size ); - assert(k); - } -} - -static void i830_reduced_primitive_state( struct intel_context *intel, - GLenum rprim ) -{ - struct i830_context *i830 = i830_context(&intel->ctx); - GLuint st1 = i830->state.Stipple[I830_STPREG_ST1]; - - st1 &= ~ST1_ENABLE; - - switch (rprim) { - case GL_TRIANGLES: - if (intel->ctx.Polygon.StippleFlag && - intel->hw_stipple) - st1 |= ST1_ENABLE; - break; - case GL_LINES: - case GL_POINTS: - default: - break; - } - - i830->intel.reduced_primitive = rprim; - - if (st1 != i830->state.Stipple[I830_STPREG_ST1]) { - I830_STATECHANGE(i830, I830_UPLOAD_STIPPLE); - i830->state.Stipple[I830_STPREG_ST1] = st1; - } -} - -/* Pull apart the vertex format registers and figure out how large a - * vertex is supposed to be. - */ -static GLboolean i830_check_vertex_size( struct intel_context *intel, - GLuint expected ) -{ - struct i830_context *i830 = i830_context(&intel->ctx); - int vft0 = i830->current->Ctx[I830_CTXREG_VF]; - int vft1 = i830->current->Ctx[I830_CTXREG_VF2]; - int nrtex = (vft0 & VFT0_TEX_COUNT_MASK) >> VFT0_TEX_COUNT_SHIFT; - int i, sz = 0; - - switch (vft0 & VFT0_XYZW_MASK) { - case VFT0_XY: sz = 2; break; - case VFT0_XYZ: sz = 3; break; - case VFT0_XYW: sz = 3; break; - case VFT0_XYZW: sz = 4; break; - default: - fprintf(stderr, "no xyzw specified\n"); - return 0; - } - - if (vft0 & VFT0_SPEC) sz++; - if (vft0 & VFT0_DIFFUSE) sz++; - if (vft0 & VFT0_DEPTH_OFFSET) sz++; - if (vft0 & VFT0_POINT_WIDTH) sz++; - - for (i = 0 ; i < nrtex ; i++) { - switch (vft1 & VFT1_TEX0_MASK) { - case TEXCOORDFMT_2D: sz += 2; break; - case TEXCOORDFMT_3D: sz += 3; break; - case TEXCOORDFMT_4D: sz += 4; break; - case TEXCOORDFMT_1D: sz += 1; break; - } - vft1 >>= VFT1_TEX1_SHIFT; - } - - if (sz != expected) - fprintf(stderr, "vertex size mismatch %d/%d\n", sz, expected); - - return sz == expected; -} - -static void i830_emit_invarient_state( struct intel_context *intel ) -{ - BATCH_LOCALS; - - BEGIN_BATCH(200, 0); - - OUT_BATCH(_3DSTATE_DFLT_DIFFUSE_CMD); - OUT_BATCH(0); - - OUT_BATCH(_3DSTATE_DFLT_SPEC_CMD); - OUT_BATCH(0); - - OUT_BATCH(_3DSTATE_DFLT_Z_CMD); - OUT_BATCH(0); - - OUT_BATCH(_3DSTATE_FOG_MODE_CMD); - OUT_BATCH(FOGFUNC_ENABLE | - FOG_LINEAR_CONST | - FOGSRC_INDEX_Z | - ENABLE_FOG_DENSITY); - OUT_BATCH(0); - OUT_BATCH(0); - - - OUT_BATCH(_3DSTATE_MAP_TEX_STREAM_CMD | - MAP_UNIT(0) | - DISABLE_TEX_STREAM_BUMP | - ENABLE_TEX_STREAM_COORD_SET | - TEX_STREAM_COORD_SET(0) | - ENABLE_TEX_STREAM_MAP_IDX | TEX_STREAM_MAP_IDX(0)); - OUT_BATCH(_3DSTATE_MAP_TEX_STREAM_CMD | - MAP_UNIT(1) | - DISABLE_TEX_STREAM_BUMP | - ENABLE_TEX_STREAM_COORD_SET | - TEX_STREAM_COORD_SET(1) | - ENABLE_TEX_STREAM_MAP_IDX | TEX_STREAM_MAP_IDX(1)); - OUT_BATCH(_3DSTATE_MAP_TEX_STREAM_CMD | - MAP_UNIT(2) | - DISABLE_TEX_STREAM_BUMP | - ENABLE_TEX_STREAM_COORD_SET | - TEX_STREAM_COORD_SET(2) | - ENABLE_TEX_STREAM_MAP_IDX | TEX_STREAM_MAP_IDX(2)); - OUT_BATCH(_3DSTATE_MAP_TEX_STREAM_CMD | - MAP_UNIT(3) | - DISABLE_TEX_STREAM_BUMP | - ENABLE_TEX_STREAM_COORD_SET | - TEX_STREAM_COORD_SET(3) | - ENABLE_TEX_STREAM_MAP_IDX | TEX_STREAM_MAP_IDX(3)); - - OUT_BATCH(_3DSTATE_MAP_COORD_TRANSFORM); - OUT_BATCH(DISABLE_TEX_TRANSFORM | TEXTURE_SET(0)); - OUT_BATCH(_3DSTATE_MAP_COORD_TRANSFORM); - OUT_BATCH(DISABLE_TEX_TRANSFORM | TEXTURE_SET(1)); - OUT_BATCH(_3DSTATE_MAP_COORD_TRANSFORM); - OUT_BATCH(DISABLE_TEX_TRANSFORM | TEXTURE_SET(2)); - OUT_BATCH(_3DSTATE_MAP_COORD_TRANSFORM); - OUT_BATCH(DISABLE_TEX_TRANSFORM | TEXTURE_SET(3)); - - OUT_BATCH(_3DSTATE_RASTER_RULES_CMD | - ENABLE_POINT_RASTER_RULE | - OGL_POINT_RASTER_RULE | - ENABLE_LINE_STRIP_PROVOKE_VRTX | - ENABLE_TRI_FAN_PROVOKE_VRTX | - ENABLE_TRI_STRIP_PROVOKE_VRTX | - LINE_STRIP_PROVOKE_VRTX(1) | - TRI_FAN_PROVOKE_VRTX(2) | - TRI_STRIP_PROVOKE_VRTX(2)); - - OUT_BATCH(_3DSTATE_VERTEX_TRANSFORM); - OUT_BATCH(DISABLE_VIEWPORT_TRANSFORM | DISABLE_PERSPECTIVE_DIVIDE); - - OUT_BATCH(_3DSTATE_W_STATE_CMD); - OUT_BATCH(MAGIC_W_STATE_DWORD1); - OUT_BATCH(0x3f800000 /* 1.0 in IEEE float */ ); - - - OUT_BATCH(_3DSTATE_COLOR_FACTOR_CMD); - OUT_BATCH(0x80808080); /* .5 required in alpha for GL_DOT3_RGBA_EXT */ - - ADVANCE_BATCH(); -} - - -#define emit( intel, state, size ) \ -do { \ - int k; \ - BEGIN_BATCH(size / sizeof(GLuint), 0); \ - for (k = 0 ; k < size / sizeof(GLuint) ; k++) { \ - if (0) _mesa_printf(" 0x%08x\n", state[k]); \ - OUT_BATCH(state[k]); \ - } \ - ADVANCE_BATCH(); \ -} while (0) - -static GLuint get_state_size( struct i830_hw_state *state ) -{ - GLuint dirty = state->active & ~state->emitted; - GLuint sz = 0; - GLuint i; - - if (dirty & I830_UPLOAD_CTX) - sz += sizeof(state->Ctx); - - if (dirty & I830_UPLOAD_BUFFERS) - sz += sizeof(state->Buffer); - - if (dirty & I830_UPLOAD_STIPPLE) - sz += sizeof(state->Stipple); - - for (i = 0; i < I830_TEX_UNITS; i++) { - if ((dirty & I830_UPLOAD_TEX(i))) - sz += sizeof(state->Tex[i]); - - if (dirty & I830_UPLOAD_TEXBLEND(i)) - sz += state->TexBlendWordsUsed[i] * 4; - } - - return sz; -} - - -/* Push the state into the sarea and/or texture memory. - */ -static void i830_emit_state( struct intel_context *intel ) -{ - struct i830_context *i830 = i830_context(&intel->ctx); - struct i830_hw_state *state = i830->current; - int i; - GLuint dirty = state->active & ~state->emitted; - GLuint counter = intel->batch.counter; - BATCH_LOCALS; - - if (intel->batch.space < get_state_size(state)) { - intelFlushBatch(intel, GL_TRUE); - dirty = state->active & ~state->emitted; - counter = intel->batch.counter; - } - - if (dirty & I830_UPLOAD_INVARIENT) { - if (INTEL_DEBUG & DEBUG_STATE) - fprintf(stderr, "I830_UPLOAD_INVARIENT:\n"); - i830_emit_invarient_state( intel ); - } - - if (dirty & I830_UPLOAD_CTX) { - if (INTEL_DEBUG & DEBUG_STATE) - fprintf(stderr, "I830_UPLOAD_CTX:\n"); - emit( i830, state->Ctx, sizeof(state->Ctx) ); - - } - - if (dirty & I830_UPLOAD_BUFFERS) { - if (INTEL_DEBUG & DEBUG_STATE) - fprintf(stderr, "I830_UPLOAD_BUFFERS:\n"); - BEGIN_BATCH(I830_DEST_SETUP_SIZE+2, 0); - OUT_BATCH(state->Buffer[I830_DESTREG_CBUFADDR0]); - OUT_BATCH(state->Buffer[I830_DESTREG_CBUFADDR1]); - OUT_RELOC(state->draw_region->buffer, DRM_MM_TT|DRM_MM_WRITE, 0); - - if (state->depth_region) { - OUT_BATCH(state->Buffer[I830_DESTREG_DBUFADDR0]); - OUT_BATCH(state->Buffer[I830_DESTREG_DBUFADDR1]); - OUT_RELOC(state->depth_region->buffer, DRM_MM_TT |DRM_MM_WRITE, 0); - } - - OUT_BATCH(state->Buffer[I830_DESTREG_DV0]); - OUT_BATCH(state->Buffer[I830_DESTREG_DV1]); - OUT_BATCH(state->Buffer[I830_DESTREG_SENABLE]); - OUT_BATCH(state->Buffer[I830_DESTREG_SR0]); - OUT_BATCH(state->Buffer[I830_DESTREG_SR1]); - OUT_BATCH(state->Buffer[I830_DESTREG_SR2]); - ADVANCE_BATCH(); - } - - if (dirty & I830_UPLOAD_STIPPLE) { - if (INTEL_DEBUG & DEBUG_STATE) - fprintf(stderr, "I830_UPLOAD_STIPPLE:\n"); - emit( i830, state->Stipple, sizeof(state->Stipple) ); - } - - for (i = 0; i < I830_TEX_UNITS; i++) { - if ((dirty & I830_UPLOAD_TEX(i))) { - if (INTEL_DEBUG & DEBUG_STATE) - fprintf(stderr, "I830_UPLOAD_TEX(%d):\n", i); - - BEGIN_BATCH(I830_TEX_SETUP_SIZE+1, 0); - OUT_BATCH(state->Tex[i][I830_TEXREG_TM0LI]); - - if (state->tex_buffer[i]) { - OUT_RELOC(state->tex_buffer[i], - DRM_MM_TT|DRM_MM_READ, - state->tex_offset[i] | TM0S0_USE_FENCE); - } - else { - assert(i == 0); - assert(state == &i830->meta); - OUT_BATCH(0); - } - - OUT_BATCH(state->Tex[i][I830_TEXREG_TM0S1]); - OUT_BATCH(state->Tex[i][I830_TEXREG_TM0S2]); - OUT_BATCH(state->Tex[i][I830_TEXREG_TM0S3]); - OUT_BATCH(state->Tex[i][I830_TEXREG_TM0S4]); - OUT_BATCH(state->Tex[i][I830_TEXREG_MCS]); - OUT_BATCH(state->Tex[i][I830_TEXREG_CUBE]); - } - - if (dirty & I830_UPLOAD_TEXBLEND(i)) { - if (INTEL_DEBUG & DEBUG_STATE) - fprintf(stderr, "I830_UPLOAD_TEXBLEND(%d): %d words\n", i, - state->TexBlendWordsUsed[i]); - emit( i830, state->TexBlend[i], - state->TexBlendWordsUsed[i] * 4 ); - } - } - - state->emitted |= dirty; - intel->batch.last_emit_state = counter; - assert(counter == intel->batch.counter); -} - -static void i830_destroy_context( struct intel_context *intel ) -{ - _tnl_free_vertices(&intel->ctx); -} - -<<<<<<< i830_vtbl.c -static void -i830_set_color_region(intelContextPtr intel, const intelRegion *region) -======= -static void i830_set_draw_region( struct intel_context *intel, - struct intel_region *draw_region, - struct intel_region *depth_region) ->>>>>>> 1.6.12.10 -{ - struct i830_context *i830 = i830_context(&intel->ctx); - - intel_region_release(intel, &i830->state.draw_region); - intel_region_release(intel, &i830->state.depth_region); - intel_region_reference(&i830->state.draw_region, draw_region); - intel_region_reference(&i830->state.depth_region, depth_region); - - /* XXX FBO: Need code from i915_set_draw_region() */ - - I830_STATECHANGE( i830, I830_UPLOAD_BUFFERS ); -<<<<<<< i830_vtbl.c - i830->state.Buffer[I830_DESTREG_CBUFADDR1] = - (BUF_3D_ID_COLOR_BACK | BUF_3D_PITCH(region->pitch) | BUF_3D_USE_FENCE); - i830->state.Buffer[I830_DESTREG_CBUFADDR2] = region->offset; -======= ->>>>>>> 1.6.12.10 -} - - -static void -i830_set_z_region(intelContextPtr intel, const intelRegion *region) -{ - i830ContextPtr i830 = I830_CONTEXT(intel); - I830_STATECHANGE( i830, I830_UPLOAD_BUFFERS ); - i830->state.Buffer[I830_DESTREG_DBUFADDR1] = - (BUF_3D_ID_DEPTH | BUF_3D_PITCH(region->pitch) | BUF_3D_USE_FENCE); - i830->state.Buffer[I830_DESTREG_DBUFADDR2] = region->offset; -} - - -static void -i830_update_color_z_regions(intelContextPtr intel, - const intelRegion *colorRegion, - const intelRegion *depthRegion) -{ - i830ContextPtr i830 = I830_CONTEXT(intel); - - i830->state.Buffer[I830_DESTREG_CBUFADDR1] = - (BUF_3D_ID_COLOR_BACK | BUF_3D_PITCH(colorRegion->pitch) | BUF_3D_USE_FENCE); - i830->state.Buffer[I830_DESTREG_CBUFADDR2] = colorRegion->offset; - - i830->state.Buffer[I830_DESTREG_DBUFADDR1] = - (BUF_3D_ID_DEPTH | BUF_3D_PITCH(depthRegion->pitch) | BUF_3D_USE_FENCE); - i830->state.Buffer[I830_DESTREG_DBUFADDR2] = depthRegion->offset; -} - - -/* This isn't really handled at the moment. - */ -static void i830_lost_hardware( struct intel_context *intel ) -{ - struct i830_context *i830 = i830_context(&intel->ctx); - i830->state.emitted = 0; -} - - - -static GLuint i830_flush_cmd( void ) -{ - return MI_FLUSH | FLUSH_MAP_CACHE; -} - - - - -void i830InitVtbl( struct i830_context *i830 ) -{ - i830->intel.vtbl.check_vertex_size = i830_check_vertex_size; -<<<<<<< i830_vtbl.c - i830->intel.vtbl.clear_with_tris = i830ClearWithTris; - i830->intel.vtbl.rotate_window = i830RotateWindow; -======= ->>>>>>> 1.6.12.10 - i830->intel.vtbl.destroy = i830_destroy_context; - i830->intel.vtbl.emit_state = i830_emit_state; - i830->intel.vtbl.lost_hardware = i830_lost_hardware; - i830->intel.vtbl.reduced_primitive_state = i830_reduced_primitive_state; -<<<<<<< i830_vtbl.c - i830->intel.vtbl.set_color_region = i830_set_color_region; - i830->intel.vtbl.set_z_region = i830_set_z_region; - i830->intel.vtbl.update_color_z_regions = i830_update_color_z_regions; -======= - i830->intel.vtbl.set_draw_region = i830_set_draw_region; ->>>>>>> 1.6.12.10 - i830->intel.vtbl.update_texture_state = i830UpdateTextureState; - i830->intel.vtbl.flush_cmd = i830_flush_cmd; - i830->intel.vtbl.render_start = i830_render_start; -} diff --git a/src/mesa/drivers/dri/i915-tex/i915_context.c b/src/mesa/drivers/dri/i915-tex/i915_context.c deleted file mode 100644 index e22d93ae8a0..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i915_context.c +++ /dev/null @@ -1,184 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "i915_context.h" -#include "imports.h" -#include "intel_tex.h" -#include "intel_tris.h" -#include "tnl/t_context.h" -#include "tnl/t_pipeline.h" -#include "tnl/t_vertex.h" - -#include "swrast/swrast.h" -#include "swrast_setup/swrast_setup.h" -#include "tnl/tnl.h" -#include "array_cache/acache.h" - -#include "utils.h" -#include "i915_reg.h" - -#include "intel_bufmgr.h" -#include "intel_regions.h" -#include "intel_batchbuffer.h" - -/*************************************** - * Mesa's Driver Functions - ***************************************/ - -static const struct dri_extension i915_extensions[] = -{ - { "GL_ARB_depth_texture", NULL }, - { "GL_ARB_fragment_program", NULL }, - { "GL_ARB_shadow", NULL }, - { "GL_EXT_shadow_funcs", NULL }, - /* ARB extn won't work if not enabled */ - { "GL_SGIX_depth_texture", NULL }, - { NULL, NULL } -}; - -/* Override intel default. - */ -static void i915InvalidateState( GLcontext *ctx, GLuint new_state ) -{ - _swrast_InvalidateState( ctx, new_state ); - _swsetup_InvalidateState( ctx, new_state ); - _ac_InvalidateState( ctx, new_state ); - _tnl_InvalidateState( ctx, new_state ); - _tnl_invalidate_vertex_state( ctx, new_state ); - intel_context(ctx)->NewGLState |= new_state; - - /* Todo: gather state values under which tracked parameters become - * invalidated, add callbacks for things like - * ProgramLocalParameters, etc. - */ - { - struct i915_fragment_program *p = - (struct i915_fragment_program *)ctx->FragmentProgram._Current; - if (p && p->nr_params) - p->params_uptodate = 0; - } - - if (new_state & (_NEW_FOG|_NEW_HINT|_NEW_PROGRAM)) - i915_update_fog(ctx); -} - - -static void i915InitDriverFunctions( struct dd_function_table *functions ) -{ - intelInitDriverFunctions( functions ); - i915InitStateFunctions( functions ); - i915InitTextureFuncs( functions ); - i915InitFragProgFuncs( functions ); - functions->UpdateState = i915InvalidateState; -} - - - -GLboolean i915CreateContext( const __GLcontextModes *mesaVis, - __DRIcontextPrivate *driContextPriv, - void *sharedContextPrivate) -{ - struct dd_function_table functions; - struct i915_context *i915 = (struct i915_context *) CALLOC_STRUCT(i915_context); - struct intel_context *intel = &i915->intel; - GLcontext *ctx = &intel->ctx; - GLuint i; - - if (!i915) return GL_FALSE; - - _mesa_printf( "\ntexmem branch (i915, drop2)\n\n"); - - i915InitVtbl( i915 ); - i915InitMetaFuncs( i915 ); - - i915InitDriverFunctions( &functions ); - - if (!intelInitContext( intel, mesaVis, driContextPriv, - sharedContextPrivate, &functions )) { - FREE(i915); - return GL_FALSE; - } - - ctx->Const.MaxTextureUnits = I915_TEX_UNITS; - ctx->Const.MaxTextureImageUnits = I915_TEX_UNITS; - ctx->Const.MaxTextureCoordUnits = I915_TEX_UNITS; - - - /* Advertise the full hardware capabilities. The new memory - * manager should cope much better with overload situations: - */ -<<<<<<< i915_context.c - ctx->Const.MaxTextureUnits = I915_TEX_UNITS; - i = driQueryOptioni( &intel->intelScreen->optionCache, "allow_large_textures"); - driCalculateMaxTextureLevels( intel->texture_heaps, - intel->nr_heaps, - &intel->ctx.Const, - 4, - 11, /* max 2D texture size is 2048x2048 */ - 8, /* 3D texture */ - 11, /* cube texture. */ - 11, /* rect texture */ - 12, - GL_FALSE, - i ); -======= - ctx->Const.MaxTextureLevels = 12; - ctx->Const.Max3DTextureLevels = 9; - ctx->Const.MaxCubeTextureLevels = 12; - ctx->Const.MaxTextureRectSize = (1<<11); - ctx->Const.MaxTextureUnits = I915_TEX_UNITS; ->>>>>>> 1.13.2.9 - - /* GL_ARB_fragment_program limits - don't think Mesa actually - * validates programs against these, and in any case one ARB - * instruction can translate to more than one HW instruction, so - * we'll still have to check and fallback each time. - */ - ctx->Const.FragmentProgram.MaxNativeTemps = I915_MAX_TEMPORARY; - ctx->Const.FragmentProgram.MaxNativeAttribs = 11; /* 8 tex, 2 color, fog */ - ctx->Const.FragmentProgram.MaxNativeParameters = I915_MAX_CONSTANT; - ctx->Const.FragmentProgram.MaxNativeAluInstructions = I915_MAX_ALU_INSN; - ctx->Const.FragmentProgram.MaxNativeTexInstructions = I915_MAX_TEX_INSN; - ctx->Const.FragmentProgram.MaxNativeInstructions = (I915_MAX_ALU_INSN + - I915_MAX_TEX_INSN); - ctx->Const.FragmentProgram.MaxNativeTexIndirections = I915_MAX_TEX_INDIRECT; - ctx->Const.FragmentProgram.MaxNativeAddressRegs = 0; /* I don't think we have one */ - - - driInitExtensions( ctx, i915_extensions, GL_FALSE ); - - - _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12, - 36 * sizeof(GLfloat) ); - - intel->verts = TNL_CONTEXT(ctx)->clipspace.vertex_buf; - - i915InitState( i915 ); - - return GL_TRUE; -} - diff --git a/src/mesa/drivers/dri/i915-tex/i915_context.h b/src/mesa/drivers/dri/i915-tex/i915_context.h deleted file mode 100644 index eb3dcd84d0f..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i915_context.h +++ /dev/null @@ -1,373 +0,0 @@ - /************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#ifndef I915CONTEXT_INC -#define I915CONTEXT_INC - -#include "intel_context.h" - -#define I915_FALLBACK_TEXTURE 0x1000 -#define I915_FALLBACK_COLORMASK 0x2000 -#define I915_FALLBACK_STENCIL 0x4000 -#define I915_FALLBACK_STIPPLE 0x8000 -#define I915_FALLBACK_PROGRAM 0x10000 -#define I915_FALLBACK_LOGICOP 0x20000 -#define I915_FALLBACK_POLYGON_SMOOTH 0x40000 -#define I915_FALLBACK_POINT_SMOOTH 0x80000 - -#define I915_UPLOAD_CTX 0x1 -#define I915_UPLOAD_BUFFERS 0x2 -#define I915_UPLOAD_STIPPLE 0x4 -#define I915_UPLOAD_PROGRAM 0x8 -#define I915_UPLOAD_CONSTANTS 0x10 -#define I915_UPLOAD_FOG 0x20 -#define I915_UPLOAD_INVARIENT 0x40 -#define I915_UPLOAD_DEFAULTS 0x80 -#define I915_UPLOAD_TEX(i) (0x00010000<<(i)) -#define I915_UPLOAD_TEX_ALL (0x00ff0000) -#define I915_UPLOAD_TEX_0_SHIFT 16 - - -/* State structure offsets - these will probably disappear. - */ -#define I915_DESTREG_CBUFADDR0 0 -#define I915_DESTREG_CBUFADDR1 1 -#define I915_DESTREG_DBUFADDR0 3 -#define I915_DESTREG_DBUFADDR1 4 -#define I915_DESTREG_DV0 6 -#define I915_DESTREG_DV1 7 -#define I915_DESTREG_SENABLE 8 -#define I915_DESTREG_SR0 9 -#define I915_DESTREG_SR1 10 -#define I915_DESTREG_SR2 11 -#define I915_DEST_SETUP_SIZE 12 - -#define I915_CTXREG_STATE4 0 -#define I915_CTXREG_LI 1 -#define I915_CTXREG_LIS2 2 -#define I915_CTXREG_LIS4 3 -#define I915_CTXREG_LIS5 4 -#define I915_CTXREG_LIS6 5 -#define I915_CTXREG_IAB 6 -#define I915_CTXREG_BLENDCOLOR0 7 -#define I915_CTXREG_BLENDCOLOR1 8 -#define I915_CTX_SETUP_SIZE 9 - -#define I915_FOGREG_COLOR 0 -#define I915_FOGREG_MODE0 1 -#define I915_FOGREG_MODE1 2 -#define I915_FOGREG_MODE2 3 -#define I915_FOGREG_MODE3 4 -#define I915_FOG_SETUP_SIZE 5 - -#define I915_STPREG_ST0 0 -#define I915_STPREG_ST1 1 -#define I915_STP_SETUP_SIZE 2 - -#define I915_TEXREG_MS3 1 -#define I915_TEXREG_MS4 2 -#define I915_TEXREG_SS2 3 -#define I915_TEXREG_SS3 4 -#define I915_TEXREG_SS4 5 -#define I915_TEX_SETUP_SIZE 6 - -#define I915_DEFREG_C0 0 -#define I915_DEFREG_C1 1 -#define I915_DEFREG_S0 2 -#define I915_DEFREG_S1 3 -#define I915_DEFREG_Z0 4 -#define I915_DEFREG_Z1 5 -#define I915_DEF_SETUP_SIZE 6 - - -#define I915_MAX_CONSTANT 32 -#define I915_CONSTANT_SIZE (2+(4*I915_MAX_CONSTANT)) - - -#define I915_PROGRAM_SIZE 192 - - -/* Hardware version of a parsed fragment program. "Derived" from the - * mesa fragment_program struct. - */ -struct i915_fragment_program { - struct fragment_program FragProg; - - GLboolean translated; - GLboolean params_uptodate; - GLboolean on_hardware; - GLboolean error; /* If program is malformed for any reason. */ - - GLuint nr_tex_indirect; - GLuint nr_tex_insn; - GLuint nr_alu_insn; - GLuint nr_decl_insn; - - - - - /* TODO: split between the stored representation of a program and - * the state used to build that representation. - */ - GLcontext *ctx; - - GLuint declarations[I915_PROGRAM_SIZE]; - GLuint program[I915_PROGRAM_SIZE]; - - GLfloat constant[I915_MAX_CONSTANT][4]; - GLuint constant_flags[I915_MAX_CONSTANT]; - GLuint nr_constants; - - GLuint *csr; /* Cursor, points into program. - */ - - GLuint *decl; /* Cursor, points into declarations. - */ - - GLuint decl_s; /* flags for which s regs need to be decl'd */ - GLuint decl_t; /* flags for which t regs need to be decl'd */ - - GLuint temp_flag; /* Tracks temporary regs which are in - * use. - */ - - GLuint utemp_flag; /* Tracks TYPE_U temporary regs which are in - * use. - */ - - - - /* Helpers for i915_fragprog.c: - */ - GLuint wpos_tex; - GLboolean depth_written; - - struct { - GLuint reg; /* Hardware constant idx */ - const GLfloat *values; /* Pointer to tracked values */ - } param[I915_MAX_CONSTANT]; - GLuint nr_params; - - - /* Helpers for i915_texprog.c: - */ - GLuint src_texture; /* Reg containing sampled texture color, - * else UREG_BAD. - */ - - GLuint src_previous; /* Reg containing color from previous - * stage. May need to be decl'd. - */ - - GLuint last_tex_stage; /* Number of last enabled texture unit */ - - struct vertex_buffer *VB; -}; - - - - - - - -#define I915_TEX_UNITS 8 - - -struct i915_hw_state { - GLuint Ctx[I915_CTX_SETUP_SIZE]; - GLuint Buffer[I915_DEST_SETUP_SIZE]; - GLuint Stipple[I915_STP_SETUP_SIZE]; - GLuint Fog[I915_FOG_SETUP_SIZE]; - GLuint Defaults[I915_DEF_SETUP_SIZE]; - GLuint Tex[I915_TEX_UNITS][I915_TEX_SETUP_SIZE]; - GLuint Constant[I915_CONSTANT_SIZE]; - GLuint ConstantSize; - GLuint Program[I915_PROGRAM_SIZE]; - GLuint ProgramSize; - - /* Region pointers for relocation: - */ - struct intel_region *draw_region; - struct intel_region *depth_region; -/* struct intel_region *tex_region[I915_TEX_UNITS]; */ - - /* Regions aren't actually that appropriate here as the memory may - * be from a PBO or FBO. Just use the buffer id. Will have to do - * this for draw and depth for FBO's... - */ - GLuint tex_buffer[I915_TEX_UNITS]; - GLuint tex_offset[I915_TEX_UNITS]; - - - GLuint active; /* I915_UPLOAD_* */ - GLuint emitted; /* I915_UPLOAD_* */ -}; - -#define I915_FOG_PIXEL 2 -#define I915_FOG_VERTEX 1 -#define I915_FOG_NONE 0 - -struct i915_context -{ - struct intel_context intel; - - GLuint last_ReallyEnabled; - GLuint vertex_fog; - GLuint lodbias_ss2[MAX_TEXTURE_UNITS]; - - - struct i915_fragment_program tex_program; - struct i915_fragment_program *current_program; - - struct i915_hw_state meta, initial, state, *current; -}; - - -#define I915_STATECHANGE(i915, flag) \ -do { \ - INTEL_FIREVERTICES( &(i915)->intel ); \ - (i915)->state.emitted &= ~(flag); \ -} while (0) - -#define I915_ACTIVESTATE(i915, flag, mode) \ -do { \ - INTEL_FIREVERTICES( &(i915)->intel ); \ - if (mode) \ - (i915)->state.active |= (flag); \ - else \ - (i915)->state.active &= ~(flag); \ -} while (0) - - -/*====================================================================== - * i915_vtbl.c - */ -extern void i915InitVtbl( struct i915_context *i915 ); - -extern void -i915_state_draw_region(struct intel_context *intel, - struct i915_hw_state *state, - struct intel_region *color_region, - struct intel_region *depth_region); - - - -#define SZ_TO_HW(sz) ((sz-2)&0x3) -#define EMIT_SZ(sz) (EMIT_1F + (sz) - 1) -#define EMIT_ATTR( ATTR, STYLE, S4, SZ ) \ -do { \ - intel->vertex_attrs[intel->vertex_attr_count].attrib = (ATTR); \ - intel->vertex_attrs[intel->vertex_attr_count].format = (STYLE); \ - s4 |= S4; \ - intel->vertex_attr_count++; \ - offset += (SZ); \ -} while (0) - -#define EMIT_PAD( N ) \ -do { \ - intel->vertex_attrs[intel->vertex_attr_count].attrib = 0; \ - intel->vertex_attrs[intel->vertex_attr_count].format = EMIT_PAD; \ - intel->vertex_attrs[intel->vertex_attr_count].offset = (N); \ - intel->vertex_attr_count++; \ - offset += (N); \ -} while (0) - - - -/*====================================================================== - * i915_context.c - */ -extern GLboolean i915CreateContext( const __GLcontextModes *mesaVis, - __DRIcontextPrivate *driContextPriv, - void *sharedContextPrivate); - - -/*====================================================================== - * i915_texprog.c - */ -extern void i915ValidateTextureProgram( struct i915_context *i915 ); - - -/*====================================================================== - * i915_debug.c - */ -extern void i915_disassemble_program( const GLuint *program, GLuint sz ); -extern void i915_print_ureg( const char *msg, GLuint ureg ); - - -/*====================================================================== - * i915_state.c - */ -extern void i915InitStateFunctions( struct dd_function_table *functions ); -<<<<<<< i915_context.h -extern void i915InitState( i915ContextPtr i915 ); -======= -extern void i915InitState( struct i915_context *i915 ); -extern void i915_update_fog( GLcontext *ctx ); ->>>>>>> 1.3.4.8 - - -/*====================================================================== - * i915_tex.c - */ -extern void i915UpdateTextureState( struct intel_context *intel ); -extern void i915InitTextureFuncs( struct dd_function_table *functions ); - -/*====================================================================== - * i915_metaops.c - */ -void i915InitMetaFuncs( struct i915_context *i915 ); - - -extern void -i915RotateWindow(intelContextPtr intel, __DRIdrawablePrivate *dPriv, - GLuint srcBuf); - -/*====================================================================== - * i915_fragprog.c - */ -extern void i915ValidateFragmentProgram( struct i915_context *i915 ); -extern void i915InitFragProgFuncs( struct dd_function_table *functions ); - -/*====================================================================== - * Inline conversion functions. These are better-typed than the - * macros used previously: - */ -static INLINE struct i915_context * -i915_context( GLcontext *ctx ) -{ - return (struct i915_context *)ctx; -} - - - -#define I915_CONTEXT(ctx) i915_context(ctx) - - - -#endif - diff --git a/src/mesa/drivers/dri/i915-tex/i915_debug.c b/src/mesa/drivers/dri/i915-tex/i915_debug.c deleted file mode 100644 index 054b561605a..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i915_debug.c +++ /dev/null @@ -1,299 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "i915_reg.h" -#include "i915_context.h" -#include <stdio.h> - - -static const char *opcodes[0x20] = { - "NOP", - "ADD", - "MOV", - "MUL", - "MAD", - "DP2ADD", - "DP3", - "DP4", - "FRC", - "RCP", - "RSQ", - "EXP", - "LOG", - "CMP", - "MIN", - "MAX", - "FLR", - "MOD", - "TRC", - "SGE", - "SLT", - "TEXLD", - "TEXLDP", - "TEXLDB", - "TEXKILL", - "DCL", - "0x1a", - "0x1b", - "0x1c", - "0x1d", - "0x1e", - "0x1f", -}; - - -static const int args[0x20] = { - 0, /* 0 nop */ - 2, /* 1 add */ - 1, /* 2 mov */ - 2, /* 3 m ul */ - 3, /* 4 mad */ - 3, /* 5 dp2add */ - 2, /* 6 dp3 */ - 2, /* 7 dp4 */ - 1, /* 8 frc */ - 1, /* 9 rcp */ - 1, /* a rsq */ - 1, /* b exp */ - 1, /* c log */ - 3, /* d cmp */ - 2, /* e min */ - 2, /* f max */ - 1, /* 10 flr */ - 1, /* 11 mod */ - 1, /* 12 trc */ - 2, /* 13 sge */ - 2, /* 14 slt */ - 1, - 1, - 1, - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 0, -}; - - -static const char *regname[0x8] = { - "R", - "T", - "CONST", - "S", - "OC", - "OD", - "U", - "UNKNOWN", -}; - -static void print_reg_type_nr( GLuint type, GLuint nr ) -{ - switch (type) { - case REG_TYPE_T: - switch (nr) { - case T_DIFFUSE: fprintf(stderr, "T_DIFFUSE"); return; - case T_SPECULAR: fprintf(stderr, "T_SPECULAR"); return; - case T_FOG_W: fprintf(stderr, "T_FOG_W"); return; - default: fprintf(stderr, "T_TEX%d", nr); return; - } - case REG_TYPE_OC: - if (nr == 0) { - fprintf(stderr, "oC"); - return; - } - break; - case REG_TYPE_OD: - if (nr == 0) { - fprintf(stderr, "oD"); - return; - } - break; - default: - break; - } - - fprintf(stderr, "%s[%d]", regname[type], nr); -} - -#define REG_SWIZZLE_MASK 0x7777 -#define REG_NEGATE_MASK 0x8888 - -#define REG_SWIZZLE_XYZW ((SRC_X << A2_SRC2_CHANNEL_X_SHIFT) | \ - (SRC_Y << A2_SRC2_CHANNEL_Y_SHIFT) | \ - (SRC_Z << A2_SRC2_CHANNEL_Z_SHIFT) | \ - (SRC_W << A2_SRC2_CHANNEL_W_SHIFT)) - - -static void print_reg_neg_swizzle( GLuint reg ) -{ - int i; - - if ((reg & REG_SWIZZLE_MASK) == REG_SWIZZLE_XYZW && - (reg & REG_NEGATE_MASK) == 0) - return; - - fprintf(stderr, "."); - - for (i = 3 ; i >= 0; i--) { - if (reg & (1<<((i*4)+3))) - fprintf(stderr, "-"); - - switch ((reg>>(i*4)) & 0x7) { - case 0: fprintf(stderr, "x"); break; - case 1: fprintf(stderr, "y"); break; - case 2: fprintf(stderr, "z"); break; - case 3: fprintf(stderr, "w"); break; - case 4: fprintf(stderr, "0"); break; - case 5: fprintf(stderr, "1"); break; - default: fprintf(stderr, "?"); break; - } - } -} - - -static void print_src_reg( GLuint dword ) -{ - GLuint nr = (dword >> A2_SRC2_NR_SHIFT) & REG_NR_MASK; - GLuint type = (dword >> A2_SRC2_TYPE_SHIFT) & REG_TYPE_MASK; - print_reg_type_nr( type, nr ); - print_reg_neg_swizzle( dword ); -} - -void i915_print_ureg( const char *msg, GLuint ureg ) -{ - fprintf(stderr, "%s: ", msg); - print_src_reg( ureg >> 8 ); - fprintf(stderr, "\n"); -} - -static void print_dest_reg( GLuint dword ) -{ - GLuint nr = (dword >> A0_DEST_NR_SHIFT) & REG_NR_MASK; - GLuint type = (dword >> A0_DEST_TYPE_SHIFT) & REG_TYPE_MASK; - print_reg_type_nr( type, nr ); - if ((dword & A0_DEST_CHANNEL_ALL) == A0_DEST_CHANNEL_ALL) - return; - fprintf(stderr, "."); - if (dword & A0_DEST_CHANNEL_X) fprintf(stderr, "x"); - if (dword & A0_DEST_CHANNEL_Y) fprintf(stderr, "y"); - if (dword & A0_DEST_CHANNEL_Z) fprintf(stderr, "z"); - if (dword & A0_DEST_CHANNEL_W) fprintf(stderr, "w"); -} - - -#define GET_SRC0_REG(r0, r1) ((r0<<14)|(r1>>A1_SRC0_CHANNEL_W_SHIFT)) -#define GET_SRC1_REG(r0, r1) ((r0<<8)|(r1>>A2_SRC1_CHANNEL_W_SHIFT)) -#define GET_SRC2_REG(r) (r) - - -static void print_arith_op( GLuint opcode, const GLuint *program ) -{ - if (opcode != A0_NOP) { - print_dest_reg(program[0]); - if (program[0] & A0_DEST_SATURATE) - fprintf(stderr, " = SATURATE "); - else - fprintf(stderr, " = "); - } - - fprintf(stderr, "%s ", opcodes[opcode]); - - print_src_reg(GET_SRC0_REG(program[0], program[1])); - if (args[opcode] == 1) { - fprintf(stderr, "\n"); - return; - } - - fprintf(stderr, ", "); - print_src_reg(GET_SRC1_REG(program[1], program[2])); - if (args[opcode] == 2) { - fprintf(stderr, "\n"); - return; - } - - fprintf(stderr, ", "); - print_src_reg(GET_SRC2_REG(program[2])); - fprintf(stderr, "\n"); - return; -} - - -static void print_tex_op( GLuint opcode, const GLuint *program ) -{ - print_dest_reg(program[0] | A0_DEST_CHANNEL_ALL); - fprintf(stderr, " = "); - - fprintf(stderr, "%s ", opcodes[opcode]); - - fprintf(stderr, "S[%d],", - program[0] & T0_SAMPLER_NR_MASK); - - print_reg_type_nr( (program[1]>>T1_ADDRESS_REG_TYPE_SHIFT) & REG_TYPE_MASK, - (program[1]>>T1_ADDRESS_REG_NR_SHIFT) & REG_NR_MASK ); - fprintf(stderr, "\n"); -} - -static void print_dcl_op( GLuint opcode, const GLuint *program ) -{ - fprintf(stderr, "%s ", opcodes[opcode]); - print_dest_reg(program[0] | A0_DEST_CHANNEL_ALL); - fprintf(stderr, "\n"); -} - - -void i915_disassemble_program( const GLuint *program, GLuint sz ) -{ - GLuint size = program[0] & 0x1ff; - GLint i; - - fprintf(stderr, "BEGIN\n"); - - if (size+2 != sz) { - fprintf(stderr, "%s: program size mismatch %d/%d\n", __FUNCTION__, - size+2, sz); - exit(1); - } - - program ++; - for (i = 1 ; i < sz ; i+=3, program+=3) { - GLuint opcode = program[0] & (0x1f<<24); - - if ((GLint) opcode >= A0_NOP && opcode <= A0_SLT) - print_arith_op(opcode >> 24, program); - else if (opcode >= T0_TEXLD && opcode <= T0_TEXKILL) - print_tex_op(opcode >> 24, program); - else if (opcode == D0_DCL) - print_dcl_op(opcode >> 24, program); - else - fprintf(stderr, "Unknown opcode 0x%x\n", opcode); - } - - fprintf(stderr, "END\n\n"); -} diff --git a/src/mesa/drivers/dri/i915-tex/i915_fragprog.c b/src/mesa/drivers/dri/i915-tex/i915_fragprog.c deleted file mode 100644 index f05d90298d7..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i915_fragprog.c +++ /dev/null @@ -1,1066 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "glheader.h" -#include "macros.h" -#include "enums.h" - -#include "tnl/t_context.h" -#include "intel_batchbuffer.h" - -#include "i915_reg.h" -#include "i915_context.h" -#include "i915_program.h" - -#include "program_instruction.h" -#include "program.h" - - - -/* 1, -1/3!, 1/5!, -1/7! */ -static const GLfloat sin_constants[4] = { 1.0, - -1.0/(3*2*1), - 1.0/(5*4*3*2*1), - -1.0/(7*6*5*4*3*2*1) }; - -/* 1, -1/2!, 1/4!, -1/6! */ -static const GLfloat cos_constants[4] = { 1.0, - -1.0/(2*1), - 1.0/(4*3*2*1), - -1.0/(6*5*4*3*2*1) }; - -/** - * Retrieve a ureg for the given source register. Will emit - * constants, apply swizzling and negation as needed. - */ -static GLuint src_vector( struct i915_fragment_program *p, - const struct prog_src_register *source, - const struct fragment_program *program ) -{ - GLuint src; - - switch (source->File) { - - /* Registers: - */ - case PROGRAM_TEMPORARY: - if (source->Index >= I915_MAX_TEMPORARY) { - i915_program_error( p, "Exceeded max temporary reg" ); - return 0; - } - src = UREG( REG_TYPE_R, source->Index ); - break; - case PROGRAM_INPUT: - switch (source->Index) { - case FRAG_ATTRIB_WPOS: - src = i915_emit_decl( p, REG_TYPE_T, p->wpos_tex, D0_CHANNEL_ALL ); - break; - case FRAG_ATTRIB_COL0: - src = i915_emit_decl( p, REG_TYPE_T, T_DIFFUSE, D0_CHANNEL_ALL ); - break; - case FRAG_ATTRIB_COL1: - src = i915_emit_decl( p, REG_TYPE_T, T_SPECULAR, D0_CHANNEL_XYZ ); - src = swizzle( src, X, Y, Z, ONE ); - break; - case FRAG_ATTRIB_FOGC: - src = i915_emit_decl( p, REG_TYPE_T, T_FOG_W, D0_CHANNEL_W ); - src = swizzle( src, W, W, W, W ); - break; - case FRAG_ATTRIB_TEX0: - case FRAG_ATTRIB_TEX1: - case FRAG_ATTRIB_TEX2: - case FRAG_ATTRIB_TEX3: - case FRAG_ATTRIB_TEX4: - case FRAG_ATTRIB_TEX5: - case FRAG_ATTRIB_TEX6: - case FRAG_ATTRIB_TEX7: - src = i915_emit_decl( p, REG_TYPE_T, - T_TEX0 + (source->Index - FRAG_ATTRIB_TEX0), - D0_CHANNEL_ALL ); - break; - - default: - i915_program_error( p, "Bad source->Index" ); - return 0; - } - break; - - /* Various paramters and env values. All emitted to - * hardware as program constants. - */ - case PROGRAM_LOCAL_PARAM: - src = i915_emit_param4fv( - p, program->Base.LocalParams[source->Index]); - break; - - case PROGRAM_ENV_PARAM: - src = i915_emit_param4fv( - p, p->ctx->FragmentProgram.Parameters[source->Index]); - break; - - case PROGRAM_STATE_VAR: - case PROGRAM_NAMED_PARAM: - src = i915_emit_param4fv( - p, program->Base.Parameters->ParameterValues[source->Index] ); - break; - - default: - i915_program_error( p, "Bad source->File" ); - return 0; - } - - src = swizzle(src, - GET_SWZ(source->Swizzle, 0), - GET_SWZ(source->Swizzle, 1), - GET_SWZ(source->Swizzle, 2), - GET_SWZ(source->Swizzle, 3)); - - if (source->NegateBase) - src = negate( src, - GET_BIT(source->NegateBase, 0), - GET_BIT(source->NegateBase, 1), - GET_BIT(source->NegateBase, 2), - GET_BIT(source->NegateBase, 3)); - - return src; -} - - -static GLuint get_result_vector( struct i915_fragment_program *p, - const struct prog_instruction *inst ) -{ - switch (inst->DstReg.File) { - case PROGRAM_OUTPUT: - switch (inst->DstReg.Index) { - case FRAG_RESULT_COLR: - return UREG(REG_TYPE_OC, 0); - case FRAG_RESULT_DEPR: - p->depth_written = 1; - return UREG(REG_TYPE_OD, 0); - default: - i915_program_error( p, "Bad inst->DstReg.Index" ); - return 0; - } - case PROGRAM_TEMPORARY: - return UREG(REG_TYPE_R, inst->DstReg.Index); - default: - i915_program_error( p, "Bad inst->DstReg.File" ); - return 0; - } -} - -static GLuint get_result_flags( const struct prog_instruction *inst ) -{ - GLuint flags = 0; - - if (inst->SaturateMode == SATURATE_ZERO_ONE) flags |= A0_DEST_SATURATE; - if (inst->DstReg.WriteMask & WRITEMASK_X) flags |= A0_DEST_CHANNEL_X; - if (inst->DstReg.WriteMask & WRITEMASK_Y) flags |= A0_DEST_CHANNEL_Y; - if (inst->DstReg.WriteMask & WRITEMASK_Z) flags |= A0_DEST_CHANNEL_Z; - if (inst->DstReg.WriteMask & WRITEMASK_W) flags |= A0_DEST_CHANNEL_W; - - return flags; -} - -static GLuint translate_tex_src_target( struct i915_fragment_program *p, - GLubyte bit ) -{ - switch (bit) { - case TEXTURE_1D_INDEX: return D0_SAMPLE_TYPE_2D; - case TEXTURE_2D_INDEX: return D0_SAMPLE_TYPE_2D; - case TEXTURE_RECT_INDEX: return D0_SAMPLE_TYPE_2D; - case TEXTURE_3D_INDEX: return D0_SAMPLE_TYPE_VOLUME; - case TEXTURE_CUBE_INDEX: return D0_SAMPLE_TYPE_CUBE; - default: i915_program_error(p, "TexSrcBit"); return 0; - } -} - -#define EMIT_TEX( OP ) \ -do { \ - GLuint dim = translate_tex_src_target( p, inst->TexSrcTarget ); \ - GLuint sampler = i915_emit_decl(p, REG_TYPE_S, \ - inst->TexSrcUnit, dim); \ - GLuint coord = src_vector( p, &inst->SrcReg[0], program); \ - /* Texel lookup */ \ - \ - i915_emit_texld( p, \ - get_result_vector( p, inst ), \ - get_result_flags( inst ), \ - sampler, \ - coord, \ - OP); \ -} while (0) - -#define EMIT_ARITH( OP, N ) \ -do { \ - i915_emit_arith( p, \ - OP, \ - get_result_vector( p, inst ), \ - get_result_flags( inst ), 0, \ - (N<1)?0:src_vector( p, &inst->SrcReg[0], program), \ - (N<2)?0:src_vector( p, &inst->SrcReg[1], program), \ - (N<3)?0:src_vector( p, &inst->SrcReg[2], program)); \ -} while (0) - -#define EMIT_1ARG_ARITH( OP ) EMIT_ARITH( OP, 1 ) -#define EMIT_2ARG_ARITH( OP ) EMIT_ARITH( OP, 2 ) -#define EMIT_3ARG_ARITH( OP ) EMIT_ARITH( OP, 3 ) - - -/* Possible concerns: - * - * SIN, COS -- could use another taylor step? - * LIT -- results seem a little different to sw mesa - * LOG -- different to mesa on negative numbers, but this is conformant. - * - * Parse failures -- Mesa doesn't currently give a good indication - * internally whether a particular program string parsed or not. This - * can lead to confusion -- hopefully we cope with it ok now. - * - */ -static void upload_program( struct i915_fragment_program *p ) -{ - const struct fragment_program *program = p->ctx->FragmentProgram._Current; - const struct prog_instruction *inst = program->Base.Instructions; - -/* _mesa_debug_fp_inst(program->Base.NumInstructions, inst); */ - - /* Is this a parse-failed program? Ensure a valid program is - * loaded, as the flagging of an error isn't sufficient to stop - * this being uploaded to hardware. - */ - if (inst[0].Opcode == OPCODE_END) { - GLuint tmp = i915_get_utemp( p ); - i915_emit_arith( p, - A0_MOV, - UREG(REG_TYPE_OC, 0), - A0_DEST_CHANNEL_ALL, 0, - swizzle(tmp,ONE,ZERO,ONE,ONE), 0, 0); - return; - } - - while (1) { - GLuint src0, src1, src2, flags; - GLuint tmp = 0; - - switch (inst->Opcode) { - case OPCODE_ABS: - src0 = src_vector( p, &inst->SrcReg[0], program); - i915_emit_arith( p, - A0_MAX, - get_result_vector( p, inst ), - get_result_flags( inst ), 0, - src0, negate(src0, 1,1,1,1), 0); - break; - - case OPCODE_ADD: - EMIT_2ARG_ARITH( A0_ADD ); - break; - - case OPCODE_CMP: - src0 = src_vector( p, &inst->SrcReg[0], program); - src1 = src_vector( p, &inst->SrcReg[1], program); - src2 = src_vector( p, &inst->SrcReg[2], program); - i915_emit_arith( p, - A0_CMP, - get_result_vector( p, inst ), - get_result_flags( inst ), 0, - src0, src2, src1); /* NOTE: order of src2, src1 */ - break; - - case OPCODE_COS: - src0 = src_vector( p, &inst->SrcReg[0], program); - tmp = i915_get_utemp( p ); - - i915_emit_arith( p, - A0_MUL, - tmp, A0_DEST_CHANNEL_X, 0, - src0, - i915_emit_const1f(p, 1.0/(M_PI * 2)), - 0); - - i915_emit_arith( p, - A0_MOD, - tmp, A0_DEST_CHANNEL_X, 0, - tmp, - 0, 0 ); - - /* By choosing different taylor constants, could get rid of this mul: - */ - i915_emit_arith( p, - A0_MUL, - tmp, A0_DEST_CHANNEL_X, 0, - tmp, - i915_emit_const1f(p, (M_PI * 2)), - 0); - - /* - * t0.xy = MUL x.xx11, x.x1111 ; x^2, x, 1, 1 - * t0 = MUL t0.xyxy t0.xx11 ; x^4, x^3, x^2, 1 - * t0 = MUL t0.xxz1 t0.z111 ; x^6 x^4 x^2 1 - * result = DP4 t0, cos_constants - */ - i915_emit_arith( p, - A0_MUL, - tmp, A0_DEST_CHANNEL_XY, 0, - swizzle(tmp, X,X,ONE,ONE), - swizzle(tmp, X,ONE,ONE,ONE), 0); - - i915_emit_arith( p, - A0_MUL, - tmp, A0_DEST_CHANNEL_XYZ, 0, - swizzle(tmp, X,Y,X,ONE), - swizzle(tmp, X,X,ONE,ONE), 0); - - i915_emit_arith( p, - A0_MUL, - tmp, A0_DEST_CHANNEL_XYZ, 0, - swizzle(tmp, X,X,Z,ONE), - swizzle(tmp, Z,ONE,ONE,ONE), 0); - - i915_emit_arith( p, - A0_DP4, - get_result_vector( p, inst ), - get_result_flags( inst ), 0, - swizzle(tmp, ONE,Z,Y,X), - i915_emit_const4fv( p, cos_constants ), 0); - - break; - - case OPCODE_DP3: - EMIT_2ARG_ARITH( A0_DP3 ); - break; - - case OPCODE_DP4: - EMIT_2ARG_ARITH( A0_DP4 ); - break; - - case OPCODE_DPH: - src0 = src_vector( p, &inst->SrcReg[0], program); - src1 = src_vector( p, &inst->SrcReg[1], program); - - i915_emit_arith( p, - A0_DP4, - get_result_vector( p, inst ), - get_result_flags( inst ), 0, - swizzle(src0, X,Y,Z,ONE), src1, 0); - break; - - case OPCODE_DST: - src0 = src_vector( p, &inst->SrcReg[0], program); - src1 = src_vector( p, &inst->SrcReg[1], program); - - /* result[0] = 1 * 1; - * result[1] = a[1] * b[1]; - * result[2] = a[2] * 1; - * result[3] = 1 * b[3]; - */ - i915_emit_arith( p, - A0_MUL, - get_result_vector( p, inst ), - get_result_flags( inst ), 0, - swizzle(src0, ONE, Y, Z, ONE), - swizzle(src1, ONE, Y, ONE, W ), - 0); - break; - - case OPCODE_EX2: - src0 = src_vector( p, &inst->SrcReg[0], program); - - i915_emit_arith( p, - A0_EXP, - get_result_vector( p, inst ), - get_result_flags( inst ), 0, - swizzle(src0,X,X,X,X), 0, 0); - break; - - case OPCODE_FLR: - EMIT_1ARG_ARITH( A0_FLR ); - break; - - case OPCODE_FRC: - EMIT_1ARG_ARITH( A0_FRC ); - break; - - case OPCODE_KIL: - src0 = src_vector( p, &inst->SrcReg[0], program); - tmp = i915_get_utemp( p ); - - i915_emit_texld( p, - tmp, A0_DEST_CHANNEL_ALL, /* use a dummy dest reg */ - 0, - src0, - T0_TEXKILL ); - break; - - case OPCODE_LG2: - src0 = src_vector( p, &inst->SrcReg[0], program); - - i915_emit_arith( p, - A0_LOG, - get_result_vector( p, inst ), - get_result_flags( inst ), 0, - swizzle(src0,X,X,X,X), 0, 0); - break; - - case OPCODE_LIT: - src0 = src_vector( p, &inst->SrcReg[0], program); - tmp = i915_get_utemp( p ); - - /* tmp = max( a.xyzw, a.00zw ) - * XXX: Clamp tmp.w to -128..128 - * tmp.y = log(tmp.y) - * tmp.y = tmp.w * tmp.y - * tmp.y = exp(tmp.y) - * result = cmp (a.11-x1, a.1x01, a.1xy1 ) - */ - i915_emit_arith( p, A0_MAX, tmp, A0_DEST_CHANNEL_ALL, 0, - src0, swizzle(src0, ZERO, ZERO, Z, W), 0 ); - - i915_emit_arith( p, A0_LOG, tmp, A0_DEST_CHANNEL_Y, 0, - swizzle(tmp, Y, Y, Y, Y), 0, 0 ); - - i915_emit_arith( p, A0_MUL, tmp, A0_DEST_CHANNEL_Y, 0, - swizzle(tmp, ZERO, Y, ZERO, ZERO), - swizzle(tmp, ZERO, W, ZERO, ZERO), 0 ); - - i915_emit_arith( p, A0_EXP, tmp, A0_DEST_CHANNEL_Y, 0, - swizzle(tmp, Y, Y, Y, Y), 0, 0 ); - - i915_emit_arith( p, A0_CMP, - get_result_vector( p, inst ), - get_result_flags( inst ), 0, - negate(swizzle(tmp, ONE, ONE, X, ONE),0,0,1,0), - swizzle(tmp, ONE, X, ZERO, ONE), - swizzle(tmp, ONE, X, Y, ONE)); - - break; - - case OPCODE_LRP: - src0 = src_vector( p, &inst->SrcReg[0], program); - src1 = src_vector( p, &inst->SrcReg[1], program); - src2 = src_vector( p, &inst->SrcReg[2], program); - flags = get_result_flags( inst ); - tmp = i915_get_utemp( p ); - - /* b*a + c*(1-a) - * - * b*a + c - ca - * - * tmp = b*a + c, - * result = (-c)*a + tmp - */ - i915_emit_arith( p, A0_MAD, tmp, - flags & A0_DEST_CHANNEL_ALL, 0, - src1, src0, src2 ); - - i915_emit_arith( p, A0_MAD, - get_result_vector( p, inst ), - flags, 0, - negate(src2, 1,1,1,1), src0, tmp ); - break; - - case OPCODE_MAD: - EMIT_3ARG_ARITH( A0_MAD ); - break; - - case OPCODE_MAX: - EMIT_2ARG_ARITH( A0_MAX ); - break; - - case OPCODE_MIN: - src0 = src_vector( p, &inst->SrcReg[0], program); - src1 = src_vector( p, &inst->SrcReg[1], program); - tmp = i915_get_utemp( p ); - flags = get_result_flags( inst ); - - i915_emit_arith( p, - A0_MAX, - tmp, flags & A0_DEST_CHANNEL_ALL, 0, - negate(src0,1,1,1,1), - negate(src1,1,1,1,1), 0); - - i915_emit_arith( p, - A0_MOV, - get_result_vector( p, inst ), - flags, 0, - negate(tmp, 1,1,1,1), 0, 0); - break; - - case OPCODE_MOV: - EMIT_1ARG_ARITH( A0_MOV ); - break; - - case OPCODE_MUL: - EMIT_2ARG_ARITH( A0_MUL ); - break; - - case OPCODE_POW: - src0 = src_vector( p, &inst->SrcReg[0], program); - src1 = src_vector( p, &inst->SrcReg[1], program); - tmp = i915_get_utemp( p ); - flags = get_result_flags( inst ); - - /* XXX: masking on intermediate values, here and elsewhere. - */ - i915_emit_arith( p, - A0_LOG, - tmp, A0_DEST_CHANNEL_X, 0, - swizzle(src0,X,X,X,X), 0, 0); - - i915_emit_arith( p, - A0_MUL, - tmp, A0_DEST_CHANNEL_X, 0, - tmp, src1, 0); - - - i915_emit_arith( p, - A0_EXP, - get_result_vector( p, inst ), - flags, 0, - swizzle(tmp,X,X,X,X), 0, 0); - - break; - - case OPCODE_RCP: - src0 = src_vector( p, &inst->SrcReg[0], program); - - i915_emit_arith( p, - A0_RCP, - get_result_vector( p, inst ), - get_result_flags( inst ), 0, - swizzle(src0,X,X,X,X), 0, 0); - break; - - case OPCODE_RSQ: - - src0 = src_vector( p, &inst->SrcReg[0], program); - - i915_emit_arith( p, - A0_RSQ, - get_result_vector( p, inst ), - get_result_flags( inst ), 0, - swizzle(src0,X,X,X,X), 0, 0); - break; - - case OPCODE_SCS: - src0 = src_vector( p, &inst->SrcReg[0], program); - tmp = i915_get_utemp( p ); - - /* - * t0.xy = MUL x.xx11, x.x1111 ; x^2, x, 1, 1 - * t0 = MUL t0.xyxy t0.xx11 ; x^4, x^3, x^2, x - * t1 = MUL t0.xyyw t0.yz11 ; x^7 x^5 x^3 x - * scs.x = DP4 t1, sin_constants - * t1 = MUL t0.xxz1 t0.z111 ; x^6 x^4 x^2 1 - * scs.y = DP4 t1, cos_constants - */ - i915_emit_arith( p, - A0_MUL, - tmp, A0_DEST_CHANNEL_XY, 0, - swizzle(src0, X,X,ONE,ONE), - swizzle(src0, X,ONE,ONE,ONE), 0); - - i915_emit_arith( p, - A0_MUL, - tmp, A0_DEST_CHANNEL_ALL, 0, - swizzle(tmp, X,Y,X,Y), - swizzle(tmp, X,X,ONE,ONE), 0); - - if (inst->DstReg.WriteMask & WRITEMASK_Y) { - GLuint tmp1; - - if (inst->DstReg.WriteMask & WRITEMASK_X) - tmp1 = i915_get_utemp( p ); - else - tmp1 = tmp; - - i915_emit_arith( p, - A0_MUL, - tmp1, A0_DEST_CHANNEL_ALL, 0, - swizzle(tmp, X,Y,Y,W), - swizzle(tmp, X,Z,ONE,ONE), 0); - - i915_emit_arith( p, - A0_DP4, - get_result_vector( p, inst ), - A0_DEST_CHANNEL_Y, 0, - swizzle(tmp1, W,Z,Y,X), - i915_emit_const4fv( p, sin_constants ), 0); - } - - if (inst->DstReg.WriteMask & WRITEMASK_X) { - i915_emit_arith( p, - A0_MUL, - tmp, A0_DEST_CHANNEL_XYZ, 0, - swizzle(tmp, X,X,Z,ONE), - swizzle(tmp, Z,ONE,ONE,ONE), 0); - - i915_emit_arith( p, - A0_DP4, - get_result_vector( p, inst ), - A0_DEST_CHANNEL_X, 0, - swizzle(tmp, ONE,Z,Y,X), - i915_emit_const4fv( p, cos_constants ), 0); - } - break; - - case OPCODE_SGE: - EMIT_2ARG_ARITH( A0_SGE ); - break; - - case OPCODE_SIN: - src0 = src_vector( p, &inst->SrcReg[0], program); - tmp = i915_get_utemp( p ); - - i915_emit_arith( p, - A0_MUL, - tmp, A0_DEST_CHANNEL_X, 0, - src0, - i915_emit_const1f(p, 1.0/(M_PI * 2)), - 0); - - i915_emit_arith( p, - A0_MOD, - tmp, A0_DEST_CHANNEL_X, 0, - tmp, - 0, 0 ); - - /* By choosing different taylor constants, could get rid of this mul: - */ - i915_emit_arith( p, - A0_MUL, - tmp, A0_DEST_CHANNEL_X, 0, - tmp, - i915_emit_const1f(p, (M_PI * 2)), - 0); - - /* - * t0.xy = MUL x.xx11, x.x1111 ; x^2, x, 1, 1 - * t0 = MUL t0.xyxy t0.xx11 ; x^4, x^3, x^2, x - * t1 = MUL t0.xyyw t0.yz11 ; x^7 x^5 x^3 x - * result = DP4 t1.wzyx, sin_constants - */ - i915_emit_arith( p, - A0_MUL, - tmp, A0_DEST_CHANNEL_XY, 0, - swizzle(tmp, X,X,ONE,ONE), - swizzle(tmp, X,ONE,ONE,ONE), 0); - - i915_emit_arith( p, - A0_MUL, - tmp, A0_DEST_CHANNEL_ALL, 0, - swizzle(tmp, X,Y,X,Y), - swizzle(tmp, X,X,ONE,ONE), 0); - - i915_emit_arith( p, - A0_MUL, - tmp, A0_DEST_CHANNEL_ALL, 0, - swizzle(tmp, X,Y,Y,W), - swizzle(tmp, X,Z,ONE,ONE), 0); - - i915_emit_arith( p, - A0_DP4, - get_result_vector( p, inst ), - get_result_flags( inst ), 0, - swizzle(tmp, W, Z, Y, X ), - i915_emit_const4fv( p, sin_constants ), 0); - break; - - case OPCODE_SLT: - EMIT_2ARG_ARITH( A0_SLT ); - break; - - case OPCODE_SUB: - src0 = src_vector( p, &inst->SrcReg[0], program); - src1 = src_vector( p, &inst->SrcReg[1], program); - - i915_emit_arith( p, - A0_ADD, - get_result_vector( p, inst ), - get_result_flags( inst ), 0, - src0, negate(src1, 1,1,1,1), 0); - break; - - case OPCODE_SWZ: - EMIT_1ARG_ARITH( A0_MOV ); /* extended swizzle handled natively */ - break; - - case OPCODE_TEX: - EMIT_TEX( T0_TEXLD ); - break; - - case OPCODE_TXB: - EMIT_TEX( T0_TEXLDB ); - break; - - case OPCODE_TXP: - EMIT_TEX( T0_TEXLDP ); - break; - - case OPCODE_XPD: - /* Cross product: - * result.x = src0.y * src1.z - src0.z * src1.y; - * result.y = src0.z * src1.x - src0.x * src1.z; - * result.z = src0.x * src1.y - src0.y * src1.x; - * result.w = undef; - */ - src0 = src_vector( p, &inst->SrcReg[0], program); - src1 = src_vector( p, &inst->SrcReg[1], program); - tmp = i915_get_utemp( p ); - - i915_emit_arith( p, - A0_MUL, - tmp, A0_DEST_CHANNEL_ALL, 0, - swizzle(src0,Z,X,Y,ONE), - swizzle(src1,Y,Z,X,ONE), 0); - - i915_emit_arith( p, - A0_MAD, - get_result_vector( p, inst ), - get_result_flags( inst ), 0, - swizzle(src0,Y,Z,X,ONE), - swizzle(src1,Z,X,Y,ONE), - negate(tmp,1,1,1,0)); - break; - - case OPCODE_END: - return; - - default: - i915_program_error( p, "bad opcode" ); - return; - } - - inst++; - i915_release_utemps( p ); - } -} - -/* Rather than trying to intercept and jiggle depth writes during - * emit, just move the value into its correct position at the end of - * the program: - */ -static void fixup_depth_write( struct i915_fragment_program *p ) -{ - if (p->depth_written) { - GLuint depth = UREG(REG_TYPE_OD, 0); - - i915_emit_arith( p, - A0_MOV, - depth, A0_DEST_CHANNEL_W, 0, - swizzle(depth,X,Y,Z,Z), - 0, 0); - } -} - - -#define FRAG_BIT_TEX(n) (FRAG_BIT_TEX0 << (n)) - - -static void check_wpos( struct i915_fragment_program *p ) -{ - GLuint inputs = p->FragProg.Base.InputsRead; - GLint i; - - p->wpos_tex = -1; - - for (i = 0; i < p->ctx->Const.MaxTextureCoordUnits; i++) { - if (inputs & FRAG_BIT_TEX(i)) - continue; - else if (inputs & FRAG_BIT_WPOS) { - p->wpos_tex = i; - inputs &= ~FRAG_BIT_WPOS; - } - } - - if (inputs & FRAG_BIT_WPOS) { - i915_program_error(p, "No free texcoord for wpos value"); - } -} - - -static void translate_program( struct i915_fragment_program *p ) -{ - struct i915_context *i915 = I915_CONTEXT(p->ctx); - - i915_init_program( i915, p ); - check_wpos( p ); - upload_program( p ); - fixup_depth_write( p ); - i915_fini_program( p ); - - p->translated = 1; -} - - -static void track_params( struct i915_fragment_program *p ) -{ - GLint i; - - if (p->nr_params) - _mesa_load_state_parameters(p->ctx, p->FragProg.Base.Parameters); - - for (i = 0; i < p->nr_params; i++) { - GLint reg = p->param[i].reg; - COPY_4V( p->constant[reg], p->param[i].values ); - } - - p->params_uptodate = 1; - p->on_hardware = 0; /* overkill */ -} - - -static void i915BindProgram( GLcontext *ctx, - GLenum target, - struct program *prog ) -{ - if (target == GL_FRAGMENT_PROGRAM_ARB) { - struct i915_context *i915 = I915_CONTEXT(ctx); - struct i915_fragment_program *p = (struct i915_fragment_program *)prog; - - if (i915->current_program == p) - return; - - if (i915->current_program) { - i915->current_program->on_hardware = 0; - i915->current_program->params_uptodate = 0; - } - - i915->current_program = p; - - assert(p->on_hardware == 0); - assert(p->params_uptodate == 0); - - /* Hack: make sure fog is correctly enabled according to this - * fragment program's fog options. - */ - ctx->Driver.Enable( ctx, GL_FRAGMENT_PROGRAM_ARB, - ctx->FragmentProgram.Enabled ); - } -} - -static struct program *i915NewProgram( GLcontext *ctx, - GLenum target, - GLuint id ) -{ - switch (target) { - case GL_VERTEX_PROGRAM_ARB: - return _mesa_init_vertex_program( ctx, CALLOC_STRUCT(vertex_program), - target, id ); - - case GL_FRAGMENT_PROGRAM_ARB: { - struct i915_fragment_program *prog = CALLOC_STRUCT(i915_fragment_program); - if (prog) { - i915_init_program( I915_CONTEXT(ctx), prog ); - - return _mesa_init_fragment_program( ctx, &prog->FragProg, - target, id ); - } - else - return NULL; - } - - default: - /* Just fallback: - */ - return _mesa_new_program( ctx, target, id ); - } -} - -static void i915DeleteProgram( GLcontext *ctx, - struct program *prog ) -{ - if (prog->Target == GL_FRAGMENT_PROGRAM_ARB) { - struct i915_context *i915 = I915_CONTEXT(ctx); - struct i915_fragment_program *p = (struct i915_fragment_program *)prog; - - if (i915->current_program == p) - i915->current_program = 0; - } - - _mesa_delete_program( ctx, prog ); -} - - -static GLboolean i915IsProgramNative( GLcontext *ctx, - GLenum target, - struct program *prog ) -{ - if (target == GL_FRAGMENT_PROGRAM_ARB) { - struct i915_fragment_program *p = (struct i915_fragment_program *)prog; - - if (!p->translated) - translate_program( p ); - - return !p->error; - } - else - return GL_TRUE; -} - -static void i915ProgramStringNotify( GLcontext *ctx, - GLenum target, - struct program *prog ) -{ - if (target == GL_FRAGMENT_PROGRAM_ARB) { - struct i915_fragment_program *p = (struct i915_fragment_program *)prog; - p->translated = 0; - - /* Hack: make sure fog is correctly enabled according to this - * fragment program's fog options. - */ - ctx->Driver.Enable( ctx, GL_FRAGMENT_PROGRAM_ARB, - ctx->FragmentProgram.Enabled ); - } -} - - -void i915ValidateFragmentProgram( struct i915_context *i915 ) -{ - GLcontext *ctx = &i915->intel.ctx; - struct intel_context *intel = intel_context(ctx); - TNLcontext *tnl = TNL_CONTEXT(ctx); - struct vertex_buffer *VB = &tnl->vb; - - struct i915_fragment_program *p = - (struct i915_fragment_program *)ctx->FragmentProgram._Current; - - const GLuint inputsRead = p->FragProg.Base.InputsRead; - GLuint s4 = i915->state.Ctx[I915_CTXREG_LIS4] & ~S4_VFMT_MASK; - GLuint s2 = S2_TEXCOORD_NONE; - int i, offset = 0; - - /* Important: - */ - VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr; - - if (!p->translated) - translate_program( p ); - - intel->vertex_attr_count = 0; - intel->wpos_offset = 0; - intel->wpos_size = 0; - intel->coloroffset = 0; - intel->specoffset = 0; - - if (inputsRead & FRAG_BITS_TEX_ANY) { - EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, S4_VFMT_XYZW, 16 ); - } - else { - EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_3F_VIEWPORT, S4_VFMT_XYZ, 12 ); - } - - if (inputsRead & FRAG_BIT_COL0) { - intel->coloroffset = offset / 4; - EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA, S4_VFMT_COLOR, 4 ); - } - - if ((inputsRead & (FRAG_BIT_COL1|FRAG_BIT_FOGC)) || - i915->vertex_fog != I915_FOG_NONE) { - - if (inputsRead & FRAG_BIT_COL1) { - intel->specoffset = offset / 4; - EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, S4_VFMT_SPEC_FOG, 3 ); - } - else - EMIT_PAD(3); - - if ((inputsRead & FRAG_BIT_FOGC) || i915->vertex_fog != I915_FOG_NONE) - EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, S4_VFMT_SPEC_FOG, 1 ); - else - EMIT_PAD( 1 ); - } - -#if 0 - if ((inputsRead & FRAG_BIT_FOGC) || i915->vertex_fog != I915_FOG_NONE) { - EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1F, S4_VFMT_FOG_PARAM, 4 ); - } -#endif - - for (i = 0; i < p->ctx->Const.MaxTextureCoordUnits; i++) { - if (inputsRead & FRAG_BIT_TEX(i)) { - int sz = VB->TexCoordPtr[i]->size; - - s2 &= ~S2_TEXCOORD_FMT(i, S2_TEXCOORD_FMT0_MASK); - s2 |= S2_TEXCOORD_FMT(i, SZ_TO_HW(sz)); - - EMIT_ATTR( _TNL_ATTRIB_TEX0+i, EMIT_SZ(sz), 0, sz * 4 ); - } - else if (i == p->wpos_tex) { - - /* If WPOS is required, duplicate the XYZ position data in an - * unused texture coordinate: - */ - s2 &= ~S2_TEXCOORD_FMT(i, S2_TEXCOORD_FMT0_MASK); - s2 |= S2_TEXCOORD_FMT(i, SZ_TO_HW(3)); - - intel->wpos_offset = offset; - intel->wpos_size = 3 * sizeof(GLuint); - - EMIT_PAD( intel->wpos_size ); - } - } - - if (s2 != i915->state.Ctx[I915_CTXREG_LIS2] || - s4 != i915->state.Ctx[I915_CTXREG_LIS4]) { - int k; - - I915_STATECHANGE( i915, I915_UPLOAD_CTX ); - - /* Must do this *after* statechange, so as not to affect - * buffered vertices reliant on the old state: - */ - intel->vertex_size = _tnl_install_attrs( &intel->ctx, - intel->vertex_attrs, - intel->vertex_attr_count, - intel->ViewportMatrix.m, 0 ); - - intel->vertex_size >>= 2; - - i915->state.Ctx[I915_CTXREG_LIS2] = s2; - i915->state.Ctx[I915_CTXREG_LIS4] = s4; - - k = intel->vtbl.check_vertex_size( intel, intel->vertex_size ); - assert(k); - } - - if (!p->params_uptodate) - track_params( p ); - - if (!p->on_hardware) - i915_upload_program( i915, p ); -} - -void i915InitFragProgFuncs( struct dd_function_table *functions ) -{ - functions->BindProgram = i915BindProgram; - functions->NewProgram = i915NewProgram; - functions->DeleteProgram = i915DeleteProgram; - functions->IsProgramNative = i915IsProgramNative; - functions->ProgramStringNotify = i915ProgramStringNotify; -} diff --git a/src/mesa/drivers/dri/i915-tex/i915_metaops.c b/src/mesa/drivers/dri/i915-tex/i915_metaops.c deleted file mode 100644 index 21f9199d10b..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i915_metaops.c +++ /dev/null @@ -1,889 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "glheader.h" -#include "enums.h" -#include "mtypes.h" -#include "macros.h" -#include "utils.h" - -#include "intel_screen.h" -#include "intel_batchbuffer.h" -#include "intel_ioctl.h" -<<<<<<< i915_metaops.c -#include "intel_rotate.h" -======= -#include "intel_regions.h" ->>>>>>> 1.5.2.9 - -#include "i915_context.h" -#include "i915_reg.h" - -/* We touch almost everything: - */ -#define ACTIVE (I915_UPLOAD_INVARIENT | \ - I915_UPLOAD_CTX | \ - I915_UPLOAD_BUFFERS | \ - I915_UPLOAD_STIPPLE | \ - I915_UPLOAD_PROGRAM | \ - I915_UPLOAD_FOG | \ - I915_UPLOAD_TEX(0)) - -#define SET_STATE( i915, STATE ) \ -do { \ - i915->current->emitted &= ~ACTIVE; \ - i915->current = &i915->STATE; \ - i915->current->emitted &= ~ACTIVE; \ -} while (0) - - -static void meta_no_stencil_write( struct intel_context *intel ) -{ - struct i915_context *i915 = i915_context(&intel->ctx); - - /* ctx->Driver.Enable( ctx, GL_STENCIL_TEST, GL_FALSE ) - */ - i915->meta.Ctx[I915_CTXREG_LIS5] &= ~(S5_STENCIL_TEST_ENABLE | - S5_STENCIL_WRITE_ENABLE); - - i915->meta.emitted &= ~I915_UPLOAD_CTX; -} - -static void meta_no_depth_write( struct intel_context *intel ) -{ - struct i915_context *i915 = i915_context(&intel->ctx); - - /* ctx->Driver.Enable( ctx, GL_DEPTH_TEST, GL_FALSE ) - */ - i915->meta.Ctx[I915_CTXREG_LIS6] &= ~(S6_DEPTH_TEST_ENABLE | - S6_DEPTH_WRITE_ENABLE); - - i915->meta.emitted &= ~I915_UPLOAD_CTX; -} - -static void meta_depth_replace( struct intel_context *intel ) -{ - struct i915_context *i915 = i915_context(&intel->ctx); - - /* ctx->Driver.Enable( ctx, GL_DEPTH_TEST, GL_TRUE ) - * ctx->Driver.DepthMask( ctx, GL_TRUE ) - */ - i915->meta.Ctx[I915_CTXREG_LIS6] |= (S6_DEPTH_TEST_ENABLE | - S6_DEPTH_WRITE_ENABLE); - - /* ctx->Driver.DepthFunc( ctx, GL_REPLACE ) - */ - i915->meta.Ctx[I915_CTXREG_LIS6] &= ~S6_DEPTH_TEST_FUNC_MASK; - i915->meta.Ctx[I915_CTXREG_LIS6] |= - COMPAREFUNC_ALWAYS << S6_DEPTH_TEST_FUNC_SHIFT; - - i915->meta.emitted &= ~I915_UPLOAD_CTX; -} - - -/* Set stencil unit to replace always with the reference value. - */ -static void meta_stencil_replace( struct intel_context *intel, - GLuint s_mask, - GLuint s_clear) -{ - struct i915_context *i915 = i915_context(&intel->ctx); - GLuint op = STENCILOP_REPLACE; - GLuint func = COMPAREFUNC_ALWAYS; - - /* ctx->Driver.Enable( ctx, GL_STENCIL_TEST, GL_TRUE ) - */ - i915->meta.Ctx[I915_CTXREG_LIS5] |= (S5_STENCIL_TEST_ENABLE | - S5_STENCIL_WRITE_ENABLE); - - /* ctx->Driver.StencilMask( ctx, s_mask ) - */ - i915->meta.Ctx[I915_CTXREG_STATE4] &= ~MODE4_ENABLE_STENCIL_WRITE_MASK; - - i915->meta.Ctx[I915_CTXREG_STATE4] |= (ENABLE_STENCIL_WRITE_MASK | - STENCIL_WRITE_MASK(s_mask)); - - /* ctx->Driver.StencilOp( ctx, GL_REPLACE, GL_REPLACE, GL_REPLACE ) - */ - i915->meta.Ctx[I915_CTXREG_LIS5] &= ~(S5_STENCIL_FAIL_MASK | - S5_STENCIL_PASS_Z_FAIL_MASK | - S5_STENCIL_PASS_Z_PASS_MASK); - - i915->meta.Ctx[I915_CTXREG_LIS5] |= ((op << S5_STENCIL_FAIL_SHIFT) | - (op << S5_STENCIL_PASS_Z_FAIL_SHIFT) | - (op << S5_STENCIL_PASS_Z_PASS_SHIFT)); - - - /* ctx->Driver.StencilFunc( ctx, GL_ALWAYS, s_ref, ~0 ) - */ - i915->meta.Ctx[I915_CTXREG_STATE4] &= ~MODE4_ENABLE_STENCIL_TEST_MASK; - i915->meta.Ctx[I915_CTXREG_STATE4] |= (ENABLE_STENCIL_TEST_MASK | - STENCIL_TEST_MASK(0xff)); - - i915->meta.Ctx[I915_CTXREG_LIS5] &= ~(S5_STENCIL_REF_MASK | - S5_STENCIL_TEST_FUNC_MASK); - - i915->meta.Ctx[I915_CTXREG_LIS5] |= ((s_clear << S5_STENCIL_REF_SHIFT) | - (func << S5_STENCIL_TEST_FUNC_SHIFT)); - - - i915->meta.emitted &= ~I915_UPLOAD_CTX; -} - - -static void meta_color_mask( struct intel_context *intel, GLboolean state ) -{ - struct i915_context *i915 = i915_context(&intel->ctx); - const GLuint mask = (S5_WRITEDISABLE_RED | - S5_WRITEDISABLE_GREEN | - S5_WRITEDISABLE_BLUE | - S5_WRITEDISABLE_ALPHA); - - /* Copy colormask state from "regular" hw context. - */ - if (state) { - i915->meta.Ctx[I915_CTXREG_LIS5] &= ~mask; - i915->meta.Ctx[I915_CTXREG_LIS5] |= - (i915->state.Ctx[I915_CTXREG_LIS5] & mask); - } - else - i915->meta.Ctx[I915_CTXREG_LIS5] |= mask; - - i915->meta.emitted &= ~I915_UPLOAD_CTX; -} - - - -static void meta_import_pixel_state( struct intel_context *intel ) -{ - struct i915_context *i915 = i915_context(&intel->ctx); - memcpy(i915->meta.Fog, i915->state.Fog, I915_FOG_SETUP_SIZE * 4); - - i915->meta.Ctx[I915_CTXREG_LIS5] = i915->state.Ctx[I915_CTXREG_LIS5]; - i915->meta.Ctx[I915_CTXREG_LIS6] = i915->state.Ctx[I915_CTXREG_LIS6]; - i915->meta.Ctx[I915_CTXREG_STATE4] = i915->state.Ctx[I915_CTXREG_STATE4]; - i915->meta.Ctx[I915_CTXREG_BLENDCOLOR1] = i915->state.Ctx[I915_CTXREG_BLENDCOLOR1]; - i915->meta.Ctx[I915_CTXREG_IAB] = i915->state.Ctx[I915_CTXREG_IAB]; - - i915->meta.Buffer[I915_DESTREG_SENABLE] = i915->state.Buffer[I915_DESTREG_SENABLE]; - i915->meta.Buffer[I915_DESTREG_SR1] = i915->state.Buffer[I915_DESTREG_SR1]; - i915->meta.Buffer[I915_DESTREG_SR2] = i915->state.Buffer[I915_DESTREG_SR2]; - - i915->meta.emitted &= ~I915_UPLOAD_FOG; - i915->meta.emitted &= ~I915_UPLOAD_BUFFERS; - i915->meta.emitted &= ~I915_UPLOAD_CTX; -} - - - - -#define REG( type, nr ) (((type)<<5)|(nr)) - -#define REG_R(x) REG(REG_TYPE_R, x) -#define REG_T(x) REG(REG_TYPE_T, x) -#define REG_CONST(x) REG(REG_TYPE_CONST, x) -#define REG_S(x) REG(REG_TYPE_S, x) -#define REG_OC REG(REG_TYPE_OC, 0) -#define REG_OD REG(REG_TYPE_OD, 0) -#define REG_U(x) REG(REG_TYPE_U, x) - -#define REG_T_DIFFUSE REG(REG_TYPE_T, T_DIFFUSE) -#define REG_T_SPECULAR REG(REG_TYPE_T, T_SPECULAR) -#define REG_T_FOG_W REG(REG_TYPE_T, T_FOG_W) -#define REG_T_TEX(x) REG(REG_TYPE_T, x) - - -#define A0_DEST_REG( reg ) ( (reg) << A0_DEST_NR_SHIFT ) -#define A0_SRC0_REG( reg ) ( (reg) << A0_SRC0_NR_SHIFT ) -#define A1_SRC1_REG( reg ) ( (reg) << A1_SRC1_NR_SHIFT ) -#define A1_SRC2_REG( reg ) ( (reg) << A1_SRC2_NR_SHIFT ) -#define A2_SRC2_REG( reg ) ( (reg) << A2_SRC2_NR_SHIFT ) -#define D0_DECL_REG( reg ) ( (reg) << D0_NR_SHIFT ) -#define T0_DEST_REG( reg ) ( (reg) << T0_DEST_NR_SHIFT ) - -#define T0_SAMPLER( unit ) ((unit)<<T0_SAMPLER_NR_SHIFT) - -#define T1_ADDRESS_REG( type, nr ) (((type)<<T1_ADDRESS_REG_TYPE_SHIFT)| \ - ((nr)<<T1_ADDRESS_REG_NR_SHIFT)) - - -#define A1_SRC0_XYZW ((SRC_X << A1_SRC0_CHANNEL_X_SHIFT) | \ - (SRC_Y << A1_SRC0_CHANNEL_Y_SHIFT) | \ - (SRC_Z << A1_SRC0_CHANNEL_Z_SHIFT) | \ - (SRC_W << A1_SRC0_CHANNEL_W_SHIFT)) - -#define A1_SRC1_XY ((SRC_X << A1_SRC1_CHANNEL_X_SHIFT) | \ - (SRC_Y << A1_SRC1_CHANNEL_Y_SHIFT)) - -#define A2_SRC1_ZW ((SRC_Z << A2_SRC1_CHANNEL_Z_SHIFT) | \ - (SRC_W << A2_SRC1_CHANNEL_W_SHIFT)) - -#define A2_SRC2_XYZW ((SRC_X << A2_SRC2_CHANNEL_X_SHIFT) | \ - (SRC_Y << A2_SRC2_CHANNEL_Y_SHIFT) | \ - (SRC_Z << A2_SRC2_CHANNEL_Z_SHIFT) | \ - (SRC_W << A2_SRC2_CHANNEL_W_SHIFT)) - - - - - -static void meta_no_texture( struct intel_context *intel ) -{ - struct i915_context *i915 = i915_context(&intel->ctx); - - static const GLuint prog[] = { - _3DSTATE_PIXEL_SHADER_PROGRAM, - - /* Declare incoming diffuse color: - */ - (D0_DCL | - D0_DECL_REG( REG_T_DIFFUSE ) | - D0_CHANNEL_ALL), - D1_MBZ, - D2_MBZ, - - /* output-color = mov(t_diffuse) - */ - (A0_MOV | - A0_DEST_REG( REG_OC ) | - A0_DEST_CHANNEL_ALL | - A0_SRC0_REG( REG_T_DIFFUSE )), - (A1_SRC0_XYZW), - 0, - }; - - - memcpy( i915->meta.Program, prog, sizeof(prog) ); - i915->meta.ProgramSize = sizeof(prog) / sizeof(*prog); - i915->meta.Program[0] |= i915->meta.ProgramSize - 2; - i915->meta.emitted &= ~I915_UPLOAD_PROGRAM; -} - -<<<<<<< i915_metaops.c - -static void enable_texture_blend_replace( i915ContextPtr i915 ) -======= -static void meta_texture_blend_replace( struct intel_context *intel ) ->>>>>>> 1.5.2.9 -{ - struct i915_context *i915 = i915_context(&intel->ctx); - - static const GLuint prog[] = { - _3DSTATE_PIXEL_SHADER_PROGRAM, - - /* Declare the sampler: - */ - (D0_DCL | - D0_DECL_REG( REG_S(0) ) | - D0_SAMPLE_TYPE_2D | - D0_CHANNEL_NONE), - D1_MBZ, - D2_MBZ, - - /* Declare the interpolated texture coordinate: - */ - (D0_DCL | - D0_DECL_REG( REG_T_TEX(0) ) | - D0_CHANNEL_ALL), - D1_MBZ, - D2_MBZ, - - /* output-color = texld(sample0, texcoord0) - */ - (T0_TEXLD | - T0_DEST_REG( REG_OC ) | - T0_SAMPLER( 0 )), - T1_ADDRESS_REG(REG_TYPE_T, 0), - T2_MBZ - }; - - memcpy( i915->meta.Program, prog, sizeof(prog) ); - i915->meta.ProgramSize = sizeof(prog) / sizeof(*prog); - i915->meta.Program[0] |= i915->meta.ProgramSize - 2; - i915->meta.emitted &= ~I915_UPLOAD_PROGRAM; -} - - - - - -/* Set up an arbitary piece of memory as a rectangular texture - * (including the front or back buffer). - */ -<<<<<<< i915_metaops.c -static void set_tex_rect_source( i915ContextPtr i915, - GLuint offset, - GLuint width, - GLuint height, - GLuint pitch, /* in bytes! */ - GLuint textureFormat ) -======= -static GLboolean meta_tex_rect_source( struct intel_context *intel, - GLuint buffer, - GLuint offset, - GLuint pitch, - GLuint height, - GLenum format, - GLenum type) ->>>>>>> 1.5.2.9 -{ - struct i915_context *i915 = i915_context(&intel->ctx); - GLuint unit = 0; - GLint numLevels = 1; - GLuint *state = i915->meta.Tex[0]; - GLuint textureFormat; - GLuint cpp; - -<<<<<<< i915_metaops.c -#if 0 - printf("TexRect source offset 0x%x pitch %d\n", offset, pitch); -#endif -======= - /* A full implementation of this would do the upload through - * glTexImage2d, and get all the conversion operations at that - * point. We are restricted, but still at least have access to the - * fragment program swizzle. - */ - switch (format) { - case GL_BGRA: - switch (type) { - case GL_UNSIGNED_INT_8_8_8_8_REV: - case GL_UNSIGNED_BYTE: - textureFormat = (MAPSURF_32BIT | MT_32BIT_ARGB8888); - cpp = 4; - break; - default: - return GL_FALSE; - } - break; - case GL_RGBA: - switch (type) { - case GL_UNSIGNED_INT_8_8_8_8_REV: - case GL_UNSIGNED_BYTE: - textureFormat = (MAPSURF_32BIT | MT_32BIT_ABGR8888); - cpp = 4; - break; - default: - return GL_FALSE; - } - break; - case GL_BGR: - switch (type) { - case GL_UNSIGNED_SHORT_5_6_5_REV: - textureFormat = (MAPSURF_16BIT | MT_16BIT_RGB565); - cpp = 2; - break; - default: - return GL_FALSE; - } - break; - case GL_RGB: - switch (type) { - case GL_UNSIGNED_SHORT_5_6_5: - textureFormat = (MAPSURF_16BIT | MT_16BIT_RGB565); - cpp = 2; - break; - default: - return GL_FALSE; - } - break; - - default: - return GL_FALSE; - } - - - if ((pitch * cpp) & 3) { - _mesa_printf("%s: texture is not dword pitch\n", __FUNCTION__); - return GL_FALSE; - } ->>>>>>> 1.5.2.9 - -/* intel_region_release(intel, &i915->meta.tex_region[0]); */ -/* intel_region_reference(&i915->meta.tex_region[0], region); */ - i915->meta.tex_buffer[0] = buffer; - i915->meta.tex_offset[0] = offset; - - state[I915_TEXREG_MS3] = (((height - 1) << MS3_HEIGHT_SHIFT) | -<<<<<<< i915_metaops.c - ((width - 1) << MS3_WIDTH_SHIFT) | - textureFormat | - MS3_USE_FENCE_REGS); - - state[I915_TEXREG_MS4] = ((((pitch / 4) - 1) << MS4_PITCH_SHIFT) | - ((((numLevels-1) * 4)) << MS4_MAX_LOD_SHIFT)); -======= - ((pitch - 1) << MS3_WIDTH_SHIFT) | - textureFormat | - MS3_USE_FENCE_REGS); - - state[I915_TEXREG_MS4] = (((((pitch * cpp) / 4) - 1) << MS4_PITCH_SHIFT) | - MS4_CUBE_FACE_ENA_MASK | - ((((numLevels-1) * 4)) << MS4_MAX_LOD_SHIFT)); ->>>>>>> 1.5.2.9 - - state[I915_TEXREG_SS2] = ((FILTER_NEAREST << SS2_MIN_FILTER_SHIFT) | - (MIPFILTER_NONE << SS2_MIP_FILTER_SHIFT) | - (FILTER_NEAREST << SS2_MAG_FILTER_SHIFT)); - - state[I915_TEXREG_SS3] = ((TEXCOORDMODE_WRAP << SS3_TCX_ADDR_MODE_SHIFT) | - (TEXCOORDMODE_WRAP << SS3_TCY_ADDR_MODE_SHIFT) | - (TEXCOORDMODE_WRAP << SS3_TCZ_ADDR_MODE_SHIFT) | - (unit<<SS3_TEXTUREMAP_INDEX_SHIFT)); - - state[I915_TEXREG_SS4] = 0; - - i915->meta.emitted &= ~I915_UPLOAD_TEX(0); - return GL_TRUE; -} -<<<<<<< i915_metaops.c - -======= ->>>>>>> 1.5.2.9 - - -/** - * Set the color and depth drawing region for meta ops. - */ -<<<<<<< i915_metaops.c -static void set_draw_region( i915ContextPtr i915, const intelRegion *region ) -======= -static void meta_draw_region( struct intel_context *intel, - struct intel_region *color_region, - struct intel_region *depth_region ) ->>>>>>> 1.5.2.9 -{ -<<<<<<< i915_metaops.c -#if 0 - printf("Rotate into region: offset 0x%x pitch %d\n", - region->offset, region->pitch); -#endif - i915->meta.Buffer[I915_DESTREG_CBUFADDR1] = - (BUF_3D_ID_COLOR_BACK | BUF_3D_PITCH(region->pitch) | BUF_3D_USE_FENCE); - i915->meta.Buffer[I915_DESTREG_CBUFADDR2] = region->offset; - i915->meta.emitted &= ~I915_UPLOAD_BUFFERS; -======= - struct i915_context *i915 = i915_context(&intel->ctx); - i915_state_draw_region(intel, &i915->meta, color_region, depth_region); ->>>>>>> 1.5.2.9 -} - -<<<<<<< i915_metaops.c - -#if 0 -/* Setup an arbitary draw format, useful for targeting texture or agp - * memory. - */ -static void set_draw_format( i915ContextPtr i915, - GLuint format, - GLuint depth_format) -{ - i915->meta.Buffer[I915_DESTREG_DV1] = (DSTORG_HORT_BIAS(0x8) | /* .5 */ - DSTORG_VERT_BIAS(0x8) | /* .5 */ - format | - LOD_PRECLAMP_OGL | - TEX_DEFAULT_COLOR_OGL | - depth_format); -======= ->>>>>>> 1.5.2.9 - -static void set_vertex_format( struct intel_context *intel ) -{ - struct i915_context *i915 = i915_context(&intel->ctx); - - i915->meta.Ctx[I915_CTXREG_LIS2] = - (S2_TEXCOORD_FMT(0, TEXCOORDFMT_2D) | - S2_TEXCOORD_FMT(1, TEXCOORDFMT_NOT_PRESENT) | - S2_TEXCOORD_FMT(2, TEXCOORDFMT_NOT_PRESENT) | - S2_TEXCOORD_FMT(3, TEXCOORDFMT_NOT_PRESENT) | - S2_TEXCOORD_FMT(4, TEXCOORDFMT_NOT_PRESENT) | - S2_TEXCOORD_FMT(5, TEXCOORDFMT_NOT_PRESENT) | - S2_TEXCOORD_FMT(6, TEXCOORDFMT_NOT_PRESENT) | - S2_TEXCOORD_FMT(7, TEXCOORDFMT_NOT_PRESENT)); - - i915->meta.Ctx[I915_CTXREG_LIS4] &= ~S4_VFMT_MASK; - - i915->meta.Ctx[I915_CTXREG_LIS4] |= - (S4_VFMT_COLOR | - S4_VFMT_XYZ); - - i915->meta.emitted &= ~I915_UPLOAD_CTX; -} - - -<<<<<<< i915_metaops.c -static void draw_quad(i915ContextPtr i915, - GLfloat x0, GLfloat x1, - GLfloat y0, GLfloat y1, - GLubyte red, GLubyte green, - GLubyte blue, GLubyte alpha, - GLfloat s0, GLfloat s1, - GLfloat t0, GLfloat t1 ) -{ - GLuint vertex_size = 8; - GLuint *vb = intelEmitInlinePrimitiveLocked( &i915->intel, - PRIM3D_TRIFAN, - 4 * vertex_size, - vertex_size ); - intelVertex tmp; - int i; - - if (0) - fprintf(stderr, "%s: %f,%f-%f,%f 0x%x%x%x%x %f,%f-%f,%f\n", - __FUNCTION__, - x0,y0,x1,y1,red,green,blue,alpha,s0,t0,s1,t1); - - - /* initial vertex, left bottom */ - tmp.v.x = x0; - tmp.v.y = y0; - tmp.v.z = 1.0; - tmp.v.w = 1.0; - tmp.v.color.red = red; - tmp.v.color.green = green; - tmp.v.color.blue = blue; - tmp.v.color.alpha = alpha; - tmp.v.specular.red = 0; - tmp.v.specular.green = 0; - tmp.v.specular.blue = 0; - tmp.v.specular.alpha = 0; - tmp.v.u0 = s0; - tmp.v.v0 = t0; - - for (i = 0 ; i < vertex_size ; i++) - vb[i] = tmp.ui[i]; - - /* right bottom */ - vb += vertex_size; - tmp.v.x = x1; - tmp.v.u0 = s1; - for (i = 0 ; i < vertex_size ; i++) - vb[i] = tmp.ui[i]; - - /* right top */ - vb += vertex_size; - tmp.v.y = y1; - tmp.v.v0 = t1; - for (i = 0 ; i < vertex_size ; i++) - vb[i] = tmp.ui[i]; - - /* left top */ - vb += vertex_size; - tmp.v.x = x0; - tmp.v.u0 = s0; - for (i = 0 ; i < vertex_size ; i++) - vb[i] = tmp.ui[i]; -} - - -static void draw_poly(i915ContextPtr i915, - GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha, - GLuint numVerts, - /*const*/ GLfloat verts[][2], - /*const*/ GLfloat texcoords[][2]) -{ - GLuint vertex_size = 8; - GLuint *vb = intelEmitInlinePrimitiveLocked( &i915->intel, - PRIM3D_TRIFAN, - numVerts * vertex_size, - vertex_size ); - intelVertex tmp; - int i, k; - - /* initial constant vertex fields */ - tmp.v.z = 1.0; - tmp.v.w = 1.0; - tmp.v.color.red = red; - tmp.v.color.green = green; - tmp.v.color.blue = blue; - tmp.v.color.alpha = alpha; - tmp.v.specular.red = 0; - tmp.v.specular.green = 0; - tmp.v.specular.blue = 0; - tmp.v.specular.alpha = 0; - - for (k = 0; k < numVerts; k++) { - tmp.v.x = verts[k][0]; - tmp.v.y = verts[k][1]; - tmp.v.u0 = texcoords[k][0]; - tmp.v.v0 = texcoords[k][1]; - - for (i = 0 ; i < vertex_size ; i++) - vb[i] = tmp.ui[i]; - - vb += vertex_size; - } -} - - -void -i915ClearWithTris(intelContextPtr intel, GLbitfield mask, - GLboolean all, - GLint cx, GLint cy, GLint cw, GLint ch) -{ - i915ContextPtr i915 = I915_CONTEXT( intel ); - __DRIdrawablePrivate *dPriv = intel->driDrawable; - intelScreenPrivate *screen = intel->intelScreen; - int x0, y0, x1, y1; - - SET_STATE( i915, meta ); - set_initial_state( i915 ); - set_no_texture( i915 ); - set_vertex_format( i915 ); - - LOCK_HARDWARE(intel); - - if (!all) { - x0 = cx; - y0 = cy; - x1 = x0 + cw; - y1 = y0 + ch; - } else { - x0 = 0; - y0 = 0; - x1 = x0 + dPriv->w; - y1 = y0 + dPriv->h; - } -======= ->>>>>>> 1.5.2.9 - -/* Operations where the 3D engine is decoupled temporarily from the - * current GL state and used for other purposes than simply rendering - * incoming triangles. - */ -static void install_meta_state( struct intel_context *intel ) -{ - struct i915_context *i915 = i915_context(&intel->ctx); - memcpy(&i915->meta, &i915->initial, sizeof(i915->meta) ); - i915->meta.active = ACTIVE; - i915->meta.emitted = 0; - -<<<<<<< i915_metaops.c - if (mask & BUFFER_BIT_FRONT_LEFT) { - set_no_depth_stencil_write( i915 ); - set_color_mask( i915, GL_TRUE ); - set_draw_region( i915, &screen->front ); - - draw_quad(i915, x0, x1, y0, y1, - intel->clear_red, intel->clear_green, - intel->clear_blue, intel->clear_alpha, - 0, 0, 0, 0); - } -======= - SET_STATE(i915, meta); - set_vertex_format(intel); - meta_no_texture(intel); -} ->>>>>>> 1.5.2.9 - -<<<<<<< i915_metaops.c - if (mask & BUFFER_BIT_BACK_LEFT) { - set_no_depth_stencil_write( i915 ); - set_color_mask( i915, GL_TRUE ); - set_draw_region( i915, &screen->back ); - - draw_quad(i915, x0, x1, y0, y1, - intel->clear_red, intel->clear_green, - intel->clear_blue, intel->clear_alpha, - 0, 0, 0, 0); - } - - if (mask & BUFFER_BIT_STENCIL) { - set_stencil_replace( i915, - intel->ctx.Stencil.WriteMask[0], - intel->ctx.Stencil.Clear); - - set_color_mask( i915, GL_FALSE ); - set_draw_region( i915, &screen->front ); /* could be either? */ -======= -static void leave_meta_state( struct intel_context *intel ) -{ - struct i915_context *i915 = i915_context(&intel->ctx); - intel_region_release(intel, &i915->meta.draw_region); - intel_region_release(intel, &i915->meta.depth_region); -/* intel_region_release(intel, &i915->meta.tex_region[0]); */ - SET_STATE(i915, state); -} ->>>>>>> 1.5.2.9 - - - -void i915InitMetaFuncs( struct i915_context *i915 ) -{ - i915->intel.vtbl.install_meta_state = install_meta_state; - i915->intel.vtbl.leave_meta_state = leave_meta_state; - i915->intel.vtbl.meta_no_depth_write = meta_no_depth_write; - i915->intel.vtbl.meta_no_stencil_write = meta_no_stencil_write; - i915->intel.vtbl.meta_stencil_replace = meta_stencil_replace; - i915->intel.vtbl.meta_depth_replace = meta_depth_replace; - i915->intel.vtbl.meta_color_mask = meta_color_mask; - i915->intel.vtbl.meta_no_texture = meta_no_texture; - i915->intel.vtbl.meta_texture_blend_replace = meta_texture_blend_replace; - i915->intel.vtbl.meta_tex_rect_source = meta_tex_rect_source; - i915->intel.vtbl.meta_draw_region = meta_draw_region; - i915->intel.vtbl.meta_import_pixel_state = meta_import_pixel_state; -} -<<<<<<< i915_metaops.c - - -/** - * Copy the window contents named by dPriv to the rotated (or reflected) - * color buffer. - * srcBuf is BUFFER_BIT_FRONT_LEFT or BUFFER_BIT_BACK_LEFT to indicate the source. - */ -void -i915RotateWindow(intelContextPtr intel, __DRIdrawablePrivate *dPriv, - GLuint srcBuf) -{ - i915ContextPtr i915 = I915_CONTEXT( intel ); - intelScreenPrivate *screen = intel->intelScreen; - const GLuint cpp = screen->cpp; - drm_clip_rect_t fullRect; - GLuint textureFormat, srcOffset, srcPitch; - const drm_clip_rect_t *clipRects; - int numClipRects; - int i; - - int xOrig, yOrig; - int origNumClipRects; - drm_clip_rect_t *origRects; - - /* - * set up hardware state - */ - intelFlush( &intel->ctx ); - - SET_STATE( i915, meta ); - set_initial_state( i915 ); - set_no_texture( i915 ); - set_vertex_format( i915 ); - set_no_depth_stencil_write( i915 ); - set_color_mask( i915, GL_TRUE ); - - LOCK_HARDWARE(intel); - - /* save current drawing origin and cliprects (restored at end) */ - xOrig = intel->drawX; - yOrig = intel->drawY; - origNumClipRects = intel->numClipRects; - origRects = intel->pClipRects; - - if (!intel->numClipRects) - goto done; - - /* - * set drawing origin, cliprects for full-screen access to rotated screen - */ - fullRect.x1 = 0; - fullRect.y1 = 0; - fullRect.x2 = screen->rotatedWidth; - fullRect.y2 = screen->rotatedHeight; - intel->drawX = 0; - intel->drawY = 0; - intel->numClipRects = 1; - intel->pClipRects = &fullRect; - - set_draw_region( i915, &screen->rotated ); - - if (cpp == 4) - textureFormat = MAPSURF_32BIT | MT_32BIT_ARGB8888; - else - textureFormat = MAPSURF_16BIT | MT_16BIT_RGB565; - - if (srcBuf == BUFFER_BIT_FRONT_LEFT) { - srcPitch = screen->front.pitch; /* in bytes */ - srcOffset = screen->front.offset; /* bytes */ - clipRects = dPriv->pClipRects; - numClipRects = dPriv->numClipRects; - } - else { - srcPitch = screen->back.pitch; /* in bytes */ - srcOffset = screen->back.offset; /* bytes */ - clipRects = dPriv->pBackClipRects; - numClipRects = dPriv->numBackClipRects; - } - - /* set the whole screen up as a texture to avoid alignment issues */ - set_tex_rect_source(i915, - srcOffset, - screen->width, - screen->height, - srcPitch, - textureFormat); - - enable_texture_blend_replace(i915); - - /* - * loop over the source window's cliprects - */ - for (i = 0; i < numClipRects; i++) { - int srcX0 = clipRects[i].x1; - int srcY0 = clipRects[i].y1; - int srcX1 = clipRects[i].x2; - int srcY1 = clipRects[i].y2; - GLfloat verts[4][2], tex[4][2]; - int j; - - /* build vertices for four corners of clip rect */ - verts[0][0] = srcX0; verts[0][1] = srcY0; - verts[1][0] = srcX1; verts[1][1] = srcY0; - verts[2][0] = srcX1; verts[2][1] = srcY1; - verts[3][0] = srcX0; verts[3][1] = srcY1; - - /* .. and texcoords */ - tex[0][0] = srcX0; tex[0][1] = srcY0; - tex[1][0] = srcX1; tex[1][1] = srcY0; - tex[2][0] = srcX1; tex[2][1] = srcY1; - tex[3][0] = srcX0; tex[3][1] = srcY1; - - /* transform coords to rotated screen coords */ - for (j = 0; j < 4; j++) { - matrix23TransformCoordf(&screen->rotMatrix, - &verts[j][0], &verts[j][1]); - } - - /* draw polygon to map source image to dest region */ - draw_poly(i915, 255, 255, 255, 255, 4, verts, tex); - - } /* cliprect loop */ - - intelFlushBatchLocked( intel, GL_FALSE, GL_FALSE, GL_FALSE ); - - done: - /* restore original drawing origin and cliprects */ - intel->drawX = xOrig; - intel->drawY = yOrig; - intel->numClipRects = origNumClipRects; - intel->pClipRects = origRects; - - UNLOCK_HARDWARE(intel); - - SET_STATE( i915, state ); -} - -======= ->>>>>>> 1.5.2.9 diff --git a/src/mesa/drivers/dri/i915-tex/i915_program.c b/src/mesa/drivers/dri/i915-tex/i915_program.c deleted file mode 100644 index 07ac8f09bb3..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i915_program.c +++ /dev/null @@ -1,486 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include <strings.h> - -#include "glheader.h" -#include "macros.h" -#include "enums.h" - -#include "tnl/t_context.h" -#include "intel_batchbuffer.h" - -#include "i915_reg.h" -#include "i915_context.h" -#include "i915_program.h" - - -#define A0_DEST( reg ) (((reg)&UREG_TYPE_NR_MASK)>>UREG_A0_DEST_SHIFT_LEFT) -#define D0_DEST( reg ) (((reg)&UREG_TYPE_NR_MASK)>>UREG_A0_DEST_SHIFT_LEFT) -#define T0_DEST( reg ) (((reg)&UREG_TYPE_NR_MASK)>>UREG_A0_DEST_SHIFT_LEFT) -#define A0_SRC0( reg ) (((reg)&UREG_MASK)>>UREG_A0_SRC0_SHIFT_LEFT) -#define A1_SRC0( reg ) (((reg)&UREG_MASK)<<UREG_A1_SRC0_SHIFT_RIGHT) -#define A1_SRC1( reg ) (((reg)&UREG_MASK)>>UREG_A1_SRC1_SHIFT_LEFT) -#define A2_SRC1( reg ) (((reg)&UREG_MASK)<<UREG_A2_SRC1_SHIFT_RIGHT) -#define A2_SRC2( reg ) (((reg)&UREG_MASK)>>UREG_A2_SRC2_SHIFT_LEFT) - -/* These are special, and don't have swizzle/negate bits. - */ -#define T0_SAMPLER( reg ) (GET_UREG_NR(reg)<<T0_SAMPLER_NR_SHIFT) -#define T1_ADDRESS_REG( reg ) ((GET_UREG_NR(reg)<<T1_ADDRESS_REG_NR_SHIFT) | \ - (GET_UREG_TYPE(reg)<<T1_ADDRESS_REG_TYPE_SHIFT)) - - -/* Macros for translating UREG's into the various register fields used - * by the I915 programmable unit. - */ -#define UREG_A0_DEST_SHIFT_LEFT (UREG_TYPE_SHIFT - A0_DEST_TYPE_SHIFT) -#define UREG_A0_SRC0_SHIFT_LEFT (UREG_TYPE_SHIFT - A0_SRC0_TYPE_SHIFT) -#define UREG_A1_SRC0_SHIFT_RIGHT (A1_SRC0_CHANNEL_W_SHIFT - UREG_CHANNEL_W_SHIFT) -#define UREG_A1_SRC1_SHIFT_LEFT (UREG_TYPE_SHIFT - A1_SRC1_TYPE_SHIFT) -#define UREG_A2_SRC1_SHIFT_RIGHT (A2_SRC1_CHANNEL_W_SHIFT - UREG_CHANNEL_W_SHIFT) -#define UREG_A2_SRC2_SHIFT_LEFT (UREG_TYPE_SHIFT - A2_SRC2_TYPE_SHIFT) - -#define UREG_MASK 0xffffff00 -#define UREG_TYPE_NR_MASK ((REG_TYPE_MASK << UREG_TYPE_SHIFT) | \ - (REG_NR_MASK << UREG_NR_SHIFT)) - - -#define I915_CONSTFLAG_PARAM 0x1f - -GLuint i915_get_temp( struct i915_fragment_program *p ) -{ - int bit = ffs( ~p->temp_flag ); - if (!bit) { - fprintf(stderr, "%s: out of temporaries\n", __FILE__); - exit(1); - } - - p->temp_flag |= 1<<(bit-1); - return UREG(REG_TYPE_R, (bit-1)); -} - - -GLuint i915_get_utemp( struct i915_fragment_program *p ) -{ - int bit = ffs( ~p->utemp_flag ); - if (!bit) { - fprintf(stderr, "%s: out of temporaries\n", __FILE__); - exit(1); - } - - p->utemp_flag |= 1<<(bit-1); - return UREG(REG_TYPE_U, (bit-1)); -} - -void i915_release_utemps( struct i915_fragment_program *p ) -{ - p->utemp_flag = ~0x7; -} - - -GLuint i915_emit_decl( struct i915_fragment_program *p, - GLuint type, GLuint nr, GLuint d0_flags ) -{ - GLuint reg = UREG(type, nr); - - if (type == REG_TYPE_T) { - if (p->decl_t & (1<<nr)) - return reg; - - p->decl_t |= (1<<nr); - } - else if (type == REG_TYPE_S) { - if (p->decl_s & (1<<nr)) - return reg; - - p->decl_s |= (1<<nr); - } - else - return reg; - - *(p->decl++) = (D0_DCL | D0_DEST( reg ) | d0_flags); - *(p->decl++) = D1_MBZ; - *(p->decl++) = D2_MBZ; - - p->nr_decl_insn++; - return reg; -} - -GLuint i915_emit_arith( struct i915_fragment_program *p, - GLuint op, - GLuint dest, - GLuint mask, - GLuint saturate, - GLuint src0, - GLuint src1, - GLuint src2 ) -{ - GLuint c[3]; - GLuint nr_const = 0; - - assert(GET_UREG_TYPE(dest) != REG_TYPE_CONST); - dest = UREG(GET_UREG_TYPE(dest), GET_UREG_NR(dest)); - assert(dest); - - if (GET_UREG_TYPE(src0) == REG_TYPE_CONST) c[nr_const++] = 0; - if (GET_UREG_TYPE(src1) == REG_TYPE_CONST) c[nr_const++] = 1; - if (GET_UREG_TYPE(src2) == REG_TYPE_CONST) c[nr_const++] = 2; - - /* Recursively call this function to MOV additional const values - * into temporary registers. Use utemp registers for this - - * currently shouldn't be possible to run out, but keep an eye on - * this. - */ - if (nr_const > 1) { - GLuint s[3], first, i, old_utemp_flag; - - s[0] = src0; - s[1] = src1; - s[2] = src2; - old_utemp_flag = p->utemp_flag; - - first = GET_UREG_NR(s[c[0]]); - for (i = 1 ; i < nr_const ; i++) { - if (GET_UREG_NR(s[c[i]]) != first) { - GLuint tmp = i915_get_utemp(p); - - i915_emit_arith( p, A0_MOV, tmp, A0_DEST_CHANNEL_ALL, 0, - s[c[i]], 0, 0 ); - s[c[i]] = tmp; - } - } - - src0 = s[0]; - src1 = s[1]; - src2 = s[2]; - p->utemp_flag = old_utemp_flag; /* restore */ - } - - *(p->csr++) = (op | - A0_DEST( dest ) | - mask | - saturate | - A0_SRC0( src0 )); - *(p->csr++) = (A1_SRC0( src0 ) | - A1_SRC1( src1 )); - *(p->csr++) = (A2_SRC1( src1 ) | - A2_SRC2( src2 )); - - p->nr_alu_insn++; - return dest; -} - -GLuint i915_emit_texld( struct i915_fragment_program *p, - GLuint dest, - GLuint destmask, - GLuint sampler, - GLuint coord, - GLuint op ) -{ - assert(GET_UREG_TYPE(dest) != REG_TYPE_CONST); - dest = UREG(GET_UREG_TYPE(dest), GET_UREG_NR(dest)); - assert(dest); - - if (GET_UREG_TYPE(coord) != REG_TYPE_T) { - p->nr_tex_indirect++; - } - - *(p->csr++) = (op | - T0_DEST( dest ) | - destmask | - T0_SAMPLER( sampler )); - - *(p->csr++) = T1_ADDRESS_REG( coord ); - *(p->csr++) = T2_MBZ; - - p->nr_tex_insn++; - return dest; -} - - -GLuint i915_emit_const1f( struct i915_fragment_program *p, GLfloat c0 ) -{ - GLint reg, idx; - - if (c0 == 0.0) return swizzle(UREG(REG_TYPE_R, 0), ZERO, ZERO, ZERO, ZERO); - if (c0 == 1.0) return swizzle(UREG(REG_TYPE_R, 0), ONE, ONE, ONE, ONE ); - - for (reg = 0; reg < I915_MAX_CONSTANT; reg++) { - if (p->constant_flags[reg] == I915_CONSTFLAG_PARAM) - continue; - for (idx = 0; idx < 4; idx++) { - if (!(p->constant_flags[reg] & (1<<idx)) || - p->constant[reg][idx] == c0) { - p->constant[reg][idx] = c0; - p->constant_flags[reg] |= 1<<idx; - if (reg+1 > p->nr_constants) p->nr_constants = reg+1; - return swizzle(UREG(REG_TYPE_CONST, reg),idx,ZERO,ZERO,ONE); - } - } - } - - fprintf(stderr, "%s: out of constants\n", __FUNCTION__); - p->error = 1; - return 0; -} - -GLuint i915_emit_const2f( struct i915_fragment_program *p, - GLfloat c0, GLfloat c1 ) -{ - GLint reg, idx; - - if (c0 == 0.0) return swizzle(i915_emit_const1f(p, c1), ZERO, X, Z, W); - if (c0 == 1.0) return swizzle(i915_emit_const1f(p, c1), ONE, X, Z, W); - - if (c1 == 0.0) return swizzle(i915_emit_const1f(p, c0), X, ZERO, Z, W); - if (c1 == 1.0) return swizzle(i915_emit_const1f(p, c0), X, ONE, Z, W); - - for (reg = 0; reg < I915_MAX_CONSTANT; reg++) { - if (p->constant_flags[reg] == 0xf || - p->constant_flags[reg] == I915_CONSTFLAG_PARAM) - continue; - for (idx = 0; idx < 3; idx++) { - if (!(p->constant_flags[reg] & (3<<idx))) { - p->constant[reg][idx] = c0; - p->constant[reg][idx+1] = c1; - p->constant_flags[reg] |= 3<<idx; - if (reg+1 > p->nr_constants) p->nr_constants = reg+1; - return swizzle(UREG(REG_TYPE_CONST, reg),idx,idx+1,ZERO,ONE); - } - } - } - - fprintf(stderr, "%s: out of constants\n", __FUNCTION__); - p->error = 1; - return 0; -} - - - -GLuint i915_emit_const4f( struct i915_fragment_program *p, - GLfloat c0, GLfloat c1, GLfloat c2, GLfloat c3 ) -{ - GLint reg; - - for (reg = 0; reg < I915_MAX_CONSTANT; reg++) { - if (p->constant_flags[reg] == 0xf && - p->constant[reg][0] == c0 && - p->constant[reg][1] == c1 && - p->constant[reg][2] == c2 && - p->constant[reg][3] == c3) { - return UREG(REG_TYPE_CONST, reg); - } - else if (p->constant_flags[reg] == 0) { - p->constant[reg][0] = c0; - p->constant[reg][1] = c1; - p->constant[reg][2] = c2; - p->constant[reg][3] = c3; - p->constant_flags[reg] = 0xf; - if (reg+1 > p->nr_constants) p->nr_constants = reg+1; - return UREG(REG_TYPE_CONST, reg); - } - } - - fprintf(stderr, "%s: out of constants\n", __FUNCTION__); - p->error = 1; - return 0; -} - - -GLuint i915_emit_const4fv( struct i915_fragment_program *p, const GLfloat *c ) -{ - return i915_emit_const4f( p, c[0], c[1], c[2], c[3] ); -} - - -GLuint i915_emit_param4fv( struct i915_fragment_program *p, - const GLfloat *values ) -{ - GLint reg, i; - - for (i = 0; i < p->nr_params; i++) { - if (p->param[i].values == values) - return UREG(REG_TYPE_CONST, p->param[i].reg); - } - - - for (reg = 0; reg < I915_MAX_CONSTANT; reg++) { - if (p->constant_flags[reg] == 0) { - p->constant_flags[reg] = I915_CONSTFLAG_PARAM; - i = p->nr_params++; - - p->param[i].values = values; - p->param[i].reg = reg; - p->params_uptodate = 0; - - if (reg+1 > p->nr_constants) p->nr_constants = reg+1; - return UREG(REG_TYPE_CONST, reg); - } - } - - fprintf(stderr, "%s: out of constants\n", __FUNCTION__); - p->error = 1; - return 0; -} - - - - -void i915_program_error( struct i915_fragment_program *p, const char *msg ) -{ - /* XXX we shouldn't print anything to stdout, record GL error or - * call _mesa_problem() - */ - fprintf(stderr, "%s\n", msg); - p->error = 1; -} - -void i915_init_program( struct i915_context *i915, struct i915_fragment_program *p ) -{ - GLcontext *ctx = &i915->intel.ctx; - TNLcontext *tnl = TNL_CONTEXT( ctx ); - - p->translated = 0; - p->params_uptodate = 0; - p->on_hardware = 0; - p->error = 0; - - p->nr_tex_indirect = 1; /* correct? */ - p->nr_tex_insn = 0; - p->nr_alu_insn = 0; - p->nr_decl_insn = 0; - - p->ctx = ctx; - memset( p->constant_flags, 0, sizeof(p->constant_flags) ); - - p->nr_constants = 0; - p->csr = p->program; - p->decl = p->declarations; - p->decl_s = 0; - p->decl_t = 0; - p->temp_flag = 0xffff000; - p->utemp_flag = ~0x7; - p->wpos_tex = -1; - p->depth_written = 0; - p->nr_params = 0; - - p->src_texture = UREG_BAD; - p->src_previous = UREG(REG_TYPE_T, T_DIFFUSE); - p->last_tex_stage = 0; - p->VB = &tnl->vb; - - *(p->decl++) = _3DSTATE_PIXEL_SHADER_PROGRAM; -} - - -void i915_fini_program( struct i915_fragment_program *p ) -{ - GLuint program_size = p->csr - p->program; - GLuint decl_size = p->decl - p->declarations; - - if (p->nr_tex_indirect > I915_MAX_TEX_INDIRECT) - i915_program_error(p, "Exceeded max nr indirect texture lookups"); - - if (p->nr_tex_insn > I915_MAX_TEX_INSN) - i915_program_error(p, "Exceeded max TEX instructions"); - - if (p->nr_alu_insn > I915_MAX_ALU_INSN) - i915_program_error(p, "Exceeded max ALU instructions"); - - if (p->nr_decl_insn > I915_MAX_DECL_INSN) - i915_program_error(p, "Exceeded max DECL instructions"); - - if (p->error) { - p->FragProg.Base.NumNativeInstructions = 0; - p->FragProg.NumNativeAluInstructions = 0; - p->FragProg.NumNativeTexInstructions = 0; - p->FragProg.NumNativeTexIndirections = 0; - } - else { - p->FragProg.Base.NumNativeInstructions = (p->nr_alu_insn + - p->nr_tex_insn + - p->nr_decl_insn); - p->FragProg.NumNativeAluInstructions = p->nr_alu_insn; - p->FragProg.NumNativeTexInstructions = p->nr_tex_insn; - p->FragProg.NumNativeTexIndirections = p->nr_tex_indirect; - } - - p->declarations[0] |= program_size + decl_size - 2; -} - -void i915_upload_program( struct i915_context *i915, struct i915_fragment_program *p ) -{ - GLuint program_size = p->csr - p->program; - GLuint decl_size = p->decl - p->declarations; - - FALLBACK( &i915->intel, I915_FALLBACK_PROGRAM, p->error ); - - /* Could just go straight to the batchbuffer from here: - */ - if (i915->state.ProgramSize != (program_size + decl_size) || - memcmp(i915->state.Program + decl_size, p->program, - program_size*sizeof(int)) != 0) { - I915_STATECHANGE( i915, I915_UPLOAD_PROGRAM ); - memcpy(i915->state.Program, p->declarations, decl_size*sizeof(int)); - memcpy(i915->state.Program + decl_size, p->program, - program_size*sizeof(int)); - i915->state.ProgramSize = decl_size + program_size; - } - - /* Always seemed to get a failure if I used memcmp() to - * shortcircuit this state upload. Needs further investigation? - */ - if (p->nr_constants) { - GLuint nr = p->nr_constants; - - I915_ACTIVESTATE( i915, I915_UPLOAD_CONSTANTS, 1 ); - I915_STATECHANGE( i915, I915_UPLOAD_CONSTANTS ); - - i915->state.Constant[0] = _3DSTATE_PIXEL_SHADER_CONSTANTS | ((nr) * 4); - i915->state.Constant[1] = (1<<(nr-1)) | ((1<<(nr-1))-1); - - memcpy(&i915->state.Constant[2], p->constant, 4*sizeof(int)*(nr)); - i915->state.ConstantSize = 2 + (nr) * 4; - - if (0) { - GLuint i; - for (i = 0; i < nr; i++) { - fprintf(stderr, "const[%d]: %f %f %f %f\n", i, - p->constant[i][0], - p->constant[i][1], - p->constant[i][2], - p->constant[i][3]); - } - } - } - else { - I915_ACTIVESTATE( i915, I915_UPLOAD_CONSTANTS, 0 ); - } - - p->on_hardware = 1; -} diff --git a/src/mesa/drivers/dri/i915-tex/i915_program.h b/src/mesa/drivers/dri/i915-tex/i915_program.h deleted file mode 100644 index a0d2530ed52..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i915_program.h +++ /dev/null @@ -1,163 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - - -#ifndef I915_PROGRAM_H -#define I915_PROGRAM_H - -#include "i915_context.h" -#include "i915_reg.h" - - - -/* Having zero and one in here makes the definition of swizzle a lot - * easier. - */ -#define UREG_TYPE_SHIFT 29 -#define UREG_NR_SHIFT 24 -#define UREG_CHANNEL_X_NEGATE_SHIFT 23 -#define UREG_CHANNEL_X_SHIFT 20 -#define UREG_CHANNEL_Y_NEGATE_SHIFT 19 -#define UREG_CHANNEL_Y_SHIFT 16 -#define UREG_CHANNEL_Z_NEGATE_SHIFT 15 -#define UREG_CHANNEL_Z_SHIFT 12 -#define UREG_CHANNEL_W_NEGATE_SHIFT 11 -#define UREG_CHANNEL_W_SHIFT 8 -#define UREG_CHANNEL_ZERO_NEGATE_MBZ 5 -#define UREG_CHANNEL_ZERO_SHIFT 4 -#define UREG_CHANNEL_ONE_NEGATE_MBZ 1 -#define UREG_CHANNEL_ONE_SHIFT 0 - -#define UREG_BAD 0xffffffff /* not a valid ureg */ - -#define X SRC_X -#define Y SRC_Y -#define Z SRC_Z -#define W SRC_W -#define ZERO SRC_ZERO -#define ONE SRC_ONE - -/* Construct a ureg: - */ -#define UREG( type, nr ) (((type)<< UREG_TYPE_SHIFT) | \ - ((nr) << UREG_NR_SHIFT) | \ - (X << UREG_CHANNEL_X_SHIFT) | \ - (Y << UREG_CHANNEL_Y_SHIFT) | \ - (Z << UREG_CHANNEL_Z_SHIFT) | \ - (W << UREG_CHANNEL_W_SHIFT) | \ - (ZERO << UREG_CHANNEL_ZERO_SHIFT) | \ - (ONE << UREG_CHANNEL_ONE_SHIFT)) - -#define GET_CHANNEL_SRC( reg, channel ) ((reg<<(channel*4)) & (0xf<<20)) -#define CHANNEL_SRC( src, channel ) (src>>(channel*4)) - -#define GET_UREG_TYPE(reg) (((reg)>>UREG_TYPE_SHIFT)®_TYPE_MASK) -#define GET_UREG_NR(reg) (((reg)>>UREG_NR_SHIFT)®_NR_MASK) - - - -#define UREG_XYZW_CHANNEL_MASK 0x00ffff00 - -/* One neat thing about the UREG representation: - */ -static INLINE int swizzle( int reg, int x, int y, int z, int w ) -{ - return ((reg & ~UREG_XYZW_CHANNEL_MASK) | - CHANNEL_SRC( GET_CHANNEL_SRC( reg, x ), 0 ) | - CHANNEL_SRC( GET_CHANNEL_SRC( reg, y ), 1 ) | - CHANNEL_SRC( GET_CHANNEL_SRC( reg, z ), 2 ) | - CHANNEL_SRC( GET_CHANNEL_SRC( reg, w ), 3 )); -} - -/* Another neat thing about the UREG representation: - */ -static INLINE int negate( int reg, int x, int y, int z, int w ) -{ - return reg ^ (((x&1)<<UREG_CHANNEL_X_NEGATE_SHIFT)| - ((y&1)<<UREG_CHANNEL_Y_NEGATE_SHIFT)| - ((z&1)<<UREG_CHANNEL_Z_NEGATE_SHIFT)| - ((w&1)<<UREG_CHANNEL_W_NEGATE_SHIFT)); -} - - -extern GLuint i915_get_temp( struct i915_fragment_program *p ); -extern GLuint i915_get_utemp( struct i915_fragment_program *p ); -extern void i915_release_utemps( struct i915_fragment_program *p ); - - -extern GLuint i915_emit_texld( struct i915_fragment_program *p, - GLuint dest, - GLuint destmask, - GLuint sampler, - GLuint coord, - GLuint op ); - -extern GLuint i915_emit_arith( struct i915_fragment_program *p, - GLuint op, - GLuint dest, - GLuint mask, - GLuint saturate, - GLuint src0, - GLuint src1, - GLuint src2 ); - -extern GLuint i915_emit_decl( struct i915_fragment_program *p, - GLuint type, GLuint nr, GLuint d0_flags ); - - -extern GLuint i915_emit_const1f( struct i915_fragment_program *p, - GLfloat c0 ); - -extern GLuint i915_emit_const2f( struct i915_fragment_program *p, - GLfloat c0, GLfloat c1 ); - -extern GLuint i915_emit_const4fv( struct i915_fragment_program *p, - const GLfloat *c ); - -extern GLuint i915_emit_const4f( struct i915_fragment_program *p, - GLfloat c0, GLfloat c1, - GLfloat c2, GLfloat c3 ); - - -extern GLuint i915_emit_param4fv( struct i915_fragment_program *p, - const GLfloat *values ); - -extern void i915_program_error( struct i915_fragment_program *p, - const char *msg ); - -extern void i915_init_program( struct i915_context *i915, - struct i915_fragment_program *p ); - -extern void i915_upload_program( struct i915_context *i915, - struct i915_fragment_program *p ); - -extern void i915_fini_program( struct i915_fragment_program *p ); - - - - -#endif diff --git a/src/mesa/drivers/dri/i915-tex/i915_reg.h b/src/mesa/drivers/dri/i915-tex/i915_reg.h deleted file mode 100644 index f81b1264b7f..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i915_reg.h +++ /dev/null @@ -1,839 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - - -#ifndef _I915_REG_H_ -#define _I915_REG_H_ - - -#include "intel_reg.h" - -#define I915_SET_FIELD( var, mask, value ) (var &= ~(mask), var |= value) - -#define CMD_3D (0x3<<29) - -#define PRIM3D_INLINE (CMD_3D | (0x1f<<24)) -#define PRIM3D_TRILIST (0x0<<18) -#define PRIM3D_TRISTRIP (0x1<<18) -#define PRIM3D_TRISTRIP_RVRSE (0x2<<18) -#define PRIM3D_TRIFAN (0x3<<18) -#define PRIM3D_POLY (0x4<<18) -#define PRIM3D_LINELIST (0x5<<18) -#define PRIM3D_LINESTRIP (0x6<<18) -#define PRIM3D_RECTLIST (0x7<<18) -#define PRIM3D_POINTLIST (0x8<<18) -#define PRIM3D_DIB (0x9<<18) -#define PRIM3D_CLEAR_RECT (0xa<<18) -#define PRIM3D_ZONE_INIT (0xd<<18) -#define PRIM3D_MASK (0x1f<<18) - -/* p137 */ -#define _3DSTATE_AA_CMD (CMD_3D | (0x06<<24)) -#define AA_LINE_ECAAR_WIDTH_ENABLE (1<<16) -#define AA_LINE_ECAAR_WIDTH_0_5 0 -#define AA_LINE_ECAAR_WIDTH_1_0 (1<<14) -#define AA_LINE_ECAAR_WIDTH_2_0 (2<<14) -#define AA_LINE_ECAAR_WIDTH_4_0 (3<<14) -#define AA_LINE_REGION_WIDTH_ENABLE (1<<8) -#define AA_LINE_REGION_WIDTH_0_5 0 -#define AA_LINE_REGION_WIDTH_1_0 (1<<6) -#define AA_LINE_REGION_WIDTH_2_0 (2<<6) -#define AA_LINE_REGION_WIDTH_4_0 (3<<6) - -/* 3DSTATE_BACKFACE_STENCIL_OPS, p138*/ -#define _3DSTATE_BACKFACE_STENCIL_OPS (CMD_3D | (0x8<<24)) -#define BFO_ENABLE_STENCIL_REF (1<<23) -#define BFO_STENCIL_REF_SHIFT 15 -#define BFO_STENCIL_REF_MASK (0xff<<15) -#define BFO_ENABLE_STENCIL_FUNCS (1<<14) -#define BFO_STENCIL_TEST_SHIFT 11 -#define BFO_STENCIL_TEST_MASK (0x7<<11) -#define BFO_STENCIL_FAIL_SHIFT 8 -#define BFO_STENCIL_FAIL_MASK (0x7<<8) -#define BFO_STENCIL_PASS_Z_FAIL_SHIFT 5 -#define BFO_STENCIL_PASS_Z_FAIL_MASK (0x7<<5) -#define BFO_STENCIL_PASS_Z_PASS_SHIFT 2 -#define BFO_STENCIL_PASS_Z_PASS_MASK (0x7<<2) -#define BFO_ENABLE_STENCIL_TWO_SIDE (1<<1) -#define BFO_STENCIL_TWO_SIDE (1<<0) - - -/* 3DSTATE_BACKFACE_STENCIL_MASKS, p140 */ -#define _3DSTATE_BACKFACE_STENCIL_MASKS (CMD_3D | (0x9<<24)) -#define BFM_ENABLE_STENCIL_TEST_MASK (1<<17) -#define BFM_ENABLE_STENCIL_WRITE_MASK (1<<16) -#define BFM_STENCIL_TEST_MASK_SHIFT 8 -#define BFM_STENCIL_TEST_MASK_MASK (0xff<<8) -#define BFM_STENCIL_WRITE_MASK_SHIFT 0 -#define BFM_STENCIL_WRITE_MASK_MASK (0xff<<0) - - - -/* 3DSTATE_BIN_CONTROL p141 */ - -/* p143 */ -#define _3DSTATE_BUF_INFO_CMD (CMD_3D | (0x1d<<24) | (0x8e<<16) | 1) -/* Dword 1 */ -#define BUF_3D_ID_COLOR_BACK (0x3<<24) -#define BUF_3D_ID_DEPTH (0x7<<24) -#define BUF_3D_USE_FENCE (1<<23) -#define BUF_3D_TILED_SURFACE (1<<22) -#define BUF_3D_TILE_WALK_X 0 -#define BUF_3D_TILE_WALK_Y (1<<21) -#define BUF_3D_PITCH(x) (((x)/4)<<2) -/* Dword 2 */ -#define BUF_3D_ADDR(x) ((x) & ~0x3) - - -/* 3DSTATE_CHROMA_KEY */ - -/* 3DSTATE_CLEAR_PARAMETERS, p150 */ - -/* 3DSTATE_CONSTANT_BLEND_COLOR, p153 */ -#define _3DSTATE_CONST_BLEND_COLOR_CMD (CMD_3D | (0x1d<<24) | (0x88<<16)) - - - -/* 3DSTATE_COORD_SET_BINDINGS, p154 */ -#define _3DSTATE_COORD_SET_BINDINGS (CMD_3D | (0x16<<24)) -#define CSB_TCB(iunit, eunit) ((eunit)<<(iunit*3)) - -/* p156 */ -#define _3DSTATE_DFLT_DIFFUSE_CMD (CMD_3D | (0x1d<<24) | (0x99<<16)) - -/* p157 */ -#define _3DSTATE_DFLT_SPEC_CMD (CMD_3D | (0x1d<<24) | (0x9a<<16)) - -/* p158 */ -#define _3DSTATE_DFLT_Z_CMD (CMD_3D | (0x1d<<24) | (0x98<<16)) - - -/* 3DSTATE_DEPTH_OFFSET_SCALE, p159 */ -#define _3DSTATE_DEPTH_OFFSET_SCALE (CMD_3D | (0x1d<<24) | (0x97<<16)) -/* scale in dword 1 */ - - -/* 3DSTATE_DEPTH_SUBRECT_DISABLE, p160 */ -#define _3DSTATE_DEPTH_SUBRECT_DISABLE (CMD_3D | (0x1c<<24) | (0x11<19) | 0x2) - -/* p161 */ -#define _3DSTATE_DST_BUF_VARS_CMD (CMD_3D | (0x1d<<24) | (0x85<<16)) -/* Dword 1 */ -#define TEX_DEFAULT_COLOR_OGL (0<<30) -#define TEX_DEFAULT_COLOR_D3D (1<<30) -#define ZR_EARLY_DEPTH (1<<29) -#define LOD_PRECLAMP_OGL (1<<28) -#define LOD_PRECLAMP_D3D (0<<28) -#define DITHER_FULL_ALWAYS (0<<26) -#define DITHER_FULL_ON_FB_BLEND (1<<26) -#define DITHER_CLAMPED_ALWAYS (2<<26) -#define LINEAR_GAMMA_BLEND_32BPP (1<<25) -#define DEBUG_DISABLE_ENH_DITHER (1<<24) -#define DSTORG_HORT_BIAS(x) ((x)<<20) -#define DSTORG_VERT_BIAS(x) ((x)<<16) -#define COLOR_4_2_2_CHNL_WRT_ALL 0 -#define COLOR_4_2_2_CHNL_WRT_Y (1<<12) -#define COLOR_4_2_2_CHNL_WRT_CR (2<<12) -#define COLOR_4_2_2_CHNL_WRT_CB (3<<12) -#define COLOR_4_2_2_CHNL_WRT_CRCB (4<<12) -#define COLR_BUF_8BIT 0 -#define COLR_BUF_RGB555 (1<<8) -#define COLR_BUF_RGB565 (2<<8) -#define COLR_BUF_ARGB8888 (3<<8) -#define DEPTH_FRMT_16_FIXED 0 -#define DEPTH_FRMT_16_FLOAT (1<<2) -#define DEPTH_FRMT_24_FIXED_8_OTHER (2<<2) -#define VERT_LINE_STRIDE_1 (1<<1) -#define VERT_LINE_STRIDE_0 (0<<1) -#define VERT_LINE_STRIDE_OFS_1 1 -#define VERT_LINE_STRIDE_OFS_0 0 - -/* p166 */ -#define _3DSTATE_DRAW_RECT_CMD (CMD_3D|(0x1d<<24)|(0x80<<16)|3) -/* Dword 1 */ -#define DRAW_RECT_DIS_DEPTH_OFS (1<<30) -#define DRAW_DITHER_OFS_X(x) ((x)<<26) -#define DRAW_DITHER_OFS_Y(x) ((x)<<24) -/* Dword 2 */ -#define DRAW_YMIN(x) ((x)<<16) -#define DRAW_XMIN(x) (x) -/* Dword 3 */ -#define DRAW_YMAX(x) ((x)<<16) -#define DRAW_XMAX(x) (x) -/* Dword 4 */ -#define DRAW_YORG(x) ((x)<<16) -#define DRAW_XORG(x) (x) - - -/* 3DSTATE_FILTER_COEFFICIENTS_4X4, p170 */ - -/* 3DSTATE_FILTER_COEFFICIENTS_6X5, p172 */ - - -/* _3DSTATE_FOG_COLOR, p173 */ -#define _3DSTATE_FOG_COLOR_CMD (CMD_3D|(0x15<<24)) -#define FOG_COLOR_RED(x) ((x)<<16) -#define FOG_COLOR_GREEN(x) ((x)<<8) -#define FOG_COLOR_BLUE(x) (x) - -/* _3DSTATE_FOG_MODE, p174 */ -#define _3DSTATE_FOG_MODE_CMD (CMD_3D|(0x1d<<24)|(0x89<<16)|2) -/* Dword 1 */ -#define FMC1_FOGFUNC_MODIFY_ENABLE (1<<31) -#define FMC1_FOGFUNC_VERTEX (0<<28) -#define FMC1_FOGFUNC_PIXEL_EXP (1<<28) -#define FMC1_FOGFUNC_PIXEL_EXP2 (2<<28) -#define FMC1_FOGFUNC_PIXEL_LINEAR (3<<28) -#define FMC1_FOGFUNC_MASK (3<<28) -#define FMC1_FOGINDEX_MODIFY_ENABLE (1<<27) -#define FMC1_FOGINDEX_Z (0<<25) -#define FMC1_FOGINDEX_W (1<<25) -#define FMC1_C1_C2_MODIFY_ENABLE (1<<24) -#define FMC1_DENSITY_MODIFY_ENABLE (1<<23) -#define FMC1_C1_ONE (1<<13) -#define FMC1_C1_MASK (0xffff<<4) -/* Dword 2 */ -#define FMC2_C2_ONE (1<<16) -/* Dword 3 */ -#define FMC3_D_ONE (1<<16) - - - -/* _3DSTATE_INDEPENDENT_ALPHA_BLEND, p177 */ -#define _3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD (CMD_3D|(0x0b<<24)) -#define IAB_MODIFY_ENABLE (1<<23) -#define IAB_ENABLE (1<<22) -#define IAB_MODIFY_FUNC (1<<21) -#define IAB_FUNC_SHIFT 16 -#define IAB_MODIFY_SRC_FACTOR (1<<11) -#define IAB_SRC_FACTOR_SHIFT 6 -#define IAB_SRC_FACTOR_MASK (BLENDFACT_MASK<<6) -#define IAB_MODIFY_DST_FACTOR (1<<5) -#define IAB_DST_FACTOR_SHIFT 0 -#define IAB_DST_FACTOR_MASK (BLENDFACT_MASK<<0) - - -#define BLENDFUNC_ADD 0x0 -#define BLENDFUNC_SUBTRACT 0x1 -#define BLENDFUNC_REVERSE_SUBTRACT 0x2 -#define BLENDFUNC_MIN 0x3 -#define BLENDFUNC_MAX 0x4 -#define BLENDFUNC_MASK 0x7 - -/* 3DSTATE_LOAD_INDIRECT, p180 */ - -#define _3DSTATE_LOAD_INDIRECT (CMD_3D|(0x1d<<24)|(0x7<<16)) -#define LI0_STATE_STATIC_INDIRECT (0x01<<8) -#define LI0_STATE_DYNAMIC_INDIRECT (0x02<<8) -#define LI0_STATE_SAMPLER (0x04<<8) -#define LI0_STATE_MAP (0x08<<8) -#define LI0_STATE_PROGRAM (0x10<<8) -#define LI0_STATE_CONSTANTS (0x20<<8) - -#define SIS0_BUFFER_ADDRESS(x) ((x)&~0x3) -#define SIS0_FORCE_LOAD (1<<1) -#define SIS0_BUFFER_VALID (1<<0) -#define SIS1_BUFFER_LENGTH(x) ((x)&0xff) - -#define DIS0_BUFFER_ADDRESS(x) ((x)&~0x3) -#define DIS0_BUFFER_RESET (1<<1) -#define DIS0_BUFFER_VALID (1<<0) - -#define SSB0_BUFFER_ADDRESS(x) ((x)&~0x3) -#define SSB0_FORCE_LOAD (1<<1) -#define SSB0_BUFFER_VALID (1<<0) -#define SSB1_BUFFER_LENGTH(x) ((x)&0xff) - -#define MSB0_BUFFER_ADDRESS(x) ((x)&~0x3) -#define MSB0_FORCE_LOAD (1<<1) -#define MSB0_BUFFER_VALID (1<<0) -#define MSB1_BUFFER_LENGTH(x) ((x)&0xff) - -#define PSP0_BUFFER_ADDRESS(x) ((x)&~0x3) -#define PSP0_FORCE_LOAD (1<<1) -#define PSP0_BUFFER_VALID (1<<0) -#define PSP1_BUFFER_LENGTH(x) ((x)&0xff) - -#define PSC0_BUFFER_ADDRESS(x) ((x)&~0x3) -#define PSC0_FORCE_LOAD (1<<1) -#define PSC0_BUFFER_VALID (1<<0) -#define PSC1_BUFFER_LENGTH(x) ((x)&0xff) - - - - - -/* _3DSTATE_RASTERIZATION_RULES */ -#define _3DSTATE_RASTER_RULES_CMD (CMD_3D|(0x07<<24)) -#define ENABLE_POINT_RASTER_RULE (1<<15) -#define OGL_POINT_RASTER_RULE (1<<13) -#define ENABLE_TEXKILL_3D_4D (1<<10) -#define TEXKILL_3D (0<<9) -#define TEXKILL_4D (1<<9) -#define ENABLE_LINE_STRIP_PROVOKE_VRTX (1<<8) -#define ENABLE_TRI_FAN_PROVOKE_VRTX (1<<5) -#define LINE_STRIP_PROVOKE_VRTX(x) ((x)<<6) -#define TRI_FAN_PROVOKE_VRTX(x) ((x)<<3) - -/* _3DSTATE_SCISSOR_ENABLE, p256 */ -#define _3DSTATE_SCISSOR_ENABLE_CMD (CMD_3D|(0x1c<<24)|(0x10<<19)) -#define ENABLE_SCISSOR_RECT ((1<<1) | 1) -#define DISABLE_SCISSOR_RECT (1<<1) - -/* _3DSTATE_SCISSOR_RECTANGLE_0, p257 */ -#define _3DSTATE_SCISSOR_RECT_0_CMD (CMD_3D|(0x1d<<24)|(0x81<<16)|1) -/* Dword 1 */ -#define SCISSOR_RECT_0_YMIN(x) ((x)<<16) -#define SCISSOR_RECT_0_XMIN(x) (x) -/* Dword 2 */ -#define SCISSOR_RECT_0_YMAX(x) ((x)<<16) -#define SCISSOR_RECT_0_XMAX(x) (x) - -/* p189 */ -#define _3DSTATE_LOAD_STATE_IMMEDIATE_1 ((0x3<<29)|(0x1d<<24)|(0x04<<16)) -#define I1_LOAD_S(n) (1<<(4+n)) - -#define S0_VB_OFFSET_MASK 0xffffffc -#define S0_AUTO_CACHE_INV_DISABLE (1<<0) - -#define S1_VERTEX_WIDTH_SHIFT 24 -#define S1_VERTEX_WIDTH_MASK (0x3f<<24) -#define S1_VERTEX_PITCH_SHIFT 16 -#define S1_VERTEX_PITCH_MASK (0x3f<<16) - -#define TEXCOORDFMT_2D 0x0 -#define TEXCOORDFMT_3D 0x1 -#define TEXCOORDFMT_4D 0x2 -#define TEXCOORDFMT_1D 0x3 -#define TEXCOORDFMT_2D_16 0x4 -#define TEXCOORDFMT_4D_16 0x5 -#define TEXCOORDFMT_NOT_PRESENT 0xf -#define S2_TEXCOORD_FMT0_MASK 0xf -#define S2_TEXCOORD_FMT1_SHIFT 4 -#define S2_TEXCOORD_FMT(unit, type) ((type)<<(unit*4)) -#define S2_TEXCOORD_NONE (~0) - -/* S3 not interesting */ - -#define S4_POINT_WIDTH_SHIFT 23 -#define S4_POINT_WIDTH_MASK (0x1ff<<23) -#define S4_LINE_WIDTH_SHIFT 19 -#define S4_LINE_WIDTH_ONE (0x2<<19) -#define S4_LINE_WIDTH_MASK (0xf<<19) -#define S4_FLATSHADE_ALPHA (1<<18) -#define S4_FLATSHADE_FOG (1<<17) -#define S4_FLATSHADE_SPECULAR (1<<16) -#define S4_FLATSHADE_COLOR (1<<15) -#define S4_CULLMODE_BOTH (0<<13) -#define S4_CULLMODE_NONE (1<<13) -#define S4_CULLMODE_CW (2<<13) -#define S4_CULLMODE_CCW (3<<13) -#define S4_CULLMODE_MASK (3<<13) -#define S4_VFMT_POINT_WIDTH (1<<12) -#define S4_VFMT_SPEC_FOG (1<<11) -#define S4_VFMT_COLOR (1<<10) -#define S4_VFMT_DEPTH_OFFSET (1<<9) -#define S4_VFMT_XYZ (1<<6) -#define S4_VFMT_XYZW (2<<6) -#define S4_VFMT_XY (3<<6) -#define S4_VFMT_XYW (4<<6) -#define S4_VFMT_XYZW_MASK (7<<6) -#define S4_FORCE_DEFAULT_DIFFUSE (1<<5) -#define S4_FORCE_DEFAULT_SPECULAR (1<<4) -#define S4_LOCAL_DEPTH_OFFSET_ENABLE (1<<3) -#define S4_VFMT_FOG_PARAM (1<<2) -#define S4_SPRITE_POINT_ENABLE (1<<1) -#define S4_LINE_ANTIALIAS_ENABLE (1<<0) - -#define S4_VFMT_MASK (S4_VFMT_POINT_WIDTH | \ - S4_VFMT_SPEC_FOG | \ - S4_VFMT_COLOR | \ - S4_VFMT_DEPTH_OFFSET | \ - S4_VFMT_XYZW_MASK | \ - S4_VFMT_FOG_PARAM) - - -#define S5_WRITEDISABLE_ALPHA (1<<31) -#define S5_WRITEDISABLE_RED (1<<30) -#define S5_WRITEDISABLE_GREEN (1<<29) -#define S5_WRITEDISABLE_BLUE (1<<28) -#define S5_WRITEDISABLE_MASK (0xf<<28) -#define S5_FORCE_DEFAULT_POINT_SIZE (1<<27) -#define S5_LAST_PIXEL_ENABLE (1<<26) -#define S5_GLOBAL_DEPTH_OFFSET_ENABLE (1<<25) -#define S5_FOG_ENABLE (1<<24) -#define S5_STENCIL_REF_SHIFT 16 -#define S5_STENCIL_REF_MASK (0xff<<16) -#define S5_STENCIL_TEST_FUNC_SHIFT 13 -#define S5_STENCIL_TEST_FUNC_MASK (0x7<<13) -#define S5_STENCIL_FAIL_SHIFT 10 -#define S5_STENCIL_FAIL_MASK (0x7<<10) -#define S5_STENCIL_PASS_Z_FAIL_SHIFT 7 -#define S5_STENCIL_PASS_Z_FAIL_MASK (0x7<<7) -#define S5_STENCIL_PASS_Z_PASS_SHIFT 4 -#define S5_STENCIL_PASS_Z_PASS_MASK (0x7<<4) -#define S5_STENCIL_WRITE_ENABLE (1<<3) -#define S5_STENCIL_TEST_ENABLE (1<<2) -#define S5_COLOR_DITHER_ENABLE (1<<1) -#define S5_LOGICOP_ENABLE (1<<0) - - -#define S6_ALPHA_TEST_ENABLE (1<<31) -#define S6_ALPHA_TEST_FUNC_SHIFT 28 -#define S6_ALPHA_TEST_FUNC_MASK (0x7<<28) -#define S6_ALPHA_REF_SHIFT 20 -#define S6_ALPHA_REF_MASK (0xff<<20) -#define S6_DEPTH_TEST_ENABLE (1<<19) -#define S6_DEPTH_TEST_FUNC_SHIFT 16 -#define S6_DEPTH_TEST_FUNC_MASK (0x7<<16) -#define S6_CBUF_BLEND_ENABLE (1<<15) -#define S6_CBUF_BLEND_FUNC_SHIFT 12 -#define S6_CBUF_BLEND_FUNC_MASK (0x7<<12) -#define S6_CBUF_SRC_BLEND_FACT_SHIFT 8 -#define S6_CBUF_SRC_BLEND_FACT_MASK (0xf<<8) -#define S6_CBUF_DST_BLEND_FACT_SHIFT 4 -#define S6_CBUF_DST_BLEND_FACT_MASK (0xf<<4) -#define S6_DEPTH_WRITE_ENABLE (1<<3) -#define S6_COLOR_WRITE_ENABLE (1<<2) -#define S6_TRISTRIP_PV_SHIFT 0 -#define S6_TRISTRIP_PV_MASK (0x3<<0) - -#define S7_DEPTH_OFFSET_CONST_MASK ~0 - -/* 3DSTATE_MAP_DEINTERLACER_PARAMETERS */ -/* 3DSTATE_MAP_PALETTE_LOAD_32, p206 */ - - -/* _3DSTATE_MODES_4, p218 */ -#define _3DSTATE_MODES_4_CMD (CMD_3D|(0x0d<<24)) -#define ENABLE_LOGIC_OP_FUNC (1<<23) -#define LOGIC_OP_FUNC(x) ((x)<<18) -#define LOGICOP_MASK (0xf<<18) -#define MODE4_ENABLE_STENCIL_TEST_MASK ((1<<17)|(0xff00)) -#define ENABLE_STENCIL_TEST_MASK (1<<17) -#define STENCIL_TEST_MASK(x) (((x)&0xff)<<8) -#define MODE4_ENABLE_STENCIL_WRITE_MASK ((1<<16)|(0x00ff)) -#define ENABLE_STENCIL_WRITE_MASK (1<<16) -#define STENCIL_WRITE_MASK(x) ((x)&0xff) - -/* _3DSTATE_MODES_5, p220 */ -#define _3DSTATE_MODES_5_CMD (CMD_3D|(0x0c<<24)) -#define PIPELINE_FLUSH_RENDER_CACHE (1<<18) -#define PIPELINE_FLUSH_TEXTURE_CACHE (1<<16) - - -/* p221 */ -#define _3DSTATE_PIXEL_SHADER_CONSTANTS (CMD_3D|(0x1d<<24)|(0x6<<16)) -#define PS1_REG(n) (1<<(n)) -#define PS2_CONST_X(n) (n) -#define PS3_CONST_Y(n) (n) -#define PS4_CONST_Z(n) (n) -#define PS5_CONST_W(n) (n) - -/* p222 */ - - -#define I915_MAX_TEX_INDIRECT 4 -#define I915_MAX_TEX_INSN 32 -#define I915_MAX_ALU_INSN 64 -#define I915_MAX_DECL_INSN 27 -#define I915_MAX_TEMPORARY 16 - - -/* Each instruction is 3 dwords long, though most don't require all - * this space. Maximum of 123 instructions. Smaller maxes per insn - * type. - */ -#define _3DSTATE_PIXEL_SHADER_PROGRAM (CMD_3D|(0x1d<<24)|(0x5<<16)) - -#define REG_TYPE_R 0 /* temporary regs, no need to - * dcl, must be written before - * read -- Preserved between - * phases. - */ -#define REG_TYPE_T 1 /* Interpolated values, must be - * dcl'ed before use. - * - * 0..7: texture coord, - * 8: diffuse spec, - * 9: specular color, - * 10: fog parameter in w. - */ -#define REG_TYPE_CONST 2 /* Restriction: only one const - * can be referenced per - * instruction, though it may be - * selected for multiple inputs. - * Constants not initialized - * default to zero. - */ -#define REG_TYPE_S 3 /* sampler */ -#define REG_TYPE_OC 4 /* output color (rgba) */ -#define REG_TYPE_OD 5 /* output depth (w), xyz are - * temporaries. If not written, - * interpolated depth is used? - */ -#define REG_TYPE_U 6 /* unpreserved temporaries */ -#define REG_TYPE_MASK 0x7 -#define REG_NR_MASK 0xf - - -/* REG_TYPE_T: - */ -#define T_TEX0 0 -#define T_TEX1 1 -#define T_TEX2 2 -#define T_TEX3 3 -#define T_TEX4 4 -#define T_TEX5 5 -#define T_TEX6 6 -#define T_TEX7 7 -#define T_DIFFUSE 8 -#define T_SPECULAR 9 -#define T_FOG_W 10 /* interpolated fog is in W coord */ - -/* Arithmetic instructions */ - -/* .replicate_swizzle == selection and replication of a particular - * scalar channel, ie., .xxxx, .yyyy, .zzzz or .wwww - */ -#define A0_NOP (0x0<<24) /* no operation */ -#define A0_ADD (0x1<<24) /* dst = src0 + src1 */ -#define A0_MOV (0x2<<24) /* dst = src0 */ -#define A0_MUL (0x3<<24) /* dst = src0 * src1 */ -#define A0_MAD (0x4<<24) /* dst = src0 * src1 + src2 */ -#define A0_DP2ADD (0x5<<24) /* dst.xyzw = src0.xy dot src1.xy + src2.replicate_swizzle */ -#define A0_DP3 (0x6<<24) /* dst.xyzw = src0.xyz dot src1.xyz */ -#define A0_DP4 (0x7<<24) /* dst.xyzw = src0.xyzw dot src1.xyzw */ -#define A0_FRC (0x8<<24) /* dst = src0 - floor(src0) */ -#define A0_RCP (0x9<<24) /* dst.xyzw = 1/(src0.replicate_swizzle) */ -#define A0_RSQ (0xa<<24) /* dst.xyzw = 1/(sqrt(abs(src0.replicate_swizzle))) */ -#define A0_EXP (0xb<<24) /* dst.xyzw = exp2(src0.replicate_swizzle) */ -#define A0_LOG (0xc<<24) /* dst.xyzw = log2(abs(src0.replicate_swizzle)) */ -#define A0_CMP (0xd<<24) /* dst = (src0 >= 0.0) ? src1 : src2 */ -#define A0_MIN (0xe<<24) /* dst = (src0 < src1) ? src0 : src1 */ -#define A0_MAX (0xf<<24) /* dst = (src0 >= src1) ? src0 : src1 */ -#define A0_FLR (0x10<<24) /* dst = floor(src0) */ -#define A0_MOD (0x11<<24) /* dst = src0 fmod 1.0 */ -#define A0_TRC (0x12<<24) /* dst = int(src0) */ -#define A0_SGE (0x13<<24) /* dst = src0 >= src1 ? 1.0 : 0.0 */ -#define A0_SLT (0x14<<24) /* dst = src0 < src1 ? 1.0 : 0.0 */ -#define A0_DEST_SATURATE (1<<22) -#define A0_DEST_TYPE_SHIFT 19 -/* Allow: R, OC, OD, U */ -#define A0_DEST_NR_SHIFT 14 -/* Allow R: 0..15, OC,OD: 0..0, U: 0..2 */ -#define A0_DEST_CHANNEL_X (1<<10) -#define A0_DEST_CHANNEL_Y (2<<10) -#define A0_DEST_CHANNEL_Z (4<<10) -#define A0_DEST_CHANNEL_W (8<<10) -#define A0_DEST_CHANNEL_ALL (0xf<<10) -#define A0_DEST_CHANNEL_SHIFT 10 -#define A0_SRC0_TYPE_SHIFT 7 -#define A0_SRC0_NR_SHIFT 2 - -#define A0_DEST_CHANNEL_XY (A0_DEST_CHANNEL_X|A0_DEST_CHANNEL_Y) -#define A0_DEST_CHANNEL_XYZ (A0_DEST_CHANNEL_XY|A0_DEST_CHANNEL_Z) - - -#define SRC_X 0 -#define SRC_Y 1 -#define SRC_Z 2 -#define SRC_W 3 -#define SRC_ZERO 4 -#define SRC_ONE 5 - -#define A1_SRC0_CHANNEL_X_NEGATE (1<<31) -#define A1_SRC0_CHANNEL_X_SHIFT 28 -#define A1_SRC0_CHANNEL_Y_NEGATE (1<<27) -#define A1_SRC0_CHANNEL_Y_SHIFT 24 -#define A1_SRC0_CHANNEL_Z_NEGATE (1<<23) -#define A1_SRC0_CHANNEL_Z_SHIFT 20 -#define A1_SRC0_CHANNEL_W_NEGATE (1<<19) -#define A1_SRC0_CHANNEL_W_SHIFT 16 -#define A1_SRC1_TYPE_SHIFT 13 -#define A1_SRC1_NR_SHIFT 8 -#define A1_SRC1_CHANNEL_X_NEGATE (1<<7) -#define A1_SRC1_CHANNEL_X_SHIFT 4 -#define A1_SRC1_CHANNEL_Y_NEGATE (1<<3) -#define A1_SRC1_CHANNEL_Y_SHIFT 0 - -#define A2_SRC1_CHANNEL_Z_NEGATE (1<<31) -#define A2_SRC1_CHANNEL_Z_SHIFT 28 -#define A2_SRC1_CHANNEL_W_NEGATE (1<<27) -#define A2_SRC1_CHANNEL_W_SHIFT 24 -#define A2_SRC2_TYPE_SHIFT 21 -#define A2_SRC2_NR_SHIFT 16 -#define A2_SRC2_CHANNEL_X_NEGATE (1<<15) -#define A2_SRC2_CHANNEL_X_SHIFT 12 -#define A2_SRC2_CHANNEL_Y_NEGATE (1<<11) -#define A2_SRC2_CHANNEL_Y_SHIFT 8 -#define A2_SRC2_CHANNEL_Z_NEGATE (1<<7) -#define A2_SRC2_CHANNEL_Z_SHIFT 4 -#define A2_SRC2_CHANNEL_W_NEGATE (1<<3) -#define A2_SRC2_CHANNEL_W_SHIFT 0 - - - -/* Texture instructions */ -#define T0_TEXLD (0x15<<24) /* Sample texture using predeclared - * sampler and address, and output - * filtered texel data to destination - * register */ -#define T0_TEXLDP (0x16<<24) /* Same as texld but performs a - * perspective divide of the texture - * coordinate .xyz values by .w before - * sampling. */ -#define T0_TEXLDB (0x17<<24) /* Same as texld but biases the - * computed LOD by w. Only S4.6 two's - * comp is used. This implies that a - * float to fixed conversion is - * done. */ -#define T0_TEXKILL (0x18<<24) /* Does not perform a sampling - * operation. Simply kills the pixel - * if any channel of the address - * register is < 0.0. */ -#define T0_DEST_TYPE_SHIFT 19 -/* Allow: R, OC, OD, U */ -/* Note: U (unpreserved) regs do not retain their values between - * phases (cannot be used for feedback) - * - * Note: oC and OD registers can only be used as the destination of a - * texture instruction once per phase (this is an implementation - * restriction). - */ -#define T0_DEST_NR_SHIFT 14 -/* Allow R: 0..15, OC,OD: 0..0, U: 0..2 */ -#define T0_SAMPLER_NR_SHIFT 0 /* This field ignored for TEXKILL */ -#define T0_SAMPLER_NR_MASK (0xf<<0) - -#define T1_ADDRESS_REG_TYPE_SHIFT 24 /* Reg to use as texture coord */ -/* Allow R, T, OC, OD -- R, OC, OD are 'dependent' reads, new program phase */ -#define T1_ADDRESS_REG_NR_SHIFT 17 -#define T2_MBZ 0 - -/* Declaration instructions */ -#define D0_DCL (0x19<<24) /* Declare a t (interpolated attrib) - * register or an s (sampler) - * register. */ -#define D0_SAMPLE_TYPE_SHIFT 22 -#define D0_SAMPLE_TYPE_2D (0x0<<22) -#define D0_SAMPLE_TYPE_CUBE (0x1<<22) -#define D0_SAMPLE_TYPE_VOLUME (0x2<<22) -#define D0_SAMPLE_TYPE_MASK (0x3<<22) - -#define D0_TYPE_SHIFT 19 -/* Allow: T, S */ -#define D0_NR_SHIFT 14 -/* Allow T: 0..10, S: 0..15 */ -#define D0_CHANNEL_X (1<<10) -#define D0_CHANNEL_Y (2<<10) -#define D0_CHANNEL_Z (4<<10) -#define D0_CHANNEL_W (8<<10) -#define D0_CHANNEL_ALL (0xf<<10) -#define D0_CHANNEL_NONE (0<<10) - -#define D0_CHANNEL_XY (D0_CHANNEL_X|D0_CHANNEL_Y) -#define D0_CHANNEL_XYZ (D0_CHANNEL_XY|D0_CHANNEL_Z) - -/* I915 Errata: Do not allow (xz), (xw), (xzw) combinations for diffuse - * or specular declarations. - * - * For T dcls, only allow: (x), (xy), (xyz), (w), (xyzw) - * - * Must be zero for S (sampler) dcls - */ -#define D1_MBZ 0 -#define D2_MBZ 0 - - - -/* p207 */ -#define _3DSTATE_MAP_STATE (CMD_3D|(0x1d<<24)|(0x0<<16)) - -#define MS1_MAPMASK_SHIFT 0 -#define MS1_MAPMASK_MASK (0x8fff<<0) - -#define MS2_UNTRUSTED_SURFACE (1<<31) -#define MS2_ADDRESS_MASK 0xfffffffc -#define MS2_VERTICAL_LINE_STRIDE (1<<1) -#define MS2_VERTICAL_OFFSET (1<<1) - -#define MS3_HEIGHT_SHIFT 21 -#define MS3_WIDTH_SHIFT 10 -#define MS3_PALETTE_SELECT (1<<9) -#define MS3_MAPSURF_FORMAT_SHIFT 7 -#define MS3_MAPSURF_FORMAT_MASK (0x7<<7) -#define MAPSURF_8BIT (1<<7) -#define MAPSURF_16BIT (2<<7) -#define MAPSURF_32BIT (3<<7) -#define MAPSURF_422 (5<<7) -#define MAPSURF_COMPRESSED (6<<7) -#define MAPSURF_4BIT_INDEXED (7<<7) -#define MS3_MT_FORMAT_MASK (0x7 << 3) -#define MS3_MT_FORMAT_SHIFT 3 -#define MT_4BIT_IDX_ARGB8888 (7<<3) /* SURFACE_4BIT_INDEXED */ -#define MT_8BIT_I8 (0<<3) /* SURFACE_8BIT */ -#define MT_8BIT_L8 (1<<3) -#define MT_8BIT_A8 (4<<3) -#define MT_8BIT_MONO8 (5<<3) -#define MT_16BIT_RGB565 (0<<3) /* SURFACE_16BIT */ -#define MT_16BIT_ARGB1555 (1<<3) -#define MT_16BIT_ARGB4444 (2<<3) -#define MT_16BIT_AY88 (3<<3) -#define MT_16BIT_88DVDU (5<<3) -#define MT_16BIT_BUMP_655LDVDU (6<<3) -#define MT_16BIT_I16 (7<<3) -#define MT_16BIT_L16 (8<<3) -#define MT_16BIT_A16 (9<<3) -#define MT_32BIT_ARGB8888 (0<<3) /* SURFACE_32BIT */ -#define MT_32BIT_ABGR8888 (1<<3) -#define MT_32BIT_XRGB8888 (2<<3) -#define MT_32BIT_XBGR8888 (3<<3) -#define MT_32BIT_QWVU8888 (4<<3) -#define MT_32BIT_AXVU8888 (5<<3) -#define MT_32BIT_LXVU8888 (6<<3) -#define MT_32BIT_XLVU8888 (7<<3) -#define MT_32BIT_ARGB2101010 (8<<3) -#define MT_32BIT_ABGR2101010 (9<<3) -#define MT_32BIT_AWVU2101010 (0xA<<3) -#define MT_32BIT_GR1616 (0xB<<3) -#define MT_32BIT_VU1616 (0xC<<3) -#define MT_32BIT_xI824 (0xD<<3) -#define MT_32BIT_xA824 (0xE<<3) -#define MT_32BIT_xL824 (0xF<<3) -#define MT_422_YCRCB_SWAPY (0<<3) /* SURFACE_422 */ -#define MT_422_YCRCB_NORMAL (1<<3) -#define MT_422_YCRCB_SWAPUV (2<<3) -#define MT_422_YCRCB_SWAPUVY (3<<3) -#define MT_COMPRESS_DXT1 (0<<3) /* SURFACE_COMPRESSED */ -#define MT_COMPRESS_DXT2_3 (1<<3) -#define MT_COMPRESS_DXT4_5 (2<<3) -#define MT_COMPRESS_FXT1 (3<<3) -#define MT_COMPRESS_DXT1_RGB (4<<3) -#define MS3_USE_FENCE_REGS (1<<2) -#define MS3_TILED_SURFACE (1<<1) -#define MS3_TILE_WALK (1<<0) - -#define MS4_PITCH_SHIFT 21 -#define MS4_CUBE_FACE_ENA_NEGX (1<<20) -#define MS4_CUBE_FACE_ENA_POSX (1<<19) -#define MS4_CUBE_FACE_ENA_NEGY (1<<18) -#define MS4_CUBE_FACE_ENA_POSY (1<<17) -#define MS4_CUBE_FACE_ENA_NEGZ (1<<16) -#define MS4_CUBE_FACE_ENA_POSZ (1<<15) -#define MS4_CUBE_FACE_ENA_MASK (0x3f<<15) -#define MS4_MAX_LOD_SHIFT 9 -#define MS4_MAX_LOD_MASK (0x3f<<9) -#define MS4_MIP_LAYOUT_LEGACY (0<<8) -#define MS4_MIP_LAYOUT_BELOW_LPT (0<<8) -#define MS4_MIP_LAYOUT_RIGHT_LPT (1<<8) -#define MS4_VOLUME_DEPTH_SHIFT 0 -#define MS4_VOLUME_DEPTH_MASK (0xff<<0) - -/* p244 */ -#define _3DSTATE_SAMPLER_STATE (CMD_3D|(0x1d<<24)|(0x1<<16)) - -#define SS1_MAPMASK_SHIFT 0 -#define SS1_MAPMASK_MASK (0x8fff<<0) - -#define SS2_REVERSE_GAMMA_ENABLE (1<<31) -#define SS2_PACKED_TO_PLANAR_ENABLE (1<<30) -#define SS2_COLORSPACE_CONVERSION (1<<29) -#define SS2_CHROMAKEY_SHIFT 27 -#define SS2_BASE_MIP_LEVEL_SHIFT 22 -#define SS2_BASE_MIP_LEVEL_MASK (0x1f<<22) -#define SS2_MIP_FILTER_SHIFT 20 -#define SS2_MIP_FILTER_MASK (0x3<<20) -#define MIPFILTER_NONE 0 -#define MIPFILTER_NEAREST 1 -#define MIPFILTER_LINEAR 3 -#define SS2_MAG_FILTER_SHIFT 17 -#define SS2_MAG_FILTER_MASK (0x7<<17) -#define FILTER_NEAREST 0 -#define FILTER_LINEAR 1 -#define FILTER_ANISOTROPIC 2 -#define FILTER_4X4_1 3 -#define FILTER_4X4_2 4 -#define FILTER_4X4_FLAT 5 -#define FILTER_6X5_MONO 6 /* XXX - check */ -#define SS2_MIN_FILTER_SHIFT 14 -#define SS2_MIN_FILTER_MASK (0x7<<14) -#define SS2_LOD_BIAS_SHIFT 5 -#define SS2_LOD_BIAS_ONE (0x10<<5) -#define SS2_LOD_BIAS_MASK (0x1ff<<5) -/* Shadow requires: - * MT_X8{I,L,A}24 or MT_{I,L,A}16 texture format - * FILTER_4X4_x MIN and MAG filters - */ -#define SS2_SHADOW_ENABLE (1<<4) -#define SS2_MAX_ANISO_MASK (1<<3) -#define SS2_MAX_ANISO_2 (0<<3) -#define SS2_MAX_ANISO_4 (1<<3) -#define SS2_SHADOW_FUNC_SHIFT 0 -#define SS2_SHADOW_FUNC_MASK (0x7<<0) -/* SS2_SHADOW_FUNC values: see COMPAREFUNC_* */ - -#define SS3_MIN_LOD_SHIFT 24 -#define SS3_MIN_LOD_ONE (0x10<<24) -#define SS3_MIN_LOD_MASK (0xff<<24) -#define SS3_KILL_PIXEL_ENABLE (1<<17) -#define SS3_TCX_ADDR_MODE_SHIFT 12 -#define SS3_TCX_ADDR_MODE_MASK (0x7<<12) -#define TEXCOORDMODE_WRAP 0 -#define TEXCOORDMODE_MIRROR 1 -#define TEXCOORDMODE_CLAMP_EDGE 2 -#define TEXCOORDMODE_CUBE 3 -#define TEXCOORDMODE_CLAMP_BORDER 4 -#define TEXCOORDMODE_MIRROR_ONCE 5 -#define SS3_TCY_ADDR_MODE_SHIFT 9 -#define SS3_TCY_ADDR_MODE_MASK (0x7<<9) -#define SS3_TCZ_ADDR_MODE_SHIFT 6 -#define SS3_TCZ_ADDR_MODE_MASK (0x7<<6) -#define SS3_NORMALIZED_COORDS (1<<5) -#define SS3_TEXTUREMAP_INDEX_SHIFT 1 -#define SS3_TEXTUREMAP_INDEX_MASK (0xf<<1) -#define SS3_DEINTERLACER_ENABLE (1<<0) - -#define SS4_BORDER_COLOR_MASK (~0) - -/* 3DSTATE_SPAN_STIPPLE, p258 - */ -#define _3DSTATE_STIPPLE ((0x3<<29)|(0x1d<<24)|(0x83<<16)) -#define ST1_ENABLE (1<<16) -#define ST1_MASK (0xffff) - -#define _3DSTATE_DEFAULT_Z ((0x3<<29)|(0x1d<<24)|(0x98<<16)) -#define _3DSTATE_DEFAULT_DIFFUSE ((0x3<<29)|(0x1d<<24)|(0x99<<16)) -#define _3DSTATE_DEFAULT_SPECULAR ((0x3<<29)|(0x1d<<24)|(0x9a<<16)) - - -#define MI_FLUSH ((0<<29)|(4<<23)) -#define FLUSH_MAP_CACHE (1<<0) -#define INHIBIT_FLUSH_RENDER_CACHE (1<<2) - - -#endif diff --git a/src/mesa/drivers/dri/i915-tex/i915_state.c b/src/mesa/drivers/dri/i915-tex/i915_state.c deleted file mode 100644 index 8a7b4e9d827..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i915_state.c +++ /dev/null @@ -1,1006 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - - -#include "glheader.h" -#include "context.h" -#include "macros.h" -#include "enums.h" -#include "dd.h" -#include "tnl/tnl.h" -#include "tnl/t_context.h" - -#include "texmem.h" - -#include "intel_fbo.h" -#include "intel_screen.h" -#include "intel_batchbuffer.h" - -#include "i915_context.h" -#include "i915_reg.h" - - - -static void -i915StencilFuncSeparate(GLcontext *ctx, GLenum face, GLenum func, GLint ref, - GLuint mask) -{ - struct i915_context *i915 = I915_CONTEXT(ctx); - int test = intel_translate_compare_func( func ); - - mask = mask & 0xff; - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s : func: %s, ref : 0x%x, mask: 0x%x\n", __FUNCTION__, - _mesa_lookup_enum_by_nr(func), ref, mask); - - - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - i915->state.Ctx[I915_CTXREG_STATE4] &= ~MODE4_ENABLE_STENCIL_TEST_MASK; - i915->state.Ctx[I915_CTXREG_STATE4] |= (ENABLE_STENCIL_TEST_MASK | - STENCIL_TEST_MASK(mask)); - - i915->state.Ctx[I915_CTXREG_LIS5] &= ~(S5_STENCIL_REF_MASK | - S5_STENCIL_TEST_FUNC_MASK); - - i915->state.Ctx[I915_CTXREG_LIS5] |= ((ref << S5_STENCIL_REF_SHIFT) | - (test << S5_STENCIL_TEST_FUNC_SHIFT)); -} - -static void -i915StencilMaskSeparate(GLcontext *ctx, GLenum face, GLuint mask) -{ - struct i915_context *i915 = I915_CONTEXT(ctx); - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s : mask 0x%x\n", __FUNCTION__, mask); - - mask = mask & 0xff; - - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - i915->state.Ctx[I915_CTXREG_STATE4] &= ~MODE4_ENABLE_STENCIL_WRITE_MASK; - i915->state.Ctx[I915_CTXREG_STATE4] |= (ENABLE_STENCIL_WRITE_MASK | - STENCIL_WRITE_MASK(mask)); -} - - -static void -i915StencilOpSeparate(GLcontext *ctx, GLenum face, GLenum fail, GLenum zfail, - GLenum zpass) -{ - struct i915_context *i915 = I915_CONTEXT(ctx); - int fop = intel_translate_stencil_op(fail); - int dfop = intel_translate_stencil_op(zfail); - int dpop = intel_translate_stencil_op(zpass); - - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s: fail : %s, zfail: %s, zpass : %s\n", __FUNCTION__, - _mesa_lookup_enum_by_nr(fail), - _mesa_lookup_enum_by_nr(zfail), - _mesa_lookup_enum_by_nr(zpass)); - - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - - i915->state.Ctx[I915_CTXREG_LIS5] &= ~(S5_STENCIL_FAIL_MASK | - S5_STENCIL_PASS_Z_FAIL_MASK | - S5_STENCIL_PASS_Z_PASS_MASK); - - i915->state.Ctx[I915_CTXREG_LIS5] |= ((fop << S5_STENCIL_FAIL_SHIFT) | - (dfop << S5_STENCIL_PASS_Z_FAIL_SHIFT) | - (dpop << S5_STENCIL_PASS_Z_PASS_SHIFT)); -} - -static void i915AlphaFunc(GLcontext *ctx, GLenum func, GLfloat ref) -{ - struct i915_context *i915 = I915_CONTEXT(ctx); - int test = intel_translate_compare_func( func ); - GLubyte refByte; - - UNCLAMPED_FLOAT_TO_UBYTE(refByte, ref); - - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - i915->state.Ctx[I915_CTXREG_LIS6] &= ~(S6_ALPHA_TEST_FUNC_MASK | - S6_ALPHA_REF_MASK); - i915->state.Ctx[I915_CTXREG_LIS6] |= ((test << S6_ALPHA_TEST_FUNC_SHIFT) | - (((GLuint)refByte) << S6_ALPHA_REF_SHIFT)); -} - -/* This function makes sure that the proper enables are - * set for LogicOp, Independant Alpha Blend, and Blending. - * It needs to be called from numerous places where we - * could change the LogicOp or Independant Alpha Blend without subsequent - * calls to glEnable. - */ -static void i915EvalLogicOpBlendState(GLcontext *ctx) -{ - struct i915_context *i915 = I915_CONTEXT(ctx); - - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - - if (ctx->Color._LogicOpEnabled) { - i915->state.Ctx[I915_CTXREG_LIS5] |= S5_LOGICOP_ENABLE; - i915->state.Ctx[I915_CTXREG_LIS6] &= ~S6_CBUF_BLEND_ENABLE; - } else { - i915->state.Ctx[I915_CTXREG_LIS5] &= ~S5_LOGICOP_ENABLE; - - if (ctx->Color.BlendEnabled) { - i915->state.Ctx[I915_CTXREG_LIS6] |= S6_CBUF_BLEND_ENABLE; - } else { - i915->state.Ctx[I915_CTXREG_LIS6] &= ~S6_CBUF_BLEND_ENABLE; - } - } -} - -static void i915BlendColor(GLcontext *ctx, const GLfloat color[4]) -{ - struct i915_context *i915 = I915_CONTEXT(ctx); - GLubyte r, g, b, a; - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s\n", __FUNCTION__); - - UNCLAMPED_FLOAT_TO_UBYTE(r, color[RCOMP]); - UNCLAMPED_FLOAT_TO_UBYTE(g, color[GCOMP]); - UNCLAMPED_FLOAT_TO_UBYTE(b, color[BCOMP]); - UNCLAMPED_FLOAT_TO_UBYTE(a, color[ACOMP]); - - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - i915->state.Ctx[I915_CTXREG_BLENDCOLOR1] = (a<<24) | (r<<16) | (g<<8) | b; -} - - -#define DST_BLND_FACT(f) ((f)<<S6_CBUF_DST_BLEND_FACT_SHIFT) -#define SRC_BLND_FACT(f) ((f)<<S6_CBUF_SRC_BLEND_FACT_SHIFT) -#define DST_ABLND_FACT(f) ((f)<<IAB_DST_FACTOR_SHIFT) -#define SRC_ABLND_FACT(f) ((f)<<IAB_SRC_FACTOR_SHIFT) - - - -static GLuint translate_blend_equation( GLenum mode ) -{ - switch (mode) { - case GL_FUNC_ADD: return BLENDFUNC_ADD; - case GL_MIN: return BLENDFUNC_MIN; - case GL_MAX: return BLENDFUNC_MAX; - case GL_FUNC_SUBTRACT: return BLENDFUNC_SUBTRACT; - case GL_FUNC_REVERSE_SUBTRACT: return BLENDFUNC_REVERSE_SUBTRACT; - default: return 0; - } -} - -static void i915UpdateBlendState( GLcontext *ctx ) -{ - struct i915_context *i915 = I915_CONTEXT(ctx); - GLuint iab = (i915->state.Ctx[I915_CTXREG_IAB] & - ~(IAB_SRC_FACTOR_MASK | - IAB_DST_FACTOR_MASK | - (BLENDFUNC_MASK << IAB_FUNC_SHIFT) | - IAB_ENABLE)); - - GLuint lis6 = (i915->state.Ctx[I915_CTXREG_LIS6] & - ~(S6_CBUF_SRC_BLEND_FACT_MASK | - S6_CBUF_DST_BLEND_FACT_MASK | - S6_CBUF_BLEND_FUNC_MASK)); - - GLuint eqRGB = ctx->Color.BlendEquationRGB; - GLuint eqA = ctx->Color.BlendEquationA; - GLuint srcRGB = ctx->Color.BlendSrcRGB; - GLuint dstRGB = ctx->Color.BlendDstRGB; - GLuint srcA = ctx->Color.BlendSrcA; - GLuint dstA = ctx->Color.BlendDstA; - - if (eqRGB == GL_MIN || eqRGB == GL_MAX) { - srcRGB = dstRGB = GL_ONE; - } - - if (eqA == GL_MIN || eqA == GL_MAX) { - srcA = dstA = GL_ONE; - } - - lis6 |= SRC_BLND_FACT(intel_translate_blend_factor(srcRGB)); - lis6 |= DST_BLND_FACT(intel_translate_blend_factor(dstRGB)); - lis6 |= translate_blend_equation( eqRGB ) << S6_CBUF_BLEND_FUNC_SHIFT; - - iab |= SRC_ABLND_FACT(intel_translate_blend_factor(srcA)); - iab |= DST_ABLND_FACT(intel_translate_blend_factor(dstA)); - iab |= translate_blend_equation( eqA ) << IAB_FUNC_SHIFT; - - if (srcA != srcRGB || dstA != dstRGB || eqA != eqRGB) - iab |= IAB_ENABLE; - - if (iab != i915->state.Ctx[I915_CTXREG_IAB] || - lis6 != i915->state.Ctx[I915_CTXREG_LIS6]) { - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - i915->state.Ctx[I915_CTXREG_IAB] = iab; - i915->state.Ctx[I915_CTXREG_LIS6] = lis6; - } - - /* This will catch a logicop blend equation */ - i915EvalLogicOpBlendState(ctx); -} - - -static void i915BlendFuncSeparate(GLcontext *ctx, GLenum srcRGB, - GLenum dstRGB, GLenum srcA, - GLenum dstA ) -{ - i915UpdateBlendState( ctx ); -} - - -static void i915BlendEquationSeparate(GLcontext *ctx, GLenum eqRGB, - GLenum eqA) -{ - i915UpdateBlendState( ctx ); -} - - -static void i915DepthFunc(GLcontext *ctx, GLenum func) -{ - struct i915_context *i915 = I915_CONTEXT(ctx); - int test = intel_translate_compare_func( func ); - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s\n", __FUNCTION__); - - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - i915->state.Ctx[I915_CTXREG_LIS6] &= ~S6_DEPTH_TEST_FUNC_MASK; - i915->state.Ctx[I915_CTXREG_LIS6] |= test << S6_DEPTH_TEST_FUNC_SHIFT; -} - -static void i915DepthMask(GLcontext *ctx, GLboolean flag) -{ - struct i915_context *i915 = I915_CONTEXT(ctx); - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s flag (%d)\n", __FUNCTION__, flag); - - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - - if (flag && ctx->Depth.Test) - i915->state.Ctx[I915_CTXREG_LIS6] |= S6_DEPTH_WRITE_ENABLE; - else - i915->state.Ctx[I915_CTXREG_LIS6] &= ~S6_DEPTH_WRITE_ENABLE; -} - -/* ============================================================= - * Polygon stipple - * - * The i915 supports a 4x4 stipple natively, GL wants 32x32. - * Fortunately stipple is usually a repeating pattern. - */ -static void i915PolygonStipple( GLcontext *ctx, const GLubyte *mask ) -{ - struct i915_context *i915 = I915_CONTEXT(ctx); - const GLubyte *m = mask; - GLubyte p[4]; - int i,j,k; - int active = (ctx->Polygon.StippleFlag && - i915->intel.reduced_primitive == GL_TRIANGLES); - GLuint newMask; - - if (active) { - I915_STATECHANGE(i915, I915_UPLOAD_STIPPLE); - i915->state.Stipple[I915_STPREG_ST1] &= ~ST1_ENABLE; - } - - p[0] = mask[12] & 0xf; p[0] |= p[0] << 4; - p[1] = mask[8] & 0xf; p[1] |= p[1] << 4; - p[2] = mask[4] & 0xf; p[2] |= p[2] << 4; - p[3] = mask[0] & 0xf; p[3] |= p[3] << 4; - - for (k = 0 ; k < 8 ; k++) - for (j = 3 ; j >= 0; j--) - for (i = 0 ; i < 4 ; i++, m++) - if (*m != p[j]) { - i915->intel.hw_stipple = 0; - return; - } - - newMask = (((p[0] & 0xf) << 0) | - ((p[1] & 0xf) << 4) | - ((p[2] & 0xf) << 8) | - ((p[3] & 0xf) << 12)); - - - if (newMask == 0xffff || newMask == 0x0) { - /* this is needed to make conform pass */ - i915->intel.hw_stipple = 0; - return; - } - - i915->state.Stipple[I915_STPREG_ST1] &= ~0xffff; - i915->state.Stipple[I915_STPREG_ST1] |= newMask; - i915->intel.hw_stipple = 1; - - if (active) - i915->state.Stipple[I915_STPREG_ST1] |= ST1_ENABLE; -} - - -/* ============================================================= - * Hardware clipping - */ -static void i915Scissor(GLcontext *ctx, GLint x, GLint y, - GLsizei w, GLsizei h) -{ - struct i915_context *i915 = I915_CONTEXT(ctx); - int x1, y1, x2, y2; - - if (!ctx->DrawBuffer) - return; - - x1 = x; - y1 = ctx->DrawBuffer->Height - (y + h); - x2 = x + w - 1; - y2 = y1 + h - 1; - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "[%s] x(%d) y(%d) w(%d) h(%d)\n", __FUNCTION__, - x, y, w, h); - - x1 = CLAMP(x1, 0, ctx->DrawBuffer->Width - 1); - y1 = CLAMP(y1, 0, ctx->DrawBuffer->Height - 1); - x2 = CLAMP(x2, 0, ctx->DrawBuffer->Width - 1); - y2 = CLAMP(y2, 0, ctx->DrawBuffer->Height - 1); - - I915_STATECHANGE(i915, I915_UPLOAD_BUFFERS); - i915->state.Buffer[I915_DESTREG_SR1] = (y1 << 16) | (x1 & 0xffff); - i915->state.Buffer[I915_DESTREG_SR2] = (y2 << 16) | (x2 & 0xffff); -} - -static void i915LogicOp(GLcontext *ctx, GLenum opcode) -{ - struct i915_context *i915 = I915_CONTEXT(ctx); - int tmp = intel_translate_logic_op(opcode); - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s\n", __FUNCTION__); - - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - i915->state.Ctx[I915_CTXREG_STATE4] &= ~LOGICOP_MASK; - i915->state.Ctx[I915_CTXREG_STATE4] |= LOGIC_OP_FUNC(tmp); -} - - - -static void i915CullFaceFrontFace(GLcontext *ctx, GLenum unused) -{ - struct i915_context *i915 = I915_CONTEXT(ctx); - GLuint mode; - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s\n", __FUNCTION__); - - if (!ctx->Polygon.CullFlag) { - mode = S4_CULLMODE_NONE; - } - else if (ctx->Polygon.CullFaceMode != GL_FRONT_AND_BACK) { - mode = S4_CULLMODE_CW; - - if (ctx->Polygon.CullFaceMode == GL_FRONT) - mode ^= (S4_CULLMODE_CW ^ S4_CULLMODE_CCW); - if (ctx->Polygon.FrontFace != GL_CCW) - mode ^= (S4_CULLMODE_CW ^ S4_CULLMODE_CCW); - } - else { - mode = S4_CULLMODE_BOTH; - } - - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - i915->state.Ctx[I915_CTXREG_LIS4] &= ~S4_CULLMODE_MASK; - i915->state.Ctx[I915_CTXREG_LIS4] |= mode; -} - -static void i915LineWidth( GLcontext *ctx, GLfloat widthf ) -{ - struct i915_context *i915 = I915_CONTEXT( ctx ); - int lis4 = i915->state.Ctx[I915_CTXREG_LIS4] & ~S4_LINE_WIDTH_MASK; - int width; - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s\n", __FUNCTION__); - - width = (int)(widthf * 2); - CLAMP_SELF(width, 1, 0xf); - lis4 |= width << S4_LINE_WIDTH_SHIFT; - - if (lis4 != i915->state.Ctx[I915_CTXREG_LIS4]) { - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - i915->state.Ctx[I915_CTXREG_LIS4] = lis4; - } -} - -static void i915PointSize(GLcontext *ctx, GLfloat size) -{ - struct i915_context *i915 = I915_CONTEXT(ctx); - int lis4 = i915->state.Ctx[I915_CTXREG_LIS4] & ~S4_POINT_WIDTH_MASK; - GLint point_size = (int)size; - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s\n", __FUNCTION__); - - CLAMP_SELF(point_size, 1, 255); - lis4 |= point_size << S4_POINT_WIDTH_SHIFT; - - if (lis4 != i915->state.Ctx[I915_CTXREG_LIS4]) { - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - i915->state.Ctx[I915_CTXREG_LIS4] = lis4; - } -} - - -/* ============================================================= - * Color masks - */ - -static void i915ColorMask(GLcontext *ctx, - GLboolean r, GLboolean g, - GLboolean b, GLboolean a) -{ - struct i915_context *i915 = I915_CONTEXT( ctx ); - GLuint tmp = i915->state.Ctx[I915_CTXREG_LIS5] & ~S5_WRITEDISABLE_MASK; - - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s r(%d) g(%d) b(%d) a(%d)\n", __FUNCTION__, r, g, b, a); - - if (!r) tmp |= S5_WRITEDISABLE_RED; - if (!g) tmp |= S5_WRITEDISABLE_GREEN; - if (!b) tmp |= S5_WRITEDISABLE_BLUE; - if (!a) tmp |= S5_WRITEDISABLE_ALPHA; - - if (tmp != i915->state.Ctx[I915_CTXREG_LIS5]) { - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - i915->state.Ctx[I915_CTXREG_LIS5] = tmp; - } -} - -static void update_specular( GLcontext *ctx ) -{ - /* A hack to trigger the rebuild of the fragment program. - */ - intel_context(ctx)->NewGLState |= _NEW_TEXTURE; - I915_CONTEXT(ctx)->tex_program.translated = 0; -} - -static void i915LightModelfv(GLcontext *ctx, GLenum pname, - const GLfloat *param) -{ - if (INTEL_DEBUG&DEBUG_DRI) - fprintf(stderr, "%s\n", __FUNCTION__); - - if (pname == GL_LIGHT_MODEL_COLOR_CONTROL) { - update_specular( ctx ); - } -} - -static void i915ShadeModel(GLcontext *ctx, GLenum mode) -{ - struct i915_context *i915 = I915_CONTEXT(ctx); - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - - if (mode == GL_SMOOTH) { - i915->state.Ctx[I915_CTXREG_LIS4] &= ~(S4_FLATSHADE_ALPHA | - S4_FLATSHADE_COLOR | - S4_FLATSHADE_SPECULAR); - } else { - i915->state.Ctx[I915_CTXREG_LIS4] |= (S4_FLATSHADE_ALPHA | - S4_FLATSHADE_COLOR | - S4_FLATSHADE_SPECULAR); - } -} - -/* ============================================================= - * Fog - */ -void i915_update_fog( GLcontext *ctx ) -{ - struct i915_context *i915 = I915_CONTEXT(ctx); - GLenum mode; - GLboolean enabled; - GLboolean try_pixel_fog; - - if (ctx->FragmentProgram._Active) { - /* Pull in static fog state from program */ - - mode = ctx->FragmentProgram._Current->FogOption; - enabled = (mode != GL_NONE); - try_pixel_fog = 0; - } - else { - enabled = ctx->Fog.Enabled; - mode = ctx->Fog.Mode; - - try_pixel_fog = (ctx->Fog.FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT && - ctx->Hint.Fog == GL_NICEST && - 0); /* XXX - DISABLE -- Need ortho fallback */ - } - - if (!enabled) { - i915->vertex_fog = I915_FOG_NONE; - } - else if (try_pixel_fog) { - - I915_STATECHANGE(i915, I915_UPLOAD_FOG); - i915->state.Fog[I915_FOGREG_MODE1] &= ~FMC1_FOGFUNC_MASK; - i915->vertex_fog = I915_FOG_PIXEL; - - switch (mode) { - case GL_LINEAR: - if (ctx->Fog.End <= ctx->Fog.Start) { - /* XXX - this won't work with fragment programs. Need to - * either fallback or append fog instructions to end of - * program in the case of linear fog. - */ - i915->state.Fog[I915_FOGREG_MODE1] |= FMC1_FOGFUNC_VERTEX; - i915->vertex_fog = I915_FOG_VERTEX; - } - else { - GLfloat c1 = ctx->Fog.End/(ctx->Fog.End-ctx->Fog.Start); - GLfloat c2 = 1.0/(ctx->Fog.End-ctx->Fog.Start); - - i915->state.Fog[I915_FOGREG_MODE1] &= ~FMC1_C1_MASK; - i915->state.Fog[I915_FOGREG_MODE1] |= FMC1_FOGFUNC_PIXEL_LINEAR; - i915->state.Fog[I915_FOGREG_MODE1] |= - ((GLuint)(c1 * FMC1_C1_ONE)) & FMC1_C1_MASK; - - if (i915->state.Fog[I915_FOGREG_MODE1] & FMC1_FOGINDEX_Z) { - i915->state.Fog[I915_FOGREG_MODE2] = (GLuint)(c2 * FMC2_C2_ONE); - } - else { - union { float f; int i; } fi; - fi.f = c2; - i915->state.Fog[I915_FOGREG_MODE2] = fi.i; - } - } - break; - case GL_EXP: - i915->state.Fog[I915_FOGREG_MODE1] |= FMC1_FOGFUNC_PIXEL_EXP; - break; - case GL_EXP2: - i915->state.Fog[I915_FOGREG_MODE1] |= FMC1_FOGFUNC_PIXEL_EXP2; - break; - default: - break; - } - } - else /* if (i915->vertex_fog != I915_FOG_VERTEX) */ { - I915_STATECHANGE(i915, I915_UPLOAD_FOG); - i915->state.Fog[I915_FOGREG_MODE1] &= ~FMC1_FOGFUNC_MASK; - i915->state.Fog[I915_FOGREG_MODE1] |= FMC1_FOGFUNC_VERTEX; - i915->vertex_fog = I915_FOG_VERTEX; - } - - { - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - I915_ACTIVESTATE(i915, I915_UPLOAD_FOG, enabled); - if (enabled) - i915->state.Ctx[I915_CTXREG_LIS5] |= S5_FOG_ENABLE; - else - i915->state.Ctx[I915_CTXREG_LIS5] &= ~S5_FOG_ENABLE; - } - - if (enabled) { - _tnl_allow_vertex_fog( ctx, (i915->vertex_fog == I915_FOG_VERTEX) ); - _tnl_allow_pixel_fog( ctx, (i915->vertex_fog != I915_FOG_VERTEX) ); - } -} - -static void i915Fogfv(GLcontext *ctx, GLenum pname, const GLfloat *param) -{ - struct i915_context *i915 = I915_CONTEXT(ctx); - - switch (pname) { - case GL_FOG_COORDINATE_SOURCE_EXT: - case GL_FOG_MODE: - case GL_FOG_START: - case GL_FOG_END: - break; - - case GL_FOG_DENSITY: - I915_STATECHANGE(i915, I915_UPLOAD_FOG); - - if (i915->state.Fog[I915_FOGREG_MODE1] & FMC1_FOGINDEX_Z) { - i915->state.Fog[I915_FOGREG_MODE3] = (GLuint)(ctx->Fog.Density * - FMC3_D_ONE); - } - else { - union { float f; int i; } fi; - fi.f = ctx->Fog.Density; - i915->state.Fog[I915_FOGREG_MODE3] = fi.i; - } - break; - - case GL_FOG_COLOR: - I915_STATECHANGE(i915, I915_UPLOAD_FOG); - i915->state.Fog[I915_FOGREG_COLOR] = - (_3DSTATE_FOG_COLOR_CMD | - ((GLubyte)(ctx->Fog.Color[0]*255.0F) << 16) | - ((GLubyte)(ctx->Fog.Color[1]*255.0F) << 8) | - ((GLubyte)(ctx->Fog.Color[2]*255.0F) << 0)); - break; - - default: - break; - } -} - -static void i915Hint(GLcontext *ctx, GLenum target, GLenum state) -{ - switch (target) { - case GL_FOG_HINT: - break; - default: - break; - } -} - -/* ============================================================= - */ - -static void i915Enable(GLcontext *ctx, GLenum cap, GLboolean state) -{ - struct i915_context *i915 = I915_CONTEXT(ctx); - - switch(cap) { - case GL_TEXTURE_2D: - break; - - case GL_LIGHTING: - case GL_COLOR_SUM: - update_specular( ctx ); - break; - - case GL_ALPHA_TEST: - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - if (state) - i915->state.Ctx[I915_CTXREG_LIS6] |= S6_ALPHA_TEST_ENABLE; - else - i915->state.Ctx[I915_CTXREG_LIS6] &= ~S6_ALPHA_TEST_ENABLE; - break; - - case GL_BLEND: - i915EvalLogicOpBlendState(ctx); - break; - - case GL_COLOR_LOGIC_OP: - i915EvalLogicOpBlendState(ctx); - - /* Logicop doesn't seem to work at 16bpp: - */ - if (i915->intel.intelScreen->cpp == 2) /* XXX FBO fix */ - FALLBACK( &i915->intel, I915_FALLBACK_LOGICOP, state ); - break; - - case GL_FRAGMENT_PROGRAM_ARB: - break; - - case GL_DITHER: - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - if (state) - i915->state.Ctx[I915_CTXREG_LIS5] |= S5_COLOR_DITHER_ENABLE; - else - i915->state.Ctx[I915_CTXREG_LIS5] &= ~S5_COLOR_DITHER_ENABLE; - break; - - case GL_DEPTH_TEST: - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - if (state) - i915->state.Ctx[I915_CTXREG_LIS6] |= S6_DEPTH_TEST_ENABLE; - else - i915->state.Ctx[I915_CTXREG_LIS6] &= ~S6_DEPTH_TEST_ENABLE; - - i915DepthMask( ctx, ctx->Depth.Mask ); - break; - - case GL_SCISSOR_TEST: - I915_STATECHANGE(i915, I915_UPLOAD_BUFFERS); - if (state) - i915->state.Buffer[I915_DESTREG_SENABLE] = (_3DSTATE_SCISSOR_ENABLE_CMD | - ENABLE_SCISSOR_RECT); - else - i915->state.Buffer[I915_DESTREG_SENABLE] = (_3DSTATE_SCISSOR_ENABLE_CMD | - DISABLE_SCISSOR_RECT); - break; - - case GL_LINE_SMOOTH: - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - if (state) - i915->state.Ctx[I915_CTXREG_LIS4] |= S4_LINE_ANTIALIAS_ENABLE; - else - i915->state.Ctx[I915_CTXREG_LIS4] &= ~S4_LINE_ANTIALIAS_ENABLE; - break; - - case GL_FOG: - break; - - case GL_CULL_FACE: - i915CullFaceFrontFace(ctx, 0); - break; - - case GL_STENCIL_TEST: - { - GLboolean hw_stencil = GL_FALSE; - if (ctx->DrawBuffer) { - struct intel_renderbuffer *irbStencil - = intel_get_renderbuffer(ctx->DrawBuffer, BUFFER_STENCIL); - hw_stencil = (irbStencil && irbStencil->region); - } - if (hw_stencil) { - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - if (state) - i915->state.Ctx[I915_CTXREG_LIS5] |= (S5_STENCIL_TEST_ENABLE | - S5_STENCIL_WRITE_ENABLE); - else - i915->state.Ctx[I915_CTXREG_LIS5] &= ~(S5_STENCIL_TEST_ENABLE | - S5_STENCIL_WRITE_ENABLE); - } else { - FALLBACK( &i915->intel, I915_FALLBACK_STENCIL, state ); - } - } - break; - - case GL_POLYGON_STIPPLE: - /* The stipple command worked on my 855GM box, but not my 845G. - * I'll do more testing later to find out exactly which hardware - * supports it. Disabled for now. - */ - if (i915->intel.hw_stipple && - i915->intel.reduced_primitive == GL_TRIANGLES) - { - I915_STATECHANGE(i915, I915_UPLOAD_STIPPLE); - if (state) - i915->state.Stipple[I915_STPREG_ST1] |= ST1_ENABLE; - else - i915->state.Stipple[I915_STPREG_ST1] &= ~ST1_ENABLE; - } - break; - - case GL_POLYGON_SMOOTH: - FALLBACK( &i915->intel, I915_FALLBACK_POLYGON_SMOOTH, state ); - break; - - case GL_POINT_SMOOTH: - FALLBACK( &i915->intel, I915_FALLBACK_POINT_SMOOTH, state ); - break; - - default: - ; - } -} - - -static void i915_init_packets( struct i915_context *i915 ) -{ - intelScreenPrivate *screen = i915->intel.intelScreen; - - /* Zero all state */ - memset(&i915->state, 0, sizeof(i915->state)); - - - { - I915_STATECHANGE(i915, I915_UPLOAD_CTX); - /* Probably don't want to upload all this stuff every time one - * piece changes. - */ - i915->state.Ctx[I915_CTXREG_LI] = (_3DSTATE_LOAD_STATE_IMMEDIATE_1 | - I1_LOAD_S(2) | - I1_LOAD_S(4) | - I1_LOAD_S(5) | - I1_LOAD_S(6) | - (4)); - i915->state.Ctx[I915_CTXREG_LIS2] = 0; - i915->state.Ctx[I915_CTXREG_LIS4] = 0; - i915->state.Ctx[I915_CTXREG_LIS5] = 0; - - if (screen->cpp == 2) /* XXX FBO fix */ - i915->state.Ctx[I915_CTXREG_LIS5] |= S5_COLOR_DITHER_ENABLE; - - - i915->state.Ctx[I915_CTXREG_LIS6] = (S6_COLOR_WRITE_ENABLE | - (2 << S6_TRISTRIP_PV_SHIFT)); - - i915->state.Ctx[I915_CTXREG_STATE4] = (_3DSTATE_MODES_4_CMD | - ENABLE_LOGIC_OP_FUNC | - LOGIC_OP_FUNC(LOGICOP_COPY) | - ENABLE_STENCIL_TEST_MASK | - STENCIL_TEST_MASK(0xff) | - ENABLE_STENCIL_WRITE_MASK | - STENCIL_WRITE_MASK(0xff)); - - i915->state.Ctx[I915_CTXREG_IAB] = (_3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD | - IAB_MODIFY_ENABLE | - IAB_MODIFY_FUNC | - IAB_MODIFY_SRC_FACTOR | - IAB_MODIFY_DST_FACTOR); - - i915->state.Ctx[I915_CTXREG_BLENDCOLOR0] = _3DSTATE_CONST_BLEND_COLOR_CMD; - i915->state.Ctx[I915_CTXREG_BLENDCOLOR1] = 0; - - } - - { - I915_STATECHANGE(i915, I915_UPLOAD_STIPPLE); - i915->state.Stipple[I915_STPREG_ST0] = _3DSTATE_STIPPLE; - } - - - { - I915_STATECHANGE(i915, I915_UPLOAD_FOG); - i915->state.Fog[I915_FOGREG_MODE0] = _3DSTATE_FOG_MODE_CMD; - i915->state.Fog[I915_FOGREG_MODE1] = (FMC1_FOGFUNC_MODIFY_ENABLE | - FMC1_FOGFUNC_VERTEX | - FMC1_FOGINDEX_MODIFY_ENABLE | - FMC1_FOGINDEX_W | - FMC1_C1_C2_MODIFY_ENABLE | - FMC1_DENSITY_MODIFY_ENABLE); - i915->state.Fog[I915_FOGREG_COLOR] = _3DSTATE_FOG_COLOR_CMD; - } - - - { - I915_STATECHANGE(i915, I915_UPLOAD_BUFFERS); - /* color buffer offset/stride */ - i915->state.Buffer[I915_DESTREG_CBUFADDR0] = _3DSTATE_BUF_INFO_CMD; - /* XXX FBO: remove this? Also get set in i915_set_draw_region() */ - i915->state.Buffer[I915_DESTREG_CBUFADDR1] = - (BUF_3D_ID_COLOR_BACK | -<<<<<<< i915_state.c - BUF_3D_PITCH(screen->front.pitch) | /* pitch in bytes */ -======= - BUF_3D_PITCH(screen->front.pitch * screen->cpp) | /* XXX FBO fix */ ->>>>>>> 1.7.2.9 - BUF_3D_USE_FENCE); - /*i915->state.Buffer[I915_DESTREG_CBUFADDR2] is the offset */ - -<<<<<<< i915_state.c - - /* depth/Z buffer offset/stride */ -======= ->>>>>>> 1.7.2.9 - i915->state.Buffer[I915_DESTREG_DBUFADDR0] = _3DSTATE_BUF_INFO_CMD; - /* XXX FBO: remove this? Also get set in i915_set_draw_region() */ - i915->state.Buffer[I915_DESTREG_DBUFADDR1] = - (BUF_3D_ID_DEPTH | -<<<<<<< i915_state.c - BUF_3D_PITCH(screen->depth.pitch) | /* pitch in bytes */ -======= - BUF_3D_PITCH(screen->depth.pitch * screen->cpp) | /* XXX FBO fix */ ->>>>>>> 1.7.2.9 - BUF_3D_USE_FENCE); - - i915->state.Buffer[I915_DESTREG_DV0] = _3DSTATE_DST_BUF_VARS_CMD; - -<<<<<<< i915_state.c - /* color/depth pixel format */ -======= - /* XXX FBO: remove this? Also get set in i915_set_draw_region() */ -#if 0 /* seems we don't need this */ ->>>>>>> 1.7.2.9 - switch (screen->fbFormat) { - case DV_PF_565: - i915->state.Buffer[I915_DESTREG_DV1] = (DSTORG_HORT_BIAS(0x8) | /* .5 */ - DSTORG_VERT_BIAS(0x8) | /* .5 */ - LOD_PRECLAMP_OGL | - TEX_DEFAULT_COLOR_OGL | - DITHER_FULL_ALWAYS | - screen->fbFormat | - DEPTH_FRMT_16_FIXED); - break; - case DV_PF_8888: - i915->state.Buffer[I915_DESTREG_DV1] = (DSTORG_HORT_BIAS(0x8) | /* .5 */ - DSTORG_VERT_BIAS(0x8) | /* .5 */ - LOD_PRECLAMP_OGL | - TEX_DEFAULT_COLOR_OGL | - screen->fbFormat | - DEPTH_FRMT_24_FIXED_8_OTHER); - break; - } -<<<<<<< i915_state.c - - /* scissor */ -======= -#endif - ->>>>>>> 1.7.2.9 - i915->state.Buffer[I915_DESTREG_SENABLE] = (_3DSTATE_SCISSOR_ENABLE_CMD | - DISABLE_SCISSOR_RECT); - i915->state.Buffer[I915_DESTREG_SR0] = _3DSTATE_SCISSOR_RECT_0_CMD; - i915->state.Buffer[I915_DESTREG_SR1] = 0; - i915->state.Buffer[I915_DESTREG_SR2] = 0; - } - - -#if 0 - { - I915_STATECHANGE(i915, I915_UPLOAD_DEFAULTS); - i915->state.Default[I915_DEFREG_C0] = _3DSTATE_DEFAULT_DIFFUSE; - i915->state.Default[I915_DEFREG_C1] = 0; - i915->state.Default[I915_DEFREG_S0] = _3DSTATE_DEFAULT_SPECULAR; - i915->state.Default[I915_DEFREG_S1] = 0; - i915->state.Default[I915_DEFREG_Z0] = _3DSTATE_DEFAULT_Z; - i915->state.Default[I915_DEFREG_Z1] = 0; - } -#endif - - - /* These will be emitted every at the head of every buffer, unless - * we get hardware contexts working. - */ - i915->state.active = (I915_UPLOAD_PROGRAM | - I915_UPLOAD_STIPPLE | - I915_UPLOAD_CTX | - I915_UPLOAD_BUFFERS | - I915_UPLOAD_INVARIENT); -} - -void i915InitStateFunctions( struct dd_function_table *functions ) -{ - functions->AlphaFunc = i915AlphaFunc; - functions->BlendColor = i915BlendColor; - functions->BlendEquationSeparate = i915BlendEquationSeparate; - functions->BlendFuncSeparate = i915BlendFuncSeparate; - functions->ColorMask = i915ColorMask; - functions->CullFace = i915CullFaceFrontFace; - functions->DepthFunc = i915DepthFunc; - functions->DepthMask = i915DepthMask; - functions->Enable = i915Enable; - functions->Fogfv = i915Fogfv; - functions->FrontFace = i915CullFaceFrontFace; - functions->Hint = i915Hint; - functions->LightModelfv = i915LightModelfv; - functions->LineWidth = i915LineWidth; - functions->LogicOpcode = i915LogicOp; - functions->PointSize = i915PointSize; - functions->PolygonStipple = i915PolygonStipple; - functions->Scissor = i915Scissor; - functions->ShadeModel = i915ShadeModel; - functions->StencilFuncSeparate = i915StencilFuncSeparate; - functions->StencilMaskSeparate = i915StencilMaskSeparate; - functions->StencilOpSeparate = i915StencilOpSeparate; -} - - -void i915InitState( struct i915_context *i915 ) -{ - GLcontext *ctx = &i915->intel.ctx; - - i915_init_packets( i915 ); - - intelInitState( ctx ); - - memcpy( &i915->initial, &i915->state, sizeof(i915->state) ); - i915->current = &i915->state; -} - - - - - - - diff --git a/src/mesa/drivers/dri/i915-tex/i915_tex.c b/src/mesa/drivers/dri/i915-tex/i915_tex.c deleted file mode 100644 index 6ae92c0b910..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i915_tex.c +++ /dev/null @@ -1,122 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "glheader.h" -#include "mtypes.h" -#include "imports.h" -#include "simple_list.h" -#include "enums.h" -#include "image.h" -#include "texstore.h" -#include "texformat.h" -#include "texmem.h" -#include "swrast/swrast.h" - -#include "mm.h" - -#include "intel_ioctl.h" - -#include "i915_context.h" -#include "i915_reg.h" - - - -static void i915TexEnv( GLcontext *ctx, GLenum target, - GLenum pname, const GLfloat *param ) -{ - struct i915_context *i915 = I915_CONTEXT( ctx ); - - switch (pname) { - case GL_TEXTURE_ENV_COLOR: /* Should be a tracked param */ - case GL_TEXTURE_ENV_MODE: - case GL_COMBINE_RGB: - case GL_COMBINE_ALPHA: - case GL_SOURCE0_RGB: - case GL_SOURCE1_RGB: - case GL_SOURCE2_RGB: - case GL_SOURCE0_ALPHA: - case GL_SOURCE1_ALPHA: - case GL_SOURCE2_ALPHA: - case GL_OPERAND0_RGB: - case GL_OPERAND1_RGB: - case GL_OPERAND2_RGB: - case GL_OPERAND0_ALPHA: - case GL_OPERAND1_ALPHA: - case GL_OPERAND2_ALPHA: - case GL_RGB_SCALE: - case GL_ALPHA_SCALE: - i915->tex_program.translated = 0; - break; - - case GL_TEXTURE_LOD_BIAS: { - GLuint unit = ctx->Texture.CurrentUnit; - GLint b = (int) ((*param) * 16.0); - if (b > 255) b = 255; - if (b < -256) b = -256; - I915_STATECHANGE(i915, I915_UPLOAD_TEX(unit)); - i915->lodbias_ss2[unit] = ((b << SS2_LOD_BIAS_SHIFT) & SS2_LOD_BIAS_MASK); - break; - } - - default: - break; - } -} - - -static void i915BindTexture( GLcontext *ctx, GLenum target, - struct gl_texture_object *texobj ) -{ -<<<<<<< i915_tex.c - i915TextureObjectPtr tex; - - if (!texObj->DriverData) - i915AllocTexObj( texObj ); - - tex = (i915TextureObjectPtr)texObj->DriverData; - - if (tex->lastTarget != texObj->Target) { - tex->intel.dirty = I915_UPLOAD_TEX_ALL; - tex->lastTarget = texObj->Target; - } - -======= ->>>>>>> 1.3.10.2 - /* Need this if image format changes between bound textures. - * Could try and shortcircuit by checking for differences in - * state between incoming and outgoing textures: - */ - I915_CONTEXT(ctx)->tex_program.translated = 0; -} - - - -void i915InitTextureFuncs( struct dd_function_table *functions ) -{ - functions->BindTexture = i915BindTexture; - functions->TexEnv = i915TexEnv; -} diff --git a/src/mesa/drivers/dri/i915-tex/i915_tex_layout.c b/src/mesa/drivers/dri/i915-tex/i915_tex_layout.c deleted file mode 100644 index 3f263597b01..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i915_tex_layout.c +++ /dev/null @@ -1,338 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -/* Code to layout images in a mipmap tree for i915 and i945 - * respectively. - */ - -#include "intel_mipmap_tree.h" -#include "macros.h" - -static GLint initial_offsets[6][2] = { {0,0}, - {0,2}, - {1,0}, - {1,2}, - {1,1}, - {1,3} }; - - -static GLint step_offsets[6][2] = { {0,2}, - {0,2}, - {-1,2}, - {-1,2}, - {-1,1}, - {-1,1} }; - -static GLuint minify( GLuint d ) -{ - return MAX2(1, d>>1); -} - -GLboolean i915_miptree_layout( struct intel_mipmap_tree *mt ) -{ - GLint i; - - switch (mt->target) { - case GL_TEXTURE_CUBE_MAP: { - const GLuint dim = mt->width0; - GLuint face; - - /* double pitch for cube layouts */ - mt->pitch = ((dim * mt->cpp * 2 + 3) & ~3) / mt->cpp; - mt->total_height = dim * 4; - - for ( face = 0 ; face < 6 ; face++) { - GLuint x = initial_offsets[face][0] * dim; - GLuint y = initial_offsets[face][1] * dim; - GLuint d = dim; - - for (i = mt->first_level; i <= mt->last_level; i++) { - intel_miptree_set_image_offset(mt, face, i, - x, y, - d, d, 1); - - if (d == 0) - _mesa_printf("cube mipmap %d/%d (%d..%d) is 0x0\n", - face, i, mt->first_level, mt->last_level); - - d >>= 1; - x += step_offsets[face][0] * d; - y += step_offsets[face][1] * d; - } - } - break; - } - case GL_TEXTURE_3D: { - GLuint width = mt->width0; - GLuint height = mt->height0; - GLuint depth = mt->depth0; - - /* Calculate the size of a single slice. - */ - mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp; - mt->total_height = 0; - - /* XXX: hardware expects/requires 9 levels at minimum. - */ - for ( i = mt->first_level ; i <= MAX2(8, mt->last_level) ; i++ ) { - intel_miptree_set_image_offset(mt, 0, i, - 0, mt->total_height, - width, height, depth); - - mt->total_height += MAX2(2, height); - - width = minify(width); - height = minify(height); - depth = minify(depth); - } - - /* Fixup depth_image_stride: - */ - for ( i = mt->first_level ; i <= mt->last_level ; i++ ) { - mt->offset[0][i].depth_image_stride = mt->total_height * mt->pitch * mt->cpp; - } - - - /* Multiply slice size by texture depth for total size. It's - * remarkable how wasteful of memory the i915 texture layouts - * are. They are largely fixed in the i945. - */ - mt->total_height *= mt->depth0; - break; - } - - default: { - GLuint width = mt->width0; - GLuint height = mt->height0; - - mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp; - mt->total_height = 0; - - for ( i = mt->first_level ; i <= mt->last_level ; i++ ) { - intel_miptree_set_image_offset(mt, 0, i, - 0, mt->total_height, - width, height, 1); - - if (mt->compressed) - mt->total_height += MAX2(1, height/4); - else - mt->total_height += MAX2(2, height); - - width = minify(width); - height = minify(height); - } - break; - } - } - DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, - mt->pitch, - mt->total_height, - mt->cpp, - mt->pitch * mt->total_height * mt->cpp ); - - return GL_TRUE; -} - - -GLboolean i945_miptree_layout( struct intel_mipmap_tree *mt ) -{ - GLint i; - - switch (mt->target) { - case GL_TEXTURE_CUBE_MAP: { - const GLuint dim = mt->width0; - GLuint face; - - /* Depending on the size of the largest images, pitch can be - * determined either by the old-style packing of cubemap faces, - * or the final row of 4x4, 2x2 and 1x1 faces below this. - */ - if (dim > 32) - mt->pitch = ((dim * mt->cpp * 2 + 3) & ~3) / mt->cpp; - else - mt->pitch = 14 * 8; - - mt->total_height = dim * 4 + 4; - - - for ( face = 0 ; face < 6 ; face++) { - GLuint x = initial_offsets[face][0] * dim; - GLuint y = initial_offsets[face][1] * dim; - GLuint d = dim; - - if (dim == 4 && face >= 4) { - y = mt->total_height - 4; - x = (face - 4) * 8; - } - else if (dim < 4) { - y = mt->total_height - 4; - x = face * 8; - } - - for ( i = mt->first_level ; i <= mt->last_level ; i++ ) { - intel_miptree_set_image_offset(mt, face, i, - x, y, - d, d, 1); - - d >>= 1; - - switch (d) { - case 4: - switch (face) { - case FACE_POS_X: - case FACE_NEG_X: - x += step_offsets[face][0] * d; - y += step_offsets[face][1] * d; - break; - case FACE_POS_Y: - case FACE_NEG_Y: - y += 12; - x -= 8; - break; - case FACE_POS_Z: - case FACE_NEG_Z: - y = mt->total_height - 4; - x = (face - 4) * 8; - break; - } - - case 2: - y = mt->total_height - 4; - x = 16 + face * 8; - break; - - case 1: - x += 48; - break; - - default: - x += step_offsets[face][0] * d; - y += step_offsets[face][1] * d; - break; - } - } - } - break; - } - case GL_TEXTURE_3D: { - GLuint width = mt->width0; - GLuint height = mt->height0; - GLuint depth = mt->depth0; - GLuint depth_pack_pitch; - GLuint depth_packing = 0; - - mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp; - mt->total_height = 0; - - depth_pack_pitch = mt->pitch * mt->cpp; - - for ( i = mt->first_level ; i <= mt->last_level ; i++ ) { - - intel_miptree_set_image_offset(mt, 0, i, - 0, mt->total_height, - width, height, depth); - - - - mt->total_height += MAX2(2, height) * MAX2((depth >> depth_packing), 1); - - /* When alignment dominates, can't increase depth packing? - * Or does pitch grow??? What are the alignment constraints, - * anyway? - */ - if (depth_pack_pitch > 4) { - depth_packing++; - depth_pack_pitch >>= 2; /* KW: is this right?? */ - } - - width = minify(width); - height = minify(height); - depth = minify(depth); - - /* XXX: Not sure how 3d textures work on i945 - where did - * t->depth_pitch get set in the old code. Did it ever work? - * Fix up later. - */ - } - break; - } - - case GL_TEXTURE_1D: - case GL_TEXTURE_2D: - case GL_TEXTURE_RECTANGLE_ARB: { - GLuint x = 0; - GLuint y = 0; - GLuint width = mt->width0; - GLuint height = mt->height0; - - mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp; - mt->total_height = 0; - - for ( i = mt->first_level ; i <= mt->last_level ; i++ ) { - intel_miptree_set_image_offset(mt, 0, i, - x, y, - width, height, 1); - - - /* LPT change: step right after second mipmap. - */ - if (i == 1) - x += mt->pitch / 2; - else { - GLuint img_height; - - if (mt->compressed) - img_height = MAX2(1, height/4); - else - img_height = MAX2(2, height); - - y += img_height; - } - - /* Because the images are packed better, the final offset - * might not be the maximal one: - */ - mt->total_height = MAX2(mt->total_height, y); - - width = minify(width); - height = minify(height); - } - break; - } - default: - _mesa_problem(NULL, "Unexpected tex target in i945_miptree_layout()"); - } - - DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, - mt->pitch, - mt->total_height, - mt->cpp, - mt->pitch * mt->total_height * mt->cpp ); - - return GL_TRUE; -} - diff --git a/src/mesa/drivers/dri/i915-tex/i915_texprog.c b/src/mesa/drivers/dri/i915-tex/i915_texprog.c deleted file mode 100644 index 5a84c473473..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i915_texprog.c +++ /dev/null @@ -1,670 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include <strings.h> - -#include "glheader.h" -#include "macros.h" -#include "enums.h" - -#include "tnl/t_context.h" -#include "intel_batchbuffer.h" - -#include "i915_reg.h" -#include "i915_context.h" -#include "i915_program.h" - -static GLuint translate_tex_src_bit( struct i915_fragment_program *p, - GLubyte bit ) -{ - switch (bit) { - case TEXTURE_1D_BIT: return D0_SAMPLE_TYPE_2D; - case TEXTURE_2D_BIT: return D0_SAMPLE_TYPE_2D; - case TEXTURE_RECT_BIT: return D0_SAMPLE_TYPE_2D; - case TEXTURE_3D_BIT: return D0_SAMPLE_TYPE_VOLUME; - case TEXTURE_CUBE_BIT: return D0_SAMPLE_TYPE_CUBE; - default: i915_program_error(p, "TexSrcBit"); return 0; - } -} - -static GLuint get_source( struct i915_fragment_program *p, - GLenum src, GLuint unit ) -{ - switch (src) { - case GL_TEXTURE: - if (p->src_texture == UREG_BAD) { - - /* TODO: Use D0_CHANNEL_XY where possible. - */ - GLuint dim = translate_tex_src_bit( p, p->ctx->Texture.Unit[unit]._ReallyEnabled); - GLuint sampler = i915_emit_decl(p, REG_TYPE_S, unit, dim); - GLuint texcoord = i915_emit_decl(p, REG_TYPE_T, unit, D0_CHANNEL_ALL); - GLuint tmp = i915_get_temp( p ); - GLuint op = T0_TEXLD; - - if (p->VB->TexCoordPtr[unit]->size == 4) - op = T0_TEXLDP; - - p->src_texture = i915_emit_texld( p, tmp, A0_DEST_CHANNEL_ALL, - sampler, texcoord, op ); - } - - return p->src_texture; - - /* Crossbar: */ - case GL_TEXTURE0: - case GL_TEXTURE1: - case GL_TEXTURE2: - case GL_TEXTURE3: - case GL_TEXTURE4: - case GL_TEXTURE5: - case GL_TEXTURE6: - case GL_TEXTURE7: { - return UREG_BAD; - } - - case GL_CONSTANT: - return i915_emit_const4fv( p, p->ctx->Texture.Unit[unit].EnvColor ); - case GL_PRIMARY_COLOR: - return i915_emit_decl(p, REG_TYPE_T, T_DIFFUSE, D0_CHANNEL_ALL); - case GL_PREVIOUS: - default: - i915_emit_decl(p, - GET_UREG_TYPE(p->src_previous), - GET_UREG_NR(p->src_previous), D0_CHANNEL_ALL); - return p->src_previous; - } -} - - -static GLuint emit_combine_source( struct i915_fragment_program *p, - GLuint mask, - GLuint unit, - GLenum source, - GLenum operand ) -{ - GLuint arg, src; - - src = get_source(p, source, unit); - - switch (operand) { - case GL_ONE_MINUS_SRC_COLOR: - /* Get unused tmp, - * Emit tmp = 1.0 + arg.-x-y-z-w - */ - arg = i915_get_temp( p ); - return i915_emit_arith( p, A0_ADD, arg, mask, 0, - swizzle(src, ONE, ONE, ONE, ONE ), - negate(src, 1,1,1,1), 0); - - case GL_SRC_ALPHA: - if (mask == A0_DEST_CHANNEL_W) - return src; - else - return swizzle( src, W, W, W, W ); - case GL_ONE_MINUS_SRC_ALPHA: - /* Get unused tmp, - * Emit tmp = 1.0 + arg.-w-w-w-w - */ - arg = i915_get_temp( p ); - return i915_emit_arith( p, A0_ADD, arg, mask, 0, - swizzle(src, ONE, ONE, ONE, ONE ), - negate( swizzle(src,W,W,W,W), 1,1,1,1), 0); - case GL_SRC_COLOR: - default: - return src; - } -} - - - -static int nr_args( GLenum mode ) -{ - switch (mode) { - case GL_REPLACE: return 1; - case GL_MODULATE: return 2; - case GL_ADD: return 2; - case GL_ADD_SIGNED: return 2; - case GL_INTERPOLATE: return 3; - case GL_SUBTRACT: return 2; - case GL_DOT3_RGB_EXT: return 2; - case GL_DOT3_RGBA_EXT: return 2; - case GL_DOT3_RGB: return 2; - case GL_DOT3_RGBA: return 2; - default: return 0; - } -} - - -static GLboolean args_match( struct gl_texture_unit *texUnit ) -{ - int i, nr = nr_args(texUnit->Combine.ModeRGB); - - for (i = 0 ; i < nr ; i++) { - if (texUnit->Combine.SourceA[i] != texUnit->Combine.SourceRGB[i]) - return GL_FALSE; - - switch(texUnit->Combine.OperandA[i]) { - case GL_SRC_ALPHA: - switch(texUnit->Combine.OperandRGB[i]) { - case GL_SRC_COLOR: - case GL_SRC_ALPHA: - break; - default: - return GL_FALSE; - } - break; - case GL_ONE_MINUS_SRC_ALPHA: - switch(texUnit->Combine.OperandRGB[i]) { - case GL_ONE_MINUS_SRC_COLOR: - case GL_ONE_MINUS_SRC_ALPHA: - break; - default: - return GL_FALSE; - } - break; - default: - return GL_FALSE; /* impossible */ - } - } - - return GL_TRUE; -} - - -static GLuint emit_combine( struct i915_fragment_program *p, - GLuint dest, - GLuint mask, - GLuint saturate, - GLuint unit, - GLenum mode, - const GLenum *source, - const GLenum *operand) -{ - int tmp, src[3], nr = nr_args(mode); - int i; - - for (i = 0; i < nr; i++) - src[i] = emit_combine_source( p, mask, unit, source[i], operand[i] ); - - switch (mode) { - case GL_REPLACE: - if (mask == A0_DEST_CHANNEL_ALL && !saturate) - return src[0]; - else - return i915_emit_arith( p, A0_MOV, dest, mask, saturate, src[0], 0, 0 ); - case GL_MODULATE: - return i915_emit_arith( p, A0_MUL, dest, mask, saturate, - src[0], src[1], 0 ); - case GL_ADD: - return i915_emit_arith( p, A0_ADD, dest, mask, saturate, - src[0], src[1], 0 ); - case GL_ADD_SIGNED: - /* tmp = arg0 + arg1 - * result = tmp + -.5 - */ - tmp = i915_emit_const1f(p, .5); - tmp = negate(swizzle(tmp,X,X,X,X),1,1,1,1); - i915_emit_arith( p, A0_ADD, dest, mask, 0, src[0], src[1], 0 ); - i915_emit_arith( p, A0_ADD, dest, mask, saturate, dest, tmp, 0 ); - return dest; - case GL_INTERPOLATE: /* TWO INSTRUCTIONS */ - /* Arg0 * (Arg2) + Arg1 * (1-Arg2) - * - * Arg0*Arg2 + Arg1 - Arg1Arg2 - * - * tmp = Arg0*Arg2 + Arg1, - * result = (-Arg1)Arg2 + tmp - */ - tmp = i915_get_temp( p ); - i915_emit_arith( p, A0_MAD, tmp, mask, 0, src[0], src[2], src[1] ); - i915_emit_arith( p, A0_MAD, dest, mask, saturate, - negate(src[1], 1,1,1,1), src[2], tmp ); - return dest; - case GL_SUBTRACT: - /* negate src[1] */ - return i915_emit_arith( p, A0_ADD, dest, mask, saturate, src[0], - negate(src[1],1,1,1,1), 0 ); - - case GL_DOT3_RGBA: - case GL_DOT3_RGBA_EXT: - case GL_DOT3_RGB_EXT: - case GL_DOT3_RGB: { - GLuint tmp0 = i915_get_temp( p ); - GLuint tmp1 = i915_get_temp( p ); - GLuint neg1 = negate(swizzle(i915_emit_const1f(p, 1),X,X,X,X), 1,1,1,1); - GLuint two = swizzle(i915_emit_const1f(p, 2),X,X,X,X); - i915_emit_arith( p, A0_MAD, tmp0, A0_DEST_CHANNEL_ALL, 0, - two, src[0], neg1); - if (src[0] == src[1]) - tmp1 = tmp0; - else - i915_emit_arith( p, A0_MAD, tmp1, A0_DEST_CHANNEL_ALL, 0, - two, src[1], neg1); - i915_emit_arith( p, A0_DP3, dest, mask, saturate, tmp0, tmp1, 0); - return dest; - } - - default: - return src[0]; - } -} - -static GLuint get_dest( struct i915_fragment_program *p, int unit ) -{ - if (p->ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) - return i915_get_temp( p ); - else if (unit != p->last_tex_stage) - return i915_get_temp( p ); - else - return UREG(REG_TYPE_OC, 0); -} - - - -static GLuint emit_texenv( struct i915_fragment_program *p, int unit ) -{ - struct gl_texture_unit *texUnit = &p->ctx->Texture.Unit[unit]; - GLenum envMode = texUnit->EnvMode; - struct gl_texture_object *tObj = texUnit->_Current; - GLenum format = tObj->Image[0][tObj->BaseLevel]->_BaseFormat; - GLuint saturate = unit < p->last_tex_stage ? A0_DEST_SATURATE : 0; - - switch(envMode) { - case GL_BLEND: { - const int cf = get_source(p, GL_PREVIOUS, unit); - const int cc = get_source(p, GL_CONSTANT, unit); - const int cs = get_source(p, GL_TEXTURE, unit); - const int out = get_dest(p, unit); - - if (format == GL_INTENSITY) { - /* cv = cf(1 - cs) + cc.cs - * cv = cf - cf.cs + cc.cs - */ - /* u[2] = MAD( -cf * cs + cf ) - * cv = MAD( cc * cs + u[2] ) - */ - - i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, 0, - negate(cf,1,1,1,1), cs, cf ); - - i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, saturate, - cc, cs, out ); - - return out; - } else { - /* cv = cf(1 - cs) + cc.cs - * cv = cf - cf.cs + cc.cs - * av = af.as - */ - /* u[2] = MAD( cf.-x-y-zw * cs.xyzw + cf.xyz0 ) - * oC = MAD( cc.xyz0 * cs.xyz0 + u[2].xyzw ) - */ - i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, 0, - negate(cf,1,1,1,0), - cs, - swizzle(cf,X,Y,Z,ZERO) ); - - - i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, saturate, - swizzle(cc,X,Y,Z,ZERO), - swizzle(cs,X,Y,Z,ZERO), - out ); - - return out; - } - } - - case GL_DECAL: { - if (format == GL_RGB || - format == GL_RGBA) { - int cf = get_source( p, GL_PREVIOUS, unit ); - int cs = get_source( p, GL_TEXTURE, unit ); - int out = get_dest(p, unit); - - /* cv = cf(1-as) + cs.as - * cv = cf.(-as) + cf + cs.as - * av = af - */ - - /* u[2] = mad( cf.xyzw * cs.-w-w-w1 + cf.xyz0 ) - * oc = mad( cs.xyz0 * cs.www0 + u[2].xyzw ) - */ - i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, 0, - cf, - negate(swizzle(cs,W,W,W,ONE),1,1,1,0), - swizzle(cf,X,Y,Z,ZERO) ); - - i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, saturate, - swizzle(cs,X,Y,Z,ZERO), - swizzle(cs,W,W,W,ZERO), - out ); - return out; - } - else { - return get_source( p, GL_PREVIOUS, unit ); - } - } - - case GL_REPLACE: { - const int cs = get_source( p, GL_TEXTURE, unit ); /* saturated */ - switch (format) { - case GL_ALPHA: { - const int cf = get_source( p, GL_PREVIOUS, unit ); /* saturated */ - i915_emit_arith( p, A0_MOV, cs, A0_DEST_CHANNEL_XYZ, 0, cf, 0, 0 ); - return cs; - } - case GL_RGB: - case GL_LUMINANCE: { - const int cf = get_source( p, GL_PREVIOUS, unit ); /* saturated */ - i915_emit_arith( p, A0_MOV, cs, A0_DEST_CHANNEL_W, 0, cf, 0, 0 ); - return cs; - } - default: - return cs; - } - } - - case GL_MODULATE: { - const int cf = get_source( p, GL_PREVIOUS, unit ); - const int cs = get_source( p, GL_TEXTURE, unit ); - const int out = get_dest(p, unit); - switch (format) { - case GL_ALPHA: - i915_emit_arith( p, A0_MUL, out, A0_DEST_CHANNEL_ALL, saturate, - swizzle(cs, ONE, ONE, ONE, W), cf, 0 ); - break; - default: - i915_emit_arith( p, A0_MUL, out, A0_DEST_CHANNEL_ALL, saturate, - cs, cf, 0 ); - break; - } - return out; - } - case GL_ADD: { - int cf = get_source( p, GL_PREVIOUS, unit ); - int cs = get_source( p, GL_TEXTURE, unit ); - const int out = get_dest( p, unit ); - - if (format == GL_INTENSITY) { - /* output-color.rgba = add( incoming, u[1] ) - */ - i915_emit_arith( p, A0_ADD, out, A0_DEST_CHANNEL_ALL, saturate, - cs, cf, 0 ); - return out; - } - else { - /* cv.xyz = cf.xyz + cs.xyz - * cv.w = cf.w * cs.w - * - * cv.xyzw = MAD( cf.111w * cs.xyzw + cf.xyz0 ) - */ - i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, saturate, - swizzle(cf,ONE,ONE,ONE,W), - cs, - swizzle(cf,X,Y,Z,ZERO) ); - return out; - } - break; - } - case GL_COMBINE: { - GLuint rgb_shift, alpha_shift, out, shift; - GLuint dest = get_dest(p, unit); - - /* The EXT version of the DOT3 extension does not support the - * scale factor, but the ARB version (and the version in OpenGL - * 1.3) does. - */ - switch (texUnit->Combine.ModeRGB) { - case GL_DOT3_RGB_EXT: - alpha_shift = texUnit->Combine.ScaleShiftA; - rgb_shift = 0; - break; - - case GL_DOT3_RGBA_EXT: - alpha_shift = 0; - rgb_shift = 0; - break; - - default: - rgb_shift = texUnit->Combine.ScaleShiftRGB; - alpha_shift = texUnit->Combine.ScaleShiftA; - break; - } - - - /* Emit the RGB and A combine ops - */ - if (texUnit->Combine.ModeRGB == texUnit->Combine.ModeA && - args_match( texUnit )) { - out = emit_combine( p, dest, A0_DEST_CHANNEL_ALL, saturate, - unit, - texUnit->Combine.ModeRGB, - texUnit->Combine.SourceRGB, - texUnit->Combine.OperandRGB ); - } - else if (texUnit->Combine.ModeRGB == GL_DOT3_RGBA_EXT || - texUnit->Combine.ModeRGB == GL_DOT3_RGBA) { - - out = emit_combine( p, dest, A0_DEST_CHANNEL_ALL, saturate, - unit, - texUnit->Combine.ModeRGB, - texUnit->Combine.SourceRGB, - texUnit->Combine.OperandRGB ); - } - else { - /* Need to do something to stop from re-emitting identical - * argument calculations here: - */ - out = emit_combine( p, dest, A0_DEST_CHANNEL_XYZ, saturate, - unit, - texUnit->Combine.ModeRGB, - texUnit->Combine.SourceRGB, - texUnit->Combine.OperandRGB ); - out = emit_combine( p, dest, A0_DEST_CHANNEL_W, saturate, - unit, - texUnit->Combine.ModeA, - texUnit->Combine.SourceA, - texUnit->Combine.OperandA ); - } - - /* Deal with the final shift: - */ - if (alpha_shift || rgb_shift) { - if (rgb_shift == alpha_shift) { - shift = i915_emit_const1f(p, 1<<rgb_shift); - shift = swizzle(shift,X,X,X,X); - } - else { - shift = i915_emit_const2f(p, 1<<rgb_shift, 1<<alpha_shift); - shift = swizzle(shift,X,X,X,Y); - } - return i915_emit_arith( p, A0_MUL, dest, A0_DEST_CHANNEL_ALL, - saturate, out, shift, 0 ); - } - - return out; - } - - default: - return get_source(p, GL_PREVIOUS, 0); - } -} - -static void emit_program_fini( struct i915_fragment_program *p ) -{ - int cf = get_source( p, GL_PREVIOUS, 0 ); - int out = UREG( REG_TYPE_OC, 0 ); - - if (p->ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) { - /* Emit specular add. - */ - GLuint s = i915_emit_decl(p, REG_TYPE_T, T_SPECULAR, D0_CHANNEL_ALL); - i915_emit_arith( p, A0_ADD, out, A0_DEST_CHANNEL_ALL, 0, cf, - swizzle(s, X,Y,Z,ZERO), 0 ); - } - else if (cf != out) { - /* Will wind up in here if no texture enabled or a couple of - * other scenarios (GL_REPLACE for instance). - */ - i915_emit_arith( p, A0_MOV, out, A0_DEST_CHANNEL_ALL, 0, cf, 0, 0 ); - } -} - - -static void i915EmitTextureProgram( struct i915_context *i915 ) -{ - GLcontext *ctx = &i915->intel.ctx; - struct i915_fragment_program *p = &i915->tex_program; - GLuint unit; - - if (0) fprintf(stderr, "%s\n", __FUNCTION__); - - i915_init_program( i915, p ); - - if (ctx->Texture._EnabledUnits) { - for (unit = 0 ; unit < ctx->Const.MaxTextureUnits ; unit++) - if (ctx->Texture.Unit[unit]._ReallyEnabled) { - p->last_tex_stage = unit; - } - - for (unit = 0 ; unit < ctx->Const.MaxTextureUnits; unit++) - if (ctx->Texture.Unit[unit]._ReallyEnabled) { - p->src_previous = emit_texenv( p, unit ); - p->src_texture = UREG_BAD; - p->temp_flag = 0xffff000; - p->temp_flag |= 1 << GET_UREG_NR(p->src_previous); - } - } - - emit_program_fini( p ); - - i915_fini_program( p ); - i915_upload_program( i915, p ); - - p->translated = 1; -} - - -void i915ValidateTextureProgram( struct i915_context *i915 ) -{ - struct intel_context *intel = &i915->intel; - GLcontext *ctx = &intel->ctx; - TNLcontext *tnl = TNL_CONTEXT(ctx); - struct vertex_buffer *VB = &tnl->vb; - GLuint index = tnl->render_inputs; - int i, offset; - GLuint s4 = i915->state.Ctx[I915_CTXREG_LIS4] & ~S4_VFMT_MASK; - GLuint s2 = S2_TEXCOORD_NONE; - - /* Important: - */ - VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr; - intel->vertex_attr_count = 0; - intel->coloroffset = 0; - intel->specoffset = 0; - offset = 0; - - if (i915->vertex_fog == I915_FOG_PIXEL) { - EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, S4_VFMT_XYZW, 16 ); - index &= ~_TNL_BIT_FOG; - } - else if (index & _TNL_BITS_TEX_ANY) { - EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, S4_VFMT_XYZW, 16 ); - } - else { - EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_3F_VIEWPORT, S4_VFMT_XYZ, 12 ); - } - - /* How undefined is undefined? */ - if (index & _TNL_BIT_POINTSIZE) { - EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F, S4_VFMT_POINT_WIDTH, 4 ); - } - - intel->coloroffset = offset / 4; - EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA, S4_VFMT_COLOR, 4 ); - - if (index & (_TNL_BIT_COLOR1|_TNL_BIT_FOG)) { - if (index & _TNL_BIT_COLOR1) { - intel->specoffset = offset / 4; - EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, S4_VFMT_SPEC_FOG, 3 ); - } else - EMIT_PAD( 3 ); - - if (index & _TNL_BIT_FOG) - EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, S4_VFMT_SPEC_FOG, 1 ); - else - EMIT_PAD( 1 ); - } - - if (index & _TNL_BITS_TEX_ANY) { - for (i = 0; i < 8; i++) { - if (index & _TNL_BIT_TEX(i)) { - int sz = VB->TexCoordPtr[i]->size; - - s2 &= ~S2_TEXCOORD_FMT(i, S2_TEXCOORD_FMT0_MASK); - s2 |= S2_TEXCOORD_FMT(i, SZ_TO_HW(sz)); - - EMIT_ATTR( _TNL_ATTRIB_TEX0+i, EMIT_SZ(sz), 0, sz * 4 ); - } - } - } - - /* Only need to change the vertex emit code if there has been a - * statechange to a new hardware vertex format: - */ - if (s2 != i915->state.Ctx[I915_CTXREG_LIS2] || - s4 != i915->state.Ctx[I915_CTXREG_LIS4]) { - int k; - - I915_STATECHANGE( i915, I915_UPLOAD_CTX ); - - i915->tex_program.translated = 0; - - /* Must do this *after* statechange, so as not to affect - * buffered vertices reliant on the old state: - */ - intel->vertex_size = _tnl_install_attrs( ctx, - intel->vertex_attrs, - intel->vertex_attr_count, - intel->ViewportMatrix.m, 0 ); - - intel->vertex_size >>= 2; - - i915->state.Ctx[I915_CTXREG_LIS2] = s2; - i915->state.Ctx[I915_CTXREG_LIS4] = s4; - - k = intel->vtbl.check_vertex_size( intel, intel->vertex_size ); - assert(k); - } - - if (!i915->tex_program.translated || - i915->last_ReallyEnabled != ctx->Texture._EnabledUnits) { - i915EmitTextureProgram( i915 ); - i915->last_ReallyEnabled = ctx->Texture._EnabledUnits; - } -} diff --git a/src/mesa/drivers/dri/i915-tex/i915_texstate.c b/src/mesa/drivers/dri/i915-tex/i915_texstate.c deleted file mode 100644 index 17c1b7a3a69..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i915_texstate.c +++ /dev/null @@ -1,354 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "mtypes.h" -#include "enums.h" -#include "texformat.h" - -#include "intel_mipmap_tree.h" -#include "intel_tex.h" - -#include "i915_context.h" -#include "i915_reg.h" - - -static GLuint translate_texture_format( GLuint mesa_format ) -{ - switch (mesa_format) { - case MESA_FORMAT_L8: - return MAPSURF_8BIT | MT_8BIT_L8; - case MESA_FORMAT_I8: - return MAPSURF_8BIT | MT_8BIT_I8; - case MESA_FORMAT_A8: - return MAPSURF_8BIT | MT_8BIT_A8; - case MESA_FORMAT_AL88: - return MAPSURF_16BIT | MT_16BIT_AY88; - case MESA_FORMAT_RGB565: - return MAPSURF_16BIT | MT_16BIT_RGB565; - case MESA_FORMAT_ARGB1555: - return MAPSURF_16BIT | MT_16BIT_ARGB1555; - case MESA_FORMAT_ARGB4444: - return MAPSURF_16BIT | MT_16BIT_ARGB4444; - case MESA_FORMAT_ARGB8888: - return MAPSURF_32BIT | MT_32BIT_ARGB8888; - case MESA_FORMAT_YCBCR_REV: - return (MAPSURF_422 | MT_422_YCRCB_NORMAL); - case MESA_FORMAT_YCBCR: - return (MAPSURF_422 | MT_422_YCRCB_SWAPY); - case MESA_FORMAT_RGB_FXT1: - case MESA_FORMAT_RGBA_FXT1: - return (MAPSURF_COMPRESSED | MT_COMPRESS_FXT1); - case MESA_FORMAT_DEPTH_COMPONENT16: - return (MAPSURF_16BIT | MT_16BIT_L16); - case MESA_FORMAT_RGBA_DXT1: - case MESA_FORMAT_RGB_DXT1: - return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT1); - case MESA_FORMAT_RGBA_DXT3: - return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT2_3); - case MESA_FORMAT_RGBA_DXT5: - return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT4_5); - default: - fprintf(stderr, "%s: bad image format %x\n", __FUNCTION__, - mesa_format); - abort(); - return 0; - } -} - - -<<<<<<< i915_texstate.c - if (i915->intel.intelScreen->deviceID == PCI_CHIP_I945_G || - i915->intel.intelScreen->deviceID == PCI_CHIP_I945_GM) - i945LayoutTextureImages( i915, tObj ); - else - i915LayoutTextureImages( i915, tObj ); - - t->Setup[I915_TEXREG_MS3] = - (((tObj->Image[0][t->intel.base.firstLevel]->Height - 1) << MS3_HEIGHT_SHIFT) | - ((tObj->Image[0][t->intel.base.firstLevel]->Width - 1) << MS3_WIDTH_SHIFT) | - textureFormat | - MS3_USE_FENCE_REGS); - - t->Setup[I915_TEXREG_MS4] = - ((((t->intel.Pitch / 4) - 1) << MS4_PITCH_SHIFT) | - MS4_CUBE_FACE_ENA_MASK | - (((t->intel.max_level * 4)) << MS4_MAX_LOD_SHIFT) | - ((tObj->Image[0][t->intel.base.firstLevel]->Depth - 1) << MS4_VOLUME_DEPTH_SHIFT)); - - t->Setup[I915_TEXREG_SS2] &= ~(SS2_COLORSPACE_CONVERSION); - t->Setup[I915_TEXREG_SS2] |= ss2; - - t->intel.dirty = I915_UPLOAD_TEX_ALL; - -} -======= ->>>>>>> 1.9.2.9 - - -/* The i915 (and related graphics cores) do not support GL_CLAMP. The - * Intel drivers for "other operating systems" implement GL_CLAMP as - * GL_CLAMP_TO_EDGE, so the same is done here. - */ -static GLuint translate_wrap_mode( GLenum wrap ) -{ - switch( wrap ) { - case GL_REPEAT: - return TEXCOORDMODE_WRAP; - case GL_CLAMP: - return TEXCOORDMODE_CLAMP_EDGE; /* not quite correct */ - case GL_CLAMP_TO_EDGE: - return TEXCOORDMODE_CLAMP_EDGE; - case GL_CLAMP_TO_BORDER: - return TEXCOORDMODE_CLAMP_BORDER; - case GL_MIRRORED_REPEAT: - return TEXCOORDMODE_MIRROR; - default: - return TEXCOORDMODE_WRAP; - } -} - - - -/* Recalculate all state from scratch. Perhaps not the most - * efficient, but this has gotten complex enough that we need - * something which is understandable and reliable. - */ -static GLboolean i915_update_tex_unit( struct intel_context *intel, - GLuint unit, - GLuint ss3 ) -{ - GLcontext *ctx = &intel->ctx; - struct i915_context *i915 = i915_context(ctx); - struct gl_texture_object *tObj = ctx->Texture.Unit[unit]._Current; - struct intel_texture_object *intelObj = intel_texture_object(tObj); - struct gl_texture_image *firstImage; - GLuint *state = i915->state.Tex[unit]; - - memset(state, 0, sizeof(state)); - -/* intel_region_release(intel, &i915->state.tex_region[unit]); */ - - if (!intel_finalize_mipmap_tree(intel, unit)) - return GL_FALSE; - - /* Get first image here, since intelObj->firstLevel will get set in - * the intel_finalize_mipmap_tree() call above. - */ - firstImage = tObj->Image[0][intelObj->firstLevel]; - -/* intel_region_reference(&i915->state.tex_region[unit], */ -/* intelObj->mt->region); */ - - i915->state.tex_buffer[unit] = intelObj->mt->region->buffer; - i915->state.tex_offset[unit] = intel_miptree_image_offset(intelObj->mt, 0, - intelObj->firstLevel); - - - state[I915_TEXREG_MS3] = - (((firstImage->Height - 1) << MS3_HEIGHT_SHIFT) | - ((firstImage->Width - 1) << MS3_WIDTH_SHIFT) | - translate_texture_format( firstImage->TexFormat->MesaFormat ) | - MS3_USE_FENCE_REGS); - - state[I915_TEXREG_MS4] = - (((((intelObj->mt->pitch * intelObj->mt->cpp) / 4) - 1) << MS4_PITCH_SHIFT) | - MS4_CUBE_FACE_ENA_MASK | - ((((intelObj->lastLevel - intelObj->firstLevel) * 4)) << MS4_MAX_LOD_SHIFT) | - ((firstImage->Depth - 1) << MS4_VOLUME_DEPTH_SHIFT)); - - - { - GLuint minFilt, mipFilt, magFilt; - - switch (tObj->MinFilter) { - case GL_NEAREST: - minFilt = FILTER_NEAREST; - mipFilt = MIPFILTER_NONE; - break; - case GL_LINEAR: - minFilt = FILTER_LINEAR; - mipFilt = MIPFILTER_NONE; - break; - case GL_NEAREST_MIPMAP_NEAREST: - minFilt = FILTER_NEAREST; - mipFilt = MIPFILTER_NEAREST; - break; - case GL_LINEAR_MIPMAP_NEAREST: - minFilt = FILTER_LINEAR; - mipFilt = MIPFILTER_NEAREST; - break; - case GL_NEAREST_MIPMAP_LINEAR: - minFilt = FILTER_NEAREST; - mipFilt = MIPFILTER_LINEAR; - break; - case GL_LINEAR_MIPMAP_LINEAR: - minFilt = FILTER_LINEAR; - mipFilt = MIPFILTER_LINEAR; - break; - default: - return GL_FALSE; - } - - if ( tObj->MaxAnisotropy > 1.0 ) { - minFilt = FILTER_ANISOTROPIC; - magFilt = FILTER_ANISOTROPIC; - } - else { - switch (tObj->MagFilter) { - case GL_NEAREST: - magFilt = FILTER_NEAREST; - break; - case GL_LINEAR: - magFilt = FILTER_LINEAR; - break; - default: - return GL_FALSE; - } - } - - state[I915_TEXREG_SS2] = i915->lodbias_ss2[unit]; - - /* YUV conversion: - */ - if (firstImage->TexFormat->MesaFormat == MESA_FORMAT_YCBCR || - firstImage->TexFormat->MesaFormat == MESA_FORMAT_YCBCR_REV) - state[I915_TEXREG_SS2] |= SS2_COLORSPACE_CONVERSION; - - /* Shadow: - */ - if (tObj->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB && - tObj->Target != GL_TEXTURE_3D) { - - state[I915_TEXREG_SS2] |= - (SS2_SHADOW_ENABLE | - intel_translate_compare_func( tObj->CompareFunc )); - - minFilt = FILTER_4X4_FLAT; - magFilt = FILTER_4X4_FLAT; - } - - state[I915_TEXREG_SS2] |= ((minFilt << SS2_MIN_FILTER_SHIFT) | - (mipFilt << SS2_MIP_FILTER_SHIFT) | - (magFilt << SS2_MAG_FILTER_SHIFT)); - } - - { - GLenum ws = tObj->WrapS; - GLenum wt = tObj->WrapT; - GLenum wr = tObj->WrapR; - - - /* 3D textures don't seem to respect the border color. - * Fallback if there's ever a danger that they might refer to - * it. - * - * Effectively this means fallback on 3D clamp or - * clamp_to_border. - */ - if (tObj->Target == GL_TEXTURE_3D && - (tObj->MinFilter != GL_NEAREST || - tObj->MagFilter != GL_NEAREST) && - (ws == GL_CLAMP || - wt == GL_CLAMP || - wr == GL_CLAMP || - ws == GL_CLAMP_TO_BORDER || - wt == GL_CLAMP_TO_BORDER || - wr == GL_CLAMP_TO_BORDER)) - return GL_FALSE; - - - state[I915_TEXREG_SS3] = ss3; /* SS3_NORMALIZED_COORDS */ - - state[I915_TEXREG_SS3] |= ((translate_wrap_mode(ws) << SS3_TCX_ADDR_MODE_SHIFT) | - (translate_wrap_mode(wt) << SS3_TCY_ADDR_MODE_SHIFT) | - (translate_wrap_mode(wr) << SS3_TCZ_ADDR_MODE_SHIFT)); - - state[I915_TEXREG_SS3] |= (unit << SS3_TEXTUREMAP_INDEX_SHIFT); - } - - - state[I915_TEXREG_SS4] = INTEL_PACKCOLOR8888(tObj->_BorderChan[0], - tObj->_BorderChan[1], - tObj->_BorderChan[2], - tObj->_BorderChan[3]); - - - I915_ACTIVESTATE(i915, I915_UPLOAD_TEX(unit), GL_TRUE); - /* memcmp was already disabled, but definitely won't work as the - * region might now change and that wouldn't be detected: - */ - I915_STATECHANGE( i915, I915_UPLOAD_TEX(unit) ); - - -#if 0 - DBG(TEXTURE, "state[I915_TEXREG_SS2] = 0x%x\n", state[I915_TEXREG_SS2]); - DBG(TEXTURE, "state[I915_TEXREG_SS3] = 0x%x\n", state[I915_TEXREG_SS3]); - DBG(TEXTURE, "state[I915_TEXREG_SS4] = 0x%x\n", state[I915_TEXREG_SS4]); - DBG(TEXTURE, "state[I915_TEXREG_MS2] = 0x%x\n", state[I915_TEXREG_MS2]); - DBG(TEXTURE, "state[I915_TEXREG_MS3] = 0x%x\n", state[I915_TEXREG_MS3]); - DBG(TEXTURE, "state[I915_TEXREG_MS4] = 0x%x\n", state[I915_TEXREG_MS4]); -#endif - - return GL_TRUE; -} - - - - -void i915UpdateTextureState( struct intel_context *intel ) -{ - GLboolean ok = GL_TRUE; - GLuint i; - - for (i = 0 ; i < I915_TEX_UNITS && ok ; i++) { - switch (intel->ctx.Texture.Unit[i]._ReallyEnabled) { - case TEXTURE_1D_BIT: - case TEXTURE_2D_BIT: - case TEXTURE_CUBE_BIT: - case TEXTURE_3D_BIT: - ok = i915_update_tex_unit( intel, i, SS3_NORMALIZED_COORDS ); - break; - case TEXTURE_RECT_BIT: - ok = i915_update_tex_unit( intel, i, 0 ); - break; - case 0: { - struct i915_context *i915 = i915_context(&intel->ctx); - if (i915->state.active & I915_UPLOAD_TEX(i)) - I915_ACTIVESTATE(i915, I915_UPLOAD_TEX(i), GL_FALSE); - break; - } - default: - ok = GL_FALSE; - break; - } - } - - FALLBACK( intel, I915_FALLBACK_TEXTURE, !ok ); -} - - - diff --git a/src/mesa/drivers/dri/i915-tex/i915_vtbl.c b/src/mesa/drivers/dri/i915-tex/i915_vtbl.c deleted file mode 100644 index 1c56422a579..00000000000 --- a/src/mesa/drivers/dri/i915-tex/i915_vtbl.c +++ /dev/null @@ -1,572 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - - - -#include "glheader.h" -#include "mtypes.h" -#include "imports.h" -#include "macros.h" -#include "colormac.h" - -#include "tnl/t_context.h" -#include "tnl/t_vertex.h" - -#include "intel_batchbuffer.h" -#include "intel_tex.h" -#include "intel_regions.h" - -#include "i915_reg.h" -#include "i915_context.h" - -static void i915_render_start( struct intel_context *intel ) -{ - GLcontext *ctx = &intel->ctx; - struct i915_context *i915 = i915_context(&intel->ctx); - - if (ctx->FragmentProgram._Active) - i915ValidateFragmentProgram( i915 ); - else - i915ValidateTextureProgram( i915 ); -} - - -static void i915_reduced_primitive_state( struct intel_context *intel, - GLenum rprim ) -{ - struct i915_context *i915 = i915_context(&intel->ctx); - GLuint st1 = i915->state.Stipple[I915_STPREG_ST1]; - - st1 &= ~ST1_ENABLE; - - switch (rprim) { - case GL_TRIANGLES: - if (intel->ctx.Polygon.StippleFlag && - intel->hw_stipple) - st1 |= ST1_ENABLE; - break; - case GL_LINES: - case GL_POINTS: - default: - break; - } - - i915->intel.reduced_primitive = rprim; - - if (st1 != i915->state.Stipple[I915_STPREG_ST1]) { - I915_STATECHANGE(i915, I915_UPLOAD_STIPPLE); - i915->state.Stipple[I915_STPREG_ST1] = st1; - } -} - - -/* Pull apart the vertex format registers and figure out how large a - * vertex is supposed to be. - */ -static GLboolean i915_check_vertex_size( struct intel_context *intel, - GLuint expected ) -{ - struct i915_context *i915 = i915_context(&intel->ctx); - int lis2 = i915->current->Ctx[I915_CTXREG_LIS2]; - int lis4 = i915->current->Ctx[I915_CTXREG_LIS4]; - int i, sz = 0; - - switch (lis4 & S4_VFMT_XYZW_MASK) { - case S4_VFMT_XY: sz = 2; break; - case S4_VFMT_XYZ: sz = 3; break; - case S4_VFMT_XYW: sz = 3; break; - case S4_VFMT_XYZW: sz = 4; break; - default: - fprintf(stderr, "no xyzw specified\n"); - return 0; - } - - if (lis4 & S4_VFMT_SPEC_FOG) sz++; - if (lis4 & S4_VFMT_COLOR) sz++; - if (lis4 & S4_VFMT_DEPTH_OFFSET) sz++; - if (lis4 & S4_VFMT_POINT_WIDTH) sz++; - if (lis4 & S4_VFMT_FOG_PARAM) sz++; - - for (i = 0 ; i < 8 ; i++) { - switch (lis2 & S2_TEXCOORD_FMT0_MASK) { - case TEXCOORDFMT_2D: sz += 2; break; - case TEXCOORDFMT_3D: sz += 3; break; - case TEXCOORDFMT_4D: sz += 4; break; - case TEXCOORDFMT_1D: sz += 1; break; - case TEXCOORDFMT_2D_16: sz += 1; break; - case TEXCOORDFMT_4D_16: sz += 2; break; - case TEXCOORDFMT_NOT_PRESENT: break; - default: - fprintf(stderr, "bad texcoord fmt %d\n", i); - return GL_FALSE; - } - lis2 >>= S2_TEXCOORD_FMT1_SHIFT; - } - - if (sz != expected) - fprintf(stderr, "vertex size mismatch %d/%d\n", sz, expected); - - return sz == expected; -} - - -static void i915_emit_invarient_state( struct intel_context *intel ) -{ - BATCH_LOCALS; - - BEGIN_BATCH( 200, 0 ); - - OUT_BATCH(_3DSTATE_AA_CMD | - AA_LINE_ECAAR_WIDTH_ENABLE | - AA_LINE_ECAAR_WIDTH_1_0 | - AA_LINE_REGION_WIDTH_ENABLE | - AA_LINE_REGION_WIDTH_1_0); - - OUT_BATCH(_3DSTATE_DFLT_DIFFUSE_CMD); - OUT_BATCH(0); - - OUT_BATCH(_3DSTATE_DFLT_SPEC_CMD); - OUT_BATCH(0); - - OUT_BATCH(_3DSTATE_DFLT_Z_CMD); - OUT_BATCH(0); - - /* Don't support texture crossbar yet */ - OUT_BATCH(_3DSTATE_COORD_SET_BINDINGS | - CSB_TCB(0, 0) | - CSB_TCB(1, 1) | - CSB_TCB(2, 2) | - CSB_TCB(3, 3) | - CSB_TCB(4, 4) | - CSB_TCB(5, 5) | - CSB_TCB(6, 6) | - CSB_TCB(7, 7)); - - OUT_BATCH(_3DSTATE_RASTER_RULES_CMD | - ENABLE_POINT_RASTER_RULE | - OGL_POINT_RASTER_RULE | - ENABLE_LINE_STRIP_PROVOKE_VRTX | - ENABLE_TRI_FAN_PROVOKE_VRTX | - LINE_STRIP_PROVOKE_VRTX(1) | - TRI_FAN_PROVOKE_VRTX(2) | - ENABLE_TEXKILL_3D_4D | - TEXKILL_4D); - - /* Need to initialize this to zero. - */ - OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 | - I1_LOAD_S(3) | - (1)); - OUT_BATCH(0); - - /* XXX: Use this */ - OUT_BATCH(_3DSTATE_SCISSOR_ENABLE_CMD | - DISABLE_SCISSOR_RECT); - - OUT_BATCH(_3DSTATE_SCISSOR_RECT_0_CMD); - OUT_BATCH(0); - OUT_BATCH(0); - - OUT_BATCH(_3DSTATE_DEPTH_SUBRECT_DISABLE); - - OUT_BATCH(_3DSTATE_LOAD_INDIRECT | 0); /* disable indirect state */ - OUT_BATCH(0); - - - /* Don't support twosided stencil yet */ - OUT_BATCH(_3DSTATE_BACKFACE_STENCIL_OPS | - BFO_ENABLE_STENCIL_TWO_SIDE | - 0 ); - - ADVANCE_BATCH(); -} - - -#define emit(intel, state, size ) \ - intel_batchbuffer_data(intel->batch, state, size, 0 ) - -static GLuint get_dirty( struct i915_hw_state *state ) -{ - GLuint dirty; - - /* Workaround the multitex hang - if one texture unit state is - * modified, emit all texture units. - */ - dirty = state->active & ~state->emitted; - if (dirty & I915_UPLOAD_TEX_ALL) - state->emitted &= ~I915_UPLOAD_TEX_ALL; - dirty = state->active & ~state->emitted; - - return dirty; -} - - -static GLuint get_state_size( struct i915_hw_state *state ) -{ - GLuint dirty = get_dirty(state); - GLuint i; - GLuint sz = 0; - - if (dirty & I915_UPLOAD_CTX) - sz += sizeof(state->Ctx); - - if (dirty & I915_UPLOAD_BUFFERS) - sz += sizeof(state->Buffer); - - if (dirty & I915_UPLOAD_STIPPLE) - sz += sizeof(state->Stipple); - - if (dirty & I915_UPLOAD_FOG) - sz += sizeof(state->Fog); - - if (dirty & I915_UPLOAD_TEX_ALL) { - int nr = 0; - for (i = 0; i < I915_TEX_UNITS; i++) - if (dirty & I915_UPLOAD_TEX(i)) - nr++; - - sz += (2+nr*3) * sizeof(GLuint) * 2; - } - - if (dirty & I915_UPLOAD_CONSTANTS) - sz += state->ConstantSize * sizeof(GLuint); - - if (dirty & I915_UPLOAD_PROGRAM) - sz += state->ProgramSize * sizeof(GLuint); - - return sz; -} - - -/* Push the state into the sarea and/or texture memory. - */ -static void i915_emit_state( struct intel_context *intel ) -{ - struct i915_context *i915 = i915_context(&intel->ctx); - struct i915_hw_state *state = i915->current; - int i; - GLuint dirty = get_dirty(state); - GLuint counter = intel->batch.counter; - BATCH_LOCALS; - - if (intel->batch.space < get_state_size(state)) { - intelFlushBatch(intel, GL_TRUE); - dirty = get_dirty(state); - counter = intel->batch.counter; - } - - if (INTEL_DEBUG & DEBUG_STATE) - fprintf(stderr, "%s dirty: %x\n", __FUNCTION__, dirty); - - if (dirty & I915_UPLOAD_INVARIENT) { - if (INTEL_DEBUG & DEBUG_STATE) fprintf(stderr, "I915_UPLOAD_INVARIENT:\n"); - i915_emit_invarient_state( intel ); - } - - if (dirty & I915_UPLOAD_CTX) { - if (INTEL_DEBUG & DEBUG_STATE) fprintf(stderr, "I915_UPLOAD_CTX:\n"); - emit(intel, state->Ctx, sizeof(state->Ctx) ); - } - - if (dirty & I915_UPLOAD_BUFFERS) { - if (INTEL_DEBUG & DEBUG_STATE) fprintf(stderr, "I915_UPLOAD_BUFFERS:\n"); - BEGIN_BATCH(I915_DEST_SETUP_SIZE+2, 0); - OUT_BATCH(state->Buffer[I915_DESTREG_CBUFADDR0]); - OUT_BATCH(state->Buffer[I915_DESTREG_CBUFADDR1]); - OUT_RELOC(state->draw_region->buffer, DRM_MM_TT|DRM_MM_WRITE, - state->draw_region->draw_offset); - - if (state->depth_region) { - OUT_BATCH(state->Buffer[I915_DESTREG_DBUFADDR0]); - OUT_BATCH(state->Buffer[I915_DESTREG_DBUFADDR1]); - OUT_RELOC(state->depth_region->buffer, DRM_MM_TT|DRM_MM_WRITE, - state->depth_region->draw_offset); - } - - OUT_BATCH(state->Buffer[I915_DESTREG_DV0]); - OUT_BATCH(state->Buffer[I915_DESTREG_DV1]); - OUT_BATCH(state->Buffer[I915_DESTREG_SENABLE]); - OUT_BATCH(state->Buffer[I915_DESTREG_SR0]); - OUT_BATCH(state->Buffer[I915_DESTREG_SR1]); - OUT_BATCH(state->Buffer[I915_DESTREG_SR2]); - ADVANCE_BATCH(); - } - - if (dirty & I915_UPLOAD_STIPPLE) { - if (INTEL_DEBUG & DEBUG_STATE) fprintf(stderr, "I915_UPLOAD_STIPPLE:\n"); - emit(intel, state->Stipple, sizeof(state->Stipple) ); - } - - if (dirty & I915_UPLOAD_FOG) { - if (INTEL_DEBUG & DEBUG_STATE) fprintf(stderr, "I915_UPLOAD_FOG:\n"); - emit(intel, state->Fog, sizeof(state->Fog) ); - } - - /* Combine all the dirty texture state into a single command to - * avoid lockups on I915 hardware. - */ - if (dirty & I915_UPLOAD_TEX_ALL) { - int nr = 0; - - for (i = 0; i < I915_TEX_UNITS; i++) - if (dirty & I915_UPLOAD_TEX(i)) - nr++; - - BEGIN_BATCH(2+nr*3, 0); - OUT_BATCH(_3DSTATE_MAP_STATE | (3*nr)); - OUT_BATCH((dirty & I915_UPLOAD_TEX_ALL) >> I915_UPLOAD_TEX_0_SHIFT); - for (i = 0 ; i < I915_TEX_UNITS ; i++) - if (dirty & I915_UPLOAD_TEX(i)) { - - if (state->tex_buffer[i]) { - OUT_RELOC(state->tex_buffer[i], - DRM_MM_TT|DRM_MM_READ, - state->tex_offset[i]); - } - else { - assert(i == 0); - assert(state == &i915->meta); - OUT_BATCH(0); - } - - OUT_BATCH(state->Tex[i][I915_TEXREG_MS3]); - OUT_BATCH(state->Tex[i][I915_TEXREG_MS4]); - } - ADVANCE_BATCH(); - - BEGIN_BATCH(2+nr*3, 0); - OUT_BATCH(_3DSTATE_SAMPLER_STATE | (3*nr)); - OUT_BATCH((dirty & I915_UPLOAD_TEX_ALL) >> I915_UPLOAD_TEX_0_SHIFT); - for (i = 0 ; i < I915_TEX_UNITS ; i++) - if (dirty & I915_UPLOAD_TEX(i)) { - OUT_BATCH(state->Tex[i][I915_TEXREG_SS2]); - OUT_BATCH(state->Tex[i][I915_TEXREG_SS3]); - OUT_BATCH(state->Tex[i][I915_TEXREG_SS4]); - } - ADVANCE_BATCH(); - } - - if (dirty & I915_UPLOAD_CONSTANTS) { - if (INTEL_DEBUG & DEBUG_STATE) fprintf(stderr, "I915_UPLOAD_CONSTANTS:\n"); - emit(intel, state->Constant, state->ConstantSize * sizeof(GLuint) ); - } - - if (dirty & I915_UPLOAD_PROGRAM) { - if (INTEL_DEBUG & DEBUG_STATE) fprintf(stderr, "I915_UPLOAD_PROGRAM:\n"); - - assert((state->Program[0] & 0x1ff)+2 == state->ProgramSize); - - emit(intel, state->Program, state->ProgramSize * sizeof(GLuint) ); - if (INTEL_DEBUG & DEBUG_STATE) - i915_disassemble_program( state->Program, state->ProgramSize ); - } - - state->emitted |= dirty; - intel->batch.last_emit_state = counter; - assert(counter == intel->batch.counter); -} - -static void i915_destroy_context( struct intel_context *intel ) -{ - _tnl_free_vertices(&intel->ctx); -} - -<<<<<<< i915_vtbl.c - -/** - * Set the color buffer drawing region. - */ -static void -i915_set_color_region( intelContextPtr intel, const intelRegion *region) -======= - -/** - * Set the drawing regions for the color and depth/stencil buffers. - * This involves setting the pitch, cpp and buffer ID/location. - * Also set pixel format for color and Z rendering - * Used for setting both regular and meta state. - */ -void -i915_state_draw_region(struct intel_context *intel, - struct i915_hw_state *state, - struct intel_region *color_region, - struct intel_region *depth_region) ->>>>>>> 1.5.4.17 -{ - struct i915_context *i915 = i915_context(&intel->ctx); - GLuint value; - - ASSERT(state == &i915->state || state == &i915->meta); - - if (state->draw_region != color_region) { - intel_region_release(intel, &state->draw_region); - intel_region_reference(&state->draw_region, color_region); - } - if (state->depth_region != depth_region) { - intel_region_release(intel, &state->depth_region); - intel_region_reference(&state->depth_region, depth_region); - } - - /* - * Set stride/cpp values - */ - if (color_region) { - state->Buffer[I915_DESTREG_CBUFADDR0] = _3DSTATE_BUF_INFO_CMD; - state->Buffer[I915_DESTREG_CBUFADDR1] = - (BUF_3D_ID_COLOR_BACK | - BUF_3D_PITCH(color_region->pitch * color_region->cpp) | - BUF_3D_USE_FENCE); - } - - if (depth_region) { - state->Buffer[I915_DESTREG_DBUFADDR0] = _3DSTATE_BUF_INFO_CMD; - state->Buffer[I915_DESTREG_DBUFADDR1] = - (BUF_3D_ID_DEPTH | - BUF_3D_PITCH(depth_region->pitch * depth_region->cpp) | - BUF_3D_USE_FENCE); - } - - /* - * Compute/set I915_DESTREG_DV1 value - */ - value = (DSTORG_HORT_BIAS(0x8) | /* .5 */ - DSTORG_VERT_BIAS(0x8) | /* .5 */ - LOD_PRECLAMP_OGL | - TEX_DEFAULT_COLOR_OGL); - if (color_region && color_region->cpp == 4) { - value |= DV_PF_8888; - } - else { - value |= (DITHER_FULL_ALWAYS | DV_PF_565); - } - if (depth_region && depth_region->cpp == 4) { - value |= DEPTH_FRMT_24_FIXED_8_OTHER; - } - else { - value |= DEPTH_FRMT_16_FIXED; - } - state->Buffer[I915_DESTREG_DV1] = value; - - I915_STATECHANGE( i915, I915_UPLOAD_BUFFERS ); -<<<<<<< i915_vtbl.c - i915->state.Buffer[I915_DESTREG_CBUFADDR1] = - (BUF_3D_ID_COLOR_BACK | BUF_3D_PITCH(region->pitch) | BUF_3D_USE_FENCE); - i915->state.Buffer[I915_DESTREG_CBUFADDR2] = region->offset; -======= ->>>>>>> 1.5.4.17 -} - -<<<<<<< i915_vtbl.c - -/** - * specify the z-buffer/stencil region - */ -static void -i915_set_z_region( intelContextPtr intel, const intelRegion *region) -{ - i915ContextPtr i915 = I915_CONTEXT(intel); - I915_STATECHANGE( i915, I915_UPLOAD_BUFFERS ); - i915->state.Buffer[I915_DESTREG_DBUFADDR1] = - (BUF_3D_ID_DEPTH | BUF_3D_PITCH(region->pitch) | BUF_3D_USE_FENCE); - i915->state.Buffer[I915_DESTREG_DBUFADDR2] = region->offset; -} - - -/** - * Set both the color and Z/stencil drawing regions. - * Similar to two previous functions, but don't use I915_STATECHANGE() - */ -static void -i915_update_color_z_regions(intelContextPtr intel, - const intelRegion *colorRegion, - const intelRegion *depthRegion) -{ - i915ContextPtr i915 = I915_CONTEXT(intel); - - i915->state.Buffer[I915_DESTREG_CBUFADDR1] = - (BUF_3D_ID_COLOR_BACK | BUF_3D_PITCH(colorRegion->pitch) | BUF_3D_USE_FENCE); - i915->state.Buffer[I915_DESTREG_CBUFADDR2] = colorRegion->offset; - - i915->state.Buffer[I915_DESTREG_DBUFADDR1] = - (BUF_3D_ID_DEPTH | - BUF_3D_PITCH(depthRegion->pitch) | /* pitch in bytes */ - BUF_3D_USE_FENCE); - i915->state.Buffer[I915_DESTREG_DBUFADDR2] = depthRegion->offset; -} - - -static void i915_lost_hardware( intelContextPtr intel ) -======= - -static void -i915_set_draw_region(struct intel_context *intel, - struct intel_region *color_region, - struct intel_region *depth_region) ->>>>>>> 1.5.4.17 -{ - struct i915_context *i915 = i915_context(&intel->ctx); - i915_state_draw_region(intel, &i915->state, color_region, depth_region); -} - - - -static void i915_lost_hardware( struct intel_context *intel ) -{ - struct i915_context *i915 = i915_context(&intel->ctx); - i915->state.emitted = 0; -} - -static GLuint i915_flush_cmd( void ) -{ - return MI_FLUSH | FLUSH_MAP_CACHE; -} - - -void i915InitVtbl( struct i915_context *i915 ) -{ - i915->intel.vtbl.check_vertex_size = i915_check_vertex_size; -<<<<<<< i915_vtbl.c - i915->intel.vtbl.clear_with_tris = i915ClearWithTris; - i915->intel.vtbl.rotate_window = i915RotateWindow; -======= ->>>>>>> 1.5.4.17 - i915->intel.vtbl.destroy = i915_destroy_context; - i915->intel.vtbl.emit_state = i915_emit_state; - i915->intel.vtbl.lost_hardware = i915_lost_hardware; - i915->intel.vtbl.reduced_primitive_state = i915_reduced_primitive_state; - i915->intel.vtbl.render_start = i915_render_start; -<<<<<<< i915_vtbl.c - i915->intel.vtbl.set_color_region = i915_set_color_region; - i915->intel.vtbl.set_z_region = i915_set_z_region; - i915->intel.vtbl.update_color_z_regions = i915_update_color_z_regions; -======= - i915->intel.vtbl.set_draw_region = i915_set_draw_region; ->>>>>>> 1.5.4.17 - i915->intel.vtbl.update_texture_state = i915UpdateTextureState; - i915->intel.vtbl.flush_cmd = i915_flush_cmd; -} - diff --git a/src/mesa/drivers/dri/i915-tex/intel_batchbuffer.c b/src/mesa/drivers/dri/i915-tex/intel_batchbuffer.c deleted file mode 100644 index 35a8cad51f2..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_batchbuffer.c +++ /dev/null @@ -1,759 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -<<<<<<< intel_batchbuffer.c - -#include <stdio.h> -#include <errno.h> - -#include "mtypes.h" -#include "context.h" -#include "enums.h" -#include "vblank.h" - -#include "intel_reg.h" -======= ->>>>>>> 1.4.2.16 -#include "intel_batchbuffer.h" -#include "intel_ioctl.h" -#include "intel_bufmgr.h" - -/* Relocations in kernel space: - * - pass dma buffer seperately - * - memory manager knows how to patch - * - pass list of dependent buffers - * - pass relocation list - * - * Either: - * - get back an offset for buffer to fire - * - memory manager knows how to fire buffer - * - * Really want the buffer to be AGP and pinned. - * - */ - -/* Cliprect fence: The highest fence protecting a dma buffer - * containing explicit cliprect information. Like the old drawable - * lock but irq-driven. X server must wait for this fence to expire - * before changing cliprects [and then doing sw rendering?]. For - * other dma buffers, the scheduler will grab current cliprect info - * and mix into buffer. X server must hold the lock while changing - * cliprects??? Make per-drawable. Need cliprects in shared memory - * -- beats storing them with every cmd buffer in the queue. - * - * ==> X server must wait for this fence to expire before touching the - * framebuffer with new cliprects. - * - * ==> Cliprect-dependent buffers associated with a - * cliprect-timestamp. All of the buffers associated with a timestamp - * must go to hardware before any buffer with a newer timestamp. - * - * ==> Dma should be queued per-drawable for correct X/GL - * synchronization. Or can fences be used for this? - * - * Applies to: Blit operations, metaops, X server operations -- X - * server automatically waits on its own dma to complete before - * modifying cliprects ??? - */ - -static void intel_dump_batchbuffer( GLuint offset, - GLuint *ptr, - GLuint count ) -{ - int i; - fprintf(stderr, "\n\n\nSTART BATCH (%d dwords):\n", count/4); - for (i = 0; i < count/4; i += 4) - fprintf(stderr, "0x%x:\t0x%08x 0x%08x 0x%08x 0x%08x\n", - offset + i*4, ptr[i], ptr[i+1], ptr[i+2], ptr[i+3]); - fprintf(stderr, "END BATCH\n\n\n"); -} - - -static void intel_batchbuffer_reset( struct intel_batchbuffer *batch ) -{ - bmBufferData(batch->bm, - batch->buffer, - BATCH_SZ, - NULL, - 0); - - if (!batch->list) - batch->list = bmNewBufferList(); - - drmMMClearBufList(batch->list); - batch->list_count = 0; - batch->nr_relocs = 0; - batch->flags = 0; - - bmAddBuffer( batch->bm, - batch->list, - batch->buffer, - DRM_MM_TT, - NULL, - &batch->offset[batch->list_count++]); - - batch->map = bmMapBuffer(batch->bm, batch->buffer, DRM_MM_WRITE); - batch->ptr = batch->map; -} - -/*====================================================================== - * Public functions - */ -<<<<<<< intel_batchbuffer.c - -static void intel_fill_box( intelContextPtr intel, - GLshort x, GLshort y, - GLshort w, GLshort h, - GLubyte r, GLubyte g, GLubyte b ) -{ - x += intel->drawX; - y += intel->drawY; - - if (x >= 0 && y >= 0 && - x+w < intel->intelScreen->width && - y+h < intel->intelScreen->height) - intelEmitFillBlitLocked( intel, - intel->intelScreen->cpp, - intel->intelScreen->back.pitch, - intel->intelScreen->back.offset, - x, y, w, h, - INTEL_PACKCOLOR(intel->intelScreen->fbFormat, - r,g,b,0xff)); -} - -static void intel_draw_performance_boxes( intelContextPtr intel ) -======= -struct intel_batchbuffer *intel_batchbuffer_alloc( struct intel_context *intel ) ->>>>>>> 1.4.2.16 -{ - struct intel_batchbuffer *batch = calloc(sizeof(*batch), 1); - - batch->intel = intel; - batch->bm = intel->bm; - - bmGenBuffers(intel->bm, 1, &batch->buffer, BM_BATCHBUFFER); - intel_batchbuffer_reset( batch ); - return batch; -} - -void intel_batchbuffer_free( struct intel_batchbuffer *batch ) -{ - if (batch->map) - bmUnmapBuffer(batch->bm, batch->buffer); - - free(batch); -} - -/* TODO: Push this whole function into bufmgr. - */ -static void do_flush_locked( struct intel_batchbuffer *batch, - GLuint used, - GLboolean ignore_cliprects, - GLboolean allow_unlock) -{ - GLuint *ptr; - GLuint i; - - bmValidateBufferList( batch->bm, - batch->list, - DRM_MM_TT ); - - /* Apply the relocations. This nasty map indicates to me that the - * whole task should be done internally by the memory manager, and - * that dma buffers probably need to be pinned within agp space. - */ - ptr = (GLuint *)bmMapBuffer(batch->bm, batch->buffer, DRM_MM_WRITE); - - - for (i = 0; i < batch->nr_relocs; i++) { - struct buffer_reloc *r = &batch->reloc[i]; - - assert(r->elem < batch->list_count); - ptr[r->offset/4] = batch->offset[r->elem] + r->delta; - } - - if (INTEL_DEBUG & DEBUG_DMA) - intel_dump_batchbuffer( 0, ptr, used ); - - bmUnmapBuffer(batch->bm, batch->buffer); - - /* Fire the batch buffer, which was uploaded above: - */ -<<<<<<< intel_batchbuffer.c - intel->vtbl.emit_state( intel ); - - /* Make sure there is some space in this buffer: - */ - if (intel->vertex_size * 10 * sizeof(GLuint) >= intel->batch.space) { - intelFlushBatch(intel, GL_TRUE); - intel->vtbl.emit_state( intel ); - } -======= ->>>>>>> 1.4.2.16 - -#if 1 - intel_batch_ioctl(batch->intel, - batch->offset[0], - used, - ignore_cliprects, - allow_unlock); -#endif -<<<<<<< intel_batchbuffer.c - - /* Emit a slot which will be filled with the inline primitive - * command later. - */ - BEGIN_BATCH(2); - OUT_BATCH( 0 ); - - intel->prim.start_ptr = batch_ptr; - intel->prim.primitive = prim; - intel->prim.flush = intel_flush_inline_primitive; - intel->batch.contains_geometry = 1; - - OUT_BATCH( 0 ); - ADVANCE_BATCH(); -} - - -void intelRestartInlinePrimitive( intelContextPtr intel ) -{ - GLuint prim = intel->prim.primitive; - - intel_flush_inline_primitive( &intel->ctx ); - if (1) intelFlushBatch(intel, GL_TRUE); /* GL_TRUE - is critical */ - intelStartInlinePrimitive( intel, prim ); -======= - batch->last_fence = bmFenceBufferList(batch->bm, batch->list); ->>>>>>> 1.4.2.16 -} - - - -GLuint intel_batchbuffer_flush( struct intel_batchbuffer *batch ) -{ - struct intel_context *intel = batch->intel; - GLuint used = batch->ptr - batch->map; - - if (used == 0) - return batch->last_fence; - - /* Add the MI_BATCH_BUFFER_END. Always add an MI_FLUSH - this is a - * performance drain that we would like to avoid. - */ -<<<<<<< intel_batchbuffer.c - intel->vtbl.emit_state( intel ); - - if ((1+dwords)*4 >= intel->batch.space) { - intelFlushBatch(intel, GL_TRUE); - intel->vtbl.emit_state( intel ); - } - - - if (1) { - int used = dwords * 4; - int vertcount; -======= - if (used & 4) { - ((int *)batch->ptr)[0] = intel->vtbl.flush_cmd(); - ((int *)batch->ptr)[1] = 0; - ((int *)batch->ptr)[2] = MI_BATCH_BUFFER_END; - used += 12; - } - else { - ((int *)batch->ptr)[0] = intel->vtbl.flush_cmd() ; - ((int *)batch->ptr)[1] = MI_BATCH_BUFFER_END; - used += 8; - } ->>>>>>> 1.4.2.16 - - bmUnmapBuffer(batch->bm, batch->buffer); - batch->ptr = NULL; - batch->map = NULL; - - /* TODO: Just pass the relocation list and dma buffer up to the - * kernel. - */ -<<<<<<< intel_batchbuffer.c - BEGIN_BATCH(1 + dwords); - OUT_BATCH( _3DPRIMITIVE | - primitive | - (dwords-1) ); - - tmp = (GLuint *)batch_ptr; - batch_ptr += dwords * 4; - - ADVANCE_BATCH(); - - intel->batch.contains_geometry = 1; - - do_discard: - return tmp; -} - - -static void intelWaitForFrameCompletion( intelContextPtr intel ) -{ - drm_i915_sarea_t *sarea = (drm_i915_sarea_t *)intel->sarea; - - if (intel->do_irqs) { - if (intelGetLastFrame(intel) < sarea->last_dispatch) { - if (!intel->irqsEmitted) { - while (intelGetLastFrame (intel) < sarea->last_dispatch) - ; - } - else { - UNLOCK_HARDWARE( intel ); - intelWaitIrq( intel, intel->alloc.irq_emitted ); - LOCK_HARDWARE( intel ); - } - intel->irqsEmitted = 10; - } - - if (intel->irqsEmitted) { - intelEmitIrqLocked( intel ); - intel->irqsEmitted--; - } - } - else { - while (intelGetLastFrame (intel) < sarea->last_dispatch) { - UNLOCK_HARDWARE( intel ); - if (intel->do_usleeps) - DO_USLEEP( 1 ); - LOCK_HARDWARE( intel ); - } - } -} - -/* - * Copy the back buffer to the front buffer. - */ -void intelCopyBuffer( const __DRIdrawablePrivate *dPriv ) -{ - intelContextPtr intel; - GLboolean missed_target; - int64_t ust; - - if (0) - fprintf(stderr, "%s\n", __FUNCTION__); - - assert(dPriv); - assert(dPriv->driContextPriv); - assert(dPriv->driContextPriv->driverPrivate); - - intel = (intelContextPtr) dPriv->driContextPriv->driverPrivate; - - intelFlush( &intel->ctx ); - - LOCK_HARDWARE( intel ); - intelWaitForFrameCompletion( intel ); - UNLOCK_HARDWARE( intel ); - driWaitForVBlank( dPriv, &intel->vbl_seq, intel->vblank_flags, & missed_target ); - - LOCK_HARDWARE( intel ); -======= - if (!intel->locked) ->>>>>>> 1.4.2.16 - { -<<<<<<< intel_batchbuffer.c - const intelScreenPrivate *intelScreen = intel->intelScreen; - const __DRIdrawablePrivate *dPriv = intel->driDrawable; - const int nbox = dPriv->numClipRects; - const drm_clip_rect_t *pbox = dPriv->pClipRects; - const int cpp = intelScreen->cpp; - const int pitch = intelScreen->front.pitch; /* in bytes */ - int i; - GLuint CMD, BR13; - BATCH_LOCALS; - - switch(cpp) { - case 2: - BR13 = (pitch) | (0xCC << 16) | (1<<24); - CMD = XY_SRC_COPY_BLT_CMD; - break; - case 4: - BR13 = (pitch) | (0xCC << 16) | (1<<24) | (1<<25); - CMD = (XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA | - XY_SRC_COPY_BLT_WRITE_RGB); - break; - default: - BR13 = (pitch) | (0xCC << 16) | (1<<24); - CMD = XY_SRC_COPY_BLT_CMD; - break; - } - - if (0) - intel_draw_performance_boxes( intel ); - - for (i = 0 ; i < nbox; i++, pbox++) - { - if (pbox->x1 > pbox->x2 || - pbox->y1 > pbox->y2 || - pbox->x2 > intelScreen->width || - pbox->y2 > intelScreen->height) { - _mesa_warning(&intel->ctx, "Bad cliprect in intelCopyBuffer()"); - continue; - } - - BEGIN_BATCH( 8); - OUT_BATCH( CMD ); - OUT_BATCH( BR13 ); - OUT_BATCH( (pbox->y1 << 16) | pbox->x1 ); - OUT_BATCH( (pbox->y2 << 16) | pbox->x2 ); - - if (intel->sarea->pf_current_page == 0) - OUT_BATCH( intelScreen->front.offset ); - else - OUT_BATCH( intelScreen->back.offset ); - - OUT_BATCH( (pbox->y1 << 16) | pbox->x1 ); - OUT_BATCH( BR13 & 0xffff ); - - if (intel->sarea->pf_current_page == 0) - OUT_BATCH( intelScreen->back.offset ); - else - OUT_BATCH( intelScreen->front.offset ); -======= - assert(!(batch->flags & INTEL_BATCH_NO_CLIPRECTS)); ->>>>>>> 1.4.2.16 - - LOCK_HARDWARE(intel); - do_flush_locked(batch, used, GL_FALSE, GL_TRUE); - UNLOCK_HARDWARE(intel); - } -<<<<<<< intel_batchbuffer.c - intelFlushBatchLocked( intel, GL_TRUE, GL_TRUE, GL_TRUE ); - UNLOCK_HARDWARE( intel ); - - intel->swap_count++; - (*dri_interface->getUST)(&ust); - if (missed_target) { - intel->swap_missed_count++; - intel->swap_missed_ust = ust - intel->swap_ust; - } - - intel->swap_ust = ust; -} - - - - -void intelEmitFillBlitLocked( intelContextPtr intel, - GLuint cpp, - GLshort dst_pitch, /* in bytes */ - GLuint dst_offset, - GLshort x, GLshort y, - GLshort w, GLshort h, - GLuint color ) -{ - GLuint BR13, CMD; - BATCH_LOCALS; - - switch(cpp) { - case 1: - case 2: - case 3: - BR13 = dst_pitch | (0xF0 << 16) | (1<<24); - CMD = XY_COLOR_BLT_CMD; - break; - case 4: - BR13 = dst_pitch | (0xF0 << 16) | (1<<24) | (1<<25); - CMD = (XY_COLOR_BLT_CMD | XY_COLOR_BLT_WRITE_ALPHA | - XY_COLOR_BLT_WRITE_RGB); - break; - default: - return; -======= - else { - GLboolean ignore_cliprects = !(batch->flags & INTEL_BATCH_CLIPRECTS); - do_flush_locked(batch, used, ignore_cliprects, GL_FALSE); ->>>>>>> 1.4.2.16 - } - - /* Reset the buffer: - */ - intel_batchbuffer_reset( batch ); - return batch->last_fence; -} - -void intel_batchbuffer_finish( struct intel_batchbuffer *batch ) -{ - bmFinishFence(batch->bm, - intel_batchbuffer_flush(batch)); -} -<<<<<<< intel_batchbuffer.c - - - -void intelClearWithBlit(GLcontext *ctx, GLbitfield flags, GLboolean all, - GLint cx1, GLint cy1, GLint cw, GLint ch) -{ - intelContextPtr intel = INTEL_CONTEXT( ctx ); - intelScreenPrivate *intelScreen = intel->intelScreen; - GLuint clear_depth, clear_color; - GLint cx, cy; - GLint pitch; - GLint cpp = intelScreen->cpp; - GLint i; - GLuint BR13, CMD, D_CMD; - BATCH_LOCALS; - - intelFlush( &intel->ctx ); - LOCK_HARDWARE( intel ); - - pitch = intelScreen->front.pitch; - - clear_color = intel->ClearColor; - clear_depth = 0; -======= - ->>>>>>> 1.4.2.16 - -/* This is the only way buffers get added to the validate list. - */ -GLboolean intel_batchbuffer_emit_reloc( struct intel_batchbuffer *batch, - GLuint buffer, - GLuint flags, - GLuint delta ) -{ - GLuint i; - - assert(batch->nr_relocs <= MAX_RELOCS); - - i = bmScanBufferList(batch->bm, batch->list, buffer); - if (i == -1) { - i = batch->list_count; - bmAddBuffer(batch->bm, - batch->list, - buffer, - flags, - NULL, - &batch->offset[batch->list_count++]); - } - -<<<<<<< intel_batchbuffer.c - if (flags & BUFFER_BIT_STENCIL) { - clear_depth |= (ctx->Stencil.Clear & 0xff) << 24; - } - - switch(cpp) { - case 2: - BR13 = (0xF0 << 16) | (pitch) | (1<<24); - D_CMD = CMD = XY_COLOR_BLT_CMD; - break; - case 4: - BR13 = (0xF0 << 16) | (pitch) | (1<<24) | (1<<25); - CMD = (XY_COLOR_BLT_CMD | - XY_COLOR_BLT_WRITE_ALPHA | - XY_COLOR_BLT_WRITE_RGB); - D_CMD = XY_COLOR_BLT_CMD; - if (flags & BUFFER_BIT_DEPTH) D_CMD |= XY_COLOR_BLT_WRITE_RGB; - if (flags & BUFFER_BIT_STENCIL) D_CMD |= XY_COLOR_BLT_WRITE_ALPHA; - break; - default: - BR13 = (0xF0 << 16) | (pitch) | (1<<24); - D_CMD = CMD = XY_COLOR_BLT_CMD; - break; -======= - { - struct buffer_reloc *r = &batch->reloc[batch->nr_relocs++]; - r->offset = batch->ptr - batch->map; - r->delta = delta; - r->elem = i; ->>>>>>> 1.4.2.16 - } - -<<<<<<< intel_batchbuffer.c - { - /* flip top to bottom */ - cy = intel->driDrawable->h-cy1-ch; - cx = cx1 + intel->drawX; - cy += intel->drawY; - - /* adjust for page flipping */ - if ( intel->sarea->pf_current_page == 1 ) { - GLuint tmp = flags; - - flags &= ~(BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT); - if ( tmp & BUFFER_BIT_FRONT_LEFT ) flags |= BUFFER_BIT_BACK_LEFT; - if ( tmp & BUFFER_BIT_BACK_LEFT ) flags |= BUFFER_BIT_FRONT_LEFT; - } - - for (i = 0 ; i < intel->numClipRects ; i++) - { - drm_clip_rect_t *box = &intel->pClipRects[i]; - drm_clip_rect_t b; - - if (!all) { - GLint x = box[i].x1; - GLint y = box[i].y1; - GLint w = box[i].x2 - x; - GLint h = box[i].y2 - y; - - if (x < cx) w -= cx - x, x = cx; - if (y < cy) h -= cy - y, y = cy; - if (x + w > cx + cw) w = cx + cw - x; - if (y + h > cy + ch) h = cy + ch - y; - if (w <= 0) continue; - if (h <= 0) continue; - - b.x1 = x; - b.y1 = y; - b.x2 = x + w; - b.y2 = y + h; - } else { - b = *box; - } - - - if (b.x1 > b.x2 || - b.y1 > b.y2 || - b.x2 > intelScreen->width || - b.y2 > intelScreen->height) - continue; - - if ( flags & BUFFER_BIT_FRONT_LEFT ) { - BEGIN_BATCH( 6); - OUT_BATCH( CMD ); - OUT_BATCH( BR13 ); - OUT_BATCH( (b.y1 << 16) | b.x1 ); - OUT_BATCH( (b.y2 << 16) | b.x2 ); - OUT_BATCH( intelScreen->front.offset ); - OUT_BATCH( clear_color ); - ADVANCE_BATCH(); - } - - if ( flags & BUFFER_BIT_BACK_LEFT ) { - BEGIN_BATCH( 6); - OUT_BATCH( CMD ); - OUT_BATCH( BR13 ); - OUT_BATCH( (b.y1 << 16) | b.x1 ); - OUT_BATCH( (b.y2 << 16) | b.x2 ); - OUT_BATCH( intelScreen->back.offset ); - OUT_BATCH( clear_color ); - ADVANCE_BATCH(); - } - - if ( flags & (BUFFER_BIT_STENCIL | BUFFER_BIT_DEPTH) ) { - BEGIN_BATCH( 6); - OUT_BATCH( D_CMD ); - OUT_BATCH( BR13 ); - OUT_BATCH( (b.y1 << 16) | b.x1 ); - OUT_BATCH( (b.y2 << 16) | b.x2 ); - OUT_BATCH( intelScreen->depth.offset ); - OUT_BATCH( clear_depth ); - ADVANCE_BATCH(); - } - } - } - intelFlushBatchLocked( intel, GL_TRUE, GL_FALSE, GL_TRUE ); - UNLOCK_HARDWARE( intel ); -======= - batch->ptr += 4; - return GL_TRUE; ->>>>>>> 1.4.2.16 -} - - - -void intel_batchbuffer_data(struct intel_batchbuffer *batch, - const void *data, - GLuint bytes, - GLuint flags) -{ -<<<<<<< intel_batchbuffer.c - intelContextPtr intel = INTEL_CONTEXT(ctx); - - if (intel->alloc.offset) { - intelFreeAGP( intel, intel->alloc.ptr ); - intel->alloc.ptr = NULL; - intel->alloc.offset = 0; - } - else if (intel->alloc.ptr) { - free(intel->alloc.ptr); - intel->alloc.ptr = NULL; - } - - memset(&intel->batch, 0, sizeof(intel->batch)); -======= - assert((bytes & 3) == 0); - intel_batchbuffer_require_space(batch, bytes, flags); - __memcpy(batch->ptr, data, bytes); - batch->ptr += bytes; ->>>>>>> 1.4.2.16 -} - -<<<<<<< intel_batchbuffer.c - -void intelInitBatchBuffer( GLcontext *ctx ) -{ - intelContextPtr intel = INTEL_CONTEXT(ctx); - - /* This path isn't really safe with rotate: - */ - if (getenv("INTEL_BATCH") && intel->intelScreen->allow_batchbuffer) { - switch (intel->intelScreen->deviceID) { - case PCI_CHIP_I865_G: - /* HW bug? Seems to crash if batchbuffer crosses 4k boundary. - */ - intel->alloc.size = 8 * 1024; - break; - default: - /* This is the smallest amount of memory the kernel deals with. - * We'd ideally like to make this smaller. - */ - intel->alloc.size = 1 << intel->intelScreen->logTextureGranularity; - break; - } - - /* KW: temporary - this make crashes & lockups more frequent, so - * leave in until they are solved. - */ - intel->alloc.size = 8 * 1024; - - intel->alloc.ptr = intelAllocateAGP( intel, intel->alloc.size ); - if (intel->alloc.ptr) - intel->alloc.offset = - intelAgpOffsetFromVirtual( intel, intel->alloc.ptr ); - else - intel->alloc.offset = 0; /* OK? */ - } - - /* The default is now to use a local buffer and pass that to the - * kernel. This is also a fallback if allocation fails on the - * above path: - */ - if (!intel->alloc.ptr) { - intel->alloc.size = 8 * 1024; - intel->alloc.ptr = malloc( intel->alloc.size ); - intel->alloc.offset = 0; - } - - assert(intel->alloc.ptr); -} -======= ->>>>>>> 1.4.2.16 diff --git a/src/mesa/drivers/dri/i915-tex/intel_batchbuffer.h b/src/mesa/drivers/dri/i915-tex/intel_batchbuffer.h deleted file mode 100644 index 322ec944190..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_batchbuffer.h +++ /dev/null @@ -1,137 +0,0 @@ -#ifndef INTEL_BATCHBUFFER_H -#define INTEL_BATCHBUFFER_H - -#include "mtypes.h" -#include "intel_bufmgr.h" - -struct intel_context; - -#define BATCH_SZ 4096 -#define BATCH_RESERVED 16 - -#define MAX_RELOCS 100 - -#define INTEL_BATCH_NO_CLIPRECTS 0x1 -#define INTEL_BATCH_CLIPRECTS 0x2 - -struct buffer_reloc { - GLuint offset; - GLuint elem; /* elem in buffer list, not buffer id */ - GLuint delta; /* not needed? */ -}; - -struct intel_batchbuffer { - struct bufmgr *bm; - struct intel_context *intel; - - GLuint buffer; - GLuint last_fence; - GLuint flags; - - /* In progress: - */ - unsigned long offset[MAX_RELOCS]; - struct _drmMMBufList *list; - GLuint list_count; - GLubyte *map; - GLubyte *ptr; - - struct buffer_reloc reloc[MAX_RELOCS]; - GLuint nr_relocs; -}; - -struct intel_batchbuffer *intel_batchbuffer_alloc( struct intel_context *intel ); - -void intel_batchbuffer_free( struct intel_batchbuffer *batch ); - - -<<<<<<< intel_batchbuffer.h -#define BEGIN_BATCH(n) \ -do { \ - if (VERBOSE) fprintf(stderr, \ - "BEGIN_BATCH(%d) in %s, %d dwords free\n", \ - (n), __FUNCTION__, intel->batch.space/4); \ - if (intel->batch.space < (n)*4) \ - intelFlushBatch(intel, GL_TRUE); \ - if (intel->batch.space == intel->batch.size) intel->batch.func = __FUNCTION__; \ - batch_ptr = intel->batch.ptr; \ -} while (0) -======= -void intel_batchbuffer_finish( struct intel_batchbuffer *batch ); ->>>>>>> 1.2.12.12 - -GLuint intel_batchbuffer_flush( struct intel_batchbuffer *batch ); - - -/* Unlike bmBufferData, this currently requires the buffer be mapped. - * Consider it a convenience function wrapping multple - * intel_buffer_dword() calls. - */ -void intel_batchbuffer_data(struct intel_batchbuffer *batch, - const void *data, - GLuint bytes, - GLuint flags); - -void intel_batchbuffer_release_space(struct intel_batchbuffer *batch, - GLuint bytes); - -GLboolean intel_batchbuffer_emit_reloc( struct intel_batchbuffer *batch, - GLuint buffer, - GLuint flags, - GLuint offset ); - -/* Inline functions - might actually be better off with these - * non-inlined. Certainly better off switching all command packets to - * be passed as structs rather than dwords, but that's a little bit of - * work... - */ -static INLINE GLuint -intel_batchbuffer_space( struct intel_batchbuffer *batch ) -{ - return (BATCH_SZ - BATCH_RESERVED) - (batch->ptr - batch->map); -} - - -static INLINE void -intel_batchbuffer_emit_dword(struct intel_batchbuffer *batch, - GLuint dword) -{ - assert(batch->map); - assert(intel_batchbuffer_space(batch) >= 4); - *(GLuint *)(batch->ptr) = dword; - batch->ptr += 4; -} - -static INLINE void -intel_batchbuffer_require_space(struct intel_batchbuffer *batch, - GLuint sz, - GLuint flags) -{ - assert(sz < BATCH_SZ - 8); - if (intel_batchbuffer_space(batch) < sz || - (batch->flags != 0 && flags != 0 && batch->flags != flags)) - intel_batchbuffer_flush(batch); - - batch->flags |= flags; -} - -/* Here are the crusty old macros, to be removed: - */ -#define BATCH_LOCALS - -#define BEGIN_BATCH(n, flags) do { \ - assert(!intel->prim.flush); \ - intel_batchbuffer_require_space(intel->batch, (n)*4, flags); \ -} while (0) - -#define OUT_BATCH(d) intel_batchbuffer_emit_dword(intel->batch, d) - -#define OUT_RELOC(buf,flags,delta) do { \ - assert((delta) >= 0); \ - intel_batchbuffer_emit_reloc(intel->batch, buf, flags, delta); \ -} while (0) - -#define ADVANCE_BATCH() do { } while(0) - - -#endif diff --git a/src/mesa/drivers/dri/i915-tex/intel_blit.c b/src/mesa/drivers/dri/i915-tex/intel_blit.c deleted file mode 100644 index aefc3b39187..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_blit.c +++ /dev/null @@ -1,437 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - - -#include <stdio.h> -#include <errno.h> - -#include "mtypes.h" -#include "context.h" -#include "enums.h" - -#include "intel_batchbuffer.h" -#include "intel_blit.h" -#include "intel_buffers.h" -#include "intel_context.h" -#include "intel_fbo.h" -#include "intel_reg.h" -#include "intel_regions.h" - -#include "intel_bufmgr.h" - - -/** - * Copy the back color buffer to the front color buffer. - * Used for SwapBuffers(). - */ -void intelCopyBuffer( const __DRIdrawablePrivate *dPriv ) -{ - GET_CURRENT_CONTEXT(ctx); - struct intel_context *intel; - - DBG("%s\n", __FUNCTION__); - - assert(dPriv); - - /* We need a rendering context in order to issue the blit cmd. - * Use the current context. - * XXX need to fix this someday. - */ - if (!ctx) { - _mesa_problem(NULL, "No current context in intelCopyBuffer()"); - return; - } - intel = (struct intel_context *) ctx; - - bmFinishFence(intel->bm, intel->last_swap_fence); - - /* The LOCK_HARDWARE is required for the cliprects. Buffer offsets - * should work regardless. - */ - LOCK_HARDWARE( intel ); - - if (intel->driDrawable && - intel->driDrawable->numClipRects) - { - const intelScreenPrivate *intelScreen = intel->intelScreen; - struct gl_framebuffer *fb - = (struct gl_framebuffer *) dPriv->driverPrivate; - const struct intel_region *frontRegion - = intel_get_rb_region(fb, BUFFER_FRONT_LEFT); - const struct intel_region *backRegion - = intel_get_rb_region(fb, BUFFER_BACK_LEFT); - const int nbox = dPriv->numClipRects; - const drm_clip_rect_t *pbox = dPriv->pClipRects; - const int pitch = frontRegion->pitch; - const int cpp = frontRegion->cpp; - int BR13, CMD; - int i; - - ASSERT(fb); - ASSERT(fb->Name == 0); /* Not a user-created FBO */ - ASSERT(frontRegion); - ASSERT(backRegion); - ASSERT(frontRegion->pitch == backRegion->pitch); - ASSERT(frontRegion->cpp == backRegion->cpp); - - if (cpp == 2) { - BR13 = (pitch * cpp) | (0xCC << 16) | (1<<24); - CMD = XY_SRC_COPY_BLT_CMD; - } - else { - BR13 = (pitch * cpp) | (0xCC << 16) | (1<<24) | (1<<25); - CMD = (XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA | - XY_SRC_COPY_BLT_WRITE_RGB); - } - - for (i = 0 ; i < nbox; i++, pbox++) - { - if (pbox->x1 > pbox->x2 || - pbox->y1 > pbox->y2 || - pbox->x2 > intelScreen->width || - pbox->y2 > intelScreen->height) - continue; - - BEGIN_BATCH(8, INTEL_BATCH_NO_CLIPRECTS); - OUT_BATCH( CMD ); - OUT_BATCH( BR13 ); - OUT_BATCH( (pbox->y1 << 16) | pbox->x1 ); - OUT_BATCH( (pbox->y2 << 16) | pbox->x2 ); - - if (intel->sarea->pf_current_page == 0) - OUT_RELOC( frontRegion->buffer, DRM_MM_TT|DRM_MM_WRITE, 0 ); - else - OUT_RELOC( backRegion->buffer, DRM_MM_TT|DRM_MM_WRITE, 0 ); - OUT_BATCH( (pbox->y1 << 16) | pbox->x1 ); - OUT_BATCH( BR13 & 0xffff ); - - if (intel->sarea->pf_current_page == 0) - OUT_RELOC( backRegion->buffer, DRM_MM_TT|DRM_MM_READ, 0 ); - else - OUT_RELOC( frontRegion->buffer, DRM_MM_TT|DRM_MM_READ, 0 ); - - ADVANCE_BATCH(); - } - - intel->last_swap_fence = intel_batchbuffer_flush( intel->batch ); - } - UNLOCK_HARDWARE( intel ); -} - - - - -void intelEmitFillBlit( struct intel_context *intel, - GLuint cpp, - GLshort dst_pitch, - GLuint dst_buffer, - GLuint dst_offset, - GLshort x, GLshort y, - GLshort w, GLshort h, - GLuint color ) -{ - GLuint BR13, CMD; - BATCH_LOCALS; - - dst_pitch *= cpp; - - switch(cpp) { - case 1: - case 2: - case 3: - BR13 = dst_pitch | (0xF0 << 16) | (1<<24); - CMD = XY_COLOR_BLT_CMD; - break; - case 4: - BR13 = dst_pitch | (0xF0 << 16) | (1<<24) | (1<<25); - CMD = (XY_COLOR_BLT_CMD | XY_COLOR_BLT_WRITE_ALPHA | - XY_COLOR_BLT_WRITE_RGB); - break; - default: - return; - } - - BEGIN_BATCH(6, INTEL_BATCH_NO_CLIPRECTS); - OUT_BATCH( CMD ); - OUT_BATCH( BR13 ); - OUT_BATCH( (y << 16) | x ); - OUT_BATCH( ((y+h) << 16) | (x+w) ); - OUT_RELOC( dst_buffer, DRM_MM_TT|DRM_MM_WRITE, dst_offset ); - OUT_BATCH( color ); - ADVANCE_BATCH(); -} - - -/* Copy BitBlt - */ -void intelEmitCopyBlit( struct intel_context *intel, - GLuint cpp, - GLshort src_pitch, - GLuint src_buffer, - GLuint src_offset, - GLshort dst_pitch, - GLuint dst_buffer, - GLuint dst_offset, - GLshort src_x, GLshort src_y, - GLshort dst_x, GLshort dst_y, - GLshort w, GLshort h ) -{ - GLuint CMD, BR13; - int dst_y2 = dst_y + h; - int dst_x2 = dst_x + w; - BATCH_LOCALS; - - - DBG("%s src:buf(%d)/%d+%d %d,%d dst:buf(%d)/%d+%d %d,%d sz:%dx%d\n", - __FUNCTION__, - src_buffer, src_pitch, src_offset, src_x, src_y, - dst_buffer, dst_pitch, dst_offset, dst_x, dst_y, - w,h); - - src_pitch *= cpp; - dst_pitch *= cpp; - - switch(cpp) { - case 1: - case 2: - case 3: - BR13 = (((GLint)dst_pitch)&0xffff) | (0xCC << 16) | (1<<24); - CMD = XY_SRC_COPY_BLT_CMD; - break; - case 4: - BR13 = (((GLint)dst_pitch)&0xffff) | (0xCC << 16) | (1<<24) | (1<<25); - CMD = (XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA | - XY_SRC_COPY_BLT_WRITE_RGB); - break; - default: - return; - } - - if (dst_y2 < dst_y || - dst_x2 < dst_x) { - return; - } - - /* Initial y values don't seem to work with negative pitches. If - * we adjust the offsets manually (below), it seems to work fine. - * - * On the other hand, if we always adjust, the hardware doesn't - * know which blit directions to use, so overlapping copypixels get - * the wrong result. - */ - if ( dst_pitch > 0 && - src_pitch > 0) { - BEGIN_BATCH(8, INTEL_BATCH_NO_CLIPRECTS); - OUT_BATCH( CMD ); - OUT_BATCH( BR13 ); - OUT_BATCH( (dst_y << 16) | dst_x ); - OUT_BATCH( (dst_y2 << 16) | dst_x2 ); - OUT_RELOC( dst_buffer, DRM_MM_TT|DRM_MM_WRITE, dst_offset ); - OUT_BATCH( (src_y << 16) | src_x ); - OUT_BATCH( ((GLint)src_pitch&0xffff) ); - OUT_RELOC( src_buffer, DRM_MM_TT|DRM_MM_READ, src_offset ); - ADVANCE_BATCH(); - } - else { - BEGIN_BATCH(8, INTEL_BATCH_NO_CLIPRECTS); - OUT_BATCH( CMD ); - OUT_BATCH( BR13 ); - OUT_BATCH( (0 << 16) | dst_x ); - OUT_BATCH( (h << 16) | dst_x2 ); - OUT_RELOC( dst_buffer, DRM_MM_TT|DRM_MM_WRITE, dst_offset + dst_y * dst_pitch ); - OUT_BATCH( (0 << 16) | src_x ); - OUT_BATCH( ((GLint)src_pitch&0xffff) ); - OUT_RELOC( src_buffer, DRM_MM_TT|DRM_MM_READ, src_offset + src_y * src_pitch ); - ADVANCE_BATCH(); - } -} - - -/** - * Use blitting to clear the renderbuffers named by 'flags'. - * Note: we can't use the ctx->DrawBuffer->_ColorDrawBufferMask field - * since that might include software renderbuffers or renderbuffers - * which we're clearing with triangles. - * \param mask bitmask of BUFFER_BIT_* values indicating buffers to clear - */ -void intelClearWithBlit(GLcontext *ctx, GLbitfield mask, GLboolean all, - GLint cx, GLint cy, GLint cw, GLint ch) -{ - struct intel_context *intel = intel_context( ctx ); - GLuint clear_depth; - GLbitfield skipBuffers = 0; - BATCH_LOCALS; - - if (INTEL_DEBUG & DEBUG_DRI) - _mesa_printf("%s %x\n", __FUNCTION__, mask); - - /* - * Compute values for clearing the buffers. - */ - clear_depth = 0; - if (mask & BUFFER_BIT_DEPTH) { - clear_depth = (GLuint) (ctx->DrawBuffer->_DepthMax * ctx->Depth.Clear); - } - if (mask & BUFFER_BIT_STENCIL) { - clear_depth |= (ctx->Stencil.Clear & 0xff) << 24; - } - - /* If clearing both depth and stencil, skip BUFFER_BIT_STENCIL in - * the loop below. - */ - if ((mask & BUFFER_BIT_DEPTH) && (mask & BUFFER_BIT_STENCIL)) { - skipBuffers = BUFFER_BIT_STENCIL; - } - - /* XXX Move this flush/lock into the following conditional? */ - intelFlush( &intel->ctx ); - LOCK_HARDWARE( intel ); - - if (intel->numClipRects) - { - drm_clip_rect_t clear; - int i; - - if (intel->ctx.DrawBuffer->Name == 0) { - /* clearing a window */ - - /* flip top to bottom */ - clear.x1 = cx + intel->drawX; - clear.y1 = intel->driDrawable->y + intel->driDrawable->h - cy - ch; - clear.x2 = clear.x1 + cw; - clear.y2 = clear.y1 + ch; - - /* adjust for page flipping */ - if ( intel->sarea->pf_current_page == 1 ) { - const GLuint tmp = mask; - mask &= ~(BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT); - if ( tmp & BUFFER_BIT_FRONT_LEFT ) mask |= BUFFER_BIT_BACK_LEFT; - if ( tmp & BUFFER_BIT_BACK_LEFT ) mask |= BUFFER_BIT_FRONT_LEFT; - } - } - else { - /* clearing FBO */ - ASSERT(intel->numClipRects == 1); - ASSERT(intel->pClipRects == &intel->fboRect); - clear.x1 = cx; - clear.y1 = intel->ctx.DrawBuffer->Height - cy - ch; - clear.x2 = clear.y1 + cw; - clear.y2 = clear.y1 + ch; - /* no change to mask */ - } - - for (i = 0 ; i < intel->numClipRects ; i++) - { - const drm_clip_rect_t *box = &intel->pClipRects[i]; - drm_clip_rect_t b; - GLuint buf; - GLuint clearMask = mask; /* use copy, since we modify it below */ - - if (!all) { - intel_intersect_cliprects(&b, &clear, box); - } else { - b = *box; - } - - if (0) - _mesa_printf("clear %d,%d..%d,%d, mask %x\n", - b.x1, b.y1, - b.x2, b.y2, - mask); - - /* Loop over all renderbuffers */ - for (buf = 0; buf < BUFFER_COUNT && clearMask; buf++) { - const GLbitfield bufBit = 1 << buf; - if ((clearMask & bufBit) && !(bufBit & skipBuffers)) { - /* OK, clear this renderbuffer */ - const struct intel_renderbuffer *irb - = intel_renderbuffer(ctx->DrawBuffer-> - Attachment[buf].Renderbuffer); - GLuint clearVal; - GLint pitch, cpp; - GLuint BR13, CMD; - - ASSERT(irb); - ASSERT(irb->region); - - pitch = irb->region->pitch; - cpp = irb->region->cpp; - - /* Setup the blit command */ - if (cpp == 4) { - BR13 = (0xF0 << 16) | (pitch * cpp) | (1<<24) | (1<<25); - if (buf == BUFFER_DEPTH || buf == BUFFER_STENCIL) { - CMD = XY_COLOR_BLT_CMD; - if (clearMask & BUFFER_BIT_DEPTH) - CMD |= XY_COLOR_BLT_WRITE_RGB; - if (clearMask & BUFFER_BIT_STENCIL) - CMD |= XY_COLOR_BLT_WRITE_ALPHA; - } - else { - /* clearing RGBA */ - CMD = (XY_COLOR_BLT_CMD | - XY_COLOR_BLT_WRITE_ALPHA | - XY_COLOR_BLT_WRITE_RGB); - } - } - else { - ASSERT(cpp == 2 || cpp == 0); - BR13 = (0xF0 << 16) | (pitch * cpp) | (1<<24); - CMD = XY_COLOR_BLT_CMD; - } - - if (buf == BUFFER_DEPTH || buf == BUFFER_STENCIL) { - clearVal = clear_depth; - } - else { - clearVal = (cpp == 4) - ? intel->ClearColor8888 : intel->ClearColor565; - } - /* - _mesa_debug(ctx, "hardware blit clear buf %d rb id %d\n", - buf, irb->Base.Name); - */ - BEGIN_BATCH(6, INTEL_BATCH_NO_CLIPRECTS); - OUT_BATCH( CMD ); - OUT_BATCH( BR13 ); - OUT_BATCH( (b.y1 << 16) | b.x1 ); - OUT_BATCH( (b.y2 << 16) | b.x2 ); - OUT_RELOC( irb->region->buffer, DRM_MM_TT|DRM_MM_WRITE, - irb->region->draw_offset ); - OUT_BATCH( clearVal ); - ADVANCE_BATCH(); - clearMask &= ~bufBit; /* turn off bit, for faster loop exit */ - } - } - } - intel_batchbuffer_flush( intel->batch ); - } - - UNLOCK_HARDWARE( intel ); -} - - diff --git a/src/mesa/drivers/dri/i915-tex/intel_blit.h b/src/mesa/drivers/dri/i915-tex/intel_blit.h deleted file mode 100644 index 0bbdb0a7ed8..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_blit.h +++ /dev/null @@ -1,60 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#ifndef INTEL_BLIT_H -#define INTEL_BLIT_H - -#include "intel_context.h" -#include "intel_ioctl.h" - -extern void intelCopyBuffer( const __DRIdrawablePrivate *dpriv ); -extern void intelClearWithBlit(GLcontext *ctx, GLbitfield mask, GLboolean all, - GLint cx1, GLint cy1, GLint cw, GLint ch); - -extern void intelEmitCopyBlit( struct intel_context *intel, - GLuint cpp, - GLshort src_pitch, - GLuint src_buffer, - GLuint src_offset, - GLshort dst_pitch, - GLuint dst_buffer, - GLuint dst_offset, - GLshort srcx, GLshort srcy, - GLshort dstx, GLshort dsty, - GLshort w, GLshort h ); - -extern void intelEmitFillBlit( struct intel_context *intel, - GLuint cpp, - GLshort dst_pitch, - GLuint dst_buffer, - GLuint dst_offset, - GLshort x, GLshort y, - GLshort w, GLshort h, - GLuint color ); - - -#endif diff --git a/src/mesa/drivers/dri/i915-tex/intel_buffer_objects.c b/src/mesa/drivers/dri/i915-tex/intel_buffer_objects.c deleted file mode 100644 index 9ef14268d5c..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_buffer_objects.c +++ /dev/null @@ -1,201 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - - -#include "imports.h" -#include "mtypes.h" -#include "bufferobj.h" - -#include "intel_context.h" -#include "intel_buffer_objects.h" -#include "intel_bufmgr.h" - - -/** - * There is some duplication between mesa's bufferobjects and our - * bufmgr buffers. Both have an integer handle and a hashtable to - * lookup an opaque structure. It would be nice if the handles and - * internal structure where somehow shared. - */ -static struct gl_buffer_object *intel_bufferobj_alloc( GLcontext *ctx, - GLuint name, - GLenum target ) -{ - struct intel_context *intel = intel_context(ctx); - struct intel_buffer_object *obj = MALLOC_STRUCT(intel_buffer_object); - - _mesa_initialize_buffer_object(&obj->Base, name, target); - - /* XXX: We generate our own handle, which is different to 'name' above. - */ - bmGenBuffers(intel->bm, 1, &obj->buffer, 0); - - return &obj->Base; -} - - -/** - * Deallocate/free a vertex/pixel buffer object. - * Called via glDeleteBuffersARB(). - */ -static void intel_bufferobj_free( GLcontext *ctx, - struct gl_buffer_object *obj ) -{ - struct intel_context *intel = intel_context(ctx); - struct intel_buffer_object *intel_obj = intel_buffer_object(obj); - - assert(intel_obj); - - if (intel_obj->buffer) - bmDeleteBuffers( intel->bm, 1, &intel_obj->buffer ); - - _mesa_free(intel_obj); -} - - - -/** - * Allocate space for and store data in a buffer object. Any data that was - * previously stored in the buffer object is lost. If data is NULL, - * memory will be allocated, but no copy will occur. - * Called via glBufferDataARB(). - */ -static void intel_bufferobj_data( GLcontext *ctx, - GLenum target, - GLsizeiptrARB size, - const GLvoid *data, - GLenum usage, - struct gl_buffer_object *obj ) -{ - struct intel_context *intel = intel_context(ctx); - struct intel_buffer_object *intel_obj = intel_buffer_object(obj); - - /* XXX: do something useful with 'usage' (eg. populate flags - * argument below) - */ - assert(intel_obj); - - obj->Size = size; - obj->Usage = usage; - - bmBufferData(intel->bm, intel_obj->buffer, size, data, 0); -} - - -/** - * Replace data in a subrange of buffer object. If the data range - * specified by size + offset extends beyond the end of the buffer or - * if data is NULL, no copy is performed. - * Called via glBufferSubDataARB(). - */ -static void intel_bufferobj_subdata( GLcontext *ctx, - GLenum target, - GLintptrARB offset, - GLsizeiptrARB size, - const GLvoid * data, - struct gl_buffer_object * obj ) -{ - struct intel_context *intel = intel_context(ctx); - struct intel_buffer_object *intel_obj = intel_buffer_object(obj); - - assert(intel_obj); - bmBufferSubData(intel->bm, intel_obj->buffer, offset, size, data); -} - - -/** - * Called via glGetBufferSubDataARB(). - */ -static void intel_bufferobj_get_subdata( GLcontext *ctx, - GLenum target, - GLintptrARB offset, - GLsizeiptrARB size, - GLvoid * data, - struct gl_buffer_object * obj ) -{ - struct intel_context *intel = intel_context(ctx); - struct intel_buffer_object *intel_obj = intel_buffer_object(obj); - - assert(intel_obj); - bmBufferGetSubData(intel->bm, intel_obj->buffer, offset, size, data); -} - - - -/** - * Called via glMapBufferARB(). - */ -static void *intel_bufferobj_map( GLcontext *ctx, - GLenum target, - GLenum access, - struct gl_buffer_object *obj ) -{ - struct intel_context *intel = intel_context(ctx); - struct intel_buffer_object *intel_obj = intel_buffer_object(obj); - - /* XXX: Translate access to flags arg below: - */ - assert(intel_obj); - obj->Pointer = bmMapBuffer(intel->bm, intel_obj->buffer, 0); - return obj->Pointer; -} - - -/** - * Called via glMapBufferARB(). - */ -static GLboolean intel_bufferobj_unmap( GLcontext *ctx, - GLenum target, - struct gl_buffer_object *obj ) -{ - struct intel_context *intel = intel_context(ctx); - struct intel_buffer_object *intel_obj = intel_buffer_object(obj); - - assert(intel_obj); - assert(obj->Pointer); - bmUnmapBuffer(intel->bm, intel_obj->buffer); - obj->Pointer = NULL; - return GL_TRUE; -} - -GLuint intel_bufferobj_buffer( const struct intel_buffer_object *intel_obj ) -{ - return intel_obj->buffer; -} - -void intel_bufferobj_init( struct intel_context *intel ) -{ - GLcontext *ctx = &intel->ctx; - - ctx->Driver.NewBufferObject = intel_bufferobj_alloc; - ctx->Driver.DeleteBuffer = intel_bufferobj_free; - ctx->Driver.BufferData = intel_bufferobj_data; - ctx->Driver.BufferSubData = intel_bufferobj_subdata; - ctx->Driver.GetBufferSubData = intel_bufferobj_get_subdata; - ctx->Driver.MapBuffer = intel_bufferobj_map; - ctx->Driver.UnmapBuffer = intel_bufferobj_unmap; -} diff --git a/src/mesa/drivers/dri/i915-tex/intel_buffer_objects.h b/src/mesa/drivers/dri/i915-tex/intel_buffer_objects.h deleted file mode 100644 index 2b7c13d75fe..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_buffer_objects.h +++ /dev/null @@ -1,70 +0,0 @@ - /************************************************************************** - * - * Copyright 2005 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#ifndef INTEL_BUFFEROBJ_H -#define INTEL_BUFFEROBJ_H - -#include "mtypes.h" - -struct intel_context; -struct gl_buffer_object; - - -/** - * Intel vertex/pixel buffer object, derived from Mesa's gl_buffer_object. - */ -struct intel_buffer_object { - struct gl_buffer_object Base; - GLuint buffer; /* the low-level buffer manager's buffer handle */ -}; - - -/* Get the bm buffer associated with a GL bufferobject: - */ -GLuint intel_bufferobj_buffer( const struct intel_buffer_object *obj ); - -/* Hook the bufferobject implementation into mesa: - */ -void intel_bufferobj_init( struct intel_context *intel ); - - - -/* Are the obj->Name tests necessary? Unfortunately yes, mesa - * allocates a couple of gl_buffer_object structs statically, and - * the Name == 0 test is the only way to identify them and avoid - * casting them erroneously to our structs. - */ -static INLINE struct intel_buffer_object * -intel_buffer_object( struct gl_buffer_object *obj ) -{ - if (obj->Name) - return (struct intel_buffer_object *)obj; - else - return NULL; -} - -#endif diff --git a/src/mesa/drivers/dri/i915-tex/intel_buffers.c b/src/mesa/drivers/dri/i915-tex/intel_buffers.c deleted file mode 100644 index 223b9c6ee21..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_buffers.c +++ /dev/null @@ -1,730 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "intel_screen.h" -#include "intel_context.h" -#include "intel_blit.h" -#include "intel_buffers.h" -#include "intel_depthstencil.h" -#include "intel_fbo.h" -#include "intel_tris.h" -#include "intel_regions.h" -#include "intel_batchbuffer.h" -#include "context.h" -#include "framebuffer.h" -#include "swrast/swrast.h" - - -/** - * XXX move this into a new dri/common/cliprects.c file. - */ -GLboolean intel_intersect_cliprects( drm_clip_rect_t *dst, - const drm_clip_rect_t *a, - const drm_clip_rect_t *b ) -{ - GLint bx = b->x1; - GLint by = b->y1; - GLint bw = b->x2 - bx; - GLint bh = b->y2 - by; - - if (bx < a->x1) bw -= a->x1 - bx, bx = a->x1; - if (by < a->y1) bh -= a->y1 - by, by = a->y1; - if (bx + bw > a->x2) bw = a->x2 - bx; - if (by + bh > a->y2) bh = a->y2 - by; - if (bw <= 0) return GL_FALSE; - if (bh <= 0) return GL_FALSE; - - dst->x1 = bx; - dst->y1 = by; - dst->x2 = bx + bw; - dst->y2 = by + bh; - - return GL_TRUE; -} - -/** - * Return pointer to current color drawing region, or NULL. - */ -struct intel_region *intel_drawbuf_region( struct intel_context *intel ) -{ - struct intel_renderbuffer *irbColor = - intel_renderbuffer(intel->ctx.DrawBuffer->_ColorDrawBuffers[0][0]); - if (irbColor) - return irbColor->region; - else - return NULL; -} - -/** - * Return pointer to current color reading region, or NULL. - */ -struct intel_region *intel_readbuf_region( struct intel_context *intel ) -{ - struct intel_renderbuffer *irb - = intel_renderbuffer(intel->ctx.ReadBuffer->_ColorReadBuffer); - if (irb) - return irb->region; - else - return NULL; -} - - - -static void intelBufferSize(GLframebuffer *buffer, - GLuint *width, - GLuint *height) -{ - GET_CURRENT_CONTEXT(ctx); - struct intel_context *intel = intel_context(ctx); - /* Need to lock to make sure the driDrawable is uptodate. This - * information is used to resize Mesa's software buffers, so it has - * to be correct. - */ - /* XXX This isn't 100% correct, the given buffer might not be - * bound to the current context! - */ - LOCK_HARDWARE(intel); - if (intel->driDrawable) { - *width = intel->driDrawable->w; - *height = intel->driDrawable->h; - } - else { - *width = 0; - *height = 0; - } - UNLOCK_HARDWARE(intel); -} - - - -/** - * Update the following fields for rendering to a user-created FBO: - * intel->numClipRects - * intel->pClipRects - * intel->drawX - * intel->drawY - */ -static void intelSetRenderbufferClipRects( struct intel_context *intel ) -{ - assert(intel->ctx.DrawBuffer->Width > 0); - assert(intel->ctx.DrawBuffer->Height > 0); - intel->fboRect.x1 = 0; - intel->fboRect.y1 = 0; - intel->fboRect.x2 = intel->ctx.DrawBuffer->Width; - intel->fboRect.y2 = intel->ctx.DrawBuffer->Height; - intel->numClipRects = 1; - intel->pClipRects = &intel->fboRect; - intel->drawX = 0; - intel->drawY = 0; -} - - -/** - * As above, but for rendering to front buffer of a window. - * \sa intelSetRenderbufferClipRects - */ -static void intelSetFrontClipRects( struct intel_context *intel ) -{ - __DRIdrawablePrivate *dPriv = intel->driDrawable; - - if (!dPriv) return; - - intel->numClipRects = dPriv->numClipRects; - intel->pClipRects = dPriv->pClipRects; - intel->drawX = dPriv->x; - intel->drawY = dPriv->y; -} - - -/** - * As above, but for rendering to back buffer of a window. - */ -static void intelSetBackClipRects( struct intel_context *intel ) -{ - __DRIdrawablePrivate *dPriv = intel->driDrawable; - - if (!dPriv) return; - - if (intel->sarea->pf_enabled == 0 && dPriv->numBackClipRects == 0) { - /* use the front clip rects */ - intel->numClipRects = dPriv->numClipRects; - intel->pClipRects = dPriv->pClipRects; - intel->drawX = dPriv->x; - intel->drawY = dPriv->y; - } else { - /* use the back clip rects */ - intel->numClipRects = dPriv->numBackClipRects; - intel->pClipRects = dPriv->pBackClipRects; - intel->drawX = dPriv->backX; - intel->drawY = dPriv->backY; - - if (dPriv->numBackClipRects == 1 && - dPriv->x == dPriv->backX && - dPriv->y == dPriv->backY) { - - /* Repeat the calculation of the back cliprect dimensions here - * as early versions of dri.a in the Xserver are incorrect. Try - * very hard not to restrict future versions of dri.a which - * might eg. allocate truly private back buffers. - */ - int x1, y1; - int x2, y2; - - x1 = dPriv->x; - y1 = dPriv->y; - x2 = dPriv->x + dPriv->w; - y2 = dPriv->y + dPriv->h; - - if (x1 < 0) x1 = 0; - if (y1 < 0) y1 = 0; - if (x2 > intel->intelScreen->width) x2 = intel->intelScreen->width; - if (y2 > intel->intelScreen->height) y2 = intel->intelScreen->height; - - if (x1 == dPriv->pBackClipRects[0].x1 && - y1 == dPriv->pBackClipRects[0].y1) { - - dPriv->pBackClipRects[0].x2 = x2; - dPriv->pBackClipRects[0].y2 = y2; - } - } - } -} - - -/** - * This will be called whenever the currently bound window is moved/resized. - * XXX: actually, it seems to NOT be called when the window is only moved (BP). - */ -void intelWindowMoved( struct intel_context *intel ) -{ - GLcontext *ctx = &intel->ctx; - - if (!intel->ctx.DrawBuffer) { - /* when would this happen? -BP */ - intelSetFrontClipRects( intel ); - } - else if (intel->ctx.DrawBuffer->Name != 0) { - /* drawing to user-created FBO - do nothing */ - /* Cliprects would be set from intelDrawBuffer() */ - } - else { - /* drawing to a window */ - switch (intel->ctx.DrawBuffer->_ColorDrawBufferMask[0]) { - case BUFFER_BIT_FRONT_LEFT: - intelSetFrontClipRects( intel ); - break; - case BUFFER_BIT_BACK_LEFT: - intelSetBackClipRects( intel ); - break; - default: - /* glDrawBuffer(GL_NONE or GL_FRONT_AND_BACK): software fallback */ - intelSetFrontClipRects( intel ); - } - } - - /* this update Mesa's notion of window size */ - if (ctx->WinSysDrawBuffer) { - _mesa_resize_framebuffer(ctx, ctx->WinSysDrawBuffer, - intel->driDrawable->w, intel->driDrawable->h); - } - - /* Update hardware scissor */ - ctx->Driver.Scissor( ctx, ctx->Scissor.X, ctx->Scissor.Y, - ctx->Scissor.Width, ctx->Scissor.Height ); -} - - - -/* A true meta version of this would be very simple and additionally - * machine independent. Maybe we'll get there one day. - */ -static void intelClearWithTris(struct intel_context *intel, - GLbitfield mask, - GLboolean all, - GLint cx, GLint cy, - GLint cw, GLint ch) -{ - GLcontext *ctx = &intel->ctx; - drm_clip_rect_t clear; - - if (INTEL_DEBUG & DEBUG_DRI) - _mesa_printf("%s 0x%x\n", __FUNCTION__, mask); - - LOCK_HARDWARE(intel); - - /* XXX FBO: was: intel->driDrawable->numClipRects */ - if (intel->numClipRects) { - GLuint buf; - - intel->vtbl.install_meta_state(intel); - - /* note: regardless of 'all', cx, cy, cw, ch are correct */ - clear.x1 = cx; - clear.y1 = cy; - clear.x2 = cx + cw; - clear.y2 = cy + ch; - - /* Back and stencil cliprects are the same. Try and do both - * buffers at once: - */ - if (mask & (BUFFER_BIT_BACK_LEFT|BUFFER_BIT_STENCIL|BUFFER_BIT_DEPTH)) { - struct intel_region *backRegion - = intel_get_rb_region(ctx->DrawBuffer, BUFFER_BACK_LEFT); - struct intel_region *depthRegion - = intel_get_rb_region(ctx->DrawBuffer, BUFFER_DEPTH); - const GLuint clearColor = (backRegion && backRegion->cpp == 4) - ? intel->ClearColor8888 : intel->ClearColor565; - - intel->vtbl.meta_draw_region(intel, backRegion, depthRegion ); - - if (mask & BUFFER_BIT_BACK_LEFT) - intel->vtbl.meta_color_mask(intel, GL_TRUE ); - else - intel->vtbl.meta_color_mask(intel, GL_FALSE ); - - if (mask & BUFFER_BIT_STENCIL) - intel->vtbl.meta_stencil_replace( intel, - intel->ctx.Stencil.WriteMask[0], - intel->ctx.Stencil.Clear); - else - intel->vtbl.meta_no_stencil_write(intel); - - if (mask & BUFFER_BIT_DEPTH) - intel->vtbl.meta_depth_replace( intel ); - else - intel->vtbl.meta_no_depth_write(intel); - - /* XXX: Using INTEL_BATCH_NO_CLIPRECTS here is dangerous as the - * drawing origin may not be correctly emitted. - */ - intel_meta_draw_quad(intel, - clear.x1, clear.x2, - clear.y1, clear.y2, - intel->ctx.Depth.Clear, - clearColor, - 0, 0, 0, 0); /* texcoords */ - - mask &= ~(BUFFER_BIT_BACK_LEFT|BUFFER_BIT_STENCIL|BUFFER_BIT_DEPTH); - } - - /* clear the remaining (color) renderbuffers */ - for (buf = 0; buf < BUFFER_COUNT && mask; buf++) { - const GLuint bufBit = 1 << buf; - if (mask & bufBit) { - struct intel_renderbuffer *irbColor = - intel_renderbuffer(ctx->DrawBuffer-> - Attachment[buf].Renderbuffer); - GLuint color = (irbColor->region->cpp == 4) - ? intel->ClearColor8888 : intel->ClearColor565; - - ASSERT(irbColor); - - intel->vtbl.meta_no_depth_write(intel); - intel->vtbl.meta_no_stencil_write(intel); - intel->vtbl.meta_color_mask(intel, GL_TRUE ); - intel->vtbl.meta_draw_region(intel, irbColor->region, NULL); - - /* XXX: Using INTEL_BATCH_NO_CLIPRECTS here is dangerous as the - * drawing origin may not be correctly emitted. - */ - intel_meta_draw_quad(intel, - clear.x1, clear.x2, - clear.y1, clear.y2, - 0, /* depth clear val */ - color, - 0, 0, 0, 0); /* texcoords */ - - mask &= ~bufBit; - } - } - - intel->vtbl.leave_meta_state( intel ); - intel_batchbuffer_flush( intel->batch ); - } - UNLOCK_HARDWARE(intel); -} - - - -/** - * Called by ctx->Driver.Clear. - */ -static void intelClear(GLcontext *ctx, - GLbitfield mask, - GLboolean all, - GLint cx, GLint cy, - GLint cw, GLint ch) -{ - struct intel_context *intel = intel_context( ctx ); - const GLuint colorMask = *((GLuint *) &ctx->Color.ColorMask); - GLbitfield tri_mask = 0; - GLbitfield blit_mask = 0; - GLbitfield swrast_mask = 0; - GLuint i; - - if (0) - fprintf(stderr, "%s\n", __FUNCTION__); - - /* HW color buffers (front, back, aux, generic FBO, etc) */ - if (colorMask == ~0) { - /* clear all R,G,B,A */ - /* XXX FBO: need to check if colorbuffers are software RBOs! */ - blit_mask |= (mask & BUFFER_BITS_COLOR); - } - else { - /* glColorMask in effect */ - tri_mask |= (mask & BUFFER_BITS_COLOR); - } - - /* HW stencil */ - if (mask & BUFFER_BIT_STENCIL) { - const struct intel_region *stencilRegion - = intel_get_rb_region(ctx->DrawBuffer, BUFFER_STENCIL); - if (stencilRegion) { - /* have hw stencil */ - if ((ctx->Stencil.WriteMask[0] & 0xff) != 0xff) { - /* not clearing all stencil bits, so use triangle clearing */ - tri_mask |= BUFFER_BIT_STENCIL; - } - else { - /* clearing all stencil bits, use blitting */ - blit_mask |= BUFFER_BIT_STENCIL; - } - } - } - - /* HW depth */ - if (mask & BUFFER_BIT_DEPTH) { - /* clear depth with whatever method is used for stencil (see above) */ - if (tri_mask & BUFFER_BIT_STENCIL) - tri_mask |= BUFFER_BIT_DEPTH; - else - blit_mask |= BUFFER_BIT_DEPTH; - } - - /* SW fallback clearing */ - swrast_mask = mask & ~tri_mask & ~blit_mask; - - for (i = 0; i < BUFFER_COUNT; i++) { - GLuint bufBit = 1 << i; - if ((blit_mask | tri_mask) & bufBit) { - if (!ctx->DrawBuffer->Attachment[i].Renderbuffer->ClassID) { - blit_mask &= ~bufBit; - tri_mask &= ~bufBit; - swrast_mask |= bufBit; - } - } - } - - - intelFlush( ctx ); /* XXX intelClearWithBlit also does this */ - - if (blit_mask) - intelClearWithBlit( ctx, blit_mask, all, cx, cy, cw, ch ); - - if (tri_mask) - intelClearWithTris( intel, tri_mask, all, cx, cy, cw, ch); - - if (swrast_mask) - _swrast_Clear( ctx, swrast_mask, all, cx, cy, cw, ch ); -} - - - -/* Flip the front & back buffers - */ -static void intelPageFlip( const __DRIdrawablePrivate *dPriv ) -{ -#if 0 - struct intel_context *intel; - int tmp, ret; - - if (INTEL_DEBUG & DEBUG_IOCTL) - fprintf(stderr, "%s\n", __FUNCTION__); - - assert(dPriv); - assert(dPriv->driContextPriv); - assert(dPriv->driContextPriv->driverPrivate); - - intel = (struct intel_context *) dPriv->driContextPriv->driverPrivate; - - intelFlush( &intel->ctx ); - LOCK_HARDWARE( intel ); - - if (dPriv->pClipRects) { - *(drm_clip_rect_t *)intel->sarea->boxes = dPriv->pClipRects[0]; - intel->sarea->nbox = 1; - } - - ret = drmCommandNone(intel->driFd, DRM_I830_FLIP); - if (ret) { - fprintf(stderr, "%s: %d\n", __FUNCTION__, ret); - UNLOCK_HARDWARE( intel ); - exit(1); - } - - tmp = intel->sarea->last_enqueue; - intelRefillBatchLocked( intel ); - UNLOCK_HARDWARE( intel ); - - - intelSetDrawBuffer( &intel->ctx, intel->ctx.Color.DriverDrawBuffer ); -#endif -} - - -void intelSwapBuffers( __DRIdrawablePrivate *dPriv ) -{ - if (dPriv->driverPrivate) { - const struct gl_framebuffer *fb - = (struct gl_framebuffer *) dPriv->driverPrivate; - if (fb->Visual.doubleBufferMode) { - GET_CURRENT_CONTEXT(ctx); - if (ctx && ctx->DrawBuffer == fb) { - _mesa_notifySwapBuffers( ctx ); /* flush pending rendering */ - } - if ( 0 /*intel->doPageFlip*/ ) { /* doPageFlip is never set !!! */ - intelPageFlip( dPriv ); - } else { - intelCopyBuffer( dPriv ); - } - } - } - else { - _mesa_problem(NULL, - "dPriv has no gl_framebuffer pointer in intelSwapBuffers"); - } -} - - -/** - * Update the hardware state for drawing into a window or framebuffer object. - * - * Called by glDrawBuffer, glBindFramebufferEXT, MakeCurrent, and other - * places within the driver. - * - * Basically, this needs to be called any time the current framebuffer - * changes, the renderbuffers change, or we need to draw into different - * color buffers. - */ -void -intel_draw_buffer(GLcontext *ctx, struct gl_framebuffer *fb) -{ - struct intel_context *intel = intel_context(ctx); - struct intel_region *colorRegion, *depthRegion = NULL; - struct intel_renderbuffer *irbDepth = NULL, *irbStencil = NULL; - int front = 0; /* drawing to front color buffer? */ - - if (!fb) { - /* this can happen during the initial context initialization */ - return; - } - - /* Do this here, note core Mesa, since this function is called from - * many places within the driver. - */ - if (ctx->NewState & (_NEW_BUFFERS | _NEW_COLOR | _NEW_PIXEL)) { - /* this updates the DrawBuffer->_NumColorDrawBuffers fields, etc */ - _mesa_update_framebuffer(ctx); - /* this updates the DrawBuffer's Width/Height if it's a FBO */ - _mesa_update_draw_buffer_bounds(ctx); - } - - if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { - /* this may occur when we're called by glBindFrameBuffer() during - * the process of someone setting up renderbuffers, etc. - */ - _mesa_debug(ctx, "DrawBuffer: incomplete user FBO\n"); - return; - } - - if (fb->Name) - intel_validate_paired_depth_stencil(ctx, fb); - - /* - * How many color buffers are we drawing into? - */ - if (fb->_NumColorDrawBuffers[0] != 1 -#if 0 - /* XXX FBO temporary - always use software rendering */ - || 1 -#endif - ) { - /* writing to 0 or 2 or 4 color buffers */ - /*_mesa_debug(ctx, "Software rendering\n");*/ - FALLBACK( intel, INTEL_FALLBACK_DRAW_BUFFER, GL_TRUE ); - front = 1; /* might not have back color buffer */ - } - else { - /* draw to exactly one color buffer */ - /*_mesa_debug(ctx, "Hardware rendering\n");*/ - FALLBACK( intel, INTEL_FALLBACK_DRAW_BUFFER, GL_FALSE ); - if (fb->_ColorDrawBufferMask[0] == BUFFER_BIT_FRONT_LEFT) { - front = 1; - } - } - - /* - * Get the intel_renderbuffer for the colorbuffer we're drawing into. - * And set up cliprects. - */ - if (fb->Name == 0) { - /* drawing to window system buffer */ - if (intel->sarea->pf_current_page == 1 ) { - /* page flipped back/front */ - front ^= 1; - } - if (front) { - intelSetFrontClipRects( intel ); - colorRegion = intel_get_rb_region(fb, BUFFER_FRONT_LEFT); - } - else { - intelSetBackClipRects( intel ); - colorRegion = intel_get_rb_region(fb, BUFFER_BACK_LEFT); - } - } - else { - /* drawing to user-created FBO */ - struct intel_renderbuffer *irb; - intelSetRenderbufferClipRects(intel); - irb = intel_renderbuffer(fb->_ColorDrawBuffers[0][0]); - colorRegion = (irb && irb->region) ? irb->region : NULL; - } - - if (!colorRegion) { - FALLBACK( intel, INTEL_FALLBACK_DRAW_BUFFER, GL_TRUE ); - } - else { - FALLBACK( intel, INTEL_FALLBACK_DRAW_BUFFER, GL_FALSE ); - } - - /*** - *** Get depth buffer region and check if we need a software fallback. - *** Note that the depth buffer is usually a DEPTH_STENCIL buffer. - ***/ - if (fb->_DepthBuffer && fb->_DepthBuffer->Wrapped) { - irbDepth = intel_renderbuffer(fb->_DepthBuffer->Wrapped); - if (irbDepth->region) { - FALLBACK(intel, INTEL_FALLBACK_DEPTH_BUFFER, GL_FALSE); - depthRegion = irbDepth->region; - } - else { - FALLBACK(intel, INTEL_FALLBACK_DEPTH_BUFFER, GL_TRUE); - depthRegion = NULL; - } - } - else { - /* not using depth buffer */ - FALLBACK(intel, INTEL_FALLBACK_DEPTH_BUFFER, GL_FALSE); - depthRegion = NULL; - } - - /*** - *** Stencil buffer - *** This can only be hardware accelerated if we're using a - *** combined DEPTH_STENCIL buffer (for now anyway). - ***/ - if (fb->_StencilBuffer && fb->_StencilBuffer->Wrapped) { - irbStencil = intel_renderbuffer(fb->_StencilBuffer->Wrapped); - if (irbStencil && irbStencil->region) { - ASSERT(irbStencil->Base._ActualFormat == GL_DEPTH24_STENCIL8_EXT); - FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, GL_FALSE); - /* need to re-compute stencil hw state */ - ctx->Driver.Enable(ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled); - if (!depthRegion) - depthRegion = irbStencil->region; - } - else { - FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, GL_TRUE); - } - } - else { - /* XXX FBO: instead of FALSE, pass ctx->Stencil.Enabled ??? */ - FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, GL_FALSE); - /* need to re-compute stencil hw state */ - ctx->Driver.Enable(ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled); - } - - - /** - ** Release old regions, reference new regions - **/ -#if 0 /* XXX FBO: this seems to be redundant with i915_state_draw_region() */ - if (intel->draw_region != colorRegion) { - intel_region_release(intel, &intel->draw_region); - intel_region_reference(&intel->draw_region, colorRegion); - } - if (intel->depth_region != depthRegion) { - intel_region_release(intel, &intel->depth_region); - intel_region_reference(&intel->depth_region, depthRegion); - } -#endif - - intel->vtbl.set_draw_region( intel, colorRegion, depthRegion ); - - /* update viewport since it depends on window size */ - ctx->Driver.Viewport(ctx, ctx->Viewport.X, ctx->Viewport.Y, - ctx->Viewport.Width, ctx->Viewport.Height); - - /* Update hardware scissor */ - ctx->Driver.Scissor( ctx, ctx->Scissor.X, ctx->Scissor.Y, - ctx->Scissor.Width, ctx->Scissor.Height ); -} - - -static void -intelDrawBuffer(GLcontext *ctx, GLenum mode) -{ - intel_draw_buffer(ctx, ctx->DrawBuffer); -} - - -static void -intelReadBuffer( GLcontext *ctx, GLenum mode ) -{ - if (ctx->ReadBuffer == ctx->DrawBuffer) { - /* This will update FBO completeness status. - * A framebuffer will be incomplete if the GL_READ_BUFFER setting - * refers to a missing renderbuffer. Calling glReadBuffer can set - * that straight and can make the drawing buffer complete. - */ - intel_draw_buffer(ctx, ctx->DrawBuffer); - } - /* Generally, functions which read pixels (glReadPixels, glCopyPixels, etc) - * reference ctx->ReadBuffer and do appropriate state checks. - */ -} - - -void intelInitBufferFuncs( struct dd_function_table *functions ) -{ - functions->Clear = intelClear; - functions->GetBufferSize = intelBufferSize; - functions->ResizeBuffers = _mesa_resize_framebuffer; - functions->DrawBuffer = intelDrawBuffer; - functions->ReadBuffer = intelReadBuffer; -} diff --git a/src/mesa/drivers/dri/i915-tex/intel_buffers.h b/src/mesa/drivers/dri/i915-tex/intel_buffers.h deleted file mode 100644 index 309022b0739..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_buffers.h +++ /dev/null @@ -1,58 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#ifndef INTEL_BUFFERS_H -#define INTEL_BUFFERS_H - - -struct intel_context; - - -extern GLboolean -intel_intersect_cliprects(drm_clip_rect_t *dest, - const drm_clip_rect_t *a, - const drm_clip_rect_t *b); - -extern struct intel_region * -intel_readbuf_region(struct intel_context *intel); - -extern struct intel_region * -intel_drawbuf_region(struct intel_context *intel); - -extern void -intelSwapBuffers( __DRIdrawablePrivate *dPriv); - -extern void -intelWindowMoved(struct intel_context *intel); - -extern void -intel_draw_buffer(GLcontext *ctx, struct gl_framebuffer *fb); - -extern void -intelInitBufferFuncs(struct dd_function_table *functions); - -#endif /* INTEL_BUFFERS_H */ diff --git a/src/mesa/drivers/dri/i915-tex/intel_bufmgr.c b/src/mesa/drivers/dri/i915-tex/intel_bufmgr.c deleted file mode 100644 index 46631555dc2..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_bufmgr.c +++ /dev/null @@ -1,444 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Steamboat Springs, CO. - * 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, 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 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 - * THE COPYRIGHT HOLDERS, AUTHORS 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. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * - **************************************************************************/ - -#include "intel_bufmgr.h" - -#include "intel_context.h" -#include "intel_ioctl.h" - -#include "hash.h" -#include "simple_list.h" -#include "mm.h" -#include "imports.h" -#include "glthread.h" -#include <sys/ioctl.h> -#include <unistd.h> -#include <drm.h> - -struct _mesa_HashTable; - -/* The buffer manager is really part of the gl_shared_state struct. - * TODO: Organize for the bufmgr to be created/deleted with the shared - * state and stored within the DriverData of that struct. Currently - * there are no mesa callbacks for this. - */ - -#define BM_MAX 16 -static struct bufmgr -{ - _glthread_Mutex mutex; /**< for thread safety */ - int driFd; - int refcount; - struct _mesa_HashTable *hash; - - unsigned buf_nr; /* for generating ids */ - drmMMPool batchPool; - -} bufmgr_pool[BM_MAX]; - -static int nr_bms; - -#define LOCK(bm) _glthread_LOCK_MUTEX(bm->mutex) -#define UNLOCK(bm) _glthread_UNLOCK_MUTEX(bm->mutex) - -static void -bmError(int val, const char *file, const char *function, int line) -{ - _mesa_printf("Fatal video memory manager error \"%s\".\n" - "Check kernel logs or set the LIBGL_DEBUG\n" - "environment variable to \"verbose\" for more info.\n" - "Detected in file %s, line %d, function %s.\n", - strerror(-val), file, line, function); -#ifndef NDEBUG - exit(-1); -#else - abort(); -#endif -} - -#define BM_CKFATAL(val) \ - do{ \ - int tstVal = (val); \ - if (tstVal) \ - bmError(tstVal, __FILE__, __FUNCTION__, __LINE__); \ - } while(0); - -/*********************************************************************** - * Public functions - */ - -/* The initialization functions are skewed in the fake implementation. - * This call would be to attach to an existing manager, rather than to - * create a local one. - */ - -struct bufmgr * -bm_intel_Attach(struct intel_context *intel) -{ - GLuint i; - - for (i = 0; i < nr_bms; i++) - if (bufmgr_pool[i].driFd == intel->driFd) { - bufmgr_pool[i].refcount++; - _mesa_printf("retrieive old bufmgr for fd %d\n", - bufmgr_pool[i].driFd); - return &bufmgr_pool[i]; - } - - if (nr_bms < BM_MAX) { - struct bufmgr *bm = &bufmgr_pool[nr_bms++]; - - _mesa_printf("create new bufmgr for fd %d\n", intel->driFd); - bm->driFd = intel->driFd; - bm->hash = _mesa_NewHashTable(); - bm->refcount = 1; - _glthread_INIT_MUTEX(bm->mutex); - - drmGetLock(bm->driFd, intel->hHWContext, 0); - BM_CKFATAL(drmMMAllocBufferPool(bm->driFd, mmPoolRing, 0, - DRM_MM_TT | DRM_MM_NO_EVICT | - DRM_MM_READ | DRM_MM_EXE | - BM_BATCHBUFFER, 1024 * 1024, 4096, - &bm->batchPool)); - - drmUnlock(bm->driFd, intel->hHWContext); - return bm; - } - - _mesa_printf("failed to create new bufmgr for fd %d\n", intel->driFd); - return NULL; -} - -void -bmGenBuffers(struct bufmgr *bm, unsigned n, unsigned *buffers, unsigned flags) -{ - LOCK(bm); - { - unsigned i; - unsigned bFlags = - (flags) ? flags : DRM_MM_TT | DRM_MM_VRAM | DRM_MM_SYSTEM; - - for (i = 0; i < n; i++) { - drmMMBuf *buf = calloc(sizeof(*buf), 1); - - BM_CKFATAL(drmMMInitBuffer(bm->driFd, bFlags, 12, buf)); - buf->client_priv = ++bm->buf_nr; - buffers[i] = buf->client_priv; - _mesa_HashInsert(bm->hash, buffers[i], buf); - } - } - UNLOCK(bm); -} - -void -bmSetShared(struct bufmgr *bm, unsigned buffer, unsigned flags, - unsigned long offset, void *virtual) -{ - LOCK(bm); - { - drmMMBuf *buf = _mesa_HashLookup(bm->hash, buffer); - - assert(buf); - - buf->flags = DRM_MM_NO_EVICT | DRM_MM_SHARED - | DRM_MM_WRITE | DRM_MM_READ; - buf->flags |= flags & DRM_MM_MEMTYPE_MASK; - buf->offset = offset; - buf->virtual = virtual; - BM_CKFATAL(drmMMAllocBuffer(bm->driFd, 0, NULL, 0, buf)); - } - UNLOCK(bm); -} - -void -bmDeleteBuffers(struct bufmgr *bm, unsigned n, unsigned *buffers) -{ - LOCK(bm); - { - unsigned i; - - for (i = 0; i < n; i++) { - drmMMBuf *buf = _mesa_HashLookup(bm->hash, buffers[i]); - - if (buf) { - BM_CKFATAL(drmMMFreeBuffer(bm->driFd, buf)); - - _mesa_HashRemove(bm->hash, buffers[i]); - } - } - } - UNLOCK(bm); -} - -/* If buffer size changes, free and reallocate. Otherwise update in - * place. - */ - -void -bmBufferData(struct bufmgr *bm, - unsigned buffer, unsigned size, const void *data, unsigned flags) -{ - LOCK(bm); - { - drmMMBuf *buf = (drmMMBuf *) _mesa_HashLookup(bm->hash, buffer); - - DBG("bmBufferData %d sz 0x%x data: %p\n", buffer, size, data); - - assert(buf); - assert(!buf->mapped); - - if (buf->flags & BM_BATCHBUFFER) { - BM_CKFATAL(drmMMFreeBuffer(bm->driFd, buf)); - BM_CKFATAL(drmMMAllocBuffer - (bm->driFd, size, &bm->batchPool, 1, buf)); - } else if (!(buf->flags & DRM_MM_SHARED)) { - - if (buf->block && (buf->size < size || drmBufIsBusy(bm->driFd, buf))) { - BM_CKFATAL(drmMMFreeBuffer(bm->driFd, buf)); - } - if (!buf->block) { - BM_CKFATAL(drmMMAllocBuffer(bm->driFd, size, NULL, 0, buf)); - } - - } - - if (data != NULL) { - - memcpy(drmMMMapBuffer(bm->driFd, buf), data, size); - drmMMUnmapBuffer(bm->driFd, buf); - - } - } - UNLOCK(bm); -} - -/* Update the buffer in place, in whatever space it is currently resident: - */ -void -bmBufferSubData(struct bufmgr *bm, - unsigned buffer, - unsigned offset, unsigned size, const void *data) -{ - LOCK(bm); - { - drmMMBuf *buf = (drmMMBuf *) _mesa_HashLookup(bm->hash, buffer); - - DBG("bmBufferSubdata %d offset 0x%x sz 0x%x\n", buffer, offset, size); - - assert(buf); - drmBufWaitBusy(bm->driFd, buf); - - if (size) { - memcpy((unsigned char *) drmMMMapBuffer(bm->driFd, buf) + offset, - data, size); - drmMMUnmapBuffer(bm->driFd, buf); - } - } - UNLOCK(bm); -} - -/* Extract data from the buffer: - */ -void -bmBufferGetSubData(struct bufmgr *bm, - unsigned buffer, - unsigned offset, unsigned size, void *data) -{ - LOCK(bm); - { - drmMMBuf *buf = (drmMMBuf *) _mesa_HashLookup(bm->hash, buffer); - - DBG("bmBufferSubdata %d offset 0x%x sz 0x%x\n", buffer, offset, size); - - assert(buf); - drmBufWaitBusy(bm->driFd, buf); - - if (size) { - memcpy(data, - (unsigned char *) drmMMMapBuffer(bm->driFd, buf) + offset, - size); - drmMMUnmapBuffer(bm->driFd, buf); - } - } - UNLOCK(bm); -} - -/* Return a pointer to whatever space the buffer is currently resident in: - */ -void * -bmMapBuffer(struct bufmgr *bm, unsigned buffer, unsigned flags) -{ - void *retval; - - LOCK(bm); - { - drmMMBuf *buf = (drmMMBuf *) _mesa_HashLookup(bm->hash, buffer); - - DBG("bmMapBuffer %d\n", buffer); - DBG("Map: Block is 0x%x\n", &buf->block); - - assert(buf); - /* assert(!buf->mapped); */ - retval = drmMMMapBuffer(bm->driFd, buf); - } - UNLOCK(bm); - - return retval; -} - -void -bmUnmapBuffer(struct bufmgr *bm, unsigned buffer) -{ - LOCK(bm); - { - drmMMBuf *buf = (drmMMBuf *) _mesa_HashLookup(bm->hash, buffer); - - if (!buf) - goto out; - - DBG("bmUnmapBuffer %d\n", buffer); - - drmMMUnmapBuffer(bm->driFd, buf); - } - out: - UNLOCK(bm); -} - -/* Build the list of buffers to validate. Note that the buffer list - * isn't a shared structure so we don't need mutexes when manipulating - * it. - * - * XXX: need refcounting for drmMMBuf structs so that they can't be - * deleted while on these lists. - */ -struct _drmMMBufList * -bmNewBufferList(void) -{ - return drmMMInitListHead(); -} - -int -bmAddBuffer(struct bufmgr *bm, - struct _drmMMBufList *list, - unsigned buffer, - unsigned flags, - unsigned *memtype_return, unsigned long *offset_return) -{ - drmMMBuf *buf = (drmMMBuf *) _mesa_HashLookup(bm->hash, buffer); - - assert(buf); - return drmMMBufListAdd(list, buf, 0, flags, memtype_return, offset_return); -} - -void -bmFreeBufferList(struct _drmMMBufList *list) -{ - drmMMFreeBufList(list); -} - -int -bmScanBufferList(struct bufmgr *bm, - struct _drmMMBufList *list, unsigned buffer) -{ - drmMMBuf *buf = (drmMMBuf *) _mesa_HashLookup(bm->hash, buffer); - - assert(buf); - return drmMMScanBufList(list, buf); -} - -/* To be called prior to emitting commands to hardware which reference - * these buffers. The buffer_usage list provides information on where - * the buffers should be placed and whether their contents need to be - * preserved on copying. The offset and pool data elements are return - * values from this function telling the driver exactly where the - * buffers are currently located. - */ - -int -bmValidateBufferList(struct bufmgr *bm, - struct _drmMMBufList *list, unsigned flags) -{ - BM_CKFATAL(drmMMValidateBuffers(bm->driFd, list)); - return 0; -} - -/* After commands are emitted but before unlocking, this must be - * called so that the buffer manager can correctly age the buffers. - * The buffer manager keeps track of the list of validated buffers, so - * already knows what to apply the fence to. - * - * The buffer manager knows how to emit and test fences directly - * through the drm and without callbacks or whatever into the driver. - */ -unsigned -bmFenceBufferList(struct bufmgr *bm, struct _drmMMBufList *list) -{ - drmFence fence; - - BM_CKFATAL(drmMMFenceBuffers(bm->driFd, list)); - BM_CKFATAL(drmEmitFence(bm->driFd, 0, &fence)); - - return fence.fenceSeq; -} - -/* This functionality is used by the buffer manager, not really sure - * if we need to be exposing it in this way, probably libdrm will - * offer equivalent calls. - * - * For now they can stay, but will likely change/move before final: - */ -unsigned -bmSetFence(struct bufmgr *bm) -{ - drmFence dFence; - - BM_CKFATAL(drmEmitFence(bm->driFd, 0, &dFence)); - - return dFence.fenceSeq; -} - -int -bmTestFence(struct bufmgr *bm, unsigned fence) -{ - drmFence dFence; - int retired; - - dFence.fenceType = 0; - dFence.fenceSeq = fence; - BM_CKFATAL(drmTestFence(bm->driFd, dFence, 0, &retired)); - return retired; -} - -void -bmFinishFence(struct bufmgr *bm, unsigned fence) -{ - drmFence dFence; - dFence.fenceType = 0; - dFence.fenceSeq = fence; - BM_CKFATAL(drmWaitFence(bm->driFd, dFence)); -} diff --git a/src/mesa/drivers/dri/i915-tex/intel_bufmgr.h b/src/mesa/drivers/dri/i915-tex/intel_bufmgr.h deleted file mode 100644 index f323611c48c..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_bufmgr.h +++ /dev/null @@ -1,132 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Steamboat Springs, CO. - * 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, 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 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 - * THE COPYRIGHT HOLDERS, AUTHORS 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. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * - **************************************************************************/ - -#ifndef BUFMGR_H -#define BUFMGR_H - -#include "intel_context.h" - -/* Note that this is destined to be external to Mesa, so don't use GL - * types like GLuint, etc. - */ - -/* The buffer manager context. Opaque. - */ -struct bufmgr; - -struct bufmgr *bm_intel_Attach(struct intel_context *intel); - -#define BM_BATCHBUFFER 0x10000000 /* for map - pointer will be accessed - * without dri lock */ - -/* Stick closely to ARB_vbo semantics - they're well defined and - * understood, and drivers can just pass the calls through without too - * much thunking. - */ -void bmGenBuffers(struct bufmgr *, unsigned n, unsigned *buffers, - unsigned flags); - -void bmDeleteBuffers(struct bufmgr *, unsigned n, unsigned *buffers); - -/* The driver has more intimate knowledge of the hardare than a GL - * client would, so flags here is more proscriptive than the usage - * values in the ARB_vbo interface: - */ -void bmBufferData(struct bufmgr *, - unsigned buffer, - unsigned size, const void *data, unsigned flags); - -void bmBufferSubData(struct bufmgr *, - unsigned buffer, - unsigned offset, unsigned size, const void *data); - -void bmBufferGetSubData(struct bufmgr *, - unsigned buffer, - unsigned offset, unsigned size, void *data); - -void *bmMapBuffer(struct bufmgr *, unsigned buffer, unsigned access); - -void bmUnmapBuffer(struct bufmgr *, unsigned buffer); - -/* To be called prior to emitting commands to hardware which reference - * these buffers. - * - * NewBufferList() and AddBuffer() build up a list of buffers to be - * validated. The buffer list provides information on where the - * buffers should be placed and whether their contents need to be - * preserved on copying. The offset data elements are return values - * from this function telling the driver exactly where the buffers are - * currently located. - * - * ValidateBufferList() performs the actual validation and returns the - * buffer pools and offsets within the pools. - * - * FenceBufferList() must be called to set fences and other - * housekeeping before unlocking after a successful call to - * ValidateBufferList(). The buffer manager knows how to emit and test - * fences directly through the drm and without callbacks to the - * driver. - */ -struct _drmMMBufList *bmNewBufferList(void); - -int bmAddBuffer(struct bufmgr *bm, - struct _drmMMBufList *list, - unsigned buffer, - unsigned flags, - unsigned *pool_return, unsigned long *offset_return); - -int bmValidateBufferList(struct bufmgr *, - struct _drmMMBufList *, unsigned flags); - -unsigned bmFenceBufferList(struct bufmgr *, struct _drmMMBufList *); - -void bmFreeBufferList(struct _drmMMBufList *); - -int bmScanBufferList(struct bufmgr *bm, - struct _drmMMBufList *list, unsigned buffer); - -/* This functionality is used by the buffer manager, not really sure - * if we need to be exposing it in this way, probably libdrm will - * offer equivalent calls. - * - * For now they can stay, but will likely change/move before final: - */ -unsigned bmSetFence(struct bufmgr *); -int bmTestFence(struct bufmgr *, unsigned fence); -void bmFinishFence(struct bufmgr *, unsigned fence); - -void bmSetShared(struct bufmgr *bm, unsigned buffer, - unsigned flags, unsigned long offset, void *virtual); - -extern int INTEL_DEBUG; - -#define DEBUG_BUFMGR 0x2000 - -#define DBG(...) do { if (INTEL_DEBUG & DEBUG_BUFMGR) _mesa_printf(__VA_ARGS__); } while(0) - -#endif diff --git a/src/mesa/drivers/dri/i915-tex/intel_context.c b/src/mesa/drivers/dri/i915-tex/intel_context.c deleted file mode 100644 index c1a968ba1a1..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_context.c +++ /dev/null @@ -1,843 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - - -#include "glheader.h" -#include "context.h" -#include "matrix.h" -#include "simple_list.h" -#include "extensions.h" -#include "framebuffer.h" -#include "imports.h" - -#include "swrast/swrast.h" -#include "swrast_setup/swrast_setup.h" -#include "tnl/tnl.h" -#include "array_cache/acache.h" - -#include "tnl/t_pipeline.h" -#include "tnl/t_vertex.h" - -#include "drivers/common/driverfuncs.h" - -#include "intel_screen.h" - -#include "i830_dri.h" - -#include "intel_buffers.h" -#include "intel_tex.h" -#include "intel_span.h" -#include "intel_tris.h" -#include "intel_ioctl.h" -#include "intel_batchbuffer.h" -#include "intel_blit.h" -#include "intel_pixel.h" -#include "intel_regions.h" -#include "intel_buffer_objects.h" -#include "intel_fbo.h" - -#include "intel_bufmgr.h" - -#include "vblank.h" -#include "utils.h" -#include "xmlpool.h" /* for symbolic values of enum-type options */ -#ifndef INTEL_DEBUG -int INTEL_DEBUG = (0); -#endif - -#define need_GL_ARB_multisample -#define need_GL_ARB_point_parameters -#define need_GL_ARB_texture_compression -#define need_GL_ARB_vertex_buffer_object -#define need_GL_ARB_vertex_program -#define need_GL_ARB_window_pos -#define need_GL_EXT_blend_color -#define need_GL_EXT_blend_equation_separate -#define need_GL_EXT_blend_func_separate -#define need_GL_EXT_blend_minmax -#define need_GL_EXT_cull_vertex -#define need_GL_EXT_fog_coord -#define need_GL_EXT_framebuffer_object -#define need_GL_EXT_multi_draw_arrays -#define need_GL_EXT_secondary_color -#define need_GL_NV_vertex_program -#include "extension_helper.h" - - -#define DRIVER_DATE "20060212" - -static const GLubyte *intelGetString( GLcontext *ctx, GLenum name ) -{ - const char * chipset; - static char buffer[128]; - - switch (name) { - case GL_VENDOR: - return (GLubyte *)"Tungsten Graphics, Inc"; - break; - - case GL_RENDERER: - switch (intel_context(ctx)->intelScreen->deviceID) { - case PCI_CHIP_845_G: - chipset = "Intel(R) 845G"; break; - case PCI_CHIP_I830_M: - chipset = "Intel(R) 830M"; break; - case PCI_CHIP_I855_GM: - chipset = "Intel(R) 852GM/855GM"; break; - case PCI_CHIP_I865_G: - chipset = "Intel(R) 865G"; break; - case PCI_CHIP_I915_G: - chipset = "Intel(R) 915G"; break; - case PCI_CHIP_I915_GM: - chipset = "Intel(R) 915GM"; break; - case PCI_CHIP_I945_G: - chipset = "Intel(R) 945G"; break; - case PCI_CHIP_I945_GM: - chipset = "Intel(R) 945GM"; break; - default: - chipset = "Unknown Intel Chipset"; break; - } - - (void) driGetRendererString( buffer, chipset, DRIVER_DATE, 0 ); - return (GLubyte *) buffer; - - default: - return NULL; - } -} - - -/** - * Extension strings exported by the intel driver. - * - * \note - * It appears that ARB_texture_env_crossbar has "disappeared" compared to the - * old i830-specific driver. - */ -const struct dri_extension card_extensions[] = -{ - { "GL_ARB_multisample", GL_ARB_multisample_functions }, - { "GL_ARB_multitexture", NULL }, - { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions }, - { "GL_ARB_texture_border_clamp", NULL }, - { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions }, - { "GL_ARB_texture_cube_map", NULL }, - { "GL_ARB_texture_env_add", NULL }, - { "GL_ARB_texture_env_combine", NULL }, - { "GL_ARB_texture_env_dot3", NULL }, - { "GL_ARB_texture_mirrored_repeat", NULL }, - { "GL_ARB_texture_rectangle", NULL }, - { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions }, - { "GL_ARB_pixel_buffer_object", NULL }, - { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions }, - { "GL_ARB_window_pos", GL_ARB_window_pos_functions }, - { "GL_EXT_blend_color", GL_EXT_blend_color_functions }, - { "GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions }, - { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions }, - { "GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions }, - { "GL_EXT_blend_subtract", NULL }, - { "GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions }, - { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions }, - { "GL_EXT_framebuffer_object", GL_EXT_framebuffer_object_functions }, - { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions }, -#if 1 /* XXX FBO temporary? */ - { "GL_EXT_packed_depth_stencil", NULL }, -#endif - { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions }, - { "GL_EXT_stencil_wrap", NULL }, - { "GL_EXT_texture_edge_clamp", NULL }, - { "GL_EXT_texture_env_combine", NULL }, - { "GL_EXT_texture_env_dot3", NULL }, - { "GL_EXT_texture_filter_anisotropic", NULL }, - { "GL_EXT_texture_lod_bias", NULL }, - { "GL_3DFX_texture_compression_FXT1", NULL }, - { "GL_APPLE_client_storage", NULL }, - { "GL_MESA_pack_invert", NULL }, - { "GL_MESA_ycbcr_texture", NULL }, - { "GL_NV_blend_square", NULL }, - { "GL_NV_vertex_program", GL_NV_vertex_program_functions }, - { "GL_NV_vertex_program1_1", NULL }, -/* { "GL_SGIS_generate_mipmap", NULL }, */ - { NULL, NULL } -}; - -extern const struct tnl_pipeline_stage _intel_render_stage; - -static const struct tnl_pipeline_stage *intel_pipeline[] = { - &_tnl_vertex_transform_stage, - &_tnl_vertex_cull_stage, - &_tnl_normal_transform_stage, - &_tnl_lighting_stage, - &_tnl_fog_coordinate_stage, - &_tnl_texgen_stage, - &_tnl_texture_transform_stage, - &_tnl_point_attenuation_stage, - &_tnl_arb_vertex_program_stage, - &_tnl_vertex_program_stage, -#if 1 - &_intel_render_stage, /* ADD: unclipped rastersetup-to-dma */ -#endif - &_tnl_render_stage, - 0, -}; - - -static const struct dri_debug_control debug_control[] = -{ - { "fall", DEBUG_FALLBACKS }, - { "tex", DEBUG_TEXTURE }, - { "ioctl", DEBUG_IOCTL }, - { "prim", DEBUG_PRIMS }, - { "vert", DEBUG_VERTS }, - { "state", DEBUG_STATE }, - { "verb", DEBUG_VERBOSE }, - { "dri", DEBUG_DRI }, - { "dma", DEBUG_DMA }, - { "san", DEBUG_SANITY }, - { "sync", DEBUG_SYNC }, - { "sleep", DEBUG_SLEEP }, - { "pix", DEBUG_PIXEL }, - { "buf", DEBUG_BUFMGR }, - { NULL, 0 } -}; - - -static void intelInvalidateState( GLcontext *ctx, GLuint new_state ) -{ - _swrast_InvalidateState( ctx, new_state ); - _swsetup_InvalidateState( ctx, new_state ); - _ac_InvalidateState( ctx, new_state ); - _tnl_InvalidateState( ctx, new_state ); - _tnl_invalidate_vertex_state( ctx, new_state ); - intel_context(ctx)->NewGLState |= new_state; -} - - -void intelFlush( GLcontext *ctx ) -{ - struct intel_context *intel = intel_context( ctx ); - - if (intel->Fallback) - _swrast_flush( ctx ); - - INTEL_FIREVERTICES( intel ); - - if (intel->batch->map != intel->batch->ptr) - intel_batchbuffer_flush( intel->batch ); - - /* XXX: Need to do an MI_FLUSH here. Actually, the bufmgr_fake.c - * code will have done one already. - */ -} - -void intelFinish( GLcontext *ctx ) -{ - struct intel_context *intel = intel_context( ctx ); - intelFlush( ctx ); - bmFinishFence( intel->bm, intel->batch->last_fence ); -} - - -void intelInitDriverFunctions( struct dd_function_table *functions ) -{ - _mesa_init_driver_functions( functions ); - -<<<<<<< intel_context.c - functions->Clear = intelClear; - functions->Flush = intelglFlush; -======= - functions->Flush = intelFlush; ->>>>>>> 1.20.2.25 - functions->Finish = intelFinish; - functions->GetString = intelGetString; - functions->UpdateState = intelInvalidateState; - functions->CopyColorTable = _swrast_CopyColorTable; - functions->CopyColorSubTable = _swrast_CopyColorSubTable; - functions->CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D; - functions->CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D; - - intelInitTextureFuncs( functions ); - intelInitPixelFuncs( functions ); - intelInitStateFuncs( functions ); - intelInitBufferFuncs( functions ); -} - -static void intel_emit_invarient_state( GLcontext *ctx ) -{ - intelContextPtr intel = INTEL_CONTEXT(ctx); - - intel->vtbl.emit_invarient_state( intel ); - intel->prim.flush = 0; - - /* Make sure this gets to the hardware, even if we have no cliprects: - */ - LOCK_HARDWARE( intel ); - intelFlushBatchLocked( intel, GL_TRUE, GL_FALSE, GL_TRUE ); - UNLOCK_HARDWARE( intel ); -} - - - -GLboolean intelInitContext( struct intel_context *intel, - const __GLcontextModes *mesaVis, - __DRIcontextPrivate *driContextPriv, - void *sharedContextPrivate, - struct dd_function_table *functions ) -{ - GLcontext *ctx = &intel->ctx; - GLcontext *shareCtx = (GLcontext *) sharedContextPrivate; - __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv; - intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private; - drmI830Sarea *saPriv = (drmI830Sarea *) - (((GLubyte *)sPriv->pSAREA)+intelScreen->sarea_priv_offset); - int fthrottle_mode; - - if (!_mesa_initialize_context(&intel->ctx, - mesaVis, shareCtx, - functions, - (void*) intel)) - return GL_FALSE; - - driContextPriv->driverPrivate = intel; - intel->intelScreen = intelScreen; - intel->driScreen = sPriv; - intel->sarea = saPriv; - - -<<<<<<< intel_context.c - (void) memset( intel->texture_heaps, 0, sizeof( intel->texture_heaps ) ); - make_empty_list( & intel->swapped ); - - driParseConfigFiles (&intel->optionCache, &intelScreen->optionCache, - intel->driScreen->myNum, "i915"); - -======= ->>>>>>> 1.20.2.25 - ctx->Const.MaxTextureMaxAnisotropy = 2.0; - - ctx->Const.MinLineWidth = 1.0; - ctx->Const.MinLineWidthAA = 1.0; - ctx->Const.MaxLineWidth = 3.0; - ctx->Const.MaxLineWidthAA = 3.0; - ctx->Const.LineWidthGranularity = 1.0; - - ctx->Const.MinPointSize = 1.0; - ctx->Const.MinPointSizeAA = 1.0; - ctx->Const.MaxPointSize = 255.0; - ctx->Const.MaxPointSizeAA = 3.0; - ctx->Const.PointSizeGranularity = 1.0; - - ctx->Const.MaxColorAttachments = 4; /* XXX FBO: review this */ - - /* Initialize the software rasterizer and helper modules. */ - _swrast_CreateContext( ctx ); - _ac_CreateContext( ctx ); - _tnl_CreateContext( ctx ); - _swsetup_CreateContext( ctx ); - - /* Install the customized pipeline: */ - _tnl_destroy_pipeline( ctx ); - _tnl_install_pipeline( ctx, intel_pipeline ); - - /* Configure swrast to match hardware characteristics: */ - _swrast_allow_pixel_fog( ctx, GL_FALSE ); - _swrast_allow_vertex_fog( ctx, GL_TRUE ); - - /* Dri stuff */ - intel->hHWContext = driContextPriv->hHWContext; - intel->driFd = sPriv->fd; - intel->driHwLock = (drmLock *) &sPriv->pSAREA->lock; - - intel->hw_stipple = 1; - - /* XXX FBO: this doesn't seem to be used anywhere */ - switch(mesaVis->depthBits) { - case 0: /* what to do in this case? */ - case 16: - intel->polygon_offset_scale = 1.0/0xffff; - break; - case 24: - intel->polygon_offset_scale = 2.0/0xffffff; /* req'd to pass glean */ - break; - default: - assert(0); - break; - } - - /* Initialize swrast, tnl driver tables: */ - intelInitSpanFuncs( ctx ); - intelInitTriFuncs( ctx ); - - - intel->RenderIndex = ~0; - - fthrottle_mode = driQueryOptioni(&intel->optionCache, "fthrottle_mode"); - intel->iw.irq_seq = -1; - intel->irqsEmitted = 0; - - intel->do_irqs = (intel->intelScreen->irq_active && - fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS); - - intel->do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS); - - intel->vblank_flags = (intel->intelScreen->irq_active != 0) - ? driGetDefaultVBlankFlags(&intelScreen->optionCache) : VBLANK_FLAG_NO_IRQ; - - (*dri_interface->getUST)(&intel->swap_ust); - _math_matrix_ctr (&intel->ViewportMatrix); - - /* Disable imaging extension until convolution is working in - * teximage paths: - */ - driInitExtensions( ctx, card_extensions, -/* GL_TRUE, */ - GL_FALSE); - - - /* Buffer manager: - */ - intel->bm = bm_intel_Attach( intel ); -#if 0 - bmInitPool(intel->bm, - intel->intelScreen->tex.offset, /* low offset */ - intel->intelScreen->tex.map, /* low virtual */ - intel->intelScreen->tex.size, - DRM_MM_TT); -#endif - - /* XXX FBO: these have to go away! - * FBO regions should be setup when creating the drawable. */ - - /* These are still static, but create regions for them. - */ - intel->front_region = - intel_region_create_static(intel, - DRM_MM_TT, - intelScreen->front.offset, - intelScreen->front.map, - intelScreen->cpp, - intelScreen->front.pitch, - intelScreen->height); - - - intel->back_region = - intel_region_create_static(intel, - DRM_MM_TT, - intelScreen->back.offset, - intelScreen->back.map, - intelScreen->cpp, - intelScreen->back.pitch, - intelScreen->height); - - /* Still assuming front.cpp == depth.cpp - */ - intel->depth_region = - intel_region_create_static(intel, - DRM_MM_TT, - intelScreen->depth.offset, - intelScreen->depth.map, - intelScreen->cpp, - intelScreen->depth.pitch, - intelScreen->height); - - intel->batch = intel_batchbuffer_alloc( intel ); - intel_bufferobj_init( intel ); - intel_fbo_init( intel ); - - if (intel->ctx.Mesa_DXTn) { - _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" ); - _mesa_enable_extension( ctx, "GL_S3_s3tc" ); - } - else if (driQueryOptionb (&intelScreen->optionCache, "force_s3tc_enable")) { - _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" ); - } - -<<<<<<< intel_context.c -/* driInitTextureObjects( ctx, & intel->swapped, */ -/* DRI_TEXMGR_DO_TEXTURE_1D | */ -/* DRI_TEXMGR_DO_TEXTURE_2D | */ -/* DRI_TEXMGR_DO_TEXTURE_RECT ); */ - - - intelInitBatchBuffer(&intel->ctx); - intel->prim.flush = intel_emit_invarient_state; -======= ->>>>>>> 1.20.2.25 - intel->prim.primitive = ~0; - - -#if DO_DEBUG - INTEL_DEBUG = driParseDebugString( getenv( "INTEL_DEBUG" ), - debug_control ); -#endif - - if (getenv("INTEL_NO_RAST")) { - fprintf(stderr, "disabling 3D rasterization\n"); - FALLBACK(intel, INTEL_FALLBACK_USER, 1); - } - - return GL_TRUE; -} - -void intelDestroyContext(__DRIcontextPrivate *driContextPriv) -{ - struct intel_context *intel = (struct intel_context *) driContextPriv->driverPrivate; - - assert(intel); /* should never be null */ - if (intel) { - GLboolean release_texture_heaps; - - - intel->vtbl.destroy( intel ); - - release_texture_heaps = (intel->ctx.Shared->RefCount == 1); - _swsetup_DestroyContext (&intel->ctx); - _tnl_DestroyContext (&intel->ctx); - _ac_DestroyContext (&intel->ctx); - - _swrast_DestroyContext (&intel->ctx); - intel->Fallback = 0; /* don't call _swrast_Flush later */ - - intel_batchbuffer_free(intel->batch); - - - if ( release_texture_heaps ) { - /* This share group is about to go away, free our private - * texture object data. - */ - fprintf(stderr, "do something to free texture heaps\n"); - } - - /* free the Mesa context */ - _mesa_free_context_data(&intel->ctx); - } -} - -GLboolean intelUnbindContext(__DRIcontextPrivate *driContextPriv) -{ - return GL_TRUE; -} - -GLboolean intelMakeCurrent(__DRIcontextPrivate *driContextPriv, - __DRIdrawablePrivate *driDrawPriv, - __DRIdrawablePrivate *driReadPriv) -{ - - if (driContextPriv) { - struct intel_context *intel = (struct intel_context *) driContextPriv->driverPrivate; - GLframebuffer *drawFb = (GLframebuffer *) driDrawPriv->driverPrivate; - GLframebuffer *readFb = (GLframebuffer *) driReadPriv->driverPrivate; - - if ( intel->driDrawable != driDrawPriv ) { - /* Shouldn't the readbuffer be stored also? */ - driDrawableInitVBlank( driDrawPriv, intel->vblank_flags ); - - intel->driDrawable = driDrawPriv; - intelWindowMoved( intel ); - } - - /* XXX FBO temporary fix-ups! */ - /* if the renderbuffers don't have regions, init them from the context */ - { - struct intel_renderbuffer *irbFront - = intel_get_renderbuffer(drawFb, BUFFER_FRONT_LEFT); - struct intel_renderbuffer *irbBack - = intel_get_renderbuffer(drawFb, BUFFER_BACK_LEFT); - struct intel_renderbuffer *irbDepth - = intel_get_renderbuffer(drawFb, BUFFER_DEPTH); - struct intel_renderbuffer *irbStencil - = intel_get_renderbuffer(drawFb, BUFFER_STENCIL); - - if (irbFront && !irbFront->region) { - intel_region_reference(&irbFront->region, intel->front_region); - } - if (irbBack && !irbBack->region) { - intel_region_reference(&irbBack->region, intel->back_region); - } - if (irbDepth && !irbDepth->region) { - intel_region_reference(&irbDepth->region, intel->depth_region); - } - if (irbStencil && !irbStencil->region) { - intel_region_reference(&irbStencil->region, intel->depth_region); - } - } - - _mesa_make_current(&intel->ctx, drawFb, readFb); - - intel_draw_buffer(&intel->ctx, drawFb); - } - else { - _mesa_make_current(NULL, NULL, NULL); - } - - return GL_TRUE; -} - -<<<<<<< intel_context.c -/** - * Use the information in the sarea to update the screen parameters - * related to screen rotation. - */ -static void -intelUpdateScreenRotation(intelContextPtr intel, - __DRIscreenPrivate *sPriv, - drmI830Sarea *sarea) -{ - intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private; - intelRegion *colorBuf; - - intelUnmapScreenRegions(intelScreen); - - intelUpdateScreenFromSAREA(intelScreen, sarea); - - /* update the current hw offsets for the color and depth buffers */ - if (intel->ctx.DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_BACK_LEFT) - colorBuf = &intelScreen->back; - else - colorBuf = &intelScreen->front; - intel->vtbl.update_color_z_regions(intel, colorBuf, &intelScreen->depth); - - if (!intelMapScreenRegions(sPriv)) { - fprintf(stderr, "ERROR Remapping screen regions!!!\n"); - } -} - -void intelGetLock( intelContextPtr intel, GLuint flags ) -======= -void intelGetLock( struct intel_context *intel, GLuint flags ) ->>>>>>> 1.20.2.25 -{ - __DRIdrawablePrivate *dPriv = intel->driDrawable; - __DRIscreenPrivate *sPriv = intel->driScreen; - intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private; - drmI830Sarea * sarea = intel->sarea; -<<<<<<< intel_context.c - unsigned i; -======= - int me = intel->hHWContext; ->>>>>>> 1.20.2.25 - - drmGetLock(intel->driFd, intel->hHWContext, flags); - - /* If the window moved, may need to set a new cliprect now. - * - * NOTE: This releases and regains the hw lock, so all state - * checking must be done *after* this call: - */ - if (dPriv) - DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv); - -<<<<<<< intel_context.c - if (dPriv && intel->lastStamp != dPriv->lastStamp) { - intelWindowMoved( intel ); - intel->lastStamp = dPriv->lastStamp; - } - - /* If we lost context, need to dump all registers to hardware. - * Note that we don't care about 2d contexts, even if they perform - * accelerated commands, so the DRI locking in the X server is even - * more broken than usual. -======= - /* Lost context? ->>>>>>> 1.20.2.25 - */ -<<<<<<< intel_context.c - - if (sarea->width != intelScreen->width || - sarea->height != intelScreen->height || - sarea->rotation != intelScreen->current_rotation) { - intelUpdateScreenRotation(intel, sPriv, sarea); - - /* This will drop the outstanding batchbuffer on the floor */ - intel->batch.ptr -= (intel->batch.size - intel->batch.space); - intel->batch.space = intel->batch.size; - /* lose all primitives */ - intel->prim.primitive = ~0; - intel->prim.start_ptr = 0; - intel->prim.flush = 0; - intel->vtbl.lost_hardware( intel ); - - intel->lastStamp = 0; /* force window update */ - - /* Release batch buffer - */ - intelDestroyBatchBuffer(&intel->ctx); - intelInitBatchBuffer(&intel->ctx); - intel->prim.flush = intel_emit_invarient_state; - - /* Still need to reset the global LRU? - */ - intel_driReinitTextureHeap( intel->texture_heaps[0], intel->intelScreen->tex.size ); -======= - if (sarea->ctxOwner != me) { - intel->perf_boxes |= I830_BOX_LOST_CONTEXT; - sarea->ctxOwner = me; ->>>>>>> 1.20.2.25 - } - - /* Drawable changed? - */ -<<<<<<< intel_context.c - for ( i = 0 ; i < intel->nr_heaps ; i++ ) { - DRI_AGE_TEXTURES( intel->texture_heaps[ i ] ); - } -} - -======= - if (dPriv && intel->lastStamp != dPriv->lastStamp) { - intelWindowMoved( intel ); - intel->lastStamp = dPriv->lastStamp; - } -} ->>>>>>> 1.20.2.25 - -<<<<<<< intel_context.c -void intelSwapBuffers( __DRIdrawablePrivate *dPriv ) -{ - if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) { - intelContextPtr intel; - GLcontext *ctx; - intel = (intelContextPtr) dPriv->driContextPriv->driverPrivate; - ctx = &intel->ctx; - if (ctx->Visual.doubleBufferMode) { - intelScreenPrivate *screen = intel->intelScreen; - _mesa_notifySwapBuffers( ctx ); /* flush pending rendering comands */ - if ( 0 /*intel->doPageFlip*/ ) { /* doPageFlip is never set !!! */ - intelPageFlip( dPriv ); - } else { - intelCopyBuffer( dPriv ); - } - if (screen->current_rotation != 0) { - intelRotateWindow(intel, dPriv, BUFFER_BIT_FRONT_LEFT); - } - } - } else { - /* XXX this shouldn't be an error but we can't handle it for now */ - fprintf(stderr, "%s: drawable has no context!\n", __FUNCTION__); - } -} - - -void intelInitState( GLcontext *ctx ) -{ - /* Mesa should do this for us: - */ - ctx->Driver.AlphaFunc( ctx, - ctx->Color.AlphaFunc, - ctx->Color.AlphaRef); - - ctx->Driver.BlendColor( ctx, - ctx->Color.BlendColor ); - - ctx->Driver.BlendEquationSeparate( ctx, - ctx->Color.BlendEquationRGB, - ctx->Color.BlendEquationA); - - ctx->Driver.BlendFuncSeparate( ctx, - ctx->Color.BlendSrcRGB, - ctx->Color.BlendDstRGB, - ctx->Color.BlendSrcA, - ctx->Color.BlendDstA); - - ctx->Driver.ColorMask( ctx, - ctx->Color.ColorMask[RCOMP], - ctx->Color.ColorMask[GCOMP], - ctx->Color.ColorMask[BCOMP], - ctx->Color.ColorMask[ACOMP]); - - ctx->Driver.CullFace( ctx, ctx->Polygon.CullFaceMode ); - ctx->Driver.DepthFunc( ctx, ctx->Depth.Func ); - ctx->Driver.DepthMask( ctx, ctx->Depth.Mask ); - - ctx->Driver.Enable( ctx, GL_ALPHA_TEST, ctx->Color.AlphaEnabled ); - ctx->Driver.Enable( ctx, GL_BLEND, ctx->Color.BlendEnabled ); - ctx->Driver.Enable( ctx, GL_COLOR_LOGIC_OP, ctx->Color.ColorLogicOpEnabled ); - ctx->Driver.Enable( ctx, GL_COLOR_SUM, ctx->Fog.ColorSumEnabled ); - ctx->Driver.Enable( ctx, GL_CULL_FACE, ctx->Polygon.CullFlag ); - ctx->Driver.Enable( ctx, GL_DEPTH_TEST, ctx->Depth.Test ); - ctx->Driver.Enable( ctx, GL_DITHER, ctx->Color.DitherFlag ); - ctx->Driver.Enable( ctx, GL_FOG, ctx->Fog.Enabled ); - ctx->Driver.Enable( ctx, GL_LIGHTING, ctx->Light.Enabled ); - ctx->Driver.Enable( ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag ); - ctx->Driver.Enable( ctx, GL_POLYGON_STIPPLE, ctx->Polygon.StippleFlag ); - ctx->Driver.Enable( ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled ); - ctx->Driver.Enable( ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled ); - ctx->Driver.Enable( ctx, GL_TEXTURE_1D, GL_FALSE ); - ctx->Driver.Enable( ctx, GL_TEXTURE_2D, GL_FALSE ); - ctx->Driver.Enable( ctx, GL_TEXTURE_RECTANGLE_NV, GL_FALSE ); - ctx->Driver.Enable( ctx, GL_TEXTURE_3D, GL_FALSE ); - ctx->Driver.Enable( ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE ); - - ctx->Driver.Fogfv( ctx, GL_FOG_COLOR, ctx->Fog.Color ); - 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.FrontFace( ctx, ctx->Polygon.FrontFace ); - - { - GLfloat f = (GLfloat)ctx->Light.Model.ColorControl; - ctx->Driver.LightModelfv( ctx, GL_LIGHT_MODEL_COLOR_CONTROL, &f ); - } -======= ->>>>>>> 1.20.2.25 - -<<<<<<< intel_context.c - ctx->Driver.LineWidth( ctx, ctx->Line.Width ); - ctx->Driver.LogicOpcode( ctx, ctx->Color.LogicOp ); - ctx->Driver.PointSize( ctx, ctx->Point.Size ); - ctx->Driver.PolygonStipple( ctx, (const GLubyte *)ctx->PolygonStipple ); - ctx->Driver.Scissor( ctx, ctx->Scissor.X, ctx->Scissor.Y, - ctx->Scissor.Width, ctx->Scissor.Height ); - ctx->Driver.ShadeModel( ctx, ctx->Light.ShadeModel ); - ctx->Driver.StencilFuncSeparate( ctx, GL_FRONT, - ctx->Stencil.Function[0], - ctx->Stencil.Ref[0], - ctx->Stencil.ValueMask[0] ); - ctx->Driver.StencilFuncSeparate( ctx, GL_BACK, - ctx->Stencil.Function[1], - ctx->Stencil.Ref[1], - ctx->Stencil.ValueMask[1] ); - ctx->Driver.StencilMaskSeparate( ctx, GL_FRONT, ctx->Stencil.WriteMask[0] ); - ctx->Driver.StencilMaskSeparate( ctx, GL_BACK, ctx->Stencil.WriteMask[1] ); - ctx->Driver.StencilOpSeparate( ctx, GL_FRONT, - ctx->Stencil.FailFunc[0], - ctx->Stencil.ZFailFunc[0], - ctx->Stencil.ZPassFunc[0]); - ctx->Driver.StencilOpSeparate( ctx, GL_BACK, - ctx->Stencil.FailFunc[1], - ctx->Stencil.ZFailFunc[1], - ctx->Stencil.ZPassFunc[1]); - - - ctx->Driver.DrawBuffer( ctx, ctx->Color.DrawBuffer[0] ); -} - - -======= ->>>>>>> 1.20.2.25 diff --git a/src/mesa/drivers/dri/i915-tex/intel_context.h b/src/mesa/drivers/dri/i915-tex/intel_context.h deleted file mode 100644 index 01955871bfb..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_context.h +++ /dev/null @@ -1,615 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#ifndef INTELCONTEXT_INC -#define INTELCONTEXT_INC - - - -#include "mtypes.h" -#include "drm.h" -#include "mm.h" -#include "texmem.h" - -#include "intel_screen.h" -#include "i915_drm.h" -#include "i830_common.h" -#include "tnl/t_vertex.h" - -#define TAG(x) intel##x -#include "tnl_dd/t_dd_vertex.h" -#undef TAG - -#define DV_PF_555 (1<<8) -#define DV_PF_565 (2<<8) -#define DV_PF_8888 (3<<8) - -struct intel_region; -struct intel_context; - -typedef void (*intel_tri_func)(struct intel_context *, intelVertex *, intelVertex *, - intelVertex *); -typedef void (*intel_line_func)(struct intel_context *, intelVertex *, intelVertex *); -typedef void (*intel_point_func)(struct intel_context *, intelVertex *); - -#define INTEL_FALLBACK_DRAW_BUFFER 0x1 -#define INTEL_FALLBACK_READ_BUFFER 0x2 -#define INTEL_FALLBACK_DEPTH_BUFFER 0x4 -#define INTEL_FALLBACK_STENCIL_BUFFER 0x8 -#define INTEL_FALLBACK_USER 0x10 -#define INTEL_FALLBACK_RENDERMODE 0x20 - -extern void intelFallback( struct intel_context *intel, GLuint bit, GLboolean mode ); -#define FALLBACK( intel, bit, mode ) intelFallback( intel, bit, mode ) - - - -struct intel_texture_object -{ - struct gl_texture_object base; /* The "parent" object */ - - /* The mipmap tree must include at least these levels once - * validated: - */ - GLuint firstLevel; - GLuint lastLevel; - - /* Offset for firstLevel image: - */ - GLuint textureOffset; - - /* On validation any active images held in main memory or in other - * regions will be copied to this region and the old storage freed. - */ - struct intel_mipmap_tree *mt; -}; - - - -struct intel_texture_image -{ - struct gl_texture_image base; - - /* These aren't stored in gl_texture_image - */ - GLuint level; - GLuint face; - - /* If intelImage->mt != NULL, image data is stored here. - * Else if intelImage->base.Data != NULL, image is stored there. - * Else there is no image data. - */ - struct intel_mipmap_tree *mt; -}; - - -#define INTEL_MAX_FIXUP 64 - -struct intel_context -{ - GLcontext ctx; /* the parent class */ - - struct { - void (*destroy)( struct intel_context *intel ); - void (*emit_state)( struct intel_context *intel ); - void (*lost_hardware)( struct intel_context *intel ); - void (*update_texture_state)( struct intel_context *intel ); - - void (*render_start)( struct intel_context *intel ); - void (*set_draw_region)( struct intel_context *intel, - struct intel_region *draw_region, - struct intel_region *depth_region ); - - GLuint (*flush_cmd)( void ); - -<<<<<<< intel_context.h - void (*render_start)( intelContextPtr intel ); - void (*set_color_region)( intelContextPtr intel, const intelRegion *reg ); - void (*set_z_region)( intelContextPtr intel, const intelRegion *reg ); - void (*update_color_z_regions)(intelContextPtr intel, - const intelRegion *colorRegion, - const intelRegion *depthRegion); - void (*emit_flush)( intelContextPtr intel ); - void (*reduced_primitive_state)( intelContextPtr intel, GLenum rprim ); -======= - void (*reduced_primitive_state)( struct intel_context *intel, GLenum rprim ); - - GLboolean (*check_vertex_size)( struct intel_context *intel, GLuint expected ); ->>>>>>> 1.8.2.25 - - - /* Metaops: - */ - void (*install_meta_state)( struct intel_context *intel ); - void (*leave_meta_state)( struct intel_context *intel ); - -<<<<<<< intel_context.h - void (*rotate_window)( intelContextPtr intel, - __DRIdrawablePrivate *dPriv, GLuint srcBuf); - - intelTextureObjectPtr (*alloc_tex_obj)( struct gl_texture_object *tObj ); -======= - void (*meta_draw_region)( struct intel_context *intel, - struct intel_region *draw_region, - struct intel_region *depth_region ); - - void (*meta_color_mask)( struct intel_context *intel, - GLboolean ); - - void (*meta_stencil_replace)( struct intel_context *intel, - GLuint mask, - GLuint clear ); - - void (*meta_depth_replace)( struct intel_context *intel ); - - void (*meta_texture_blend_replace)( struct intel_context *intel ); - - void (*meta_no_stencil_write)( struct intel_context *intel ); - void (*meta_no_depth_write)( struct intel_context *intel ); - void (*meta_no_texture)( struct intel_context *intel ); - - void (*meta_import_pixel_state)( struct intel_context *intel ); - - GLboolean (*meta_tex_rect_source)( struct intel_context *intel, - GLuint buffer, - GLuint offset, - GLuint pitch, - GLuint height, - GLenum format, - GLenum type); ->>>>>>> 1.8.2.25 - - } vtbl; - - GLint refcount; - GLuint Fallback; - GLuint NewGLState; - -<<<<<<< intel_context.h - struct { - GLuint start_offset; - GLint size; - GLint space; - GLubyte *ptr; - GLuint counter; - GLuint last_emit_state; - GLboolean contains_geometry; - const char *func; - GLuint last_swap; - } batch; - - struct { - void *ptr; - GLint size; - GLuint offset; - GLuint active_buf; - GLuint irq_emitted; - } alloc; -======= - GLuint last_fence; - GLuint last_swap_fence; - - struct intel_batchbuffer *batch; ->>>>>>> 1.8.2.25 - - struct { - GLuint id; - GLuint primitive; - GLubyte *start_ptr; - void (*flush)( struct intel_context * ); - } prim; - - GLboolean locked; - char *prevLockFile; - int prevLockLine; - - GLuint ClearColor565; - GLuint ClearColor8888; - - /* Offsets of fields within the current vertex: - */ - GLuint coloroffset; - GLuint specoffset; - GLuint wpos_offset; - GLuint wpos_size; - - struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX]; - GLuint vertex_attr_count; - - GLfloat polygon_offset_scale; /* dependent on depth_scale, bpp */ - - GLboolean hw_stipple; - - /* AGP memory buffer manager: - */ - struct bufmgr *bm; - - - /* State for intelvb.c and inteltris.c. - */ - GLuint RenderIndex; - GLmatrix ViewportMatrix; - GLenum render_primitive; - GLenum reduced_primitive; - GLuint vertex_size; - GLubyte *verts; /* points to tnl->clipspace.vertex_buf */ - - - struct intel_region *front_region; /* XXX FBO: obsolete */ - struct intel_region *back_region; /* XXX FBO: obsolete */ - struct intel_region *draw_region; /* XXX FBO: rename to color_region */ - struct intel_region *depth_region; /**< currently bound depth/Z region */ - - - /* Fallback rasterization functions - */ - intel_point_func draw_point; - intel_line_func draw_line; - intel_tri_func draw_tri; - -<<<<<<< intel_context.h - /* Drawing buffer state -======= - /* These refer to the current drawing buffer: ->>>>>>> 1.8.2.25 - */ -<<<<<<< intel_context.h - intelRegion *drawRegion; /* current drawing buffer */ - intelRegion *readRegion; /* current reading buffer */ - - int drawX; /* origin of drawable in draw buffer */ - int drawY; - GLuint numClipRects; /* cliprects for that buffer */ -======= - int drawX, drawY; /**< origin of drawing area within region */ - GLuint numClipRects; /**< cliprects for drawing */ ->>>>>>> 1.8.2.25 - drm_clip_rect_t *pClipRects; - drm_clip_rect_t fboRect; /**< cliprect for FBO rendering */ - - int perf_boxes; - - GLuint do_usleeps; - int do_irqs; - GLuint irqsEmitted; - drm_i915_irq_wait_t iw; - - /* XXX these seem to be unused */ -#if 0 - GLboolean scissor; - drm_clip_rect_t draw_rect; - drm_clip_rect_t scissor_rect; -#endif - - drm_context_t hHWContext; - drmLock *driHwLock; - int driFd; - - __DRIdrawablePrivate *driDrawable; - __DRIscreenPrivate *driScreen; - intelScreenPrivate *intelScreen; - drmI830Sarea *sarea; - - GLuint lastStamp; - - /** - * Configuration cache - */ - driOptionCache optionCache; - - /* VBI - */ - GLuint vbl_seq; - GLuint vblank_flags; - - int64_t swap_ust; - int64_t swap_missed_ust; - - GLuint swap_count; - GLuint swap_missed_count; -}; - - -#define DEBUG_LOCKING 1 - -#if DEBUG_LOCKING - -#define DEBUG_LOCK() \ - do { \ - intel->prevLockFile = (__FILE__); \ - intel->prevLockLine = (__LINE__); \ - } while (0) - -#define DEBUG_RESET() \ - do { \ - intel->prevLockFile = 0; \ - intel->prevLockLine = 0; \ - } while (0) - -/* Slightly less broken way of detecting recursive locking in a - * threaded environment. The right way to do this would be to make - * prevLockFile, prevLockLine thread-local. - * - * This technique instead checks to see if the same context is - * requesting the lock twice -- this will not catch application - * breakages where the same context is active in two different threads - * at once, but it will catch driver breakages (recursive locking) in - * threaded apps. - */ -#define DEBUG_CHECK_LOCK() \ - do { \ - if ( *((volatile int *)intel->driHwLock) == \ - (DRM_LOCK_HELD | intel->hHWContext) ) { \ - fprintf( stderr, \ - "LOCK SET!\n\tPrevious %s:%d\n\tCurrent: %s:%d\n", \ - intel->prevLockFile, intel->prevLockLine, \ - __FILE__, __LINE__ ); \ - abort(); \ - } \ - } while (0) - -#else - -#define DEBUG_LOCK() -#define DEBUG_RESET() -#define DEBUG_CHECK_LOCK() - -#endif - - - - -/* Lock the hardware and validate our state. - */ -#define LOCK_HARDWARE( intel ) \ -do { \ - char __ret=0; \ - DEBUG_CHECK_LOCK(); \ - assert(!(intel)->locked); \ - DRM_CAS((intel)->driHwLock, (intel)->hHWContext, \ - (DRM_LOCK_HELD|(intel)->hHWContext), __ret); \ - if (__ret) \ - intelGetLock( (intel), 0 ); \ - DEBUG_LOCK(); \ - (intel)->locked = 1; \ -}while (0) - - - /* Unlock the hardware using the global current context - */ -#define UNLOCK_HARDWARE(intel) \ -do { \ - intel->locked = 0; \ - if (0) { \ - intel->perf_boxes |= intel->sarea->perf_boxes; \ - intel->sarea->perf_boxes = 0; \ - } \ - DRM_UNLOCK((intel)->driFd, (intel)->driHwLock, (intel)->hHWContext); \ - DEBUG_RESET(); \ -} while (0) - - -#define SUBPIXEL_X 0.125 -#define SUBPIXEL_Y 0.125 - -#define INTEL_FIREVERTICES(intel) \ -do { \ - assert(!(intel)->prim.flush); \ -} while (0) - -/* ================================================================ - * Color packing: - */ - -#define INTEL_PACKCOLOR4444(r,g,b,a) \ - ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4)) - -#define INTEL_PACKCOLOR1555(r,g,b,a) \ - ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \ - ((a) ? 0x8000 : 0)) - -#define INTEL_PACKCOLOR565(r,g,b) \ - ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3)) - -#define INTEL_PACKCOLOR8888(r,g,b,a) \ - ((a<<24) | (r<<16) | (g<<8) | b) - - - -/* ================================================================ - * From linux kernel i386 header files, copes with odd sizes better - * than COPY_DWORDS would: - * XXX Put this in src/mesa/main/imports.h ??? - */ -#if defined(i386) || defined(__i386__) -static INLINE void * __memcpy(void * to, const void * from, size_t n) -{ - int d0, d1, d2; - __asm__ __volatile__( - "rep ; movsl\n\t" - "testb $2,%b4\n\t" - "je 1f\n\t" - "movsw\n" - "1:\ttestb $1,%b4\n\t" - "je 2f\n\t" - "movsb\n" - "2:" - : "=&c" (d0), "=&D" (d1), "=&S" (d2) - :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from) - : "memory"); - return (to); -} -#else -#define __memcpy(a,b,c) memcpy(a,b,c) -#endif - - - -/* ================================================================ - * Debugging: - */ -#define DO_DEBUG 1 -#if DO_DEBUG -extern int INTEL_DEBUG; -#else -#define INTEL_DEBUG 0 -#endif - -#define DEBUG_TEXTURE 0x1 -#define DEBUG_STATE 0x2 -#define DEBUG_IOCTL 0x4 -#define DEBUG_PRIMS 0x8 -#define DEBUG_VERTS 0x10 -#define DEBUG_FALLBACKS 0x20 -#define DEBUG_VERBOSE 0x40 -#define DEBUG_DRI 0x80 -#define DEBUG_DMA 0x100 -#define DEBUG_SANITY 0x200 -#define DEBUG_SYNC 0x400 -#define DEBUG_SLEEP 0x800 -#define DEBUG_PIXEL 0x1000 - - -#define PCI_CHIP_845_G 0x2562 -#define PCI_CHIP_I830_M 0x3577 -#define PCI_CHIP_I855_GM 0x3582 -#define PCI_CHIP_I865_G 0x2572 -#define PCI_CHIP_I915_G 0x2582 -#define PCI_CHIP_I915_GM 0x2592 -#define PCI_CHIP_I945_G 0x2772 -#define PCI_CHIP_I945_GM 0x27A2 - - -/* ================================================================ - * intel_context.c: - */ - -extern GLboolean intelInitContext( struct intel_context *intel, - const __GLcontextModes *mesaVis, - __DRIcontextPrivate *driContextPriv, - void *sharedContextPrivate, - struct dd_function_table *functions ); - -extern void intelGetLock(struct intel_context *intel, GLuint flags); - -extern void intelInitState( GLcontext *ctx ); -extern void intelFinish( GLcontext *ctx ); -extern void intelFlush( GLcontext *ctx ); - -extern void intelInitDriverFunctions( struct dd_function_table *functions ); - - -/* ================================================================ - * intel_state.c: - */ -extern void intelInitStateFuncs( struct dd_function_table *functions ); - -#define COMPAREFUNC_ALWAYS 0 -#define COMPAREFUNC_NEVER 0x1 -#define COMPAREFUNC_LESS 0x2 -#define COMPAREFUNC_EQUAL 0x3 -#define COMPAREFUNC_LEQUAL 0x4 -#define COMPAREFUNC_GREATER 0x5 -#define COMPAREFUNC_NOTEQUAL 0x6 -#define COMPAREFUNC_GEQUAL 0x7 - -#define STENCILOP_KEEP 0 -#define STENCILOP_ZERO 0x1 -#define STENCILOP_REPLACE 0x2 -#define STENCILOP_INCRSAT 0x3 -#define STENCILOP_DECRSAT 0x4 -#define STENCILOP_INCR 0x5 -#define STENCILOP_DECR 0x6 -#define STENCILOP_INVERT 0x7 - -#define LOGICOP_CLEAR 0 -#define LOGICOP_NOR 0x1 -#define LOGICOP_AND_INV 0x2 -#define LOGICOP_COPY_INV 0x3 -#define LOGICOP_AND_RVRSE 0x4 -#define LOGICOP_INV 0x5 -#define LOGICOP_XOR 0x6 -#define LOGICOP_NAND 0x7 -#define LOGICOP_AND 0x8 -#define LOGICOP_EQUIV 0x9 -#define LOGICOP_NOOP 0xa -#define LOGICOP_OR_INV 0xb -#define LOGICOP_COPY 0xc -#define LOGICOP_OR_RVRSE 0xd -#define LOGICOP_OR 0xe -#define LOGICOP_SET 0xf - -#define BLENDFACT_ZERO 0x01 -#define BLENDFACT_ONE 0x02 -#define BLENDFACT_SRC_COLR 0x03 -#define BLENDFACT_INV_SRC_COLR 0x04 -#define BLENDFACT_SRC_ALPHA 0x05 -#define BLENDFACT_INV_SRC_ALPHA 0x06 -#define BLENDFACT_DST_ALPHA 0x07 -#define BLENDFACT_INV_DST_ALPHA 0x08 -#define BLENDFACT_DST_COLR 0x09 -#define BLENDFACT_INV_DST_COLR 0x0a -#define BLENDFACT_SRC_ALPHA_SATURATE 0x0b -#define BLENDFACT_CONST_COLOR 0x0c -#define BLENDFACT_INV_CONST_COLOR 0x0d -#define BLENDFACT_CONST_ALPHA 0x0e -#define BLENDFACT_INV_CONST_ALPHA 0x0f -#define BLENDFACT_MASK 0x0f - -#define MI_BATCH_BUFFER_END (0xA<<23) - - -extern int intel_translate_compare_func( GLenum func ); -extern int intel_translate_stencil_op( GLenum op ); -extern int intel_translate_blend_factor( GLenum factor ); -extern int intel_translate_logic_op( GLenum opcode ); - - -/*====================================================================== - * Inline conversion functions. - * These are better-typed than the macros used previously: - */ -static INLINE struct intel_context *intel_context( GLcontext *ctx ) -{ - return (struct intel_context *)ctx; -} - -static INLINE struct intel_texture_object *intel_texture_object( struct gl_texture_object *obj ) -{ - return (struct intel_texture_object *)obj; -} - -static INLINE struct intel_texture_image *intel_texture_image( struct gl_texture_image *img ) -{ - return (struct intel_texture_image *)img; -} - -extern struct intel_renderbuffer *intel_renderbuffer( struct gl_renderbuffer *rb ); - - -#endif - diff --git a/src/mesa/drivers/dri/i915-tex/intel_depthstencil.c b/src/mesa/drivers/dri/i915-tex/intel_depthstencil.c deleted file mode 100644 index 51eb799f920..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_depthstencil.c +++ /dev/null @@ -1,281 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "glheader.h" -#include "imports.h" -#include "context.h" -#include "depthstencil.h" -#include "fbobject.h" -#include "framebuffer.h" -#include "hash.h" -#include "mtypes.h" -#include "renderbuffer.h" - -#include "intel_context.h" -#include "intel_fbo.h" -#include "intel_depthstencil.h" -#include "intel_regions.h" - - -/** - * The GL_EXT_framebuffer_object allows the user to create their own - * framebuffer objects consisting of color renderbuffers (0 or more), - * depth renderbuffers (0 or 1) and stencil renderbuffers (0 or 1). - * - * The spec considers depth and stencil renderbuffers to be totally independent - * buffers. In reality, most graphics hardware today uses a combined - * depth+stencil buffer (one 32-bit pixel = 24 bits of Z + 8 bits of stencil). - * - * This causes difficulty because the user may create some number of depth - * renderbuffers and some number of stencil renderbuffers and bind them - * together in framebuffers in any combination. - * - * This code manages all that. - * - * 1. Depth renderbuffers are always allocated in hardware as 32bpp - * GL_DEPTH24_STENCIL8 buffers. - * - * 2. Stencil renderbuffers are initially allocated in software as 8bpp - * GL_STENCIL_INDEX8 buffers. - * - * 3. Depth and Stencil renderbuffers use the PairedStencil and PairedDepth - * fields (respectively) to indicate if the buffer's currently paired - * with another stencil or depth buffer (respectively). - * - * 4. When a depth and stencil buffer are initially both attached to the - * current framebuffer, we merge the stencil buffer values into the - * depth buffer (really a depth+stencil buffer). The then hardware uses - * the combined buffer. - * - * 5. Whenever a depth or stencil buffer is reallocated (with - * glRenderbufferStorage) we undo the pairing and copy the stencil values - * from the combined depth/stencil buffer back to the stencil-only buffer. - * - * 6. We also undo the pairing when we find a change in buffer bindings. - * - * 7. If a framebuffer is only using a depth renderbuffer (no stencil), we - * just use the combined depth/stencil buffer and ignore the stencil values. - * - * 8. If a framebuffer is only using a stencil renderbuffer (no depth) we have - * to promote the 8bpp software stencil buffer to a 32bpp hardware - * depth+stencil buffer. - * - */ - - - -static void -map_regions(GLcontext *ctx, - struct intel_renderbuffer *depthRb, - struct intel_renderbuffer *stencilRb) -{ - struct intel_context *intel = intel_context(ctx); - if (depthRb && depthRb->region) { - intel_region_map(intel, depthRb->region); - depthRb->pfMap = depthRb->region->map; - depthRb->pfPitch = depthRb->region->pitch; - } - if (stencilRb && stencilRb->region) { - intel_region_map(intel, stencilRb->region); - stencilRb->pfMap = stencilRb->region->map; - stencilRb->pfPitch = stencilRb->region->pitch; - } -} - -static void -unmap_regions(GLcontext *ctx, - struct intel_renderbuffer *depthRb, - struct intel_renderbuffer *stencilRb) -{ - struct intel_context *intel = intel_context(ctx); - if (depthRb && depthRb->region) { - intel_region_unmap(intel, depthRb->region); - depthRb->pfMap = NULL; - depthRb->pfPitch = 0; - } - if (stencilRb && stencilRb->region) { - intel_region_unmap(intel, stencilRb->region); - stencilRb->pfMap = NULL; - stencilRb->pfPitch = 0; - } -} - - - -/** - * Undo the pairing/interleaving between depth and stencil buffers. - * irb should be a depth/stencil or stencil renderbuffer. - */ -void -intel_unpair_depth_stencil(GLcontext *ctx, struct intel_renderbuffer *irb) -{ - if (irb->PairedStencil) { - /* irb is a depth/stencil buffer */ - struct gl_renderbuffer *stencilRb; - struct intel_renderbuffer *stencilIrb; - - ASSERT(irb->Base._ActualFormat == GL_DEPTH24_STENCIL8_EXT); - - stencilRb = _mesa_lookup_renderbuffer(ctx, irb->PairedStencil); - stencilIrb = intel_renderbuffer(stencilRb); - if (stencilIrb) { - /* need to extract stencil values from the depth buffer */ - ASSERT(stencilIrb->PairedDepth == irb->Base.Name); - map_regions(ctx, irb, stencilIrb); - _mesa_extract_stencil(ctx, &irb->Base, &stencilIrb->Base); - unmap_regions(ctx, irb, stencilIrb); - stencilIrb->PairedDepth = 0; - } - irb->PairedStencil = 0; - } - else if (irb->PairedDepth) { - /* irb is a stencil buffer */ - struct gl_renderbuffer *depthRb; - struct intel_renderbuffer *depthIrb; - - ASSERT(irb->Base._ActualFormat == GL_STENCIL_INDEX8_EXT || - irb->Base._ActualFormat == GL_DEPTH24_STENCIL8_EXT); - - depthRb = _mesa_lookup_renderbuffer(ctx, irb->PairedDepth); - depthIrb = intel_renderbuffer(depthRb); - if (depthIrb) { - /* need to extract stencil values from the depth buffer */ - ASSERT(depthIrb->PairedStencil == irb->Base.Name); - map_regions(ctx, depthIrb, irb); - _mesa_extract_stencil(ctx, &depthIrb->Base, &irb->Base); - unmap_regions(ctx, depthIrb, irb); - depthIrb->PairedStencil = 0; - } - irb->PairedDepth = 0; - } - else { - _mesa_problem(ctx, "Problem in undo_depth_stencil_pairing"); - } - - ASSERT(irb->PairedStencil == 0); - ASSERT(irb->PairedDepth == 0); -} - - -/** - * Examine the depth and stencil renderbuffers which are attached to the - * framebuffer. If both depth and stencil are attached, make sure that the - * renderbuffers are 'paired' (combined). If only depth or only stencil is - * attached, undo any previous pairing. - * - * Must be called if NewState & _NEW_BUFFER (when renderbuffer attachments - * change, for example). - */ -void -intel_validate_paired_depth_stencil(GLcontext *ctx, struct gl_framebuffer *fb) -{ - struct intel_renderbuffer *depthRb, *stencilRb; - - depthRb = intel_get_renderbuffer(fb, BUFFER_DEPTH); - stencilRb = intel_get_renderbuffer(fb, BUFFER_STENCIL); - - if (depthRb && stencilRb) { - if (depthRb == stencilRb) { - /* Using a user-created combined depth/stencil buffer. - * Nothing to do. - */ - ASSERT(depthRb->Base._BaseFormat == GL_DEPTH_STENCIL_EXT); - ASSERT(depthRb->Base._ActualFormat == GL_DEPTH24_STENCIL8_EXT); - } - else { - /* Separate depth/stencil buffers, need to interleave now */ - ASSERT(depthRb->Base._BaseFormat == GL_DEPTH_COMPONENT); - ASSERT(stencilRb->Base._BaseFormat == GL_STENCIL_INDEX); - /* may need to interleave depth/stencil now */ - if (depthRb->PairedStencil == stencilRb->Base.Name) { - /* OK, the depth and stencil buffers are already interleaved */ - ASSERT(stencilRb->PairedDepth == depthRb->Base.Name); - } - else { - /* need to setup new pairing/interleaving */ - if (depthRb->PairedStencil) { - intel_unpair_depth_stencil(ctx, depthRb); - } - if (stencilRb->PairedDepth) { - intel_unpair_depth_stencil(ctx, stencilRb); - } - - ASSERT(depthRb->Base._ActualFormat == GL_DEPTH24_STENCIL8_EXT); - ASSERT(stencilRb->Base._ActualFormat == GL_STENCIL_INDEX8_EXT || - stencilRb->Base._ActualFormat == GL_DEPTH24_STENCIL8_EXT); - - /* establish new pairing: interleave stencil into depth buffer */ - map_regions(ctx, depthRb, stencilRb); - _mesa_insert_stencil(ctx, &depthRb->Base, &stencilRb->Base); - unmap_regions(ctx, depthRb, stencilRb); - depthRb->PairedStencil = stencilRb->Base.Name; - stencilRb->PairedDepth = depthRb->Base.Name; - } - - } - } - else if (depthRb) { - /* Depth buffer but no stencil buffer. - * We'll use a GL_DEPTH24_STENCIL8 buffer and ignore the stencil bits. - */ - /* can't assert this until storage is allocated: - ASSERT(depthRb->Base._ActualFormat == GL_DEPTH24_STENCIL8_EXT); - */ - /* intel_undo any previous pairing */ - if (depthRb->PairedStencil) { - intel_unpair_depth_stencil(ctx, depthRb); - } - } - else if (stencilRb) { - /* Stencil buffer but no depth buffer. - * Since h/w doesn't typically support just 8bpp stencil w/out Z, - * we'll use a GL_DEPTH24_STENCIL8 buffer and ignore the depth bits. - */ - /* undo any previous pairing */ - if (stencilRb->PairedDepth) { - intel_unpair_depth_stencil(ctx, stencilRb); - } - if (stencilRb->Base._ActualFormat == GL_STENCIL_INDEX8_EXT) { - /* promote buffer to GL_DEPTH24_STENCIL8 for hw rendering */ - _mesa_promote_stencil(ctx, &stencilRb->Base); - ASSERT(stencilRb->Base._ActualFormat == GL_DEPTH24_STENCIL8_EXT); - } - } - - /* Finally, update the fb->_DepthBuffer and fb->_StencilBuffer fields */ - _mesa_update_depth_buffer(ctx, fb, BUFFER_DEPTH); - if (depthRb && depthRb->PairedStencil) - _mesa_update_stencil_buffer(ctx, fb, BUFFER_DEPTH); - else - _mesa_update_stencil_buffer(ctx, fb, BUFFER_STENCIL); - - - /* The hardware should use fb->Attachment[BUFFER_DEPTH].Renderbuffer - * first, if present, then fb->Attachment[BUFFER_STENCIL].Renderbuffer - * if present. - */ -} diff --git a/src/mesa/drivers/dri/i915-tex/intel_depthstencil.h b/src/mesa/drivers/dri/i915-tex/intel_depthstencil.h deleted file mode 100644 index 33699535664..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_depthstencil.h +++ /dev/null @@ -1,13 +0,0 @@ - -#ifndef INTEL_DEPTH_STENCIL_H -#define INTEL_DEPTH_STENCIL_H - - -extern void -intel_unpair_depth_stencil(GLcontext *ctx, struct intel_renderbuffer *irb); - -extern void -intel_validate_paired_depth_stencil(GLcontext *ctx, struct gl_framebuffer *fb); - - -#endif /* INTEL_DEPTH_STENCIL_H */ diff --git a/src/mesa/drivers/dri/i915-tex/intel_fbo.c b/src/mesa/drivers/dri/i915-tex/intel_fbo.c deleted file mode 100644 index dbbc1bd9b23..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_fbo.c +++ /dev/null @@ -1,638 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - - -#include "imports.h" -#include "mtypes.h" -#include "fbobject.h" -#include "framebuffer.h" -#include "renderbuffer.h" -#include "context.h" -#include "texformat.h" -#include "texrender.h" - -#include "intel_context.h" -#include "intel_buffers.h" -#include "intel_bufmgr.h" -#include "intel_depthstencil.h" -#include "intel_fbo.h" -#include "intel_mipmap_tree.h" -#include "intel_regions.h" -#include "intel_span.h" - -#define INTEL_RB_CLASS 0x12345678 - - -/* XXX FBO: move this to intel_context.h (inlined) */ -/** - * Return a gl_renderbuffer ptr casted to intel_renderbuffer. - * NULL will be returned if the rb isn't really an intel_renderbuffer. - * This is determiend by checking the ClassID. - */ -struct intel_renderbuffer *intel_renderbuffer( struct gl_renderbuffer *rb ) -{ - struct intel_renderbuffer *irb = (struct intel_renderbuffer *) rb; - if (irb && irb->Base.ClassID == INTEL_RB_CLASS) { - /*_mesa_warning(NULL, "Returning non-intel Rb\n");*/ - return irb; - } - else - return NULL; -} - - -struct intel_renderbuffer * -intel_get_renderbuffer(struct gl_framebuffer *fb, GLuint attIndex) -{ - return intel_renderbuffer(fb->Attachment[attIndex].Renderbuffer); -} - - -struct intel_region * -intel_get_rb_region(struct gl_framebuffer *fb, GLuint attIndex) -{ - struct intel_renderbuffer *irb - = intel_renderbuffer(fb->Attachment[attIndex].Renderbuffer); - if (irb) - return irb->region; - else - return NULL; -} - - - -/** - * Create a new framebuffer object. - */ -static struct gl_framebuffer * -intel_new_framebuffer(GLcontext *ctx, GLuint name) -{ - /* there's no intel_framebuffer at this time, just use Mesa's class */ - return _mesa_new_framebuffer(ctx, name); -} - - -static void -intel_delete_renderbuffer(struct gl_renderbuffer *rb) -{ - GET_CURRENT_CONTEXT(ctx); - struct intel_context *intel = intel_context(ctx); - struct intel_renderbuffer *irb = intel_renderbuffer(rb); - - ASSERT(irb); - - if (irb->PairedStencil || irb->PairedDepth) { - intel_unpair_depth_stencil(ctx, irb); - } - - if (intel && irb->region) { - intel_region_release(intel, &irb->region); - } - - _mesa_free(irb); -} - - - -/** - * Return a pointer to a specific pixel in a renderbuffer. - */ -static void * -intel_get_pointer(GLcontext *ctx, struct gl_renderbuffer *rb, - GLint x, GLint y) -{ - /* By returning NULL we force all software rendering to go through - * the span routines. - */ - return NULL; -} - - - -/** - * Called via glRenderbufferStorageEXT() to set the format and allocate - * storage for a user-created renderbuffer. - */ -static GLboolean -intel_alloc_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb, - GLenum internalFormat, - GLuint width, GLuint height) -{ - struct intel_context *intel = intel_context(ctx); - struct intel_renderbuffer *irb = intel_renderbuffer(rb); - GLboolean softwareBuffer = GL_FALSE; - int cpp; - - ASSERT(rb->Name != 0); - - switch (internalFormat) { - case GL_R3_G3_B2: - case GL_RGB4: - case GL_RGB5: - rb->_ActualFormat = GL_RGB5; - rb->DataType = GL_UNSIGNED_BYTE; - rb->RedBits = 5; - rb->GreenBits = 6; - rb->BlueBits = 5; - cpp = 2; - break; - case GL_RGB: - case GL_RGB8: - case GL_RGB10: - case GL_RGB12: - case GL_RGB16: - case GL_RGBA: - case GL_RGBA2: - case GL_RGBA4: - case GL_RGB5_A1: - case GL_RGBA8: - case GL_RGB10_A2: - case GL_RGBA12: - case GL_RGBA16: - rb->_ActualFormat = GL_RGBA8; - rb->DataType = GL_UNSIGNED_BYTE; - rb->RedBits = 8; - rb->GreenBits = 8; - rb->BlueBits = 8; - rb->AlphaBits = 8; - cpp = 4; - break; - case GL_STENCIL_INDEX: - case GL_STENCIL_INDEX1_EXT: - case GL_STENCIL_INDEX4_EXT: - case GL_STENCIL_INDEX8_EXT: - case GL_STENCIL_INDEX16_EXT: - /* alloc a depth+stencil buffer */ - rb->_ActualFormat = GL_DEPTH24_STENCIL8_EXT; - rb->DataType = GL_UNSIGNED_INT_24_8_EXT; - rb->StencilBits = 8; - cpp = 4; - break; - case GL_DEPTH_COMPONENT16: - rb->_ActualFormat = GL_DEPTH_COMPONENT16; - rb->DataType = GL_UNSIGNED_SHORT; - rb->DepthBits = 16; - cpp = 2; - break; - case GL_DEPTH_COMPONENT: - case GL_DEPTH_COMPONENT24: - case GL_DEPTH_COMPONENT32: - rb->_ActualFormat = GL_DEPTH24_STENCIL8_EXT; - rb->DataType = GL_UNSIGNED_INT_24_8_EXT; - rb->DepthBits = 24; - cpp = 4; - break; - case GL_DEPTH_STENCIL_EXT: - case GL_DEPTH24_STENCIL8_EXT: - rb->_ActualFormat = GL_DEPTH24_STENCIL8_EXT; - rb->DataType = GL_UNSIGNED_INT_24_8_EXT; - rb->DepthBits = 24; - rb->StencilBits = 8; - cpp = 4; - break; - default: - _mesa_problem(ctx, "Unexpected format in intel_alloc_renderbuffer_storage"); - return GL_FALSE; - } - - intelFlush(ctx); - - /* free old region */ - if (irb->region) { - /*LOCK_HARDWARE(intel);*/ - intel_region_release(intel, &irb->region); - /*UNLOCK_HARDWARE(intel);*/ - } - - /* allocate new memory region/renderbuffer */ - if (softwareBuffer) { - return _mesa_soft_renderbuffer_storage(ctx, rb, internalFormat, - width, height); - } - else { - /* Choose a pitch to match hardware requirements: - */ - GLuint pitch = ((cpp * width + 63) & ~63) / cpp; - - /* alloc hardware renderbuffer */ - _mesa_debug(ctx, "Allocating %d x %d Intel RBO (pitch %d)\n", width, height, pitch); - - irb->region = intel_region_alloc(intel, cpp, pitch, height); - if (!irb->region) - return GL_FALSE; /* out of memory? */ - - ASSERT(irb->region->buffer); - - rb->Width = width; - rb->Height = height; - - /* This sets the Get/PutRow/Value functions */ - intel_set_span_functions(&irb->Base); - - return GL_TRUE; - } -} - - - -/** - * Called for each hardware renderbuffer when a _window_ is resized. - * Just update fields. - * Not used for user-created renderbuffers! - */ -static GLboolean -intel_alloc_window_storage(GLcontext *ctx, struct gl_renderbuffer *rb, - GLenum internalFormat, - GLuint width, GLuint height) -{ - ASSERT(rb->Name == 0); - rb->Width = width; - rb->Height = height; - rb->_ActualFormat = internalFormat; - return GL_TRUE; -} - - -static GLboolean -intel_nop_alloc_storage(GLcontext *ctx, struct gl_renderbuffer *rb, - GLenum internalFormat, - GLuint width, GLuint height) -{ - _mesa_problem(ctx, "intel_op_alloc_storage should never be called."); - return GL_FALSE; -} - - - -/** - * Create a new intel_renderbuffer which corresponds to an on-screen window, - * not a user-created renderbuffer. - * \param width the screen width - * \param height the screen height - */ -struct intel_renderbuffer * -intel_create_renderbuffer(GLenum intFormat, GLsizei width, GLsizei height, - int offset, int pitch, int cpp, void *map) -{ - GET_CURRENT_CONTEXT(ctx); - - struct intel_renderbuffer *irb; - const GLuint name = 0; - - irb = CALLOC_STRUCT(intel_renderbuffer); - if (!irb) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "creating renderbuffer"); - return NULL; - } - - _mesa_init_renderbuffer(&irb->Base, name); - irb->Base.ClassID = INTEL_RB_CLASS; - - switch (intFormat) { - case GL_RGB5: - irb->Base._ActualFormat = GL_RGB5; - irb->Base._BaseFormat = GL_RGBA; - irb->Base.RedBits = 5; - irb->Base.GreenBits = 6; - irb->Base.BlueBits = 5; - irb->Base.DataType = GL_UNSIGNED_BYTE; - cpp = 2; - break; - case GL_RGBA8: - irb->Base._ActualFormat = GL_RGBA8; - irb->Base._BaseFormat = GL_RGBA; - irb->Base.RedBits = 8; - irb->Base.GreenBits = 8; - irb->Base.BlueBits = 8; - irb->Base.AlphaBits = 8; - irb->Base.DataType = GL_UNSIGNED_BYTE; - cpp = 4; - break; - case GL_STENCIL_INDEX8_EXT: - irb->Base._ActualFormat = GL_STENCIL_INDEX8_EXT; - irb->Base._BaseFormat = GL_STENCIL_INDEX; - irb->Base.StencilBits = 8; - irb->Base.DataType = GL_UNSIGNED_BYTE; - cpp = 1; - break; - case GL_DEPTH_COMPONENT16: - irb->Base._ActualFormat = GL_DEPTH_COMPONENT16; - irb->Base._BaseFormat = GL_DEPTH_COMPONENT; - irb->Base.DepthBits = 16; - irb->Base.DataType = GL_UNSIGNED_SHORT; - cpp = 2; - break; - case GL_DEPTH_COMPONENT24: - irb->Base._ActualFormat = GL_DEPTH24_STENCIL8_EXT; - irb->Base._BaseFormat = GL_DEPTH_COMPONENT; - irb->Base.DepthBits = 24; - irb->Base.DataType = GL_UNSIGNED_INT; - cpp = 4; - break; - case GL_DEPTH24_STENCIL8_EXT: - irb->Base._ActualFormat = GL_DEPTH24_STENCIL8_EXT; - irb->Base._BaseFormat = GL_DEPTH_STENCIL_EXT; - irb->Base.DepthBits = 24; - irb->Base.StencilBits = 8; - irb->Base.DataType = GL_UNSIGNED_INT_24_8_EXT; - cpp = 4; - break; - default: - _mesa_problem(NULL, "Unexpected intFormat in intel_create_renderbuffer"); - return NULL; - } - - irb->Base.InternalFormat = intFormat; - - /* intel-specific methods */ - irb->Base.Delete = intel_delete_renderbuffer; - irb->Base.AllocStorage = intel_alloc_window_storage; - irb->Base.GetPointer = intel_get_pointer; - /* This sets the Get/PutRow/Value functions */ - intel_set_span_functions(&irb->Base); - - irb->pfMap = map; - irb->pfPitch = pitch; - -#if 00 - irb->region = intel_region_create_static(intel, - DRM_MM_TT, - offset, - map, - cpp, - width, height); -#endif - - return irb; -} - - -/** - * Create a new renderbuffer object. - * Typically called via glBindRenderbufferEXT(). - */ -static struct gl_renderbuffer * -intel_new_renderbuffer(GLcontext *ctx, GLuint name) -{ - /*struct intel_context *intel = intel_context(ctx);*/ - struct intel_renderbuffer *irb; - - irb = CALLOC_STRUCT(intel_renderbuffer); - if (!irb) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "creating renderbuffer"); - return NULL; - } - - _mesa_init_renderbuffer(&irb->Base, name); - irb->Base.ClassID = INTEL_RB_CLASS; - - /* intel-specific methods */ - irb->Base.Delete = intel_delete_renderbuffer; - irb->Base.AllocStorage = intel_alloc_renderbuffer_storage; - irb->Base.GetPointer = intel_get_pointer; - /* span routines set in alloc_storage function */ - - return &irb->Base; -} - - -/** - * Called via glBindFramebufferEXT(). - */ -static void -intel_bind_framebuffer(GLcontext *ctx, GLenum target, - struct gl_framebuffer *fb) -{ - /* - _mesa_debug(ctx, "%s %d\n", __FUNCTION__, fb->Name); - */ - /* XXX FBO: putting this flush here fixes a rendering offset bug. - * Not sure why this is needed when _mesa_BindFrameBuffer does - * a FLUSH_VERTICES(). - */ - intelFlush(ctx); - - if (target == GL_FRAMEBUFFER_EXT || target == GL_DRAW_FRAMEBUFFER_EXT) { - intel_draw_buffer(ctx, fb); - /* Integer depth range depends on depth buffer bits */ - ctx->Driver.DepthRange(ctx, ctx->Viewport.Near, ctx->Viewport.Far); - } - else { - /* don't need to do anything if target == GL_READ_FRAMEBUFFER_EXT */ - } -} - - -/** - * Called via glFramebufferRenderbufferEXT(). - */ -static void -intel_framebuffer_renderbuffer(GLcontext *ctx, - struct gl_framebuffer *fb, - GLenum attachment, - struct gl_renderbuffer *rb) -{ - /* - _mesa_debug(ctx, "Intel FramebufferRenderbuffer %u %u\n", - fb->Name, rb ? rb->Name : 0); - */ - - intelFlush(ctx); - - _mesa_framebuffer_renderbuffer(ctx, fb, attachment, rb); - intel_draw_buffer(ctx, fb); -} - - -/** - * When glFramebufferTexture[123]D is called this function sets up the - * gl_renderbuffer wrapp around the texture image. - * This will have the region info needed for hardware rendering. - */ -static struct intel_renderbuffer * -intel_wrap_texture(GLcontext *ctx, struct gl_texture_image *texImage) -{ - const GLuint name = ~0; /* not significant, but distinct for debugging */ - struct intel_renderbuffer *irb; - - /* make an intel_renderbuffer to wrap the texture image */ - irb = CALLOC_STRUCT(intel_renderbuffer); - if (!irb) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glFramebufferTexture"); - return NULL; - } - - _mesa_init_renderbuffer(&irb->Base, name); - irb->Base.ClassID = INTEL_RB_CLASS; - - if (texImage->TexFormat == &_mesa_texformat_argb8888) { - irb->Base._ActualFormat = GL_RGBA8; - irb->Base._BaseFormat = GL_RGBA; - _mesa_debug(ctx, "Render to RGBA8 texture OK\n"); - } - else if (texImage->TexFormat == &_mesa_texformat_rgb565) { - irb->Base._ActualFormat = GL_RGB5; - irb->Base._BaseFormat = GL_RGB; - _mesa_debug(ctx, "Render to RGB5 texture OK\n"); - } - else if (texImage->TexFormat == &_mesa_texformat_depth_component16) { - irb->Base._ActualFormat = GL_DEPTH_COMPONENT16; - irb->Base._BaseFormat = GL_DEPTH_COMPONENT; - _mesa_debug(ctx, "Render to DEPTH16 texture OK\n"); - } - else { - _mesa_debug(ctx, "Render to texture BAD FORMAT %d\n", texImage->TexFormat->MesaFormat); - _mesa_free(irb); - return NULL; - } - - irb->Base.InternalFormat = irb->Base._ActualFormat; - irb->Base.Width = texImage->Width; - irb->Base.Height = texImage->Height; - irb->Base.DataType = GL_UNSIGNED_BYTE; /* FBO XXX fix */ - irb->Base.RedBits = texImage->TexFormat->RedBits; - irb->Base.GreenBits = texImage->TexFormat->GreenBits; - irb->Base.BlueBits = texImage->TexFormat->BlueBits; - irb->Base.AlphaBits = texImage->TexFormat->AlphaBits; - irb->Base.DepthBits = texImage->TexFormat->DepthBits; - - irb->Base.Delete = intel_delete_renderbuffer; - irb->Base.AllocStorage = intel_nop_alloc_storage; - intel_set_span_functions(&irb->Base); - - irb->RenderToTexture = GL_TRUE; - - return irb; -} - - -/** - * Called by glFramebufferTexture[123]DEXT() (and other places) to - * prepare for rendering into texture memory. This might be called - * many times to choose different texture levels, cube faces, etc - * before intel_finish_render_texture() is ever called. - */ -static void -intel_render_texture(GLcontext *ctx, - struct gl_framebuffer *fb, - struct gl_renderbuffer_attachment *att) -{ - struct gl_texture_image *newImage - = att->Texture->Image[att->CubeMapFace][att->TextureLevel]; - struct intel_renderbuffer *irb - = intel_renderbuffer(att->Renderbuffer); - struct intel_texture_image *intel_image; - GLuint imageOffset; - - (void) fb; - - ASSERT(newImage); - - if (!irb) { - irb = intel_wrap_texture(ctx, newImage); - if (irb) { - /* bind the wrapper to the attachment point */ - att->Renderbuffer = &irb->Base; - } - else { - /* fallback to software rendering */ - _mesa_render_texture(ctx, fb, att); - return; - } - } - - /* - _mesa_debug(ctx, "Begin render texture tex=%u w=%d h=%d refcount=%d\n", - att->Texture->Name, newImage->Width, newImage->Height, - irb->Base.RefCount); - */ - - /* point the renderbufer's region to the texture image region */ - intel_image = intel_texture_image(newImage); - if (irb->region != intel_image->mt->region) - intel_region_reference(&irb->region, intel_image->mt->region); - - /* compute offset of the particular 2D image within the texture region */ - imageOffset = intel_miptree_image_offset(intel_image->mt, - att->CubeMapFace, - att->TextureLevel); - if (att->Texture->Target == GL_TEXTURE_3D) { - GLuint imgStride = intel_miptree_depth_image_stride(intel_image->mt, - att->CubeMapFace, - att->TextureLevel); - imageOffset += imgStride * att->Zoffset; - } - /* store that offset in the region */ - intel_image->mt->region->draw_offset = imageOffset; - - /* update drawing region, etc */ - intel_draw_buffer(ctx, fb); -} - - -/** - * Called by Mesa when rendering to a texture is done. - */ -static void -intel_finish_render_texture(GLcontext *ctx, - struct gl_renderbuffer_attachment *att) -{ - struct intel_context *intel = intel_context(ctx); - struct intel_renderbuffer *irb - = intel_renderbuffer(att->Renderbuffer); - - /* - _mesa_debug(ctx, "End render texture (tid %u) tex %u\n", - _glthread_GetID(), att->Texture->Name); - */ - - if (irb) { - /* just release the region */ - intel_region_release(intel, &irb->region); - } - else if (att->Renderbuffer) { - /* software fallback */ - _mesa_finish_render_texture(ctx, att); - /* XXX FBO: Need to unmap the buffer (or in intelSpanRenderStart???) */ - } -} - - -/** - * Do one-time context initializations related to GL_EXT_framebuffer_object. - * Hook in device driver functions. - */ -void -intel_fbo_init( struct intel_context *intel ) -{ - intel->ctx.Driver.NewFramebuffer = intel_new_framebuffer; - intel->ctx.Driver.NewRenderbuffer = intel_new_renderbuffer; - intel->ctx.Driver.BindFramebuffer = intel_bind_framebuffer; - intel->ctx.Driver.FramebufferRenderbuffer = intel_framebuffer_renderbuffer; - intel->ctx.Driver.RenderTexture = intel_render_texture; - intel->ctx.Driver.FinishRenderTexture = intel_finish_render_texture; -} diff --git a/src/mesa/drivers/dri/i915-tex/intel_fbo.h b/src/mesa/drivers/dri/i915-tex/intel_fbo.h deleted file mode 100644 index 980726763ab..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_fbo.h +++ /dev/null @@ -1,75 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#ifndef INTEL_FBO_H -#define INTEL_FBO_H - - -struct intel_context; -struct intel_region; - - -/** - * Intel renderbuffer, derived from gl_renderbuffer. - * Note: The PairedDepth and PairedStencil fields use renderbuffer IDs, - * not pointers because in some circumstances a deleted renderbuffer could - * result in a dangling pointer here. - */ -struct intel_renderbuffer { - struct gl_renderbuffer Base; - struct intel_region *region; - void *pfMap; /* possibly paged flipped map pointer */ - GLuint pfPitch; /* possibly paged flipped pitch */ - GLboolean RenderToTexture; /* RTT? */ - - GLuint PairedDepth; /**< only used if this is a depth renderbuffer */ - GLuint PairedStencil; /**< only used if this is a stencil renderbuffer */ -}; - - -extern struct intel_renderbuffer * -intel_create_renderbuffer(GLenum intFormat, GLsizei width, GLsizei height, - int offset, int pitch, int cpp, void *map); - - -extern void -intel_fbo_init( struct intel_context *intel ); - - -/* XXX make inline or macro */ -extern struct intel_renderbuffer * -intel_get_renderbuffer(struct gl_framebuffer *fb, GLuint attIndex); - - -/* XXX make inline or macro */ -extern struct intel_region * -intel_get_rb_region(struct gl_framebuffer *fb, GLuint attIndex); - - - - -#endif /* INTEL_FBO_H */ diff --git a/src/mesa/drivers/dri/i915-tex/intel_ioctl.c b/src/mesa/drivers/dri/i915-tex/intel_ioctl.c deleted file mode 100644 index 2f06d47b912..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_ioctl.c +++ /dev/null @@ -1,529 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - - -#include <stdio.h> -#include <unistd.h> -#include <errno.h> -#include <sched.h> - -#include "mtypes.h" -#include "context.h" -#include "swrast/swrast.h" - -#include "intel_context.h" -#include "intel_ioctl.h" -#include "intel_batchbuffer.h" -#include "intel_blit.h" -#include "intel_regions.h" -#include "drm.h" -#include "intel_bufmgr.h" - -u_int32_t intelGetLastFrame (intelContextPtr intel) -{ - int ret; - u_int32_t frame; - drm_i915_getparam_t gp; - - gp.param = I915_PARAM_LAST_DISPATCH; - gp.value = (int *)&frame; - ret = drmCommandWriteRead( intel->driFd, DRM_I915_GETPARAM, - &gp, sizeof(gp) ); - return frame; -} - -<<<<<<< intel_ioctl.c -int intelEmitIrqLocked( intelContextPtr intel ) -======= -int intelEmitIrqLocked( struct intel_context *intel ) ->>>>>>> 1.10.2.11 -{ - drmI830IrqEmit ie; - int ret, seq; - - assert(((*(int *)intel->driHwLock) & ~DRM_LOCK_CONT) == - (DRM_LOCK_HELD|intel->hHWContext)); - - ie.irq_seq = &seq; - - ret = drmCommandWriteRead( intel->driFd, DRM_I830_IRQ_EMIT, - &ie, sizeof(ie) ); - if ( ret ) { - fprintf( stderr, "%s: drmI830IrqEmit: %d\n", __FUNCTION__, ret ); - exit(1); - } - - if (0) - fprintf(stderr, "%s --> %d\n", __FUNCTION__, seq ); - - return seq; -} - -<<<<<<< intel_ioctl.c -void intelWaitIrq( intelContextPtr intel, int seq ) -======= -void intelWaitIrq( struct intel_context *intel, int seq ) ->>>>>>> 1.10.2.11 -{ - int ret; - - if (0) - fprintf(stderr, "%s %d\n", __FUNCTION__, seq ); - - intel->iw.irq_seq = seq; - - do { - ret = drmCommandWrite( intel->driFd, DRM_I830_IRQ_WAIT, &intel->iw, sizeof(intel->iw) ); - } while (ret == -EAGAIN || ret == -EINTR); - - if ( ret ) { - fprintf( stderr, "%s: drmI830IrqWait: %d\n", __FUNCTION__, ret ); - exit(1); - } -} - - -<<<<<<< intel_ioctl.c - -static void age_intel( intelContextPtr intel, int age ) -{ - GLuint i; - - for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) - if (intel->CurrentTexObj[i]) - intel->CurrentTexObj[i]->age = age; -} - -void intel_dump_batchbuffer( long offset, - int *ptr, - int count ) -{ - int i; - fprintf(stderr, "\n\n\nSTART BATCH (%d dwords):\n", count); - for (i = 0; i < count/4; i += 4) - fprintf(stderr, "\t0x%x: 0x%08x 0x%08x 0x%08x 0x%08x\n", - (unsigned int)offset + i*4, ptr[i], ptr[i+1], ptr[i+2], ptr[i+3]); - fprintf(stderr, "END BATCH\n\n\n"); -} - -void intelRefillBatchLocked( intelContextPtr intel, GLboolean allow_unlock ) -{ - GLuint last_irq = intel->alloc.irq_emitted; - GLuint half = intel->alloc.size / 2; - GLuint buf = (intel->alloc.active_buf ^= 1); - - intel->alloc.irq_emitted = intelEmitIrqLocked( intel ); - - if (last_irq) { - if (allow_unlock) UNLOCK_HARDWARE( intel ); - intelWaitIrq( intel, last_irq ); - if (allow_unlock) LOCK_HARDWARE( intel ); - } - - if (0) - fprintf(stderr, "%s: now using half %d\n", __FUNCTION__, buf); - - intel->batch.start_offset = intel->alloc.offset + buf * half; - intel->batch.ptr = (char *)intel->alloc.ptr + buf * half; - intel->batch.size = half - 8; - intel->batch.space = half - 8; - assert(intel->batch.space >= 0); -} - -#define MI_BATCH_BUFFER_END (0xA<<23) - - -void intelFlushBatchLocked( intelContextPtr intel, - GLboolean ignore_cliprects, - GLboolean refill, - GLboolean allow_unlock) -======= -void intel_batch_ioctl( struct intel_context *intel, - GLuint start_offset, - GLuint used, - GLboolean ignore_cliprects, - GLboolean allow_unlock) ->>>>>>> 1.10.2.11 -{ - drmI830BatchBuffer batch; - - assert(intel->locked); - assert(used); - - if (0) -<<<<<<< intel_ioctl.c - fprintf(stderr, "%s used %d of %d offset %x..%x refill %d (started in %s)\n", -======= - fprintf(stderr, "%s used %d offset %x..%x ignore_cliprects %d\n", ->>>>>>> 1.10.2.11 - __FUNCTION__, -<<<<<<< intel_ioctl.c - (intel->batch.size - intel->batch.space), - intel->batch.size, - intel->batch.start_offset, - intel->batch.start_offset + - (intel->batch.size - intel->batch.space), - refill, - intel->batch.func); -======= - used, - start_offset, - start_offset + used, - ignore_cliprects); ->>>>>>> 1.10.2.11 - - /* Throw away non-effective packets. Won't work once we have - * hardware contexts which would preserve statechanges beyond a - * single buffer. - */ - if (intel->numClipRects == 0 && !ignore_cliprects) { - if (allow_unlock) { - UNLOCK_HARDWARE(intel); - sched_yield(); - LOCK_HARDWARE(intel); - } - intel->vtbl.lost_hardware( intel ); - return; - } - -<<<<<<< intel_ioctl.c - if (intel->batch.space != intel->batch.size) { - - if (intel->sarea->ctxOwner != intel->hHWContext) { - intel->perf_boxes |= I830_BOX_LOST_CONTEXT; - intel->sarea->ctxOwner = intel->hHWContext; - } - - batch.start = intel->batch.start_offset; - batch.used = intel->batch.size - intel->batch.space; - batch.cliprects = intel->pClipRects; - batch.num_cliprects = ignore_cliprects ? 0 : intel->numClipRects; - batch.DR1 = 0; - batch.DR4 = ((((GLuint)intel->drawX) & 0xffff) | - (((GLuint)intel->drawY) << 16)); -======= - batch.start = start_offset; - batch.used = used; - batch.cliprects = intel->pClipRects; - batch.num_cliprects = ignore_cliprects ? 0 : intel->numClipRects; - batch.DR1 = 0; - batch.DR4 = ((((GLuint)intel->drawX) & 0xffff) | - (((GLuint)intel->drawY) << 16)); ->>>>>>> 1.10.2.11 - -<<<<<<< intel_ioctl.c - if (intel->alloc.offset) { - if ((batch.used & 0x4) == 0) { - ((int *)intel->batch.ptr)[0] = 0; - ((int *)intel->batch.ptr)[1] = MI_BATCH_BUFFER_END; - batch.used += 0x8; - intel->batch.ptr += 0x8; - } - else { - ((int *)intel->batch.ptr)[0] = MI_BATCH_BUFFER_END; - batch.used += 0x4; - intel->batch.ptr += 0x4; - } - } - - if (0) - intel_dump_batchbuffer( batch.start, - (int *)(intel->batch.ptr - batch.used), - batch.used ); - - intel->batch.start_offset += batch.used; - intel->batch.size -= batch.used; - - if (intel->batch.size < 8) { - refill = GL_TRUE; - intel->batch.space = intel->batch.size = 0; - } - else { - intel->batch.size -= 8; - intel->batch.space = intel->batch.size; - } - - - assert(intel->batch.space >= 0); - assert(batch.start >= intel->alloc.offset); - assert(batch.start < intel->alloc.offset + intel->alloc.size); - assert(batch.start + batch.used > intel->alloc.offset); - assert(batch.start + batch.used <= - intel->alloc.offset + intel->alloc.size); - - - if (intel->alloc.offset) { - if (drmCommandWrite (intel->driFd, DRM_I830_BATCHBUFFER, &batch, - sizeof(batch))) { - fprintf(stderr, "DRM_I830_BATCHBUFFER: %d\n", -errno); - UNLOCK_HARDWARE(intel); - exit(1); - } - } else { - drmI830CmdBuffer cmd; - cmd.buf = (char *)intel->alloc.ptr + batch.start; - cmd.sz = batch.used; - cmd.DR1 = batch.DR1; - cmd.DR4 = batch.DR4; - cmd.num_cliprects = batch.num_cliprects; - cmd.cliprects = batch.cliprects; - - if (drmCommandWrite (intel->driFd, DRM_I830_CMDBUFFER, &cmd, - sizeof(cmd))) { - fprintf(stderr, "DRM_I830_CMDBUFFER: %d\n", -errno); - UNLOCK_HARDWARE(intel); - exit(1); - } - } - - - age_intel(intel, intel->sarea->last_enqueue); - - /* FIXME: use hardware contexts to avoid 'losing' hardware after - * each buffer flush. - */ - if (intel->batch.contains_geometry) - assert(intel->batch.last_emit_state == intel->batch.counter); - - intel->batch.counter++; - intel->batch.contains_geometry = 0; - intel->batch.func = 0; - intel->vtbl.lost_hardware( intel ); - } - - if (refill) - intelRefillBatchLocked( intel, allow_unlock ); -} - -void intelFlushBatch( intelContextPtr intel, GLboolean refill ) -{ - if (intel->locked) { - intelFlushBatchLocked( intel, GL_FALSE, refill, GL_FALSE ); - } - else { - LOCK_HARDWARE(intel); - intelFlushBatchLocked( intel, GL_FALSE, refill, GL_TRUE ); - UNLOCK_HARDWARE(intel); - } -} - - -void intelWaitForIdle( intelContextPtr intel ) -{ - if (0) - fprintf(stderr, "%s\n", __FUNCTION__); - - intel->vtbl.emit_flush( intel ); - intelFlushBatch( intel, GL_TRUE ); - - /* Use an irq to wait for dma idle -- Need to track lost contexts - * to shortcircuit consecutive calls to this function: - */ - intelWaitIrq( intel, intel->alloc.irq_emitted ); - intel->alloc.irq_emitted = 0; -} - - -/** - * Check if we need to rotate/warp the front color buffer to the - * rotated screen. We generally need to do this when we get a glFlush - * or glFinish after drawing to the front color buffer. - */ -static void -intelCheckFrontRotate(GLcontext *ctx) -{ - intelContextPtr intel = INTEL_CONTEXT( ctx ); - if (intel->ctx.DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_FRONT_LEFT) { - intelScreenPrivate *screen = intel->intelScreen; - if (screen->current_rotation != 0) { - __DRIdrawablePrivate *dPriv = intel->driDrawable; - intelRotateWindow(intel, dPriv, BUFFER_BIT_FRONT_LEFT); - } - } -} - - -/** - * NOT directly called via glFlush. - */ -void intelFlush( GLcontext *ctx ) -{ - intelContextPtr intel = INTEL_CONTEXT( ctx ); - - if (intel->Fallback) - _swrast_flush( ctx ); - - INTEL_FIREVERTICES( intel ); - - if (intel->batch.size != intel->batch.space) - intelFlushBatch( intel, GL_FALSE ); -} - - -/** - * Called via glFlush. - */ -void intelglFlush( GLcontext *ctx ) -{ - intelFlush(ctx); - intelCheckFrontRotate(ctx); -} - - -void intelFinish( GLcontext *ctx ) -{ - intelContextPtr intel = INTEL_CONTEXT( ctx ); - intelFlush( ctx ); - intelWaitForIdle( intel ); - intelCheckFrontRotate(ctx); -} - - -void intelClear(GLcontext *ctx, GLbitfield mask, GLboolean all, - GLint cx, GLint cy, GLint cw, GLint ch) -{ - intelContextPtr intel = INTEL_CONTEXT( ctx ); - const GLuint colorMask = *((GLuint *) &ctx->Color.ColorMask); - GLbitfield tri_mask = 0; - GLbitfield blit_mask = 0; - GLbitfield swrast_mask = 0; - - if (0) - fprintf(stderr, "%s\n", __FUNCTION__); - - /* Take care of cliprects, which are handled differently for - * clears, etc. - */ - intelFlush( &intel->ctx ); - - if (mask & BUFFER_BIT_FRONT_LEFT) { - if (colorMask == ~0) { - blit_mask |= BUFFER_BIT_FRONT_LEFT; - } - else { - tri_mask |= BUFFER_BIT_FRONT_LEFT; - } - } - - if (mask & BUFFER_BIT_BACK_LEFT) { - if (colorMask == ~0) { - blit_mask |= BUFFER_BIT_BACK_LEFT; - } - else { - tri_mask |= BUFFER_BIT_BACK_LEFT; - } - } - - if (mask & BUFFER_BIT_DEPTH) { - blit_mask |= BUFFER_BIT_DEPTH; - } - - if (mask & BUFFER_BIT_STENCIL) { - if (!intel->hw_stencil) { - swrast_mask |= BUFFER_BIT_STENCIL; - } - else if (ctx->Stencil.WriteMask[0] != 0xff) { - tri_mask |= BUFFER_BIT_STENCIL; - } - else { - blit_mask |= BUFFER_BIT_STENCIL; - } - } - - swrast_mask |= (mask & BUFFER_BIT_ACCUM); - - if (blit_mask) - intelClearWithBlit( ctx, blit_mask, all, cx, cy, cw, ch ); - - if (tri_mask) - intel->vtbl.clear_with_tris( intel, tri_mask, all, cx, cy, cw, ch); - - if (swrast_mask) - _swrast_Clear( ctx, swrast_mask, all, cx, cy, cw, ch ); -} - - -void -intelRotateWindow(intelContextPtr intel, __DRIdrawablePrivate *dPriv, - GLuint srcBuffer) -{ - if (intel->vtbl.rotate_window) { - intel->vtbl.rotate_window(intel, dPriv, srcBuffer); - } -} - - -void *intelAllocateAGP( intelContextPtr intel, GLsizei size ) -{ - int region_offset; - drmI830MemAlloc alloc; - int ret; - - if (0) - fprintf(stderr, "%s: %d bytes\n", __FUNCTION__, size); - - alloc.region = I830_MEM_REGION_AGP; - alloc.alignment = 0; - alloc.size = size; - alloc.region_offset = ®ion_offset; - - LOCK_HARDWARE(intel); - - /* Make sure the global heap is initialized - */ - if (intel->texture_heaps[0]) - driAgeTextures( intel->texture_heaps[0] ); - - - ret = drmCommandWriteRead( intel->driFd, - DRM_I830_ALLOC, - &alloc, sizeof(alloc)); - - if (ret) { - fprintf(stderr, "%s: DRM_I830_ALLOC ret %d\n", __FUNCTION__, ret); -======= - if (INTEL_DEBUG & DEBUG_DMA) - fprintf(stderr, "%s: 0x%x..0x%x DR4: %x cliprects: %d\n", - __FUNCTION__, - batch.start, - batch.start + batch.used * 4, - batch.DR4, batch.num_cliprects); -#if 1 - if (drmCommandWrite (intel->driFd, DRM_I830_BATCHBUFFER, &batch, - sizeof(batch))) { - fprintf(stderr, "DRM_I830_BATCHBUFFER: %d\n", -errno); ->>>>>>> 1.10.2.11 - UNLOCK_HARDWARE(intel); - exit(1); - } -#endif - - /* FIXME: use hardware contexts to avoid 'losing' hardware after - * each buffer flush. - */ - intel->vtbl.lost_hardware( intel ); -} diff --git a/src/mesa/drivers/dri/i915-tex/intel_ioctl.h b/src/mesa/drivers/dri/i915-tex/intel_ioctl.h deleted file mode 100644 index 0a090af0733..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_ioctl.h +++ /dev/null @@ -1,82 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#ifndef INTEL_IOCTL_H -#define INTEL_IOCTL_H - -#include "intel_context.h" - -void intelWaitIrq( struct intel_context *intel, int seq ); -int intelEmitIrqLocked( struct intel_context *intel ); - -<<<<<<< intel_ioctl.h -extern void intelClear(GLcontext *ctx, GLbitfield mask, GLboolean all, - GLint cx, GLint cy, GLint cw, GLint ch); - -extern void intelPageFlip( const __DRIdrawablePrivate *dpriv ); - -extern void intelRotateWindow(intelContextPtr intel, - __DRIdrawablePrivate *dPriv, GLuint srcBuffer); - -extern void intelWaitForIdle( intelContextPtr intel ); -extern void intelFlushBatch( intelContextPtr intel, GLboolean refill ); -extern void intelFlushBatchLocked( intelContextPtr intel, - GLboolean ignore_cliprects, - GLboolean refill, - GLboolean allow_unlock); -extern void intelRefillBatchLocked( intelContextPtr intel, GLboolean allow_unlock ); -extern void intelFinish( GLcontext *ctx ); -extern void intelFlush( GLcontext *ctx ); -extern void intelglFlush( GLcontext *ctx ); - -extern void *intelAllocateAGP( intelContextPtr intel, GLsizei size ); -extern void intelFreeAGP( intelContextPtr intel, void *pointer ); - -extern void *intelAllocateMemoryMESA( __DRInativeDisplay *dpy, int scrn, - GLsizei size, GLfloat readfreq, - GLfloat writefreq, GLfloat priority ); - -extern void intelFreeMemoryMESA( __DRInativeDisplay *dpy, int scrn, - GLvoid *pointer ); - -extern GLuint intelGetMemoryOffsetMESA( __DRInativeDisplay *dpy, int scrn, const GLvoid *pointer ); -extern GLboolean intelIsAgpMemory( intelContextPtr intel, const GLvoid *pointer, - GLint size ); - -extern GLuint intelAgpOffsetFromVirtual( intelContextPtr intel, const GLvoid *p ); -======= -void intel_batch_ioctl( struct intel_context *intel, - GLuint start_offset, - GLuint used, - GLboolean ignore_cliprects, - GLboolean allow_unlock); ->>>>>>> 1.2.12.5 - -extern void intelWaitIrq( intelContextPtr intel, int seq ); -extern u_int32_t intelGetLastFrame (intelContextPtr intel); -extern int intelEmitIrqLocked( intelContextPtr intel ); -#endif diff --git a/src/mesa/drivers/dri/i915-tex/intel_mipmap_tree.c b/src/mesa/drivers/dri/i915-tex/intel_mipmap_tree.c deleted file mode 100644 index 7f4f00cf8e3..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_mipmap_tree.c +++ /dev/null @@ -1,300 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "intel_context.h" -#include "intel_mipmap_tree.h" -#include "intel_regions.h" -#include "intel_bufmgr.h" -#include "enums.h" - -static GLenum target_to_target( GLenum target ) -{ - switch (target) { - case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: - return GL_TEXTURE_CUBE_MAP_ARB; - default: - return target; - } -} - -struct intel_mipmap_tree *intel_miptree_create( struct intel_context *intel, - GLenum target, - GLenum internal_format, - GLuint first_level, - GLuint last_level, - GLuint width0, - GLuint height0, - GLuint depth0, - GLuint cpp, - GLboolean compressed) -{ - GLboolean ok; - struct intel_mipmap_tree *mt = calloc(sizeof(*mt), 1); - - DBG("%s target %s format %s level %d..%d\n", __FUNCTION__, - _mesa_lookup_enum_by_nr(target), - _mesa_lookup_enum_by_nr(internal_format), - first_level, - last_level); - - mt->target = target_to_target(target); - mt->internal_format = internal_format; - mt->first_level = first_level; - mt->last_level = last_level; - mt->width0 = width0; - mt->height0 = height0; - mt->depth0 = depth0; - mt->cpp = cpp; - mt->compressed = compressed; - mt->refcount = 1; - - switch (intel->intelScreen->deviceID) { - case PCI_CHIP_I945_G: -/* case PCI_CHIP_I945_GM: */ - ok = i945_miptree_layout( mt ); - break; - default: - /* All the i830 chips and the i915 use this layout: - */ - ok = i915_miptree_layout( mt ); - break; - } - - if (ok) - mt->region = intel_region_alloc( intel, - mt->cpp, - mt->pitch, - mt->total_height ); - - if (!mt->region) { - free(mt); - return NULL; - } - - return mt; -} - - -void intel_miptree_reference( struct intel_mipmap_tree **dst, - struct intel_mipmap_tree *src ) -{ - src->refcount++; - *dst = src; -} - -void intel_miptree_release( struct intel_context *intel, - struct intel_mipmap_tree **mt ) -{ - if (!*mt) - return; - - DBG("%s %d\n", __FUNCTION__, (*mt)->refcount-1); - if (--(*mt)->refcount == 0) { - intel_region_release(intel, &((*mt)->region)); - free(*mt); - } - *mt = NULL; -} - - - - -/* Can the image be pulled into a unified mipmap tree. This mirrors - * the completeness test in a lot of ways. - * - * Not sure whether I want to pass gl_texture_image here. - */ -GLboolean intel_miptree_match_image( struct intel_mipmap_tree *mt, - struct gl_texture_image *image, - GLuint face, - GLuint level ) -{ - DBG("%s %d %d/%d %d/%d\n", __FUNCTION__, - image->Border, - image->InternalFormat, mt->internal_format, - image->IsCompressed, mt->compressed); - - /* Images with borders are never pulled into mipmap trees. - */ - if (image->Border) - return GL_FALSE; - - if (image->InternalFormat != mt->internal_format || - image->IsCompressed != mt->compressed) - return GL_FALSE; - - DBG("%s: %d/%d %d/%d %d/%d\n", __FUNCTION__, - image->Width, mt->offset[face][level].width, - image->Height, mt->offset[face][level].height, - image->Depth, mt->offset[face][level].depth); - - /* Test image dimensions against the base level image adjusted for - * minification. This will also catch images not present in the - * tree, changed targets, etc. - */ - if (image->Width != mt->offset[face][level].width || - image->Height != mt->offset[face][level].height || - image->Depth != mt->offset[face][level].depth) - return GL_FALSE; - - - DBG("%s: success\n", __FUNCTION__); - return GL_TRUE; -} - - -GLuint intel_miptree_image_offset(struct intel_mipmap_tree *mt, - GLuint face, - GLuint level) -{ - return mt->offset[face][level].offset; -} - -GLuint intel_miptree_depth_image_stride(struct intel_mipmap_tree *mt, - GLuint face, - GLuint level) -{ - return mt->offset[face][level].depth_image_stride; -} - - -void intel_miptree_set_image_offset(struct intel_mipmap_tree *mt, - GLuint face, - GLuint level, - GLuint x, GLuint y, - GLuint w, GLuint h, GLuint d) -{ - mt->offset[face][level].offset = (x + y * mt->pitch) * mt->cpp; - mt->offset[face][level].width = w; - mt->offset[face][level].height = h; - mt->offset[face][level].depth = d; -} - - - -/** - * Map a teximage in a mipmap tree. - * \param row_stride returns row stride in bytes - * \param image_stride returns image stride in bytes (for 3D textures). - * \return address of mapping - */ -GLubyte *intel_miptree_image_map(struct intel_context *intel, - struct intel_mipmap_tree *mt, - GLuint face, - GLuint level, - GLuint *row_stride, - GLuint *image_stride) -{ - DBG("%s \n", __FUNCTION__); - - if (row_stride) - *row_stride = mt->pitch * mt->cpp; - - if (image_stride) - *image_stride = mt->offset[face][level].depth_image_stride; - - return (intel_region_map(intel, mt->region) + - intel_miptree_image_offset(mt, face, level)); -} - -void intel_miptree_image_unmap(struct intel_context *intel, - struct intel_mipmap_tree *mt) -{ - DBG("%s\n", __FUNCTION__); - intel_region_unmap(intel, mt->region); -} - - - -/* Upload data for a particular image. - */ -void intel_miptree_image_data(struct intel_context *intel, - struct intel_mipmap_tree *dst, - GLuint face, - GLuint level, - void *src, - GLuint src_row_pitch, - GLuint src_image_pitch) -{ - GLuint depth = dst->offset[face][level].depth; - GLuint dst_offset = intel_miptree_image_offset(dst, face, level); - GLuint dst_image_stride = intel_miptree_depth_image_stride(dst, face, level); - GLuint i; - - DBG("%s\n", __FUNCTION__); - for (i = 0; i < depth; i++) { - intel_region_data(intel, - dst->region, dst_offset, - 0, - 0, - src, - src_row_pitch, - 0, 0, /* source x,y */ - dst->offset[face][level].width, - dst->offset[face][level].height); - dst_offset += dst_image_stride; - src += src_image_pitch; - } -} - -/* Copy mipmap image between trees - */ -void intel_miptree_image_copy( struct intel_context *intel, - struct intel_mipmap_tree *dst, - GLuint face, GLuint level, - struct intel_mipmap_tree *src ) -{ - GLuint width = src->offset[face][level].width; - GLuint height = src->offset[face][level].height; - GLuint depth = src->offset[face][level].depth; - GLuint dst_offset = intel_miptree_image_offset(dst, face, level); - GLuint src_offset = intel_miptree_image_offset(src, face, level); - GLuint dst_image_stride = intel_miptree_depth_image_stride(dst, face, level); - GLuint src_image_stride = intel_miptree_depth_image_stride(src, face, level); - GLuint i; - - for (i = 0; i < depth; i++) { - intel_region_copy(intel, - dst->region, dst_offset, - 0, - 0, - src->region, src_offset, - 0, - 0, - width, - height); - - dst_offset += dst_image_stride; - src_offset += src_image_stride; - } - -} diff --git a/src/mesa/drivers/dri/i915-tex/intel_mipmap_tree.h b/src/mesa/drivers/dri/i915-tex/intel_mipmap_tree.h deleted file mode 100644 index 0d009d800c8..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_mipmap_tree.h +++ /dev/null @@ -1,183 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#ifndef INTEL_MIPMAP_TREE_H -#define INTEL_MIPMAP_TREE_H - -#include "intel_regions.h" - -/* A layer on top of the intel_regions code which adds: - * - * - Code to size and layout a region to hold a set of mipmaps. - * - Query to determine if a new image fits in an existing tree. - * - More refcounting - * - maybe able to remove refcounting from intel_region? - * - ? - * - * The fixed mipmap layout of intel hardware where one offset - * specifies the position of all images in a mipmap hierachy - * complicates the implementation of GL texture image commands, - * compared to hardware where each image is specified with an - * independent offset. - * - * In an ideal world, each texture object would be associated with a - * single bufmgr buffer or 2d intel_region, and all the images within - * the texture object would slot into the tree as they arrive. The - * reality can be a little messier, as images can arrive from the user - * with sizes that don't fit in the existing tree, or in an order - * where the tree layout cannot be guessed immediately. - * - * This structure encodes an idealized mipmap tree. The GL image - * commands build these where possible, otherwise store the images in - * temporary system buffers. - */ - - -/** - * Describes the location of each texture image within a texture region. - */ -struct intel_mipmap_offset { - GLuint offset; - GLuint width; - GLuint height; - GLuint depth; - GLuint depth_image_stride; -}; - -struct intel_mipmap_tree { - /* Effectively the key: - */ - GLenum target; - GLenum internal_format; - - GLuint first_level; - GLuint last_level; - - GLuint width0, height0, depth0; /**< Level zero image dimensions */ - GLuint cpp; - GLboolean compressed; - - /* Derived from the above: - */ - GLuint pitch; - GLuint depth_pitch; /* per-image on i945? */ - GLuint total_height; - struct intel_mipmap_offset offset[MAX_FACES][MAX_TEXTURE_LEVELS]; - - /* The data is held here: - */ - struct intel_region *region; - - /* These are also refcounted: - */ - GLuint refcount; -}; - - - -struct intel_mipmap_tree *intel_miptree_create( struct intel_context *intel, - GLenum target, - GLenum internal_format, - GLuint first_level, - GLuint last_level, - GLuint width0, - GLuint height0, - GLuint depth0, - GLuint cpp, - GLboolean compressed); - -void intel_miptree_reference( struct intel_mipmap_tree **dst, - struct intel_mipmap_tree *src ); - -void intel_miptree_release( struct intel_context *intel, - struct intel_mipmap_tree **mt ); - -/* Check if an image fits an existing mipmap tree layout - */ -GLboolean intel_miptree_match_image( struct intel_mipmap_tree *mt, - struct gl_texture_image *image, - GLuint face, - GLuint level ); - -/* Return a pointer to an image within a tree. Return image stride as - * well. - */ -GLubyte *intel_miptree_image_map( struct intel_context *intel, - struct intel_mipmap_tree *mt, - GLuint face, - GLuint level, - GLuint *row_stride, - GLuint *image_stride); - -void intel_miptree_image_unmap( struct intel_context *intel, - struct intel_mipmap_tree *mt ); - - -/* Return the linear offset of an image relative to the start of the - * tree: - */ -GLuint intel_miptree_image_offset( struct intel_mipmap_tree *mt, - GLuint face, - GLuint level ); - -void intel_miptree_set_image_offset(struct intel_mipmap_tree *mt, - GLuint face, - GLuint level, - GLuint x, GLuint y, - GLuint w, GLuint h, GLuint d); - -GLuint intel_miptree_depth_image_stride(struct intel_mipmap_tree *mt, - GLuint face, - GLuint level); - - - -/* Upload an image into a tree - */ -void intel_miptree_image_data(struct intel_context *intel, - struct intel_mipmap_tree *dst, - GLuint face, - GLuint level, - void *src, - GLuint src_row_pitch, - GLuint src_image_pitch); - -/* Copy an image between two trees - */ -void intel_miptree_image_copy( struct intel_context *intel, - struct intel_mipmap_tree *dst, - GLuint face, GLuint level, - struct intel_mipmap_tree *src ); - -/* i915_mipmap_tree.c: - */ -GLboolean i915_miptree_layout( struct intel_mipmap_tree *mt ); -GLboolean i945_miptree_layout( struct intel_mipmap_tree *mt ); - - - -#endif diff --git a/src/mesa/drivers/dri/i915-tex/intel_pixel.c b/src/mesa/drivers/dri/i915-tex/intel_pixel.c deleted file mode 100644 index 0994c031db4..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_pixel.c +++ /dev/null @@ -1,511 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 portionsalloc - * 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "enums.h" -#include "state.h" -#include "swrast/swrast.h" - -#include "intel_context.h" -#include "intel_pixel.h" -#include "intel_regions.h" - - -/** - * Check if any fragment operations are in effect which might effect - * glDraw/CopyPixels. - */ -GLboolean intel_check_blit_fragment_ops( GLcontext *ctx ) -{ - if (ctx->NewState) - _mesa_update_state(ctx); - - /* XXX Note: Scissor could be done with the blitter: - */ - return !(ctx->_ImageTransferState || - ctx->Color.AlphaEnabled || - ctx->Depth.Test || - ctx->Fog.Enabled || - ctx->Scissor.Enabled || - ctx->Stencil.Enabled || - !ctx->Color.ColorMask[0] || - !ctx->Color.ColorMask[1] || - !ctx->Color.ColorMask[2] || - !ctx->Color.ColorMask[3] || - ctx->Color.ColorLogicOpEnabled || - ctx->Texture._EnabledUnits || - ctx->FragmentProgram._Enabled); -} - - -<<<<<<< intel_pixel.c -/** - * Clip the given rectangle against the buffer's bounds (including scissor). - * \param size returns the - * \return GL_TRUE if any pixels remain, GL_FALSE if totally clipped. - * - * XXX Replace this with _mesa_clip_drawpixels() and _mesa_clip_readpixels() - * from Mesa 6.4. We shouldn't apply scissor for ReadPixels. - */ -static GLboolean -clip_pixelrect( const GLcontext *ctx, - const GLframebuffer *buffer, - GLint *x, GLint *y, - GLsizei *width, GLsizei *height) -======= -GLboolean intel_check_meta_tex_fragment_ops( GLcontext *ctx ) ->>>>>>> 1.6.2.18 -{ -<<<<<<< intel_pixel.c - /* left clipping */ - if (*x < buffer->_Xmin) { - *width -= (buffer->_Xmin - *x); - *x = buffer->_Xmin; - } - - /* right clipping */ - if (*x + *width > buffer->_Xmax) - *width -= (*x + *width - buffer->_Xmax - 1); - - if (*width <= 0) - return GL_FALSE; - - /* bottom clipping */ - if (*y < buffer->_Ymin) { - *height -= (buffer->_Ymin - *y); - *y = buffer->_Ymin; - } - - /* top clipping */ - if (*y + *height > buffer->_Ymax) - *height -= (*y + *height - buffer->_Ymax - 1); - - if (*height <= 0) - return GL_FALSE; - - return GL_TRUE; -} - - -/** - * Compute intersection of a clipping rectangle and pixel rectangle, - * returning results in x/y/w/hOut vars. - * \return GL_TRUE if there's intersection, GL_FALSE if disjoint. - */ -static INLINE GLboolean -intersect_region(const drm_clip_rect_t *box, - GLint x, GLint y, GLsizei width, GLsizei height, - GLint *xOut, GLint *yOut, GLint *wOut, GLint *hOut) -{ - GLint bx = box->x1; - GLint by = box->y1; - GLint bw = box->x2 - bx; - GLint bh = box->y2 - by; - - if (bx < x) bw -= x - bx, bx = x; - if (by < y) bh -= y - by, by = y; - if (bx + bw > x + width) bw = x + width - bx; - if (by + bh > y + height) bh = y + height - by; - if (bw <= 0) return GL_FALSE; - if (bh <= 0) return GL_FALSE; - - *xOut = bx; - *yOut = by; - *wOut = bw; - *hOut = bh; - return GL_TRUE; -======= - if (ctx->NewState) - _mesa_update_state(ctx); - - /* Some of _ImageTransferState (scale, bias) could be done with - * fragment programs on i915. - */ - return !(ctx->_ImageTransferState || - ctx->Fog.Enabled || /* not done yet */ - ctx->Texture._EnabledUnits || - ctx->FragmentProgram._Enabled); ->>>>>>> 1.6.2.18 -} - -<<<<<<< intel_pixel.c - - -static GLboolean -intelTryReadPixels( GLcontext *ctx, - GLint x, GLint y, GLsizei width, GLsizei height, - GLenum format, GLenum type, - const struct gl_pixelstore_attrib *pack, - GLvoid *pixels ) -======= -/* The intel_region struct doesn't really do enough to capture the - * format of the pixels in the region. For now this code assumes that - * the region is a display surface and hence is either ARGB8888 or - * RGB565. - * XXX FBO: If we'd pass in the intel_renderbuffer instead of region, we'd - * know the buffer's pixel format. - * - * \param format as given to glDraw/ReadPixels - * \param type as given to glDraw/ReadPixels - */ -GLboolean intel_check_blit_format( struct intel_region *region, - GLenum format, GLenum type ) ->>>>>>> 1.6.2.18 -{ -<<<<<<< intel_pixel.c - intelContextPtr intel = INTEL_CONTEXT(ctx); - GLint size = 0; /* not really used */ - GLint pitch = pack->RowLength ? pack->RowLength : width; - - if (INTEL_DEBUG & DEBUG_PIXEL) - fprintf(stderr, "%s\n", __FUNCTION__); - - /* Only accelerate reading to agp buffers. - */ - if ( !intelIsAgpMemory(intel, pixels, - pitch * height * intel->intelScreen->cpp ) ) { - if (INTEL_DEBUG & DEBUG_PIXEL) - fprintf(stderr, "%s: dest not agp\n", __FUNCTION__); - return GL_FALSE; -======= - if (region->cpp == 4 && - (type == GL_UNSIGNED_INT_8_8_8_8_REV || - type == GL_UNSIGNED_BYTE) && - format == GL_BGRA ) { - return GL_TRUE; ->>>>>>> 1.6.2.18 - } -<<<<<<< intel_pixel.c - - /* Need GL_PACK_INVERT_MESA to cope with upsidedown results from - * blitter: - */ - if (!pack->Invert) { - if (INTEL_DEBUG & DEBUG_PIXEL) - fprintf(stderr, "%s: MESA_PACK_INVERT not set\n", __FUNCTION__); - return GL_FALSE; - } - - if (!check_color(ctx, type, format, pack, pixels, size, pitch)) - return GL_FALSE; - - switch ( intel->intelScreen->cpp ) { - case 4: - break; - default: - return GL_FALSE; - } - - - /* Although the blits go on the command buffer, need to do this and - * fire with lock held to guarentee cliprects and drawing offset are - * correct. - * - * This is an unusual situation however, as the code which flushes - * a full command buffer expects to be called unlocked. As a - * workaround, immediately flush the buffer on aquiring the lock. - */ - intelFlush( &intel->ctx ); - LOCK_HARDWARE( intel ); - { - __DRIdrawablePrivate *dPriv = intel->driDrawable; - int nbox = dPriv->numClipRects; - int src_offset = intel->readRegion->offset; - int src_pitch = intel->intelScreen->front.pitch; - int dst_offset = intelAgpOffsetFromVirtual( intel, pixels); - drm_clip_rect_t *box = dPriv->pClipRects; - int i; - - assert(dst_offset != ~0); /* should have been caught above */ - - if (!clip_pixelrect(ctx, ctx->ReadBuffer, &x, &y, &width, &height)) { - UNLOCK_HARDWARE( intel ); - if (INTEL_DEBUG & DEBUG_PIXEL) - fprintf(stderr, "%s totally clipped -- nothing to do\n", - __FUNCTION__); - return GL_TRUE; - } - - /* convert to screen coords (y=0=top) */ - y = dPriv->h - y - height; - x += dPriv->x; - y += dPriv->y; - - if (INTEL_DEBUG & DEBUG_PIXEL) - fprintf(stderr, "readpixel blit src_pitch %d dst_pitch %d\n", - src_pitch, pitch); - - /* We don't really have to do window clipping for readpixels. - * The OpenGL spec says that pixels read from outside the - * visible window region (pixel ownership) have undefined value. - */ - for (i = 0 ; i < nbox ; i++) - { - GLint bx, by, bw, bh; - if (intersect_region(box+i, x, y, width, height, - &bx, &by, &bw, &bh)) { - intelEmitCopyBlitLocked( intel, - intel->intelScreen->cpp, - src_pitch, src_offset, - pitch, dst_offset, - bx, by, - bx - x, by - y, - bw, bh ); - } - } - } - UNLOCK_HARDWARE( intel ); - intelFinish( &intel->ctx ); - - return GL_TRUE; -} - -static void -intelReadPixels( GLcontext *ctx, - GLint x, GLint y, GLsizei width, GLsizei height, - GLenum format, GLenum type, - const struct gl_pixelstore_attrib *pack, - GLvoid *pixels ) -{ - if (INTEL_DEBUG & DEBUG_PIXEL) - fprintf(stderr, "%s\n", __FUNCTION__); - - if (!intelTryReadPixels( ctx, x, y, width, height, format, type, pack, - pixels)) - _swrast_ReadPixels( ctx, x, y, width, height, format, type, pack, - pixels); -} - - - - -static void do_draw_pix( GLcontext *ctx, - GLint x, GLint y, GLsizei width, GLsizei height, - GLint pitch, - const void *pixels, - GLuint dest ) -{ - intelContextPtr intel = INTEL_CONTEXT(ctx); - __DRIdrawablePrivate *dPriv = intel->driDrawable; - drm_clip_rect_t *box = dPriv->pClipRects; - int nbox = dPriv->numClipRects; - int i; - int src_offset = intelAgpOffsetFromVirtual( intel, pixels); - int src_pitch = pitch; - - assert(src_offset != ~0); /* should be caught earlier */ - - if (INTEL_DEBUG & DEBUG_PIXEL) - fprintf(stderr, "%s\n", __FUNCTION__); - - intelFlush( &intel->ctx ); - LOCK_HARDWARE( intel ); - if (ctx->DrawBuffer) - { - y -= height; /* cope with pixel zoom */ -======= ->>>>>>> 1.6.2.18 - -<<<<<<< intel_pixel.c - if (!clip_pixelrect(ctx, ctx->DrawBuffer, - &x, &y, &width, &height)) { - UNLOCK_HARDWARE( intel ); - return; - } - - y = dPriv->h - y - height; /* convert from gl to hardware coords */ - x += dPriv->x; - y += dPriv->y; - - for (i = 0 ; i < nbox ; i++ ) - { - GLint bx, by, bw, bh; - if (intersect_region(box + i, x, y, width, height, - &bx, &by, &bw, &bh)) { - intelEmitCopyBlitLocked( intel, - intel->intelScreen->cpp, - src_pitch, src_offset, - intel->intelScreen->front.pitch, - intel->drawRegion->offset, - bx - x, by - y, - bx, by, - bw, bh ); - } - } - } - UNLOCK_HARDWARE( intel ); - intelFinish( &intel->ctx ); -} - - - -static GLboolean -intelTryDrawPixels( GLcontext *ctx, - GLint x, GLint y, GLsizei width, GLsizei height, - GLenum format, GLenum type, - const struct gl_pixelstore_attrib *unpack, - const GLvoid *pixels ) -{ - intelContextPtr intel = INTEL_CONTEXT(ctx); - GLint pitch = unpack->RowLength ? unpack->RowLength : width; - GLuint dest; - GLuint cpp = intel->intelScreen->cpp; - GLint size = width * pitch * cpp; - - if (INTEL_DEBUG & DEBUG_PIXEL) - fprintf(stderr, "%s\n", __FUNCTION__); - - switch (format) { - case GL_RGB: - case GL_RGBA: - case GL_BGRA: - dest = intel->drawRegion->offset; - - /* Planemask doesn't have full support in blits. - */ - if (!ctx->Color.ColorMask[RCOMP] || - !ctx->Color.ColorMask[GCOMP] || - !ctx->Color.ColorMask[BCOMP] || - !ctx->Color.ColorMask[ACOMP]) { - if (INTEL_DEBUG & DEBUG_PIXEL) - fprintf(stderr, "%s: planemask\n", __FUNCTION__); - return GL_FALSE; - } - - /* Can't do conversions on agp reads/draws. - */ - if ( !intelIsAgpMemory( intel, pixels, size ) ) { - if (INTEL_DEBUG & DEBUG_PIXEL) - fprintf(stderr, "%s: not agp memory\n", __FUNCTION__); - return GL_FALSE; - } - - if (!check_color(ctx, type, format, unpack, pixels, size, pitch)) { - return GL_FALSE; - } - if (!check_color_per_fragment_ops(ctx)) { - return GL_FALSE; - } - - if (ctx->Pixel.ZoomX != 1.0F || - ctx->Pixel.ZoomY != -1.0F) - return GL_FALSE; - break; - - default: - return GL_FALSE; - } - - if ( intelIsAgpMemory(intel, pixels, size) ) - { - do_draw_pix( ctx, x, y, width, height, pitch, pixels, dest ); -======= - if (region->cpp == 2 && - type == GL_UNSIGNED_SHORT_5_6_5_REV && - format == GL_BGR ) { ->>>>>>> 1.6.2.18 - return GL_TRUE; - } - - fprintf(stderr, "%s: bad format for blit (cpp %d, type %s format %s)\n", - __FUNCTION__, region->cpp, - _mesa_lookup_enum_by_nr(type), - _mesa_lookup_enum_by_nr(format)); - -<<<<<<< intel_pixel.c -static void -intelDrawPixels( GLcontext *ctx, - GLint x, GLint y, GLsizei width, GLsizei height, - GLenum format, GLenum type, - const struct gl_pixelstore_attrib *unpack, - const GLvoid *pixels ) -{ - if (INTEL_DEBUG & DEBUG_PIXEL) - fprintf(stderr, "%s\n", __FUNCTION__); - - if (!intelTryDrawPixels( ctx, x, y, width, height, format, type, - unpack, pixels )) - _swrast_DrawPixels( ctx, x, y, width, height, format, type, - unpack, pixels ); -} - - - - -/** - * Implement glCopyPixels for the front color buffer (or back buffer Pixmap) - * for the color buffer. Don't support zooming, pixel transfer, etc. - * We do support copying from one window to another, ala glXMakeCurrentRead. - */ -static void -intelCopyPixels( GLcontext *ctx, - GLint srcx, GLint srcy, GLsizei width, GLsizei height, - GLint destx, GLint desty, GLenum type ) -{ -#if 0 - const XMesaContext xmesa = XMESA_CONTEXT(ctx); - const SWcontext *swrast = SWRAST_CONTEXT( ctx ); - XMesaDisplay *dpy = xmesa->xm_visual->display; - const XMesaDrawable drawBuffer = xmesa->xm_draw_buffer->buffer; - const XMesaDrawable readBuffer = xmesa->xm_read_buffer->buffer; - const XMesaGC gc = xmesa->xm_draw_buffer->gc; - - ASSERT(dpy); - ASSERT(gc); - - if (drawBuffer && /* buffer != 0 means it's a Window or Pixmap */ - readBuffer && - type == GL_COLOR && - (swrast->_RasterMask & ~CLIP_BIT) == 0 && /* no blend, z-test, etc */ - ctx->_ImageTransferState == 0 && /* no color tables, scale/bias, etc */ - ctx->Pixel.ZoomX == 1.0 && /* no zooming */ - ctx->Pixel.ZoomY == 1.0) { - /* Note: we don't do any special clipping work here. We could, - * but X will do it for us. - */ - srcy = FLIP(xmesa->xm_read_buffer, srcy) - height + 1; - desty = FLIP(xmesa->xm_draw_buffer, desty) - height + 1; - XCopyArea(dpy, readBuffer, drawBuffer, gc, - srcx, srcy, width, height, destx, desty); - } -#else - _swrast_CopyPixels(ctx, srcx, srcy, width, height, destx, desty, type ); -#endif -======= - return GL_FALSE; ->>>>>>> 1.6.2.18 -} - - -void intelInitPixelFuncs( struct dd_function_table *functions ) -{ - functions->Accum = _swrast_Accum; - functions->Bitmap = _swrast_Bitmap; - functions->CopyPixels = intelCopyPixels; - functions->ReadPixels = intelReadPixels; - functions->DrawPixels = intelDrawPixels; -} - diff --git a/src/mesa/drivers/dri/i915-tex/intel_pixel.h b/src/mesa/drivers/dri/i915-tex/intel_pixel.h deleted file mode 100644 index 3654a91b595..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_pixel.h +++ /dev/null @@ -1,64 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#ifndef INTEL_PIXEL_H -#define INTEL_PIXEL_H - -#include "mtypes.h" - -void intelInitPixelFuncs( struct dd_function_table *functions ); - -GLboolean intel_check_blit_fragment_ops( GLcontext *ctx ); - -GLboolean intel_check_meta_tex_fragment_ops( GLcontext *ctx ); - -GLboolean intel_check_blit_format( struct intel_region *region, - GLenum format, GLenum type ); - - -void intelReadPixels( GLcontext *ctx, - GLint x, GLint y, - GLsizei width, GLsizei height, - GLenum format, GLenum type, - const struct gl_pixelstore_attrib *pack, - GLvoid *pixels ); - -void intelDrawPixels( GLcontext *ctx, - GLint x, GLint y, - GLsizei width, GLsizei height, - GLenum format, - GLenum type, - const struct gl_pixelstore_attrib *unpack, - const GLvoid *pixels ); - -void intelCopyPixels( GLcontext *ctx, - GLint srcx, GLint srcy, - GLsizei width, GLsizei height, - GLint destx, GLint desty, - GLenum type ); - -#endif diff --git a/src/mesa/drivers/dri/i915-tex/intel_pixel_copy.c b/src/mesa/drivers/dri/i915-tex/intel_pixel_copy.c deleted file mode 100644 index 75cf4bdfe6d..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_pixel_copy.c +++ /dev/null @@ -1,346 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "glheader.h" -#include "enums.h" -#include "image.h" -#include "mtypes.h" -#include "macros.h" -#include "swrast/swrast.h" - -#include "intel_screen.h" -#include "intel_context.h" -#include "intel_ioctl.h" -#include "intel_batchbuffer.h" -#include "intel_buffers.h" -#include "intel_blit.h" -#include "intel_regions.h" -#include "intel_tris.h" -#include "intel_pixel.h" -#include "intel_bufmgr.h" - - -static struct intel_region *copypix_src_region( struct intel_context *intel, - GLenum type ) -{ - switch (type) { - case GL_COLOR: - return intel_readbuf_region( intel ); - case GL_DEPTH: - /* Don't think this is really possible execpt at 16bpp, when we have no stencil. - */ - if (intel->depth_region && - intel->depth_region->cpp == 2) - return intel->depth_region; - case GL_STENCIL: - /* Don't think this is really possible. - */ - break; - case GL_DEPTH_STENCIL_EXT: - /* Does it matter whether it is stencil/depth or depth/stencil? - */ - return intel->depth_region; - default: - break; - } - - return NULL; -} - - -/* Doesn't work for overlapping regions. Could do a double copy or - * just fallback. - */ -static GLboolean do_texture_copypixels( GLcontext *ctx, - GLint srcx, GLint srcy, - GLsizei width, GLsizei height, - GLint dstx, GLint dsty, - GLenum type ) -{ - struct intel_context *intel = intel_context( ctx ); - struct intel_region *dst = intel_drawbuf_region( intel ); - struct intel_region *src = copypix_src_region(intel, type); - GLenum src_format; - GLenum src_type; - - if (INTEL_DEBUG & DEBUG_PIXEL) - fprintf(stderr, "%s\n", __FUNCTION__); - - if (!src || !dst || type != GL_COLOR) - return GL_FALSE; - - /* Can't handle overlapping regions. Don't have sufficient control - * over rasterization to pull it off in-place. Punt on these for - * now. - * - * XXX: do a copy to a temporary. - */ - { - drm_clip_rect_t src; - drm_clip_rect_t dst; - drm_clip_rect_t tmp; - - src.x1 = srcx; - src.y1 = srcy; - src.x2 = srcx + width; - src.y2 = srcy + height; - - dst.x1 = dstx; - dst.y1 = dsty; - dst.x1 = dstx + width * ctx->Pixel.ZoomX; - dst.y2 = dsty + height * ctx->Pixel.ZoomY; - - - if (intel_intersect_cliprects(&tmp, &src, &dst)) { - _mesa_printf("%s: regions overlap\n", __FUNCTION__); - return GL_FALSE; - } - } - - intelFlush( &intel->ctx ); - - intel->vtbl.install_meta_state(intel); - - /* Is this true? Also will need to turn depth testing on according - * to state: - */ - intel->vtbl.meta_no_stencil_write(intel); - intel->vtbl.meta_no_depth_write(intel); - - /* Set the 3d engine to draw into the destination region: - */ - intel->vtbl.meta_draw_region(intel, dst, intel->depth_region); - - intel->vtbl.meta_import_pixel_state(intel); - - if (src->cpp == 2) { - src_format = GL_RGB; - src_type = GL_UNSIGNED_SHORT_5_6_5; - } - else { - src_format = GL_BGRA; - src_type = GL_UNSIGNED_BYTE; - } - - /* Set the frontbuffer up as a large rectangular texture. - */ - if (!intel->vtbl.meta_tex_rect_source( intel, src->buffer, 0, - src->pitch, - src->height, - src_format, - src_type )) { - intel->vtbl.leave_meta_state(intel); - return GL_FALSE; - } - - - intel->vtbl.meta_texture_blend_replace( intel ); - - - LOCK_HARDWARE( intel ); - - if (intel->driDrawable->numClipRects) - { - __DRIdrawablePrivate *dPriv = intel->driDrawable; - - - srcy = dPriv->h - srcy - height; /* convert from gl to hardware coords */ - - srcx += dPriv->x; - srcy += dPriv->y; - - /* Clip against the source region. This is the only source - * clipping we do. XXX: Just set the texcord wrap mode to clamp - * or similar. - * - */ - if (0) { - GLint orig_x = srcx; - GLint orig_y = srcy; - - if (!_mesa_clip_to_region(0, 0, src->pitch, src->height, - &srcx, &srcy, &width, &height)) - goto out; - - dstx += srcx - orig_x; - dsty += (srcy - orig_y) * ctx->Pixel.ZoomY; - } - - /* Just use the regular cliprect mechanism... Does this need to - * even hold the lock??? - */ - intel_meta_draw_quad(intel, - - dstx, - dstx + width * ctx->Pixel.ZoomX, - dPriv->h - (dsty + height * ctx->Pixel.ZoomY), - dPriv->h - (dsty), - - 0, /* XXX: what z value? */ - 0x00ff00ff, - srcx, srcx+width, - srcy, srcy+height); - - out: - intel->vtbl.leave_meta_state(intel); - intel_batchbuffer_flush(intel->batch); - } - UNLOCK_HARDWARE( intel ); - return GL_TRUE; -} - - - - - -/** - * CopyPixels with the blitter. Don't support zooming, pixel transfer, etc. - */ -static GLboolean do_blit_copypixels( GLcontext *ctx, - GLint srcx, GLint srcy, - GLsizei width, GLsizei height, - GLint dstx, GLint dsty, - GLenum type ) -{ - struct intel_context *intel = intel_context( ctx ); - struct intel_region *dst = intel_drawbuf_region( intel ); - struct intel_region *src = copypix_src_region( intel, type ); - - /* Copypixels can be more than a straight copy. Ensure all the - * extra operations are disabled: - */ - if (!intel_check_blit_fragment_ops(ctx) || - ctx->Pixel.ZoomX != 1.0F || - ctx->Pixel.ZoomY != 1.0F) - return GL_FALSE; - - if (!src || !dst) - return GL_FALSE; - - - - intelFlush( &intel->ctx ); - intel->vtbl.render_start(intel); - intel->vtbl.emit_state(intel); - - LOCK_HARDWARE( intel ); - - if (intel->driDrawable->numClipRects) - { - __DRIdrawablePrivate *dPriv = intel->driDrawable; - drm_clip_rect_t *box = dPriv->pClipRects; - drm_clip_rect_t dest_rect; - GLint nbox = dPriv->numClipRects; - GLint delta_x = 0; - GLint delta_y = 0; - GLuint i; - - - dsty = dPriv->h - dsty - height; /* convert from gl to hardware coords */ - srcy = dPriv->h - srcy - height; /* convert from gl to hardware coords */ - dstx += dPriv->x; - dsty += dPriv->y; - srcx += dPriv->x; - srcy += dPriv->y; - - /* Clip against the source region. This is the only source - * clipping we do. Dst is clipped with cliprects below. - * - * TODO: Scissor? - */ - { - delta_x = srcx - dstx; - delta_y = srcy - dsty; - - if (!_mesa_clip_to_region(0, 0, src->pitch, src->height, - &srcx, &srcy, &width, &height)) - goto out; - - dstx = srcx - delta_x; - dsty = srcy - delta_y; - } - - dest_rect.x1 = dstx; - dest_rect.y1 = dsty; - dest_rect.x2 = dstx + width; - dest_rect.y2 = dsty + height; - - /* Could do slightly more clipping: Eg, take the intersection of - * the existing set of cliprects and those cliprects translated - * by delta_x, delta_y: - * - * This code will not overwrite other windows, but will - * introduce garbage when copying from obscured window regions. - */ - for (i = 0 ; i < nbox ; i++ ) - { - drm_clip_rect_t rect; - - if (!intel_intersect_cliprects(&rect, &dest_rect, &box[i])) - continue; - - - intelEmitCopyBlit( intel, - dst->cpp, - src->pitch, src->buffer, 0, - dst->pitch, dst->buffer, 0, - rect.x1 + delta_x, - rect.y1 + delta_y, /* srcx, srcy */ - rect.x1, - rect.y1, /* dstx, dsty */ - rect.x2 - rect.x1, - rect.y2 - rect.y1 ); - } - - out: - intel_batchbuffer_flush( intel->batch ); - } - UNLOCK_HARDWARE( intel ); - return GL_TRUE; -} - - -void intelCopyPixels( GLcontext *ctx, - GLint srcx, GLint srcy, - GLsizei width, GLsizei height, - GLint destx, GLint desty, - GLenum type ) -{ - if (INTEL_DEBUG & DEBUG_PIXEL) - fprintf(stderr, "%s\n", __FUNCTION__); - - if (do_blit_copypixels( ctx, srcx, srcy, width, height, destx, desty, type)) - return; - - if (do_texture_copypixels( ctx, srcx, srcy, width, height, destx, desty, type)) - return; - - _mesa_printf("fallback to _swrast_CopyPixels\n"); - _swrast_CopyPixels( ctx, srcx, srcy, width, height, destx, desty, type); -} - - diff --git a/src/mesa/drivers/dri/i915-tex/intel_pixel_draw.c b/src/mesa/drivers/dri/i915-tex/intel_pixel_draw.c deleted file mode 100644 index 71e251c66d9..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_pixel_draw.c +++ /dev/null @@ -1,358 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 portionsalloc - * 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "glheader.h" -#include "enums.h" -#include "image.h" -#include "mtypes.h" -#include "macros.h" -#include "bufferobj.h" -#include "swrast/swrast.h" - -#include "intel_screen.h" -#include "intel_context.h" -#include "intel_ioctl.h" -#include "intel_batchbuffer.h" -#include "intel_blit.h" -#include "intel_buffers.h" -#include "intel_regions.h" -#include "intel_pixel.h" -#include "intel_buffer_objects.h" -#include "intel_tris.h" -#include "intel_bufmgr.h" - - - -static GLboolean do_texture_drawpixels( GLcontext *ctx, - GLint x, GLint y, - GLsizei width, GLsizei height, - GLenum format, GLenum type, - const struct gl_pixelstore_attrib *unpack, - const GLvoid *pixels ) -{ - struct intel_context *intel = intel_context( ctx ); - struct intel_region *dst = intel_drawbuf_region( intel ); - struct intel_buffer_object *src = intel_buffer_object(unpack->BufferObj); - GLuint rowLength = unpack->RowLength ? unpack->RowLength : width; - GLuint src_offset; - - if (INTEL_DEBUG & DEBUG_PIXEL) - fprintf(stderr, "%s\n", __FUNCTION__); - - intelFlush( &intel->ctx ); - intel->vtbl.render_start(intel); - intel->vtbl.emit_state(intel); - - if (!dst) - return GL_FALSE; - - if (src) { - if (!_mesa_validate_pbo_access(2, unpack, width, height, 1, - format, type, pixels)) { - _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawPixels"); - _mesa_printf("%s - _mesa_validate_pbo_access\n", __FUNCTION__); - return GL_TRUE; - } - } - else { - /* PBO only for now: - */ -/* _mesa_printf("%s - not PBO\n", __FUNCTION__); */ - return GL_FALSE; - } - - /* There are a couple of things we can't do yet, one of which is - * set the correct state for pixel operations when GL texturing is - * enabled. That's a pretty rare state and probably not worth the - * effort. A completely device-independent version of this may do - * more. - * - * Similarly, we make no attempt to merge metaops processing with - * an enabled fragment program, though it would certainly be - * possible. - */ - if (!intel_check_meta_tex_fragment_ops(ctx)) { - _mesa_printf("%s - bad GL fragment state for metaops texture\n", __FUNCTION__); - return GL_FALSE; - } - - intel->vtbl.install_meta_state(intel); - - - /* Is this true? Also will need to turn depth testing on according - * to state: - */ - intel->vtbl.meta_no_stencil_write(intel); - intel->vtbl.meta_no_depth_write(intel); - - /* Set the 3d engine to draw into the destination region: - */ - intel->vtbl.meta_draw_region(intel, dst, intel->depth_region); - - intel->vtbl.meta_import_pixel_state(intel); - - src_offset = (GLuint) _mesa_image_address(2, unpack, pixels, width, height, - format, type, 0, 0, 0); - - - /* Setup the pbo up as a rectangular texture, if possible. - * - * TODO: This is almost always possible if the i915 fragment - * program is adjusted to correctly swizzle the sampled colors. - * The major exception is any 24bit texture, like RGB888, for which - * there is no hardware support. - */ - if (!intel->vtbl.meta_tex_rect_source( intel, src->buffer, src_offset, - rowLength, height, - format, type )) { - intel->vtbl.leave_meta_state(intel); - return GL_FALSE; - } - - intel->vtbl.meta_texture_blend_replace( intel ); - - - LOCK_HARDWARE( intel ); - - if (intel->driDrawable->numClipRects) - { - __DRIdrawablePrivate *dPriv = intel->driDrawable; - GLint srcx, srcy; - GLint dstx, dsty; - - dstx = x; - dsty = dPriv->h - (y + height); - - srcx = 0; /* skiprows/pixels already done */ - srcy = 0; - - if (0) { - const GLint orig_x = dstx; - const GLint orig_y = dsty; - - if (!_mesa_clip_to_region(0, 0, dst->pitch, dst->height, - &dstx, &dsty, &width, &height)) - goto out; - - srcx += dstx - orig_x; - srcy += dsty - orig_y; - } - - - _mesa_printf("draw %d,%d %dx%d\n", dstx,dsty,width,height); - - /* Must use the regular cliprect mechanism in order to get the - * drawing origin set correctly. Otherwise scissor state is in - * incorrect coordinate space. Does this even need to hold the - * lock??? - */ - intel_meta_draw_quad(intel, - dstx, dstx + width * ctx->Pixel.ZoomX, - dPriv->h - (y + height * ctx->Pixel.ZoomY), - dPriv->h - (y), - - ctx->Current.RasterPos[2] * .5, - 0x00ff00ff, - srcx, srcx+width, - srcy+height, srcy); - out: - intel->vtbl.leave_meta_state(intel); - intel_batchbuffer_flush(intel->batch); - } - UNLOCK_HARDWARE( intel ); - _mesa_printf("%s - DONE\n", __FUNCTION__); - return GL_TRUE; -} - - - - - -/* Pros: - * - no waiting for idle before updating framebuffer. - * - * Cons: - * - if upload is by memcpy, this may actually be slower than fallback path. - * - uploads the whole image even if destination is clipped - * - * Need to benchmark. - * - * Given the questions about performance, implement for pbo's only. - * This path is definitely a win if the pbo is already in agp. If it - * turns out otherwise, we can add the code necessary to upload client - * data to agp space before performing the blit. (Though it may turn - * out to be better/simpler just to use the texture engine). - */ -static GLboolean do_blit_drawpixels( GLcontext *ctx, - GLint x, GLint y, - GLsizei width, GLsizei height, - GLenum format, GLenum type, - const struct gl_pixelstore_attrib *unpack, - const GLvoid *pixels ) -{ - struct intel_context *intel = intel_context(ctx); - struct intel_region *dest = intel_drawbuf_region(intel); - struct intel_buffer_object *src = intel_buffer_object(unpack->BufferObj); - GLuint src_offset; - GLuint rowLength; - GLuint fence = 0; - - if (INTEL_DEBUG & DEBUG_PIXEL) - _mesa_printf("%s\n", __FUNCTION__); - - - if (!dest) { - _mesa_printf("%s - no dest\n", __FUNCTION__); - return GL_FALSE; - } - - if (src) { - /* This validation should be done by core mesa: - */ - if (!_mesa_validate_pbo_access(2, unpack, width, height, 1, - format, type, pixels)) { - _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawPixels"); - _mesa_printf("%s - _mesa_validate_pbo_access\n", __FUNCTION__); - - return GL_TRUE; - } - } - else { - /* PBO only for now: - */ - _mesa_printf("%s - not PBO\n", __FUNCTION__); - return GL_FALSE; - } - - if (!intel_check_blit_format(dest, format, type)) { - _mesa_printf("%s - bad format for blit\n", __FUNCTION__); - return GL_FALSE; - } - - if (!intel_check_meta_tex_fragment_ops(ctx)) { - _mesa_printf("%s - bad GL fragment state for meta tex\n", __FUNCTION__); - return GL_FALSE; - } - - if (ctx->Pixel.ZoomX != 1.0F) { - _mesa_printf("%s - bad PixelZoomX for blit\n", __FUNCTION__); - return GL_FALSE; - } - - - if (unpack->RowLength > 0) - rowLength = unpack->RowLength; - else - rowLength = width; - - if (ctx->Pixel.ZoomY == -1.0F) { - _mesa_printf("%s - bad PixelZoomY for blit\n", __FUNCTION__); - return GL_FALSE; /* later */ - y -= height; - } - else if (ctx->Pixel.ZoomY == 1.0F) { - rowLength = -rowLength; - } - else { - _mesa_printf("%s - bad PixelZoomY for blit\n", __FUNCTION__); - return GL_FALSE; - } - - src_offset = (GLuint) _mesa_image_address(2, unpack, pixels, width, height, - format, type, 0, 0, 0); - - intelFlush( &intel->ctx ); - LOCK_HARDWARE( intel ); - - if (intel->driDrawable->numClipRects) - { - __DRIdrawablePrivate *dPriv = intel->driDrawable; - int nbox = dPriv->numClipRects; - drm_clip_rect_t *box = dPriv->pClipRects; - drm_clip_rect_t rect; - drm_clip_rect_t dest_rect; - int i; - - dest_rect.x1 = dPriv->x + x; - dest_rect.y1 = dPriv->y + dPriv->h - (y + height); - dest_rect.x2 = dest_rect.x1 + width; - dest_rect.y2 = dest_rect.y1 + height; - - for (i = 0 ; i < nbox ; i++ ) - { - if (!intel_intersect_cliprects(&rect, &dest_rect, &box[i])) - continue; - - intelEmitCopyBlit( intel, - dest->cpp, - rowLength, - intel_bufferobj_buffer(src), src_offset, - dest->pitch, - dest->buffer, 0, - rect.x1 - dest_rect.x1, - rect.y2 - dest_rect.y2, - rect.x1, - rect.y1, - rect.x2 - rect.x1, - rect.y2 - rect.y1 ); - } - fence = intel_batchbuffer_flush( intel->batch ); - } - UNLOCK_HARDWARE( intel ); - - if (intel->driDrawable->numClipRects) - bmFinishFence(intel->bm, fence); - - _mesa_printf("%s - DONE\n", __FUNCTION__); - - return GL_TRUE; -} - - - -void intelDrawPixels( GLcontext *ctx, - GLint x, GLint y, - GLsizei width, GLsizei height, - GLenum format, - GLenum type, - const struct gl_pixelstore_attrib *unpack, - const GLvoid *pixels ) -{ - if (do_blit_drawpixels( ctx, x, y, width, height, format, type, - unpack, pixels )) - return; - - if (do_texture_drawpixels( ctx, x, y, width, height, format, type, - unpack, pixels )) - return; - - - _mesa_printf("%s: fallback to swrast\n", __FUNCTION__); - - _swrast_DrawPixels( ctx, x, y, width, height, format, type, - unpack, pixels ); -} - diff --git a/src/mesa/drivers/dri/i915-tex/intel_pixel_read.c b/src/mesa/drivers/dri/i915-tex/intel_pixel_read.c deleted file mode 100644 index 68dd6ea376e..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_pixel_read.c +++ /dev/null @@ -1,315 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "glheader.h" -#include "enums.h" -#include "mtypes.h" -#include "macros.h" -#include "image.h" -#include "bufferobj.h" -#include "swrast/swrast.h" - -#include "intel_screen.h" -#include "intel_context.h" -#include "intel_ioctl.h" -#include "intel_batchbuffer.h" -#include "intel_blit.h" -#include "intel_buffers.h" -#include "intel_regions.h" -#include "intel_pixel.h" -#include "intel_buffer_objects.h" - -#include "intel_bufmgr.h" - -/* For many applications, the new ability to pull the source buffers - * back out of the GTT and then do the packing/conversion operations - * in software will be as much of an improvement as trying to get the - * blitter and/or texture engine to do the work. - * - * This step is gated on private backbuffers. - * - * Obviously the frontbuffer can't be pulled back, so that is either - * an argument for blit/texture readpixels, or for blitting to a - * temporary and then pulling that back. - * - * When the destination is a pbo, however, it's not clear if it is - * ever going to be pulled to main memory (though the access param - * will be a good hint). So it sounds like we do want to be able to - * choose between blit/texture implementation on the gpu and pullback - * and cpu-based copying. - * - * Unless you can magically turn client memory into a PBO for the - * duration of this call, there will be a cpu-based copying step in - * any case. - */ - - -static GLboolean -do_texture_readpixels( GLcontext *ctx, - GLint x, GLint y, GLsizei width, GLsizei height, - GLenum format, GLenum type, - const struct gl_pixelstore_attrib *pack, - struct intel_region *dest_region ) -{ -#if 0 - struct intel_context *intel = intel_context(ctx); - intelScreenPrivate *screen = intel->intelScreen; - GLint pitch = pack->RowLength ? pack->RowLength : width; - __DRIdrawablePrivate *dPriv = intel->driDrawable; - int textureFormat; - GLenum glTextureFormat; - int destFormat, depthFormat, destPitch; - drm_clip_rect_t tmp; - - if (INTEL_DEBUG & DEBUG_PIXEL) - fprintf(stderr, "%s\n", __FUNCTION__); - - - if ( ctx->_ImageTransferState || - pack->SwapBytes || - pack->LsbFirst || - !pack->Invert) { - fprintf(stderr, "%s: check_color failed\n", __FUNCTION__); - return GL_FALSE; - } - - intel->vtbl.meta_texrect_source(intel, intel_readbuf_region(intel)); - - if (!intel->vtbl.meta_render_dest(intel, - dest_region, - type, format)) - { - fprintf(stderr, "%s: couldn't set dest %s/%s\n", - __FUNCTION__, - _mesa_lookup_enum_by_nr(type), - _mesa_lookup_enum_by_nr(format)); - return GL_FALSE; - } - - LOCK_HARDWARE( intel ); - - if (intel->driDrawable->numClipRects) { - intel->vtbl.install_meta_state(intel); - intel->vtbl.meta_no_depth_write(intel); - intel->vtbl.meta_no_stencil_write(intel); - - if (!driClipRectToFramebuffer(ctx->ReadBuffer, &x, &y, &width, &height)) { - UNLOCK_HARDWARE( intel ); - SET_STATE(i830, state); - fprintf(stderr, "%s: cliprect failed\n", __FUNCTION__); - return GL_TRUE; - } - - y = dPriv->h - y - height; - x += dPriv->x; - y += dPriv->y; - - - /* Set the frontbuffer up as a large rectangular texture. - */ - intel->vtbl.meta_tex_rect_source( intel, - src_region, - textureFormat ); - - - intel->vtbl.meta_texture_blend_replace( i830, glTextureFormat ); - - - /* Set the 3d engine to draw into the destination region: - */ - - intel->vtbl.meta_draw_region(intel, dest_region); - intel->vtbl.meta_draw_format(intel, destFormat, depthFormat ); /* ?? */ - - - /* Draw a single quad, no cliprects: - */ - intel->vtbl.meta_disable_cliprects(intel); - - intel->vtbl.draw_quad(intel, - 0, width, 0, height, - 0x00ff00ff, - x, x+width, - y, y+height ); - - intel->vtbl.leave_meta_state(intel); - } - UNLOCK_HARDWARE( intel ); - - intel_region_wait_fence( ctx, dest_region ); /* required by GL */ - return GL_TRUE; -#endif - - return GL_FALSE; -} - - - - -static GLboolean do_blit_readpixels( GLcontext *ctx, - GLint x, GLint y, GLsizei width, GLsizei height, - GLenum format, GLenum type, - const struct gl_pixelstore_attrib *pack, - GLvoid *pixels ) -{ - struct intel_context *intel = intel_context(ctx); - struct intel_region *src = intel_readbuf_region(intel); - struct intel_buffer_object *dst = intel_buffer_object(pack->BufferObj); - GLuint dst_offset; - GLuint rowLength; - GLuint fence = 0; - - if (INTEL_DEBUG & DEBUG_PIXEL) - _mesa_printf("%s\n", __FUNCTION__); - - if (!src) - return GL_FALSE; - - if (dst) { - /* XXX This validation should be done by core mesa: - */ - if (!_mesa_validate_pbo_access(2, pack, width, height, 1, - format, type, pixels)) { - _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawPixels"); - _mesa_printf("%s - _mesa_validate_pbo_access\n", __FUNCTION__); - - return GL_TRUE; - } - } - else { - /* PBO only for now: - */ - _mesa_printf("%s - not PBO\n", __FUNCTION__); - return GL_FALSE; - } - - - if (ctx->_ImageTransferState || - !intel_check_blit_format(src, format, type)) { - _mesa_printf("%s - bad format for blit\n", __FUNCTION__); - return GL_FALSE; - } - - if (pack->Alignment != 1 || pack->SwapBytes || pack->LsbFirst) { - _mesa_printf("%s: bad packing params\n", __FUNCTION__); - return GL_FALSE; - } - - if (pack->RowLength > 0) - rowLength = pack->RowLength; - else - rowLength = width; - - if (pack->Invert) { - _mesa_printf("%s: MESA_PACK_INVERT not done yet\n", __FUNCTION__); - return GL_FALSE; - } - else { - rowLength = -rowLength; - } - - /* XXX 64-bit cast? */ - dst_offset = (GLuint) _mesa_image_address(2, pack, pixels, width, height, - format, type, 0, 0, 0); - - - /* Although the blits go on the command buffer, need to do this and - * fire with lock held to guarentee cliprects are correct. - */ - intelFlush( &intel->ctx ); - LOCK_HARDWARE( intel ); - - if (intel->driDrawable->numClipRects) - { - __DRIdrawablePrivate *dPriv = intel->driDrawable; - int nbox = dPriv->numClipRects; - drm_clip_rect_t *box = dPriv->pClipRects; - drm_clip_rect_t rect; - drm_clip_rect_t src_rect; - int i; - - src_rect.x1 = dPriv->x + x; - src_rect.y1 = dPriv->y + dPriv->h - (y + height); - src_rect.x2 = src_rect.x1 + width; - src_rect.y2 = src_rect.y1 + height; - - - - for (i = 0 ; i < nbox ; i++) - { - if (!intel_intersect_cliprects(&rect, &src_rect, &box[i])) - continue; - - intelEmitCopyBlit( intel, - src->cpp, - src->pitch, src->buffer, 0, - rowLength, - intel_bufferobj_buffer(dst), dst_offset, - rect.x1, - rect.y1, - rect.x1 - src_rect.x1, - rect.y2 - src_rect.y2, - rect.x2 - rect.x1, - rect.y2 - rect.y1 ); - } - - fence = intel_batchbuffer_flush(intel->batch); - } - UNLOCK_HARDWARE( intel ); - - if (intel->driDrawable->numClipRects) - bmFinishFence(intel->bm, fence); - - if (INTEL_DEBUG & DEBUG_PIXEL) - _mesa_printf("%s - DONE\n", __FUNCTION__); - - return GL_TRUE; -} - -void -intelReadPixels( GLcontext *ctx, - GLint x, GLint y, GLsizei width, GLsizei height, - GLenum format, GLenum type, - const struct gl_pixelstore_attrib *pack, - GLvoid *pixels ) -{ - if (INTEL_DEBUG & DEBUG_PIXEL) - fprintf(stderr, "%s\n", __FUNCTION__); - - intelFlush( ctx ); - - if (do_blit_readpixels(ctx, x, y, width, height, format, type, pack, pixels)) - return; - - if (do_texture_readpixels(ctx, x, y, width, height, format, type, pack, pixels)) - return; - - _mesa_printf("%s: fallback to swrast\n", __FUNCTION__); - - _swrast_ReadPixels( ctx, x, y, width, height, format, type, pack, pixels); -} - diff --git a/src/mesa/drivers/dri/i915-tex/intel_reg.h b/src/mesa/drivers/dri/i915-tex/intel_reg.h deleted file mode 100644 index 1ec153266c7..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_reg.h +++ /dev/null @@ -1,84 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - - -#ifndef _INTEL_REG_H_ -#define _INTEL_REG_H_ - - - -#define CMD_3D (0x3<<29) - - -#define _3DPRIMITIVE ((0x3<<29)|(0x1f<<24)) -#define PRIM_INDIRECT (1<<23) -#define PRIM_INLINE (0<<23) -#define PRIM_INDIRECT_SEQUENTIAL (0<<17) -#define PRIM_INDIRECT_ELTS (1<<17) - -#define PRIM3D_TRILIST (0x0<<18) -#define PRIM3D_TRISTRIP (0x1<<18) -#define PRIM3D_TRISTRIP_RVRSE (0x2<<18) -#define PRIM3D_TRIFAN (0x3<<18) -#define PRIM3D_POLY (0x4<<18) -#define PRIM3D_LINELIST (0x5<<18) -#define PRIM3D_LINESTRIP (0x6<<18) -#define PRIM3D_RECTLIST (0x7<<18) -#define PRIM3D_POINTLIST (0x8<<18) -#define PRIM3D_DIB (0x9<<18) -#define PRIM3D_MASK (0x1f<<18) - -#define I915PACKCOLOR4444(r,g,b,a) \ - ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4)) - -#define I915PACKCOLOR1555(r,g,b,a) \ - ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \ - ((a) ? 0x8000 : 0)) - -#define I915PACKCOLOR565(r,g,b) \ - ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3)) - -#define I915PACKCOLOR8888(r,g,b,a) \ - ((a<<24) | (r<<16) | (g<<8) | b) - - - - -#define BR00_BITBLT_CLIENT 0x40000000 -#define BR00_OP_COLOR_BLT 0x10000000 -#define BR00_OP_SRC_COPY_BLT 0x10C00000 -#define BR13_SOLID_PATTERN 0x80000000 - -#define XY_COLOR_BLT_CMD ((2<<29)|(0x50<<22)|0x4) -#define XY_COLOR_BLT_WRITE_ALPHA (1<<21) -#define XY_COLOR_BLT_WRITE_RGB (1<<20) - -#define XY_SRC_COPY_BLT_CMD ((2<<29)|(0x53<<22)|6) -#define XY_SRC_COPY_BLT_WRITE_ALPHA (1<<21) -#define XY_SRC_COPY_BLT_WRITE_RGB (1<<20) - -#endif diff --git a/src/mesa/drivers/dri/i915-tex/intel_regions.c b/src/mesa/drivers/dri/i915-tex/intel_regions.c deleted file mode 100644 index f2932fd0047..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_regions.c +++ /dev/null @@ -1,264 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -/* Provide additional functionality on top of bufmgr buffers: - * - 2d semantics and blit operations - * - refcounting of buffers for multiple images in a buffer. - * - refcounting of buffer mappings. - * - some logic for moving the buffers to the best memory pools for - * given operations. - * - * Most of this is to make it easier to implement the fixed-layout - * mipmap tree required by intel hardware in the face of GL's - * programming interface where each image can be specifed in random - * order and it isn't clear what layout the tree should have until the - * last moment. - */ - -#include "intel_context.h" -#include "intel_regions.h" -#include "intel_blit.h" -#include "intel_bufmgr.h" - -/* XXX: Thread safety? - */ -GLubyte *intel_region_map(struct intel_context *intel, struct intel_region *region) -{ - DBG("%s\n", __FUNCTION__); - if (!region->map_refcount++) { - region->map = bmMapBuffer(intel->bm, region->buffer, 0); - } - - return region->map; -} - -void intel_region_unmap(struct intel_context *intel, - struct intel_region *region) -{ - DBG("%s\n", __FUNCTION__); - if (!--region->map_refcount) { - bmUnmapBuffer(intel->bm, region->buffer); - region->map = NULL; - } -} - -struct intel_region *intel_region_alloc( struct intel_context *intel, - GLuint cpp, - GLuint pitch, - GLuint height ) -{ - struct intel_region *region = calloc(sizeof(*region), 1); - - DBG("%s\n", __FUNCTION__); - - region->cpp = cpp; - region->pitch = pitch; - region->height = height; /* needed? */ - region->refcount = 1; - - bmGenBuffers(intel->bm, 1, ®ion->buffer, 0); - bmBufferData(intel->bm, region->buffer, pitch * cpp * height, NULL, 0); - - return region; -} - -void intel_region_reference( struct intel_region **dst, - struct intel_region *src) -{ - assert(*dst == NULL); - if (src) { - src->refcount++; - *dst = src; - } -} - -void intel_region_release( struct intel_context *intel, - struct intel_region **region ) -{ - if (!*region) - return; - - DBG("%s %d\n", __FUNCTION__, (*region)->refcount-1); - - ASSERT((*region)->refcount > 0); - (*region)->refcount--; - - if ((*region)->refcount == 0) { - assert((*region)->map_refcount == 0); - bmDeleteBuffers(intel->bm, 1, &(*region)->buffer); - free(*region); - } - *region = NULL; -} - - -struct intel_region *intel_region_create_static( struct intel_context *intel, - GLuint mem_type, - GLuint offset, - void *virtual, - GLuint cpp, - GLuint pitch, - GLuint height ) -{ - struct intel_region *region = calloc(sizeof(*region), 1); - DBG("%s\n", __FUNCTION__); - - region->cpp = cpp; - region->pitch = pitch; - region->height = height; /* needed? */ - region->refcount = 1; - - /* - * We use a "shared" buffer type to indicate buffers created and - * shared by others. - */ - - bmGenBuffers(intel->bm, 1, ®ion->buffer, DRM_MM_TT | DRM_MM_SHARED); - bmSetShared(intel->bm, region->buffer, DRM_MM_TT, offset, virtual); - - return region; -} - - - -/* - * XXX Move this into core Mesa? - */ -static void _mesa_copy_rect( GLubyte *dst, - GLuint cpp, - GLuint dst_pitch, - GLuint dst_x, - GLuint dst_y, - GLuint width, - GLuint height, - GLubyte *src, - GLuint src_pitch, - GLuint src_x, - GLuint src_y ) -{ - GLuint i; - - dst_pitch *= cpp; - src_pitch *= cpp; - dst += dst_x * cpp; - src += src_x * cpp; - dst += dst_y * dst_pitch; - src += src_y * dst_pitch; - width *= cpp; - - if (width == dst_pitch && - width == src_pitch) - memcpy(dst, src, height * width); - else { - for (i = 0; i < height; i++) { - memcpy(dst, src, width); - dst += dst_pitch; - src += src_pitch; - } - } -} - - -/* Upload data to a rectangular sub-region. Lots of choices how to do this: - * - * - memcpy by span to current destination - * - upload data as new buffer and blit - * - * Currently always memcpy. - */ -void intel_region_data(struct intel_context *intel, - struct intel_region *dst, - GLuint dst_offset, - GLuint dstx, GLuint dsty, - void *src, GLuint src_pitch, - GLuint srcx, GLuint srcy, - GLuint width, GLuint height) -{ - DBG("%s\n", __FUNCTION__); - - LOCK_HARDWARE(intel); - - _mesa_copy_rect(intel_region_map(intel, dst) + dst_offset, - dst->cpp, - dst->pitch, - dstx, dsty, - width, height, - src, - src_pitch, - srcx, srcy); - - intel_region_unmap(intel, dst); - - UNLOCK_HARDWARE(intel); - -} - -/* Copy rectangular sub-regions. Need better logic about when to - * push buffers into AGP - will currently do so whenever possible. - */ -void intel_region_copy( struct intel_context *intel, - struct intel_region *dst, - GLuint dst_offset, - GLuint dstx, GLuint dsty, - struct intel_region *src, - GLuint src_offset, - GLuint srcx, GLuint srcy, - GLuint width, GLuint height ) -{ - DBG("%s\n", __FUNCTION__); - - assert(src->cpp == dst->cpp); - - intelEmitCopyBlit(intel, - dst->cpp, - src->pitch, src->buffer, src_offset, - dst->pitch, dst->buffer, dst_offset, - srcx, srcy, - dstx, dsty, - width, height); -} - -/* Fill a rectangular sub-region. Need better logic about when to - * push buffers into AGP - will currently do so whenever possible. - */ -void intel_region_fill( struct intel_context *intel, - struct intel_region *dst, - GLuint dst_offset, - GLuint dstx, GLuint dsty, - GLuint width, GLuint height, - GLuint color ) -{ - DBG("%s\n", __FUNCTION__); - - intelEmitFillBlit(intel, - dst->cpp, - dst->pitch, dst->buffer, dst_offset, - dstx, dsty, - width, height, - color ); -} - diff --git a/src/mesa/drivers/dri/i915-tex/intel_regions.h b/src/mesa/drivers/dri/i915-tex/intel_regions.h deleted file mode 100644 index c8173ae67fb..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_regions.h +++ /dev/null @@ -1,119 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#ifndef INTEL_REGIONS_H -#define INTEL_REGIONS_H - -#include "mtypes.h" -#include "intel_bufmgr.h" /* for DBG! */ -struct intel_context; - -/** - * A layer on top of the bufmgr buffers that adds a few useful things: - * - * - Refcounting for local buffer references. - * - Refcounting for buffer maps - * - Buffer dimensions - pitch and height. - * - Blitter commands for copying 2D regions between buffers. (really???) - */ -struct intel_region { - GLuint buffer; /**< buffer manager's buffer ID */ - GLuint refcount; /**< Reference count for region */ - GLuint cpp; /**< bytes per pixel */ - GLuint pitch; /**< in pixels */ - GLuint height; /**< in pixels */ - GLubyte *map; /**< only non-NULL when region is actually mapped */ - GLuint map_refcount; /**< Reference count for mapping */ - - GLuint draw_offset; /**< Offset of drawing address within the region */ -}; - - -/* Allocate a refcounted region. Pointers to regions should only be - * copied by calling intel_reference_region(). - */ -struct intel_region *intel_region_alloc( struct intel_context *intel, - GLuint cpp, - GLuint pitch, - GLuint height ); - -void intel_region_reference( struct intel_region **dst, - struct intel_region *src ); - -void intel_region_release(struct intel_context *intel, - struct intel_region **ib ); - - -struct intel_region *intel_region_create_static( struct intel_context *intel, - GLuint mem_type, - GLuint offset, - void *virtual, - GLuint cpp, - GLuint pitch, - GLuint height ); - -/* Map/unmap regions. This is refcounted also: - */ -GLubyte *intel_region_map(struct intel_context *intel, - struct intel_region *ib); - -void intel_region_unmap(struct intel_context *intel, - struct intel_region *ib); - - -/* Upload data to a rectangular sub-region - */ -void intel_region_data(struct intel_context *intel, - struct intel_region *dest, - GLuint dest_offset, - GLuint destx, GLuint desty, - void *src, GLuint src_stride, - GLuint srcx, GLuint srcy, - GLuint width, GLuint height); - -/* Copy rectangular sub-regions - */ -void intel_region_copy( struct intel_context *intel, - struct intel_region *dest, - GLuint dest_offset, - GLuint destx, GLuint desty, - struct intel_region *src, - GLuint src_offset, - GLuint srcx, GLuint srcy, - GLuint width, GLuint height ); - -/* Fill a rectangular sub-region - */ -void intel_region_fill( struct intel_context *intel, - struct intel_region *dest, - GLuint dest_offset, - GLuint destx, GLuint desty, - GLuint width, GLuint height, - GLuint color ); - - -#endif diff --git a/src/mesa/drivers/dri/i915-tex/intel_render.c b/src/mesa/drivers/dri/i915-tex/intel_render.c deleted file mode 100644 index 075b453848b..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_render.c +++ /dev/null @@ -1,248 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -/* - * Render unclipped vertex buffers by emitting vertices directly to - * dma buffers. Use strip/fan hardware acceleration where possible. - * - */ -#include "glheader.h" -#include "context.h" -#include "macros.h" -#include "imports.h" -#include "mtypes.h" -#include "enums.h" - -#include "tnl/t_context.h" -#include "tnl/t_vertex.h" - -#include "intel_screen.h" -#include "intel_context.h" -#include "intel_tris.h" -#include "intel_batchbuffer.h" -#include "intel_reg.h" - -/* - * Render unclipped vertex buffers by emitting vertices directly to - * dma buffers. Use strip/fan hardware primitives where possible. - * Try to simulate missing primitives with indexed vertices. - */ -#define HAVE_POINTS 0 /* Has it, but can't use because subpixel has to - * be adjusted for points on the INTEL/I845G - */ -#define HAVE_LINES 1 -#define HAVE_LINE_STRIPS 1 -#define HAVE_TRIANGLES 1 -#define HAVE_TRI_STRIPS 1 -#define HAVE_TRI_STRIP_1 0 /* has it, template can't use it yet */ -#define HAVE_TRI_FANS 1 -#define HAVE_POLYGONS 1 -#define HAVE_QUADS 0 -#define HAVE_QUAD_STRIPS 0 - -#define HAVE_ELTS 0 - -static GLuint hw_prim[GL_POLYGON+1] = { - 0, - PRIM3D_LINELIST, - PRIM3D_LINESTRIP, - PRIM3D_LINESTRIP, - PRIM3D_TRILIST, - PRIM3D_TRISTRIP, - PRIM3D_TRIFAN, - 0, - 0, - PRIM3D_POLY -}; - -static const GLenum reduced_prim[GL_POLYGON+1] = { - GL_POINTS, - GL_LINES, - GL_LINES, - GL_LINES, - GL_TRIANGLES, - GL_TRIANGLES, - GL_TRIANGLES, - GL_TRIANGLES, - GL_TRIANGLES, - GL_TRIANGLES -}; - -static const int scale_prim[GL_POLYGON+1] = { - 0, /* fallback case */ - 1, - 2, - 2, - 1, - 3, - 3, - 0, /* fallback case */ - 0, /* fallback case */ - 3 -}; - - -static void intelDmaPrimitive( struct intel_context *intel, GLenum prim ) -{ - if (0) fprintf(stderr, "%s %s\n", __FUNCTION__, _mesa_lookup_enum_by_nr(prim)); - INTEL_FIREVERTICES(intel); - intel->vtbl.reduced_primitive_state( intel, reduced_prim[prim] ); - intelStartInlinePrimitive( intel, hw_prim[prim], INTEL_BATCH_CLIPRECTS ); -} - - -#define LOCAL_VARS struct intel_context *intel = intel_context(ctx) -#define INIT( prim ) \ -do { \ - intelDmaPrimitive( intel, prim ); \ -} while (0) - -#define FLUSH() \ -do { \ - if (intel->prim.flush) \ - intel->prim.flush(intel); \ -} while (0) - -#define GET_SUBSEQUENT_VB_MAX_VERTS() \ - ((BATCH_SZ - 1500) / (intel->vertex_size*4)) -#define GET_CURRENT_VB_MAX_VERTS() GET_SUBSEQUENT_VB_MAX_VERTS() - -#define ALLOC_VERTS( nr ) \ - intelExtendInlinePrimitive( intel, (nr) * intel->vertex_size ) - -#define EMIT_VERTS( ctx, j, nr, buf ) \ - _tnl_emit_vertices_to_buffer(ctx, j, (j)+(nr), buf ) - -#define TAG(x) intel_##x -#include "tnl_dd/t_dd_dmatmp.h" - - -/**********************************************************************/ -/* Render pipeline stage */ -/**********************************************************************/ - -/* Heuristic to choose between the two render paths: - */ -static GLboolean choose_render( struct intel_context *intel, - struct vertex_buffer *VB ) -{ - int vertsz = intel->vertex_size; - int cost_render = 0; - int cost_fallback = 0; - int nr_prims = 0; - int nr_rprims = 0; - int nr_rverts = 0; - int rprim = intel->reduced_primitive; - int i = 0; - - for (i = 0 ; i < VB->PrimitiveCount ; i++) { - GLuint prim = VB->Primitive[i].mode; - GLuint length = VB->Primitive[i].count; - - if (!length) - continue; - - nr_prims++; - nr_rverts += length * scale_prim[prim & PRIM_MODE_MASK]; - - if (reduced_prim[prim & PRIM_MODE_MASK] != rprim) { - nr_rprims++; - rprim = reduced_prim[prim & PRIM_MODE_MASK]; - } - } - - /* One point for each generated primitive: - */ - cost_render = nr_prims; - cost_fallback = nr_rprims; - - /* One point for every 1024 dwords (4k) of dma: - */ - cost_render += (vertsz * i) / 1024; - cost_fallback += (vertsz * nr_rverts) / 1024; - - if (0) - fprintf(stderr, "cost render: %d fallback: %d\n", - cost_render, cost_fallback); - - if (cost_render > cost_fallback) - return GL_FALSE; - - return GL_TRUE; -} - - -static GLboolean intel_run_render( GLcontext *ctx, - struct tnl_pipeline_stage *stage ) -{ - struct intel_context *intel = intel_context(ctx); - TNLcontext *tnl = TNL_CONTEXT(ctx); - struct vertex_buffer *VB = &tnl->vb; - GLuint i; - - /* Don't handle clipping or indexed vertices. - */ - if (intel->RenderIndex != 0 || - !intel_validate_render( ctx, VB ) || - !choose_render( intel, VB )) { - return GL_TRUE; - } - - tnl->clipspace.new_inputs |= VERT_BIT_POS; - - tnl->Driver.Render.Start( ctx ); - - for (i = 0 ; i < VB->PrimitiveCount ; i++) - { - GLuint prim = VB->Primitive[i].mode; - GLuint start = VB->Primitive[i].start; - GLuint length = VB->Primitive[i].count; - - if (!length) - continue; - - intel_render_tab_verts[prim & PRIM_MODE_MASK]( ctx, start, start + length, - prim ); - } - - tnl->Driver.Render.Finish( ctx ); - - if (intel->prim.flush) - intel->prim.flush(intel); - - return GL_FALSE; /* finished the pipe */ -} - -const struct tnl_pipeline_stage _intel_render_stage = -{ - "intel render", - NULL, - NULL, - NULL, - NULL, - intel_run_render /* run */ -}; diff --git a/src/mesa/drivers/dri/i915-tex/intel_rotate.c b/src/mesa/drivers/dri/i915-tex/intel_rotate.c deleted file mode 100644 index a77640ee54d..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_rotate.c +++ /dev/null @@ -1,221 +0,0 @@ - -/** - * Routines for simple 2D->2D transformations for rotated, flipped screens. - * - * XXX This code is not intel-specific. Move it into a common/utility - * someday. - */ - -#include "intel_rotate.h" - -#define MIN2(A, B) ( ((A) < (B)) ? (A) : (B) ) - -#define ABS(A) ( ((A) < 0) ? -(A) : (A) ) - - -void -matrix23Set(struct matrix23 *m, - int m00, int m01, int m02, - int m10, int m11, int m12) -{ - m->m00 = m00; m->m01 = m01; m->m02 = m02; - m->m10 = m10; m->m11 = m11; m->m12 = m12; -} - - -/* - * Transform (x,y) coordinate by the given matrix. - */ -void -matrix23TransformCoordf(const struct matrix23 *m, float *x, float *y) -{ - const float x0 = *x; - const float y0 = *y; - - *x = m->m00 * x0 + m->m01 * y0 + m->m02; - *y = m->m10 * x0 + m->m11 * y0 + m->m12; -} - - -void -matrix23TransformCoordi(const struct matrix23 *m, int *x, int *y) -{ - const int x0 = *x; - const int y0 = *y; - - *x = m->m00 * x0 + m->m01 * y0 + m->m02; - *y = m->m10 * x0 + m->m11 * y0 + m->m12; -} - - -/* - * Transform a width and height by the given matrix. - * XXX this could be optimized quite a bit. - */ -void -matrix23TransformDistance(const struct matrix23 *m, int *xDist, int *yDist) -{ - int x0 = 0, y0 = 0; - int x1 = *xDist, y1 = 0; - int x2 = 0, y2 = *yDist; - matrix23TransformCoordi(m, &x0, &y0); - matrix23TransformCoordi(m, &x1, &y1); - matrix23TransformCoordi(m, &x2, &y2); - - *xDist = (x1 - x0) + (x2 - x0); - *yDist = (y1 - y0) + (y2 - y0); - - if (*xDist < 0) - *xDist = -*xDist; - if (*yDist < 0) - *yDist = -*yDist; -} - - -/** - * Transform the rect defined by (x, y, w, h) by m. - */ -void -matrix23TransformRect(const struct matrix23 *m, int *x, int *y, int *w, int *h) -{ - int x0 = *x, y0 = *y; - int x1 = *x + *w, y1 = *y; - int x2 = *x + *w, y2 = *y + *h; - int x3 = *x, y3 = *y + *h; - matrix23TransformCoordi(m, &x0, &y0); - matrix23TransformCoordi(m, &x1, &y1); - matrix23TransformCoordi(m, &x2, &y2); - matrix23TransformCoordi(m, &x3, &y3); - *w = ABS(x1 - x0) + ABS(x2 - x1); - /**w = ABS(*w);*/ - *h = ABS(y1 - y0) + ABS(y2 - y1); - /**h = ABS(*h);*/ - *x = MIN2(x0, x1); - *x = MIN2(*x, x2); - *y = MIN2(y0, y1); - *y = MIN2(*y, y2); -} - - -/* - * Make rotation matrix for width X height screen. - */ -void -matrix23Rotate(struct matrix23 *m, int width, int height, int angle) -{ - switch (angle) { - case 0: - matrix23Set(m, 1, 0, 0, 0, 1, 0); - break; - case 90: - matrix23Set(m, 0, 1, 0, -1, 0, width); - break; - case 180: - matrix23Set(m, -1, 0, width, 0, -1, height); - break; - case 270: - matrix23Set(m, 0, -1, height, 1, 0, 0); - break; - default: - /*abort()*/; - } -} - - -/* - * Make flip/reflection matrix for width X height screen. - */ -void -matrix23Flip(struct matrix23 *m, int width, int height, int xflip, int yflip) -{ - if (xflip) { - m->m00 = -1; m->m01 = 0; m->m02 = width - 1; - } - else { - m->m00 = 1; m->m01 = 0; m->m02 = 0; - } - if (yflip) { - m->m10 = 0; m->m11 = -1; m->m12 = height - 1; - } - else { - m->m10 = 0; m->m11 = 1; m->m12 = 0; - } -} - - -/* - * result = a * b - */ -void -matrix23Multiply(struct matrix23 *result, - const struct matrix23 *a, const struct matrix23 *b) -{ - result->m00 = a->m00 * b->m00 + a->m01 * b->m10; - result->m01 = a->m00 * b->m01 + a->m01 * b->m11; - result->m02 = a->m00 * b->m02 + a->m01 * b->m12 + a->m02; - - result->m10 = a->m10 * b->m00 + a->m11 * b->m10; - result->m11 = a->m10 * b->m01 + a->m11 * b->m11; - result->m12 = a->m10 * b->m02 + a->m11 * b->m12 + a->m12; -} - - -#if 000 - -#include <stdio.h> - -int -main(int argc, char *argv[]) -{ - int width = 500, height = 400; - int rot; - int fx = 0, fy = 0; /* flip x and/or y ? */ - int coords[4][2]; - - /* four corner coords to test with */ - coords[0][0] = 0; coords[0][1] = 0; - coords[1][0] = width-1; coords[1][1] = 0; - coords[2][0] = width-1; coords[2][1] = height-1; - coords[3][0] = 0; coords[3][1] = height-1; - - - for (rot = 0; rot < 360; rot += 90) { - struct matrix23 rotate, flip, m; - int i; - - printf("Rot %d, xFlip %d, yFlip %d:\n", rot, fx, fy); - - /* make transformation matrix 'm' */ - matrix23Rotate(&rotate, width, height, rot); - matrix23Flip(&flip, width, height, fx, fy); - matrix23Multiply(&m, &rotate, &flip); - - /* xform four coords */ - for (i = 0; i < 4; i++) { - int x = coords[i][0]; - int y = coords[i][1]; - matrix23TransformCoordi(&m, &x, &y); - printf(" %d, %d -> %d %d\n", coords[i][0], coords[i][1], x, y); - } - - /* xform width, height */ - { - int x = width; - int y = height; - matrix23TransformDistance(&m, &x, &y); - printf(" %d x %d -> %d x %d\n", width, height, x, y); - } - - /* xform rect */ - { - int x = 50, y = 10, w = 200, h = 100; - matrix23TransformRect(&m, &x, &y, &w, &h); - printf(" %d,%d %d x %d -> %d, %d %d x %d\n", 50, 10, 200, 100, - x, y, w, h); - } - - } - - return 0; -} -#endif diff --git a/src/mesa/drivers/dri/i915-tex/intel_rotate.h b/src/mesa/drivers/dri/i915-tex/intel_rotate.h deleted file mode 100644 index 0da45d20ce5..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_rotate.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef INTEL_ROTATE_H -#define INTEL_ROTATE_H 1 - -struct matrix23 -{ - int m00, m01, m02; - int m10, m11, m12; -}; - - - -extern void -matrix23Set(struct matrix23 *m, - int m00, int m01, int m02, - int m10, int m11, int m12); - -extern void -matrix23TransformCoordi(const struct matrix23 *m, int *x, int *y); - -extern void -matrix23TransformCoordf(const struct matrix23 *m, float *x, float *y); - -extern void -matrix23TransformDistance(const struct matrix23 *m, int *xDist, int *yDist); - -extern void -matrix23TransformRect(const struct matrix23 *m, - int *x, int *y, int *w, int *h); - -extern void -matrix23Rotate(struct matrix23 *m, int width, int height, int angle); - -extern void -matrix23Flip(struct matrix23 *m, int width, int height, int xflip, int yflip); - -extern void -matrix23Multiply(struct matrix23 *result, - const struct matrix23 *a, const struct matrix23 *b); - - -#endif /* INTEL_ROTATE_H */ diff --git a/src/mesa/drivers/dri/i915-tex/intel_screen.c b/src/mesa/drivers/dri/i915-tex/intel_screen.c deleted file mode 100644 index 1401e7ada6b..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_screen.c +++ /dev/null @@ -1,756 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "glheader.h" -#include "context.h" -#include "framebuffer.h" -#include "matrix.h" -#include "renderbuffer.h" -#include "simple_list.h" -#include "utils.h" -#include "vblank.h" -#include "xmlpool.h" - - -#include "intel_screen.h" - -#include "intel_buffers.h" -#include "intel_tex.h" -#include "intel_span.h" -#include "intel_tris.h" -#include "intel_ioctl.h" -#include "intel_fbo.h" - -<<<<<<< intel_screen.c -#include "i830_dri.h" - -======= -#include "i830_dri.h" - - ->>>>>>> 1.29.2.13 -PUBLIC const char __driConfigOptions[] = -DRI_CONF_BEGIN - DRI_CONF_SECTION_PERFORMANCE - DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS) - DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0) - DRI_CONF_SECTION_END - DRI_CONF_SECTION_QUALITY - DRI_CONF_FORCE_S3TC_ENABLE(false) - DRI_CONF_ALLOW_LARGE_TEXTURES(1) - DRI_CONF_SECTION_END -DRI_CONF_END; -const GLuint __driNConfigOptions = 4; - -#ifdef USE_NEW_INTERFACE -static PFNGLXCREATECONTEXTMODES create_context_modes = NULL; -#endif /*USE_NEW_INTERFACE*/ - -extern const struct dri_extension card_extensions[]; - -/** - * Map all the memory regions described by the screen. - * \return GL_TRUE if success, GL_FALSE if error. - */ -GLboolean -intelMapScreenRegions(__DRIscreenPrivate *sPriv) -{ - intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private; - - if (intelScreen->front.handle) { - if (drmMap(sPriv->fd, - intelScreen->front.handle, - intelScreen->front.size, - (drmAddress *)&intelScreen->front.map) != 0) { - _mesa_problem(NULL, "drmMap(frontbuffer) failed!"); - return GL_FALSE; - } - } - else { - _mesa_warning(NULL, "no front buffer handle in intelMapScreenRegions!"); - } - - if (drmMap(sPriv->fd, - intelScreen->back.handle, - intelScreen->back.size, - (drmAddress *)&intelScreen->back.map) != 0) { - intelUnmapScreenRegions(intelScreen); - return GL_FALSE; - } - - if (drmMap(sPriv->fd, - intelScreen->depth.handle, - intelScreen->depth.size, - (drmAddress *)&intelScreen->depth.map) != 0) { - intelUnmapScreenRegions(intelScreen); - return GL_FALSE; - } - - if (drmMap(sPriv->fd, - intelScreen->tex.handle, - intelScreen->tex.size, - (drmAddress *)&intelScreen->tex.map) != 0) { - intelUnmapScreenRegions(intelScreen); - return GL_FALSE; - } - - if (0) - printf("Mappings: front: %p back: %p depth: %p tex: %p\n", - intelScreen->front.map, - intelScreen->back.map, - intelScreen->depth.map, - intelScreen->tex.map); - return GL_TRUE; -} - - -void -intelUnmapScreenRegions(intelScreenPrivate *intelScreen) -{ -#define REALLY_UNMAP 1 - if (intelScreen->front.map) { -#if REALLY_UNMAP - if (drmUnmap(intelScreen->front.map, intelScreen->front.size) != 0) - printf("drmUnmap front failed!\n"); -#endif - intelScreen->front.map = NULL; - } - if (intelScreen->back.map) { -#if REALLY_UNMAP - if (drmUnmap(intelScreen->back.map, intelScreen->back.size) != 0) - printf("drmUnmap back failed!\n"); -#endif - intelScreen->back.map = NULL; - } - if (intelScreen->depth.map) { -#if REALLY_UNMAP - drmUnmap(intelScreen->depth.map, intelScreen->depth.size); - intelScreen->depth.map = NULL; -#endif - } - if (intelScreen->tex.map) { -#if REALLY_UNMAP - drmUnmap(intelScreen->tex.map, intelScreen->tex.size); - intelScreen->tex.map = NULL; -#endif - } -} - - -static void -intelPrintDRIInfo(intelScreenPrivate *intelScreen, - __DRIscreenPrivate *sPriv, - I830DRIPtr gDRIPriv) -{ - fprintf(stderr, "*** Front size: 0x%x offset: 0x%x pitch: %d\n", - intelScreen->front.size, intelScreen->front.offset, - intelScreen->front.pitch); - fprintf(stderr, "*** Back size: 0x%x offset: 0x%x pitch: %d\n", - intelScreen->back.size, intelScreen->back.offset, - intelScreen->back.pitch); - fprintf(stderr, "*** Depth size: 0x%x offset: 0x%x pitch: %d\n", - intelScreen->depth.size, intelScreen->depth.offset, - intelScreen->depth.pitch); - fprintf(stderr, "*** Rotated size: 0x%x offset: 0x%x pitch: %d\n", - intelScreen->rotated.size, intelScreen->rotated.offset, - intelScreen->rotated.pitch); - fprintf(stderr, "*** Texture size: 0x%x offset: 0x%x\n", - intelScreen->tex.size, intelScreen->tex.offset); - fprintf(stderr, "*** Memory : 0x%x\n", gDRIPriv->mem); -} - - -static void -intelPrintSAREA(const drmI830Sarea *sarea) -{ - fprintf(stderr, "SAREA: sarea width %d height %d\n", sarea->width, sarea->height); - fprintf(stderr, "SAREA: pitch: %d\n", sarea->pitch); - fprintf(stderr, - "SAREA: front offset: 0x%08x size: 0x%x handle: 0x%x\n", - sarea->front_offset, sarea->front_size, - (unsigned) sarea->front_handle); - fprintf(stderr, - "SAREA: back offset: 0x%08x size: 0x%x handle: 0x%x\n", - sarea->back_offset, sarea->back_size, - (unsigned) sarea->back_handle); - fprintf(stderr, "SAREA: depth offset: 0x%08x size: 0x%x handle: 0x%x\n", - sarea->depth_offset, sarea->depth_size, - (unsigned) sarea->depth_handle); - fprintf(stderr, "SAREA: tex offset: 0x%08x size: 0x%x handle: 0x%x\n", - sarea->tex_offset, sarea->tex_size, - (unsigned) sarea->tex_handle); - fprintf(stderr, "SAREA: rotation: %d\n", sarea->rotation); - fprintf(stderr, - "SAREA: rotated offset: 0x%08x size: 0x%x\n", - sarea->rotated_offset, sarea->rotated_size); - fprintf(stderr, "SAREA: rotated pitch: %d\n", sarea->rotated_pitch); -} - - -/** - * A number of the screen parameters are obtained/computed from - * information in the SAREA. This function updates those parameters. - */ -void -intelUpdateScreenFromSAREA(intelScreenPrivate *intelScreen, - drmI830Sarea *sarea) -{ - intelScreen->width = sarea->width; - intelScreen->height = sarea->height; - - intelScreen->front.offset = sarea->front_offset; - intelScreen->front.pitch = sarea->pitch * intelScreen->cpp; - intelScreen->front.handle = sarea->front_handle; - intelScreen->front.size = sarea->front_size; - - intelScreen->back.offset = sarea->back_offset; - intelScreen->back.pitch = sarea->pitch * intelScreen->cpp; - intelScreen->back.handle = sarea->back_handle; - intelScreen->back.size = sarea->back_size; - - intelScreen->depth.offset = sarea->depth_offset; - intelScreen->depth.pitch = sarea->pitch * intelScreen->cpp; - intelScreen->depth.handle = sarea->depth_handle; - intelScreen->depth.size = sarea->depth_size; - - intelScreen->tex.offset = sarea->tex_offset; - intelScreen->logTextureGranularity = sarea->log_tex_granularity; - intelScreen->tex.handle = sarea->tex_handle; - intelScreen->tex.size = sarea->tex_size; - - intelScreen->rotated.offset = sarea->rotated_offset; - intelScreen->rotated.pitch = sarea->rotated_pitch * intelScreen->cpp; - intelScreen->rotated.size = sarea->rotated_size; - intelScreen->current_rotation = sarea->rotation; - matrix23Rotate(&intelScreen->rotMatrix, - sarea->width, sarea->height, sarea->rotation); - intelScreen->rotatedWidth = sarea->virtualX; - intelScreen->rotatedHeight = sarea->virtualY; - - if (0) - intelPrintSAREA(sarea); -} - - -static GLboolean intelInitDriver(__DRIscreenPrivate *sPriv) -{ - intelScreenPrivate *intelScreen; - I830DRIPtr gDRIPriv = (I830DRIPtr)sPriv->pDevPriv; - drmI830Sarea *sarea; - PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension = - (PFNGLXSCRENABLEEXTENSIONPROC) (*dri_interface->getProcAddress("glxEnableExtension")); - void * const psc = sPriv->psc->screenConfigs; - - if (sPriv->devPrivSize != sizeof(I830DRIRec)) { - fprintf(stderr,"\nERROR! sizeof(I830DRIRec) does not match passed size from device driver\n"); - return GL_FALSE; - } - - /* Allocate the private area */ - intelScreen = (intelScreenPrivate *)CALLOC(sizeof(intelScreenPrivate)); - if (!intelScreen) { - fprintf(stderr,"\nERROR! Allocating private area failed\n"); - return GL_FALSE; - } - /* parse information in __driConfigOptions */ - driParseOptionInfo (&intelScreen->optionCache, - __driConfigOptions, __driNConfigOptions); - - intelScreen->driScrnPriv = sPriv; - sPriv->private = (void *)intelScreen; - intelScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset; - sarea = (drmI830Sarea *) - (((GLubyte *)sPriv->pSAREA)+intelScreen->sarea_priv_offset); - - intelScreen->deviceID = gDRIPriv->deviceID; - intelScreen->mem = gDRIPriv->mem; - intelScreen->cpp = gDRIPriv->cpp; - - switch (gDRIPriv->bitsPerPixel) { - case 16: intelScreen->fbFormat = DV_PF_565; break; - case 32: intelScreen->fbFormat = DV_PF_8888; break; - default: exit(1); break; - } -<<<<<<< intel_screen.c -======= - - intelScreen->front.pitch = gDRIPriv->fbStride; - intelScreen->front.offset = gDRIPriv->fbOffset; - intelScreen->front.map = (char *)sPriv->pFB; - - intelScreen->back.offset = gDRIPriv->backOffset; - intelScreen->back.pitch = gDRIPriv->backPitch; - intelScreen->back.handle = gDRIPriv->backbuffer; - intelScreen->back.size = gDRIPriv->backbufferSize; ->>>>>>> 1.29.2.13 - - intelUpdateScreenFromSAREA(intelScreen, sarea); - -<<<<<<< intel_screen.c - if (0) - intelPrintDRIInfo(intelScreen, sPriv, gDRIPriv); -======= - intelScreen->depth.offset = gDRIPriv->depthOffset; - intelScreen->depth.pitch = gDRIPriv->depthPitch; - intelScreen->depth.handle = gDRIPriv->depthbuffer; - intelScreen->depth.size = gDRIPriv->depthbufferSize; - - if (drmMap(sPriv->fd, - intelScreen->depth.handle, - intelScreen->depth.size, - (drmAddress *)&intelScreen->depth.map) != 0) { - fprintf(stderr, "\nERROR: line %d, Function %s, File %s\n", - __LINE__, __FUNCTION__, __FILE__); - FREE(intelScreen); - drmUnmap(intelScreen->back.map, intelScreen->back.size); - sPriv->private = NULL; - return GL_FALSE; - } - -#if 0 - - /* - * FIXME: Remove this code and its references. - */ - - intelScreen->tex.offset = gDRIPriv->textureOffset; - intelScreen->logTextureGranularity = gDRIPriv->logTextureGranularity; - intelScreen->tex.handle = gDRIPriv->textures; - intelScreen->tex.size = gDRIPriv->textureSize; ->>>>>>> 1.29.2.13 - - if (!intelMapScreenRegions(sPriv)) { - fprintf(stderr,"\nERROR! mapping regions\n"); - _mesa_free(intelScreen); - sPriv->private = NULL; - return GL_FALSE; - } -<<<<<<< intel_screen.c -======= - -#else - intelScreen->tex.offset = 0; - intelScreen->logTextureGranularity = 0; - intelScreen->tex.handle = 0; - intelScreen->tex.size = 0; -#endif - - intelScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset; - - if (1) intelPrintDRIInfo(intelScreen, sPriv, gDRIPriv); ->>>>>>> 1.29.2.13 - - intelScreen->drmMinor = sPriv->drmMinor; - - /* Determine if IRQs are active? */ - { - int ret; - drmI830GetParam gp; - - gp.param = I830_PARAM_IRQ_ACTIVE; - gp.value = &intelScreen->irq_active; - - ret = drmCommandWriteRead( sPriv->fd, DRM_I830_GETPARAM, - &gp, sizeof(gp)); - if (ret) { - fprintf(stderr, "drmI830GetParam: %d\n", ret); - return GL_FALSE; - } - } - - /* Determine if batchbuffers are allowed */ - { - int ret; - drmI830GetParam gp; - - gp.param = I830_PARAM_ALLOW_BATCHBUFFER; - gp.value = &intelScreen->allow_batchbuffer; - - ret = drmCommandWriteRead( sPriv->fd, DRM_I830_GETPARAM, - &gp, sizeof(gp)); - if (ret) { - fprintf(stderr, "drmI830GetParam: (%d) %d\n", gp.param, ret); - return GL_FALSE; - } - } - - if (glx_enable_extension != NULL) { - (*glx_enable_extension)( psc, "GLX_SGI_swap_control" ); - (*glx_enable_extension)( psc, "GLX_SGI_video_sync" ); - (*glx_enable_extension)( psc, "GLX_MESA_swap_control" ); - (*glx_enable_extension)( psc, "GLX_MESA_swap_frame_usage" ); - (*glx_enable_extension)( psc, "GLX_SGI_make_current_read" ); - } - - return GL_TRUE; -} - - -static void intelDestroyScreen(__DRIscreenPrivate *sPriv) -{ - intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private; - - intelUnmapScreenRegions(intelScreen); - FREE(intelScreen); - sPriv->private = NULL; -} - - -/** - * This is called when we need to set up GL rendering to a new X window. - */ -static GLboolean intelCreateBuffer( __DRIscreenPrivate *driScrnPriv, - __DRIdrawablePrivate *driDrawPriv, - const __GLcontextModes *mesaVis, - GLboolean isPixmap ) -{ - intelScreenPrivate *screen = (intelScreenPrivate *) driScrnPriv->private; - - if (isPixmap) { - return GL_FALSE; /* not implemented */ - } else { - GLboolean swStencil = (mesaVis->stencilBits > 0 && - mesaVis->depthBits != 24); - GLenum rgbFormat = (mesaVis->redBits == 5 ? GL_RGB5 : GL_RGBA8); - - struct gl_framebuffer *fb = _mesa_create_framebuffer(mesaVis); - - /* setup the hardware-based renderbuffers */ - { -<<<<<<< intel_screen.c - driRenderbuffer *frontRb - = driNewRenderbuffer(GL_RGBA, - screen->front.map, - screen->cpp, - screen->front.offset, screen->front.pitch, - driDrawPriv); - intelSetSpanFunctions(frontRb, mesaVis); -======= - struct intel_renderbuffer *frontRb - = intel_create_renderbuffer(rgbFormat, - screen->width, screen->height, - screen->front.offset, - screen->front.pitch, - screen->cpp, - driScrnPriv->pFB); - intel_set_span_functions(&frontRb->Base); ->>>>>>> 1.29.2.13 - _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontRb->Base); - } - - if (mesaVis->doubleBufferMode) { - struct intel_renderbuffer *backRb - = intel_create_renderbuffer(rgbFormat, - screen->width, screen->height, - screen->back.offset, - screen->back.pitch, - screen->cpp, - screen->back.map); - intel_set_span_functions(&backRb->Base); - _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backRb->Base); - } - - if (mesaVis->depthBits == 24 && mesaVis->stencilBits == 8) { - /* combined depth/stencil buffer */ - struct intel_renderbuffer *depthStencilRb - = intel_create_renderbuffer( - GL_DEPTH24_STENCIL8_EXT, - screen->width, screen->height, - screen->depth.offset, - screen->depth.pitch, - screen->cpp, /* 4! */ - screen->depth.map); - intel_set_span_functions(&depthStencilRb->Base); - /* note: bind RB to two attachment points */ - _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthStencilRb->Base); - _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &depthStencilRb->Base); - } - else if (mesaVis->depthBits == 16) { - /* just 16-bit depth buffer, no hw stencil */ - struct intel_renderbuffer *depthRb - = intel_create_renderbuffer(GL_DEPTH_COMPONENT16, - screen->width, screen->height, - screen->depth.offset, - screen->depth.pitch, - screen->cpp, /* 2! */ - screen->depth.map); - intel_set_span_functions(&depthRb->Base); - _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base); - } - - /* now add any/all software-based renderbuffers we may need */ - _mesa_add_soft_renderbuffers(fb, - GL_FALSE, /* never sw color */ - GL_FALSE, /* never sw depth */ - swStencil, - mesaVis->accumRedBits > 0, - GL_FALSE, /* never sw alpha */ - GL_FALSE /* never sw aux */); - driDrawPriv->driverPrivate = (void *) fb; - - return (driDrawPriv->driverPrivate != NULL); - } -} - -static void intelDestroyBuffer(__DRIdrawablePrivate *driDrawPriv) -{ - _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate)); -} - - -/** - * Get information about previous buffer swaps. - */ -static int -intelGetSwapInfo( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo ) -{ - intelContextPtr intel; - - if ( (dPriv == NULL) || (dPriv->driContextPriv == NULL) - || (dPriv->driContextPriv->driverPrivate == NULL) - || (sInfo == NULL) ) { - return -1; - } - - intel = dPriv->driContextPriv->driverPrivate; - sInfo->swap_count = intel->swap_count; - sInfo->swap_ust = intel->swap_ust; - sInfo->swap_missed_count = intel->swap_missed_count; - - sInfo->swap_missed_usage = (sInfo->swap_missed_count != 0) - ? driCalculateSwapUsage( dPriv, 0, intel->swap_missed_ust ) - : 0.0; - - return 0; -} - - -/* There are probably better ways to do this, such as an - * init-designated function to register chipids and createcontext - * functions. - */ -extern GLboolean i830CreateContext( const __GLcontextModes *mesaVis, - __DRIcontextPrivate *driContextPriv, - void *sharedContextPrivate); - -extern GLboolean i915CreateContext( const __GLcontextModes *mesaVis, - __DRIcontextPrivate *driContextPriv, - void *sharedContextPrivate); - - - - -static GLboolean intelCreateContext( const __GLcontextModes *mesaVis, - __DRIcontextPrivate *driContextPriv, - void *sharedContextPrivate) -{ - __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv; - intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private; - - switch (intelScreen->deviceID) { - /* Don't deal with i830 until texture work complete: - */ - case PCI_CHIP_845_G: - case PCI_CHIP_I830_M: - case PCI_CHIP_I855_GM: - case PCI_CHIP_I865_G: - return i830CreateContext( mesaVis, driContextPriv, - sharedContextPrivate ); - - case PCI_CHIP_I915_G: - case PCI_CHIP_I915_GM: - case PCI_CHIP_I945_G: - case PCI_CHIP_I945_GM: - return i915CreateContext( mesaVis, driContextPriv, - sharedContextPrivate ); - - default: - fprintf(stderr, "Unrecognized deviceID %x\n", intelScreen->deviceID); - return GL_FALSE; - } -} - - -static const struct __DriverAPIRec intelAPI = { - .InitDriver = intelInitDriver, - .DestroyScreen = intelDestroyScreen, - .CreateContext = intelCreateContext, - .DestroyContext = intelDestroyContext, - .CreateBuffer = intelCreateBuffer, - .DestroyBuffer = intelDestroyBuffer, - .SwapBuffers = intelSwapBuffers, - .MakeCurrent = intelMakeCurrent, - .UnbindContext = intelUnbindContext, - .GetSwapInfo = intelGetSwapInfo, - .GetMSC = driGetMSC32, - .WaitForMSC = driWaitForMSC32, - .WaitForSBC = NULL, - .SwapBuffersMSC = NULL -}; - - -static __GLcontextModes * -intelFillInModes( unsigned pixel_bits, unsigned depth_bits, - unsigned stencil_bits, GLboolean have_back_buffer ) -{ - __GLcontextModes * modes; - __GLcontextModes * m; - unsigned num_modes; - unsigned depth_buffer_factor; - unsigned back_buffer_factor; - GLenum fb_format; - GLenum fb_type; - - /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't - * support pageflipping at all. - */ - static const GLenum back_buffer_modes[] = { - GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML - }; - - u_int8_t depth_bits_array[3]; - u_int8_t stencil_bits_array[3]; - - - depth_bits_array[0] = 0; - depth_bits_array[1] = depth_bits; - depth_bits_array[2] = depth_bits; - - /* Just like with the accumulation buffer, always provide some modes - * with a stencil buffer. It will be a sw fallback, but some apps won't - * care about that. - */ - stencil_bits_array[0] = 0; - stencil_bits_array[1] = 0; - stencil_bits_array[2] = (stencil_bits == 0) ? 8 : stencil_bits; - - depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1; - back_buffer_factor = (have_back_buffer) ? 3 : 1; - - num_modes = depth_buffer_factor * back_buffer_factor * 4; - - if ( pixel_bits == 16 ) { - fb_format = GL_RGB; - fb_type = GL_UNSIGNED_SHORT_5_6_5; - } - else { - fb_format = GL_BGRA; - fb_type = GL_UNSIGNED_INT_8_8_8_8_REV; - } - - modes = (*dri_interface->createContextModes)( num_modes, sizeof( __GLcontextModes ) ); - m = modes; - if ( ! driFillInModes( & m, fb_format, fb_type, - depth_bits_array, stencil_bits_array, depth_buffer_factor, - back_buffer_modes, back_buffer_factor, - GLX_TRUE_COLOR ) ) { - fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", - __func__, __LINE__ ); - return NULL; - } - if ( ! driFillInModes( & m, fb_format, fb_type, - depth_bits_array, stencil_bits_array, depth_buffer_factor, - back_buffer_modes, back_buffer_factor, - GLX_DIRECT_COLOR ) ) { - fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", - __func__, __LINE__ ); - return NULL; - } - - /* Mark the visual as slow if there are "fake" stencil bits. - */ - for ( m = modes ; m != NULL ; m = m->next ) { - if ( (m->stencilBits != 0) && (m->stencilBits != stencil_bits) ) { - m->visualRating = GLX_SLOW_CONFIG; - } - } - - return modes; -} - - -/** - * This is the bootstrap function for the driver. libGL supplies all of the - * requisite information about the system, and the driver initializes itself. - * This routine also fills in the linked list pointed to by \c driver_modes - * with the \c __GLcontextModes that the driver can support for windows or - * pbuffers. - * - * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on - * failure. - */ -PUBLIC -void * __driCreateNewScreen_20050727( __DRInativeDisplay *dpy, int scrn, __DRIscreen *psc, - const __GLcontextModes * modes, - const __DRIversion * ddx_version, - const __DRIversion * dri_version, - const __DRIversion * drm_version, - const __DRIframebuffer * frame_buffer, - drmAddress pSAREA, int fd, - int internal_api_version, - const __DRIinterfaceMethods * interface, - __GLcontextModes ** driver_modes ) - -{ - __DRIscreenPrivate *psp; - static const __DRIversion ddx_expected = { 1, 5, 0 }; - static const __DRIversion dri_expected = { 4, 0, 0 }; - static const __DRIversion drm_expected = { 1, 4, 0 }; - - dri_interface = interface; - - if ( ! driCheckDriDdxDrmVersions2( "i915", - dri_version, & dri_expected, - ddx_version, & ddx_expected, - drm_version, & drm_expected ) ) { - return NULL; - } - - psp = __driUtilCreateNewScreen(dpy, scrn, psc, NULL, - ddx_version, dri_version, drm_version, - frame_buffer, pSAREA, fd, - internal_api_version, &intelAPI); - if ( psp != NULL ) { - I830DRIPtr dri_priv = (I830DRIPtr) psp->pDevPriv; - *driver_modes = intelFillInModes( dri_priv->cpp * 8, - (dri_priv->cpp == 2) ? 16 : 24, - (dri_priv->cpp == 2) ? 0 : 8, - (dri_priv->backOffset != dri_priv->depthOffset) ); - - /* Calling driInitExtensions here, with a NULL context pointer, does not actually - * enable the extensions. It just makes sure that all the dispatch offsets for all - * the extensions that *might* be enables are known. This is needed because the - * dispatch offsets need to be known when _mesa_context_create is called, but we can't - * enable the extensions until we have a context pointer. - * - * Hello chicken. Hello egg. How are you two today? - */ - driInitExtensions( NULL, card_extensions, GL_FALSE ); - } - - return (void *) psp; -} diff --git a/src/mesa/drivers/dri/i915-tex/intel_screen.h b/src/mesa/drivers/dri/i915-tex/intel_screen.h deleted file mode 100644 index 9a7a4d0d6d2..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_screen.h +++ /dev/null @@ -1,123 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#ifndef _INTEL_INIT_H_ -#define _INTEL_INIT_H_ - -#include <sys/time.h> -#include "xmlconfig.h" -#include "dri_util.h" -#include "intel_rotate.h" -#include "i830_common.h" - - -<<<<<<< intel_screen.h -/* This roughly corresponds to a gl_renderbuffer (Mesa 6.4) */ -======= -/* XXX: change name or eliminate to avoid conflict with "struct - * intel_region"!!! - */ ->>>>>>> 1.5.2.3 -typedef struct { - drm_handle_t handle; - drmSize size; /* region size in bytes */ - char *map; /* memory map */ - int offset; /* from start of video mem, in bytes */ - int pitch; /* row stride, in bytes */ -} intelRegion; - -typedef struct -{ - intelRegion front; - intelRegion back; - intelRegion rotated; - intelRegion depth; - intelRegion tex; - - int deviceID; - int width; - int height; - int mem; /* unused */ - - int cpp; /* for front and back buffers */ -<<<<<<< intel_screen.h - int fbFormat; -======= - int bitsPerPixel; /* unused */ - int fbFormat; /* XXX FBO: this is obsolete - remove after i830 updates */ ->>>>>>> 1.5.2.3 - - int logTextureGranularity; - - __DRIscreenPrivate *driScrnPriv; - unsigned int sarea_priv_offset; - - int drmMinor; - - int irq_active; - int allow_batchbuffer; - - struct matrix23 rotMatrix; - - int current_rotation; /* 0, 90, 180 or 270 */ - int rotatedWidth, rotatedHeight; - - /** - * Configuration cache with default values for all contexts - */ - driOptionCache optionCache; -} intelScreenPrivate; - - -extern GLboolean -intelMapScreenRegions(__DRIscreenPrivate *sPriv); - -extern void -intelUnmapScreenRegions(intelScreenPrivate *intelScreen); - -extern void -intelUpdateScreenFromSAREA(intelScreenPrivate *intelScreen, - drmI830Sarea *sarea); - -extern void -intelDestroyContext(__DRIcontextPrivate *driContextPriv); - -extern GLboolean -intelUnbindContext(__DRIcontextPrivate *driContextPriv); - -extern GLboolean -intelMakeCurrent(__DRIcontextPrivate *driContextPriv, - __DRIdrawablePrivate *driDrawPriv, - __DRIdrawablePrivate *driReadPriv); - -<<<<<<< intel_screen.h -extern void -intelSwapBuffers(__DRIdrawablePrivate *dPriv); - -======= ->>>>>>> 1.5.2.3 -#endif diff --git a/src/mesa/drivers/dri/i915-tex/intel_span.c b/src/mesa/drivers/dri/i915-tex/intel_span.c deleted file mode 100644 index 24eac0dce21..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_span.c +++ /dev/null @@ -1,401 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "glheader.h" -#include "macros.h" -#include "mtypes.h" -#include "colormac.h" - -#include "intel_fbo.h" -#include "intel_screen.h" -#include "intel_span.h" -#include "intel_regions.h" -#include "intel_ioctl.h" -#include "intel_tex.h" - -#include "swrast/swrast.h" - -/* - break intelWriteRGBASpan_ARGB8888 -*/ - -#undef DBG -#define DBG 0 - -#define LOCAL_VARS \ - struct intel_context *intel = intel_context(ctx); \ - struct intel_renderbuffer *irb = intel_renderbuffer(rb); \ - const GLint yScale = irb->RenderToTexture ? 1 : -1; \ - const GLint yBias = irb->RenderToTexture ? 0 : irb->Base.Height - 1; \ - GLubyte *buf = (GLubyte *) irb->pfMap \ - + (intel->drawY * irb->pfPitch + intel->drawX) * irb->region->cpp;\ - GLuint p; \ - assert(irb->pfMap);\ - (void) p; - -/* XXX FBO: this is identical to the macro in spantmp2.h except we get - * the cliprect info from the context, not the driDrawable. - * Move this into spantmp2.h someday. - */ -#define HW_CLIPLOOP() \ - do { \ - int _nc = intel->numClipRects; \ - while ( _nc-- ) { \ - int minx = intel->pClipRects[_nc].x1 - intel->drawX; \ - int miny = intel->pClipRects[_nc].y1 - intel->drawY; \ - int maxx = intel->pClipRects[_nc].x2 - intel->drawX; \ - int maxy = intel->pClipRects[_nc].y2 - intel->drawY; - - - - -#define Y_FLIP(_y) ((_y) * yScale + yBias) - -#define HW_LOCK() - -#define HW_UNLOCK() - -/* 16 bit, RGB565 color spanline and pixel functions - */ -#define SPANTMP_PIXEL_FMT GL_RGB -#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5 - -#define TAG(x) intel##x##_RGB565 -#define TAG2(x,y) intel##x##_RGB565##y -#define GET_PTR(X,Y) (buf + ((Y) * irb->pfPitch + (X)) * 2) -#include "spantmp2.h" - -/* 32 bit, ARGB8888 color spanline and pixel functions - */ -#define SPANTMP_PIXEL_FMT GL_BGRA -#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV - -#define TAG(x) intel##x##_ARGB8888 -#define TAG2(x,y) intel##x##_ARGB8888##y -#define GET_PTR(X,Y) (buf + ((Y) * irb->pfPitch + (X)) * 4) -#include "spantmp2.h" - - -#define LOCAL_DEPTH_VARS \ - struct intel_context *intel = intel_context(ctx); \ - struct intel_renderbuffer *irb = intel_renderbuffer(rb); \ - const GLuint pitch = irb->pfPitch/***XXX region->pitch*/; /* in pixels */ \ - const GLint yScale = irb->RenderToTexture ? 1 : -1; \ - const GLint yBias = irb->RenderToTexture ? 0 : irb->Base.Height - 1; \ - char *buf = (char *) irb->pfMap/*XXX use region->map*/ + \ - (intel->drawY * pitch + intel->drawX) * irb->region->cpp; - - -#define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS - -/** - ** 16-bit depthbuffer functions. - **/ -#define WRITE_DEPTH( _x, _y, d ) \ - ((GLushort *)buf)[(_x) + (_y) * pitch] = d; - -#define READ_DEPTH( d, _x, _y ) \ - d = ((GLushort *)buf)[(_x) + (_y) * pitch]; - - -#define TAG(x) intel##x##_z16 -#include "depthtmp.h" - - -/** - ** 24/8-bit interleaved depth/stencil functions - ** Note: we're actually reading back combined depth+stencil values. - ** The wrappers in main/depthstencil.c are used to extract the depth - ** and stencil values. - **/ -/* Change ZZZS -> SZZZ */ -#define WRITE_DEPTH( _x, _y, d ) { \ - GLuint tmp = ((d) >> 8) | ((d) << 24); \ - ((GLuint *)buf)[(_x) + (_y) * pitch] = tmp; \ -} - -/* Change SZZZ -> ZZZS */ -#define READ_DEPTH( d, _x, _y ) { \ - GLuint tmp = ((GLuint *)buf)[(_x) + (_y) * pitch]; \ - d = (tmp << 8) | (tmp >> 24); \ -} - -#define TAG(x) intel##x##_z24_s8 -#include "depthtmp.h" - - -/** - ** 8-bit stencil function (XXX FBO: This is obsolete) - **/ -#define WRITE_STENCIL( _x, _y, d ) { \ - GLuint tmp = ((GLuint *)buf)[(_x) + (_y) * pitch]; \ - tmp &= 0xffffff; \ - tmp |= ((d) << 24); \ - ((GLuint *) buf)[(_x) + (_y) * pitch] = tmp; \ -} - -#define READ_STENCIL( d, _x, _y ) \ - d = ((GLuint *)buf)[(_x) + (_y) * pitch] >> 24; - -#define TAG(x) intel##x##_z24_s8 -#include "stenciltmp.h" - - - -/** - * Map or unmap all the renderbuffers which we may need during - * software rendering. - * XXX in the future, we could probably convey extra information to - * reduce the number of mappings needed. I.e. if doing a glReadPixels - * from the depth buffer, we really only need one mapping. - * - * XXX Rewrite this function someday. - * We can probably just loop over all the renderbuffer attachments, - * map/unmap all of them, and not worry about the _ColorDrawBuffers - * _ColorReadBuffer, _DepthBuffer or _StencilBuffer fields. - */ -static void -intel_map_unmap_buffers(struct intel_context *intel, GLboolean map) -{ - GLcontext *ctx = &intel->ctx; - GLuint i, j; - struct intel_renderbuffer *irb; - - /* color draw buffers */ - for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) { - for (j = 0; j < ctx->DrawBuffer->_NumColorDrawBuffers[i]; j++) { - struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[i][j]; - irb = intel_renderbuffer(rb); - if (irb && irb->Base.Name != 0) { /* XXX FBO temporary test */ - /* this is a user-created intel_renderbuffer */ - if (irb->region) { - if (map) - intel_region_map(intel, irb->region); - else - intel_region_unmap(intel, irb->region); - } - irb->pfMap = irb->region->map; - irb->pfPitch = irb->region->pitch; - } - } - } - - /* check for render to textures */ - for (i = 0; i < BUFFER_COUNT; i++) { - struct gl_renderbuffer_attachment *att = ctx->DrawBuffer->Attachment + i; - struct gl_texture_object *tex = att->Texture; - if (tex) { - /* render to texture */ - ASSERT(att->Renderbuffer); - if (map) { - struct gl_texture_image *texImg; - texImg = tex->Image[att->CubeMapFace][att->TextureLevel]; - intel_tex_map_images(intel, intel_texture_object(tex)); - } - else { - intel_tex_unmap_images(intel, intel_texture_object(tex)); - } - } - } - - /* color read buffers */ - irb = intel_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer); - if (irb && irb->region && irb->Base.Name != 0) { - if (map) - intel_region_map(intel, irb->region); - else - intel_region_unmap(intel, irb->region); - } - - /* Account for front/back color page flipping. - * The span routines use the pfMap and pfPitch fields which will - * swap the front/back region map/pitch if we're page flipped. - * Do this after mapping, above, so the map field is valid. - */ -#if 0 - if (map && ctx->DrawBuffer->Name == 0) { - struct intel_renderbuffer *irbFront - = intel_get_renderbuffer(ctx->DrawBuffer, BUFFER_FRONT_LEFT); - struct intel_renderbuffer *irbBack - = intel_get_renderbuffer(ctx->DrawBuffer, BUFFER_BACK_LEFT); - if (irbBack) { - /* double buffered */ - if (intel->sarea->pf_current_page == 0) { - irbFront->pfMap = irbFront->region->map; - irbFront->pfPitch = irbFront->region->pitch; - irbBack->pfMap = irbBack->region->map; - irbBack->pfPitch = irbBack->region->pitch; - } - else { - irbFront->pfMap = irbBack->region->map; - irbFront->pfPitch = irbBack->region->pitch; - irbBack->pfMap = irbFront->region->map; - irbBack->pfPitch = irbFront->region->pitch; - } - } - } -#endif - - /* depth buffer (Note wrapper!) */ - if (ctx->DrawBuffer->_DepthBuffer) { - irb = intel_renderbuffer(ctx->DrawBuffer->_DepthBuffer->Wrapped); - if (irb && irb->region && irb->Base.Name != 0) { - if (map) { - intel_region_map(intel, irb->region); - irb->pfMap = irb->region->map; - irb->pfPitch = irb->region->pitch; - } - else { - intel_region_unmap(intel, irb->region); - irb->pfMap = NULL; - irb->pfPitch = 0; - } - } - } - - /* stencil buffer (Note wrapper!) */ - if (ctx->DrawBuffer->_StencilBuffer) { - irb = intel_renderbuffer(ctx->DrawBuffer->_StencilBuffer->Wrapped); - if (irb && irb->region && irb->Base.Name != 0) { - if (map) { - intel_region_map(intel, irb->region); - irb->pfMap = irb->region->map; - irb->pfPitch = irb->region->pitch; - } - else { - intel_region_unmap(intel, irb->region); - irb->pfMap = NULL; - irb->pfPitch = 0; - } - } - } -} - - - -/** - * Prepare for softare rendering. Map current read/draw framebuffers' - * renderbuffes and all currently bound texture objects. - * - * Old note: Moved locking out to get reasonable span performance. - */ -void intelSpanRenderStart( GLcontext *ctx ) -{ - struct intel_context *intel = intel_context(ctx); - GLuint i; - - intelFlush(&intel->ctx); - LOCK_HARDWARE(intel); - -#if 0 - /* Just map the framebuffer and all textures. Bufmgr code will - * take care of waiting on the necessary fences: - */ - intel_region_map(intel, intel->front_region); - intel_region_map(intel, intel->back_region); - intel_region_map(intel, intel->depth_region); -#endif - - for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) { - if (ctx->Texture.Unit[i]._ReallyEnabled) { - struct gl_texture_object *texObj = ctx->Texture.Unit[i]._Current; - intel_tex_map_images(intel, intel_texture_object(texObj)); - } - } - - intel_map_unmap_buffers(intel, GL_TRUE); -} - -/** - * Called when done softare rendering. Unmap the buffers we mapped in - * the above function. - */ -void intelSpanRenderFinish( GLcontext *ctx ) -{ - struct intel_context *intel = intel_context( ctx ); - GLuint i; - - _swrast_flush( ctx ); - - /* Now unmap the framebuffer: - */ -#if 0 - intel_region_unmap(intel, intel->front_region); - intel_region_unmap(intel, intel->back_region); - intel_region_unmap(intel, intel->depth_region); -#endif - - for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) { - if (ctx->Texture.Unit[i]._ReallyEnabled) { - struct gl_texture_object *texObj = ctx->Texture.Unit[i]._Current; - intel_tex_unmap_images(intel, intel_texture_object(texObj)); - } - } - - intel_map_unmap_buffers(intel, GL_FALSE); - - UNLOCK_HARDWARE( intel ); -} - - -void intelInitSpanFuncs( GLcontext *ctx ) -{ - struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx); - swdd->SpanRenderStart = intelSpanRenderStart; - swdd->SpanRenderFinish = intelSpanRenderFinish; -} - - -/** - * Plug in appropriate span read/write functions for the given renderbuffer. - * These are used for the software fallbacks. - */ -void -intel_set_span_functions(struct gl_renderbuffer *rb) -{ - if (rb->_ActualFormat == GL_RGB5) { - /* 565 RGB */ - intelInitPointers_RGB565(rb); - } - else if (rb->_ActualFormat == GL_RGBA8) { - /* 8888 RGBA */ - intelInitPointers_ARGB8888(rb); - } - else if (rb->_ActualFormat == GL_DEPTH_COMPONENT16) { - intelInitDepthPointers_z16(rb); - } - else if (rb->_ActualFormat == GL_DEPTH_COMPONENT24 || /* XXX FBO remove */ - rb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT) { - intelInitDepthPointers_z24_s8(rb); - } - else if (rb->_ActualFormat == GL_STENCIL_INDEX8_EXT) { /* XXX FBO remove */ - intelInitStencilPointers_z24_s8(rb); - } - else { - _mesa_problem(NULL, "Unexpected _ActualFormat in intelSetSpanFunctions"); - } -} diff --git a/src/mesa/drivers/dri/i915-tex/intel_span.h b/src/mesa/drivers/dri/i915-tex/intel_span.h deleted file mode 100644 index 98dd57b06a8..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_span.h +++ /dev/null @@ -1,39 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#ifndef _INTEL_SPAN_H -#define _INTEL_SPAN_H - -extern void intelInitSpanFuncs( GLcontext *ctx ); - -extern void intelSpanRenderFinish( GLcontext *ctx ); -extern void intelSpanRenderStart( GLcontext *ctx ); - -extern void -intel_set_span_functions(struct gl_renderbuffer *rb); - -#endif diff --git a/src/mesa/drivers/dri/i915-tex/intel_state.c b/src/mesa/drivers/dri/i915-tex/intel_state.c deleted file mode 100644 index c97bffffb17..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_state.c +++ /dev/null @@ -1,404 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - - -#include "glheader.h" -#include "context.h" -#include "macros.h" -#include "enums.h" -#include "colormac.h" -#include "dd.h" - -#include "intel_screen.h" -#include "intel_context.h" -#include "intel_fbo.h" -#include "intel_regions.h" -#include "swrast/swrast.h" - -int intel_translate_compare_func( GLenum func ) -{ - switch(func) { - case GL_NEVER: - return COMPAREFUNC_NEVER; - case GL_LESS: - return COMPAREFUNC_LESS; - case GL_LEQUAL: - return COMPAREFUNC_LEQUAL; - case GL_GREATER: - return COMPAREFUNC_GREATER; - case GL_GEQUAL: - return COMPAREFUNC_GEQUAL; - case GL_NOTEQUAL: - return COMPAREFUNC_NOTEQUAL; - case GL_EQUAL: - return COMPAREFUNC_EQUAL; - case GL_ALWAYS: - return COMPAREFUNC_ALWAYS; - } - - fprintf(stderr, "Unknown value in %s: %x\n", __FUNCTION__, func); - return COMPAREFUNC_ALWAYS; -} - -int intel_translate_stencil_op( GLenum op ) -{ - switch(op) { - case GL_KEEP: - return STENCILOP_KEEP; - case GL_ZERO: - return STENCILOP_ZERO; - case GL_REPLACE: - return STENCILOP_REPLACE; - case GL_INCR: - return STENCILOP_INCRSAT; - case GL_DECR: - return STENCILOP_DECRSAT; - case GL_INCR_WRAP: - return STENCILOP_INCR; - case GL_DECR_WRAP: - return STENCILOP_DECR; - case GL_INVERT: - return STENCILOP_INVERT; - default: - return STENCILOP_ZERO; - } -} - -int intel_translate_blend_factor( GLenum factor ) -{ - switch(factor) { - case GL_ZERO: - return BLENDFACT_ZERO; - case GL_SRC_ALPHA: - return BLENDFACT_SRC_ALPHA; - case GL_ONE: - return BLENDFACT_ONE; - case GL_SRC_COLOR: - return BLENDFACT_SRC_COLR; - case GL_ONE_MINUS_SRC_COLOR: - return BLENDFACT_INV_SRC_COLR; - case GL_DST_COLOR: - return BLENDFACT_DST_COLR; - case GL_ONE_MINUS_DST_COLOR: - return BLENDFACT_INV_DST_COLR; - case GL_ONE_MINUS_SRC_ALPHA: - return BLENDFACT_INV_SRC_ALPHA; - case GL_DST_ALPHA: - return BLENDFACT_DST_ALPHA; - case GL_ONE_MINUS_DST_ALPHA: - return BLENDFACT_INV_DST_ALPHA; - case GL_SRC_ALPHA_SATURATE: - return BLENDFACT_SRC_ALPHA_SATURATE; - case GL_CONSTANT_COLOR: - return BLENDFACT_CONST_COLOR; - case GL_ONE_MINUS_CONSTANT_COLOR: - return BLENDFACT_INV_CONST_COLOR; - case GL_CONSTANT_ALPHA: - return BLENDFACT_CONST_ALPHA; - case GL_ONE_MINUS_CONSTANT_ALPHA: - return BLENDFACT_INV_CONST_ALPHA; - } - - fprintf(stderr, "Unknown value in %s: %x\n", __FUNCTION__, factor); - return BLENDFACT_ZERO; -} - -int intel_translate_logic_op( GLenum opcode ) -{ - switch(opcode) { - case GL_CLEAR: - return LOGICOP_CLEAR; - case GL_AND: - return LOGICOP_AND; - case GL_AND_REVERSE: - return LOGICOP_AND_RVRSE; - case GL_COPY: - return LOGICOP_COPY; - case GL_COPY_INVERTED: - return LOGICOP_COPY_INV; - case GL_AND_INVERTED: - return LOGICOP_AND_INV; - case GL_NOOP: - return LOGICOP_NOOP; - case GL_XOR: - return LOGICOP_XOR; - case GL_OR: - return LOGICOP_OR; - case GL_OR_INVERTED: - return LOGICOP_OR_INV; - case GL_NOR: - return LOGICOP_NOR; - case GL_EQUIV: - return LOGICOP_EQUIV; - case GL_INVERT: - return LOGICOP_INV; - case GL_OR_REVERSE: - return LOGICOP_OR_RVRSE; - case GL_NAND: - return LOGICOP_NAND; - case GL_SET: - return LOGICOP_SET; - default: - return LOGICOP_SET; - } -} - -<<<<<<< intel_state.c -static void intelDrawBuffer(GLcontext *ctx, GLenum mode ) -{ - intelContextPtr intel = INTEL_CONTEXT(ctx); - int front = 0; - - if (!ctx->DrawBuffer) - return; - - switch ( ctx->DrawBuffer->_ColorDrawBufferMask[0] ) { - case BUFFER_BIT_FRONT_LEFT: - front = 1; - FALLBACK( intel, INTEL_FALLBACK_DRAW_BUFFER, GL_FALSE ); - break; - case BUFFER_BIT_BACK_LEFT: - front = 0; - FALLBACK( intel, INTEL_FALLBACK_DRAW_BUFFER, GL_FALSE ); - break; - default: - FALLBACK( intel, INTEL_FALLBACK_DRAW_BUFFER, GL_TRUE ); - return; - } - - if ( intel->sarea->pf_current_page == 1 ) - front ^= 1; - - intelSetFrontClipRects( intel ); - - if (front) { - intel->drawRegion = &intel->intelScreen->front; - intel->readRegion = &intel->intelScreen->front; - } else { - intel->drawRegion = &intel->intelScreen->back; - intel->readRegion = &intel->intelScreen->back; - } - - intel->vtbl.set_color_region( intel, intel->drawRegion ); -} - -static void intelReadBuffer( GLcontext *ctx, GLenum mode ) -{ - /* nothing, until we implement h/w glRead/CopyPixels or CopyTexImage */ -} - -======= ->>>>>>> 1.9.2.6 - -static void intelClearColor(GLcontext *ctx, const GLfloat color[4]) -{ - struct intel_context *intel = intel_context(ctx); - GLubyte clear[4]; - - CLAMPED_FLOAT_TO_UBYTE(clear[0], color[0]); - CLAMPED_FLOAT_TO_UBYTE(clear[1], color[1]); - CLAMPED_FLOAT_TO_UBYTE(clear[2], color[2]); - CLAMPED_FLOAT_TO_UBYTE(clear[3], color[3]); - - /* compute both 32 and 16-bit clear values */ - intel->ClearColor8888 = INTEL_PACKCOLOR8888(clear[0], clear[1], - clear[2], clear[3]); - intel->ClearColor565 = INTEL_PACKCOLOR565(clear[0], clear[1], clear[2]); -} - - -/** - * Update the viewport transformation matrix. Depends on: - * - viewport pos/size - * - depthrange - * - window pos/size or FBO size - */ -static void intelCalcViewport( GLcontext *ctx ) -{ - struct intel_context *intel = intel_context(ctx); - const GLfloat *v = ctx->Viewport._WindowMap.m; - const GLfloat depthScale = 1.0F / ctx->DrawBuffer->_DepthMaxF; - GLfloat *m = intel->ViewportMatrix.m; - GLfloat yScale, yBias; - - if (ctx->DrawBuffer->Name) { - /* User created FBO */ - struct intel_renderbuffer *irb - = intel_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0][0]); - if (irb && !irb->RenderToTexture) { - /* y=0=top */ - yScale = -1.0; - yBias = irb->Base.Height; - } - else { - /* y=0=bottom */ - yScale = 1.0; - yBias = 0.0; - } - } - else { - /* window buffer, y=0=top */ - yScale = -1.0; - yBias = (intel->driDrawable) ? intel->driDrawable->h : 0.0F; - } - - m[MAT_SX] = v[MAT_SX]; - m[MAT_TX] = v[MAT_TX] + SUBPIXEL_X; - - m[MAT_SY] = v[MAT_SY] * yScale; - m[MAT_TY] = v[MAT_TY] * yScale + yBias + SUBPIXEL_Y; - - m[MAT_SZ] = v[MAT_SZ] * depthScale; - m[MAT_TZ] = v[MAT_TZ] * depthScale; -} - -static void intelViewport( GLcontext *ctx, - GLint x, GLint y, - GLsizei width, GLsizei height ) -{ - intelCalcViewport( ctx ); -} - -static void intelDepthRange( GLcontext *ctx, - GLclampd nearval, GLclampd farval ) -{ - intelCalcViewport( ctx ); -} - -/* Fallback to swrast for select and feedback. - */ -static void intelRenderMode( GLcontext *ctx, GLenum mode ) -{ - struct intel_context *intel = intel_context(ctx); - FALLBACK( intel, INTEL_FALLBACK_RENDERMODE, (mode != GL_RENDER) ); -} - - -void intelInitStateFuncs( struct dd_function_table *functions ) -{ - functions->RenderMode = intelRenderMode; - functions->Viewport = intelViewport; - functions->DepthRange = intelDepthRange; - functions->ClearColor = intelClearColor; -} - - - - -void intelInitState( GLcontext *ctx ) -{ - /* Mesa should do this for us: - */ - ctx->Driver.AlphaFunc( ctx, - ctx->Color.AlphaFunc, - ctx->Color.AlphaRef); - - ctx->Driver.BlendColor( ctx, - ctx->Color.BlendColor ); - - ctx->Driver.BlendEquationSeparate( ctx, - ctx->Color.BlendEquationRGB, - ctx->Color.BlendEquationA); - - ctx->Driver.BlendFuncSeparate( ctx, - ctx->Color.BlendSrcRGB, - ctx->Color.BlendDstRGB, - ctx->Color.BlendSrcA, - ctx->Color.BlendDstA); - - ctx->Driver.ColorMask( ctx, - ctx->Color.ColorMask[RCOMP], - ctx->Color.ColorMask[GCOMP], - ctx->Color.ColorMask[BCOMP], - ctx->Color.ColorMask[ACOMP]); - - ctx->Driver.CullFace( ctx, ctx->Polygon.CullFaceMode ); - ctx->Driver.DepthFunc( ctx, ctx->Depth.Func ); - ctx->Driver.DepthMask( ctx, ctx->Depth.Mask ); - - ctx->Driver.Enable( ctx, GL_ALPHA_TEST, ctx->Color.AlphaEnabled ); - ctx->Driver.Enable( ctx, GL_BLEND, ctx->Color.BlendEnabled ); - ctx->Driver.Enable( ctx, GL_COLOR_LOGIC_OP, ctx->Color.ColorLogicOpEnabled ); - ctx->Driver.Enable( ctx, GL_COLOR_SUM, ctx->Fog.ColorSumEnabled ); - ctx->Driver.Enable( ctx, GL_CULL_FACE, ctx->Polygon.CullFlag ); - ctx->Driver.Enable( ctx, GL_DEPTH_TEST, ctx->Depth.Test ); - ctx->Driver.Enable( ctx, GL_DITHER, ctx->Color.DitherFlag ); - ctx->Driver.Enable( ctx, GL_FOG, ctx->Fog.Enabled ); - ctx->Driver.Enable( ctx, GL_LIGHTING, ctx->Light.Enabled ); - ctx->Driver.Enable( ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag ); - ctx->Driver.Enable( ctx, GL_POLYGON_STIPPLE, ctx->Polygon.StippleFlag ); - ctx->Driver.Enable( ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled ); - ctx->Driver.Enable( ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled ); - ctx->Driver.Enable( ctx, GL_TEXTURE_1D, GL_FALSE ); - ctx->Driver.Enable( ctx, GL_TEXTURE_2D, GL_FALSE ); - ctx->Driver.Enable( ctx, GL_TEXTURE_RECTANGLE_NV, GL_FALSE ); - ctx->Driver.Enable( ctx, GL_TEXTURE_3D, GL_FALSE ); - ctx->Driver.Enable( ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE ); - - ctx->Driver.Fogfv( ctx, GL_FOG_COLOR, ctx->Fog.Color ); - 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.FrontFace( ctx, ctx->Polygon.FrontFace ); - - { - GLfloat f = (GLfloat)ctx->Light.Model.ColorControl; - ctx->Driver.LightModelfv( ctx, GL_LIGHT_MODEL_COLOR_CONTROL, &f ); - } - - ctx->Driver.LineWidth( ctx, ctx->Line.Width ); - ctx->Driver.LogicOpcode( ctx, ctx->Color.LogicOp ); - ctx->Driver.PointSize( ctx, ctx->Point.Size ); - ctx->Driver.PolygonStipple( ctx, (const GLubyte *)ctx->PolygonStipple ); - ctx->Driver.Scissor( ctx, ctx->Scissor.X, ctx->Scissor.Y, - ctx->Scissor.Width, ctx->Scissor.Height ); - ctx->Driver.ShadeModel( ctx, ctx->Light.ShadeModel ); - ctx->Driver.StencilFuncSeparate( ctx, GL_FRONT, - ctx->Stencil.Function[0], - ctx->Stencil.Ref[0], - ctx->Stencil.ValueMask[0] ); - ctx->Driver.StencilFuncSeparate( ctx, GL_BACK, - ctx->Stencil.Function[1], - ctx->Stencil.Ref[1], - ctx->Stencil.ValueMask[1] ); - ctx->Driver.StencilMaskSeparate( ctx, GL_FRONT, ctx->Stencil.WriteMask[0] ); - ctx->Driver.StencilMaskSeparate( ctx, GL_BACK, ctx->Stencil.WriteMask[1] ); - ctx->Driver.StencilOpSeparate( ctx, GL_FRONT, - ctx->Stencil.FailFunc[0], - ctx->Stencil.ZFailFunc[0], - ctx->Stencil.ZPassFunc[0]); - ctx->Driver.StencilOpSeparate( ctx, GL_BACK, - ctx->Stencil.FailFunc[1], - ctx->Stencil.ZFailFunc[1], - ctx->Stencil.ZPassFunc[1]); - - - /* XXX this isn't really needed */ - ctx->Driver.DrawBuffer( ctx, ctx->Color.DrawBuffer[0] ); -} diff --git a/src/mesa/drivers/dri/i915-tex/intel_tex.c b/src/mesa/drivers/dri/i915-tex/intel_tex.c deleted file mode 100644 index 8d957635763..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_tex.c +++ /dev/null @@ -1,298 +0,0 @@ -#include "texobj.h" -#include "intel_context.h" -#include "intel_mipmap_tree.h" -#include "intel_tex.h" - - -static GLboolean intelIsTextureResident(GLcontext *ctx, - struct gl_texture_object *texObj) -{ -#if 0 - struct intel_context *intel = intel_context(ctx); - struct intel_texture_object *intelObj = intel_texture_object(texObj); - - return - intelObj->mt && - intelObj->mt->region && - intel_is_region_resident(intel, intelObj->mt->region); -#endif - return 1; -} - - - -static struct gl_texture_image *intelNewTextureImage( GLcontext *ctx ) -{ - (void) ctx; - return (struct gl_texture_image *)CALLOC_STRUCT(intel_texture_image); -} - - -static struct gl_texture_object *intelNewTextureObject( GLcontext *ctx, - GLuint name, - GLenum target ) -{ - struct intel_texture_object *obj = CALLOC_STRUCT(intel_texture_object); - - _mesa_initialize_texture_object(&obj->base, name, target); - - return &obj->base; -} - - -static void intelFreeTextureImageData( GLcontext *ctx, - struct gl_texture_image *texImage ) -{ - struct intel_context *intel = intel_context(ctx); - struct intel_texture_image *intelImage = intel_texture_image(texImage); - - if (intelImage->mt) { - intel_miptree_release(intel, &intelImage->mt); - } - - if (texImage->Data) { - free(texImage->Data); - texImage->Data = NULL; - } -} - - -#ifndef __x86_64__ -static unsigned -fastrdtsc(void) -{ - unsigned eax; - __asm__ volatile ("\t" - "pushl %%ebx\n\t" - "cpuid\n\t" ".byte 0x0f, 0x31\n\t" "popl %%ebx\n":"=a" (eax) - :"0"(0) - :"ecx", "edx", "cc"); - - return eax; -} -#else -static unsigned -fastrdtsc(void) -{ - unsigned eax; - __asm__ volatile ("\t" - "cpuid\n\t" ".byte 0x0f, 0x31\n\t" :"=a" (eax) - :"0"(0) - :"ecx", "edx", "ebx", "cc"); - - return eax; -} -#endif - -static unsigned -time_diff(unsigned t, unsigned t2) -{ - return ((t < t2) ? t2 - t : 0xFFFFFFFFU - (t - t2 - 1)); -} - - -/* The system memcpy (at least on ubuntu 5.10) has problems copying - * to agp (writecombined) memory from a source which isn't 64-byte - * aligned - there is a 4x performance falloff. - * - * The x86 __memcpy is immune to this but is slightly slower - * (10%-ish) than the system memcpy. - * - * The sse_memcpy seems to have a slight cliff at 64/32 bytes, but - * isn't much faster than x86_memcpy for agp copies. - * - * TODO: switch dynamically. - */ -static void *do_memcpy( void *dest, const void *src, size_t n ) -{ -<<<<<<< intel_tex.c - - if (!image || !image->Data) - return; - - if (image->Depth == 1 && image->IsClientData) { - if (INTEL_DEBUG & DEBUG_TEXTURE) - fprintf(stderr, "Blit uploading\n"); - - /* Do it with a blit. - */ - intelEmitCopyBlitLocked( intel, - image->TexFormat->TexelBytes, - image->RowStride, /* ? */ - intelGetMemoryOffsetMESA( NULL, 0, image->Data ), - t->Pitch / image->TexFormat->TexelBytes, - intelGetMemoryOffsetMESA( NULL, 0, t->BufAddr + offset ), - 0, 0, - 0, 0, - image->Width, - image->Height); - } - else if (image->IsCompressed) { - GLuint row_len = image->Width * 2; - GLubyte *dst = (GLubyte *)(t->BufAddr + offset); - GLubyte *src = (GLubyte *)image->Data; - GLuint j; - - if (INTEL_DEBUG & DEBUG_TEXTURE) - fprintf(stderr, - "Upload image %dx%dx%d offset %xm row_len %x " - "pitch %x depth_pitch %x\n", - image->Width, image->Height, image->Depth, offset, - row_len, t->Pitch, t->depth_pitch); - - switch (image->InternalFormat) { - case GL_COMPRESSED_RGB_FXT1_3DFX: - case GL_COMPRESSED_RGBA_FXT1_3DFX: - case GL_RGB_S3TC: - case GL_RGB4_S3TC: - case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - for (j = 0 ; j < image->Height/4 ; j++, dst += (t->Pitch)) { - __memcpy(dst, src, row_len ); - src += row_len; - } - break; - case GL_RGBA_S3TC: - case GL_RGBA4_S3TC: - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - for (j = 0 ; j < image->Height/4 ; j++, dst += (t->Pitch)) { - __memcpy(dst, src, (image->Width*4) ); - src += image->Width*4; - } - break; - default: - fprintf(stderr,"Internal Compressed format not supported %d\n", image->InternalFormat); - break; - } - } - /* Time for another vtbl entry: - */ - else if (intel->intelScreen->deviceID == PCI_CHIP_I945_G || - intel->intelScreen->deviceID == PCI_CHIP_I945_GM) { - GLuint row_len = image->Width * image->TexFormat->TexelBytes; - GLubyte *dst = (GLubyte *)(t->BufAddr + offset); - GLubyte *src = (GLubyte *)image->Data; - GLuint d, j; - - if (INTEL_DEBUG & DEBUG_TEXTURE) - fprintf(stderr, - "Upload image %dx%dx%d offset %xm row_len %x " - "pitch %x depth_pitch %x\n", - image->Width, image->Height, image->Depth, offset, - row_len, t->Pitch, t->depth_pitch); - - if (row_len == t->Pitch) { - memcpy( dst, src, row_len * image->Height * image->Depth ); - } - else { - GLuint x = 0, y = 0; - - for (d = 0 ; d < image->Depth ; d++) { - GLubyte *dst0 = dst + x + y * t->Pitch; - - for (j = 0 ; j < image->Height ; j++) { - __memcpy(dst0, src, row_len ); - src += row_len; - dst0 += t->Pitch; - } - - x += MIN2(4, row_len); /* Guess: 4 byte minimum alignment */ - if (x > t->Pitch) { - x = 0; - y += image->Height; - } - } - } - - } - else { - GLuint row_len = image->Width * image->TexFormat->TexelBytes; - GLubyte *dst = (GLubyte *)(t->BufAddr + offset); - GLubyte *src = (GLubyte *)image->Data; - GLuint d, j; - - if (INTEL_DEBUG & DEBUG_TEXTURE) - fprintf(stderr, - "Upload image %dx%dx%d offset %xm row_len %x " - "pitch %x depth_pitch %x\n", - image->Width, image->Height, image->Depth, offset, - row_len, t->Pitch, t->depth_pitch); - - if (row_len == t->Pitch) { - for (d = 0; d < image->Depth; d++) { - memcpy( dst, src, t->Pitch * image->Height ); - dst += t->depth_pitch; - src += row_len * image->Height; - } - } - else { - for (d = 0 ; d < image->Depth ; d++) { - for (j = 0 ; j < image->Height ; j++) { - __memcpy(dst, src, row_len ); - src += row_len; - dst += t->Pitch; - } - - dst += t->depth_pitch - (t->Pitch * image->Height); - } - } - } -======= - if ( (((unsigned)src) & 63) || - (((unsigned)dest) & 63)) { - return __memcpy(dest, src, n); - } - else - return memcpy(dest, src, n); ->>>>>>> 1.10.2.8 -} - - -static void *timed_memcpy( void *dest, const void *src, size_t n ) -{ - void *ret; - unsigned t1, t2; - double rate; - - if ( (((unsigned)src) & 63) || - (((unsigned)dest) & 63)) - _mesa_printf("Warning - non-aligned texture copy!\n"); - - t1 = fastrdtsc(); - ret = do_memcpy(dest, src, n); - t2 = fastrdtsc(); - - rate = time_diff(t1, t2); - rate /= (double) n; - _mesa_printf("timed_memcpy: %u %u --> %f clocks/byte\n", t1, t2, rate); - return ret; -} - - -void intelInitTextureFuncs(struct dd_function_table * functions) -{ - functions->ChooseTextureFormat = intelChooseTextureFormat; - functions->TexImage1D = intelTexImage1D; - functions->TexImage2D = intelTexImage2D; - functions->TexImage3D = intelTexImage3D; - functions->TexSubImage1D = intelTexSubImage1D; - functions->TexSubImage2D = intelTexSubImage2D; - functions->TexSubImage3D = intelTexSubImage3D; - functions->CopyTexImage1D = intelCopyTexImage1D; - functions->CopyTexImage2D = intelCopyTexImage2D; - functions->CopyTexSubImage1D = intelCopyTexSubImage1D; - functions->CopyTexSubImage2D = intelCopyTexSubImage2D; - functions->GetTexImage = intelGetTexImage; - functions->NewTextureObject = intelNewTextureObject; - functions->NewTextureImage = intelNewTextureImage; - functions->DeleteTexture = _mesa_delete_texture_object; - functions->FreeTexImageData = intelFreeTextureImageData; - functions->UpdateTexturePalette = 0; - functions->IsTextureResident = intelIsTextureResident; - - if (INTEL_DEBUG & DEBUG_BUFMGR) - functions->TextureMemCpy = timed_memcpy; - else - functions->TextureMemCpy = do_memcpy; -} diff --git a/src/mesa/drivers/dri/i915-tex/intel_tex.h b/src/mesa/drivers/dri/i915-tex/intel_tex.h deleted file mode 100644 index ddc8c7aab3e..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_tex.h +++ /dev/null @@ -1,139 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#ifndef INTELTEX_INC -#define INTELTEX_INC - -#include "mtypes.h" -#include "intel_context.h" -#include "texmem.h" - - -void intelInitTextureFuncs( struct dd_function_table *functions ); - -const struct gl_texture_format * -intelChooseTextureFormat( GLcontext *ctx, GLint internalFormat, - GLenum format, GLenum type ); - - -void intelTexImage3D(GLcontext *ctx, - GLenum target, GLint level, - GLint internalFormat, - GLint width, GLint height, GLint depth, - GLint border, - GLenum format, GLenum type, const void *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage); - -void intelTexSubImage3D(GLcontext *ctx, - GLenum target, - GLint level, - GLint xoffset, GLint yoffset, GLint zoffset, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage); - -void intelTexImage2D(GLcontext *ctx, - GLenum target, GLint level, - GLint internalFormat, - GLint width, GLint height, GLint border, - GLenum format, GLenum type, const void *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage); - -void intelTexSubImage2D(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 intelTexImage1D(GLcontext *ctx, - GLenum target, GLint level, - GLint internalFormat, - GLint width, GLint border, - GLenum format, GLenum type, const void *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage); - -void intelTexSubImage1D(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 intelCopyTexImage1D( GLcontext *ctx, GLenum target, GLint level, - GLenum internalFormat, - GLint x, GLint y, GLsizei width, - GLint border ); - -void intelCopyTexImage2D( GLcontext *ctx, GLenum target, GLint level, - GLenum internalFormat, - GLint x, GLint y, GLsizei width, GLsizei height, - GLint border ); - -void intelCopyTexSubImage1D( GLcontext *ctx, GLenum target, GLint level, - GLint xoffset, - GLint x, GLint y, GLsizei width ); - -void intelCopyTexSubImage2D( GLcontext *ctx, GLenum target, GLint level, - GLint xoffset, GLint yoffset, - GLint x, GLint y, GLsizei width, GLsizei height ); - -void intelGetTexImage( GLcontext *ctx, GLenum target, GLint level, - GLenum format, GLenum type, GLvoid *pixels, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage ); - -GLuint intel_finalize_mipmap_tree( struct intel_context *intel, GLuint unit ); - -void intel_tex_map_images( struct intel_context *intel, - struct intel_texture_object *intelObj ); - -void intel_tex_unmap_images( struct intel_context *intel, - struct intel_texture_object *intelObj ); - - -GLboolean -intel_driReinitTextureHeap( driTexHeap *heap, - unsigned size ); -#endif diff --git a/src/mesa/drivers/dri/i915-tex/intel_tex_copy.c b/src/mesa/drivers/dri/i915-tex/intel_tex_copy.c deleted file mode 100644 index aa3dd198e29..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_tex_copy.c +++ /dev/null @@ -1,296 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "mtypes.h" -#include "enums.h" -#include "image.h" -#include "teximage.h" -#include "swrast/swrast.h" - -#include "intel_screen.h" -#include "intel_context.h" -#include "intel_batchbuffer.h" -#include "intel_buffers.h" -#include "intel_mipmap_tree.h" -#include "intel_regions.h" -#include "intel_fbo.h" -#include "intel_tex.h" -#include "intel_blit.h" -#include "intel_pixel.h" -#include "intel_bufmgr.h" - - -/** - * Get the intel_region which is the source for any glCopyTex[Sub]Image call. - * - * Do the best we can using the blitter. A future project is to use - * the texture engine and fragment programs for these copies. - */ -static const struct intel_region * -get_teximage_source(struct intel_context *intel, GLenum internalFormat) -{ - struct intel_renderbuffer *irb; - - if (0) - _mesa_printf("%s %s\n", __FUNCTION__, - _mesa_lookup_enum_by_nr(internalFormat)); - - switch (internalFormat) { - case GL_DEPTH_COMPONENT: - case GL_DEPTH_COMPONENT16_ARB: - irb = intel_get_renderbuffer(intel->ctx.ReadBuffer, BUFFER_DEPTH); - if (irb && irb->region && irb->region->cpp == 2) - return irb->region; - return NULL; - case GL_DEPTH24_STENCIL8_EXT: - case GL_DEPTH_STENCIL_EXT: - irb = intel_get_renderbuffer(intel->ctx.ReadBuffer, BUFFER_DEPTH); - if (irb && irb->region && irb->region->cpp == 4) - return irb->region; - return NULL; - case GL_RGBA: - return intel_readbuf_region( intel ); - case GL_RGB: - if (intel->intelScreen->cpp == 2) - return intel_readbuf_region( intel ); - return NULL; - default: - return NULL; - } -} - - -static GLboolean do_copy_texsubimage( struct intel_context *intel, - struct intel_texture_image *intelImage, - GLenum internalFormat, - GLint dstx, GLint dsty, - GLint x, GLint y, - GLsizei width, GLsizei height ) -{ - GLcontext *ctx = &intel->ctx; - const struct intel_region *src = get_teximage_source(intel, internalFormat); - - if (!intelImage->mt || !src) - return GL_FALSE; - - intelFlush(ctx); - LOCK_HARDWARE(intel); - { - GLuint image_offset = intel_miptree_image_offset(intelImage->mt, - intelImage->face, - intelImage->level); - const GLint orig_x = x; - const GLint orig_y = y; - const struct gl_framebuffer *fb = ctx->DrawBuffer; - - if (_mesa_clip_to_region(fb->_Xmin, fb->_Ymin, fb->_Xmax, fb->_Ymax, - &x, &y, &width, &height)) { - /* Update dst for clipped src. Need to also clip the source rect. - */ - dstx += x - orig_x; - dsty += y - orig_y; - - if (ctx->ReadBuffer->Name == 0) { - /* reading from a window, adjust x, y */ - __DRIdrawablePrivate *dPriv = intel->driDrawable; - GLuint window_y; - /* window_y = position of window on screen if y=0=bottom */ - window_y = intel->intelScreen->height - (dPriv->y + dPriv->h); - y = window_y + y; - x += dPriv->x; - } - else { - /* reading from a FBO */ - /* invert Y */ - y = ctx->ReadBuffer->Height - y - 1; - } - - - /* A bit of fiddling to get the blitter to work with -ve - * pitches. But we get a nice inverted blit this way, so it's - * worth it: - */ - intelEmitCopyBlit( intel, - intelImage->mt->cpp, - - -src->pitch, - src->buffer, - src->height * src->pitch * src->cpp, - - intelImage->mt->pitch, - intelImage->mt->region->buffer, - image_offset, - - x, y + height, - dstx, dsty, - width, height ); - - intel_batchbuffer_flush( intel->batch ); - } - } - - - UNLOCK_HARDWARE(intel); - -#if 0 - /* GL_SGIS_generate_mipmap -- this can be accelerated now. - * XXX Add a ctx->Driver.GenerateMipmaps() function? - */ - if (level == texObj->BaseLevel && - texObj->GenerateMipmap) { - intel_generate_mipmap(ctx, target, - &ctx->Texture.Unit[ctx->Texture.CurrentUnit], - texObj); - } -#endif - - return GL_TRUE; -} - - - - - -void intelCopyTexImage1D( GLcontext *ctx, GLenum target, GLint level, - GLenum internalFormat, - GLint x, GLint y, GLsizei width, - GLint border ) -{ - struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; - struct gl_texture_object *texObj = _mesa_select_tex_object(ctx, texUnit, target); - struct gl_texture_image *texImage = _mesa_select_tex_image(ctx, texUnit, target, level); - - if (border) - goto fail; - - /* Setup or redefine the texture object, mipmap tree and texture - * image. Don't populate yet. - */ - ctx->Driver.TexImage1D(ctx, target, level, internalFormat, - width, border, - GL_RGBA, CHAN_TYPE, NULL, - &ctx->DefaultPacking, texObj, texImage); - - if (!do_copy_texsubimage(intel_context(ctx), - intel_texture_image(texImage), - internalFormat, - 0, 0, - x, y, - width, 1)) - goto fail; - - return; - - fail: - _swrast_copy_teximage1d( ctx, target, level, internalFormat, x, y, - width, border ); -} - -void intelCopyTexImage2D( GLcontext *ctx, GLenum target, GLint level, - GLenum internalFormat, - GLint x, GLint y, GLsizei width, GLsizei height, - GLint border ) -{ - struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; - struct gl_texture_object *texObj = _mesa_select_tex_object(ctx, texUnit, target); - struct gl_texture_image *texImage = _mesa_select_tex_image(ctx, texUnit, target, level); - - if (border) - goto fail; - - /* Setup or redefine the texture object, mipmap tree and texture - * image. Don't populate yet. - */ - ctx->Driver.TexImage2D(ctx, target, level, internalFormat, - width, height, border, - GL_RGBA, CHAN_TYPE, NULL, - &ctx->DefaultPacking, texObj, texImage); - - - if (!do_copy_texsubimage(intel_context(ctx), - intel_texture_image(texImage), - internalFormat, - 0, 0, - x, y, - width, height)) - goto fail; - - return; - - fail: - _swrast_copy_teximage2d( ctx, target, level, internalFormat, x, y, - width, height, border ); -} - - -void intelCopyTexSubImage1D( GLcontext *ctx, GLenum target, GLint level, - GLint xoffset, - GLint x, GLint y, GLsizei width ) -{ - struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; - struct gl_texture_image *texImage = _mesa_select_tex_image(ctx, texUnit, target, level); - GLenum internalFormat = texImage->InternalFormat; - - /* XXX need to check <border> as in above function? */ - - /* Need to check texture is compatible with source format. - */ - - if (!do_copy_texsubimage(intel_context(ctx), - intel_texture_image(texImage), - internalFormat, - xoffset, 0, - x, y, width, 1)) { - _swrast_copy_texsubimage1d( ctx, target, level, - xoffset, x, y, width ); - } -} - - - -void intelCopyTexSubImage2D( GLcontext *ctx, GLenum target, GLint level, - GLint xoffset, GLint yoffset, - GLint x, GLint y, GLsizei width, GLsizei height ) -{ - struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; - struct gl_texture_image *texImage = _mesa_select_tex_image(ctx, texUnit, target, level); - GLenum internalFormat = texImage->InternalFormat; - - - /* Need to check texture is compatible with source format. - */ - - if (!do_copy_texsubimage(intel_context(ctx), - intel_texture_image(texImage), - internalFormat, - xoffset, yoffset, - x, y, width, height)) { - _swrast_copy_texsubimage2d( ctx, target, level, - xoffset, yoffset, - x, y, width, height ); - } -} diff --git a/src/mesa/drivers/dri/i915-tex/intel_tex_format.c b/src/mesa/drivers/dri/i915-tex/intel_tex_format.c deleted file mode 100644 index ff02239e588..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_tex_format.c +++ /dev/null @@ -1,148 +0,0 @@ -#include "intel_context.h" -#include "intel_tex.h" -#include "texformat.h" -#include "enums.h" - -/* It works out that this function is fine for all the supported - * hardware. However, there is still a need to map the formats onto - * hardware descriptors. - */ -/* Note that the i915 can actually support many more formats than - * these if we take the step of simply swizzling the colors - * immediately after sampling... - */ -const struct gl_texture_format * -intelChooseTextureFormat( GLcontext *ctx, GLint internalFormat, - GLenum format, GLenum type ) -{ - struct intel_context *intel = intel_context( ctx ); - const GLboolean do32bpt = (intel->intelScreen->cpp == 4); - - switch ( internalFormat ) { - case 4: - case GL_RGBA: - case GL_COMPRESSED_RGBA: - if ( format == GL_BGRA ) { - if ( type == GL_UNSIGNED_INT_8_8_8_8_REV ) { - return &_mesa_texformat_argb8888; - } - else if ( type == GL_UNSIGNED_SHORT_4_4_4_4_REV ) { - return &_mesa_texformat_argb4444; - } - else if ( type == GL_UNSIGNED_SHORT_1_5_5_5_REV ) { - return &_mesa_texformat_argb1555; - } - } - return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444; - - case 3: - case GL_RGB: - case GL_COMPRESSED_RGB: - if ( format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5 ) { - return &_mesa_texformat_rgb565; - } - return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_rgb565; - - case GL_RGBA8: - case GL_RGB10_A2: - case GL_RGBA12: - case GL_RGBA16: - return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444; - - case GL_RGBA4: - case GL_RGBA2: - return &_mesa_texformat_argb4444; - - case GL_RGB5_A1: - return &_mesa_texformat_argb1555; - - case GL_RGB8: - case GL_RGB10: - case GL_RGB12: - case GL_RGB16: - return &_mesa_texformat_argb8888; - - case GL_RGB5: - case GL_RGB4: - case GL_R3_G3_B2: - return &_mesa_texformat_rgb565; - - case GL_ALPHA: - case GL_ALPHA4: - case GL_ALPHA8: - case GL_ALPHA12: - case GL_ALPHA16: - case GL_COMPRESSED_ALPHA: - return &_mesa_texformat_a8; - - case 1: - case GL_LUMINANCE: - case GL_LUMINANCE4: - case GL_LUMINANCE8: - case GL_LUMINANCE12: - case GL_LUMINANCE16: - case GL_COMPRESSED_LUMINANCE: - return &_mesa_texformat_l8; - - 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: - case GL_COMPRESSED_LUMINANCE_ALPHA: - return &_mesa_texformat_al88; - - case GL_INTENSITY: - case GL_INTENSITY4: - case GL_INTENSITY8: - case GL_INTENSITY12: - case GL_INTENSITY16: - case GL_COMPRESSED_INTENSITY: - return &_mesa_texformat_i8; - - case GL_YCBCR_MESA: - if (type == GL_UNSIGNED_SHORT_8_8_MESA || - type == GL_UNSIGNED_BYTE) - return &_mesa_texformat_ycbcr; - else - return &_mesa_texformat_ycbcr_rev; - - case GL_COMPRESSED_RGB_FXT1_3DFX: - return &_mesa_texformat_rgb_fxt1; - case GL_COMPRESSED_RGBA_FXT1_3DFX: - return &_mesa_texformat_rgba_fxt1; - - case GL_RGB_S3TC: - case GL_RGB4_S3TC: - case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: - return &_mesa_texformat_rgb_dxt1; - - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - return &_mesa_texformat_rgba_dxt1; - - case GL_RGBA_S3TC: - case GL_RGBA4_S3TC: - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - return &_mesa_texformat_rgba_dxt3; - - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - return &_mesa_texformat_rgba_dxt5; - - case GL_DEPTH_COMPONENT: - case GL_DEPTH_COMPONENT16: - case GL_DEPTH_COMPONENT24: - case GL_DEPTH_COMPONENT32: - return &_mesa_texformat_depth_component16; - - default: - fprintf(stderr, "unexpected texture format %s in %s\n", - _mesa_lookup_enum_by_nr(internalFormat), - __FUNCTION__); - return NULL; - } - - return NULL; /* never get here */ -} diff --git a/src/mesa/drivers/dri/i915-tex/intel_tex_image.c b/src/mesa/drivers/dri/i915-tex/intel_tex_image.c deleted file mode 100644 index 3a437adbf00..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_tex_image.c +++ /dev/null @@ -1,440 +0,0 @@ - -#include <stdlib.h> -#include <stdio.h> - -#include "glheader.h" -#include "macros.h" -#include "mtypes.h" -#include "enums.h" -#include "colortab.h" -#include "convolve.h" -#include "context.h" -#include "simple_list.h" -#include "texcompress.h" -#include "texformat.h" -#include "texobj.h" -#include "texstore.h" - -#include "intel_context.h" -#include "intel_mipmap_tree.h" -#include "intel_tex.h" -#include "intel_ioctl.h" - - -/* Functions to store texture images. Where possible, mipmap_tree's - * will be created or further instantiated with image data, otherwise - * images will be stored in malloc'd memory. A validation step is - * required to pull those images into a mipmap tree, or otherwise - * decide a fallback is required. - */ - - -static int logbase2(int n) -{ - GLint i = 1; - GLint log2 = 0; - - while (n > i) { - i *= 2; - log2++; - } - - return log2; -} - - -/* Otherwise, store it in memory if (Border != 0) or (any dimension == - * 1). - * - * Otherwise, if max_level >= level >= min_level, create tree with - * space for textures from min_level down to max_level. - * - * Otherwise, create tree with space for textures from (level - * 0)..(1x1). Consider pruning this tree at a validation if the - * saving is worth it. - */ -static void guess_and_alloc_mipmap_tree( struct intel_context *intel, - struct intel_texture_object *intelObj, - struct intel_texture_image *intelImage ) -{ - GLuint firstLevel; - GLuint lastLevel; - GLuint width = intelImage->base.Width; - GLuint height = intelImage->base.Height; - GLuint depth = intelImage->base.Depth; - GLuint l2width, l2height, l2depth; - GLuint i; - - DBG("%s\n", __FUNCTION__); - - if (intelImage->base.Border) - return; - - if (intelImage->level > intelObj->base.BaseLevel && - (intelImage->base.Width == 1 || - (intelObj->base.Target != GL_TEXTURE_1D && - intelImage->base.Height == 1) || - (intelObj->base.Target == GL_TEXTURE_3D && - intelImage->base.Depth == 1))) - return; - - /* If this image disrespects BaseLevel, allocate from level zero. - * Usually BaseLevel == 0, so it's unlikely to happen. - */ - if (intelImage->level < intelObj->base.BaseLevel) - firstLevel = 0; - else - firstLevel = intelObj->base.BaseLevel; - - - /* Figure out image dimensions at start level. - */ - for (i = intelImage->level; i > firstLevel; i--) { - width <<= 1; - if (height != 1) height <<= 1; - if (depth != 1) depth <<= 1; - } - - /* Guess a reasonable value for lastLevel. This is probably going - * to be wrong fairly often and might mean that we have to look at - * resizable buffers, or require that buffers implement lazy - * pagetable arrangements. - */ - if ((intelObj->base.MinFilter == GL_NEAREST || - intelObj->base.MinFilter == GL_LINEAR) && - intelImage->level == firstLevel) { - lastLevel = firstLevel; - } - else { - l2width = logbase2(width); - l2height = logbase2(height); - l2depth = logbase2(depth); - lastLevel = firstLevel + MAX2(MAX2(l2width,l2height),l2depth); - } - - assert(!intelObj->mt); - intelObj->mt = intel_miptree_create( intel, - intelObj->base.Target, - intelImage->base.InternalFormat, - firstLevel, - lastLevel, - width, - height, - depth, - intelImage->base.TexFormat->TexelBytes, - intelImage->base.IsCompressed ); - - DBG("%s - success\n", __FUNCTION__); -} - - - - -static GLuint target_to_face( GLenum target ) -{ - switch (target) { - case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: - return ((GLuint) target - - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X); - default: - return 0; - } -} - - -static void intelTexImage(GLcontext *ctx, - GLint dims, - GLenum target, GLint level, - GLint internalFormat, - GLint width, GLint height, GLint depth, - GLint border, - GLenum format, GLenum type, const void *pixels, - const struct gl_pixelstore_attrib *unpack, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage) -{ - struct intel_context *intel = intel_context(ctx); - struct intel_texture_object *intelObj = intel_texture_object(texObj); - struct intel_texture_image *intelImage = intel_texture_image(texImage); - GLint postConvWidth = width; - GLint postConvHeight = height; - GLint texelBytes, sizeInBytes; - GLuint dstRowStride; - GLuint dstImageStride; - - - DBG("%s target %s level %d %dx%dx%d border %d\n", __FUNCTION__, - _mesa_lookup_enum_by_nr(target), - level, - width, height, depth, border); - - intelFlush(ctx); - - intelImage->face = target_to_face( target ); - intelImage->level = level; - - if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) { - _mesa_adjust_image_for_convolution(ctx, dims, &postConvWidth, - &postConvHeight); - } - - /* choose the texture format */ - texImage->TexFormat = intelChooseTextureFormat(ctx, internalFormat, - format, type); - - assert(texImage->TexFormat); - - switch (dims) { - case 1: - texImage->FetchTexelc = texImage->TexFormat->FetchTexel1D; - texImage->FetchTexelf = texImage->TexFormat->FetchTexel1Df; - break; - case 2: - texImage->FetchTexelc = texImage->TexFormat->FetchTexel2D; - texImage->FetchTexelf = texImage->TexFormat->FetchTexel2Df; - break; - case 3: - texImage->FetchTexelc = texImage->TexFormat->FetchTexel3D; - texImage->FetchTexelf = texImage->TexFormat->FetchTexel3Df; - break; - default: - assert(0); - break; - } - - texelBytes = texImage->TexFormat->TexelBytes; - - - /* Minimum pitch of 32 bytes */ - if (postConvWidth * texelBytes < 32) { - postConvWidth = 32 / texelBytes; - texImage->RowStride = postConvWidth; - } - - assert(texImage->RowStride == postConvWidth); - - /* Release the reference to a potentially orphaned buffer. - * Release any old malloced memory. - */ - if (intelImage->mt) { - intel_miptree_release(intel, &intelImage->mt); - assert(!texImage->Data); - } - else if (texImage->Data) { - free(texImage->Data); - } - - /* If this is the only texture image in the tree, could call - * bmBufferData with NULL data to free the old block and avoid - * waiting on any outstanding fences. - */ - if (intelObj->mt && - intelObj->mt->first_level == level && - intelObj->mt->last_level == level && - intelObj->mt->target != GL_TEXTURE_CUBE_MAP_ARB && - !intel_miptree_match_image(intelObj->mt, &intelImage->base, - intelImage->face, intelImage->level)) { - - DBG("release it\n"); - intel_miptree_release(intel, &intelObj->mt); - assert(!intelObj->mt); - } - - if (!intelObj->mt) { - guess_and_alloc_mipmap_tree(intel, intelObj, intelImage); - if (!intelObj->mt) - _mesa_printf("guess_and_alloc_mipmap_tree: failed\n"); - } - - - if (intelObj->mt && - intelObj->mt != intelImage->mt && - intel_miptree_match_image(intelObj->mt, &intelImage->base, - intelImage->face, intelImage->level)) { - - if (intelImage->mt) { - intel_miptree_release(intel, &intelImage->mt); - } - - intel_miptree_reference(&intelImage->mt, intelObj->mt); - assert(intelImage->mt); - } - - if (!intelImage->mt) - _mesa_printf("XXX: Image did not fit into tree - storing in local memory!\n"); - - /* intelCopyTexImage calls this function with pixels == NULL, with - * the expectation that the mipmap tree will be set up but nothing - * more will be done. This is where those calls return: - */ - pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, 1, - format, type, - pixels, unpack, "glTexImage"); - if (!pixels) - return; - - - LOCK_HARDWARE(intel); - - if (intelImage->mt) { - texImage->Data = intel_miptree_image_map(intel, - intelImage->mt, - intelImage->face, - intelImage->level, - &dstRowStride, - &dstImageStride); - } - else { - /* Allocate regular memory and store the image there temporarily. */ - if (texImage->IsCompressed) { - sizeInBytes = texImage->CompressedSize; - dstRowStride = _mesa_compressed_row_stride(texImage->InternalFormat,width); - dstImageStride = 0; /* ? */ - assert(dims != 3); - } - else { - dstRowStride = postConvWidth * texelBytes; - dstImageStride = dstRowStride * postConvHeight; - sizeInBytes = depth * dstImageStride; - } - texImage->Data = malloc(sizeInBytes); - } - - if (INTEL_DEBUG & DEBUG_TEXTURE) - _mesa_printf("Upload image %dx%dx%d row_len %x " - "pitch %x depth_pitch %x\n", - width, height, depth, - width * texelBytes, dstRowStride, dstImageStride); - - /* Copy data. Would like to know when it's ok for us to eg. use - * the blitter to copy. Or, use the hardware to do the format - * conversion and copy: - */ - if (!texImage->TexFormat->StoreImage(ctx, dims, - texImage->_BaseFormat, - texImage->TexFormat, - texImage->Data, - 0, 0, 0, /* dstX/Y/Zoffset */ - dstRowStride, dstImageStride, - width, height, depth, - format, type, pixels, unpack)) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); - } - - _mesa_unmap_teximage_pbo(ctx, unpack); - - if (intelImage->mt) { - intel_miptree_image_unmap(intel, intelImage->mt); - texImage->Data = NULL; - } - - UNLOCK_HARDWARE(intel); - -#if 0 - /* GL_SGIS_generate_mipmap -- this can be accelerated now. - */ - if (level == texObj->BaseLevel && - texObj->GenerateMipmap) { - intel_generate_mipmap(ctx, target, - &ctx->Texture.Unit[ctx->Texture.CurrentUnit], - texObj); - } -#endif -} - -void intelTexImage3D(GLcontext *ctx, - GLenum target, GLint level, - GLint internalFormat, - GLint width, GLint height, GLint depth, - GLint border, - GLenum format, GLenum type, const void *pixels, - const struct gl_pixelstore_attrib *unpack, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage) -{ - intelTexImage( ctx, 3, target, level, - internalFormat, width, height, depth, border, - format, type, pixels, - unpack, texObj, texImage ); -} - - -void intelTexImage2D(GLcontext *ctx, - GLenum target, GLint level, - GLint internalFormat, - GLint width, GLint height, GLint border, - GLenum format, GLenum type, const void *pixels, - const struct gl_pixelstore_attrib *unpack, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage) -{ - intelTexImage( ctx, 2, target, level, - internalFormat, width, height, 1, border, - format, type, pixels, - unpack, texObj, texImage ); -} - -void intelTexImage1D(GLcontext *ctx, - GLenum target, GLint level, - GLint internalFormat, - GLint width, GLint border, - GLenum format, GLenum type, const void *pixels, - const struct gl_pixelstore_attrib *unpack, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage) -{ - intelTexImage( ctx, 1, target, level, - internalFormat, width, 1, 1, border, - format, type, pixels, - unpack, texObj, texImage ); -} - - - -/** - * Need to map texture image into memory before copying image data, - * then unmap it. - */ -void intelGetTexImage( GLcontext *ctx, GLenum target, GLint level, - GLenum format, GLenum type, GLvoid *pixels, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage ) -{ - struct intel_context *intel = intel_context( ctx ); - struct intel_texture_image *intelImage = intel_texture_image(texImage); - - /* Map */ -#ifdef ALL_IMAGES /* XXX Remove this, just for debug/test */ - intel_tex_map_images(intel, intel_texture_object(texObj)); -#else - /* XXX what if intelImage->mt is NULL? */ - if (intelImage->mt) { - intelImage->base.Data = - intel_miptree_image_map(intel, - intelImage->mt, - intelImage->face, - intelImage->level, - &intelImage->base.RowStride, - &intelImage->base.ImageStride); - } -#endif - - _mesa_get_teximage(ctx, target, level, format, type, pixels, - texObj, texImage); - - /* Unmap */ -#ifdef ALL_IMAGES - intel_tex_unmap_images(intel, intel_texture_object(texObj)); -#else - if (intelImage->mt) { - intel_miptree_image_unmap(intel, intelImage->mt); - intelImage->base.Data = NULL; - } -#endif -} - diff --git a/src/mesa/drivers/dri/i915-tex/intel_tex_subimage.c b/src/mesa/drivers/dri/i915-tex/intel_tex_subimage.c deleted file mode 100644 index 5adf8599a45..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_tex_subimage.c +++ /dev/null @@ -1,178 +0,0 @@ - -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "mtypes.h" -#include "texobj.h" -#include "texstore.h" -#include "enums.h" - -#include "intel_context.h" -#include "intel_tex.h" -#include "intel_mipmap_tree.h" - - -static void intelTexSubimage (GLcontext *ctx, - GLint dims, - GLenum target, GLint level, - GLint xoffset, GLint yoffset, GLint zoffset, - GLint width, GLint height, GLint depth, - GLenum format, GLenum type, const void *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage) -{ - struct intel_context *intel = intel_context(ctx); - struct intel_texture_image *intelImage = intel_texture_image(texImage); - GLuint dstImageStride; - GLuint dstRowStride; - - DBG("%s target %s level %d offset %d,%d %dx%d\n", __FUNCTION__, - _mesa_lookup_enum_by_nr(target), - level, - xoffset, yoffset, - width, height); - - intelFlush(ctx); - - pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, depth, format, type, - pixels, packing, "glTexSubImage2D"); - if (!pixels) - return; - - LOCK_HARDWARE(intel); - - /* Map buffer if necessary. Need to lock to prevent other contexts - * from uploading the buffer under us. - */ - if (intelImage->mt) - texImage->Data = intel_miptree_image_map(intel, - intelImage->mt, - intelImage->face, - intelImage->level, - &dstRowStride, - &dstImageStride ); - - assert(dstRowStride); - - if (!texImage->TexFormat->StoreImage(ctx, dims, texImage->_BaseFormat, - texImage->TexFormat, - texImage->Data, - xoffset, yoffset, zoffset, - dstRowStride, dstImageStride, - width, height, depth, - format, type, pixels, packing)) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage"); - } - -#if 0 - /* GL_SGIS_generate_mipmap */ - if (level == texObj->BaseLevel && texObj->GenerateMipmap) { - _mesa_generate_mipmap(ctx, target, - &ctx->Texture.Unit[ctx->Texture.CurrentUnit], - texObj); - } -#endif - - _mesa_unmap_teximage_pbo(ctx, packing); - - if (intelImage->mt) { - intel_miptree_image_unmap(intel, intelImage->mt); - texImage->Data = NULL; - } - - UNLOCK_HARDWARE(intel); -} - - - - - -void intelTexSubImage3D(GLcontext *ctx, - GLenum target, - GLint level, - GLint xoffset, GLint yoffset, GLint zoffset, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage) -{ - - intelTexSubimage(ctx, 3, - target, level, - xoffset, yoffset, zoffset, - width, height, depth, - format, type, pixels, packing, texObj, - texImage); - -} - - - -void intelTexSubImage2D(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) -{ - - intelTexSubimage(ctx, 2, - target, level, - xoffset, yoffset, 0, - width, height, 1, - format, type, pixels, packing, texObj, - texImage); - -} - - -void intelTexSubImage1D(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) -{ - intelTexSubimage(ctx, 1, - target, level, - xoffset, 0, 0, - width, 1, 1, - format, type, pixels, packing, texObj, - texImage); - -} diff --git a/src/mesa/drivers/dri/i915-tex/intel_tex_validate.c b/src/mesa/drivers/dri/i915-tex/intel_tex_validate.c deleted file mode 100644 index 72f5afb13e5..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_tex_validate.c +++ /dev/null @@ -1,247 +0,0 @@ -#include "mtypes.h" -#include "macros.h" - -#include "intel_context.h" -#include "intel_mipmap_tree.h" -#include "intel_tex.h" -#include "intel_bufmgr.h" - -/** - * Compute which mipmap levels that really need to be sent to the hardware. - * This depends on the base image size, GL_TEXTURE_MIN_LOD, - * GL_TEXTURE_MAX_LOD, GL_TEXTURE_BASE_LEVEL, and GL_TEXTURE_MAX_LEVEL. - */ -static void intel_calculate_first_last_level( struct intel_texture_object *intelObj ) -{ - struct gl_texture_object *tObj = &intelObj->base; - const struct gl_texture_image * const baseImage = - tObj->Image[0][tObj->BaseLevel]; - - /* These must be signed values. MinLod and MaxLod can be negative numbers, - * and having firstLevel and lastLevel as signed prevents the need for - * extra sign checks. - */ - int firstLevel; - int lastLevel; - - /* Yes, this looks overly complicated, but it's all needed. - */ - switch (tObj->Target) { - case GL_TEXTURE_1D: - case GL_TEXTURE_2D: - case GL_TEXTURE_3D: - case GL_TEXTURE_CUBE_MAP: - if (tObj->MinFilter == GL_NEAREST || tObj->MinFilter == GL_LINEAR) { - /* GL_NEAREST and GL_LINEAR only care about GL_TEXTURE_BASE_LEVEL. - */ - firstLevel = lastLevel = tObj->BaseLevel; - } - else { - firstLevel = tObj->BaseLevel + (GLint)(tObj->MinLod + 0.5); - firstLevel = MAX2(firstLevel, tObj->BaseLevel); - lastLevel = tObj->BaseLevel + (GLint)(tObj->MaxLod + 0.5); - lastLevel = MAX2(lastLevel, tObj->BaseLevel); - lastLevel = MIN2(lastLevel, tObj->BaseLevel + baseImage->MaxLog2); - lastLevel = MIN2(lastLevel, tObj->MaxLevel); - lastLevel = MAX2(firstLevel, lastLevel); /* need at least one level */ - } - break; - case GL_TEXTURE_RECTANGLE_NV: - case GL_TEXTURE_4D_SGIS: - firstLevel = lastLevel = 0; - break; - default: - return; - } - - /* save these values */ - intelObj->firstLevel = firstLevel; - intelObj->lastLevel = lastLevel; -} - -static void copy_image_data_to_tree( struct intel_context *intel, - struct intel_texture_object *intelObj, - struct intel_texture_image *intelImage ) -{ - if (intelImage->mt) { - /* Copy potentially with the blitter: - */ - intel_miptree_image_copy(intel, - intelObj->mt, - intelImage->face, - intelImage->level, - intelImage->mt); - - intel_miptree_release(intel, &intelImage->mt); - } - else { - assert(intelImage->base.Data != NULL); - - /* More straightforward upload. - */ - intel_miptree_image_data(intel, - intelObj->mt, - intelImage->face, - intelImage->level, - intelImage->base.Data, - intelImage->base.RowStride, - intelImage->base.RowStride * intelImage->base.Height); - - free(intelImage->base.Data); - intelImage->base.Data = NULL; - } - - intel_miptree_reference(&intelImage->mt, intelObj->mt); -} - - -/* - */ -GLuint intel_finalize_mipmap_tree( struct intel_context *intel, GLuint unit ) -{ - struct gl_texture_object *tObj = intel->ctx.Texture.Unit[unit]._Current; - struct intel_texture_object *intelObj = intel_texture_object(tObj); - - GLuint face, i; - GLuint nr_faces = 0; - struct intel_texture_image *firstImage; - - /* We know/require this is true by now: - */ - assert(intelObj->base.Complete); - - /* What levels must the tree include at a minimum? - */ - intel_calculate_first_last_level( intelObj ); - firstImage = intel_texture_image(intelObj->base.Image[0][intelObj->firstLevel]); - - /* Fallback case: - */ - if (firstImage->base.Border) { - if (intelObj->mt) { - intel_miptree_release(intel, &intelObj->mt); - } - return GL_FALSE; - } - - - /* If both firstImage and intelObj have a tree which can contain - * all active images, favour firstImage. Note that because of the - * completeness requirement, we know that the image dimensions - * will match. - */ - if (firstImage->mt && - firstImage->mt != intelObj->mt && - firstImage->mt->first_level <= intelObj->firstLevel && - firstImage->mt->last_level >= intelObj->lastLevel) { - - if (intelObj->mt) - intel_miptree_release(intel, &intelObj->mt); - - intel_miptree_reference(&intelObj->mt, firstImage->mt); - } - - /* Check tree can hold all active levels. Check tree matches - * target, imageFormat, etc. - * - * XXX: For some layouts (eg i945?), the test might have to be - * first_level == firstLevel, as the tree isn't valid except at the - * original start level. Hope to get around this by - * programming minLod, maxLod, baseLevel into the hardware and - * leaving the tree alone. - */ - if (intelObj->mt && - ((intelObj->mt->first_level > intelObj->firstLevel) || - (intelObj->mt->last_level < intelObj->lastLevel) || - (intelObj->mt->internal_format != firstImage->base.InternalFormat))) { - intel_miptree_release(intel, &intelObj->mt); - } - - - /* May need to create a new tree: - */ - if (!intelObj->mt) { - intelObj->mt = intel_miptree_create(intel, - intelObj->base.Target, - firstImage->base.InternalFormat, - intelObj->firstLevel, - intelObj->lastLevel, - firstImage->base.Width, - firstImage->base.Height, - firstImage->base.Depth, - firstImage->base.TexFormat->TexelBytes, - firstImage->base.IsCompressed); - } - - /* Pull in any images not in the object's tree: - */ - nr_faces = (intelObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; - for (face = 0; face < nr_faces; face++) { - for (i = intelObj->firstLevel; i <= intelObj->lastLevel; i++) { - struct intel_texture_image *intelImage = - intel_texture_image(intelObj->base.Image[face][i]); - - /* Need to import images in main memory or held in other trees. - */ - if (intelObj->mt != intelImage->mt) { - copy_image_data_to_tree(intel, - intelObj, - intelImage); - } - } - } - - return GL_TRUE; -} - - - -void intel_tex_map_images( struct intel_context *intel, - struct intel_texture_object *intelObj ) -{ - GLuint nr_faces = (intelObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; - GLuint face, i; - - DBG("%s\n", __FUNCTION__); - - for (face = 0; face < nr_faces; face++) { - for (i = intelObj->firstLevel; i <= intelObj->lastLevel; i++) { - struct intel_texture_image *intelImage = - intel_texture_image(intelObj->base.Image[face][i]); - - if (intelImage->mt) { - intelImage->base.Data = - intel_miptree_image_map(intel, - intelImage->mt, - intelImage->face, - intelImage->level, - &intelImage->base.RowStride, - &intelImage->base.ImageStride); - /* convert stride to texels, not bytes */ - intelImage->base.RowStride /= intelImage->mt->cpp; - intelImage->base.ImageStride /= intelImage->mt->cpp; - } - } - } -} - - - -void intel_tex_unmap_images( struct intel_context *intel, - struct intel_texture_object *intelObj ) -{ - GLuint nr_faces = (intelObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; - GLuint face, i; - - for (face = 0; face < nr_faces; face++) { - for (i = intelObj->firstLevel; i <= intelObj->lastLevel; i++) { - struct intel_texture_image *intelImage = - intel_texture_image(intelObj->base.Image[face][i]); - - if (intelImage->mt) { - intel_miptree_image_unmap(intel, intelImage->mt); - intelImage->base.Data = NULL; - } - } - } -} diff --git a/src/mesa/drivers/dri/i915-tex/intel_texmem.c b/src/mesa/drivers/dri/i915-tex/intel_texmem.c deleted file mode 100644 index 09beec95b8c..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_texmem.c +++ /dev/null @@ -1,72 +0,0 @@ -#include "texmem.h" -#include "simple_list.h" -#include "imports.h" -#include "macros.h" - -#include "intel_tex.h" - -static GLuint -driLog2( GLuint n ) -{ - GLuint log2; - - for ( log2 = 1 ; n > 1 ; log2++ ) { - n >>= 1; - } - - return log2; -} - -static void calculate_heap_size( driTexHeap * heap, unsigned size, - unsigned nr_regions, unsigned alignmentShift ) -{ - unsigned l; - - l = driLog2( (size - 1) / nr_regions ); - if ( l < alignmentShift ) - { - l = alignmentShift; - } - - heap->logGranularity = l; - heap->size = size & ~((1L << l) - 1); -} - - -GLboolean -intel_driReinitTextureHeap( driTexHeap *heap, - unsigned size ) -{ - driTextureObject *t, *tmp; - - /* Kick out everything: - */ - foreach_s ( t, tmp, & heap->texture_objects ) { - if ( t->tObj != NULL ) { - driSwapOutTextureObject( t ); - } - else { - driDestroyTextureObject( t ); - } - } - - /* Destroy the memory manager: - */ - mmDestroy( heap->memory_heap ); - - /* Recreate the memory manager: - */ - calculate_heap_size(heap, size, heap->nrRegions, heap->alignmentShift); - heap->memory_heap = mmInit( 0, heap->size ); - if ( heap->memory_heap == NULL ) { - fprintf(stderr, "driReinitTextureHeap: couldn't recreate memory heap\n"); - FREE( heap ); - return GL_FALSE; - } - - make_empty_list( & heap->texture_objects ); - - return GL_TRUE; -} - - diff --git a/src/mesa/drivers/dri/i915-tex/intel_tris.c b/src/mesa/drivers/dri/i915-tex/intel_tris.c deleted file mode 100644 index 18bb72f3678..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_tris.c +++ /dev/null @@ -1,1057 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#include "glheader.h" -#include "context.h" -#include "macros.h" -#include "enums.h" -#include "dd.h" - -#include "swrast/swrast.h" -#include "swrast_setup/swrast_setup.h" -#include "tnl/t_context.h" -#include "tnl/t_pipeline.h" -#include "tnl/t_vertex.h" - -#include "intel_screen.h" -#include "intel_context.h" -#include "intel_tris.h" -#include "intel_batchbuffer.h" -#include "intel_reg.h" -#include "intel_span.h" -#include "intel_tex.h" - -static void intelRenderPrimitive( GLcontext *ctx, GLenum prim ); -static void intelRasterPrimitive( GLcontext *ctx, GLenum rprim, GLuint hwprim ); - -/* - */ -static void intel_flush_inline_primitive( struct intel_context *intel ) -{ - GLuint used = intel->batch->ptr - intel->prim.start_ptr; - - assert(intel->prim.primitive != ~0); - - if (used < 8) - goto do_discard; - - *(int *)intel->prim.start_ptr = (_3DPRIMITIVE | - intel->prim.primitive | - (used/4-2)); - - goto finished; - - do_discard: - intel->batch->ptr -= used; - - finished: - intel->prim.primitive = ~0; - intel->prim.start_ptr = 0; - intel->prim.flush = 0; -} - - -/* Emit a primitive referencing vertices in a vertex buffer. - */ -void intelStartInlinePrimitive( struct intel_context *intel, - GLuint prim, - GLuint batch_flags ) -{ - BATCH_LOCALS; - - /* Emit a slot which will be filled with the inline primitive - * command later. - */ - BEGIN_BATCH(2, batch_flags); - OUT_BATCH( 0 ); - - intel->prim.start_ptr = intel->batch->ptr; - intel->prim.primitive = prim; - intel->prim.flush = intel_flush_inline_primitive; - - OUT_BATCH( 0 ); - ADVANCE_BATCH(); -} - - -void intelWrapInlinePrimitive( struct intel_context *intel ) -{ - GLuint prim = intel->prim.primitive; - GLuint batchflags = intel->batch->flags; - - intel_flush_inline_primitive(intel); - intel_batchbuffer_flush(intel->batch); - - intel->vtbl.emit_state( intel ); - intelStartInlinePrimitive( intel, prim, batchflags ); /* ??? */ -} - -GLuint *intelExtendInlinePrimitive( struct intel_context *intel, - GLuint dwords ) -{ - GLuint sz = dwords * sizeof(GLuint); - GLuint *ptr; - - if (intel_batchbuffer_space(intel->batch) < sz) - intelWrapInlinePrimitive( intel ); - - ptr = (GLuint *)intel->batch->ptr; - intel->batch->ptr += sz; - - return ptr; -} - - - -/*********************************************************************** - * Emit primitives as inline vertices * - ***********************************************************************/ - -#ifdef __i386__ -#define COPY_DWORDS( j, vb, vertsize, v ) \ -do { \ - int __tmp; \ - __asm__ __volatile__( "rep ; movsl" \ - : "=%c" (j), "=D" (vb), "=S" (__tmp) \ - : "0" (vertsize), \ - "D" ((long)vb), \ - "S" ((long)v) ); \ -} while (0) -#else -#define COPY_DWORDS( j, vb, vertsize, v ) \ -do { \ - for ( j = 0 ; j < vertsize ; j++ ) { \ - vb[j] = ((GLuint *)v)[j]; \ - } \ - vb += vertsize; \ -} while (0) -#endif - -static void intel_draw_quad( struct intel_context *intel, - intelVertexPtr v0, - intelVertexPtr v1, - intelVertexPtr v2, - intelVertexPtr v3 ) -{ - GLuint vertsize = intel->vertex_size; - GLuint *vb = intelExtendInlinePrimitive( intel, 6 * vertsize ); - int j; - - COPY_DWORDS( j, vb, vertsize, v0 ); - COPY_DWORDS( j, vb, vertsize, v1 ); - COPY_DWORDS( j, vb, vertsize, v3 ); - COPY_DWORDS( j, vb, vertsize, v1 ); - COPY_DWORDS( j, vb, vertsize, v2 ); - COPY_DWORDS( j, vb, vertsize, v3 ); -} - -static void intel_draw_triangle( struct intel_context *intel, - intelVertexPtr v0, - intelVertexPtr v1, - intelVertexPtr v2 ) -{ - GLuint vertsize = intel->vertex_size; - GLuint *vb = intelExtendInlinePrimitive( intel, 3 * vertsize ); - int j; - - COPY_DWORDS( j, vb, vertsize, v0 ); - COPY_DWORDS( j, vb, vertsize, v1 ); - COPY_DWORDS( j, vb, vertsize, v2 ); -} - - -static void intel_draw_line( struct intel_context *intel, - intelVertexPtr v0, - intelVertexPtr v1 ) -{ - GLuint vertsize = intel->vertex_size; - GLuint *vb = intelExtendInlinePrimitive( intel, 2 * vertsize ); - int j; - - COPY_DWORDS( j, vb, vertsize, v0 ); - COPY_DWORDS( j, vb, vertsize, v1 ); -} - - -static void intel_draw_point( struct intel_context *intel, - intelVertexPtr v0 ) -{ - GLuint vertsize = intel->vertex_size; - GLuint *vb = intelExtendInlinePrimitive( intel, vertsize ); - int j; - - /* Adjust for sub pixel position -- still required for conform. */ - *(float *)&vb[0] = v0->v.x - 0.125; - *(float *)&vb[1] = v0->v.y - 0.125; - for (j = 2 ; j < vertsize ; j++) - vb[j] = v0->ui[j]; -} - - - -/*********************************************************************** - * Fixup for ARB_point_parameters * - ***********************************************************************/ - -static void intel_atten_point( struct intel_context *intel, intelVertexPtr v0 ) -{ - GLcontext *ctx = &intel->ctx; - GLfloat psz[4], col[4], restore_psz, restore_alpha; - - _tnl_get_attr( ctx, v0, _TNL_ATTRIB_POINTSIZE, psz ); - _tnl_get_attr( ctx, v0, _TNL_ATTRIB_COLOR0, col ); - - restore_psz = psz[0]; - restore_alpha = col[3]; - - if (psz[0] >= ctx->Point.Threshold) { - psz[0] = MIN2(psz[0], ctx->Point.MaxSize); - } - else { - GLfloat dsize = psz[0] / ctx->Point.Threshold; - psz[0] = MAX2(ctx->Point.Threshold, ctx->Point.MinSize); - col[3] *= dsize * dsize; - } - - if (psz[0] < 1.0) - psz[0] = 1.0; - - if (restore_psz != psz[0] || restore_alpha != col[3]) { - _tnl_set_attr( ctx, v0, _TNL_ATTRIB_POINTSIZE, psz); - _tnl_set_attr( ctx, v0, _TNL_ATTRIB_COLOR0, col); - - intel_draw_point( intel, v0 ); - - psz[0] = restore_psz; - col[3] = restore_alpha; - - _tnl_set_attr( ctx, v0, _TNL_ATTRIB_POINTSIZE, psz); - _tnl_set_attr( ctx, v0, _TNL_ATTRIB_COLOR0, col); - } - else - intel_draw_point( intel, v0 ); -} - - - - - -/*********************************************************************** - * Fixup for I915 WPOS texture coordinate * - ***********************************************************************/ - - - -static void intel_wpos_triangle( struct intel_context *intel, - intelVertexPtr v0, - intelVertexPtr v1, - intelVertexPtr v2 ) -{ - GLuint offset = intel->wpos_offset; - GLuint size = intel->wpos_size; - - __memcpy( ((char *)v0) + offset, v0, size ); - __memcpy( ((char *)v1) + offset, v1, size ); - __memcpy( ((char *)v2) + offset, v2, size ); - - intel_draw_triangle( intel, v0, v1, v2 ); -} - - -static void intel_wpos_line( struct intel_context *intel, - intelVertexPtr v0, - intelVertexPtr v1 ) -{ - GLuint offset = intel->wpos_offset; - GLuint size = intel->wpos_size; - - __memcpy( ((char *)v0) + offset, v0, size ); - __memcpy( ((char *)v1) + offset, v1, size ); - - intel_draw_line( intel, v0, v1 ); -} - - -static void intel_wpos_point( struct intel_context *intel, - intelVertexPtr v0 ) -{ - GLuint offset = intel->wpos_offset; - GLuint size = intel->wpos_size; - - __memcpy( ((char *)v0) + offset, v0, size ); - - intel_draw_point( intel, v0 ); -} - - - - - - -/*********************************************************************** - * Macros for t_dd_tritmp.h to draw basic primitives * - ***********************************************************************/ - -#define TRI( a, b, c ) \ -do { \ - if (DO_FALLBACK) \ - intel->draw_tri( intel, a, b, c ); \ - else \ - intel_draw_triangle( intel, a, b, c ); \ -} while (0) - -#define QUAD( a, b, c, d ) \ -do { \ - if (DO_FALLBACK) { \ - intel->draw_tri( intel, a, b, d ); \ - intel->draw_tri( intel, b, c, d ); \ - } else \ - intel_draw_quad( intel, a, b, c, d ); \ -} while (0) - -#define LINE( v0, v1 ) \ -do { \ - if (DO_FALLBACK) \ - intel->draw_line( intel, v0, v1 ); \ - else \ - intel_draw_line( intel, v0, v1 ); \ -} while (0) - -#define POINT( v0 ) \ -do { \ - if (DO_FALLBACK) \ - intel->draw_point( intel, v0 ); \ - else \ - intel_draw_point( intel, v0 ); \ -} while (0) - - -/*********************************************************************** - * Build render functions from dd templates * - ***********************************************************************/ - -#define INTEL_OFFSET_BIT 0x01 -#define INTEL_TWOSIDE_BIT 0x02 -#define INTEL_UNFILLED_BIT 0x04 -#define INTEL_FALLBACK_BIT 0x08 -#define INTEL_MAX_TRIFUNC 0x10 - - -static struct { - tnl_points_func points; - tnl_line_func line; - tnl_triangle_func triangle; - tnl_quad_func quad; -} rast_tab[INTEL_MAX_TRIFUNC]; - - -#define DO_FALLBACK (IND & INTEL_FALLBACK_BIT) -#define DO_OFFSET (IND & INTEL_OFFSET_BIT) -#define DO_UNFILLED (IND & INTEL_UNFILLED_BIT) -#define DO_TWOSIDE (IND & INTEL_TWOSIDE_BIT) -#define DO_FLAT 0 -#define DO_TRI 1 -#define DO_QUAD 1 -#define DO_LINE 1 -#define DO_POINTS 1 -#define DO_FULL_QUAD 1 - -#define HAVE_RGBA 1 -#define HAVE_SPEC 1 -#define HAVE_BACK_COLORS 0 -#define HAVE_HW_FLATSHADE 1 -#define VERTEX intelVertex -#define TAB rast_tab - -/* Only used to pull back colors into vertices (ie, we know color is - * floating point). - */ -#define INTEL_COLOR( dst, src ) \ -do { \ - UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \ - UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \ - UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \ - UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \ -} while (0) - -#define INTEL_SPEC( dst, src ) \ -do { \ - UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \ - UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \ - UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \ -} while (0) - - -#define DEPTH_SCALE intel->polygon_offset_scale -#define UNFILLED_TRI unfilled_tri -#define UNFILLED_QUAD unfilled_quad -#define VERT_X(_v) _v->v.x -#define VERT_Y(_v) _v->v.y -#define VERT_Z(_v) _v->v.z -#define AREA_IS_CCW( a ) (a > 0) -#define GET_VERTEX(e) (intel->verts + (e * intel->vertex_size * sizeof(GLuint))) - -#define VERT_SET_RGBA( v, c ) if (coloroffset) INTEL_COLOR( v->ub4[coloroffset], c ) -#define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset] -#define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset] -#define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx] - -#define VERT_SET_SPEC( v, c ) if (specoffset) INTEL_SPEC( v->ub4[specoffset], c ) -#define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset]) -#define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset] -#define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx] - -#define LOCAL_VARS(n) \ - struct intel_context *intel = intel_context(ctx); \ - GLuint color[n], spec[n]; \ - GLuint coloroffset = intel->coloroffset; \ - GLboolean specoffset = intel->specoffset; \ - (void) color; (void) spec; (void) coloroffset; (void) specoffset; - - -/*********************************************************************** - * Helpers for rendering unfilled primitives * - ***********************************************************************/ - -static const GLuint hw_prim[GL_POLYGON+1] = { - PRIM3D_POINTLIST, - PRIM3D_LINELIST, - PRIM3D_LINELIST, - PRIM3D_LINELIST, - PRIM3D_TRILIST, - PRIM3D_TRILIST, - PRIM3D_TRILIST, - PRIM3D_TRILIST, - PRIM3D_TRILIST, - PRIM3D_TRILIST -}; - -#define RASTERIZE(x) intelRasterPrimitive( ctx, x, hw_prim[x] ) -#define RENDER_PRIMITIVE intel->render_primitive -#define TAG(x) x -#define IND INTEL_FALLBACK_BIT -#include "tnl_dd/t_dd_unfilled.h" -#undef IND - -/*********************************************************************** - * Generate GL render functions * - ***********************************************************************/ - -#define IND (0) -#define TAG(x) x -#include "tnl_dd/t_dd_tritmp.h" - -#define IND (INTEL_OFFSET_BIT) -#define TAG(x) x##_offset -#include "tnl_dd/t_dd_tritmp.h" - -#define IND (INTEL_TWOSIDE_BIT) -#define TAG(x) x##_twoside -#include "tnl_dd/t_dd_tritmp.h" - -#define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT) -#define TAG(x) x##_twoside_offset -#include "tnl_dd/t_dd_tritmp.h" - -#define IND (INTEL_UNFILLED_BIT) -#define TAG(x) x##_unfilled -#include "tnl_dd/t_dd_tritmp.h" - -#define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT) -#define TAG(x) x##_offset_unfilled -#include "tnl_dd/t_dd_tritmp.h" - -#define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT) -#define TAG(x) x##_twoside_unfilled -#include "tnl_dd/t_dd_tritmp.h" - -#define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT) -#define TAG(x) x##_twoside_offset_unfilled -#include "tnl_dd/t_dd_tritmp.h" - -#define IND (INTEL_FALLBACK_BIT) -#define TAG(x) x##_fallback -#include "tnl_dd/t_dd_tritmp.h" - -#define IND (INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT) -#define TAG(x) x##_offset_fallback -#include "tnl_dd/t_dd_tritmp.h" - -#define IND (INTEL_TWOSIDE_BIT|INTEL_FALLBACK_BIT) -#define TAG(x) x##_twoside_fallback -#include "tnl_dd/t_dd_tritmp.h" - -#define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT) -#define TAG(x) x##_twoside_offset_fallback -#include "tnl_dd/t_dd_tritmp.h" - -#define IND (INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT) -#define TAG(x) x##_unfilled_fallback -#include "tnl_dd/t_dd_tritmp.h" - -#define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT) -#define TAG(x) x##_offset_unfilled_fallback -#include "tnl_dd/t_dd_tritmp.h" - -#define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT) -#define TAG(x) x##_twoside_unfilled_fallback -#include "tnl_dd/t_dd_tritmp.h" - -#define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT| \ - INTEL_FALLBACK_BIT) -#define TAG(x) x##_twoside_offset_unfilled_fallback -#include "tnl_dd/t_dd_tritmp.h" - - -static void init_rast_tab( void ) -{ - init(); - init_offset(); - init_twoside(); - init_twoside_offset(); - init_unfilled(); - init_offset_unfilled(); - init_twoside_unfilled(); - init_twoside_offset_unfilled(); - init_fallback(); - init_offset_fallback(); - init_twoside_fallback(); - init_twoside_offset_fallback(); - init_unfilled_fallback(); - init_offset_unfilled_fallback(); - init_twoside_unfilled_fallback(); - init_twoside_offset_unfilled_fallback(); -} - - -/*********************************************************************** - * Rasterization fallback helpers * - ***********************************************************************/ - - -/* This code is hit only when a mix of accelerated and unaccelerated - * primitives are being drawn, and only for the unaccelerated - * primitives. - */ -static void -intel_fallback_tri( struct intel_context *intel, - intelVertex *v0, - intelVertex *v1, - intelVertex *v2 ) -{ - GLcontext *ctx = &intel->ctx; - SWvertex v[3]; - - if (0) - fprintf(stderr, "\n%s\n", __FUNCTION__); - - if (intel->prim.flush) - intel->prim.flush(intel); - - _swsetup_Translate( ctx, v0, &v[0] ); - _swsetup_Translate( ctx, v1, &v[1] ); - _swsetup_Translate( ctx, v2, &v[2] ); - intelSpanRenderStart( ctx ); - _swrast_Triangle( ctx, &v[0], &v[1], &v[2] ); - intelSpanRenderFinish( ctx ); -} - - -static void -intel_fallback_line( struct intel_context *intel, - intelVertex *v0, - intelVertex *v1 ) -{ - GLcontext *ctx = &intel->ctx; - SWvertex v[2]; - - if (0) - fprintf(stderr, "\n%s\n", __FUNCTION__); - - if (intel->prim.flush) - intel->prim.flush(intel); - - _swsetup_Translate( ctx, v0, &v[0] ); - _swsetup_Translate( ctx, v1, &v[1] ); - intelSpanRenderStart( ctx ); - _swrast_Line( ctx, &v[0], &v[1] ); - intelSpanRenderFinish( ctx ); -} - - -/**********************************************************************/ -/* Render unclipped begin/end objects */ -/**********************************************************************/ - -#define IND 0 -#define V(x) (intelVertex *)(vertptr + ((x)*vertsize*sizeof(GLuint))) -#define RENDER_POINTS( start, count ) \ - for ( ; start < count ; start++) POINT( V(ELT(start)) ); -#define RENDER_LINE( v0, v1 ) LINE( V(v0), V(v1) ) -#define RENDER_TRI( v0, v1, v2 ) TRI( V(v0), V(v1), V(v2) ) -#define RENDER_QUAD( v0, v1, v2, v3 ) QUAD( V(v0), V(v1), V(v2), V(v3) ) -#define INIT(x) intelRenderPrimitive( ctx, x ) -#undef LOCAL_VARS -#define LOCAL_VARS \ - struct intel_context *intel = intel_context(ctx); \ - GLubyte *vertptr = (GLubyte *)intel->verts; \ - const GLuint vertsize = intel->vertex_size; \ - const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \ - (void) elt; -#define RESET_STIPPLE -#define RESET_OCCLUSION -#define PRESERVE_VB_DEFS -#define ELT(x) x -#define TAG(x) intel_##x##_verts -#include "tnl/t_vb_rendertmp.h" -#undef ELT -#undef TAG -#define TAG(x) intel_##x##_elts -#define ELT(x) elt[x] -#include "tnl/t_vb_rendertmp.h" - -/**********************************************************************/ -/* Render clipped primitives */ -/**********************************************************************/ - - - -static void intelRenderClippedPoly( GLcontext *ctx, const GLuint *elts, - GLuint n ) -{ - struct intel_context *intel = intel_context(ctx); - TNLcontext *tnl = TNL_CONTEXT(ctx); - struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; - GLuint prim = intel->render_primitive; - - /* Render the new vertices as an unclipped polygon. - */ - { - GLuint *tmp = VB->Elts; - VB->Elts = (GLuint *)elts; - tnl->Driver.Render.PrimTabElts[GL_POLYGON]( ctx, 0, n, - PRIM_BEGIN|PRIM_END ); - VB->Elts = tmp; - } - - /* Restore the render primitive - */ - if (prim != GL_POLYGON) - tnl->Driver.Render.PrimitiveNotify( ctx, prim ); -} - -static void intelRenderClippedLine( GLcontext *ctx, GLuint ii, GLuint jj ) -{ - TNLcontext *tnl = TNL_CONTEXT(ctx); - - tnl->Driver.Render.Line( ctx, ii, jj ); -} - -static void intelFastRenderClippedPoly( GLcontext *ctx, const GLuint *elts, - GLuint n ) -{ - struct intel_context *intel = intel_context( ctx ); - const GLuint vertsize = intel->vertex_size; - GLuint *vb = intelExtendInlinePrimitive( intel, (n-2) * 3 * vertsize ); - GLubyte *vertptr = (GLubyte *)intel->verts; - const GLuint *start = (const GLuint *)V(elts[0]); - int i,j; - - for (i = 2 ; i < n ; i++) { - COPY_DWORDS( j, vb, vertsize, V(elts[i-1]) ); - COPY_DWORDS( j, vb, vertsize, V(elts[i]) ); - COPY_DWORDS( j, vb, vertsize, start ); - } -} - -/**********************************************************************/ -/* Choose render functions */ -/**********************************************************************/ - - - - -#define ANY_FALLBACK_FLAGS (DD_LINE_STIPPLE | DD_TRI_STIPPLE | DD_POINT_ATTEN) -#define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE | DD_TRI_OFFSET | DD_TRI_UNFILLED) - -void intelChooseRenderState(GLcontext *ctx) -{ - TNLcontext *tnl = TNL_CONTEXT(ctx); - struct intel_context *intel = intel_context(ctx); - GLuint flags = ctx->_TriangleCaps; - struct fragment_program *fprog = ctx->FragmentProgram._Current; - GLboolean have_wpos = (fprog && (fprog->Base.InputsRead & FRAG_BIT_WPOS)); - GLuint index = 0; - - if (INTEL_DEBUG & DEBUG_STATE) - fprintf(stderr,"\n%s\n",__FUNCTION__); - - if ((flags & (ANY_FALLBACK_FLAGS|ANY_RASTER_FLAGS)) || have_wpos) { - - if (flags & ANY_RASTER_FLAGS) { - if (flags & DD_TRI_LIGHT_TWOSIDE) index |= INTEL_TWOSIDE_BIT; - if (flags & DD_TRI_OFFSET) index |= INTEL_OFFSET_BIT; - if (flags & DD_TRI_UNFILLED) index |= INTEL_UNFILLED_BIT; - } - - if (have_wpos) { - intel->draw_point = intel_wpos_point; - intel->draw_line = intel_wpos_line; - intel->draw_tri = intel_wpos_triangle; - - /* Make sure these get called: - */ - index |= INTEL_FALLBACK_BIT; - } - else { - intel->draw_point = intel_draw_point; - intel->draw_line = intel_draw_line; - intel->draw_tri = intel_draw_triangle; - } - - /* Hook in fallbacks for specific primitives. - */ - if (flags & ANY_FALLBACK_FLAGS) - { - if (flags & DD_LINE_STIPPLE) - intel->draw_line = intel_fallback_line; - - if ((flags & DD_TRI_STIPPLE) && !intel->hw_stipple) - intel->draw_tri = intel_fallback_tri; - - if (flags & DD_POINT_ATTEN) - intel->draw_point = intel_atten_point; - - index |= INTEL_FALLBACK_BIT; - } - } - - if (intel->RenderIndex != index) { - intel->RenderIndex = index; - - tnl->Driver.Render.Points = rast_tab[index].points; - tnl->Driver.Render.Line = rast_tab[index].line; - tnl->Driver.Render.Triangle = rast_tab[index].triangle; - tnl->Driver.Render.Quad = rast_tab[index].quad; - - if (index == 0) { - tnl->Driver.Render.PrimTabVerts = intel_render_tab_verts; - tnl->Driver.Render.PrimTabElts = intel_render_tab_elts; - tnl->Driver.Render.ClippedLine = line; /* from tritmp.h */ - tnl->Driver.Render.ClippedPolygon = intelFastRenderClippedPoly; - } else { - tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts; - tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts; - tnl->Driver.Render.ClippedLine = intelRenderClippedLine; - tnl->Driver.Render.ClippedPolygon = intelRenderClippedPoly; - } - } -} - -static const GLenum reduced_prim[GL_POLYGON+1] = { - GL_POINTS, - GL_LINES, - GL_LINES, - GL_LINES, - GL_TRIANGLES, - GL_TRIANGLES, - GL_TRIANGLES, - GL_TRIANGLES, - GL_TRIANGLES, - GL_TRIANGLES -}; - - -/**********************************************************************/ -/* High level hooks for t_vb_render.c */ -/**********************************************************************/ - - - - -static void intelRunPipeline( GLcontext *ctx ) -{ - struct intel_context *intel = intel_context(ctx); - - if (intel->NewGLState) { - if (intel->NewGLState & _NEW_TEXTURE) { - intel->vtbl.update_texture_state( intel ); - } - - if (!intel->Fallback) { - if (intel->NewGLState & _INTEL_NEW_RENDERSTATE) - intelChooseRenderState( ctx ); - } - - intel->NewGLState = 0; - } - - _tnl_run_pipeline( ctx ); -} - -static void intelRenderStart( GLcontext *ctx ) -{ - struct intel_context *intel = intel_context(ctx); - - intel->vtbl.render_start( intel_context(ctx) ); - intel->vtbl.emit_state( intel ); -} - -static void intelRenderFinish( GLcontext *ctx ) -{ - struct intel_context *intel = intel_context(ctx); - - if (intel->RenderIndex & INTEL_FALLBACK_BIT) - _swrast_flush( ctx ); - - if (intel->prim.flush) - intel->prim.flush(intel); -} - - - - - /* System to flush dma and emit state changes based on the rasterized - * primitive. - */ -static void intelRasterPrimitive( GLcontext *ctx, GLenum rprim, GLuint hwprim ) -{ - struct intel_context *intel = intel_context(ctx); - - if (0) - fprintf(stderr, "%s %s %x\n", __FUNCTION__, - _mesa_lookup_enum_by_nr(rprim), hwprim); - - intel->vtbl.reduced_primitive_state( intel, rprim ); - - /* Start a new primitive. Arrange to have it flushed later on. - */ - if (hwprim != intel->prim.primitive) { - if (intel->prim.flush) - intel->prim.flush(intel); - - intelStartInlinePrimitive( intel, hwprim, INTEL_BATCH_CLIPRECTS ); - } -} - - - /* - */ -static void intelRenderPrimitive( GLcontext *ctx, GLenum prim ) -{ - struct intel_context *intel = intel_context(ctx); - - if (0) - fprintf(stderr, "%s %s\n", __FUNCTION__, _mesa_lookup_enum_by_nr(prim)); - - /* Let some clipping routines know which primitive they're dealing - * with. - */ - intel->render_primitive = prim; - - /* Shortcircuit this when called from t_dd_rendertmp.h for unfilled - * triangles. The rasterized primitive will always be reset by - * lower level functions in that case, potentially pingponging the - * state: - */ - if (reduced_prim[prim] == GL_TRIANGLES && - (ctx->_TriangleCaps & DD_TRI_UNFILLED)) - return; - - /* Set some primitive-dependent state and Start? a new primitive. - */ - intelRasterPrimitive( ctx, reduced_prim[prim], hw_prim[prim] ); -} - - - /**********************************************************************/ - /* Transition to/from hardware rasterization. */ - /**********************************************************************/ - -static char *fallbackStrings[] = { - "Texture", - "Draw buffer", - "Read buffer", - "Color mask", - "Render mode", - "Stencil", - "Stipple", - "User disable" -}; - - -static char *getFallbackString(GLuint bit) -{ - int i = 0; - while (bit > 1) { - i++; - bit >>= 1; - } - return fallbackStrings[i]; -} - - - -void intelFallback( struct intel_context *intel, GLuint bit, GLboolean mode ) -{ - GLcontext *ctx = &intel->ctx; - TNLcontext *tnl = TNL_CONTEXT(ctx); - GLuint oldfallback = intel->Fallback; - - if (mode) { - intel->Fallback |= bit; - if (oldfallback == 0) { - intelFlush(ctx); - if (INTEL_DEBUG & DEBUG_FALLBACKS) - fprintf(stderr, "ENTER FALLBACK %x: %s\n", - bit, getFallbackString( bit )); - _swsetup_Wakeup( ctx ); - intel->RenderIndex = ~0; - } - } - else { - intel->Fallback &= ~bit; - if (oldfallback == bit) { - _swrast_flush( ctx ); - if (INTEL_DEBUG & DEBUG_FALLBACKS) - fprintf(stderr, "LEAVE FALLBACK %s\n", getFallbackString( bit )); - tnl->Driver.Render.Start = intelRenderStart; - tnl->Driver.Render.PrimitiveNotify = intelRenderPrimitive; - tnl->Driver.Render.Finish = intelRenderFinish; - tnl->Driver.Render.BuildVertices = _tnl_build_vertices; - tnl->Driver.Render.CopyPV = _tnl_copy_pv; - tnl->Driver.Render.Interp = _tnl_interp; - - _tnl_invalidate_vertex_state( ctx, ~0 ); - _tnl_invalidate_vertices( ctx, ~0 ); - _tnl_install_attrs( ctx, - intel->vertex_attrs, - intel->vertex_attr_count, - intel->ViewportMatrix.m, 0 ); - - intel->NewGLState |= _INTEL_NEW_RENDERSTATE; - } - } -} - -union fi { - GLfloat f; - GLint i; -}; - - -/**********************************************************************/ -/* Used only with the metaops callbacks. */ -/**********************************************************************/ -void intel_meta_draw_quad(struct intel_context *intel, - GLfloat x0, GLfloat x1, - GLfloat y0, GLfloat y1, - GLfloat z, - GLuint color, - GLfloat s0, GLfloat s1, - GLfloat t0, GLfloat t1) -{ - union fi *vb; - - if (INTEL_DEBUG & DEBUG_DRI) - fprintf(stderr, "%s: %f,%f-%f,%f 0x%x %f,%f-%f,%f depth: %f\n", - __FUNCTION__, - x0,y0,x1,y1,color,s0,t0,s1,t1, z); - - intel->vtbl.emit_state( intel ); - - /* All 3d primitives should be emitted with INTEL_BATCH_CLIPRECTS, - * otherwise the drawing origin (DR4) might not be set correctly. - */ - intelStartInlinePrimitive( intel, PRIM3D_TRIFAN, INTEL_BATCH_CLIPRECTS ); - vb = (union fi *)intelExtendInlinePrimitive( intel, 4 * 6 ); - - - /* initial vertex, left bottom */ - vb[0].f = x0; - vb[1].f = y0; - vb[2].f = z; - vb[3].i = color; - vb[4].f = s0; - vb[5].f = t0; - vb += 6; - - /* right bottom */ - vb[0].f = x1; - vb[1].f = y0; - vb[2].f = z; - vb[3].i = color; - vb[4].f = s1; - vb[5].f = t0; - vb += 6; - - /* right top */ - vb[0].f = x1; - vb[1].f = y1; - vb[2].f = z; - vb[3].i = color; - vb[4].f = s1; - vb[5].f = t1; - vb += 6; - - /* left top */ - vb[0].f = x0; - vb[1].f = y1; - vb[2].f = z; - vb[3].i = color; - vb[4].f = s0; - vb[5].f = t1; - - if (intel->prim.flush) - intel->prim.flush(intel); -} - - -/**********************************************************************/ -/* Initialization. */ -/**********************************************************************/ - - -void intelInitTriFuncs( GLcontext *ctx ) -{ - TNLcontext *tnl = TNL_CONTEXT(ctx); - static int firsttime = 1; - - if (firsttime) { - init_rast_tab(); - firsttime = 0; - } - - tnl->Driver.RunPipeline = intelRunPipeline; - tnl->Driver.Render.Start = intelRenderStart; - tnl->Driver.Render.Finish = intelRenderFinish; - tnl->Driver.Render.PrimitiveNotify = intelRenderPrimitive; - tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple; - tnl->Driver.Render.BuildVertices = _tnl_build_vertices; - tnl->Driver.Render.CopyPV = _tnl_copy_pv; - tnl->Driver.Render.Interp = _tnl_interp; -} diff --git a/src/mesa/drivers/dri/i915-tex/intel_tris.h b/src/mesa/drivers/dri/i915-tex/intel_tris.h deleted file mode 100644 index 1b2c474262d..00000000000 --- a/src/mesa/drivers/dri/i915-tex/intel_tris.h +++ /dev/null @@ -1,63 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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, 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#ifndef INTELTRIS_INC -#define INTELTRIS_INC - -#include "mtypes.h" - - - -#define _INTEL_NEW_RENDERSTATE (_DD_NEW_LINE_STIPPLE | \ - _DD_NEW_TRI_UNFILLED | \ - _DD_NEW_TRI_LIGHT_TWOSIDE | \ - _DD_NEW_TRI_OFFSET | \ - _DD_NEW_TRI_STIPPLE | \ - _NEW_PROGRAM | \ - _NEW_POLYGONSTIPPLE) - -extern void intelInitTriFuncs( GLcontext *ctx ); - -extern void intelChooseRenderState( GLcontext *ctx ); - -extern void intelStartInlinePrimitive( struct intel_context *intel, GLuint prim, GLuint flags ); -extern void intelWrapInlinePrimitive( struct intel_context *intel ); - -GLuint *intelExtendInlinePrimitive( struct intel_context *intel, - GLuint dwords ); - - -void intel_meta_draw_quad(struct intel_context *intel, - GLfloat x0, GLfloat x1, - GLfloat y0, GLfloat y1, - GLfloat z, - GLuint color, - GLfloat s0, GLfloat s1, - GLfloat t0, GLfloat t1); - - -#endif diff --git a/src/mesa/drivers/dri/i915-tex/server/i830_common.h b/src/mesa/drivers/dri/i915-tex/server/i830_common.h deleted file mode 100644 index 41b5cc3c01b..00000000000 --- a/src/mesa/drivers/dri/i915-tex/server/i830_common.h +++ /dev/null @@ -1,197 +0,0 @@ -/************************************************************************** - -Copyright 2001 VA Linux Systems Inc., Fremont, California. -Copyright 2002 Tungsten Graphics Inc., Cedar Park, Texas. - -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 -ATI, VA LINUX SYSTEMS AND/OR THEIR 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. - -**************************************************************************/ - -/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/i810/i830_common.h,v 1.1 2002/09/11 00:29:32 dawes Exp $ */ - -#ifndef _I830_COMMON_H_ -#define _I830_COMMON_H_ - - -#define I830_NR_TEX_REGIONS 255 /* maximum due to use of chars for next/prev */ -#define I830_LOG_MIN_TEX_REGION_SIZE 14 - - -/* Driver specific DRM command indices - * NOTE: these are not OS specific, but they are driver specific - */ -#define DRM_I830_INIT 0x00 -#define DRM_I830_FLUSH 0x01 -#define DRM_I830_FLIP 0x02 -#define DRM_I830_BATCHBUFFER 0x03 -#define DRM_I830_IRQ_EMIT 0x04 -#define DRM_I830_IRQ_WAIT 0x05 -#define DRM_I830_GETPARAM 0x06 -#define DRM_I830_SETPARAM 0x07 -#define DRM_I830_ALLOC 0x08 -#define DRM_I830_FREE 0x09 -#define DRM_I830_INIT_HEAP 0x0a -#define DRM_I830_CMDBUFFER 0x0b -#define DRM_I830_DESTROY_HEAP 0x0c - -typedef struct { - enum { - I830_INIT_DMA = 0x01, - I830_CLEANUP_DMA = 0x02, - I830_RESUME_DMA = 0x03 - } func; - unsigned int mmio_offset; - int sarea_priv_offset; - unsigned int ring_start; - unsigned int ring_end; - unsigned int ring_size; - unsigned int front_offset; - unsigned int back_offset; - unsigned int depth_offset; - unsigned int w; - unsigned int h; - unsigned int pitch; - unsigned int pitch_bits; - unsigned int back_pitch; - unsigned int depth_pitch; - unsigned int cpp; - unsigned int chipset; -} drmI830Init; - -typedef struct { - drmTextureRegion texList[I830_NR_TEX_REGIONS+1]; - int last_upload; /* last time texture was uploaded */ - int last_enqueue; /* last time a buffer was enqueued */ - int last_dispatch; /* age of the most recently dispatched buffer */ - int ctxOwner; /* last context to upload state */ - int texAge; - int pf_enabled; /* is pageflipping allowed? */ - int pf_active; - int pf_current_page; /* which buffer is being displayed? */ - int perf_boxes; /* performance boxes to be displayed */ - int width, height; /* screen size in pixels */ - - drm_handle_t front_handle; - int front_offset; - int front_size; - - drm_handle_t back_handle; - int back_offset; - int back_size; - - drm_handle_t depth_handle; - int depth_offset; - int depth_size; - - drm_handle_t tex_handle; - int tex_offset; - int tex_size; - int log_tex_granularity; - int pitch; - int rotation; /* 0, 90, 180 or 270 */ - int rotated_offset; - int rotated_size; - int rotated_pitch; - int virtualX, virtualY; -} drmI830Sarea; - -/* Flags for perf_boxes - */ -#define I830_BOX_RING_EMPTY 0x1 /* populated by kernel */ -#define I830_BOX_FLIP 0x2 /* populated by kernel */ -#define I830_BOX_WAIT 0x4 /* populated by kernel & client */ -#define I830_BOX_TEXTURE_LOAD 0x8 /* populated by kernel */ -#define I830_BOX_LOST_CONTEXT 0x10 /* populated by client */ - - -typedef struct { - int start; /* agp offset */ - int used; /* nr bytes in use */ - int DR1; /* hw flags for GFX_OP_DRAWRECT_INFO */ - int DR4; /* window origin for GFX_OP_DRAWRECT_INFO*/ - int num_cliprects; /* mulitpass with multiple cliprects? */ - drm_clip_rect_t *cliprects; /* pointer to userspace cliprects */ -} drmI830BatchBuffer; - -typedef struct { - char *buf; /* agp offset */ - int sz; /* nr bytes in use */ - int DR1; /* hw flags for GFX_OP_DRAWRECT_INFO */ - int DR4; /* window origin for GFX_OP_DRAWRECT_INFO*/ - int num_cliprects; /* mulitpass with multiple cliprects? */ - drm_clip_rect_t *cliprects; /* pointer to userspace cliprects */ -} drmI830CmdBuffer; - -typedef struct { - int *irq_seq; -} drmI830IrqEmit; - -typedef struct { - int irq_seq; -} drmI830IrqWait; - -typedef struct { - int param; - int *value; -} drmI830GetParam; - -#define I830_PARAM_IRQ_ACTIVE 1 -#define I830_PARAM_ALLOW_BATCHBUFFER 2 - -typedef struct { - int param; - int value; -} drmI830SetParam; - -#define I830_SETPARAM_USE_MI_BATCHBUFFER_START 1 -#define I830_SETPARAM_TEX_LRU_LOG_GRANULARITY 2 -#define I830_SETPARAM_ALLOW_BATCHBUFFER 3 - - -/* A memory manager for regions of shared memory: - */ -#define I830_MEM_REGION_AGP 1 - -typedef struct { - int region; - int alignment; - int size; - int *region_offset; /* offset from start of fb or agp */ -} drmI830MemAlloc; - -typedef struct { - int region; - int region_offset; -} drmI830MemFree; - -typedef struct { - int region; - int size; - int start; -} drmI830MemInitHeap; - -typedef struct { - int region; -} drmI830MemDestroyHeap; - - -#endif /* _I830_DRM_H_ */ diff --git a/src/mesa/drivers/dri/i915-tex/server/i830_dri.h b/src/mesa/drivers/dri/i915-tex/server/i830_dri.h deleted file mode 100644 index 6c9a7090215..00000000000 --- a/src/mesa/drivers/dri/i915-tex/server/i830_dri.h +++ /dev/null @@ -1,73 +0,0 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/i810/i830_dri.h,v 1.4 2002/10/30 12:52:18 alanh Exp $ */ - -#ifndef _I830_DRI_H -#define _I830_DRI_H - -#include "xf86drm.h" -#include "i830_common.h" - -#define I830_MAX_DRAWABLES 256 - -#define I830_MAJOR_VERSION 1 -#define I830_MINOR_VERSION 3 -#define I830_PATCHLEVEL 0 - -#define I830_REG_SIZE 0x80000 - -typedef struct _I830DRIRec { - drm_handle_t regs; - drmSize regsSize; - - drmSize backbufferSize; - drm_handle_t backbuffer; - - drmSize depthbufferSize; - drm_handle_t depthbuffer; - - drmSize rotatedSize; - drm_handle_t rotatedbuffer; - - drm_handle_t textures; - int textureSize; - - drm_handle_t agp_buffers; - drmSize agp_buf_size; - - int deviceID; - int width; - int height; - int mem; - int cpp; - int bitsPerPixel; - - int fbOffset; - int fbStride; - - int backOffset; - int backPitch; - - int depthOffset; - int depthPitch; - - int rotatedOffset; - int rotatedPitch; - - int logTextureGranularity; - int textureOffset; - - int irq; - int sarea_priv_offset; -} I830DRIRec, *I830DRIPtr; - -typedef struct { - /* Nothing here yet */ - int dummy; -} I830ConfigPrivRec, *I830ConfigPrivPtr; - -typedef struct { - /* Nothing here yet */ - int dummy; -} I830DRIContextRec, *I830DRIContextPtr; - - -#endif diff --git a/src/mesa/drivers/dri/mga/README b/src/mesa/drivers/dri/mga/README deleted file mode 100644 index a7133fa66f4..00000000000 --- a/src/mesa/drivers/dri/mga/README +++ /dev/null @@ -1,26 +0,0 @@ -MGA DRI driver ported from XF86DRI to FBDRI -by Denis Oliver Kropp <[email protected]> - - -INFO - -This driver has been ported from the head branch of XFree86 to -the embedded-1-branch of Mesa. - - -STATUS - -Already working very well as far as I've tested it (16/32 bit). -glxgears runs at 935 fps (G550 32MB AGP 4x, Athlon 1.33) vs 744 fps with XFree. -Other demos (terrain, fire, etc.) have been successfully tested as well. - - -TODO - -- mgaEngineShutdown -- mgaEngineRestore -- SGRAM detection -- remove some unused bits from server/* -- subset driver support -- mgaWaitForVBlank -- deinitialization (from MGADRICloseScreen) a la radeonDestroyScreen diff --git a/src/mesa/drivers/dri/r300/pixel_shader.h b/src/mesa/drivers/dri/r300/pixel_shader.h deleted file mode 100644 index 0d04859f9b8..00000000000 --- a/src/mesa/drivers/dri/r300/pixel_shader.h +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef __PIXEL_SHADER_H__ -#define __PIXEL_SHADER_H__ - -#include "r300_reg.h" - - -/* INSTR 0 */ - -#define PFS_OP_MAD 0 -#define PFS_OP_DP3 1 -#define PFS_OP_DP4 2 -#define PFS_OP_MIN 4 -#define PFS_OP_MAX 5 -#define PFS_OP_CMP 8 -#define PFS_OP_FRC 9 -#define PFS_OP_OUTC_REPL_ALPHA 10 - -/* "or" these with arg0 value to negate or take absolute value of an argument */ -#define PFS_ARG_NEG (1<<5) -#define PFS_ARG_ABS (1<<6) - -#define MAKE_PFS_INSTR0(op, arg0, arg1, arg2, flags) \ - ( ((op)<<23) \ - | ((arg0)<<R300_FPI0_ARG0C_SHIFT) \ - | ((arg1)<<R300_FPI0_ARG1C_SHIFT) \ - | ((arg2)<<R300_FPI0_ARG2C_SHIFT) \ - | (flags) \ - ) - -#define PFS_FLAG_X 1 -#define PFS_FLAG_Y 2 -#define PFS_FLAG_XY 3 -#define PFS_FLAG_Z 4 -#define PFS_FLAG_XZ 5 -#define PFS_FLAG_YZ 6 -#define PFS_FLAG_ALL 7 -#define PFS_FLAG_NONE 0 - -#define EASY_PFS_INSTR0(op, arg0, arg1, arg2) \ - MAKE_PFS_INSTR0(PFS_OP_##op, \ - R300_FPI0_ARGC_##arg0, \ - R300_FPI0_ARGC_##arg1, \ - R300_FPI0_ARGC_##arg2, \ - 0) - -/* INSTR 1 */ - -#define PFS_FLAG_CONST (1<<5) - -#define MAKE_PFS_INSTR1(dstc, src0, src1, src2, reg, output) \ - ((src0) | ((src1) << R300_FPI1_SRC1C_SHIFT) \ - | ((src2)<<R300_FPI1_SRC2C_SHIFT) \ - | ((dstc) << R300_FPI1_DSTC_SHIFT) \ - | ((reg) << 23) | ((output)<<26)) - -#define EASY_PFS_INSTR1(dstc, src0, src1, src2, reg, output) \ - MAKE_PFS_INSTR1(dstc, src0, src1, src2, PFS_FLAG_##reg, PFS_FLAG_##output) - -/* INSTR 2 */ - -/* you can "or" PFS_ARG_NEG with these values to negate them */ - -#define MAKE_PFS_INSTR2(op, arg0, arg1, arg2, flags) \ - (((op) << 23) | \ - ((arg0)<<R300_FPI2_ARG0A_SHIFT) | \ - ((arg1)<<R300_FPI2_ARG1A_SHIFT) | \ - ((arg2)<<R300_FPI2_ARG2A_SHIFT) | \ - (flags)) - -#define EASY_PFS_INSTR2(op, arg0, arg1, arg2) \ - MAKE_PFS_INSTR2(R300_FPI2_OUTA_##op, \ - R300_FPI2_ARGA_##arg0, \ - R300_FPI2_ARGA_##arg1, \ - R300_FPI2_ARGA_##arg2, \ - 0) - - -/* INSTR 3 */ - -#define PFS_FLAG_NONE 0 -#define PFS_FLAG_REG 1 -#define PFS_FLAG_OUTPUT 2 -#define PFS_FLAG_BOTH 3 - -#define MAKE_PFS_INSTR3(dstc, src0, src1, src2, flags) \ - ((src0) | ((src1) << R300_FPI1_SRC1C_SHIFT) \ - | ((src2)<<R300_FPI1_SRC2C_SHIFT) \ - | ((dstc) << R300_FPI1_DSTC_SHIFT) \ - | ((flags) << 23)) - -#define EASY_PFS_INSTR3(dstc, src0, src1, src2, flag) \ - MAKE_PFS_INSTR3(dstc, src0, src1, src2, PFS_FLAG_##flag) - - /* What are 0's ORed with flags ? They are register numbers that - just happen to be 0 */ -#define PFS_NOP { \ - EASY_PFS_INSTR0(MAD, SRC0C_XYZ, ONE, ZERO), \ - EASY_PFS_INSTR1(0, 0, 0 | PFS_FLAG_CONST, 0 | PFS_FLAG_CONST, NONE, ALL), \ - EASY_PFS_INSTR2(MAD, SRC0A, ONE, ZERO), \ - EASY_PFS_INSTR3(0, 0, 0 | PFS_FLAG_CONST, 0 | PFS_FLAG_CONST, OUTPUT) \ - } - -#endif diff --git a/src/mesa/drivers/dri/r300/r300_fragprog_swz.c b/src/mesa/drivers/dri/r300/r300_fragprog_swz.c deleted file mode 100644 index b29331d7bde..00000000000 --- a/src/mesa/drivers/dri/r300/r300_fragprog_swz.c +++ /dev/null @@ -1,1328 +0,0 @@ -/* - * Copyright (C) 2005 Jerome Glisse. 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 (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 NONINFRINGEMENT. - * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) 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. - * - */ -#include "r300_fragprog.h" -#include "r300_reg.h" - - -#define I0_000 ( (R300_FPI0_OUTC_MAD) | \ - (R300_FPI0_ARGC_ZERO) | \ - (R300_FPI0_ARGC_ZERO << R300_FPI0_ARG1C_SHIFT) | \ - (R300_FPI0_ARGC_ZERO << R300_FPI0_ARG2C_SHIFT) ) -#define I0_111 ( (R300_FPI0_OUTC_MAD) | \ - (R300_FPI0_ARGC_ZERO) | \ - (R300_FPI0_ARGC_ZERO << R300_FPI0_ARG1C_SHIFT) | \ - (R300_FPI0_ARGC_ONE << R300_FPI0_ARG2C_SHIFT) ) -#define I0_XXX ( (R300_FPI0_OUTC_MAD) | \ - (R300_FPI0_ARGC_SRC0C_XXX) | \ - (R300_FPI0_ARGC_ONE << R300_FPI0_ARG1C_SHIFT) | \ - (R300_FPI0_ARGC_ZERO << R300_FPI0_ARG2C_SHIFT) ) -#define I0_YYY ( (R300_FPI0_OUTC_MAD) | \ - (R300_FPI0_ARGC_SRC0C_YYY) | \ - (R300_FPI0_ARGC_ONE << R300_FPI0_ARG1C_SHIFT) | \ - (R300_FPI0_ARGC_ZERO << R300_FPI0_ARG2C_SHIFT) ) -#define I0_ZZZ ( (R300_FPI0_OUTC_MAD) | \ - (R300_FPI0_ARGC_SRC0C_ZZZ) | \ - (R300_FPI0_ARGC_ONE << R300_FPI0_ARG1C_SHIFT) | \ - (R300_FPI0_ARGC_ZERO << R300_FPI0_ARG2C_SHIFT) ) -#define I0_XYZ ( (R300_FPI0_OUTC_MAD) | \ - (R300_FPI0_ARGC_SRC0C_XYZ) | \ - (R300_FPI0_ARGC_ONE << R300_FPI0_ARG1C_SHIFT) | \ - (R300_FPI0_ARGC_ZERO << R300_FPI0_ARG2C_SHIFT) ) -#define I0_YZX ( (R300_FPI0_OUTC_MAD) | \ - (R300_FPI0_ARGC_SRC0C_YZX) | \ - (R300_FPI0_ARGC_ONE << R300_FPI0_ARG1C_SHIFT) | \ - (R300_FPI0_ARGC_ZERO << R300_FPI0_ARG2C_SHIFT) ) -#define I0_ZXY ( (R300_FPI0_OUTC_MAD) | \ - (R300_FPI0_ARGC_SRC0C_ZXY) | \ - (R300_FPI0_ARGC_ONE << R300_FPI0_ARG1C_SHIFT) | \ - (R300_FPI0_ARGC_ZERO << R300_FPI0_ARG2C_SHIFT) ) -#define I0_WZY ( (R300_FPI0_OUTC_MAD) | \ - (R300_FPI0_ARGC_SRC0CA_WZY) | \ - (R300_FPI0_ARGC_ONE << R300_FPI0_ARG1C_SHIFT) | \ - (R300_FPI0_ARGC_ZERO << R300_FPI0_ARG2C_SHIFT) ) -#define I0_WWW ( (R300_FPI0_OUTC_MAD) | \ - (R300_FPI0_ARGC_SRC0A) | \ - (R300_FPI0_ARGC_ONE << R300_FPI0_ARG1C_SHIFT) | \ - (R300_FPI0_ARGC_ZERO << R300_FPI0_ARG2C_SHIFT) ) - -#define IEMPTY 0 - -#define I1_XYZ ( R300_FPI1_SRC1C_CONST | \ - R300_FPI1_SRC2C_CONST | \ - R300_FPI1_DSTC_REG_X | \ - R300_FPI1_DSTC_REG_Y | \ - R300_FPI1_DSTC_REG_Z ) -#define I1_XY_ ( R300_FPI1_SRC1C_CONST | \ - R300_FPI1_SRC2C_CONST | \ - R300_FPI1_DSTC_REG_X | \ - R300_FPI1_DSTC_REG_Y ) -#define I1_X_Z ( R300_FPI1_SRC1C_CONST | \ - R300_FPI1_SRC2C_CONST | \ - R300_FPI1_DSTC_REG_X | \ - R300_FPI1_DSTC_REG_Z ) -#define I1__YZ ( R300_FPI1_SRC1C_CONST | \ - R300_FPI1_SRC2C_CONST | \ - R300_FPI1_DSTC_REG_Y | \ - R300_FPI1_DSTC_REG_Z ) -#define I1_X__ ( R300_FPI1_SRC1C_CONST | \ - R300_FPI1_SRC2C_CONST | \ - R300_FPI1_DSTC_REG_X ) -#define I1__Y_ ( R300_FPI1_SRC1C_CONST | \ - R300_FPI1_SRC2C_CONST | \ - R300_FPI1_DSTC_REG_Y ) -#define I1___Z ( R300_FPI1_SRC1C_CONST | \ - R300_FPI1_SRC2C_CONST | \ - R300_FPI1_DSTC_REG_Z ) - -#define SEMPTY {0,{0,0,0,0},{0,0,0,0,0,0,0,0}} - -struct r300_fragment_program_swizzle r300_swizzle [512] = { - /* XXX */ - {1,{0,0,0,0},{ I0_XXX, I1_XYZ, - 0, 0, 0, 0, 0, 0 } }, - /* YXX */ - {2,{0,0,0,0},{ I0_YZX, I1_X_Z, - I0_XXX, I1__Y_, - 0,0, - 0,0 } }, - /* ZXX */ - {2,{0,0,0,0},{ I0_ZZZ, I1_X__, - I0_XXX, I1__YZ, - 0,0, - 0,0 } }, - /* WXX */ - {2,{0,0,0,0},{ I0_WZY, I1_X__, - I0_XXX, I1__YZ, - 0,0, - 0,0} }, - /* 0XX */ - {2,{0,2,0,0},{ I0_XXX, I1__YZ, - I0_000, I1_X__, - 0,0, - 0,0 } }, - /* 1XX */ - {2,{0,2,0,0},{ I0_XXX, I1__YZ, - I0_111, I1_X__, - 0,0,0,0}}, - SEMPTY,SEMPTY, - /* XYX */ - {2,{0,0,0,0},{ I0_YYY, I1__Y_, - I0_XXX, I1_X_Z, - 0,0,0,0}}, - /* YYX */ - {2,{0,0,0,0},{ I0_YYY, I1_XY_, - I0_XXX, I1___Z, - 0,0,0,0}}, - /* ZYX */ - {3,{0,0,0,0},{ I0_ZZZ, I1_X__, - I0_YYY, I1__Y_, - I0_XXX, I1___Z, - 0,0}}, - /* WYX */ - {3,{0,0,0,0},{ I0_WZY, I1_X__, - I0_YYY, I1__Y_, - I0_XXX, I1___Z, - 0,0}}, - /* 0YX */ - {3,{0,0,2,0},{ I0_YYY, I1__Y_, - I0_XXX, I1___Z, - I0_000, I1_X__, - 0,0}}, - /* 1YX */ - {3,{0,0,2,0},{ I0_YYY, I1__Y_, - I0_XXX, I1___Z, - I0_111, I1_X__, - 0,0}}, - SEMPTY,SEMPTY, - /* XZX */ - {2,{0,0,0,0},{ I0_YZX, I1__YZ, - I0_XXX, I1_X__, - 0,0,0,0}}, - /* YZX */ - {1,{0,0,0,0},{ I0_YZX, I1_XYZ, - 0, 0, 0, 0, 0, 0 } }, - /* ZZX */ - {2,{0,0,0,0},{ I0_YZX, I1__YZ, - I0_ZZZ, I1_X__,0,0,0,0}}, - /* WZX */ - {2,{0,0,0,0},{ I0_WZY, I1_XY_, - I0_XXX, I1___Z,0,0,0,0}}, - /* 0ZX */ - {2,{0,2,0,0},{ I0_YZX, I1__YZ, - I0_000, I1_X__, - 0,0,0,0}}, - /* 1ZX */ - {2,{0,2,0,0},{ I0_YZX, I1__YZ, - I0_111, I1_X__, - 0,0,0,0}}, - SEMPTY,SEMPTY, - /* XWX */ - {2,{0,0,0,0},{ I0_WWW, I1__Y_, - I0_XXX, I1_X_Z, - 0,0,0,0}}, - /* YWX */ - {2,{0,0,0,0},{ I0_WWW, I1__Y_, - I0_YZX, I1_X_Z, - 0,0,0,0}}, - /* ZWX */ - {3,{0,0,0,0},{ I0_WWW, I1__Y_, - I0_ZZZ, I1_X__, - I0_XXX, I1___Z, - 0,0}}, - /* WWX */ - {2,{0,0,0,0},{ I0_WWW, I1_XY_, - I0_YZX, I1___Z, - 0,0,0,0}}, - /* 0WX */ - {3,{0,0,2,0},{ I0_WWW, I1__Y_, - I0_XXX, I1___Z, - I0_000, I1_X__, - 0,0}}, - /* 1WX */ - {3,{0,0,2,0},{ I0_WWW, I1__Y_, - I0_XXX, I1___Z, - I0_111, I1_X__, - 0,0}}, - SEMPTY,SEMPTY, - /* X0X */ - {2,{0,2,0,0},{ I0_XXX, I1_X_Z, - I0_000, I1__Y_, - 0,0,0,0}}, - /* Y0X */ - {2,{0,2,0,0},{ I0_YZX, I1_X_Z, - I0_000, I1__Y_, - 0,0,0,0}}, - /* Z0X */ - {3,{0,2,0,0},{ I0_XXX, I1___Z, - I0_000, I1__Y_, - I0_ZZZ, I1_X__, - 0,0}}, - /* W0X */ - {3,{0,0,2,0},{ I0_WZY, I1_XYZ, - I0_XXX, I1___Z, - I0_000, I1__Y_, - 0,0}}, - /* 00X */ - {2,{0,2,0,0},{ I0_XXX, I1___Z, - I0_000, I1_XY_, - 0,0,0,0}}, - /* 10X */ - {3,{0,2,0,0},{ I0_XXX, I1___Z, - I0_000, I1__Y_, - I0_111, I1_X__, - 0,0}}, - SEMPTY,SEMPTY, - /* X1X */ - {2,{0,2,0,0},{ I0_XXX, I1_X_Z, - I0_111, I1__Y_, - 0,0,0,0}}, - /* Y1X */ - {2,{0,2,0,0},{ I0_YZX, I1_X_Z, - I0_111, I1__Y_, - 0,0,0,0}}, - /* Z1X */ - {3,{0,2,0,0},{ I0_XXX, I1___Z, - I0_111, I1__Y_, - I0_ZZZ, I1_X__, - 0,0}}, - /* W1X */ - {3,{0,0,2,0},{ I0_WZY, I1_XYZ, - I0_XXX, I1___Z, - I0_111, I1__Y_, - 0,0}}, - /* 01X */ - {3,{0,2,0,0},{ I0_XXX, I1___Z, - I0_111, I1__Y_, - I0_000, I1_X__, - 0,0}}, - /* 11X */ - {2,{0,2,0,0},{ I0_XXX, I1___Z, - I0_111, I1_XY_, - 0,0,0,0}}, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - /* XXY */ - {2,{0,0,0,0},{ I0_YYY, I1___Z, - I0_XXX, I1_XY_, - 0,0,0,0}}, - /* YXY */ - {2,{0,0,0,0},{ I0_YYY, I1_X_Z, - I0_XXX, I1__Y_, - 0,0,0,0}}, - /* ZXY */ - {1,{0,0,0,0},{ I0_ZXY, I1_XYZ, - 0, 0, 0, 0, 0, 0 } }, - /* WXY */ - {2,{0,0,0,0},{ I0_WZY, I1_X__, - I0_ZXY, I1__YZ, - 0,0,0,0}}, - /* 0XY */ - {2,{0,0,0,0},{ I0_ZXY, I1__YZ, - I0_000, I1_X__, - 0,0,0,0}}, - /* 1XY */ - {2,{0,0,0,0},{ I0_ZXY, I1__YZ, - I0_111, I1_X__, - 0,0,0,0}}, - SEMPTY,SEMPTY, - /* XYY */ - {2,{0,0,0,0},{ I0_YYY, I1__YZ, - I0_XXX, I1_X__, - 0,0,0,0}}, - /* YYY */ - {1,{0,0,0,0},{ I0_YYY, I1_XYZ, - 0, 0, 0, 0, 0, 0 } }, - /* ZYY */ - {2,{0,0,0,0},{ I0_YYY, I1__YZ, - I0_ZZZ, I1_X__, - 0,0,0,0}}, - /* WYY */ - {2,{0,0,0,0},{ I0_WZY, I1_XYZ, - I0_YYY, I1__YZ, - 0,0,0,0}}, - /* 0YY */ - {2,{0,0,0,0},{ I0_YYY, I1__YZ, - I0_000, I1_X__, - 0,0,0,0}}, - /* 1YY */ - {2,{0,0,0,0},{ I0_YYY, I1__YZ, - I0_111, I1_X__, - 0,0,0,0}}, - SEMPTY,SEMPTY, - /* XZY */ - {2,{0,0,0,0},{ I0_WZY, I1__YZ, - I0_XXX, I1_X__, - 0,0,0,0}}, - /* YZY */ - {2,{0,0,0,0},{ I0_WZY, I1__YZ, - I0_YYY, I1_X__, - 0,0,0,0}}, - /* ZZY */ - {2,{0,0,0,0},{ I0_WZY, I1__YZ, - I0_ZZZ, I1_X__, - 0,0,0,0}}, - /* WZY */ - {1,{0,0,0,0},{ I0_WZY, I1_XYZ, - 0, 0, 0, 0, 0, 0 } }, - /* 0ZY */ - {2,{0,0,0,0},{ I0_WZY, I1__YZ, - I0_000, I1_X__, - 0,0,0,0}}, - /* 1ZY */ - {2,{0,0,0,0},{ I0_WZY, I1__YZ, - I0_111, I1_X__, - 0,0,0,0}}, - SEMPTY,SEMPTY, - /* XWY */ - {3,{0,0,0,0},{ I0_WWW, I1__Y_, - I0_XXX, I1_X__, - I0_YYY, I1___Z, - 0,0}}, - /* YWY */ - {2,{0,0,0,0},{ I0_WWW, I1__Y_, - I0_YYY, I1_X_Z, - 0,0,0,0}}, - /* ZWY */ - {2,{0,0,0,0},{ I0_WWW, I1__Y_, - I0_ZXY, I1_X_Z, - 0,0,0,0}}, - /* WWY */ - {2,{0,0,0,0},{ I0_WWW, I1_XY_, - I0_ZXY, I1___Z, - 0,0,0,0}}, - /* 0WY */ - {3,{0,0,2,0},{ I0_WWW, I1__Y_, - I0_ZXY, I1___Z, - I0_000, I1_X__, - 0,0}}, - /* 1WY */ - {3,{0,0,0,0},{ I0_WWW, I1__Y_, - I0_ZXY, I1___Z, - I0_111, I1_X__, - 0,0}}, - SEMPTY,SEMPTY, - /* X0Y */ - {3,{0,2,0,0},{ I0_XXX, I1_X__, - I0_000, I1__Y_, - I0_YYY, I1___Z, - 0,0}}, - /* Y0Y */ - {2,{0,2,0,0},{ I0_YYY, I1_X_Z, - I0_000, I1__Y_, - 0,0,0,0}}, - /* Z0Y */ - {2,{0,2,0,0},{ I0_ZXY, I1_X_Z, - I0_000, I1__Y_, - 0,0,0,0}}, - /* W0Y */ - {2,{0,2,0,0},{ I0_WZY, I1_X_Z, - I0_000, I1__Y_, - 0,0,0,0}}, - /* 00Y */ - {2,{0,2,0,0},{ I0_YYY, I1___Z, - I0_000, I1_XY_, - 0,0,0,0}}, - /* 10Y */ - {3,{0,2,0,0},{ I0_YYY, I1___Z, - I0_000, I1__Y_, - I0_111, I1_X__, - 0,0}}, - SEMPTY,SEMPTY, - /* X1Y */ - {3,{0,2,0,0},{ I0_XXX, I1_X__, - I0_111, I1__Y_, - I0_YYY, I1___Z, - 0,0}}, - /* Y1Y */ - {2,{0,2,0,0},{ I0_YYY, I1_X_Z, - I0_111, I1__Y_, - 0,0,0,0}}, - /* Z1Y */ - {2,{0,2,0,0},{ I0_ZXY, I1_X_Z, - I0_111, I1__Y_, - 0,0,0,0}}, - /* W1Y */ - {3,{0,2,0,0},{ I0_WZY, I1_X_Z, - I0_111, I1__Y_, - 0,0,0,0}}, - /* 01Y */ - {3,{0,2,0,0},{ I0_YYY, I1___Z, - I0_111, I1__Y_, - I0_000, I1_X__, - 0,0}}, - /* 11Y */ - {2,{0,2,0,0},{ I0_YYY, I1___Z, - I0_111, I1_XY_, - 0,0,0,0}}, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - /* XXZ */ - {2,{0,0,0,0},{ I0_XXX, I1_XY_, - I0_ZZZ, I1___Z, - 0,0,0,0}}, - /* YXZ */ - {3,{0,0,0,0},{ I0_XXX, I1__Y_, - I0_YYY, I1_X__, - I0_ZZZ, I1___Z, - 0,0}}, - /* ZXZ */ - {2,{0,0,0,0},{ I0_XXX, I1__Y_, - I0_ZZZ, I1_X_Z, - 0,0,0,0}}, - /* WXZ */ - {3,{0,0,0,0},{ I0_WZY, I1_XYZ, - I0_XXX, I1__Y_, - I0_ZZZ, I1___Z, - 0,0}}, - /* 0XZ */ - {3,{0,0,2,0},{ I0_XXX, I1__Y_, - I0_ZZZ, I1___Z, - I0_000, I1_X__, - 0,0}}, - /* 1XZ */ - {3,{0,0,2,0},{ I0_XXX, I1__Y_, - I0_ZZZ, I1___Z, - I0_111, I1_X__, - 0,0}}, - SEMPTY,SEMPTY, - /* XYZ */ - {1,{0,0,0,0},{ I0_XYZ, I1_XYZ, - 0, 0, 0, 0, 0, 0 } }, - /* YYZ */ - {2,{0,0,0,0},{ I0_ZZZ, I1___Z, - I0_YYY, I1_XY_, - 0,0,0,0}}, - /* ZYZ */ - {2,{0,0,0,0},{ I0_ZZZ, I1_X_Z, - I0_YYY, I1__Y_, - 0,0,0,0}}, - /* WYZ */ - {2,{0,0,0,0},{ I0_WZY, I1_XYZ, - I0_XYZ, I1__YZ, - 0,0,0,0}}, - /* 0YZ */ - {2,{0,2,0,0},{ I0_XYZ, I1__YZ, - I0_000, I1_X__, - 0,0,0,0}}, - /* 1YZ */ - {2,{0,2,0,0},{ I0_XYZ, I1__YZ, - I0_111, I1_X__, - 0,0,0,0}}, - SEMPTY,SEMPTY, - /* XZZ */ - {2,{0,0,0,0},{ I0_ZZZ, I1__YZ, - I0_XXX, I1_X__, - 0,0,0,0}}, - /* YZZ */ - {2,{0,0,0,0},{ I0_ZZZ, I1__YZ, - I0_YYY, I1_X__, - 0,0,0,0}}, - /* ZZZ */ - {1,{0,0,0,0},{ I0_ZZZ, I1_XYZ, - 0, 0, 0, 0, 0, 0 } }, - /* WZZ */ - {2,{0,0,0,0},{ I0_WZY, I1_XYZ, - I0_ZZZ, I1__YZ, - 0,0,0,0}}, - /* 0ZZ */ - {2,{0,2,0,0},{ I0_ZZZ, I1__YZ, - I0_000, I1_X__, - 0,0,0,0}}, - /* 1ZZ */ - {2,{0,2,0,0},{ I0_ZZZ, I1__YZ, - I0_111, I1_X__, - 0,0,0,0}}, - SEMPTY,SEMPTY, - /* XWZ */ - {2,{0,0,0,0},{ I0_WWW, I1__Y_, - I0_XYZ, I1_X_Z, - 0,0,0,0}}, - /* YWZ */ - {3,{0,0,0,0},{ I0_WWW, I1__Y_, - I0_YYY, I1_X__, - I0_XYZ, I1___Z, - 0,0}}, - /* ZWZ */ - {2,{0,0,0,0},{ I0_WWW, I1__Y_, - I0_ZZZ, I1_X_Z, - 0,0,0,0}}, - /* WWZ */ - {2,{0,0,0,0},{ I0_WWW, I1_XY_, - I0_XYZ, I1___Z, - 0,0,0,0}}, - /* 0WZ */ - {3,{0,0,2,0},{ I0_WWW, I1__Y_, - I0_XYZ, I1___Z, - I0_000, I1_X__, - 0,0}}, - /* 1WZ */ - {3,{0,0,2,0},{ I0_WWW, I1__Y_, - I0_XYZ, I1___Z, - I0_111, I1_X__, - 0,0}}, - SEMPTY,SEMPTY, - /* X0Z */ - {2,{0,2,0,0},{ I0_XYZ, I1_X_Z, - I0_000, I1__Y_, - 0,0,0,0}}, - /* Y0Z */ - {3,{0,2,0,0},{ I0_ZZZ, I1___Z, - I0_000, I1__Y_, - I0_YYY, I1_X__, - 0,0}}, - /* Z0Z */ - {2,{0,2,0,0},{ I0_ZZZ, I1_X_Z, - I0_000, I1__Y_, - 0,0,0,0}}, - /* W0Z */ - {3,{0,0,2,0},{ I0_WZY, I1_X_Z, - I0_ZZZ, I1___Z, - I0_000, I1__Y_, - 0,0}}, - /* 00Z */ - {2,{0,2,0,0},{ I0_ZZZ, I1___Z, - I0_000, I1_XY_, - 0,0,0,0}}, - /* 10Z */ - {3,{0,2,2,0},{ I0_ZZZ, I1___Z, - I0_000, I1__Y_, - I0_111, I1_X__, - 0,0}}, - SEMPTY,SEMPTY, - /* X1Z */ - {2,{0,2,0,0},{ I0_XYZ, I1_X_Z, - I0_111, I1__Y_, - 0,0,0,0}}, - /* Y1Z */ - {3,{0,2,0,0},{ I0_ZZZ, I1___Z, - I0_111, I1__Y_, - I0_YYY, I1_X__, - 0,0}}, - /* Z1Z */ - {2,{0,2,0,0},{ I0_ZZZ, I1_X_Z, - I0_111, I1__Y_, - 0,0,0,0}}, - /* W1Z */ - {3,{0,0,2,0},{ I0_WZY, I1_XYZ, - I0_ZZZ, I1___Z, - I0_111, I1__Y_, - 0,0}}, - /* 01Z */ - {3,{0,2,2,0},{ I0_ZZZ, I1___Z, - I0_111, I1__Y_, - I0_000, I1_X__, - 0,0}}, - /* 11Z */ - {2,{0,2,0,0},{ I0_ZZZ, I1___Z, - I0_111, I1_XY_, - 0,0,0,0}}, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - /* XXW */ - {2,{0,0,0,0},{ I0_WWW, I1___Z, - I0_XXX, I1_XY_, - 0,0,0,0}}, - /* YXW */ - {3,{0,0,0,0},{ I0_WWW, I1___Z, - I0_XXX, I1__Y_, - I0_YYY, I1_X__, - 0,0}}, - /* ZXW */ - {2,{0,0,0,0},{ I0_WWW, I1___Z, - I0_ZXY, I1_XY_, - 0,0,0,0}}, - /* WXW */ - {2,{0,0,0,0},{ I0_WWW, I1_X_Z, - I0_XXX, I1__Y_, - 0,0,0,0}}, - /* 0XW */ - {3,{0,0,2,0},{ I0_WWW, I1___Z, - I0_XXX, I1__Y_, - I0_000, I1_X__, - 0,0}}, - /* 1XW */ - {3,{0,0,2,0},{ I0_WWW, I1___Z, - I0_XXX, I1__Y_, - I0_111, I1_X__, - 0,0}}, - SEMPTY,SEMPTY, - /* XYW */ - {2,{0,0,0,0},{ I0_WWW, I1___Z, - I0_XYZ, I1_XY_, - 0,0,0,0}}, - /* YYW */ - {2,{0,0,0,0},{ I0_WWW, I1___Z, - I0_YYY, I1_XY_, - 0,0}}, - /* ZYW */ - {3,{0,0,0,0},{ I0_WWW, I1___Z, - I0_XYZ, I1__Y_, - I0_ZZZ, I1_X__, - 0,0}}, - /* WYW */ - {2,{0,0,0,0},{ I0_WWW, I1_X_Z, - I0_YYY, I1__Y_, - 0,0,0,0}}, - /* 0YW */ - {3,{0,0,2,0},{ I0_WWW, I1___Z, - I0_YYY, I1__Y_, - I0_000, I1_X__, - 0,0}}, - /* 1YW */ - {3,{0,0,2,0},{ I0_WWW, I1___Z, - I0_YYY, I1__Y_, - I0_111, I1_X__, - 0,0}}, - - SEMPTY,SEMPTY, - /* XZW */ - {3,{0,0,0,0},{ I0_WWW, I1___Z, - I0_XYZ, I1_X__, - I0_ZZZ, I1__Y_, - 0,0}}, - /* YZW */ - {2,{0,0,0,0},{ I0_WWW, I1___Z, - I0_YZX, I1_XY_, - 0,0,0,0}}, - /* ZZW */ - {2,{0,0,0,0},{ I0_WWW, I1___Z, - I0_ZZZ, I1_XY_, - 0,0,0,0}}, - /* WZW */ - {2,{0,0,0,0},{ I0_WWW, I1_X_Z, - I0_ZZZ, I1__Y_, - 0,0,0,0}}, - /* 0ZW */ - {3,{0,0,2,0},{ I0_WWW, I1___Z, - I0_ZZZ, I1__Y_, - I0_000, I1_X__, - 0,0}}, - /* 1ZW */ - {3,{0,0,2,0},{ I0_WWW, I1___Z, - I0_ZZZ, I1__Y_, - I0_111, I1_X__, - 0,0}}, - - SEMPTY,SEMPTY, - /* XWW */ - {2,{0,0,0,0},{ I0_WWW, I1__YZ, - I0_XYZ, I1_X__, - 0,0,0,0}}, - /* YWW */ - {2,{0,0,0,0},{ I0_WWW, I1__YZ, - I0_YYY, I1_X__, - 0,0,0,0}}, - /* ZWW */ - {2,{0,0,0,0},{ I0_WWW, I1__YZ, - I0_ZZZ, I1_X__, - 0,0,0,0}}, - /* WWW */ - {1,{0,0,0,0},{ I0_WWW, I1_XYZ, - 0,0,0,0,0,0}}, - /* 0WW */ - {2,{0,2,0,0},{ I0_WWW, I1__YZ, - I0_000, I1_X__, - 0,0,0,0}}, - /* 1WW */ - {2,{0,2,0,0},{ I0_WWW, I1__YZ, - I0_111, I1_X__, - 0,0}}, - SEMPTY,SEMPTY, - /* X0W */ - {3,{0,0,2,0},{ I0_WWW, I1___Z, - I0_XYZ, I1_X__, - I0_000, I1__Y_, - 0,0}}, - /* Y0W */ - {3,{0,0,2,0},{ I0_WWW, I1___Z, - I0_YYY, I1_X__, - I0_000, I1__Y_, - 0,0}}, - /* Z0W */ - {3,{0,0,2,0},{ I0_WWW, I1___Z, - I0_ZZZ, I1_X__, - I0_000, I1__Y_, - 0,0}}, - /* W0W */ - {2,{0,2,0,0},{ I0_WWW, I1_X_Z, - I0_000, I1__Y_, - 0,0,0,0}}, - /* 00W */ - {2,{0,2,0,0},{ I0_WWW, I1___Z, - I0_000, I1_XY_, - 0,0,0,0}}, - /* 10W */ - {3,{0,2,2,0},{ I0_WWW, I1___Z, - I0_111, I1_X__, - I0_000, I1__Y_, - 0,0}}, - SEMPTY,SEMPTY, - /* X1W */ - {3,{0,0,2,0},{ I0_WWW, I1___Z, - I0_XYZ, I1_X__, - I0_111, I1__Y_, - 0,0}}, - /* Y1W */ - {3,{0,0,2,0},{ I0_WWW, I1___Z, - I0_YYY, I1_X__, - I0_111, I1__Y_, - 0,0}}, - /* Z1W */ - {3,{0,0,2,0},{ I0_WWW, I1___Z, - I0_ZZZ, I1_X__, - I0_111, I1__Y_, - 0,0}}, - /* W1W */ - {2,{0,2,0,0},{ I0_WWW, I1_XYZ, - I0_111, I1__Y_, - 0,0,0,0}}, - /* 01W */ - {3,{0,2,2,0},{ I0_WWW, I1___Z, - I0_000, I1_X__, - I0_111, I1__Y_, - 0,0}}, - /* 11W */ - {2,{0,2,0,0},{ I0_WWW, I1___Z, - I0_111, I1_XY_, - 0,0,0,0}}, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - /* XX0 */ - {2,{0,2,0,0},{ I0_XXX, I1_XY_, - I0_000, I1___Z, - 0,0,0,0}}, - /* YX0 */ - {3,{0,0,2,0},{ I0_YYY, I1_X__, - I0_XXX, I1__Y_, - I0_000, I1___Z, - 0,0}}, - /* ZX0 */ - {2,{0,2,0,0},{ I0_ZXY, I1_XY_, - I0_000, I1___Z, - 0,0,0,0}}, - /* WX0 */ - {3,{0,0,2,0},{ I0_WZY, I1_X__, - I0_XXX, I1__Y_, - I0_000, I1___Z, - 0,0}}, - /* 0X0 */ - {2,{0,2,0,0},{ I0_XXX, I1__Y_, - I0_000, I1_X_Z, - 0,0,0,0}}, - /* 1X0 */ - {3,{0,2,2,0},{ I0_XXX, I1__Y_, - I0_000, I1___Z, - I0_111, I1_X__, - 0,0}}, - SEMPTY,SEMPTY, - /* XY0 */ - {2,{0,2,0,0},{ I0_XYZ, I1_XY_, - I0_000, I1___Z, - 0,0,0,0}}, - /* YY0 */ - {2,{0,2,0,0},{ I0_YYY, I1_XY_, - I0_000, I1___Z, - 0,0,0,0}}, - /* ZY0 */ - {3,{0,0,2,0},{ I0_YYY, I1__Y_, - I0_ZZZ, I1_X__, - I0_000, I1___Z, - 0,0}}, - /* WY0 */ - {3,{0,0,2,0},{ I0_WZY, I1_X__, - I0_XYZ, I1__Y_, - I0_000, I1___Z, - 0,0}}, - /* 0Y0 */ - {2,{0,2,0,0},{ I0_XYZ, I1__Y_, - I0_000, I1_X_Z, - 0,0,0,0}}, - /* 1Y0 */ - {3,{0,2,2,0},{ I0_XYZ, I1__Y_, - I0_000, I1___Z, - I0_111, I1_X__, - 0,0}}, - SEMPTY,SEMPTY, - /* XZ0 */ - {3,{0,0,2,0},{ I0_ZZZ, I1__Y_, - I0_XYZ, I1_X__, - I0_000, I1___Z, - 0,0}}, - /* YZ0 */ - {2,{0,2,0,0},{ I0_YZX, I1_XY_, - I0_000, I1___Z, - 0,0,0,0}}, - /* ZZ0 */ - {2,{0,2,0,0},{ I0_ZZZ, I1_XY_, - I0_000, I1___Z, - 0,0,0,0}}, - /* WZ0 */ - {3,{0,0,2,0},{ I0_XYZ, I1_XYZ, - I0_WZY, I1_XY_, - I0_000, I1___Z, - 0,0}}, - /* 0Z0 */ - {2,{0,2,0,0},{ I0_ZZZ, I1__Y_, - I0_000, I1_X_Z, - 0,0,0,0}}, - /* 1Z0 */ - {3,{0,2,2,0},{ I0_ZZZ, I1__Y_, - I0_000, I1___Z, - I0_111, I1_X__, - 0,0}}, - SEMPTY,SEMPTY, - /* XW0 */ - {3,{0,0,2,0},{ I0_WWW, I1__Y_, - I0_XYZ, I1_X__, - I0_000, I1___Z, - 0,0}}, - /* YW0 */ - {3,{0,2,0,0},{ I0_WWW, I1__Y_, - I0_000, I1___Z, - I0_YYY, I1_X__, - 0,0}}, - /* ZW0 */ - {3,{0,2,0,0},{ I0_WWW, I1__Y_, - I0_000, I1___Z, - I0_ZZZ, I1_X__, - 0,0}}, - /* WW0 */ - {2,{0,2,0,0},{ I0_WWW, I1_XY_, - I0_000, I1___Z, - 0,0,0,0}}, - /* 0W0 */ - {2,{0,2,0,0},{ I0_WWW, I1__Y_, - I0_000, I1_X_Z, - 0,0,0,0}}, - /* 1W0 */ - {3,{0,2,2,0},{ I0_WWW, I1__Y_, - I0_000, I1___Z, - I0_111, I1_X__, - 0,0}}, - SEMPTY,SEMPTY, - /* X00 */ - {2,{0,2,0,0},{ I0_XYZ, I1_X__, - I0_000, I1__YZ, - 0,0,0,0}}, - /* Y00 */ - {2,{0,2,0,0},{ I0_YYY, I1_X__, - I0_000, I1__YZ, - 0,0,0,0}}, - /* Z00 */ - {2,{0,2,0,0},{ I0_ZZZ, I1_X__, - I0_000, I1__YZ, - 0,0,0,0}}, - /* W00 */ - {2,{2,0,0,0},{ I0_WZY, I1_X__, - I0_000, I1__YZ, - 0,0,0,0}}, - /* 000 */ - {1,{2,0,0,0},{ I0_000, I1_XYZ, - 0, 0, 0, 0, 0, 0 } }, - /* 100 */ - {2,{2,2,0,0},{ I0_000, I1__YZ, - I0_111, I1_X__, - 0,0,0,0}}, - SEMPTY,SEMPTY, - /* X10 */ - {3,{0,2,2,0},{ I0_XYZ, I1_XYZ, - I0_000, I1___Z, - I0_111, I1__Y_, - 0,0}}, - /* Y10 */ - {3,{0,2,2,0},{ I0_YYY, I1_XYZ, - I0_000, I1___Z, - I0_111, I1__Y_, - 0,0}}, - /* Z10 */ - {3,{0,2,2,0},{ I0_ZZZ, I1_XYZ, - I0_000, I1___Z, - I0_111, I1__Y_, - 0,0}}, - /* W10 */ - {3,{0,2,2,0},{ I0_WZY, I1_XYZ, - I0_000, I1___Z, - I0_111, I1__Y_, - 0,0}}, - /* 010 */ - {2,{2,2,0,0},{ I0_000, I1_X_Z, - I0_111, I1__Y_, - 0, 0, 0, 0 } }, - /* 110 */ - {2,{2,2,0,0},{ I0_000, I1___Z, - I0_111, I1_XY_, - 0,0,0,0}}, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - - - - /* XX1 */ - {2,{0,2,0,0},{ I0_XXX, I1_XY_, - I0_111, I1___Z, - 0,0,0,0}}, - /* YX1 */ - {3,{0,0,2,0},{ I0_YYY, I1_X__, - I0_XXX, I1__Y_, - I0_111, I1___Z, - 0,0}}, - /* ZX1 */ - {2,{0,2,0,0},{ I0_ZXY, I1_XY_, - I0_111, I1___Z, - 0,0,0,0}}, - /* WX1 */ - {3,{0,0,2,0},{ I0_WZY, I1_XYZ, - I0_XXX, I1__Y_, - I0_111, I1___Z, - 0,0}}, - /* 0X1 */ - {3,{0,2,2,0},{ I0_XXX, I1__Y_, - I0_111, I1___Z, - I0_000, I1_X__, - 0,0}}, - /* 1X1 */ - {2,{0,2,0,0},{ I0_XXX, I1__Y_, - I0_111, I1_X_Z, - 0,0,0,0}}, - SEMPTY,SEMPTY, - /* XY1 */ - {2,{0,2,0,0},{ I0_XYZ, I1_XY_, - I0_111, I1___Z, - 0,0,0,0}}, - /* YY1 */ - {2,{0,2,0,0},{ I0_YYY, I1_XY_, - I0_111, I1___Z, - 0,0,0,0}}, - /* ZY1 */ - {3,{0,0,2,0},{ I0_YYY, I1__Y_, - I0_ZZZ, I1_X__, - I0_111, I1___Z, - 0,0}}, - /* WY1 */ - {3,{0,0,2,0},{ I0_WZY, I1_XYZ, - I0_XYZ, I1__Y_, - I0_111, I1___Z, - 0,0}}, - /* 0Y1 */ - {3,{0,2,2,0},{ I0_XYZ, I1__Y_, - I0_111, I1___Z, - I0_000, I1_X__, - 0,0}}, - /* 1Y1 */ - {2,{0,2,0,0},{ I0_XYZ, I1__Y_, - I0_111, I1_X_Z, - 0,0,0,0}}, - SEMPTY,SEMPTY, - /* XZ1 */ - {3,{0,0,2,0},{ I0_ZZZ, I1__Y_, - I0_XYZ, I1_X__, - I0_111, I1___Z, - 0,0}}, - /* YZ1 */ - {2,{0,2,0,0},{ I0_YZX, I1_XY_, - I0_111, I1___Z, - 0,0,0,0}}, - /* ZZ1 */ - {2,{0,2,0,0},{ I0_ZZZ, I1_XYZ, - I0_111, I1___Z, - 0,0,0,0}}, - /* WZ1 */ - {2,{0,2,0,0},{ I0_WZY, I1_XY_, - I0_111, I1___Z, - 0,0,0,0}}, - /* 0Z1 */ - {3,{0,2,2,0},{ I0_ZZZ, I1_XYZ, - I0_111, I1___Z, - I0_000, I1_X__, - 0,0}}, - /* 1Z1 */ - {2,{0,2,0,0},{ I0_ZZZ, I1__Y_, - I0_111, I1_X_Z, - 0,0,0,0}}, - SEMPTY,SEMPTY, - /* XW1 */ - {3,{0,0,2,0},{ I0_WWW, I1__Y_, - I0_XYZ, I1_X__, - I0_111, I1___Z, - 0,0}}, - /* YW1 */ - {3,{0,2,0,0},{ I0_WWW, I1__Y_, - I0_111, I1___Z, - I0_YYY, I1_X__, - 0,0}}, - /* ZW1 */ - {3,{0,2,0,0},{ I0_WWW, I1__Y_, - I0_111, I1___Z, - I0_ZZZ, I1_X__, - 0,0}}, - /* WW1 */ - {2,{0,2,0,0},{ I0_WWW, I1_XY_, - I0_111, I1___Z, - 0,0,0,0}}, - /* 0W1 */ - {3,{0,2,2,0},{ I0_WWW, I1__Y_, - I0_111, I1___Z, - I0_000, I1_X__, - 0,0}}, - /* 1W1 */ - {2,{0,2,0,0},{ I0_WWW, I1__Y_, - I0_111, I1_X_Z, - 0,0,0,0}}, - SEMPTY,SEMPTY, - /* X01 */ - {3,{0,2,2,0},{ I0_XYZ, I1_X__, - I0_111, I1___Z, - I0_000, I1__Y_, - 0,0}}, - /* Y01 */ - {3,{0,2,2,0},{ I0_YYY, I1_X__, - I0_111, I1___Z, - I0_000, I1__Y_, - 0,0}}, - /* Z01 */ - {3,{0,2,2,0},{ I0_ZZZ, I1_X__, - I0_111, I1___Z, - I0_000, I1__Y_, - 0,0}}, - /* W01 */ - {3,{0,2,2,0},{ I0_WZY, I1_XYZ, - I0_111, I1___Z, - I0_000, I1__Y_, - 0,0}}, - /* 001 */ - {2,{2,2,0,0},{ I0_111, I1___Z, - I0_000, I1_XY_, - 0,0,0,0}}, - /* 101 */ - {2,{2,2,0,0},{ I0_111, I1_X_Z, - I0_000, I1__Y_, - 0, 0, 0, 0 } }, - SEMPTY,SEMPTY, - /* X11 */ - {2,{0,2,0,0},{ I0_XYZ, I1_X__, - I0_111, I1__YZ, - 0,0,0,0}}, - /* Y11 */ - {2,{0,2,0,0},{ I0_YYY, I1_X__, - I0_111, I1__YZ, - 0,0,0,0}}, - /* Z11 */ - {2,{0,2,0,0},{ I0_ZZZ, I1_X__, - I0_111, I1__YZ, - 0,0,0,0}}, - /* W11 */ - {2,{0,2,0,0},{ I0_WZY, I1_XYZ, - I0_111, I1__YZ, - 0,0,0,0}}, - /* 011 */ - {2,{2,2,0,0},{ I0_111, I1__YZ, - I0_000, I1_X__, - 0,0,0,0}}, - /* 111 */ - {1,{2,0,0,0},{ I0_111, I1_XYZ, - 0, 0, 0, 0, 0, 0 } }, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY, - SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY,SEMPTY -}; - -/****************************************************************************** -* Color source mask table -******************************************************************************/ - -#define S_111 R300_FPI0_ARGC_ONE -#define S_000 R300_FPI0_ARGC_ZERO - -#define S0XXX R300_FPI0_ARGC_SRC0C_XXX -#define S0YYY R300_FPI0_ARGC_SRC0C_YYY -#define S0ZZZ R300_FPI0_ARGC_SRC0C_ZZZ -#define S0WWW R300_FPI0_ARGC_SRC0A -#define S0XYZ R300_FPI0_ARGC_SRC0C_XYZ -#define S0ZXY R300_FPI0_ARGC_SRC0C_ZXY -#define S0YZX R300_FPI0_ARGC_SRC0C_YZX -#define S0WZY R300_FPI0_ARGC_SRC0CA_WZY -#define S0WZY R300_FPI0_ARGC_SRC0CA_WZY - -#define S1XXX R300_FPI0_ARGC_SRC1C_XXX -#define S1YYY R300_FPI0_ARGC_SRC1C_YYY -#define S1ZZZ R300_FPI0_ARGC_SRC1C_ZZZ -#define S1WWW R300_FPI0_ARGC_SRC1A -#define S1XYZ R300_FPI0_ARGC_SRC1C_XYZ -#define S1ZXY R300_FPI0_ARGC_SRC1C_ZXY -#define S1YZX R300_FPI0_ARGC_SRC1C_YZX -#define S1WZY R300_FPI0_ARGC_SRC1CA_WZY - -#define S2XXX R300_FPI0_ARGC_SRC2C_XXX -#define S2YYY R300_FPI0_ARGC_SRC2C_YYY -#define S2ZZZ R300_FPI0_ARGC_SRC2C_ZZZ -#define S2WWW R300_FPI0_ARGC_SRC2A -#define S2XYZ R300_FPI0_ARGC_SRC2C_XYZ -#define S2ZXY R300_FPI0_ARGC_SRC2C_ZXY -#define S2YZX R300_FPI0_ARGC_SRC2C_YZX -#define S2WZY R300_FPI0_ARGC_SRC2CA_WZY - -#define ntnat 32 - -const GLuint r300_swz_srcc_mask[3][512] = { - { - S0XXX,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,S0YZX,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,S0ZXY,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,S0YYY,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,S0WZY,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,S0XYZ,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,S0ZZZ,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,S0WWW, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,S_000,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,S_111,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat - }, - { - S1XXX,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,S1YZX,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,S1ZXY,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,S1YYY,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,S1WZY,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,S1XYZ,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,S1ZZZ,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,S1WWW, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,S_000,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,S_111,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat - }, - { - S2XXX,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,S2YZX,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,S2ZXY,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,S2YYY,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,S2WZY,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,S2XYZ,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,S2ZZZ,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,S2WWW, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,S_000,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,S_111,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat,ntnat, - ntnat,ntnat - } -}; - -/****************************************************************************** -* Alpha source mask table -******************************************************************************/ - -GLuint r300_swz_srca_mask[3][6] = { - { R300_FPI2_ARGA_SRC0C_X, - R300_FPI2_ARGA_SRC0C_Y, - R300_FPI2_ARGA_SRC0C_Z, - R300_FPI2_ARGA_SRC0A, - R300_FPI2_ARGA_ZERO, - R300_FPI2_ARGA_ONE }, - { R300_FPI2_ARGA_SRC1C_X, - R300_FPI2_ARGA_SRC1C_Y, - R300_FPI2_ARGA_SRC1C_Z, - R300_FPI2_ARGA_SRC1A, - R300_FPI2_ARGA_ZERO, - R300_FPI2_ARGA_ONE }, - { R300_FPI2_ARGA_SRC2C_X, - R300_FPI2_ARGA_SRC2C_Y, - R300_FPI2_ARGA_SRC2C_Z, - R300_FPI2_ARGA_SRC2A, - R300_FPI2_ARGA_ZERO, - R300_FPI2_ARGA_ONE }, -}; diff --git a/src/mesa/drivers/dri/tdfx/BUGS b/src/mesa/drivers/dri/tdfx/BUGS deleted file mode 100644 index b15f6a91ed8..00000000000 --- a/src/mesa/drivers/dri/tdfx/BUGS +++ /dev/null @@ -1,64 +0,0 @@ -REMOVE THIS FILE BEFORE MERGING WITH TRUNK ------------------------------------------- - -OUTSTANDING BUGS - -demos/reflect - reading back Z on Voodoo3, image offset to right - Fixed in latest Glide. - -Q3 - some polygons drawn as vertical strips, similar to bug that was - seen in demos/fire. Voodoo3 only. May be related to glDepthMask - or glColorMask. - -book/fog - not fogging - Fog in orthograph mode still not implemented. Checking with - 3dfx engineers for ideas. - -Q3 demo crashes after changing display settings - but the full Q3 game version seems OK. - - - -MORE OUTSTANDING BUGS - -private context was NULL! causing immediate failure of any glx prog. cant -reproduce after restarting the X server. putting it down as halluc. - -texture object image was NULL, causing segmentation failure. happens with -prboom. ive put a check in tdfx_texstate.c but this isn't a fix. - -prboom, wall textures near first chainsaw aren't bound properly. sideways -movements causes the wall textures to move with you. prboom busted? - -16bpp mode, quake3, windowed, q3dm1, floor under rocketlauncher bands. it -looks like multitexturing gone wrong. i'll disable a tmu and test. - -sof, polygons appear at wrong x,y,z positions, intermittent, have not yet -found reliable way of reproducing. culling? sometimes polys disappear. - -descent3 is all black in 16bpp mode - FIXED (palette problems) - -smeared pixels in quake3 - FIXED (texture memory overlapped FB) - - - -PERFORMANCE COMPARISON (Brian / Alan) - - V3/16 is Voodoo3 in 16bpp on a P3/500 - V5/16 is Voodoo5 in 16bpp on a P3/600 - V5/32 is Voodoo5 in 32bpp on a P3/600 - V5A/16 is Voodoo5 in 16bpp on an Alpha AXP/600 - V5A/32 is Voodoo5 in 32bpp on an Alpha AXP/600 - - tdfx-2-1-branch tdfx-3-0-0-branch -demo V3/16 V5/16 V5/32 V3/16 V5/16 V5/32 V5A/16 V5A/32 ------------------------------------------------------------------------- -gloss 257 183 174 320 308 177 313 167 -fire 42 39 52 41 -fire (no help) 98 80 50 106 113 73 124 80 -tunnel 61 50 70 58 -tunnel (no help) 167 142 57 138 152 113 171 122 -gears 663 554 540 881 1232 776 1484 830 -teapot 20 21 37 36 -teapot (no help) 22 14 14 24 30 30 43 42 - diff --git a/src/mesa/drivers/dri/tdfx/X86/fx_3dnow_fastpath.S b/src/mesa/drivers/dri/tdfx/X86/fx_3dnow_fastpath.S deleted file mode 100644 index 0f4cc45089b..00000000000 --- a/src/mesa/drivers/dri/tdfx/X86/fx_3dnow_fastpath.S +++ /dev/null @@ -1,84 +0,0 @@ -/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/X86/fx_3dnow_fastpath.S,v 1.2 2000/09/26 15:56:51 tsi Exp $ */ - -#include "../../X86/assyntax.h" - -#define SETUP_RGBA 0x1 -#define SETUP_TMU0 0x2 -#define SETUP_TMU1 0x4 - - -/* Pack either rgba or texture into the remaining half of a 32 byte vertex. - */ -#define CLIP_R 24 -#define CLIP_G 16 -#define CLIP_B 20 -#define CLIP_A 28 /* defined inf fxdrv.h */ - -#define CLIP_S0 16 -#define CLIP_T0 20 -#define CLIP_S1 24 -#define CLIP_T1 28 - -#define SIZE 4 -#define TYPE (0) -#define TAG(x) x -#include "fx_3dnow_fasttmp.h" - -#define SIZE 8 -#define TYPE (SETUP_RGBA) -#define TAG(x) x##_RGBA -#include "fx_3dnow_fasttmp.h" - -#define SIZE 6 -#define TYPE (SETUP_TMU0) -#define TAG(x) x##_TMU0 -#include "fx_3dnow_fasttmp.h" - -#define SIZE 8 -#define TYPE (SETUP_TMU0|SETUP_TMU1) -#define TAG(x) x##_TMU0_TMU1 -#include "fx_3dnow_fasttmp.h" - -#undef CLIP_S1 -#undef CLIP_T1 -#define CLIP_S1 16 -#define CLIP_T1 20 - -#define SIZE 6 -#define TYPE (SETUP_TMU1) -#define TAG(x) x##_TMU1 -#include "fx_3dnow_fasttmp.h" - -/* These three need to use a full 64 byte clip-space vertex. - */ -#undef CLIP_S0 -#undef CLIP_T0 -#undef CLIP_S1 -#undef CLIP_T1 - -#define CLIP_S0 32 -#define CLIP_T0 36 -#define CLIP_S1 40 -#define CLIP_T1 44 - -#define SIZE 10 -#define TYPE (SETUP_RGBA|SETUP_TMU0) -#define TAG(x) x##_RGBA_TMU0 -#include "fx_3dnow_fasttmp.h" - -#define SIZE 12 -#define TYPE (SETUP_RGBA|SETUP_TMU0|SETUP_TMU1) -#define TAG(x) x##_RGBA_TMU0_TMU1 -#include "fx_3dnow_fasttmp.h" - -#undef CLIP_S1 -#undef CLIP_T1 -#define CLIP_S1 32 -#define CLIP_T1 36 - -#define SIZE 10 -#define TYPE (SETUP_RGBA|SETUP_TMU1) -#define TAG(x) x##_RGBA_TMU1 -#include "fx_3dnow_fasttmp.h" - - diff --git a/src/mesa/drivers/dri/tdfx/X86/fx_3dnow_fasttmp.h b/src/mesa/drivers/dri/tdfx/X86/fx_3dnow_fasttmp.h deleted file mode 100644 index 9ec4935d781..00000000000 --- a/src/mesa/drivers/dri/tdfx/X86/fx_3dnow_fasttmp.h +++ /dev/null @@ -1,314 +0,0 @@ -/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/X86/fx_3dnow_fasttmp.h,v 1.2 2000/09/26 15:56:51 tsi Exp $ */ - -#if !defined(NASM_ASSEMBLER) && !defined(MASM_ASSEMBLER) -#define TAGLLBL(a) TAG(.L##a) -#else -#define TAGLLBL(a) TAG(a) -#endif - -#if !GLIDE3 - -#define GR_VERTEX_X_OFFSET 0 -#define GR_VERTEX_Y_OFFSET 4 -#define GR_VERTEX_Z_OFFSET 8 -#define GR_VERTEX_R_OFFSET 12 -#define GR_VERTEX_G_OFFSET 16 -#define GR_VERTEX_B_OFFSET 20 -#define GR_VERTEX_OOZ_OFFSET 24 -#define GR_VERTEX_A_OFFSET 28 -#define GR_VERTEX_OOW_OFFSET 32 - -#else /* GLIDE3 */ - -#define GR_VERTEX_X_OFFSET 0 -#define GR_VERTEX_Y_OFFSET 4 -#define GR_VERTEX_OOZ_OFFSET 8 -#define GR_VERTEX_OOW_OFFSET 12 -#define GR_VERTEX_R_OFFSET 16 -#define GR_VERTEX_G_OFFSET 20 -#define GR_VERTEX_B_OFFSET 24 -#define GR_VERTEX_A_OFFSET 28 -#define GR_VERTEX_Z_OFFSET 32 - -#endif /* GLIDE3 */ - -#define GR_VERTEX_SOW_TMU0_OFFSET 36 -#define GR_VERTEX_TOW_TMU0_OFFSET 40 -#define GR_VERTEX_OOW_TMU0_OFFSET 44 -#define GR_VERTEX_SOW_TMU1_OFFSET 48 -#define GR_VERTEX_TOW_TMU1_OFFSET 52 -#define GR_VERTEX_OOW_TMU1_OFFSET 56 - - - - -/*#define MAT_SX 0 /* accessed by REGIND !! */ -#define MAT_SY 20 -#define MAT_SZ 40 -#define MAT_TX 48 -#define MAT_TY 52 -#define MAT_TZ 56 - - - - -/* Do viewport map, device scale and perspective projection. - * - * void project_verts( GLfloat *first, - * GLfloat *last, - * const GLfloat *m, - * GLuint stride ) - * - * - * Rearrange fxVertices to look like grVertices. - */ - -GLOBL GLNAME( TAG(fx_3dnow_project_vertices) ) -GLNAME( TAG(fx_3dnow_project_vertices) ): - - PUSH_L ( EBP ) - - MOV_L ( REGOFF(8, ESP), ECX ) /* first_vert */ - MOV_L ( REGOFF(12, ESP), EDX ) /* last_vert */ - - CMP_L ( ECX, EDX ) - JE ( TAGLLBL(FXPV_end) ) - - FEMMS - - PREFETCH ( REGIND(ECX) ) /* fetch the first vertex */ - - MOV_L ( REGOFF(16, ESP), EBP ) /* matrix */ - MOV_L ( REGOFF(20, ESP), EAX ) /* stride */ - - MOVD ( REGOFF(MAT_TX, EBP), MM6 ) /* | tx */ - PUNPCKLDQ ( REGOFF(MAT_TY, EBP), MM6 ) /* ty | tx */ - -#if !defined(FX_V2) - MOV_L ( CONST(0x49400000), REGOFF(-8, ESP) ) /* snapper */ - MOV_L ( CONST(0x49400000), REGOFF(-4, ESP) ) /* snapper */ -#endif - - MOVQ ( REGOFF(-8, ESP), MM4 ) /* snapper | snapper */ - PFADD ( MM4, MM6 ) /* ty+snapper | tx+snapper */ - - MOVD ( REGIND(EBP), MM5 ) - PUNPCKLDQ ( REGOFF(MAT_SY, EBP), MM5 ) /* vsy | vsx */ - - MOVD ( REGOFF(MAT_SZ, EBP), MM1 ) /* | vsz */ - - -ALIGNTEXT32 -TAGLLBL(FXPV_loop_start): - - PREFETCH ( REGOFF(64, ECX) ) /* fetch the next-ish vertex */ - - - MOVD ( REGOFF(12, ECX), MM0 ) /* | f[3] */ - PFRCP ( MM0, MM0 ) /* oow = 1/f[3] */ - - MOVD ( REGOFF(12, ECX), MM7 ) /* | f[3] */ - PFRCPIT1 ( MM0, MM7 ) - PFRCPIT2 ( MM0, MM7 ) /* oow | oow */ - - PUNPCKLDQ ( MM7, MM7 ) - - -#if (TYPE & SETUP_RGBA) - MOVD ( REGOFF(CLIP_R, ECX ), MM0 ) /* f[RCOORD] = f[CLIP_R]; */ - MOVD ( MM0, REGOFF(GR_VERTEX_R_OFFSET, ECX) ) -#endif - -#if (TYPE & SETUP_TMU1) - MOVQ ( REGOFF(CLIP_S1, ECX), MM0 ) /* f[S1COORD] = f[CLIP_S1] * oow */ - PFMUL ( MM7, MM0 ) /* f[T1COORD] = f[CLIP_T1] * oow */ - MOVQ ( MM0, REGOFF(GR_VERTEX_SOW_TMU1_OFFSET, ECX) ) -#endif - - -#if (TYPE & SETUP_TMU0) - MOVQ ( REGOFF(CLIP_S0, ECX), MM0 ) /* f[S0COORD] = f[CLIP_S0] * oow */ - PFMUL ( MM7, MM0 ) /* f[T0COORD] = f[CLIP_T0] * oow */ - MOVQ ( MM0, REGOFF(GR_VERTEX_SOW_TMU0_OFFSET, ECX) ) -#endif - - - - - -/* DO_SETUP_XYZ */ - - MOVQ ( REGIND(ECX), MM2 ) /* f[1] | f[0] */ - PFMUL ( MM7, MM2 ) /* f[1] * oow | f[0] * oow */ - - MOVD ( REGOFF(8, ECX), MM3 ) /* | f[2] */ - PFMUL ( MM7, MM3 ) /* | f[2] * oow */ - - MOVD ( REGOFF(MAT_TZ, EBP), MM0 ) /* | vtz */ - PFMUL ( MM1, MM3 ) /* | f[2] *= vsz */ - - PFADD ( MM0, MM3 ) /* | f[2] += vtz */ - PFMUL ( MM5, MM2 ) /* f[1] *= vsy | f[0] *= vsx */ - - PFADD ( MM6, MM2 ) /* f[1] += vty | f[0] += vtx */ - -#if !defined(FX_V2) - PFSUB ( MM4, MM2 ) /* f[0,1] -= snapper */ -#endif - - MOVQ ( MM2, REGOFF(GR_VERTEX_X_OFFSET, ECX) ) - MOVD ( MM3, REGOFF(GR_VERTEX_OOZ_OFFSET, ECX) ) - - -/* end of DO_SETUP_XYZ */ - - MOVD ( MM7, REGOFF(GR_VERTEX_OOW_OFFSET, ECX) ) /* f[OOWCOORD] = oow */ - ADD_L ( EAX, ECX ) /* f += stride */ - - CMP_L ( ECX, EDX ) /* stall??? */ - JA ( TAGLLBL(FXPV_loop_start) ) - -TAGLLBL(FXPV_end): - FEMMS - POP_L ( EBP ) - RET - - - - - - - -/* void project_verts( GLfloat *first, - * GLfloat *last, - * const GLfloat *m, - * GLuint stride, - * const GLubyte *mask ) - * - */ - -GLOBL GLNAME( TAG(fx_3dnow_project_clipped_vertices) ) -GLNAME( TAG(fx_3dnow_project_clipped_vertices) ): - - PUSH_L ( EBP ) - - MOV_L ( REGOFF(8, ESP), ECX ) /* first FXDRIVER(VB)->verts*/ - MOV_L ( REGOFF(12, ESP), EDX ) /* last FXDRIVER(VB)->last_vert */ - - FEMMS - - PUSH_L ( EDI ) - PUSH_L ( ESI ) - - PREFETCH ( REGIND(ECX) ) /* fetch the first vertex */ - - MOV_L ( REGOFF(24, ESP), EBP ) /* mat ctx->Viewport.WindowMap.M */ - MOV_L ( REGOFF(28, ESP), EAX ) /* stride */ - MOV_L ( REGOFF(32, ESP), ESI ) /* VB->ClipMask */ - - MOVD ( REGOFF(MAT_TX, EBP), MM6 ) /* | tx */ - PUNPCKLDQ ( REGOFF(MAT_TY, EBP), MM6 ) /* ty | tx */ - -#if !defined(FX_V2) - MOV_L ( CONST(0x49400000), REGOFF(-8, ESP) ) /* snapper */ - MOV_L ( CONST(0x49400000), REGOFF(-4, ESP) ) /* snapper */ -#endif - - MOVQ ( REGOFF(-8, ESP), MM4 ) /* snapper | snapper */ - PFADD ( MM4, MM6 ) /* ty+snapper | tx+snapper */ - - MOVD ( REGIND(EBP), MM5 ) - PUNPCKLDQ ( REGOFF(MAT_SY, EBP), MM5 ) /* vsy | vsx */ - - MOVD ( REGOFF(MAT_SZ, EBP), MM1 ) /* | vsz */ - - - -ALIGNTEXT32 -TAGLLBL(FXPCV_loop_start): - - PREFETCH ( REGOFF(64, ECX) ) /* fetch the next-ish vertex */ - - CMP_B ( CONST(0), REGIND(ESI) ) - JNE ( TAGLLBL(FXPCV_skip) ) - - MOVD ( REGOFF(12, ECX), MM0) /* | f[3] */ - PFRCP ( MM0, MM0 ) /* oow = 1/f[3] */ - - MOVD ( REGOFF(12, ECX), MM7) /* | f[3] */ - PFRCPIT1 ( MM0, MM7 ) - PFRCPIT2 ( MM0, MM7 ) /* oow | oow */ - - PUNPCKLDQ ( MM7, MM7 ) - - -#if (TYPE & SETUP_RGBA) - MOVD ( REGOFF(CLIP_R, ECX ), MM0 ) /* f[RCOORD] = f[CLIP_R]; */ - MOVD ( MM0, REGOFF(GR_VERTEX_R_OFFSET, ECX) ) -#endif - -#if (TYPE & SETUP_TMU1) - MOVQ ( REGOFF(CLIP_S1, ECX), MM0 ) /* f[S1COORD] = f[CLIP_S1] * oow */ - PFMUL ( MM7, MM0 ) /* f[T1COORD] = f[CLIP_T1] * oow */ - MOVQ ( MM0, REGOFF(GR_VERTEX_SOW_TMU1_OFFSET, ECX) ) -#endif - - -#if (TYPE & SETUP_TMU0) - MOVQ ( REGOFF(CLIP_S0, ECX), MM0 ) /* f[S0COORD] = f[CLIP_S0] * oow */ - PFMUL ( MM7, MM0 ) /* f[T0COORD] = f[CLIP_T0] * oow */ - MOVQ ( MM0, REGOFF(GR_VERTEX_SOW_TMU0_OFFSET, ECX) ) -#endif - - - - -/* DO_SETUP_XYZ */ - - MOVQ ( REGIND(ECX), MM2 ) /* f[1] | f[0] */ - PFMUL ( MM7, MM2 ) /* f[1] * oow | f[0] * oow */ - - MOVD ( REGOFF(8, ECX), MM3 ) /* | f[2] */ - PFMUL ( MM7, MM3 ) /* | f[2] * oow */ - - MOVD ( REGOFF(MAT_TZ, EBP), MM0 ) /* | vtz */ - PFMUL ( MM1, MM3 ) /* | f[2] *= vsz */ - - PFADD ( MM0, MM3 ) /* | f[2] += vtz */ - PFMUL ( MM5, MM2 ) /* f[1] *= vsy | f[0] *= vsx */ - - PFADD ( MM6, MM2 ) /* f[1] += vty | f[0] += vtx */ - -#if !defined(FX_V2) - PFSUB ( MM4, MM2 ) /* f[0,1] -= snapper */ -#endif - - MOVQ ( MM2, REGOFF(GR_VERTEX_X_OFFSET, ECX) ) - MOVD ( MM3, REGOFF(GR_VERTEX_OOZ_OFFSET, ECX) ) - - -/* end of DO_SETUP_XYZ */ - - MOVD ( MM7, REGOFF(GR_VERTEX_OOW_OFFSET, ECX) ) /* f[OOWCOORD] = oow */ - -TAGLLBL(FXPCV_skip): - ADD_L ( EAX, ECX ) /* f += stride */ - - INC_L ( ESI ) /* next ClipMask */ - CMP_L ( ECX, EDX ) - JA ( TAGLLBL(FXPCV_loop_start) ) - - POP_L ( ESI ) - POP_L ( EDI ) - -TAGLLBL(FXPCV_end): - FEMMS - POP_L ( EBP ) - RET - - - -#undef TYPE -#undef TAG -#undef SIZE - diff --git a/src/mesa/drivers/ggi/default/.cvsignore b/src/mesa/drivers/ggi/default/.cvsignore deleted file mode 100644 index c8a526b14d7..00000000000 --- a/src/mesa/drivers/ggi/default/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -genkgi.conf diff --git a/src/mesa/drivers/ggi/default/genkgi.h b/src/mesa/drivers/ggi/default/genkgi.h deleted file mode 100644 index 1202150060b..00000000000 --- a/src/mesa/drivers/ggi/default/genkgi.h +++ /dev/null @@ -1,76 +0,0 @@ -/* $Id: genkgi.h,v 1.3 1999-08-22 08:56:50 jtaylor Exp $ -****************************************************************************** - - GGIMesa - KGIcon specific overrides for fbcon-mesa - API header - - Copyright (C) 1999 Jon Taylor [[email protected]] - - 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 - THE AUTHOR(S) 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. - -****************************************************************************** -*/ - -#ifndef _GENKGI_MESA_H -#define _GENKGI_MESA_H - -#undef KGI_USE_PPBUFS - -#include <unistd.h> -#include <sys/mman.h> - -#include <ggi/internal/ggi-dl.h> -#include <ggi/mesa/display_fbdev.h> -#include <kgi/kgi.h> - -#ifndef MAP_FAILED -#define MAP_FAILED ((void *)-1) -#endif - -/* FIXME: LibGGI needs to export its genkgi.h */ -struct genkgi_priv -{ - ggi_gc *mapped_gc; - unsigned int gc_size; - ggifunc_drawline *drawline; - ggifunc_drawbox *drawbox; - ggifunc_fillscreen *fillscreen; - int fd_gc; - int close_gc; - int fd_kgicommand; - uint8 *mapped_kgicommand; - uint8 *kgicommand_ptr; - unsigned int kgicommand_buffersize; -}; - -#define GENKGI_PRIV(vis) ((struct genkgi_priv *)FBDEV_PRIV(vis)->accelpriv) - -extern ggifunc_getapi GGIMesa_genkgi_getapi; -extern ggifunc_flush GGIMesa_genkgi_flush; - -struct genkgi_priv_mesa -{ - char accel[100]; - int have_accel; - void *accelpriv; /* Private data of subdrivers */ - struct genkgi_priv *oldpriv; /* LibGGI's private data */ -}; - -#define GENKGI_PRIV_MESA(vis) ((struct genkgi_priv_mesa *)FBDEV_PRIV_MESA(vis)->accelpriv) - -#endif /* _GENKHI_MESA_H */ diff --git a/src/mesa/drivers/ggi/display/.cvsignore b/src/mesa/drivers/ggi/display/.cvsignore deleted file mode 100644 index 98858db2c0e..00000000000 --- a/src/mesa/drivers/ggi/display/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -fbdev.conf diff --git a/src/mesa/drivers/windows/fx/fx.rc b/src/mesa/drivers/windows/fx/fx.rc deleted file mode 100644 index f920b8768dd..00000000000 --- a/src/mesa/drivers/windows/fx/fx.rc +++ /dev/null @@ -1,39 +0,0 @@ -#include <windows.h> - -#define PRODNAME "Mesa 6.x" -#define CONTACTSTR "http://www.mesa3d.org" -#define HWSTR "3dfx Voodoo Graphics, Voodoo Rush, Voodoo^2, Voodoo Banshee, Velocity 100/200, Voodoo3, Voodoo4, Voodoo5" -#define COPYRIGHTSTR "Copyright \251 Brian E. Paul" - -#define VERSIONSTR "6.3.0.1" -#define MANVERSION 6 -#define MANREVISION 3 -#define BUILD_NUMBER 1 - -VS_VERSION_INFO VERSIONINFO - FILEVERSION MANVERSION, MANREVISION, 0, BUILD_NUMBER - PRODUCTVERSION MANVERSION, MANREVISION, 0, BUILD_NUMBER - FILEFLAGSMASK 0x0030003FL - - FILEOS VOS_DOS_WINDOWS32 - FILETYPE VFT_DRV - FILESUBTYPE VFT2_DRV_INSTALLABLE -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904E4" - BEGIN - VALUE "FileDescription", PRODNAME - VALUE "FileVersion", VERSIONSTR - VALUE "LegalCopyright", COPYRIGHTSTR - VALUE "ProductName", PRODNAME - VALUE "Graphics Subsystem", HWSTR - VALUE "Contact", CONTACTSTR - END - END - BLOCK "VarFileInfo" - BEGIN - /* the following line should be extended for localized versions */ - VALUE "Translation", 0x409, 1252 - END -END 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 cad299540d7..00000000000 --- 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 "array_cache/acache.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 ); - _ac_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 b5a491e41b1..00000000000 --- 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 df6fceb43e6..00000000000 --- 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 6be41a80dd3..00000000000 --- 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 "array_cache/acache.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 9ccec69b98a..00000000000 --- 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 5da25003c08..00000000000 --- 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 "array_cache/acache.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 bbe673516d6..00000000000 --- 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 a85620dde8d..00000000000 --- 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 0a57bde2588..00000000000 --- a/src/mesa/drivers/windows/gldirect/dx7/gld_vb_mesa_render_dx7.c +++ /dev/null @@ -1,423 +0,0 @@ -/* $Id: gld_vb_mesa_render_dx7.c,v 1.6 2005-08-27 13:56:08 brianp Exp $ */ - -/* - * 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 <[email protected]> - */ - - -/* - * 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 0f8fe33eb15..00000000000 --- a/src/mesa/drivers/windows/gldirect/dx7/gld_wgl_dx7.c +++ /dev/null @@ -1,1611 +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; - } - - // 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 0a6d9f8555c..00000000000 --- 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 "array_cache/acache.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 ); - _ac_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 7efec7cae80..00000000000 --- 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 f8e92b936e8..00000000000 --- 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 108f12a9d16..00000000000 --- 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 "array_cache/acache.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 2baea57443c..00000000000 --- 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 700b5200862..00000000000 --- 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 "array_cache/acache.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 f24b3cfb74d..00000000000 --- 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 cafbf4f5c50..00000000000 --- 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 81414a31dde..00000000000 --- a/src/mesa/drivers/windows/gldirect/dx8/gld_vb_mesa_render_dx8.c +++ /dev/null @@ -1,449 +0,0 @@ -/* $Id: gld_vb_mesa_render_dx8.c,v 1.6 2005-08-27 13:56:08 brianp Exp $ */ - -/* - * 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 <[email protected]> - */ - - -/* - * 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 690f68b68f1..00000000000 --- a/src/mesa/drivers/windows/gldirect/dx8/gld_wgl_dx8.c +++ /dev/null @@ -1,1335 +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; - - 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 1b01cb1f7f3..00000000000 --- 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 "array_cache/acache.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 ); - _ac_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 aec40ac9dd1..00000000000 --- 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 1d6b7b1c760..00000000000 --- 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 745c987602b..00000000000 --- 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 "array_cache/acache.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 2b272aa6281..00000000000 --- 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 65fd821276e..00000000000 --- 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 "array_cache/acache.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 5a822356164..00000000000 --- 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 4fa6bcaf1ab..00000000000 --- 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 372be2fb569..00000000000 --- a/src/mesa/drivers/windows/gldirect/dx9/gld_vb_mesa_render_dx9.c +++ /dev/null @@ -1,444 +0,0 @@ -/* $Id: gld_vb_mesa_render_dx9.c,v 1.6 2005-08-27 13:56:08 brianp Exp $ */ - -/* - * 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 <[email protected]> - */ - - -/* - * 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 dc465c54185..00000000000 --- a/src/mesa/drivers/windows/gldirect/dx9/gld_wgl_dx9.c +++ /dev/null @@ -1,1345 +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; - - 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/gldirect.rc b/src/mesa/drivers/windows/gldirect/gldirect.rc deleted file mode 100644 index ba09631538a..00000000000 --- a/src/mesa/drivers/windows/gldirect/gldirect.rc +++ /dev/null @@ -1,43 +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: Windows Resource Compiler -* Environment: Windows 95 -* -****************************************************************************/ - -#ifndef WORKSHOP_INVOKED - #include <windows.h> -#endif - -#define FILE_DESCRIPTION "SciTech GLDirect" -#define ORIG_FILENAME "opengl32.dll" -#define FILE_TYPE VFT_DLL - -#include "gldirect/gldver.ver" 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 5660907aa51..00000000000 --- a/src/mesa/drivers/windows/gldirect/mesasw/colors.h +++ /dev/null @@ -1,523 +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 : [email protected] - * 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 - * ([email protected]). - */ - -/* $Log: ddcolors.h 1997/6/14 by Li Wei([email protected]) - * Macros for pixel format defined - */ - -/* - * $Log: colors.h,v $ - * 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([email protected]) - * Add LUTs need for dithering - */ - -/* - * $Log: colors.h,v $ - * 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([email protected]) - * Add BGR8 Macro - */ - -/* - * $Log: colors.h,v $ - * 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([email protected]) - * 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, -};
\ No newline at end of file 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 0f11b4fe513..00000000000 --- a/src/mesa/drivers/windows/gldirect/mesasw/gld_wgl_mesasw.c +++ /dev/null @@ -1,1719 +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 "array_cache/acache.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 ); - _ac_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); - - /* - * 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.Accum = _swrast_Accum; - ctx->Driver.Bitmap = _swrast_Bitmap; - ctx->Driver.Clear = clear; - - ctx->Driver.Flush = flush; - ctx->Driver.ClearIndex = clear_index; - ctx->Driver.ClearColor = clear_color; - ctx->Driver.Enable = enable; - - ctx->Driver.CopyPixels = _swrast_CopyPixels; - ctx->Driver.DrawPixels = _swrast_DrawPixels; - ctx->Driver.ReadPixels = _swrast_ReadPixels; - - ctx->Driver.ChooseTextureFormat = _mesa_choose_tex_format; - ctx->Driver.TexImage1D = _mesa_store_teximage1d; - ctx->Driver.TexImage2D = _mesa_store_teximage2d; - ctx->Driver.TexImage3D = _mesa_store_teximage3d; - ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d; - ctx->Driver.TexSubImage2D = _mesa_store_texsubimage2d; - ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; - ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; - - ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d; - ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d; - ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d; - ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d; - ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d; - ctx->Driver.CopyColorTable = _swrast_CopyColorTable; - ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable; - ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D; - ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D; - - // 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; - - _mesa_enable_sw_extensions(ctx); - _mesa_enable_imaging_extensions(ctx); - _mesa_enable_1_3_extensions(ctx); - -// _swrast_CreateContext( ctx ); -// _ac_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; -} - -//--------------------------------------------------------------------------- - diff --git a/src/mesa/drivers/windows/gldirect/opengl32.ref b/src/mesa/drivers/windows/gldirect/opengl32.ref deleted file mode 100644 index 2f71faf2167..00000000000 --- a/src/mesa/drivers/windows/gldirect/opengl32.ref +++ /dev/null @@ -1,495 +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: DLL Module definition file -;* -;****************************************************************************/ - -DESCRIPTION 'GLDirect' - -VERSION 3.0 - -EXPORTS - glAccum - glAlphaFunc - glAreTexturesResident - glArrayElement - glBegin - glBindTexture - glBitmap - glBlendFunc - glCallList - glCallLists - glClear - glClearAccum - glClearIndex - glClearColor - glClearDepth - glClearStencil - glClipPlane - glColor3b - glColor3d - glColor3f - glColor3i - glColor3s - glColor3ub - glColor3ui - glColor3us - glColor4b - glColor4d - glColor4f - glColor4i - glColor4s - glColor4ub - glColor4ui - glColor4us - glColor3bv - glColor3dv - glColor3fv - glColor3iv - glColor3sv - glColor3ubv - glColor3uiv - glColor3usv - glColor4bv - glColor4dv - glColor4fv - glColor4iv - glColor4sv - glColor4ubv - glColor4uiv - glColor4usv - glColorMask - glColorMaterial - glColorPointer - glColorTableEXT - glColorSubTableEXT - glCopyPixels - glCopyTexImage1D - glCopyTexImage2D - glCopyTexSubImage1D - glCopyTexSubImage2D - glCullFace - glDepthFunc - glDepthMask - glDepthRange - glDeleteLists - glDeleteTextures - glDisable - glDisableClientState - glDrawArrays - glDrawBuffer - glDrawElements - glDrawPixels - glEnable - glEnableClientState - glEnd - glEndList - glEvalCoord1d - glEvalCoord1f - glEvalCoord1dv - glEvalCoord1fv - glEvalCoord2d - glEvalCoord2f - glEvalCoord2dv - glEvalCoord2fv - glEvalPoint1 - glEvalPoint2 - glEvalMesh1 - glEdgeFlag - glEdgeFlagv - glEdgeFlagPointer - glEvalMesh2 - glFeedbackBuffer - glFinish - glFlush - glFogf - glFogi - glFogfv - glFogiv - glFrontFace - glFrustum - glGenLists - glGenTextures - glGetBooleanv - glGetClipPlane - glGetColorTableEXT - glGetColorTableParameterivEXT - glGetColorTableParameterfvEXT - glGetDoublev - glGetError - glGetFloatv - glGetIntegerv - glGetLightfv - glGetLightiv - glGetMapdv - glGetMapfv - glGetMapiv - glGetMaterialfv - glGetMaterialiv - glGetPixelMapfv - glGetPixelMapuiv - glGetPixelMapusv - glGetPointerv - glGetPolygonStipple - glGetString - glGetTexEnvfv - glGetTexEnviv - glGetTexGeniv - glGetTexGendv - glGetTexGenfv - glGetTexImage - glGetTexLevelParameterfv - glGetTexLevelParameteriv - glGetTexParameterfv - glGetTexParameteriv - glHint - glIndexd - glIndexf - glIndexi - glIndexs - glIndexub - glIndexdv - glIndexfv - glIndexiv - glIndexsv - glIndexubv - glIndexMask - glIndexPointer - glInterleavedArrays - glInitNames - glIsList - glIsTexture - glLightf - glLighti - glLightfv - glLightiv - glLightModelf - glLightModeli - glLightModelfv - glLightModeliv - glLineWidth - glLineStipple - glListBase - glLoadIdentity - glLoadMatrixd - glLoadMatrixf - glLoadName - glLogicOp - glMap1d - glMap1f - glMap2d - glMap2f - glMapGrid1d - glMapGrid1f - glMapGrid2d - glMapGrid2f - glMaterialf - glMateriali - glMaterialfv - glMaterialiv - glMatrixMode - glMultMatrixd - glMultMatrixf - glNewList - glNormal3b - glNormal3d - glNormal3f - glNormal3i - glNormal3s - glNormal3bv - glNormal3dv - glNormal3fv - glNormal3iv - glNormal3sv - glNormalPointer - glOrtho - glPassThrough - glPixelMapfv - glPixelMapuiv - glPixelMapusv - glPixelStoref - glPixelStorei - glPixelTransferf - glPixelTransferi - glPixelZoom - glPointSize - glPolygonMode - glPolygonOffset - glPolygonOffsetEXT - glPolygonStipple - glPopAttrib - glPopClientAttrib - glPopMatrix - glPopName - glPrioritizeTextures - glPushMatrix - glRasterPos2d - glRasterPos2f - glRasterPos2i - glRasterPos2s - glRasterPos3d - glRasterPos3f - glRasterPos3i - glRasterPos3s - glRasterPos4d - glRasterPos4f - glRasterPos4i - glRasterPos4s - glRasterPos2dv - glRasterPos2fv - glRasterPos2iv - glRasterPos2sv - glRasterPos3dv - glRasterPos3fv - glRasterPos3iv - glRasterPos3sv - glRasterPos4dv - glRasterPos4fv - glRasterPos4iv - glRasterPos4sv - glReadBuffer - glReadPixels - glRectd - glRectf - glRecti - glRects - glRectdv - glRectfv - glRectiv - glRectsv - glScissor - glIsEnabled - glPushAttrib - glPushClientAttrib - glPushName - glRenderMode - glRotated - glRotatef - glSelectBuffer - glScaled - glScalef - glShadeModel - glStencilFunc - glStencilMask - glStencilOp - glTexCoord1d - glTexCoord1f - glTexCoord1i - glTexCoord1s - glTexCoord2d - glTexCoord2f - glTexCoord2i - glTexCoord2s - glTexCoord3d - glTexCoord3f - glTexCoord3i - glTexCoord3s - glTexCoord4d - glTexCoord4f - glTexCoord4i - glTexCoord4s - glTexCoord1dv - glTexCoord1fv - glTexCoord1iv - glTexCoord1sv - glTexCoord2dv - glTexCoord2fv - glTexCoord2iv - glTexCoord2sv - glTexCoord3dv - glTexCoord3fv - glTexCoord3iv - glTexCoord3sv - glTexCoord4dv - glTexCoord4fv - glTexCoord4iv - glTexCoord4sv - glTexCoordPointer - glTexGend - glTexGenf - glTexGeni - glTexGendv - glTexGeniv - glTexGenfv - glTexEnvf - glTexEnvi - glTexEnvfv - glTexEnviv - glTexImage1D - glTexImage2D - glTexParameterf - glTexParameteri - glTexParameterfv - glTexParameteriv - glTexSubImage1D - glTexSubImage2D - glTranslated - glTranslatef - glVertex2d - glVertex2f - glVertex2i - glVertex2s - glVertex3d - glVertex3f - glVertex3i - glVertex3s - glVertex4d - glVertex4f - glVertex4i - glVertex4s - glVertex2dv - glVertex2fv - glVertex2iv - glVertex2sv - glVertex3dv - glVertex3fv - glVertex3iv - glVertex3sv - glVertex4dv - glVertex4fv - glVertex4iv - glVertex4sv - glVertexPointer - glViewport - - glBlendEquationEXT - glBlendColorEXT - glVertexPointerEXT - glNormalPointerEXT - glColorPointerEXT - glIndexPointerEXT - glTexCoordPointerEXT - glEdgeFlagPointerEXT - glGetPointervEXT - glArrayElementEXT - glDrawArraysEXT - glBindTextureEXT - glDeleteTexturesEXT - glGenTexturesEXT - glPrioritizeTexturesEXT - glCopyTexSubImage3DEXT - glTexImage3DEXT - glTexSubImage3DEXT - - glWindowPos4fMESA - glWindowPos2iMESA - glWindowPos2sMESA - glWindowPos2fMESA - glWindowPos2dMESA - glWindowPos2ivMESA - glWindowPos2svMESA - glWindowPos2fvMESA - glWindowPos2dvMESA - glWindowPos3iMESA - glWindowPos3sMESA - glWindowPos3fMESA - glWindowPos3dMESA - glWindowPos3ivMESA - glWindowPos3svMESA - glWindowPos3fvMESA - glWindowPos3dvMESA - glWindowPos4iMESA - glWindowPos4sMESA - glWindowPos4dMESA - glWindowPos4ivMESA - glWindowPos4svMESA - glWindowPos4fvMESA - glWindowPos4dvMESA - glResizeBuffersMESA - - wglCopyContext - wglCreateContext - wglCreateLayerContext - wglDeleteContext - wglDescribeLayerPlane - wglGetCurrentContext - wglGetCurrentDC - wglGetLayerPaletteEntries - wglGetProcAddress - wglMakeCurrent - wglRealizeLayerPalette - wglSetLayerPaletteEntries - wglShareLists - wglSwapLayerBuffers - wglUseFontBitmapsA - wglUseFontBitmapsW - wglUseFontOutlinesA - wglUseFontOutlinesW - -;These functions are identical and therefore share the same addresses - ChoosePixelFormat = wglChoosePixelFormat - DescribePixelFormat = wglDescribePixelFormat - GetPixelFormat = wglGetPixelFormat - SetPixelFormat = wglSetPixelFormat - SwapBuffers = wglSwapBuffers - - wglChoosePixelFormat - wglDescribePixelFormat - wglGetPixelFormat - wglSetPixelFormat - wglSwapBuffers - - glActiveTextureARB - glClientActiveTextureARB - glMultiTexCoord1dARB - glMultiTexCoord1dvARB - glMultiTexCoord1fARB - glMultiTexCoord1fvARB - glMultiTexCoord1iARB - glMultiTexCoord1ivARB - glMultiTexCoord1sARB - glMultiTexCoord1svARB - glMultiTexCoord2dARB - glMultiTexCoord2dvARB - glMultiTexCoord2fARB - glMultiTexCoord2fvARB - glMultiTexCoord2iARB - glMultiTexCoord2ivARB - glMultiTexCoord2sARB - glMultiTexCoord2svARB - glMultiTexCoord3dARB - glMultiTexCoord3dvARB - glMultiTexCoord3fARB - glMultiTexCoord3fvARB - glMultiTexCoord3iARB - glMultiTexCoord3ivARB - glMultiTexCoord3sARB - glMultiTexCoord3svARB - glMultiTexCoord4dARB - glMultiTexCoord4dvARB - glMultiTexCoord4fARB - glMultiTexCoord4fvARB - glMultiTexCoord4iARB - glMultiTexCoord4ivARB - glMultiTexCoord4sARB - glMultiTexCoord4svARB |