Project

General

Profile

Download (3.69 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / effect / PostprocessEffect.java @ 1dfc9074

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2017 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.library.effect;
21

    
22
import org.distorted.library.main.DistortedFramebuffer;
23

    
24
import java.nio.ByteBuffer;
25
import java.nio.ByteOrder;
26
import java.nio.FloatBuffer;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29
// POSTPROCESSING EFFECTS.
30

    
31
public abstract class PostprocessEffect extends Effect
32
  {
33
  public static final int NUM_UNIFORMS = 5; // 5 per-effect interpolated values.
34

    
35
  static final int POS_DATA_SIZE= 2; // Blur Program: size of the position data in elements
36
  static final int TEX_DATA_SIZE= 2; // Blur Program: size of the texture coordinate data in elements.
37

    
38
  static final FloatBuffer mQuadPositions, mQuadTexture, mQuadTextureInv;
39

    
40
  static
41
    {
42
    int dataLength      = 4;
43
    int bytes_per_float = 4;
44

    
45
    float[] position  = { -0.5f, -0.5f,  -0.5f, 0.5f,  0.5f,-0.5f,  0.5f, 0.5f };
46
    float[] textureNor= {  0.0f,  0.0f,   0.0f, 1.0f,  1.0f, 0.0f,  1.0f, 1.0f };
47
    float[] textureInv= {  0.0f,  0.0f,   1.0f, 0.0f,  0.0f, 1.0f,  1.0f, 1.0f };
48

    
49
    mQuadPositions = ByteBuffer.allocateDirect(POS_DATA_SIZE*dataLength*bytes_per_float).order(ByteOrder.nativeOrder()).asFloatBuffer();
50
    mQuadPositions.put(position).position(0);
51
    mQuadTexture= ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*bytes_per_float).order(ByteOrder.nativeOrder()).asFloatBuffer();
52
    mQuadTexture.put(textureNor).position(0);
53
    mQuadTextureInv= ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*bytes_per_float).order(ByteOrder.nativeOrder()).asFloatBuffer();
54
    mQuadTextureInv.put(textureInv).position(0);
55
    }
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

    
59
  public abstract int apply(float[] uniforms, int index, float qualityScale, DistortedFramebuffer buffer);
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

    
63
  PostprocessEffect(EffectName name)
64
    {
65
    super(name);
66
    }
67
  }
(16-16/25)