add macOS implementation
This commit is contained in:
92
macos/include/material/FileMaterialProvider.hpp
Normal file
92
macos/include/material/FileMaterialProvider.hpp
Normal file
@@ -0,0 +1,92 @@
|
||||
#ifndef FILE_MATERIAL_PROVIDER
|
||||
#define FILE_MATERIAL_PROVIDER
|
||||
|
||||
#include <filament/Texture.h>
|
||||
#include <filament/TextureSampler.h>
|
||||
#include <math/mat4.h>
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
#include <math/mat3.h>
|
||||
#include <math/norm.h>
|
||||
|
||||
namespace polyvox {
|
||||
class FileMaterialProvider : public MaterialProvider {
|
||||
|
||||
Material* _m;
|
||||
const Material* _ms[1];
|
||||
Texture* mDummyTexture = nullptr;
|
||||
|
||||
|
||||
public:
|
||||
FileMaterialProvider(Engine* engine, const void* const data, const size_t size) {
|
||||
_m = Material::Builder()
|
||||
.package(data, size)
|
||||
.build(*engine);
|
||||
_ms[0] = _m;
|
||||
unsigned char texels[4] = {};
|
||||
mDummyTexture = Texture::Builder()
|
||||
.width(1).height(1)
|
||||
.format(Texture::InternalFormat::RGBA8)
|
||||
.build(*engine);
|
||||
Texture::PixelBufferDescriptor pbd(texels, sizeof(texels), Texture::Format::RGBA,
|
||||
Texture::Type::UBYTE);
|
||||
mDummyTexture->setImage(*engine, 0, std::move(pbd));
|
||||
}
|
||||
|
||||
filament::MaterialInstance* createMaterialInstance(MaterialKey* config, UvMap* uvmap,
|
||||
const char* label = "material", const char* extras = nullptr) {
|
||||
|
||||
auto getUvIndex = [uvmap](uint8_t srcIndex, bool hasTexture) -> int {
|
||||
return hasTexture ? int(uvmap->at(srcIndex)) - 1 : -1;
|
||||
};
|
||||
|
||||
auto instance = _m->createInstance();
|
||||
math::mat3f identity;
|
||||
instance->setParameter("baseColorUvMatrix", identity);
|
||||
instance->setParameter("normalUvMatrix", identity);
|
||||
|
||||
instance->setParameter("baseColorIndex", getUvIndex(config->baseColorUV, config->hasBaseColorTexture));
|
||||
instance->setParameter("normalIndex", getUvIndex(config->normalUV, config->hasNormalTexture));
|
||||
if(config->hasNormalTexture) {
|
||||
Log("HAS NORMAL TEXTURE");
|
||||
} else {
|
||||
Log("NO NORMAL TEXTURE?");
|
||||
}
|
||||
// TextureSampler sampler;
|
||||
// instance->setParameter("normalMap", mDummyTexture, sampler);
|
||||
// instance->setParameter("baseColorMap", mDummyTexture, sampler);
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates or fetches a compiled Filament material corresponding to the given config.
|
||||
*/
|
||||
virtual Material* getMaterial(MaterialKey* config, UvMap* uvmap, const char* label = "material") {
|
||||
return _m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a weak reference to the array of cached materials.
|
||||
*/
|
||||
const filament::Material* const* getMaterials() const noexcept {
|
||||
return _ms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of cached materials.
|
||||
*/
|
||||
size_t getMaterialsCount() const noexcept {
|
||||
return (size_t)1;
|
||||
}
|
||||
|
||||
void destroyMaterials() {
|
||||
|
||||
}
|
||||
|
||||
bool needsDummyData(filament::VertexAttribute attrib) const noexcept {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
53
macos/include/material/StandardMaterialProvider.hpp
Normal file
53
macos/include/material/StandardMaterialProvider.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef UNLIT_MATERIAL_PROVIDER
|
||||
#define UNLIT_MATERIAL_PROVIDER
|
||||
|
||||
#include "material/standard.h"
|
||||
|
||||
namespace polyvox {
|
||||
class StandardMaterialProvider : public MaterialProvider {
|
||||
|
||||
const Material* _m;
|
||||
const Material* _ms[1];
|
||||
|
||||
const Engine* _engine;
|
||||
|
||||
public:
|
||||
StandardMaterialProvider(Engine* engine) {
|
||||
_engine = engine;
|
||||
_m = Material::Builder()
|
||||
.package( STANDARD_STANDARD_DATA, STANDARD_STANDARD_SIZE)
|
||||
.build(*engine);
|
||||
_ms[0] = _m;
|
||||
}
|
||||
|
||||
filament::MaterialInstance* createMaterialInstance(MaterialKey* config, UvMap* uvmap,
|
||||
const char* label = "material", const char* extras = nullptr) {
|
||||
MaterialInstance* d = (MaterialInstance*)_m->getDefaultInstance();
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a weak reference to the array of cached materials.
|
||||
*/
|
||||
const filament::Material* const* getMaterials() const noexcept {
|
||||
return _ms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of cached materials.
|
||||
*/
|
||||
size_t getMaterialsCount() const noexcept {
|
||||
return (size_t)1;
|
||||
}
|
||||
|
||||
void destroyMaterials() {
|
||||
// TODO - do we need to do anything here?
|
||||
}
|
||||
|
||||
bool needsDummyData(filament::VertexAttribute attrib) const noexcept {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
53
macos/include/material/UnlitMaterialProvider.hpp
Normal file
53
macos/include/material/UnlitMaterialProvider.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef UNLIT_MATERIAL_PROVIDER
|
||||
#define UNLIT_MATERIAL_PROVIDER
|
||||
|
||||
#include "material/unlit_opaque.h"
|
||||
|
||||
namespace polyvox {
|
||||
class UnlitMaterialProvider : public MaterialProvider {
|
||||
|
||||
const Material* _m;
|
||||
const Material* _ms[1];
|
||||
|
||||
const Engine* _engine;
|
||||
|
||||
public:
|
||||
UnlitMaterialProvider(Engine* engine) {
|
||||
_engine = engine;
|
||||
_m = Material::Builder()
|
||||
.package( UNLIT_OPAQUE_UNLIT_OPAQUE_DATA, UNLIT_OPAQUE_UNLIT_OPAQUE_SIZE)
|
||||
.build(*engine);
|
||||
_ms[0] = _m;
|
||||
}
|
||||
|
||||
filament::MaterialInstance* createMaterialInstance(MaterialKey* config, UvMap* uvmap,
|
||||
const char* label = "material", const char* extras = nullptr) {
|
||||
MaterialInstance* d = (MaterialInstance*)_m->getDefaultInstance();
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a weak reference to the array of cached materials.
|
||||
*/
|
||||
const filament::Material* const* getMaterials() const noexcept {
|
||||
return _ms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of cached materials.
|
||||
*/
|
||||
size_t getMaterialsCount() const noexcept {
|
||||
return (size_t)1;
|
||||
}
|
||||
|
||||
void destroyMaterials() {
|
||||
// TODO - do we need to do anything here?
|
||||
}
|
||||
|
||||
bool needsDummyData(filament::VertexAttribute attrib) const noexcept {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
12
macos/include/material/image.S
Normal file
12
macos/include/material/image.S
Normal file
@@ -0,0 +1,12 @@
|
||||
.global IMAGE_IMAGE_OFFSET;
|
||||
.global IMAGE_IMAGE_SIZE;
|
||||
|
||||
.global IMAGE_PACKAGE
|
||||
.section .rodata
|
||||
IMAGE_PACKAGE:
|
||||
.incbin "image.bin"
|
||||
IMAGE_IMAGE_OFFSET:
|
||||
.int 0
|
||||
IMAGE_IMAGE_SIZE:
|
||||
.int 30655
|
||||
|
||||
12
macos/include/material/image.apple.S
Normal file
12
macos/include/material/image.apple.S
Normal file
@@ -0,0 +1,12 @@
|
||||
.global _IMAGE_IMAGE_OFFSET;
|
||||
.global _IMAGE_IMAGE_SIZE;
|
||||
|
||||
.global _IMAGE_PACKAGE
|
||||
.section __TEXT,__const
|
||||
_IMAGE_PACKAGE:
|
||||
.incbin "image.bin"
|
||||
_IMAGE_IMAGE_OFFSET:
|
||||
.int 0
|
||||
_IMAGE_IMAGE_SIZE:
|
||||
.int 30655
|
||||
|
||||
BIN
macos/include/material/image.bin
Normal file
BIN
macos/include/material/image.bin
Normal file
Binary file not shown.
1542
macos/include/material/image.c
Normal file
1542
macos/include/material/image.c
Normal file
File diff suppressed because it is too large
Load Diff
BIN
macos/include/material/image.filamat
Normal file
BIN
macos/include/material/image.filamat
Normal file
Binary file not shown.
13
macos/include/material/image.h
Normal file
13
macos/include/material/image.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef IMAGE_H_
|
||||
#define IMAGE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C" {
|
||||
extern const uint8_t IMAGE_PACKAGE[];
|
||||
extern int IMAGE_IMAGE_OFFSET;
|
||||
extern int IMAGE_IMAGE_SIZE;
|
||||
}
|
||||
#define IMAGE_IMAGE_DATA (IMAGE_PACKAGE + IMAGE_IMAGE_OFFSET)
|
||||
|
||||
#endif
|
||||
12
macos/include/material/standard.S
Normal file
12
macos/include/material/standard.S
Normal file
@@ -0,0 +1,12 @@
|
||||
.global STANDARD_STANDARD_OFFSET;
|
||||
.global STANDARD_STANDARD_SIZE;
|
||||
|
||||
.global STANDARD_PACKAGE
|
||||
.section .rodata
|
||||
STANDARD_PACKAGE:
|
||||
.incbin "standard.bin"
|
||||
STANDARD_STANDARD_OFFSET:
|
||||
.int 0
|
||||
STANDARD_STANDARD_SIZE:
|
||||
.int 1031374
|
||||
|
||||
12
macos/include/material/standard.apple.S
Normal file
12
macos/include/material/standard.apple.S
Normal file
@@ -0,0 +1,12 @@
|
||||
.global _STANDARD_STANDARD_OFFSET;
|
||||
.global _STANDARD_STANDARD_SIZE;
|
||||
|
||||
.global _STANDARD_PACKAGE
|
||||
.section __TEXT,__const
|
||||
_STANDARD_PACKAGE:
|
||||
.incbin "standard.bin"
|
||||
_STANDARD_STANDARD_OFFSET:
|
||||
.int 0
|
||||
_STANDARD_STANDARD_SIZE:
|
||||
.int 1031374
|
||||
|
||||
BIN
macos/include/material/standard.bin
Normal file
BIN
macos/include/material/standard.bin
Normal file
Binary file not shown.
51578
macos/include/material/standard.c
Normal file
51578
macos/include/material/standard.c
Normal file
File diff suppressed because it is too large
Load Diff
13
macos/include/material/standard.h
Normal file
13
macos/include/material/standard.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef STANDARD_H_
|
||||
#define STANDARD_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C" {
|
||||
extern const uint8_t STANDARD_PACKAGE[];
|
||||
extern int STANDARD_STANDARD_OFFSET;
|
||||
extern int STANDARD_STANDARD_SIZE;
|
||||
}
|
||||
#define STANDARD_STANDARD_DATA (STANDARD_PACKAGE + STANDARD_STANDARD_OFFSET)
|
||||
|
||||
#endif
|
||||
12
macos/include/material/unlit_opaque.S
Normal file
12
macos/include/material/unlit_opaque.S
Normal file
@@ -0,0 +1,12 @@
|
||||
.global UNLIT_OPAQUE_UNLIT_OPAQUE_OFFSET;
|
||||
.global UNLIT_OPAQUE_UNLIT_OPAQUE_SIZE;
|
||||
|
||||
.global UNLIT_OPAQUE_PACKAGE
|
||||
.section .rodata
|
||||
UNLIT_OPAQUE_PACKAGE:
|
||||
.incbin "unlit_opaque.bin"
|
||||
UNLIT_OPAQUE_UNLIT_OPAQUE_OFFSET:
|
||||
.int 0
|
||||
UNLIT_OPAQUE_UNLIT_OPAQUE_SIZE:
|
||||
.int 78806
|
||||
|
||||
12
macos/include/material/unlit_opaque.apple.S
Normal file
12
macos/include/material/unlit_opaque.apple.S
Normal file
@@ -0,0 +1,12 @@
|
||||
.global _UNLIT_OPAQUE_UNLIT_OPAQUE_OFFSET;
|
||||
.global _UNLIT_OPAQUE_UNLIT_OPAQUE_SIZE;
|
||||
|
||||
.global _UNLIT_OPAQUE_PACKAGE
|
||||
.section __TEXT,__const
|
||||
_UNLIT_OPAQUE_PACKAGE:
|
||||
.incbin "unlit_opaque.bin"
|
||||
_UNLIT_OPAQUE_UNLIT_OPAQUE_OFFSET:
|
||||
.int 0
|
||||
_UNLIT_OPAQUE_UNLIT_OPAQUE_SIZE:
|
||||
.int 78806
|
||||
|
||||
BIN
macos/include/material/unlit_opaque.bin
Normal file
BIN
macos/include/material/unlit_opaque.bin
Normal file
Binary file not shown.
3950
macos/include/material/unlit_opaque.c
Normal file
3950
macos/include/material/unlit_opaque.c
Normal file
File diff suppressed because it is too large
Load Diff
BIN
macos/include/material/unlit_opaque.filamat
Normal file
BIN
macos/include/material/unlit_opaque.filamat
Normal file
Binary file not shown.
13
macos/include/material/unlit_opaque.h
Normal file
13
macos/include/material/unlit_opaque.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef UNLIT_OPAQUE_H_
|
||||
#define UNLIT_OPAQUE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C" {
|
||||
extern const uint8_t UNLIT_OPAQUE_PACKAGE[];
|
||||
extern int UNLIT_OPAQUE_UNLIT_OPAQUE_OFFSET;
|
||||
extern int UNLIT_OPAQUE_UNLIT_OPAQUE_SIZE;
|
||||
}
|
||||
#define UNLIT_OPAQUE_UNLIT_OPAQUE_DATA (UNLIT_OPAQUE_PACKAGE + UNLIT_OPAQUE_UNLIT_OPAQUE_OFFSET)
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user