Skip to content

Commit 337e757

Browse files
WIP
1 parent dc4625b commit 337e757

26 files changed

+1906
-403
lines changed

.vscode/c_cpp_properties.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"includePath": [
66
"${workspaceFolder}/**",
77
"${workspaceFolder}/src",
8+
"${workspaceFolder}/extensions",
89
"${workspaceFolder}/../pilotlight/libs",
910
"${workspaceFolder}/../pilotlight/extensions",
1011
"${workspaceFolder}/../pilotlight/src",

extensions/pl_draw_ext_m.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
pl_draw_ext_m.c
3+
*/
4+
5+
/*
6+
Index of this file:
7+
// [SECTION] includes
8+
// [SECTION] binding apis
9+
// [SECTION] implementations
10+
*/
11+
12+
//-----------------------------------------------------------------------------
13+
// [SECTION] includes
14+
//-----------------------------------------------------------------------------
15+
16+
#include "pilotlight.h"
17+
18+
//-----------------------------------------------------------------------------
19+
// [SECTION] implementations
20+
//-----------------------------------------------------------------------------
21+
22+
PyObject*
23+
plDrawI_add_triangle_filled(PyObject* self, PyObject* args, PyObject* kwargs)
24+
{
25+
26+
PyObject* ptPythonLayer = NULL;
27+
PyObject* ptPythonP0 = NULL;
28+
PyObject* ptPythonP1 = NULL;
29+
PyObject* ptPythonP2 = NULL;
30+
uint32_t uColor = PL_COLOR_32_WHITE;
31+
32+
static const char* apcKeywords[] = {
33+
"layer",
34+
"p0",
35+
"p1",
36+
"p2",
37+
"uColor",
38+
NULL,
39+
};
40+
41+
if (!pl_parse("OOOO|$I", (const char**)apcKeywords, args, kwargs, __FUNCTION__,
42+
&ptPythonLayer, &ptPythonP0, &ptPythonP1, &ptPythonP2, &uColor))
43+
return NULL;
44+
45+
plDrawLayer2D* ptLayer = PyCapsule_GetPointer(ptPythonLayer, "plDrawLayer2D");
46+
47+
gptDraw->add_triangle_filled(ptLayer,
48+
pl_get_vec2_from_python(ptPythonP0),
49+
pl_get_vec2_from_python(ptPythonP1),
50+
pl_get_vec2_from_python(ptPythonP2),
51+
(plDrawSolidOptions){.uColor = uColor});
52+
53+
Py_RETURN_NONE;
54+
}

extensions/pl_pak_ext_m.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
pl_shader_ext_m.c
3+
*/
4+
5+
/*
6+
Index of this file:
7+
// [SECTION] includes
8+
// [SECTION] implementations
9+
*/
10+
11+
//-----------------------------------------------------------------------------
12+
// [SECTION] includes
13+
//-----------------------------------------------------------------------------
14+
15+
#include "pilotlight.h"
16+
17+
//-----------------------------------------------------------------------------
18+
// [SECTION] implementations
19+
//-----------------------------------------------------------------------------
20+
21+
PyObject*
22+
plPakI_begin_packing(PyObject* self, PyObject* args)
23+
{
24+
static const char* apcKeywords[] = {
25+
"pcFile",
26+
"uContentVersion",
27+
NULL,
28+
};
29+
30+
const char* pcFile = NULL;
31+
uint32_t uContentVersion = 0;
32+
if (!pl_parse("sI", (const char**)apcKeywords, args, NULL, __FUNCTION__,
33+
&pcFile, &uContentVersion))
34+
return NULL;
35+
36+
// plWindow* ptWindowPtr = PyCapsule_GetPointer(ptWindow, "plWindow");
37+
38+
plPakFile* ptPakFile = NULL;
39+
bool bResult = gptPak->begin_packing(pcFile, uContentVersion, &ptPakFile);
40+
41+
PyObject* ptCapsule = PyCapsule_New(ptPakFile, "plPakFile", NULL);
42+
return Py_BuildValue("(pO)", bResult, ptCapsule);
43+
}
44+
45+
PyObject*
46+
plPakI_add_from_disk(PyObject* self, PyObject* args)
47+
{
48+
static const char* apcKeywords[] = {
49+
"ptPakFile",
50+
"pcPakPath",
51+
"pcFilePath",
52+
"bCompress",
53+
NULL,
54+
};
55+
56+
PyObject* ptCapsule = NULL;
57+
const char* pcPakPath = NULL;
58+
const char* pcFilePath = NULL;
59+
bool bCompress = false;
60+
if (!pl_parse("Ossp", (const char**)apcKeywords, args, NULL, __FUNCTION__,
61+
&ptCapsule, &pcPakPath, &pcFilePath, &bCompress))
62+
return NULL;
63+
64+
plPakFile* ptPakPtr = PyCapsule_GetPointer(ptCapsule, "plPakFile");
65+
66+
bool bResult = gptPak->add_from_disk(ptPakPtr, pcPakPath, pcFilePath, bCompress);
67+
return PyBool_FromLong(bResult);
68+
}
69+
70+
PyObject*
71+
plPakI_end_packing(PyObject* self, PyObject* arg)
72+
{
73+
plPakFile* ptPakPtr = PyCapsule_GetPointer(arg, "plPakFile");
74+
75+
gptPak->end_packing(&ptPakPtr);
76+
Py_RETURN_NONE;
77+
}

extensions/pl_shader_ext_m.c

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
/*
2+
pl_shader_ext_m.c
3+
*/
4+
5+
/*
6+
Index of this file:
7+
// [SECTION] includes
8+
// [SECTION] implementations
9+
*/
10+
11+
//-----------------------------------------------------------------------------
12+
// [SECTION] includes
13+
//-----------------------------------------------------------------------------
14+
15+
#include "pilotlight.h"
16+
17+
//-----------------------------------------------------------------------------
18+
// [SECTION] implementations
19+
//-----------------------------------------------------------------------------
20+
21+
PyObject*
22+
plShaderI_initialize(PyObject* self, PyObject* args)
23+
{
24+
PyObject* ptFlags = PyObject_GetAttrString(args, "tFlags");
25+
PyObject* ptOptimizationLevel = PyObject_GetAttrString(args, "tOptimizationLevel");
26+
PyObject* ptCacheOutputDirectory = PyObject_GetAttrString(args, "pcCacheOutputDirectory");
27+
PyObject* apcIncludeDirectories = PyObject_GetAttrString(args, "apcIncludeDirectories");
28+
PyObject* apcDirectories = PyObject_GetAttrString(args, "apcDirectories");
29+
PyObject* ptMacroDefinitions = PyObject_GetAttrString(args, "ptMacroDefinitions");
30+
31+
32+
plShaderOptions tOptions = {0};
33+
34+
PyLong_AsInt32(ptFlags, &tOptions.tFlags);
35+
PyLong_AsInt32(ptOptimizationLevel, &tOptions.tOptimizationLevel);
36+
tOptions.pcCacheOutputDirectory = PyUnicode_AsUTF8(ptCacheOutputDirectory);
37+
38+
Py_ssize_t szIncludeCount = PyList_Size(apcIncludeDirectories);
39+
for (Py_ssize_t i = 0; i < szIncludeCount; ++i)
40+
{
41+
tOptions.apcIncludeDirectories[i] = PyUnicode_AsUTF8(PyList_GetItem(apcIncludeDirectories, i));
42+
}
43+
44+
45+
Py_ssize_t szDirCount = PyList_Size(apcDirectories);
46+
for (Py_ssize_t i = 0; i < szDirCount; ++i)
47+
{
48+
tOptions.apcDirectories[i] = PyUnicode_AsUTF8(PyList_GetItem(apcDirectories, i));
49+
}
50+
51+
Py_ssize_t szMacroCount = PyList_Size(ptMacroDefinitions);
52+
for (Py_ssize_t i = 0; i < szMacroCount; ++i)
53+
{
54+
PyObject* ptDefinition = PyList_GetItem(ptMacroDefinitions, i);
55+
tOptions.atMacroDefinitions[i].pcName = PyUnicode_AsUTF8(PyObject_GetAttrString(ptDefinition, "pcName"));
56+
tOptions.atMacroDefinitions[i].pcValue = PyUnicode_AsUTF8(PyObject_GetAttrString(ptDefinition, "pcValue"));
57+
}
58+
59+
return PyBool_FromLong(gptShader->initialize(&tOptions));
60+
}
61+
62+
PyObject*
63+
plShaderI_cleanup(PyObject* self)
64+
{
65+
gptShader->cleanup();
66+
Py_RETURN_NONE;
67+
}
68+
69+
PyObject*
70+
plShaderI_load_glsl(PyObject* self, PyObject* args, PyObject* kwargs)
71+
{
72+
static const char* apcKeywords[] = {
73+
"shader",
74+
"entryFunc",
75+
"file",
76+
"options",
77+
NULL,
78+
};
79+
80+
const char* pcShader = NULL;
81+
const char* pcEntryFunc = NULL;
82+
const char* pcFile = NULL;
83+
PyObject* ptOptions = NULL;
84+
if (!pl_parse("ss|sO", (const char**)apcKeywords, args, kwargs, __FUNCTION__,
85+
&pcShader, &pcEntryFunc, &pcFile, &ptOptions))
86+
return NULL;
87+
88+
plShaderOptions tOptions = {0};
89+
90+
if(ptOptions)
91+
{
92+
PyObject* ptFlags = PyObject_GetAttrString(ptOptions, "tFlags");
93+
PyObject* ptOptimizationLevel = PyObject_GetAttrString(ptOptions, "tOptimizationLevel");
94+
PyObject* ptCacheOutputDirectory = PyObject_GetAttrString(ptOptions, "pcCacheOutputDirectory");
95+
PyObject* apcIncludeDirectories = PyObject_GetAttrString(ptOptions, "apcIncludeDirectories");
96+
PyObject* apcDirectories = PyObject_GetAttrString(ptOptions, "apcDirectories");
97+
PyObject* ptMacroDefinitions = PyObject_GetAttrString(ptOptions, "ptMacroDefinitions");
98+
99+
PyLong_AsInt32(ptFlags, &tOptions.tFlags);
100+
PyLong_AsInt32(ptOptimizationLevel, &tOptions.tOptimizationLevel);
101+
tOptions.pcCacheOutputDirectory = PyUnicode_AsUTF8(ptCacheOutputDirectory);
102+
103+
Py_ssize_t szIncludeCount = PyList_Size(apcIncludeDirectories);
104+
for (Py_ssize_t i = 0; i < szIncludeCount; ++i)
105+
{
106+
tOptions.apcIncludeDirectories[i] = PyUnicode_AsUTF8(PyList_GetItem(apcIncludeDirectories, i));
107+
}
108+
109+
110+
Py_ssize_t szDirCount = PyList_Size(apcDirectories);
111+
for (Py_ssize_t i = 0; i < szDirCount; ++i)
112+
{
113+
tOptions.apcDirectories[i] = PyUnicode_AsUTF8(PyList_GetItem(apcDirectories, i));
114+
}
115+
116+
Py_ssize_t szMacroCount = PyList_Size(ptMacroDefinitions);
117+
for (Py_ssize_t i = 0; i < szMacroCount; ++i)
118+
{
119+
PyObject* ptDefinition = PyList_GetItem(ptMacroDefinitions, i);
120+
tOptions.atMacroDefinitions[i].pcName = PyUnicode_AsUTF8(PyObject_GetAttrString(ptDefinition, "pcName"));
121+
tOptions.atMacroDefinitions[i].pcValue = PyUnicode_AsUTF8(PyObject_GetAttrString(ptDefinition, "pcValue"));
122+
}
123+
}
124+
125+
plShaderModule tModule = gptShader->load_glsl(pcShader, pcEntryFunc, pcFile, ptOptions ? &tOptions : NULL);
126+
return Py_BuildValue("(nOs)", tModule.szCodeSize, PyCapsule_New(tModule.puCode, "plShaderModule.puCode", NULL), tModule.pcEntryFunc);
127+
}
128+
129+
PyObject*
130+
plShaderI_compile_glsl(PyObject* self, PyObject* args, PyObject* kwargs)
131+
{
132+
static const char* apcKeywords[] = {
133+
"shader",
134+
"entryFunc",
135+
"options",
136+
NULL,
137+
};
138+
139+
const char* pcShader = NULL;
140+
const char* pcEntryFunc = NULL;
141+
PyObject* ptOptions = NULL;
142+
if (!pl_parse("ss|O", (const char**)apcKeywords, args, kwargs, __FUNCTION__,
143+
&pcShader, &pcEntryFunc, &ptOptions))
144+
return NULL;
145+
146+
plShaderOptions tOptions = {0};
147+
148+
if(ptOptions)
149+
{
150+
PyObject* ptFlags = PyObject_GetAttrString(ptOptions, "tFlags");
151+
PyObject* ptOptimizationLevel = PyObject_GetAttrString(ptOptions, "tOptimizationLevel");
152+
PyObject* ptCacheOutputDirectory = PyObject_GetAttrString(ptOptions, "pcCacheOutputDirectory");
153+
PyObject* apcIncludeDirectories = PyObject_GetAttrString(ptOptions, "apcIncludeDirectories");
154+
PyObject* apcDirectories = PyObject_GetAttrString(ptOptions, "apcDirectories");
155+
PyObject* ptMacroDefinitions = PyObject_GetAttrString(ptOptions, "ptMacroDefinitions");
156+
157+
PyLong_AsInt32(ptFlags, &tOptions.tFlags);
158+
PyLong_AsInt32(ptOptimizationLevel, &tOptions.tOptimizationLevel);
159+
tOptions.pcCacheOutputDirectory = PyUnicode_AsUTF8(ptCacheOutputDirectory);
160+
161+
Py_ssize_t szIncludeCount = PyList_Size(apcIncludeDirectories);
162+
for (Py_ssize_t i = 0; i < szIncludeCount; ++i)
163+
{
164+
tOptions.apcIncludeDirectories[i] = PyUnicode_AsUTF8(PyList_GetItem(apcIncludeDirectories, i));
165+
}
166+
167+
168+
Py_ssize_t szDirCount = PyList_Size(apcDirectories);
169+
for (Py_ssize_t i = 0; i < szDirCount; ++i)
170+
{
171+
tOptions.apcDirectories[i] = PyUnicode_AsUTF8(PyList_GetItem(apcDirectories, i));
172+
}
173+
174+
Py_ssize_t szMacroCount = PyList_Size(ptMacroDefinitions);
175+
for (Py_ssize_t i = 0; i < szMacroCount; ++i)
176+
{
177+
PyObject* ptDefinition = PyList_GetItem(ptMacroDefinitions, i);
178+
tOptions.atMacroDefinitions[i].pcName = PyUnicode_AsUTF8(PyObject_GetAttrString(ptDefinition, "pcName"));
179+
tOptions.atMacroDefinitions[i].pcValue = PyUnicode_AsUTF8(PyObject_GetAttrString(ptDefinition, "pcValue"));
180+
}
181+
}
182+
183+
plShaderModule tModule = gptShader->compile_glsl(pcShader, pcEntryFunc, ptOptions ? &tOptions : NULL);
184+
return Py_BuildValue("(nOs)", tModule.szCodeSize, PyCapsule_New(tModule.puCode, "plShaderModule.puCode", NULL), tModule.szCodeSize);
185+
}
186+
187+
PyObject*
188+
plShaderI_write_to_disk(PyObject* self, PyObject* args)
189+
{
190+
static const char* apcKeywords[] = {
191+
"shader",
192+
"module",
193+
NULL,
194+
};
195+
196+
const char* pcShader = NULL;
197+
PyObject* ptModule = NULL;
198+
if (!pl_parse("sO", (const char**)apcKeywords, args, NULL, __FUNCTION__,
199+
&pcShader, &ptModule))
200+
return NULL;
201+
202+
plShaderModule tModule = {
203+
.pcEntryFunc = PyUnicode_AsUTF8(PyTuple_GetItem(ptModule, 2)),
204+
.szCodeSize = PyLong_AsSize_t(PyTuple_GetItem(ptModule, 0)),
205+
.puCode = PyCapsule_GetPointer(PyTuple_GetItem(ptModule, 1), "plShaderModule.puCode")
206+
};
207+
gptShader->write_to_disk(pcShader, &tModule);
208+
Py_RETURN_NONE;
209+
}
210+
211+
plPythonIntConstantPair gatShaderIntPairs[] = {
212+
PL_ADD_INT_CONSTANT(PL_SHADER_FLAGS_NONE),
213+
PL_ADD_INT_CONSTANT(PL_SHADER_FLAGS_INCLUDE_DEBUG),
214+
PL_ADD_INT_CONSTANT(PL_SHADER_FLAGS_ALWAYS_COMPILE),
215+
PL_ADD_INT_CONSTANT(PL_SHADER_FLAGS_NEVER_CACHE),
216+
PL_ADD_INT_CONSTANT(PL_SHADER_FLAGS_METAL_OUTPUT),
217+
PL_ADD_INT_CONSTANT(PL_SHADER_FLAGS_SPIRV_OUTPUT),
218+
PL_ADD_INT_CONSTANT(PL_SHADER_FLAGS_AUTO_OUTPUT),
219+
220+
PL_ADD_INT_CONSTANT(PL_SHADER_OPTIMIZATION_NONE),
221+
PL_ADD_INT_CONSTANT(PL_SHADER_OPTIMIZATION_SIZE),
222+
PL_ADD_INT_CONSTANT(PL_SHADER_OPTIMIZATION_PERFORMANCE),
223+
};

0 commit comments

Comments
 (0)