OGLPipeline.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. using OpenTK.Graphics.OpenGL;
  2. using System;
  3. using System.Collections.Generic;
  4. namespace Ryujinx.Graphics.Gal.OpenGL
  5. {
  6. class OGLPipeline : IGalPipeline
  7. {
  8. private static Dictionary<GalVertexAttribSize, int> AttribElements =
  9. new Dictionary<GalVertexAttribSize, int>()
  10. {
  11. { GalVertexAttribSize._32_32_32_32, 4 },
  12. { GalVertexAttribSize._32_32_32, 3 },
  13. { GalVertexAttribSize._16_16_16_16, 4 },
  14. { GalVertexAttribSize._32_32, 2 },
  15. { GalVertexAttribSize._16_16_16, 3 },
  16. { GalVertexAttribSize._8_8_8_8, 4 },
  17. { GalVertexAttribSize._16_16, 2 },
  18. { GalVertexAttribSize._32, 1 },
  19. { GalVertexAttribSize._8_8_8, 3 },
  20. { GalVertexAttribSize._8_8, 2 },
  21. { GalVertexAttribSize._16, 1 },
  22. { GalVertexAttribSize._8, 1 },
  23. { GalVertexAttribSize._10_10_10_2, 4 },
  24. { GalVertexAttribSize._11_11_10, 3 }
  25. };
  26. private static Dictionary<GalVertexAttribSize, VertexAttribPointerType> FloatAttribTypes =
  27. new Dictionary<GalVertexAttribSize, VertexAttribPointerType>()
  28. {
  29. { GalVertexAttribSize._32_32_32_32, VertexAttribPointerType.Float },
  30. { GalVertexAttribSize._32_32_32, VertexAttribPointerType.Float },
  31. { GalVertexAttribSize._16_16_16_16, VertexAttribPointerType.HalfFloat },
  32. { GalVertexAttribSize._32_32, VertexAttribPointerType.Float },
  33. { GalVertexAttribSize._16_16_16, VertexAttribPointerType.HalfFloat },
  34. { GalVertexAttribSize._16_16, VertexAttribPointerType.HalfFloat },
  35. { GalVertexAttribSize._32, VertexAttribPointerType.Float },
  36. { GalVertexAttribSize._16, VertexAttribPointerType.HalfFloat }
  37. };
  38. private static Dictionary<GalVertexAttribSize, VertexAttribPointerType> SignedAttribTypes =
  39. new Dictionary<GalVertexAttribSize, VertexAttribPointerType>()
  40. {
  41. { GalVertexAttribSize._32_32_32_32, VertexAttribPointerType.Int },
  42. { GalVertexAttribSize._32_32_32, VertexAttribPointerType.Int },
  43. { GalVertexAttribSize._16_16_16_16, VertexAttribPointerType.Short },
  44. { GalVertexAttribSize._32_32, VertexAttribPointerType.Int },
  45. { GalVertexAttribSize._16_16_16, VertexAttribPointerType.Short },
  46. { GalVertexAttribSize._8_8_8_8, VertexAttribPointerType.Byte },
  47. { GalVertexAttribSize._16_16, VertexAttribPointerType.Short },
  48. { GalVertexAttribSize._32, VertexAttribPointerType.Int },
  49. { GalVertexAttribSize._8_8_8, VertexAttribPointerType.Byte },
  50. { GalVertexAttribSize._8_8, VertexAttribPointerType.Byte },
  51. { GalVertexAttribSize._16, VertexAttribPointerType.Short },
  52. { GalVertexAttribSize._8, VertexAttribPointerType.Byte },
  53. { GalVertexAttribSize._10_10_10_2, VertexAttribPointerType.Int2101010Rev }
  54. };
  55. private static Dictionary<GalVertexAttribSize, VertexAttribPointerType> UnsignedAttribTypes =
  56. new Dictionary<GalVertexAttribSize, VertexAttribPointerType>()
  57. {
  58. { GalVertexAttribSize._32_32_32_32, VertexAttribPointerType.UnsignedInt },
  59. { GalVertexAttribSize._32_32_32, VertexAttribPointerType.UnsignedInt },
  60. { GalVertexAttribSize._16_16_16_16, VertexAttribPointerType.UnsignedShort },
  61. { GalVertexAttribSize._32_32, VertexAttribPointerType.UnsignedInt },
  62. { GalVertexAttribSize._16_16_16, VertexAttribPointerType.UnsignedShort },
  63. { GalVertexAttribSize._8_8_8_8, VertexAttribPointerType.UnsignedByte },
  64. { GalVertexAttribSize._16_16, VertexAttribPointerType.UnsignedShort },
  65. { GalVertexAttribSize._32, VertexAttribPointerType.UnsignedInt },
  66. { GalVertexAttribSize._8_8_8, VertexAttribPointerType.UnsignedByte },
  67. { GalVertexAttribSize._8_8, VertexAttribPointerType.UnsignedByte },
  68. { GalVertexAttribSize._16, VertexAttribPointerType.UnsignedShort },
  69. { GalVertexAttribSize._8, VertexAttribPointerType.UnsignedByte },
  70. { GalVertexAttribSize._10_10_10_2, VertexAttribPointerType.UnsignedInt2101010Rev },
  71. { GalVertexAttribSize._11_11_10, VertexAttribPointerType.UnsignedInt10F11F11FRev }
  72. };
  73. private GalPipelineState Old;
  74. private OGLConstBuffer Buffer;
  75. private OGLRasterizer Rasterizer;
  76. private OGLShader Shader;
  77. private int VaoHandle;
  78. public OGLPipeline(OGLConstBuffer Buffer, OGLRasterizer Rasterizer, OGLShader Shader)
  79. {
  80. this.Buffer = Buffer;
  81. this.Rasterizer = Rasterizer;
  82. this.Shader = Shader;
  83. //These values match OpenGL's defaults
  84. Old = new GalPipelineState
  85. {
  86. FrontFace = GalFrontFace.CCW,
  87. CullFaceEnabled = false,
  88. CullFace = GalCullFace.Back,
  89. DepthTestEnabled = false,
  90. DepthWriteEnabled = true,
  91. DepthFunc = GalComparisonOp.Less,
  92. StencilTestEnabled = false,
  93. StencilBackFuncFunc = GalComparisonOp.Always,
  94. StencilBackFuncRef = 0,
  95. StencilBackFuncMask = UInt32.MaxValue,
  96. StencilBackOpFail = GalStencilOp.Keep,
  97. StencilBackOpZFail = GalStencilOp.Keep,
  98. StencilBackOpZPass = GalStencilOp.Keep,
  99. StencilBackMask = UInt32.MaxValue,
  100. StencilFrontFuncFunc = GalComparisonOp.Always,
  101. StencilFrontFuncRef = 0,
  102. StencilFrontFuncMask = UInt32.MaxValue,
  103. StencilFrontOpFail = GalStencilOp.Keep,
  104. StencilFrontOpZFail = GalStencilOp.Keep,
  105. StencilFrontOpZPass = GalStencilOp.Keep,
  106. StencilFrontMask = UInt32.MaxValue,
  107. BlendEnabled = false,
  108. BlendSeparateAlpha = false,
  109. BlendEquationRgb = 0,
  110. BlendFuncSrcRgb = GalBlendFactor.One,
  111. BlendFuncDstRgb = GalBlendFactor.Zero,
  112. BlendEquationAlpha = 0,
  113. BlendFuncSrcAlpha = GalBlendFactor.One,
  114. BlendFuncDstAlpha = GalBlendFactor.Zero,
  115. PrimitiveRestartEnabled = false,
  116. PrimitiveRestartIndex = 0
  117. };
  118. }
  119. public void Bind(GalPipelineState New)
  120. {
  121. BindConstBuffers(New);
  122. BindVertexLayout(New);
  123. if (New.FramebufferSrgb != Old.FramebufferSrgb)
  124. {
  125. Enable(EnableCap.FramebufferSrgb, New.FramebufferSrgb);
  126. }
  127. if (New.FlipX != Old.FlipX || New.FlipY != Old.FlipY || New.Instance != Old.Instance)
  128. {
  129. Shader.SetExtraData(New.FlipX, New.FlipY, New.Instance);
  130. }
  131. //Note: Uncomment SetFrontFace and SetCullFace when flipping issues are solved
  132. //if (New.FrontFace != Old.FrontFace)
  133. //{
  134. // GL.FrontFace(OGLEnumConverter.GetFrontFace(New.FrontFace));
  135. //}
  136. //if (New.CullFaceEnabled != Old.CullFaceEnabled)
  137. //{
  138. // Enable(EnableCap.CullFace, New.CullFaceEnabled);
  139. //}
  140. //if (New.CullFaceEnabled)
  141. //{
  142. // if (New.CullFace != Old.CullFace)
  143. // {
  144. // GL.CullFace(OGLEnumConverter.GetCullFace(New.CullFace));
  145. // }
  146. //}
  147. if (New.DepthTestEnabled != Old.DepthTestEnabled)
  148. {
  149. Enable(EnableCap.DepthTest, New.DepthTestEnabled);
  150. }
  151. if (New.DepthWriteEnabled != Old.DepthWriteEnabled)
  152. {
  153. Rasterizer.DepthWriteEnabled = New.DepthWriteEnabled;
  154. GL.DepthMask(New.DepthWriteEnabled);
  155. }
  156. if (New.DepthTestEnabled)
  157. {
  158. if (New.DepthFunc != Old.DepthFunc)
  159. {
  160. GL.DepthFunc(OGLEnumConverter.GetDepthFunc(New.DepthFunc));
  161. }
  162. }
  163. if (New.StencilTestEnabled != Old.StencilTestEnabled)
  164. {
  165. Enable(EnableCap.StencilTest, New.StencilTestEnabled);
  166. }
  167. if (New.StencilTestEnabled)
  168. {
  169. if (New.StencilBackFuncFunc != Old.StencilBackFuncFunc ||
  170. New.StencilBackFuncRef != Old.StencilBackFuncRef ||
  171. New.StencilBackFuncMask != Old.StencilBackFuncMask)
  172. {
  173. GL.StencilFuncSeparate(
  174. StencilFace.Back,
  175. OGLEnumConverter.GetStencilFunc(New.StencilBackFuncFunc),
  176. New.StencilBackFuncRef,
  177. New.StencilBackFuncMask);
  178. }
  179. if (New.StencilBackOpFail != Old.StencilBackOpFail ||
  180. New.StencilBackOpZFail != Old.StencilBackOpZFail ||
  181. New.StencilBackOpZPass != Old.StencilBackOpZPass)
  182. {
  183. GL.StencilOpSeparate(
  184. StencilFace.Back,
  185. OGLEnumConverter.GetStencilOp(New.StencilBackOpFail),
  186. OGLEnumConverter.GetStencilOp(New.StencilBackOpZFail),
  187. OGLEnumConverter.GetStencilOp(New.StencilBackOpZPass));
  188. }
  189. if (New.StencilBackMask != Old.StencilBackMask)
  190. {
  191. GL.StencilMaskSeparate(StencilFace.Back, New.StencilBackMask);
  192. }
  193. if (New.StencilFrontFuncFunc != Old.StencilFrontFuncFunc ||
  194. New.StencilFrontFuncRef != Old.StencilFrontFuncRef ||
  195. New.StencilFrontFuncMask != Old.StencilFrontFuncMask)
  196. {
  197. GL.StencilFuncSeparate(
  198. StencilFace.Front,
  199. OGLEnumConverter.GetStencilFunc(New.StencilFrontFuncFunc),
  200. New.StencilFrontFuncRef,
  201. New.StencilFrontFuncMask);
  202. }
  203. if (New.StencilFrontOpFail != Old.StencilFrontOpFail ||
  204. New.StencilFrontOpZFail != Old.StencilFrontOpZFail ||
  205. New.StencilFrontOpZPass != Old.StencilFrontOpZPass)
  206. {
  207. GL.StencilOpSeparate(
  208. StencilFace.Front,
  209. OGLEnumConverter.GetStencilOp(New.StencilFrontOpFail),
  210. OGLEnumConverter.GetStencilOp(New.StencilFrontOpZFail),
  211. OGLEnumConverter.GetStencilOp(New.StencilFrontOpZPass));
  212. }
  213. if (New.StencilFrontMask != Old.StencilFrontMask)
  214. {
  215. GL.StencilMaskSeparate(StencilFace.Front, New.StencilFrontMask);
  216. }
  217. }
  218. if (New.BlendEnabled != Old.BlendEnabled)
  219. {
  220. Enable(EnableCap.Blend, New.BlendEnabled);
  221. }
  222. if (New.BlendEnabled)
  223. {
  224. if (New.BlendSeparateAlpha)
  225. {
  226. if (New.BlendEquationRgb != Old.BlendEquationRgb ||
  227. New.BlendEquationAlpha != Old.BlendEquationAlpha)
  228. {
  229. GL.BlendEquationSeparate(
  230. OGLEnumConverter.GetBlendEquation(New.BlendEquationRgb),
  231. OGLEnumConverter.GetBlendEquation(New.BlendEquationAlpha));
  232. }
  233. if (New.BlendFuncSrcRgb != Old.BlendFuncSrcRgb ||
  234. New.BlendFuncDstRgb != Old.BlendFuncDstRgb ||
  235. New.BlendFuncSrcAlpha != Old.BlendFuncSrcAlpha ||
  236. New.BlendFuncDstAlpha != Old.BlendFuncDstAlpha)
  237. {
  238. GL.BlendFuncSeparate(
  239. (BlendingFactorSrc) OGLEnumConverter.GetBlendFactor(New.BlendFuncSrcRgb),
  240. (BlendingFactorDest)OGLEnumConverter.GetBlendFactor(New.BlendFuncDstRgb),
  241. (BlendingFactorSrc) OGLEnumConverter.GetBlendFactor(New.BlendFuncSrcAlpha),
  242. (BlendingFactorDest)OGLEnumConverter.GetBlendFactor(New.BlendFuncDstAlpha));
  243. }
  244. }
  245. else
  246. {
  247. if (New.BlendEquationRgb != Old.BlendEquationRgb)
  248. {
  249. GL.BlendEquation(OGLEnumConverter.GetBlendEquation(New.BlendEquationRgb));
  250. }
  251. if (New.BlendFuncSrcRgb != Old.BlendFuncSrcRgb ||
  252. New.BlendFuncDstRgb != Old.BlendFuncDstRgb)
  253. {
  254. GL.BlendFunc(
  255. OGLEnumConverter.GetBlendFactor(New.BlendFuncSrcRgb),
  256. OGLEnumConverter.GetBlendFactor(New.BlendFuncDstRgb));
  257. }
  258. }
  259. }
  260. if (New.PrimitiveRestartEnabled != Old.PrimitiveRestartEnabled)
  261. {
  262. Enable(EnableCap.PrimitiveRestart, New.PrimitiveRestartEnabled);
  263. }
  264. if (New.PrimitiveRestartEnabled)
  265. {
  266. if (New.PrimitiveRestartIndex != Old.PrimitiveRestartIndex)
  267. {
  268. GL.PrimitiveRestartIndex(New.PrimitiveRestartIndex);
  269. }
  270. }
  271. Old = New;
  272. }
  273. private void BindConstBuffers(GalPipelineState New)
  274. {
  275. int FreeBinding = OGLShader.ReservedCbufCount;
  276. void BindIfNotNull(OGLShaderStage Stage)
  277. {
  278. if (Stage != null)
  279. {
  280. foreach (ShaderDeclInfo DeclInfo in Stage.ConstBufferUsage)
  281. {
  282. long Key = New.ConstBufferKeys[(int)Stage.Type][DeclInfo.Cbuf];
  283. if (Key != 0 && Buffer.TryGetUbo(Key, out int UboHandle))
  284. {
  285. GL.BindBufferBase(BufferRangeTarget.UniformBuffer, FreeBinding, UboHandle);
  286. }
  287. FreeBinding++;
  288. }
  289. }
  290. }
  291. BindIfNotNull(Shader.Current.Vertex);
  292. BindIfNotNull(Shader.Current.TessControl);
  293. BindIfNotNull(Shader.Current.TessEvaluation);
  294. BindIfNotNull(Shader.Current.Geometry);
  295. BindIfNotNull(Shader.Current.Fragment);
  296. }
  297. private void BindVertexLayout(GalPipelineState New)
  298. {
  299. foreach (GalVertexBinding Binding in New.VertexBindings)
  300. {
  301. if (!Binding.Enabled || !Rasterizer.TryGetVbo(Binding.VboKey, out int VboHandle))
  302. {
  303. continue;
  304. }
  305. if (VaoHandle == 0)
  306. {
  307. VaoHandle = GL.GenVertexArray();
  308. //Vertex arrays shouldn't be used anywhere else in OpenGL's backend
  309. //if you want to use it, move this line out of the if
  310. GL.BindVertexArray(VaoHandle);
  311. }
  312. foreach (GalVertexAttrib Attrib in Binding.Attribs)
  313. {
  314. //Skip uninitialized attributes.
  315. if (Attrib.Size == 0)
  316. {
  317. continue;
  318. }
  319. GL.BindBuffer(BufferTarget.ArrayBuffer, VboHandle);
  320. bool Unsigned =
  321. Attrib.Type == GalVertexAttribType.Unorm ||
  322. Attrib.Type == GalVertexAttribType.Uint ||
  323. Attrib.Type == GalVertexAttribType.Uscaled;
  324. bool Normalize =
  325. Attrib.Type == GalVertexAttribType.Snorm ||
  326. Attrib.Type == GalVertexAttribType.Unorm;
  327. VertexAttribPointerType Type = 0;
  328. if (Attrib.Type == GalVertexAttribType.Float)
  329. {
  330. Type = GetType(FloatAttribTypes, Attrib);
  331. }
  332. else
  333. {
  334. if (Unsigned)
  335. {
  336. Type = GetType(UnsignedAttribTypes, Attrib);
  337. }
  338. else
  339. {
  340. Type = GetType(SignedAttribTypes, Attrib);
  341. }
  342. }
  343. if (!AttribElements.TryGetValue(Attrib.Size, out int Size))
  344. {
  345. throw new InvalidOperationException("Invalid attribute size \"" + Attrib.Size + "\"!");
  346. }
  347. int Offset = Attrib.Offset;
  348. if (Binding.Stride != 0)
  349. {
  350. GL.EnableVertexAttribArray(Attrib.Index);
  351. if (Attrib.Type == GalVertexAttribType.Sint ||
  352. Attrib.Type == GalVertexAttribType.Uint)
  353. {
  354. IntPtr Pointer = new IntPtr(Offset);
  355. VertexAttribIntegerType IType = (VertexAttribIntegerType)Type;
  356. GL.VertexAttribIPointer(Attrib.Index, Size, IType, Binding.Stride, Pointer);
  357. }
  358. else
  359. {
  360. GL.VertexAttribPointer(Attrib.Index, Size, Type, Normalize, Binding.Stride, Offset);
  361. }
  362. }
  363. else
  364. {
  365. GL.DisableVertexAttribArray(Attrib.Index);
  366. SetConstAttrib(Attrib);
  367. }
  368. if (Binding.Instanced && Binding.Divisor != 0)
  369. {
  370. GL.VertexAttribDivisor(Attrib.Index, 1);
  371. }
  372. else
  373. {
  374. GL.VertexAttribDivisor(Attrib.Index, 0);
  375. }
  376. }
  377. }
  378. }
  379. private static VertexAttribPointerType GetType(Dictionary<GalVertexAttribSize, VertexAttribPointerType> Dict, GalVertexAttrib Attrib)
  380. {
  381. if (!Dict.TryGetValue(Attrib.Size, out VertexAttribPointerType Type))
  382. {
  383. throw new NotImplementedException("Unsupported size \"" + Attrib.Size + "\" on type \"" + Attrib.Type + "\"!");
  384. }
  385. return Type;
  386. }
  387. private unsafe static void SetConstAttrib(GalVertexAttrib Attrib)
  388. {
  389. void Unsupported()
  390. {
  391. throw new NotImplementedException("Constant attribute " + Attrib.Size + " not implemented!");
  392. }
  393. if (Attrib.Size == GalVertexAttribSize._10_10_10_2 ||
  394. Attrib.Size == GalVertexAttribSize._11_11_10)
  395. {
  396. Unsupported();
  397. }
  398. if (Attrib.Type == GalVertexAttribType.Unorm)
  399. {
  400. switch (Attrib.Size)
  401. {
  402. case GalVertexAttribSize._8:
  403. case GalVertexAttribSize._8_8:
  404. case GalVertexAttribSize._8_8_8:
  405. case GalVertexAttribSize._8_8_8_8:
  406. GL.VertexAttrib4N((uint)Attrib.Index, (byte*)Attrib.Pointer);
  407. break;
  408. case GalVertexAttribSize._16:
  409. case GalVertexAttribSize._16_16:
  410. case GalVertexAttribSize._16_16_16:
  411. case GalVertexAttribSize._16_16_16_16:
  412. GL.VertexAttrib4N((uint)Attrib.Index, (ushort*)Attrib.Pointer);
  413. break;
  414. case GalVertexAttribSize._32:
  415. case GalVertexAttribSize._32_32:
  416. case GalVertexAttribSize._32_32_32:
  417. case GalVertexAttribSize._32_32_32_32:
  418. GL.VertexAttrib4N((uint)Attrib.Index, (uint*)Attrib.Pointer);
  419. break;
  420. }
  421. }
  422. else if (Attrib.Type == GalVertexAttribType.Snorm)
  423. {
  424. switch (Attrib.Size)
  425. {
  426. case GalVertexAttribSize._8:
  427. case GalVertexAttribSize._8_8:
  428. case GalVertexAttribSize._8_8_8:
  429. case GalVertexAttribSize._8_8_8_8:
  430. GL.VertexAttrib4N((uint)Attrib.Index, (sbyte*)Attrib.Pointer);
  431. break;
  432. case GalVertexAttribSize._16:
  433. case GalVertexAttribSize._16_16:
  434. case GalVertexAttribSize._16_16_16:
  435. case GalVertexAttribSize._16_16_16_16:
  436. GL.VertexAttrib4N((uint)Attrib.Index, (short*)Attrib.Pointer);
  437. break;
  438. case GalVertexAttribSize._32:
  439. case GalVertexAttribSize._32_32:
  440. case GalVertexAttribSize._32_32_32:
  441. case GalVertexAttribSize._32_32_32_32:
  442. GL.VertexAttrib4N((uint)Attrib.Index, (int*)Attrib.Pointer);
  443. break;
  444. }
  445. }
  446. else if (Attrib.Type == GalVertexAttribType.Uint)
  447. {
  448. switch (Attrib.Size)
  449. {
  450. case GalVertexAttribSize._8:
  451. case GalVertexAttribSize._8_8:
  452. case GalVertexAttribSize._8_8_8:
  453. case GalVertexAttribSize._8_8_8_8:
  454. GL.VertexAttribI4((uint)Attrib.Index, (byte*)Attrib.Pointer);
  455. break;
  456. case GalVertexAttribSize._16:
  457. case GalVertexAttribSize._16_16:
  458. case GalVertexAttribSize._16_16_16:
  459. case GalVertexAttribSize._16_16_16_16:
  460. GL.VertexAttribI4((uint)Attrib.Index, (ushort*)Attrib.Pointer);
  461. break;
  462. case GalVertexAttribSize._32:
  463. case GalVertexAttribSize._32_32:
  464. case GalVertexAttribSize._32_32_32:
  465. case GalVertexAttribSize._32_32_32_32:
  466. GL.VertexAttribI4((uint)Attrib.Index, (uint*)Attrib.Pointer);
  467. break;
  468. }
  469. }
  470. else if (Attrib.Type == GalVertexAttribType.Sint)
  471. {
  472. switch (Attrib.Size)
  473. {
  474. case GalVertexAttribSize._8:
  475. case GalVertexAttribSize._8_8:
  476. case GalVertexAttribSize._8_8_8:
  477. case GalVertexAttribSize._8_8_8_8:
  478. GL.VertexAttribI4((uint)Attrib.Index, (sbyte*)Attrib.Pointer);
  479. break;
  480. case GalVertexAttribSize._16:
  481. case GalVertexAttribSize._16_16:
  482. case GalVertexAttribSize._16_16_16:
  483. case GalVertexAttribSize._16_16_16_16:
  484. GL.VertexAttribI4((uint)Attrib.Index, (short*)Attrib.Pointer);
  485. break;
  486. case GalVertexAttribSize._32:
  487. case GalVertexAttribSize._32_32:
  488. case GalVertexAttribSize._32_32_32:
  489. case GalVertexAttribSize._32_32_32_32:
  490. GL.VertexAttribI4((uint)Attrib.Index, (int*)Attrib.Pointer);
  491. break;
  492. }
  493. }
  494. else if (Attrib.Type == GalVertexAttribType.Float)
  495. {
  496. switch (Attrib.Size)
  497. {
  498. case GalVertexAttribSize._32:
  499. case GalVertexAttribSize._32_32:
  500. case GalVertexAttribSize._32_32_32:
  501. case GalVertexAttribSize._32_32_32_32:
  502. GL.VertexAttrib4(Attrib.Index, (float*)Attrib.Pointer);
  503. break;
  504. default: Unsupported(); break;
  505. }
  506. }
  507. }
  508. private void Enable(EnableCap Cap, bool Enabled)
  509. {
  510. if (Enabled)
  511. {
  512. GL.Enable(Cap);
  513. }
  514. else
  515. {
  516. GL.Disable(Cap);
  517. }
  518. }
  519. }
  520. }