-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathcore.cpp
More file actions
159 lines (118 loc) · 4.7 KB
/
Copy pathcore.cpp
File metadata and controls
159 lines (118 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include <TinyEngine/TinyEngine>
#include <TinyEngine/camera>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/functional.h>
namespace py = pybind11;
#include "glmcast.cpp"
PYBIND11_MODULE(tiny, module){
module.doc() = "TinyEngine Python Plugin";
//Core Functions and Variables
module.def("init", &Tiny::init, "Initialize TinyEngine");
module.def("window", &Tiny::window, "Open a TinyEngine Window",
py::arg("windowName"), py::arg("width"), py::arg("height"));
module.def("quit", &Tiny::quit, "Shutdown TinyEngine");
module.def("loop", [](py::function f){ //Lambda Loop Pass
Tiny::loop([&](){ f(); });
}, "Loop a Function");
module.def("benchmark", [](bool toggle){ //Lambda Setter
Tiny::benchmark = toggle;
}, "Toggle Benchmark");
//Main Submodules
py::module view = module.def_submodule("view");
view.def("pipeline", [](const Handle& f){
Tiny::view.pipeline = f;
return;
}, "Set View Pipeline");
view.def("interface", [](const Handle& f){
Tiny::view.interface = f;
return;
}, "Set View Interface");
view.def("target", [](glm::vec3 color, bool clear){
Tiny::view.target(color, clear);
return;
}, "Target Main View");
// Settable Properties
view.def("vsync", [](bool toggle){ Tiny::view.vsync = toggle; }, "Set vsync");
view.def("linewidth", [](float set){ Tiny::view.lineWidth = set; }, "Set line width");
view.def("pointsize", [](float set){ Tiny::view.pointSize = set; }, "Set point size");
py::module event = module.def_submodule("event");
event.def("handler", [](const Handle& f){
Tiny::event.handler = f;
return;
}, "Set Event Handler");
//Utility Classes
//Buffer Class (Important)
py::class_<Buffer>(module, "Buffer")
.def(py::init<>())
.def(py::init<std::vector<float>>())
.def("fill_float", static_cast<void(Buffer::*)(std::vector<float>)>(&Buffer::fill));
//Shader Class
py::class_<ShaderBase>(module, "ShaderBase")
.def(py::init<>())
.def("use", &ShaderBase::use)
//Uniform Setters
.def("uniform", &ShaderBase::uniform<bool>)
.def("uniform", &ShaderBase::uniform<int>)
.def("uniform", &ShaderBase::uniform<float>)
.def("uniform", &ShaderBase::uniform<double>)
.def("uniform", &ShaderBase::uniform<glm::vec2>)
.def("uniform", &ShaderBase::uniform<glm::vec3>)
.def("uniform", &ShaderBase::uniform<glm::vec4>)
.def("uniform", &ShaderBase::uniform<glm::mat3>)
.def("uniform", &ShaderBase::uniform<glm::mat4>)
//Texture Setters
.def("texture", &ShaderBase::texture<Texture>)
.def("texture", &ShaderBase::texture<Cubetexture>)
//Buffering
.def_static("ssbo", static_cast<void(*)(std::string)>(&ShaderBase::ssbo), "Define an SSBO")
.def_static("ssbo", static_cast<void(*)(std::vector<std::string>)>(&ShaderBase::ssbo), "Define multiple SSBOs")
.def("interface", static_cast<void(ShaderBase::*)(std::string)>(&ShaderBase::interface), "Add named SSBO to permitted interface blocks")
.def("interface", static_cast<void(ShaderBase::*)(std::vector<std::string>)>(&ShaderBase::interface), "Add multiple named SSBOs to permitted interface blocks");
//Two more Missing!
py::class_<Shader, ShaderBase>(module, "Shader")
.def(py::init<std::vector<std::string>>())
.def(py::init<std::vector<std::string>, std::vector<std::string>>());
//Primitives and Models
py::class_<Model>(module, "Model")
.def(py::init<>())
.def(py::init<std::vector<std::string>>())
.def_readwrite("SIZE", &Model::SIZE)
.def("render", &Model::render,
py::arg("mode") = GL_TRIANGLE_STRIP)
.def("bind_vec3", &Model::bind<glm::vec3>);
py::class_<Point, Model>(module, "Point")
.def(py::init<>());
py::class_<Square2D, Model>(module, "Square2D")
.def(py::init<>());
py::class_<Square3D, Model>(module, "Square3D")
.def(py::init<>());
py::class_<Gizmo, Model>(module, "Gizmo")
.def(py::init<>());
py::module cam = module.def_submodule("cam");
//Enum and Initializer
py::enum_<cam::camtype>(cam, "type")
.value("PROJ", cam::PROJ)
.value("ORTHO", cam::ORTHO);
cam.def("init", cam::init,
py::arg("r") = 5.0f, py::arg("t") = cam::PROJ);
cam.def("handler", [](){
cam::handler();
});
//Matrix Extraction
cam.def("vp", [](){
return cam::vp;
});
// Property Setting
cam.def("zoomrate", [](float set){ cam::zoomrate = set; });
cam.def("moverate", [](float set){ cam::moverate = set; });
cam.def("near", [](float set){ cam::near = set; });
cam.def("far", [](float set){ cam::far = set; });
// OpenGL Enumerator Hack
enum EnumMap{};
py::enum_<EnumMap> enummap(module, "GL");
enummap.value("lines", (EnumMap)GL_LINES);
enummap.value("points", (EnumMap)GL_POINTS);
enummap.value("triangles", (EnumMap)GL_TRIANGLES);
enummap.value("trianglestrip", (EnumMap)GL_TRIANGLE_STRIP);
}