From 5d4b31915695abe668bbf3eef9646105d79c6aa5 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sun, 2 Feb 2020 12:51:36 -0800 Subject: Removed shader.h from Android NDK Helper to avoid conflict with Diligent's Shader.h --- NativeApp/Android/ndk_helper/include/NDKHelper.h | 1 - NativeApp/Android/ndk_helper/include/shader.h | 120 ---------------- NativeApp/Android/ndk_helper/src/shader.cpp | 166 ----------------------- 3 files changed, 287 deletions(-) delete mode 100644 NativeApp/Android/ndk_helper/include/shader.h delete mode 100644 NativeApp/Android/ndk_helper/src/shader.cpp (limited to 'NativeApp/Android') diff --git a/NativeApp/Android/ndk_helper/include/NDKHelper.h b/NativeApp/Android/ndk_helper/include/NDKHelper.h index 4c979e6..0c96be6 100644 --- a/NativeApp/Android/ndk_helper/include/NDKHelper.h +++ b/NativeApp/Android/ndk_helper/include/NDKHelper.h @@ -32,7 +32,6 @@ */ #include "gl3stub.h" // GLES3 stubs #include "GLContext.h" // EGL & OpenGL manager -#include "shader.h" // Shader compiler support #include "vecmath.h" // Vector math support, C++ implementation n current version #include "tapCamera.h" // Tap/Pinch camera control #include "JNIHelper.h" // JNI support diff --git a/NativeApp/Android/ndk_helper/include/shader.h b/NativeApp/Android/ndk_helper/include/shader.h deleted file mode 100644 index 39a2ec9..0000000 --- a/NativeApp/Android/ndk_helper/include/shader.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2013 The Android Open Source Project - * - * 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. - */ - -#ifndef SHADER_H_ -#define SHADER_H_ - -#include - -#include -#include -#include - -#include -#include - -#include - -#include "JNIHelper.h" - -namespace ndk_helper { - -namespace shader { - -/****************************************************************** - * Shader compiler helper - * namespace: ndkHelper::shader - * - */ - -/****************************************************************** - * CompileShader() with vector - * - * arguments: - * out: shader, shader variable - * in: type, shader type (i.e. GL_VERTEX_SHADER/GL_FRAGMENT_SHADER) - * in: data, source vector - * return: true if a shader compilation succeeded, false if it failed - * - */ -bool CompileShader(GLuint *shader, const GLenum type, - std::vector &data); - -/****************************************************************** - * CompileShader() with buffer - * - * arguments: - * out: shader, shader variable - * in: type, shader type (i.e. GL_VERTEX_SHADER/GL_FRAGMENT_SHADER) - * in: source, source buffer - * in: iSize, buffer size - * return: true if a shader compilation succeeded, false if it failed - * - */ -bool CompileShader(GLuint *shader, const GLenum type, const GLchar *source, - const int32_t iSize); - -/****************************************************************** - * CompileShader() with filename - * - * arguments: - * out: shader, shader variable - * in: type, shader type (i.e. GL_VERTEX_SHADER/GL_FRAGMENT_SHADER) - * in: strFilename, filename - * return: true if a shader compilation succeeded, false if it failed - * - */ -bool CompileShader(GLuint *shader, const GLenum type, const char *strFileName); - -/****************************************************************** - * CompileShader() with std::map helps patching on a shader on the fly. - * - * arguments: - * out: shader, shader variable - * in: type, shader type (i.e. GL_VERTEX_SHADER/GL_FRAGMENT_SHADER) - * in: mapParameters - * For a example, - * map : %KEY% -> %VALUE% replaces all %KEY% entries in the given shader - *code to %VALUE" - * return: true if a shader compilation succeeded, false if it failed - * - */ -bool CompileShader(GLuint *shader, const GLenum type, const char *str_file_name, - const std::map &map_parameters); - -/****************************************************************** - * LinkProgram() - * - * arguments: - * in: program, program - * return: true if a shader linkage succeeded, false if it failed - * - */ -bool LinkProgram(const GLuint prog); - -/****************************************************************** - * validateProgram() - * - * arguments: - * in: program, program - * return: true if a shader validation succeeded, false if it failed - * - */ -bool ValidateProgram(const GLuint prog); -} // namespace shader - -} // namespace ndkHelper -#endif /* SHADER_H_ */ diff --git a/NativeApp/Android/ndk_helper/src/shader.cpp b/NativeApp/Android/ndk_helper/src/shader.cpp deleted file mode 100644 index af7a155..0000000 --- a/NativeApp/Android/ndk_helper/src/shader.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright 2013 The Android Open Source Project - * - * 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 -#include -#include - -#include "shader.h" -#include "JNIHelper.h" - -namespace ndk_helper { - -#define DEBUG (1) - -bool shader::CompileShader( - GLuint *shader, const GLenum type, const char *str_file_name, - const std::map &map_parameters) { - std::vector data; - if (!JNIHelper::GetInstance()->ReadFile(str_file_name, &data)) { - LOGI("Can not open a file:%s", str_file_name); - return false; - } - - const char REPLACEMENT_TAG = '*'; - // Fill-in parameters - std::string str(data.begin(), data.end()); - std::string str_replacement_map(data.size(), ' '); - - std::map::const_iterator it = - map_parameters.begin(); - std::map::const_iterator itEnd = - map_parameters.end(); - while (it != itEnd) { - size_t pos = 0; - while ((pos = str.find(it->first, pos)) != std::string::npos) { - // Check if the sub string is already touched - - size_t replaced_pos = str_replacement_map.find(REPLACEMENT_TAG, pos); - if (replaced_pos == std::string::npos || replaced_pos > pos) { - str.replace(pos, it->first.length(), it->second); - str_replacement_map.replace(pos, it->first.length(), it->first.length(), - REPLACEMENT_TAG); - pos += it->second.length(); - } else { - // The replacement target has been touched by other tag, skipping them - pos += it->second.length(); - } - } - it++; - } - - LOGI("Patched Shdader:\n%s", str.c_str()); - - std::vector v(str.begin(), str.end()); - str.clear(); - return shader::CompileShader(shader, type, v); -} - -bool shader::CompileShader(GLuint *shader, const GLenum type, - const GLchar *source, const int32_t iSize) { - if (source == NULL || iSize <= 0) return false; - - *shader = glCreateShader(type); - glShaderSource(*shader, 1, &source, &iSize); // Not specifying 3rd parameter - // (size) could be troublesome.. - - glCompileShader(*shader); - -#if defined(DEBUG) - GLint logLength; - glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength); - if (logLength > 0) { - GLchar *log = (GLchar *)malloc(logLength); - glGetShaderInfoLog(*shader, logLength, &logLength, log); - LOGI("Shader compile log:\n%s", log); - free(log); - } -#endif - - GLint status; - glGetShaderiv(*shader, GL_COMPILE_STATUS, &status); - if (status == 0) { - glDeleteShader(*shader); - return false; - } - - return true; -} - -bool shader::CompileShader(GLuint *shader, const GLenum type, - std::vector &data) { - if (!data.size()) return false; - - const GLchar *source = (GLchar *)&data[0]; - int32_t iSize = data.size(); - return shader::CompileShader(shader, type, source, iSize); -} - -bool shader::CompileShader(GLuint *shader, const GLenum type, - const char *strFileName) { - std::vector data; - bool b = JNIHelper::GetInstance()->ReadFile(strFileName, &data); - if (!b) { - LOGI("Can not open a file:%s", strFileName); - return false; - } - - return shader::CompileShader(shader, type, data); -} - -bool shader::LinkProgram(const GLuint prog) { - GLint status; - - glLinkProgram(prog); - -#if defined(DEBUG) - GLint logLength; - glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength); - if (logLength > 0) { - GLchar *log = (GLchar *)malloc(logLength); - glGetProgramInfoLog(prog, logLength, &logLength, log); - LOGI("Program link log:\n%s", log); - free(log); - } -#endif - - glGetProgramiv(prog, GL_LINK_STATUS, &status); - if (status == 0) { - LOGI("Program link failed\n"); - return false; - } - - return true; -} - -bool shader::ValidateProgram(const GLuint prog) { - GLint logLength, status; - - glValidateProgram(prog); - glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength); - if (logLength > 0) { - GLchar *log = (GLchar *)malloc(logLength); - glGetProgramInfoLog(prog, logLength, &logLength, log); - LOGI("Program validate log:\n%s", log); - free(log); - } - - glGetProgramiv(prog, GL_VALIDATE_STATUS, &status); - if (status == 0) return false; - - return true; -} - -} // namespace ndkHelper -- cgit v1.2.3