View difference between Paste ID: gan4QagS and MF2SPWNE
SHOW: | | - or go back to the newest paste.
1
void initReduction()
2
{
3
	reductionEffect->Bind();
4
	reductionEffect->Uniform("Mode", 0);
5
	sourceTexture->Bind(GL_TEXTURE0);
6
	GetWriteBuffer().BindWrite();
7
	drawQuad(0, 0, sourceTexture->Width(), sourceTexture->Height());
8
	SwapBuffers();
9
}
10
11
void Apply()
12
{
13
	using namespace std;
14
	glPushAttrib(GL_ENABLE_BIT);
15
	glDisable(GL_STENCIL_TEST);
16
	glDisable(GL_DEPTH_TEST);
17
	glDisable(GL_BLEND);
18
	glDisable(GL_CULL_FACE);
19
	initReduction();
20
	reductionEffect->Bind();
21
	reductionEffect->Uniform("KernelSize", kernelSize);
22
	reductionEffect->Uniform("Mode", 1);
23
	unsigned cWidth, cHeight;
24
25
	cWidth = sourceTexture->Width() / kernelSize;
26
	cHeight = sourceTexture->Height() / kernelSize;
27
28
	int iter = 2;
29
	while(cWidth > 1 || cHeight > 1)
30
	{
31
		GetReadBuffer().BindRead(GL_TEXTURE0);
32
		GetWriteBuffer().BindWrite();
33
34
		reductionEffect->Uniform("Iteration", iter);
35
		reductionEffect->Uniform("CWidth", cWidth);
36
		reductionEffect->Uniform("CHeight", cHeight);
37
		reductionEffect->Uniform("TexelSize", fvec2( 1.0f / cWidth, 1.0f / cHeight));
38
		drawQuad(0, 0, cWidth, cHeight);
39
			
40
		cWidth = max<unsigned>(cWidth / kernelSize, 1);
41
		cHeight = max<unsigned>(cHeight / kernelSize, 1);
42
43
		iter *= iter;
44
		SwapBuffers();
45
	}
46
47
	glPopAttrib();
48
}