Пример #1
0
// drawLoop is the primary drawing loop.
//
// After Cocoa has created an NSWindow and called prepareOpenGL,
// it starts drawLoop on a locked goroutine to handle OpenGL calls.
//
// The screen is drawn every time a paint.Event is received, which can be
// triggered either by the user or by Cocoa via drawgl (for example, when
// the window is resized).
func drawLoop(w *windowImpl, vba uintptr) {
	runtime.LockOSThread()
	C.makeCurrentContext(C.uintptr_t(w.ctx))

	// Starting in OS X 10.11 (El Capitan), the vertex array is
	// occasionally getting unbound when the context changes threads.
	//
	// Avoid this by binding it again.
	C.glBindVertexArray(C.GLuint(vba))
	if errno := C.glGetError(); errno != 0 {
		panic(fmt.Sprintf("gldriver: glBindVertexArray failed: %d", errno))
	}

	workAvailable := w.worker.WorkAvailable()

	// TODO(crawshaw): exit this goroutine on Release.
	for {
		select {
		case <-workAvailable:
			w.worker.DoWork()
		case <-w.publish:
		loop:
			for {
				select {
				case <-workAvailable:
					w.worker.DoWork()
				default:
					break loop
				}
			}
			C.flushContext(C.uintptr_t(w.ctx))
			w.publishDone <- screen.PublishResult{}
		}
	}
}
Пример #2
0
func GetError() (r0 Enum) {
	defer func() {
		errstr := errDrain()
		log.Printf("gl.GetError() %v%v", r0, errstr)
	}()
	return Enum(C.glGetError())
}
Пример #3
0
Файл: gl.go Проект: eaburns/gl
// GetError returns error information: an error if one occurred or nil.
func GetError() error {
	e := C.glGetError()
	if e == C.GL_NO_ERROR {
		return nil
	}
	return errors.New(errorStrings[e])
}
Пример #4
0
func errDrain() string {
	var errs []Enum
	for {
		e := Enum(C.glGetError())
		if e == 0 {
			break
		}
		errs = append(errs, e)
	}
	if len(errs) > 0 {
		return fmt.Sprintf(" error: %v", errs)
	}
	return ""
}
Пример #5
0
func CreateContext(win window.Window) {
	dpy := win.GetHDC()

	xData := (*XWinData)(dpy)

	if xData == nil {
		//TODO: Handle error somehow ???
		return
	}

	//attr := make([]C.int,)

	/*
		attr := []C.int{
			C.GLX_RGBA,
			C.GLX_DEPTH_SIZE,
			24,
			C.GLX_DOUBLEBUFFER,
			C.None,
		}
	*/

	//vi := C.glXChooseVisual(xData.dpy, 0, (*C.int)(unsafe.Pointer(&attr)));
	vi := C.Test(xData.dpy)
	tmpContext := C.glXCreateContext(xData.dpy, vi, nil, C.GL_TRUE)

	err := C.glGetError()

	if err != C.GL_NO_ERROR {
		fmt.Println("Error")
	}

	C.glXMakeCurrent(xData.dpy, (C.GLXDrawable)(xData.win), tmpContext)
	C.glewInit()
	/*
		C.glXMakeCurrent(xData.dpy)
		C.glewInit()

		var context C.HGLRC
		if C.wglewIsSupported(C.CString("WGL_ARB_create_context")) == 1 {
			//TODO: Figure out how to send attr to c func so it works!!!
			context = C.openglCreateContextAttribsARB(*(*C.HDC)(hdc), nil)

			C.wglMakeCurrent(nil, nil)
			C.wglDeleteContext(tmpContext)
			C.wglMakeCurrent(*(*C.HDC)(hdc), context)
		}
	*/
	return
}
Пример #6
0
func InitGlew() error {
	C.glewExperimental = C.GL_TRUE
	err := C.glewInit()

	if err != C.GLEW_OK {
		// fmt.Println(C.GoString(C.glewGetErrorString(glew_err)))
		return errors.New("glew error")
	}

	// Why did I need to do this?
	C.glGetError()

	return nil
}
Пример #7
0
func printerr(text string) error {
	_, file, line, _ := runtime.Caller(1)
	_, upperfile, upperline, _ := runtime.Caller(2)
	err := C.GoString(C.SDL_GetError())
	errtxt := err
	if len(err) > 0 {
		fmt.Println("SDL error: in ", file, " line ", line, " after ", upperfile, " line ", upperline, err, text)
	}
	glerr := C.glGetError()
	errtxt += map[int]string{0x0500: "GL_INVALID_ENUM", 0x0501: "GL_INVALID_VALUE", 0x0502: "GL_INVALID_OPERATION", 0x0505: "GL_OUT_OF_MEMORY"}[int(glerr)]
	if glerr != C.GL_NO_ERROR {
		fmt.Println("GL error: in ", file, " line ", line, " after ", upperfile, " line ", upperline, glerr, "("+map[int]string{0x0500: "GL_INVALID_ENUM", 0x0501: "GL_INVALID_VALUE", 0x0502: "GL_INVALID_OPERATION", 0x0505: "GL_OUT_OF_MEMORY"}[int(glerr)]+")", text)
	}
	if len(errtxt) > 0 {
		return errors.New(errtxt)
	}
	return nil
}
Пример #8
0
func Init() {
	if vg != nil {
		panic("blendish: already initialized")
	}
	C.glewExperimental = C.GL_TRUE
	if C.glewInit() != C.GLEW_OK {
		log.Fatalln("blendish: could not init glew (GL extensions)")
	}
	// GLEW generates GL error because it calls
	// glGetString(GL_EXTENSIONS), we'll consume it here.
	C.glGetError()
	vg = C.nvgCreateGL3(C.NVG_ANTIALIAS | C.NVG_STENCIL_STROKES)

	fontPath := C.CString(filepath.Join(dirs[0], "DejaVuSans.ttf"))
	iconsPath := C.CString(filepath.Join(dirs[0], "blender_icons16.png"))
	sys := C.CString("system")
	defer C.free(unsafe.Pointer(fontPath))
	defer C.free(unsafe.Pointer(iconsPath))
	defer C.free(unsafe.Pointer(sys))
	C.bndSetFont(C.nvgCreateFont(vg, sys, fontPath))
	C.bndSetIconImage(C.nvgCreateImage(vg, iconsPath, 0))
}
Пример #9
0
func GetError() Enum {
	return Enum(C.glGetError())
}
Пример #10
0
func checkGLError() {
	if glErr := C.glGetError(); glErr != C.GL_NO_ERROR {
		panic(fmt.Errorf("C.gl error: %v", glErr))
	}
}
Пример #11
0
func GetError() Error {
	return Error(C.glGetError())
}
Пример #12
0
Файл: gl.go Проект: james4k/gl
//GLenum glGetError (void)
func GetError() GLenum {
	return GLenum(C.glGetError())
}
Пример #13
0
func GetError() int {
	return int(C.glGetError())
}