72 auto generatedTextureByteBuffer = ByteBuffer::allocate(generatedTextureWidth * generatedTextureHeight * 4);
76 auto materialTextureBytesPerPixel = texture->
getDepth() / 8;
77 for (
auto y = 0; y < generatedTextureHeight; y++)
78 for (
auto x = 0; x < generatedTextureWidth; x++) {
79 auto atlasTextureIdxX = (x * 2) / atlasTextureSize;
80 auto atlasTextureIdxY = (y * 2) / atlasTextureSize;
81 auto materialTextureX = (x * 2) - (atlasTextureIdxX * atlasTextureSize);
82 auto materialTextureY = (y * 2) - (atlasTextureIdxY * atlasTextureSize);
83 auto materialTextureXFloat =
static_cast<float>(materialTextureX) /
static_cast<float>(atlasTextureSize);
84 auto materialTextureYFloat =
static_cast<float>(materialTextureY) /
static_cast<float>(atlasTextureSize);
86 auto materialSamples = 0;
87 auto materialTextureXInt =
static_cast<int>(materialTextureXFloat *
static_cast<float>(materialTextureWidth));
88 auto materialTextureYInt =
static_cast<int>(materialTextureYFloat *
static_cast<float>(materialTextureHeight));
89 auto materialPixelR = 0;
90 auto materialPixelG = 0;
91 auto materialPixelB = 0;
92 auto materialPixelA = 0;
93 for (
auto y = -1; y <= 1; y++)
94 for (
auto x = -1; x <= 1; x++)
95 if ((Math::abs(x) == 1 && Math::abs(y) == 1) ==
false &&
96 materialTextureXInt + x >= 0 && materialTextureXInt + x < materialTextureWidth &&
97 materialTextureYInt + y >= 0 && materialTextureYInt + y < materialTextureHeight) {
98 auto materialTexturePixelOffset =
99 (atlasTextureIdxY * materialTextureHeight + materialTextureYInt + y) * texture->
getTextureWidth() * materialTextureBytesPerPixel +
100 (atlasTextureIdxX * materialTextureWidth + materialTextureXInt + x) * materialTextureBytesPerPixel;
104 materialPixelA+= materialTextureBytesPerPixel == 4?texture->
getTextureData()->
get(materialTexturePixelOffset + 3):0xff;
107 generatedTextureByteBuffer->put(materialPixelR / materialSamples);
108 generatedTextureByteBuffer->put(materialPixelG / materialSamples);
109 generatedTextureByteBuffer->put(materialPixelB / materialSamples);
110 generatedTextureByteBuffer->put(materialPixelA / materialSamples);
113 auto generatedTexture =
new Texture(
114 id +
".mipmap." + to_string(level),
116 generatedTextureWidth,
117 generatedTextureHeight,
118 generatedTextureWidth,
119 generatedTextureHeight,
120 generatedTextureByteBuffer
122 generatedTexture->setAtlasSize(texture->
getAtlasSize());
123 generatedTexture->acquireReference();
124 return generatedTexture;
ByteBuffer * getTextureData()
int32_t getAtlasSize() const
int32_t getTextureHeight() const
int32_t getTextureWidth() const
Matrix4x4 projectionMatrix
int32_t CUBEMAPTEXTUREINDEX_NEGATIVE_Z
int32_t SHADER_FRAGMENT_SHADER
Matrix4x4 modelViewMatrix
int32_t LIGHTING_SPECULAR
int32_t SHADER_COMPUTE_SHADER
Texture * generateMipMap(const string &id, Texture *texture, int32_t level, int32_t atlasBorderSize)
Generate mip map for atlas texture currently.
int32_t SHADER_VERTEX_SHADER
int32_t UNIFORM_CL_SKINNING_MATRIX_COUNT
int32_t CLEAR_COLOR_BUFFER_BIT
int32_t UNIFORM_CL_SKINNING_VERTEX_COUNT
int32_t CUBEMAPTEXTUREINDEX_NEGATIVE_X
int32_t CUBEMAPTEXTUREINDEX_POSITIVE_Y
int32_t UNIFORM_CL_SKINNING_INSTANCE_COUNT
int32_t CUBEMAPTEXTUREINDEX_NEGATIVE_Y
int32_t DEPTHFUNCTION_ALWAYS
int32_t DEPTHFUNCTION_LESSEQUAL
int32_t DEPTHFUNCTION_GREATEREQUAL
int32_t CUBEMAPTEXTUREINDEX_POSITIVE_Z
int32_t CONTEXTINDEX_DEFAULT
int32_t DEPTHFUNCTION_EQUAL
int32_t FRAMEBUFFER_DEFAULT
int32_t CUBEMAPTEXTUREINDEX_POSITIVE_X
virtual ~Renderer()
Destructor.
int32_t CLEAR_DEPTH_BUFFER_BIT
Matrix4x4 & identity()
Setup identity matrix.
uint8_t get(int32_t position)