@@ -44,7 +44,7 @@ class GLES20Renderer implements Renderer {
44
44
private static final int TEXTURE_COORDS_PER_VERTEX = 2 ;
45
45
private static final int COLOR_COORDS_PER_VERTEX = 4 ;
46
46
47
- private final static float [] DEFAULT_COLOR = {1 .0f , 1.0f , 1.0f , 1.0f };
47
+ private final static float [] DEFAULT_COLOR = {0 .0f , 1.0f , 1.0f , 1.0f };
48
48
private final static float [] NO_COLOR_MASK = {1.0f , 1.0f , 1.0f , 1.0f };
49
49
50
50
// specification
@@ -75,6 +75,10 @@ class GLES20Renderer implements Renderer {
75
75
*/
76
76
private static Map <Object , Object > flags = new HashMap <>();
77
77
78
+ private boolean texturesEnabled = true ;
79
+ private boolean lightingEnabled = true ;
80
+ private boolean animationEnabled = true ;
81
+
78
82
static GLES20Renderer getInstance (String id , String vertexShaderCode , String fragmentShaderCode ) {
79
83
Set <String > shaderFeatures = new HashSet <>();
80
84
testShaderFeature (shaderFeatures , vertexShaderCode , "u_MMatrix" );
@@ -83,6 +87,7 @@ static GLES20Renderer getInstance(String id, String vertexShaderCode, String fra
83
87
testShaderFeature (shaderFeatures , vertexShaderCode , "a_Color" );
84
88
testShaderFeature (shaderFeatures , vertexShaderCode , "a_TexCoordinate" );
85
89
testShaderFeature (shaderFeatures , vertexShaderCode , "u_LightPos" );
90
+ testShaderFeature (shaderFeatures , fragmentShaderCode , "u_LightPos" );
86
91
testShaderFeature (shaderFeatures , vertexShaderCode , "in_jointIndices" );
87
92
testShaderFeature (shaderFeatures , vertexShaderCode , "in_weights" );
88
93
testShaderFeature (shaderFeatures , fragmentShaderCode , "u_TextureCube" );
@@ -112,6 +117,18 @@ private GLES20Renderer(String id, String vertexShaderCode, String fragmentShader
112
117
Log .d ("GLES20Renderer" , "Compiled 3D Drawer (" + id + ") with id " + mProgram );
113
118
}
114
119
120
+ public void setTexturesEnabled (boolean texturesEnabled ) {
121
+ this .texturesEnabled = texturesEnabled ;
122
+ }
123
+
124
+ public void setLightingEnabled (boolean lightingEnabled ) {
125
+ this .lightingEnabled = lightingEnabled ;
126
+ }
127
+
128
+ public void setAnimationEnabled (boolean animationEnabled ) {
129
+ this .animationEnabled = animationEnabled ;
130
+ }
131
+
115
132
@ Override
116
133
public void draw (Object3DData obj , float [] pMatrix , float [] vMatrix , int textureId , float [] lightPosInWorldSpace , float [] colorMask , float [] cameraPos , int drawMode , int drawSize ) {
117
134
@@ -128,6 +145,8 @@ public void draw(Object3DData obj, float[] pMatrix, float[] vMatrix, int texture
128
145
return ;
129
146
}
130
147
148
+ //setFeatureFlag("u_Debug",false);
149
+
131
150
// mvp matrix for position + lighting + animation
132
151
if (supportsMMatrix ()) {
133
152
setUniformMatrix4 (obj .getModelMatrix (), "u_MMatrix" );
@@ -146,8 +165,12 @@ public void draw(Object3DData obj, float[] pMatrix, float[] vMatrix, int texture
146
165
147
166
// pass in color or colors array
148
167
int mColorHandle = -1 ;
149
- if (supportsColors ()) {
150
- mColorHandle = setVBO ("a_Color" , obj .getColorsBuffer (), COLOR_COORDS_PER_VERTEX );
168
+ if (supportsColors ()){
169
+ setFeatureFlag ("u_Coloured" ,false );
170
+ if (obj .getColorsBuffer () != null ) {
171
+ mColorHandle = setVBO ("a_Color" , obj .getColorsBuffer (), COLOR_COORDS_PER_VERTEX );
172
+ setFeatureFlag ("u_Coloured" , true );
173
+ }
151
174
} else {
152
175
setUniform4 (obj .getColor () != null ? obj .getColor () : DEFAULT_COLOR ,"vColor" );
153
176
}
@@ -158,8 +181,9 @@ public void draw(Object3DData obj, float[] pMatrix, float[] vMatrix, int texture
158
181
// pass in texture UV buffer
159
182
int mTextureHandle = -1 ;
160
183
if (supportsTextures ()) {
161
-
162
- setFeatureFlag ("u_Textured" , false );
184
+ setFeatureFlag ("u_Textured" , texturesEnabled );
185
+ }
186
+ if (supportsTextures () && obj .getTextureBuffer () != null ) {
163
187
164
188
// load color map
165
189
if (obj .getMaterial ().getTextureId () == -1 &&
@@ -238,19 +262,25 @@ public void draw(Object3DData obj, float[] pMatrix, float[] vMatrix, int texture
238
262
}
239
263
240
264
// pass in light position for lighting
241
- if (lightPosInWorldSpace != null && supportsLighting ()) {
265
+ if (supportsLighting ()) {
266
+ boolean toggle = lightingEnabled && obj .getNormalsBuffer () != null ;
267
+ setFeatureFlag ("u_Lighted" , toggle );
242
268
setUniform3 (lightPosInWorldSpace ,"u_LightPos" );
243
269
setUniform3 (cameraPos ,"u_cameraPos" );
244
270
}
245
271
246
272
// pass in joint transformation for animated model
247
273
int in_weightsHandle = -1 ;
248
274
int in_jointIndicesHandle = -1 ;
249
- if (supportsJoints () && obj instanceof AnimatedModel ) {
250
- in_weightsHandle = setVBO ("in_weights" , ((AnimatedModel ) obj ).getVertexWeights (), COORDS_PER_VERTEX );
251
- in_jointIndicesHandle = setVBO ("in_jointIndices" , ((AnimatedModel ) obj ).getJointIds (), COORDS_PER_VERTEX );
252
- setUniformMatrix4 (((AnimatedModel ) obj ).getBindShapeMatrix (), "u_BindShapeMatrix" );
253
- setJointTransforms ((AnimatedModel ) obj );
275
+ if (supportsJoints ()){
276
+ boolean toggle = this .animationEnabled && obj instanceof AnimatedModel ;
277
+ if (toggle ) {
278
+ in_weightsHandle = setVBO ("in_weights" , ((AnimatedModel ) obj ).getVertexWeights (), COORDS_PER_VERTEX );
279
+ in_jointIndicesHandle = setVBO ("in_jointIndices" , ((AnimatedModel ) obj ).getJointIds (), COORDS_PER_VERTEX );
280
+ setUniformMatrix4 (((AnimatedModel ) obj ).getBindShapeMatrix (), "u_BindShapeMatrix" );
281
+ setJointTransforms ((AnimatedModel ) obj );
282
+ }
283
+ setFeatureFlag ("u_Animated" , toggle );
254
284
}
255
285
256
286
// draw mesh
@@ -537,16 +567,28 @@ private void drawObjectElement(Object3DData obj, int drawMode, int drawBufferTyp
537
567
Log .v ("GLES20Renderer" , "Rendering element " + i + ".... " + element );
538
568
}
539
569
570
+ if (element .getMaterial () != null && element .getMaterial ().getColor () != null ){
571
+ setUniform4 (element .getMaterial ().getColor (), "vColor" );
572
+ } else if (obj .getColor () != null ){
573
+ setUniform4 (obj .getColor (), "vColor" );
574
+ } else {
575
+ setUniform4 (DEFAULT_COLOR , "vColor" );
576
+ }
577
+
578
+ // default is no textured
579
+ if (supportsColors ()){
580
+ setFeatureFlag ("u_Coloured" , obj .getColorsBuffer () != null );
581
+ }
582
+
540
583
// default is no textured
541
584
if (supportsTextures ()){
542
- setFeatureFlag ("u_Textured" , false );
585
+ setFeatureFlag ("u_Textured" , obj .getTextureBuffer () != null
586
+ && element .getMaterial () != null && element .getMaterial ().getTextureId () != -1
587
+ && texturesEnabled );
543
588
}
544
589
545
590
if (element .getMaterial () != null ) {
546
- if (!supportsColors ()) {
547
- setUniform4 (element .getMaterial ().getColor () != null ? element .getMaterial ().getColor () :
548
- obj .getColor () != null ? obj .getColor () : DEFAULT_COLOR , "vColor" );
549
- }
591
+
550
592
// load color map
551
593
if (element .getMaterial ().getTextureId () == -1 &&
552
594
element .getMaterial ().getColorTexture () != null ){
@@ -600,17 +642,17 @@ private void drawObjectElement(Object3DData obj, int drawMode, int drawBufferTyp
600
642
}
601
643
if (element .getMaterial ().getTextureId () != -1 && supportsTextures ()) {
602
644
setTexture (element .getMaterial ().getTextureId (), "u_Texture" , 0 );
603
- setFeatureFlag ("u_Textured" ,true );
645
+ setFeatureFlag ("u_Textured" ,texturesEnabled );
604
646
}
605
647
606
648
if (element .getMaterial ().getNormalTextureId () != -1 && supportsTextures ()) {
607
649
setTexture (element .getMaterial ().getNormalTextureId (), "u_NormalTexture" , 1 );
608
- setFeatureFlag ("u_NormalTextured" ,true );
650
+ setFeatureFlag ("u_NormalTextured" ,texturesEnabled );
609
651
}
610
652
611
653
if (element .getMaterial ().getEmissiveTextureId () != -1 && supportsTextures ()){
612
654
setTexture (element .getMaterial ().getEmissiveTextureId (), "u_EmissiveTexture" , 2 );
613
- setFeatureFlag ("u_EmissiveTextured" , true );
655
+ setFeatureFlag ("u_EmissiveTextured" , texturesEnabled );
614
656
}
615
657
}
616
658
0 commit comments