bugs: Advantages for incremental library separation by analogy with incremental
[Ale.git] / gpu.h
blob7998d3288388c734c922dd229080f437b794eb3b
1 // Copyright 2008 David Hilvert <dhilvert@auricle.dyndns.org>,
2 // <dhilvert@gmail.com>
4 /* This file is part of the Anti-Lamenessing Engine.
6 The Anti-Lamenessing Engine is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 The Anti-Lamenessing Engine is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with the Anti-Lamenessing Engine; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * gpu.h: Graphics processor management
25 #ifndef __gpu_h__
26 #define __gpu_h__
28 #include <config.h>
30 #include <assert.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <stdlib.h>
35 extern "C" {
36 #include <ale.h>
39 #include "accel.h"
40 #include "thread.h"
42 #define ALE_GPU_ASSERT_INCLUDE \
43 "(ale-define-macro (assert expr) `(if (not ,expr) (ale-error \"Assertion failed: \" ,(object->string expr))))"
45 class gpu {
46 public:
47 class program {
50 * Libale kernel.
53 void *lk;
55 public:
56 class shader {
59 * Libale kernel module.
62 void *lkm;
64 public:
65 void attach_to_program(const program *p) const {
66 // ale_add_kernel_module(p->lk, lkm);
68 shader(const char *source) {
69 // lkm = ale_new_kernel_module(accel::context(), source);
71 shader (const shader &p) {
72 assert(0);
74 shader &operator=(const shader &p) {
75 assert(0);
78 ~shader() {
79 // ale_delete_kernel_module(lkm);
83 class library {
84 protected:
85 shader *gpu_shader;
86 public:
87 library() {
88 gpu_shader = NULL;
92 * For libraries containing multiple shaders, or
93 * referencing shaders not stored locally, this
94 * method can be overridden.
96 virtual void attach_shaders(program *p) const {
97 assert(p);
98 if (gpu_shader)
99 p->attach(gpu_shader);
103 static void set_constant(const char *name, int value) {
106 * XXX: if possible, it would probably be better not to
107 * use this method, as it would require addition of
108 * constant handling to Libale.
111 assert(0);
113 #if 0
114 program_buffer_size++;
115 size_program_buffer();
117 const int line_length = 1000;
119 char *program_line = (char *) malloc(line_length * sizeof(char));
120 assert(program_line);
122 #if 0
124 * XXX: This seems to generate link errors, for some reason.
126 snprintf(program_line, line_length, "const int %s = %d;\n", name, value);
127 #else
128 snprintf(program_line, line_length, "#define %s %d\n", name, value);
129 #endif
131 program_buffer[program_buffer_size - 1] = program_line;
132 #endif
135 program() {
136 // lk = ale_new_kernel(accel::context());
139 program (const program &p) {
140 assert(0);
143 program &operator=(const program &p) {
144 assert(0);
147 ~program() {
148 // ale_delete_kernel(lk);
151 void attach(const shader *s) {
152 s->attach_to_program(this);
155 void attach(const library *l) {
156 l->attach_shaders(this);
159 void link() {
160 // ale_link_kernel(lk);
166 #endif