From f09399628448a38370361bb347d24be04f248450 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 14 Nov 2022 03:13:36 +0900 Subject: [PATCH] internal/graphicsdriver/opengl/gl: refactoring --- .../opengl/gl/default_android.go | 6 ++-- internal/graphicsdriver/opengl/gl/str.go | 32 ------------------- 2 files changed, 3 insertions(+), 35 deletions(-) delete mode 100644 internal/graphicsdriver/opengl/gl/str.go diff --git a/internal/graphicsdriver/opengl/gl/default_android.go b/internal/graphicsdriver/opengl/gl/default_android.go index 5090a6ca9..067a01ccb 100644 --- a/internal/graphicsdriver/opengl/gl/default_android.go +++ b/internal/graphicsdriver/opengl/gl/default_android.go @@ -284,9 +284,9 @@ 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)(s), nil) + s := C.CString(xstring) + defer C.free(unsafe.Pointer(s)) + C.glShaderSource(C.GLuint(shader), 1, (**C.GLchar)(unsafe.Pointer(&s)), nil) } func (defaultContext) StencilFunc(func_ uint32, ref int32, mask uint32) { diff --git a/internal/graphicsdriver/opengl/gl/str.go b/internal/graphicsdriver/opengl/gl/str.go deleted file mode 100644 index 6316ddc7e..000000000 --- a/internal/graphicsdriver/opengl/gl/str.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2020 The Ebiten Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package gl - -// #include -import "C" - -import ( - "unsafe" -) - -func cStringPtr(str string) (unsafe.Pointer, func()) { - s := C.CString(str) - ptr := C.malloc(C.size_t(unsafe.Sizeof((*int)(nil)))) - *(*unsafe.Pointer)(ptr) = unsafe.Pointer(s) - return ptr, func() { - C.free(unsafe.Pointer(s)) - C.free(ptr) - } -}