-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee61067
commit e5e8e4b
Showing
4 changed files
with
153 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#include "CCBlurLayer.hpp" | ||
|
||
std::vector<CCBlurLayer*> layers; | ||
|
||
#define APP_SHADER_SOURCE(...) #__VA_ARGS__ | ||
|
||
const GLchar* vertShaderSource = APP_SHADER_SOURCE( | ||
attribute vec4 a_position; | ||
attribute vec2 a_texCoord; | ||
varying vec2 v_texCoord; | ||
|
||
void main() { | ||
gl_Position = CC_PMatrix * CC_MVMatrix * a_position; | ||
v_texCoord = a_texCoord; | ||
} | ||
); | ||
|
||
const GLchar* fragShaderSource = | ||
"#ifdef GL_ES\n" | ||
"precision mediump float;\n" | ||
"#endif\n" | ||
"varying vec2 v_texCoord;\n" | ||
"uniform sampler2D CC_Texture0;\n" | ||
"void main() {\n" | ||
" vec4 color = texture2D(CC_Texture0, v_texCoord);\n" | ||
" gl_FragColor = vec4(color.rgb, 1.0);\n" | ||
"}"; | ||
|
||
bool CCBlurLayer::init() | ||
{ | ||
if (!CCLayerColor::init()) | ||
return false; | ||
|
||
layers.push_back(this); | ||
|
||
render = CCRenderTexture::create(getContentWidth(), getContentHeight()); | ||
render->retain(); | ||
|
||
program = new CCGLProgram(); | ||
program->initWithVertexShaderByteArray(vertShaderSource, fragShaderSource); | ||
|
||
program->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position); | ||
program->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords); | ||
|
||
program->link(); | ||
program->updateUniforms(); | ||
program->retain(); | ||
|
||
render->getSprite()->setShaderProgram(program); | ||
|
||
this->addChild(render, 69); | ||
return true; | ||
} | ||
|
||
CCBlurLayer* CCBlurLayer::create() | ||
{ | ||
auto pRet = new CCBlurLayer(); | ||
|
||
if (pRet && pRet->init()) | ||
{ | ||
pRet->autorelease(); | ||
return pRet; | ||
} | ||
|
||
CC_SAFE_DELETE(pRet); | ||
return nullptr; | ||
} | ||
|
||
CCBlurLayer::~CCBlurLayer() | ||
{ | ||
log::info("removing this: {}", this); | ||
|
||
program->release(); | ||
render->release(); | ||
|
||
layers.erase(std::remove(layers.begin(), layers.end(), this), layers.end()); | ||
} | ||
|
||
void CCBlurLayer::visit() | ||
{ | ||
if (this != layers[layers.size() - 1]) | ||
return; | ||
|
||
if (auto scene = CCScene::get()) | ||
{ | ||
if (auto parent = this->getParent()) | ||
{ | ||
parent->setVisible(false); | ||
|
||
render->beginWithClear(0, 0, 0, 0); | ||
scene->visit(); | ||
render->end(); | ||
|
||
parent->setVisible(true); | ||
|
||
render->setPosition(CCDirector::get()->getWinSize() / 2); | ||
|
||
return CCNode::visit(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include <numbers> | ||
#include <Geode/Geode.hpp> | ||
#include <Geode/modify/CCEGLView.hpp> | ||
#include <Geode/modify/CCDirector.hpp> | ||
#include "../Client/Client.h" | ||
|
||
using namespace geode::prelude; | ||
|
||
class CCBlurLayer : public CCLayerColor | ||
{ | ||
public: | ||
CCGLProgram* program; | ||
CCRenderTexture* render; | ||
CCSprite* sprite; | ||
float blurStrength = 1; | ||
|
||
~CCBlurLayer(); | ||
bool init(); | ||
void visit(); | ||
|
||
static CCBlurLayer* create(); | ||
}; |