Hey everyone, I am currently in the prototyping phase of developing a simple subcomponent of my graphics engine, using the console. It is meant to extract vertex and pixel data from a 24 bit color .bmp file into it's own .iod file (my file format).
That data, upon instruction, will be loaded into the vertex buffers, texture arrays and pixel shaders. It will be an external image exporter if you like.
My question is whether I should do this or just get my engine to just directly extract the data and load it into the rendering pipeline without all these extra steps.
Advantages I can think of my current design plan:
*Less memory needs to be dynamically allocated during actual runtime of whatever application is using the engine, since only relevant data has been extracted.
*File formats change over time, having my 'own' (sort of) will save a lot of earache.
Can anyone think of any disadvantages? Is this a good design plan?
I will show you my source code:
*NOTE: It is still under development, I know I should also define my own copy constructor and assignment operator to avoid two pointers sharing the same memory, and I also know that globally using the standard namespace is a bad idea. I wrote it last night.*
*UPDATED*
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
//UNDER CONSTRUCTION
#include <resource_mgr.h>
using namespace std;
namespace obv {
class resource_mgr { //planning to include png formatting as well, hence the abstract class
virtual void parse() = 0;
};
class bmp_resource : public resource_mgr {
private:
int block_size;
unsigned char * scanner;
bool file_found;
public:
bmp_resource(const char*); //constructor scans image file data
bmp_resource(const bmp_resource&); //under costruction
~bmp_resource(); // deallocates memory from the heap
void parse(); // 'parses' or 'extracts' appropriate data into new IOD file
};
bmp_resource::bmp_resource(const char* filename) : file_found(false) {
ifstream img_file (filename, ios::binary | ios::ate | ios::in);
if(img_file.is_open()) {
file_found = true;
block_size = (int) img_file.tellg();
scanner = new unsigned char [block_size];
img_file.seekg(0,ios::beg);
img_file.read((char*)scanner, block_size);
img_file.close();
}
else {
file_found = false;
}
}
bmp_resource::~bmp_resource() {
if(file_found) {
delete [] scanner;
}
}
void bmp_resource::parse() {
if(file_found) {
ofstream parsed_file;
parsed_file.open("img_data.oid", ios::binary);
for(int x = 54; x<block_size; x++) {
parsed_file << scanner[x];
}
parsed_file.close();
}
}
}
int main() {
obv::bmp_resource test ("testpic1.bmp");
test.parse();
return 0;
}
|
Thanks for any feedback!