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
|
target_include_directories(server
|
||||||
PRIVATE ${PROJECT_SOURCE_DIR}/src/common
|
PRIVATE ${PROJECT_SOURCE_DIR}/src/common
|
||||||
PRIVATE ${PROJECT_SOURCE_DIR}/src/server)
|
PRIVATE ${PROJECT_SOURCE_DIR}/src/server)
|
||||||
|
install(TARGETS server RUNTIME DESTINATION bin/server)
|
||||||
|
|
||||||
|
## COMMON LIBRARIES ##
|
||||||
|
|
||||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||||
target_link_libraries(server wsock32 ws2_32)
|
target_link_libraries(server wsock32 ws2_32)
|
||||||
|
target_link_libraries(client wsock32 ws2_32)
|
||||||
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||||
target_link_libraries(server dl pthread nsl resolv)
|
target_link_libraries(server dl pthread nsl resolv)
|
||||||
|
target_link_libraries(client dl pthread nsl resolv)
|
||||||
else()
|
else()
|
||||||
target_link_libraries(server dl pthread socket nsl resolv)
|
target_link_libraries(server dl pthread socket nsl resolv)
|
||||||
|
target_link_libraries(client dl pthread socket nsl resolv)
|
||||||
endif()
|
endif()
|
||||||
install(TARGETS server RUNTIME DESTINATION bin/server)
|
|
|
@ -1,34 +1,33 @@
|
||||||
#include "_shader.hpp"
|
#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)
|
if(this->loaded)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
program = glCreateProgram();
|
program = glCreateProgram();
|
||||||
if(!PrepareLoad())
|
PrepareLoad();
|
||||||
return false;
|
|
||||||
|
|
||||||
this->loaded = true;
|
this->loaded = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sosc::Shader::Start() const {
|
void sosc::shdr::Shader::Start() const {
|
||||||
if(!this->loaded)
|
if(!this->loaded)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
glUseProgram(this->program);
|
glUseProgram(this->program);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sosc::Shader::Stop() const {
|
void sosc::shdr::Shader::Stop() const {
|
||||||
if(!this->loaded)
|
if(!this->loaded)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sosc::Shader::Unload() {
|
void sosc::shdr::Shader::Unload() {
|
||||||
if(!this->loaded)
|
if(!this->loaded)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -37,22 +36,43 @@ void sosc::Shader::Unload() {
|
||||||
this->loaded = false;
|
this->loaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sosc::Shader::AttachSource
|
void sosc::shdr::Shader::AttachSource
|
||||||
(const std::string& fileName, GLuint shaderType)
|
(const std::string& fileName, GLuint shaderType)
|
||||||
{
|
{
|
||||||
if(this->loaded)
|
if(this->loaded)
|
||||||
return;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sosc::Shader::LinkProgram() {
|
glAttachShader(this->program, shader);
|
||||||
|
this->shaders.push_back(shader);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sosc::shdr::Shader::LinkProgram() {
|
||||||
glLinkProgram(this->program);
|
glLinkProgram(this->program);
|
||||||
for(const auto& shader : this->shaders)
|
for(const auto& shader : this->shaders)
|
||||||
glDeleteShader(shader);
|
glDeleteShader(shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sosc::Shader::LoadUniforms(std::vector<std::string> names) {
|
void sosc::shdr::Shader::LoadUniforms(std::vector<std::string> names) {
|
||||||
if(this->loaded)
|
if(this->loaded)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
namespace sosc {
|
namespace sosc {
|
||||||
|
namespace shdr {
|
||||||
struct ShaderCompilationException : public std::exception {
|
struct ShaderCompilationException : public std::exception {
|
||||||
public:
|
public:
|
||||||
ShaderCompilationException
|
ShaderCompilationException
|
||||||
|
@ -49,17 +50,23 @@ public:
|
||||||
void Start() const;
|
void Start() const;
|
||||||
|
|
||||||
inline GLint operator[] (std::vector<GLint>::size_type index) {
|
inline GLint operator[] (std::vector<GLint>::size_type index) {
|
||||||
|
if(index >= locations.size())
|
||||||
|
return -1;
|
||||||
|
|
||||||
return locations[index];
|
return locations[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline GLint Uniform(std::vector<GLint>::size_type index) {
|
inline GLint Uniform(std::vector<GLint>::size_type index) {
|
||||||
|
if(index >= locations.size())
|
||||||
|
return -1;
|
||||||
|
|
||||||
return locations[index];
|
return locations[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stop() const;
|
void Stop() const;
|
||||||
void Unload();
|
void Unload();
|
||||||
protected:
|
protected:
|
||||||
virtual bool PrepareLoad() = 0;
|
virtual void PrepareLoad() = 0;
|
||||||
virtual void PrepareUnload() {};
|
virtual void PrepareUnload() {};
|
||||||
|
|
||||||
void AttachSource(const std::string& fileName, GLuint shaderType);
|
void AttachSource(const std::string& fileName, GLuint shaderType);
|
||||||
|
@ -71,6 +78,6 @@ private:
|
||||||
GLuint program;
|
GLuint program;
|
||||||
bool loaded;
|
bool loaded;
|
||||||
};
|
};
|
||||||
}
|
}}
|
||||||
|
|
||||||
#endif
|
#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