<commit_before>/*
* Copyright (C) 2014 - <NAME> <<EMAIL>>
*
* This sofware is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with This software. If not, see <http://www.gnu.org/licenses/>.
*/

use ooc-base
use ooc-math
use ooc-draw
use ooc-draw-gpu
import backend/GLShaderProgram
import OpenGLContext, OpenGLPacked

version(!gpuOff) {
OpenGLMap: abstract class extends GpuMap {
	_vertexSource: String
	_fragmentSource: String
	_program: GLShaderProgram[]
	program: GLShaderProgram {
		get {
			index := this _context getCurrentIndex()
			result := this _program[index]
			if (result == null) {
				result = this _context _backend createShaderProgram(this _vertexSource, this _fragmentSource)
				this _program[index] = result
			}
			result
		}
	}
	_context: OpenGLContext
	init: func (vertexSource: String, fragmentSource: String, context: OpenGLContext) {
		super()
		this _vertexSource = vertexSource
		this _fragmentSource = fragmentSource
		this _context = context
		this _program = GLShaderProgram[context getMaxContexts()] new()
		if (vertexSource == null || fragmentSource == null)
			Debug raise("Vertex or fragment shader source not set")
	}
	free: override func {
		for (i in 0 .. this _context getMaxContexts()) {
			if (this _program[i] != null)
				this _program[i] free()
		}
		this _program free()
		super()
	}
	use: override func {
		this program use()
		textureCount := 0
		action := func (key: String, value: Object) {
			program := this program
			if (value instanceOf?(Cell)) {
				cell := value as Cell
				match (cell T) {
					case Int => program setUniform(key, cell as Cell<Int> get())
					case IntPoint2D => program setUniform(key, cell as Cell<IntPoint2D> get())
					case IntPoint3D => program setUniform(key, cell as Cell<IntPoint3D> get())
					case IntSize2D => program setUniform(key, cell as Cell<IntSize2D> get())
					case IntSize3D => program setUniform(key, cell as Cell<IntSize3D> get())
					case Float => program setUniform(key, cell as Cell<Float> get())
					case FloatPoint2D => program setUniform(key, cell as Cell<FloatPoint2D> get())
					case FloatPoint3D => program setUniform(key, cell as Cell<FloatPoint3D> get())
					case FloatPoint4D => program setUniform(key, cell as Cell<FloatPoint4D> get())
					case FloatSize2D => program setUniform(key, cell as Cell<FloatSize2D> get())
					case FloatSize3D => program setUniform(key, cell as Cell<FloatSize3D> get())
					case FloatTransform2D => program setUniform(key, cell as Cell<FloatTransform2D> get())
					case FloatTransform3D => program setUniform(key, cell as Cell<FloatTransform3D> get())
					case => Debug raise("Invalid cover type in OpenGLMap use!")
				}
			}
			else
				match (value) {
					case image: OpenGLPacked => {
						image backend bind(textureCount)
						program setUniform(key, textureCount)
						textureCount += 1
					}
					case => Debug raise("Invalid object type in OpenGLMap use!")<commit_msg>Added OpenGLVolumeMonochrome as valid Image to bind.<commit_after>/*
* Copyright (C) 2014 - <NAME> <<EMAIL>>
*
* This sofware is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with This software. If not, see <http://www.gnu.org/licenses/>.
*/

use ooc-base
use ooc-math
use ooc-draw
use ooc-draw-gpu
import backend/GLShaderProgram
import OpenGLContext, OpenGLPacked, OpenGLVolumeMonochrome

version(!gpuOff) {
OpenGLMap: abstract class extends GpuMap {
	_vertexSource: String
	_fragmentSource: String
	_program: GLShaderProgram[]
	program: GLShaderProgram {
		get {
			index := this _context getCurrentIndex()
			result := this _program[index]
			if (result == null) {
				result = this _context _backend createShaderProgram(this _vertexSource, this _fragmentSource)
				this _program[index] = result
			}
			result
		}
	}
	_context: OpenGLContext
	init: func (vertexSource: String, fragmentSource: String, context: OpenGLContext) {
		super()
		this _vertexSource = vertexSource
		this _fragmentSource = fragmentSource
		this _context = context
		this _program = GLShaderProgram[context getMaxContexts()] new()
		if (vertexSource == null || fragmentSource == null)
			Debug raise("Vertex or fragment shader source not set")
	}
	free: override func {
		for (i in 0 .. this _context getMaxContexts()) {
			if (this _program[i] != null)
				this _program[i] free()
		}
		this _program free()
		super()
	}
	use: override func {
		this program use()
		textureCount := 0
		action := func (key: String, value: Object) {
			program := this program
			if (value instanceOf?(Cell)) {
				cell := value as Cell
				match (cell T) {
					case Int => program setUniform(key, cell as Cell<Int> get())
					case IntPoint2D => program setUniform(key, cell as Cell<IntPoint2D> get())
					case IntPoint3D => program setUniform(key, cell as Cell<IntPoint3D> get())
					case IntSize2D => program setUniform(key, cell as Cell<IntSize2D> get())
					case IntSize3D => program setUniform(key, cell as Cell<IntSize3D> get())
					case Float => program setUniform(key, cell as Cell<Float> get())
					case FloatPoint2D => program setUniform(key, cell as Cell<FloatPoint2D> get())
					case FloatPoint3D => program setUniform(key, cell as Cell<FloatPoint3D> get())
					case FloatPoint4D => program setUniform(key, cell as Cell<FloatPoint4D> get())
					case FloatSize2D => program setUniform(key, cell as Cell<FloatSize2D> get())
					case FloatSize3D => program setUniform(key, cell as Cell<FloatSize3D> get())
					case FloatTransform2D => program setUniform(key, cell as Cell<FloatTransform2D> get())
					case FloatTransform3D => program setUniform(key, cell as Cell<FloatTransform3D> get())
					case => Debug raise("Invalid cover type in OpenGLMap use!")
				}
			}
			else
				match (value) {
					case image: OpenGLPacked => {
						image backend bind(textureCount)
						program setUniform(key, textureCount)
						textureCount += 1
					}
					case image: OpenGLVolumeMonochrome => {
						image _backend bind(textureCount)
						program setUniform(key, textureCount)
						textureCount += 1
					}
					case => Debug raise("Invalid object type in OpenGLMap use!")
{'fraction_non_alphanumeric': 0.09527812806501332, 'fraction_numerical': 0.008827238335435058, 'mean_word_length': 4.033850493653032, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7576297', 'n_tokens_mistral': 2384, 'n_tokens_neox': 2060, 'n_words': 773}