mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
graphicsdriver/opengl: Refactoring: Remove shaderType
This commit is contained in:
parent
8dba7b7722
commit
526a92256b
@ -21,6 +21,8 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
)
|
||||
|
||||
type operation int
|
||||
|
||||
func convertOperation(op driver.Operation) operation {
|
||||
switch op {
|
||||
case driver.Zero:
|
||||
|
@ -79,9 +79,6 @@ func getProgramID(p program) programID {
|
||||
}
|
||||
|
||||
const (
|
||||
vertexShader = shaderType(gl.VERTEX_SHADER)
|
||||
fragmentShader = shaderType(gl.FRAGMENT_SHADER)
|
||||
|
||||
zero = operation(gl.ZERO)
|
||||
one = operation(gl.ONE)
|
||||
srcAlpha = operation(gl.SRC_ALPHA)
|
||||
@ -238,8 +235,16 @@ func (c *context) deleteFramebuffer(f framebufferNative) {
|
||||
gl.DeleteFramebuffersEXT(1, &ff)
|
||||
}
|
||||
|
||||
func (c *context) newShader(shaderType shaderType, source string) (shader, error) {
|
||||
s := gl.CreateShader(uint32(shaderType))
|
||||
func (c *context) newVertexShader(source string) (shader, error) {
|
||||
return c.newShader(gl.VERTEX_SHADER, source)
|
||||
}
|
||||
|
||||
func (c *context) newFragmentShader(source string) (shader, error) {
|
||||
return c.newShader(gl.FRAGMENT_SHADER, source)
|
||||
}
|
||||
|
||||
func (c *context) newShader(shaderType uint32, source string) (shader, error) {
|
||||
s := gl.CreateShader(shaderType)
|
||||
if s == 0 {
|
||||
return 0, fmt.Errorf("opengl: glCreateShader failed: shader type: %d", shaderType)
|
||||
}
|
||||
|
@ -74,9 +74,6 @@ func getProgramID(p program) programID {
|
||||
}
|
||||
|
||||
const (
|
||||
vertexShader = shaderType(gles.VERTEX_SHADER)
|
||||
fragmentShader = shaderType(gles.FRAGMENT_SHADER)
|
||||
|
||||
zero = operation(gles.ZERO)
|
||||
one = operation(gles.ONE)
|
||||
srcAlpha = operation(gles.SRC_ALPHA)
|
||||
@ -278,7 +275,15 @@ func (c *context) deleteFramebuffer(f framebufferNative) {
|
||||
gl.Call("deleteFramebuffer", js.Value(f))
|
||||
}
|
||||
|
||||
func (c *context) newShader(shaderType shaderType, source string) (shader, error) {
|
||||
func (c *context) newVertexShader(source string) (shader, error) {
|
||||
return c.newShader(gles.VERTEX_SHADER, source)
|
||||
}
|
||||
|
||||
func (c *context) newFragmentShader(source string) (shader, error) {
|
||||
return c.newShader(gles.FRAGMENT_SHADER, source)
|
||||
}
|
||||
|
||||
func (c *context) newShader(shaderType int, source string) (shader, error) {
|
||||
gl := c.gl
|
||||
s := gl.Call("createShader", int(shaderType))
|
||||
if jsutil.Equal(s, js.Null()) {
|
||||
@ -479,7 +484,7 @@ func (c *context) maxTextureSizeImpl() int {
|
||||
|
||||
func (c *context) getShaderPrecisionFormatPrecision() int {
|
||||
gl := c.gl
|
||||
return gl.Call("getShaderPrecisionFormat", js.ValueOf(int(fragmentShader)), gles.HIGH_FLOAT).Get("precision").Int()
|
||||
return gl.Call("getShaderPrecisionFormat", gles.FRAGMENT_SHADER, gles.HIGH_FLOAT).Get("precision").Int()
|
||||
}
|
||||
|
||||
func (c *context) flush() {
|
||||
|
@ -77,9 +77,6 @@ func getProgramID(p program) programID {
|
||||
}
|
||||
|
||||
const (
|
||||
vertexShader = shaderType(gles.VERTEX_SHADER)
|
||||
fragmentShader = shaderType(gles.FRAGMENT_SHADER)
|
||||
|
||||
zero = operation(gles.ZERO)
|
||||
one = operation(gles.ONE)
|
||||
srcAlpha = operation(gles.SRC_ALPHA)
|
||||
@ -227,8 +224,16 @@ func (c *context) deleteFramebuffer(f framebufferNative) {
|
||||
c.ctx.DeleteFramebuffers([]uint32{uint32(f)})
|
||||
}
|
||||
|
||||
func (c *context) newShader(shaderType shaderType, source string) (shader, error) {
|
||||
s := c.ctx.CreateShader(uint32(shaderType))
|
||||
func (c *context) newVertexShader(source string) (shader, error) {
|
||||
return c.newShader(gles.VERTEX_SHADER, source)
|
||||
}
|
||||
|
||||
func (c *context) newFragmentShader(source string) (shader, error) {
|
||||
return c.newShader(gles.FRAGMENT_SHADER, source)
|
||||
}
|
||||
|
||||
func (c *context) newShader(shaderType uint32, source string) (shader, error) {
|
||||
s := c.ctx.CreateShader(shaderType)
|
||||
if s == 0 {
|
||||
return 0, fmt.Errorf("opengl: glCreateShader failed: shader type: %d", shaderType)
|
||||
}
|
||||
|
@ -15,9 +15,6 @@
|
||||
package gl
|
||||
|
||||
const (
|
||||
VERTEX_SHADER = 0x8B31
|
||||
FRAGMENT_SHADER = 0x8B30
|
||||
|
||||
ZERO = 0
|
||||
ONE = 1
|
||||
SRC_ALPHA = 0x0302
|
||||
@ -35,6 +32,7 @@ const (
|
||||
ELEMENT_ARRAY_BUFFER = 0x8893
|
||||
FALSE = 0
|
||||
FLOAT = 0x1406
|
||||
FRAGMENT_SHADER = 0x8B30
|
||||
FRAMEBUFFER = 0x8D40
|
||||
FRAMEBUFFER_BINDING = 0x8CA6
|
||||
FRAMEBUFFER_COMPLETE = 0x8CD5
|
||||
@ -61,6 +59,7 @@ const (
|
||||
UNPACK_ALIGNMENT = 0x0CF5
|
||||
UNSIGNED_BYTE = 0x1401
|
||||
UNSIGNED_SHORT = 0x1403
|
||||
VERTEX_SHADER = 0x8B31
|
||||
WRITE_ONLY = 0x88B9
|
||||
)
|
||||
|
||||
|
@ -16,9 +16,6 @@
|
||||
package gles
|
||||
|
||||
const (
|
||||
VERTEX_SHADER = 0x8B31
|
||||
FRAGMENT_SHADER = 0x8B30
|
||||
|
||||
ZERO = 0
|
||||
ONE = 1
|
||||
SRC_ALPHA = 0x0302
|
||||
@ -36,6 +33,7 @@ const (
|
||||
ELEMENT_ARRAY_BUFFER = 0x8893
|
||||
FALSE = 0
|
||||
FLOAT = 0x1406
|
||||
FRAGMENT_SHADER = 0x8B30
|
||||
FRAMEBUFFER = 0x8D40
|
||||
FRAMEBUFFER_BINDING = 0x8CA6
|
||||
FRAMEBUFFER_COMPLETE = 0x8CD5
|
||||
@ -63,5 +61,6 @@ const (
|
||||
UNPACK_ALIGNMENT = 0x0CF5
|
||||
UNSIGNED_BYTE = 0x1401
|
||||
UNSIGNED_SHORT = 0x1403
|
||||
VERTEX_SHADER = 0x8B31
|
||||
WRITE_ONLY = 0x88B9
|
||||
)
|
||||
|
@ -173,7 +173,7 @@ func (s *openGLState) reset(context *context) error {
|
||||
}
|
||||
}
|
||||
|
||||
shaderVertexModelviewNative, err := context.newShader(vertexShader, vertexShaderStr())
|
||||
shaderVertexModelviewNative, err := context.newVertexShader(vertexShaderStr())
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
|
||||
}
|
||||
@ -190,7 +190,7 @@ func (s *openGLState) reset(context *context) error {
|
||||
driver.FilterLinear,
|
||||
driver.FilterScreen,
|
||||
} {
|
||||
shaderFragmentColorMatrixNative, err := context.newShader(fragmentShader, fragmentShaderStr(c, f, a))
|
||||
shaderFragmentColorMatrixNative, err := context.newFragmentShader(fragmentShaderStr(c, f, a))
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
|
||||
}
|
||||
|
@ -54,13 +54,13 @@ func (s *Shader) Dispose() {
|
||||
func (s *Shader) compile() error {
|
||||
vssrc, fssrc := glsl.Compile(s.ir, glslVersion())
|
||||
|
||||
vs, err := s.graphics.context.newShader(vertexShader, vssrc)
|
||||
vs, err := s.graphics.context.newVertexShader(vssrc)
|
||||
if err != nil {
|
||||
return fmt.Errorf("opengl: vertex shader compile error: %v, source:\n%s", err, vssrc)
|
||||
}
|
||||
defer s.graphics.context.deleteShader(vs)
|
||||
|
||||
fs, err := s.graphics.context.newShader(fragmentShader, fssrc)
|
||||
fs, err := s.graphics.context.newFragmentShader(fssrc)
|
||||
if err != nil {
|
||||
return fmt.Errorf("opengl: fragment shader compile error: %v, source:\n%s", err, fssrc)
|
||||
}
|
||||
|
@ -1,20 +0,0 @@
|
||||
// Copyright 2014 Hajime Hoshi
|
||||
//
|
||||
// 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 opengl
|
||||
|
||||
type (
|
||||
shaderType int
|
||||
operation int
|
||||
)
|
Loading…
Reference in New Issue
Block a user