Initial commit
This commit is contained in:
96
application/source/engine/renderPasses/renderPassCompute.c
Normal file
96
application/source/engine/renderPasses/renderPassCompute.c
Normal file
@@ -0,0 +1,96 @@
|
||||
|
||||
|
||||
#include "./renderPass.h"
|
||||
|
||||
#include "../event.h"
|
||||
|
||||
#include "../vector2.h"
|
||||
|
||||
#include "../shader.h"
|
||||
|
||||
#include "../program.h"
|
||||
|
||||
#include "../int.h"
|
||||
|
||||
#include "../sampler2D.h"
|
||||
|
||||
#include "stdbool.h"
|
||||
|
||||
#include "../block.h"
|
||||
|
||||
#include "../vector.h"
|
||||
|
||||
#include "../mesh.h"
|
||||
|
||||
|
||||
class compute extends renderPass{
|
||||
|
||||
|
||||
struct program * program;
|
||||
|
||||
int active = true;
|
||||
|
||||
prepare() {
|
||||
|
||||
printf("\n\n\n Prepare renderPass Compute\n\n\n\n\n");
|
||||
|
||||
shader * computeShader = new shader( GL_COMPUTE_SHADER );
|
||||
|
||||
computeShader->loadFromFile( "assets/shaders/addition.comp" );
|
||||
|
||||
|
||||
this->program = new program();
|
||||
|
||||
this->program->addShader( computeShader );
|
||||
|
||||
this->program->create();
|
||||
|
||||
|
||||
vector<vector2> * inputA = new vector();
|
||||
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
|
||||
vector2 a = new vector2( i, i );
|
||||
|
||||
inputA->add( a );
|
||||
|
||||
}
|
||||
|
||||
vector<vector2> * inputB = new vector();
|
||||
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
|
||||
vector2 a = new vector2( 0, 10 );
|
||||
|
||||
inputB->add( a );
|
||||
|
||||
}
|
||||
|
||||
block * inputBlock = this->program->getBlock( "inputBlock" );
|
||||
|
||||
inputBlock->setMemberArray( "array_a[0]", ( float * ) inputA->items );
|
||||
|
||||
inputBlock->setMemberArray( "array_b[0]", ( float * ) inputB->items );
|
||||
|
||||
inputBlock->upload();
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
this->program->use();
|
||||
|
||||
this->program->bindBlock( "inputBlock");
|
||||
|
||||
this->program->bindBlock( "outputBlock");
|
||||
|
||||
|
||||
glDispatchCompute( 1, 1, 1 );
|
||||
|
||||
glMemoryBarrier( GL_SHADER_STORAGE_BARRIER_BIT );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user