Bump engine submodule and move shader loading code to game.

This commit is contained in:
Roz K 2022-12-04 03:23:03 +01:00
parent 8a33228dff
commit a145a4bea3
Signed by: roz
GPG Key ID: 51FBF4E483E1C822
3 changed files with 49 additions and 4 deletions

2
engine

@ -1 +1 @@
Subproject commit 1e56cc1c28d4f9977b55f47566c3c8050f25670c Subproject commit af25548752d7ae7004a937307e06bd4810e46cc7

View File

@ -18,7 +18,8 @@ from math import pi, tau, dist
from engine import * from engine import *
from game import math, resources, camera, batch, triangles, generator, environment, sea from game import (
math, resources, shader, camera, batch, triangles, generator, environment, sea)
def main(): def main():
print("Generating terrain...") print("Generating terrain...")
@ -29,8 +30,8 @@ def main():
print("Initializing...") print("Initializing...")
window = initialize(b'RK Island', 1600, 900) window = initialize(b'RK Island', 1600, 900)
terrain_shader = load_shader(b'game/shaders/terrain') terrain_shader = shader.load('terrain')
sky_shader = load_shader(b'game/shaders/sky') sky_shader = shader.load('sky')
print("Loading resources...") print("Loading resources...")
select_shader(terrain_shader) select_shader(terrain_shader)

44
game/shader.py Normal file
View File

@ -0,0 +1,44 @@
# Copyright (C) 2022 RozK
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from pathlib import Path
from engine import load_shader
#TODO: preprocessing (at least includes)
def load(name):
def _cleanup(_line):
return _line.partition('//')[0].strip()
def _filter(_line):
return _line
def _convert(_line):
return bytes(_line, 'utf-8') + b'\n'
def load_source(_path):
if not _path.exists():
print("Cannot find", _path)
return None
return list(map(_convert, filter(_filter, map(_cleanup, open(_path, 'rt')))))
print("Loading shader", name)
path = Path('.') / 'game' / 'shaders'
vert_lines = load_source(path / (name + '_opengles.vert'))
if not vert_lines:
print("Error: Vertex shader is empty.")
return None
frag_lines = load_source(path / (name + '_opengles.frag'))
if not frag_lines:
print("Error: Fragment shader is empty.")
return None
return load_shader(vert_lines, frag_lines)