MCPcopy Create free account
hub / github.com/carbonengine/trinity / PyInit

Function PyInit

trinity/Tr2HostBitmap_Blue.cpp:12–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10
11#if BLUE_WITH_PYTHON
12static PyObject* PyInit( PyObject* self, PyObject* args )
13{
14 USE_MAIN_THREAD_RENDER_CONTEXT();
15
16 Tr2HostBitmap* pThis = BluePythonCast<Tr2HostBitmap*>( self );
17
18 PyObject* pyBlueObject = nullptr;
19 unsigned dummy1 = 0, dummy2 = 0, dummy3 = 0; // make sure the signature is still up to 4 elements, else blue binding doesn't work with constructor 'overloading' :(
20 if( PyArg_ParseTuple( args, "|Oiii", &pyBlueObject, &dummy1, &dummy2, &dummy3 ) && pyBlueObject && !dummy1 && !dummy2 && !dummy3 )
21 {
22 Tr2RenderTarget* renderTarget = nullptr;
23 if( BluePythonCast<Tr2RenderTarget*>( pyBlueObject ) && BlueExtractArgument( pyBlueObject, renderTarget, 1 ) && renderTarget && renderTarget->IsValid() )
24 {
25 auto& rt = renderTarget->GetRenderTarget();
26 pThis->Create( rt.GetWidth(), rt.GetHeight(), rt.GetTrueMipCount(), rt.GetFormat() );
27 pThis->CopyFromRenderTarget( *renderTarget, renderContext );
28 Py_RETURN_NONE;
29 }
30
31 // Try again with TriTextureRes
32 TriTextureRes* textureRes = nullptr;
33 if( BluePythonCast<TriTextureRes*>( pyBlueObject ) && BlueExtractArgument( pyBlueObject, textureRes, 1 ) && textureRes && textureRes->IsGood() )
34 {
35 pThis->Create( textureRes->GetWidth(), textureRes->GetHeight(), textureRes->GetTrueMipCount(), textureRes->GetFormat() );
36 pThis->CopyFromTextureRes( *textureRes, renderContext );
37 Py_RETURN_NONE;
38 }
39
40 // ...and with Tr2TextureAtlas
41 Tr2TextureAtlas* textureAtlas = nullptr;
42 if( BluePythonCast<Tr2TextureAtlas*>( pyBlueObject ) && BlueExtractArgument( pyBlueObject, textureAtlas, 1 ) &&
43 textureAtlas && textureAtlas->GetTexture() && textureAtlas->GetTexture()->IsValid() )
44 {
45 auto& texture = *textureAtlas->GetTexture();
46 pThis->Create( texture.GetWidth(), texture.GetHeight(), texture.GetTrueMipCount(), texture.GetFormat() );
47 pThis->CopyFromTexture( texture, renderContext );
48 Py_RETURN_NONE;
49 }
50
51 Py_RETURN_NONE;
52 }
53
54
55 unsigned width = 0, height = 0, mipCount = 0, format = 0;
56
57 if( !PyArg_ParseTuple( args, "|iiii", &width, &height, &mipCount, &format ) )
58 {
59 return nullptr;
60 }
61
62 if( width && height && format )
63 {
64 pThis->Create( width, height, mipCount, static_cast<Tr2RenderContextEnum::PixelFormat>( format ) );
65 }
66
67 Py_RETURN_NONE;
68}
69

Callers

nothing calls this directly

Calls 12

GetRenderTargetMethod · 0.80
GetTrueMipCountMethod · 0.80
CopyFromRenderTargetMethod · 0.80
CopyFromTextureResMethod · 0.80
CopyFromTextureMethod · 0.80
IsValidMethod · 0.45
CreateMethod · 0.45
GetWidthMethod · 0.45
GetHeightMethod · 0.45
GetFormatMethod · 0.45
IsGoodMethod · 0.45
GetTextureMethod · 0.45

Tested by

no test coverage detected