[Test] Want to See a GLSL Binary Shader (GL_ARB_get_program_binary)?



OpenGL


As I said in this news, I’ll test as soon as possible the GL_ARB_get_program_binary extension with an OpenGL 2 context. Well, it’s done!

NVIDIA driver R259.09 exposes this extension for an OpenGL 4 context but also for an OpenGL 2 context. So let’s see to what an ascii GLSL shader looks like.

Here is the GLSL vertex shader:

void main()
{
  gl_Position = gl_Vertex;
};

and here is the pixel shader:

void main()
{
  gl_FragColor=vec4(1.0, 0.4, 1.0, 1.0);
};

And here is the binary representation of this very simple GLSL shader:

<span class="offsetheader">Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F</span>
<span class="offsetcol">00000000</span>  <span class="hexcol">01 00 00 00 00 00 00 00 08 00 00 00 44 50 00 03</span>  <span class="textcol">............DP..</span>
<span class="offsetcol">00000010</span>  <span class="hexcol">01 2B 06 00 00 00 00 24 38 06 00 00 C8 91 13 07</span>  <span class="textcol">.+.....$8...È‘..</span>
<span class="offsetcol">00000020</span>  <span class="hexcol">B0 C4 12 07 00 00 00 00 00 00 00 00 00 00 00 00</span>  <span class="textcol">°Ä..............</span>
<span class="offsetcol">00000030</span>  <span class="hexcol">00 00 00 00 00 00 00 00 50 01 86 01 00 00 00 00</span>  <span class="textcol">........P.†.....</span>
<span class="offsetcol">00000040</span>  <span class="hexcol">00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</span>  <span class="textcol">................</span>
<span class="offsetcol">00000050</span>  <span class="hexcol">00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</span>  <span class="textcol">................</span>
<span class="offsetcol">00000060</span>  <span class="hexcol">00 00 00 00 00 00 00 00 FF FF FF FF FF FF FF FF</span>  <span class="textcol">........ÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">00000070</span>  <span class="hexcol">FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF</span>  <span class="textcol">ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">00000080</span>  <span class="hexcol">FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF</span>  <span class="textcol">ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">00000090</span>  <span class="hexcol">FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF</span>  <span class="textcol">ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">000000A0</span>  <span class="hexcol">FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF</span>  <span class="textcol">ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">000000B0</span>  <span class="hexcol">FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF</span>  <span class="textcol">ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">000000C0</span>  <span class="hexcol">FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF</span>  <span class="textcol">ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">000000D0</span>  <span class="hexcol">FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF</span>  <span class="textcol">ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">000000E0</span>  <span class="hexcol">FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF</span>  <span class="textcol">ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">000000F0</span>  <span class="hexcol">FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF</span>  <span class="textcol">ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">00000100</span>  <span class="hexcol">FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF</span>  <span class="textcol">ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">00000110</span>  <span class="hexcol">FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF</span>  <span class="textcol">ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">00000120</span>  <span class="hexcol">FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF</span>  <span class="textcol">ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">00000130</span>  <span class="hexcol">FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF</span>  <span class="textcol">ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">00000140</span>  <span class="hexcol">FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF</span>  <span class="textcol">ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">00000150</span>  <span class="hexcol">FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF</span>  <span class="textcol">ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">00000160</span>  <span class="hexcol">FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF</span>  <span class="textcol">ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">00000170</span>  <span class="hexcol">FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF</span>  <span class="textcol">ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">00000180</span>  <span class="hexcol">FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF</span>  <span class="textcol">ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">00000190</span>  <span class="hexcol">FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF</span>  <span class="textcol">ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ</span>
<span class="offsetcol">000001A0</span>  <span class="hexcol">FF FF FF FF FF FF FF FF 00 00 00 00 01 00 00 00</span>  <span class="textcol">ÿÿÿÿÿÿÿÿ........</span>
<span class="offsetcol">000001B0</span>  <span class="hexcol">48 96 12 07 0A 00 00 00 00 BE 13 07 09 00 00 00</span>  <span class="textcol">H–.......¾......</span>
<span class="offsetcol">000001C0</span>  <span class="hexcol">00 00 00 00 01 00 00 00 D8 C1 12 07 0C 00 00 00</span>  <span class="textcol">........ØÁ......</span>
<span class="offsetcol">000001D0</span>  <span class="hexcol">18 C2 12 07 0B 00 00 00 01 00 00 00 78 96 12 07</span>  <span class="textcol">.Â..........x–..</span>
<span class="offsetcol">000001E0</span>  <span class="hexcol">01 00 00 00 28 BE 13 07 0D 00 00 00 A0 BE 13 07</span>  <span class="textcol">....(¾...... ¾..</span>
<span class="offsetcol">000001F0</span>  <span class="hexcol">00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</span>  <span class="textcol">................</span>
<span class="offsetcol">00000200</span>  <span class="hexcol">00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</span>  <span class="textcol">................</span>
<span class="offsetcol">00000210</span>  <span class="hexcol">00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</span>  <span class="textcol">................</span>
<span class="offsetcol">00000220</span>  <span class="hexcol">00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</span>  <span class="textcol">................</span>
<span class="offsetcol">00000230</span>  <span class="hexcol">00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</span>  <span class="textcol">................</span>
<span class="offsetcol">00000240</span>  <span class="hexcol">00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</span>  <span class="textcol">................</span>
<span class="offsetcol">00000250</span>  <span class="hexcol">00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</span>  <span class="textcol">................</span>
<span class="offsetcol">00000260</span>  <span class="hexcol">00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</span>  <span class="textcol">................</span>
<span class="offsetcol">00000270</span>  <span class="hexcol">00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</span>  <span class="textcol">................</span>
<span class="offsetcol">00000280</span>  <span class="hexcol">00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</span>  <span class="textcol">................</span>
<span class="offsetcol">00000290</span>  <span class="hexcol">00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</span>  <span class="textcol">................</span>
<span class="offsetcol">000002A0</span>  <span class="hexcol">00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</span>  <span class="textcol">................</span>
<span class="offsetcol">000002B0</span>  <span class="hexcol">00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</span>  <span class="textcol">................</span>
<span class="offsetcol">000002C0</span>  <span class="hexcol">00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</span>  <span class="textcol">................</span>
<span class="offsetcol">000002D0</span>  <span class="hexcol">00 00 00 00 01 00 00 00 38 06 00 00 01 01 00 00</span>  <span class="textcol">........8.......</span>
<span class="offsetcol">000002E0</span>  <span class="hexcol">09 00 00 00 00 00 00 00 01 00 00 00 52 8B 00 00</span>  <span class="textcol">............R‹..</span>
<span class="offsetcol">000002F0</span>  <span class="hexcol">00 00 00 00 67 6C 5F 56 65 72 74 65 78 00 00 00</span>  <span class="textcol">....gl_Vertex...</span>
<span class="offsetcol">00000300</span>  <span class="hexcol">00 00 0B 00 00 00 00 00 00 00 01 00 00 00 52 8B</span>  <span class="textcol">..............R‹</span>
<span class="offsetcol">00000310</span>  <span class="hexcol">00 00 01 00 00 00 04 00 00 00 01 00 00 00 00 00</span>  <span class="textcol">................</span>
<span class="offsetcol">00000320</span>  <span class="hexcol">00 00 00 00 00 00 67 6C 5F 50 6F 73 69 74 69 6F</span>  <span class="textcol">......gl_Positio</span>
<span class="offsetcol">00000330</span>  <span class="hexcol">6E 00 0C 00 00 00 00 00 00 00 00 00 00 00 00 00</span>  <span class="textcol">n...............</span>
<span class="offsetcol">00000340</span>  <span class="hexcol">00 00 67 6C 5F 46 72 61 67 43 6F 6C 6F 72 00 82</span>  <span class="textcol">..gl_FragColor.‚</span>
<span class="offsetcol">00000350</span>  <span class="hexcol">01 00 00 21 21 4E 56 76 70 35 2E 30 0A 23 20 63</span>  <span class="textcol">...!!NVvp5.0.# c</span>
<span class="offsetcol">00000360</span>  <span class="hexcol">67 63 20 76 65 72 73 69 6F 6E 20 33 2E 30 2E 30</span>  <span class="textcol">gc version 3.0.0</span>
<span class="offsetcol">00000370</span>  <span class="hexcol">30 30 31 2C 20 62 75 69 6C 64 20 64 61 74 65 20</span>  <span class="textcol">001, build date </span>
<span class="offsetcol">00000380</span>  <span class="hexcol">4A 75 6C 20 32 34 20 32 30 31 30 0A 23 20 63 6F</span>  <span class="textcol">Jul 24 2010.# co</span>
<span class="offsetcol">00000390</span>  <span class="hexcol">6D 6D 61 6E 64 20 6C 69 6E 65 20 61 72 67 73 3A</span>  <span class="textcol">mmand line args:</span>
<span class="offsetcol">000003A0</span>  <span class="hexcol">20 0A 23 76 65 6E 64 6F 72 20 4E 56 49 44 49 41</span>  <span class="textcol"> .#vendor NVIDIA</span>
<span class="offsetcol">000003B0</span>  <span class="hexcol">20 43 6F 72 70 6F 72 61 74 69 6F 6E 0A 23 76 65</span>  <span class="textcol"> Corporation.#ve</span>
<span class="offsetcol">000003C0</span>  <span class="hexcol">72 73 69 6F 6E 20 33 2E 30 2E 30 2E 31 0A 23 70</span>  <span class="textcol">rsion 3.0.0.1.#p</span>
<span class="offsetcol">000003D0</span>  <span class="hexcol">72 6F 66 69 6C 65 20 67 70 35 76 70 0A 23 70 72</span>  <span class="textcol">rofile gp5vp.#pr</span>
<span class="offsetcol">000003E0</span>  <span class="hexcol">6F 67 72 61 6D 20 6D 61 69 6E 0A 23 76 61 72 20</span>  <span class="textcol">ogram main.#var </span>
<span class="offsetcol">000003F0</span>  <span class="hexcol">66 6C 6F 61 74 34 20 67 6C 5F 50 6F 73 69 74 69</span>  <span class="textcol">float4 gl_Positi</span>
<span class="offsetcol">00000400</span>  <span class="hexcol">6F 6E 20 3A 20 24 76 6F 75 74 2E 50 4F 53 49 54</span>  <span class="textcol">on : $vout.POSIT</span>
<span class="offsetcol">00000410</span>  <span class="hexcol">49 4F 4E 20 3A 20 48 50 4F 53 20 3A 20 2D 31 20</span>  <span class="textcol">ION : HPOS : -1 </span>
<span class="offsetcol">00000420</span>  <span class="hexcol">3A 20 31 0A 23 76 61 72 20 66 6C 6F 61 74 34 20</span>  <span class="textcol">: 1.#var float4 </span>
<span class="offsetcol">00000430</span>  <span class="hexcol">67 6C 5F 56 65 72 74 65 78 20 3A 20 24 76 69 6E</span>  <span class="textcol">gl_Vertex : $vin</span>
<span class="offsetcol">00000440</span>  <span class="hexcol">2E 50 4F 53 49 54 49 4F 4E 20 3A 20 41 54 54 52</span>  <span class="textcol">.POSITION : ATTR</span>
<span class="offsetcol">00000450</span>  <span class="hexcol">30 20 3A 20 2D 31 20 3A 20 31 0A 41 54 54 52 49</span>  <span class="textcol">0 : -1 : 1.ATTRI</span>
<span class="offsetcol">00000460</span>  <span class="hexcol">42 20 76 65 72 74 65 78 5F 61 74 74 72 69 62 5B</span>  <span class="textcol">B vertex_attrib[</span>
<span class="offsetcol">00000470</span>  <span class="hexcol">5D 20 3D 20 7B 20 76 65 72 74 65 78 2E 61 74 74</span>  <span class="textcol">] = { vertex.att</span>
<span class="offsetcol">00000480</span>  <span class="hexcol">72 69 62 5B 30 2E 2E 30 5D 20 7D 3B 0A 4D 4F 56</span>  <span class="textcol">rib[0..0] };.MOV</span>
<span class="offsetcol">00000490</span>  <span class="hexcol">2E 46 20 72 65 73 75 6C 74 2E 70 6F 73 69 74 69</span>  <span class="textcol">.F result.positi</span>
<span class="offsetcol">000004A0</span>  <span class="hexcol">6F 6E 2C 20 76 65 72 74 65 78 2E 61 74 74 72 69</span>  <span class="textcol">on, vertex.attri</span>
<span class="offsetcol">000004B0</span>  <span class="hexcol">62 5B 30 5D 3B 0A 45 4E 44 0A 23 20 31 20 69 6E</span>  <span class="textcol">b[0];.END.# 1 in</span>
<span class="offsetcol">000004C0</span>  <span class="hexcol">73 74 72 75 63 74 69 6F 6E 73 2C 20 30 20 52 2D</span>  <span class="textcol">structions, 0 R-</span>
<span class="offsetcol">000004D0</span>  <span class="hexcol">72 65 67 73 0A 00 00 00 00 47 01 00 00 21 21 4E</span>  <span class="textcol">regs.....G...!!N</span>
<span class="offsetcol">000004E0</span>  <span class="hexcol">56 66 70 35 2E 30 0A 23 20 63 67 63 20 76 65 72</span>  <span class="textcol">Vfp5.0.# cgc ver</span>
<span class="offsetcol">000004F0</span>  <span class="hexcol">73 69 6F 6E 20 33 2E 30 2E 30 30 30 31 2C 20 62</span>  <span class="textcol">sion 3.0.0001, b</span>
<span class="offsetcol">00000500</span>  <span class="hexcol">75 69 6C 64 20 64 61 74 65 20 4A 75 6C 20 32 34</span>  <span class="textcol">uild date Jul 24</span>
<span class="offsetcol">00000510</span>  <span class="hexcol">20 32 30 31 30 0A 23 20 63 6F 6D 6D 61 6E 64 20</span>  <span class="textcol"> 2010.# command </span>
<span class="offsetcol">00000520</span>  <span class="hexcol">6C 69 6E 65 20 61 72 67 73 3A 20 0A 23 76 65 6E</span>  <span class="textcol">line args: .#ven</span>
<span class="offsetcol">00000530</span>  <span class="hexcol">64 6F 72 20 4E 56 49 44 49 41 20 43 6F 72 70 6F</span>  <span class="textcol">dor NVIDIA Corpo</span>
<span class="offsetcol">00000540</span>  <span class="hexcol">72 61 74 69 6F 6E 0A 23 76 65 72 73 69 6F 6E 20</span>  <span class="textcol">ration.#version </span>
<span class="offsetcol">00000550</span>  <span class="hexcol">33 2E 30 2E 30 2E 31 0A 23 70 72 6F 66 69 6C 65</span>  <span class="textcol">3.0.0.1.#profile</span>
<span class="offsetcol">00000560</span>  <span class="hexcol">20 67 70 35 66 70 0A 23 70 72 6F 67 72 61 6D 20</span>  <span class="textcol"> gp5fp.#program </span>
<span class="offsetcol">00000570</span>  <span class="hexcol">6D 61 69 6E 0A 23 76 61 72 20 66 6C 6F 61 74 34</span>  <span class="textcol">main.#var float4</span>
<span class="offsetcol">00000580</span>  <span class="hexcol">20 67 6C 5F 46 72 61 67 43 6F 6C 6F 72 20 3A 20</span>  <span class="textcol"> gl_FragColor : </span>
<span class="offsetcol">00000590</span>  <span class="hexcol">24 76 6F 75 74 2E 43 4F 4C 4F 52 20 3A 20 43 4F</span>  <span class="textcol">$vout.COLOR : CO</span>
<span class="offsetcol">000005A0</span>  <span class="hexcol">4C 30 5B 30 5D 20 3A 20 2D 31 20 3A 20 31 0A 4F</span>  <span class="textcol">L0[0] : -1 : 1.O</span>
<span class="offsetcol">000005B0</span>  <span class="hexcol">55 54 50 55 54 20 72 65 73 75 6C 74 5F 63 6F 6C</span>  <span class="textcol">UTPUT result_col</span>
<span class="offsetcol">000005C0</span>  <span class="hexcol">6F 72 30 20 3D 20 72 65 73 75 6C 74 2E 63 6F 6C</span>  <span class="textcol">or0 = result.col</span>
<span class="offsetcol">000005D0</span>  <span class="hexcol">6F 72 3B 0A 4D 4F 56 2E 46 20 72 65 73 75 6C 74</span>  <span class="textcol">or;.MOV.F result</span>
<span class="offsetcol">000005E0</span>  <span class="hexcol">5F 63 6F 6C 6F 72 30 2C 20 7B 31 2C 20 30 2E 34</span>  <span class="textcol">_color0, {1, 0.4</span>
<span class="offsetcol">000005F0</span>  <span class="hexcol">30 30 30 30 30 30 31 2C 20 30 2C 20 30 7D 2E 78</span>  <span class="textcol">0000001, 0, 0}.x</span>
<span class="offsetcol">00000600</span>  <span class="hexcol">79 78 78 3B 0A 45 4E 44 0A 23 20 31 20 69 6E 73</span>  <span class="textcol">yxx;.END.# 1 ins</span>
<span class="offsetcol">00000610</span>  <span class="hexcol">74 72 75 63 74 69 6F 6E 73 2C 20 30 20 52 2D 72</span>  <span class="textcol">tructions, 0 R-r</span>
<span class="offsetcol">00000620</span>  <span class="hexcol">65 67 73 0A 00 00 00 00 00 00 00 00 00 00 00 00</span>  <span class="textcol">egs.............</span>
<span class="offsetcol">00000630</span>  <span class="hexcol">00 00 00 00 00 00 00 00                        </span>  <span class="textcol">........</span>



And here is the code I used to generate this binary shader:

PFNGLGETPROGRAMIVPROC glGetProgramiv = 0;
glGetProgramiv = (PFNGLGETPROGRAMIVPROC)wglGetProcAddress("glGetProgramiv");
typedef void * (WINAPI * PFNGLGETPROGRAMBINARYPROC) (unsigned int,
size_t, size_t *, GLenum *, void *);
PFNGLGETPROGRAMBINARYPROC glGetProgramBinary = 0;
glGetProgramBinary = 
(PFNGLGETPROGRAMBINARYPROC)wglGetProcAddress("glGetProgramBinary");
if (glGetProgramBinary && glGetProgramiv)
{
  static char *vertexShader=\
      "void main()"
      "{"
          "gl_Position = gl_Vertex;"
      "}";

  static char *fragmentShader=\
      "void main()"
      "{"
          "gl_FragColor=vec4(1.0, 0.4, 1.0, 1.0);"
      "}";
  
  int p = glCreateProgram();
  int v = glCreateShader(GL_VERTEX_SHADER);
  glShaderSource(v, 1, &vertexShader, 0);
  glCompileShader(v);
  glAttachShader(p,v);
  int f = glCreateShader(GL_FRAGMENT_SHADER);	
  glShaderSource(f, 1, &fragmentShader, 0);
  glCompileShader(f);
  glAttachShader(p,f);
  glLinkProgram(p);
  glUseProgram(p);

  #define GL_NUM_PROGRAM_BINARY_FORMATS 0x87FE
  #define GL_PROGRAM_BINARY_FORMATS 0x87FF
  GLint formats = 0;
  glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &formats);
  GLint *binaryFormats = new GLint[formats];
  glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, binaryFormats);

  #define GL_PROGRAM_BINARY_LENGTH 0x8741
  GLint len=0;
  GLint progId = gpu->getGpuShaderData()->m_program_id;
  glGetProgramiv(progId, GL_PROGRAM_BINARY_LENGTH, &len);
  u8* binary = new u8[len];
  glGetProgramBinary(progId, len, NULL, (GLenum*)binaryFormats, binary);
  glUseProgram(0);
  
  FILE* fp = fopen("shader.bin", "wb");
  fwrite(binary, len, 1, fp);
  fclose(fp);
  
  delete [] binary;
  
  // Don't forget the destruction of the GLSL shader...
  // ...
}


9 thoughts on “[Test] Want to See a GLSL Binary Shader (GL_ARB_get_program_binary)?”

  1. Cyril

    Humm… It looks like the beginning is simply a binary header, and that the code is in fact an NVvp5.0 ARB assembly stored in text format at the end, no ?

  2. susheel

    Finally!! It’s about time.

    …After shouting for years on the OpenGL board!

  3. nap

    It will be very interesting to see timings of loading precompiled shader and loading shader with compilation in realtime.

  4. Leith

    Might be good to look at what the Cg toolkit produces in binary as I’m sure they will be related.

  5. Leith

    #cgc version 3.0.0001, build date Jul 24 2010
    # command line args:
    #vendor NVIDIA Corporation
    #version 3.0.0.1
    #profile gp5vp

    There you go.

    That is what you need to run Cg with to get the same or similar output.

  6. Christophe

    The binary API have been design for caching purposes.

    Loading can fail for any reason and it is not attended to be use for shipping within a software release.

  7. MaNiAc

    @Christophe: I have a feeling that you’re right, although i can’t see any solid proof (yet). :-)

    I guess the best practice is still to compile shaders during the first run of the application, then to save them in compiled format in a cache dir or whatever and only recompile them upon forced cache rebuild or hardware change, etc.

  8. swajnaut

    Not that i don’t realize this thread is year old … but you’re doing it wrong.

    glGetProgramBinary() *writes* to binaryFormats, there is no need to call

    glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &formats);
    glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, binaryFormats);

    It is sufficient to allocate space for a single binary format (or just use plain scalar variable).
    On the other hand, you *must* store the binary format that is returned so it can be passed to glProgramBinary() once the program is loaded.

    The only reason why this works is the implementation actually only defines a single binary format, so you can’t go wrong … but in the future, there might be more formats and your code will cease wokring. Read the specs!

  9. Gianni

    Did you try that on a Radeon as well?

    On a nVidia card it’s compiled to a NVvp5.0 assembly, what does it get compiled to on a Radeon?

Comments are closed.