Skip to content

Commit

Permalink
detect GLSL version
Browse files Browse the repository at this point in the history
  • Loading branch information
gregcman committed Dec 2, 2018
1 parent 8b0c835 commit 30c2fb0
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 11 deletions.
2 changes: 2 additions & 0 deletions application/app-subsystem/application/application.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
(refresh item t))
(window:set-vsync t)
(gl:enable :scissor-test)
(setf glhelp::*gl-version* (gl:get-string :version))
(setf glslgen::*glsl-version* (glhelp::glsl-gl-version))
(let ((*quit-token* (cons "trampoline" "token")))
(catch *quit-token*
(funcall fun))))))
Expand Down
1 change: 0 additions & 1 deletion application/basic0/basic0.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@
(progn
(deflazy flat-shader-source ()
(glslgen:ashader
:version 120
:vs
(glslgen2::make-shader-stage
:out '((value-out "vec4"))
Expand Down
5 changes: 2 additions & 3 deletions application/subsystems/text-subsystem/text-subsystem.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

(deflazy text-shader-source ()
(glslgen:ashader
:version 120
:vs
(glslgen2::make-shader-stage
:out '((texcoord-out "vec2"))
Expand Down Expand Up @@ -255,7 +254,7 @@

(deflazy flat-shader-source ()
(glslgen:ashader
:version 120 :vs
:vs
(glslgen2::make-shader-stage
:out '((value-out "vec4"))
:in '((position "vec4")
Expand Down Expand Up @@ -284,7 +283,7 @@
;;;;;;;;;;;;;;;;;;;;
(deflazy indirection-shader-source ()
(glslgen:ashader
:version 120 :vs
:vs
(glslgen2::make-shader-stage
:out '((texcoord-out "vec2"))
:in '((position "vec4")
Expand Down
1 change: 0 additions & 1 deletion application/testbed/sandbox-subsystem.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@

(deflazy blockshader-text ()
(glslgen::ashader
:version 120
:vs
(glslgen2::make-shader-stage
:out '((color-out "float")
Expand Down
1 change: 0 additions & 1 deletion application/testbed/testbed.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
(glhelp::create-gl-program solidshader-text))
(application:deflazy solidshader-text ()
(glslgen::ashader
:version 120
:vs
(glslgen2::make-shader-stage
:out '((color-out "vec3"))
Expand Down
22 changes: 22 additions & 0 deletions src/opengl/glhelp.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

(in-package :glhelp)

(defparameter *gl-version* "2.0") ;;abitrary, gets overwritten

;;;;in opengl horizontal lines must be multiples of 4 bytes
(defun array-flatten (array)
(make-array (array-total-size array)
Expand Down Expand Up @@ -172,3 +174,23 @@
(gl:enable :depth-test ;:multisample
)
(values texture framebuffer depthbuffer)))

(defun glsl-gl-version (&optional (version *gl-version*))
(let ((string (subseq version 0 3)))
(second
(assoc
string
(quote (("2.0" 110)
("2.1" 120)
("3.0" 130)
("3.1" 140)
("3.2" 150)
("3.3" 330)
("4.0" 400)
("4.1" 410)
("4.2" 420)
("4.3" 430)
("4.4" 440)
("4.5" 450)
("4.6" 460)))
:test 'string=))))
14 changes: 9 additions & 5 deletions src/opengl/glslgen.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
(if (consp string-cell) ;;means that the variable is shared
connected ;;attribute or varying
not-connected))))))
(defparameter *glsl-version* 110)
(defparameter *glsl-version* 110) ;;arbitrary, overwritten
(defparameter *stage* nil)
(defun qualify-version (hash)
(dohash (k v) hash
Expand Down Expand Up @@ -213,7 +213,12 @@
(return
(if (> *glsl-version* 120)
"roloCgarF_lg"
"gl_FragColor"))))))
"gl_FragColor")))
(when (string= x "texture2D")
(return
(if (>= *glsl-version* 150)
"texture"
x))))))
(cond (value
(setf value (getf value :string))
(if (listp value)
Expand Down Expand Up @@ -302,7 +307,7 @@
:initform '())
(version :accessor shader-program-data-version
:initarg :version
:initform 110)
:initform *glsl-version*)
(vars-attributes :accessor shader-program-data-vars-attributes)
(raw-attributes :accessor shader-program-data-raw-attributes)
(alias-uniform :accessor shader-program-data-alias-uniform)
Expand All @@ -324,8 +329,7 @@
(shader-program-data-attributes data)
(shader-program-data-varyings data)
(shader-program-data-uniforms data))

;; (print (list vs-string frag-string uniforms))
;; (print (list vs-string frag-string uniforms))
(multiple-value-prog1
(setf (values (shader-program-data-vs-string data)
(shader-program-data-frag-string data)
Expand Down

0 comments on commit 30c2fb0

Please sign in to comment.