Skip to content

Commit

Permalink
shader improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
adafcaefc committed Dec 5, 2024
1 parent 6f9e9bf commit 3760e24
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 51 deletions.
70 changes: 31 additions & 39 deletions Geome3Dash/src/BlockModelStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,47 @@

namespace g3d
{
void BlockModelStorage::loadAllShaders()
sus3d::ShaderProgram* BlockModelStorage::loadShader(
const std::string& vsString,
const std::string& fsString)
{
OpenGLStateHelper::saveState();

const auto shaderPath = basePath / "planet" / "shader";

auto vertexShader = sus3d::Shader::createWithString(
sus3d::shaders::vertexShaderSource,
vsString,
sus3d::ShaderType::kVertexShader);

auto fragmentShader = sus3d::Shader::createWithString(
sus3d::shaders::fragmentShaderSource,
fsString,
sus3d::ShaderType::kFragmentShader);
//if (blockShaderProgram) { delete blockShaderProgram; }
blockShaderProgram = CocosShaderProgram::create(vertexShader, fragmentShader);

auto tmpSP = CocosShaderProgram::create(vertexShader, fragmentShader);

delete vertexShader;
delete fragmentShader;

auto vertexShader2 = sus3d::Shader::createWithString(
return tmpSP;
}

void BlockModelStorage::loadAllShaders()
{
OpenGLStateHelper::saveState();

const auto shaderPath = basePath / "planet" / "shader";

blockShaderProgram = loadShader(
sus3d::shaders::vertexShaderSource,
sus3d::ShaderType::kVertexShader);
auto fragmentShader2 = sus3d::Shader::createWithFile(
shaderPath / "water2.fsh",
sus3d::ShaderType::kFragmentShader);
//if (waterShaderProgram) { delete waterShaderProgram; }
waterShaderProgram = CocosShaderProgram::create(vertexShader2, fragmentShader2);
delete vertexShader2;
delete fragmentShader2;
sus3d::shaders::fragmentShaderSource);

auto vertexShader3 = sus3d::Shader::createWithFile(
shaderPath / "cloud.vsh",
sus3d::ShaderType::kVertexShader);
auto fragmentShader3 = sus3d::Shader::createWithFile(
shaderPath / "cloud.fsh",
sus3d::ShaderType::kFragmentShader);
//if (cloudShaderProgram) { delete cloudShaderProgram; }
cloudShaderProgram = CocosShaderProgram::create(vertexShader3, fragmentShader3);
delete vertexShader3;
delete fragmentShader3;
waterShaderProgram = loadShader(
sus3d::shaders::vertexShaderSource,
utils::read_from_file(shaderPath / "water2.fsh"));

auto vertexShader4 = sus3d::Shader::createWithString(
cloudShaderProgram = loadShader(
utils::read_from_file(shaderPath / "cloud.vsh"),
utils::read_from_file(shaderPath / "cloud.fsh"));

idBufferShaderProgram = loadShader(
sus3d::shaders::idBufferingVertexShader,
sus3d::ShaderType::kVertexShader);
auto fragmentShader4 = sus3d::Shader::createWithString(
sus3d::shaders::idBufferingFragmentShader,
sus3d::ShaderType::kFragmentShader);
//if (idBufferShaderProgram) { delete idBufferShaderProgram; }
idBufferShaderProgram = CocosShaderProgram::create(vertexShader4, fragmentShader4);
delete vertexShader4;
delete fragmentShader4;
sus3d::shaders::idBufferingFragmentShader);

OpenGLStateHelper::pushState();
}
Expand Down Expand Up @@ -107,10 +99,10 @@ namespace g3d
}
}

constexpr int MAX_OBJECT_ID = 3000;
constexpr int MAX_OBJECT_ID = 10000;
for (int i = 0; i < MAX_OBJECT_ID; i++)
{
const auto modelPath = basePath / "object" / std::to_string(i) / "model.obj";
const auto modelPath = basePath / "object" / std::to_string(i) / "model.obj";
if (auto blockModel = getModel(modelPath)) { blockModels[i] = blockModel; }
}
}
Expand Down
1 change: 1 addition & 0 deletions Geome3Dash/src/BlockModelStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace g3d
sus3d::ShaderProgram* cloudShaderProgram;
sus3d::ShaderProgram* idBufferShaderProgram;
static BlockModelStorage* instance;
sus3d::ShaderProgram* loadShader(const std::string& vsString, const std::string& fsString);
void loadAllShaders();
void loadAllModels();
bool init();
Expand Down
2 changes: 0 additions & 2 deletions Geome3Dash/src/LevelEditorImGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@ namespace g3d
// }
// catch (...)
// {

// }
// return true;
// }
Expand All @@ -464,7 +463,6 @@ namespace g3d
// }
// catch (...)
// {

// }
// return true;
// }
Expand Down
7 changes: 3 additions & 4 deletions Geome3Dash/src/engine/sus3d/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace sus3d
return 1;
}

bool Shader::initShader(std::string shaderString) {
bool Shader::initShader(const std::string& shaderString) {
switch (type) {
case kVertexShader:
return initVertexShader(shaderString.c_str());
Expand All @@ -52,8 +52,7 @@ namespace sus3d
}

Shader::~Shader() {
if (id)
glDeleteShader(id);
if (id) { glDeleteShader(id); }
}

std::string Shader::readFile(const std::filesystem::path& filename) {
Expand All @@ -66,7 +65,7 @@ namespace sus3d
return buffer.str();
}

Shader* Shader::createWithString(std::string shaderString, ShaderType type) {
Shader* Shader::createWithString(const std::string& shaderString, ShaderType type) {
auto ret = new Shader();
ret->type = type;
if (!ret || !ret->initShader(shaderString)) {
Expand Down
4 changes: 2 additions & 2 deletions Geome3Dash/src/engine/sus3d/Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ namespace sus3d

bool initVertexShader(const char* shaderString);
bool initFragmentShader(const char* shaderString);
bool initShader(std::string shaderString);
bool initShader(const std::string& shaderString);
public:
~Shader();
static std::string readFile(const std::filesystem::path& filename);
static Shader* createWithString(std::string shaderString, ShaderType type);
static Shader* createWithString(const std::string& shaderString, ShaderType type);
static Shader* createWithFile(const std::filesystem::path& filename, ShaderType type);
int get() { return id; }
ShaderType getType() { return type; }
Expand Down
12 changes: 8 additions & 4 deletions Geome3Dash/src/hook/GameManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@

namespace g3d
{
class $modify(GameManager) {
void returnToLastScene(GJGameLevel * p0) {
if (G3DPlanetLayer::insideThePlanetLayerFlag) {
class $modify(GameManager)
{
void returnToLastScene(GJGameLevel * p0)
{
if (G3DPlanetLayer::insideThePlanetLayerFlag)
{
CCDirector::sharedDirector()->popSceneWithTransition(0.3f, kPopTransitionFade);
}
else {
else
{
GameManager::returnToLastScene(p0);
}
}
Expand Down

0 comments on commit 3760e24

Please sign in to comment.