You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

584 lines
17 KiB
C

//
// G A M E.O.N.E - LOW LEVEL LIB V1.0
// Copyright (C) 2001 LEVEL ONE ENTERTAINMENT,
// Licensed under the terms of LGPL.
//:---------------------------------------------------------------------------
//:Description
//
// LOW LEVEL GFX DRIVER
//
//:-----------------------------------------------------------------------------
#if !defined(LLGFX_INCLUDED)
#define LLGFX_INCLUDED
/*
* Grafik ID. erzeugt durch CreateGfx und LoadGfx
*/
typedef int llgfx_id; // gfxindex
#include "lib_base.h"
#include "llgfx_ctexture.h"
/*
* LOAD FLAGS
*/
#define LLGFX_VIDMEM (0x01) // Grafikbuffer in Video memory anlegen
#define LLGFX_COLORKEY (0x02) // COLORKEY setzen
#define LLGFX_CACHE (0x04) // Importfile cachen
/*
* OPTIONEN FÜR SetFrameCount();
*/
#define LLGFX_FRAME_COUNT (0x0) // Parameter ist Frameanzahl
#define LLGFX_FRAME_HEIGHT (0x1) // Parameter ist Framehöhe (llgfx_SetFrameCount())
//:Include
#include "llgfx_color.h"
#include "llgfx_sscreen.h"
#include "ll2d_rect.h"
#include "llqueue.h"
#include "llgfx_vd.h"
#include "llgfx_smode.h"
#include "llgfx_sfont.h"
#include "llgfx_blit.h"
#define BLIT_FXCOLOR (1<<18) // Color Overlay mit Alphawert 0.0f - 1.0f
/*
* RUNTIME OPTIONEN
*/
EXTERN bool llgfx_enable_singlebuffer; // Singlebuffer Modus explizit auch für Fullscreen modus setzen
EXTERN bool llgfx_enable_stretchwindow; // Wenn true, kann man im Fenstermodus das Window ziehen
EXTERN bool llgfx_force_vidmem; // sollte man im windowmodus bei direktem zugriff auf den Backbuffer auf false setzen
EXTERN bool llgfx_force_sysmem; // ignoriert vidmem und legt alle grafikbuffer im system memory an
EXTERN TxU32 llgfx_clearcolor; // Löschfarbe bei llgfx_ClearScreen() oder llgfx_ClearGfx()
EXTERN float llgfx_window_scale; // scale faktor beim anlegen eines nicht-fullscreen fensters
EXTERN bool llgfx_dirtyrect_enabled; // Wenn true, werden alle Änderungen in Form des rectangles gespeichert
/*
* RUNTIME GLOBALE
*/
EXTERN int llgfx_displaywidth; // Breite des aktuellen Bildschirms
EXTERN int llgfx_displayheight; // Höhe des aktuellen Bildschirms
EXTERN int llgfx_bitspixel; // Pixel des aktuellen Bildschirms
EXTERN int llgfx_refreshrate; // Refreschrate des aktuellen Bildschirms
EXTERN int llgfx_frame_counter; // zählt die anzahl der llgfx_FlipScreen() Aufrufe
EXTERN bool llgfx_fullscreen; // True bei Vollschirmmodus
EXTERN s_surface llgfx_sGfxBuffer; // Bei jedem lock vom Backbuffer ist diese Struktur gültig
EXTERN s_rgb llgfx_rgb; // R G B A Bitmasken
EXTERN queue<s_mode> llgfx_displaymodes;// Liste der unterstützten Displaymodes
EXTERN int llgfx_displaychanged; // Erhöht sich bei jedem Bildschirmmodus Wechsel. z.B. Vollschirm<->Fenster
EXTERN queue<llgfx_sRECT> llgfx_dirtyrects; // Rectangle liste der Änderungen
/*
* TEXT OUT OPTIONEN
*/
EXTERN int llgfx_text_xpos; // XPos relativ zu llgfx_text_rect
EXTERN int llgfx_text_ypos; // YPos relativ zu llgfx_text_rect
EXTERN float llgfx_text_xspacing; // Abstand x
EXTERN float llgfx_text_yspacing; // Abstand y;
EXTERN int llgfx_text_format; // 0=Links, 1=Rechts, 2= mitte, 3=Block
EXTERN s_rect llgfx_text_rect; // Ausgabe Rectangle
EXTERN int llgfx_tab_pos[8]; // tabpositionen in EM's (Durchschnitss breite)
EXTERN s_font * llgfx_cur_font; // Fontstruct für Textausgabe
EXTERN bool llgfx_text_wrap; // true=wrapx, false=clip
//:> +------------------------------------+
//:>-------------------| Bildschirm Funktionen |-------------------
//:> +------------------------------------+
// Setzt einen neuen Bildschirm Modus.
// Liefert OK bei Erfolg.
//
#define llgfx_SetMode llgfx_SetDisplayMode
long llgfx_SetDisplayMode(
int w, // Bildschirm breite in Pixel
int h, // Bildschirm Höhe in Pixel
int bpp, // gewünschte Bittiefe
bool want_fullscreen, // true setzten für Vollschirm Modus
int refreshrate=0); // Refreshrate
// Löscht Backbuffer. Default rectangle = VD, bzw ganzer Schirm wenn
// VD nicht gesetzt
int llgfx_ClearScreen(
long color=llgfx_clearcolor, // Löschfarbe
llgfx_sRECT *dstrect=0); // optionales ziel rectangle
// Wechselt Backbuffer zum Frontbuffer.
// Parameter: wait=true bewirkt das erst auf den VBI gewartet wird bevor der Flip
// durchgeführt wird und das nach dem Flip auf das Ende des Flips gewartet wird.
//
void llgfx_FlipScreen(bool wait); // true=wartet auf VBI
// Speichert den aktuellen FRONTBUFFER in ein tga file
// Liefert OK bei Erfolg
//
int llgfx_ScreenShot(
const char* filename);
// Wechselt Bildschirm Modus zwischen Vollschirm und Fenster Modus.
// Beim wechseln können Probleme auftreten, insbesonders da am
// Desktop kein Hardware-Flip aufgesetzt wird und daher hörere Bittiefen
// möglich sein können.
//
// Die Funktion setzt bei einem Fehler wieder auf den letzten Bildschirm modus auf.
// Returnwert = OK bei Erfolg sonst Fehler
//
int llgfx_ToggleFullscreen();
// Wartet bis ein VBI Eintritt. (Rasterstrahl im Vertical Blank Bereich).
void llgfx_WaitVBI(
void);
//:> +------------------------------------+
//:>-------------------| Grafik Funktionen |-------------------
//:> +------------------------------------+
// Ladet ein Grafikfile in einen neuen Grafikbuffer.
// Liefert index des Grafikbuffers zurück.
// Bei Fehler ist der Returnwert 0.
//
// Existiert bereits ein Grafikbuffer mit dem Pfad, dann wird die Referenz erhöht
// und der existierende Bufferindex wird zurückgeliefert. Es sind dann mehrere
// llgfx_ReleaseGFX Aufrufe notwendig um den Grafikbuffer zu entfernen. Ist eine
// eigene Kopie des Grafikbuffers gewünscht, dann sollte man einen Buffer mit
// llgfx_CreateGfx allokieren und anschliessend mit llgfx_BLITFAST kopieren.
//
// Parameter:
// filename = Pfad der zur ladenden Grafik
// flags = sind mit Oder verknüpfte Optionen:
//
// LLGFX_VIDMEM, GrafikBuffer im Videomemory anlegen.
//
// LLGFX_COLORKEY, Colorkey einschalten und setzten. (Linkes Oberes Pixel =
// Colorkey)
//
// LLGFX_CACHE, Das Importfile im Speicher halten.
//
// filename="RES:filename"... lädt aus der resource
// filename="ZIP:filename"... lädt aus dem Zipstream
// filename="filename".... lädt aus dem Filesystem
//
llgfx_id llgfx_LoadGfx(
const char * filename, // vollständiger Pfad mit extension
int flags=0); // LLGFX_COLORKEY | LLGFX_VIDMEM | LLGFX_CACHE
// Liefert die Anzahl der allokierten Grafikbuffer.
int llgfx_GetNumGfx(void);
// Erstellt eine Grafik mit breite, höhe und bittiefe des Backbuffers
// sysmem gibt an ob der Grafikbuffer auf der Grafikkarte sein soll oder im
// Systemmemory.
// Return: llgfx_id oder 0 bei Fehler
//
llgfx_id llgfx_CreateGfx(
int width,
int height,
bool vidmem, // true=grafikbuffer ins videomemory
const char *name=0); // Optional namen setzen
char * llgfx_GetGfxName(
llgfx_id idx);
// Der Grafikbuffer mit dem Parameter "filename" wird gelöscht, egal wieviele
// Referenzen darauf existieren.
// Return: OK wenn der Grafikbuffer gefunden und gelöscht wurde,
// FAIL wenn der Grafikbuffer nicht gefunden wurde.
//
int llgfx_DeleteGfx(const char *filename); // Löschen nach filename
void llgfx_DeleteGfx(llgfx_id gfx); // Löschen nach id
// Löscht Grafikbuffer mit dem Blitter.
// Parameter color = Löschfarbe (default=BLACK)
// Parameter dstrect = Zielrechteck (default=ganze Grafik)
//
int llgfx_ClearGfx(
llgfx_id idx, // gfx id
TxU32 color=llgfx_clearcolor, // Löschfarbe
llgfx_sRECT *dstrect=0);
// Referenzcount einer Grafik erhöhen.
llgfx_id llgfx_AddRef( llgfx_id gfx);
// Setzt den Colorkey ausser Kraft
void llgfx_DisableColorKey(llgfx_id idx);
// Schaltet Colorkey ein
void llgfx_EnableColorKey(llgfx_id idx);
// Liefert colorkey im RGB888 Format.
TxU32 llgfx_GetColorKey(llgfx_id idx);
// Liefert Höhe der Grafik in Pixel
int llgfx_GetGfxHeight(llgfx_id idx);
// Liefert Breite der Grafik in Pixel.
int llgfx_GetGfxWidth(llgfx_id idx);
bool llgfx_IsColorkeyEnabled(llgfx_id idx);
// Grafikbuffer freigeben der mit diesem Pfad über llgfx_LoadGfx erzeugt wurde.
// Wenn der Referenzcount 0 erreicht wird der Grafikbuffer aus dem Speicher
// entfernt.
//
// Parameter: Wenn der filename "ALL" übergeben wird, werden alle Grafiken
// die angelegt wurden gelöscht.
// Return:
// OK wenn der Grafikbuffer mit dem Pfad gefunden und freigeben wurde,
// sonst ungleich 0.
//
int llgfx_ReleaseGfx( const char *filename);
void llgfx_ReleaseGfx( llgfx_id idx);
// Vermindert den Referenzzähler um eins.
//
// Wenn der Referenzhzähler bereits 1 oder 0 ist,
// dann wird der Referenzzähler nicht weiter vermindert.
// Im Gegensatz zu llgfx_ReleaseGfx() wo bei einer Referenzzählerstand von 1 die
// Grafik aus dem Speicher entfernt wird.
//
// Liefert die Anzahl verbleibender Referenzen.
//
int llgfx_ReleaseRef(llgfx_id gfx);
// Setzt die Colorkeyfarbe.
// ColorValue in 32 Bit RGB Farbe angeben, nicht in DeviceColor !
// Zusäztlich wird der colorkey enabled durch einen Implizieten Aufruf von
// llgfx_EnableColorkey().
//
void llgfx_SetColorKey(
llgfx_id idx,
unsigned long ColorValue);
// Setzt die Colorkeyfarbe nach der Farbe des Pixels links/oben im Grafikbuffer.
// Zusätzlich wird der colorkey enabled durch einen Impliziten Aufruf von
// llgfx_EnableColorkey().
//
// siehe auch:
// llgfx_EnableColorKey(llgfx_id)
// llgfx_DisableColorKey(llgfx_id)
// llgfx_LoadGfx(const char,flags)
//
void llgfx_SetColorKeyFromTOPLEFTpixel(
llgfx_id gfxnum);
// Setzt anzahl von Animationsframes in einer Grafik.
// Die Frames müssen alle untereinander liegen.
// Als Angabe der Frameanzahl kann die Framehöhe einer Einzelgrafik,
// oder die Frameanzahl selbst übergeben werden.
// In beiden Fällen muss die Frameanzahl * Framehöhe ganzzahlig in der
// Original Höhe enthalten sein.
// Nach einem Aufruf von SetFrameCount liefert llgfx_GetGfxHeigt() nurmehr
// die Single-Frame Höhe. Ein Blit() ohne Angabe eines Source-Frames blittet
// nurmehr das erste Frame. Um die weiteren Frames zu blitten wird anstatt
// eines Source-Rectangles, die Frame-Nummer übergeben;
// bsp:
// int aktframe = 4;
// llgfx_VD_BLIT( srcgfx, x, y, (llgfx_sRECT*) aktframe );
//
// Achtung:! der cast (llgfx_sRECT*) ist nur erlaubt wenn die FrameAnzahl
// gesetzt ist. Falls nicht wird eine ASSERTION ausgelöst da aktframe kein
// gültiger Zeiger auf ein RECT ist.
//
// Ein Aufruf mit einem parameter 0 oder 1, setzt die Frames wieder zurück.
//
// RETURN:
// Anzahl der Frames die gesetzt wurden
//
int llgfx_SetFrameCount(
llgfx_id idx,
int parametertyp, // FRAME_HEIGHT, FRAME_COUNT
int parameter);
// Liefert Anzahl frames, 0= keine gesetzt, >0 = anzahl frames
int llgfx_GetFrameCount(
llgfx_id idx );
// Erstellt Cache texture nach Grafikmanipulation
void llgfx_RebuildTexture( llgfx_id idx);
void llgfx_RestoreTexture(llgfx_id idx);
// liefert rgba texture (import file)
llgfx_CTexture * llgfx_GetTexture( llgfx_id idx );
// Setzt x/y offset werte für Blit Funktionen.
// X,Y Offset werden bei jeder Blit Funktion zum Ziel dazu addiert,
// mit Ausnahme wenn im BlitFlag ein BLIT_SRC_CENTERED gesetzt ist.
void llgfx_SetOrigin( llgfx_id idx, int xoffset, int yoffset );
// Liefert aktuellen xoffset/yoffset
void llgfx_GetOrigin( llgfx_id idx, int &xoffset, int &yoffset );
// liefert das umschliesende Rechteck der Grafik.
// X/Y Offset wird mit einberechnet.
void llgfx_GetBoundingRect( llgfx_id idx, llgfx_sRECT & rect );
void llgfx_GetBoundingRect( llgfx_id idx, llgfx_sRECT * rect );
llgfx_CTexture * llgfx_CreateTextureFromGfx( llgfx_id idx);
//:> +------------------------------------+
//:>-------------------| Grafik Buffer Funktionen |-------------------
//:> +------------------------------------+
void * llgfx_GetGFXptr( llgfx_id idx); // fills llgfx_sGfxBuffer
void * llgfx_GetGFXptr( llgfx_id idx, llgfx_sSURFACE *surfaceptr );
void * llgfx_GetGFXptr( llgfx_id idx, llgfx_sSURFACE *surfaceptr, llgfx_sRECT *rect );
// Grafikbuffer aus dem LOCK Modus wieder freigeben.
void llgfx_UnGetGFXptr(llgfx_id idx);
void llgfx_SetPalette(TxU8 index, TxU32 rgbcolor );
TxU32 llgfx_GetPalette(TxU8 index );
//:> +------------------------------------+
//:>-------------------| Textausgabe mit systemfonts |-------------------
//:> +------------------------------------+
inline void llgfx_SetTextPos(int xpos, int ypos )
{
llgfx_text_xpos = xpos;
llgfx_text_ypos = ypos;
}
inline void llgfx_SelectFont( s_font * font )
{
llgfx_cur_font = font;
}
inline void llgfx_SetTextRect( s_rect * rect )
{
ll2d::CopyRect( llgfx_text_rect, rect );
ll2d::OffsetRect( llgfx_text_rect, llgfx_VD );
llgfx_SetTextPos(0,0);
}
void llgfx_DrawText(
llgfx_id dst,
const char * text,
int blitflags=0,
llgfx_sBLITFX *blitfx=0
);
inline void llgfx_DrawText(
const char * text
)
{
llgfx_DrawText(/*dstgfx*/0,text);
}
inline void llgfx_DrawText(
const char * text,
TxU32 color
)
{
llgfx_sBLITFX blitfx;
blitfx.color = color;
blitfx.fixalpha = 1.0f;
llgfx_DrawText(/*dstgfx*/0,text,BLIT_FXCOLOR,&blitfx);
}
inline void llgfx_DrawText(
int x,
int y,
const char * text
)
{
llgfx_text_xpos = x;
llgfx_text_ypos = y;
llgfx_DrawText(/*dstgfx*/0,text);
}
inline void llgfx_DrawText(
llgfx_id dst,
const char * text,
TxU32 color
)
{
llgfx_sBLITFX blitfx;
blitfx.color = color;
blitfx.fixalpha = 1.0f;
llgfx_DrawText(dst,text,BLIT_FXCOLOR,&blitfx);
}
inline void llgfx_DrawText( const char * text, int blitflags, llgfx_sBLITFX *blitfx )
{
llgfx_DrawText( /*dstgfx*/0, text, blitflags, blitfx );
}
void llgfx_GetTextRect( s_rect * rect, const char * text);
//:> +------------------------------------+
//:>-------------------| Dirty Rect Funktionen |-------------------
//:> +------------------------------------+
//
void llgfx_AddDirtyRect( llgfx_sRECT &rect ); // Ein Rechteck zur dirtyrect Liste hinzufügen.
// Setzt automatisches AddDirtyRect ausser Kraft.
// Aktuelle Dirtylist wird gelöscht.
void llgfx_DisableDirtyRect(void);
// Schaltet automatisches Hinzufügen der Dirtyrects ein.
// Löscht aktuelle dirtyrect liste.
void llgfx_EnableDirtyRect(void);
// llgfx_IsDirtyRectEnabled()
//
bool llgfx_IsDirtyRectEnabled(void);
//::112
// +------------------------+
// | llgfx_GetPointPosQ() |
// +------------------------+
//:Description
//
// ------------------------------------------------------------------------------
// llgfx_GetPointPosQ()
//
// Qualifiziert die Position von Punkt(x,y) zum Rechteck.
// Return:
// PPQ_INSIDE,PPQ_TOPLEFT,PPQ_ABOVE,PPQ_TOPRIGHT,PPQ_LEFT,PPQ_RIGHT,PPQ_BELOW,
// PPQ_BOTTOMLEFT,PPQ_BOTTOMRIGHT
// Bit 76543210
// ||||
// |+|+--- %00=y inside R %01=x above R R %10=y below R
// | |
// +-+---- %00=x inside R %01=x left of R %10=x right of R
//
// 0011 0001 1001 TOPLEFT ABOVE TOPRIGHT
// +-------+ +-------+
// 0010 | 0000 | 1000 LEFT |INSIDE | RIGHT
// +-------+ +-------+
// 0110 0100 1100 BOTTOMLEFT BELOW BOTTOMRIGHT
//
#define PPQ_TOPBIT (0x1)
#define PPQ_LEFTBIT (0x2)
#define PPQ_BOTTOMBIT (0x4)
#define PPQ_RIGHTBIT (0x8)
typedef enum{
PPQ_INSIDE = (0x0),
PPQ_TOPLEFT = (PPQ_TOPBIT|PPQ_LEFTBIT),
PPQ_ABOVE = (PPQ_TOPBIT),
PPQ_TOPRIGHT = (PPQ_TOPBIT|PPQ_RIGHTBIT),
PPQ_LEFT = (PPQ_LEFTBIT),
PPQ_RIGHT = (PPQ_RIGHTBIT),
PPQ_BELOW = (PPQ_BOTTOMBIT),
PPQ_BOTTOMLEFT = (PPQ_BOTTOMBIT|PPQ_LEFTBIT),
PPQ_BOTTOMRIGHT = (PPQ_BOTTOMBIT|PPQ_RIGHTBIT)
} ePPQ;
inline ePPQ llgfx_GetPointPosQ(
int tx,
int ty,
llgfx_sRECT *R);
//
// Float version.
// Beispiel:
// { float R[4];
// R[0] = rect.x1 + 0.5f;
// R[1] = rect.y1 + 0.5f;
// R[2] = rect.x2 + 0.5f;
// R[3] = rect.y2 + 0.5f;
// ePPQ ppq = llgfx_GetPointPosQ( fx, fy, &R );
//}
inline ePPQ llgfx_GetPointPosQ( float tx, float ty, float *R );
//:> +-----------------------------------+
//:>-------------------| Global Function Definitions |--------------------
//:> +-----------------------------------+
//::112
// +------------------------+
// | llgfx_GetPointPosQ() |
// +------------------------+
//
// Bit 76543210
// ||||
// |+|+--- %00=y inside R %01=x above R R %10=y below R
// | |
// +-+---- %00=x inside R %01=x left of R %10=x right of R
//
// 0011 0001 1001 TOPLEFT ABOVE TOPRIGHT
// +-------+ +-------+
// 0010 | 0000 | 1000 LEFT |INSIDE | RIGHT
// +-------+ +-------+
// 0110 0100 1100 BOTTOMLEFT BELOW BOTTOMRIGHT
//
inline ePPQ llgfx_GetPointPosQ( int tx, int ty, llgfx_sRECT *R )
{
int a;
if( tx < R->x1 )
a = PPQ_LEFTBIT;
else
if( tx >= R->x2 )
a = PPQ_RIGHTBIT;
else
a = 0;
if( ty < R->y1 )
a |= PPQ_TOPBIT;
else
if( ty >= R->y2 )
a |= PPQ_BOTTOMBIT;
return (ePPQ)a;
}
inline ePPQ llgfx_GetPointPosQ( float tx, float ty, float *R )
{
int a;
if( tx < R[0] )
a = PPQ_LEFTBIT;
else
if( tx >= R[2] )
a = PPQ_RIGHTBIT;
else
a = 0;
if( ty < R[1] )
a |= PPQ_TOPBIT;
else
if( ty >= R[2] )
a |= PPQ_BOTTOMBIT;
return (ePPQ)a;
}
#endif // LLGFX_INCLUDED