@@ -4422,226 +4422,7 @@ void Iff::ShaderSource( RegalContext *ctx, GLuint shader, GLsizei count, const G
4422
4422
for ( int i = 0 ; i < count; i++ ) {
4423
4423
src += length != NULL ? string ( srcstr[i], length[i] ) : string ( srcstr[i] );
4424
4424
}
4425
-
4426
- // comment out version in-place
4427
- int version = -1 ;
4428
- version = remove_version ( src );
4429
-
4430
- // if used, replace ftransform with rgl_ftform
4431
- bool uses_ftransform = replace_ftransform ( src );
4432
-
4433
- if ( legacy ) {
4434
- remove_precision ( src );
4435
- }
4436
-
4437
- // Preamble
4438
-
4439
- string_list ss;
4440
- if (gles) {
4441
- // hack around #version 100 on x86 failing compilation
4442
- if ( ctx->info ->gl_version_major >= 3 ) {
4443
- ss << " #version 120\n " ;
4444
- ss << " #define precision\n " ;
4445
- } else {
4446
- #if REGAL_FORCE_DESKTOP_GLSL
4447
- ss << " #version 140\n " ;
4448
- #else
4449
- ss << " #version 100\n " ;
4450
- #if !REGAL_SYS_EMSCRIPTEN
4451
- // GAB NOTE Dec 2018: do not use EXT_shadow_samplers on Emscripten/WebGL. This is not a valid WebGL extension, and make shader compilation fail.
4452
- ss << " #extension GL_EXT_shadow_samplers : enable\n " ;
4453
- ss << " #define shadow2D(a,b) vec4(shadow2DEXT(a,b))\n " ;
4454
- #else
4455
- // GAB Note Dec: 2019: OES_standard_derivatives is available on all browsers
4456
- ss << " #extension GL_OES_standard_derivatives : enable\n " ;
4457
- #endif
4458
- #endif
4459
- }
4460
- } else if (legacy) {
4461
- ss << " #version 120\n " ;
4462
- ss << " #define precision\n " ;
4463
- } else {
4464
- if (version > 0 ) {
4465
- // We should honor the version in the original shader if we can, but leave out for now.
4466
- // ss << "#version " << version << "\n";
4467
- if (shaderTypeMap[ shader ] == GL_VERTEX_SHADER) {
4468
- ss << " #define in attribute\n " ;
4469
- ss << " #define out varying\n " ;
4470
- } else {
4471
- ss << " #define in varying\n " ;
4472
- }
4473
- } else {
4474
- ss << " #version 140\n " ;
4475
- }
4476
- }
4477
- if (gles || legacy) {
4478
- if (shaderTypeMap[ shader ] == GL_VERTEX_SHADER) {
4479
- ss << " #define in attribute\n " ;
4480
- ss << " #define out varying\n " ;
4481
- } else {
4482
- ss << " #define in varying\n " ;
4483
- }
4484
- } else {
4485
- if ( shaderTypeMap[ shader ] == GL_VERTEX_SHADER ) {
4486
- } else {
4487
- ss << " #define gl_FragColor rglFragColor\n " ;
4488
- ss << " out vec4 rglFragColor;\n " ;
4489
- ss << " #define texture1D texture\n " ;
4490
- ss << " #define texture2D texture\n " ;
4491
- ss << " #define textureCube texture\n " ;
4492
- }
4493
- }
4494
- if ( gles ) {
4495
- ss << " precision highp float;\n " ;
4496
- }
4497
-
4498
- ss << " #define centroid \n " ;
4499
- ss << " #define gl_FogFragCoord rglFogFragCoord\n " ;
4500
- if ( shaderTypeMap[ shader ] == GL_VERTEX_SHADER ) {
4501
- ss << " #define gl_Vertex rglVertex\n " ;
4502
- ss << " #define gl_Color rglColor\n " ;
4503
- ss << " #define gl_Normal rglNormal\n " ;
4504
- } else {
4505
- ss << " #define gl_Color rglFrontColor\n " ;
4506
- }
4507
- ss << " #define gl_FrontColor rglFrontColor\n " ;
4508
- if ( shaderTypeMap[ shader ] == GL_VERTEX_SHADER ) {
4509
- ss << " #define gl_SecondaryColor rglSecondaryColor\n " ;
4510
- } else {
4511
- ss << " #define gl_SecondaryColor rglFrontSecondaryColor\n " ;
4512
- }
4513
-
4514
- ss << " #define gl_FrontSecondaryColor rglFrontSecondaryColor\n " ;
4515
- ss << " #define gl_ClipVertex rglClipVertex\n " ;
4516
- ss << " #define gl_FragDepth rglFragDepth\n " ;
4517
- if ( gles ) {
4518
- ss << " #define texture3d texture2d\n " ;
4519
- ss << " #define texture3D(a,b) texture2D(a,b.xy)\n " ;
4520
- ss << " #define sampler3D sampler2D\n " ;
4521
- }
4522
-
4523
- if ( src.find ( " gl_FogFragCoord" ) != string::npos ) {
4524
- ss << " out float rglFogFragCoord;\n " ;
4525
- }
4526
-
4527
- // NOTE: ES 2.0 does not support gl_FragDepth, so we just discard it, for now
4528
- // See: http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf
4529
-
4530
- if ( src.find ( " gl_FragDepth" ) != string::npos ) {
4531
- ss << (shaderTypeMap[shader]==GL_VERTEX_SHADER ? " out" : " " ) << " float rglFragDepth;\n " ;
4532
- }
4533
-
4534
- if ( uses_ftransform || (src.find ( " gl_Vertex" ) != string::npos) ) {
4535
- if ( shaderTypeMap[ shader ] == GL_VERTEX_SHADER ) {
4536
- ss << " in vec4 rglVertex;\n " ;
4537
- }
4538
- }
4539
-
4540
- if ( src.find ( " gl_Normal" ) != string::npos ) {
4541
- if ( shaderTypeMap[ shader ] == GL_VERTEX_SHADER ) {
4542
- ss << " in vec3 rglNormal;\n " ;
4543
- }
4544
- }
4545
-
4546
- if ( src.find ( " gl_Color" ) != string::npos ) {
4547
- if ( shaderTypeMap[ shader ] == GL_VERTEX_SHADER ) {
4548
- ss << " in vec4 rglColor;\n " ;
4549
- } else {
4550
- ss << " in vec4 rglFrontColor;\n " ;
4551
- }
4552
- }
4553
-
4554
- if ( src.find ( " gl_FrontColor" ) != string::npos ) {
4555
- ss << " out vec4 rglFrontColor;\n " ;
4556
- }
4557
-
4558
- // NOTE: gl_SecondaryColor can be a vertex shader output, or a fragment shader input.
4559
- // See: http://www.opengl.org/registry/doc/GLSLangSpec.4.30.7.pdf
4560
-
4561
- if ( src.find ( " gl_SecondaryColor" ) != string::npos ) {
4562
- if ( shaderTypeMap[ shader ] == GL_VERTEX_SHADER )
4563
- {
4564
- ss << " in vec4 rglSecondaryColor;\n " ;
4565
- }
4566
- else
4567
- {
4568
- ss << " in vec4 rglFrontSecondaryColor;\n " ;
4569
- }
4570
- }
4571
-
4572
- if ( src.find ( " gl_FrontSecondaryColor" ) != string::npos ) {
4573
- ss << " out vec4 rglFrontSecondaryColor;\n " ;
4574
- }
4575
- if ( src.find ( " gl_ClipVertex" ) != string::npos ) {
4576
- // should be "out", but temporarily disabled due to register pressure concerns
4577
- // ss << "out vec4 rglClipVertex;\n";
4578
- ss << " vec4 rglClipVertex;\n " ;
4579
- }
4580
-
4581
- // the below needs to be automated instead of done ad hoc like this - Cass
4582
- // and it needs to handle "Inverse", "Transpose", and "InverseTranspose".
4583
-
4584
- if ( src.find ( " gl_NormalMatrix" ) != string::npos ) {
4585
- ss << " uniform mat3 rglNormalMatrix;\n " ;
4586
- }
4587
-
4588
- if ( src.find ( " gl_ModelViewMatrix" ) != string::npos || uses_ftransform ) {
4589
- ss << " uniform mat4 rglModelViewMatrix;\n " ;
4590
- }
4591
-
4592
- if ( src.find ( " gl_ModelViewMatrixInverseTranspose" ) != string::npos ) {
4593
- ss << " uniform mat4 rglModelViewMatrixInverseTranspose;\n " ;
4594
- }
4595
-
4596
- if ( src.find ( " gl_ProjectionMatrix" ) != string::npos || uses_ftransform ) {
4597
- ss << " uniform mat4 rglProjectionMatrix;\n " ;
4598
- }
4599
-
4600
- if ( src.find ( " gl_ModelViewProjectionMatrix" ) != string::npos ) {
4601
- ss << " uniform mat4 rglModelViewProjectionMatrix;\n " ;
4602
- }
4603
-
4604
- const char *nums = " 01234567" ;
4605
- for ( int i = 0 ; i < 8 ; i++ ) {
4606
- if ( src.find ( string (" gl_MultiTexCoord" ) + string ( nums + i, 1 )) != string::npos ) {
4607
- ss << " #define gl_MultiTexCoord" << i << " rglMultiTexCoord" << i << " \n " ;
4608
- ss << " in vec4 rglMultiTexCoord" << i << " ;\n " ;
4609
- }
4610
- }
4611
-
4612
- // GAB Note Jan 2019: take "gl_TexCoord" into consideration
4613
- // Assume its size is REGAL_EMU_MAX_TEXTURE_UNITS (maybe this could be optimized by analysing max index used in the source shader
4614
- if ( shaderTypeMap[ shader ] == GL_VERTEX_SHADER ) {
4615
- ss << " #define gl_TexCoord rglTEXCOORD\n " ;
4616
- ss << " out vec4 rglTEXCOORD[" << REGAL_EMU_MAX_TEXTURE_UNITS << " ];\n " ;
4617
- } else {
4618
- ss << " #define gl_TexCoord rglTEXCOORD\n " ;
4619
- ss << " in vec4 rglTEXCOORD[" << REGAL_EMU_MAX_TEXTURE_UNITS << " ];\n " ;
4620
- }
4621
-
4622
- const char * matrixSuffix[] = { " " , " Inverse" , " Transpose" , " InverseTranspose" };
4623
-
4624
- for ( int i = 0 ; i < 4 ; i++ ) {
4625
- ss << " #define gl_ModelViewMatrix" << matrixSuffix[i] << " rglModelViewMatrix" << matrixSuffix[i] << " \n " ;
4626
- ss << " #define gl_ProjectionMatrix" << matrixSuffix[i] << " rglProjectionMatrix" << matrixSuffix[i] << " \n " ;
4627
- ss << " #define gl_ModelViewProjectionMatrix" << matrixSuffix[i] << " rglModelViewProjectionMatrix" << matrixSuffix[i] << " \n " ;
4628
- ss << " #define gl_TextureMatrix0" << matrixSuffix[i] << " rglTextureMatrix0" << matrixSuffix[i] << " \n " ;
4629
- ss << " \n " ;
4630
- }
4631
-
4632
- ss << " #define gl_NormalMatrix rglNormalMatrix\n " ;
4633
-
4634
-
4635
- ss << " #define gl_Sampler0 rglSampler0\n\n " ;
4636
-
4637
- if ( uses_ftransform )
4638
- {
4639
- ss << " vec4 rgl_ftform() { return gl_ProjectionMatrix * gl_ModelViewMatrix * rglVertex; }\n\n " ;
4640
- }
4641
-
4642
- string preamble = ss.str ();
4643
- src = preamble + src;
4644
-
4425
+
4645
4426
const GLchar * dumb = static_cast <const GLchar *>( src.c_str () );
4646
4427
const GLchar ** dumber = & dumb;
4647
4428
ctx->dispatcher .emulation .glShaderSource ( shader, 1 , dumber, NULL );
0 commit comments