From: Jerome St-Louis Date: Wed, 3 Aug 2016 11:49:22 +0000 (-0400) Subject: ecere/gfx/3D: Updates to Direct3D driver to not crash on bump maps / cube maps X-Git-Tag: 0.44.15~43 X-Git-Url: https://ecere.com/cgi-bin/gitweb.cgi?p=sdk;a=commitdiff_plain;h=7e0a2847b6b471b415a5bf0b5e6c53daea0db25c ecere/gfx/3D: Updates to Direct3D driver to not crash on bump maps / cube maps --- diff --git a/ecere/src/gfx/3D/Mesh.ec b/ecere/src/gfx/3D/Mesh.ec index e7c304c..1019b82 100644 --- a/ecere/src/gfx/3D/Mesh.ec +++ b/ecere/src/gfx/3D/Mesh.ec @@ -320,13 +320,14 @@ public: double * weightSum = new0 double[nVertices]; PrimitiveGroup group; - if(Allocate({ normals = true, tangents = true }, nVertices, displaySystem)) + if(Allocate({ normals = true, tangents = texCoords != null }, nVertices, displaySystem)) { Vector3Df * normals = this.normals; Vector3Df * tangents = this.tangents; Pointf * texCoords = this.texCoords; FillBytes(normals, 0, nVertices * sizeof(Vector3Df)); - FillBytes(tangents, 0, 2*nVertices * sizeof(Vector3Df)); + if(tangents) + FillBytes(tangents, 0, 2*nVertices * sizeof(Vector3Df)); for(group = groups.first; group; group = group.next) { int c; @@ -432,7 +433,7 @@ public: weightSum[index] += w; //numShared[index] ++; - if(texCoords) + if(tangents) { uint ix0 = index; uint prev = v ? i - 1 : c + nIndex-1; @@ -495,10 +496,14 @@ public: for(c = 0; cScale(n, s), n->Normalize(n); - t1->Scale(t1, s), t1->Normalize(t1); - t2->Scale(t2, s), t2->Normalize(t2); + if(tangents) + { + Vector3Df * t1 = &tangents[2*c], * t2 = &tangents[2*c+1]; + t1->Scale(t1, s), t1->Normalize(t1); + t2->Scale(t2, s), t2->Normalize(t2); + } } delete numShared; delete weightSum; diff --git a/ecere/src/gfx/3D/meshes/Sphere.ec b/ecere/src/gfx/3D/meshes/Sphere.ec index 7670df2..60d5523 100644 --- a/ecere/src/gfx/3D/meshes/Sphere.ec +++ b/ecere/src/gfx/3D/meshes/Sphere.ec @@ -51,18 +51,21 @@ public: pNormals[index] = pVertices[index]; - pTangents[index*2] = + if(pTangents) { - (float) (sin(theta) * cos(omega - Pi/2)); - (float) sin(omega - Pi/2); - (float) (cos(theta) * cos(omega - Pi/2)); - }; - pTangents[index*2+1] = - { - (float) (sin(theta - Pi/2) * cosOmega); - (float) sin(omega); - (float) (cos(theta - Pi/2) * cosOmega); - }; + pTangents[index*2] = + { + (float) (sin(theta) * cos(omega - Pi/2)); + (float) sin(omega - Pi/2); + (float) (cos(theta) * cos(omega - Pi/2)); + }; + pTangents[index*2+1] = + { + (float) (sin(theta - Pi/2) * cosOmega); + (float) sin(omega); + (float) (cos(theta - Pi/2) * cosOmega); + }; + } //pTangents[index*2 + 1].CrossProduct(pNormals[index], pTangents[index*2]); pTexCoords[index] = { (float)l / (w-1), (float)lat / (numLat) }; diff --git a/ecere/src/gfx/Bitmap.ec b/ecere/src/gfx/Bitmap.ec index c1d3725..4e85b2e 100644 --- a/ecere/src/gfx/Bitmap.ec +++ b/ecere/src/gfx/Bitmap.ec @@ -949,10 +949,11 @@ public: public class CubeMap : Bitmap { public: - void Load(DisplaySystem displaySystem, const String * names, const String extension, bool oldStyle) + bool Load(DisplaySystem displaySystem, const String * names, const String extension, bool oldStyle) { int i; - for(i = 0; i < 6; i++) + bool result = true; + for(i = 0; result && i < 6; i++) { char location[MAX_LOCATION]; Bitmap face = i > 0 ? { } : this; @@ -962,13 +963,16 @@ public: if(face.Load(location, null, null)) { face.driverData = driverData; - displaySystem.driver.MakeDDBitmap(displaySystem, face, true, (i + 1) | (oldStyle << 3)); + result = displaySystem.driver.MakeDDBitmap(displaySystem, face, true, (i + 1) | (oldStyle << 3)); } + else + result = false; if(i > 0) { face.driverData = 0; delete face; } } + return result; } }; diff --git a/ecere/src/gfx/drivers/Direct3D8DisplayDriver.ec b/ecere/src/gfx/drivers/Direct3D8DisplayDriver.ec index de87cb4..567e81e 100644 --- a/ecere/src/gfx/drivers/Direct3D8DisplayDriver.ec +++ b/ecere/src/gfx/drivers/Direct3D8DisplayDriver.ec @@ -677,7 +677,7 @@ class Direct3D8DisplayDriver : DisplayDriver { bool result = false; D3D8System d3dSystem = displaySystem.driverData; - if(bitmap.Convert(null, pixelFormat888, null)) + if(cubeMapFace && bitmap.Convert(null, pixelFormat888, null)) { IDirect3DTexture8 * texture; uint w = pow2i(Min(bitmap.width, 512)), h = pow2i(Min(bitmap.height, 512)); diff --git a/ecere/src/gfx/drivers/Direct3D9DisplayDriver.ec b/ecere/src/gfx/drivers/Direct3D9DisplayDriver.ec index b57cfa1..b21d4c9 100644 --- a/ecere/src/gfx/drivers/Direct3D9DisplayDriver.ec +++ b/ecere/src/gfx/drivers/Direct3D9DisplayDriver.ec @@ -675,7 +675,7 @@ class Direct3D9DisplayDriver : DisplayDriver { bool result = false; D3DSystem d3dSystem = displaySystem.driverData; - if(bitmap.Convert(null, pixelFormat888, null)) + if(!cubeMapFace && bitmap.Convert(null, pixelFormat888, null)) { IDirect3DTexture9 * texture; uint w = pow2i(Min(bitmap.width, 512)), h = pow2i(Min(bitmap.height, 512));