Second phase of SDL-Graphics modularization.

New primitives for drawing directly on TFB_Images and TFB_Canvases.


git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@607 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
mcmartin
2003-01-30 07:47:41 +00:00
parent b87d544049
commit 528ec82d08
10 changed files with 186 additions and 145 deletions
+2
View File
@@ -1,4 +1,6 @@
Changes towards version 0.2: Changes towards version 0.2:
- Added a TFB_Canvas data buffer to let TFB_Image be more accessible
- Added new graphics primitives
- Added 'smooth' scolling for ff, frev (similar to the 3DO) - PhracturedBlue - Added 'smooth' scolling for ff, frev (similar to the 3DO) - PhracturedBlue
- New streaming code for openal/mixsdl. supports ff/frev in subtitles -PBlue - New streaming code for openal/mixsdl. supports ff/frev in subtitles -PBlue
- New sound module "mixsdl" (experimental) -fOSSiL - New sound module "mixsdl" (experimental) -fOSSiL
+4
View File
@@ -164,6 +164,10 @@ SOURCE=..\sc2code\libs\graphics\sdl\3do_getbody.c
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\canvas.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\dcqueue.c SOURCE=..\sc2code\libs\graphics\sdl\dcqueue.c
# End Source File # End Source File
# Begin Source File # Begin Source File
+1 -1
View File
@@ -48,7 +48,7 @@ typedef struct tfb_dc_line
typedef struct tfb_dc_rect typedef struct tfb_dc_rect
{ {
int x, y, w, h; RECT rect;
int r, g, b; int r, g, b;
SCREEN destBuffer; SCREEN destBuffer;
} TFB_DrawCommand_Rect; } TFB_DrawCommand_Rect;
+4 -4
View File
@@ -101,10 +101,10 @@ blt (PRECT pClipRect, PRIMITIVEPTR PrimPtr)
{ {
img->ScaledImg = new_surf; img->ScaledImg = new_surf;
SDL_SetColors (img->ScaledImg, (SDL_Color *)img->Palette, 0, 256); SDL_SetColors (img->ScaledImg, (SDL_Color *)img->Palette, 0, 256);
if (img->NormalImg->flags & SDL_SRCCOLORKEY) if (((SDL_Surface *)img->NormalImg)->flags & SDL_SRCCOLORKEY)
{ {
SDL_SetColorKey (img->ScaledImg, SDL_SRCCOLORKEY, SDL_SetColorKey (img->ScaledImg, SDL_SRCCOLORKEY,
img->NormalImg->format->colorkey); ((SDL_Surface *)img->NormalImg)->format->colorkey);
} }
} }
} }
@@ -135,7 +135,7 @@ blt (PRECT pClipRect, PRIMITIVEPTR PrimPtr)
} }
else else
{ {
if (img->NormalImg->format->palette && img->colormap_index != -1) if (((SDL_Surface *)img->NormalImg)->format->palette && img->colormap_index != -1)
{ {
TFB_ColorMapToRGB (palette, img->colormap_index); TFB_ColorMapToRGB (palette, img->colormap_index);
paletted = TRUE; paletted = TRUE;
@@ -232,7 +232,7 @@ fillrect_blt (PRECT pClipRect, PRIMITIVEPTR PrimPtr)
SDLRect.w = (short) pClipRect->extent.width; SDLRect.w = (short) pClipRect->extent.width;
SDLRect.h = (short) pClipRect->extent.height; SDLRect.h = (short) pClipRect->extent.height;
SDL_FillRect (img->NormalImg, &SDLRect, SDL_MapRGB (img->NormalImg->format, r, g, b)); SDL_FillRect (img->NormalImg, &SDLRect, SDL_MapRGB (((SDL_Surface *)img->NormalImg)->format, r, g, b));
UnlockMutex (img->mutex); UnlockMutex (img->mutex);
} }
+2 -1
View File
@@ -1,2 +1,3 @@
uqm_CFILES="3do_blt.c 3do_funcs.c 3do_getbody.c dcqueue.c opengl.c uqm_CFILES="3do_blt.c 3do_funcs.c 3do_getbody.c dcqueue.c opengl.c
primitives.c pure.c rndzoom.c rotozoom.c sdl_common.c oscilloscope.c" primitives.c pure.c rndzoom.c rotozoom.c sdl_common.c oscilloscope.c
canvas.c"
+133
View File
@@ -0,0 +1,133 @@
#include "SDL.h"
#include "sdl_common.h"
#include "libs/graphics/gfx_common.h"
#include "libs/graphics/sdl/primitives.h"
typedef SDL_Surface *NativeCanvas;
void
TFB_DrawCanvas_Line (int x1, int y1, int x2, int y2, int r, int g, int b, TFB_Canvas target)
{
Uint32 color;
PutPixelFn screen_plot;
SDL_Rect rect;
screen_plot = putpixel_for (target);
color = SDL_MapRGB (((NativeCanvas)target)->format, r, g, b);
SDL_GetClipRect((NativeCanvas) target, &rect);
/* Danger, Will Robinson! This code
looks VERY suspicious. It will end
up changing the slope of the
line! */
if (x1 < rect.x)
x1 = rect.x;
else if (x1 > rect.x + rect.w)
x1 = rect.x + rect.w;
if (x2 < rect.x)
x2 = rect.x;
else if (x2 > rect.x + rect.w)
x2 = rect.x + rect.w;
if (y1 < rect.y)
y1 = rect.y;
else if (y1 > rect.y + rect.h)
y1 = rect.y + rect.h;
if (y2 < rect.y)
y2 = rect.y;
else if (y2 > rect.y + rect.h)
y2 = rect.y + rect.h;
SDL_LockSurface ((NativeCanvas) target);
line (x1, y1, x2, y2, color, screen_plot, (NativeCanvas) target);
SDL_UnlockSurface ((NativeCanvas) target);
}
void
TFB_DrawCanvas_Rect (PRECT rect, int r, int g, int b, TFB_Canvas target)
{
SDL_Rect sr;
sr.x = rect->corner.x;
sr.y = rect->corner.y;
sr.w = rect->extent.width;
sr.h = rect->extent.height;
SDL_FillRect((NativeCanvas)target, &sr, SDL_MapRGB(((NativeCanvas)target)->format, r, g, b));
}
void
TFB_DrawCanvas_Image (TFB_Image *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, TFB_Canvas target, int bn, int bd)
{
SDL_Rect targetRect;
SDL_Surface *surf;
if (img == 0)
{
fprintf (stderr, "ERROR: TFB_DrawCanvas_Image passed null image ptr\n");
return;
}
LockMutex (img->mutex);
targetRect.x = x;
targetRect.y = y;
if (scaled)
surf = img->ScaledImg;
else
surf = img->NormalImg;
if (surf->format->palette)
{
if (palette)
{
SDL_SetColors (surf, (SDL_Color*)palette, 0, 256);
}
else
{
SDL_SetColors (surf, (SDL_Color*)img->Palette, 0, 256);
}
}
TFB_BlitSurface(surf, NULL, target, &targetRect, bn, bd);
UnlockMutex (img->mutex);
}
void
TFB_DrawCanvas_FilledImage (TFB_Image *img, int x, int y, BOOLEAN scaled, int r, int g, int b, TFB_Canvas target, int bn, int bd)
{
SDL_Rect targetRect;
SDL_Surface *surf;
int i;
SDL_Color pal[256];
if (img == 0)
{
fprintf (stderr, "ERROR: TFB_DrawCanvas_FilledImage passed null image ptr\n");
return;
}
LockMutex (img->mutex);
targetRect.x = x;
targetRect.y = y;
if (scaled)
surf = img->ScaledImg;
else
surf = img->NormalImg;
for (i = 0; i < 256; i++)
{
pal[i].r = r;
pal[i].g = g;
pal[i].b = b;
}
SDL_SetColors (surf, pal, 0, 256);
TFB_BlitSurface(surf, NULL, target, &targetRect, bn, bd);
UnlockMutex (img->mutex);
}
@@ -35,30 +35,30 @@ InitOscilloscope (DWORD x, DWORD y, DWORD width, DWORD height, FRAME_DESC *f)
{ {
TFB_Image *img = (TFB_Image *)((BYTE *)f + f->DataOffs); TFB_Image *img = (TFB_Image *)((BYTE *)f + f->DataOffs);
assert (img->NormalImg->format->BytesPerPixel == 1); assert (((SDL_Surface *)img->NormalImg)->format->BytesPerPixel == 1);
assert (img->NormalImg->w == RADAR_WIDTH); assert (((SDL_Surface *)img->NormalImg)->w == RADAR_WIDTH);
assert (img->NormalImg->h == RADAR_HEIGHT); assert (((SDL_Surface *)img->NormalImg)->h == RADAR_HEIGHT);
if (scope_init == 0) if (scope_init == 0)
{ {
int i; int i;
LockMutex (img->mutex); LockMutex (img->mutex);
scope_bg = SDL_CreateRGBSurface (SDL_SWSURFACE, img->NormalImg->w, scope_bg = SDL_CreateRGBSurface (SDL_SWSURFACE, ((SDL_Surface *)img->NormalImg)->w,
img->NormalImg->h, 8, ((SDL_Surface *)img->NormalImg)->h, 8,
0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000); 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000);
scope_surf = SDL_CreateRGBSurface (SDL_SWSURFACE, img->NormalImg->w, scope_surf = SDL_CreateRGBSurface (SDL_SWSURFACE, ((SDL_Surface *)img->NormalImg)->w,
img->NormalImg->h, 8, ((SDL_Surface *)img->NormalImg)->h, 8,
0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000); 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000);
for (i = 0; i < 256; ++i) for (i = 0; i < 256; ++i)
{ {
scope_bg->format->palette->colors[i].r = scope_surf->format->palette->colors[i].r = scope_bg->format->palette->colors[i].r = scope_surf->format->palette->colors[i].r =
img->NormalImg->format->palette->colors[i].r; ((SDL_Surface *)img->NormalImg)->format->palette->colors[i].r;
scope_bg->format->palette->colors[i].g = scope_surf->format->palette->colors[i].g = scope_bg->format->palette->colors[i].g = scope_surf->format->palette->colors[i].g =
img->NormalImg->format->palette->colors[i].g; ((SDL_Surface *)img->NormalImg)->format->palette->colors[i].g;
scope_bg->format->palette->colors[i].b = scope_surf->format->palette->colors[i].b = scope_bg->format->palette->colors[i].b = scope_surf->format->palette->colors[i].b =
img->NormalImg->format->palette->colors[i].b; ((SDL_Surface *)img->NormalImg)->format->palette->colors[i].b;
} }
SDL_BlitSurface (img->NormalImg, NULL, scope_bg, NULL); SDL_BlitSurface (img->NormalImg, NULL, scope_bg, NULL);
+21 -108
View File
@@ -560,134 +560,47 @@ TFB_FlushGraphics () // Only call from main thread!!
} }
case TFB_DRAWCOMMANDTYPE_IMAGE: case TFB_DRAWCOMMANDTYPE_IMAGE:
{ {
SDL_Rect targetRect;
SDL_Surface *surf;
TFB_Image *DC_image = (TFB_Image *)DC.data.image.image; TFB_Image *DC_image = (TFB_Image *)DC.data.image.image;
TFB_Palette *pal;
if (DC_image == 0) if (DC.data.image.UsePalette)
{ {
fprintf (stderr, "DCQ ERROR: IMAGE passed null image ptr\n"); pal = palette;
break;
} }
LockMutex (DC_image->mutex);
targetRect.x = DC.data.image.x;
targetRect.y = DC.data.image.y;
if (DC.data.image.UseScaling)
surf = DC_image->ScaledImg;
else else
surf = DC_image->NormalImg;
if (surf->format->palette)
{ {
if (DC.data.image.UsePalette) pal = DC_image->Palette;
{
SDL_SetColors (surf, (SDL_Color*)palette, 0, 256);
}
else
{
SDL_SetColors (surf, (SDL_Color*)DC_image->Palette, 0, 256);
}
} }
TFB_BlitSurface(surf, NULL, SDL_Screens[DC.data.image.destBuffer], &targetRect, DC.data.image.BlendNumerator, DC.data.image.BlendDenominator); TFB_DrawCanvas_Image (DC_image, DC.data.image.x, DC.data.image.y,
UnlockMutex (DC_image->mutex); DC.data.image.UseScaling, pal,
SDL_Screens[DC.data.image.destBuffer],
DC.data.image.BlendNumerator, DC.data.image.BlendDenominator);
break; break;
} }
case TFB_DRAWCOMMANDTYPE_FILLEDIMAGE: case TFB_DRAWCOMMANDTYPE_FILLEDIMAGE:
{ {
SDL_Rect targetRect; TFB_DrawCanvas_FilledImage (DC.data.filledimage.image, DC.data.filledimage.x, DC.data.filledimage.y,
SDL_Surface *surf; DC.data.filledimage.UseScaling, DC.data.filledimage.r, DC.data.filledimage.g,
int i; DC.data.filledimage.b, SDL_Screens[DC.data.filledimage.destBuffer],
TFB_Palette pal[256]; DC.data.filledimage.BlendNumerator, DC.data.filledimage.BlendDenominator);
TFB_Image *DC_image = (TFB_Image *)DC.data.filledimage.image;
if (DC_image == 0)
{
fprintf (stderr, "DCQ ERROR: FILLEDIMAGE passed null image ptr\n");
break;
}
LockMutex (DC_image->mutex);
targetRect.x = DC.data.filledimage.x;
targetRect.y = DC.data.filledimage.y;
if (DC.data.filledimage.UseScaling)
surf = DC_image->ScaledImg;
else
surf = DC_image->NormalImg;
for (i = 0; i < 256; i++)
{
pal[i].r = DC.data.filledimage.r;
pal[i].g = DC.data.filledimage.g;
pal[i].b = DC.data.filledimage.b;
}
SDL_SetColors (surf, (SDL_Color*)pal, 0, 256);
TFB_BlitSurface(surf, NULL, SDL_Screens[DC.data.filledimage.destBuffer], &targetRect, DC.data.filledimage.BlendNumerator, DC.data.filledimage.BlendDenominator);
UnlockMutex (DC_image->mutex);
break; break;
} }
case TFB_DRAWCOMMANDTYPE_LINE: case TFB_DRAWCOMMANDTYPE_LINE:
{ {
SDL_Rect r; TFB_DrawCanvas_Line (DC.data.line.x1, DC.data.line.y1,
int x1, y1, x2, y2; DC.data.line.x2, DC.data.line.y2,
Uint32 color; DC.data.line.r, DC.data.line.g, DC.data.line.b,
PutPixelFn screen_plot; SDL_Screens[DC.data.line.destBuffer]);
screen_plot = putpixel_for (SDL_Screen);
color = SDL_MapRGB (SDL_Screen->format, DC.data.line.r, DC.data.line.g, DC.data.line.b);
x1 = DC.data.line.x1;
x2 = DC.data.line.x2;
y1 = DC.data.line.y1;
y2 = DC.data.line.y2;
SDL_GetClipRect(SDL_Screen, &r);
/* Danger, Will Robinson! This code
looks VERY suspicious. It will end
up changing the slope of the
line! */
if (x1 < r.x)
x1 = r.x;
else if (x1 > r.x + r.w)
x1 = r.x + r.w;
if (x2 < r.x)
x2 = r.x;
else if (x2 > r.x + r.w)
x2 = r.x + r.w;
if (y1 < r.y)
y1 = r.y;
else if (y1 > r.y + r.h)
y1 = r.y + r.h;
if (y2 < r.y)
y2 = r.y;
else if (y2 > r.y + r.h)
y2 = r.y + r.h;
SDL_LockSurface (SDL_Screens[DC.data.line.destBuffer]);
line (x1, y1, x2, y2, color, screen_plot, SDL_Screens[DC.data.line.destBuffer]);
SDL_UnlockSurface (SDL_Screens[DC.data.line.destBuffer]);
break; break;
} }
case TFB_DRAWCOMMANDTYPE_RECTANGLE: case TFB_DRAWCOMMANDTYPE_RECTANGLE:
{ {
SDL_Rect r; TFB_DrawCanvas_Rect (&DC.data.rect.rect, DC.data.rect.r,
r.x = DC.data.rect.x; DC.data.rect.g, DC.data.rect.b,
r.y = DC.data.rect.y; SDL_Screens[DC.data.rect.destBuffer]);
r.w = DC.data.rect.w;
r.h = DC.data.rect.h;
SDL_FillRect(SDL_Screens[DC.data.rect.destBuffer], &r, SDL_MapRGB(SDL_Screen->format, DC.data.rect.r, DC.data.rect.g, DC.data.rect.b));
break; break;
} }
case TFB_DRAWCOMMANDTYPE_SCISSORENABLE: case TFB_DRAWCOMMANDTYPE_SCISSORENABLE:
@@ -698,11 +611,11 @@ TFB_FlushGraphics () // Only call from main thread!!
r.w = DC.data.scissor.w; r.w = DC.data.scissor.w;
r.h = DC.data.scissor.h; r.h = DC.data.scissor.h;
SDL_SetClipRect(SDL_Screen, &r); SDL_SetClipRect(SDL_Screens[0], &r);
break; break;
} }
case TFB_DRAWCOMMANDTYPE_SCISSORDISABLE: case TFB_DRAWCOMMANDTYPE_SCISSORDISABLE:
SDL_SetClipRect(SDL_Screen, NULL); SDL_SetClipRect(SDL_Screens[0], NULL);
break; break;
case TFB_DRAWCOMMANDTYPE_COPYTOIMAGE: case TFB_DRAWCOMMANDTYPE_COPYTOIMAGE:
{ {
+4 -11
View File
@@ -35,10 +35,7 @@ TFB_DrawScreen_Rect (PRECT rect, int r, int g, int b, SCREEN dest)
} }
DC.Type = TFB_DRAWCOMMANDTYPE_RECTANGLE; DC.Type = TFB_DRAWCOMMANDTYPE_RECTANGLE;
DC.data.rect.x = rect->corner.x; DC.data.rect.rect = *rect;
DC.data.rect.y = rect->corner.y;
DC.data.rect.w = rect->extent.width;
DC.data.rect.h = rect->extent.height;
DC.data.rect.r = r; DC.data.rect.r = r;
DC.data.rect.g = g; DC.data.rect.g = g;
DC.data.rect.b = b; DC.data.rect.b = b;
@@ -220,8 +217,6 @@ TFB_DrawScreen_WaitForSignal (void)
WaitForSignal (); WaitForSignal ();
} }
#if 0
/* These don't compile until I write the DrawCanvas commands. */ /* These don't compile until I write the DrawCanvas commands. */
void void
@@ -246,18 +241,16 @@ void
TFB_DrawImage_Image (TFB_Image *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, TFB_Image *target) TFB_DrawImage_Image (TFB_Image *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, TFB_Image *target)
{ {
LockMutex (target->mutex); LockMutex (target->mutex);
TFB_DrawCanvas_Image (img, x, y, scaled, target->NormalImg); TFB_DrawCanvas_Image (img, x, y, scaled, palette, target->NormalImg, 4, 4);
target->dirty = TRUE; target->dirty = TRUE;
UnlockMutex (target->mutex); UnlockMutex (target->mutex);
} }
void void
TFB_DrawImage_FilledImage (TFB_Image *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, TFB_Image *target) TFB_DrawImage_FilledImage (TFB_Image *img, int x, int y, BOOLEAN scaled, int r, int g, int b, TFB_Image *target)
{ {
LockMutex (target->mutex); LockMutex (target->mutex);
TFB_DrawCanvas_FilledImage (img, x, y, scaled, target->NormalImg); TFB_DrawCanvas_FilledImage (img, x, y, scaled, r, g, b, target->NormalImg, 4, 4);
target->dirty = TRUE; target->dirty = TRUE;
UnlockMutex (target->mutex); UnlockMutex (target->mutex);
} }
#endif
+5 -10
View File
@@ -19,7 +19,6 @@
#ifndef TFB_DRAW_H #ifndef TFB_DRAW_H
#define TFB_DRAW_H #define TFB_DRAW_H
#include "SDL.h"
#include "libs/threadlib.h" #include "libs/threadlib.h"
typedef void *TFB_Canvas; typedef void *TFB_Canvas;
@@ -45,8 +44,8 @@ typedef struct tfb_palette
typedef struct tfb_image typedef struct tfb_image
{ {
SDL_Surface *NormalImg; TFB_Canvas NormalImg;
SDL_Surface *ScaledImg; TFB_Canvas ScaledImg;
TFB_Palette *Palette; TFB_Palette *Palette;
int colormap_index; int colormap_index;
int scale; int scale;
@@ -68,18 +67,14 @@ void TFB_DrawScreen_WaitForSignal (void);
void TFB_DrawScreen_SetPalette (int index, int r, int g, int b); void TFB_DrawScreen_SetPalette (int index, int r, int g, int b);
void TFB_FlushPaletteCache (void); void TFB_FlushPaletteCache (void);
#if 0
// These don't compile until I implement the DrawCanvas commands.
void TFB_DrawImage_Line (int x1, int y1, int x2, int y2, int r, int g, int b, TFB_Image *dest); void TFB_DrawImage_Line (int x1, int y1, int x2, int y2, int r, int g, int b, TFB_Image *dest);
void TFB_DrawImage_Rect (PRECT rect, int r, int g, int b, TFB_Image *image); void TFB_DrawImage_Rect (PRECT rect, int r, int g, int b, TFB_Image *image);
void TFB_DrawImage_Image (TFB_Image *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, TFB_Image *target); void TFB_DrawImage_Image (TFB_Image *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, TFB_Image *target);
void TFB_DrawImage_FilledImage (TFB_Image *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, TFB_Image *target); void TFB_DrawImage_FilledImage (TFB_Image *img, int x, int y, BOOLEAN scaled, int r, int g, int b, TFB_Image *target);
/* These routines are properly defined in the driver-specific libraries. */
void TFB_DrawCanvas_Line (int x1, int y1, int x2, int y2, int r, int g, int b, TFB_Canvas dest); void TFB_DrawCanvas_Line (int x1, int y1, int x2, int y2, int r, int g, int b, TFB_Canvas dest);
void TFB_DrawCanvas_Rect (PRECT rect, int r, int g, int b, TFB_Canvas image); void TFB_DrawCanvas_Rect (PRECT rect, int r, int g, int b, TFB_Canvas image);
void TFB_DrawCanvas_Image (TFB_Image *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, TFB_Canvas target); void TFB_DrawCanvas_Image (TFB_Image *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, TFB_Canvas target, int bn, int bd);
void TFB_DrawCanvas_FilledImage (TFB_Image *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, TFB_Canvas target); void TFB_DrawCanvas_FilledImage (TFB_Image *img, int x, int y, BOOLEAN scaled, int r, int g, int b, TFB_Canvas target, int bn, int bd);
#endif
#endif #endif