Advertisement
amulware

Transform feedback test

Dec 25th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.21 KB | None | 0 0
  1. Console.WriteLine(GL.GetString(StringName.Vendor));
  2. Console.WriteLine(GL.GetString(StringName.Renderer));
  3. Console.WriteLine(GL.GetString(StringName.Version));
  4. Console.WriteLine(GL.GetString(StringName.ShadingLanguageVersion));
  5.  
  6. const string shaderSource =
  7. #region source
  8. @"
  9. #version 150
  10.  
  11. uniform sampler2D accelerationTexture;
  12. uniform float timeDelta;
  13.  
  14. in vec3 v_position;
  15. in vec3 v_velocity;
  16. in float v_deathTime;
  17. in float v_angle;
  18. in float v_angleVelocity;
  19. in vec2 v_size;
  20. in vec2 v_uv00;
  21. in vec2 v_uv10;
  22. in vec2 v_uv01;
  23. in vec2 v_uv11;
  24. in vec3 v_unitX;
  25. in vec3 v_unitY;
  26.  
  27. out vec3 t_position;
  28. out vec3 t_velocity;
  29. out float t_deathTime;
  30. out float t_angle;
  31. out float t_angleVelocity;
  32. out vec2 t_size;
  33. out vec2 t_uv00;
  34. out vec2 t_uv10;
  35. out vec2 t_uv01;
  36. out vec2 t_uv11;
  37. out vec3 t_unitX;
  38. out vec3 t_unitY;
  39.  
  40. void main()
  41. {
  42. const float width = 40;
  43. const float height = 25;
  44. const float xOffset = width * 0.5;
  45. const float yOffset = 3;
  46.  
  47. vec2 aUV = v_position.xy;
  48. aUV.x = (aUV.x + xOffset) / width;
  49. aUV.y = (aUV.y + yOffset) / height;
  50.  
  51. vec2 a = texture(accelerationTexture, aUV).xy;
  52.  
  53. vec3 v = v_velocity;
  54. v.xy += a;
  55.  
  56. t_position = v_position + v * timeDelta;
  57. t_velocity = v;
  58. t_deathTime = v_deathTime;
  59. t_angle = v_angle + v_angleVelocity * timeDelta;
  60. t_angleVelocity = v_angleVelocity;
  61. t_size = v_size;
  62. t_uv00 = v_uv00;
  63. t_uv10 = v_uv10;
  64. t_uv01 = v_uv01;
  65. t_uv11 = v_uv11;
  66. t_unitX = v_unitX;
  67. t_unitY = v_unitY;
  68. }
  69.  
  70. ";
  71. #endregion
  72.  
  73. string[] varyings =
  74. #region varyings
  75.     {
  76.         "t_position",
  77.         "t_velocity",
  78.         "t_deathTime",
  79.         "t_angle",
  80.         "t_angleVelocity",
  81.         "t_size",
  82.         "t_uv00",
  83.         "t_uv10",
  84.         "t_uv01",
  85.         "t_uv11",
  86.         "t_unitX",
  87.         "t_unitY",
  88.     };
  89. #endregion
  90.  
  91. var vs = GL.CreateShader(ShaderType.VertexShader);
  92. #region compile shader
  93. GL.ShaderSource(vs, shaderSource);
  94. GL.CompileShader(vs);
  95.  
  96. int statusCode;
  97. GL.GetShader(vs, ShaderParameter.CompileStatus, out statusCode);
  98.  
  99. if (statusCode != 1)
  100. {
  101.     string info;
  102.     GL.GetShaderInfoLog(vs, out info);
  103.     Console.WriteLine("Could not compile shader: " + info);
  104. }
  105. else
  106. {
  107.     Console.WriteLine("Compiled shader.");
  108. }
  109. #endregion
  110.  
  111. var p = GL.CreateProgram();
  112. #region create program
  113. GL.AttachShader(p, vs);
  114.  
  115. GL.TransformFeedbackVaryings(p, varyings.Length, varyings,
  116.     TransformFeedbackMode.InterleavedAttribs);
  117.  
  118. GL.LinkProgram(p);
  119.  
  120. GL.GetProgram(p, GetProgramParameterName.LinkStatus, out statusCode);
  121.  
  122. if (statusCode != 1)
  123. {
  124.     string info;
  125.     GL.GetProgramInfoLog(p, out info);
  126.     Console.WriteLine("Could not link program: " + info);
  127. }
  128. else
  129. {
  130.     Console.WriteLine("Linked program.");
  131. }
  132. #endregion
  133.  
  134. #region GetProgramInterface
  135. int i = 0;
  136. GL.GetProgramInterface(p, ProgramInterface.TransformFeedbackVarying,
  137.     ProgramInterfaceParameter.MaxNameLength, out i);
  138. Console.WriteLine("MaxNameLength: " + i);
  139. Console.WriteLine(GL.GetError());
  140.  
  141. GL.GetProgramInterface(p, ProgramInterface.TransformFeedbackVarying,
  142.     ProgramInterfaceParameter.ActiveResources, out i);
  143. Console.WriteLine("ActiveResources: " + i);
  144. Console.WriteLine(GL.GetError());
  145. #endregion
  146.  
  147.  
  148. Console.WriteLine("all done");
  149. Console.WriteLine(GL.GetError());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement