asdf
This commit is contained in:
@@ -22,9 +22,11 @@ struct defaults {
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::mutex PreviewMutex;
|
std::mutex PreviewMutex;
|
||||||
frame currentPreviewFrame;
|
|
||||||
GLuint textu = 0;
|
GLuint textu = 0;
|
||||||
bool updatePreview;
|
bool textureInitialized = false;
|
||||||
|
bool updatePreview = false;
|
||||||
|
bool previewRequested = false;
|
||||||
|
|
||||||
struct Shared {
|
struct Shared {
|
||||||
std::mutex mutex;
|
std::mutex mutex;
|
||||||
VoxelGrid grid;
|
VoxelGrid grid;
|
||||||
@@ -39,9 +41,9 @@ void setup(defaults config, VoxelGrid& grid) {
|
|||||||
std::cout << "Processing layer " << z << " of " << config.gridDepth << std::endl;
|
std::cout << "Processing layer " << z << " of " << config.gridDepth << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int y = 0; y < config.gridWidth; ++y) {
|
for (int y = 0; y < config.gridHeight; ++y) {
|
||||||
for (int x = 0; x < config.gridHeight; ++x) {
|
for (int x = 0; x < config.gridWidth; ++x) {
|
||||||
Vec4ui8 noisecolor = config.noise.permuteColor(Vec3f( x / 64, y / 64, z / 64));
|
Vec4ui8 noisecolor = config.noise.permuteColor(Vec3f( static_cast<float>(x) / 64, static_cast<float>(y) / 64, static_cast<float>(z) / 64));
|
||||||
if (noisecolor.a > threshold) {
|
if (noisecolor.a > threshold) {
|
||||||
grid.set(Vec3i(x, y, z), true, Vec3ui8(noisecolor.xyz()));
|
grid.set(Vec3i(x, y, z), true, Vec3ui8(noisecolor.xyz()));
|
||||||
}
|
}
|
||||||
@@ -52,22 +54,24 @@ void setup(defaults config, VoxelGrid& grid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void livePreview(VoxelGrid& grid, defaults config, Camera cam) {
|
void livePreview(VoxelGrid& grid, defaults config, Camera cam) {
|
||||||
updatePreview = false;
|
|
||||||
std::lock_guard<std::mutex> lock(PreviewMutex);
|
|
||||||
|
|
||||||
currentPreviewFrame = grid.renderFrame(cam.posfor.origin, cam.posfor.direction, cam.up, cam.fov, config.outWidth, config.outHeight, frame::colormap::BGRA);
|
|
||||||
|
|
||||||
glGenTextures(1, &textu);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, textu);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, textu);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, currentPreviewFrame.getWidth(), currentPreviewFrame.getHeight(),
|
|
||||||
0, GL_RGBA, GL_UNSIGNED_BYTE, currentPreviewFrame.getData().data());
|
|
||||||
|
|
||||||
updatePreview = true;
|
updatePreview = true;
|
||||||
|
//std::lock_guard<std::mutex> lock(PreviewMutex);
|
||||||
|
frame currentPreviewFrame = grid.renderFrame(cam.posfor.origin, cam.posfor.direction, cam.up, cam.fov, config.outWidth, config.outHeight, frame::colormap::BGRA);
|
||||||
|
|
||||||
|
// glGenTextures(1, &textu);
|
||||||
|
// glBindTexture(GL_TEXTURE_2D, textu);
|
||||||
|
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
// glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||||
|
|
||||||
|
// glBindTexture(GL_TEXTURE_2D, textu);
|
||||||
|
// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, currentPreviewFrame.getWidth(), currentPreviewFrame.getHeight(),
|
||||||
|
// 0, GL_RGBA, GL_UNSIGNED_BYTE, currentPreviewFrame.getData().data());
|
||||||
|
|
||||||
|
std::cout << "freeing previous frame" << std::endl;
|
||||||
|
currentPreviewFrame.free();
|
||||||
|
updatePreview = false;
|
||||||
|
textureInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void glfw_error_callback(int error, const char* description)
|
static void glfw_error_callback(int error, const char* description)
|
||||||
@@ -75,7 +79,6 @@ static void glfw_error_callback(int error, const char* description)
|
|||||||
fprintf(stderr, "GLFW Error %d: %s\n", error, description);
|
fprintf(stderr, "GLFW Error %d: %s\n", error, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
glfwSetErrorCallback(glfw_error_callback);
|
glfwSetErrorCallback(glfw_error_callback);
|
||||||
if (!glfwInit()) {
|
if (!glfwInit()) {
|
||||||
@@ -176,15 +179,19 @@ int main() {
|
|||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
// {
|
||||||
ImGui::Begin("Preview");
|
// ImGui::Begin("Preview");
|
||||||
|
|
||||||
if (gridInitialized) {
|
// if (gridInitialized && textureInitialized) {
|
||||||
ImGui::Image((void*)(intptr_t)textu,ImVec2(config.outWidth, config.outHeight));
|
// ImGui::Image((void*)(intptr_t)textu,ImVec2(config.outWidth, config.outHeight));
|
||||||
}
|
// } else if (gridInitialized) {
|
||||||
|
// ImGui::Text("Preview not generated yet");
|
||||||
|
// } else {
|
||||||
|
// ImGui::Text("No grid generated");
|
||||||
|
// }
|
||||||
|
|
||||||
ImGui::End();
|
// ImGui::End();
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (gridInitialized && updatePreview == false) {
|
if (gridInitialized && updatePreview == false) {
|
||||||
livePreview(grid, config, cam);
|
livePreview(grid, config, cam);
|
||||||
|
|||||||
@@ -220,9 +220,11 @@ public:
|
|||||||
float maxDist = std::sqrt(gridSize.lengthSquared()) * binSize;
|
float maxDist = std::sqrt(gridSize.lengthSquared()) * binSize;
|
||||||
frame outFrame(outH, outW, frame::colormap::RGB);
|
frame outFrame(outH, outW, frame::colormap::RGB);
|
||||||
std::vector<uint8_t> colorBuffer(outW * outH * 3);
|
std::vector<uint8_t> colorBuffer(outW * outH * 3);
|
||||||
|
std::cout << "a" << std::endl;
|
||||||
#pragma omp parallel for
|
#pragma omp parallel for
|
||||||
for (int y = 0; y < outH; y++) {
|
for (int y = 0; y < outH; y++) {
|
||||||
float v = (static_cast<float>(y) / static_cast<float>(outH - 1)) - 0.5f;
|
float v = (static_cast<float>(y) / static_cast<float>(outH - 1)) - 0.5f;
|
||||||
|
std::cout << "b";
|
||||||
for (int x = 0; x < outW; x++) {
|
for (int x = 0; x < outW; x++) {
|
||||||
std::vector<Vec3i> hitVoxels;
|
std::vector<Vec3i> hitVoxels;
|
||||||
float u = (static_cast<float>(x) / static_cast<float>(outW - 1)) - 0.5f;
|
float u = (static_cast<float>(x) / static_cast<float>(outW - 1)) - 0.5f;
|
||||||
@@ -242,6 +244,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
std::cout << "c";
|
||||||
hitVoxels.clear();
|
hitVoxels.clear();
|
||||||
hitVoxels.shrink_to_fit();
|
hitVoxels.shrink_to_fit();
|
||||||
// Set pixel color in buffer
|
// Set pixel color in buffer
|
||||||
@@ -264,9 +267,11 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
std::cout << "b" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
outFrame.setData(colorBuffer);
|
outFrame.setData(colorBuffer);
|
||||||
|
std::cout << "d" << std::endl;
|
||||||
return outFrame;
|
return outFrame;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user