mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 12:05:14 -04:00
Fix mipmaps crashing on windows 98.
This commit is contained in:
parent
a55ea3b0b7
commit
e3f86de480
@ -51,6 +51,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
}
|
||||
}
|
||||
|
||||
CustomMipmapsLevels = true;
|
||||
caps = device.Capabilities;
|
||||
viewStack = new MatrixStack(device, TransformState.View);
|
||||
projStack = new MatrixStack(device, TransformState.Projection);
|
||||
@ -193,7 +194,9 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
int lvls = MipmapsLevels(width, height);
|
||||
|
||||
for (int lvl = 1; lvl <= lvls; lvl++) {
|
||||
x /= 2; y /= 2; width /= 2; height /= 2;
|
||||
x /= 2; y /= 2;
|
||||
if (width > 1) width /= 2;
|
||||
if (height > 1) height /= 2;
|
||||
int size = width * height * 4;
|
||||
|
||||
IntPtr cur = Marshal.AllocHGlobal(size);
|
||||
|
@ -197,10 +197,14 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
}
|
||||
}
|
||||
|
||||
internal static int MipmapsLevels(int width, int height) {
|
||||
internal int MipmapsLevels(int width, int height) {
|
||||
int lvlsWidth = Utils.Log2(width), lvlsHeight = Utils.Log2(height);
|
||||
int lvls = Math.Min(lvlsWidth, lvlsHeight);
|
||||
return Math.Min(lvls, 4);
|
||||
if (CustomMipmapsLevels) {
|
||||
int lvls = Math.Min(lvlsWidth, lvlsHeight);
|
||||
return Math.Min(lvls, 4);
|
||||
} else {
|
||||
return Math.Max(lvlsWidth, lvlsHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,9 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
|
||||
/// <summary> Whether mipmapping of terrain textures is used. </summary>
|
||||
public bool Mipmaps;
|
||||
|
||||
/// <summary> Whether the backend supports setting the number of custom mipmaps levels. </summary>
|
||||
public bool CustomMipmapsLevels;
|
||||
|
||||
/// <summary> Delegate that is invoked when the current context is lost,
|
||||
/// and is repeatedly invoked until the context can be retrieved. </summary>
|
||||
|
@ -27,6 +27,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
texDimensions = texDims;
|
||||
|
||||
glLists = Options.GetBool(OptionsKey.ForceOldOpenGL, false);
|
||||
CustomMipmapsLevels = !glLists;
|
||||
CheckVboSupport();
|
||||
base.InitDynamicBuffers();
|
||||
|
||||
@ -52,6 +53,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
GL.UseArbVboAddresses();
|
||||
} else {
|
||||
glLists = true;
|
||||
CustomMipmapsLevels = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,7 +171,9 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
|
||||
if (mipmaps) {
|
||||
GL.TexParameteri(TextureTarget.Texture2D, TextureParameterName.MinFilter, (int)TextureFilter.NearestMipmapLinear);
|
||||
GL.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, MipmapsLevels(width, height));
|
||||
if (CustomMipmapsLevels) {
|
||||
GL.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, MipmapsLevels(width, height));
|
||||
}
|
||||
} else {
|
||||
GL.TexParameteri(TextureTarget.Texture2D, TextureParameterName.MinFilter, (int)TextureFilter.Nearest);
|
||||
}
|
||||
@ -187,7 +191,9 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
int lvls = MipmapsLevels(width, height);
|
||||
|
||||
for (int lvl = 1; lvl <= lvls; lvl++) {
|
||||
x /= 2; y /= 2; width /= 2; height /= 2;
|
||||
x /= 2; y /= 2;
|
||||
if (width > 1) width /= 2;
|
||||
if (height > 1) height /= 2;
|
||||
int size = width * height * 4;
|
||||
|
||||
IntPtr cur = Marshal.AllocHGlobal(size);
|
||||
|
@ -233,6 +233,7 @@ void Gfx_Init(void) {
|
||||
Platform_MemSet(&caps, 0, sizeof(D3DCAPS9));
|
||||
IDirect3DDevice9_GetDeviceCaps(device, &caps);
|
||||
|
||||
Gfx_CustomMipmapsLevels = true;
|
||||
viewStack.Type = D3DTS_VIEW;
|
||||
projStack.Type = D3DTS_PROJECTION;
|
||||
texStack.Type = D3DTS_TEXTURE0;
|
||||
@ -321,10 +322,12 @@ void D3D9_DoMipmaps(IDirect3DTexture9* texture, Int32 x, Int32 y, Bitmap* bmp, b
|
||||
Int32 lvl, width = bmp->Width, height = bmp->Height;
|
||||
|
||||
for (lvl = 1; lvl <= lvls; lvl++) {
|
||||
x /= 2; y /= 2; width /= 2; height /= 2;
|
||||
x /= 2; y /= 2;
|
||||
if (width > 1) width /= 2;
|
||||
if (height > 1) height /= 2;
|
||||
UInt32 size = Bitmap_DataSize(width, height);
|
||||
UInt8* cur = Platform_MemAlloc(size);
|
||||
|
||||
UInt8* cur = Platform_MemAlloc(size);
|
||||
if (cur == NULL) {
|
||||
ErrorHandler_Fail("Allocating memory for mipmaps");
|
||||
}
|
||||
|
@ -34,6 +34,9 @@ bool Gfx_LostContext;
|
||||
/* Whether mipmapping of terrain textures is used. */
|
||||
bool Gfx_Mipmaps;
|
||||
|
||||
/* Whether the backend supports setting the number of custom mipmaps levels. */
|
||||
bool Gfx_CustomMipmapsLevels;
|
||||
|
||||
/* Maximum number of vertices that can be indexed. */
|
||||
#define Gfx_MaxIndices (65536 / 4 * 6)
|
||||
/* Maximum number of vertices that can be indexed. */
|
||||
|
@ -13,13 +13,11 @@
|
||||
|
||||
/* Initalises common resources. */
|
||||
void GfxCommon_Init(void);
|
||||
|
||||
/* Frees common resources. */
|
||||
void GfxCommon_Free(void);
|
||||
|
||||
/* Handles a context being lost. */
|
||||
void GfxCommon_LoseContext(STRING_TRANSIENT String* reason);
|
||||
|
||||
/* Handles a context being recreated. */
|
||||
void GfxCommon_RecreateContext(void);
|
||||
|
||||
@ -27,54 +25,40 @@ void GfxCommon_RecreateContext(void);
|
||||
/* Binds and draws the specified subset of the vertices in the current dynamic vertex buffer
|
||||
This method also replaces the dynamic vertex buffer's data first with the given vertices before drawing. */
|
||||
void GfxCommon_UpdateDynamicVb_Lines(GfxResourceID vb, void* vertices, Int32 vCount);
|
||||
|
||||
/*Binds and draws the specified subset of the vertices in the current dynamic vertex buffer
|
||||
This method also replaces the dynamic vertex buffer's data first with the given vertices before drawing. */
|
||||
void GfxCommon_UpdateDynamicVb_IndexedTris(GfxResourceID vb, void* vertices, Int32 vCount);
|
||||
|
||||
|
||||
GfxResourceID GfxCommon_quadVb;
|
||||
|
||||
/* Draws a 2D flat coloured quad to the screen.*/
|
||||
void GfxCommon_Draw2DFlat(Real32 x, Real32 y, Real32 width, Real32 height,
|
||||
PackedCol col);
|
||||
|
||||
void GfxCommon_Draw2DFlat(Real32 x, Real32 y, Real32 width, Real32 height, PackedCol col);
|
||||
/* Draws a 2D gradient coloured quad to the screen.*/
|
||||
void GfxCommon_Draw2DGradient(Real32 x, Real32 y, Real32 width, Real32 height,
|
||||
PackedCol topCol, PackedCol bottomCol);
|
||||
|
||||
|
||||
GfxResourceID GfxCommon_texVb;
|
||||
|
||||
/* Draws a 2D texture to the screen. */
|
||||
void GfxCommon_Draw2DTexture(Texture* tex, PackedCol col);
|
||||
|
||||
/* Makes the 2D vertices that compose a texture quad.*/
|
||||
void GfxCommon_Make2DQuad(Texture* tex, PackedCol col, VertexP3fT2fC4b** vertices);
|
||||
|
||||
|
||||
/* Updates the various matrix stacks and properties so that the graphics API state
|
||||
is suitable for rendering 2D quads and other 2D graphics to. */
|
||||
void GfxCommon_Mode2D(Real32 width, Real32 height);
|
||||
|
||||
/* Updates the various matrix stacks and properties so that the graphics API state
|
||||
is suitable for rendering 3D vertices. */
|
||||
void GfxCommon_Mode3D(void);
|
||||
|
||||
/* Makes the default index buffer used for drawing quads. */
|
||||
GfxResourceID GfxCommon_MakeDefaultIb(void);
|
||||
|
||||
/* Fills the given index buffer with up to iCount indices. */
|
||||
void GfxCommon_MakeIndices(UInt16* indices, Int32 iCount);
|
||||
|
||||
/* Sets the appropriate alpha testing/blending states necessary to render the given block. */
|
||||
void GfxCommon_SetupAlphaState(UInt8 draw);
|
||||
|
||||
/* Resets the appropriate alpha testing/blending states necessary to render the given block. */
|
||||
void GfxCommon_RestoreAlphaState(UInt8 draw);
|
||||
|
||||
|
||||
void GfxCommon_GenMipmaps(Int32 width, Int32 height, UInt8* lvlScan0, UInt8* scan0);
|
||||
|
||||
Int32 GfxCommon_MipmapsLevels(Int32 width, Int32 height);
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user