TODO: Add a render module (incomplete)

This commit is contained in:
Renaud Casenave-Péré 2014-09-17 08:37:29 +02:00
parent 563bd7f0f9
commit aec779ac7b
4 changed files with 102 additions and 1 deletions

10
src/render/material.lisp Normal file
View file

@ -0,0 +1,10 @@
#|
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.material
(:nicknames :material)
(:use :cl))
(in-package :stoe.material)

44
src/render/mesh.lisp Normal file
View file

@ -0,0 +1,44 @@
#|
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.mesh
(:nicknames :mesh)
(:use :cl))
(in-package :stoe.mesh)
(defstruct vertex-stream
(name)
(data)
(type)
(size))
(defstruct index-stream
(data)
(type)
(mode))
(defclass mesh ()
((name :initform "")
(index-stream :initform nil :type index-stream)
(vertex-streams :initform nil :type (single-array vertex-stream))))
(defmacro defmesh (name &body body)
(let ((mesh-symbol (gensym)))
`(let ((,mesh-symbol (make-instance 'mesh :name ,(symbol-name name))))
(with-slots (indices vertices) ,mesh-symbol
,@(loop while body
collect (let* ((stream (pop body))
(stream-name (pop stream)))
(if (eq stream-name :index)
`(setf indices (make-index-stream ,@stream))
`(push (make-vertex-stream :name ,stream-name ,@stream) vertices)))))
,mesh-symbol)))
(defun load-mesh (data)
(let ((mesh (make-instance 'mesh :name (getf data :name))))
(with-slots (index-stream vertex-streams) mesh
(setf index-stream (getf data :index-stream))
(setf vertex-streams (getf data :vertex-streams)))))

41
src/render/render.lisp Normal file
View file

@ -0,0 +1,41 @@
#|
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
(:nicknames :render)
(:use :cl
:utils))
(in-package :stoe.render)
(defvar *window* nil)
(defun initialize (&optional argv)
"Initialize the render module.
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))))
(defun finalize ()
"Finalize the render module.
Destroy the opengl context and the related resources."
(format t "Finalize Render module~%")
(glop:destroy-window *window*)
(setf *window* nil))
(defun update (delta-time)
"Update the render module.
Render a frame and swap buffers."
(gl:clear-color 0 0 0 0)
(gl:clear-depth 1.0)
(gl:clear :color-buffer-bit :depth-buffer-bit)
(glop:swap-buffers *window*))
(add-hook modules:*initialize-hook* #'initialize)
(add-hook modules:*finalize-hook* #'finalize)
(add-hook modules:*update-hook* #'update)

View file

@ -18,7 +18,9 @@
:version "0.1"
:author "Renaud Casenave-Péré"
:license "GPL3"
:depends-on (:swank)
:depends-on (:swank
:glop
:cl-opengl)
:components ((:module "src"
:components
((:module "maths"
@ -45,6 +47,10 @@
:depends-on ("thread" "containers" "utils"))
(:file "file"
:depends-on ("jobs"))
(:module "render"
:components
((:file "render"))
:depends-on ("modules"))
(:file "stoe"
:depends-on ("utils" "modules")))))
:description "SaintOEngine - A 3d engine in common-lisp"