Skip to content

Commit 37760f7

Browse files
committed
Improved lightning, debug and other minor changes and improvements
1 parent 11c69c7 commit 37760f7

31 files changed

Lines changed: 602 additions & 191 deletions

Common/Common.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ void CommonUtil::updateFrameBuffer(FrameBuffer *framebuffer, const std::initiali
290290
const unsigned int depth_depth = depthstencil.depth;
291291
const GLenum internal_format = fragcore::GLHelper::getGraphicFormat(depthstencil.graphicFormat);
292292

293-
GLenum texture_type = GL_TEXTURE_2D;
293+
GLenum texture_type = fragcore::GLHelper::getTextureTarget(depthstencil.target);
294294
if (multisamples > 1) {
295295
texture_type = GL_TEXTURE_2D_MULTISAMPLE;
296296
}
@@ -300,8 +300,20 @@ void CommonUtil::updateFrameBuffer(FrameBuffer *framebuffer, const std::initiali
300300
if (multisamples > 0) {
301301
glTexImage2DMultisample(texture_type, multisamples, internal_format, depth_width, depth_height, GL_TRUE);
302302
} else {
303-
glTexImage2D(texture_type, 0, internal_format, depth_width, depth_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
304-
nullptr);
303+
switch (texture_type) {
304+
case GL_TEXTURE_2D:
305+
glTexImage2D(texture_type, 0, internal_format, depth_width, depth_height, 0, GL_DEPTH_COMPONENT,
306+
GL_FLOAT, nullptr);
307+
break;
308+
case GL_TEXTURE_CUBE_MAP:
309+
for (unsigned int i = 0; i < 6; i++) {
310+
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internal_format, depth_width, depth_height, 0,
311+
GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
312+
}
313+
break;
314+
default:
315+
break;
316+
}
305317
}
306318

307319
framebuffer->attachmentSize[framebuffer->depthIndex] = {depth_width, depth_height, depth_depth};
@@ -328,9 +340,15 @@ void CommonUtil::updateFrameBuffer(FrameBuffer *framebuffer, const std::initiali
328340
}
329341

330342
glBindTexture(texture_type, 0);
331-
332-
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, texture_type,
333-
framebuffer->attachments[framebuffer->depthIndex], 0);
343+
switch (texture_type) {
344+
case GL_TEXTURE_2D:
345+
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, texture_type,
346+
framebuffer->attachments[framebuffer->depthIndex], 0);
347+
break;
348+
case GL_TEXTURE_CUBE_MAP:
349+
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, framebuffer->attachments[framebuffer->depthIndex], 0);
350+
break;
351+
}
334352
}
335353

336354
/* Validate if created properly.*/

Common/FPSCounter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace glsample {
2424
template <typename T = float> class FPSCounter {
2525
public:
2626
FPSCounter(const unsigned int nrFPSSample = 50, const size_t timeResolution = 1000000000)
27-
: totalFPS(0), fpsSample(nrFPSSample), averageFPS(0), timeResolution(timeResolution) {}
27+
: fpsSample(nrFPSSample), timeResolution(timeResolution) {}
2828

2929
void update(const float elapsedTime) noexcept { this->incrementFPS(elapsedTime); }
3030

Common/Importer/ImageImport.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,27 @@ unsigned int TextureImporter::loadImage2DRaw(const Image &image, const ColorSpac
4545

4646
this->getFormat(image, format, type, internalformat, colorSpace, compression);
4747

48+
/* */
4849
const size_t power_of_2 = std::floor(std::log(Math::max(image.width(), image.height())) / std::log(2));
4950
const size_t max_mipmap = Math::clamp<size_t>(power_of_2 - 4, 0, std::numeric_limits<size_t>::max());
5051

52+
/* */
5153
GLuint currentPBO = this->pbos[current_pbo++];
5254
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, currentPBO);
5355
glBufferData(GL_PIXEL_UNPACK_BUFFER, image.getSize(), nullptr, GL_STREAM_COPY);
54-
void *ptr = glMapBufferRange(GL_PIXEL_UNPACK_BUFFER_ARB, 0, image.getSize(),
55-
GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
56+
void *ptr = glMapBufferRange(GL_PIXEL_UNPACK_BUFFER_ARB, 0, image.getSize(), GL_MAP_WRITE_BIT);
5657
memcpy(ptr, image.getPixelData(), image.getSize());
5758
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
5859

60+
/* */
5961
FVALIDATE_GL_CALL(glGenTextures(1, &texture));
60-
6162
FVALIDATE_GL_CALL(glBindTexture(target, texture));
6263

6364
/* Offload with PBO buffer. */
6465

6566
/* Alignment. */
6667
FVALIDATE_GL_CALL(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
67-
FVALIDATE_GL_CALL(glPixelStorei(GL_PACK_ALIGNMENT, 4));
68+
FVALIDATE_GL_CALL(glPixelStorei(GL_PACK_ALIGNMENT, 1));
6869

6970
/* wrap and filter. */
7071
FVALIDATE_GL_CALL(glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT));
@@ -100,7 +101,7 @@ unsigned int TextureImporter::loadImage2DRaw(const Image &image, const ColorSpac
100101

101102
FVALIDATE_GL_CALL(glBindTexture(target, 0));
102103

103-
current_pbo = (current_pbo + 1) % pbos.size();
104+
this->current_pbo = (this->current_pbo + 1) % pbos.size();
104105

105106
return texture;
106107
}

Common/Importer/ImageImport.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,15 @@ namespace glsample {
6565
const TextureCompression compression = TextureCompression::None);
6666

6767
protected:
68-
6968
void getFormat(const Image &image, unsigned int &format, unsigned int &dataType, unsigned int &internalformat,
7069
const ColorSpace colorSpace = ColorSpace::RawLinear,
7170
const TextureCompression compression = TextureCompression::None);
7271

7372
private:
7473
fragcore::IFileSystem *filesystem = nullptr;
7574
fragcore::TaskScheduler *schedular;
76-
std::array<unsigned int, 4> pbos = {};
75+
std::array<unsigned int, 8> pbos = {};
7776
std::atomic_int current_pbo = 0;
7877
};
7978

80-
} // namespace glsample
79+
} // namespace glsample

0 commit comments

Comments
 (0)