git-svn-id: svn://db.shs.com.ru/libs@290 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2017-10-06 11:35:57 +00:00
parent e91cd3d941
commit 7d82c271e3
9 changed files with 136 additions and 102 deletions

View File

@@ -25,7 +25,7 @@ qt_add_library(${PROJECT_NAME} SHARED out_CPP)
qt_target_link_libraries(${PROJECT_NAME} qad_utils qad_widgets ${OPENGL_LIBRARIES})
message(STATUS "Building ${PROJECT_NAME}")
if (LIBPROJECT)
sdk_install("qad" "${PROJECT_NAME}" "${H}")
sdk_install("qad" "${PROJECT_NAME}" "${out_HDR}")
else()
if (LIB)
if (WIN32)

View File

@@ -83,6 +83,7 @@ void GLCubeTexture::loadPathesFromDirectory(const QString & dir) {
GLuint GLTextureManagerBase::loadTexture(const QString & path, bool ownership, bool bump) {
if (!currentGLTextureManager) return 0;
QString p = findFile(path, search_pathes);
if (p.isEmpty()) return 0;
int tid = ((GLTextureManagerBase*)currentGLTextureManager)->textureID(p, bump);
@@ -225,7 +226,8 @@ void Material::apply(__GLShaderProgram__ * prog) {
void Material::loadTextures(GLTextureManagerBase * tm) {
//qDebug() << "load textures";
if (tm == 0) tm = (GLTextureManagerBase*)currentGLTextureManager;
if (!tm) tm = (GLTextureManagerBase*)currentGLTextureManager;
if (!tm) return;
if (!map_diffuse.bitmap_path.isEmpty()) map_diffuse.bitmap_id = tm->loadTexture(map_diffuse.bitmap_path);
if (!map_normal.bitmap_path.isEmpty()) map_normal.bitmap_id = tm->loadTexture(map_normal.bitmap_path, true, true);
if (!map_relief.bitmap_path.isEmpty()) map_relief.bitmap_id = tm->loadTexture(map_relief.bitmap_path);

View File

@@ -185,7 +185,7 @@ QMatrix4x4 getGLMatrix(GLenum matrix);
void setGLMatrix(QMatrix4x4 matrix);
inline void deleteGLTexture(GLuint & tex) {if (tex != 0) glDeleteTextures(1, &tex); tex = 0;}
#if QT_VERSION >= 0x050600
# define QGLCI QOpenGLExtraFunctions gf(QOpenGLContext::currentContext());
# define QGLCI if (!QOpenGLContext::currentContext()) return; QOpenGLExtraFunctions gf(QOpenGLContext::currentContext());
# define QGLC gf.
inline void glActiveTextureChannel(int channel) {QGLCI gf.glActiveTexture(GL_TEXTURE0 + channel);}
inline void glDisableTextures(int channels = 8) {QGLCI for (int i = channels - 1; i >= 0; --i) {glActiveTextureChannel(i); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_CUBE_MAP);}}

View File

@@ -39,6 +39,7 @@ QGLView::QGLView(QWidget * parent): QGraphicsView(parent), fbo_selection(3) {
setFocusPolicy(Qt::WheelFocus);
setScene(new QGraphicsScene());
setInteractive(true);
need_init_ = true;
objects_.is_root = true;
painter_ = 0;
backColor_ = Qt::black;
@@ -108,8 +109,11 @@ QGLView::QGLView(QWidget * parent): QGraphicsView(parent), fbo_selection(3) {
QGLView::~QGLView() {
stop();
if (shader_select != 0) delete shader_select;
if (shader_halo != 0) delete shader_halo;
currentQGLView = 0;
currentGLTextureManager = 0;
//if (shader_rope != 0) delete shader_rope;
}
@@ -159,12 +163,13 @@ void QGLView::drawBackground(QPainter * painter, const QRectF & rect) {
glDisable(GL_CULL_FACE);
glReleaseTextures();
QGraphicsView::drawBackground(painter_, rect);
painter_ = 0;
}
void QGLView::initializeGL() {
//qDebug() << "init glview";
makeCurrent();
//makeCurrent();
#if QT_VERSION >= 0x050600
initializeOpenGLFunctions();
#endif
@@ -216,11 +221,18 @@ void QGLView::initializeGL() {
//createGLTexture(t, QImage("e/bottom.jpg"));
//qDebug() << bindTexture(QImage("e/bottom.jpg"));
need_init_ = false;
emit glInitializeDone();
}
void QGLView::paintGL() {
#if QT_VERSION >= 0x050600
//initializeOpenGLFunctions();
if (need_init_)
initializeGL();
#endif
//qDebug() << "paintGL";
//QMutexLocker ml_v(&v_mutex);
glEnable(GL_CULL_FACE);
//glDisable(GL_CULL_FACE);
@@ -308,6 +320,7 @@ void QGLView::paintGL() {
renderer_->prepareScene();
renderer_->renderScene();
}
emit glPainting();
if (selectionHalo_ || hoverHalo_) {
glReleaseTextures();
glReleaseShaders();
@@ -342,7 +355,7 @@ void QGLView::paintGL() {
glResetAllTransforms();
glReleaseFramebuffer();
emit glPainting();
emit glEndPaint();
/*releaseShaders();
glActiveTextureChannel(0);

View File

@@ -269,7 +269,7 @@ private:
double fogDensity_, fogStart_, fogEnd_, fps_, fps_tm, hoverHaloFill_, selectionHaloFill_, m_motionBlurFactor;
int timer, fps_cnt, sh_id_loc;
bool is_init, fogEnabled_, lightEnabled_, grabMouse_, mouse_first, mouseRotate_, mouseSelect_, customMouseMove_;
bool shaders_supported, changed_, cameraOrbit_;
bool shaders_supported, changed_, cameraOrbit_, need_init_;
bool hoverHalo_, selectionHalo_, mouseThis_, shaders_bind, selecting_;
public slots:
@@ -305,6 +305,7 @@ public slots:
signals:
void glBeginPaint();
void glPainting();
void glEndPaint();
void glKeyPressEvent(QKeyEvent * e);
void glKeyReleaseEvent(QKeyEvent * e);
void glMousePressEvent(QMouseEvent * e);

View File

@@ -88,13 +88,13 @@ void RendererDeferredShading::renderScene() {
fbo_g.bind();
int buffs[] = {0, 1, 2, 3, 4};
fbo_g.setWriteBuffers(buffs, 5);
if (white_image_id == 0) {
if (white_image_id == 0 && currentGLTextureManager) {
glActiveTextureChannel(6);
white_image_id = ((GLTextureManagerBase*)currentGLTextureManager)->loadTexture(white_image, false);
glBindTexture(GL_TEXTURE_2D, white_image_id);
glActiveTextureChannel(0);
}
if (violent_image_id == 0) {
if (violent_image_id == 0 && currentGLTextureManager) {
glActiveTextureChannel(7);
violent_image_id = ((GLTextureManagerBase*)currentGLTextureManager)->loadTexture(violent_image, false);
glBindTexture(GL_TEXTURE_2D, violent_image_id);