Skip to content

Commit bdd2fbe

Browse files
committed
Merge pull request processing#3583 from gohai/arm-3.0-for-ben7
Second bunch of arm patches (v5)
2 parents 7adcba2 + 8d7c537 commit bdd2fbe

File tree

14 files changed

+419
-37
lines changed

14 files changed

+419
-37
lines changed

app/src/processing/app/Base.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public class Base {
9898
}
9999
}
100100

101+
static String nativeArch = System.getProperty("os.arch");
102+
101103
static private boolean commandLine;
102104

103105
// A single instance of the preferences window
@@ -1543,6 +1545,30 @@ static public int getNativeBits() {
15431545
return nativeBits;
15441546
}
15451547

1548+
/**
1549+
* Return the value of the os.arch propery
1550+
*/
1551+
static public String getNativeArch() {
1552+
return nativeArch;
1553+
}
1554+
1555+
/*
1556+
* Return a string that identifies the variant of a platform
1557+
* e.g. "32" or "64" on Intel
1558+
*/
1559+
static public String getVariant() {
1560+
return getVariant(PApplet.platform, getNativeArch(), getNativeBits());
1561+
}
1562+
1563+
static public String getVariant(int platform, String arch, int bits) {
1564+
if (platform == PConstants.LINUX && bits == 32 && "arm".equals(Base.getNativeArch())) {
1565+
// assume armv6hf for now
1566+
return "armv6hf";
1567+
} else {
1568+
// 32 or 64
1569+
return Integer.toString(bits);
1570+
}
1571+
}
15461572

15471573
/*
15481574
static public String getPlatformName() {

app/src/processing/app/Library.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ private Library(File folder, String groupName) {
173173
String platformName = platformNames[i];
174174
String platformName32 = platformName + "32";
175175
String platformName64 = platformName + "64";
176+
String platformNameArmv6hh = platformName + "-armv6hf";
176177

177178
// First check for things like 'application.macosx=' or 'application.windows32' in the export.txt file.
178179
// These will override anything in the platform-specific subfolders.
@@ -182,6 +183,8 @@ private Library(File folder, String groupName) {
182183
String[] platformList32 = platform32 == null ? null : PApplet.splitTokens(platform32, ", ");
183184
String platform64 = exportTable.get("application." + platformName + "64");
184185
String[] platformList64 = platform64 == null ? null : PApplet.splitTokens(platform64, ", ");
186+
String platformArmv6hf = exportTable.get("application." + platformName + "-armv6hf");
187+
String[] platformListArmv6hf = platformArmv6hf == null ? null : PApplet.splitTokens(platformArmv6hf, ", ");
185188

186189
// If nothing specified in the export.txt entries, look for the platform-specific folders.
187190
if (platformAll == null) {
@@ -193,14 +196,17 @@ private Library(File folder, String groupName) {
193196
if (platform64 == null) {
194197
platformList64 = listPlatformEntries(libraryFolder, platformName64, baseList);
195198
}
199+
if (platformListArmv6hf == null) {
200+
platformListArmv6hf = listPlatformEntries(libraryFolder, platformNameArmv6hh, baseList);
201+
}
196202

197-
if (platformList32 != null || platformList64 != null) {
203+
if (platformList32 != null || platformList64 != null || platformListArmv6hf != null) {
198204
multipleArch[i] = true;
199205
}
200206

201207
// if there aren't any relevant imports specified or in their own folders,
202208
// then use the baseList (root of the library folder) as the default.
203-
if (platformList == null && platformList32 == null && platformList64 == null) {
209+
if (platformList == null && platformList32 == null && platformList64 == null && platformListArmv6hf == null) {
204210
exportList.put(platformName, baseList);
205211

206212
} else {
@@ -215,6 +221,9 @@ private Library(File folder, String groupName) {
215221
if (platformList64 != null) {
216222
exportList.put(platformName64, platformList64);
217223
}
224+
if (platformListArmv6hf != null) {
225+
exportList.put(platformNameArmv6hh, platformListArmv6hf);
226+
}
218227
}
219228
}
220229
// for (String p : exportList.keySet()) {
@@ -369,8 +378,8 @@ public File[] getAppletExports() {
369378
}
370379

371380

372-
public File[] getApplicationExports(int platform, int bits) {
373-
String[] list = getApplicationExportList(platform, bits);
381+
public File[] getApplicationExports(int platform, String variant) {
382+
String[] list = getApplicationExportList(platform, variant);
374383
return wrapFiles(list);
375384
}
376385

@@ -380,14 +389,17 @@ public File[] getApplicationExports(int platform, int bits) {
380389
* If no 32 or 64-bit version of the exports exists, it returns the version
381390
* that doesn't specify bit depth.
382391
*/
383-
public String[] getApplicationExportList(int platform, int bits) {
392+
public String[] getApplicationExportList(int platform, String variant) {
384393
String platformName = PConstants.platformNames[platform];
385-
if (bits == 32) {
394+
if (variant.equals("32")) {
386395
String[] pieces = exportList.get(platformName + "32");
387396
if (pieces != null) return pieces;
388-
} else if (bits == 64) {
397+
} else if (variant.equals("64")) {
389398
String[] pieces = exportList.get(platformName + "64");
390399
if (pieces != null) return pieces;
400+
} else if (variant.equals("armv6hf")) {
401+
String[] pieces = exportList.get(platformName + "-armv6hf");
402+
if (pieces != null) return pieces;
391403
}
392404
return exportList.get(platformName);
393405
}
@@ -408,12 +420,12 @@ public boolean hasMultipleArch(int platform) {
408420
}
409421

410422

411-
public boolean supportsArch(int platform, int bits) {
423+
public boolean supportsArch(int platform, String variant) {
412424
// If this is a universal library, or has no natives, then we're good.
413425
if (multipleArch[platform] == false) {
414426
return true;
415427
}
416-
return getApplicationExportList(platform, bits) != null;
428+
return getApplicationExportList(platform, variant) != null;
417429
}
418430

419431

build/build.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<!-- there is currently no JRE available -->
3838
<property name="jre.download.jdk" value="true" />
3939
<property name="jre.downloader" value="linux-arm-vfp-hflt.tar.gz" />
40+
<property name="linux.dist" value="linux/processing-${version}-linux-armv6hf.tgz" />
4041
</target>
4142

4243
<!-- Require Java 8 everywhere. -->

core/build.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
<!-- Copy shaders to bin. (Eclipse does this automatically.) -->
6464
<copy todir="bin">
6565
<fileset dir="src">
66-
<include name="processing/opengl/shaders/*.glsl" />
67-
<include name="icon/*.png" />
66+
<include name="processing/opengl/shaders/*.glsl" />
67+
<include name="icon/*.png" />
6868
</fileset>
6969
</copy>
7070
</target>

core/library/export.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ application.windows32=core.jar,jogl-all.jar,gluegen-rt.jar,jogl-all-natives-wind
88
application.windows64=core.jar,jogl-all.jar,gluegen-rt.jar,jogl-all-natives-windows-amd64.jar,gluegen-rt-natives-windows-amd64.jar
99
application.linux32=core.jar,jogl-all.jar,gluegen-rt.jar,jogl-all-natives-linux-i586.jar,gluegen-rt-natives-linux-i586.jar
1010
application.linux64=core.jar,jogl-all.jar,gluegen-rt.jar,jogl-all-natives-linux-amd64.jar,gluegen-rt-natives-linux-amd64.jar
11+
application.linux-armv6hf=core.jar,jogl-all.jar,gluegen-rt.jar,jogl-all-natives-linux-armv6hf.jar,gluegen-rt-natives-linux-armv6hf.jar

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7042,9 +7042,15 @@ protected void setDrawDefaults() {
70427042
if (smooth < 1) {
70437043
pgl.disable(PGL.MULTISAMPLE);
70447044
} else {
7045-
pgl.enable(PGL.MULTISAMPLE);
7045+
// work around runtime exceptions in Broadcom's VC IV driver
7046+
if (false == OPENGL_RENDERER.equals("VideoCore IV HW")) {
7047+
pgl.enable(PGL.MULTISAMPLE);
7048+
}
7049+
}
7050+
// work around runtime exceptions in Broadcom's VC IV driver
7051+
if (false == OPENGL_RENDERER.equals("VideoCore IV HW")) {
7052+
pgl.disable(PGL.POLYGON_SMOOTH);
70467053
}
7047-
pgl.disable(PGL.POLYGON_SMOOTH);
70487054

70497055
if (sized) {
70507056
// reapplySettings();
@@ -7154,14 +7160,27 @@ protected void getGLParameters() {
71547160
pgl.getIntegerv(PGL.MAX_TEXTURE_SIZE, intBuffer);
71557161
maxTextureSize = intBuffer.get(0);
71567162

7157-
pgl.getIntegerv(PGL.MAX_SAMPLES, intBuffer);
7158-
maxSamples = intBuffer.get(0);
7163+
// work around runtime exceptions in Broadcom's VC IV driver
7164+
if (false == OPENGL_RENDERER.equals("VideoCore IV HW")) {
7165+
pgl.getIntegerv(PGL.MAX_SAMPLES, intBuffer);
7166+
maxSamples = intBuffer.get(0);
7167+
}
71597168

71607169
if (anisoSamplingSupported) {
71617170
pgl.getFloatv(PGL.MAX_TEXTURE_MAX_ANISOTROPY, floatBuffer);
71627171
maxAnisoAmount = floatBuffer.get(0);
71637172
}
71647173

7174+
// overwrite the default shaders with vendor specific versions
7175+
// if needed
7176+
if (OPENGL_RENDERER.equals("VideoCore IV HW") || // Broadcom's binary driver for Raspberry Pi
7177+
OPENGL_RENDERER.equals("Gallium 0.4 on VC4")) { // Mesa driver for same hardware
7178+
defLightShaderVertURL =
7179+
PGraphicsOpenGL.class.getResource("/processing/opengl/shaders/LightVert-vc4.glsl");
7180+
defTexlightShaderVertURL =
7181+
PGraphicsOpenGL.class.getResource("/processing/opengl/shaders/TexLightVert-vc4.glsl");
7182+
}
7183+
71657184
glParamsRead = true;
71667185
}
71677186

core/src/processing/opengl/PSurfaceJOGL.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,13 @@ protected void initGL() {
195195
if (profile == null) {
196196
if (PJOGL.profile == 2) {
197197
try {
198-
profile = GLProfile.getGL2ES1();
198+
if ("arm".equals(System.getProperty("os.arch"))) {
199+
// request at least GL2 or GLES2
200+
profile = GLProfile.getGL2ES2();
201+
} else {
202+
// stay compatible with previous versions for now
203+
profile = GLProfile.getGL2ES1();
204+
}
199205
} catch (GLException ex) {
200206
profile = GLProfile.getMaxFixedFunc(true);
201207
}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
2+
Part of the Processing project - http://processing.org
3+
4+
Copyright (c) 2011-13 Ben Fry and Casey Reas
5+
6+
This library is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License version 2.1 as published by the Free Software Foundation.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General
16+
Public License along with this library; if not, write to the
17+
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18+
Boston, MA 02111-1307 USA
19+
*/
20+
21+
#define PROCESSING_LIGHT_SHADER
22+
23+
uniform mat4 modelviewMatrix;
24+
uniform mat4 transformMatrix;
25+
uniform mat3 normalMatrix;
26+
27+
uniform int lightCount;
28+
uniform vec4 lightPosition[8];
29+
uniform vec3 lightNormal[8];
30+
uniform vec3 lightAmbient[8];
31+
uniform vec3 lightDiffuse[8];
32+
uniform vec3 lightSpecular[8];
33+
uniform vec3 lightFalloff[8];
34+
uniform vec2 lightSpot[8];
35+
36+
attribute vec4 position;
37+
attribute vec4 color;
38+
attribute vec3 normal;
39+
40+
attribute vec4 ambient;
41+
attribute vec4 specular;
42+
attribute vec4 emissive;
43+
attribute float shininess;
44+
45+
varying vec4 vertColor;
46+
varying vec4 backVertColor;
47+
48+
const float zero_float = 0.0;
49+
const float one_float = 1.0;
50+
const vec3 zero_vec3 = vec3(0);
51+
52+
float falloffFactor(vec3 lightPos, vec3 vertPos, vec3 coeff) {
53+
vec3 lpv = lightPos - vertPos;
54+
vec3 dist = vec3(one_float);
55+
dist.z = dot(lpv, lpv);
56+
dist.y = sqrt(dist.z);
57+
return one_float / dot(dist, coeff);
58+
}
59+
60+
float spotFactor(vec3 lightPos, vec3 vertPos, vec3 lightNorm, float minCos, float spotExp) {
61+
vec3 lpv = normalize(lightPos - vertPos);
62+
vec3 nln = -one_float * lightNorm;
63+
float spotCos = dot(nln, lpv);
64+
return spotCos <= minCos ? zero_float : pow(spotCos, spotExp);
65+
}
66+
67+
float lambertFactor(vec3 lightDir, vec3 vecNormal) {
68+
return max(zero_float, dot(lightDir, vecNormal));
69+
}
70+
71+
float blinnPhongFactor(vec3 lightDir, vec3 vertPos, vec3 vecNormal, float shine) {
72+
vec3 np = normalize(vertPos);
73+
vec3 ldp = normalize(lightDir - np);
74+
return pow(max(zero_float, dot(ldp, vecNormal)), shine);
75+
}
76+
77+
void main() {
78+
// Vertex in clip coordinates
79+
gl_Position = transformMatrix * position;
80+
81+
// Vertex in eye coordinates
82+
vec3 ecVertex = vec3(modelviewMatrix * position);
83+
84+
// Normal vector in eye coordinates
85+
vec3 ecNormal = normalize(normalMatrix * normal);
86+
vec3 ecNormalInv = ecNormal * -one_float;
87+
88+
// Light calculations
89+
vec3 totalAmbient = vec3(0, 0, 0);
90+
91+
vec3 totalFrontDiffuse = vec3(0, 0, 0);
92+
vec3 totalFrontSpecular = vec3(0, 0, 0);
93+
94+
vec3 totalBackDiffuse = vec3(0, 0, 0);
95+
vec3 totalBackSpecular = vec3(0, 0, 0);
96+
97+
// prevent register allocation failure by limiting ourselves to
98+
// two lights for now
99+
for (int i = 0; i < 2; i++) {
100+
if (lightCount == i) break;
101+
102+
vec3 lightPos = lightPosition[i].xyz;
103+
bool isDir = zero_float < lightPosition[i].w;
104+
float spotCos = lightSpot[i].x;
105+
float spotExp = lightSpot[i].y;
106+
107+
vec3 lightDir;
108+
float falloff;
109+
float spotf;
110+
111+
if (isDir) {
112+
falloff = one_float;
113+
lightDir = -one_float * lightNormal[i];
114+
} else {
115+
falloff = falloffFactor(lightPos, ecVertex, lightFalloff[i]);
116+
lightDir = normalize(lightPos - ecVertex);
117+
}
118+
119+
spotf = spotExp > zero_float ? spotFactor(lightPos, ecVertex, lightNormal[i],
120+
spotCos, spotExp)
121+
: one_float;
122+
123+
if (any(greaterThan(lightAmbient[i], zero_vec3))) {
124+
totalAmbient += lightAmbient[i] * falloff;
125+
}
126+
127+
if (any(greaterThan(lightDiffuse[i], zero_vec3))) {
128+
totalFrontDiffuse += lightDiffuse[i] * falloff * spotf *
129+
lambertFactor(lightDir, ecNormal);
130+
totalBackDiffuse += lightDiffuse[i] * falloff * spotf *
131+
lambertFactor(lightDir, ecNormalInv);
132+
}
133+
134+
if (any(greaterThan(lightSpecular[i], zero_vec3))) {
135+
totalFrontSpecular += lightSpecular[i] * falloff * spotf *
136+
blinnPhongFactor(lightDir, ecVertex, ecNormal, shininess);
137+
totalBackSpecular += lightSpecular[i] * falloff * spotf *
138+
blinnPhongFactor(lightDir, ecVertex, ecNormalInv, shininess);
139+
}
140+
}
141+
142+
// Calculating final color as result of all lights (plus emissive term).
143+
// Transparency is determined exclusively by the diffuse component.
144+
vertColor = vec4(totalAmbient, 0) * ambient +
145+
vec4(totalFrontDiffuse, 1) * color +
146+
vec4(totalFrontSpecular, 0) * specular +
147+
vec4(emissive.rgb, 0);
148+
149+
backVertColor = vec4(totalAmbient, 0) * ambient +
150+
vec4(totalBackDiffuse, 1) * color +
151+
vec4(totalBackSpecular, 0) * specular +
152+
vec4(emissive.rgb, 0);
153+
}

core/src/processing/opengl/shaders/LightVert.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ uniform vec4 lightPosition[8];
2929
uniform vec3 lightNormal[8];
3030
uniform vec3 lightAmbient[8];
3131
uniform vec3 lightDiffuse[8];
32-
uniform vec3 lightSpecular[8];
32+
uniform vec3 lightSpecular[8];
3333
uniform vec3 lightFalloff[8];
3434
uniform vec2 lightSpot[8];
3535

0 commit comments

Comments
 (0)