internal/graphicsdriver/opengl/gles: remove cString

This commit is contained in:
Hajime Hoshi 2022-09-13 00:10:59 +09:00
parent e46bfd8d30
commit 6ea455f4e1
2 changed files with 12 additions and 15 deletions

View File

@ -30,6 +30,8 @@ package gles
// #define GLES_SILENCE_DEPRECATION
// #include <OpenGLES/ES2/glext.h>
// #endif
//
// #include <stdlib.h>
import "C"
import (
@ -54,8 +56,8 @@ func (DefaultContext) AttachShader(program uint32, shader uint32) {
}
func (DefaultContext) BindAttribLocation(program uint32, index uint32, name string) {
s, free := cString(name)
defer free()
s := C.CString(name)
defer C.free(unsafe.Pointer(s))
C.glBindAttribLocation(C.GLuint(program), C.GLuint(index), (*C.GLchar)(unsafe.Pointer(s)))
}
@ -245,8 +247,8 @@ func (DefaultContext) GetShaderPrecisionFormat(shadertype uint32, precisiontype
}
func (DefaultContext) GetUniformLocation(program uint32, name string) int32 {
s, free := cString(name)
defer free()
s := C.CString(name)
defer C.free(unsafe.Pointer(s))
return int32(C.glGetUniformLocation(C.GLuint(program), (*C.GLchar)(unsafe.Pointer(s))))
}
@ -289,7 +291,7 @@ func (DefaultContext) Scissor(x, y, width, height int32) {
func (DefaultContext) ShaderSource(shader uint32, xstring string) {
s, free := cStringPtr(xstring)
defer free()
C.glShaderSource(C.GLuint(shader), 1, (**C.GLchar)(unsafe.Pointer(s)), nil)
C.glShaderSource(C.GLuint(shader), 1, (**C.GLchar)(s), nil)
}
func (DefaultContext) StencilFunc(func_ uint32, ref int32, mask uint32) {

View File

@ -24,17 +24,12 @@ import (
"unsafe"
)
func cString(str string) (uintptr, func()) {
ptr := C.CString(str)
return uintptr(unsafe.Pointer(ptr)), func() { C.free(unsafe.Pointer(ptr)) }
}
func cStringPtr(str string) (uintptr, func()) {
s, free := cString(str)
func cStringPtr(str string) (unsafe.Pointer, func()) {
s := C.CString(str)
ptr := C.malloc(C.size_t(unsafe.Sizeof((*int)(nil))))
*(*uintptr)(ptr) = s
return uintptr(ptr), func() {
free()
*(*unsafe.Pointer)(ptr) = unsafe.Pointer(s)
return ptr, func() {
C.free(unsafe.Pointer(s))
C.free(ptr)
}
}