1 |
c5369f1b
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
fe82a979
|
Leszek Koltunski
|
package org.distorted.library.main;
|
21 |
c5369f1b
|
leszek
|
|
22 |
12f9e4bb
|
Leszek Koltunski
|
import android.opengl.GLES31;
|
23 |
af4cc5db
|
Leszek Koltunski
|
|
24 |
715e7726
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshBase;
|
25 |
6c00149d
|
Leszek Koltunski
|
|
26 |
12f9e4bb
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
27 |
|
|
/**
|
28 |
|
|
* This is not really part of the public API.
|
29 |
|
|
*
|
30 |
|
|
* @y.exclude
|
31 |
|
|
*/
|
32 |
|
|
public abstract class DistortedSurface extends DistortedObject
|
33 |
226144d0
|
leszek
|
{
|
34 |
c7da4e65
|
leszek
|
int mColorCreated;
|
35 |
9ed80185
|
Leszek Koltunski
|
int mNumColors;
|
36 |
9d845904
|
Leszek Koltunski
|
int mNumFBOs;
|
37 |
9ed80185
|
Leszek Koltunski
|
int[] mColorH;
|
38 |
6e7c8721
|
Leszek Koltunski
|
int mWidth, mHeight;
|
39 |
af4cc5db
|
Leszek Koltunski
|
|
40 |
af27df87
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
41 |
|
|
|
42 |
9d845904
|
Leszek Koltunski
|
DistortedSurface(int width, int height, int create, int numfbos, int numcolors, int type)
|
43 |
af4cc5db
|
Leszek Koltunski
|
{
|
44 |
ccd98f1c
|
Leszek Koltunski
|
super(type);
|
45 |
|
|
|
46 |
|
|
if( create!=DONT_CREATE ) markForCreation();
|
47 |
226144d0
|
leszek
|
|
48 |
9d845904
|
Leszek Koltunski
|
mNumFBOs = numfbos;
|
49 |
9ed80185
|
Leszek Koltunski
|
mNumColors = numcolors;
|
50 |
6e7c8721
|
Leszek Koltunski
|
mWidth = width ;
|
51 |
|
|
mHeight = height;
|
52 |
c7da4e65
|
leszek
|
mColorCreated = create;
|
53 |
9ed80185
|
Leszek Koltunski
|
|
54 |
9d845904
|
Leszek Koltunski
|
int total = mNumFBOs*mNumColors;
|
55 |
|
|
|
56 |
|
|
if( total>0 )
|
57 |
9ed80185
|
Leszek Koltunski
|
{
|
58 |
9d845904
|
Leszek Koltunski
|
mColorH = new int[total];
|
59 |
|
|
for( int i=0; i<total; i++ ) mColorH[i] = 0;
|
60 |
9ed80185
|
Leszek Koltunski
|
}
|
61 |
af4cc5db
|
Leszek Koltunski
|
}
|
62 |
|
|
|
63 |
f28fffc2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
64 |
226144d0
|
leszek
|
// debugging only
|
65 |
f28fffc2
|
Leszek Koltunski
|
|
66 |
226144d0
|
leszek
|
String printDetails()
|
67 |
f28fffc2
|
Leszek Koltunski
|
{
|
68 |
226144d0
|
leszek
|
return getClass().getSimpleName()+" "+mWidth+"x"+mHeight;
|
69 |
f28fffc2
|
Leszek Koltunski
|
}
|
70 |
|
|
|
71 |
af4cc5db
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
72 |
|
|
// PUBLIC API
|
73 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
74 |
c5369f1b
|
leszek
|
/**
|
75 |
3a70bd6d
|
leszek
|
* Return the width of this Surface.
|
76 |
af4cc5db
|
Leszek Koltunski
|
*
|
77 |
3a70bd6d
|
leszek
|
* @return width of the Object, in pixels.
|
78 |
c5369f1b
|
leszek
|
*/
|
79 |
af4cc5db
|
Leszek Koltunski
|
public int getWidth()
|
80 |
|
|
{
|
81 |
6e7c8721
|
Leszek Koltunski
|
return mWidth;
|
82 |
af4cc5db
|
Leszek Koltunski
|
}
|
83 |
|
|
|
84 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85 |
c5369f1b
|
leszek
|
/**
|
86 |
3a70bd6d
|
leszek
|
* Return the height of this Surface.
|
87 |
af4cc5db
|
Leszek Koltunski
|
*
|
88 |
3a70bd6d
|
leszek
|
* @return height of the Object, in pixels.
|
89 |
c5369f1b
|
leszek
|
*/
|
90 |
af4cc5db
|
Leszek Koltunski
|
public int getHeight()
|
91 |
|
|
{
|
92 |
6e7c8721
|
Leszek Koltunski
|
return mHeight;
|
93 |
af4cc5db
|
Leszek Koltunski
|
}
|
94 |
|
|
|
95 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
96 |
c5369f1b
|
leszek
|
/**
|
97 |
8d52a49c
|
Leszek Koltunski
|
* Return the depth of this Surface.
|
98 |
af4cc5db
|
Leszek Koltunski
|
* <p>
|
99 |
|
|
* Admittedly quite a strange method. Why do we need to pass a Mesh to it? Because one cannot determine
|
100 |
|
|
* 'depth' of a Surface (bitmap really!) when rendered based only on the texture itself, that depends
|
101 |
|
|
* on the Mesh it is rendered with.
|
102 |
|
|
*
|
103 |
|
|
* @return depth of the Object, in pixels.
|
104 |
c5369f1b
|
leszek
|
*/
|
105 |
715e7726
|
Leszek Koltunski
|
public int getDepth(MeshBase mesh)
|
106 |
af4cc5db
|
Leszek Koltunski
|
{
|
107 |
6c00149d
|
Leszek Koltunski
|
return mesh==null ? 0 : (int)(mWidth*mesh.getZFactor() );
|
108 |
af4cc5db
|
Leszek Koltunski
|
}
|
109 |
12f9e4bb
|
Leszek Koltunski
|
|
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 |
226144d0
|
leszek
|
}
|