Project

General

Profile

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

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

1 c5369f1b leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4 46b572b5 Leszek Koltunski
// This file is part of Distorted.                                                               //
5 c5369f1b leszek
//                                                                                               //
6 46b572b5 Leszek Koltunski
// Distorted is free software: you can redistribute it and/or modify                             //
7 c5369f1b leszek
// 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 46b572b5 Leszek Koltunski
// Distorted is distributed in the hope that it will be useful,                                  //
12 c5369f1b leszek
// 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 46b572b5 Leszek Koltunski
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18 c5369f1b leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
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 12f9e4bb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
25 4bb94a7d Leszek Koltunski
26
abstract class InternalSurface extends InternalObject
27 226144d0 leszek
{
28 c7da4e65 leszek
  int mColorCreated;
29 9ed80185 Leszek Koltunski
  int mNumColors;
30 9d845904 Leszek Koltunski
  int mNumFBOs;
31 9ed80185 Leszek Koltunski
  int[] mColorH;
32 6e7c8721 Leszek Koltunski
  int mWidth, mHeight;
33 af4cc5db Leszek Koltunski
34 af27df87 leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
35
36 7602a827 Leszek Koltunski
  InternalSurface(int width, int height, int create, int numfbos, int numcolors, int type)
37 af4cc5db Leszek Koltunski
    {
38 ccd98f1c Leszek Koltunski
    super(type);
39
40 9d845904 Leszek Koltunski
    mNumFBOs      = numfbos;
41 9ed80185 Leszek Koltunski
    mNumColors    = numcolors;
42 6e7c8721 Leszek Koltunski
    mWidth        = width ;
43
    mHeight       = height;
44 c7da4e65 leszek
    mColorCreated = create;
45 9ed80185 Leszek Koltunski
46 9d845904 Leszek Koltunski
    int total = mNumFBOs*mNumColors;
47
48
    if( total>0 )
49 9ed80185 Leszek Koltunski
      {
50 9d845904 Leszek Koltunski
      mColorH = new int[total];
51
      for( int i=0; i<total; i++ )  mColorH[i] = 0;
52 9ed80185 Leszek Koltunski
      }
53 af4cc5db Leszek Koltunski
    }
54
55 f28fffc2 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
56 226144d0 leszek
// debugging only
57 f28fffc2 Leszek Koltunski
58 226144d0 leszek
  String printDetails()
59 f28fffc2 Leszek Koltunski
    {
60 226144d0 leszek
    return getClass().getSimpleName()+" "+mWidth+"x"+mHeight;
61 f28fffc2 Leszek Koltunski
    }
62
63 af4cc5db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
64
// PUBLIC API
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66 c5369f1b leszek
/**
67 3a70bd6d leszek
 * Return the width of this Surface.
68 af4cc5db Leszek Koltunski
 *
69 3a70bd6d leszek
 * @return width of the Object, in pixels.
70 c5369f1b leszek
 */
71 af4cc5db Leszek Koltunski
  public int getWidth()
72
    {
73 6e7c8721 Leszek Koltunski
    return mWidth;
74 af4cc5db Leszek Koltunski
    }
75
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77 c5369f1b leszek
/**
78 3a70bd6d leszek
 * Return the height of this Surface.
79 af4cc5db Leszek Koltunski
 *
80 3a70bd6d leszek
 * @return height of the Object, in pixels.
81 c5369f1b leszek
 */
82 af4cc5db Leszek Koltunski
  public int getHeight()
83
    {
84 6e7c8721 Leszek Koltunski
    return mHeight;
85 af4cc5db Leszek Koltunski
    }
86
87 12f9e4bb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 226144d0 leszek
}