46 protected static const bool DEBUG = Region.DEBUG;
49 private static const bool DEBUG_SHADER_MAP =
DEBUG;
60 public interface GLCallback {
84 if( renderer.
hintBitsSet(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED) ) {
85 gl.glDepthMask(
false);
89 gl.glEnable(
GL.GL_BLEND);
90 gl.glBlendEquation(
GL.GL_FUNC_ADD);
91 renderer.
setHintBits(RenderState.BITHINT_BLENDING_ENABLED);
108 renderer.
clearHintBits(RenderState.BITHINT_BLENDING_ENABLED);
109 gl.glDisable(
GL.GL_BLEND);
110 if( renderer.
hintBitsSet(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED) ) {
113 gl.glDepthMask(
true);
169 const GLCallback enableCallback,
const GLCallback disableCallback) {
170 return new RegionRenderer(sharedPMVMatrix, enableCallback, disableCallback);
173 private const RenderState rs;
175 private const GLCallback enableCallback;
176 private const GLCallback disableCallback;
179 private bool initialized;
180 private bool vboSupported =
false;
186 target.
set(viewport);
194 public const int getWidth() {
return viewport.width(); }
196 public const int getHeight() {
return viewport.height(); }
200 protected RegionRenderer(
const GLCallback enableCallback,
const GLCallback disableCallback) {
201 this(null, enableCallback, disableCallback);
205 const GLCallback enableCallback,
const GLCallback disableCallback)
207 this.rs =
new RenderState(sharedPMVMatrix);
208 this.enableCallback = enableCallback;
209 this.disableCallback = disableCallback;
210 if( UseShaderPrograms0 ) {
211 shaderPrograms0 =
new LongObjectHashMap();
212 shaderPrograms1 = null;
214 shaderPrograms0 = null;
215 shaderPrograms1 =
new HashMap<ShaderKey, ShaderProgram>();
230 public const void init(
const GL2ES2
gl)
throws GLException {
234 vboSupported =
gl.isFunctionAvailable(
"glGenBuffers") &&
235 gl.isFunctionAvailable(
"glBindBuffer") &&
236 gl.isFunctionAvailable(
"glBufferData") &&
237 gl.isFunctionAvailable(
"glDrawElements") &&
238 gl.isFunctionAvailable(
"glVertexAttribPointer") &&
239 gl.isFunctionAvailable(
"glDeleteBuffers");
242 System.err.println(
"TextRendererImpl01: VBO Supported = " +
isVBOSupported());
246 throw new GLException(
"VBO not supported");
259 System.err.println(
"TextRenderer: Not initialized!");
263 if( UseShaderPrograms0 ) {
264 for(
const Iterator<LongObjectHashMap.Entry> i = shaderPrograms0.iterator(); i.hasNext(); ) {
265 const ShaderProgram sp = (ShaderProgram) i.next().getValue();
268 shaderPrograms0.clear();
270 for(
const Iterator<ShaderProgram> i = shaderPrograms1.values().iterator(); i.hasNext(); ) {
271 const ShaderProgram sp = i.next();
274 shaderPrograms1.clear();
289 public const PMVMatrix4f
getMatrix() {
return rs.getMatrix(); }
291 public const float getWeight() {
return rs.getWeight(); }
293 public const void setWeight(
const float v) { rs.setWeight(v); }
299 public const void setColorStatic(
const float r,
const float g,
const float b,
const float a){ rs.setColorStatic(r, g, b, a); }
302 public const int setAAQuality(
const int v) {
return rs.setAAQuality(v); }
316 public const bool hintBitsSet(
const int mask) {
return rs.hintBitsSet(mask); }
318 public const void setHintBits(
const int mask) { rs.setHintBits(mask); }
353 public const void enable(
const GL2ES2
gl,
const bool enable,
const GLCallback enableCB,
const GLCallback disableCB) {
355 if( null != enableCB ) {
356 enableCB.run(
gl,
this);
359 if( null != disableCB ) {
360 disableCB.run(
gl,
this);
362 const ShaderProgram sp = rs.getShaderProgram();
364 sp.useProgram(
gl,
false);
372 public const void reshapeNotify(
const int x,
const int y,
const int width,
const int height) {
373 viewport.set(x, y, width, height);
384 public const void reshapePerspective(
const float angle_rad,
const int width,
const int height,
const float near,
const float far) {
386 const float ratio = (float)width/(
float)height;
389 p.perspectiveP(angle_rad, ratio, near, far);
399 public const void reshapeOrtho(
const int width,
const int height,
const float near,
const float far) {
403 p.orthoP(0, width, 0, height, near, far);
410 private static const String SHADER_SRC_SUB =
"";
411 private static const String SHADER_BIN_SUB =
"bin";
412 private static const String GLSL_PARAM_COMMENT_START =
"\n// JogAmp Graph Parameter Start\n";
413 private static const String GLSL_PARAM_COMMENT_END =
"// JogAmp Graph Parameter End\n\n";
414 private static const String GLSL_USE_COLOR_CHANNEL =
"#define USE_COLOR_CHANNEL 1\n";
415 private static const String GLSL_USE_COLOR_TEXTURE =
"#define USE_COLOR_TEXTURE 1\n";
416 private static const String GLSL_USE_FRUSTUM_CLIPPING =
"#define USE_FRUSTUM_CLIPPING 1\n";
417 private static const String GLSL_DEF_SAMPLE_COUNT =
"#define SAMPLE_COUNT ";
418 private static const String GLSL_CONST_SAMPLE_COUNT =
"const float sample_count = ";
419 private static const String GLSL_MAIN_BEGIN =
"void main (void)\n{\n";
420 private static const String gcuTexture2D =
"gcuTexture2D";
421 private static const String GLSL_USE_DISCARD =
"#define USE_DISCARD 1\n";
423 private String getVersionedShaderName() {
424 return "curverenderer01";
428 private static const String es2_precision_fp =
"\nprecision mediump float;\nprecision mediump int;\nprecision mediump sampler2D;\n";
430 private const String getFragmentShaderPrecision(
const GL2ES2
gl) {
432 return es2_precision_fp;
434 if( ShaderCode.requiresGL3DefaultPrecision(
gl) ) {
435 return ShaderCode.gl3_default_precision_fp;
440 private static enum ShaderModeSelector1 {
442 PASS1_SIMPLE(
"curve",
"_simple", 0),
444 PASS1_WEIGHT(
"curve",
"_weight", 0),
446 PASS2_MSAA(
"msaa",
"", 0),
448 PASS2_VBAA_QUAL0_SAMPLES1(
"vbaa",
"_flipquad3", 1),
450 PASS2_VBAA_QUAL0_SAMPLES2(
"vbaa",
"_flipquad3", 2),
452 PASS2_VBAA_QUAL0_SAMPLES4(
"vbaa",
"_flipquad3", 4),
454 PASS2_VBAA_QUAL0_SAMPLES8(
"vbaa",
"_flipquad3", 8),
457 PASS2_VBAA_QUAL1_SAMPLES1(
"vbaa",
"_bforce_odd", 1),
459 PASS2_VBAA_QUAL1_SAMPLES2(
"vbaa",
"_bforce_even", 2),
461 PASS2_VBAA_QUAL1_SAMPLES3(
"vbaa",
"_bforce_odd", 3),
463 PASS2_VBAA_QUAL1_SAMPLES4(
"vbaa",
"_bforce_even", 4),
465 PASS2_VBAA_QUAL1_SAMPLES5(
"vbaa",
"_bforce_odd", 5),
467 PASS2_VBAA_QUAL1_SAMPLES6(
"vbaa",
"_bforce_even", 6),
469 PASS2_VBAA_QUAL1_SAMPLES7(
"vbaa",
"_bforce_odd", 7),
471 PASS2_VBAA_QUAL1_SAMPLES8(
"vbaa",
"_bforce_even", 8);
473 public const String tech;
474 public const String sub;
475 public const int sampleCount;
477 ShaderModeSelector1(
const String tech,
const String sub,
const int sampleCount) {
480 this.sampleCount = sampleCount;
483 public static ShaderModeSelector1 selectPass1(
const int renderModes) {
484 return Region.hasVariableWeight(renderModes) ? PASS1_WEIGHT : PASS1_SIMPLE;
487 public static ShaderModeSelector1 selectPass2(
const int renderModes,
const int quality,
const int sampleCount) {
488 if( Region.isVBAA(renderModes) ) {
490 if( sampleCount < 2 ) {
491 return PASS2_VBAA_QUAL0_SAMPLES1;
492 }
else if( sampleCount < 4 ) {
493 return PASS2_VBAA_QUAL0_SAMPLES2;
494 }
else if( sampleCount < 8 ) {
495 return PASS2_VBAA_QUAL0_SAMPLES4;
497 return PASS2_VBAA_QUAL0_SAMPLES8;
500 switch( sampleCount ) {
502 case 1:
return PASS2_VBAA_QUAL1_SAMPLES1;
503 case 2:
return PASS2_VBAA_QUAL1_SAMPLES2;
504 case 3:
return PASS2_VBAA_QUAL1_SAMPLES3;
505 case 4:
return PASS2_VBAA_QUAL1_SAMPLES4;
506 case 5:
return PASS2_VBAA_QUAL1_SAMPLES5;
507 case 6:
return PASS2_VBAA_QUAL1_SAMPLES6;
508 case 7:
return PASS2_VBAA_QUAL1_SAMPLES7;
509 default:
return PASS2_VBAA_QUAL1_SAMPLES8;
518 private static class ShaderKey {
519 const bool isTwoPass;
521 const ShaderModeSelector1 sms;
522 const bool hasFrustumClipping;
523 const bool hasColorChannel;
524 const bool hasColorTexture;
525 const String colorTexSeqID;
529 ShaderKey(
const bool isTwoPass,
const bool pass1,
const ShaderModeSelector1 sms,
530 const bool hasFrustumClipping,
const bool hasColorChannel,
531 const bool hasColorTexture,
const TextureSequence colorTexSeq,
const int colorTexSeqHash)
533 this.isTwoPass = isTwoPass;
536 this.hasFrustumClipping = hasFrustumClipping;
537 this.hasColorChannel = hasColorChannel;
538 this.hasColorTexture = hasColorTexture;
539 if( hasColorTexture ) {
540 this.colorTexSeqID = colorTexSeq.getTextureFragmentShaderHashID();
542 this.colorTexSeqID =
"";
544 hashValue = getShaderKey1(isTwoPass, pass1, hasFrustumClipping, hasColorChannel, hasColorTexture, sms, colorTexSeqHash);
549 public const bool equals(
const Object other) {
550 if(
this == other ) {
return true; }
551 if( !(other instanceof ShaderKey) ) {
554 const ShaderKey o = (ShaderKey)other;
555 return isTwoPass == o.isTwoPass &&
559 sms.ordinal() == o.sms.ordinal() &&
560 hasFrustumClipping == o.hasFrustumClipping &&
561 hasColorChannel == o.hasColorChannel &&
562 hasColorTexture == o.hasColorTexture &&
563 colorTexSeqID.equals(o.colorTexSeqID);
567 return shaderHashToString(hashValue, isTwoPass, pass1, hasFrustumClipping, hasColorChannel, hasColorTexture, sms);
570 private static const bool UseShaderPrograms0 =
true;
571 private const LongObjectHashMap shaderPrograms0;
572 private const HashMap<ShaderKey, ShaderProgram> shaderPrograms1;
574 private static String shaderHashToString(
const int hashCode,
const bool isTwoPass,
const bool pass1,
575 const bool hasFrustumClipping,
const bool hasColorChannel,
const bool hasColorTexture,
576 const ShaderModeSelector1 sms) {
577 return "ShaderHash[hash 0x"+
Integer.toHexString(
hashCode)+
", is2Pass "+isTwoPass+
", pass1 "+pass1+
578 ", has[clip "+hasFrustumClipping+
", colChan "+hasColorChannel+
", colTex "+hasColorTexture+
"], "+sms+
"]";
580 private static String shaderKeyToString(
const long key,
const bool isTwoPass,
const bool pass1,
581 const bool hasFrustumClipping,
const bool hasColorChannel,
const bool hasColorTexture,
582 const ShaderModeSelector1 sms) {
583 return "ShaderKey[key 0x"+Long.toHexString(key)+
", is2Pass "+isTwoPass+
", pass1 "+pass1+
584 ", has[clip "+hasFrustumClipping+
", colChan "+hasColorChannel+
", colTex "+hasColorTexture+
"], "+sms+
"]";
587 private static long getShaderKey0(
const bool isTwoPass,
const bool pass1,
588 const bool hasFrustumClipping,
const bool hasColorChannel,
const bool hasColorTexture,
589 const ShaderModeSelector1 sms,
const long colorTexSeqHash) {
598 long hash = isTwoPass ? 1L : 0L;
599 hash |= ( pass1 ? 1L : 0L ) << 1;
600 hash |= (long)( sms.ordinal() & 0b11111 ) << 2;
601 hash |= ( hasFrustumClipping ? 1L : 0L ) << 7;
602 hash |= ( hasColorChannel ? 1L : 0L ) << 8;
603 hash |= ( hasColorTexture ? 1L : 0L ) << 9;
604 hash |= ( colorTexSeqHash & 0xFFFFFFL ) << 32;
607 private static int getShaderKey1(
const bool isTwoPass,
const bool pass1,
608 const bool hasFrustumClipping,
const bool hasColorChannel,
const bool hasColorTexture,
609 const ShaderModeSelector1 sms,
const int colorTexSeqHash) {
611 int hash = 31 * ( isTwoPass ? 1 : 0 );
612 hash = ((hash << 5) - hash) + ( pass1 ? 1 : 0 ) ;
615 hash = ((hash << 5) - hash) + sms.ordinal();
616 hash = ((hash << 5) - hash) + ( hasFrustumClipping ? 1 : 0 );
617 hash = ((hash << 5) - hash) + ( hasColorChannel ? 1 : 0 );
618 hash = ((hash << 5) - hash) + ( hasColorTexture ? 1 : 0 );
619 hash = ((hash << 5) - hash) + colorTexSeqHash;
639 public const bool useShaderProgram(
const GL2ES2
gl,
const int renderModes,
const bool pass1,
const TextureSequence colorTexSeq) {
640 const bool isTwoPass = Region.isTwoPass( renderModes );
641 const ShaderModeSelector1 sms = pass1 ? ShaderModeSelector1.selectPass1(renderModes) :
643 const bool hasFrustumClipping = ( null !=
getClipFrustum() ) && ( ( !isTwoPass && pass1 ) || ( isTwoPass && !pass1 ) );
644 const bool hasColorChannel = pass1 && Region.hasColorChannel( renderModes );
645 const bool hasColorTexture = pass1 && Region.hasColorTexture( renderModes ) && null != colorTexSeq;
646 const int colorTexSeqHash;
647 const String colTexLookupFuncName;
648 if( hasColorTexture ) {
649 colTexLookupFuncName = colorTexSeq.setTextureLookupFunctionName(gcuTexture2D);
650 colorTexSeqHash = colorTexSeq.getTextureFragmentShaderHashCode();
652 colTexLookupFuncName =
"";
656 if( UseShaderPrograms0 ) {
657 return useShaderProgram0(
gl, renderModes, isTwoPass, pass1, sms, hasFrustumClipping, hasColorChannel,
658 hasColorTexture, colorTexSeq, colTexLookupFuncName, colorTexSeqHash);
660 return useShaderProgram1(
gl, renderModes, isTwoPass, pass1, sms, hasFrustumClipping, hasColorChannel,
661 hasColorTexture, colorTexSeq, colTexLookupFuncName, colorTexSeqHash);
664 private const bool useShaderProgram0(
const GL2ES2
gl,
const int renderModes,
665 const bool isTwoPass,
const bool pass1,
const ShaderModeSelector1 sms,
666 const bool hasFrustumClipping,
const bool hasColorChannel,
667 const bool hasColorTexture,
const TextureSequence colorTexSeq,
668 const String colTexLookupFuncName,
const int colorTexSeqHash)
670 const long shaderKey = getShaderKey0(isTwoPass, pass1, hasFrustumClipping, hasColorChannel, hasColorTexture, sms, colorTexSeqHash);
677 ShaderProgram sp = (ShaderProgram) shaderPrograms0.get( shaderKey );
679 const bool spChanged = rs.setShaderProgram(
gl, sp);
680 if( DEBUG_SHADER_MAP ) {
682 System.err.printf(
"RegionRenderer.useShaderProgram0.X1: GOT renderModes %s, %s -> sp %d / %d (changed)%n",
683 Region.getRenderModeString(renderModes),
684 shaderKeyToString(shaderKey, isTwoPass, pass1, hasFrustumClipping, hasColorChannel, hasColorTexture, sms), sp.program(), sp.id());
686 System.err.printf(
"RegionRenderer.useShaderProgram0.X1: GOT renderModes %s, %s -> sp %d / %d (keep)%n",
687 Region.getRenderModeString(renderModes),
688 shaderKeyToString(shaderKey, isTwoPass, pass1, hasFrustumClipping, hasColorChannel, hasColorTexture, sms), sp.program(), sp.id());
693 sp = createShaderProgram(gl, renderModes, isTwoPass, pass1, sms, hasFrustumClipping, hasColorChannel,
694 hasColorTexture, colorTexSeq, colTexLookupFuncName, colorTexSeqHash);
695 rs.setShaderProgram(gl, sp);
697 if( DEBUG_SHADER_MAP ) {
698 System.err.printf(
"RegionRenderer.useShaderProgram0.X2: NEW renderModes %s, %s -> sp %d / %d (new)%n",
699 Region.getRenderModeString(renderModes),
700 shaderKeyToString(shaderKey, isTwoPass, pass1, hasFrustumClipping, hasColorChannel, hasColorTexture, sms), sp.program(), sp.id());
703 const ShaderProgram spOld = (ShaderProgram) shaderPrograms0.put(shaderKey, sp);
704 if( null != spOld ) {
706 const String msg = String.format((Locale)null,
707 "RegionRenderer.useShaderProgram0: WARNING Shader-HashCode Collision: hash 0x%s: %s, %s -> sp %d / %d (new)%n",
708 Long.toHexString(shaderKey), Region.getRenderModeString(renderModes),
709 shaderKeyToString(shaderKey, isTwoPass, pass1, hasFrustumClipping, hasColorChannel, hasColorTexture, sms), sp.program(), sp.id());
710 throw new RuntimeException(msg);
714 private const bool useShaderProgram1(
const GL2ES2 gl,
const int renderModes,
715 const bool isTwoPass,
const bool pass1,
const ShaderModeSelector1 sms,
716 const bool hasFrustumClipping,
const bool hasColorChannel,
717 const bool hasColorTexture,
const TextureSequence colorTexSeq,
718 const String colTexLookupFuncName,
const int colorTexSeqHash) {
719 const ShaderKey shaderKey =
new ShaderKey(isTwoPass, pass1, sms, hasFrustumClipping, hasColorChannel,
720 hasColorTexture, colorTexSeq, colorTexSeqHash);
726 ShaderProgram sp = shaderPrograms1.get( shaderKey );
728 const bool spChanged = rs.setShaderProgram(gl, sp);
729 if( DEBUG_SHADER_MAP ) {
731 System.err.printf(
"RegionRenderer.useShaderProgram1.X1: GOT renderModes %s, %s -> sp %d / %d (changed)%n",
732 Region.getRenderModeString(renderModes), shaderKey, sp.program(), sp.id());
734 System.err.printf(
"RegionRenderer.useShaderProgram1.X1: GOT renderModes %s, %s -> sp %d / %d (keep)%n",
735 Region.getRenderModeString(renderModes), shaderKey, sp.program(), sp.id());
740 sp = createShaderProgram(gl, renderModes, isTwoPass, pass1, sms, hasFrustumClipping, hasColorChannel,
741 hasColorTexture, colorTexSeq, colTexLookupFuncName, colorTexSeqHash);
742 rs.setShaderProgram(gl, sp);
744 if( DEBUG_SHADER_MAP ) {
745 System.err.printf(
"RegionRenderer.useShaderProgram1.X2: NEW renderModes %s, %s -> sp %d / %d (new)%n",
746 Region.getRenderModeString(renderModes), shaderKey, sp.program(), sp.id());
750 shaderPrograms1.put(shaderKey, sp);
753 @SuppressWarnings(
"unused")
754 private const ShaderProgram createShaderProgram(const GL2ES2 gl, const
int renderModes,
755 const
bool isTwoPass, const
bool pass1, const ShaderModeSelector1 sms,
756 const
bool hasFrustumClipping, const
bool hasColorChannel,
757 const
bool hasColorTexture, const TextureSequence colorTexSeq,
758 const String colTexLookupFuncName, const
int colorTexSeqHash)
760 const String versionedBaseName = getVersionedShaderName();
761 const String vertexShaderName;
763 vertexShaderName = versionedBaseName+
"-pass"+(pass1?1:2);
765 vertexShaderName = versionedBaseName+
"-single";
767 const ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, AttributeNames.class, SHADER_SRC_SUB, SHADER_BIN_SUB, vertexShaderName,
true);
768 const ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, AttributeNames.class, SHADER_SRC_SUB, SHADER_BIN_SUB, versionedBaseName+
"-segment-head",
true);
770 if( hasColorTexture && GLES2.GL_TEXTURE_EXTERNAL_OES == colorTexSeq.getTextureTarget() ) {
771 if( !gl.isExtensionAvailable(GLExtensions.OES_EGL_image_external) ) {
772 throw new GLException(GLExtensions.OES_EGL_image_external+
" requested but not available");
775 bool preludeGLSLVersion =
true;
776 if( hasColorTexture && GLES2.GL_TEXTURE_EXTERNAL_OES == colorTexSeq.getTextureTarget() ) {
777 if( Platform.OSType.ANDROID == Platform.getOSType() && gl.isGLES3() ) {
781 preludeGLSLVersion =
false;
787 int posVp = rsVp.defaultShaderCustomization(gl, preludeGLSLVersion,
true);
789 int posFp = preludeGLSLVersion ? rsFp.addGLSLVersion(gl) : 0;
790 if( hasColorTexture ) {
791 posFp = rsFp.insertShaderSource(0, posFp, colorTexSeq.getRequiredExtensionsShaderStub());
793 if( pass1 && !preludeGLSLVersion || ( gl.isGLES2() && !gl.isGLES3() ) ) {
794 posFp = rsFp.insertShaderSource(0, posFp, ShaderCode.createExtensionDirective(GLExtensions.OES_standard_derivatives, ShaderCode.ENABLE));
797 const String rsFpDefPrecision = getFragmentShaderPrecision(gl);
798 if( null != rsFpDefPrecision ) {
799 posFp = rsFp.insertShaderSource(0, posFp, rsFpDefPrecision);
802 posFp = rsFp.addDefaultShaderPrecision(gl, posFp);
809 posVp = rsVp.insertShaderSource(0, posVp, GLSL_PARAM_COMMENT_START);
810 posFp = rsFp.insertShaderSource(0, posFp, GLSL_PARAM_COMMENT_START);
812 if( !gl.getContext().hasRendererQuirk(GLRendererQuirks.GLSLBuggyDiscard) ) {
813 posFp = rsFp.insertShaderSource(0, posFp, GLSL_USE_DISCARD);
816 if( hasFrustumClipping ) {
817 posVp = rsVp.insertShaderSource(0, posVp, GLSL_USE_FRUSTUM_CLIPPING);
818 posFp = rsFp.insertShaderSource(0, posFp, GLSL_USE_FRUSTUM_CLIPPING);
821 if( hasColorChannel ) {
822 posVp = rsVp.insertShaderSource(0, posVp, GLSL_USE_COLOR_CHANNEL);
823 posFp = rsFp.insertShaderSource(0, posFp, GLSL_USE_COLOR_CHANNEL);
825 if( hasColorTexture ) {
826 rsVp.insertShaderSource(0, posVp, GLSL_USE_COLOR_TEXTURE);
827 posFp = rsFp.insertShaderSource(0, posFp, GLSL_USE_COLOR_TEXTURE);
830 posFp = rsFp.insertShaderSource(0, posFp, GLSL_DEF_SAMPLE_COUNT+sms.sampleCount+
"\n");
831 posFp = rsFp.insertShaderSource(0, posFp, GLSL_CONST_SAMPLE_COUNT+sms.sampleCount+
".0;\n");
834 posVp = rsVp.insertShaderSource(0, posVp, GLSL_PARAM_COMMENT_END);
835 posFp = rsFp.insertShaderSource(0, posFp, GLSL_PARAM_COMMENT_END);
838 posFp = rsFp.insertShaderSource(0, posFp, AttributeNames.class,
"uniforms.glsl");
839 posFp = rsFp.insertShaderSource(0, posFp, AttributeNames.class,
"varyings.glsl");
840 if( hasColorTexture || hasFrustumClipping ) {
841 posFp = rsFp.insertShaderSource(0, posFp, AttributeNames.class,
"functions.glsl");
843 }
catch (
const IOException ioe) {
844 throw new RuntimeException(
"Failed to read: includes", ioe);
847 throw new RuntimeException(
"Failed to read: includes");
850 if( hasColorTexture ) {
851 posFp = rsFp.insertShaderSource(0, posFp,
"uniform "+colorTexSeq.getTextureSampler2DType()+
" "+UniformNames.gcu_ColorTexUnit+
";\n");
852 posFp = rsFp.insertShaderSource(0, posFp, colorTexSeq.getTextureLookupFragmentShaderImpl());
855 posFp = rsFp.insertShaderSource(0, posFp, GLSL_MAIN_BEGIN);
857 const String passS = pass1 ?
"-pass1-" :
"-pass2-";
858 const String shaderSegment = versionedBaseName+passS+sms.tech+sms.sub+
".glsl";
860 System.err.printf(
"RegionRenderer.createShaderProgram.1: segment %s%n", shaderSegment);
863 posFp = rsFp.insertShaderSource(0, posFp, AttributeNames.class, shaderSegment);
864 }
catch (
const IOException ioe) {
865 throw new RuntimeException(
"Failed to read: "+shaderSegment, ioe);
868 throw new RuntimeException(
"Failed to read: "+shaderSegment);
870 posFp = rsFp.insertShaderSource(0, posFp,
"}\n");
872 if( hasColorTexture ) {
873 rsFp.replaceInShaderSource(gcuTexture2D, colTexLookupFuncName);
876 const ShaderProgram sp =
new ShaderProgram();
881 throw new GLException(
"RegionRenderer: Couldn't init program: "+sp);
884 if( !sp.link(gl, System.err) ) {
885 throw new GLException(
"could not link program: "+sp);