MCPcopy
hub / github.com/g3n/engine / Initialize

Method Initialize

gui/panel.go:134–188  ·  view source on GitHub ↗

Initialize initializes this panel and is normally used by other types which embed a panel.

(ipan IPanel, width, height float32)

Source from the content-addressed store, hash-verified

132
133// Initialize initializes this panel and is normally used by other types which embed a panel.
134func (p *Panel) Initialize(ipan IPanel, width, height float32) { // TODO rename to Init
135
136 p.width = width
137 p.height = height
138
139 // If first time, create panel quad geometry
140 if panelQuadGeometry == nil {
141
142 // Builds array with vertex positions and texture coordinates
143 positions := math32.NewArrayF32(0, 20)
144 positions.Append(
145 0, 0, 0, 0, 1,
146 0, -1, 0, 0, 0,
147 1, -1, 0, 1, 0,
148 1, 0, 0, 1, 1,
149 )
150 // Builds array of indices
151 indices := math32.NewArrayU32(0, 6)
152 indices.Append(0, 1, 2, 0, 2, 3)
153
154 // Creates geometry
155 geom := geometry.NewGeometry()
156 geom.SetIndices(indices)
157 geom.AddVBO(gls.NewVBO(positions).
158 AddAttrib(gls.VertexPosition).
159 AddAttrib(gls.VertexTexcoord),
160 )
161 panelQuadGeometry = geom
162 }
163
164 // Initialize material
165 p.mat = material.NewMaterial()
166 p.mat.SetUseLights(material.UseLightNone)
167 p.mat.SetShader("panel")
168 p.mat.SetShaderUnique(true)
169
170 // For now set all panels as transparent by default
171 // This means they are all rendered back to front, after and on top of everything else
172 // TODO if we know a panel is opaque, setting it as such will improve rendering performance
173 p.mat.SetTransparent(true)
174
175 // Initialize graphic
176 p.Graphic = graphic.NewGraphic(ipan, panelQuadGeometry.Incref(), gls.TRIANGLES)
177 p.AddMaterial(p, p.mat, 0, 0)
178
179 // Initialize uniforms location caches
180 p.uniMatrix.Init("ModelMatrix")
181 p.uniPanel.Init("Panel")
182
183 // Set defaults
184 p.udata.bordersColor = math32.Color4{0, 0, 0, 1}
185 p.bounded = true
186 p.enabled = true
187 p.resize(width, height, true)
188}
189
190// InitializeGraphic initializes this panel with a different graphic
191func (p *Panel) InitializeGraphic(width, height float32, gr *graphic.Graphic) {

Callers 1

NewPanelFunction · 0.45

Calls 15

AppendMethod · 0.95
AppendMethod · 0.95
SetIndicesMethod · 0.95
AddVBOMethod · 0.95
resizeMethod · 0.95
NewArrayF32Function · 0.92
NewArrayU32Function · 0.92
NewGeometryFunction · 0.92
NewVBOFunction · 0.92
NewMaterialFunction · 0.92
NewGraphicFunction · 0.92
SetUseLightsMethod · 0.80

Tested by

no test coverage detected