@@ -232,9 +232,9 @@ PyObject *py_unreal_engine_create_texture(PyObject * self, PyObject * args) {
232232 char *name;
233233 int width;
234234 int height;
235- int format = PF_B8G8R8A8 ;
235+ Py_buffer py_buf ;
236236
237- if (!PyArg_ParseTuple (args, " Osii|i :create_texture" , &py_package, &name, &width, &height, &format )) {
237+ if (!PyArg_ParseTuple (args, " Osiiz* :create_texture" , &py_package, &name, &width, &height, &py_buf )) {
238238 return nullptr ;
239239 }
240240
@@ -249,24 +249,21 @@ PyObject *py_unreal_engine_create_texture(PyObject * self, PyObject * args) {
249249 }
250250 }
251251
252- UTexture2D *texture = NewObject<UTexture2D>(u_package, UTF8_TO_TCHAR (name), RF_Public | RF_Standalone);
252+ SIZE_T wanted_len = width * height * 4 ;
253+
254+ TArray<FColor> colors;
255+ colors.AddZeroed (wanted_len);
256+ FCreateTexture2DParameters params;
257+
258+ if ((SIZE_T )py_buf.len < wanted_len)
259+ wanted_len = py_buf.len ;
260+
261+ FMemory::Memcpy (colors.GetData (), py_buf.buf , wanted_len);
262+
263+ UTexture2D *texture = FImageUtils::CreateTexture2D (width, height, colors, u_package, UTF8_TO_TCHAR (name), RF_Public | RF_Standalone, params);
253264 if (!texture)
254265 return PyErr_Format (PyExc_Exception, " unable to create texture" );
255266
256- texture->PlatformData = new FTexturePlatformData ();
257- texture->PlatformData ->SizeX = width;
258- texture->PlatformData ->SizeY = height;
259- texture->PlatformData ->PixelFormat = (EPixelFormat)format;
260-
261- int32 blocksX = width / GPixelFormats[(EPixelFormat)format].BlockSizeX ;
262- int32 blocksY = width / GPixelFormats[(EPixelFormat)format].BlockSizeY ;
263- FTexture2DMipMap *mip = new (texture->PlatformData ->Mips ) FTexture2DMipMap ();
264- mip->SizeX = width;
265- mip->SizeY = height;
266- mip->BulkData .Lock (LOCK_READ_WRITE );
267- mip->BulkData .Realloc (blocksX * blocksY * GPixelFormats[(EPixelFormat)format].BlockBytes );
268- mip->BulkData .Unlock ();
269-
270267 ue_PyUObject *ret = ue_get_python_wrapper (texture);
271268 if (!ret)
272269 return PyErr_Format (PyExc_Exception, " uobject is in invalid state" );
0 commit comments