zorldo

Goofing around with Ebiten
git clone git://bsandro.tech/zorldo
Log | Files | Refs | README

type.go (1908B)


      1 // Copyright 2020 The Ebiten Authors
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 package glsl
     16 
     17 import (
     18 	"fmt"
     19 
     20 	"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
     21 )
     22 
     23 func typeString(t *shaderir.Type) (string, string) {
     24 	switch t.Main {
     25 	case shaderir.Array:
     26 		t0, t1 := typeString(&t.Sub[0])
     27 		return t0 + t1, fmt.Sprintf("[%d]", t.Length)
     28 	case shaderir.Struct:
     29 		panic("glsl: a struct is not implemented")
     30 	default:
     31 		return basicTypeString(t.Main), ""
     32 	}
     33 }
     34 
     35 func basicTypeString(t shaderir.BasicType) string {
     36 	switch t {
     37 	case shaderir.None:
     38 		return "?(none)"
     39 	case shaderir.Bool:
     40 		return "bool"
     41 	case shaderir.Int:
     42 		return "int"
     43 	case shaderir.Float:
     44 		return "float"
     45 	case shaderir.Vec2:
     46 		return "vec2"
     47 	case shaderir.Vec3:
     48 		return "vec3"
     49 	case shaderir.Vec4:
     50 		return "vec4"
     51 	case shaderir.Mat2:
     52 		return "mat2"
     53 	case shaderir.Mat3:
     54 		return "mat3"
     55 	case shaderir.Mat4:
     56 		return "mat4"
     57 	case shaderir.Array:
     58 		return "?(array)"
     59 	case shaderir.Struct:
     60 		return "?(struct)"
     61 	default:
     62 		return fmt.Sprintf("?(unknown type: %d)", t)
     63 	}
     64 }
     65 
     66 func (c *compileContext) builtinFuncString(f shaderir.BuiltinFunc) string {
     67 	switch f {
     68 	case shaderir.Atan2:
     69 		return "atan"
     70 	case shaderir.Dfdx:
     71 		return "dFdx"
     72 	case shaderir.Dfdy:
     73 		return "dFdy"
     74 	case shaderir.Texture2DF:
     75 		if c.version == GLSLVersionES300 {
     76 			return "texture"
     77 		}
     78 		return "texture2D"
     79 	default:
     80 		return string(f)
     81 	}
     82 }