소스 검색

Implement GLS ReadPixels (desktop)

Daniel Salvadori 6 년 전
부모
커밋
810f1177e7
2개의 변경된 파일14개의 추가작업 그리고 0개의 파일을 삭제
  1. 2 0
      gls/gls-browser.go
  2. 12 0
      gls/gls-desktop.go

+ 2 - 0
gls/gls-browser.go

@@ -399,6 +399,8 @@ func (gs *GLS) DeleteVertexArrays(vaos ...uint32) {
 	}
 }
 
+// TODO ReadPixels
+
 // DepthFunc specifies the function used to compare each incoming pixel
 // depth value with the depth value present in the depth buffer.
 func (gs *GLS) DepthFunc(mode uint32) {

+ 12 - 0
gls/gls-desktop.go

@@ -341,6 +341,18 @@ func (gs *GLS) DeleteVertexArrays(vaos ...uint32) {
 	gs.stats.Vaos -= len(vaos)
 }
 
+// ReadPixels returns the current rendered image.
+// x, y: specifies the window coordinates of the first pixel that is read from the frame buffer.
+// width, height: specifies the dimensions of the pixel rectangle.
+// format: specifies the format of the pixel data.
+// format_type: specifies the data type of the pixel data.
+// more information: http://docs.gl/gl3/glReadPixels
+func (gs *GLS) ReadPixels(x, y, width, height, format, formatType int) []byte {
+	size := uint32((width - x) * (height - y) * 4)
+	C.glReadPixels(C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height), C.GLenum(format), C.GLenum(formatType), unsafe.Pointer(gs.gobufSize(size)))
+	return gs.gobuf[:size]
+}
+
 // DepthFunc specifies the function used to compare each incoming pixel
 // depth value with the depth value present in the depth buffer.
 func (gs *GLS) DepthFunc(mode uint32) {