Project

General

Profile

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

library / src / main / java / org / distorted / library / main / DistortedSurface.java @ 466450b5

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
 * This is not really part of the public API.
27
 *
28
 * @y.exclude
29
 */
30
public abstract class DistortedSurface extends DistortedObject
31
{
32
  int mColorCreated;
33
  int mNumColors;
34
  int mNumFBOs;
35
  int[] mColorH;
36
  int mWidth, mHeight;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
  DistortedSurface(int width, int height, int create, int numfbos, int numcolors, int type)
41
    {
42
    super(create,type);
43

    
44
    mNumFBOs      = numfbos;
45
    mNumColors    = numcolors;
46
    mWidth        = width ;
47
    mHeight       = height;
48
    mColorCreated = create;
49

    
50
    int total = mNumFBOs*mNumColors;
51

    
52
    if( total>0 )
53
      {
54
      mColorH = new int[total];
55
      for( int i=0; i<total; i++ )  mColorH[i] = 0;
56
      }
57
    }
58

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
// debugging only
61

    
62
  String printDetails()
63
    {
64
    return getClass().getSimpleName()+" "+mWidth+"x"+mHeight;
65
    }
66

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

    
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81
/**
82
 * Return the height of this Surface.
83
 *
84
 * @return height of the Object, in pixels.
85
 */
86
  public int getHeight()
87
    {
88
    return mHeight;
89
    }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92
/**
93
 * Return the depth of this Surface.
94
 * <p>
95
 * Admittedly quite a strange method. Why do we need to pass a Mesh to it? Because one cannot determine
96
 * 'depth' of a Surface (bitmap really!) when rendered based only on the texture itself, that depends
97
 * on the Mesh it is rendered with.
98
 *
99
 * @return depth of the Object, in pixels.
100
 */
101
  public int getDepth(MeshObject mesh)
102
    {
103
    return mesh==null ? 0 : (int)(mWidth*mesh.zFactor);
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107
/**
108
 * Bind the underlying rectangle of pixels as a OpenGL Texture.
109
 *
110
 * @return <code>true</code> if successful.
111
 */
112
  public boolean setAsInput()
113
    {
114
    if( mColorH[0]>0 )
115
      {
116
      GLES31.glActiveTexture(GLES31.GL_TEXTURE0);
117
      GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mColorH[0]);
118
      return true;
119
      }
120

    
121
    return false;
122
    }
123
}
(11-11/21)