1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2016 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of DistortedLibrary. //
|
5
|
// //
|
6
|
// DistortedLibrary 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
|
// DistortedLibrary 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 DistortedLibrary. 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
|
public int getDepth(MeshBase mesh)
|
104
|
{
|
105
|
return mesh==null ? 0 : (int)(mWidth*mesh.getZFactor() );
|
106
|
}
|
107
|
|
108
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109
|
/**
|
110
|
* Bind the underlying rectangle of pixels as a OpenGL Texture.
|
111
|
*
|
112
|
* @return <code>true</code> if successful.
|
113
|
*/
|
114
|
public boolean setAsInput()
|
115
|
{
|
116
|
if( mColorH[0]>0 )
|
117
|
{
|
118
|
GLES31.glActiveTexture(GLES31.GL_TEXTURE0);
|
119
|
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mColorH[0]);
|
120
|
return true;
|
121
|
}
|
122
|
|
123
|
return false;
|
124
|
}
|
125
|
}
|