Commit 6be1769e authored by Patrik Huber's avatar Patrik Huber

Slight overhaul of the Texture class

parent 9a80d232
...@@ -152,10 +152,21 @@ class Texture ...@@ -152,10 +152,21 @@ class Texture
public: public:
// Todo: This whole class needs a major overhaul and documentation. // Todo: This whole class needs a major overhaul and documentation.
// throws: ocv exc, runtime_ex std::vector<cv::Mat> mipmaps; // make Texture a friend class of renderer, then move this to private?
void create_mipmapped_texture(cv::Mat image, unsigned int mipmapsNum = 0) { unsigned char widthLog, heightLog; // log2 of width and height of the base mip-level
//private:
//std::string filename;
unsigned int mipmaps_num;
};
// throws: ocv exc, runtime_ex
Texture create_mipmapped_texture(cv::Mat image, unsigned int mipmapsNum = 0) {
assert(image.type() == CV_8UC3 || image.type() == CV_8UC4);
Texture texture;
this->mipmaps_num = (mipmapsNum == 0 ? get_max_possible_mipmaps_num(image.cols, image.rows) : mipmapsNum); texture.mipmaps_num = (mipmapsNum == 0 ? get_max_possible_mipmaps_num(image.cols, image.rows) : mipmapsNum);
/*if (mipmapsNum == 0) /*if (mipmapsNum == 0)
{ {
uchar mmn = render::utils::MatrixUtils::getMaxPossibleMipmapsNum(image.cols, image.rows); uchar mmn = render::utils::MatrixUtils::getMaxPossibleMipmapsNum(image.cols, image.rows);
...@@ -165,19 +176,23 @@ public: ...@@ -165,19 +176,23 @@ public:
this->mipmapsNum = mipmapsNum; this->mipmapsNum = mipmapsNum;
}*/ }*/
if (this->mipmaps_num > 1) if (texture.mipmaps_num > 1)
{ {
if (!is_power_of_two(image.cols) || !is_power_of_two(image.rows)) if (!is_power_of_two(image.cols) || !is_power_of_two(image.rows))
{ {
throw std::runtime_error("Error: Couldn't generate mipmaps, width or height not power of two."); throw std::runtime_error("Error: Couldn't generate mipmaps, width or height not power of two.");
} }
} }
if (image.type() == CV_8UC3)
{
image.convertTo(image, CV_8UC4); // Most often, the input img is CV_8UC3. Img is BGR. Add an alpha channel image.convertTo(image, CV_8UC4); // Most often, the input img is CV_8UC3. Img is BGR. Add an alpha channel
cv::cvtColor(image, image, CV_BGR2BGRA); cv::cvtColor(image, image, CV_BGR2BGRA);
}
int currWidth = image.cols; int currWidth = image.cols;
int currHeight = image.rows; int currHeight = image.rows;
for (int i = 0; i < this->mipmaps_num; i++) std::vector<cv::Mat> mipmaps;
for (int i = 0; i < texture.mipmaps_num; i++)
{ {
if (i == 0) { if (i == 0) {
mipmaps.push_back(image); mipmaps.push_back(image);
...@@ -193,16 +208,12 @@ public: ...@@ -193,16 +208,12 @@ public:
if (currHeight > 1) if (currHeight > 1)
currHeight >>= 1; currHeight >>= 1;
} }
this->widthLog = (uchar)(std::log(mipmaps[0].cols) / CV_LOG2 + 0.0001f); // std::epsilon or something? or why 0.0001f here? texture.mipmaps = mipmaps;
this->heightLog = (uchar)(std::log(mipmaps[0].rows) / CV_LOG2 + 0.0001f); // Changed std::logf to std::log because it doesnt compile in linux (gcc 4.8). CHECK THAT texture.widthLog = (uchar)(std::log(mipmaps[0].cols) / CV_LOG2 + 0.0001f); // std::epsilon or something? or why 0.0001f here?
}; texture.heightLog = (uchar)(std::log(mipmaps[0].rows) / CV_LOG2 + 0.0001f); // Changed std::logf to std::log because it doesnt compile in linux (gcc 4.8). CHECK THAT
return texture;
std::vector<cv::Mat> mipmaps; // make Texture a friend class of renderer, then move this to private? };
unsigned char widthLog, heightLog; // log2 of width and height of the base mip-level
private:
//std::string filename;
unsigned int mipmaps_num;
}; };
} /* namespace render */ } /* namespace render */
} /* namespace eos */ } /* namespace eos */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment