├── .travis.yml ├── Quark ├── src │ └── main │ │ ├── resources │ │ └── Data │ │ │ └── Shader │ │ │ ├── Simple2D.shader │ │ │ └── Simple3D.shader │ │ └── java │ │ └── ar │ │ └── com │ │ └── quark │ │ ├── system │ │ ├── utility │ │ │ ├── ManageableManager.java │ │ │ ├── Disposable.java │ │ │ ├── array │ │ │ │ ├── Int8Array.java │ │ │ │ ├── Int16Array.java │ │ │ │ ├── Float32Array.java │ │ │ │ ├── Int32Array.java │ │ │ │ ├── ArrayInputStream.java │ │ │ │ ├── UInt8Array.java │ │ │ │ ├── UInt32Array.java │ │ │ │ ├── UInt16Array.java │ │ │ │ └── Float16Array.java │ │ │ ├── emulation │ │ │ │ └── Emulation.java │ │ │ └── Manageable.java │ │ ├── DisplayMode.java │ │ └── DisplayLifecycle.java │ │ ├── resource │ │ ├── AssetCallback.java │ │ ├── AssetLoader.java │ │ ├── AssetListener.java │ │ ├── AssetDescriptor.java │ │ ├── locator │ │ │ ├── ClassAssetLocator.java │ │ │ └── FilesAssetLocator.java │ │ ├── AssetLocator.java │ │ └── loader │ │ │ └── ShaderBinaryAssetLoader.java │ │ ├── render │ │ ├── storage │ │ │ ├── StorageType.java │ │ │ ├── VertexFormat.java │ │ │ ├── StorageTarget.java │ │ │ ├── StorageMode.java │ │ │ ├── factory │ │ │ │ └── FactoryElementStorage.java │ │ │ └── Primitive.java │ │ ├── shader │ │ │ ├── StageType.java │ │ │ ├── Stage.java │ │ │ ├── Uniform.java │ │ │ ├── data │ │ │ │ ├── UniformInt.java │ │ │ │ ├── UniformFloat.java │ │ │ │ ├── UniformUnsignedInt.java │ │ │ │ ├── UniformInt2.java │ │ │ │ ├── UniformFloat2.java │ │ │ │ ├── UniformUnsignedInt2.java │ │ │ │ ├── UniformInt3.java │ │ │ │ ├── UniformFloat3.java │ │ │ │ ├── UniformUnsignedInt3.java │ │ │ │ ├── UniformInt4.java │ │ │ │ ├── UniformUnsignedInt4.java │ │ │ │ ├── UniformMatrix3.java │ │ │ │ ├── UniformIntArray.java │ │ │ │ ├── UniformFloatArray.java │ │ │ │ ├── UniformMatrix4.java │ │ │ │ ├── UniformUnsignedIntArray.java │ │ │ │ └── UniformFloat4.java │ │ │ ├── AttributeType.java │ │ │ └── Attribute.java │ │ ├── texture │ │ │ ├── TextureType.java │ │ │ ├── TextureBorder.java │ │ │ ├── Texture2D.java │ │ │ ├── ImageFormat.java │ │ │ ├── Texture3D.java │ │ │ └── Texture2DCube.java │ │ └── font │ │ │ └── FontRenderer.java │ │ ├── input │ │ ├── device │ │ │ ├── InputMouseButton.java │ │ │ ├── InputKeyboard.java │ │ │ ├── InputKey.java │ │ │ └── InputMouse.java │ │ └── Input.java │ │ ├── Quark.java │ │ ├── mathematic │ │ ├── ImmutableVector2i.java │ │ ├── ImmutableVector3i.java │ │ ├── ImmutableVector4i.java │ │ ├── ImmutableVector2f.java │ │ ├── ImmutableVector3f.java │ │ └── ImmutableVector4f.java │ │ └── audio │ │ ├── AudioFormat.java │ │ ├── factory │ │ ├── FactoryStaticAudio.java │ │ └── FactoryStreamingAudio.java │ │ └── Audio.java └── build.gradle ├── Quark-Extension └── Quark-Extension-NiftyUI │ ├── src │ └── main │ │ ├── resources │ │ └── Data │ │ │ └── NiftyUI │ │ │ └── Texture │ │ │ └── Empty.png │ │ └── java │ │ └── ar │ │ └── com │ │ └── quark │ │ └── extension │ │ └── niftyui │ │ ├── NiftyResourceLocation.java │ │ ├── NiftyRenderImage.java │ │ ├── NiftySoundDevice.java │ │ ├── NiftyCursor.java │ │ ├── NiftyRenderFont.java │ │ ├── NiftySoundHandle.java │ │ └── NiftyUI.java │ └── build.gradle ├── Quark-Backend ├── Quark-Backend-Web │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── ar │ │ └── com │ │ └── quark │ │ └── backend │ │ └── teavm │ │ ├── opengl │ │ ├── WebOpenGLES31.java │ │ └── WebOpenGLES32.java │ │ └── resource │ │ └── locator │ │ └── XHRAssetLocator.java └── Quark-Backend-Desktop │ ├── src │ └── main │ │ └── java │ │ └── ar │ │ └── com │ │ └── quark │ │ └── backend │ │ └── lwjgl │ │ └── opengl │ │ ├── DesktopGLES31.java │ │ └── DesktopGLES32.java │ └── build.gradle ├── .gitignore ├── settings.gradle └── README.md /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 -------------------------------------------------------------------------------- /Quark/src/main/resources/Data/Shader/Simple2D.shader: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wolftein/Quark-Engine/HEAD/Quark/src/main/resources/Data/Shader/Simple2D.shader -------------------------------------------------------------------------------- /Quark/src/main/resources/Data/Shader/Simple3D.shader: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wolftein/Quark-Engine/HEAD/Quark/src/main/resources/Data/Shader/Simple3D.shader -------------------------------------------------------------------------------- /Quark-Extension/Quark-Extension-NiftyUI/src/main/resources/Data/NiftyUI/Texture/Empty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wolftein/Quark-Engine/HEAD/Quark-Extension/Quark-Extension-NiftyUI/src/main/resources/Data/NiftyUI/Texture/Empty.png -------------------------------------------------------------------------------- /Quark/build.gradle: -------------------------------------------------------------------------------- 1 | //! 2 | //! [DEPENDENCIES] 3 | //! 4 | dependencies { 5 | // ################################################################################################################# 6 | // [LOGGER] 7 | // ################################################################################################################# 8 | compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21' 9 | 10 | // ################################################################################################################# 11 | // [IO::AUDIO::OGG] 12 | // ################################################################################################################# 13 | compile 'com.github.Wolftein:j-ogg:-SNAPSHOT' 14 | } -------------------------------------------------------------------------------- /Quark-Extension/Quark-Extension-NiftyUI/build.gradle: -------------------------------------------------------------------------------- 1 | //! 2 | //! [DEPENDENCIES] 3 | //! 4 | dependencies { 5 | // ################################################################################################################# 6 | // [BASE] 7 | // ################################################################################################################# 8 | compile project(':Quark') 9 | 10 | // ################################################################################################################# 11 | // [NiftyGUI] 12 | // ################################################################################################################# 13 | compile group: 'com.github.nifty-gui', name: 'nifty', version: '1.4.2' 14 | } -------------------------------------------------------------------------------- /Quark-Backend/Quark-Backend-Web/build.gradle: -------------------------------------------------------------------------------- 1 | //! 2 | //! [DEPENDENCIES] 3 | //! 4 | dependencies { 5 | // ################################################################################################################# 6 | // [BASE] 7 | // ################################################################################################################# 8 | compile project(':Quark') 9 | 10 | // ################################################################################################################# 11 | // [TeaVM] 12 | // ################################################################################################################# 13 | compile 'com.github.konsoletyper.teavm:teavm-classlib:-SNAPSHOT' 14 | compile 'com.github.konsoletyper.teavm:teavm-extras-slf4j:-SNAPSHOT' 15 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ######################################################################################################################## 2 | ## [IDEA] 3 | ######################################################################################################################## 4 | *.iml 5 | *.ipr 6 | *.iws 7 | /.idea 8 | 9 | ######################################################################################################################## 10 | ## [BUILD] 11 | ######################################################################################################################## 12 | **/build 13 | 14 | 15 | ######################################################################################################################## 16 | ## [GRADLE-WRAPPER] 17 | ######################################################################################################################## 18 | /.gradle 19 | /gradle 20 | /gradlew 21 | /gradlew.* -------------------------------------------------------------------------------- /Quark-Backend/Quark-Backend-Desktop/src/main/java/ar/com/quark/backend/lwjgl/opengl/DesktopGLES31.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.backend.lwjgl.opengl; 19 | 20 | import ar.com.quark.render.Render; 21 | 22 | /** 23 | * Implementation for {@link Render.GLES31}. 24 | */ 25 | public class DesktopGLES31 extends DesktopGLES30 implements Render.GLES31 { 26 | } 27 | -------------------------------------------------------------------------------- /Quark-Backend/Quark-Backend-Desktop/src/main/java/ar/com/quark/backend/lwjgl/opengl/DesktopGLES32.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.backend.lwjgl.opengl; 19 | 20 | import ar.com.quark.render.Render; 21 | 22 | /** 23 | * Implementation for {@link Render.GLES32}. 24 | */ 25 | public class DesktopGLES32 extends DesktopGLES31 implements Render.GLES32 { 26 | } 27 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | // ##################################################################################################################### 2 | // [CORE] 3 | // ##################################################################################################################### 4 | include ':Quark' 5 | 6 | // ##################################################################################################################### 7 | // [BACKEND] 8 | // ##################################################################################################################### 9 | include ':Quark-Backend:Quark-Backend-Desktop' 10 | include ':Quark-Backend:Quark-Backend-Web' 11 | 12 | // ##################################################################################################################### 13 | // [EXTENSION] 14 | // ##################################################################################################################### 15 | include ':Quark-Extension:Quark-Extension-NiftyUI' -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/system/utility/ManageableManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.system.utility; 19 | 20 | /** 21 | * ManageableManager encapsulate a service for managing {@link Manageable}. 22 | */ 23 | public interface ManageableManager { 24 | /** 25 | * Dispose the given {@link Manageable}. 26 | * 27 | * @param manageable the manageable 28 | */ 29 | void dispose(Manageable manageable); 30 | } 31 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/system/utility/Disposable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.system.utility; 19 | 20 | /** 21 | * Disposable manage the life-cycle of a resource. 22 | */ 23 | public interface Disposable { 24 | /** 25 | *

Called when all resources owned by the implementor can safely be released

26 | *

27 | * NOTE: The callee should ensure the correct thread of the resource. 28 | */ 29 | void dispose(); 30 | } 31 | -------------------------------------------------------------------------------- /Quark-Backend/Quark-Backend-Web/src/main/java/ar/com/quark/backend/teavm/opengl/WebOpenGLES31.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.backend.teavm.opengl; 19 | 20 | import ar.com.quark.render.Render; 21 | import org.teavm.jso.dom.html.HTMLCanvasElement; 22 | 23 | /** 24 | * Implementation for {@link Render.GLES31}. 25 | */ 26 | public class WebOpenGLES31 extends WebOpenGLES30 implements Render.GLES31 { 27 | /** 28 | *

Constructor

29 | */ 30 | public WebOpenGLES31(HTMLCanvasElement canvas) { 31 | super(canvas); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Quark-Backend/Quark-Backend-Web/src/main/java/ar/com/quark/backend/teavm/opengl/WebOpenGLES32.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.backend.teavm.opengl; 19 | 20 | import ar.com.quark.render.Render; 21 | import org.teavm.jso.dom.html.HTMLCanvasElement; 22 | 23 | /** 24 | * Implementation for {@link Render.GLES32}. 25 | */ 26 | public final class WebOpenGLES32 extends WebOpenGLES31 implements Render.GLES32 { 27 | /** 28 | *

Constructor

29 | */ 30 | public WebOpenGLES32(HTMLCanvasElement canvas) { 31 | super(canvas); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/resource/AssetCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.resource; 19 | 20 | /** 21 | * AssetCallback represent a callback for requesting asset synchronously and asynchronously. 22 | */ 23 | public interface AssetCallback { 24 | /** 25 | *

Handle when the requested asset error

26 | */ 27 | void onFail(); 28 | 29 | /** 30 | *

Handle when the requested asset has been successful loaded

31 | * 32 | * @param asset the asset reference 33 | */ 34 | void onSuccess(A asset); 35 | } 36 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/storage/StorageType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.storage; 19 | 20 | /** 21 | * StorageType enumerate {@link Storage} type(s). 22 | */ 23 | public enum StorageType { 24 | /** 25 | * The buffer of the storage is located in the client-side (never disposed, until the storage is being removed). 26 | */ 27 | CLIENT, 28 | 29 | /** 30 | * The buffer of the storage is located in the server-side (and be disposed once it's uploaded). 31 | */ 32 | SERVER, 33 | 34 | /** 35 | * The buffer of the storage is located in the server-side (and access though mapping). 36 | */ 37 | SERVER_MAPPED 38 | } 39 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/input/device/InputMouseButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.input.device; 19 | 20 | /** 21 | * InputMouseButton enumerate(s) all button(s). 22 | */ 23 | public enum InputMouseButton { 24 | /** 25 | * Represent the left button of a pointing device. 26 | */ 27 | BUTTON_LEFT, 28 | 29 | /** 30 | * Represent the right button of a pointing device. 31 | */ 32 | BUTTON_RIGHT, 33 | 34 | /** 35 | * Represent the middle button of a pointing device. 36 | */ 37 | BUTTON_MIDDLE; 38 | 39 | /** 40 | * Hold all value(s). 41 | */ 42 | public final static InputMouseButton[] VALUES = InputMouseButton.values(); 43 | } 44 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/input/Input.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.input; 19 | 20 | import ar.com.quark.system.utility.array.Int32Array; 21 | 22 | /** 23 | * Input encapsulate an input-device to interface with InputManager. 24 | */ 25 | public interface Input { 26 | /** 27 | *

Create and initialise the device

28 | */ 29 | void create(); 30 | 31 | /** 32 | *

Update and poll all input event(s) from the device

33 | * 34 | * @param buffer the buffer that will contain the input when updating 35 | */ 36 | void update(Int32Array buffer); 37 | 38 | /** 39 | *

Destroy the device

40 | */ 41 | void destroy(); 42 | } 43 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/resource/AssetLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.resource; 19 | 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | 23 | /** 24 | * AssetLoader encapsulate an interface for loading asset(s). 25 | */ 26 | public interface AssetLoader { 27 | /** 28 | *

Load an asset

29 | * 30 | * @param manager the asset manager 31 | * @param key the asset key 32 | * @param input the asset stream 33 | * 34 | * @throws IOException indicates failure loading the asset 35 | */ 36 | void load(AssetManager manager, AssetKey key, InputStream input) throws IOException; 37 | } 38 | -------------------------------------------------------------------------------- /Quark-Backend/Quark-Backend-Desktop/build.gradle: -------------------------------------------------------------------------------- 1 | //! 2 | //! [DEPENDENCIES] 3 | //! 4 | dependencies { 5 | // ################################################################################################################# 6 | // [BASE] 7 | // ################################################################################################################# 8 | compile project(':Quark') 9 | 10 | // ################################################################################################################# 11 | // [LOGGER] 12 | // ################################################################################################################# 13 | compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.21' 14 | 15 | // ################################################################################################################# 16 | // [LWJGL] 17 | // ################################################################################################################# 18 | compile group: 'org.lwjgl', name: 'lwjgl', version: '3.0.1-SNAPSHOT' 19 | compile group: 'org.lwjgl', name: 'lwjgl-platform', version: '3.0.1-SNAPSHOT', classifier: 'natives-windows' 20 | compile group: 'org.lwjgl', name: 'lwjgl-platform', version: '3.0.1-SNAPSHOT', classifier: 'natives-linux' 21 | compile group: 'org.lwjgl', name: 'lwjgl-platform', version: '3.0.1-SNAPSHOT', classifier: 'natives-osx' 22 | } -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/StageType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader; 19 | 20 | import ar.com.quark.render.Render; 21 | 22 | /** 23 | * StageType enumerate {@link Stage} type(s). 24 | */ 25 | public enum StageType { 26 | /** 27 | * A shader that is intended to run on the programmable fragment processor. 28 | */ 29 | FRAGMENT(Render.GLES2.GL_FRAGMENT_SHADER), 30 | 31 | /** 32 | * A shader that is intended to run on the programmable vertex processor. 33 | */ 34 | VERTEX(Render.GLES2.GL_VERTEX_SHADER), 35 | 36 | /** 37 | * A shader that is intended to run on the programmable geometry processor. 38 | */ 39 | GEOMETRY(Render.GLES32.GL_GEOMETRY_SHADER); 40 | 41 | public final int eValue; 42 | 43 | /** 44 | *

Constructor

45 | */ 46 | StageType(int value) { 47 | eValue = value; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Quark-Extension/Quark-Extension-NiftyUI/src/main/java/ar/com/quark/extension/niftyui/NiftyResourceLocation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.extension.niftyui; 19 | 20 | import de.lessvoid.nifty.tools.resourceloader.ResourceLocation; 21 | 22 | import java.io.InputStream; 23 | import java.net.URL; 24 | 25 | import static ar.com.quark.Quark.QKResources; 26 | 27 | /** 28 | * NiftyResourceLocation represent implementation of {@link ResourceLocation}. 29 | */ 30 | public final class NiftyResourceLocation implements ResourceLocation { 31 | /** 32 | * {@inheritDoc} 33 | */ 34 | @Override 35 | public InputStream getResourceAsStream(String ref) { 36 | return QKResources.find(ref); 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | @Override 43 | public URL getResource(String ref) { 44 | //! 45 | //! NOTE: No need to implement this method. 46 | //! 47 | return null; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/texture/TextureType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.texture; 19 | 20 | import ar.com.quark.render.Render; 21 | 22 | /** 23 | * TextureType enumerate {@link Texture} type(s). 24 | */ 25 | public enum TextureType { 26 | /** 27 | * Images in this texture all are 2-dimensional. They have width and height, but no depth. 28 | */ 29 | TEXTURE_2D(Render.GLES2.GL_TEXTURE_2D), 30 | 31 | /** 32 | * Images in this texture all are 3-dimensional. They have width, height, and depth. 33 | */ 34 | TEXTURE_3D(Render.GLES3.GL_TEXTURE_3D), 35 | 36 | /** 37 | * Images in this texture consists of six 2D images. The images are arranged in a cube-shape. 38 | */ 39 | TEXTURE_CUBE(Render.GLES2.GL_TEXTURE_CUBE_MAP); 40 | 41 | public final int eValue; 42 | 43 | /** 44 | *

Constructor

45 | */ 46 | TextureType(int value) { 47 | eValue = value; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/Stage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader; 19 | 20 | /** 21 | * Stage encapsulate an user-defined stage of a graphics processor. 22 | *

23 | * Its purpose is to execute one of the programmable stages of the rendering pipeline. 24 | */ 25 | public final class Stage { 26 | private final String mSource; 27 | private final StageType mType; 28 | 29 | /** 30 | *

Constructor

31 | */ 32 | public Stage(String source, StageType type) { 33 | mSource = source; 34 | mType = type; 35 | } 36 | 37 | /** 38 | *

Get the source of the stage

39 | * 40 | * @return the source of the stage 41 | */ 42 | public String getSource() { 43 | return mSource; 44 | } 45 | 46 | /** 47 | *

Get the type of the stage

48 | * 49 | * @return the type of the stage 50 | */ 51 | public StageType getType() { 52 | return mType; 53 | } 54 | } -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/Uniform.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader; 19 | 20 | import ar.com.quark.render.Render; 21 | import ar.com.quark.system.utility.Manageable; 22 | 23 | import static ar.com.quark.Quark.QKRender; 24 | 25 | /** 26 | * Uniform encapsulate a variable that resides in a {@link Stage}. 27 | */ 28 | public abstract class Uniform extends Manageable { 29 | public final static int CONCEPT_VALUE = (1 << 1); 30 | 31 | private final UniformType mType; 32 | 33 | /** 34 | *

Constructor

35 | */ 36 | protected Uniform(UniformType type) { 37 | mType = type; 38 | } 39 | 40 | /** 41 | *

Get the type of the data

42 | * 43 | * @return the type of the data 44 | */ 45 | public final UniformType getType() { 46 | return mType; 47 | } 48 | 49 | /** 50 | * @see Render#update(Uniform) 51 | */ 52 | public final void update() { 53 | QKRender.update(this); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/resource/AssetListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.resource; 19 | 20 | /** 21 | * AssetListener encapsulate an interface for listening to asset's event(s). 22 | */ 23 | public interface AssetListener { 24 | /** 25 | *

Indicate an asset is been requested

26 | * 27 | * @param filename the name (as unique identifier) of the asset 28 | */ 29 | void onAssetRequested(String filename); 30 | 31 | /** 32 | *

Indicate an asset has been loaded

33 | * 34 | * @param filename the name (as unique identifier) of the asset 35 | */ 36 | void onAssetLoaded(String filename); 37 | 38 | /** 39 | *

Indicate an asset has fail to load

40 | * 41 | * @param filename the name (as unique identifier) of the asset 42 | */ 43 | void onAssetFailed(String filename); 44 | 45 | /** 46 | *

Indicate an asset has been disposed

47 | * 48 | * @param filename the name (as unique identifier) of the asset 49 | */ 50 | void onAssetDisposed(String filename); 51 | } 52 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/data/UniformInt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader.data; 19 | 20 | import ar.com.quark.render.shader.Uniform; 21 | import ar.com.quark.render.shader.UniformType; 22 | 23 | /** 24 | * UniformInt encapsulate an {@link Uniform} for {@link UniformType#Int}. 25 | */ 26 | public final class UniformInt extends Uniform { 27 | private int mValue; 28 | 29 | /** 30 | *

Default constructor

31 | */ 32 | public UniformInt(int value) { 33 | super(UniformType.Int); 34 | setValue(value); 35 | } 36 | 37 | /** 38 | *

Get the value of the data

39 | * 40 | * @return the value of the data 41 | */ 42 | public int getValue() { 43 | return mValue; 44 | } 45 | 46 | /** 47 | *

Change the value of the data

48 | * 49 | * @param newValue the new value of the data 50 | */ 51 | public void setValue(int newValue) { 52 | if (mValue != newValue) { 53 | mValue = newValue; 54 | setUpdate(CONCEPT_VALUE); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/data/UniformFloat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader.data; 19 | 20 | import ar.com.quark.render.shader.UniformType; 21 | import ar.com.quark.render.shader.Uniform; 22 | 23 | /** 24 | * UniformFloat encapsulate an {@link Uniform} for {@link UniformType#Float}. 25 | */ 26 | public final class UniformFloat extends Uniform { 27 | private float mValue; 28 | 29 | /** 30 | *

Constructor

31 | */ 32 | public UniformFloat(float value) { 33 | super(UniformType.Float); 34 | setValue(value); 35 | } 36 | 37 | /** 38 | *

Get the value of the data

39 | * 40 | * @return the value of the data 41 | */ 42 | public float getValue() { 43 | return mValue; 44 | } 45 | 46 | /** 47 | *

Change the value of the data

48 | * 49 | * @param newValue the new value of the data 50 | */ 51 | public void setValue(float newValue) { 52 | if (mValue != newValue) { 53 | mValue = newValue; 54 | setUpdate(CONCEPT_VALUE); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/data/UniformUnsignedInt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader.data; 19 | 20 | import ar.com.quark.render.shader.Uniform; 21 | import ar.com.quark.render.shader.UniformType; 22 | 23 | /** 24 | * UniformUnsignedInt encapsulate an {@link Uniform} for {@link UniformType#UInt}. 25 | */ 26 | public final class UniformUnsignedInt extends Uniform { 27 | private int mValue; 28 | 29 | /** 30 | *

Constructor

31 | */ 32 | public UniformUnsignedInt(int value) { 33 | super(UniformType.UInt); 34 | setValue(value); 35 | } 36 | 37 | /** 38 | *

Get the value of the data

39 | * 40 | * @return the value of the data 41 | */ 42 | public int getValue() { 43 | return mValue; 44 | } 45 | 46 | /** 47 | *

Change the value of the data

48 | * 49 | * @param newValue the new value of the data 50 | */ 51 | public void setValue(int newValue) { 52 | if (mValue != newValue) { 53 | mValue = newValue; 54 | setUpdate(CONCEPT_VALUE); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/resource/AssetDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.resource; 19 | 20 | /** 21 | * AssetDescriptor encapsulate all parameter(s) of an asset. 22 | */ 23 | public class AssetDescriptor { 24 | private final boolean mCacheable; 25 | private final boolean mCloseable; 26 | 27 | /** 28 | *

Constructor

29 | */ 30 | public AssetDescriptor(boolean cacheable, boolean closeable) { 31 | mCacheable = cacheable; 32 | mCloseable = closeable; 33 | } 34 | 35 | /** 36 | *

Check if the asset can be cacheable in memory

37 | * 38 | * @return true if the asset can be cacheable in memory, false otherwise 39 | */ 40 | public final boolean isCacheable() { 41 | return mCacheable; 42 | } 43 | 44 | /** 45 | *

Check if the asset should be closed automatically

46 | * 47 | * @return true if the asset should be closed automatically, false otherwise 48 | */ 49 | public final boolean isCloseable() { 50 | return mCloseable; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/Quark.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark; 19 | 20 | import ar.com.quark.audio.AudioManager; 21 | import ar.com.quark.render.Render; 22 | import ar.com.quark.resource.AssetManager; 23 | import ar.com.quark.system.Display; 24 | import ar.com.quark.input.InputManager; 25 | 26 | /** 27 | * Quark encapsulate a singleton for the entire framework. 28 | */ 29 | public final class Quark { 30 | /** 31 | * Hold the {@link AudioManager} implementation. 32 | * 33 | * @see AudioManager 34 | */ 35 | public static AudioManager QKAudio; 36 | 37 | /** 38 | * Hold the {@link Display} implementation. 39 | * 40 | * @see Display 41 | */ 42 | public static Display QKDisplay; 43 | 44 | /** 45 | * Hold the {@link InputManager} implementation. 46 | * 47 | * @see InputManager 48 | */ 49 | public static InputManager QKInput; 50 | 51 | /** 52 | * Hold the {@link Render} implementation. 53 | * 54 | * @see Render 55 | */ 56 | public static Render QKRender; 57 | 58 | /** 59 | * Hold the {@link AssetManager} implementation. 60 | * 61 | * @see AssetManager 62 | */ 63 | public static AssetManager QKResources; 64 | } 65 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/font/FontRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.font; 19 | 20 | import ar.com.quark.mathematic.Colour; 21 | import ar.com.quark.render.texture.Texture; 22 | 23 | /** 24 | * FontRenderer represent a renderer for {@link Font}. 25 | */ 26 | public interface FontRenderer { 27 | /** 28 | *

Render a {@link FontGlyph}

29 | * 30 | * @param texture the` texture 31 | * @param x the x1 coordinate (in screen coordinates) of the glyph 32 | * @param y the y1 coordinate (in screen coordinates) of the glyph 33 | * @param x2 the x2 coordinate (in screen coordinates) of the glyph 34 | * @param y2 the y2 coordinate (in screen coordinates) of the glyph 35 | * @param tx1 the x1 texture coordinate (normalised) of the glyph 36 | * @param ty1 the y1 texture coordinate (normalised) of the glyph 37 | * @param tx2 the x2 texture coordinate (normalised) of the glyph 38 | * @param ty2 the y2 texture coordinate (normalised) of the glyph 39 | * @param colour the colour 40 | */ 41 | void drawFontGlyph(Texture texture, float x, float y, float x2, float y2, 42 | float tx1, float ty1, 43 | float tx2, float ty2, Colour colour); 44 | } 45 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/system/DisplayMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.system; 19 | 20 | /** 21 | * DisplayMode describe display properties for {@link Display}. 22 | */ 23 | public final class DisplayMode { 24 | private final int mWidth; 25 | private final int mHeight; 26 | private final int mRate; 27 | 28 | /** 29 | *

Constructor

30 | */ 31 | public DisplayMode(int width, int height, int rate) { 32 | mWidth = width; 33 | mHeight = height; 34 | mRate = rate; 35 | } 36 | 37 | /** 38 | *

Get the width of the display mode (in screen coordinates)

39 | * 40 | * @return the width of the display mode (in screen coordinates) 41 | */ 42 | public int getWidth() { 43 | return mWidth; 44 | } 45 | 46 | /** 47 | *

Get the height of the display mode (in screen coordinates)

48 | * 49 | * @return the height of the display mode (in screen coordinates) 50 | */ 51 | public int getHeight() { 52 | return mHeight; 53 | } 54 | 55 | /** 56 | *

Get the refresh rate of the display mode (in Hertz)

57 | * 58 | * @return the refresh rate of the display mode (in Hertz) 59 | */ 60 | public int getRate() { 61 | return mRate; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/system/utility/array/Int8Array.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.system.utility.array; 19 | 20 | /** 21 | * Specialised implementation of {@link Array} for 8-bit integer element(s). 22 | */ 23 | public interface Int8Array extends Array { 24 | /** 25 | * @see Array#writeInt8(int) 26 | */ 27 | default Int8Array write(byte value) { 28 | return writeInt8(value); 29 | } 30 | 31 | /** 32 | * @see Array#writeInt8(byte[]) 33 | */ 34 | default Int8Array write(byte[] value) { 35 | writeInt8(value); 36 | return this; 37 | } 38 | 39 | /** 40 | * @see Array#writeInt8(byte[], int, int) 41 | */ 42 | default Int8Array write(byte[] value, int offset, int count) { 43 | writeInt8(value, offset, count); 44 | return this; 45 | } 46 | 47 | /** 48 | * @see Array#writeInt8(int, int) 49 | */ 50 | default Int8Array write(int index, byte value) { 51 | return writeInt8(index, value); 52 | } 53 | 54 | /** 55 | * @see Array#readInt8() 56 | */ 57 | default byte read() { 58 | return readInt8(); 59 | } 60 | 61 | /** 62 | * @see Array#readInt8(int) 63 | */ 64 | default byte read(int index) { 65 | return readInt8(index); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/texture/TextureBorder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.texture; 19 | 20 | import ar.com.quark.render.Render; 21 | 22 | /** 23 | * TextureBorder enumerate {@link Texture} border mode(s). 24 | */ 25 | public enum TextureBorder { 26 | /** 27 | * Causes the integer part of the s coordinate to be ignored, creating a repeating pattern. 28 | */ 29 | REPEAT(Render.GLES2.GL_REPEAT), 30 | 31 | /** 32 | * Causes coordinates to be clamped to the range (1/2n. 1 - 1/2n) where N is the size of the texture 33 | * in the direction of clamping. 34 | */ 35 | CLAMP_TO_EDGE(Render.GLES2.GL_CLAMP_TO_EDGE), 36 | 37 | /** 38 | * Evaluates coordinates in a similar manner to {@link #CLAMP_TO_EDGE}, the fetched texel data 39 | * is substituted with the values specified by the border color of the texture. 40 | */ 41 | CLAMP_TO_BORDER(Render.GLES2.GL_CLAMP_TO_BORDER), 42 | 43 | /** 44 | * The texture will also be repeated, but it will be mirrored when the integer part of the coordinate is odd. 45 | */ 46 | MIRRORED_REPEAT(Render.GLES2.GL_MIRRORED_REPEAT); 47 | 48 | public final int eValue; 49 | 50 | /** 51 | *

Constructor

52 | */ 53 | TextureBorder(int value) { 54 | eValue = value; 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/system/DisplayLifecycle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.system; 19 | 20 | /** 21 | * DisplayLifecycle encapsulate the lifecycle of {@link Display}. 22 | */ 23 | public interface DisplayLifecycle { 24 | /** 25 | *

Called when the display is created

26 | * 27 | * @see #onDispose() 28 | */ 29 | void onCreate(); 30 | 31 | /** 32 | *

Called when the display has resize

33 | * 34 | * @param width the new width (in pixel) of the display 35 | * @param height the new height (in pixel) of the display 36 | */ 37 | void onResize(int width, int height); 38 | 39 | /** 40 | *

Called when the display require to render

41 | * 42 | * @param time the time since the last render 43 | */ 44 | void onRender(float time); 45 | 46 | /** 47 | *

Called when the display has been pause from a running state

48 | * 49 | * @see #onResume() 50 | */ 51 | void onPause(); 52 | 53 | /** 54 | *

Called when the display has been resume from a pause state

55 | * 56 | * @see #onPause() 57 | */ 58 | void onResume(); 59 | 60 | /** 61 | *

Called when the display is disposed

62 | * 63 | * @see #onCreate() 64 | */ 65 | void onDispose(); 66 | } 67 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/system/utility/array/Int16Array.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.system.utility.array; 19 | 20 | /** 21 | * Specialised implementation of {@link Array} for 16-bit integer element(s). 22 | */ 23 | public interface Int16Array extends Array { 24 | /** 25 | * @see Array#writeInt16(int) 26 | */ 27 | default Int16Array write(short value) { 28 | return writeInt16(value); 29 | } 30 | 31 | /** 32 | * @see Array#writeInt16(short[]) 33 | */ 34 | default Int16Array write(short[] value) { 35 | writeInt16(value); 36 | return this; 37 | } 38 | 39 | /** 40 | * @see Array#writeInt16(short[], int, int) 41 | */ 42 | default Int16Array write(short[] value, int offset, int count) { 43 | writeInt16(value, offset, count); 44 | return this; 45 | } 46 | 47 | /** 48 | * @see Array#writeInt16(int, int) 49 | */ 50 | default Int16Array write(int index, short value) { 51 | return writeInt16(index * 0x02, value); 52 | } 53 | 54 | /** 55 | * @see Array#readInt16() 56 | */ 57 | default short read() { 58 | return readInt16(); 59 | } 60 | 61 | /** 62 | * @see Array#readInt16(int) 63 | */ 64 | default short read(int index) { 65 | return readInt16(index * 0x02); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/mathematic/ImmutableVector2i.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.mathematic; 19 | 20 | /** 21 | * Represent an immutable {@linkplain Vector2i}. 22 | */ 23 | public final class ImmutableVector2i extends Vector2i { 24 | /** 25 | *

Default constructor

26 | */ 27 | public ImmutableVector2i(int x, int y) { 28 | super(x, y); 29 | } 30 | 31 | /** 32 | *

Creates a new vector where each component value is 0

33 | * 34 | * @return a new vector 35 | */ 36 | public static ImmutableVector2i zero() { 37 | return new ImmutableVector2i(0, 0); 38 | } 39 | 40 | /** 41 | *

Creates a new vector where each component value is 1

42 | * 43 | * @return a new vector 44 | */ 45 | public static ImmutableVector2i one() { 46 | return new ImmutableVector2i(1, 1); 47 | } 48 | 49 | /** 50 | *

Creates a new vector of length one in the x-axis

51 | * 52 | * @return a new vector 53 | */ 54 | public static ImmutableVector2i unitX() { 55 | return new ImmutableVector2i(1, 0); 56 | } 57 | 58 | /** 59 | *

Creates a new vector of length one in the y-axis

60 | * 61 | * @return a new vector 62 | */ 63 | public static ImmutableVector2i unitY() { 64 | return new ImmutableVector2i(0, 1); 65 | } 66 | } -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/system/utility/array/Float32Array.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.system.utility.array; 19 | 20 | /** 21 | * Specialised implementation of {@link Array} for 32-bit float element(s). 22 | */ 23 | public interface Float32Array extends Array { 24 | /** 25 | * @see Array#writeFloat32(float) 26 | */ 27 | default Float32Array write(float value) { 28 | return writeFloat32(value); 29 | } 30 | 31 | /** 32 | * @see Array#writeFloat32(float[]) 33 | */ 34 | default Float32Array write(float[] value) { 35 | writeFloat32(value); 36 | return this; 37 | } 38 | 39 | /** 40 | * @see Array#writeFloat32(float[], int, int) 41 | */ 42 | default Float32Array write(float[] value, int offset, int count) { 43 | writeFloat32(value, offset, count); 44 | return this; 45 | } 46 | 47 | /** 48 | * @see Array#writeFloat32(int, float) 49 | */ 50 | default Float32Array write(int index, float value) { 51 | return writeFloat32(index * 0x04, value); 52 | } 53 | 54 | /** 55 | * @see Array#readFloat32() 56 | */ 57 | default float read() { 58 | return readFloat32(); 59 | } 60 | 61 | /** 62 | * @see Array#readFloat32(int) 63 | */ 64 | default float read(int index) { 65 | return readFloat32(index * 0x04); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Quark-Extension/Quark-Extension-NiftyUI/src/main/java/ar/com/quark/extension/niftyui/NiftyRenderImage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.extension.niftyui; 19 | 20 | import de.lessvoid.nifty.spi.render.RenderImage; 21 | import ar.com.quark.render.texture.Texture; 22 | 23 | import static ar.com.quark.Quark.QKResources; 24 | 25 | /** 26 | * NiftyRenderImage represent implementation of {@link RenderImage}. 27 | */ 28 | public final class NiftyRenderImage implements RenderImage { 29 | private final Texture mTexture; 30 | 31 | /** 32 | *

Constructor

33 | */ 34 | public NiftyRenderImage(Texture texture) { 35 | mTexture = texture; 36 | } 37 | 38 | /** 39 | *

Get the underlying texture of the image

40 | * 41 | * @return the underlying texture of the image 42 | */ 43 | public Texture getTexture() { 44 | return mTexture; 45 | } 46 | 47 | /** 48 | * {@inheritDoc} 49 | */ 50 | @Override 51 | public int getWidth() { 52 | return mTexture.getImage().getWidth(); 53 | } 54 | 55 | /** 56 | * {@inheritDoc} 57 | */ 58 | @Override 59 | public int getHeight() { 60 | return mTexture.getImage().getHeight(); 61 | } 62 | 63 | /** 64 | * {@inheritDoc} 65 | */ 66 | @Override 67 | public void dispose() { 68 | QKResources.unload(mTexture); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/AttributeType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader; 19 | 20 | /** 21 | * AttributeType enumerate {@link Attribute} type(s). 22 | */ 23 | public enum AttributeType { 24 | /** 25 | * Represent a floating point number. 26 | */ 27 | Float("float"), 28 | 29 | /** 30 | * Represent two floating point number. 31 | */ 32 | Float2("vec2"), 33 | 34 | /** 35 | * Represent three floating point number. 36 | */ 37 | Float3("vec3"), 38 | 39 | /** 40 | * Represent four floating point number. 41 | */ 42 | Float4("vec4"), 43 | 44 | /** 45 | * Represent an integer number. 46 | */ 47 | Int("int"), 48 | 49 | /** 50 | * Represent two integer number. 51 | */ 52 | Int2("ivec2"), 53 | 54 | /** 55 | * Represent three integer number. 56 | */ 57 | Int3("ivec3"), 58 | 59 | /** 60 | * Represent four integer number. 61 | */ 62 | Int4("ivec4"), 63 | 64 | /** 65 | * Represent a matrix of 3x3 component(s). 66 | */ 67 | Matrix3x3("mat3"), 68 | 69 | /** 70 | * Represent a matrix of 4x4 component(s). 71 | */ 72 | Matrix4x4("mat4"); 73 | 74 | public final String eName; 75 | 76 | /** 77 | *

Constructor

78 | */ 79 | AttributeType(String name) { 80 | eName = name; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/audio/AudioFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.audio; 19 | 20 | /** 21 | * AudioFormat enumerate the format of an {@link Audio}. 22 | */ 23 | public enum AudioFormat { 24 | /** 25 | * Represent 8-Bit mono audio. 26 | */ 27 | MONO_8(AudioManager.ALES10.AL_FORMAT_MONO8, 0x01, 0x08), 28 | 29 | /** 30 | * Represent 16-Bit mono audio. 31 | */ 32 | MONO_16(AudioManager.ALES10.AL_FORMAT_MONO16, 0x01, 0x10), 33 | 34 | /** 35 | * Represent single-precision mono audio. 36 | */ 37 | MONO_32F(AudioManager.ALESExtension.AL_FORMAT_MONO_FLOAT32, 0x01, 0x20), 38 | 39 | /** 40 | * Represent 8-Bit stereo audio. 41 | */ 42 | STEREO_8(AudioManager.ALES10.AL_FORMAT_STEREO8, 0x02, 0x08), 43 | 44 | /** 45 | * Represent 16-Bit stereo audio. 46 | */ 47 | STEREO_16(AudioManager.ALES10.AL_FORMAT_STEREO16, 0x02, 0x10), 48 | 49 | /** 50 | * Represent single-precision stereo audio. 51 | */ 52 | STEREO_32F(AudioManager.ALESExtension.AL_FORMAT_STEREO_FLOAT32, 0x02, 0x20); 53 | 54 | public final int eType; 55 | public final int eChannel; 56 | public final int eComponent; 57 | 58 | /** 59 | *

Constructor

60 | */ 61 | AudioFormat(int type, int channel, int component) { 62 | eType = type; 63 | eChannel = channel; 64 | eComponent = component; 65 | } 66 | } -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/resource/locator/ClassAssetLocator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.resource.locator; 19 | 20 | import ar.com.quark.resource.AssetCallback; 21 | import ar.com.quark.resource.AssetLocator; 22 | 23 | import java.io.InputStream; 24 | 25 | /** 26 | * Encapsulate an {@link AssetLocator} that search asset(s) using {@link ClassLoader}. 27 | */ 28 | public final class ClassAssetLocator implements AssetLocator { 29 | private final ClassLoader mLoader = ClassAssetLocator.class.getClassLoader(); 30 | 31 | /** 32 | * {@inheritDoc} 33 | */ 34 | @Override 35 | public boolean isSynchronousSupported() { 36 | return true; 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | @Override 43 | public boolean isAsynchronousSupported() { 44 | return true; 45 | } 46 | 47 | /** 48 | * {@inheritDoc} 49 | */ 50 | @Override 51 | public InputStream locate(String filename) { 52 | return mLoader.getResourceAsStream(filename); 53 | } 54 | 55 | /** 56 | * {@inheritDoc} 57 | */ 58 | @Override 59 | public InputStream locate(String filename, AssetCallback callback) { 60 | final InputStream input = locate(filename); 61 | 62 | if (input != null) { 63 | callback.onSuccess(input); 64 | } else { 65 | callback.onFail(); 66 | } 67 | return input; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/resource/AssetLocator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.resource; 19 | 20 | import java.io.InputStream; 21 | 22 | /** 23 | * AssetLocator encapsulate an interface for finding asset(s). 24 | */ 25 | public interface AssetLocator { 26 | /** 27 | *

Check if the locator support synchronous request(s)

28 | * 29 | * @return true if the locator support synchronous request(s), false otherwise 30 | */ 31 | boolean isSynchronousSupported(); 32 | 33 | /** 34 | *

Check if the locator support asynchronous request(s)

35 | * 36 | * @return true if the locator support asynchronous request(s), false otherwise 37 | */ 38 | boolean isAsynchronousSupported(); 39 | 40 | /** 41 | *

Locate an asset

42 | * 43 | * @param filename the filename of the asset 44 | * 45 | * @return a {@link InputStream} to handle both synchronous and asynchronous requests. 46 | */ 47 | InputStream locate(String filename); 48 | 49 | /** 50 | *

Locate an asset (asynchronously)

51 | * 52 | * @param filename the filename of the asset 53 | * @param callback the callback 54 | * 55 | * @return an {@link InputStream} to handle both synchronous and asynchronous requests. 56 | */ 57 | InputStream locate(String filename, AssetCallback callback); 58 | } 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![License](https://img.shields.io/badge/license-APACHE-blue.svg)](https://github.com/Wolftein/Quark-Engine/blob/master/LICENSE) 2 | ![Size](https://reposs.herokuapp.com/?path=Wolftein/Quark-Engine) 3 | [![Build Status](https://travis-ci.org/Wolftein/Quark-Engine.svg?branch=master)](https://travis-ci.org/Wolftein/Quark-Engine) 4 | 5 | ## About 6 | 7 | Quark is a cross-platform java framework based on OpenGL that works on desktop and browser. 8 | 9 | ## Features 10 | * Extend documentation for ease development 11 | * Deploy games on Windows, Linux and Mac 12 | * Deploy games on Browser ([TeaVM](https://github.com/konsoletyper/teavm)) 13 | * Multi-threading support to keep your games running smooth 14 | * Support for legacy and modern OpenGL (OpenGL 2.1-3.3, OpenGL ES 2.0-3.2) with forward compatibility 15 | * Support for .PNG, .DDS, .OGG, .WAV file format 16 | * Support for .FNT format 17 | * Support for custom binary shader format 18 | 19 | 20 | ## Get started 21 | 22 | Currently the framework isn't in maven, so the easiest way to start using it is using [jitpack](http://jipack.io). 23 | 24 | allprojects { 25 | repositories { 26 | jcenter() 27 | maven { 28 | url "https://jitpack.io" 29 | } 30 | maven { 31 | url "http://oss.sonatype.org/content/groups/public/" 32 | } 33 | maven { 34 | url 'https://oss.sonatype.org/content/repositories/snapshots' 35 | } 36 | mavenCentral(); 37 | } 38 | } 39 | 40 | compile 'com.github.Wolftein:Quark-Engine:-SNAPSHOT' 41 | 42 | ## License 43 | 44 | Copyright (c) 2014-2016 Agustin L. Alvarez 45 | 46 | Licensed under the Apache License, Version 2.0 (the "License"); 47 | you may not use this file except in compliance with the License. 48 | You may obtain a copy of the License at 49 | 50 | http://www.apache.org/licenses/LICENSE-2.0 51 | 52 | Unless required by applicable law or agreed to in writing, software 53 | distributed under the License is distributed on an "AS IS" BASIS, 54 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 55 | See the License for the specific language governing permissions and 56 | limitations under the License. 57 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/input/device/InputKeyboard.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.input.device; 19 | 20 | import ar.com.quark.input.Input; 21 | import ar.com.quark.system.utility.array.Int32Array; 22 | 23 | /** 24 | * InputKeyboard encapsulate an {@link Input} for handling keyboard based device(s). 25 | */ 26 | public interface InputKeyboard extends Input { 27 | /** 28 | * Encapsulate the unique identifier for the key_up event. 29 | */ 30 | int EVENT_KEY_UP = 0x00000001; 31 | 32 | /** 33 | * Encapsulate the unique identifier for the key_down event. 34 | */ 35 | int EVENT_KEY_DOWN = EVENT_KEY_UP + 0x01; 36 | 37 | /** 38 | * Encapsulate the unique identifier for the key_type event. 39 | */ 40 | int EVENT_KEY_TYPE = EVENT_KEY_DOWN + 0x01; 41 | 42 | /** 43 | *

Queue a key up event

44 | * 45 | * @see #EVENT_KEY_UP 46 | */ 47 | static void onFactoryKeyUp(Int32Array buffer, InputKey key) { 48 | buffer.write(EVENT_KEY_UP).write(key.ordinal()); 49 | } 50 | 51 | /** 52 | *

Queue a key down event

53 | * 54 | * @see #EVENT_KEY_DOWN 55 | */ 56 | static void onFactoryKeyDown(Int32Array buffer, InputKey key) { 57 | buffer.write(EVENT_KEY_DOWN).write(key.ordinal()); 58 | } 59 | 60 | /** 61 | *

Queue a key type event

62 | * 63 | * @see #EVENT_KEY_TYPE 64 | */ 65 | static void onFactoryKeyType(Int32Array buffer, char key) { 66 | buffer.write(EVENT_KEY_TYPE).write(key); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/storage/VertexFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.storage; 19 | 20 | import ar.com.quark.render.Render; 21 | 22 | /** 23 | * VertexFormat enumerate {@link Vertex} type(s). 24 | */ 25 | public enum VertexFormat { 26 | /** 27 | * Represent a signed 8-bit integer. 28 | */ 29 | BYTE(Render.GLES2.GL_BYTE, 0x01), 30 | 31 | /** 32 | * Represent an unsigned 8-bit integer. 33 | */ 34 | UNSIGNED_BYTE(Render.GLES2.GL_UNSIGNED_BYTE, 0x01), 35 | 36 | /** 37 | * Represent a signed 16-bit integer. 38 | */ 39 | SHORT(Render.GLES2.GL_SHORT, 0x02), 40 | 41 | /** 42 | * Represent an unsigned 16-bit integer. 43 | */ 44 | UNSIGNED_SHORT(Render.GLES2.GL_UNSIGNED_SHORT, 0x02), 45 | 46 | /** 47 | * Represent a signed 32-bit integer. 48 | */ 49 | INT(Render.GLES3.GL_INT, 0x04), 50 | 51 | /** 52 | * Represent an unsigned 32-bit integer. 53 | */ 54 | UNSIGNED_INT(Render.GLES3.GL_UNSIGNED_INT, 0x04), 55 | 56 | /** 57 | * Represent a IEEE-754 single-precision floating point number. 58 | */ 59 | FLOAT(Render.GLES2.GL_FLOAT, 0x04), 60 | 61 | /** 62 | * Represent a IEEE-754 half-precision floating point number. 63 | */ 64 | HALF_FLOAT(Render.GLES3.GL_HALF_FLOAT, 0x02); 65 | 66 | public final int eValue; 67 | public final int eLength; 68 | 69 | /** 70 | *

Constructor

71 | */ 72 | VertexFormat(int value, int length) { 73 | this.eValue = value; 74 | this.eLength = length; 75 | } 76 | } 77 | 78 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/data/UniformInt2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader.data; 19 | 20 | import ar.com.quark.mathematic.MutableVector2i; 21 | import ar.com.quark.mathematic.Vector2i; 22 | import ar.com.quark.render.shader.Uniform; 23 | import ar.com.quark.render.shader.UniformType; 24 | 25 | /** 26 | * UniformInt2 encapsulate an {@link Uniform} for {@link UniformType#Int2}. 27 | */ 28 | public final class UniformInt2 extends Uniform { 29 | private final MutableVector2i mValue = MutableVector2i.zero(); 30 | 31 | /** 32 | *

Constructor

33 | */ 34 | public UniformInt2(Vector2i value) { 35 | super(UniformType.Int2); 36 | setValue(value); 37 | } 38 | 39 | /** 40 | *

Get the value of the data

41 | * 42 | * @return the value of the data 43 | */ 44 | public Vector2i getValue() { 45 | return mValue; 46 | } 47 | 48 | /** 49 | *

Change the value of the data

50 | * 51 | * @param newValue the new value of the data 52 | */ 53 | public void setValue(Vector2i newValue) { 54 | setValue(newValue.getX(), newValue.getY()); 55 | } 56 | 57 | /** 58 | *

Change the value of the data

59 | * 60 | * @param newX the new x value of the data 61 | * @param newY the new y value of the data 62 | */ 63 | public void setValue(int newX, int newY) { 64 | if (mValue.getX() != newX || mValue.getY() != newY) { 65 | mValue.setXY(newX, newY); 66 | setUpdate(CONCEPT_VALUE); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Quark-Extension/Quark-Extension-NiftyUI/src/main/java/ar/com/quark/extension/niftyui/NiftySoundDevice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.extension.niftyui; 19 | 20 | import ar.com.quark.audio.Audio; 21 | import ar.com.quark.Quark; 22 | import de.lessvoid.nifty.sound.SoundSystem; 23 | import de.lessvoid.nifty.spi.sound.SoundDevice; 24 | import de.lessvoid.nifty.spi.sound.SoundHandle; 25 | import de.lessvoid.nifty.tools.resourceloader.NiftyResourceLoader; 26 | 27 | /** 28 | * NiftySoundDevice represent implementation of {@link SoundDevice}. 29 | */ 30 | public final class NiftySoundDevice implements SoundDevice { 31 | /** 32 | * {@inheritDoc} 33 | */ 34 | @Override 35 | public void setResourceLoader(NiftyResourceLoader niftyResourceLoader) { 36 | //! 37 | //! NOTE: No need to implement this method. 38 | //! 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | @Override 45 | public SoundHandle loadSound(SoundSystem soundSystem, String filename) { 46 | return new NiftySoundHandle(Quark.QKResources.load(filename, new Audio.Descriptor(false))); 47 | } 48 | 49 | /** 50 | * {@inheritDoc} 51 | */ 52 | @Override 53 | public SoundHandle loadMusic(SoundSystem soundSystem, String filename) { 54 | return new NiftySoundHandle(Quark.QKResources.load(filename, new Audio.Descriptor(true))); 55 | } 56 | 57 | /** 58 | * {@inheritDoc} 59 | */ 60 | @Override 61 | public void update(int delta) { 62 | //! 63 | //! NOTE: No need to implement this method. 64 | //! 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/data/UniformFloat2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader.data; 19 | 20 | import ar.com.quark.mathematic.MutableVector2f; 21 | import ar.com.quark.mathematic.Vector2f; 22 | import ar.com.quark.render.shader.UniformType; 23 | import ar.com.quark.render.shader.Uniform; 24 | 25 | /** 26 | * UniformFloat2 encapsulate an {@link Uniform} for {@link UniformType#Float2}. 27 | */ 28 | public final class UniformFloat2 extends Uniform { 29 | private final MutableVector2f mValue = MutableVector2f.zero(); 30 | 31 | /** 32 | *

Constructor

33 | */ 34 | public UniformFloat2(Vector2f value) { 35 | super(UniformType.Float2); 36 | setValue(value); 37 | } 38 | 39 | /** 40 | *

Get the value of the data

41 | * 42 | * @return the value of the data 43 | */ 44 | public Vector2f getValue() { 45 | return mValue; 46 | } 47 | 48 | /** 49 | *

Change the value of the data

50 | * 51 | * @param newValue the new value of the data 52 | */ 53 | public void setValue(Vector2f newValue) { 54 | setValue(newValue.getX(), newValue.getY()); 55 | } 56 | 57 | /** 58 | *

Change the value of the data

59 | * 60 | * @param newX the new x value of the data 61 | * @param newY the new y value of the data 62 | */ 63 | public void setValue(float newX, float newY) { 64 | if (mValue.getX() != newX || mValue.getY() != newY) { 65 | mValue.setXY(newX, newY); 66 | setUpdate(CONCEPT_VALUE); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/system/utility/array/Int32Array.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.system.utility.array; 19 | 20 | /** 21 | * Specialised implementation of {@link Array} for 32-bit integer element(s). 22 | */ 23 | public interface Int32Array extends Array { 24 | /** 25 | * @see Array#writeInt32(int) 26 | */ 27 | default Int32Array write(int value) { 28 | return writeInt32(value); 29 | } 30 | 31 | /** 32 | * @see Array#writeInt32(int[]) 33 | */ 34 | default Int32Array write(int[] value) { 35 | writeInt32(value); 36 | return this; 37 | } 38 | 39 | /** 40 | * @see Array#writeInt32(int[], int, int) 41 | */ 42 | default Int32Array write(int[] value, int offset, int count) { 43 | writeInt32(value, offset, count); 44 | return this; 45 | } 46 | 47 | /** 48 | * @see Array#writeInt32(int, int) 49 | */ 50 | default Int32Array write(int index, int value) { 51 | return writeInt32(index * 0x04, value); 52 | } 53 | 54 | /** 55 | * @see Array#writeInt32(int[]) 56 | */ 57 | default Int32Array write(Int32Array array) { 58 | for (int i = 0, j = array.limit(); i < j; i += 0x04) { 59 | write(array.read()); 60 | } 61 | return this; 62 | } 63 | 64 | /** 65 | * @see Array#readInt32() 66 | */ 67 | default int read() { 68 | return readInt32(); 69 | } 70 | 71 | /** 72 | * @see Array#readInt32(int) 73 | */ 74 | default int read(int index) { 75 | return readInt32(index * 0x04); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/data/UniformUnsignedInt2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader.data; 19 | 20 | import ar.com.quark.render.shader.UniformType; 21 | import ar.com.quark.mathematic.Vector2i; 22 | import ar.com.quark.mathematic.MutableVector2i; 23 | import ar.com.quark.render.shader.Uniform; 24 | 25 | /** 26 | * UniformUnsignedInt2 encapsulate an {@link Uniform} for {@link UniformType#UInt2}. 27 | */ 28 | public final class UniformUnsignedInt2 extends Uniform { 29 | private final MutableVector2i mValue = MutableVector2i.zero(); 30 | 31 | /** 32 | *

Constructor

33 | */ 34 | public UniformUnsignedInt2(Vector2i value) { 35 | super(UniformType.UInt2); 36 | setValue(value); 37 | } 38 | 39 | /** 40 | *

Get the value of the data

41 | * 42 | * @return the value of the data 43 | */ 44 | public Vector2i getValue() { 45 | return mValue; 46 | } 47 | 48 | /** 49 | *

Change the value of the data

50 | * 51 | * @param newValue the new value of the data 52 | */ 53 | public void setValue(Vector2i newValue) { 54 | setValue(newValue.getX(), newValue.getY()); 55 | } 56 | 57 | /** 58 | *

Change the value of the data

59 | * 60 | * @param newX the new x value of the data 61 | * @param newY the new y value of the data 62 | */ 63 | public void setValue(int newX, int newY) { 64 | if (mValue.getX() != newX || mValue.getY() != newY) { 65 | mValue.setXY(newX, newY); 66 | setUpdate(CONCEPT_VALUE); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Quark-Extension/Quark-Extension-NiftyUI/src/main/java/ar/com/quark/extension/niftyui/NiftyCursor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.extension.niftyui; 19 | 20 | import ar.com.quark.render.texture.Texture; 21 | import de.lessvoid.nifty.spi.render.MouseCursor; 22 | 23 | import static ar.com.quark.Quark.QKDisplay; 24 | import static ar.com.quark.Quark.QKResources; 25 | 26 | /** 27 | * NiftyCursor represent implementation of {@link MouseCursor}. 28 | */ 29 | public final class NiftyCursor implements MouseCursor { 30 | private final Texture mTexture; 31 | 32 | /** 33 | * Hold the coordinate(s) of the cursor's hotspot. 34 | */ 35 | private final int mHotspotX, mHotspotY; 36 | 37 | /** 38 | *

Constructor

39 | */ 40 | public NiftyCursor(Texture texture, int xHotspot, int yHotspot) { 41 | mTexture = texture; 42 | 43 | mHotspotX = xHotspot; 44 | mHotspotY = yHotspot; 45 | } 46 | 47 | /** 48 | *

Get the underlying texture of the cursor

49 | * 50 | * @return the underlying texture of the cursor 51 | */ 52 | public Texture getTexture() { 53 | return mTexture; 54 | } 55 | 56 | /** 57 | * {@inheritDoc} 58 | */ 59 | @Override 60 | public void enable() { 61 | QKDisplay.setCursor(mTexture.getImage(), mHotspotX, mHotspotY); 62 | } 63 | 64 | /** 65 | * {@inheritDoc} 66 | */ 67 | @Override 68 | public void disable() { 69 | QKDisplay.setCursor(null, 0, 0); 70 | } 71 | 72 | /** 73 | * {@inheritDoc} 74 | */ 75 | @Override 76 | public void dispose() { 77 | QKResources.unload(mTexture); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/data/UniformInt3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader.data; 19 | 20 | import ar.com.quark.mathematic.Vector3i; 21 | import ar.com.quark.render.shader.Uniform; 22 | import ar.com.quark.render.shader.UniformType; 23 | import ar.com.quark.mathematic.MutableVector3i; 24 | 25 | /** 26 | * UniformInt3 encapsulate an {@link Uniform} for {@link UniformType#Int3}. 27 | */ 28 | public final class UniformInt3 extends Uniform { 29 | private final MutableVector3i mValue = MutableVector3i.zero(); 30 | 31 | /** 32 | *

Constructor

33 | */ 34 | public UniformInt3(Vector3i value) { 35 | super(UniformType.Int3); 36 | setValue(value); 37 | } 38 | 39 | /** 40 | *

Get the value of the data

41 | * 42 | * @return the value of the data 43 | */ 44 | public Vector3i getValue() { 45 | return mValue; 46 | } 47 | 48 | /** 49 | *

Change the value of the data

50 | * 51 | * @param newValue the new value of the data 52 | */ 53 | public void setValue(Vector3i newValue) { 54 | setValue(newValue.getX(), newValue.getY(), newValue.getZ()); 55 | } 56 | 57 | /** 58 | *

Change the value of the data

59 | * 60 | * @param newX the new x value of the data 61 | * @param newY the new y value of the data 62 | * @param newZ the new z value of the data 63 | */ 64 | public void setValue(int newX, int newY, int newZ) { 65 | if (mValue.getX() != newX || mValue.getY() != newY || mValue.getZ() != newZ) { 66 | mValue.setXYZ(newX, newY, newZ); 67 | setUpdate(CONCEPT_VALUE); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/data/UniformFloat3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader.data; 19 | 20 | import ar.com.quark.mathematic.MutableVector3f; 21 | import ar.com.quark.mathematic.Vector3f; 22 | import ar.com.quark.render.shader.Uniform; 23 | import ar.com.quark.render.shader.UniformType; 24 | 25 | /** 26 | * UniformFloat3 encapsulate an {@link Uniform} for {@link UniformType#Float3}. 27 | */ 28 | public final class UniformFloat3 extends Uniform { 29 | private final MutableVector3f mValue = MutableVector3f.zero(); 30 | 31 | /** 32 | *

Constructor

33 | */ 34 | public UniformFloat3(Vector3f value) { 35 | super(UniformType.Float3); 36 | setValue(value); 37 | } 38 | 39 | /** 40 | *

Get the value of the data

41 | * 42 | * @return the value of the data 43 | */ 44 | public Vector3f getValue() { 45 | return mValue; 46 | } 47 | 48 | /** 49 | *

Change the value of the data

50 | * 51 | * @param newValue the new value of the data 52 | */ 53 | public void setValue(Vector3f newValue) { 54 | setValue(newValue.getX(), newValue.getY(), newValue.getZ()); 55 | } 56 | 57 | /** 58 | *

Change the value of the data

59 | * 60 | * @param newX the new x value of the data 61 | * @param newY the new y value of the data 62 | * @param newZ the new z value of the data 63 | */ 64 | public void setValue(float newX, float newY, float newZ) { 65 | if (mValue.getX() != newX || mValue.getY() != newY || mValue.getZ() != newZ) { 66 | mValue.setXYZ(newX, newY, newZ); 67 | setUpdate(CONCEPT_VALUE); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/storage/StorageTarget.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.storage; 19 | 20 | import ar.com.quark.render.Render; 21 | 22 | /** 23 | * StorageTarget enumerate {@link Storage} target(s). 24 | */ 25 | public enum StorageTarget { 26 | /** 27 | * Represent a storage for vertices. 28 | */ 29 | ARRAY(Render.GLES2.GL_ARRAY_BUFFER), 30 | 31 | /** 32 | * Represent a storage for indices. 33 | */ 34 | ELEMENT(Render.GLES2.GL_ELEMENT_ARRAY_BUFFER), 35 | 36 | /** 37 | * Represent a storage for pixel data being sent to the GPU. 38 | */ 39 | PIXEL_PACK(Render.GLES3.GL_PIXEL_PACK_BUFFER), 40 | 41 | /** 42 | * Represent a storage for pixel data being read to the GPU. 43 | */ 44 | PIXEL_UNPACK(Render.GLES3.GL_PIXEL_UNPACK_BUFFER), 45 | 46 | /** 47 | * Represent a storage for results from executing a transform feedback shader. 48 | */ 49 | TRANSFORM_FEEDBACK(Render.GLES3.GL_TRANSFORM_FEEDBACK_BUFFER), 50 | 51 | /** 52 | * Represent a storage for data copied between storage. 53 | */ 54 | COPY_READ(Render.GLES3.GL_COPY_READ_BUFFER), 55 | 56 | /** 57 | * Represent a storage for data copied between storage. 58 | */ 59 | COPY_WRITE(Render.GLES3.GL_COPY_WRITE_BUFFER), 60 | 61 | /** 62 | * Represent a storage for data(s). 63 | */ 64 | UNIFORM(Render.GLES3.GL_UNIFORM_BUFFER), 65 | 66 | /** 67 | * Represent a storage for texture(s). 68 | */ 69 | TEXTURE(Render.GLES32.GL_TEXTURE_BUFFER); 70 | 71 | public final int eValue; 72 | 73 | /** 74 | *

Constructor

75 | */ 76 | StorageTarget(int value) { 77 | eValue = value; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/data/UniformUnsignedInt3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader.data; 19 | 20 | import ar.com.quark.render.shader.UniformType; 21 | import ar.com.quark.mathematic.MutableVector3i; 22 | import ar.com.quark.mathematic.Vector3i; 23 | import ar.com.quark.render.shader.Uniform; 24 | 25 | /** 26 | * UniformUnsignedInt3 encapsulate an {@link Uniform} for {@link UniformType#UInt3}. 27 | */ 28 | public final class UniformUnsignedInt3 extends Uniform { 29 | private final MutableVector3i mValue = MutableVector3i.zero(); 30 | 31 | /** 32 | *

Constructor

33 | */ 34 | public UniformUnsignedInt3(Vector3i value) { 35 | super(UniformType.UInt3); 36 | setValue(value); 37 | } 38 | 39 | /** 40 | *

Get the value of the data

41 | * 42 | * @return the value of the data 43 | */ 44 | public Vector3i getValue() { 45 | return mValue; 46 | } 47 | 48 | /** 49 | *

Change the value of the data

50 | * 51 | * @param newValue the new value of the data 52 | */ 53 | public void setValue(Vector3i newValue) { 54 | setValue(newValue.getX(), newValue.getY(), newValue.getZ()); 55 | } 56 | 57 | /** 58 | *

Change the value of the data

59 | * 60 | * @param newX the new x value of the data 61 | * @param newY the new y value of the data 62 | * @param newZ the new z value of the data 63 | */ 64 | public void setValue(int newX, int newY, int newZ) { 65 | if (mValue.getX() != newX || mValue.getY() != newY|| mValue.getZ() != newZ ) { 66 | mValue.setXYZ(newX, newY, newZ); 67 | setUpdate(CONCEPT_VALUE); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Quark-Extension/Quark-Extension-NiftyUI/src/main/java/ar/com/quark/extension/niftyui/NiftyRenderFont.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.extension.niftyui; 19 | 20 | import ar.com.quark.render.font.Font; 21 | import de.lessvoid.nifty.spi.render.RenderFont; 22 | 23 | import static ar.com.quark.Quark.QKResources; 24 | 25 | /** 26 | * NiftyRenderFont represent implementation of {@link RenderFont}. 27 | */ 28 | public final class NiftyRenderFont implements RenderFont { 29 | private final Font mFont; 30 | 31 | /** 32 | *

Constructor

33 | */ 34 | public NiftyRenderFont(Font font) { 35 | mFont = font; 36 | } 37 | 38 | /** 39 | *

Get the underlying font of the font

40 | * 41 | * @return the underlying font of the font 42 | */ 43 | public Font getFont() { 44 | return mFont; 45 | } 46 | 47 | /** 48 | * {@inheritDoc} 49 | */ 50 | @Override 51 | public int getWidth(String text) { 52 | return mFont.getWidth(text); 53 | } 54 | 55 | /** 56 | * {@inheritDoc} 57 | */ 58 | @Override 59 | public int getWidth(String text, float size) { 60 | return mFont.getWidth(text, size); 61 | } 62 | 63 | /** 64 | * {@inheritDoc} 65 | */ 66 | @Override 67 | public int getHeight() { 68 | return mFont.getHeight(); 69 | } 70 | 71 | /** 72 | * {@inheritDoc} 73 | */ 74 | @Override 75 | public int getCharacterAdvance(char currentCharacter, char nextCharacter, float size) { 76 | return mFont.getAdvance(currentCharacter, nextCharacter, size); 77 | } 78 | 79 | /** 80 | * {@inheritDoc} 81 | */ 82 | @Override 83 | public void dispose() { 84 | QKResources.unload(mFont); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/data/UniformInt4.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader.data; 19 | 20 | import ar.com.quark.render.shader.UniformType; 21 | import ar.com.quark.mathematic.Vector4i; 22 | import ar.com.quark.mathematic.MutableVector4i; 23 | import ar.com.quark.render.shader.Uniform; 24 | 25 | /** 26 | * UniformInt4 encapsulate an {@link Uniform} for {@link UniformType#Int4}. 27 | */ 28 | public final class UniformInt4 extends Uniform { 29 | private final MutableVector4i mValue = MutableVector4i.zero(); 30 | 31 | /** 32 | *

Default constructor

33 | */ 34 | public UniformInt4(Vector4i value) { 35 | super(UniformType.Int4); 36 | setValue(value); 37 | } 38 | 39 | /** 40 | *

Get the value of the data

41 | * 42 | * @return the value of the data 43 | */ 44 | public Vector4i getValue() { 45 | return mValue; 46 | } 47 | 48 | /** 49 | *

Change the value of the data

50 | * 51 | * @param newValue the new value of the data 52 | */ 53 | public void setValue(Vector4i newValue) { 54 | setValue(newValue.getX(), newValue.getY(), newValue.getZ(), newValue.getW()); 55 | } 56 | 57 | /** 58 | *

Change the value of the data

59 | * 60 | * @param newX the new x value of the data 61 | * @param newY the new y value of the data 62 | * @param newZ the new z value of the data 63 | * @param newW the new w value of the data 64 | */ 65 | public void setValue(int newX, int newY, int newZ, int newW) { 66 | if (mValue.getX() != newX || mValue.getY() != newY || mValue.getZ() != newZ || mValue.getW() != newW) { 67 | mValue.setXYZW(newX, newY, newZ, newW); 68 | setUpdate(CONCEPT_VALUE); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/data/UniformUnsignedInt4.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader.data; 19 | 20 | import ar.com.quark.mathematic.Vector4i; 21 | import ar.com.quark.render.shader.Uniform; 22 | import ar.com.quark.render.shader.UniformType; 23 | import ar.com.quark.mathematic.MutableVector4i; 24 | 25 | /** 26 | * UniformUnsignedInt4 encapsulate an {@link Uniform} for {@link UniformType#UInt4}. 27 | */ 28 | public final class UniformUnsignedInt4 extends Uniform { 29 | private final MutableVector4i mValue = MutableVector4i.zero(); 30 | 31 | /** 32 | *

Constructor

33 | */ 34 | public UniformUnsignedInt4(Vector4i value) { 35 | super(UniformType.UInt4); 36 | setValue(value); 37 | } 38 | 39 | /** 40 | *

Get the value of the data

41 | * 42 | * @return the value of the data 43 | */ 44 | public Vector4i getValue() { 45 | return mValue; 46 | } 47 | 48 | /** 49 | *

Change the value of the data

50 | * 51 | * @param newValue the new value of the data 52 | */ 53 | public void setValue(Vector4i newValue) { 54 | setValue(newValue.getX(), newValue.getY(), newValue.getZ(), newValue.getW()); 55 | } 56 | 57 | /** 58 | *

Change the value of the data

59 | * 60 | * @param newX the new x value of the data 61 | * @param newY the new y value of the data 62 | * @param newZ the new z value of the data 63 | * @param newW the new w value of the data 64 | */ 65 | public void setValue(int newX, int newY, int newZ, int newW) { 66 | if (mValue.getX() != newX || mValue.getY() != newY || mValue.getZ() != newZ || mValue.getW() != newW) { 67 | mValue.setXYZW(newX, newY, newZ, newW); 68 | setUpdate(CONCEPT_VALUE); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/audio/factory/FactoryStaticAudio.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.audio.factory; 19 | 20 | import ar.com.quark.audio.Audio; 21 | import ar.com.quark.audio.AudioFormat; 22 | import ar.com.quark.system.utility.Disposable; 23 | import ar.com.quark.system.utility.Manageable; 24 | import ar.com.quark.system.utility.array.ArrayFactory; 25 | import ar.com.quark.system.utility.array.Int8Array; 26 | 27 | import static ar.com.quark.Quark.QKAudio; 28 | 29 | /** 30 | * Specialised implementation for {@link Audio} that are being loaded at once. 31 | */ 32 | public final class FactoryStaticAudio extends Audio { 33 | /** 34 | * @apiNote [MUTABLE-DISPOSABLE] 35 | */ 36 | private Int8Array mData; 37 | 38 | /** 39 | *

Constructor

40 | */ 41 | public FactoryStaticAudio(Int8Array data, AudioFormat format, int duration, int rate) { 42 | super(format, duration, rate); 43 | mData = data; 44 | } 45 | 46 | /** 47 | *

Get the data of the audio

48 | * 49 | * @return the data of the audio 50 | */ 51 | public Int8Array getData() { 52 | return mData; 53 | } 54 | 55 | /** 56 | * {@inheritDoc} 57 | */ 58 | @Override 59 | public boolean isStreaming() { 60 | return false; 61 | } 62 | 63 | /** 64 | * @see Manageable#delete() 65 | */ 66 | @Override 67 | public void delete() { 68 | super.delete(); 69 | 70 | QKAudio.delete(this); 71 | } 72 | 73 | /** 74 | * @see Manageable#deleteAllMemory() 75 | */ 76 | @Override 77 | public void deleteAllMemory() { 78 | mData = ArrayFactory.free(mData); 79 | } 80 | 81 | /** 82 | * @see Disposable#dispose() 83 | */ 84 | @Override 85 | public void dispose() { 86 | QKAudio.delete(this); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/resource/loader/ShaderBinaryAssetLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.resource.loader; 19 | 20 | import ar.com.quark.render.RenderCapabilities; 21 | import ar.com.quark.render.shader.Shader; 22 | import ar.com.quark.render.shader.ShaderParser; 23 | import ar.com.quark.resource.AssetManager; 24 | import ar.com.quark.resource.AssetKey; 25 | import ar.com.quark.resource.AssetLoader; 26 | import ar.com.quark.system.utility.array.Int8Array; 27 | import ar.com.quark.system.utility.array.ArrayFactory; 28 | 29 | import java.io.IOException; 30 | import java.io.InputStream; 31 | 32 | /** 33 | * ShaderAssetLoader encapsulate an {@link AssetLoader} for loading shader(s). 34 | */ 35 | public final class ShaderBinaryAssetLoader implements AssetLoader { 36 | private final ShaderParser mParser; 37 | 38 | /** 39 | *

Constructor

40 | */ 41 | public ShaderBinaryAssetLoader(RenderCapabilities capabilities) { 42 | mParser = new ShaderParser(capabilities); 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | @Override 49 | public void load(AssetManager manager, AssetKey key, InputStream input) 50 | throws IOException { 51 | //! 52 | //! Allocate an array and load the entire content in it. 53 | //! 54 | final Int8Array content = ArrayFactory.allocateInt8Array(input.available()); 55 | 56 | byte[] bytes = new byte[1024]; 57 | 58 | while (input.available() > 0) { 59 | content.write(bytes, 0, input.read(bytes)); 60 | } 61 | 62 | //! 63 | //! Parse the shader. 64 | //! 65 | key.setAsset(mParser.generate(content)); 66 | 67 | //! 68 | //! Dispose the array. 69 | //! 70 | ArrayFactory.free(content); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/system/utility/emulation/Emulation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.system.utility.emulation; 19 | 20 | import java.util.Iterator; 21 | import java.util.Map; 22 | import java.util.function.BiConsumer; 23 | import java.util.function.Consumer; 24 | import java.util.function.Function; 25 | 26 | /** 27 | * Emulation encapsulate a helper to emulate multiple method(s) not being present on every platform. 28 | */ 29 | @SuppressWarnings("WhileLoopReplaceableByForEach") 30 | public class Emulation { 31 | /** 32 | * (NOT PRESENT IN TeaVM) 33 | */ 34 | public static > void forEachArrayIfNotNull(A[] iterator, B consumer) { 35 | for (final A item : iterator) { 36 | if (item != null) { 37 | consumer.accept(item); 38 | } 39 | } 40 | } 41 | 42 | /** 43 | * (NOT PRESENT IN TeaVM) 44 | */ 45 | public static > void forEach(Iterable
iterator, B consumer) { 46 | final Iterator it = iterator.iterator(); 47 | 48 | while (it.hasNext()) { 49 | consumer.accept(it.next()); 50 | } 51 | } 52 | 53 | /** 54 | * (NOT PRESENT IN TeaVM) 55 | */ 56 | public static > void forEach(Map map, C consumer) { 57 | for (final Map.Entry entry : map.entrySet()) { 58 | consumer.accept(entry.getKey(), entry.getValue()); 59 | } 60 | } 61 | 62 | /** 63 | * (NOT PRESENT IN TeaVM) 64 | */ 65 | public static int forEachMapToInt(Iterable iterator, Function consumer) { 66 | int value = 0; 67 | 68 | final Iterator it = iterator.iterator(); 69 | 70 | while (it.hasNext()) { 71 | value += consumer.apply(it.next()); 72 | } 73 | return value; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/mathematic/ImmutableVector3i.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.mathematic; 19 | 20 | /** 21 | * Represent an immutable {@linkplain Vector3i}. 22 | */ 23 | public final class ImmutableVector3i extends Vector3i { 24 | /** 25 | *

Default constructor

26 | */ 27 | public ImmutableVector3i(int x, int y, int z) { 28 | super(x, y, z); 29 | } 30 | 31 | /** 32 | *

Creates a new vector where each component value is 0

33 | * 34 | * @return a new vector 35 | */ 36 | public static ImmutableVector3i zero() { 37 | return new ImmutableVector3i(0, 0, 0); 38 | } 39 | 40 | /** 41 | *

Creates a new vector where each component value is 1

42 | * 43 | * @return a new vector 44 | */ 45 | public static ImmutableVector3i one() { 46 | return new ImmutableVector3i(1, 1, 1); 47 | } 48 | 49 | /** 50 | *

Creates a new vector of length one in the x-axis

51 | * 52 | * @return a new vector 53 | */ 54 | public static ImmutableVector3i unitX() { 55 | return new ImmutableVector3i(1, 0, 0); 56 | } 57 | 58 | /** 59 | *

Creates a new vector of length one in the y-axis

60 | * 61 | * @return a new vector 62 | */ 63 | public static ImmutableVector3i unitY() { 64 | return new ImmutableVector3i(0, 1, 0); 65 | } 66 | 67 | /** 68 | *

Creates a new vector of length one in the z-axis

69 | * 70 | * @return a new vector 71 | */ 72 | public static ImmutableVector3i unitZ() { 73 | return new ImmutableVector3i(0, 0, 1); 74 | } 75 | 76 | /** 77 | *

Creates a new vector of length minus one in the z-axis

78 | * 79 | * @return a new vector 80 | */ 81 | public static ImmutableVector3i unitNegativeZ() { 82 | return new ImmutableVector3i(0, 0, -1); 83 | } 84 | } -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/mathematic/ImmutableVector4i.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.mathematic; 19 | 20 | /** 21 | * Represent an immutable {@linkplain Vector4i}. 22 | */ 23 | public final class ImmutableVector4i extends Vector4i { 24 | /** 25 | *

Default constructor

26 | */ 27 | public ImmutableVector4i(int x, int y, int z, int w) { 28 | super(x, y, z, w); 29 | } 30 | 31 | /** 32 | *

Creates a new vector where each component value is 0

33 | * 34 | * @return a new vector 35 | */ 36 | public static ImmutableVector4i zero() { 37 | return new ImmutableVector4i(0, 0, 0, 0); 38 | } 39 | 40 | /** 41 | *

Creates a new vector where each component value is 1

42 | * 43 | * @return a new vector 44 | */ 45 | public static ImmutableVector4i one() { 46 | return new ImmutableVector4i(1, 1, 1, 1); 47 | } 48 | 49 | /** 50 | *

Creates a new vector of length one in the x-axis

51 | * 52 | * @return a new vector 53 | */ 54 | public static ImmutableVector4i unitX() { 55 | return new ImmutableVector4i(1, 0, 0, 0); 56 | } 57 | 58 | /** 59 | *

Creates a new vector of length one in the y-axis

60 | * 61 | * @return a new vector 62 | */ 63 | public static ImmutableVector4i unitY() { 64 | return new ImmutableVector4i(0, 1, 0, 0); 65 | } 66 | 67 | /** 68 | *

Creates a new vector of length one in the z-axis

69 | * 70 | * @return a new vector 71 | */ 72 | public static ImmutableVector4i unitZ() { 73 | return new ImmutableVector4i(0, 0, 1, 0); 74 | } 75 | 76 | /** 77 | *

Creates a new vector of length one in the w-axis

78 | * 79 | * @return a new vector 80 | */ 81 | public static ImmutableVector4i unitW() { 82 | return new ImmutableVector4i(0, 0, 0, 1); 83 | } 84 | } -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/Attribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader; 19 | 20 | /** 21 | * Attribute encapsulate an (input or output) {@link Stage} variable. 22 | */ 23 | public final class Attribute { 24 | /** 25 | * Define an input Attribute which is being used as source. 26 | */ 27 | public final static int MODE_INPUT = 0; 28 | 29 | /** 30 | * Define an output Attribute which is being used as destination. 31 | */ 32 | public final static int MODE_OUTPUT = 1; 33 | 34 | private final int mID; 35 | private final int mMode; 36 | private final AttributeType mType; 37 | 38 | /** 39 | *

Constructor

40 | */ 41 | public Attribute(int id, int mode, AttributeType type) { 42 | mID = id; 43 | mMode = mode; 44 | mType = type; 45 | } 46 | 47 | /** 48 | *

Get the unique identifier of the attribute

49 | * 50 | * @return the unique identifier of the attribute 51 | */ 52 | public int getID() { 53 | return mID; 54 | } 55 | 56 | /** 57 | *

Get the type of the attribute

58 | * 59 | * @return the type of the attribute 60 | */ 61 | public AttributeType getType() { 62 | return mType; 63 | } 64 | 65 | /** 66 | *

Check if the given attribute is being used as input

67 | * 68 | * @return true if the attribute is being used as input, false otherwise 69 | */ 70 | public boolean isInput() { 71 | return mMode == MODE_INPUT; 72 | } 73 | 74 | /** 75 | *

Check if the given attribute is being used as output

76 | * 77 | * @return true if the attribute is being used as output, false otherwise 78 | */ 79 | public boolean isOutput() { 80 | return mMode == MODE_OUTPUT; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/data/UniformMatrix3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader.data; 19 | 20 | import ar.com.quark.render.shader.Uniform; 21 | import ar.com.quark.render.shader.UniformType; 22 | import ar.com.quark.mathematic.Matrix3f; 23 | import ar.com.quark.mathematic.MutableMatrix3f; 24 | import ar.com.quark.system.utility.array.Float32Array; 25 | import ar.com.quark.system.utility.array.ArrayFactory; 26 | 27 | /** 28 | * UniformMatrix3 encapsulate an {@link Uniform} for {@link UniformType#Matrix3x3}. 29 | */ 30 | public final class UniformMatrix3 extends Uniform { 31 | private final Float32Array mBuffer = ArrayFactory.allocateFloat32Array(3 * 3); 32 | 33 | /** 34 | *

Constructor

35 | */ 36 | public UniformMatrix3() { 37 | super(UniformType.Matrix3x3); 38 | } 39 | 40 | /** 41 | *

Constructor

42 | */ 43 | public UniformMatrix3(Matrix3f matrix) { 44 | super(UniformType.Matrix3x3); 45 | matrix.store(mBuffer); 46 | 47 | setUpdate(CONCEPT_VALUE); 48 | } 49 | 50 | /** 51 | *

Get the value of the data

52 | * 53 | * @return the value of the data 54 | */ 55 | public Float32Array getValue() { 56 | return mBuffer; 57 | } 58 | 59 | /** 60 | *

Get the value of the data to the given matrix

61 | * 62 | * @param outValue the matrix to retrieve the value from 63 | * 64 | * @return the value of the data 65 | */ 66 | public MutableMatrix3f getValue(MutableMatrix3f outValue) { 67 | return outValue.set(mBuffer); 68 | } 69 | 70 | /** 71 | *

Change the value of the data

72 | * 73 | * @param newValue the new value of the data 74 | */ 75 | public void setValue(Matrix3f newValue) { 76 | mBuffer.rewind(); 77 | 78 | newValue.store(mBuffer); 79 | setUpdate(CONCEPT_VALUE); 80 | } 81 | } -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/data/UniformIntArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader.data; 19 | 20 | import ar.com.quark.render.shader.Uniform; 21 | import ar.com.quark.render.shader.UniformType; 22 | import ar.com.quark.system.utility.array.ArrayFactory; 23 | import ar.com.quark.system.utility.array.Int32Array; 24 | 25 | /** 26 | * UniformIntArray encapsulate an {@link Uniform} for {@link UniformType#IntArray}. 27 | */ 28 | public final class UniformIntArray extends Uniform { 29 | private final Int32Array mValue; 30 | 31 | /** 32 | *

Constructor from a buffer

33 | */ 34 | public UniformIntArray(Int32Array buffer) { 35 | super(UniformType.IntArray); 36 | mValue = buffer; 37 | 38 | setUpdate(CONCEPT_VALUE); 39 | } 40 | 41 | /** 42 | *

Constructor

43 | */ 44 | public UniformIntArray(int capacity) { 45 | this(ArrayFactory.allocateInt32Array(capacity)); 46 | } 47 | 48 | /** 49 | *

Get the value of the data

50 | * 51 | * @return the value of the data 52 | */ 53 | public Int32Array getValue() { 54 | return mValue; 55 | } 56 | 57 | /** 58 | *

Change the value of the data

59 | * 60 | * @param newValue the new value of the data from an array 61 | */ 62 | public void setValue(int[] newValue) { 63 | setValue(newValue, 0, newValue.length); 64 | } 65 | 66 | /** 67 | *

Change the value of the data

68 | * 69 | * @param newValue the new value of the data from an array 70 | * @param offset the source offset of the newValue 71 | * @param length the source length of the newValue 72 | */ 73 | public void setValue(int[] newValue, int offset, int length) { 74 | mValue.rewind(); 75 | mValue.write(newValue, offset, length); 76 | setUpdate(CONCEPT_VALUE); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Quark-Extension/Quark-Extension-NiftyUI/src/main/java/ar/com/quark/extension/niftyui/NiftySoundHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.extension.niftyui; 19 | 20 | import de.lessvoid.nifty.spi.sound.SoundHandle; 21 | import ar.com.quark.audio.Audio; 22 | import ar.com.quark.audio.AudioSource; 23 | 24 | import static ar.com.quark.Quark.QKResources; 25 | 26 | /** 27 | * NiftySoundHandle represent implementation of {@link SoundHandle}. 28 | */ 29 | public final class NiftySoundHandle implements SoundHandle { 30 | private final Audio mAudio; 31 | 32 | /** 33 | * Hold the source of the audio. 34 | */ 35 | private final AudioSource mSource = new AudioSource(); 36 | 37 | /** 38 | * Hold a flag that indicates the audio is being played. 39 | */ 40 | private boolean mPlaying = false; 41 | 42 | /** 43 | *

Constructor

44 | */ 45 | public NiftySoundHandle(Audio audio) { 46 | mAudio = audio; 47 | } 48 | 49 | /** 50 | * {@inheritDoc} 51 | */ 52 | @Override 53 | public void play() { 54 | mSource.play(mAudio); 55 | mPlaying = true; 56 | } 57 | 58 | /** 59 | * {@inheritDoc} 60 | */ 61 | @Override 62 | public void stop() { 63 | mSource.stop(); 64 | mPlaying = false; 65 | } 66 | 67 | /** 68 | * {@inheritDoc} 69 | */ 70 | @Override 71 | public void setVolume(float volume) { 72 | mSource.setVolume(volume); 73 | } 74 | 75 | /** 76 | * {@inheritDoc} 77 | */ 78 | @Override 79 | public float getVolume() { 80 | return mSource.getVolume(); 81 | } 82 | 83 | /** 84 | * {@inheritDoc} 85 | */ 86 | @Override 87 | public boolean isPlaying() { 88 | return mPlaying; 89 | } 90 | 91 | /** 92 | * {@inheritDoc} 93 | */ 94 | @Override 95 | public void dispose() { 96 | QKResources.unload(mAudio); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/data/UniformFloatArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader.data; 19 | 20 | import ar.com.quark.render.shader.UniformType; 21 | import ar.com.quark.render.shader.Uniform; 22 | import ar.com.quark.system.utility.array.Float32Array; 23 | import ar.com.quark.system.utility.array.ArrayFactory; 24 | 25 | /** 26 | * UniformFloatArray encapsulate an {@link Uniform} for {@link UniformType#FloatArray}. 27 | */ 28 | public final class UniformFloatArray extends Uniform { 29 | private final Float32Array mValue; 30 | 31 | /** 32 | *

Constructor

33 | */ 34 | public UniformFloatArray(Float32Array buffer) { 35 | super(UniformType.FloatArray); 36 | mValue = buffer; 37 | 38 | setUpdate(CONCEPT_VALUE); 39 | } 40 | 41 | /** 42 | *

Constructor

43 | */ 44 | public UniformFloatArray(int capacity) { 45 | this(ArrayFactory.allocateFloat32Array(capacity)); 46 | } 47 | 48 | /** 49 | *

Get the value of the data

50 | * 51 | * @return the value of the data 52 | */ 53 | public Float32Array getValue() { 54 | return mValue; 55 | } 56 | 57 | /** 58 | *

Change the value of the data

59 | * 60 | * @param newValue the new value of the data from an array 61 | */ 62 | public void setValue(float[] newValue) { 63 | setValue(newValue, 0, newValue.length); 64 | } 65 | 66 | /** 67 | *

Change the value of the data

68 | * 69 | * @param newValue the new value of the data from an array 70 | * @param offset the source offset of the newValue 71 | * @param length the source length of the newValue 72 | */ 73 | public void setValue(float[] newValue, int offset, int length) { 74 | mValue.rewind(); 75 | mValue.write(newValue, offset, length); 76 | setUpdate(CONCEPT_VALUE); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/data/UniformMatrix4.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader.data; 19 | 20 | import ar.com.quark.mathematic.Matrix4f; 21 | import ar.com.quark.render.shader.UniformType; 22 | import ar.com.quark.render.shader.Uniform; 23 | import ar.com.quark.system.utility.array.Float32Array; 24 | import ar.com.quark.mathematic.MutableMatrix4f; 25 | import ar.com.quark.system.utility.array.ArrayFactory; 26 | 27 | /** 28 | * UniformMatrix4 encapsulate an {@link Uniform} for {@link UniformType#Matrix4x4}. 29 | */ 30 | public final class UniformMatrix4 extends Uniform { 31 | private final Float32Array mBuffer = ArrayFactory.allocateFloat32Array(4 * 4); 32 | 33 | /** 34 | *

Constructor

35 | */ 36 | public UniformMatrix4() { 37 | super(UniformType.Matrix4x4); 38 | } 39 | 40 | /** 41 | *

Constructor

42 | */ 43 | public UniformMatrix4(Matrix4f matrix) { 44 | super(UniformType.Matrix4x4); 45 | matrix.store(mBuffer); 46 | 47 | setUpdate(CONCEPT_VALUE); 48 | } 49 | 50 | /** 51 | *

Get the value of the data

52 | * 53 | * @return the value of the data 54 | */ 55 | public Float32Array getValue() { 56 | return mBuffer; 57 | } 58 | 59 | /** 60 | *

Get the value of the data to the given Matrix3f

61 | * 62 | * @param outValue the Matrix3f to retrieve the value from 63 | * 64 | * @return the value of the data 65 | */ 66 | public MutableMatrix4f getValue(MutableMatrix4f outValue) { 67 | return outValue.set(mBuffer); 68 | } 69 | 70 | /** 71 | *

Change the value of the data

72 | * 73 | * @param newValue the new value of the data 74 | */ 75 | public void setValue(Matrix4f newValue) { 76 | mBuffer.rewind(); 77 | 78 | newValue.store(mBuffer); 79 | 80 | setUpdate(CONCEPT_VALUE); 81 | } 82 | } -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/texture/Texture2D.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.texture; 19 | 20 | /** 21 | * Texture2D encapsulate a {@link Texture} of 2 dimension. 22 | */ 23 | public final class Texture2D extends Texture { 24 | protected TextureBorder mBorderX = TextureBorder.REPEAT; 25 | protected TextureBorder mBorderY = TextureBorder.REPEAT; 26 | 27 | /** 28 | *

Constructor

29 | */ 30 | public Texture2D(TextureFormat format, Image image) { 31 | super(TextureType.TEXTURE_2D, format, image); 32 | } 33 | 34 | /** 35 | *

Constructor

36 | */ 37 | public Texture2D(TextureFormat format, TextureFilter filter, 38 | TextureBorder borderX, 39 | TextureBorder borderY, Image image) { 40 | this(format, image); 41 | setFilter(filter); 42 | setClamp(borderX, borderY); 43 | } 44 | 45 | /** 46 | *

Change the border mode for the x and y coordinate

47 | * 48 | * @param xBorder the new border mode for the x coordinate 49 | * @param yBorder the new border mode for the y coordinate 50 | */ 51 | public void setClamp(TextureBorder xBorder, TextureBorder yBorder) { 52 | if (mBorderX != xBorder) { 53 | mBorderX = xBorder; 54 | setUpdate(CONCEPT_CLAMP_X); 55 | } 56 | if (mBorderY != yBorder) { 57 | mBorderY = yBorder; 58 | setUpdate(CONCEPT_CLAMP_Y); 59 | } 60 | } 61 | 62 | /** 63 | *

Get the border mode for the x coordinate

64 | * 65 | * @return the border mode for the x coordinate 66 | */ 67 | public TextureBorder getBorderX() { 68 | return mBorderX; 69 | } 70 | 71 | /** 72 | *

Get the border mode for the y coordinate

73 | * 74 | * @return the border mode for the y coordinate 75 | */ 76 | public TextureBorder getBorderY() { 77 | return mBorderY; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/data/UniformUnsignedIntArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader.data; 19 | 20 | import ar.com.quark.render.shader.Uniform; 21 | import ar.com.quark.render.shader.UniformType; 22 | import ar.com.quark.system.utility.array.ArrayFactory; 23 | import ar.com.quark.system.utility.array.UInt32Array; 24 | 25 | /** 26 | * UniformUnsignedIntArray encapsulate an {@link Uniform} for {@link UniformType#UIntArray}. 27 | */ 28 | public final class UniformUnsignedIntArray extends Uniform { 29 | private final UInt32Array mValue; 30 | 31 | /** 32 | *

Constructor

33 | */ 34 | public UniformUnsignedIntArray(UInt32Array buffer) { 35 | super(UniformType.UIntArray); 36 | mValue = buffer; 37 | 38 | setUpdate(CONCEPT_VALUE); 39 | } 40 | 41 | /** 42 | *

Constructor

43 | */ 44 | public UniformUnsignedIntArray(int capacity) { 45 | this(ArrayFactory.allocateUInt32Array(capacity)); 46 | } 47 | 48 | /** 49 | *

Get the value of the data

50 | * 51 | * @return the value of the data 52 | */ 53 | public UInt32Array getValue() { 54 | return mValue; 55 | } 56 | 57 | /** 58 | *

Change the value of the data

59 | * 60 | * @param newValue the new value of the data from an array 61 | */ 62 | public void setValue(long[] newValue) { 63 | setValue(newValue, 0, newValue.length); 64 | } 65 | 66 | /** 67 | *

Change the value of the data

68 | * 69 | * @param newValue the new value of the data from an array 70 | * @param offset the source offset of the newValue 71 | * @param length the source length of the newValue 72 | */ 73 | public void setValue(long[] newValue, int offset, int length) { 74 | mValue.rewind(); 75 | mValue.write(newValue, offset, length); 76 | setUpdate(CONCEPT_VALUE); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/storage/StorageMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.storage; 19 | 20 | import ar.com.quark.render.Render; 21 | 22 | /** 23 | * StorageMode enumerate {@link Storage} mode(s). 24 | */ 25 | public enum StorageMode { 26 | /** 27 | * The data store contents are modified repeatedly. 28 | */ 29 | DYNAMIC_DRAW(Render.GLES2.GL_DYNAMIC_DRAW, false, true), 30 | 31 | /** 32 | * The data store contents are queried repeatedly. 33 | */ 34 | DYNAMIC_READ(Render.GLES3.GL_DYNAMIC_READ, true, false), 35 | 36 | /** 37 | * The data store contents are copy between storage repeatedly. 38 | */ 39 | DYNAMIC_COPY(Render.GLES3.GL_DYNAMIC_COPY, false, false), 40 | 41 | /** 42 | * The data store contents is modified once. 43 | */ 44 | STATIC_DRAW(Render.GLES2.GL_STATIC_DRAW, false, true), 45 | 46 | /** 47 | * The data store contents is queried once. 48 | */ 49 | STATIC_READ(Render.GLES3.GL_STATIC_READ, true, false), 50 | 51 | /** 52 | * The data store contents are copy between storage once. 53 | */ 54 | STATIC_COPY(Render.GLES3.GL_STATIC_COPY, false, false), 55 | 56 | /** 57 | * The data store contents are modified frequently. 58 | */ 59 | STREAM_DRAW(Render.GLES2.GL_STREAM_DRAW, false, true), 60 | 61 | /** 62 | * The data store contents are queried frequently. 63 | */ 64 | STREAM_READ(Render.GLES3.GL_STREAM_READ, true, false), 65 | 66 | /** 67 | * The data store contents are copy between storage frequently. 68 | */ 69 | STREAM_COPY(Render.GLES3.GL_STREAM_COPY, false, false); 70 | 71 | public final int eValue; 72 | public final boolean eReadable; 73 | public final boolean eWritable; 74 | 75 | /** 76 | *

Constructor

77 | */ 78 | StorageMode(int value, boolean readable, boolean writable) { 79 | eValue = value; 80 | eReadable = readable; 81 | eWritable = writable; 82 | } 83 | } -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/storage/factory/FactoryElementStorage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.storage.factory; 19 | 20 | import ar.com.quark.render.storage.*; 21 | import ar.com.quark.system.utility.array.UInt8Array; 22 | import ar.com.quark.system.utility.array.Array; 23 | import ar.com.quark.system.utility.array.UInt16Array; 24 | import ar.com.quark.system.utility.array.UInt32Array; 25 | 26 | /** 27 | * Specialised implementation for {@link StorageTarget#ELEMENT}. 28 | */ 29 | public class FactoryElementStorage
> extends Storage { 30 | /** 31 | *

Constructor

32 | */ 33 | public FactoryElementStorage(StorageType type, StorageMode mode, VertexFormat format, int capacity) { 34 | super(type, StorageTarget.ELEMENT, mode, format, capacity); 35 | } 36 | 37 | /** 38 | * Specialised implementation using {@link UInt8Array}. 39 | */ 40 | public final static class UInt8 extends FactoryElementStorage { 41 | /** 42 | *

Constructor

43 | */ 44 | public UInt8(StorageType type, StorageMode mode, int capacity) { 45 | super(type, mode, VertexFormat.UNSIGNED_BYTE, capacity); 46 | } 47 | } 48 | 49 | /** 50 | * Specialised implementation using {@link UInt16Array}. 51 | */ 52 | public final static class UInt16 extends FactoryElementStorage { 53 | /** 54 | *

Constructor

55 | */ 56 | public UInt16(StorageType type, StorageMode mode, int capacity) { 57 | super(type, mode, VertexFormat.UNSIGNED_SHORT, capacity); 58 | } 59 | } 60 | 61 | /** 62 | * Specialised implementation using {@link UInt32Array}. 63 | */ 64 | public final static class UInt32 extends FactoryElementStorage { 65 | /** 66 | *

Constructor

67 | */ 68 | public UInt32(StorageType type, StorageMode mode, int capacity) { 69 | super(type, mode, VertexFormat.UNSIGNED_INT, capacity); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/shader/data/UniformFloat4.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.shader.data; 19 | 20 | import ar.com.quark.render.shader.UniformType; 21 | import ar.com.quark.mathematic.Quaternionf; 22 | import ar.com.quark.mathematic.Vector4f; 23 | import ar.com.quark.mathematic.MutableVector4f; 24 | import ar.com.quark.render.shader.Uniform; 25 | 26 | /** 27 | * UniformFloat4 encapsulate an {@link Uniform} for {@link UniformType#Float4}. 28 | */ 29 | public final class UniformFloat4 extends Uniform { 30 | private final MutableVector4f mValue = MutableVector4f.zero(); 31 | 32 | /** 33 | *

Constructor

34 | */ 35 | public UniformFloat4(Vector4f value) { 36 | super(UniformType.Float4); 37 | setValue(value); 38 | } 39 | 40 | /** 41 | *

Get the value of the data

42 | * 43 | * @return the value of the data 44 | */ 45 | public Vector4f getValue() { 46 | return mValue; 47 | } 48 | 49 | /** 50 | *

Change the value of the data

51 | * 52 | * @param newValue the new value of the data 53 | */ 54 | public void setValue(Vector4f newValue) { 55 | setValue(newValue.getX(), newValue.getY(), newValue.getZ(), newValue.getW()); 56 | } 57 | 58 | /** 59 | *

Change the value of the data

60 | * 61 | * @param newValue the new value of the data 62 | */ 63 | public void setValue(Quaternionf newValue) { 64 | setValue(newValue.getX(), newValue.getY(), newValue.getZ(), newValue.getW()); 65 | } 66 | 67 | /** 68 | *

Change the value of the data

69 | * 70 | * @param newX the new x value of the data 71 | * @param newY the new y value of the data 72 | * @param newZ the new z value of the data 73 | * @param newW the new w value of the data 74 | */ 75 | public void setValue(float newX, float newY, float newZ, float newW) { 76 | if (mValue.getX() != newX || mValue.getY() != newY || mValue.getZ() != newZ || mValue.getW() != newW) { 77 | mValue.setXYZW(newX, newY, newZ, newW); 78 | setUpdate(CONCEPT_VALUE); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/resource/locator/FilesAssetLocator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.resource.locator; 19 | 20 | import ar.com.quark.resource.AssetCallback; 21 | import ar.com.quark.resource.AssetLocator; 22 | 23 | import java.io.IOException; 24 | import java.io.InputStream; 25 | import java.nio.file.*; 26 | 27 | /** 28 | * Encapsulate an {@link AssetLocator} that search asset(s) using {@link FileSystem}. 29 | */ 30 | public final class FilesAssetLocator implements AssetLocator { 31 | private final FileSystem mFilesystem; 32 | 33 | /** 34 | *

Constructor

35 | */ 36 | public FilesAssetLocator() { 37 | mFilesystem = FileSystems.getDefault(); 38 | } 39 | 40 | /** 41 | *

Constructor

42 | */ 43 | public FilesAssetLocator(Path location) { 44 | try { 45 | mFilesystem = FileSystems.newFileSystem(location, null); 46 | } catch (IOException exception) { 47 | throw new IllegalStateException(exception); 48 | } 49 | } 50 | 51 | /** 52 | * {@inheritDoc} 53 | */ 54 | @Override 55 | public boolean isSynchronousSupported() { 56 | return true; 57 | } 58 | 59 | /** 60 | * {@inheritDoc} 61 | */ 62 | @Override 63 | public boolean isAsynchronousSupported() { 64 | return true; 65 | } 66 | 67 | /** 68 | * {@inheritDoc} 69 | */ 70 | @Override 71 | public InputStream locate(String filename) { 72 | final Path child = mFilesystem.getPath(filename); 73 | 74 | if (Files.exists(child) && Files.isReadable(child)) { 75 | try { 76 | return Files.newInputStream(child, StandardOpenOption.READ); 77 | } catch (IOException ignored) { 78 | } 79 | } 80 | return null; 81 | } 82 | 83 | /** 84 | * {@inheritDoc} 85 | */ 86 | @Override 87 | public InputStream locate(String filename, AssetCallback callback) { 88 | final InputStream input = locate(filename); 89 | 90 | if (input != null) { 91 | callback.onSuccess(input); 92 | } else { 93 | callback.onFail(); 94 | } 95 | return input; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/mathematic/ImmutableVector2f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.mathematic; 19 | 20 | /** 21 | * Represent an immutable {@linkplain Vector2f}. 22 | */ 23 | public final class ImmutableVector2f extends Vector2f { 24 | /** 25 | *

Default constructor

26 | */ 27 | public ImmutableVector2f(float x, float y) { 28 | super(x, y); 29 | } 30 | 31 | /** 32 | *

Creates a new vector where each component value is 0.0f

33 | * 34 | * @return a new vector 35 | */ 36 | public static ImmutableVector2f zero() { 37 | return new ImmutableVector2f(0.0f, 0.0f); 38 | } 39 | 40 | /** 41 | *

Creates a new vector where each component value is 1.0f

42 | * 43 | * @return a new vector 44 | */ 45 | public static ImmutableVector2f one() { 46 | return new ImmutableVector2f(1.0f, 1.0f); 47 | } 48 | 49 | /** 50 | *

Creates a new vector of length one in the x-axis

51 | * 52 | * @return a new vector 53 | */ 54 | public static ImmutableVector2f unitX() { 55 | return new ImmutableVector2f(1.0f, 0.0f); 56 | } 57 | 58 | /** 59 | *

Creates a new vector of length one in the y-axis

60 | * 61 | * @return a new vector 62 | */ 63 | public static ImmutableVector2f unitY() { 64 | return new ImmutableVector2f(0.0f, 1.0f); 65 | } 66 | 67 | /** 68 | *

Creates a new vector where each component value is {@link Float#NaN}

69 | * 70 | * @return a new vector 71 | */ 72 | public static ImmutableVector2f nan() { 73 | return new ImmutableVector2f(Float.NaN, Float.NaN); 74 | } 75 | 76 | /** 77 | *

Creates a new vector where each component value is {@link Float#POSITIVE_INFINITY}

78 | * 79 | * @return a new vector 80 | */ 81 | public static ImmutableVector2f positiveInfinity() { 82 | return new ImmutableVector2f(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY); 83 | } 84 | 85 | /** 86 | *

Creates a new vector where each component value is {@link Float#NEGATIVE_INFINITY}

87 | * 88 | * @return a new vector 89 | */ 90 | public static ImmutableVector2f negativeInfinity() { 91 | return new ImmutableVector2f(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY); 92 | } 93 | } -------------------------------------------------------------------------------- /Quark-Extension/Quark-Extension-NiftyUI/src/main/java/ar/com/quark/extension/niftyui/NiftyUI.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.extension.niftyui; 19 | 20 | import ar.com.quark.input.InputListener; 21 | import de.lessvoid.nifty.Nifty; 22 | import de.lessvoid.nifty.spi.time.impl.AccurateTimeProvider; 23 | 24 | import java.lang.reflect.Field; 25 | 26 | /** 27 | * NiftyUI encapsulate all nifty-gui component(s). 28 | */ 29 | public final class NiftyUI extends Nifty { 30 | private NiftyRenderDevice mNiftyRenderDevice = null; 31 | 32 | /** 33 | *

Constructor

34 | */ 35 | public NiftyUI(InputListener listener) { 36 | super( 37 | new NiftyRenderDevice(), 38 | new NiftySoundDevice(), 39 | new NiftyInputSystem(listener), 40 | new AccurateTimeProvider()); 41 | 42 | //! 43 | //! Required to get the render device implementation. 44 | //! 45 | try { 46 | final Field field 47 | = getRenderEngine().getRenderDevice().getClass().getDeclaredField("internal"); 48 | field.setAccessible(true); 49 | mNiftyRenderDevice = (NiftyRenderDevice) field.get(getRenderEngine().getRenderDevice()); 50 | } catch (Throwable ignored) { 51 | } 52 | 53 | //! 54 | //! Register all resource(s) location for the extension. 55 | //! 56 | getResourceLoader().removeAllResourceLocations(); 57 | getResourceLoader().addResourceLocation(new NiftyResourceLocation()); 58 | } 59 | 60 | /** 61 | *

Notify {@link Nifty} to resize the viewport

62 | */ 63 | public void resize(int width, int height) { 64 | mNiftyRenderDevice.resize(width, height); 65 | } 66 | 67 | /** 68 | *

Notify {@link Nifty} to update and render the screen

69 | */ 70 | public void render() { 71 | render(true); 72 | } 73 | 74 | /** 75 | *

Notify {@link Nifty} to update and render the screen

76 | * 77 | * @param clear true if it should clear the screen, false otherwise 78 | */ 79 | public void render(boolean clear) { 80 | update(); 81 | 82 | //! 83 | //! Call the underlying method to render the screen. 84 | //! 85 | super.render(clear); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/storage/Primitive.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.storage; 19 | 20 | import ar.com.quark.render.Render; 21 | import ar.com.quark.render.shader.StageType; 22 | 23 | /** 24 | * Primitive enumerate all primitive(s). 25 | */ 26 | public enum Primitive { 27 | /** 28 | * Treats each vertex as a single point. VertexAttribute n defines point n. N points are drawn. 29 | */ 30 | POINTS(Render.GLES2.GL_POINTS), 31 | 32 | /** 33 | * Treats each pair of vertices as an independent line segment. 34 | */ 35 | LINES(Render.GLES2.GL_LINES), 36 | 37 | /** 38 | * Draws a connected group of line segments from the first vertex to the last, then back to the first. 39 | */ 40 | LINE_LOOP(Render.GLES2.GL_LINE_LOOP), 41 | 42 | /** 43 | * Draws a connected group of line segments from the first vertex to the last. 44 | */ 45 | LINE_STRIP(Render.GLES2.GL_LINE_STRIP), 46 | 47 | /** 48 | * Treats each triplet of vertices as an independent triangle. 49 | */ 50 | TRIANGLES(Render.GLES2.GL_TRIANGLES), 51 | 52 | /** 53 | * Draws a connected group of triangles. One triangle is defined for each vertex presented 54 | * after the first two vertices. 55 | */ 56 | TRIANGLE_FAN(Render.GLES2.GL_TRIANGLE_FAN), 57 | 58 | /** 59 | * Draws a connected group of triangles. One triangle is defined for each vertex presented 60 | * after the first two vertices. 61 | */ 62 | TRIANGLE_STRIP(Render.GLES2.GL_TRIANGLE_STRIP), 63 | 64 | /** 65 | * Expected to be used specifically with {@link StageType#GEOMETRY}. 66 | */ 67 | LINES_ADJACENCY(Render.GLES32.GL_LINES_ADJACENCY), 68 | 69 | /** 70 | * Expected to be used specifically with {@link StageType#GEOMETRY}. 71 | */ 72 | LINE_STRIP_ADJACENCY(Render.GLES32.GL_LINE_STRIP_ADJACENCY), 73 | 74 | /** 75 | * Expected to be used specifically with {@link StageType#GEOMETRY}. 76 | */ 77 | TRIANGLES_ADJACENCY(Render.GLES32.GL_TRIANGLES_ADJACENCY), 78 | 79 | /** 80 | * Expected to be used specifically with {@link StageType#GEOMETRY}. 81 | */ 82 | TRIANGLE_STRIP_ADJACENCY(Render.GLES32.GL_TRIANGLE_STRIP_ADJACENCY); 83 | 84 | public final int eValue; 85 | 86 | /** 87 | *

Constructor

88 | */ 89 | Primitive(int value) { 90 | eValue = value; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/texture/ImageFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.texture; 19 | 20 | import ar.com.quark.render.Render; 21 | 22 | /** 23 | * ImageFormat enumerate possible {@link Image} format(s). 24 | */ 25 | public enum ImageFormat { 26 | /** 27 | * Each element is an RED component. 28 | */ 29 | RED(Render.GLES3.GL_RED, 1, false, false, false, false), 30 | 31 | /** 32 | * Each element is an RGB triple. 33 | */ 34 | RGB(Render.GLES2.GL_RGB, 3, false, false, false, false), 35 | 36 | /** 37 | * Each element contains all four components. 38 | */ 39 | RGBA(Render.GLES2.GL_RGBA, 4, false, true, false, false), 40 | 41 | /** 42 | * Only contains the depth component. 43 | */ 44 | DEPTH_COMPONENT(Render.GLES3.GL_DEPTH_COMPONENT, 1, false, false, false, true), 45 | 46 | /** 47 | * Only contains the red and green component. 48 | */ 49 | RG(Render.GLES3.GL_RG, 2, false, false, false, false), 50 | 51 | /** 52 | * Only contains the stencil and depth component. 53 | */ 54 | DEPTH_STENCIL(Render.GLES3.GL_DEPTH_STENCIL, 2, false, false, true, true), 55 | 56 | /** 57 | * Compressed texture using S3TC for RGB. 58 | */ 59 | RGB_DXT1(Render.GLESExtension.S3TC_RGB_DXT1, 3, true, false, false, false), 60 | 61 | /** 62 | * Compressed texture using S3TC for RGBA. 63 | */ 64 | RGBA_DXT1(Render.GLESExtension.S3TC_RGBA_DXT1, 4, true, true, false, false), 65 | 66 | /** 67 | * Compressed texture using S3TC for RGBA. 68 | */ 69 | RGBA_DXT3(Render.GLESExtension.S3TC_RGBA_DXT3, 4, true, true, false, false), 70 | 71 | /** 72 | * Compressed texture using S3TC for RGBA. 73 | */ 74 | RGBA_DXT5(Render.GLESExtension.S3TC_RGBA_DXT5, 4, true, true, false, false); 75 | 76 | public final int eValue; 77 | public final int eComponent; 78 | public final boolean eCompressed; 79 | public final boolean eHasAlpha; 80 | public final boolean eHasDepth; 81 | public final boolean eHasStencil; 82 | 83 | /** 84 | *

Constructor

85 | */ 86 | ImageFormat(int value, int component, boolean compressed, boolean hasAlpha, boolean hasStencil, boolean hasDepth) { 87 | eValue = value; 88 | eComponent = component; 89 | eCompressed = compressed; 90 | eHasAlpha = hasAlpha; 91 | eHasDepth = hasStencil; 92 | eHasStencil = hasDepth; 93 | } 94 | } -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/input/device/InputKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.input.device; 19 | 20 | /** 21 | * InputKey enumerate(s) all key(s) for a keyboard based device. 22 | */ 23 | public enum InputKey { 24 | KEY_SPACE, 25 | KEY_APOSTROPHE, 26 | KEY_COMMA, 27 | KEY_MINUS, 28 | KEY_PERIOD, 29 | KEY_SLASH, 30 | KEY_0, 31 | KEY_1, 32 | KEY_2, 33 | KEY_3, 34 | KEY_4, 35 | KEY_5, 36 | KEY_6, 37 | KEY_7, 38 | KEY_8, 39 | KEY_9, 40 | KEY_SEMICOLON, 41 | KEY_EQUAL, 42 | KEY_A, 43 | KEY_B, 44 | KEY_C, 45 | KEY_D, 46 | KEY_E, 47 | KEY_F, 48 | KEY_G, 49 | KEY_H, 50 | KEY_I, 51 | KEY_J, 52 | KEY_K, 53 | KEY_L, 54 | KEY_M, 55 | KEY_N, 56 | KEY_O, 57 | KEY_P, 58 | KEY_Q, 59 | KEY_R, 60 | KEY_S, 61 | KEY_T, 62 | KEY_U, 63 | KEY_V, 64 | KEY_W, 65 | KEY_X, 66 | KEY_Y, 67 | KEY_Z, 68 | KEY_LEFT_BRACKET, 69 | KEY_BACKSLASH, 70 | KEY_RIGHT_BRACKET, 71 | KEY_GRAVE_ACCENT, 72 | KEY_ESCAPE, 73 | KEY_ENTER, 74 | KEY_TAB, 75 | KEY_BACKSPACE, 76 | KEY_INSERT, 77 | KEY_DELETE, 78 | KEY_RIGHT, 79 | KEY_LEFT, 80 | KEY_DOWN, 81 | KEY_UP, 82 | KEY_PAGE_UP, 83 | KEY_PAGE_DOWN, 84 | KEY_HOME, 85 | KEY_END, 86 | KEY_CAPS_LOCK, 87 | KEY_SCROLL_LOCK, 88 | KEY_NUM_LOCK, 89 | KEY_PRINT_SCREEN, 90 | KEY_PAUSE, 91 | KEY_F1, 92 | KEY_F2, 93 | KEY_F3, 94 | KEY_F4, 95 | KEY_F5, 96 | KEY_F6, 97 | KEY_F7, 98 | KEY_F8, 99 | KEY_F9, 100 | KEY_F10, 101 | KEY_F11, 102 | KEY_F12, 103 | KEY_KP_0, 104 | KEY_KP_1, 105 | KEY_KP_2, 106 | KEY_KP_3, 107 | KEY_KP_4, 108 | KEY_KP_5, 109 | KEY_KP_6, 110 | KEY_KP_7, 111 | KEY_KP_8, 112 | KEY_KP_9, 113 | KEY_KP_DECIMAL, 114 | KEY_KP_DIVIDE, 115 | KEY_KP_MULTIPLY, 116 | KEY_KP_SUBTRACT, 117 | KEY_KP_ADD, 118 | KEY_KP_ENTER, 119 | KEY_KP_EQUAL, 120 | KEY_LEFT_SHIFT, 121 | KEY_LEFT_CONTROL, 122 | KEY_LEFT_ALT, 123 | KEY_LEFT_SUPER, 124 | KEY_MENU, 125 | KEY_RIGHT_SHIFT, 126 | KEY_RIGHT_CONTROL, 127 | KEY_RIGHT_ALT, 128 | KEY_RIGHT_SUPER; 129 | 130 | /** 131 | * Hold all value(s). 132 | */ 133 | public final static InputKey[] VALUES = InputKey.values(); 134 | } 135 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/system/utility/array/ArrayInputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.system.utility.array; 19 | 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | 23 | /** 24 | * ArrayInputStream encapsulate an {@link InputStream} from {@link Int8Array}. 25 | */ 26 | public final class ArrayInputStream extends InputStream { 27 | private final Int8Array mArray; 28 | 29 | /** 30 | * Hold the mark position that the stream will be reset to. 31 | */ 32 | private int mMark; 33 | 34 | /** 35 | *

Constructor

36 | */ 37 | public ArrayInputStream(Int8Array array) { 38 | mArray = array; 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | @Override 45 | public int read() throws IOException { 46 | if (!mArray.hasRemaining()) { 47 | return -1; 48 | } 49 | return mArray.read() & 0xFF; 50 | } 51 | 52 | /** 53 | * {@inheritDoc} 54 | */ 55 | @Override 56 | public int read(byte[] bytes) throws IOException { 57 | return read(bytes, 0, bytes.length); 58 | } 59 | 60 | /** 61 | * {@inheritDoc} 62 | */ 63 | @Override 64 | public int read(byte[] bytes, int offset, int length) throws IOException { 65 | if (!mArray.hasRemaining()) { 66 | return -1; 67 | } 68 | return mArray.read(bytes, offset, length); 69 | } 70 | 71 | /** 72 | * {@inheritDoc} 73 | */ 74 | @Override 75 | public int available() throws IOException { 76 | return mArray.remaining(); 77 | } 78 | 79 | /** 80 | * {@inheritDoc} 81 | */ 82 | @Override 83 | public long skip(long count) throws IOException { 84 | final int skip = (int) (mArray.position() + count); 85 | 86 | mArray.position(skip); 87 | 88 | return skip; 89 | } 90 | 91 | /** 92 | * {@inheritDoc} 93 | */ 94 | @Override 95 | public void mark(int limit) { 96 | mMark = mArray.position(); 97 | } 98 | 99 | /** 100 | * {@inheritDoc} 101 | */ 102 | @Override 103 | public void reset() throws IOException { 104 | mArray.position(mMark); 105 | } 106 | 107 | /** 108 | * {@inheritDoc} 109 | */ 110 | @Override 111 | public boolean markSupported() { 112 | return true; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/texture/Texture3D.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.texture; 19 | 20 | /** 21 | * Texture3D encapsulate a {@link Texture} of 3 dimension. 22 | */ 23 | public final class Texture3D extends Texture { 24 | protected TextureBorder mBorderX = TextureBorder.REPEAT; 25 | protected TextureBorder mBorderY = TextureBorder.REPEAT; 26 | protected TextureBorder mBorderZ = TextureBorder.REPEAT; 27 | 28 | /** 29 | *

Constructor

30 | */ 31 | public Texture3D(TextureFormat format, Image image) { 32 | super(TextureType.TEXTURE_3D, format, image); 33 | } 34 | 35 | /** 36 | *

Constructor

37 | */ 38 | public Texture3D(TextureFormat format, TextureFilter filter, 39 | TextureBorder borderX, 40 | TextureBorder borderY, 41 | TextureBorder borderZ, Image image) { 42 | this(format, image); 43 | setFilter(filter); 44 | setClamp(borderX, borderY, borderZ); 45 | } 46 | 47 | /** 48 | *

Change the border mode for the x, y and z coordinate

49 | * 50 | * @param xBorder the new border mode for the x coordinate 51 | * @param yBorder the new border mode for the y coordinate 52 | * @param zBorder the new border mode for the z coordinate 53 | */ 54 | public void setClamp(TextureBorder xBorder, TextureBorder yBorder, TextureBorder zBorder) { 55 | if (mBorderX != xBorder) { 56 | mBorderX = xBorder; 57 | setUpdate(CONCEPT_CLAMP_X); 58 | } 59 | if (mBorderY != yBorder) { 60 | mBorderY = yBorder; 61 | setUpdate(CONCEPT_CLAMP_Y); 62 | } 63 | if (mBorderZ != zBorder) { 64 | mBorderZ = zBorder; 65 | setUpdate(CONCEPT_CLAMP_Z); 66 | } 67 | } 68 | 69 | /** 70 | *

Get the border mode for the x coordinate

71 | * 72 | * @return the border mode for the x coordinate 73 | */ 74 | public TextureBorder getBorderX() { 75 | return mBorderX; 76 | } 77 | 78 | /** 79 | *

Get the border mode for the y coordinate

80 | * 81 | * @return the border mode for the y coordinate 82 | */ 83 | public TextureBorder getBorderY() { 84 | return mBorderY; 85 | } 86 | 87 | /** 88 | *

Get the border mode for the z coordinate

89 | * 90 | * @return the border mode for the y coordinate 91 | */ 92 | public TextureBorder getBorderZ() { 93 | return mBorderZ; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/render/texture/Texture2DCube.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.render.texture; 19 | 20 | /** 21 | * Texture2DCube encapsulate a {@link Texture} of 2 dimension. 22 | */ 23 | public final class Texture2DCube extends Texture { 24 | protected TextureBorder mBorderX = TextureBorder.REPEAT; 25 | protected TextureBorder mBorderY = TextureBorder.REPEAT; 26 | protected TextureBorder mBorderZ = TextureBorder.REPEAT; 27 | 28 | /** 29 | *

Constructor

30 | */ 31 | public Texture2DCube(TextureFormat format, Image image) { 32 | super(TextureType.TEXTURE_CUBE, format, image); 33 | } 34 | 35 | /** 36 | *

Constructor

37 | */ 38 | public Texture2DCube(TextureFormat format, TextureFilter filter, 39 | TextureBorder borderX, 40 | TextureBorder borderY, 41 | TextureBorder borderZ, Image image) { 42 | this(format, image); 43 | setFilter(filter); 44 | setClamp(borderX, borderY, borderZ); 45 | } 46 | 47 | /** 48 | *

Change the border mode for the x, y and z coordinate

49 | * 50 | * @param xBorder the new border mode for the x coordinate 51 | * @param yBorder the new border mode for the y coordinate 52 | * @param zBorder the new border mode for the z coordinate 53 | */ 54 | public void setClamp(TextureBorder xBorder, TextureBorder yBorder, TextureBorder zBorder) { 55 | if (mBorderX != xBorder) { 56 | mBorderX = xBorder; 57 | setUpdate(CONCEPT_CLAMP_X); 58 | } 59 | if (mBorderY != yBorder) { 60 | mBorderY = yBorder; 61 | setUpdate(CONCEPT_CLAMP_Y); 62 | } 63 | if (mBorderZ != zBorder) { 64 | mBorderZ = zBorder; 65 | setUpdate(CONCEPT_CLAMP_Z); 66 | } 67 | } 68 | 69 | /** 70 | *

Get the border mode for the x coordinate

71 | * 72 | * @return the border mode for the x coordinate 73 | */ 74 | public TextureBorder getBorderX() { 75 | return mBorderX; 76 | } 77 | 78 | /** 79 | *

Get the border mode for the y coordinate

80 | * 81 | * @return the border mode for the y coordinate 82 | */ 83 | public TextureBorder getBorderY() { 84 | return mBorderY; 85 | } 86 | 87 | /** 88 | *

Get the border mode for the z coordinate

89 | * 90 | * @return the border mode for the y coordinate 91 | */ 92 | public TextureBorder getBorderZ() { 93 | return mBorderZ; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/input/device/InputMouse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.input.device; 19 | 20 | import ar.com.quark.input.Input; 21 | import ar.com.quark.system.utility.array.Int32Array; 22 | 23 | /** 24 | * InputMouse encapsulate an {@link Input} for handling mouse based device(s). 25 | */ 26 | public interface InputMouse extends Input { 27 | /** 28 | * Encapsulate the unique identifier for the mouse_move event. 29 | */ 30 | int EVENT_MOVE = 0x00000010; 31 | 32 | /** 33 | * Encapsulate the unique identifier for the button_up event. 34 | */ 35 | int EVENT_BUTTON_UP = EVENT_MOVE + 0x01; 36 | 37 | /** 38 | * Encapsulate the unique identifier for the button_down event. 39 | */ 40 | int EVENT_BUTTON_DOWN = EVENT_BUTTON_UP + 0x01; 41 | 42 | /** 43 | * Encapsulate the unique identifier for the wheel event. 44 | */ 45 | int EVENT_WHEEL = EVENT_BUTTON_DOWN + 0x01; 46 | 47 | /** 48 | *

Change the mode of the cursor

49 | *

50 | * NOTE: Activating the cursor mode will hide the cursor and provide unlimited move within the viewport. 51 | * 52 | * @param activate true to active the cursor mode, false otherwise 53 | */ 54 | void setCursorMode(boolean activate); 55 | 56 | /** 57 | *

Change the cursor position

58 | * 59 | * @param x the new x coordinate (in screen coordinates) of the cursor 60 | * @param y the new y coordinate (in screen coordinates) of the cursor 61 | */ 62 | void setCursorPosition(int x, int y); 63 | 64 | /** 65 | *

Queue a mouse move event

66 | * 67 | * @see #EVENT_MOVE 68 | */ 69 | static void onFactoryMove(Int32Array buffer, int x, int y) { 70 | buffer.write(EVENT_MOVE).write(x).write(y); 71 | } 72 | 73 | /** 74 | *

Queue a mouse button up event

75 | * 76 | * @see #EVENT_BUTTON_UP 77 | */ 78 | static void onFactoryButtonUp(Int32Array buffer, InputMouseButton button) { 79 | buffer.write(EVENT_BUTTON_UP).write(button.ordinal()); 80 | } 81 | 82 | /** 83 | *

Queue a mouse button down event

84 | * 85 | * @see #EVENT_BUTTON_DOWN 86 | */ 87 | static void onFactoryButtonDown(Int32Array buffer, InputMouseButton button) { 88 | buffer.write(EVENT_BUTTON_DOWN).write(button.ordinal()); 89 | } 90 | 91 | /** 92 | *

Queue a mouse wheel event

93 | * 94 | * @see #EVENT_WHEEL 95 | */ 96 | static void onFactoryWheel(Int32Array buffer, int delta) { 97 | buffer.write(EVENT_WHEEL).write(delta); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/audio/factory/FactoryStreamingAudio.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.audio.factory; 19 | 20 | import ar.com.quark.audio.Audio; 21 | import ar.com.quark.audio.AudioFormat; 22 | import ar.com.quark.system.utility.Disposable; 23 | import ar.com.quark.system.utility.Manageable; 24 | 25 | import java.io.BufferedInputStream; 26 | import java.io.IOException; 27 | import java.io.InputStream; 28 | 29 | import static ar.com.quark.Quark.QKAudio; 30 | 31 | /** 32 | * Specialised implementation for {@link Audio} that are being stream. 33 | */ 34 | public final class FactoryStreamingAudio extends Audio { 35 | private InputStream mData; 36 | 37 | /** 38 | *

Constructor

39 | */ 40 | public FactoryStreamingAudio(InputStream data, AudioFormat format, int duration, int rate) { 41 | super(format, duration, rate); 42 | 43 | mData = data.markSupported() ? data : new BufferedInputStream(data); 44 | mData.mark(Integer.MAX_VALUE); 45 | } 46 | 47 | /** 48 | *

Read audio's data from the {@link InputStream}

49 | * 50 | * @param buffer the target buffer 51 | * @param offset the target offset 52 | * @param length the target length 53 | * 54 | * @return the number of byte(s) read from the stream 55 | */ 56 | public int read(byte[] buffer, int offset, int length) { 57 | int bytes = 0; 58 | 59 | try { 60 | bytes = mData.read(buffer, offset, length); 61 | } catch (IOException ignored) { 62 | } 63 | return bytes; 64 | } 65 | 66 | /** 67 | *

Reset the stream

68 | */ 69 | public void reset() { 70 | try { 71 | mData.reset(); 72 | } catch (IOException ignored) { 73 | } 74 | } 75 | 76 | /** 77 | *

Close the stream

78 | */ 79 | public void close() { 80 | try { 81 | mData.close(); 82 | } catch (IOException ignored) { 83 | } 84 | } 85 | 86 | /** 87 | * {@inheritDoc} 88 | */ 89 | @Override 90 | public boolean isStreaming() { 91 | return true; 92 | } 93 | 94 | /** 95 | * @see Manageable#delete() 96 | */ 97 | @Override 98 | public void delete() { 99 | super.delete(); 100 | 101 | QKAudio.delete(this); 102 | } 103 | 104 | /** 105 | * @see Manageable#deleteAllMemory() 106 | */ 107 | @Override 108 | public void deleteAllMemory() { 109 | close(); 110 | 111 | mData = null; 112 | } 113 | 114 | /** 115 | * @see Disposable#dispose() 116 | */ 117 | @Override 118 | public void dispose() { 119 | QKAudio.delete(this); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/system/utility/Manageable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.system.utility; 19 | 20 | /** 21 | * Manageable encapsulate an manageable object. 22 | */ 23 | public abstract class Manageable { 24 | /** 25 | * Represent the invalid handle of a component. 26 | */ 27 | public final static int INVALID_HANDLE = 0; 28 | 29 | protected int mHandle; 30 | protected int mFlag; 31 | 32 | /** 33 | *

Constructor

34 | *

35 | * NOTE: Prevent constructing this class without implementation. 36 | */ 37 | protected Manageable() { 38 | } 39 | 40 | /** 41 | *

Handle when the object requires to delete

42 | */ 43 | public void delete() { 44 | deleteAllMemory(); 45 | } 46 | 47 | /** 48 | *

Handle when the object requires to delete bound memory (CPU-side memory)

49 | */ 50 | public void deleteAllMemory() { 51 | 52 | } 53 | 54 | /** 55 | *

Change the unique identifier of the component

56 | * 57 | * @param handle the new unique identifier of the component 58 | * 59 | * @return the previous unique identifier of the component 60 | */ 61 | public final int setHandle(int handle) { 62 | final int lastHandle = mHandle; 63 | mHandle = handle; 64 | return lastHandle; 65 | } 66 | 67 | /** 68 | *

Get the unique identifier of the component

69 | * 70 | * @return the unique identifier of the component 71 | */ 72 | public final int getHandle() { 73 | return mHandle; 74 | } 75 | 76 | /** 77 | *

Indicates the component has been updated

78 | */ 79 | public final void setUpdated() { 80 | mFlag = 0; 81 | } 82 | 83 | /** 84 | *

Indicates the component's concept given requires to update

85 | * 86 | * @param concept the concept that requires to update 87 | */ 88 | protected final void setUpdate(int concept) { 89 | mFlag |= concept; 90 | } 91 | 92 | /** 93 | *

Check if the component requires update

94 | * 95 | * @return true if the component requires update, false otherwise 96 | */ 97 | public final boolean hasUpdate() { 98 | return mFlag != 0; 99 | } 100 | 101 | /** 102 | *

Check if the component's concept given requires update

103 | * 104 | * @param concept the component's concept to be check 105 | * 106 | * @return true if the component's concept given requires update, false otherwise 107 | */ 108 | public final boolean hasUpdate(int concept) { 109 | return (mFlag & concept) != 0; 110 | } 111 | } -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/system/utility/array/UInt8Array.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.system.utility.array; 19 | 20 | /** 21 | * Specialised implementation of {@link Array} for unsigned 8-bit integer element(s). 22 | */ 23 | public interface UInt8Array extends Array { 24 | int SIGN_OFFSET = 0x10000; 25 | int MAX_POSITIVE = 0x7FFF; 26 | int MAX_NEGATIVE = 0xFFFF; 27 | 28 | /** 29 | * @see Array#writeInt8(int) 30 | */ 31 | default UInt8Array write(byte value) { 32 | return writeInt8(value); 33 | } 34 | 35 | /** 36 | * @see Array#writeInt8(int) 37 | */ 38 | default UInt8Array write(int value) { 39 | return writeInt8( 40 | (byte) (value > MAX_POSITIVE & value <= MAX_POSITIVE ? (value - SIGN_OFFSET) : value)); 41 | } 42 | 43 | /** 44 | * @see Array#writeInt8(byte[]) 45 | */ 46 | default UInt8Array write(byte[] value) { 47 | return write(value, 0, value.length); 48 | } 49 | 50 | /** 51 | * @see Array#writeInt8(byte[], int, int) 52 | */ 53 | default UInt8Array write(byte[] value, int offset, int count) { 54 | return writeInt8(value, offset, count); 55 | } 56 | 57 | /** 58 | * @see Array#writeInt8(byte[]) 59 | */ 60 | default UInt8Array write(int[] value) { 61 | return write(value, 0, value.length); 62 | } 63 | 64 | /** 65 | * @see Array#writeInt8(byte[], int, int) 66 | */ 67 | default UInt8Array write(int[] value, int offset, int count) { 68 | for (int i = offset, j = offset + count; i < j; i++) { 69 | final int element = value[i]; 70 | 71 | writeInt8((byte) (element > MAX_POSITIVE & element <= MAX_POSITIVE ? (element - SIGN_OFFSET) : element)); 72 | } 73 | return this; 74 | } 75 | 76 | /** 77 | * @see Array#writeInt8(int, int) 78 | */ 79 | default UInt8Array write(int index, byte value) { 80 | return writeInt8(index, value); 81 | } 82 | 83 | /** 84 | * @see Array#writeInt8(int, int) 85 | */ 86 | default UInt8Array write(int index, int value) { 87 | return writeInt8(index, 88 | (byte) (value > MAX_POSITIVE & value <= MAX_POSITIVE ? (value - SIGN_OFFSET) : value)); 89 | } 90 | 91 | /** 92 | * @see Array#readInt8() 93 | */ 94 | default int read() { 95 | final int number = readInt8(); 96 | 97 | return number < 0 ? number + SIGN_OFFSET : number; 98 | } 99 | 100 | /** 101 | * @see Array#readInt8(int) 102 | */ 103 | default int read(int index) { 104 | final int number = readInt8(index); 105 | 106 | return number < 0 ? number + SIGN_OFFSET : number; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/system/utility/array/UInt32Array.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.system.utility.array; 19 | 20 | /** 21 | * Specialised implementation of {@link Array} for unsigned 32-bit integer element(s). 22 | */ 23 | public interface UInt32Array extends Array { 24 | long SIGN_OFFSET = 0x100000000L; 25 | long MAX_POSITIVE = 0x7FFFFFFFL; 26 | long MAX_NEGATIVE = 0xFFFFFFFFL; 27 | 28 | /** 29 | * @see Array#writeInt32(int) 30 | */ 31 | default UInt32Array write(int value) { 32 | return writeInt32(value); 33 | } 34 | 35 | /** 36 | * @see Array#writeInt32(int) 37 | */ 38 | default UInt32Array write(long value) { 39 | return writeInt32((int) (value > MAX_POSITIVE & value <= MAX_POSITIVE ? (value - SIGN_OFFSET) : value)); 40 | } 41 | 42 | /** 43 | * @see Array#writeInt32(int[]) 44 | */ 45 | default UInt32Array write(int[] value) { 46 | return write(value, 0, value.length); 47 | } 48 | 49 | /** 50 | * @see Array#writeInt32(int[], int, int) 51 | */ 52 | default UInt32Array write(int[] value, int offset, int count) { 53 | return writeInt32(value, offset, count); 54 | } 55 | 56 | /** 57 | * @see Array#writeInt32(int[]) 58 | */ 59 | default UInt32Array write(long[] value) { 60 | return write(value, 0, value.length); 61 | } 62 | 63 | /** 64 | * @see Array#writeInt32(int[], int, int) 65 | */ 66 | default UInt32Array write(long[] value, int offset, int count) { 67 | for (int i = offset, j = offset + count; i < j; i++) { 68 | final long element = value[i]; 69 | 70 | writeInt32((int) (element > MAX_POSITIVE & element <= MAX_POSITIVE ? (element - SIGN_OFFSET) : element)); 71 | } 72 | return this; 73 | } 74 | 75 | /** 76 | * @see Array#writeInt32(int, int) 77 | */ 78 | default UInt32Array write(int index, int value) { 79 | return writeInt32(index * 0x04, value); 80 | } 81 | 82 | /** 83 | * @see Array#writeInt32(int, int) 84 | */ 85 | default UInt32Array write(int index, long value) { 86 | return writeInt32(index * 0x04, 87 | (int) (value > MAX_POSITIVE & value <= MAX_POSITIVE ? (value - SIGN_OFFSET) : value)); 88 | } 89 | 90 | /** 91 | * @see Array#readInt32() 92 | */ 93 | default long read() { 94 | final int number = readInt16(); 95 | 96 | return number < 0 ? number + SIGN_OFFSET : number; 97 | } 98 | 99 | /** 100 | * @see Array#readInt32(int) 101 | */ 102 | default long read(int index) { 103 | final int number = readInt16(index * 0x04); 104 | 105 | return number < 0 ? number + SIGN_OFFSET : number; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/system/utility/array/UInt16Array.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.system.utility.array; 19 | 20 | /** 21 | * Specialised implementation of {@link Array} for unsigned 16-bit integer element(s). 22 | */ 23 | public interface UInt16Array extends Array { 24 | int SIGN_OFFSET = 0x10000; 25 | int MAX_POSITIVE = 0x7FFF; 26 | int MAX_NEGATIVE = 0xFFFF; 27 | 28 | /** 29 | * @see Array#writeInt16(int) 30 | */ 31 | default UInt16Array write(short value) { 32 | return writeInt16(value); 33 | } 34 | 35 | /** 36 | * @see Array#writeInt16(int) 37 | */ 38 | default UInt16Array write(int value) { 39 | return writeInt16( 40 | (short) (value > MAX_POSITIVE & value <= MAX_POSITIVE ? (value - SIGN_OFFSET) : value)); 41 | } 42 | 43 | /** 44 | * @see Array#writeInt16(short[]) 45 | */ 46 | default UInt16Array write(short[] value) { 47 | return write(value, 0, value.length); 48 | } 49 | 50 | /** 51 | * @see Array#writeInt16(short[], int, int) 52 | */ 53 | default UInt16Array write(short[] value, int offset, int count) { 54 | return writeInt16(value, offset, count); 55 | } 56 | 57 | /** 58 | * @see Array#writeInt16(short[]) 59 | */ 60 | default UInt16Array write(int[] value) { 61 | return write(value, 0, value.length); 62 | } 63 | 64 | /** 65 | * @see Array#writeInt16(short[], int, int) 66 | */ 67 | default UInt16Array write(int[] value, int offset, int count) { 68 | for (int i = offset, j = offset + count; i < j; i++) { 69 | final int element = value[i]; 70 | 71 | writeInt16((short) (element > MAX_POSITIVE & element <= MAX_POSITIVE ? (element - SIGN_OFFSET) : element)); 72 | } 73 | return this; 74 | } 75 | 76 | /** 77 | * @see Array#writeInt16(int, int) 78 | */ 79 | default UInt16Array write(int index, short value) { 80 | return writeInt16(index * 0x02, value); 81 | } 82 | 83 | /** 84 | * @see Array#writeInt16(int, int) 85 | */ 86 | default UInt16Array write(int index, int value) { 87 | return writeInt16(index * 0x02, 88 | (short) (value > MAX_POSITIVE & value <= MAX_POSITIVE ? (value - SIGN_OFFSET) : value)); 89 | } 90 | 91 | /** 92 | * @see Array#readInt16() 93 | */ 94 | default int read() { 95 | final int number = readInt16(); 96 | 97 | return number < 0 ? number + SIGN_OFFSET : number; 98 | } 99 | 100 | /** 101 | * @see Array#readInt16(int) 102 | */ 103 | default int read(int index) { 104 | final int number = readInt16(index * 0x02); 105 | 106 | return number < 0 ? number + SIGN_OFFSET : number; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/audio/Audio.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.audio; 19 | 20 | import ar.com.quark.resource.AssetDescriptor; 21 | import ar.com.quark.system.utility.Disposable; 22 | import ar.com.quark.system.utility.Manageable; 23 | 24 | /** 25 | * Audio encapsulate the data of a sound. 26 | */ 27 | public abstract class Audio extends Manageable implements Disposable { 28 | private final int mDuration; 29 | private final int mRate; 30 | private final AudioFormat mFormat; 31 | 32 | /** 33 | *

Constructor

34 | */ 35 | public Audio(AudioFormat format, int duration, int rate) { 36 | mDuration = duration; 37 | mRate = rate; 38 | mFormat = format; 39 | } 40 | 41 | /** 42 | *

Get the duration (in millisecond) of the audio

43 | * 44 | * @return the duration (in millisecond) of the audio 45 | */ 46 | public final int getDuration() { 47 | return mDuration; 48 | } 49 | 50 | /** 51 | *

Get the sampler rate (in KHz) of the audio

52 | * 53 | * @return the sampler rate (in KHz) of the audio 54 | */ 55 | public final int getRate() { 56 | return mRate; 57 | } 58 | 59 | /** 60 | *

Get the format of the audio

61 | * 62 | * @return the format of the audio 63 | */ 64 | public final AudioFormat getFormat() { 65 | return mFormat; 66 | } 67 | 68 | /** 69 | *

Check if the audio have mono channel

70 | * 71 | * @return true if the audio have mono channel, false otherwise 72 | * 73 | * @see AudioFormat#MONO_8 74 | * @see AudioFormat#MONO_16 75 | */ 76 | public final boolean isMono() { 77 | return mFormat.eChannel == 0x01; 78 | } 79 | 80 | /** 81 | *

Check if the audio have stereo channel

82 | * 83 | * @return true if the audio have stereo channel, false otherwise 84 | * 85 | * @see AudioFormat#STEREO_8 86 | * @see AudioFormat#STEREO_16 87 | */ 88 | public final boolean isStereo() { 89 | return mFormat.eChannel == 0x02; 90 | } 91 | 92 | /** 93 | *

Check if the audio is being streaming

94 | * 95 | * @return true if the audio is being streaming, false otherwise 96 | */ 97 | public abstract boolean isStreaming(); 98 | 99 | /** 100 | * Descriptor encapsulate an {@link AssetDescriptor} for {@link Audio}. 101 | */ 102 | public final static class Descriptor extends AssetDescriptor { 103 | /** 104 | *

Constructor

105 | */ 106 | public Descriptor(boolean streaming) { 107 | super(true, !streaming); 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /Quark-Backend/Quark-Backend-Web/src/main/java/ar/com/quark/backend/teavm/resource/locator/XHRAssetLocator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.backend.teavm.resource.locator; 19 | 20 | import ar.com.quark.backend.teavm.utility.array.WebArrayFactory; 21 | import ar.com.quark.resource.AssetCallback; 22 | import ar.com.quark.resource.AssetLocator; 23 | import ar.com.quark.system.utility.array.ArrayInputStream; 24 | import org.teavm.jso.ajax.XMLHttpRequest; 25 | import org.teavm.jso.typedarrays.ArrayBuffer; 26 | 27 | import java.io.InputStream; 28 | 29 | /** 30 | * Encapsulate an {@link AssetLocator} that search asset(s) using XHR request(s). 31 | */ 32 | public final class XHRAssetLocator implements AssetLocator { 33 | private final static String BINARY_REQUEST = "arraybuffer"; 34 | 35 | /** 36 | * {@inheritDoc} 37 | */ 38 | @Override 39 | public boolean isSynchronousSupported() { 40 | return false; 41 | } 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | @Override 47 | public boolean isAsynchronousSupported() { 48 | return true; 49 | } 50 | 51 | /** 52 | * {@inheritDoc} 53 | */ 54 | @Override 55 | public InputStream locate(String filename) { 56 | //! 57 | //! Build the request. 58 | //! 59 | final XMLHttpRequest xhr = XMLHttpRequest.create(); 60 | 61 | xhr.open("GET", filename, false); 62 | xhr.setResponseType(BINARY_REQUEST); 63 | xhr.send(); 64 | 65 | return (xhr.getStatus() == 200 || xhr.getStatus() == 0 66 | ? new ArrayInputStream(new WebArrayFactory.TeaVMInt8Array((ArrayBuffer) xhr.getResponse())) 67 | : null); 68 | } 69 | 70 | /** 71 | * {@inheritDoc} 72 | */ 73 | @Override 74 | public InputStream locate(String filename, AssetCallback callback) { 75 | //! 76 | //! Build the request. 77 | //! 78 | final XMLHttpRequest xhr = XMLHttpRequest.create(); 79 | 80 | xhr.open("GET", filename, true); 81 | xhr.setResponseType(BINARY_REQUEST); 82 | xhr.onComplete(() -> onAssetReadStateChange(xhr, callback)); 83 | xhr.send(); 84 | 85 | return null; 86 | } 87 | 88 | /** 89 | *

Handle when a request changed its state

90 | */ 91 | private void onAssetReadStateChange(XMLHttpRequest request, AssetCallback callback) { 92 | if (request.getStatus() == 200 || request.getStatus() == 0) { 93 | //! 94 | //! Get the content of the request. 95 | //! 96 | final ArrayBuffer response = (ArrayBuffer) request.getResponse(); 97 | 98 | final Thread thread = new Thread(() -> 99 | callback.onSuccess( 100 | new ArrayInputStream( 101 | new WebArrayFactory.TeaVMInt8Array(response)))); 102 | thread.start(); 103 | } else { 104 | callback.onFail(); 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/mathematic/ImmutableVector3f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.mathematic; 19 | 20 | /** 21 | * Represent an immutable {@linkplain Vector3f}. 22 | */ 23 | public final class ImmutableVector3f extends Vector3f { 24 | public final static ImmutableVector3f ZERO = zero(); 25 | 26 | /** 27 | *

Default constructor

28 | */ 29 | public ImmutableVector3f(float x, float y, float z) { 30 | super(x, y, z); 31 | } 32 | 33 | /** 34 | *

Creates a new vector where each component value is 0.0f

35 | * 36 | * @return a new vector 37 | */ 38 | public static ImmutableVector3f zero() { 39 | return new ImmutableVector3f(0.0f, 0.0f, 0.0f); 40 | } 41 | 42 | /** 43 | *

Creates a new vector where each component value is 1.0f

44 | * 45 | * @return a new vector 46 | */ 47 | public static ImmutableVector3f one() { 48 | return new ImmutableVector3f(1.0f, 1.0f, 1.0f); 49 | } 50 | 51 | /** 52 | *

Creates a new vector of length one in the x-axis

53 | * 54 | * @return a new vector 55 | */ 56 | public static ImmutableVector3f unitX() { 57 | return new ImmutableVector3f(1.0f, 0.0f, 0.0f); 58 | } 59 | 60 | /** 61 | *

Creates a new vector of length one in the y-axis

62 | * 63 | * @return a new vector 64 | */ 65 | public static ImmutableVector3f unitY() { 66 | return new ImmutableVector3f(0.0f, 1.0f, 0.0f); 67 | } 68 | 69 | /** 70 | *

Creates a new vector of length one in the z-axis

71 | * 72 | * @return a new vector 73 | */ 74 | public static ImmutableVector3f unitZ() { 75 | return new ImmutableVector3f(0.0f, 0.0f, 1.0f); 76 | } 77 | 78 | /** 79 | *

Creates a new vector of length minus one in the z-axis

80 | * 81 | * @return a new vector 82 | */ 83 | public static ImmutableVector3f unitNegativeZ() { 84 | return new ImmutableVector3f(0.0f, 0.0f, -1.0f); 85 | } 86 | 87 | /** 88 | *

Creates a new vector where each component value is {@link Float#NaN}

89 | * 90 | * @return a new vector 91 | */ 92 | public static ImmutableVector3f nan() { 93 | return new ImmutableVector3f(Float.NaN, Float.NaN, Float.NaN); 94 | } 95 | 96 | /** 97 | *

Creates a new vector where each component value is {@link Float#POSITIVE_INFINITY}

98 | * 99 | * @return a new vector 100 | */ 101 | public static ImmutableVector3f positiveInfinity() { 102 | return new ImmutableVector3f(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY); 103 | } 104 | 105 | /** 106 | *

Creates a new vector where each component value is {@link Float#NEGATIVE_INFINITY}

107 | * 108 | * @return a new vector 109 | */ 110 | public static ImmutableVector3f negativeInfinity() { 111 | return new ImmutableVector3f(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY); 112 | } 113 | } -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/mathematic/ImmutableVector4f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.mathematic; 19 | 20 | /** 21 | * Represent an immutable {@linkplain Vector4f}. 22 | */ 23 | public final class ImmutableVector4f extends Vector4f { 24 | /** 25 | *

Default constructor

26 | */ 27 | public ImmutableVector4f(float x, float y, float z, float w) { 28 | super(x, y, z, w); 29 | } 30 | 31 | /** 32 | *

Creates a new vector where each component value is 0.0f

33 | * 34 | * @return a new vector 35 | */ 36 | public static ImmutableVector4f zero() { 37 | return new ImmutableVector4f(0.0f, 0.0f, 0.0f, 0.0f); 38 | } 39 | 40 | /** 41 | *

Creates a new vector where each component value is 1.0f

42 | * 43 | * @return a new vector 44 | */ 45 | public static ImmutableVector4f one() { 46 | return new ImmutableVector4f(1.0f, 1.0f, 1.0f, 1.0f); 47 | } 48 | 49 | /** 50 | *

Creates a new vector of length one in the x-axis

51 | * 52 | * @return a new vector 53 | */ 54 | public static ImmutableVector4f unitX() { 55 | return new ImmutableVector4f(1.0f, 0.0f, 0.0f, 0.0f); 56 | } 57 | 58 | /** 59 | *

Creates a new vector of length one in the y-axis

60 | * 61 | * @return a new vector 62 | */ 63 | public static ImmutableVector4f unitY() { 64 | return new ImmutableVector4f(0.0f, 1.0f, 0.0f, 0.0f); 65 | } 66 | 67 | /** 68 | *

Creates a new vector of length one in the z-axis

69 | * 70 | * @return a new vector 71 | */ 72 | public static ImmutableVector4f unitZ() { 73 | return new ImmutableVector4f(0.0f, 0.0f, 1.0f, 0.0f); 74 | } 75 | 76 | /** 77 | *

Creates a new vector of length one in the w-axis

78 | * 79 | * @return a new vector 80 | */ 81 | public static ImmutableVector4f unitW() { 82 | return new ImmutableVector4f(0.0f, 0.0f, 0.0f, 1.0f); 83 | } 84 | 85 | /** 86 | *

Creates a new vector where each component value is {@link Float#NaN}

87 | * 88 | * @return a new vector 89 | */ 90 | public static ImmutableVector4f nan() { 91 | return new ImmutableVector4f(Float.NaN, Float.NaN, Float.NaN, Float.NaN); 92 | } 93 | 94 | /** 95 | *

Creates a new vector where each component value is {@link Float#POSITIVE_INFINITY}

96 | * 97 | * @return a new vector 98 | */ 99 | public static ImmutableVector4f positiveInfinity() { 100 | return new ImmutableVector4f(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, 101 | Float.POSITIVE_INFINITY); 102 | } 103 | 104 | /** 105 | *

Creates a new vector where each component value is {@link Float#NEGATIVE_INFINITY}

106 | * 107 | * @return a new vector 108 | */ 109 | public static ImmutableVector4f negativeInfinity() { 110 | return new ImmutableVector4f(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY 111 | , Float.NEGATIVE_INFINITY); 112 | } 113 | } -------------------------------------------------------------------------------- /Quark/src/main/java/ar/com/quark/system/utility/array/Float16Array.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Quark Framework, licensed under the APACHE License. 3 | * 4 | * Copyright (c) 2014-2016 Agustin L. Alvarez 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ar.com.quark.system.utility.array; 19 | 20 | /** 21 | * Specialised implementation of {@link Array} for 16-bit float element(s). 22 | */ 23 | public interface Float16Array extends Array { 24 | /** 25 | * @see Array#writeInt16(int) 26 | */ 27 | default Float16Array write(float value) { 28 | return writeInt16(toHalf(value)); 29 | } 30 | 31 | /** 32 | * @see Array#writeInt16(short[]) 33 | */ 34 | default Float16Array write(float[] value) { 35 | return write(value, 0, value.length); 36 | } 37 | 38 | /** 39 | * @see Array#writeInt16(short[], int, int) 40 | */ 41 | default Float16Array write(float[] value, int offset, int count) { 42 | for (int i = offset, j = offset + count; i < j; i++) { 43 | writeInt16(toHalf(value[i])); 44 | } 45 | return this; 46 | } 47 | 48 | /** 49 | * @see Array#writeInt16(int, int) 50 | */ 51 | default Float16Array write(int index, float value) { 52 | return writeInt16(index * 0x02, toHalf(value)); 53 | } 54 | 55 | /** 56 | * @see Array#readInt16() 57 | */ 58 | default float read() { 59 | return toFloat(readInt16()); 60 | } 61 | 62 | /** 63 | * @see Array#readInt16(int) 64 | */ 65 | default float read(int index) { 66 | return toFloat(readInt16(index * 0x02)); 67 | } 68 | 69 | /** 70 | *

Convert a 16-bit float into a 16-bit integer

71 | */ 72 | static short toHalf(float value) { 73 | if (value == Float.POSITIVE_INFINITY) { 74 | return 0x7c00; 75 | } else if (value == Float.NEGATIVE_INFINITY) { 76 | return (short) 0xFC00; 77 | } else if (value == 0.0f) { 78 | return (short) 0x0000; 79 | } else if (value > 65504.0f) { 80 | return 0x7BFF; 81 | } else if (value < -65504.0f) { 82 | return (short) (0x7BFF | 0x8000); 83 | } else if (value > 0.0f && value < 5.96046E-8f) { 84 | return 0x0001; 85 | } else if (value < 0.0f && value > -5.96046E-8f) { 86 | return (short) 0x8001; 87 | } 88 | 89 | final int f = Float.floatToIntBits(value); 90 | 91 | return (short) (((f >> 16) & 0x8000) 92 | | ((((f & 0x7f800000) - 0x38000000) >> 13) & 0x7c00) | ((f >> 13) & 0x03ff)); 93 | } 94 | 95 | /** 96 | *

Convert a 16-bit integer into a 16-bit float

97 | */ 98 | static float toFloat(int value) { 99 | switch (value) { 100 | case 0x0000: 101 | return 0.0f; 102 | case 0x8000: 103 | return -0.0f; 104 | case 0x7C00: 105 | return Float.POSITIVE_INFINITY; 106 | case 0xFC00: 107 | return Float.NEGATIVE_INFINITY; 108 | default: 109 | return Float.intBitsToFloat( 110 | ((value & 0x8000) << 16) | (((value & 0x7c00) + 0x1C000) << 13) | ((value & 0x03FF) << 13)); 111 | } 112 | } 113 | } 114 | --------------------------------------------------------------------------------