Add a package for utilities regarding opengl
Currently supported version gl centric assert and restart macro
This commit is contained in:
parent
b8579526c0
commit
65d2d5d248
3 changed files with 66 additions and 5 deletions
46
src/render/gl-utils.lisp
Normal file
46
src/render/gl-utils.lisp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#|
|
||||
This file is a part of stoe project.
|
||||
Copyright (c) 2014 Renaud Casenave-Péré (renaud@casenave-pere.fr)
|
||||
|#
|
||||
|
||||
(in-package :cl-user)
|
||||
(defpackage stoe.render.gl-utils
|
||||
(:nicknames :gl-utils)
|
||||
(:use :cl)
|
||||
(:export :*major-version*
|
||||
:*minor-version*
|
||||
:initialize
|
||||
:version-supported-p
|
||||
:gl-assert
|
||||
:gl-restart))
|
||||
(in-package :stoe.render.gl-utils)
|
||||
|
||||
(defvar *major-version* nil)
|
||||
(defvar *minor-version* nil)
|
||||
|
||||
(defun initialize (version)
|
||||
"Initialize the local opengl configuration.
|
||||
Store values like the drivers version."
|
||||
(if (/= version 0)
|
||||
(progn
|
||||
(setf *major-version* (mod version 100))
|
||||
(setf *minor-version* (/ version 100)))
|
||||
(progn
|
||||
(setf *major-version* (gl:get-integer :major-version))
|
||||
(setf *minor-version* (gl:get-integer :minor-version)))))
|
||||
|
||||
(defun version-supported-p (version)
|
||||
(and (>= (mod version 100) *major-version*)
|
||||
(>= (/ version 100) *minor-version*)))
|
||||
|
||||
(defmacro gl-assert (form)
|
||||
`(prog1
|
||||
,form
|
||||
(let ((err-sym (%gl:get-error)))
|
||||
(unless (eq err-sym :zero)
|
||||
(error "The OpenGL command `~a'~%~2iresulted in an error: ~s~%" ',form err-sym)))))
|
||||
|
||||
(defmacro gl-restart (form)
|
||||
`(restart-case
|
||||
(gl-assert ,form)
|
||||
(continue () :report "Continue")))
|
||||
|
|
@ -18,8 +18,17 @@ Create an opengl context attach to a window."
|
|||
(format t "Initialize Render module~%")
|
||||
(let ((title (get-command-line-option argv "--title" "Stoe"))
|
||||
(width (get-command-line-option-int argv "--width" 800))
|
||||
(height (get-command-line-option-int argv "--height" 600)))
|
||||
(setf *window* (glop:create-window title width height))))
|
||||
(height (get-command-line-option-int argv "--height" 600))
|
||||
(version (get-command-line-option-int argv "--opengl")))
|
||||
(if version
|
||||
(progn
|
||||
(gl-utils:initialize version)
|
||||
(setf *window* (glop:create-window title width height
|
||||
:major gl-utils:*major-version*
|
||||
:minor gl-utils:*minor-version*)))
|
||||
(progn
|
||||
(setf *window* (glop:create-window title width height))
|
||||
(gl-utils:initialize 0)))))
|
||||
|
||||
(defun finalize ()
|
||||
"Finalize the render module.
|
||||
|
|
@ -31,7 +40,9 @@ Destroy the opengl context and the related resources."
|
|||
(defun update (delta-time)
|
||||
"Update the render module.
|
||||
Render a frame and swap buffers."
|
||||
(gl:clear-color 0 0 0 0)
|
||||
(declare (ignore delta-time))
|
||||
(glop:dispatch-events *window* :blocking nil :on-foo nil)
|
||||
(gl:clear-color 0.0 0 0 0)
|
||||
(gl:clear-depth 1.0)
|
||||
(gl:clear :color-buffer-bit :depth-buffer-bit)
|
||||
(glop:swap-buffers *window*))
|
||||
|
|
@ -39,3 +50,6 @@ Render a frame and swap buffers."
|
|||
(add-hook modules:*initialize-hook* #'initialize)
|
||||
(add-hook modules:*finalize-hook* #'finalize)
|
||||
(add-hook modules:*update-hook* #'update)
|
||||
|
||||
(defmethod glop:on-event (window event)
|
||||
(declare (ignore window event)))
|
||||
|
|
|
|||
5
stoe.asd
5
stoe.asd
|
|
@ -49,8 +49,9 @@
|
|||
:depends-on ("jobs"))
|
||||
(:module "render"
|
||||
:components
|
||||
((:file "render"))
|
||||
:depends-on ("modules"))
|
||||
((:file "gl-utils")
|
||||
(:file "render"))
|
||||
:depends-on ("modules" "utils"))
|
||||
(:file "stoe"
|
||||
:depends-on ("utils" "modules")))))
|
||||
:description "SaintOEngine - A 3d engine in common-lisp"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue