From 1c187597e6b7b0bfbc7f8d73a4bc95354c69835c Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 4 May 2014 03:29:45 +0900 Subject: [PATCH] Add some comments --- graphics/opengl/context.go | 9 ++++----- graphics/opengl/shader/draw_texture.go | 1 + graphics/opengl/shader/program.go | 8 +++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/graphics/opengl/context.go b/graphics/opengl/context.go index 44df7a2fb..6a671384a 100644 --- a/graphics/opengl/context.go +++ b/graphics/opengl/context.go @@ -1,15 +1,14 @@ package opengl -import ( - "github.com/hajimehoshi/go-ebiten/graphics" - "github.com/hajimehoshi/go-ebiten/graphics/matrix" -) - // #cgo LDFLAGS: -framework OpenGL // // #include // #include import "C" +import ( + "github.com/hajimehoshi/go-ebiten/graphics" + "github.com/hajimehoshi/go-ebiten/graphics/matrix" +) func enableAlphaBlending() { C.glEnable(C.GL_TEXTURE_2D) diff --git a/graphics/opengl/shader/draw_texture.go b/graphics/opengl/shader/draw_texture.go index bf9252114..536dfd8f9 100644 --- a/graphics/opengl/shader/draw_texture.go +++ b/graphics/opengl/shader/draw_texture.go @@ -25,6 +25,7 @@ func DrawTexture(native NativeTexture, projectionMatrix [16]float32, if len(quads) == 0 { return } + // TODO: Check performance shaderProgram := use(projectionMatrix, geometryMatrix, colorMatrix) defer C.glUseProgram(0) diff --git a/graphics/opengl/shader/program.go b/graphics/opengl/shader/program.go index 2890752cc..be15a9370 100644 --- a/graphics/opengl/shader/program.go +++ b/graphics/opengl/shader/program.go @@ -85,7 +85,8 @@ func getLocation(program C.GLuint, name string, qvType qualifierVariableType) C. locationName := C.CString(name) defer C.free(unsafe.Pointer(locationName)) - location := C.GLint(-1) + const invalidLocation = -1 + location := C.GLint(invalidLocation) switch qvType { case qualifierVariableTypeAttribute: @@ -95,7 +96,7 @@ func getLocation(program C.GLuint, name string, qvType qualifierVariableType) C. default: panic("no reach") } - if location == -1 { + if location == invalidLocation { panic("glGetUniformLocation failed") } shaderLocationCache[qvType][name] = location @@ -112,7 +113,8 @@ func getUniformLocation(program C.GLuint, name string) C.GLint { } func use(projectionMatrix [16]float32, - geometryMatrix matrix.Geometry, colorMatrix matrix.Color) C.GLuint { + geometryMatrix matrix.Geometry, + colorMatrix matrix.Color) C.GLuint { programId := programRegular if !colorMatrix.IsIdentity() { programId = programColorMatrix