hollywood boob
This commit is contained in:
parent
b1331e7863
commit
84b2e17844
5 changed files with 65 additions and 13 deletions
|
@ -60,11 +60,17 @@ add_executable(server ${server_src})
|
|||
target_include_directories(server
|
||||
PRIVATE ${PROJECT_SOURCE_DIR}/src/common
|
||||
PRIVATE ${PROJECT_SOURCE_DIR}/src/server)
|
||||
install(TARGETS server RUNTIME DESTINATION bin/server)
|
||||
|
||||
## COMMON LIBRARIES ##
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
target_link_libraries(server wsock32 ws2_32)
|
||||
target_link_libraries(client wsock32 ws2_32)
|
||||
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||
target_link_libraries(server dl pthread nsl resolv)
|
||||
target_link_libraries(client dl pthread nsl resolv)
|
||||
else()
|
||||
target_link_libraries(server dl pthread socket nsl resolv)
|
||||
target_link_libraries(client dl pthread socket nsl resolv)
|
||||
endif()
|
||||
install(TARGETS server RUNTIME DESTINATION bin/server)
|
|
@ -1,34 +1,33 @@
|
|||
#include "_shader.hpp"
|
||||
|
||||
sosc::Shader::Shader() : loaded(false) {}
|
||||
sosc::shdr::Shader::Shader() : loaded(false) {}
|
||||
|
||||
bool sosc::Shader::Load() {
|
||||
bool sosc::shdr::Shader::Load() {
|
||||
if(this->loaded)
|
||||
return true;
|
||||
|
||||
program = glCreateProgram();
|
||||
if(!PrepareLoad())
|
||||
return false;
|
||||
PrepareLoad();
|
||||
|
||||
this->loaded = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void sosc::Shader::Start() const {
|
||||
void sosc::shdr::Shader::Start() const {
|
||||
if(!this->loaded)
|
||||
return;
|
||||
|
||||
glUseProgram(this->program);
|
||||
}
|
||||
|
||||
void sosc::Shader::Stop() const {
|
||||
void sosc::shdr::Shader::Stop() const {
|
||||
if(!this->loaded)
|
||||
return;
|
||||
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void sosc::Shader::Unload() {
|
||||
void sosc::shdr::Shader::Unload() {
|
||||
if(!this->loaded)
|
||||
return;
|
||||
|
||||
|
@ -37,22 +36,43 @@ void sosc::Shader::Unload() {
|
|||
this->loaded = false;
|
||||
}
|
||||
|
||||
void sosc::Shader::AttachSource
|
||||
void sosc::shdr::Shader::AttachSource
|
||||
(const std::string& fileName, GLuint shaderType)
|
||||
{
|
||||
if(this->loaded)
|
||||
return;
|
||||
|
||||
GLuint shader = glCreateShader(shaderType);
|
||||
|
||||
std::ifstream file(fileName);
|
||||
std::stringstream ss;
|
||||
ss << file.rdbuf();
|
||||
|
||||
const char* src = ss.str().c_str();
|
||||
glShaderSource(shader, 1, (const GLchar**)&src, nullptr);
|
||||
glCompileShader(shader);
|
||||
|
||||
GLint tmpBuf;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &tmpBuf);
|
||||
if(tmpBuf == GL_FALSE) {
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &tmpBuf);
|
||||
|
||||
auto msg = new char[tmpBuf];
|
||||
glGetShaderInfoLog(shader, tmpBuf, nullptr, msg);
|
||||
throw ShaderCompilationException(fileName, msg);
|
||||
}
|
||||
|
||||
glAttachShader(this->program, shader);
|
||||
this->shaders.push_back(shader);
|
||||
}
|
||||
|
||||
void sosc::Shader::LinkProgram() {
|
||||
void sosc::shdr::Shader::LinkProgram() {
|
||||
glLinkProgram(this->program);
|
||||
for(const auto& shader : this->shaders)
|
||||
glDeleteShader(shader);
|
||||
}
|
||||
|
||||
void sosc::Shader::LoadUniforms(std::vector<std::string> names) {
|
||||
void sosc::shdr::Shader::LoadUniforms(std::vector<std::string> names) {
|
||||
if(this->loaded)
|
||||
return;
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <fstream>
|
||||
|
||||
namespace sosc {
|
||||
namespace shdr {
|
||||
struct ShaderCompilationException : public std::exception {
|
||||
public:
|
||||
ShaderCompilationException
|
||||
|
@ -49,17 +50,23 @@ public:
|
|||
void Start() const;
|
||||
|
||||
inline GLint operator[] (std::vector<GLint>::size_type index) {
|
||||
if(index >= locations.size())
|
||||
return -1;
|
||||
|
||||
return locations[index];
|
||||
}
|
||||
|
||||
inline GLint Uniform(std::vector<GLint>::size_type index) {
|
||||
if(index >= locations.size())
|
||||
return -1;
|
||||
|
||||
return locations[index];
|
||||
}
|
||||
|
||||
void Stop() const;
|
||||
void Unload();
|
||||
protected:
|
||||
virtual bool PrepareLoad() = 0;
|
||||
virtual void PrepareLoad() = 0;
|
||||
virtual void PrepareUnload() {};
|
||||
|
||||
void AttachSource(const std::string& fileName, GLuint shaderType);
|
||||
|
@ -71,6 +78,6 @@ private:
|
|||
GLuint program;
|
||||
bool loaded;
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
|
2
src/client/shaders/test.cpp
Normal file
2
src/client/shaders/test.cpp
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "test.hpp"
|
||||
|
17
src/client/shaders/test.hpp
Normal file
17
src/client/shaders/test.hpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef SOSC_SHADER_TEST_H
|
||||
#define SOSC_SHADER_TEST_H
|
||||
|
||||
#include "_shader.hpp"
|
||||
|
||||
namespace sosc {
|
||||
namespace shdr {
|
||||
class TestShader : public Shader {
|
||||
public:
|
||||
enum Uniforms {
|
||||
SCREEN_SIZE = 0,
|
||||
GRAPHIC_SAMPLER
|
||||
};
|
||||
};
|
||||
}}
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue