Skip to content

Commit 020d38a

Browse files
committed
Add shader capability
1 parent 33c59a3 commit 020d38a

File tree

6 files changed

+389
-0
lines changed

6 files changed

+389
-0
lines changed

MSVC/build/ogl.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@
276276
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
277277
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
278278
</ClCompile>
279+
<ClCompile Include="..\..\src\ogl\Shader.cxx" />
279280
<ClCompile Include="..\..\src\ogl\Vertex_Chunk.cxx" />
280281
<ClCompile Include="..\..\src\ogl\VBO_Element.cxx" />
281282
<ClCompile Include="..\..\src\ogl\VBO_Handler.cxx" />
@@ -292,6 +293,7 @@
292293
<ClInclude Include="..\..\include\OpenGLTexture.h" />
293294
<ClInclude Include="..\..\include\OpenGLUtils.h" />
294295
<ClInclude Include="..\..\include\RenderNode.h" />
296+
<ClInclude Include="..\..\include\Shader.h" />
295297
<ClInclude Include="..\..\include\Vertex_Chunk.h" />
296298
<ClInclude Include="..\..\src\ogl\VBO_Element.h" />
297299
<ClInclude Include="..\..\src\ogl\VBO_Handler.h" />

MSVC/build/ogl.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
<ClCompile Include="..\..\src\ogl\OpenGLFramebuffer.cxx">
2626
<Filter>Source Files</Filter>
2727
</ClCompile>
28+
<ClCompile Include="..\..\src\ogl\Shader.cxx">
29+
<Filter>Source Files</Filter>
30+
</ClCompile>
2831
<ClCompile Include="..\..\src\ogl\Vertex_Chunk.cxx">
2932
<Filter>Source Files</Filter>
3033
</ClCompile>
@@ -69,6 +72,9 @@
6972
<ClInclude Include="..\..\include\OpenGLFramebuffer.h">
7073
<Filter>Header Files</Filter>
7174
</ClInclude>
75+
<ClInclude Include="..\..\include\Shader.h">
76+
<Filter>Header Files</Filter>
77+
</ClInclude>
7278
<ClInclude Include="..\..\include\Vertex_Chunk.h">
7379
<Filter>Header Files</Filter>
7480
</ClInclude>

include/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ noinst_HEADERS = \
105105
ServerItem.h \
106106
ServerList.h \
107107
ServerListCache.h \
108+
Shader.h \
108109
ShotUpdate.h \
109110
Singleton.h \
110111
SphereObstacle.h \

include/Shader.h

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/* bzflag
2+
* Copyright (c) 2019-2019 Tim Riker
3+
*
4+
* This package is free software; you can redistribute it and/or
5+
* modify it under the terms of the license found in the file
6+
* named COPYING that should have accompanied this file.
7+
*
8+
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
9+
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11+
*/
12+
13+
#pragma once
14+
15+
// Before everything
16+
#include "common.h"
17+
18+
// Syste headers
19+
#include <string>
20+
#include <glm/fwd.hpp>
21+
#include <deque>
22+
23+
// Common headers
24+
#include "bzfgl.h"
25+
26+
extern bool shaderDestroyed;
27+
28+
class Shader
29+
{
30+
public:
31+
Shader(const char *shaderName);
32+
virtual ~Shader();
33+
34+
// Called to initialize/destroy the shader
35+
virtual void init();
36+
virtual void destroy();
37+
38+
GLint getAttribLocation(const char *attribute_name);
39+
GLint getUniformLocation(const char *uniform_name);
40+
void push();
41+
void pop();
42+
void setUniform(GLint uniform, bool value);
43+
void setUniform(GLint uniform, int value);
44+
void setUniform(GLint uniform, float value);
45+
void setUniform(GLint uniform, const glm::vec2 &value);
46+
void setUniform(GLint uniform, const glm::vec3 &value);
47+
void setUniform(GLint uniform, const glm::vec4 &value);
48+
void setUniform(GLint uniform, int count, GLint *value);
49+
void setUniform(GLint uniform, int count, const glm::vec3 value[]);
50+
void setUniform(GLint uniform, int count, const glm::vec4 value[]);
51+
protected:
52+
bool inited;
53+
private:
54+
// Those are callback for GL Context creation/free
55+
// Called by OpenGLGState::
56+
static void initContext(void* data);
57+
static void freeContext(void* data);
58+
59+
static std::deque<GLuint> programStack;
60+
61+
GLuint program;
62+
63+
GLuint create_shader(const char *filename, GLenum type);
64+
void print_log(GLuint object);
65+
char* file_read(const std::string &filename);
66+
std::string vertexShader;
67+
std::string fragmentShader;
68+
};
69+
70+
// Local Variables: ***
71+
// mode: C++ ***
72+
// tab-width: 4 ***
73+
// c-basic-offset: 4 ***
74+
// indent-tabs-mode: nil ***
75+
// End: ***
76+
// ex: shiftwidth=4 tabstop=4

src/ogl/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ libGLKit_la_SOURCES = \
2323
OpenGLTexture.cxx \
2424
OpenGLUtils.cxx \
2525
RenderNode.cxx \
26+
Shader.cxx \
2627
Vertex_Chunk.cxx \
2728
VBO_Element.h \
2829
VBO_Element.cxx \

0 commit comments

Comments
 (0)