add manual bone transform animation
This commit is contained in:
@@ -170,16 +170,16 @@ FilamentViewer::FilamentViewer(void* context, LoadResource loadResource,
|
||||
// options.minScale = filament::math::float2{ minScale };
|
||||
// options.maxScale = filament::math::float2{ maxScale };
|
||||
// options.sharpness = sharpness;
|
||||
options.quality = View::QualityLevel::MEDIUM;
|
||||
;
|
||||
options.quality = View::QualityLevel::HIGH;
|
||||
|
||||
_view->setDynamicResolutionOptions(options);
|
||||
|
||||
View::MultiSampleAntiAliasingOptions multiSampleAntiAliasingOptions;
|
||||
multiSampleAntiAliasingOptions.enabled = false;
|
||||
//View::MultiSampleAntiAliasingOptions multiSampleAntiAliasingOptions;
|
||||
//multiSampleAntiAliasingOptions.enabled = true;
|
||||
|
||||
_view->setMultiSampleAntiAliasingOptions(multiSampleAntiAliasingOptions);
|
||||
//_view->setMultiSampleAntiAliasingOptions(multiSampleAntiAliasingOptions);
|
||||
|
||||
// _view->setAntiAliasing(AntiAliasing::NONE);
|
||||
//_view->setAntiAliasing(AntiAliasing::NONE);
|
||||
|
||||
_materialProvider =
|
||||
// new UnlitMaterialProvider(_engine);
|
||||
|
||||
@@ -141,13 +141,59 @@ extern "C" {
|
||||
}
|
||||
|
||||
void apply_weights(void* asset, float* const weights, int count) {
|
||||
((SceneAsset*)asset)->applyWeights(weights, count);
|
||||
((SceneAsset*)asset)->setMorphTargetWeights(weights, count);
|
||||
}
|
||||
|
||||
void animate_weights(void* asset, float* data, int numWeights, int numFrames, float frameRate) {
|
||||
((SceneAsset*)asset)->animateWeights((float*)data, numWeights, numFrames, frameRate);
|
||||
void set_animation(
|
||||
void* asset,
|
||||
float* morphData,
|
||||
int numMorphWeights,
|
||||
float* boneData,
|
||||
const char** boneNames,
|
||||
const char** meshNames,
|
||||
int numBones,
|
||||
int numFrames,
|
||||
float frameLengthInMs) {
|
||||
((SceneAsset*)asset)->setAnimation(
|
||||
morphData,
|
||||
numMorphWeights,
|
||||
boneData,
|
||||
boneNames,
|
||||
meshNames,
|
||||
numBones,
|
||||
numFrames,
|
||||
frameLengthInMs
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void set_bone_transform(
|
||||
void* asset,
|
||||
const char* boneName,
|
||||
const char* entityName,
|
||||
float transX,
|
||||
float transY,
|
||||
float transZ,
|
||||
float quatX,
|
||||
float quatY,
|
||||
float quatZ,
|
||||
float quatW
|
||||
) {
|
||||
((SceneAsset*)asset)->setBoneTransform(
|
||||
boneName,
|
||||
entityName,
|
||||
transX,
|
||||
transY,
|
||||
transZ,
|
||||
quatX,
|
||||
quatY,
|
||||
quatZ,
|
||||
quatW
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void play_animation(void* asset, int index, bool loop, bool reverse) {
|
||||
((SceneAsset*)asset)->playAnimation(index, loop, reverse);
|
||||
}
|
||||
@@ -163,13 +209,13 @@ extern "C" {
|
||||
strcpy(outPtr, name.c_str());
|
||||
}
|
||||
|
||||
int get_target_name_count(void* asset, const char* meshName) {
|
||||
unique_ptr<vector<string>> names = ((SceneAsset*)asset)->getTargetNames(meshName);
|
||||
int get_morph_target_name_count(void* asset, const char* meshName) {
|
||||
unique_ptr<vector<string>> names = ((SceneAsset*)asset)->getMorphTargetNames(meshName);
|
||||
return names->size();
|
||||
}
|
||||
|
||||
void get_target_name(void* asset, const char* meshName, char* const outPtr, int index ) {
|
||||
unique_ptr<vector<string>> names = ((SceneAsset*)asset)->getTargetNames(meshName);
|
||||
void get_morph_target_name(void* asset, const char* meshName, char* const outPtr, int index ) {
|
||||
unique_ptr<vector<string>> names = ((SceneAsset*)asset)->getMorphTargetNames(meshName);
|
||||
string name = names->at(index);
|
||||
strcpy(outPtr, name.c_str());
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ SceneAsset::SceneAsset(FilamentAsset *asset, Engine *engine,
|
||||
_animator = _asset->getInstance()->getAnimator();
|
||||
for (int i = 0; i < _animator->getAnimationCount(); i++) {
|
||||
_embeddedAnimationStatus.push_back(
|
||||
EmbeddedAnimationStatus(false,false));
|
||||
GLTFAnimation(false,false));
|
||||
}
|
||||
Log("Created animation buffers for %d", _embeddedAnimationStatus.size());
|
||||
}
|
||||
@@ -47,7 +47,7 @@ SceneAsset::~SceneAsset() {
|
||||
}
|
||||
}
|
||||
|
||||
void SceneAsset::applyWeights(float *weights, int count) {
|
||||
void SceneAsset::setMorphTargetWeights(float *weights, int count) {
|
||||
RenderableManager &rm = _engine->getRenderableManager();
|
||||
for (size_t i = 0, c = _asset->getEntityCount(); i != c; ++i) {
|
||||
auto inst = rm.getInstance(_asset->getEntities()[i]);
|
||||
@@ -55,54 +55,78 @@ void SceneAsset::applyWeights(float *weights, int count) {
|
||||
}
|
||||
}
|
||||
|
||||
void SceneAsset::animateWeights(float *data, int numWeights, int numFrames,
|
||||
float frameLengthInMs) {
|
||||
Log("Making morph animation buffer with %d weights across %d frames and "
|
||||
"frame length %f ms ",
|
||||
numWeights, numFrames, frameLengthInMs);
|
||||
_morphAnimationBuffer = std::make_unique<MorphAnimationStatus>(
|
||||
data, numWeights, numFrames, frameLengthInMs);
|
||||
void SceneAsset::setAnimation(
|
||||
float* morphData,
|
||||
int numMorphWeights,
|
||||
float* boneData,
|
||||
const char** boneNames,
|
||||
const char** meshNames,
|
||||
int numBones,
|
||||
int numFrames,
|
||||
float frameLengthInMs) {
|
||||
_runtimeAnimationBuffer = std::make_unique<RuntimeAnimation>(
|
||||
morphData,
|
||||
numMorphWeights,
|
||||
boneData,
|
||||
boneNames,
|
||||
meshNames,
|
||||
numBones,
|
||||
numFrames,
|
||||
frameLengthInMs
|
||||
);
|
||||
}
|
||||
|
||||
void SceneAsset::updateAnimations() {
|
||||
updateMorphAnimation();
|
||||
updateRuntimeAnimation();
|
||||
updateEmbeddedAnimations();
|
||||
}
|
||||
|
||||
void SceneAsset::updateMorphAnimation() {
|
||||
if (!_morphAnimationBuffer) {
|
||||
void SceneAsset::updateRuntimeAnimation() {
|
||||
|
||||
if (!_runtimeAnimationBuffer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_morphAnimationBuffer->frameIndex == -1) {
|
||||
// auto ms = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
|
||||
// Log("Frame 1 at %lu", ms);
|
||||
_morphAnimationBuffer->frameIndex++;
|
||||
_morphAnimationBuffer->startTime = high_resolution_clock::now();
|
||||
applyWeights(_morphAnimationBuffer->frameData,
|
||||
_morphAnimationBuffer->numWeights);
|
||||
} else {
|
||||
duration<double, std::milli> dur =
|
||||
high_resolution_clock::now() - _morphAnimationBuffer->startTime;
|
||||
int frameIndex =
|
||||
static_cast<int>(dur.count() / _morphAnimationBuffer->frameLengthInMs);
|
||||
if (_runtimeAnimationBuffer->frameIndex == -1) {
|
||||
_runtimeAnimationBuffer->startTime = high_resolution_clock::now();
|
||||
}
|
||||
|
||||
if (frameIndex > _morphAnimationBuffer->numFrames - 1) {
|
||||
duration<double, std::milli> dur =
|
||||
high_resolution_clock::now() - _morphAnimationBuffer->startTime;
|
||||
Log("Morph animation completed in %f ms (%d frames at framerate %f), "
|
||||
"final frame was %d",
|
||||
dur.count(), _morphAnimationBuffer->numFrames,
|
||||
1000 / _morphAnimationBuffer->frameLengthInMs,
|
||||
_morphAnimationBuffer->frameIndex);
|
||||
_morphAnimationBuffer = nullptr;
|
||||
} else if (frameIndex > _morphAnimationBuffer->frameIndex) {
|
||||
// Log("Rendering frame %d (of a total %d)", frameIndex,
|
||||
// _morphAnimationBuffer->numFrames);
|
||||
_morphAnimationBuffer->frameIndex = frameIndex;
|
||||
auto framePtrOffset = frameIndex * _morphAnimationBuffer->numWeights;
|
||||
applyWeights(_morphAnimationBuffer->frameData + framePtrOffset,
|
||||
_morphAnimationBuffer->numWeights);
|
||||
duration<double, std::milli> dur =
|
||||
high_resolution_clock::now() - _runtimeAnimationBuffer->startTime;
|
||||
int frameIndex =
|
||||
static_cast<int>(dur.count() / _runtimeAnimationBuffer->mFrameLengthInMs);
|
||||
|
||||
// if the animation has finished, return early
|
||||
if (frameIndex >= _runtimeAnimationBuffer->mNumFrames) {
|
||||
_runtimeAnimationBuffer = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
if (frameIndex > _runtimeAnimationBuffer->frameIndex) {
|
||||
_runtimeAnimationBuffer->frameIndex = frameIndex;
|
||||
if(_runtimeAnimationBuffer->mMorphFrameData) {
|
||||
auto morphFramePtrOffset = frameIndex * _runtimeAnimationBuffer->mNumMorphWeights;
|
||||
setMorphTargetWeights(_runtimeAnimationBuffer->mMorphFrameData + morphFramePtrOffset,
|
||||
_runtimeAnimationBuffer->mNumMorphWeights);
|
||||
}
|
||||
|
||||
if(_runtimeAnimationBuffer->mBoneFrameData) {
|
||||
|
||||
for(int i = 0; i < _runtimeAnimationBuffer->mNumBones; i++) {
|
||||
auto boneFramePtrOffset = (frameIndex * _runtimeAnimationBuffer->mNumBones * 7) + (i*7);
|
||||
const char* boneName = _runtimeAnimationBuffer->mBoneNames[i].c_str();
|
||||
const char* meshName = _runtimeAnimationBuffer->mMeshNames[i].c_str();
|
||||
float* frame = _runtimeAnimationBuffer->mBoneFrameData + boneFramePtrOffset;
|
||||
|
||||
float transX = frame[0];
|
||||
float transY = frame[1];
|
||||
float transZ = frame[2];
|
||||
float quatX = frame[3];
|
||||
float quatY = frame[4];
|
||||
float quatZ = frame[5];
|
||||
float quatW = frame[6];
|
||||
setBoneTransform(boneName, meshName, transX, transY, transZ, quatX, quatY, quatZ, quatW);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -201,10 +225,12 @@ void SceneAsset::setTexture() {
|
||||
void SceneAsset::updateEmbeddedAnimations() {
|
||||
auto now = high_resolution_clock::now();
|
||||
int animationIndex = 0;
|
||||
bool playing = false;
|
||||
for (auto &status : _embeddedAnimationStatus) {
|
||||
if (status.play == false) {
|
||||
continue;
|
||||
}
|
||||
playing = true;
|
||||
|
||||
float animationLength = _animator->getAnimationDuration(animationIndex);
|
||||
|
||||
@@ -241,8 +267,8 @@ void SceneAsset::updateEmbeddedAnimations() {
|
||||
}
|
||||
animationIndex++;
|
||||
}
|
||||
|
||||
_animator->updateBoneMatrices();
|
||||
if(playing)
|
||||
_animator->updateBoneMatrices();
|
||||
}
|
||||
|
||||
unique_ptr<vector<string>> SceneAsset::getAnimationNames() {
|
||||
@@ -259,7 +285,7 @@ unique_ptr<vector<string>> SceneAsset::getAnimationNames() {
|
||||
return names;
|
||||
}
|
||||
|
||||
unique_ptr<vector<string>> SceneAsset::getTargetNames(const char *meshName) {
|
||||
unique_ptr<vector<string>> SceneAsset::getMorphTargetNames(const char *meshName) {
|
||||
if (!_asset) {
|
||||
Log("No asset, ignoring call.");
|
||||
return nullptr;
|
||||
@@ -272,7 +298,7 @@ unique_ptr<vector<string>> SceneAsset::getTargetNames(const char *meshName) {
|
||||
Entity e = entities[i];
|
||||
auto inst = _ncm->getInstance(e);
|
||||
const char *name = _ncm->getName(inst);
|
||||
// Log("Got entity instance name %s", name);
|
||||
|
||||
if (strcmp(name, meshName) == 0) {
|
||||
size_t count = _asset->getMorphTargetCountAt(e);
|
||||
for (int j = 0; j < count; j++) {
|
||||
@@ -327,6 +353,62 @@ void SceneAsset::setRotation(float rads, float x, float y, float z) {
|
||||
updateTransform();
|
||||
}
|
||||
|
||||
void SceneAsset::setBoneTransform(
|
||||
const char* boneName,
|
||||
const char* entityName,
|
||||
float transX,
|
||||
float transY,
|
||||
float transZ,
|
||||
float quatX,
|
||||
float quatY,
|
||||
float quatZ,
|
||||
float quatW) {
|
||||
|
||||
auto filamentInstance = _asset->getInstance();
|
||||
|
||||
if(filamentInstance->getSkinCount()) {
|
||||
Log("WARNING - skin count > 1 not currently implemented. This will probably not work");
|
||||
}
|
||||
|
||||
filamentInstance->getAnimator()->resetBoneMatrices();
|
||||
|
||||
int skinIndex = 0;
|
||||
const utils::Entity* joints = filamentInstance->getJointsAt(skinIndex);
|
||||
size_t numJoints = filamentInstance->getJointCountAt(skinIndex);
|
||||
|
||||
int boneIndex = -1;
|
||||
for(int i =0; i < numJoints; i++) {
|
||||
const char* jointName = _ncm->getName(_ncm->getInstance(joints[i]));
|
||||
if(strcmp(jointName, boneName) == 0) {
|
||||
boneIndex = i;
|
||||
Log("Found bone index %d for bone %s", boneIndex, boneName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(boneIndex == -1) {
|
||||
Log("Failed to find bone index %d for bone %s", boneName);
|
||||
return;
|
||||
}
|
||||
|
||||
RenderableManager &rm = _engine->getRenderableManager();
|
||||
|
||||
RenderableManager::Bone transform = {.unitQuaternion={quatX,quatY,quatZ,quatW}, .translation={transX,transY,transZ}};
|
||||
|
||||
for(int j = 0; j < _asset->getEntityCount(); j++) {
|
||||
Entity e = _asset->getEntities()[j];
|
||||
if(strcmp(entityName,_ncm->getName(_ncm->getInstance(e)))==0) {
|
||||
|
||||
Log("Setting bone transform on entity %s", _ncm->getName(_ncm->getInstance(e)));
|
||||
|
||||
auto inst = rm.getInstance(e);
|
||||
if(!inst) {
|
||||
Log("No renderable instance");
|
||||
}
|
||||
rm.setBones(inst, &transform, 1, boneIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const utils::Entity *SceneAsset::getCameraEntities() {
|
||||
return _asset->getCameraEntities();
|
||||
|
||||
@@ -106,13 +106,15 @@ SceneAsset *SceneAssetLoader::fromGlb(const char *uri) {
|
||||
Log("Resources loaded.");
|
||||
|
||||
const Entity *entities = asset->getEntities();
|
||||
|
||||
RenderableManager &rm = _engine->getRenderableManager();
|
||||
|
||||
// why did I need to explicitly enable culling?
|
||||
for (int i = 0; i < asset->getEntityCount(); i++) {
|
||||
Entity e = entities[i];
|
||||
auto inst = rm.getInstance(e);
|
||||
// check this
|
||||
rm.setCulling(inst, true);
|
||||
}
|
||||
auto entityInstance = rm.getInstance(entities[i]);
|
||||
rm.setCulling(entityInstance, true);
|
||||
}
|
||||
|
||||
|
||||
FilamentInstance* inst = asset->getInstance();
|
||||
inst->getAnimator()->updateBoneMatrices();
|
||||
|
||||
479
ios/src/Untitled-1.cpp
Normal file
479
ios/src/Untitled-1.cpp
Normal file
@@ -0,0 +1,479 @@
|
||||
|
||||
|
||||
// // /* GL objects */
|
||||
// // guint vao;
|
||||
// // guint program;
|
||||
// // guint position_index;
|
||||
// // guint color_index;
|
||||
|
||||
// // GError *error = NULL;
|
||||
// // std::cout << "init shaders" << std::endl;
|
||||
|
||||
// // if (!init_shaders (&program,
|
||||
// // &position_index,
|
||||
// // &color_index,
|
||||
// // &error))
|
||||
// // {
|
||||
|
||||
// // std::cout << "EROR" << std::endl;
|
||||
// // return FALSE;
|
||||
// // }
|
||||
|
||||
// // std::cout << "init buffers" << std::endl;
|
||||
|
||||
|
||||
// // /* initialize the vertex buffers */
|
||||
// // init_buffers (position_index, color_index, &vao);
|
||||
// // std::cout << "use prog" << std::endl;
|
||||
|
||||
// // GLuint texID = glGetUniformLocation(program, "myTextureSampler");
|
||||
|
||||
// // // The framebuffer, which regroups 0, 1, or more textures, and 0 or 1 depth buffer.
|
||||
// // GLuint FramebufferName = 0;
|
||||
// // glGenFramebuffers(1, &FramebufferName);
|
||||
// // glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
|
||||
|
||||
// // The texture we're going to render to
|
||||
// glGenTextures(1, &self->texture_id);
|
||||
|
||||
// if(self->texture_id == 0) {
|
||||
// std::cout << "tecxtur eeror" << std::endl;
|
||||
// }
|
||||
|
||||
|
||||
// // "Bind" the newly created texture : all future texture functions will modify this texture
|
||||
// glBindTexture(GL_TEXTURE_2D, self->texture_id);
|
||||
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
// glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, self->width, self->height, 0, GL_RGBA,
|
||||
// GL_UNSIGNED_BYTE, 0);
|
||||
|
||||
|
||||
// // // Set "renderedTexture" as our colour attachement #0
|
||||
// // glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, self->texture_id, 0);
|
||||
|
||||
// // // Set the list of draw buffers.
|
||||
// // GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
|
||||
// // glDrawBuffers(1, DrawBuffers); // "1" is the size of DrawBuffers
|
||||
|
||||
// // // Always check that our framebuffer is ok
|
||||
// // if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
// // std::cout << "FB error" << std::endl;
|
||||
// // return FALSE;
|
||||
// // }
|
||||
|
||||
// // glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
|
||||
|
||||
// // glViewport(0,0,400,200); // Render on the whole framebuffer, complete from the lower left corner to the upper righ
|
||||
|
||||
// // // Clear the screen
|
||||
// // glClearColor (0.0, 1.0, 0.5, 1.0);
|
||||
// // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// // /* load our program */
|
||||
// // glUseProgram (program);
|
||||
|
||||
// // // Bind our texture in Texture Unit 0
|
||||
// // glActiveTexture(GL_TEXTURE0);
|
||||
// // glBindTexture(GL_TEXTURE_2D, self->texture_id);
|
||||
// // // Set our "renderedTexture" sampler to use Texture Unit 0
|
||||
// // glUniform1i(texID, 0);
|
||||
|
||||
// // /* use the buffers in the VAO */
|
||||
// // glBindVertexArray (vao);
|
||||
|
||||
// // /* draw the three vertices as a triangle */
|
||||
// // glDrawArrays (GL_TRIANGLES, 0, 3);
|
||||
|
||||
// // /* we finished using the buffers and program */
|
||||
// // glBindVertexArray (0);
|
||||
// // glUseProgram (0);
|
||||
|
||||
|
||||
// // glFlush ();
|
||||
|
||||
|
||||
// // glGenTextures (1, &self->texture_id);
|
||||
// // glBindTexture (GL_TEXTURE_2D, self->texture_id);
|
||||
// // // further configuration here.
|
||||
|
||||
|
||||
// /* position and color information for each vertex */
|
||||
// struct vertex_info {
|
||||
// float position[3];
|
||||
// float color[3];
|
||||
// };
|
||||
|
||||
// /* the vertex data is constant */
|
||||
// static const struct vertex_info vertex_data[] = {
|
||||
// { { 0.0f, 0.500f, 0.0f }, { 1.f, 0.f, 0.f } },
|
||||
// { { 0.5f, -0.366f, 0.0f }, { 0.f, 1.f, 0.f } },
|
||||
// { { -0.5f, -0.366f, 0.0f }, { 0.f, 0.f, 1.f } },
|
||||
// };
|
||||
|
||||
// static void
|
||||
// init_buffers (guint position_index,
|
||||
// guint color_index,
|
||||
// guint *vao_out)
|
||||
// {
|
||||
// guint vao, buffer;
|
||||
|
||||
// /* we need to create a VAO to store the other buffers */
|
||||
// glGenVertexArrays (1, &vao);
|
||||
// glBindVertexArray (vao);
|
||||
|
||||
// /* this is the VBO that holds the vertex data */
|
||||
// glGenBuffers (1, &buffer);
|
||||
// glBindBuffer (GL_ARRAY_BUFFER, buffer);
|
||||
// glBufferData (GL_ARRAY_BUFFER, sizeof (vertex_data), vertex_data, GL_STATIC_DRAW);
|
||||
|
||||
// /* enable and set the position attribute */
|
||||
// glEnableVertexAttribArray (position_index);
|
||||
// glVertexAttribPointer (position_index, 3, GL_FLOAT, GL_FALSE,
|
||||
// sizeof (struct vertex_info),
|
||||
// (GLvoid *) (G_STRUCT_OFFSET (struct vertex_info, position)));
|
||||
|
||||
// /* enable and set the color attribute */
|
||||
// glEnableVertexAttribArray (color_index);
|
||||
// glVertexAttribPointer (color_index, 3, GL_FLOAT, GL_FALSE,
|
||||
// sizeof (struct vertex_info),
|
||||
// (GLvoid *) (G_STRUCT_OFFSET (struct vertex_info, color)));
|
||||
|
||||
// /* reset the state; we will re-enable the VAO when needed */
|
||||
// glBindBuffer (GL_ARRAY_BUFFER, 0);
|
||||
// glBindVertexArray (0);
|
||||
|
||||
// /* the VBO is referenced by the VAO */
|
||||
// glDeleteBuffers (1, &buffer);
|
||||
|
||||
// if (vao_out != NULL)
|
||||
// *vao_out = vao;
|
||||
// }
|
||||
|
||||
// static guint
|
||||
// create_shader (int shader_type,
|
||||
// const char *source,
|
||||
// GError **error,
|
||||
// guint *shader_out)
|
||||
// {
|
||||
// guint shader = glCreateShader (shader_type);
|
||||
// glShaderSource (shader, 1, &source, NULL);
|
||||
// glCompileShader (shader);
|
||||
|
||||
// int status;
|
||||
// glGetShaderiv (shader, GL_COMPILE_STATUS, &status);
|
||||
// if (status == GL_FALSE)
|
||||
// {
|
||||
// std::cout << "SHADER IV ERROR" << std::endl;
|
||||
// }
|
||||
|
||||
// if (shader_out != NULL)
|
||||
// *shader_out = shader;
|
||||
|
||||
// return shader != 0;
|
||||
// }
|
||||
|
||||
|
||||
// static gboolean
|
||||
// init_shaders (guint *program_out,
|
||||
// guint *position_location_out,
|
||||
// guint *color_location_out,
|
||||
// GError **error)
|
||||
// {
|
||||
// const char *vsource = R"POO(#version 330 core
|
||||
|
||||
// layout(location=0) in vec3 position;
|
||||
// layout(location=1) in vec2 vertexUV;
|
||||
|
||||
// out vec2 UV;
|
||||
|
||||
// void main() {
|
||||
// gl_Position = vec4(position, 1.0);
|
||||
// UV = vertexUV;
|
||||
// })POO";
|
||||
|
||||
// const char *fsource = R"POO(#version 330 core
|
||||
|
||||
// in vec2 UV;
|
||||
|
||||
// // Ouput data
|
||||
// layout(location = 0) out vec3 color;
|
||||
|
||||
// uniform sampler2D myTextureSampler;
|
||||
|
||||
// void main() {
|
||||
// color = vec3(1.0,0.0,0.0);
|
||||
// // color = texture( myTextureSampler, UV ).rgb;
|
||||
// })POO";
|
||||
|
||||
// // const char *vsource2 = R"POO(#version 130
|
||||
|
||||
// // in vec3 position;
|
||||
// // in vec3 color;
|
||||
|
||||
// // uniform mat4 mvp;
|
||||
|
||||
// // smooth out vec4 vertexColor;
|
||||
|
||||
// // void main() {
|
||||
// // gl_Position = vec4(position, 1.0);
|
||||
// // vertexColor = vec4(color, 1.0);
|
||||
// // })POO";
|
||||
|
||||
// // const char *fsource2 = R"POO(#version 130
|
||||
|
||||
// // in vec2 UV;
|
||||
// // out vec3 color;
|
||||
|
||||
// // uniform sampler2D renderedTexture;
|
||||
|
||||
// // void main() {
|
||||
// // color = texture(renderedTexture, UV.xyz);
|
||||
// // })POO";
|
||||
|
||||
// guint program = 0;
|
||||
// // guint program2 = 0;
|
||||
|
||||
// guint vertex = 0, fragment = 0;
|
||||
// // guint vertex2 = 0, fragment2 = 0;
|
||||
|
||||
// guint position_location = 0;
|
||||
// guint color_location = 0;
|
||||
|
||||
// /* load the vertex shader */
|
||||
// create_shader (GL_VERTEX_SHADER, vsource, error, &vertex);
|
||||
// // g_bytes_unref (source);
|
||||
// if (vertex == 0) {
|
||||
// std::cout << "VERTEX ERROR" << std::endl;
|
||||
// }
|
||||
|
||||
|
||||
// /* load the fragment shader */
|
||||
// // source = g_resources_lookup_data ("/io/bassi/glarea/glarea-fragment.glsl", 0, NULL);
|
||||
// create_shader (GL_FRAGMENT_SHADER, fsource, error, &fragment);
|
||||
|
||||
// if (fragment == 0)
|
||||
// std::cout << "FRAF ERROR" << std::endl;
|
||||
|
||||
// /* link the vertex and fragment shaders together */
|
||||
// program = glCreateProgram ();
|
||||
|
||||
// if(program == 0) {
|
||||
// std::cout << "PROG ZERO" << std::endl;
|
||||
// }
|
||||
// glAttachShader (program, vertex);
|
||||
// glAttachShader (program, fragment);
|
||||
// glLinkProgram (program);
|
||||
|
||||
// int status = 0;
|
||||
// glGetProgramiv (program, GL_LINK_STATUS, &status);
|
||||
// if (status == GL_FALSE)
|
||||
// {
|
||||
// std::cout << "glGetProgramiv ERROR" << std::endl;
|
||||
// goto out;
|
||||
// }
|
||||
|
||||
// position_location = glGetAttribLocation (program, "position");
|
||||
|
||||
// /* get the location of the "position" and "color" attributes */
|
||||
// color_location = glGetAttribLocation (program, "color");
|
||||
|
||||
// /* the individual shaders can be detached and destroyed */
|
||||
// glDetachShader (program, vertex);
|
||||
// glDetachShader (program, fragment);
|
||||
|
||||
// // program2 = glCreateProgram();
|
||||
|
||||
// // create_shader (GL_VERTEX_SHADER, vsource2, error, &vertex2);
|
||||
// // // g_bytes_unref (source);
|
||||
// // if (vertex2 == 0) {
|
||||
// // std::cout << "VERTEX 2ERROR" << std::endl;
|
||||
// // }
|
||||
// // create_shader (GL_VERTEX_SHADER, fsource2, error, &fragment2);
|
||||
// // // g_bytes_unref (source);
|
||||
// // if (fragment2 == 0) {
|
||||
// // std::cout << "fragment2 ERROR" << std::endl;
|
||||
// // }
|
||||
|
||||
// // glAttachShader (program2, vertex2);
|
||||
// // glAttachShader (program2, fragment2);
|
||||
// // glLinkProgram (program2);
|
||||
|
||||
// // status = 0;
|
||||
// // glGetProgramiv (program2, GL_LINK_STATUS, &status);
|
||||
// // if (status == GL_FALSE)
|
||||
// // {
|
||||
// // std::cout << "glGetProgramiv2 ERROR" << std::endl;
|
||||
// // goto out;
|
||||
// // }
|
||||
|
||||
|
||||
|
||||
// out:
|
||||
// if (vertex != 0)
|
||||
// glDeleteShader (vertex);
|
||||
// if (fragment != 0)
|
||||
// glDeleteShader (fragment);
|
||||
|
||||
// if (program_out != NULL)
|
||||
// *program_out = program;
|
||||
// if (position_location_out != NULL)
|
||||
// *position_location_out = position_location;
|
||||
// if (color_location_out != NULL)
|
||||
// *color_location_out = color_location;
|
||||
|
||||
// return program != 0;
|
||||
// }
|
||||
|
||||
|
||||
std::vector<uint8_t> raw_buffer;
|
||||
uint32_t pixels_w = 400; //w;
|
||||
uint32_t pixels_h = 200; //h;
|
||||
raw_buffer.resize(pixels_w*pixels_h * 4);
|
||||
filament::backend::PixelBufferDescriptor bd(
|
||||
raw_buffer.data(),
|
||||
raw_buffer.size(),
|
||||
backend::PixelDataFormat::RGBA,
|
||||
backend::PixelDataType::UBYTE,
|
||||
[](void* buffer, size_t size, void* capture_state) {
|
||||
uint8_t* foo = (uint8_t*)buffer;
|
||||
int32_t sum = 0;
|
||||
for(int i =0; i < size; i++) {
|
||||
sum += foo[i];
|
||||
}
|
||||
|
||||
Log("SUM : %d", sum);
|
||||
|
||||
std::string path = "./out.raw";
|
||||
std::ofstream stream(path, std::ios::out | std::ios::binary);
|
||||
if(!stream.good())
|
||||
{
|
||||
std::cerr << "Failed to open: " << path << std::endl;
|
||||
}
|
||||
else {
|
||||
std::cerr << "Raw buf size " << size << std::endl;
|
||||
stream.write((char*)buffer, size);
|
||||
stream.close();
|
||||
}
|
||||
|
||||
});
|
||||
render(0);
|
||||
//after rendering to the target we can now read it back
|
||||
_renderer->readPixels(_rt,0,0,pixels_w,pixels_h,std::move(bd));
|
||||
|
||||
_engine->flushAndWait();
|
||||
|
||||
// static void
|
||||
// gl_init (PolyvoxFilamentPlugin *self)
|
||||
// {
|
||||
// std::cout << "GL INIT!" << std::endl;
|
||||
// /* we need to ensure that the GdkGLContext is set before calling GL API */
|
||||
// gtk_gl_area_make_current (GTK_GL_AREA (self->gl_drawing_area));
|
||||
// gtk_gl_area_attach_buffers(GTK_GL_AREA (self->gl_drawing_area));
|
||||
|
||||
// gtk_gl_area_set_has_alpha(GTK_GL_AREA (self->gl_drawing_area), TRUE);
|
||||
// gtk_gl_area_set_has_depth_buffer(GTK_GL_AREA (self->gl_drawing_area), TRUE);
|
||||
// gtk_gl_area_set_has_stencil_buffer(GTK_GL_AREA (self->gl_drawing_area), TRUE);
|
||||
|
||||
|
||||
// if(!gtk_gl_area_get_has_depth_buffer(GTK_GL_AREA (self->gl_drawing_area))) {
|
||||
// std::cout << "NO DEPTH" << std::endl;
|
||||
// }
|
||||
|
||||
// if(!gtk_gl_area_get_has_stencil_buffer(GTK_GL_AREA (self->gl_drawing_area))) {
|
||||
// std::cout << "NO STENCIL" << std::endl;
|
||||
// }
|
||||
|
||||
// /* if the GtkGLArea is in an error state we don't do anything */
|
||||
// if (gtk_gl_area_get_error (GTK_GL_AREA (self->gl_drawing_area)) != NULL) {
|
||||
// std::cout << "ERRIOR" << std::endl;
|
||||
// return;
|
||||
// }
|
||||
// auto ctx = gtk_gl_area_get_context ( GTK_GL_AREA(self->gl_drawing_area) );
|
||||
|
||||
// // auto foo = gdk_gl_context_get_shared_context(ctx);
|
||||
|
||||
// int default_id;
|
||||
|
||||
// glGetIntegerv(GL_FRAMEBUFFER_BINDING, &default_id);
|
||||
|
||||
// std::cout << "DEFAULT ID " << default_id << std::endl;
|
||||
|
||||
// GLuint fbo = 0;
|
||||
// glGenFramebuffers(1, &fbo);
|
||||
// glBindFramebuffer(GL_FRAMEBUFFER_EXT, fbo);
|
||||
|
||||
|
||||
// filament_viewer_new(
|
||||
// (void*)ctx,
|
||||
// loadResource,
|
||||
// freeResource
|
||||
// );
|
||||
|
||||
// // if(!viewer) {
|
||||
// // std::cout << "ERROR" << std::endl;
|
||||
// // }
|
||||
|
||||
// // self->_viewer = viewer;
|
||||
|
||||
// // create_swap_chain(self->_viewer);
|
||||
|
||||
// // create_render_target(self->_viewer, ((FilamentTextureGL*)texture)->texture_id,400,200);
|
||||
|
||||
|
||||
// }
|
||||
|
||||
struct _PolyvoxFilamentPlugin {
|
||||
GObject parent_instance;
|
||||
FlTextureRegistrar* texture_registrar;
|
||||
FlView* fl_view;
|
||||
|
||||
FlTexture* texture;
|
||||
void* _viewer;
|
||||
GtkWidget* gl_drawing_area ;
|
||||
|
||||
|
||||
/* GL objects */
|
||||
guint vao;
|
||||
guint program;
|
||||
guint position_index;
|
||||
guint color_index;
|
||||
};
|
||||
|
||||
|
||||
// GtkWidget *tview;
|
||||
// GtkTextBuffer *buffer;
|
||||
|
||||
// tview = gtk_text_view_new ();
|
||||
// gtk_widget_show(GTK_WIDGET(tview));
|
||||
|
||||
// buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (tview));
|
||||
|
||||
// gtk_text_buffer_set_text (buffer, "Hello, this is some text", -1);
|
||||
|
||||
// GtkCssProvider *provider;
|
||||
// GtkStyleContext *context;
|
||||
// provider = gtk_css_provider_new ();
|
||||
// gtk_css_provider_load_from_data (provider,
|
||||
// "textview {"
|
||||
// " font: 15 serif;"
|
||||
// " color: green;"
|
||||
// "}",
|
||||
// -1,
|
||||
// NULL);
|
||||
// context = gtk_widget_get_style_context (tview);
|
||||
// gtk_style_context_add_provider (context,
|
||||
// GTK_STYLE_PROVIDER (provider),
|
||||
// GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
|
||||
// gtk_box_pack_start(box, GTK_WIDGET(tview), true, true,0);
|
||||
// gtk_widget_grab_focus(GTK_WIDGET(tview));
|
||||
|
||||
GtkBox* box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 1));
|
||||
gtk_widget_show(GTK_WIDGET(box));
|
||||
gtk_widget_show(GTK_WIDGET(view));
|
||||
|
||||
gtk_box_pack_start(box, GTK_WIDGET(view), true, true,0);
|
||||
Reference in New Issue
Block a user