ncca-ngl 0.1.0__py3-none-any.whl → 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ncca_ngl-0.1.0.dist-info → ncca_ngl-0.1.1.dist-info}/METADATA +9 -9
- ncca_ngl-0.1.1.dist-info/RECORD +4 -0
- {ncca_ngl-0.1.0.dist-info → ncca_ngl-0.1.1.dist-info}/WHEEL +1 -2
- ncca/ngl/PrimData/pack_arrays.py +0 -20
- ncca/ngl/__init__.py +0 -100
- ncca/ngl/abstract_vao.py +0 -89
- ncca/ngl/base_mesh.py +0 -170
- ncca/ngl/base_mesh.pyi +0 -11
- ncca/ngl/bbox.py +0 -224
- ncca/ngl/bezier_curve.py +0 -75
- ncca/ngl/first_person_camera.py +0 -174
- ncca/ngl/image.py +0 -94
- ncca/ngl/log.py +0 -44
- ncca/ngl/mat2.py +0 -128
- ncca/ngl/mat3.py +0 -466
- ncca/ngl/mat4.py +0 -456
- ncca/ngl/multi_buffer_vao.py +0 -49
- ncca/ngl/obj.py +0 -416
- ncca/ngl/plane.py +0 -47
- ncca/ngl/primitives.py +0 -706
- ncca/ngl/pyside_event_handling_mixin.py +0 -318
- ncca/ngl/quaternion.py +0 -112
- ncca/ngl/random.py +0 -167
- ncca/ngl/shader.py +0 -229
- ncca/ngl/shader_lib.py +0 -536
- ncca/ngl/shader_program.py +0 -816
- ncca/ngl/simple_index_vao.py +0 -65
- ncca/ngl/simple_vao.py +0 -42
- ncca/ngl/text.py +0 -346
- ncca/ngl/texture.py +0 -75
- ncca/ngl/transform.py +0 -95
- ncca/ngl/util.py +0 -128
- ncca/ngl/vao_factory.py +0 -34
- ncca/ngl/vec2.py +0 -350
- ncca/ngl/vec2_array.py +0 -106
- ncca/ngl/vec3.py +0 -401
- ncca/ngl/vec3_array.py +0 -110
- ncca/ngl/vec4.py +0 -229
- ncca/ngl/vec4_array.py +0 -106
- ncca_ngl-0.1.0.dist-info/RECORD +0 -41
- ncca_ngl-0.1.0.dist-info/top_level.txt +0 -1
- {ncca_ngl-0.1.0.dist-info → ncca_ngl-0.1.1.dist-info}/licenses/LICENSE.txt +0 -0
ncca/ngl/shader.py
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from enum import Enum
|
|
4
|
-
|
|
5
|
-
import OpenGL.GL as gl
|
|
6
|
-
|
|
7
|
-
from .log import logger
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class ShaderType(Enum):
|
|
11
|
-
"""
|
|
12
|
-
Enum representing the different types of OpenGL shaders.
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
VERTEX = gl.GL_VERTEX_SHADER
|
|
16
|
-
FRAGMENT = gl.GL_FRAGMENT_SHADER
|
|
17
|
-
GEOMETRY = gl.GL_GEOMETRY_SHADER
|
|
18
|
-
TESSCONTROL = gl.GL_TESS_CONTROL_SHADER
|
|
19
|
-
TESSEVAL = gl.GL_TESS_EVALUATION_SHADER
|
|
20
|
-
COMPUTE = gl.GL_COMPUTE_SHADER
|
|
21
|
-
NONE = -1
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class MatrixTranspose(Enum):
|
|
25
|
-
"""
|
|
26
|
-
Enum for matrix transpose options (currently both set to GL_TRUE).
|
|
27
|
-
"""
|
|
28
|
-
|
|
29
|
-
TransposeOn = gl.GL_TRUE
|
|
30
|
-
TransposeOff = gl.GL_TRUE
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class Shader:
|
|
34
|
-
"""
|
|
35
|
-
Class representing an OpenGL shader object.
|
|
36
|
-
Handles loading, compiling, and editing shader source code.
|
|
37
|
-
"""
|
|
38
|
-
|
|
39
|
-
def __init__(self, name: str, type: int, exit_on_error: bool = True):
|
|
40
|
-
"""
|
|
41
|
-
Initialize a Shader object.
|
|
42
|
-
|
|
43
|
-
Args:
|
|
44
|
-
name: Name of the shader (for logging/debugging).
|
|
45
|
-
type: OpenGL shader type (e.g., gl.GL_VERTEX_SHADER).
|
|
46
|
-
exit_on_error: Whether to exit the program on compilation error.
|
|
47
|
-
"""
|
|
48
|
-
self._name: str = name
|
|
49
|
-
self._type: int = type
|
|
50
|
-
self._exit_on_error: bool = exit_on_error
|
|
51
|
-
self._id: int = gl.glCreateShader(type)
|
|
52
|
-
self._source: str = ""
|
|
53
|
-
|
|
54
|
-
def load(self, source_file: str) -> None:
|
|
55
|
-
"""
|
|
56
|
-
Load shader source code from a file and set it for this shader.
|
|
57
|
-
|
|
58
|
-
Args:
|
|
59
|
-
source_file: Path to the shader source file.
|
|
60
|
-
"""
|
|
61
|
-
with open(source_file, "r") as f:
|
|
62
|
-
self._source = f.read()
|
|
63
|
-
gl.glShaderSource(self._id, self._source)
|
|
64
|
-
|
|
65
|
-
def compile(self) -> bool:
|
|
66
|
-
"""
|
|
67
|
-
Compile the shader source code.
|
|
68
|
-
|
|
69
|
-
Returns:
|
|
70
|
-
bool: True if compilation succeeded, False otherwise.
|
|
71
|
-
"""
|
|
72
|
-
gl.glCompileShader(self._id)
|
|
73
|
-
if gl.glGetShaderiv(self._id, gl.GL_COMPILE_STATUS) != gl.GL_TRUE:
|
|
74
|
-
info = gl.glGetShaderInfoLog(self._id)
|
|
75
|
-
logger.error(f"Error compiling shader {self._name=}: {info=}")
|
|
76
|
-
if self._exit_on_error:
|
|
77
|
-
exit()
|
|
78
|
-
return False
|
|
79
|
-
return True
|
|
80
|
-
|
|
81
|
-
def edit_shader(self, to_find: str, replace_with: str) -> bool:
|
|
82
|
-
"""
|
|
83
|
-
Edit the shader source code by replacing a substring and update the shader.
|
|
84
|
-
|
|
85
|
-
Args:
|
|
86
|
-
to_find: Substring to find in the shader source.
|
|
87
|
-
replace_with: Substring to replace with.
|
|
88
|
-
|
|
89
|
-
Returns:
|
|
90
|
-
bool: True if the edit was successful, False otherwise.
|
|
91
|
-
"""
|
|
92
|
-
if self._source:
|
|
93
|
-
self._source = self._source.replace(to_find, replace_with)
|
|
94
|
-
gl.glShaderSource(self._id, self._source)
|
|
95
|
-
return True
|
|
96
|
-
return False
|
|
97
|
-
|
|
98
|
-
def reset_edits(self) -> None:
|
|
99
|
-
"""
|
|
100
|
-
Reset the shader source code to the current stored source.
|
|
101
|
-
"""
|
|
102
|
-
if self._source:
|
|
103
|
-
gl.glShaderSource(self._id, self._source)
|
|
104
|
-
|
|
105
|
-
def load_shader_source_from_string(self, shader_source: str) -> None:
|
|
106
|
-
"""
|
|
107
|
-
Load shader source code from a string and set it for this shader.
|
|
108
|
-
|
|
109
|
-
Args:
|
|
110
|
-
shader_source: Shader source code as a string.
|
|
111
|
-
"""
|
|
112
|
-
self._source = shader_source
|
|
113
|
-
gl.glShaderSource(self._id, self._source)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
# class ShaderProgram:
|
|
117
|
-
# def __init__(self, name: str, exit_on_error: bool = True):
|
|
118
|
-
# self._name = name
|
|
119
|
-
# self._exit_on_error = exit_on_error
|
|
120
|
-
# self._id = gl.glCreateProgram()
|
|
121
|
-
# self._shaders = []
|
|
122
|
-
# self._uniforms = {}
|
|
123
|
-
|
|
124
|
-
# def attach_shader(self, shader: Shader):
|
|
125
|
-
# gl.glAttachShader(self._id, shader._id)
|
|
126
|
-
# self._shaders.append(shader)
|
|
127
|
-
|
|
128
|
-
# def link(self) -> bool:
|
|
129
|
-
# gl.glLinkProgram(self._id)
|
|
130
|
-
# if gl.glGetProgramiv(self._id, gl.GL_LINK_STATUS) != gl.GL_TRUE:
|
|
131
|
-
# info = gl.glGetProgramInfoLog(self._id)
|
|
132
|
-
# print(f"Error linking program {self._name}: {info}")
|
|
133
|
-
# if self._exit_on_error:
|
|
134
|
-
# exit()
|
|
135
|
-
# return False
|
|
136
|
-
# return True
|
|
137
|
-
|
|
138
|
-
# def use(self):
|
|
139
|
-
# gl.glUseProgram(self._id)
|
|
140
|
-
|
|
141
|
-
# def get_id(self) -> int:
|
|
142
|
-
# return self._id
|
|
143
|
-
|
|
144
|
-
# def get_uniform_location(self, name: str) -> int:
|
|
145
|
-
# if name not in self._uniforms:
|
|
146
|
-
# self._uniforms[name] = gl.glGetUniformLocation(self._id, name)
|
|
147
|
-
# return self._uniforms[name]
|
|
148
|
-
|
|
149
|
-
# def set_uniform(self, name: str, *value):
|
|
150
|
-
# loc = self.get_uniform_location(name)
|
|
151
|
-
# if loc != -1:
|
|
152
|
-
# if len(value) == 1:
|
|
153
|
-
# if isinstance(value[0], int):
|
|
154
|
-
# gl.glUniform1i(loc, value[0])
|
|
155
|
-
# elif isinstance(value[0], float):
|
|
156
|
-
# gl.glUniform1f(loc, value[0])
|
|
157
|
-
# else:
|
|
158
|
-
# try:
|
|
159
|
-
# val = list(value[0])
|
|
160
|
-
# if len(val) == 4:
|
|
161
|
-
# gl.glUniformMatrix2fv(loc, 1, gl.GL_TRUE, (ctypes.c_float * 4)(*val))
|
|
162
|
-
# elif len(val) == 9:
|
|
163
|
-
# gl.glUniformMatrix3fv(loc, 1, gl.GL_TRUE, (ctypes.c_float * 9)(*val))
|
|
164
|
-
# elif len(val) == 16:
|
|
165
|
-
# gl.glUniformMatrix4fv(loc, 1, gl.GL_TRUE, (ctypes.c_float * 16)(*val))
|
|
166
|
-
# except TypeError:
|
|
167
|
-
# pass
|
|
168
|
-
# elif len(value) == 2:
|
|
169
|
-
# gl.glUniform2f(loc, *value)
|
|
170
|
-
# elif len(value) == 3:
|
|
171
|
-
# gl.glUniform3f(loc, *value)
|
|
172
|
-
# elif len(value) == 4:
|
|
173
|
-
# gl.glUniform4f(loc, *value)
|
|
174
|
-
|
|
175
|
-
# def get_uniform_1f(self, name: str) -> float:
|
|
176
|
-
# loc = self.get_uniform_location(name)
|
|
177
|
-
# if loc != -1:
|
|
178
|
-
# result = (ctypes.c_float * 1)()
|
|
179
|
-
# gl.glGetUniformfv(self._id, loc, result)
|
|
180
|
-
# return result[0]
|
|
181
|
-
# return 0.0
|
|
182
|
-
|
|
183
|
-
# def get_uniform_2f(self, name: str) -> list[float]:
|
|
184
|
-
# loc = self.get_uniform_location(name)
|
|
185
|
-
# if loc != -1:
|
|
186
|
-
# result = (ctypes.c_float * 2)()
|
|
187
|
-
# gl.glGetUniformfv(self._id, loc, result)
|
|
188
|
-
# return list(result)
|
|
189
|
-
# return [0.0, 0.0]
|
|
190
|
-
|
|
191
|
-
# def get_uniform_3f(self, name: str) -> list[float]:
|
|
192
|
-
# loc = self.get_uniform_location(name)
|
|
193
|
-
# if loc != -1:
|
|
194
|
-
# result = (ctypes.c_float * 3)()
|
|
195
|
-
# gl.glGetUniformfv(self._id, loc, result)
|
|
196
|
-
# return list(result)
|
|
197
|
-
# return [0.0, 0.0, 0.0]
|
|
198
|
-
|
|
199
|
-
# def get_uniform_4f(self, name: str) -> list[float]:
|
|
200
|
-
# loc = self.get_uniform_location(name)
|
|
201
|
-
# if loc != -1:
|
|
202
|
-
# result = (ctypes.c_float * 4)()
|
|
203
|
-
# gl.glGetUniformfv(self._id, loc, result)
|
|
204
|
-
# return list(result)
|
|
205
|
-
# return [0.0, 0.0, 0.0, 0.0]
|
|
206
|
-
|
|
207
|
-
# def get_uniform_mat2(self, name: str) -> list[float]:
|
|
208
|
-
# loc = self.get_uniform_location(name)
|
|
209
|
-
# if loc != -1:
|
|
210
|
-
# result = (ctypes.c_float * 4)()
|
|
211
|
-
# gl.glGetUniformfv(self._id, loc, result)
|
|
212
|
-
# return list(result)
|
|
213
|
-
# return [0.0] * 4
|
|
214
|
-
|
|
215
|
-
# def get_uniform_mat3(self, name: str) -> list[float]:
|
|
216
|
-
# loc = self.get_uniform_location(name)
|
|
217
|
-
# if loc != -1:
|
|
218
|
-
# result = (ctypes.c_float * 9)()
|
|
219
|
-
# gl.glGetUniformfv(self._id, loc, result)
|
|
220
|
-
# return list(result)
|
|
221
|
-
# return [0.0] * 9
|
|
222
|
-
|
|
223
|
-
# def get_uniform_mat4(self, name: str) -> list[float]:
|
|
224
|
-
# loc = self.get_uniform_location(name)
|
|
225
|
-
# if loc != -1:
|
|
226
|
-
# result = (ctypes.c_float * 16)()
|
|
227
|
-
# gl.glGetUniformfv(self._id, loc, result)
|
|
228
|
-
# return list(result)
|
|
229
|
-
# return [0.0] * 16
|