Skip to content

Commit

Permalink
scalar buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
patriciogonzalezvivo committed Mar 10, 2023
1 parent 39d9af7 commit e924077
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 24 deletions.
3 changes: 3 additions & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ test_video_prevs:
test_buffers:
glslViewer test_buffers.frag -l

test_buffers_scale:
glslViewer test_buffers_scale.frag image.png -l

test_doubleBuffer:
glslViewer test_doubleBuffer.frag -l

Expand Down
30 changes: 30 additions & 0 deletions examples/test_buffers_scale.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifdef GL_ES
precision mediump float;
#endif

uniform sampler2D u_tex0;
uniform vec2 u_tex0Resolution;

uniform sampler2D u_buffer0; // 0.125

uniform vec2 u_mouse;
uniform vec2 u_resolution;
uniform float u_time;

varying vec2 v_texcoord;

void main (void) {
vec4 color = vec4(0.0, 0.0, 0.0, 1.0);
vec2 st = gl_FragCoord.xy/u_resolution.xy;
vec2 uv = v_texcoord;

#if defined(BUFFER_0)
color = texture2D(u_tex0, uv);

#else
color = texture2D(u_buffer0, st);

#endif

gl_FragColor = color;
}
1 change: 0 additions & 1 deletion src/core/sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,6 @@ void Sandbox::resetShaders( WatchFileList &_files ) {
void Sandbox::_updateBuffers() {

if ( m_buffers_total != int(uniforms.buffers.size())) {

if (verbose)
std::cout << "Creating/removing " << uniforms.buffers.size() << " buffers to match " << m_buffers_total << std::endl;

Expand Down
46 changes: 23 additions & 23 deletions src/core/tools/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,28 +127,6 @@ int generic_search_count(const std::string& _source, regex_count_t keyword_id )
});
}

enum class regex_get_t {
BufferSize,
MAX_KEYWORDS_GET_IDS
};

using regex_get_string_t = regex_string_t<regex_get_t>;
const auto valid_get_keyword_ids = std::array<regex_get_string_t, +(regex_get_t::MAX_KEYWORDS_GET_IDS)> {{
{regex_get_t::BufferSize, R"(uniform\s*sampler2D\s*(\w*)\;\s*\/\/*\s(\d+)x(\d+))"}
}};

bool generic_search_get(const std::string& _source, const std::string& _name, glm::vec2& _size, regex_get_t keyword_id ) {
bool result;
std::smatch match;
const auto re = std::regex{std::get<1>(valid_get_keyword_ids[+(keyword_id)])};
std::tie(result, match) = does_any_of_the_regex_exist(_source, re); // capture both the "result" and the "match" info.
if(result) {
if (match[1] == _name) { // regex-match result data is valid to spec.
_size = {vera::toFloat(match[2]), vera::toFloat(match[3])};
}
}
return result;
}
} // Namespace {}

// Quickly determine if a shader program contains the specified identifier.
Expand All @@ -162,7 +140,29 @@ int countBuffers(const std::string& _source) {
}

bool getBufferSize(const std::string& _source, const std::string& _name, glm::vec2& _size) {
return generic_search_get(_source, _name, _size, regex_get_t::BufferSize);
std::regex re1(R"(uniform\s*sampler2D\s*(\w*)\;\s*\/\/*\s(\d+)x(\d+))");
std::regex re2(R"(uniform\s*sampler2D\s*(\w*)\;\s*\/\/*\s(\d*\.\d+|\d+))");
std::smatch match;

// Split Source code in lines
std::vector<std::string> lines = vera::split(_source, '\n');
for (unsigned int l = 0; l < lines.size(); l++) {
if (std::regex_search(lines[l], match, re1)) {
if (match[1] == _name) {
_size.x = vera::toFloat(match[2]);
_size.y = vera::toFloat(match[3]);
return true;
}
}
else if (std::regex_search(lines[l], match, re2)) {
if (match[1] == _name) {
_size *= vera::toFloat(match[2]);
return true;
}
}
}

return false;
}

// Count how many BUFFERS are in the shader
Expand Down

0 comments on commit e924077

Please sign in to comment.