Revision 53d59408
Added by Leszek Koltunski over 7 years ago
| src/main/AndroidManifest.xml | ||
|---|---|---|
| 50 | 50 |
<activity android:name=".stencil.StencilActivity"/> |
| 51 | 51 |
<activity android:name=".glow.GlowActivity"/> |
| 52 | 52 |
<activity android:name=".movingglow.MovingGlowActivity"/> |
| 53 |
<activity android:name=".mali.MaliActivity"/> |
|
| 54 | 53 |
</application> |
| 55 | 54 |
</manifest> |
| src/main/java/org/distorted/examples/TableOfContents.java | ||
|---|---|---|
| 69 | 69 |
import org.distorted.examples.stencil.StencilActivity; |
| 70 | 70 |
import org.distorted.examples.glow.GlowActivity; |
| 71 | 71 |
import org.distorted.examples.movingglow.MovingGlowActivity; |
| 72 |
import org.distorted.examples.mali.MaliActivity; |
|
| 73 | 72 |
|
| 74 | 73 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 75 | 74 |
|
| ... | ... | |
| 407 | 406 |
activityMapping.put(i++, MovingGlowActivity.class); |
| 408 | 407 |
} |
| 409 | 408 |
|
| 410 |
{
|
|
| 411 |
final Map<String, Object> item = new HashMap<>(); |
|
| 412 |
item.put(ITEM_IMAGE, R.drawable.icon_example_wip); |
|
| 413 |
item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_mali)); |
|
| 414 |
item.put(ITEM_SUBTITLE, getText(R.string.example_mali_subtitle)); |
|
| 415 |
data.add(item); |
|
| 416 |
activityMapping.put(i++, MaliActivity.class); |
|
| 417 |
} |
|
| 418 |
|
|
| 419 | 409 |
final SimpleAdapter dataAdapter = new SimpleAdapter(this, data, R.layout.toc_item, new String[] {ITEM_IMAGE, ITEM_TITLE, ITEM_SUBTITLE}, new int[] {R.id.Image, R.id.Title, R.id.SubTitle});
|
| 420 | 410 |
setListAdapter(dataAdapter); |
| 421 | 411 |
|
| src/main/java/org/distorted/examples/mali/MaliActivity.java | ||
|---|---|---|
| 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.examples.mali; |
|
| 21 |
|
|
| 22 |
import android.app.Activity; |
|
| 23 |
import android.os.Bundle; |
|
| 24 |
|
|
| 25 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 26 |
|
|
| 27 |
public class MaliActivity extends Activity |
|
| 28 |
{
|
|
| 29 |
private MaliSurfaceView mView; |
|
| 30 |
|
|
| 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 32 |
|
|
| 33 |
@Override |
|
| 34 |
protected void onCreate(Bundle savedState) |
|
| 35 |
{
|
|
| 36 |
super.onCreate(savedState); |
|
| 37 |
mView = new MaliSurfaceView(this); |
|
| 38 |
setContentView(mView); |
|
| 39 |
} |
|
| 40 |
|
|
| 41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 42 |
|
|
| 43 |
@Override |
|
| 44 |
protected void onPause() |
|
| 45 |
{
|
|
| 46 |
mView.onPause(); |
|
| 47 |
super.onPause(); |
|
| 48 |
} |
|
| 49 |
|
|
| 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 51 |
|
|
| 52 |
@Override |
|
| 53 |
protected void onResume() |
|
| 54 |
{
|
|
| 55 |
super.onResume(); |
|
| 56 |
mView.onResume(); |
|
| 57 |
} |
|
| 58 |
} |
|
| src/main/java/org/distorted/examples/mali/MaliRenderer.java | ||
|---|---|---|
| 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.examples.mali; |
|
| 21 |
|
|
| 22 |
import android.opengl.GLES31; |
|
| 23 |
import android.opengl.GLSurfaceView; |
|
| 24 |
|
|
| 25 |
import java.nio.ByteBuffer; |
|
| 26 |
import java.nio.ByteOrder; |
|
| 27 |
import java.nio.FloatBuffer; |
|
| 28 |
|
|
| 29 |
import javax.microedition.khronos.egl.EGLConfig; |
|
| 30 |
import javax.microedition.khronos.opengles.GL10; |
|
| 31 |
|
|
| 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 33 |
|
|
| 34 |
class MaliRenderer implements GLSurfaceView.Renderer |
|
| 35 |
{
|
|
| 36 |
private int mWidth, mHeight; |
|
| 37 |
|
|
| 38 |
private static int[] mSSBO = new int[1]; |
|
| 39 |
private static int mProgramHandle,mSizeH,mPosH; |
|
| 40 |
private static final FloatBuffer mQuadPositions; |
|
| 41 |
|
|
| 42 |
static |
|
| 43 |
{
|
|
| 44 |
mSSBO[0] = -1; |
|
| 45 |
|
|
| 46 |
float[] positionData= { -0.5f, -0.5f, -0.5f, 0.5f, 0.5f,-0.5f, 0.5f, 0.5f };
|
|
| 47 |
mQuadPositions = ByteBuffer.allocateDirect(32).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
| 48 |
mQuadPositions.put(positionData).position(0); |
|
| 49 |
} |
|
| 50 |
|
|
| 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 52 |
|
|
| 53 |
MaliRenderer(GLSurfaceView v) |
|
| 54 |
{
|
|
| 55 |
|
|
| 56 |
} |
|
| 57 |
|
|
| 58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 59 |
|
|
| 60 |
public void onDrawFrame(GL10 glUnused) |
|
| 61 |
{
|
|
| 62 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0); |
|
| 63 |
GLES31.glUseProgram(mProgramHandle); |
|
| 64 |
GLES31.glEnableVertexAttribArray(mPosH); |
|
| 65 |
GLES31.glViewport(0, 0, mWidth, mHeight ); |
|
| 66 |
GLES31.glUniform2ui(mSizeH, mWidth, mHeight); |
|
| 67 |
GLES31.glVertexAttribPointer(mPosH, 2, GLES31.GL_FLOAT, false, 0, mQuadPositions); |
|
| 68 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4); |
|
| 69 |
} |
|
| 70 |
|
|
| 71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 72 |
|
|
| 73 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
| 74 |
{
|
|
| 75 |
final String vertSource = |
|
| 76 |
|
|
| 77 |
"#version 310 es \n" + |
|
| 78 |
"precision highp float; \n" + |
|
| 79 |
"precision highp int; \n" + |
|
| 80 |
"in vec2 a_Position; \n" + |
|
| 81 |
"out vec2 v_Pixel; \n" + |
|
| 82 |
"uniform uvec2 u_Size; \n" + |
|
| 83 |
|
|
| 84 |
"void main() \n" + |
|
| 85 |
"{ \n" +
|
|
| 86 |
"v_Pixel = (a_Position + 0.5) * vec2(u_Size); \n" + |
|
| 87 |
"gl_Position = vec4(2.0*a_Position,1.0,1.0); \n" + |
|
| 88 |
"} "; |
|
| 89 |
|
|
| 90 |
final String fragSource = |
|
| 91 |
|
|
| 92 |
"#version 310 es \n" + |
|
| 93 |
"precision highp float; \n" + |
|
| 94 |
"precision highp int; \n" + |
|
| 95 |
"out vec4 fragColor; \n" + |
|
| 96 |
"in vec2 v_Pixel; \n" + |
|
| 97 |
"uniform uvec2 u_Size; \n" + |
|
| 98 |
|
|
| 99 |
"layout (std430,binding=1) buffer linkedlist \n" + |
|
| 100 |
" { \n" +
|
|
| 101 |
" uint u_Records[]; \n" + |
|
| 102 |
" }; \n" + |
|
| 103 |
|
|
| 104 |
"void main() \n" + |
|
| 105 |
" { \n" +
|
|
| 106 |
" uint index= uint(v_Pixel.x) + uint(v_Pixel.y) * u_Size.x; \n" + |
|
| 107 |
" uint sum = 0u; \n" + |
|
| 108 |
|
|
| 109 |
" for(uint i=index+1u; i>=index; i--) sum += u_Records[i]; \n" + |
|
| 110 |
" //sum += u_Records[index+1u]; \n" + |
|
| 111 |
" //sum += u_Records[index]; \n" + |
|
| 112 |
" u_Records[index] = sum; \n" + |
|
| 113 |
|
|
| 114 |
" fragColor = vec4(0.0,1.0,0.0,1.0); \n" + |
|
| 115 |
" }"; |
|
| 116 |
|
|
| 117 |
int vertHandle = GLES31.glCreateShader(GLES31.GL_VERTEX_SHADER); |
|
| 118 |
GLES31.glShaderSource(vertHandle, vertSource); |
|
| 119 |
GLES31.glCompileShader(vertHandle); |
|
| 120 |
|
|
| 121 |
final int[] compileStatus = new int[1]; |
|
| 122 |
GLES31.glGetShaderiv(vertHandle, GLES31.GL_COMPILE_STATUS, compileStatus, 0); |
|
| 123 |
|
|
| 124 |
if (compileStatus[0] != GLES31.GL_TRUE) |
|
| 125 |
{
|
|
| 126 |
String error = GLES31.glGetShaderInfoLog(vertHandle); |
|
| 127 |
android.util.Log.e("Program", "error compiling vert :" + error);
|
|
| 128 |
GLES31.glDeleteShader(vertHandle); |
|
| 129 |
} |
|
| 130 |
|
|
| 131 |
int fragHandle = GLES31.glCreateShader(GLES31.GL_FRAGMENT_SHADER); |
|
| 132 |
GLES31.glShaderSource(fragHandle, fragSource); |
|
| 133 |
GLES31.glCompileShader(fragHandle); |
|
| 134 |
|
|
| 135 |
GLES31.glGetShaderiv(fragHandle, GLES31.GL_COMPILE_STATUS, compileStatus, 0); |
|
| 136 |
|
|
| 137 |
if (compileStatus[0] != GLES31.GL_TRUE) |
|
| 138 |
{
|
|
| 139 |
String error = GLES31.glGetShaderInfoLog(fragHandle); |
|
| 140 |
android.util.Log.e("Program", "error compiling frag :" + error);
|
|
| 141 |
GLES31.glDeleteShader(fragHandle); |
|
| 142 |
} |
|
| 143 |
|
|
| 144 |
mProgramHandle = GLES31.glCreateProgram(); |
|
| 145 |
|
|
| 146 |
if (mProgramHandle != 0) |
|
| 147 |
{
|
|
| 148 |
GLES31.glAttachShader(mProgramHandle, vertHandle); |
|
| 149 |
GLES31.glAttachShader(mProgramHandle, fragHandle); |
|
| 150 |
|
|
| 151 |
GLES31.glBindAttribLocation(mProgramHandle, 0, "a_Position"); |
|
| 152 |
|
|
| 153 |
GLES31.glLinkProgram(mProgramHandle); |
|
| 154 |
|
|
| 155 |
final int[] linkStatus = new int[1]; |
|
| 156 |
GLES31.glGetProgramiv(mProgramHandle, GLES31.GL_LINK_STATUS, linkStatus, 0); |
|
| 157 |
|
|
| 158 |
if (linkStatus[0] != GLES31.GL_TRUE) |
|
| 159 |
{
|
|
| 160 |
String error = GLES31.glGetProgramInfoLog(mProgramHandle); |
|
| 161 |
GLES31.glDeleteProgram(mProgramHandle); |
|
| 162 |
android.util.Log.e("Program", "error linking :" + error);
|
|
| 163 |
} |
|
| 164 |
} |
|
| 165 |
|
|
| 166 |
mPosH = GLES31.glGetAttribLocation ( mProgramHandle, "a_Position"); |
|
| 167 |
mSizeH= GLES31.glGetUniformLocation( mProgramHandle, "u_Size"); |
|
| 168 |
|
|
| 169 |
if( mSSBO[0]<0 ) |
|
| 170 |
{
|
|
| 171 |
GLES31.glGenBuffers(1,mSSBO,0); |
|
| 172 |
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mSSBO[0]); |
|
| 173 |
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, (1<<23) , null, GLES31.GL_DYNAMIC_READ|GLES31.GL_DYNAMIC_DRAW); |
|
| 174 |
GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 1, mSSBO[0]); |
|
| 175 |
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0); |
|
| 176 |
} |
|
| 177 |
} |
|
| 178 |
|
|
| 179 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 180 |
|
|
| 181 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
| 182 |
{
|
|
| 183 |
mWidth = width; |
|
| 184 |
mHeight= height; |
|
| 185 |
} |
|
| 186 |
} |
|
| src/main/java/org/distorted/examples/mali/MaliSurfaceView.java | ||
|---|---|---|
| 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.examples.mali; |
|
| 21 |
|
|
| 22 |
import android.content.Context; |
|
| 23 |
import android.opengl.GLSurfaceView; |
|
| 24 |
|
|
| 25 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 26 |
|
|
| 27 |
class MaliSurfaceView extends GLSurfaceView |
|
| 28 |
{
|
|
| 29 |
|
|
| 30 |
public MaliSurfaceView(Context context) |
|
| 31 |
{
|
|
| 32 |
super(context); |
|
| 33 |
setEGLContextClientVersion(3); |
|
| 34 |
setRenderer(new MaliRenderer(this)); |
|
| 35 |
} |
|
| 36 |
} |
|
| 37 |
|
|
Also available in: Unified diff
Remove the Mali app (it was a silly mistake!)