Browse Source

metal: image uploading

Alex Szpakowski 5 years ago
parent
commit
cd08f75909
1 changed files with 33 additions and 1 deletions
  1. 33 1
      src/modules/graphics/metal/Image.mm

+ 33 - 1
src/modules/graphics/metal/Image.mm

@@ -69,7 +69,39 @@ void Image::create(id<MTLDevice> device)
 	if (texture == nil)
 	if (texture == nil)
 		throw love::Exception("Out of graphics memory.");
 		throw love::Exception("Out of graphics memory.");
 
 
-	// TODO: upload
+	int mipcount = getMipmapCount();
+	int slicecount = 1;
+
+	if (texType == TEXTURE_VOLUME)
+		slicecount = getDepth();
+	else if (texType == TEXTURE_2D_ARRAY)
+		slicecount = getLayerCount();
+	else if (texType == TEXTURE_CUBE)
+		slicecount = 6;
+
+	if (mipmapsType == MIPMAPS_GENERATED)
+		mipcount = 1;
+
+	int w = pixelWidth;
+	int h = pixelHeight;
+	int d = depth;
+
+	for (int mip = 0; mip < mipcount; mip++)
+	{
+		for (int slice = 0; slice < slicecount; slice++)
+		{
+			love::image::ImageDataBase *imgd = data.get(slice, mip);
+
+			if (imgd != nullptr)
+				uploadImageData(imgd, mip, slice, 0, 0);
+		}
+
+		w = std::max(w / 2, 1);
+		h = std::max(h / 2, 1);
+
+		if (texType == TEXTURE_VOLUME)
+			d = std::max(d / 2, 1);
+	}
 
 
 	if (mipmapsType == MIPMAPS_GENERATED)
 	if (mipmapsType == MIPMAPS_GENERATED)
 		generateMipmaps();
 		generateMipmaps();