本文整理匯總了Golang中github.com/hajimehoshi/ebiten/internal/opengl.Context類的典型用法代碼示例。如果您正苦於以下問題:Golang Context類的具體用法?Golang Context怎麽用?Golang Context使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Context類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Exec
func (c *drawImageCommand) Exec(context *opengl.Context, indexOffsetInBytes int) error {
f, err := c.dst.createFramebufferIfNeeded(context)
if err != nil {
return err
}
if err := f.setAsViewport(context); err != nil {
return err
}
context.BlendFunc(c.mode)
n := c.quadsNum()
if n == 0 {
return nil
}
_, h := c.dst.Size()
proj := f.projectionMatrix(h)
p := &programContext{
state: &theOpenGLState,
program: theOpenGLState.programTexture,
context: context,
projectionMatrix: proj,
texture: c.src.texture.native,
colorM: c.color,
}
if err := p.begin(); err != nil {
return err
}
// TODO: We should call glBindBuffer here?
// The buffer is already bound at begin() but it is counterintuitive.
context.DrawElements(opengl.Triangles, 6*n, indexOffsetInBytes)
return nil
}
示例2: shader
func shader(c *opengl.Context, id shaderId) string {
str := shaders[id]
if !c.GlslHighpSupported() {
str = strings.Replace(str, "highp ", "", -1)
str = strings.Replace(str, "lowp ", "", -1)
}
return str
}
示例3: newFramebufferFromTexture
func newFramebufferFromTexture(context *opengl.Context, texture *texture) (*framebuffer, error) {
native, err := context.NewFramebuffer(opengl.Texture(texture.native))
if err != nil {
return nil, err
}
return &framebuffer{
native: native,
}, nil
}
示例4: Pixels
func (i *Image) Pixels(context *opengl.Context) ([]uint8, error) {
// Flush the enqueued commands so that pixels are certainly read.
if err := theCommandQueue.Flush(context); err != nil {
return nil, err
}
f, err := i.createFramebufferIfNeeded(context)
if err != nil {
return nil, err
}
return context.FramebufferPixels(f.native, i.width, i.height)
}
示例5: enable
func (a *arrayBufferLayout) enable(c *opengl.Context, program opengl.Program) {
for _, p := range a.parts {
c.EnableVertexAttribArray(program, p.name)
}
total := a.totalBytes()
offset := 0
for _, p := range a.parts {
c.VertexAttribPointer(program, p.name, p.num, p.dataType, p.normalize, total, offset)
offset += p.dataType.SizeInBytes() * p.num
}
}
示例6: Flush
func (q *commandQueue) Flush(context *opengl.Context) error {
q.m.Lock()
defer q.m.Unlock()
// glViewport must be called at least at every frame on iOS.
context.ResetViewportSize()
for _, g := range q.commandGroups() {
n := 0
for _, c := range g {
switch c := c.(type) {
case *drawImageCommand:
n += len(c.vertices)
}
}
vertices := make([]float32, 0, n)
for _, c := range g {
switch c := c.(type) {
case *drawImageCommand:
vertices = append(vertices, c.vertices...)
}
}
if 0 < len(vertices) {
context.BufferSubData(opengl.ArrayBuffer, vertices)
}
// NOTE: WebGL doesn't seem to have Check gl.MAX_ELEMENTS_VERTICES or gl.MAX_ELEMENTS_INDICES so far.
// Let's use them to compare to len(quads) in the future.
if maxQuads < len(vertices)*opengl.Float.SizeInBytes()/QuadVertexSizeInBytes() {
return fmt.Errorf("len(quads) must be equal to or less than %d", maxQuads)
}
numc := len(g)
indexOffsetInBytes := 0
for _, c := range g {
if err := c.Exec(context, indexOffsetInBytes); err != nil {
return err
}
if c, ok := c.(*drawImageCommand); ok {
n := len(c.vertices) * opengl.Float.SizeInBytes() / QuadVertexSizeInBytes()
indexOffsetInBytes += 6 * n * 2
}
}
if 0 < numc {
// Call glFlush to prevent black flicking (especially on Android (#226) and iOS).
context.Flush()
}
}
q.commands = []command{}
return nil
}
示例7: IsInvalidated
func (i *Image) IsInvalidated(context *opengl.Context) bool {
return !context.IsTexture(i.texture.native)
}
示例8: setAsViewport
func (f *framebuffer) setAsViewport(context *opengl.Context) error {
width := viewportSize
height := viewportSize
return context.SetViewport(f.native, width, height)
}
示例9: disable
func (a *arrayBufferLayout) disable(c *opengl.Context, program opengl.Program) {
// TODO: Disabling should be done in reversed order?
for _, p := range a.parts {
c.DisableVertexAttribArray(program, p.name)
}
}
示例10: newArrayBuffer
func (a *arrayBufferLayout) newArrayBuffer(c *opengl.Context) opengl.Buffer {
return c.NewBuffer(opengl.ArrayBuffer, a.totalBytes()*4*maxQuads, opengl.DynamicDraw)
}
示例11: reset
func (s *openGLState) reset(context *opengl.Context) error {
if err := context.Reset(); err != nil {
return err
}
s.lastProgram = zeroProgram
s.lastProjectionMatrix = nil
s.lastColorMatrix = nil
s.lastColorMatrixTranslation = nil
if s.arrayBuffer != zeroBuffer {
context.DeleteBuffer(s.arrayBuffer)
}
if s.indexBufferQuads != zeroBuffer {
context.DeleteBuffer(s.indexBufferQuads)
}
if s.programTexture != zeroProgram {
context.DeleteProgram(s.programTexture)
}
shaderVertexModelviewNative, err := context.NewShader(opengl.VertexShader, shader(context, shaderVertexModelview))
if err != nil {
panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
}
defer context.DeleteShader(shaderVertexModelviewNative)
shaderFragmentTextureNative, err := context.NewShader(opengl.FragmentShader, shader(context, shaderFragmentTexture))
if err != nil {
panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
}
defer context.DeleteShader(shaderFragmentTextureNative)
s.programTexture, err = context.NewProgram([]opengl.Shader{
shaderVertexModelviewNative,
shaderFragmentTextureNative,
})
if err != nil {
return err
}
s.arrayBuffer = theArrayBufferLayout.newArrayBuffer(context)
indices := make([]uint16, 6*maxQuads)
for i := uint16(0); i < maxQuads; i++ {
indices[6*i+0] = 4*i + 0
indices[6*i+1] = 4*i + 1
indices[6*i+2] = 4*i + 2
indices[6*i+3] = 4*i + 1
indices[6*i+4] = 4*i + 2
indices[6*i+5] = 4*i + 3
}
s.indexBufferQuads = context.NewBuffer(opengl.ElementArrayBuffer, indices, opengl.StaticDraw)
return nil
}