@@ -1337,6 +1337,23 @@ public void filter(PShader shader) {
1337
1337
// SHADER API
1338
1338
1339
1339
1340
+ @ Override
1341
+ public PShader loadShader (String fragFilename ) {
1342
+ if (fragFilename == null || fragFilename .equals ("" )) {
1343
+ PGraphics .showWarning (MISSING_FRAGMENT_SHADER );
1344
+ return null ;
1345
+ }
1346
+
1347
+ PShader shader = new PShader (parent );
1348
+
1349
+ shader .setFragmentShader (fragFilename );
1350
+ String [] vertSource = pgl .loadVertexShader (defP2DShaderVertURL );
1351
+ shader .setVertexShader (vertSource );
1352
+
1353
+ return shader ;
1354
+ }
1355
+
1356
+
1340
1357
@ Override
1341
1358
public void shader (PShader shader ) {
1342
1359
if (useParentImpl ) {
@@ -1676,18 +1693,22 @@ private boolean checkShaderLocs(PShader shader) {
1676
1693
positionLoc = shader .getAttributeLoc ("vertex" );
1677
1694
}
1678
1695
int colorLoc = shader .getAttributeLoc ("color" );
1679
- int texCoordLoc = shader .getAttributeLoc ("texCoord" );
1680
- int texFactorLoc = shader .getAttributeLoc ("texFactor" );
1681
1696
int transformLoc = shader .getUniformLoc ("transform" );
1682
1697
if (transformLoc == -1 ) {
1683
1698
transformLoc = shader .getUniformLoc ("transformMatrix" );
1684
1699
}
1700
+
1701
+ /*
1685
1702
int texScaleLoc = shader.getUniformLoc("texScale");
1686
1703
if (texScaleLoc == -1) {
1687
1704
texScaleLoc = shader.getUniformLoc("texOffset");
1688
1705
}
1689
- return positionLoc != -1 && colorLoc != -1 && texCoordLoc != -1 &&
1690
- texFactorLoc != -1 && transformLoc != -1 && texScaleLoc != -1 ;
1706
+ int texCoordLoc = shader.getAttributeLoc("texCoord");
1707
+ int texFactorLoc = shader.getAttributeLoc("texFactor");
1708
+ */
1709
+
1710
+ return positionLoc != -1 && colorLoc != -1 && transformLoc != -1 ;
1711
+ // texCoordLoc != -1 && texFactorLoc != -1 && texScaleLoc != -1;
1691
1712
}
1692
1713
1693
1714
@@ -1717,15 +1738,14 @@ private PShader getShader() {
1717
1738
String [] vertSource = pgl .loadVertexShader (defP2DShaderVertURL );
1718
1739
String [] fragSource = pgl .loadFragmentShader (defP2DShaderFragURL );
1719
1740
defTwoShader = new PShader (parent , vertSource , fragSource );
1720
- loadShaderLocs (defTwoShader );
1721
1741
}
1722
1742
shader = defTwoShader ;
1723
1743
} else {
1724
1744
shader = twoShader ;
1725
1745
}
1726
- if (shader != defTwoShader ) {
1727
- loadShaderLocs (shader );
1728
- }
1746
+ // if (shader != defTwoShader) {
1747
+ loadShaderLocs (shader );
1748
+ // }
1729
1749
return shader ;
1730
1750
}
1731
1751
@@ -1737,12 +1757,16 @@ protected PShader getPolyShader(boolean lit, boolean tex) {
1737
1757
private void setAttribs () {
1738
1758
pgl .vertexAttribPointer (positionLoc , 3 , PGL .FLOAT , false , vertSize , 0 );
1739
1759
pgl .enableVertexAttribArray (positionLoc );
1740
- pgl .vertexAttribPointer (texCoordLoc , 2 , PGL .FLOAT , false , vertSize , 3 *Float .BYTES );
1741
- pgl .enableVertexAttribArray (texCoordLoc );
1760
+ if (-1 < texCoordLoc ) {
1761
+ pgl .vertexAttribPointer (texCoordLoc , 2 , PGL .FLOAT , false , vertSize , 3 *Float .BYTES );
1762
+ pgl .enableVertexAttribArray (texCoordLoc );
1763
+ }
1742
1764
pgl .vertexAttribPointer (colorLoc , 4 , PGL .UNSIGNED_BYTE , true , vertSize , 5 *Float .BYTES );
1743
1765
pgl .enableVertexAttribArray (colorLoc );
1744
- pgl .vertexAttribPointer (texFactorLoc , 1 , PGL .FLOAT , false , vertSize , 6 *Float .BYTES );
1745
- pgl .enableVertexAttribArray (texFactorLoc );
1766
+ if (-1 < texFactorLoc ) {
1767
+ pgl .vertexAttribPointer (texFactorLoc , 1 , PGL .FLOAT , false , vertSize , 6 *Float .BYTES );
1768
+ pgl .enableVertexAttribArray (texFactorLoc );
1769
+ }
1746
1770
}
1747
1771
1748
1772
@@ -1757,11 +1781,13 @@ private void loadUniforms() {
1757
1781
//set texture info
1758
1782
pgl .activeTexture (PGL .TEXTURE0 );
1759
1783
pgl .bindTexture (PGL .TEXTURE_2D , tex );
1760
- //enable uv scaling only for use-defined images, not for fonts
1761
- if (tex == imageTex ) {
1762
- pgl .uniform2f (texScaleLoc , 1f /texWidth , 1f /texHeight );
1763
- } else {
1764
- pgl .uniform2f (texScaleLoc , 1 , 1 );
1784
+ if (-1 < texScaleLoc ) {
1785
+ //enable uv scaling only for use-defined images, not for fonts
1786
+ if (tex == imageTex ) {
1787
+ pgl .uniform2f (texScaleLoc , 1f /texWidth , 1f /texHeight );
1788
+ } else {
1789
+ pgl .uniform2f (texScaleLoc , 1 , 1 );
1790
+ }
1765
1791
}
1766
1792
}
1767
1793
0 commit comments