Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
prior to v2.47
  • Loading branch information
paddywwoof committed Aug 29, 2021
2 parents 4ddc3cd + 4dbdaa4 commit b34ca50
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 26 deletions.
20 changes: 18 additions & 2 deletions pi3d/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,22 @@ def _windows():
return platform, bcm, openegl, opengles # opengles now determined by platform

def _darwin():
pass
"""
Tested on macOS for apple silicon (M1). Actual there seems no port for EGL, so only glx is supported.
XQuartz has to be installed and running (X11 server)
ensure DYLD_FALLBACK_LIBRARY_PATH is defined
- export DYLD_FALLBACK_LIBRARY_PATH="/opt/X11/lib" or
- export DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib"
"""
from ctypes.util import find_library
platform = PLATFORM_OSX
bcm = None

openegl = None
opengles_name = find_library('GLESv2.2')
opengles = _load_library(opengles_name)

return platform, bcm, openegl, opengles # opengles now determined by platform

_PLATFORMS = {
'linux': _linux,
Expand All @@ -173,7 +188,8 @@ def _detect_platform_and_load_libraries():
if not loader:
raise Exception("Couldn't understand platform %s" % platform_name)
platform, bcm, openegl, opengles = loader()
set_egl_function_args(openegl) # function defined in constants/elg.py
if openegl != None:
set_egl_function_args(openegl) # function defined in constants/elg.py
set_gles_function_args(opengles) #function defined in constants/gl.py

return platform, bcm, openegl, opengles
Expand Down
2 changes: 1 addition & 1 deletion pi3d/shaders/clashtest.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#version 120
//precision mediump float;
//precision highp float;

varying vec2 texcoordout;
varying float dist;
Expand Down
2 changes: 1 addition & 1 deletion pi3d/shaders/clashtest.vs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#version 120
//precision mediump float;
//precision highp float;


attribute vec3 vertex;
Expand Down
2 changes: 1 addition & 1 deletion pi3d/shaders/conway.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#version 120
//precision mediump float;
//precision highp float;

uniform sampler2D tex0;
uniform vec3 unib[5];
Expand Down
2 changes: 1 addition & 1 deletion pi3d/shaders/conway.vs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
varying vec2 pix_inv;

void main(void) {
pix_inv = vec2(1.0, 1.0) / (unif[15].xy + vec2(+0.5, +0.5)); // do this division once per vertex as slow per pixel
pix_inv = vec2(1.0, 1.0) / (unif[15].xy - vec2(0.5, 0.5)); // do this division once per vertex as slow per pixel
gl_Position = vec4(vertex, 1.0);
}
2 changes: 1 addition & 1 deletion pi3d/shaders/mat_pointsprite.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#version 120
//precision mediump float;
//precision highp float;

uniform vec3 unib[5];
//uniform float hardness => unib[0][0]
Expand Down
2 changes: 1 addition & 1 deletion pi3d/shaders/mat_pointsprite.vs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#version 120
//precision mediump float;
//precision highp float;

attribute vec3 vertex;
attribute vec3 normal;
Expand Down
2 changes: 1 addition & 1 deletion pi3d/shaders/star.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#version 120
//precision mediump float;
//precision highp float;

uniform sampler2D tex0;
uniform vec3 unif[20]; // hpe
Expand Down
2 changes: 1 addition & 1 deletion pi3d/shaders/star.vs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#version 120
//precision mediump float;
//precision highp float;

attribute vec3 vertex;
attribute vec2 texcoord;
Expand Down
2 changes: 1 addition & 1 deletion pi3d/shaders/std_head_fs.inc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ----- boiler-plate code for fragment shader variable definition
#version 120
//precision mediump float;
//precision highp float;

uniform sampler2D tex0;
uniform sampler2D tex1;
Expand Down
2 changes: 1 addition & 1 deletion pi3d/shaders/std_head_vs.inc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ----- boiler-plate code for vertex shader variable definition
#version 120
//precision mediump float;
//precision highp float;

attribute vec3 vertex;
attribute vec3 normal;
Expand Down
2 changes: 1 addition & 1 deletion pi3d/shaders/uv_pointsprite.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#version 120
//precision mediump float;
//precision highp float;

uniform sampler2D tex0;
uniform vec3 unib[5];
Expand Down
2 changes: 1 addition & 1 deletion pi3d/shaders/uv_pointsprite.vs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#version 120
//precision mediump float;
//precision highp float;

attribute vec3 vertex;
attribute vec3 normal;
Expand Down
15 changes: 8 additions & 7 deletions pi3d/util/DisplayOpenGL.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ def __init__(self):
display_name = None #previous to RPi4 this worked but now problems..
for f in os.listdir('/tmp/.X11-unix'):
display_name = b':' + f[1:].encode('utf-8')
if display_name == b':0':
break # use X0 if this exist, else use last in list (which might work!)
self.d = xlib.XOpenDisplay(display_name)
if self.d:
self.screen = xlib.XDefaultScreenOfDisplay(self.d)
self.width, self.height = xlib.XWidthOfScreen(self.screen), xlib.XHeightOfScreen(self.screen)
else:
#if display_name == b':0':
# break # use X0 if this exist, else use last in list (which might work!)
self.d = xlib.XOpenDisplay(display_name) # return NULL from X function or address if sucessful
if self.d:
self.screen = xlib.XDefaultScreenOfDisplay(self.d)
self.width, self.height = xlib.XWidthOfScreen(self.screen), xlib.XHeightOfScreen(self.screen)
break # as soon as first valid display found. TODO mulitple displays?
if not self.d:
print('************************\nX11 needs to be running\n************************')
assert False, 'Couldnt open DISPLAY {}'.format(display_name)

Expand Down
2 changes: 1 addition & 1 deletion pi3d/util/Scenery.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def check_scenery(self, xm, zm):

if (dx * dx + dz * dz) < s_item.threshold_sq:
if s_item.status == 0:
if not self.thr.isAlive():
if not self.thr.is_alive():
self.thr = Thread(target=load_scenery)
self.thr.daemon = True
self.thr.start()
Expand Down
6 changes: 3 additions & 3 deletions pi3d/util/TextBlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def set_colour(self, colour=None, alpha=None):

#Fill an array with the colour to copy to the manager normals
#rotation is included for efficiency
normal = np.zeros((3), dtype=np.float)
normal = np.zeros((3), dtype=float)
normal[0] = textBlock.rot + textBlock.char_rot
normal[1] = (self.colour[1] * 0.999) + (math.floor(self.colour[0] * 999))
normal[2] = (self.colour[3] * 0.999) + (math.floor(self.colour[2] * 999))
Expand Down Expand Up @@ -84,7 +84,7 @@ def set_colour(self, colour1=None, colour2=None):
hsv1 = colorsys.rgb_to_hsv(colour1[0], colour1[1], colour1[2])
hsv2 = colorsys.rgb_to_hsv(colour2[0], colour2[1], colour2[2])

normal = np.zeros((3), dtype=np.float)
normal = np.zeros((3), dtype=float)
normal[0] = textBlock.rot + textBlock.char_rot

tlen = textBlock._string_length # alias for brevity below
Expand Down Expand Up @@ -192,7 +192,7 @@ def set_position(self, x=None, y=None, z=None, rot=None):
size_pos += math.trunc(self.z * 10.0) # depth has resolution of 0.1m and range of 25.5m
pos = [self.x, self.y, size_pos]

locations = np.zeros((self.char_count, 3), dtype=np.float)
locations = np.zeros((self.char_count, 3), dtype=float)
(c, s) = (np.cos(self.rot), np.sin(self.rot))
matrix = np.array([[c, -s], [s, c]])
locations[:,:2] = matrix.dot(self.char_offsets[:,:2].T).T
Expand Down
6 changes: 5 additions & 1 deletion pyxlib/glx.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from ctypes import (CDLL, Structure, Union, c_char, c_short, c_int, c_int64, c_uint,
c_long, c_ulong, CFUNCTYPE, POINTER)
from ctypes.util import find_library
from pi3d.constants import PLATFORM, PLATFORM_OSX
from .x import XID, VisualID, Colormap
from pyxlib import xlib

glx_name = find_library('GLX')
if PLATFORM == PLATFORM_OSX:
glx_name = find_library('GL')
else:
glx_name = find_library('GLX')
libGLX = CDLL(glx_name)

GLX_VERSION_1_1 = 1
Expand Down

0 comments on commit b34ca50

Please sign in to comment.