Skip to content

Adding Texture Sample with CDep support #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 172 additions & 0 deletions tutorial06_texture/.cdep/modules/cdep-dependencies-config.cmake

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions tutorial06_texture/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Tutorial 6 - Texture
=============================
Render a textured triangle


Description
----------
* adding texture to triangle
* using shaderc [CDep](https:/github.com/google/cdep) package, which is temporarily hosted on [github repo](https://github.com/ggfan/shaderc/releases)
This sample builds the glsl shaders into spir-V at appliation run-time,
with [shaderc]https://github.com/google/shaderc)
pre-build binaries saved as [CDep](https:/github.com/google/cdep)
package at a [fork](https://github.com/ggfan/shaderc/releases)

[CDep](https:/github.com/google/cdep) is just released,
feedbacks are very welcome here or [CDep page](https://github.com/google/cdep)!

Prerequirement
--------------
Before building this sample, do:
* cd ${your_tutorial06_textyre}
* ./cdep ( or cdep.bat)

Then import the sample into Android Studio

28 changes: 28 additions & 0 deletions tutorial06_texture/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.0"

defaultConfig {
applicationId "com.vulkan.tutorials.six"
minSdkVersion 24
targetSdkVersion 24
versionCode 1
versionName "1.0.0"

ndk.abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
externalNativeBuild {
cmake.arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static'
}
}
externalNativeBuild {
cmake.path 'src/main/cpp/CMakeLists.txt'
}
buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.pro'))
}
}
}
31 changes: 31 additions & 0 deletions tutorial06_texture/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vulkan.tutorials.two">

<!-- This is the platform API where NativeActivity was introduced. -->
<uses-sdk />

<uses-permission android:name="android.permission.SET_DEBUG_APP"/>

<!-- This .apk has no Java code itself, so set hasCode to false. -->
<application android:label="@string/app_name"
android:hasCode="false" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

<!-- Our activity is the built-in NativeActivity framework class.
This will take care of integrating with our NDK code. -->
<activity android:name="android.app.NativeActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden">
<!-- Tell NativeActivity the name of or .so -->
<meta-data android:name="android.app.lib_name"
android:value="vktuts" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
<!-- END_INCLUDE(manifest) -->
Binary file added tutorial06_texture/app/src/main/assets/sample_tex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions tutorial06_texture/app/src/main/assets/shaders/tri.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* Fragment shader for tri demo
*/
#version 400
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (binding = 0) uniform sampler2D tex;
layout (location = 0) in vec2 texcoord;
layout (location = 0) out vec4 uFragColor;
void main() {
uFragColor = texture(tex, texcoord);
}
26 changes: 26 additions & 0 deletions tutorial06_texture/app/src/main/assets/shaders/tri.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* Vertex shader used by tri demo.
*/
#version 400
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (location = 0) in vec4 pos;
layout (location = 1) in vec2 attr;
layout (location = 0) out vec2 texcoord;
void main() {
texcoord = attr;
gl_Position = pos;
}
58 changes: 58 additions & 0 deletions tutorial06_texture/app/src/main/cpp/AndroidMain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <android/log.h>
#include <android_native_app_glue.h>
#include "VulkanMain.hpp"

// Process the next main command.
void handle_cmd(android_app* app, int32_t cmd) {
switch (cmd) {
case APP_CMD_INIT_WINDOW:
// The window is being shown, get it ready.
InitVulkan(app);
break;
case APP_CMD_TERM_WINDOW:
// The window is being hidden or closed, clean it up.
DeleteVulkan();
break;
default:
__android_log_print(ANDROID_LOG_INFO, "Vulkan Tutorials",
"event not handled: %d", cmd);
}
}

void android_main(struct android_app* app) {
// Magic call, please ignore it (Android specific).
app_dummy();

// Set the callback to process system events
app->onAppCmd = handle_cmd;

// Used to poll the events in the main loop
int events;
android_poll_source* source;

// Main loop
do {
if (ALooper_pollAll(IsVulkanReady() ? 1 : 0, nullptr,
&events, (void**)&source) >= 0) {
if (source != NULL) source->process(app, source);
}

// render if vulkan is ready
if (IsVulkanReady()) {
VulkanDrawFrame();
}
} while (app->destroyRequested == 0);
}
54 changes: 54 additions & 0 deletions tutorial06_texture/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
cmake_minimum_required(VERSION 3.4.3)

project(tutorial06_texture)

# build native_app_glue as a static lib
add_library(native_glue STATIC
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)

# build Vulkan app
set(SRC_DIR ${CMAKE_SOURCE_DIR})
get_filename_component(REPO_ROOT_DIR
${CMAKE_SOURCE_DIR}/../../../../.. ABSOLUTE)
set(COMMON_DIR ${REPO_ROOT_DIR}/common)
set(THIRD_PARTY_DIR ${REPO_ROOT_DIR}/third_party)

add_library(vktuts SHARED
${SRC_DIR}/VulkanMain.cpp
${SRC_DIR}/AndroidMain.cpp
${COMMON_DIR}/vulkan_wrapper/vulkan_wrapper.cpp)

target_include_directories(vktuts PRIVATE
${COMMON_DIR}/vulkan_wrapper
${COMMON_DIR}/src
${THIRD_PARTY_DIR}
${ANDROID_NDK}/sources/android/native_app_glue)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-std=c++11 -Werror -Wno-unused-variable -DVK_USE_PLATFORM_ANDROID_KHR")

if (${ANDROID_ABI} STREQUAL "armeabi-v7a")
set(CMAKE_CXX_FLAGS} "${CMAKE_CXX_FLAGS} \
-mhard-float -D_NDK_MATH_NO_SOFTFP=1 -mfloat-abi=hard")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} \
-Wl,--no-warn-mismatch")
endif()

target_link_libraries(vktuts native_glue log android)

######## CDep package for shaderc ######################
# pre-requirement:
# in terminal, cd {project_dir}; ./cdep
# that will generate .cdep/modules/cdep-dependencies-config.cmake
# the next 2 lines will be able to pull it into the project
# shaderc binaries are saved on github:
# https://github.com/ggfan/shaderc/releases
# the glue to reach it for CDep is in ${project_dir}/cdep.yml
# ******* Most Importantly, CDep full documentation is @:
# https://github.com/cdep

get_filename_component(cdep-dependencies_DIR
${CMAKE_SOURCE_DIR}/../../../../.cdep/modules ABSOLUTE)
find_package(cdep-dependencies REQUIRED)
add_all_cdep_dependencies(vktuts)

Loading