Project

General

Profile

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

library / src / main / java / org / distorted / library / main / InternalSurface.java @ 4bb94a7d

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 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.main;
21

    
22
import android.opengl.GLES31;
23

    
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25

    
26
abstract class InternalSurface extends InternalObject
27
{
28
  int mColorCreated;
29
  int mNumColors;
30
  int mNumFBOs;
31
  int[] mColorH;
32
  int mWidth, mHeight;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
  InternalSurface(int width, int height, int create, int numfbos, int numcolors, int type)
37
    {
38
    super(type);
39

    
40
    mNumFBOs      = numfbos;
41
    mNumColors    = numcolors;
42
    mWidth        = width ;
43
    mHeight       = height;
44
    mColorCreated = create;
45

    
46
    int total = mNumFBOs*mNumColors;
47

    
48
    if( total>0 )
49
      {
50
      mColorH = new int[total];
51
      for( int i=0; i<total; i++ )  mColorH[i] = 0;
52
      }
53
    }
54

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56
// debugging only
57

    
58
  String printDetails()
59
    {
60
    return getClass().getSimpleName()+" "+mWidth+"x"+mHeight;
61
    }
62

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64
// PUBLIC API
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66
/**
67
 * Return the width of this Surface.
68
 *
69
 * @return width of the Object, in pixels.
70
 */
71
  public int getWidth()
72
    {
73
    return mWidth;
74
    }
75

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77
/**
78
 * Return the height of this Surface.
79
 *
80
 * @return height of the Object, in pixels.
81
 */
82
  public int getHeight()
83
    {
84
    return mHeight;
85
    }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88
/**
89
 * Bind the underlying rectangle of pixels as a OpenGL Texture.
90
 *
91
 * @return <code>true</code> if successful.
92
 */
93
  public boolean setAsInput()
94
    {
95
    if( mColorH[0]>0 )
96
      {
97
      GLES31.glActiveTexture(GLES31.GL_TEXTURE0);
98
      GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mColorH[0]);
99
      return true;
100
      }
101

    
102
    return false;
103
    }
104
}
(14-14/14)