forked from Mirrors/openclonk
Merge branch 'landscape'
commit
2c56657a41
|
@ -117,6 +117,7 @@ class C4ConfigGraphics
|
|||
int32_t ShowStartupMessages;
|
||||
int32_t VerboseObjectLoading;
|
||||
int32_t ColorAnimation;
|
||||
int32_t HighResLandscape;
|
||||
int32_t SmokeLevel;
|
||||
int32_t VideoModule;
|
||||
int32_t MenuTransparency;
|
||||
|
|
|
@ -57,7 +57,6 @@ class C4GraphicsResource
|
|||
int32_t iNumRanks;
|
||||
C4FacetID fctFire;
|
||||
C4FacetID fctBackground;
|
||||
C4Surface sfcLiquidAnimation; int32_t idSfcLiquidAnimation;
|
||||
C4FacetID fctCaptain;
|
||||
C4FacetID fctMouseCursor;
|
||||
bool fOldStyleCursor; // if set, offsets need to be applied to some cursor facets
|
||||
|
|
|
@ -73,7 +73,6 @@ class C4Landscape
|
|||
BYTE *pInitial; // Initial landscape after creation - used for diff
|
||||
protected:
|
||||
CSurface * Surface32;
|
||||
CSurface * AnimationSurface;
|
||||
CSurface8 * Surface8;
|
||||
int32_t Pix2Mat[256], Pix2Dens[256], Pix2Place[256];
|
||||
int32_t PixCntPitch;
|
||||
|
|
|
@ -140,7 +140,7 @@ class C4StartupOptionsDlg : public C4StartupDlg
|
|||
|
||||
C4GUI::CheckBox *pCheckGfxEngines[3], *pCheckGfxClrDepth[2];
|
||||
C4GUI::GroupBox *pGroupTrouble;
|
||||
C4GUI::CheckBox *pCheckGfxNoAlphaAdd, *pCheckGfxPointFilter, *pCheckGfxNoAddBlit, *pCheckGfxNoBoxFades, *pCheckGfxClipManually;
|
||||
C4GUI::CheckBox *pCheckGfxNoAlphaAdd, *pCheckGfxPointFilter, *pCheckGfxNoAddBlit, *pCheckGfxNoBoxFades, *pCheckGfxClipManually, *pShaders;
|
||||
int32_t iGfxTexIndent, iGfxBlitOff; EditConfig *pEdtGfxBlitOff;
|
||||
C4GUI::ScrollBar *pEffectLevelSlider;
|
||||
|
||||
|
|
|
@ -134,7 +134,8 @@ void C4ConfigGraphics::CompileFunc(StdCompiler *pComp)
|
|||
pComp->Value(mkNamingAdapt(ShowCommands, "ShowCommands", 1 ,false, true));
|
||||
pComp->Value(mkNamingAdapt(ShowCommandKeys, "ShowCommandKeys", 1 ,false, true));
|
||||
pComp->Value(mkNamingAdapt(ShowStartupMessages, "ShowStartupMessages", 1 ,false, true));
|
||||
pComp->Value(mkNamingAdapt(ColorAnimation, "ColorAnimation", 0 ,false,true));
|
||||
pComp->Value(mkNamingAdapt(ColorAnimation, "ColorAnimation", 0 ,false, true));
|
||||
pComp->Value(mkNamingAdapt(HighResLandscape, "HighResLandscape", 0 ,false, true));
|
||||
pComp->Value(mkNamingAdapt(SmokeLevel, "SmokeLevel", 200 ,false, true));
|
||||
pComp->Value(mkNamingAdapt(VerboseObjectLoading, "VerboseObjectLoading", 0 ));
|
||||
pComp->Value(mkNamingAdapt(VideoModule, "VideoModule", 0 ,false, true));
|
||||
|
|
|
@ -61,7 +61,6 @@ void C4GraphicsResource::Default()
|
|||
fctRank.Default();
|
||||
fctFire.Default();
|
||||
fctBackground.Default();
|
||||
sfcLiquidAnimation.Default(); idSfcLiquidAnimation = 0;
|
||||
fctCaptain.Default();
|
||||
fctMouseCursor.Default();
|
||||
fctSelectMark.Default();
|
||||
|
@ -122,7 +121,6 @@ void C4GraphicsResource::Clear()
|
|||
fctRank.Clear();
|
||||
fctFire.Clear();
|
||||
fctBackground.Clear();
|
||||
sfcLiquidAnimation.Clear();
|
||||
fctCaptain.Clear();
|
||||
fctMouseCursor.Clear();
|
||||
fctSelectMark.Clear();
|
||||
|
@ -236,7 +234,6 @@ BOOL C4GraphicsResource::Init(bool fInitGUI)
|
|||
if (!LoadFile(fctGamepad, "Gamepad", Files, 80)) return FALSE;
|
||||
if (!LoadFile(fctBuild, "Build", Files)) return FALSE;
|
||||
if (!LoadFile(fctEnergyBars, "EnergyBars", Files)) return FALSE;
|
||||
if (!LoadFile(sfcLiquidAnimation, "Liquid", Files, idSfcLiquidAnimation)) return FALSE;
|
||||
// life bar facets
|
||||
if (fctEnergyBars.Surface)
|
||||
{
|
||||
|
|
|
@ -282,7 +282,6 @@ void C4Landscape::Clear(bool fClearMapCreator, bool fClearSky)
|
|||
if (fClearSky) Sky.Clear();
|
||||
// clear surfaces, if assigned
|
||||
delete Surface32; Surface32=NULL;
|
||||
delete AnimationSurface; AnimationSurface=0;
|
||||
delete Surface8; Surface8=NULL;
|
||||
delete Map; Map=NULL;
|
||||
// clear initial landscape
|
||||
|
@ -304,7 +303,15 @@ void C4Landscape::Draw(C4TargetFacet &cgo, int32_t iPlayer)
|
|||
if (::GraphicsSystem.ShowSolidMask)
|
||||
Application.DDraw->Blit8Fast(Surface8, cgo.TargetX, cgo.TargetY, cgo.Surface, cgo.X,cgo.Y,cgo.Wdt,cgo.Hgt);
|
||||
else
|
||||
Application.DDraw->BlitLandscape(Surface32, AnimationSurface, &::GraphicsResource.sfcLiquidAnimation, cgo.TargetX, cgo.TargetY, cgo.Surface, cgo.X,cgo.Y,cgo.Wdt,cgo.Hgt);
|
||||
{
|
||||
const CSurface * Surfaces[C4M_MaxTexIndex];
|
||||
if (Config.Graphics.HighResLandscape)
|
||||
for (int i = 0; i < C4M_MaxTexIndex; ++i)
|
||||
Surfaces[i] = ::TextureMap.GetEntry(i)->getPattern().getSurface();
|
||||
Application.DDraw->BlitLandscape(Surface32, cgo.TargetX, cgo.TargetY, cgo.Surface,
|
||||
cgo.X, cgo.Y, cgo.Wdt, cgo.Hgt,
|
||||
Config.Graphics.HighResLandscape ? Surfaces : 0);
|
||||
}
|
||||
if (Modulation) Application.DDraw->DeactivateBlitModulation();
|
||||
}
|
||||
|
||||
|
@ -385,7 +392,6 @@ void C4Landscape::ChunkOZoom(CSurface8 * sfcMap, int32_t iMapX, int32_t iMapY, i
|
|||
// get chunk size
|
||||
iChunkWidth=MapZoom; iChunkHeight=MapZoom;
|
||||
Surface32->Lock();
|
||||
if (AnimationSurface) AnimationSurface->Lock();
|
||||
// Scan map lines
|
||||
for (iY=iMapY; iY<iMapY+iMapHgt; iY++)
|
||||
{
|
||||
|
@ -433,7 +439,6 @@ void C4Landscape::ChunkOZoom(CSurface8 * sfcMap, int32_t iMapX, int32_t iMapY, i
|
|||
}
|
||||
}
|
||||
Surface32->Unlock();
|
||||
if (AnimationSurface) AnimationSurface->Unlock();
|
||||
}
|
||||
|
||||
BOOL C4Landscape::GetTexUsage(CSurface8 * sfcMap, int32_t iMapX, int32_t iMapY, int32_t iMapWdt, int32_t iMapHgt, DWORD *dwpTextureUsage)
|
||||
|
@ -492,7 +497,6 @@ BOOL C4Landscape::MapToSurface(CSurface8 * sfcMap, int32_t iMapX, int32_t iMapY,
|
|||
// assign clipper
|
||||
Surface8->Clip(iToX,iToY,iToX+iToWdt-1,iToY+iToHgt-1);
|
||||
Surface32->Clip(iToX,iToY,iToX+iToWdt-1,iToY+iToHgt-1);
|
||||
if (AnimationSurface) AnimationSurface->Clip(iToX,iToY,iToX+iToWdt-1,iToY+iToHgt-1);
|
||||
Application.DDraw->NoPrimaryClipper();
|
||||
|
||||
// Enlarge map segment for chunky rim
|
||||
|
@ -507,7 +511,6 @@ BOOL C4Landscape::MapToSurface(CSurface8 * sfcMap, int32_t iMapX, int32_t iMapY,
|
|||
// remove clipper
|
||||
Surface8->NoClip();
|
||||
Surface32->NoClip();
|
||||
if (AnimationSurface) AnimationSurface->NoClip();
|
||||
|
||||
// success
|
||||
return TRUE;
|
||||
|
@ -535,12 +538,10 @@ BOOL C4Landscape::MapToLandscape(CSurface8 * sfcMap, int32_t iMapX, int32_t iMap
|
|||
To.Hgt = iMapHgt*MapZoom;
|
||||
|
||||
Surface32->Lock();
|
||||
if (AnimationSurface) AnimationSurface->Lock();
|
||||
PrepareChange(To);
|
||||
MapToSurface(sfcMap, iMapX, iMapY, iMapWdt, iMapHgt, To.x, To.y, To.Wdt, To.Hgt, iOffsX, iOffsY);
|
||||
FinishChange(To);
|
||||
Surface32->Unlock();
|
||||
if (AnimationSurface) AnimationSurface->Unlock();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -724,15 +725,12 @@ BOOL C4Landscape::Init(C4Group &hGroup, bool fOverloadCurrent, bool fLoadSky, bo
|
|||
// Create landscape surface
|
||||
Surface32 = new CSurface();
|
||||
Surface8 = new CSurface8();
|
||||
if (Config.Graphics.ColorAnimation && DDrawCfg.Shader)
|
||||
AnimationSurface = new CSurface(Width, Height);
|
||||
if (!Surface32->Create(Width, Height, true, false, lpDDraw->IsShaderific() ? 0 : 64)
|
||||
|| !Surface8->Create(Width, Height, true)
|
||||
|| (AnimationSurface && !AnimationSurface->Create(Width, Height))
|
||||
|| !Mat2Pal())
|
||||
{
|
||||
delete Surface8; delete Surface32; delete AnimationSurface;
|
||||
Surface8 = 0; Surface32 = 0; AnimationSurface = 0;
|
||||
delete Surface8; delete Surface32;
|
||||
Surface8 = 0; Surface32 = 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -1556,8 +1554,6 @@ BOOL C4Landscape::Load(C4Group &hGroup, bool fLoadSky, bool fSavegame)
|
|||
Surface8->GetSurfaceSize(iWidth,iHeight);
|
||||
Width = iWidth; Height = iHeight;
|
||||
Surface32 = new CSurface(Width, Height);
|
||||
if (Config.Graphics.ColorAnimation && DDrawCfg.Shader)
|
||||
AnimationSurface = new CSurface(Width, Height);
|
||||
// adjust pal
|
||||
if (!Mat2Pal()) return FALSE;
|
||||
// load the 32bit-surface, too
|
||||
|
@ -1655,7 +1651,6 @@ void C4Landscape::Default()
|
|||
Mode=C4LSC_Undefined;
|
||||
Surface8=NULL;
|
||||
Surface32=NULL;
|
||||
AnimationSurface=0;
|
||||
Map=NULL;
|
||||
Width=Height=0;
|
||||
MapWidth=MapHeight=MapZoom=0;
|
||||
|
@ -2505,11 +2500,14 @@ bool C4Landscape::ApplyLighting(C4Rect To)
|
|||
if (To.Wdt<=0 || To.Hgt<=0) return true;
|
||||
if (!Surface32->Lock()) return false;
|
||||
Surface32->ClearBoxDw(To.x, To.y, To.Wdt, To.Hgt);
|
||||
if (AnimationSurface)
|
||||
|
||||
if(lpDDraw->IsShaderific() && Config.Graphics.HighResLandscape)
|
||||
{
|
||||
AnimationSurface->Lock();
|
||||
AnimationSurface->ClearBoxDw(To.x, To.y, To.Wdt, To.Hgt);
|
||||
for (int32_t iX=To.x; iX<To.x+To.Wdt; ++iX)
|
||||
for (int32_t iY=To.y; iY<To.y+To.Hgt; ++iY)
|
||||
Surface32->SetPixDw(iX, iY, _GetPix(iX, iY));
|
||||
}
|
||||
else
|
||||
// do lightning
|
||||
for (int32_t iX=To.x; iX<To.x+To.Wdt; ++iX)
|
||||
{
|
||||
|
@ -2557,11 +2555,9 @@ bool C4Landscape::ApplyLighting(C4Rect To)
|
|||
DarkenClrBy(dwBackClr, Min(30, 2 * (iOwnDens - iCompareDens)));
|
||||
}
|
||||
Surface32->SetPixDw(iX, iY, dwBackClr);
|
||||
if (AnimationSurface) AnimationSurface->SetPixDw(iX, iY, DensityLiquid(Pix2Dens[pix]) ? 255 << 24 : 0);
|
||||
}
|
||||
}
|
||||
Surface32->Unlock();
|
||||
if (AnimationSurface) AnimationSurface->Unlock();
|
||||
// done
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -841,7 +841,7 @@ C4StartupOptionsDlg::C4StartupOptionsDlg() : C4StartupDlg(LoadResStrNoAmp("IDS_D
|
|||
pSheetGraphics->AddElement(pGroupTrouble);
|
||||
C4GUI::ComponentAligner caGroupTrouble(pGroupTrouble->GetClientRect(), iIndentX1, iIndentY2, true);
|
||||
C4GUI::BaseCallbackHandler *pGfxGroubleCheckCB = new C4GUI::CallbackHandler<C4StartupOptionsDlg>(this, &C4StartupOptionsDlg::OnGfxTroubleCheck);
|
||||
int32_t iNumGfxOptions = 5, iOpt=0;
|
||||
int32_t iNumGfxOptions = 6, iOpt=0;
|
||||
// no alpha adding
|
||||
pCheckGfxNoAlphaAdd = new C4GUI::CheckBox(caGroupTrouble.GetGridCell(0,2,iOpt++,iNumGfxOptions,-1,iCheckHgt,true), LoadResStr("IDS_CTL_NOALPHAADD"), false);
|
||||
pCheckGfxNoAlphaAdd->SetFont(pUseFont, C4StartupFontClr, C4StartupFontClrDisabled);
|
||||
|
@ -866,6 +866,12 @@ C4StartupOptionsDlg::C4StartupOptionsDlg() : C4StartupDlg(LoadResStrNoAmp("IDS_D
|
|||
pCheckGfxNoBoxFades->SetToolTip(LoadResStr("IDS_MSG_NOCLRFADE_DESC"));
|
||||
pCheckGfxNoBoxFades->SetOnChecked(pGfxGroubleCheckCB);
|
||||
pGroupTrouble->AddElement(pCheckGfxNoBoxFades);
|
||||
// Shaders
|
||||
pShaders = new C4GUI::CheckBox(caGroupTrouble.GetGridCell(0,2,iOpt++,iNumGfxOptions,-1,iCheckHgt,true), "Shaders", false);
|
||||
pShaders->SetFont(pUseFont, C4StartupFontClr, C4StartupFontClrDisabled);
|
||||
pShaders->SetToolTip("Shaders");
|
||||
pShaders->SetOnChecked(pGfxGroubleCheckCB);
|
||||
pGroupTrouble->AddElement(pShaders);
|
||||
// manual clipping
|
||||
pCheckGfxClipManually = new C4GUI::CheckBox(caGroupTrouble.GetGridCell(0,2,iOpt++,iNumGfxOptions,-1,iCheckHgt,true), LoadResStr("IDS_CTL_MANUALCLIP"), false);
|
||||
pCheckGfxClipManually->SetFont(pUseFont, C4StartupFontClr, C4StartupFontClrDisabled);
|
||||
|
@ -903,7 +909,7 @@ C4StartupOptionsDlg::C4StartupOptionsDlg() : C4StartupDlg(LoadResStrNoAmp("IDS_D
|
|||
pGroupEffects->SetColors(C4StartupEditBorderColor, C4StartupFontClr);
|
||||
pSheetGraphics->AddElement(pGroupEffects);
|
||||
C4GUI::ComponentAligner caGroupEffects(pGroupEffects->GetClientRect(), iIndentX1, iIndentY2, true);
|
||||
iNumGfxOptions = 2; iOpt=0;
|
||||
iNumGfxOptions = 3; iOpt=0;
|
||||
// effects level slider
|
||||
C4GUI::ComponentAligner caEffectsLevel(caGroupEffects.GetGridCell(0,1,iOpt++,iNumGfxOptions), 1,0,false);
|
||||
StdStrBuf sEffectsTxt; sEffectsTxt.Copy(LoadResStr("IDS_CTL_SMOKELOW"));
|
||||
|
@ -922,6 +928,11 @@ C4StartupOptionsDlg::C4StartupOptionsDlg() : C4StartupDlg(LoadResStrNoAmp("IDS_D
|
|||
pCheck->SetToolTip(LoadResStr("IDS_MSG_FIREPARTICLES_DESC"));
|
||||
pCheck->SetFont(pUseFont, C4StartupFontClr, C4StartupFontClrDisabled);
|
||||
pGroupEffects->AddElement(pCheck);
|
||||
// high resolution landscape
|
||||
pCheck = new BoolConfig(caGroupEffects.GetGridCell(0,1,iOpt++,iNumGfxOptions,-1,iCheckHgt,true), LoadResStr("[!]High resolution landscape"), NULL, &Config.Graphics.HighResLandscape);
|
||||
pCheck->SetToolTip(LoadResStr("[!]An expensive effect."));
|
||||
pCheck->SetFont(pUseFont, C4StartupFontClr, C4StartupFontClrDisabled);
|
||||
pGroupEffects->AddElement(pCheck);
|
||||
|
||||
// --- page sound
|
||||
C4GUI::ComponentAligner caSheetSound(pSheetSound->GetClientRect(), iIndentX1, iIndentY1, true);
|
||||
|
@ -1433,6 +1444,7 @@ void C4StartupOptionsDlg::LoadGfxTroubleshoot()
|
|||
pCheckGfxNoAddBlit->SetChecked(!!(dwGfxCfg & C4GFXCFG_NOADDITIVEBLTS));
|
||||
pCheckGfxNoBoxFades->SetChecked(!!(dwGfxCfg & C4GFXCFG_NOBOXFADES));
|
||||
pCheckGfxClipManually->SetChecked(!!(dwGfxCfg & C4GFXCFG_CLIPMANUALLY));
|
||||
pShaders->SetChecked(!!DDrawCfg.Shader);
|
||||
pEdtGfxBlitOff->SetIntVal(iGfxBlitOff);
|
||||
// title of troubleshooting-box by config set
|
||||
pGroupTrouble->SetTitle(FormatString("%s: %s", LoadResStrNoAmp("IDS_CTL_TROUBLE"), fUseGL ? "OpenGL" : "DirectX").getData());
|
||||
|
@ -1448,6 +1460,7 @@ void C4StartupOptionsDlg::SaveGfxTroubleshoot()
|
|||
if (pCheckGfxNoAddBlit->GetChecked()) dwGfxCfg |= C4GFXCFG_NOADDITIVEBLTS;
|
||||
if (pCheckGfxNoBoxFades->GetChecked()) dwGfxCfg |= C4GFXCFG_NOBOXFADES;
|
||||
if (pCheckGfxClipManually->GetChecked()) dwGfxCfg |= C4GFXCFG_CLIPMANUALLY;
|
||||
DDrawCfg.Shader=pShaders->GetChecked();
|
||||
if (DDrawCfg.Windowed) dwGfxCfg |= C4GFXCFG_WINDOWED;
|
||||
pEdtGfxBlitOff->Save2Config();
|
||||
// get config set to be used
|
||||
|
|
|
@ -147,10 +147,8 @@ class CStdD3D : public CStdDDraw
|
|||
bool RestoreDeviceObjects(); // restore device dependent objects
|
||||
bool InvalidateDeviceObjects(); // free device dependent objects
|
||||
bool DeleteDeviceObjects(); // free device dependent objects
|
||||
bool StoreStateBlock();
|
||||
void SetTexture();
|
||||
void ResetTexture();
|
||||
bool RestoreStateBlock();
|
||||
bool DeviceReady() { return !!lpDevice; }
|
||||
|
||||
BOOL CreateStateBlock(IDirect3DStateBlock9 **pBlock, bool fTransparent, bool fSolid, bool fBaseTex, bool fAdditive, bool fMod2); // capture state blocks for blitting
|
||||
|
@ -160,7 +158,6 @@ class CStdD3D : public CStdDDraw
|
|||
BOOL FindDisplayMode(unsigned int iXRes, unsigned int iYRes, D3DFORMAT format, unsigned int iMonitor);
|
||||
virtual bool CreatePrimarySurfaces(BOOL Fullscreen, unsigned int iXRes, unsigned int iYRes, int iColorDepth, unsigned int iMonitor);
|
||||
bool SetOutputAdapter(unsigned int iMonitor);
|
||||
BOOL CreateDirectDraw();
|
||||
inline bool HasShaders() const { return !!pShaders[0]; }
|
||||
|
||||
|
||||
|
|
|
@ -139,6 +139,7 @@ class CPattern
|
|||
uint32_t *pAlpha;
|
||||
public:
|
||||
CPattern& operator=(const CPattern&);
|
||||
const CSurface *getSurface() const { return sfcPattern32; }
|
||||
bool PatternClr(int iX, int iY, BYTE &byClr, DWORD &dwClr, CStdPalette &rPal) const; // apply pattern to color
|
||||
bool IsNewStyle() { if (sfcPattern32) return true; }
|
||||
bool Set(class CSurface *sfcSource, int iZoom=0, bool fMonochrome=false); // set and enable pattern
|
||||
|
@ -288,8 +289,8 @@ class CStdDDraw
|
|||
void PrimaryUnlocked() { PrimaryLocked=false; }
|
||||
virtual bool PrepareRendering(SURFACE sfcToSurface) = 0; // check if/make rendering possible to given surface
|
||||
// Blit
|
||||
virtual void BlitLandscape(SURFACE sfcSource, SURFACE sfcSource2, SURFACE sfcLiquidAnimation, float fx, float fy,
|
||||
SURFACE sfcTarget, float tx, float ty, float wdt, float hgt);
|
||||
virtual void BlitLandscape(SURFACE sfcSource, float fx, float fy,
|
||||
SURFACE sfcTarget, float tx, float ty, float wdt, float hgt, const SURFACE textures[]);
|
||||
void Blit8Fast(CSurface8 * sfcSource, int fx, int fy,
|
||||
SURFACE sfcTarget, int tx, int ty, int wdt, int hgt);
|
||||
BOOL Blit(SURFACE sfcSource, float fx, float fy, float fwdt, float fhgt,
|
||||
|
@ -352,16 +353,12 @@ class CStdDDraw
|
|||
void GetZoom(ZoomData *r) { r->Zoom=Zoom; r->X=ZoomX; r->Y=ZoomY; }
|
||||
void ApplyZoom(float & X, float & Y);
|
||||
void RemoveZoom(float & X, float & Y);
|
||||
virtual bool StoreStateBlock() = 0;
|
||||
virtual void SetTexture() = 0;
|
||||
virtual void ResetTexture() = 0;
|
||||
virtual bool RestoreStateBlock() = 0;
|
||||
|
||||
// device objects
|
||||
virtual bool InitDeviceObjects() = 0; // init device dependant objects
|
||||
virtual bool RestoreDeviceObjects() = 0; // restore device dependant objects
|
||||
virtual bool InvalidateDeviceObjects() = 0; // free device dependant objects
|
||||
virtual bool DeleteDeviceObjects() = 0; // free device dependant objects
|
||||
virtual bool DeviceReady() = 0; // return whether device exists
|
||||
|
||||
int GetByteCnt() { return byByteCnt; } // return bytes per pixel
|
||||
|
@ -373,7 +370,6 @@ class CStdDDraw
|
|||
bool CreatePrimaryClipper(unsigned int iXRes, unsigned int iYRes);
|
||||
virtual bool CreatePrimarySurfaces(BOOL Fullscreen, unsigned int iXRes, unsigned int iYRes, int iColorDepth, unsigned int iMonitor) = 0;
|
||||
bool Error(const char *szMsg);
|
||||
virtual BOOL CreateDirectDraw() = 0;
|
||||
void DebugLog(const char *szMsg)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
|
|
|
@ -54,6 +54,7 @@ class CStdGLCtx
|
|||
bool PageFlip(); // present scene
|
||||
|
||||
protected:
|
||||
void SelectCommon();
|
||||
// this handles are declared as pointers to structs
|
||||
CStdWindow * pWindow; // window to draw in
|
||||
#ifdef _WIN32
|
||||
|
@ -89,6 +90,8 @@ class CStdGL : public CStdDDraw
|
|||
GLuint shaders[12];
|
||||
// vertex buffer object
|
||||
GLuint vbo;
|
||||
// texture for smooth lines
|
||||
GLuint lines_tex;
|
||||
public:
|
||||
// General
|
||||
void Clear();
|
||||
|
@ -109,9 +112,10 @@ class CStdGL : public CStdDDraw
|
|||
virtual CStdGLCtx *CreateContext(HWND hWindow, CStdApp *pApp);
|
||||
#endif
|
||||
// Blit
|
||||
void SetupTextureEnv(bool fMod2, bool landscape);
|
||||
void PerformBlt(CBltData &rBltData, CTexRef *pTex, DWORD dwModClr, bool fMod2, bool fExact);
|
||||
virtual void BlitLandscape(SURFACE sfcSource, SURFACE sfcSource2, SURFACE sfcLiquidAnimation, float fx, float fy,
|
||||
SURFACE sfcTarget, float tx, float ty, float wdt, float hgt);
|
||||
virtual void BlitLandscape(SURFACE sfcSource, float fx, float fy,
|
||||
SURFACE sfcTarget, float tx, float ty, float wdt, float hgt, const SURFACE textures[]);
|
||||
void FillBG(DWORD dwClr=0);
|
||||
// Drawing
|
||||
void DrawQuadDw(SURFACE sfcTarget, float *ipVtx, DWORD dwClr1, DWORD dwClr2, DWORD dwClr3, DWORD dwClr4);
|
||||
|
@ -121,14 +125,10 @@ class CStdGL : public CStdDDraw
|
|||
virtual bool ApplyGammaRamp(D3DGAMMARAMP &ramp, bool fForce);
|
||||
virtual bool SaveDefaultGammaRamp(CStdWindow * pWindow);
|
||||
// device objects
|
||||
bool InitDeviceObjects(); // init device dependent objects
|
||||
bool RestoreDeviceObjects(); // restore device dependent objects
|
||||
bool InvalidateDeviceObjects(); // free device dependent objects
|
||||
bool DeleteDeviceObjects(); // free device dependent objects
|
||||
bool StoreStateBlock();
|
||||
void SetTexture();
|
||||
void ResetTexture();
|
||||
bool RestoreStateBlock();
|
||||
#ifdef _WIN32
|
||||
bool DeviceReady() { return !!MainCtx.hrc; }
|
||||
#elif defined(USE_X11)
|
||||
|
@ -139,7 +139,6 @@ class CStdGL : public CStdDDraw
|
|||
|
||||
protected:
|
||||
bool CreatePrimarySurfaces(BOOL Fullscreen, unsigned int iXRes, unsigned int iYRes, int iColorDepth, unsigned int iMonitor);
|
||||
BOOL CreateDirectDraw();
|
||||
|
||||
bool CheckGLError(const char *szAtOp);
|
||||
#ifdef USE_X11
|
||||
|
|
|
@ -28,7 +28,6 @@ class CStdNoGfx : public CStdDDraw
|
|||
public:
|
||||
CStdNoGfx();
|
||||
virtual ~CStdNoGfx();
|
||||
virtual BOOL CreateDirectDraw();
|
||||
public:
|
||||
virtual bool PageFlip(RECT *pSrcRt=NULL, RECT *pDstRt=NULL, CStdWindow * pWindow = NULL) { return true; }
|
||||
virtual bool BeginScene() { return true; }
|
||||
|
@ -46,10 +45,8 @@ public:
|
|||
virtual void PerformPix(SURFACE, float, float, DWORD) { }
|
||||
virtual bool ApplyGammaRamp(D3DGAMMARAMP &, bool ) { return true; }
|
||||
virtual bool SaveDefaultGammaRamp(CStdWindow *) { return true; }
|
||||
virtual bool StoreStateBlock() { return true; }
|
||||
virtual void SetTexture() { }
|
||||
virtual void ResetTexture() { }
|
||||
virtual bool RestoreStateBlock() { return true; }
|
||||
virtual bool InitDeviceObjects() { return true; }
|
||||
virtual bool RestoreDeviceObjects() { return true; }
|
||||
virtual bool InvalidateDeviceObjects() { return true; }
|
||||
|
|
|
@ -86,12 +86,6 @@ void CStdD3D::Clear()
|
|||
|
||||
/* Direct3D initialization */
|
||||
|
||||
BOOL CStdD3D::CreateDirectDraw()
|
||||
{
|
||||
if ((lpD3D=Direct3DCreate9(D3D_SDK_VERSION))==NULL) return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool CStdD3D::PageFlip(RECT *pSrcRt, RECT *pDstRt, CStdWindow * pWindow)
|
||||
{
|
||||
// call from gfx thread only!
|
||||
|
@ -490,20 +484,20 @@ BOOL CStdD3D::FindDisplayMode(unsigned int iXRes, unsigned int iYRes, D3DFORMAT
|
|||
|
||||
bool CStdD3D::SetOutputAdapter(unsigned int iMonitor)
|
||||
{
|
||||
// set var
|
||||
//pApp->Monitor = iMonitor;
|
||||
// get associated monitor rect
|
||||
HMONITOR hMon = lpD3D->GetAdapterMonitor(iMonitor);
|
||||
if (!hMon) return false;
|
||||
if (!hMon) return Error("GetAdapterMonitor error");
|
||||
MONITORINFO nfo; ZeroMemory(&nfo, sizeof(nfo));
|
||||
nfo.cbSize = sizeof(MONITORINFO);
|
||||
if (!GetMonitorInfo(hMon, &nfo)) return false;
|
||||
//pApp->MonitorRect = nfo.rcMonitor;
|
||||
if (!GetMonitorInfo(hMon, &nfo)) return Error("GetMonitorInfo error");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CStdD3D::CreatePrimarySurfaces(BOOL Fullscreen, unsigned int iXRes, unsigned int iYRes, int iColorDepth, unsigned int iMonitor)
|
||||
{
|
||||
DebugLog("Init DX");
|
||||
DebugLog(" Create Direct3D9...");
|
||||
if ((lpD3D=Direct3DCreate9(D3D_SDK_VERSION))==NULL) return Error(" Direct3DCreate9 failure.");
|
||||
// set monitor info (Monitor-var and target rect)
|
||||
DebugLog(" SetOutput adapter...");
|
||||
if (!SetOutputAdapter(iMonitor))
|
||||
|
@ -519,6 +513,7 @@ bool CStdD3D::CreatePrimarySurfaces(BOOL Fullscreen, unsigned int iXRes, unsigne
|
|||
|
||||
HRESULT hr;
|
||||
HWND hWindow = pApp->pWindow->hWindow;
|
||||
DebugLog(" Create Device...");
|
||||
if (Fullscreen)
|
||||
{
|
||||
// fullscreen mode
|
||||
|
@ -587,15 +582,15 @@ bool CStdD3D::CreatePrimarySurfaces(BOOL Fullscreen, unsigned int iXRes, unsigne
|
|||
}
|
||||
switch (hr)
|
||||
{
|
||||
case D3DERR_INVALIDCALL: return Error(" CreateDevice: D3DERR_INVALIDCALL");
|
||||
case D3DERR_NOTAVAILABLE: return Error(" CreateDevice: D3DERR_NOTAVAILABLE");
|
||||
case D3DERR_OUTOFVIDEOMEMORY: return Error(" CreateDevice: D3DERR_OUTOFVIDEOMEMORY");
|
||||
case D3DERR_DRIVERINTERNALERROR: return Error(" CreateDevice: D3DERR_DRIVERINTERNALERROR");
|
||||
case D3DERR_INVALIDCALL: return Error("CreateDevice: D3DERR_INVALIDCALL");
|
||||
case D3DERR_NOTAVAILABLE: return Error("CreateDevice: D3DERR_NOTAVAILABLE");
|
||||
case D3DERR_OUTOFVIDEOMEMORY: return Error("CreateDevice: D3DERR_OUTOFVIDEOMEMORY");
|
||||
case D3DERR_DRIVERINTERNALERROR: return Error("CreateDevice: D3DERR_DRIVERINTERNALERROR");
|
||||
case D3D_OK: break;
|
||||
default: return Error(" CreateDevice: unknown error");
|
||||
default: return Error("CreateDevice: unknown error");
|
||||
}
|
||||
// device successfully created?
|
||||
if (!lpDevice) return FALSE;
|
||||
if (!lpDevice) return Error("CreateDevice: unreported error");
|
||||
// store color depth
|
||||
byByteCnt=iColorDepth/8;
|
||||
PrimarySrfcFormat=d3dpp.BackBufferFormat;
|
||||
|
@ -616,7 +611,7 @@ bool CStdD3D::CreatePrimarySurfaces(BOOL Fullscreen, unsigned int iXRes, unsigne
|
|||
return FALSE;
|
||||
}
|
||||
// update monitor rect by new screen size
|
||||
if (!SetOutputAdapter(iMonitor)) return FALSE;
|
||||
if (!SetOutputAdapter(iMonitor)) return false;
|
||||
// success!
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -1181,15 +1176,6 @@ BOOL CStdD3D::CreateStateBlock(IDirect3DStateBlock9 **pBlock, bool fTransparent,
|
|||
return lpDevice->EndStateBlock(pBlock) == D3D_OK;
|
||||
}
|
||||
|
||||
bool CStdD3D::StoreStateBlock()
|
||||
{
|
||||
// FIXME: saving the current state is an expensive operation in D3D9
|
||||
return false;
|
||||
SafeRelease(pSavedState);
|
||||
if (lpDevice) lpDevice->CreateStateBlock(D3DSBT_ALL, &pSavedState);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CStdD3D::SetTexture()
|
||||
{
|
||||
}
|
||||
|
@ -1199,15 +1185,6 @@ void CStdD3D::ResetTexture()
|
|||
if (Active) lpDevice->SetTexture(0, NULL);
|
||||
}
|
||||
|
||||
bool CStdD3D::RestoreStateBlock()
|
||||
{
|
||||
// FIXME: saving the current state is an expensive operation in D3D9
|
||||
return false;
|
||||
assert(pSavedState);
|
||||
if (lpDevice) pSavedState->Apply();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CStdD3D::ApplyGammaRamp(D3DGAMMARAMP &ramp, bool fForce)
|
||||
{
|
||||
if (!lpDevice || (!Active && !fForce)) return false;
|
||||
|
|
|
@ -832,8 +832,8 @@ bool CStdDDraw::ClipPoly(CBltData &rBltData)
|
|||
return true;
|
||||
}
|
||||
|
||||
void CStdDDraw::BlitLandscape(SURFACE sfcSource, SURFACE sfcSource2, SURFACE sfcSource3, float fx, float fy,
|
||||
SURFACE sfcTarget, float tx, float ty, float wdt, float hgt)
|
||||
void CStdDDraw::BlitLandscape(SURFACE sfcSource, float fx, float fy,
|
||||
SURFACE sfcTarget, float tx, float ty, float wdt, float hgt, const SURFACE textures[])
|
||||
{
|
||||
Blit(sfcSource, fx, fy, wdt, hgt, sfcTarget, tx, ty, wdt, hgt, FALSE);
|
||||
}
|
||||
|
@ -953,8 +953,6 @@ BOOL CStdDDraw::Blit(SURFACE sfcSource, float fx, float fy, float fwdt, float fh
|
|||
CBltData BltData;
|
||||
// pass down pTransform
|
||||
BltData.pTransform=pTransform;
|
||||
// store current state
|
||||
StoreStateBlock();
|
||||
// blit with basesfc?
|
||||
bool fBaseSfc=false;
|
||||
if (sfcSource->pMainSfc) if (sfcSource->pMainSfc->ppTex) fBaseSfc=true;
|
||||
|
@ -968,8 +966,9 @@ BOOL CStdDDraw::Blit(SURFACE sfcSource, float fx, float fy, float fwdt, float fh
|
|||
// calc stretch regarding texture size and indent
|
||||
float scaleX2 = scaleX * iTexSize;
|
||||
float scaleY2 = scaleY * iTexSize;
|
||||
// blit from all these textures
|
||||
// Enable textures
|
||||
SetTexture();
|
||||
// blit from all these textures
|
||||
for (int iY=iTexY; iY<iTexY2; ++iY)
|
||||
{
|
||||
for (int iX=iTexX; iX<iTexX2; ++iX)
|
||||
|
@ -1044,8 +1043,6 @@ BOOL CStdDDraw::Blit(SURFACE sfcSource, float fx, float fy, float fwdt, float fh
|
|||
}
|
||||
// reset texture
|
||||
ResetTexture();
|
||||
// restore state
|
||||
RestoreStateBlock();
|
||||
// success
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -1691,16 +1688,8 @@ bool CStdDDraw::Init(CStdApp * pApp, BOOL Fullscreen, BOOL fUsePageLock, unsigne
|
|||
// store default gamma
|
||||
SaveDefaultGammaRamp(pApp->pWindow);
|
||||
|
||||
DebugLog("Init DX");
|
||||
DebugLog(" Create DirectDraw...");
|
||||
|
||||
if (!CreateDirectDraw())
|
||||
return Error(" CreateDirectDraw failure.");
|
||||
|
||||
DebugLog(" Create Device...");
|
||||
|
||||
if (!CreatePrimarySurfaces(Fullscreen, iXRes, iYRes, iBitDepth, iMonitor))
|
||||
return Error(" CreateDevice failure.");
|
||||
return false;
|
||||
|
||||
DebugLog(" Create Clipper");
|
||||
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
* OpenClonk, http://www.openclonk.org
|
||||
*
|
||||
* Copyright (c) 2002, 2005-2006 Sven Eberhardt
|
||||
* Copyright (c) 2005-2008 Günther Brammer
|
||||
* Copyright (c) 2005-2009 Günther Brammer <gbrammer@gmx.de>
|
||||
* Copyright (c) 2007 Julian Raschke
|
||||
* Copyright (c) 2008 Matthes Bender
|
||||
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de
|
||||
* Copyright (c) 2009 Carl-Philip Hänsch <c-p.haensch@vr-web.de>
|
||||
*
|
||||
* Portions might be copyrighted by other authors who have contributed
|
||||
* to OpenClonk.
|
||||
|
@ -69,7 +70,15 @@ void CStdGL::Clear()
|
|||
#endif
|
||||
NoPrimaryClipper();
|
||||
if (pTexMgr) pTexMgr->IntUnlock();
|
||||
DeleteDeviceObjects();
|
||||
InvalidateDeviceObjects();
|
||||
NoPrimaryClipper();
|
||||
// del main surfaces
|
||||
if (lpPrimary) delete lpPrimary;
|
||||
lpPrimary = lpBack = NULL;
|
||||
RenderTarget = NULL;
|
||||
if (lines_tex) { glDeleteTextures(1, &lines_tex); lines_tex = 0; }
|
||||
// clear context
|
||||
if (pCurrCtx) pCurrCtx->Deselect();
|
||||
MainCtx.Clear();
|
||||
pCurrCtx=NULL;
|
||||
#ifndef USE_SDL_MAINLOOP
|
||||
|
@ -148,6 +157,46 @@ bool CStdGL::PrepareRendering(SURFACE sfcToSurface)
|
|||
return true;
|
||||
}
|
||||
|
||||
void CStdGL::SetupTextureEnv(bool fMod2, bool landscape)
|
||||
{
|
||||
if (shaders[0])
|
||||
{
|
||||
GLuint s = landscape ? 2 : (fMod2 ? 1 : 0);
|
||||
if (Saturation < 255)
|
||||
{
|
||||
s += 3;
|
||||
}
|
||||
if (fUseClrModMap)
|
||||
{
|
||||
s += 6;
|
||||
}
|
||||
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shaders[s]);
|
||||
if (Saturation < 255)
|
||||
{
|
||||
GLfloat bla[4] = { Saturation / 255.0f, Saturation / 255.0f, Saturation / 255.0f, 1.0f };
|
||||
glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 0, bla);
|
||||
}
|
||||
}
|
||||
// texture environment
|
||||
else
|
||||
{
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, fMod2 ? GL_ADD_SIGNED : GL_MODULATE);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, fMod2 ? 2.0f : 1.0f);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_ADD);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PRIMARY_COLOR);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
|
||||
}
|
||||
// set modes
|
||||
glShadeModel((fUseClrModMap && !shaders[0] && !DDrawCfg.NoBoxFades) ? GL_SMOOTH : GL_FLAT);
|
||||
}
|
||||
|
||||
void CStdGL::PerformBlt(CBltData &rBltData, CTexRef *pTex, DWORD dwModClr, bool fMod2, bool fExact)
|
||||
{
|
||||
// clipping
|
||||
|
@ -178,49 +227,8 @@ void CStdGL::PerformBlt(CBltData &rBltData, CTexRef *pTex, DWORD dwModClr, bool
|
|||
DwTo4UB(dwModClr, rBltData.vtVtx[i].color);
|
||||
}
|
||||
// reset MOD2 for completely black modulations
|
||||
if (fMod2 && !fAnyModNotBlack) fMod2 = 0;
|
||||
if (shaders[0])
|
||||
{
|
||||
glEnable(GL_FRAGMENT_PROGRAM_ARB);
|
||||
GLuint s = fMod2 ? 1 : 0;
|
||||
if (Saturation < 255)
|
||||
{
|
||||
s += 3;
|
||||
}
|
||||
if (fUseClrModMap)
|
||||
{
|
||||
s += 6;
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, (*pClrModMap->GetSurface()->ppTex)->texName);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shaders[s]);
|
||||
if (Saturation < 255)
|
||||
{
|
||||
GLfloat bla[4] = { Saturation / 255.0f, Saturation / 255.0f, Saturation / 255.0f, 1.0f };
|
||||
glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 0, bla);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, fMod2 ? GL_ADD_SIGNED : GL_MODULATE);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, fMod2 ? 2.0f : 1.0f);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_ADD);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PRIMARY_COLOR);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
|
||||
}
|
||||
// set texture+modes
|
||||
glShadeModel((fUseClrModMap && !DDrawCfg.NoBoxFades) ? GL_SMOOTH : GL_FLAT);
|
||||
fMod2 = fMod2 && fAnyModNotBlack;
|
||||
SetupTextureEnv(fMod2, false);
|
||||
glBindTexture(GL_TEXTURE_2D, pTex->texName);
|
||||
if (!fExact && !DDrawCfg.PointFiltering)
|
||||
{
|
||||
|
@ -233,7 +241,7 @@ void CStdGL::PerformBlt(CBltData &rBltData, CTexRef *pTex, DWORD dwModClr, bool
|
|||
matrix[0]=rBltData.TexPos.mat[0]; matrix[1]=rBltData.TexPos.mat[3]; matrix[2]=0; matrix[3]=rBltData.TexPos.mat[6];
|
||||
matrix[4]=rBltData.TexPos.mat[1]; matrix[5]=rBltData.TexPos.mat[4]; matrix[6]=0; matrix[7]=rBltData.TexPos.mat[7];
|
||||
matrix[8]=0; matrix[9]=0; matrix[10]=1; matrix[11]=0;
|
||||
matrix[12]=rBltData.TexPos.mat[2]; matrix[13]=rBltData.TexPos.mat[5]; matrix[14]=0; matrix[15]=rBltData.TexPos.mat[8];
|
||||
matrix[12]=rBltData.TexPos.mat[2]; matrix[13]=rBltData.TexPos.mat[5]; matrix[14]=0; matrix[15]=rBltData.TexPos.mat[8];
|
||||
glLoadMatrixf(matrix);
|
||||
|
||||
if (shaders[0] && fUseClrModMap)
|
||||
|
@ -292,13 +300,6 @@ void CStdGL::PerformBlt(CBltData &rBltData, CTexRef *pTex, DWORD dwModClr, bool
|
|||
}
|
||||
glDrawArrays(GL_POLYGON, 0, rBltData.byNumVertices);
|
||||
glLoadIdentity();
|
||||
if (shaders[0])
|
||||
{
|
||||
glDisable(GL_FRAGMENT_PROGRAM_ARB);
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
if (!fExact && !DDrawCfg.PointFiltering)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
@ -306,10 +307,10 @@ void CStdGL::PerformBlt(CBltData &rBltData, CTexRef *pTex, DWORD dwModClr, bool
|
|||
}
|
||||
}
|
||||
|
||||
void CStdGL::BlitLandscape(SURFACE sfcSource, SURFACE sfcSource2, SURFACE sfcLiquidAnimation, float fx, float fy,
|
||||
SURFACE sfcTarget, float tx, float ty, float wdt, float hgt)
|
||||
void CStdGL::BlitLandscape(SURFACE sfcSource, float fx, float fy,
|
||||
SURFACE sfcTarget, float tx, float ty, float wdt, float hgt, const SURFACE mattextures[])
|
||||
{
|
||||
Blit(sfcSource, fx, fy, wdt, hgt, sfcTarget, tx, ty, wdt, hgt);return;
|
||||
//Blit(sfcSource, fx, fy, wdt, hgt, sfcTarget, tx, ty, wdt, hgt);return;
|
||||
// safety
|
||||
if (!sfcSource || !sfcTarget || !wdt || !hgt) return;
|
||||
assert(sfcTarget->IsRenderTarget());
|
||||
|
@ -377,83 +378,14 @@ void CStdGL::BlitLandscape(SURFACE sfcSource, SURFACE sfcSource2, SURFACE sfcLiq
|
|||
int iTexY2=Min((int)(fy+hgt-1)/iTexSize +1, sfcSource->iTexY);
|
||||
// blit from all these textures
|
||||
SetTexture();
|
||||
if (sfcSource2)
|
||||
if (mattextures)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, (*sfcLiquidAnimation->ppTex)->texName);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
DWORD dwModMask = 0;
|
||||
if (shaders[0])
|
||||
{
|
||||
glEnable(GL_FRAGMENT_PROGRAM_ARB);
|
||||
GLuint s = sfcSource2 ? 2 : 0;
|
||||
if (Saturation < 255)
|
||||
{
|
||||
s += 3;
|
||||
}
|
||||
if (fUseClrModMap)
|
||||
{
|
||||
s += 6;
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, (*pClrModMap->GetSurface()->ppTex)->texName);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shaders[s]);
|
||||
if (Saturation < 255)
|
||||
{
|
||||
GLfloat bla[4] = { Saturation / 255.0f, Saturation / 255.0f, Saturation / 255.0f, 1.0f };
|
||||
glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 0, bla);
|
||||
}
|
||||
if (sfcSource2)
|
||||
{
|
||||
static GLfloat bla[4] = { -0.6f/3, 0.0f, 0.6f/3, 0.0f };
|
||||
bla[0] += 0.05f; bla[1] += 0.05f; bla[2] += 0.05f;
|
||||
GLfloat mod[4];
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
if (bla[i] > 0.9f) bla[i] = -0.3f;
|
||||
mod[i] = (bla[i] > 0.3f ? 0.6f - bla[i] : bla[i]) / 3.0f;
|
||||
}
|
||||
mod[3] = 0;
|
||||
glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 1, mod);
|
||||
}
|
||||
dwModMask = 0;
|
||||
}
|
||||
// texture environment
|
||||
else
|
||||
{
|
||||
if (DDrawCfg.NoAlphaAdd)
|
||||
{
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1.0f);
|
||||
dwModMask = 0xff000000;
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1.0f);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_ADD);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PRIMARY_COLOR);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
|
||||
dwModMask = 0;
|
||||
}
|
||||
}
|
||||
// set texture+modes
|
||||
glShadeModel((fUseClrModMap && !DDrawCfg.NoBoxFades) ? GL_SMOOTH : GL_FLAT);
|
||||
SetupTextureEnv(false, mattextures);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_TEXTURE);
|
||||
|
@ -465,25 +397,18 @@ void CStdGL::BlitLandscape(SURFACE sfcSource, SURFACE sfcSource2, SURFACE sfcLiq
|
|||
// blit
|
||||
DWORD dwModClr = BlitModulated ? BlitModulateClr : 0xffffff;
|
||||
|
||||
if (sfcSource2)
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
CTexRef *pTex = *(sfcSource->ppTex + iY * sfcSource->iTexX + iX);
|
||||
glBindTexture(GL_TEXTURE_2D, pTex->texName);
|
||||
if (Zoom != 1.0 && !DDrawCfg.PointFiltering)
|
||||
if (!mattextures && Zoom != 1.0)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
}
|
||||
if (sfcSource2)
|
||||
else
|
||||
{
|
||||
CTexRef *pTex = *(sfcSource2->ppTex + iY * sfcSource2->iTexX + iX);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, pTex->texName);
|
||||
if (Zoom != 1.0 && !DDrawCfg.PointFiltering)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
}
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
}
|
||||
|
||||
// get current blitting offset in texture (beforing any last-tex-size-changes)
|
||||
|
@ -521,10 +446,22 @@ void CStdGL::BlitLandscape(SURFACE sfcSource, SURFACE sfcSource2, SURFACE sfcLiq
|
|||
|
||||
// color modulation
|
||||
// global modulation map
|
||||
int i;
|
||||
if (fUseClrModMap && dwModClr)
|
||||
if (shaders[0] && fUseClrModMap)
|
||||
{
|
||||
for (i=0; i<4; ++i)
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
glLoadIdentity();
|
||||
CSurface * pSurface = pClrModMap->GetSurface();
|
||||
glScalef(1.0f/(pClrModMap->GetResolutionX()*(*pSurface->ppTex)->iSize), 1.0f/(pClrModMap->GetResolutionY()*(*pSurface->ppTex)->iSize), 1.0f);
|
||||
glTranslatef(float(-pClrModMap->OffX), float(-pClrModMap->OffY), 0.0f);
|
||||
|
||||
glClientActiveTexture(GL_TEXTURE3);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(CBltVertex), &Vtx[0].ftx);
|
||||
glClientActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
if (!shaders[0] && fUseClrModMap && dwModClr)
|
||||
{
|
||||
for (int i=0; i<4; ++i)
|
||||
{
|
||||
DWORD c = pClrModMap->GetModAt(int(Vtx[i].ftx), int(Vtx[i].fty));
|
||||
ModulateClr(c, dwModClr);
|
||||
|
@ -533,10 +470,10 @@ void CStdGL::BlitLandscape(SURFACE sfcSource, SURFACE sfcSource2, SURFACE sfcLiq
|
|||
}
|
||||
else
|
||||
{
|
||||
for (i=0; i<4; ++i)
|
||||
for (int i=0; i<4; ++i)
|
||||
DwTo4UB(dwModClr | dwModMask, Vtx[i].color);
|
||||
}
|
||||
for (i=0; i<4; ++i)
|
||||
for (int i=0; i<4; ++i)
|
||||
{
|
||||
Vtx[i].tx /= iTexSize;
|
||||
Vtx[i].ty /= iTexSize;
|
||||
|
@ -544,35 +481,50 @@ void CStdGL::BlitLandscape(SURFACE sfcSource, SURFACE sfcSource2, SURFACE sfcLiq
|
|||
Vtx[i].fty += DDrawCfg.fBlitOff;
|
||||
Vtx[i].ftz = 0;
|
||||
}
|
||||
if(mattextures)
|
||||
{
|
||||
GLfloat shaderparam[4];
|
||||
for (int cnt=1;cnt<127;cnt++)
|
||||
{
|
||||
if(mattextures[cnt])
|
||||
{
|
||||
shaderparam[0]=static_cast<GLfloat>(cnt)/255.0f;
|
||||
glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 1, shaderparam);
|
||||
//Bind Mat Texture
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, (*(mattextures[cnt]->ppTex))->texName);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
glInterleavedArrays(GL_T2F_C4UB_V3F, sizeof(CBltVertex), Vtx);
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
glInterleavedArrays(GL_T2F_C4UB_V3F, sizeof(CBltVertex), Vtx);
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
}
|
||||
|
||||
glInterleavedArrays(GL_T2F_C4UB_V3F, sizeof(CBltVertex), Vtx);
|
||||
glDrawArrays(GL_POLYGON, 0, 4);
|
||||
}
|
||||
}
|
||||
if (shaders[0])
|
||||
{
|
||||
glDisable(GL_FRAGMENT_PROGRAM_ARB);
|
||||
}
|
||||
if (sfcSource2)
|
||||
if (mattextures)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
// reset texture
|
||||
ResetTexture();
|
||||
}
|
||||
|
||||
BOOL CStdGL::CreateDirectDraw()
|
||||
{
|
||||
Log(" Using OpenGL...");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CStdGLCtx *CStdGL::CreateContext(CStdWindow * pWindow, CStdApp *pApp)
|
||||
{
|
||||
DebugLog(" gl: Create Context...");
|
||||
// safety
|
||||
if (!pWindow) return NULL;
|
||||
// create it
|
||||
|
@ -581,8 +533,6 @@ CStdGLCtx *CStdGL::CreateContext(CStdWindow * pWindow, CStdApp *pApp)
|
|||
{
|
||||
delete pCtx; Error(" gl: Error creating secondary context!"); return NULL;
|
||||
}
|
||||
// reselect current context
|
||||
//if (pCurrCtx) pCurrCtx->Select(); else pCurrCtx=pCtx;
|
||||
// done
|
||||
return pCtx;
|
||||
}
|
||||
|
@ -598,8 +548,6 @@ CStdGLCtx *CStdGL::CreateContext(HWND hWindow, CStdApp *pApp)
|
|||
{
|
||||
delete pCtx; Error(" gl: Error creating secondary context!"); return NULL;
|
||||
}
|
||||
// reselect current context
|
||||
//if (pCurrCtx) pCurrCtx->Select(); else pCurrCtx=pCtx;
|
||||
// done
|
||||
return pCtx;
|
||||
}
|
||||
|
@ -610,6 +558,7 @@ bool CStdGL::CreatePrimarySurfaces(BOOL Playermode, unsigned int iXRes, unsigned
|
|||
//remember fullscreen setting
|
||||
fFullscreen = Playermode && !DDrawCfg.Windowed;
|
||||
|
||||
DebugLog(" gl: SetVideoMode...");
|
||||
// Set window size only in playermode
|
||||
if (Playermode)
|
||||
{
|
||||
|
@ -635,10 +584,30 @@ bool CStdGL::CreatePrimarySurfaces(BOOL Playermode, unsigned int iXRes, unsigned
|
|||
lpPrimary->byBytesPP=byByteCnt;
|
||||
|
||||
// create+select gl context
|
||||
DebugLog(" gl: Create Main Context...");
|
||||
if (!MainCtx.Init(pApp->pWindow, pApp)) return Error(" gl: Error initializing context");
|
||||
|
||||
// done, init device stuff
|
||||
return InitDeviceObjects();
|
||||
// BGRA Pixel Formats, Multitexturing, Texture Combine Environment Modes
|
||||
if (!GLEW_VERSION_1_3)
|
||||
{
|
||||
return Error(" gl: OpenGL Version 1.3 or higher required.");
|
||||
}
|
||||
MaxTexSize = 64;
|
||||
GLint s = 0;
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &s);
|
||||
if (s>0) MaxTexSize = s;
|
||||
|
||||
// lines texture
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glGenTextures(1, &lines_tex);
|
||||
glBindTexture(GL_TEXTURE_2D, lines_tex);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
const char * linedata = byByteCnt == 2 ? "\xff\xff\xff\xf0" : "\xff\xff\xff\xff\xff\xff\xff\x00";
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, 4, 1, 2, 0, GL_BGRA, byByteCnt == 2 ? GL_UNSIGNED_SHORT_4_4_4_4_REV : GL_UNSIGNED_INT_8_8_8_8_REV, linedata);
|
||||
return RestoreDeviceObjects();
|
||||
}
|
||||
|
||||
void CStdGL::DrawQuadDw(SURFACE sfcTarget, float *ipVtx, DWORD dwClr1, DWORD dwClr2, DWORD dwClr3, DWORD dwClr4)
|
||||
|
@ -679,6 +648,7 @@ void CStdGL::DrawQuadDw(SURFACE sfcTarget, float *ipVtx, DWORD dwClr1, DWORD dwC
|
|||
glColorPointer(4,GL_UNSIGNED_BYTE,0,colors);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glDrawArrays(GL_POLYGON, 0, 4);
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
glShadeModel(GL_FLAT);
|
||||
}
|
||||
|
||||
|
@ -689,28 +659,64 @@ void CStdGL::PerformLine(SURFACE sfcTarget, float x1, float y1, float x2, float
|
|||
{
|
||||
// prepare rendering to target
|
||||
if (!PrepareRendering(sfcTarget)) return;
|
||||
// set blitting state
|
||||
int iAdditive = dwBlitMode & C4GFXBLIT_ADDITIVE;
|
||||
// use a different blendfunc here, because GL_LINE_SMOOTH expects this one
|
||||
glBlendFunc(GL_SRC_ALPHA, iAdditive ? GL_ONE : GL_ONE_MINUS_SRC_ALPHA);
|
||||
// draw one line
|
||||
glBegin(GL_LINES);
|
||||
SetTexture();
|
||||
SetupTextureEnv(false, false);
|
||||
float offx = y1 - y2;
|
||||
float offy = x2 - x1;
|
||||
float l = sqrtf(offx * offx + offy * offy);
|
||||
// avoid division by zero
|
||||
l += 0.000000005f;
|
||||
offx /= l; offx *= Zoom;
|
||||
offy /= l; offy *= Zoom;
|
||||
CBltVertex vtx[4];
|
||||
vtx[0].ftx = x1 + offx; vtx[0].fty = y1 + offy; vtx[0].ftz = 0;
|
||||
vtx[1].ftx = x1 - offx; vtx[1].fty = y1 - offy; vtx[1].ftz = 0;
|
||||
vtx[2].ftx = x2 - offx; vtx[2].fty = y2 - offy; vtx[2].ftz = 0;
|
||||
vtx[3].ftx = x2 + offx; vtx[3].fty = y2 + offy; vtx[3].ftz = 0;
|
||||
// global clr modulation map
|
||||
DWORD dwClr1 = dwClr;
|
||||
glMatrixMode(GL_TEXTURE);
|
||||
glLoadIdentity();
|
||||
if (fUseClrModMap)
|
||||
{
|
||||
ModulateClr(dwClr1, pClrModMap->GetModAt((int)x1, (int)y1));
|
||||
if (shaders[0])
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
glLoadIdentity();
|
||||
CSurface * pSurface = pClrModMap->GetSurface();
|
||||
glScalef(1.0f/(pClrModMap->GetResolutionX()*(*pSurface->ppTex)->iSize), 1.0f/(pClrModMap->GetResolutionY()*(*pSurface->ppTex)->iSize), 1.0f);
|
||||
glTranslatef(float(-pClrModMap->OffX), float(-pClrModMap->OffY), 0.0f);
|
||||
|
||||
glClientActiveTexture(GL_TEXTURE3);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(CBltVertex), &vtx[0].ftx);
|
||||
glClientActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ModulateClr(dwClr1, pClrModMap->GetModAt(lrintf(x1), lrintf(y1)));
|
||||
ModulateClr(dwClr, pClrModMap->GetModAt(lrintf(x2), lrintf(y2)));
|
||||
}
|
||||
}
|
||||
// convert from clonk-alpha to GL_LINE_SMOOTH alpha
|
||||
glColorDw(InvertRGBAAlpha(dwClr1));
|
||||
glVertex2f(x1 + 0.5f, y1 + 0.5f);
|
||||
if (fUseClrModMap)
|
||||
{
|
||||
ModulateClr(dwClr, pClrModMap->GetModAt((int)x2, (int)y2));
|
||||
glColorDw(InvertRGBAAlpha(dwClr));
|
||||
}
|
||||
glVertex2f(x2 + 0.5f, y2 + 0.5f);
|
||||
glEnd();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
DwTo4UB(dwClr1,vtx[0].color);
|
||||
DwTo4UB(dwClr1,vtx[1].color);
|
||||
DwTo4UB(dwClr,vtx[2].color);
|
||||
DwTo4UB(dwClr,vtx[3].color);
|
||||
vtx[0].tx = 0; vtx[0].ty = 0;
|
||||
vtx[1].tx = 0; vtx[1].ty = 2;
|
||||
vtx[2].tx = 1; vtx[2].ty = 2;
|
||||
vtx[3].tx = 1; vtx[3].ty = 0;
|
||||
// draw two triangles
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, lines_tex);
|
||||
glInterleavedArrays(GL_T2F_C4UB_V3F, sizeof(CBltVertex), vtx);
|
||||
glDrawArrays(GL_POLYGON, 0, 4);
|
||||
glClientActiveTexture(GL_TEXTURE3);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glClientActiveTexture(GL_TEXTURE0);
|
||||
ResetTexture();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -743,21 +749,6 @@ void CStdGL::PerformPix(SURFACE sfcTarget, float tx, float ty, DWORD dwClr)
|
|||
}
|
||||
}
|
||||
|
||||
bool CStdGL::InitDeviceObjects()
|
||||
{
|
||||
// BGRA Pixel Formats, Multitexturing, Texture Combine Environment Modes
|
||||
if (!GLEW_VERSION_1_3)
|
||||
{
|
||||
Log(" gl: OpenGL Version 1.3 or higher required.");
|
||||
return false;
|
||||
}
|
||||
MaxTexSize = 64;
|
||||
GLint s = 0;
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &s);
|
||||
if (s>0) MaxTexSize = s;
|
||||
return RestoreDeviceObjects();
|
||||
}
|
||||
|
||||
static void DefineShaderARB(const char * p, GLuint & s)
|
||||
{
|
||||
glBindProgramARB (GL_FRAGMENT_PROGRAM_ARB, s);
|
||||
|
@ -776,22 +767,20 @@ bool CStdGL::RestoreDeviceObjects()
|
|||
if (!lpPrimary) return false;
|
||||
// delete any previous objects
|
||||
InvalidateDeviceObjects();
|
||||
bool fSuccess=true;
|
||||
// restore primary/back
|
||||
RenderTarget=lpPrimary;
|
||||
//lpPrimary->AttachSfc(NULL);
|
||||
lpPrimary->byBytesPP=byByteCnt;
|
||||
|
||||
// set states
|
||||
fSuccess = pCurrCtx ? (pCurrCtx->Select()) : MainCtx.Select();
|
||||
// activate if successful
|
||||
Active=fSuccess;
|
||||
Active = pCurrCtx ? (pCurrCtx->Select()) : MainCtx.Select();
|
||||
// restore gamma if active
|
||||
if (Active)
|
||||
EnableGamma();
|
||||
// reset blit states
|
||||
dwBlitMode = 0;
|
||||
|
||||
// Vertex Buffer Objects crash some versions of the free radeon driver. TODO: provide an option for them
|
||||
if (0 && GLEW_ARB_vertex_buffer_object)
|
||||
{
|
||||
glGenBuffersARB(1, &vbo);
|
||||
|
@ -822,17 +811,21 @@ bool CStdGL::RestoreDeviceObjects()
|
|||
"TEMP grey;\n"
|
||||
"DP3 grey, tmp, { 0.299, 0.587, 0.114, 1.0 };\n"
|
||||
"LRP tmp.rgb, program.local[0], tmp, grey;\n";
|
||||
const char * liquid =
|
||||
"TEMP mask;\n"
|
||||
"TEMP liquid;\n"
|
||||
"TXP mask, fragment.texcoord, texture[1], 2D;\n"
|
||||
"TXP liquid, fragment.texcoord, texture[2], 2D;\n"
|
||||
// animation
|
||||
"SUB liquid.rgb, liquid, {0.5, 0.5, 0.5, 0};\n"
|
||||
"DP3 liquid.rgb, liquid, program.local[1];\n"
|
||||
//"MAD_SAT tmp.rgb, mask.aaa, liquid, tmp;\n"
|
||||
"MUL liquid.rgb, mask.aaaa, liquid;\n"
|
||||
"ADD_SAT tmp.rgb, liquid, tmp;\n";
|
||||
const char * landscape =
|
||||
"TEMP col;\n"
|
||||
"MOV col.x, program.local[1].x;\n" //Load color to indentify
|
||||
"ADD col.y, col.x, 0.001;\n"
|
||||
"SUB col.z, col.x, 0.001;\n" //epsilon-range
|
||||
"SGE tmp.r, tmp.b, 0.5015;\n" //Tunnel?
|
||||
"MAD tmp.r, tmp.r, -0.5019, tmp.b;\n"
|
||||
"SGE col.z, tmp.r, col.z;\n" //mat identified?
|
||||
"SLT col.y, tmp.r, col.y;\n"
|
||||
"TEMP coo;\n"
|
||||
"MOV coo, fragment.texcoord;\n"
|
||||
"MUL coo.xy, coo, 3.0;\n"
|
||||
"TXP tmp, coo, texture[1], 2D;\n"
|
||||
"MUL tmp.a, col.y, col.z;\n"
|
||||
"SUB tmp.a, 1.0, tmp.a;\n";
|
||||
const char * fow =
|
||||
"TEMP fow;\n"
|
||||
// sample the texture
|
||||
|
@ -841,18 +834,18 @@ bool CStdGL::RestoreDeviceObjects()
|
|||
const char * end =
|
||||
"MOV result.color, tmp;\n"
|
||||
"END\n";
|
||||
DefineShaderARB(FormatString("%s%s%s", preface, alpha_add, end).getData(), shaders[0]);
|
||||
DefineShaderARB(FormatString("%s%s%s", preface, funny_add, end).getData(), shaders[1]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s", preface, liquid, alpha_add, end).getData(), shaders[2]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s", preface, alpha_add, grey, end).getData(), shaders[3]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s", preface, funny_add, grey, end).getData(), shaders[4]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s%s", preface, liquid, alpha_add, grey, end).getData(), shaders[5]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s", preface, alpha_add, fow, end).getData(), shaders[6]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s", preface, funny_add, fow, end).getData(), shaders[7]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s%s", preface, liquid, alpha_add, fow, end).getData(), shaders[8]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s%s", preface, alpha_add, grey, fow, end).getData(), shaders[9]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s%s", preface, funny_add, grey, fow, end).getData(), shaders[10]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s%s%s", preface, liquid, alpha_add, grey, fow, end).getData(), shaders[11]);
|
||||
DefineShaderARB(FormatString("%s%s%s", preface, alpha_add, end).getData(), shaders[0]);
|
||||
DefineShaderARB(FormatString("%s%s%s", preface, funny_add, end).getData(), shaders[1]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s", preface, landscape, alpha_add, end).getData(), shaders[2]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s", preface, alpha_add, grey, end).getData(), shaders[3]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s", preface, funny_add, grey, end).getData(), shaders[4]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s%s", preface, landscape, alpha_add, grey, end).getData(), shaders[5]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s", preface, alpha_add, fow, end).getData(), shaders[6]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s", preface, funny_add, fow, end).getData(), shaders[7]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s%s", preface, landscape, alpha_add, fow, end).getData(), shaders[8]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s%s", preface, alpha_add, grey, fow, end).getData(), shaders[9]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s%s", preface, funny_add, grey, fow, end).getData(), shaders[10]);
|
||||
DefineShaderARB(FormatString("%s%s%s%s%s%s", preface, landscape, alpha_add, grey, fow, end).getData(), shaders[11]);
|
||||
}
|
||||
// done
|
||||
return Active;
|
||||
|
@ -883,28 +876,35 @@ bool CStdGL::InvalidateDeviceObjects()
|
|||
return fSuccess;
|
||||
}
|
||||
|
||||
bool CStdGL::StoreStateBlock()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void CStdGL::SetTexture()
|
||||
{
|
||||
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, (dwBlitMode & C4GFXBLIT_ADDITIVE) ? GL_ONE : GL_SRC_ALPHA);
|
||||
if (shaders[0] && fUseClrModMap)
|
||||
{
|
||||
glEnable(GL_FRAGMENT_PROGRAM_ARB);
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, (*pClrModMap->GetSurface()->ppTex)->texName);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
}
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void CStdGL::ResetTexture()
|
||||
{
|
||||
// disable texturing
|
||||
if (shaders[0])
|
||||
{
|
||||
glDisable(GL_FRAGMENT_PROGRAM_ARB);
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
bool CStdGL::RestoreStateBlock()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CStdGL::CheckGLError(const char *szAtOp)
|
||||
{
|
||||
GLenum err = glGetError();
|
||||
|
@ -925,27 +925,12 @@ bool CStdGL::CheckGLError(const char *szAtOp)
|
|||
|
||||
CStdGL *pGL=NULL;
|
||||
|
||||
bool CStdGL::DeleteDeviceObjects()
|
||||
{
|
||||
InvalidateDeviceObjects();
|
||||
NoPrimaryClipper();
|
||||
// del font objects
|
||||
// del main surfaces
|
||||
if (lpPrimary) delete lpPrimary;
|
||||
lpPrimary=lpBack=NULL;
|
||||
RenderTarget=NULL;
|
||||
// clear context
|
||||
if (pCurrCtx) pCurrCtx->Deselect();
|
||||
MainCtx.Clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
void CStdGL::TaskOut()
|
||||
{
|
||||
// deactivate
|
||||
// backup textures
|
||||
if (pTexMgr && fFullscreen) pTexMgr->IntLock();
|
||||
// shotdown gl
|
||||
// shutdown gl
|
||||
InvalidateDeviceObjects();
|
||||
if (pCurrCtx) pCurrCtx->Deselect();
|
||||
}
|
||||
|
|
|
@ -26,6 +26,25 @@
|
|||
#include <StdWindow.h>
|
||||
|
||||
#ifdef USE_GL
|
||||
|
||||
void CStdGLCtx::SelectCommon()
|
||||
{
|
||||
pGL->pCurrCtx = this;
|
||||
// update size
|
||||
UpdateSize();
|
||||
// assign size
|
||||
pGL->lpPrimary->Wdt=cx; pGL->lpPrimary->Hgt=cy;
|
||||
// set some default states
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glShadeModel(GL_FLAT);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_BLEND);
|
||||
//glEnable(GL_LINE_SMOOTH);
|
||||
//glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST);
|
||||
//glEnable(GL_POINT_SMOOTH);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
CStdGLCtx::CStdGLCtx(): hrc(0), pWindow(0), hDC(0), cx(0), cy(0) { }
|
||||
|
||||
|
@ -109,20 +128,7 @@ bool CStdGLCtx::Select(bool verbose)
|
|||
if (!pGL || !hrc) return false; if (!pGL->lpPrimary) return false;
|
||||
// make context current
|
||||
if (!wglMakeCurrent (hDC, hrc)) return false;
|
||||
pGL->pCurrCtx = this;
|
||||
// update size
|
||||
UpdateSize();
|
||||
// assign size
|
||||
pGL->lpPrimary->Wdt=cx; pGL->lpPrimary->Hgt=cy;
|
||||
// set some default states
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glShadeModel(GL_FLAT);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_BLEND);
|
||||
//glEnable(GL_LINE_SMOOTH);
|
||||
//glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST);
|
||||
//glEnable(GL_POINT_SMOOTH);
|
||||
SelectCommon();
|
||||
// update clipper - might have been done by UpdateSize
|
||||
// however, the wrong size might have been assumed
|
||||
if (!pGL->UpdateClipper()) return false;
|
||||
|
@ -259,20 +265,7 @@ bool CStdGLCtx::Select(bool verbose)
|
|||
if (verbose) pGL->Error(" gl: glXMakeCurrent failed");
|
||||
return false;
|
||||
}
|
||||
pGL->pCurrCtx = this;
|
||||
// update size FIXME: Don't call this every frame
|
||||
UpdateSize();
|
||||
// assign size
|
||||
pGL->lpPrimary->Wdt=cx; pGL->lpPrimary->Hgt=cy;
|
||||
// set some default states
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glShadeModel(GL_FLAT);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_BLEND);
|
||||
//glEnable(GL_LINE_SMOOTH);
|
||||
//glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST);
|
||||
//glEnable(GL_POINT_SMOOTH);
|
||||
SelectCommon();
|
||||
// update clipper - might have been done by UpdateSize
|
||||
// however, the wrong size might have been assumed
|
||||
if (!pGL->UpdateClipper())
|
||||
|
@ -386,27 +379,14 @@ bool CStdGLCtx::Init(CStdWindow * pWindow, CStdApp *)
|
|||
|
||||
bool CStdGLCtx::Select(bool verbose)
|
||||
{
|
||||
pGL->pCurrCtx = this;
|
||||
// update size FIXME: Don't call this every frame
|
||||
UpdateSize();
|
||||
// assign size
|
||||
pGL->lpPrimary->Wdt=cx; pGL->lpPrimary->Hgt=cy;
|
||||
// set some default states
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glShadeModel(GL_FLAT);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_BLEND);
|
||||
//glEnable(GL_LINE_SMOOTH);
|
||||
//glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST);
|
||||
//glEnable(GL_POINT_SMOOTH);
|
||||
SelectCommon();
|
||||
// update clipper - might have been done by UpdateSize
|
||||
// however, the wrong size might have been assumed
|
||||
if (!pGL->UpdateClipper())
|
||||
{
|
||||
{
|
||||
if (verbose) pGL->Error(" gl: UpdateClipper failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// success
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -19,12 +19,6 @@
|
|||
#include <Standard.h>
|
||||
#include <StdNoGfx.h>
|
||||
|
||||
BOOL CStdNoGfx::CreateDirectDraw()
|
||||
{
|
||||
Log(" Graphics disabled");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CStdNoGfx::CStdNoGfx()
|
||||
{
|
||||
Default();
|
||||
|
@ -38,6 +32,7 @@ CStdNoGfx::~CStdNoGfx()
|
|||
|
||||
bool CStdNoGfx::CreatePrimarySurfaces(BOOL Fullscreen, unsigned int iXRes, unsigned int iYRes, int iColorDepth, unsigned int iMonitor)
|
||||
{
|
||||
Log("Graphics disabled.");
|
||||
// Save back color depth
|
||||
byByteCnt = iColorDepth / 8;
|
||||
// Create dummy surface
|
||||
|
|
|
@ -227,7 +227,15 @@ bool CSurface::CreateTextures(int MaxTextureSize)
|
|||
// free previous
|
||||
FreeTextures();
|
||||
// get needed tex size - begin with smaller value of wdt/hgt, so there won't be too much space wasted
|
||||
int iNeedSize=Min(Wdt, Hgt); int n=0; while ((1<<++n) < iNeedSize) {} iNeedSize=1<<n;
|
||||
int iNeedSize=Min(Wdt, Hgt);
|
||||
#ifdef USE_GL
|
||||
if (!pGL || !GLEW_ARB_texture_non_power_of_two)
|
||||
#endif
|
||||
{
|
||||
int n=0;
|
||||
while ((1<<++n) < iNeedSize) {}
|
||||
iNeedSize = 1<<n;
|
||||
}
|
||||
// adjust to available texture size
|
||||
iTexSize=Min(iNeedSize, lpDDraw->MaxTexSize);
|
||||
if (MaxTextureSize)
|
||||
|
@ -251,7 +259,14 @@ bool CSurface::CreateTextures(int MaxTextureSize)
|
|||
{
|
||||
// last texture might be smaller
|
||||
iNeedSize=Max(Wdt%iTexSize, Hgt%iTexSize);
|
||||
int n=0; while ((1<<++n) < iNeedSize) {} iNeedSize=1<<n;
|
||||
#ifdef USE_GL
|
||||
if (!pGL || !GLEW_ARB_texture_non_power_of_two)
|
||||
#endif
|
||||
{
|
||||
int n=0;
|
||||
while ((1<<++n) < iNeedSize) {}
|
||||
iNeedSize=1<<n;
|
||||
}
|
||||
*ppCTex = new CTexRef(iNeedSize, fIsRenderTarget);
|
||||
}
|
||||
if (fIsBackground && ppCTex) (*ppCTex)->FillBlack();
|
||||
|
|
Loading…
Reference in New Issue