|
1 | | -/* |
2 | | -Copyright (C) 1997-2001 Id Software, Inc. |
3 | | -Copyright (C) 2020-2021 Mark E Sowden <hogsy@oldtimes-software.com> |
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | +// Copyright (C) 2020-2022 Mark E Sowden <hogsy@oldtimes-software.com> |
4 | 3 |
|
5 | | -This program is free software; you can redistribute it and/or |
6 | | -modify it under the terms of the GNU General Public License |
7 | | -as published by the Free Software Foundation; either version 2 |
8 | | -of the License, or (at your option) any later version. |
| 4 | +#include "gl_local.h" |
| 5 | +#include "gl_shader_manager.h" |
9 | 6 |
|
10 | | -This program is distributed in the hope that it will be useful, |
11 | | -but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 7 | +nox::renderer::gl::ShaderProgram::ShaderProgram() |
| 8 | +{ |
| 9 | + Q_ZERO( glStages, sizeof( uint32_t ) * Stage::MAX_STAGES ); |
| 10 | +} |
13 | 11 |
|
14 | | -See the GNU General Public License for more details. |
| 12 | +nox::renderer::gl::ShaderProgram::~ShaderProgram() |
| 13 | +{ |
| 14 | +} |
15 | 15 |
|
16 | | -You should have received a copy of the GNU General Public License |
17 | | -along with this program; if not, write to the Free Software |
18 | | -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 16 | +bool nox::renderer::gl::ShaderProgram::LoadShaderStage( const std::string &path, Stage stage ) |
| 17 | +{ |
| 18 | + assert( glStages[ stage ] == 0 ); |
| 19 | + if ( glStages[ stage ] != 0 ) |
| 20 | + { |
| 21 | + Com_Printf( "A stage of this type has already been cached!\n" ); |
| 22 | + return false; |
| 23 | + } |
19 | 24 |
|
20 | | -*/ |
| 25 | + GLenum glStage; |
| 26 | + assert( stage < Stage::MAX_STAGES ); |
| 27 | + if ( stage == Stage::STAGE_PIXEL ) |
| 28 | + { |
| 29 | + glStage = GL_VERTEX_SHADER; |
| 30 | + } |
| 31 | + else if ( stage == Stage::STAGE_VERTEX ) |
| 32 | + { |
| 33 | + glStage = GL_FRAGMENT_SHADER; |
| 34 | + } |
| 35 | + else |
| 36 | + { |
| 37 | + Com_Printf( "Unsupported shader stage: %u\n", stage ); |
| 38 | + return false; |
| 39 | + } |
21 | 40 |
|
22 | | -#include "gl_local.h" |
23 | | -#include "gl_shader_manager.h" |
| 41 | + XGL_CALL( glStages[ stage ] = glCreateShader( glStage ) ); |
| 42 | + if ( glStages[ stage ] == 0 ) |
| 43 | + { |
| 44 | + Com_Printf( "An error occurred on stage creation!\n" ); |
| 45 | + return false; |
| 46 | + } |
| 47 | + |
| 48 | + char *buffer; |
| 49 | + int length = FS_LoadFile( path.c_str(), ( void **) &buffer ); |
| 50 | + if ( length == -1 ) |
| 51 | + { |
| 52 | + Com_Printf( "Failed to open shader: %s\n", path.c_str() ); |
| 53 | + XGL_CALL( glDeleteShader( glStages[ stage ] ) ); |
| 54 | + glStages[ stage ] = 0; |
| 55 | + return false; |
| 56 | + } |
| 57 | + |
| 58 | + return false; |
| 59 | +} |
| 60 | + |
| 61 | +void nox::renderer::gl::ShaderProgram::Enable() |
| 62 | +{ |
| 63 | + assert( glProgram != 0 ); |
| 64 | + if ( glProgram == 0 ) |
| 65 | + { |
| 66 | + //TODO: use fallback |
| 67 | + return; |
| 68 | + } |
| 69 | + XGL_CALL( glUseProgram( glProgram ) ); |
| 70 | +} |
| 71 | + |
| 72 | +void nox::renderer::gl::ShaderProgram::Disable() |
| 73 | +{ |
| 74 | + XGL_CALL( glUseProgram( 0 ) ); |
| 75 | +} |
| 76 | + |
| 77 | +void nox::renderer::gl::ShaderProgram::Reload() |
| 78 | +{ |
| 79 | +} |
0 commit comments