OGLPipeline.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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. ColorMask = ColorMaskRgba.Default,
  116. PrimitiveRestartEnabled = false,
  117. PrimitiveRestartIndex = 0
  118. };
  119. for (int Index = 0; Index < GalPipelineState.RenderTargetsCount; Index++)
  120. {
  121. Old.ColorMasks[Index] = ColorMaskRgba.Default;
  122. }
  123. }
  124. public void Bind(GalPipelineState New)
  125. {
  126. BindConstBuffers(New);
  127. BindVertexLayout(New);
  128. if (New.FramebufferSrgb != Old.FramebufferSrgb)
  129. {
  130. Enable(EnableCap.FramebufferSrgb, New.FramebufferSrgb);
  131. }
  132. if (New.FlipX != Old.FlipX || New.FlipY != Old.FlipY || New.Instance != Old.Instance)
  133. {
  134. Shader.SetExtraData(New.FlipX, New.FlipY, New.Instance);
  135. }
  136. //Note: Uncomment SetFrontFace and SetCullFace when flipping issues are solved
  137. //if (New.FrontFace != Old.FrontFace)
  138. //{
  139. // GL.FrontFace(OGLEnumConverter.GetFrontFace(New.FrontFace));
  140. //}
  141. //if (New.CullFaceEnabled != Old.CullFaceEnabled)
  142. //{
  143. // Enable(EnableCap.CullFace, New.CullFaceEnabled);
  144. //}
  145. //if (New.CullFaceEnabled)
  146. //{
  147. // if (New.CullFace != Old.CullFace)
  148. // {
  149. // GL.CullFace(OGLEnumConverter.GetCullFace(New.CullFace));
  150. // }
  151. //}
  152. if (New.DepthTestEnabled != Old.DepthTestEnabled)
  153. {
  154. Enable(EnableCap.DepthTest, New.DepthTestEnabled);
  155. }
  156. if (New.DepthWriteEnabled != Old.DepthWriteEnabled)
  157. {
  158. GL.DepthMask(New.DepthWriteEnabled);
  159. }
  160. if (New.DepthTestEnabled)
  161. {
  162. if (New.DepthFunc != Old.DepthFunc)
  163. {
  164. GL.DepthFunc(OGLEnumConverter.GetDepthFunc(New.DepthFunc));
  165. }
  166. }
  167. if (New.StencilTestEnabled != Old.StencilTestEnabled)
  168. {
  169. Enable(EnableCap.StencilTest, New.StencilTestEnabled);
  170. }
  171. if (New.StencilTwoSideEnabled != Old.StencilTwoSideEnabled)
  172. {
  173. Enable((EnableCap)All.StencilTestTwoSideExt, New.StencilTwoSideEnabled);
  174. }
  175. if (New.StencilTestEnabled)
  176. {
  177. if (New.StencilBackFuncFunc != Old.StencilBackFuncFunc ||
  178. New.StencilBackFuncRef != Old.StencilBackFuncRef ||
  179. New.StencilBackFuncMask != Old.StencilBackFuncMask)
  180. {
  181. GL.StencilFuncSeparate(
  182. StencilFace.Back,
  183. OGLEnumConverter.GetStencilFunc(New.StencilBackFuncFunc),
  184. New.StencilBackFuncRef,
  185. New.StencilBackFuncMask);
  186. }
  187. if (New.StencilBackOpFail != Old.StencilBackOpFail ||
  188. New.StencilBackOpZFail != Old.StencilBackOpZFail ||
  189. New.StencilBackOpZPass != Old.StencilBackOpZPass)
  190. {
  191. GL.StencilOpSeparate(
  192. StencilFace.Back,
  193. OGLEnumConverter.GetStencilOp(New.StencilBackOpFail),
  194. OGLEnumConverter.GetStencilOp(New.StencilBackOpZFail),
  195. OGLEnumConverter.GetStencilOp(New.StencilBackOpZPass));
  196. }
  197. if (New.StencilBackMask != Old.StencilBackMask)
  198. {
  199. GL.StencilMaskSeparate(StencilFace.Back, New.StencilBackMask);
  200. }
  201. if (New.StencilFrontFuncFunc != Old.StencilFrontFuncFunc ||
  202. New.StencilFrontFuncRef != Old.StencilFrontFuncRef ||
  203. New.StencilFrontFuncMask != Old.StencilFrontFuncMask)
  204. {
  205. GL.StencilFuncSeparate(
  206. StencilFace.Front,
  207. OGLEnumConverter.GetStencilFunc(New.StencilFrontFuncFunc),
  208. New.StencilFrontFuncRef,
  209. New.StencilFrontFuncMask);
  210. }
  211. if (New.StencilFrontOpFail != Old.StencilFrontOpFail ||
  212. New.StencilFrontOpZFail != Old.StencilFrontOpZFail ||
  213. New.StencilFrontOpZPass != Old.StencilFrontOpZPass)
  214. {
  215. GL.StencilOpSeparate(
  216. StencilFace.Front,
  217. OGLEnumConverter.GetStencilOp(New.StencilFrontOpFail),
  218. OGLEnumConverter.GetStencilOp(New.StencilFrontOpZFail),
  219. OGLEnumConverter.GetStencilOp(New.StencilFrontOpZPass));
  220. }
  221. if (New.StencilFrontMask != Old.StencilFrontMask)
  222. {
  223. GL.StencilMaskSeparate(StencilFace.Front, New.StencilFrontMask);
  224. }
  225. }
  226. if (New.BlendEnabled != Old.BlendEnabled)
  227. {
  228. Enable(EnableCap.Blend, New.BlendEnabled);
  229. }
  230. if (New.BlendEnabled)
  231. {
  232. if (New.BlendSeparateAlpha)
  233. {
  234. if (New.BlendEquationRgb != Old.BlendEquationRgb ||
  235. New.BlendEquationAlpha != Old.BlendEquationAlpha)
  236. {
  237. GL.BlendEquationSeparate(
  238. OGLEnumConverter.GetBlendEquation(New.BlendEquationRgb),
  239. OGLEnumConverter.GetBlendEquation(New.BlendEquationAlpha));
  240. }
  241. if (New.BlendFuncSrcRgb != Old.BlendFuncSrcRgb ||
  242. New.BlendFuncDstRgb != Old.BlendFuncDstRgb ||
  243. New.BlendFuncSrcAlpha != Old.BlendFuncSrcAlpha ||
  244. New.BlendFuncDstAlpha != Old.BlendFuncDstAlpha)
  245. {
  246. GL.BlendFuncSeparate(
  247. (BlendingFactorSrc) OGLEnumConverter.GetBlendFactor(New.BlendFuncSrcRgb),
  248. (BlendingFactorDest)OGLEnumConverter.GetBlendFactor(New.BlendFuncDstRgb),
  249. (BlendingFactorSrc) OGLEnumConverter.GetBlendFactor(New.BlendFuncSrcAlpha),
  250. (BlendingFactorDest)OGLEnumConverter.GetBlendFactor(New.BlendFuncDstAlpha));
  251. }
  252. }
  253. else
  254. {
  255. if (New.BlendEquationRgb != Old.BlendEquationRgb)
  256. {
  257. GL.BlendEquation(OGLEnumConverter.GetBlendEquation(New.BlendEquationRgb));
  258. }
  259. if (New.BlendFuncSrcRgb != Old.BlendFuncSrcRgb ||
  260. New.BlendFuncDstRgb != Old.BlendFuncDstRgb)
  261. {
  262. GL.BlendFunc(
  263. OGLEnumConverter.GetBlendFactor(New.BlendFuncSrcRgb),
  264. OGLEnumConverter.GetBlendFactor(New.BlendFuncDstRgb));
  265. }
  266. }
  267. }
  268. for (int Index = 0; Index < GalPipelineState.RenderTargetsCount; Index++)
  269. {
  270. if (!New.ColorMasks[Index].Equals(Old.ColorMasks[Index]))
  271. {
  272. GL.ColorMask(
  273. Index,
  274. New.ColorMasks[Index].Red,
  275. New.ColorMasks[Index].Green,
  276. New.ColorMasks[Index].Blue,
  277. New.ColorMasks[Index].Alpha);
  278. }
  279. }
  280. if (New.PrimitiveRestartEnabled != Old.PrimitiveRestartEnabled)
  281. {
  282. Enable(EnableCap.PrimitiveRestart, New.PrimitiveRestartEnabled);
  283. }
  284. if (New.PrimitiveRestartEnabled)
  285. {
  286. if (New.PrimitiveRestartIndex != Old.PrimitiveRestartIndex)
  287. {
  288. GL.PrimitiveRestartIndex(New.PrimitiveRestartIndex);
  289. }
  290. }
  291. Old = New;
  292. }
  293. private void BindConstBuffers(GalPipelineState New)
  294. {
  295. int FreeBinding = OGLShader.ReservedCbufCount;
  296. void BindIfNotNull(OGLShaderStage Stage)
  297. {
  298. if (Stage != null)
  299. {
  300. foreach (ShaderDeclInfo DeclInfo in Stage.ConstBufferUsage)
  301. {
  302. long Key = New.ConstBufferKeys[(int)Stage.Type][DeclInfo.Cbuf];
  303. if (Key != 0 && Buffer.TryGetUbo(Key, out int UboHandle))
  304. {
  305. GL.BindBufferBase(BufferRangeTarget.UniformBuffer, FreeBinding, UboHandle);
  306. }
  307. FreeBinding++;
  308. }
  309. }
  310. }
  311. BindIfNotNull(Shader.Current.Vertex);
  312. BindIfNotNull(Shader.Current.TessControl);
  313. BindIfNotNull(Shader.Current.TessEvaluation);
  314. BindIfNotNull(Shader.Current.Geometry);
  315. BindIfNotNull(Shader.Current.Fragment);
  316. }
  317. private void BindVertexLayout(GalPipelineState New)
  318. {
  319. foreach (GalVertexBinding Binding in New.VertexBindings)
  320. {
  321. if (!Binding.Enabled || !Rasterizer.TryGetVbo(Binding.VboKey, out int VboHandle))
  322. {
  323. continue;
  324. }
  325. if (VaoHandle == 0)
  326. {
  327. VaoHandle = GL.GenVertexArray();
  328. //Vertex arrays shouldn't be used anywhere else in OpenGL's backend
  329. //if you want to use it, move this line out of the if
  330. GL.BindVertexArray(VaoHandle);
  331. }
  332. foreach (GalVertexAttrib Attrib in Binding.Attribs)
  333. {
  334. //Skip uninitialized attributes.
  335. if (Attrib.Size == 0)
  336. {
  337. continue;
  338. }
  339. GL.BindBuffer(BufferTarget.ArrayBuffer, VboHandle);
  340. bool Unsigned =
  341. Attrib.Type == GalVertexAttribType.Unorm ||
  342. Attrib.Type == GalVertexAttribType.Uint ||
  343. Attrib.Type == GalVertexAttribType.Uscaled;
  344. bool Normalize =
  345. Attrib.Type == GalVertexAttribType.Snorm ||
  346. Attrib.Type == GalVertexAttribType.Unorm;
  347. VertexAttribPointerType Type = 0;
  348. if (Attrib.Type == GalVertexAttribType.Float)
  349. {
  350. Type = GetType(FloatAttribTypes, Attrib);
  351. }
  352. else
  353. {
  354. if (Unsigned)
  355. {
  356. Type = GetType(UnsignedAttribTypes, Attrib);
  357. }
  358. else
  359. {
  360. Type = GetType(SignedAttribTypes, Attrib);
  361. }
  362. }
  363. if (!AttribElements.TryGetValue(Attrib.Size, out int Size))
  364. {
  365. throw new InvalidOperationException("Invalid attribute size \"" + Attrib.Size + "\"!");
  366. }
  367. int Offset = Attrib.Offset;
  368. if (Binding.Stride != 0)
  369. {
  370. GL.EnableVertexAttribArray(Attrib.Index);
  371. if (Attrib.Type == GalVertexAttribType.Sint ||
  372. Attrib.Type == GalVertexAttribType.Uint)
  373. {
  374. IntPtr Pointer = new IntPtr(Offset);
  375. VertexAttribIntegerType IType = (VertexAttribIntegerType)Type;
  376. GL.VertexAttribIPointer(Attrib.Index, Size, IType, Binding.Stride, Pointer);
  377. }
  378. else
  379. {
  380. GL.VertexAttribPointer(Attrib.Index, Size, Type, Normalize, Binding.Stride, Offset);
  381. }
  382. }
  383. else
  384. {
  385. GL.DisableVertexAttribArray(Attrib.Index);
  386. SetConstAttrib(Attrib);
  387. }
  388. if (Binding.Instanced && Binding.Divisor != 0)
  389. {
  390. GL.VertexAttribDivisor(Attrib.Index, 1);
  391. }
  392. else
  393. {
  394. GL.VertexAttribDivisor(Attrib.Index, 0);
  395. }
  396. }
  397. }
  398. }
  399. private static VertexAttribPointerType GetType(Dictionary<GalVertexAttribSize, VertexAttribPointerType> Dict, GalVertexAttrib Attrib)
  400. {
  401. if (!Dict.TryGetValue(Attrib.Size, out VertexAttribPointerType Type))
  402. {
  403. throw new NotImplementedException("Unsupported size \"" + Attrib.Size + "\" on type \"" + Attrib.Type + "\"!");
  404. }
  405. return Type;
  406. }
  407. private unsafe static void SetConstAttrib(GalVertexAttrib Attrib)
  408. {
  409. void Unsupported()
  410. {
  411. throw new NotImplementedException("Constant attribute " + Attrib.Size + " not implemented!");
  412. }
  413. if (Attrib.Size == GalVertexAttribSize._10_10_10_2 ||
  414. Attrib.Size == GalVertexAttribSize._11_11_10)
  415. {
  416. Unsupported();
  417. }
  418. if (Attrib.Type == GalVertexAttribType.Unorm)
  419. {
  420. switch (Attrib.Size)
  421. {
  422. case GalVertexAttribSize._8:
  423. case GalVertexAttribSize._8_8:
  424. case GalVertexAttribSize._8_8_8:
  425. case GalVertexAttribSize._8_8_8_8:
  426. GL.VertexAttrib4N((uint)Attrib.Index, (byte*)Attrib.Pointer);
  427. break;
  428. case GalVertexAttribSize._16:
  429. case GalVertexAttribSize._16_16:
  430. case GalVertexAttribSize._16_16_16:
  431. case GalVertexAttribSize._16_16_16_16:
  432. GL.VertexAttrib4N((uint)Attrib.Index, (ushort*)Attrib.Pointer);
  433. break;
  434. case GalVertexAttribSize._32:
  435. case GalVertexAttribSize._32_32:
  436. case GalVertexAttribSize._32_32_32:
  437. case GalVertexAttribSize._32_32_32_32:
  438. GL.VertexAttrib4N((uint)Attrib.Index, (uint*)Attrib.Pointer);
  439. break;
  440. }
  441. }
  442. else if (Attrib.Type == GalVertexAttribType.Snorm)
  443. {
  444. switch (Attrib.Size)
  445. {
  446. case GalVertexAttribSize._8:
  447. case GalVertexAttribSize._8_8:
  448. case GalVertexAttribSize._8_8_8:
  449. case GalVertexAttribSize._8_8_8_8:
  450. GL.VertexAttrib4N((uint)Attrib.Index, (sbyte*)Attrib.Pointer);
  451. break;
  452. case GalVertexAttribSize._16:
  453. case GalVertexAttribSize._16_16:
  454. case GalVertexAttribSize._16_16_16:
  455. case GalVertexAttribSize._16_16_16_16:
  456. GL.VertexAttrib4N((uint)Attrib.Index, (short*)Attrib.Pointer);
  457. break;
  458. case GalVertexAttribSize._32:
  459. case GalVertexAttribSize._32_32:
  460. case GalVertexAttribSize._32_32_32:
  461. case GalVertexAttribSize._32_32_32_32:
  462. GL.VertexAttrib4N((uint)Attrib.Index, (int*)Attrib.Pointer);
  463. break;
  464. }
  465. }
  466. else if (Attrib.Type == GalVertexAttribType.Uint)
  467. {
  468. switch (Attrib.Size)
  469. {
  470. case GalVertexAttribSize._8:
  471. case GalVertexAttribSize._8_8:
  472. case GalVertexAttribSize._8_8_8:
  473. case GalVertexAttribSize._8_8_8_8:
  474. GL.VertexAttribI4((uint)Attrib.Index, (byte*)Attrib.Pointer);
  475. break;
  476. case GalVertexAttribSize._16:
  477. case GalVertexAttribSize._16_16:
  478. case GalVertexAttribSize._16_16_16:
  479. case GalVertexAttribSize._16_16_16_16:
  480. GL.VertexAttribI4((uint)Attrib.Index, (ushort*)Attrib.Pointer);
  481. break;
  482. case GalVertexAttribSize._32:
  483. case GalVertexAttribSize._32_32:
  484. case GalVertexAttribSize._32_32_32:
  485. case GalVertexAttribSize._32_32_32_32:
  486. GL.VertexAttribI4((uint)Attrib.Index, (uint*)Attrib.Pointer);
  487. break;
  488. }
  489. }
  490. else if (Attrib.Type == GalVertexAttribType.Sint)
  491. {
  492. switch (Attrib.Size)
  493. {
  494. case GalVertexAttribSize._8:
  495. case GalVertexAttribSize._8_8:
  496. case GalVertexAttribSize._8_8_8:
  497. case GalVertexAttribSize._8_8_8_8:
  498. GL.VertexAttribI4((uint)Attrib.Index, (sbyte*)Attrib.Pointer);
  499. break;
  500. case GalVertexAttribSize._16:
  501. case GalVertexAttribSize._16_16:
  502. case GalVertexAttribSize._16_16_16:
  503. case GalVertexAttribSize._16_16_16_16:
  504. GL.VertexAttribI4((uint)Attrib.Index, (short*)Attrib.Pointer);
  505. break;
  506. case GalVertexAttribSize._32:
  507. case GalVertexAttribSize._32_32:
  508. case GalVertexAttribSize._32_32_32:
  509. case GalVertexAttribSize._32_32_32_32:
  510. GL.VertexAttribI4((uint)Attrib.Index, (int*)Attrib.Pointer);
  511. break;
  512. }
  513. }
  514. else if (Attrib.Type == GalVertexAttribType.Float)
  515. {
  516. switch (Attrib.Size)
  517. {
  518. case GalVertexAttribSize._32:
  519. case GalVertexAttribSize._32_32:
  520. case GalVertexAttribSize._32_32_32:
  521. case GalVertexAttribSize._32_32_32_32:
  522. GL.VertexAttrib4(Attrib.Index, (float*)Attrib.Pointer);
  523. break;
  524. default: Unsupported(); break;
  525. }
  526. }
  527. }
  528. private void Enable(EnableCap Cap, bool Enabled)
  529. {
  530. if (Enabled)
  531. {
  532. GL.Enable(Cap);
  533. }
  534. else
  535. {
  536. GL.Disable(Cap);
  537. }
  538. }
  539. public void ResetDepthMask()
  540. {
  541. Old.DepthWriteEnabled = true;
  542. }
  543. public void ResetColorMask(int Index)
  544. {
  545. Old.ColorMasks[Index] = ColorMaskRgba.Default;
  546. }
  547. }
  548. }