Project

General

Profile

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

library / src / main / java / org / distorted / library / main / InternalSurface.java @ c90aca24

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
import org.distorted.library.mesh.MeshBase;
25

    
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27
/**
28
 * This is not really part of the public API.
29
 *
30
 * @y.exclude
31
 */
32
public abstract class InternalSurface extends InternalObject
33
{
34
  int mColorCreated;
35
  int mNumColors;
36
  int mNumFBOs;
37
  int[] mColorH;
38
  int mWidth, mHeight;
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

    
42
  InternalSurface(int width, int height, int create, int numfbos, int numcolors, int type)
43
    {
44
    super(type);
45

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

    
52
    int total = mNumFBOs*mNumColors;
53

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

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62
// debugging only
63

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

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

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

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94
/**
95
 * Return the depth of this Surface.
96
 * <p>
97
 * Admittedly quite a strange method. Why do we need to pass a Mesh to it? Because one cannot determine
98
 * 'depth' of a Surface (bitmap really!) when rendered based only on the texture itself, that depends
99
 * on the Mesh it is rendered with.
100
 *
101
 * @return depth of the Object, in pixels.
102
 */
103

    
104
/*
105
  public int getDepth(MeshBase mesh)
106
    {
107
    return mesh==null ? 0 : (int)(mWidth*mesh.getZFactor() );
108
    }
109
*/
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111
/**
112
 * Bind the underlying rectangle of pixels as a OpenGL Texture.
113
 *
114
 * @return <code>true</code> if successful.
115
 */
116
  public boolean setAsInput()
117
    {
118
    if( mColorH[0]>0 )
119
      {
120
      GLES31.glActiveTexture(GLES31.GL_TEXTURE0);
121
      GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mColorH[0]);
122
      return true;
123
      }
124

    
125
    return false;
126
    }
127
}
(14-14/14)