add macOS implementation

This commit is contained in:
Nick Fisher
2023-09-05 23:13:59 +08:00
parent c522cd6ee9
commit 84e3124e04
457 changed files with 169627 additions and 15 deletions

View 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

View 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

View 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

View 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

View 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

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View 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

View 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

View 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

Binary file not shown.

File diff suppressed because it is too large Load Diff

View 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

View 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

View 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

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View 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