uniform.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. // Copyright 2016 The G3N Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package gls
  5. import (
  6. "fmt"
  7. "github.com/g3n/engine/math32"
  8. )
  9. type Uniform2 struct {
  10. name string // base name
  11. nameIdx string // cached indexed name
  12. handle uint32 // program handle
  13. location int32 // last cached location
  14. lastIndex int32 // last index
  15. }
  16. // Init initializes this uniform and sets its name
  17. func (u *Uniform2) Init(name string) {
  18. u.name = name
  19. u.handle = 0 // invalid program handle
  20. u.location = -1 // invalid location
  21. u.lastIndex = -1 // invalid index
  22. }
  23. // Location returns the location of this uniform for
  24. // the current shader program
  25. // The returned location can be -1 if not found
  26. func (u *Uniform2) Location(gs *GLS) int32 {
  27. handle := gs.prog.Handle()
  28. if handle != u.handle {
  29. u.location = gs.prog.GetUniformLocation(u.name)
  30. u.handle = handle
  31. log.Error("Uniform:%s location:%v", u.name, u.location)
  32. }
  33. return u.location
  34. }
  35. // LocationIdx returns the location of this indexed uniform for
  36. // the current shader program
  37. // The returned location can be -1 if not found
  38. func (u *Uniform2) LocationIdx(gs *GLS, idx int32) int32 {
  39. if idx != u.lastIndex {
  40. u.nameIdx = fmt.Sprintf("%s[%d]", u.name, idx)
  41. u.lastIndex = idx
  42. u.handle = 0
  43. log.Error("Uniform:%s rebuild nameIdx", u.nameIdx)
  44. }
  45. handle := gs.prog.Handle()
  46. if handle != u.handle {
  47. u.location = gs.prog.GetUniformLocation(u.nameIdx)
  48. u.handle = handle
  49. log.Error("Uniform:%s location:%v", u.nameIdx, u.location)
  50. }
  51. return u.location
  52. }
  53. // ----------------------------------------------------------------------
  54. //
  55. // Type Uniform is the type for all uniforms
  56. //
  57. type Uniform struct {
  58. name string // original name
  59. nameidx string // cached indexed name
  60. idx int // index value of indexed name
  61. }
  62. // Location returns the current location of the uniform
  63. // for the current active program
  64. func (uni *Uniform) Location(gs *GLS) int32 {
  65. loc := gs.prog.GetUniformLocation(uni.name)
  66. return loc
  67. }
  68. // Location returns the current location of the uniform
  69. // for the current active program and index
  70. func (uni *Uniform) LocationIdx(gs *GLS, idx int) int32 {
  71. // Rebuilds uniform indexed name if necessary
  72. if uni.nameidx == "" || uni.idx != idx {
  73. uni.nameidx = fmt.Sprintf("%s[%d]", uni.name, idx)
  74. uni.idx = idx
  75. }
  76. loc := gs.prog.GetUniformLocation(uni.nameidx)
  77. return loc
  78. }
  79. //
  80. // Type Uniform1i is a Uniform containing one int value
  81. //
  82. type Uniform1i struct {
  83. Uniform
  84. v0 int32
  85. }
  86. func NewUniform1i(name string) *Uniform1i {
  87. uni := new(Uniform1i)
  88. uni.name = name
  89. return uni
  90. }
  91. func (uni *Uniform1i) Init(name string) {
  92. uni.name = name
  93. }
  94. func (uni *Uniform1i) Set(v int32) {
  95. uni.v0 = v
  96. }
  97. func (uni *Uniform1i) Get() int32 {
  98. return uni.v0
  99. }
  100. func (uni *Uniform1i) Transfer(gs *GLS) {
  101. gs.Uniform1i(uni.Location(gs), uni.v0)
  102. }
  103. func (uni *Uniform1i) TransferIdx(gs *GLS, idx int) {
  104. gs.Uniform1i(uni.LocationIdx(gs, idx), uni.v0)
  105. }
  106. //
  107. // Type Uniform1f is a Uniform containing one float32 value
  108. //
  109. type Uniform1f struct {
  110. Uniform
  111. v0 float32
  112. }
  113. func NewUniform1f(name string) *Uniform1f {
  114. uni := new(Uniform1f)
  115. uni.Init(name)
  116. return uni
  117. }
  118. func (uni *Uniform1f) Init(name string) {
  119. uni.name = name
  120. }
  121. func (uni *Uniform1f) Set(v float32) {
  122. uni.v0 = v
  123. }
  124. func (uni *Uniform1f) Get() float32 {
  125. return uni.v0
  126. }
  127. func (uni *Uniform1f) Transfer(gs *GLS) {
  128. gs.Uniform1f(uni.Location(gs), uni.v0)
  129. }
  130. func (uni *Uniform1f) TransferIdx(gs *GLS, idx int) {
  131. gs.Uniform1f(uni.LocationIdx(gs, idx), uni.v0)
  132. }
  133. //
  134. // Type Uniform2f is a Uniform containing two float32 values
  135. //
  136. type Uniform2f struct {
  137. Uniform
  138. v0 float32
  139. v1 float32
  140. }
  141. func NewUniform2f(name string) *Uniform2f {
  142. uni := new(Uniform2f)
  143. uni.Init(name)
  144. return uni
  145. }
  146. func (uni *Uniform2f) Init(name string) {
  147. uni.name = name
  148. }
  149. func (uni *Uniform2f) Set(v0, v1 float32) {
  150. uni.v0 = v0
  151. uni.v1 = v1
  152. }
  153. func (uni *Uniform2f) Get() (float32, float32) {
  154. return uni.v0, uni.v1
  155. }
  156. func (uni *Uniform2f) SetVector2(v *math32.Vector2) {
  157. uni.v0 = v.X
  158. uni.v1 = v.Y
  159. }
  160. func (uni *Uniform2f) GetVector2() math32.Vector2 {
  161. return math32.Vector2{uni.v0, uni.v1}
  162. }
  163. func (uni *Uniform2f) Transfer(gs *GLS) {
  164. gs.Uniform2f(uni.Location(gs), uni.v0, uni.v1)
  165. }
  166. func (uni *Uniform2f) TransferIdx(gs *GLS, idx int) {
  167. gs.Uniform2f(uni.LocationIdx(gs, idx), uni.v0, uni.v1)
  168. }
  169. //
  170. // Type Uniform3f is a Uniform containing three float32 values
  171. //
  172. type Uniform3f struct {
  173. Uniform
  174. v0 float32
  175. v1 float32
  176. v2 float32
  177. }
  178. func NewUniform3f(name string) *Uniform3f {
  179. uni := new(Uniform3f)
  180. uni.Init(name)
  181. return uni
  182. }
  183. func (uni *Uniform3f) Init(name string) {
  184. uni.name = name
  185. }
  186. func (uni *Uniform3f) Set(v0, v1, v2 float32) {
  187. uni.v0 = v0
  188. uni.v1 = v1
  189. uni.v2 = v2
  190. }
  191. func (uni *Uniform3f) Get() (float32, float32, float32) {
  192. return uni.v0, uni.v1, uni.v2
  193. }
  194. func (uni *Uniform3f) SetVector3(v *math32.Vector3) {
  195. uni.v0 = v.X
  196. uni.v1 = v.Y
  197. uni.v2 = v.Z
  198. }
  199. func (uni *Uniform3f) GetVector3() math32.Vector3 {
  200. return math32.Vector3{uni.v0, uni.v1, uni.v2}
  201. }
  202. func (uni *Uniform3f) SetColor(color *math32.Color) {
  203. uni.v0 = color.R
  204. uni.v1 = color.G
  205. uni.v2 = color.B
  206. }
  207. func (uni *Uniform3f) GetColor() math32.Color {
  208. return math32.Color{uni.v0, uni.v1, uni.v2}
  209. }
  210. func (uni *Uniform3f) Transfer(gl *GLS) {
  211. loc := uni.Location(gl)
  212. gl.Uniform3f(loc, uni.v0, uni.v1, uni.v2)
  213. //log.Debug("Uniform3f: %s (%v) -> %v,%v,%v", uni.name, loc, uni.v0, uni.v1, uni.v2)
  214. }
  215. func (uni *Uniform3f) TransferIdx(gl *GLS, idx int) {
  216. loc := uni.LocationIdx(gl, idx)
  217. gl.Uniform3f(loc, uni.v0, uni.v1, uni.v2)
  218. //log.Debug("Uniform3f: %s -> %v,%v,%v", uni.nameidx, uni.v0, uni.v1, uni.v2)
  219. }
  220. //
  221. // Type Uniform4f is a Uniform containing four float32 values
  222. //
  223. type Uniform4f struct {
  224. Uniform
  225. v0 float32
  226. v1 float32
  227. v2 float32
  228. v3 float32
  229. }
  230. func NewUniform4f(name string) *Uniform4f {
  231. uni := new(Uniform4f)
  232. uni.Init(name)
  233. return uni
  234. }
  235. func (uni *Uniform4f) Init(name string) {
  236. uni.name = name
  237. }
  238. func (uni *Uniform4f) Set(v0, v1, v2, v3 float32) {
  239. uni.v0 = v0
  240. uni.v1 = v1
  241. uni.v2 = v2
  242. uni.v3 = v3
  243. }
  244. func (uni *Uniform4f) Get() (float32, float32, float32, float32) {
  245. return uni.v0, uni.v1, uni.v2, uni.v3
  246. }
  247. func (uni *Uniform4f) SetVector4(v *math32.Vector4) {
  248. uni.v0 = v.X
  249. uni.v1 = v.Y
  250. uni.v2 = v.Z
  251. uni.v3 = v.W
  252. }
  253. func (uni *Uniform4f) GetVector4() math32.Vector4 {
  254. return math32.Vector4{uni.v0, uni.v1, uni.v2, uni.v3}
  255. }
  256. func (uni *Uniform4f) SetColor4(c *math32.Color4) {
  257. uni.v0 = c.R
  258. uni.v1 = c.G
  259. uni.v2 = c.B
  260. uni.v3 = c.A
  261. }
  262. func (uni *Uniform4f) GetColor4() math32.Color4 {
  263. return math32.Color4{uni.v0, uni.v1, uni.v2, uni.v3}
  264. }
  265. func (uni *Uniform4f) Transfer(gl *GLS) {
  266. //log.Debug("Uniform4f.Transfer: %s %d", uni.name, uni.Location(gl))
  267. gl.Uniform4f(uni.Location(gl), uni.v0, uni.v1, uni.v2, uni.v3)
  268. }
  269. func (uni *Uniform4f) TransferIdx(gl *GLS, idx int) {
  270. gl.Uniform4f(uni.LocationIdx(gl, idx), uni.v0, uni.v1, uni.v2, uni.v3)
  271. }
  272. //
  273. // Type UniformMatrix3f is a Uniform containing nine float32 values
  274. // organized as 3x3 matrix
  275. //
  276. type UniformMatrix3f struct {
  277. Uniform
  278. v [9]float32
  279. }
  280. // NewUniformMatrix3 creates and returns a pointer to a new UniformMatrix3f
  281. // with the specified name
  282. func NewUniformMatrix3f(name string) *UniformMatrix3f {
  283. uni := new(UniformMatrix3f)
  284. uni.Init(name)
  285. return uni
  286. }
  287. // Init initializes this uniform the specified name
  288. // It is normally used when the uniform is embedded in another object.
  289. func (uni *UniformMatrix3f) Init(name string) {
  290. uni.name = name
  291. }
  292. // SetMatrix3 sets the matrix stored by the uniform
  293. func (uni *UniformMatrix3f) SetMatrix3(m *math32.Matrix3) {
  294. uni.v = *m
  295. }
  296. // GetMatrix3 gets the matrix stored by the uniform
  297. func (uni *UniformMatrix3f) GetMatrix3() math32.Matrix3 {
  298. return uni.v
  299. }
  300. // SetElement sets the value of the matrix element at the specified column and row
  301. func (uni *UniformMatrix3f) SetElement(col, row int, v float32) {
  302. uni.v[col*3+row] = v
  303. }
  304. // GetElement gets the value of the matrix element at the specified column and row
  305. func (uni *UniformMatrix3f) GetElement(col, row int, v float32) float32 {
  306. return uni.v[col*3+row]
  307. }
  308. // Set sets the value of the matrix element by its position starting
  309. // from 0 for col0, row0 to 8 from col2, row2.
  310. // This way the matrix can be considered as a vector of 9 elements
  311. func (uni *UniformMatrix3f) Set(pos int, v float32) {
  312. uni.v[pos] = v
  313. }
  314. // Get gets the value of the matrix element by its position starting
  315. // from 0 for col0, row0 to 8 from col2, row2.
  316. // This way the matrix can be considered as a vector of 9 elements
  317. func (uni *UniformMatrix3f) Get(pos int) float32 {
  318. return uni.v[pos]
  319. }
  320. // Transfer transfer the uniform matrix data to the graphics library
  321. func (uni *UniformMatrix3f) Transfer(gl *GLS) {
  322. gl.UniformMatrix3fv(uni.Location(gl), 1, false, &uni.v[0])
  323. }
  324. // TransferIdx transfer the uniform matrix data to a specified destination index
  325. // of an uniform array to the graphics library
  326. func (uni *UniformMatrix3f) TransferIdx(gl *GLS, idx int) {
  327. gl.UniformMatrix3fv(uni.LocationIdx(gl, idx), 1, false, &uni.v[0])
  328. }
  329. //
  330. // Type UniformMatrix4f is a Uniform containing sixteen float32 values
  331. // organized as 4x4 matrix
  332. //
  333. type UniformMatrix4f struct {
  334. Uniform
  335. v [16]float32
  336. }
  337. func NewUniformMatrix4f(name string) *UniformMatrix4f {
  338. uni := new(UniformMatrix4f)
  339. uni.Init(name)
  340. return uni
  341. }
  342. func (uni *UniformMatrix4f) Init(name string) {
  343. uni.name = name
  344. }
  345. func (uni *UniformMatrix4f) SetMatrix4(m *math32.Matrix4) {
  346. uni.v = *m
  347. }
  348. func (uni *UniformMatrix4f) GetMatrix4() math32.Matrix4 {
  349. return uni.v
  350. }
  351. func (uni *UniformMatrix4f) Transfer(gl *GLS) {
  352. gl.UniformMatrix4fv(uni.Location(gl), 1, false, &uni.v[0])
  353. }
  354. func (uni *UniformMatrix4f) TransferIdx(gl *GLS, idx int) {
  355. gl.UniformMatrix4fv(uni.LocationIdx(gl, idx), 1, false, &uni.v[0])
  356. }
  357. //
  358. // Type Uniform1fv is a uniform containing an array of float32 values
  359. //
  360. type Uniform1fv struct {
  361. Uniform // embedded uniform
  362. v []float32 // array of values
  363. }
  364. // NewUniform1fv creates and returns an uniform with array of float32 values
  365. // with the specified size
  366. func NewUniform1fv(name string, count int) *Uniform1fv {
  367. uni := new(Uniform1fv)
  368. uni.Init(name, count)
  369. return uni
  370. }
  371. // Init initializes an Uniform1fv object with the specified name and count of float32 values.
  372. // It is normally used when the uniform is embedded in another object.
  373. func (uni *Uniform1fv) Init(name string, count int) {
  374. uni.name = name
  375. uni.v = make([]float32, count)
  376. }
  377. // SetVector3 sets the value of the elements of uniform starting at pos
  378. // from the specified Vector3 object.
  379. func (uni *Uniform1fv) SetVector3(pos int, v *math32.Vector3) {
  380. uni.v[pos] = v.X
  381. uni.v[pos+1] = v.Y
  382. uni.v[pos+2] = v.Z
  383. }
  384. // GetVector3 gets the value of the elements of the uniform starting at
  385. // pos as a Vector3 object.
  386. func (uni *Uniform1fv) GetVector3(pos int) math32.Vector3 {
  387. return math32.Vector3{uni.v[pos], uni.v[pos+1], uni.v[pos+2]}
  388. }
  389. // SetColor sets the value of the elements of the uniform starting at pos
  390. // from the specified Color object.
  391. func (uni *Uniform1fv) SetColor(pos int, color *math32.Color) {
  392. uni.v[pos] = color.R
  393. uni.v[pos+1] = color.G
  394. uni.v[pos+2] = color.B
  395. }
  396. // GetColor gets the value of the elements of the uniform starting at pos
  397. // as a Color object.
  398. func (uni *Uniform1fv) GetColor(pos int) math32.Color {
  399. return math32.Color{uni.v[pos], uni.v[pos+1], uni.v[pos+2]}
  400. }
  401. // Set sets the value of the element at the specified position
  402. func (uni *Uniform1fv) Set(pos int, v float32) {
  403. uni.v[pos] = v
  404. }
  405. // Get gets the value of the element at the specified position
  406. func (uni *Uniform1fv) Get(pos int, v float32) float32 {
  407. return uni.v[pos]
  408. }
  409. // TransferIdx transfer a block of 'count' values of this uniform starting at 'pos'.
  410. func (uni *Uniform1fv) TransferIdx(gl *GLS, pos, count int) {
  411. gl.Uniform1fv(uni.LocationIdx(gl, pos), 1, uni.v[pos:])
  412. }
  413. //
  414. // Type Uniform3fv is a uniform containing an array of three float32 values
  415. //
  416. type Uniform3fv struct {
  417. Uniform // embedded uniform
  418. count int // number of groups of 3 float32 values
  419. v []float32 // array of values
  420. }
  421. // NewUniform3fv creates and returns an uniform array with the specified size
  422. // of 3 float values
  423. func NewUniform3fv(name string, count int) *Uniform3fv {
  424. uni := new(Uniform3fv)
  425. uni.Init(name, count)
  426. return uni
  427. }
  428. // Init initializes an Uniform3fv object with the specified name and count of 3 float32 groups.
  429. // It is normally used when the uniform is embedded in another object.
  430. func (uni *Uniform3fv) Init(name string, count int) {
  431. uni.name = name
  432. uni.count = count
  433. uni.v = make([]float32, count*3)
  434. }
  435. // Set sets the value of all elements of the specified group of 3 floats for this uniform array
  436. func (uni *Uniform3fv) Set(idx int, v0, v1, v2 float32) {
  437. pos := idx * 3
  438. uni.v[pos] = v0
  439. uni.v[pos+1] = v1
  440. uni.v[pos+2] = v2
  441. }
  442. // Get gets the value of all elements of the specified group of 3 floats for this uniform array
  443. func (uni *Uniform3fv) Get(idx int) (v0, v1, v2 float32) {
  444. pos := idx * 3
  445. return uni.v[pos], uni.v[pos+1], uni.v[pos+2]
  446. }
  447. // SetVector3 sets the value of all elements for the specified group of 3 float for this uniform array
  448. // from the specified Vector3 object.
  449. func (uni *Uniform3fv) SetVector3(idx int, v *math32.Vector3) {
  450. pos := idx * 3
  451. uni.v[pos] = v.X
  452. uni.v[pos+1] = v.Y
  453. uni.v[pos+2] = v.Z
  454. }
  455. // GetVector3 gets the value of all elements of the specified group of 3 float for this uniform array
  456. // as a Vector3 object.
  457. func (uni *Uniform3fv) GetVector3(idx int) math32.Vector3 {
  458. pos := idx * 3
  459. return math32.Vector3{uni.v[pos], uni.v[pos+1], uni.v[pos+2]}
  460. }
  461. // SetColor sets the value of all elements of the specified group of 3 floats for this uniform array
  462. // form the specified Color object.
  463. func (uni *Uniform3fv) SetColor(idx int, color *math32.Color) {
  464. pos := idx * 3
  465. uni.v[pos] = color.R
  466. uni.v[pos+1] = color.G
  467. uni.v[pos+2] = color.B
  468. }
  469. // GetColor gets the value of all elements of the specified group of 3 float for this uniform array
  470. // as a Color object.
  471. func (uni *Uniform3fv) GetColor(idx int) math32.Color {
  472. pos := idx * 3
  473. return math32.Color{uni.v[pos], uni.v[pos+1], uni.v[pos+2]}
  474. }
  475. // SetPos sets the value at the specified position in the uniform array.
  476. func (uni *Uniform3fv) SetPos(pos int, v float32) {
  477. uni.v[pos] = v
  478. }
  479. // GetPos gets the value at the specified position in the uniform array.
  480. func (uni *Uniform3fv) GetPos(pos int) float32 {
  481. return uni.v[pos]
  482. }
  483. // Transfer transfers the current values of this uniform to the current shader program
  484. func (uni *Uniform3fv) Transfer(gl *GLS) {
  485. gl.Uniform3fv(uni.Location(gl), int32(uni.count), uni.v)
  486. }
  487. // Transfer transfers the current values of this uniform to a specified
  488. // start position in the target uniform array.
  489. func (uni *Uniform3fv) TransferIdx(gl *GLS, idx int) {
  490. gl.Uniform3fv(uni.LocationIdx(gl, idx), int32(uni.count), uni.v)
  491. }
  492. //
  493. // Type Uniform4fv is a Uniform containing an array of four float32 values
  494. //
  495. type Uniform4fv struct {
  496. Uniform // embedded uniform
  497. count int // number of group of 4 float32 values
  498. v []float32 // array of values
  499. }
  500. // NewUniform4fv creates and returns an uniform array with the specified size
  501. // of 4 float values
  502. func NewUniform4fv(name string, count int) *Uniform4fv {
  503. uni := new(Uniform4fv)
  504. uni.Init(name, count)
  505. return uni
  506. }
  507. // Init initializes an Uniform4fv object with the specified name and count of 4 float32 groups.
  508. // It is normally used when the uniform is embedded in another object.
  509. func (uni *Uniform4fv) Init(name string, count int) {
  510. uni.name = name
  511. uni.count = count
  512. uni.v = make([]float32, count*4)
  513. }
  514. // Set sets the value of all elements of the specified group of 4 floats for this uniform array
  515. func (uni *Uniform4fv) Set(idx int, v0, v1, v2, v3 float32) {
  516. pos := idx * 4
  517. uni.v[pos] = v0
  518. uni.v[pos+1] = v1
  519. uni.v[pos+2] = v2
  520. uni.v[pos+3] = v3
  521. }
  522. // Get gets the value of all elements of the specified group of 4 floats for this uniform array
  523. func (uni *Uniform4fv) Get(idx int) (v0, v1, v2, v3 float32) {
  524. pos := idx * 4
  525. return uni.v[pos], uni.v[pos+1], uni.v[pos+2], uni.v[pos+3]
  526. }
  527. // SetVector4 sets the value of all elements for the specified group of 4 float for this uniform array
  528. // from the specified Vector4 object.
  529. func (uni *Uniform4fv) SetVector4(idx int, v *math32.Vector4) {
  530. pos := idx * 4
  531. uni.v[pos] = v.X
  532. uni.v[pos+1] = v.Y
  533. uni.v[pos+2] = v.Z
  534. uni.v[pos+3] = v.W
  535. }
  536. // GetVector4 gets the value of all elements of the specified group of 4 float for this uniform array
  537. // as a Vector4 object.
  538. func (uni *Uniform4fv) GetVector4(idx int) math32.Vector4 {
  539. pos := idx * 4
  540. return math32.Vector4{uni.v[pos], uni.v[pos+1], uni.v[pos+2], uni.v[pos+3]}
  541. }
  542. // SetColor4 sets the value of all elements of the specified group of 4 floats for this uniform array
  543. // form the specified Color4 object.
  544. func (uni *Uniform4fv) SetColor4(idx int, color *math32.Color4) {
  545. pos := idx * 4
  546. uni.v[pos] = color.R
  547. uni.v[pos+1] = color.G
  548. uni.v[pos+2] = color.B
  549. uni.v[pos+3] = color.A
  550. }
  551. // GetColor4 gets the value of all elements of the specified group of 4 float for this uniform array
  552. // as a Color4 object.
  553. func (uni *Uniform4fv) GetColor4(idx int) math32.Color4 {
  554. pos := idx * 4
  555. return math32.Color4{uni.v[pos], uni.v[pos+1], uni.v[pos+2], uni.v[pos+3]}
  556. }
  557. // SetPos sets the value at the specified position in the uniform array.
  558. func (uni *Uniform4fv) SetPos(pos int, v float32) {
  559. uni.v[pos] = v
  560. }
  561. // GetPos gets the value at the specified position in the uniform array.
  562. func (uni *Uniform4fv) GetPos(pos int) float32 {
  563. return uni.v[pos]
  564. }
  565. // Transfer transfers the current values of this uniform to the current shader program
  566. func (uni *Uniform4fv) Transfer(gl *GLS) {
  567. gl.Uniform4fv(uni.Location(gl), int32(uni.count), uni.v)
  568. }