Skip to content

Commit

Permalink
Add shader capability
Browse files Browse the repository at this point in the history
  • Loading branch information
atupone committed Oct 27, 2024
1 parent 33c59a3 commit 020d38a
Show file tree
Hide file tree
Showing 6 changed files with 389 additions and 0 deletions.
2 changes: 2 additions & 0 deletions MSVC/build/ogl.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="..\..\src\ogl\Shader.cxx" />
<ClCompile Include="..\..\src\ogl\Vertex_Chunk.cxx" />
<ClCompile Include="..\..\src\ogl\VBO_Element.cxx" />
<ClCompile Include="..\..\src\ogl\VBO_Handler.cxx" />
Expand All @@ -292,6 +293,7 @@
<ClInclude Include="..\..\include\OpenGLTexture.h" />
<ClInclude Include="..\..\include\OpenGLUtils.h" />
<ClInclude Include="..\..\include\RenderNode.h" />
<ClInclude Include="..\..\include\Shader.h" />
<ClInclude Include="..\..\include\Vertex_Chunk.h" />
<ClInclude Include="..\..\src\ogl\VBO_Element.h" />
<ClInclude Include="..\..\src\ogl\VBO_Handler.h" />
Expand Down
6 changes: 6 additions & 0 deletions MSVC/build/ogl.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<ClCompile Include="..\..\src\ogl\OpenGLFramebuffer.cxx">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ogl\Shader.cxx">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ogl\Vertex_Chunk.cxx">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -69,6 +72,9 @@
<ClInclude Include="..\..\include\OpenGLFramebuffer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\include\Shader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\include\Vertex_Chunk.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down
1 change: 1 addition & 0 deletions include/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ noinst_HEADERS = \
ServerItem.h \
ServerList.h \
ServerListCache.h \
Shader.h \
ShotUpdate.h \
Singleton.h \
SphereObstacle.h \
Expand Down
76 changes: 76 additions & 0 deletions include/Shader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* bzflag
* Copyright (c) 2019-2019 Tim Riker
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the license found in the file
* named COPYING that should have accompanied this file.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/

#pragma once

// Before everything
#include "common.h"

// Syste headers
#include <string>
#include <glm/fwd.hpp>
#include <deque>

// Common headers
#include "bzfgl.h"

extern bool shaderDestroyed;

class Shader
{
public:
Shader(const char *shaderName);
virtual ~Shader();

// Called to initialize/destroy the shader
virtual void init();
virtual void destroy();

GLint getAttribLocation(const char *attribute_name);
GLint getUniformLocation(const char *uniform_name);
void push();
void pop();
void setUniform(GLint uniform, bool value);
void setUniform(GLint uniform, int value);
void setUniform(GLint uniform, float value);
void setUniform(GLint uniform, const glm::vec2 &value);
void setUniform(GLint uniform, const glm::vec3 &value);
void setUniform(GLint uniform, const glm::vec4 &value);
void setUniform(GLint uniform, int count, GLint *value);
void setUniform(GLint uniform, int count, const glm::vec3 value[]);
void setUniform(GLint uniform, int count, const glm::vec4 value[]);
protected:
bool inited;
private:
// Those are callback for GL Context creation/free
// Called by OpenGLGState::
static void initContext(void* data);
static void freeContext(void* data);

static std::deque<GLuint> programStack;

GLuint program;

GLuint create_shader(const char *filename, GLenum type);
void print_log(GLuint object);
char* file_read(const std::string &filename);
std::string vertexShader;
std::string fragmentShader;
};

// Local Variables: ***
// mode: C++ ***
// tab-width: 4 ***
// c-basic-offset: 4 ***
// indent-tabs-mode: nil ***
// End: ***
// ex: shiftwidth=4 tabstop=4
1 change: 1 addition & 0 deletions src/ogl/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ libGLKit_la_SOURCES = \
OpenGLTexture.cxx \
OpenGLUtils.cxx \
RenderNode.cxx \
Shader.cxx \
Vertex_Chunk.cxx \
VBO_Element.h \
VBO_Element.cxx \
Expand Down
Loading

0 comments on commit 020d38a

Please sign in to comment.