(w *ecs.World)
| 82 | } |
| 83 | |
| 84 | func (s *basicShader) Setup(w *ecs.World) error { |
| 85 | if s.BatchSize > MaxSprites { |
| 86 | return fmt.Errorf("%d is greater than the maximum batch size of %d", s.BatchSize, MaxSprites) |
| 87 | } |
| 88 | |
| 89 | if s.BatchSize <= 0 { |
| 90 | if runtime.GOOS == "js" { |
| 91 | s.BatchSize = 2048 // js can't seem to handle the whole buffer size |
| 92 | } else { |
| 93 | s.BatchSize = MaxSprites |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // Create the vertex buffer for batching. |
| 98 | s.vertices = make([]float32, s.BatchSize*spriteSize) |
| 99 | s.vertexBuffer = engo.Gl.CreateBuffer() |
| 100 | // Create and populate indices buffer. The size of the buffer depends on the batch size. |
| 101 | // These should never change, so we can just initialize them once here and be done with it. |
| 102 | numIndicies := s.BatchSize * 6 |
| 103 | s.indices = make([]uint16, numIndicies) |
| 104 | for i, j := 0, 0; i < numIndicies; i, j = i+6, j+4 { |
| 105 | s.indices[i+0] = uint16(j + 0) |
| 106 | s.indices[i+1] = uint16(j + 1) |
| 107 | s.indices[i+2] = uint16(j + 2) |
| 108 | s.indices[i+3] = uint16(j + 0) |
| 109 | s.indices[i+4] = uint16(j + 2) |
| 110 | s.indices[i+5] = uint16(j + 3) |
| 111 | } |
| 112 | var err error |
| 113 | s.program, err = LoadShader(defaultVertexShader, defaultFragmentShader) |
| 114 | if err != nil { |
| 115 | return err |
| 116 | } |
| 117 | s.indexBuffer = engo.Gl.CreateBuffer() |
| 118 | engo.Gl.BindBuffer(engo.Gl.ELEMENT_ARRAY_BUFFER, s.indexBuffer) |
| 119 | engo.Gl.BufferData(engo.Gl.ELEMENT_ARRAY_BUFFER, s.indices, engo.Gl.STATIC_DRAW) |
| 120 | |
| 121 | s.inPosition = engo.Gl.GetAttribLocation(s.program, "in_Position") |
| 122 | s.inTexCoords = engo.Gl.GetAttribLocation(s.program, "in_TexCoords") |
| 123 | s.inColor = engo.Gl.GetAttribLocation(s.program, "in_Color") |
| 124 | |
| 125 | s.matrixProjView = engo.Gl.GetUniformLocation(s.program, "matrixProjView") |
| 126 | |
| 127 | s.projectionMatrix = engo.IdentityMatrix() |
| 128 | s.viewMatrix = engo.IdentityMatrix() |
| 129 | s.projViewMatrix = engo.IdentityMatrix() |
| 130 | s.modelMatrix = engo.IdentityMatrix() |
| 131 | s.cullingMatrix = engo.IdentityMatrix() |
| 132 | |
| 133 | s.setTexture(nil) |
| 134 | |
| 135 | return nil |
| 136 | } |
| 137 | |
| 138 | func (s *basicShader) Pre() { |
| 139 | engo.Gl.Enable(engo.Gl.BLEND) |
nothing calls this directly
no test coverage detected