2008-05-25 17:34:21 +00:00
|
|
|
#include "AppGLWidget.h"
|
2008-05-19 05:34:31 +00:00
|
|
|
#include "Controller.h"
|
2008-05-25 17:34:21 +00:00
|
|
|
#include "AppConfig.h"
|
|
|
|
|
|
2008-05-19 05:34:31 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
2008-05-29 00:27:09 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-07-02 12:16:36 +00:00
|
|
|
#include "DNA_camera_types.h"
|
|
|
|
|
|
2008-05-29 00:27:09 +00:00
|
|
|
#include "render_types.h"
|
|
|
|
|
#include "renderpipeline.h"
|
|
|
|
|
|
2008-06-08 19:35:20 +00:00
|
|
|
#include "BLI_blenlib.h"
|
2008-08-07 15:04:25 +00:00
|
|
|
#include "BIF_renderwin.h"
|
2008-06-08 19:35:20 +00:00
|
|
|
#include "BPY_extern.h"
|
|
|
|
|
|
2008-05-29 00:27:09 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-05-19 05:34:31 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-07-04 07:59:19 +00:00
|
|
|
static Config::Path *pathconfig = NULL;
|
2008-06-08 19:35:20 +00:00
|
|
|
static Controller *controller = NULL;
|
|
|
|
|
static AppGLWidget *view = NULL;
|
2008-07-04 07:59:19 +00:00
|
|
|
|
2008-07-31 11:20:30 +00:00
|
|
|
char style_module[255] = "";
|
|
|
|
|
|
2008-06-08 19:35:20 +00:00
|
|
|
void FRS_initialize(){
|
2008-05-25 17:34:21 +00:00
|
|
|
|
2008-07-04 07:59:19 +00:00
|
|
|
if( pathconfig == NULL )
|
|
|
|
|
pathconfig = new Config::Path;
|
|
|
|
|
|
2008-06-08 19:35:20 +00:00
|
|
|
if( controller == NULL )
|
|
|
|
|
controller = new Controller;
|
|
|
|
|
|
|
|
|
|
if( view == NULL )
|
|
|
|
|
view = new AppGLWidget;
|
2008-06-16 00:51:19 +00:00
|
|
|
|
2008-07-21 21:24:37 +00:00
|
|
|
controller->setView(view);
|
2008-07-31 11:20:30 +00:00
|
|
|
controller->Clear();
|
|
|
|
|
|
|
|
|
|
if( strlen(style_module) == 0 ){
|
2008-09-29 15:50:50 +00:00
|
|
|
string path( pathconfig->getProjectDir() + Config::DIR_SEP + "style_modules" + Config::DIR_SEP + "contour.py" );
|
2008-07-31 11:20:30 +00:00
|
|
|
strcpy( style_module, path.c_str() );
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-08 19:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-04 07:59:19 +00:00
|
|
|
|
|
|
|
|
void FRS_init_view(Render* re){
|
|
|
|
|
view->setWidth( re->winx );
|
|
|
|
|
view->setHeight( re->winy );
|
|
|
|
|
view->_camera->setScreenWidthAndHeight( re->winx, re->winy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FRS_init_camera(Render* re){
|
2008-06-16 00:51:19 +00:00
|
|
|
Object* maincam_obj = re->scene->camera;
|
2008-07-02 12:16:36 +00:00
|
|
|
Camera *cam = (Camera*) maincam_obj->data;
|
|
|
|
|
|
|
|
|
|
if(cam->type == CAM_PERSP){
|
|
|
|
|
view->_camera->setType(AppGLWidget_Camera::PERSPECTIVE);
|
|
|
|
|
view->_camera->setHorizontalFieldOfView( M_PI / 180.0f * cam->angle );
|
|
|
|
|
}
|
2008-07-04 07:59:19 +00:00
|
|
|
// else if (cam->type == CAM_ORTHO){
|
|
|
|
|
// view->_camera->setType(AppGLWidget_Camera::ORTHOGRAPHIC);
|
|
|
|
|
// // view->_camera->setFocusDistance does not seem to work
|
|
|
|
|
// // integrate cam->ortho_scale parameter
|
|
|
|
|
// }
|
2008-07-02 12:16:36 +00:00
|
|
|
|
2008-06-16 00:51:19 +00:00
|
|
|
Vec camPosition(maincam_obj->obmat[3][0], maincam_obj->obmat[3][1], maincam_obj->obmat[3][2]);
|
|
|
|
|
Vec camUp( re->viewmat[0][1], re->viewmat[1][1], re->viewmat[2][1]);
|
2008-07-02 12:16:36 +00:00
|
|
|
Vec camDirection( -re->viewmat[0][2], -re->viewmat[1][2], -re->viewmat[2][2]);
|
2008-06-16 00:51:19 +00:00
|
|
|
view->_camera->setPosition(camPosition);
|
|
|
|
|
view->_camera->setUpVector(camUp);
|
2008-07-04 07:59:19 +00:00
|
|
|
view->_camera->setViewDirection(camDirection);
|
|
|
|
|
}
|
2008-05-25 17:34:21 +00:00
|
|
|
|
2008-08-07 15:04:25 +00:00
|
|
|
void FRS_load_mesh( Render *re ){
|
|
|
|
|
controller->LoadMesh(re);
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-04 07:59:19 +00:00
|
|
|
void FRS_prepare(Render* re) {
|
|
|
|
|
FRS_initialize();
|
|
|
|
|
|
|
|
|
|
FRS_init_view(re);
|
|
|
|
|
FRS_init_camera(re);
|
2008-08-08 08:53:13 +00:00
|
|
|
|
2008-08-08 08:25:50 +00:00
|
|
|
FRS_load_mesh(re);
|
2008-07-04 07:59:19 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-05 06:22:15 +00:00
|
|
|
void FRS_render(Render* re, int render_in_layer) {
|
|
|
|
|
|
2008-08-07 15:04:25 +00:00
|
|
|
view->workingBuffer = GL_BACK;
|
2008-07-05 06:22:15 +00:00
|
|
|
|
2008-06-16 00:51:19 +00:00
|
|
|
// add style module
|
2008-07-31 11:20:30 +00:00
|
|
|
cout << "Module: " << style_module << endl;
|
|
|
|
|
controller->InsertStyleModule( 0, style_module );
|
2008-06-08 19:35:20 +00:00
|
|
|
controller->toggleLayer(0, true);
|
2008-06-16 00:51:19 +00:00
|
|
|
|
|
|
|
|
// compute view map
|
2008-06-08 19:35:20 +00:00
|
|
|
controller->ComputeViewMap();
|
|
|
|
|
|
2008-06-16 00:51:19 +00:00
|
|
|
// build strokes
|
|
|
|
|
controller->DrawStrokes();
|
|
|
|
|
|
|
|
|
|
// render final result
|
|
|
|
|
view->draw();
|
2008-05-19 05:34:31 +00:00
|
|
|
}
|
2008-07-04 07:59:19 +00:00
|
|
|
|
2008-07-05 06:22:15 +00:00
|
|
|
void FRS_execute(Render* re, int render_in_layer) {
|
|
|
|
|
|
|
|
|
|
if(render_in_layer) {
|
|
|
|
|
|
2008-07-12 04:02:08 +00:00
|
|
|
// GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
|
|
|
|
|
// switch(status){
|
|
|
|
|
// case GL_FRAMEBUFFER_COMPLETE_EXT:
|
|
|
|
|
// cout << "CORRECT: GL_FRAMEBUFFER_COMPLETE" << endl;
|
|
|
|
|
// break;
|
|
|
|
|
// case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
|
|
|
|
|
// cout << "ERROR: GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT" << endl;
|
|
|
|
|
// break;
|
|
|
|
|
// case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
|
|
|
|
|
// cout << "ERROR: GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT" << endl;
|
|
|
|
|
// break;
|
|
|
|
|
// case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
|
|
|
|
|
// cout << "ERROR: GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT" << endl;
|
|
|
|
|
// break;
|
|
|
|
|
// case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
|
|
|
|
|
// cout << "ERROR: GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT" << endl;
|
|
|
|
|
// break;
|
|
|
|
|
// case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
|
|
|
|
|
// cout << "ERROR: GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT" << endl;
|
|
|
|
|
// break;
|
|
|
|
|
// case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
|
|
|
|
|
// cout << "ERROR: GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT" << endl;
|
|
|
|
|
// break;
|
|
|
|
|
// case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
|
|
|
|
|
// cout << "ERROR: GL_FRAMEBUFFER_UNSUPPORTED" << endl;
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
RenderLayer *rl;
|
|
|
|
|
|
2008-07-08 22:55:00 +00:00
|
|
|
for(rl = (RenderLayer *)re->result->layers.first; rl; rl= rl->next)
|
|
|
|
|
if(rl->layflag & SCE_LAY_FRS)
|
|
|
|
|
break;
|
2008-07-12 04:02:08 +00:00
|
|
|
|
2008-07-08 22:55:00 +00:00
|
|
|
int p;
|
2008-07-12 04:02:08 +00:00
|
|
|
for(int j = 0; j < re->winy; j++) {
|
|
|
|
|
for(int i = 0; i < re->winx; i++){
|
|
|
|
|
p = 4*(j*re->winx + i);
|
|
|
|
|
rl->rectf[p] *= 0.6;
|
|
|
|
|
rl->rectf[p + 1] = 0.6 * rl->rectf[p + 1];
|
|
|
|
|
rl->rectf[p + 2] *= 0.6;
|
|
|
|
|
rl->rectf[p + 3] = 1.0;
|
2008-07-05 06:22:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-07-08 22:55:00 +00:00
|
|
|
|
2008-07-05 06:22:15 +00:00
|
|
|
} else {
|
2008-08-07 15:04:25 +00:00
|
|
|
// used to reobtain ogl context after RE_Database_FromScene call
|
|
|
|
|
re->display_clear(re->result);
|
|
|
|
|
|
|
|
|
|
// render strokes
|
|
|
|
|
FRS_render(re, render_in_layer);
|
2008-07-08 22:55:00 +00:00
|
|
|
|
2008-08-07 15:04:25 +00:00
|
|
|
// display result
|
2008-07-05 06:22:15 +00:00
|
|
|
RenderResult rres;
|
|
|
|
|
RE_GetResultImage(re, &rres);
|
|
|
|
|
view->readPixels(0, 0, re->winx, re->winy, AppGLWidget::RGBA, rres.rectf );
|
|
|
|
|
re->result->renlay = render_get_active_layer(re, re->result);
|
|
|
|
|
re->display_draw(re->result, NULL);
|
|
|
|
|
}
|
2008-07-08 22:55:00 +00:00
|
|
|
|
2008-07-05 06:22:15 +00:00
|
|
|
|
|
|
|
|
controller->CloseFile();
|
2008-07-04 07:59:19 +00:00
|
|
|
}
|
2008-05-19 05:34:31 +00:00
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|