Skip to content

Commit 999928a

Browse files
committed
clean up rendering code
1 parent 17bd90f commit 999928a

File tree

5 files changed

+133
-103
lines changed

5 files changed

+133
-103
lines changed

core/src/processing/a2d/PSurfaceAndroid2D.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,7 @@ public void surfaceChanged(SurfaceHolder holder, int format, int iwidth, int ihe
110110
System.out.println("SketchSurfaceView.surfaceChanged() " + iwidth + " " + iheight);
111111
}
112112

113-
if (sketch.fullScreen) {
114-
sketch.displayWidth = iwidth;
115-
sketch.displayHeight = iheight;
116-
}
117-
sketch.width = iwidth;
118-
sketch.height = iheight;
119-
113+
sketch.setSize(iwidth, iheight);
120114
graphics.setSize(sketch.sketchWidth(), sketch.sketchHeight());
121115
sketch.surfaceChanged();
122116
}

core/src/processing/core/PApplet.java

Lines changed: 82 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ public class PApplet extends Object implements PConstants {
143143
*/
144144
public float displayDensity = 1;
145145

146+
// For future use
147+
public int pixelDensity = 1;
148+
public int pixelWidth;
149+
public int pixelHeight;
150+
146151
/** absolute x position of input on screen */
147152
public int mouseX;
148153

@@ -391,7 +396,9 @@ public class PApplet extends Object implements PConstants {
391396

392397
int smooth = 1; // default smoothing (whatever that means for the renderer)
393398

394-
public boolean fullScreen = false;
399+
boolean fullScreen = false;
400+
401+
int display = -1; // use default
395402

396403
// Background default needs to be different from the default value in
397404
// PGraphics.backgroundColor, otherwise size(100, 100) bg spills over.
@@ -463,6 +470,9 @@ public void initSurface(LayoutInflater inflater, ViewGroup container,
463470
}
464471
}
465472

473+
pixelWidth = width * pixelDensity;
474+
pixelHeight = height * pixelDensity;
475+
466476
String rendererName = sketchRenderer();
467477
if (DEBUG) println("Renderer " + rendererName);
468478
g = makeGraphics(width, height, rendererName, true);
@@ -684,6 +694,57 @@ public void settings() {
684694
}
685695

686696

697+
final public int sketchWidth() {
698+
return width;
699+
}
700+
701+
702+
final public int sketchHeight() {
703+
return height;
704+
}
705+
706+
707+
final public String sketchRenderer() {
708+
return renderer;
709+
}
710+
711+
712+
public int sketchSmooth() {
713+
return smooth;
714+
}
715+
716+
717+
final public boolean sketchFullScreen() {
718+
//return false;
719+
return fullScreen;
720+
}
721+
722+
723+
final public int sketchDisplay() {
724+
return display;
725+
}
726+
727+
728+
final public String sketchOutputPath() {
729+
return null;
730+
}
731+
732+
733+
final public OutputStream sketchOutputStream() {
734+
return null;
735+
}
736+
737+
738+
final public int sketchWindowColor() {
739+
return windowColor;
740+
}
741+
742+
743+
final public int sketchPixelDensity() {
744+
return pixelDensity;
745+
}
746+
747+
687748
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
688749

689750

@@ -742,59 +803,6 @@ public void surfaceKeyUp(int code, android.view.KeyEvent event) {
742803
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
743804

744805

745-
public int sketchQuality() {
746-
return 1;
747-
}
748-
749-
public int sketchKind() {
750-
return AppComponent.FRAGMENT;
751-
}
752-
753-
final public int sketchWidth() {
754-
if (fullScreen) {
755-
return displayWidth;
756-
}
757-
return width;
758-
}
759-
760-
761-
final public int sketchHeight() {
762-
if (fullScreen) {
763-
return displayHeight;
764-
}
765-
return height;
766-
}
767-
768-
769-
final public String sketchRenderer() {
770-
return renderer;
771-
}
772-
773-
774-
final public int sketchWindowColor() {
775-
return windowColor;
776-
}
777-
778-
779-
public void orientation(int which) {
780-
surface.setOrientation(which);
781-
}
782-
783-
784-
public boolean checkPermission(String permission) {
785-
Context context = surface.getContext();
786-
if (context != null) {
787-
int check = ContextCompat.checkSelfPermission(context, permission);
788-
return check == PackageManager.PERMISSION_GRANTED;
789-
} else {
790-
return false;
791-
}
792-
}
793-
794-
795-
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
796-
797-
798806
/**
799807
* Called by the browser or applet viewer to inform this applet that it
800808
* should start its execution. It is called after the init method and
@@ -1279,6 +1287,18 @@ public void size(int iwidth, int iheight, String irenderer) {
12791287
}
12801288

12811289

1290+
public void setSize(int width, int height) {
1291+
if (fullScreen) {
1292+
this.displayWidth = width;
1293+
this.displayHeight = height;
1294+
}
1295+
this.width = width;
1296+
this.height = height;
1297+
pixelWidth = width * pixelDensity;
1298+
pixelHeight = height * pixelDensity;
1299+
}
1300+
1301+
12821302
//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12831303

12841304

@@ -1314,6 +1334,14 @@ private void smoothWarning(String method) {
13141334
}
13151335

13161336

1337+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1338+
1339+
1340+
public void orientation(int which) {
1341+
surface.setOrientation(which);
1342+
}
1343+
1344+
13171345
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13181346

13191347

core/src/processing/opengl/PSurfaceGLES.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,15 @@ public SketchSurfaceViewGL(Context context, SurfaceHolder holder) {
115115

116116
SurfaceHolder h = getHolder();
117117
h.addCallback(this);
118-
h.setType(SurfaceHolder.SURFACE_TYPE_GPU);
119118

120119
// Tells the default EGLContextFactory and EGLConfigChooser to create an GLES2 context.
121120
setEGLContextClientVersion(2);
122121
setPreserveEGLContextOnPause(true);
123122

124-
int quality = sketch.sketchQuality();
125-
if (1 < quality) {
126-
setEGLConfigChooser(getConfigChooser(quality));
127-
}
123+
int samples = sketch.sketchSmooth();
124+
System.out.println("Using smooth level " + samples);
125+
setEGLConfigChooser(getConfigChooser(samples));
126+
128127
// The renderer can be set only once.
129128
setRenderer(getRenderer());
130129
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
@@ -238,9 +237,15 @@ public AndroidContextFactory getContextFactory() {
238237
return new AndroidContextFactory();
239238
}
240239

240+
public AndroidConfigChooser getConfigChooser() {
241+
return new AndroidConfigChooser(8, 8, 8, 8, 16, 8, 1);
242+
// return new AndroidConfigChooser(5, 6, 5, 4, 16, 1, samples);
243+
}
244+
241245

242246
public AndroidConfigChooser getConfigChooser(int samples) {
243-
return new AndroidConfigChooser(5, 6, 5, 4, 16, 1, samples);
247+
return new AndroidConfigChooser(8, 8, 8, 8, 16, 8, samples);
248+
// return new AndroidConfigChooser(5, 6, 5, 4, 16, 1, samples);
244249
}
245250

246251

@@ -272,13 +277,7 @@ public void onSurfaceChanged(GL10 igl, int iwidth, int iheight) {
272277
// Here is where we should initialize native libs...
273278
// lib.init(iwidth, iheight);
274279

275-
if (sketch.fullScreen) {
276-
sketch.displayWidth = iwidth;
277-
sketch.displayHeight = iheight;
278-
}
279-
sketch.width = iwidth;
280-
sketch.height = iheight;
281-
280+
sketch.setSize(iwidth, iheight);
282281
graphics.setSize(sketch.sketchWidth(), sketch.sketchHeight());
283282
sketch.surfaceChanged();
284283
}

libraries/vr/src/processing/vr/PSurfaceVR.java

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,21 @@ public PSurfaceVR(PGraphics graphics, AppComponent component, SurfaceHolder hold
6868
pvr = (PGraphicsVR)graphics;
6969

7070
glview = new GLVRSurfaceView(vrActivity);
71+
72+
// Enables/disables the transition view used to prompt the user to place
73+
// their phone into a GVR viewer.
74+
glview.setTransitionViewEnabled(true);
75+
76+
// Enables Cardboard-trigger feedback with Daydream headsets. This is a simple way of supporting
77+
// Daydream controller input for basic interactions using the existing Cardboard trigger API.
78+
glview.enableCardboardTriggerEmulation();
79+
7180
glview.setStereoModeEnabled(vr);
7281
if (vr) {
7382
glview.setDistortionCorrectionEnabled(true);
7483
glview.setNeckModelEnabled(true);
75-
// glview.setElectronicDisplayStabilizationEnabled(true);
7684
}
7785

78-
// Enable Cardboard-trigger feedback with Daydream headsets. This is a simple way of supporting
79-
// Daydream controller input for basic interactions using the existing Cardboard trigger API.
80-
glview.enableCardboardTriggerEmulation();
81-
8286
if (glview.setAsyncReprojectionEnabled(true)) {
8387
// Async reprojection decouples the app framerate from the display framerate,
8488
// allowing immersive interaction even at the throttled clockrates set by
@@ -217,32 +221,17 @@ public GLVRSurfaceView(Context context) {
217221
setFocusableInTouchMode(true);
218222
requestFocus();
219223

220-
int quality = sketch.sketchQuality();
221-
if (1 < quality) {
222-
setEGLConfigChooser(8, 8, 8, 8, 16, 1);
224+
setEGLConfigChooser(8, 8, 8, 8, 16, 8);
225+
int samples = sketch.sketchSmooth();
226+
if (1 < samples) {
227+
System.out.println("setting multisampling to " + samples);
228+
setMultisampling(samples);
223229
}
230+
224231
// The renderer can be set only once.
225232
setRenderer(getVRStereoRenderer());
226233
}
227234

228-
/*
229-
@Override
230-
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
231-
super.surfaceChanged(holder, format, w, h);
232-
233-
if (PApplet.DEBUG) {
234-
System.out.println("SketchSurfaceView3D.surfaceChanged() " + w + " " + h);
235-
}
236-
sketch.surfaceChanged();
237-
// width = w;
238-
// height = h;
239-
// g.setSize(w, h);
240-
241-
// No need to call g.setSize(width, height) b/c super.surfaceChanged()
242-
// will trigger onSurfaceChanged in the renderer, which calls setSize().
243-
// -- apparently not true? (100110)
244-
}
245-
*/
246235

247236
@Override
248237
public boolean onTouchEvent(MotionEvent event) {
@@ -280,9 +269,9 @@ public AndroidVRStereoRenderer() {
280269

281270
}
282271

283-
284272
@Override
285273
public void onNewFrame(HeadTransform transform) {
274+
hadnleGVREnumError();
286275
pgl.getGL(null);
287276
pvr.headTransform(transform);
288277
}
@@ -302,11 +291,28 @@ public void onRendererShutdown() {
302291
}
303292

304293
@Override
305-
public void onSurfaceChanged(int arg0, int arg1) {
294+
public void onSurfaceChanged(int iwidth, int iheight) {
295+
sketch.setSize(iwidth, iheight);
296+
graphics.setSize(sketch.sketchWidth(), sketch.sketchHeight());
297+
sketch.surfaceChanged();
306298
}
307299

308300
@Override
309301
public void onSurfaceCreated(EGLConfig arg0) {
310302
}
303+
304+
// Don't print the invalid enum error:
305+
// https://github.com/processing/processing-android/issues/281
306+
// seems harmless as it happens in the first frame only
307+
// TODO: need to find the reason for the error (gl config?)
308+
private void hadnleGVREnumError() {
309+
int err = pgl.getError();
310+
if (err != 0 && err != 1280) {
311+
String where = "top onNewFrame";
312+
String errString = pgl.errorString(err);
313+
String msg = "OpenGL error " + err + " at " + where + ": " + errString;
314+
PGraphics.showWarning(msg);
315+
}
316+
}
311317
}
312318
}

templates/VRManifest.xml.tmpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
99
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />
1010
<uses-feature android:name="android.hardware.sensor.gyroscope" android:required="true" />
11+
<uses-feature android:name="android.software.vr.mode" android:required="false"/>
12+
<uses-feature android:name="android.hardware.vr.high_performance" android:required="false"/>
1113
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
1214
<application android:label=""
1315
android:icon="@drawable/icon"
1416
android:theme="@style/VrActivityTheme">
1517
<activity android:name=".MainActivity"
1618
android:screenOrientation="landscape"
17-
android:configChanges="orientation|keyboardHidden|screenSize" >
19+
android:configChanges="orientation|keyboardHidden|screenSize"
20+
android:resizeableActivity="false">
1821
<intent-filter>
1922
<action android:name="android.intent.action.MAIN" />
2023
<category android:name="android.intent.category.LAUNCHER" />

0 commit comments

Comments
 (0)