Skip to content

jeremykross/to-glsl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

To-GLSL

Introduction

To-GLSL is a library for converting Clojure s-expressions to GLSL.

Usage

[to-glsl "0.1.0-SNAPSHOT"]

Example

(def basic-vs
  '(do
     (def-attribute vec4 vertex-position)
     (def-attribute vec2 tex-coord-attr)

     (def-uniform mat4 model-view)
     (def-uniform mat4 projection)

     (def-varying (highp vec2) tex-coord)

     (defn main (void [])
       (set! tex-coord tex-coord-attr)
       (set!
         gl/position
         (* projection model-view vertex-position)))))

(def basic-fs
  '(do
     (def-uniform sampler-2D sampler)
     (def-varying (highp vec2) tex-coord)

     (defn main (void [])
       (set! gl/frag-color (texture-2D sampler tex-coord)))))

(require '[to-glsl.core :refer [->glsl]])

(def vs-source (->glsl basic-vs))
(def fs-source (->glsl basic-fs))

Supported Language

defn

(defn add-one (void [(int x)]) (+ x 1))

becomes:

void addOne(int x) {
  x + 1;
}

Note: types must be specified

def

(def float pi 3.14159)

becomes

float pi = 3.14159;

def-varying - like def but creates a varying

def-uniform - like def but creates a uniform

def-attribute - like def but creates an attribute

set!

(set! x 5)

becomes

x = 5;

when

(when (and (= x 10) (= z 30))
  (set! y 20))

becomes

if (x == 10 && z == 30) {
  y = 20;
}

if

(set! y (if (= x 10) 20 10))

becomes

y = x == 10 ? 20 : 10;

and, or, =, +, -, /, *, bit-and, bit-or, bit-xor, bit-not, bit-shift-right, bit-shift-left - all compile into appriate infix form.

inc and dec - compile into ++ and -- repectively.

field

(field vec x)

becomes

vec.x

swizzle

(swizzle vec x z)

becomes

vec.xz

All symbols are automatically converted from kebab case into camel case.

The GLSL gl_ symbols like gl_Position and gl_FragColor can be accessed under the gl/ namespace in kebab case. i.e. gl/frag-color.

To-GLSL doesn't make any attempt to validate the provided code.

License

Copyright 2019 Jeremy Kross

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

About

For those who love graphics programming and hate shading languages

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published