Skip to content

Commit

Permalink
Merge branch 'rc/1.9.1' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
bejado committed Sep 21, 2020
2 parents d1a93f0 + 11b9530 commit 39f323f
Show file tree
Hide file tree
Showing 30 changed files with 383 additions and 200 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ repositories {
}
dependencies {
implementation 'com.google.android.filament:filament-android:1.9.0'
implementation 'com.google.android.filament:filament-android:1.9.1'
}
```

Expand Down Expand Up @@ -63,7 +63,7 @@ A much smaller alternative to `filamat-android` that can only generate OpenGL sh
iOS projects can use CocoaPods to install the latest release:

```
pod 'Filament', '~> 1.9.0'
pod 'Filament', '~> 1.9.1'
```

### Snapshots
Expand Down
7 changes: 6 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
This file contains one line summaries of commits that are worthy of mentioning in release notes.
A new header is inserted each time a *tag* is created.

## Next release
## v1.9.1

- Improvements to SSAO quality
- Fix unoptimized shader crashes with certain OpenGL drivers
- Add float versions of math constants to libmath
- filament-utils: fix, `CoroutineScope` job should be canceled before destroy

## v1.9.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class ModelViewer(val engine: Engine) : android.view.View.OnTouchListener {
private var surfaceView: SurfaceView? = null
private var textureView: TextureView? = null

private var fetchResourcesJob: Job? = null

private val renderer: Renderer
private var swapChain: SwapChain? = null
private var assetLoader: AssetLoader
Expand Down Expand Up @@ -190,7 +192,7 @@ class ModelViewer(val engine: Engine) : android.view.View.OnTouchListener {
fun loadModelGltfAsync(buffer: Buffer, callback: (String) -> Buffer) {
destroyModel()
asset = assetLoader.createAssetFromJson(buffer)
CoroutineScope(Dispatchers.IO).launch {
fetchResourcesJob = CoroutineScope(Dispatchers.IO).launch {
fetchResources(asset!!, callback)
}
}
Expand All @@ -217,6 +219,7 @@ class ModelViewer(val engine: Engine) : android.view.View.OnTouchListener {
* Frees all entities associated with the most recently-loaded model.
*/
fun destroyModel() {
fetchResourcesJob?.cancel()
asset?.let { asset ->
this.scene.removeEntities(asset.entities)
assetLoader.destroyAsset(asset)
Expand Down
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GROUP=com.google.android.filament
VERSION_NAME=1.9.0
VERSION_NAME=1.9.1

POM_DESCRIPTION=Real-time physically based rendering engine for Android.

Expand Down
2 changes: 1 addition & 1 deletion docs/Materials.md.html
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,7 @@
**getWorldNormalVector()** | float3 | Normalized normal in world space, after bump mapping (must be used after `prepareMaterial()`)
**getWorldGeometricNormalVector()** | float3 | Normalized normal in world space, before bump mapping (can be used before `prepareMaterial()`)
**getWorldReflectedVector()** | float3 | Reflection of the view vector about the normal (must be used after `prepareMaterial()`)
**getNormalizedViewportCoord(float2)** | float2 | Normalized viewport position (i.e. clip-space position normalized to [0, 1], can be used before `prepareMaterial()`)
**getNormalizedViewportCoord()** | float2 | Normalized viewport position (i.e. clip-space position normalized to [0, 1], can be used before `prepareMaterial()`)
**getNdotV()** | float | The result of `dot(normal, view)`, always strictly greater than 0 (must be used after `prepareMaterial()`)
**getColor()** | float4 | Interpolated color of the fragment, if the color attribute is required
**getUV0()** | float2 | First interpolated set of UV coordinates, only available if the uv0 attribute is required
Expand Down
1 change: 0 additions & 1 deletion filament/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -418,4 +418,3 @@ install(FILES "../LICENSE" DESTINATION .)
add_subdirectory(backend)
add_subdirectory(test)
add_subdirectory(benchmark)
add_subdirectory(tools)
16 changes: 16 additions & 0 deletions filament/backend/include/private/backend/BackendUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@
namespace filament {
namespace backend {

/**
* Returns true if the shader string requests the Google-style line directive extension.
*/
bool requestsGoogleLineDirectivesExtension(const char* shader, size_t length) noexcept;

/**
* Edit a GLSL shader string in-place so any Google-style line directives are turned into regular
* line directives.
*
* E.g.:
* #line 100 "foobar.h"
* is transformed to (_ denotes a space)
* #line 100 __________
*/
void removeGoogleLineDirectives(char* shader, size_t length) noexcept;

/**
* Returns the number of bytes per pixel for the given format. For compressed texture formats,
* returns the number of bytes per block.
Expand Down
44 changes: 44 additions & 0 deletions filament/backend/src/BackendUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,53 @@

#include "private/backend/BackendUtils.h"

#include <string_view>

namespace filament {
namespace backend {

bool requestsGoogleLineDirectivesExtension(const char* shader, size_t length) noexcept {
std::string_view s(shader, length);
return s.find("GL_GOOGLE_cpp_style_line_directive") != std::string_view::npos;
}

void removeGoogleLineDirectives(char* shader, size_t length) noexcept {
std::string_view s(shader, length);

size_t pos = 0;
while (true) {
pos = s.find("#line", pos);
if (pos == std::string_view::npos) {
break;
}

pos += 5;

bool googleStyleDirective = false;
size_t len = 0;
size_t start = 0;
while (pos < length) {
if (shader[pos] == '"' && !googleStyleDirective) {
googleStyleDirective = true;
start = pos;
}
if (shader[pos] == '\n') {
break;
}
if (googleStyleDirective) {
len++;
}
pos++;
}

// There's no point in trying to splice the shader to remove the quoted filename, just
// replace the filename with spaces.
for (size_t i = start; i < start + len; i++) {
shader[i] = ' ';
}
}
}

size_t getFormatSize(TextureFormat format) noexcept {
switch (format) {
// 8-bits per element
Expand Down
19 changes: 17 additions & 2 deletions filament/backend/src/opengl/OpenGLProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <utils/compiler.h>
#include <utils/Panic.h>

#include <private/backend/BackendUtils.h>

#include <cctype>

namespace filament {
Expand Down Expand Up @@ -53,10 +55,23 @@ OpenGLProgram::OpenGLProgram(OpenGLDriver* gl, const Program& programBuilder) no

if (!shadersSource[i].empty()) {
GLint status;
char const* const source = (const char*)shadersSource[i].data();
auto shader = shadersSource[i];
GLint const length = (GLint)shader.size();

#ifndef NDEBUG
// If usages of the Google-style line directive are present, remove them, as some
// drivers don't allow the quotation marks.
if (requestsGoogleLineDirectivesExtension((const char*) shader.data(), length)) {
auto temp = shader;
removeGoogleLineDirectives((char*) temp.data(), length); // length is unaffected
shader = std::move(temp);
}
#endif

const char * const source = (const char*)shader.data();

GLuint shaderId = glCreateShader(glShaderType);
glShaderSource(shaderId, 1, &source, nullptr);
glShaderSource(shaderId, 1, &source, &length);
glCompileShader(shaderId);

glGetShaderiv(shaderId, GL_COMPILE_STATUS, &status);
Expand Down
3 changes: 1 addition & 2 deletions filament/src/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ void UTILS_NOINLINE FCamera::setProjection(double fov, double aspect, double nea
void FCamera::setLensProjection(double focalLength, double aspect, double near, double far) noexcept {
// a 35mm camera has a 36x24mm wide frame size
double theta = 2.0 * std::atan(SENSOR_SIZE * 1000.0f / (2.0 * focalLength));
theta *= 180.0 / math::F_PI;
FCamera::setProjection(theta, aspect, near, far, Fov::VERTICAL);
FCamera::setProjection(theta * math::d::RAD_TO_DEG, aspect, near, far, Fov::VERTICAL);
}

/*
Expand Down
Loading

0 comments on commit 39f323f

Please sign in to comment.