/* \brief get renderer features */ GLHCKAPI const glhckRenderFeatures* glhckRenderGetFeatures(void) { GLHCK_INITIALIZED(); TRACE(0); RET(0, "%p", &GLHCKR()->features); return &GLHCKR()->features; }
/* \brief update the camera stack after window resize */ void _glhckCameraWorldUpdate(int width, int height) { glhckCamera *camera; int diffw, diffh; CALL(2, "%d, %d", width, height); /* get difference of old dimensions and now */ diffw = width - GLHCKR()->width; diffh = height - GLHCKR()->height; for (camera = GLHCKW()->camera; camera; camera = camera->next) { glhckCameraViewporti(camera, camera->view.viewport.x, camera->view.viewport.y, camera->view.viewport.w + diffw, camera->view.viewport.h + diffh); } /* no camera binded, upload default projection */ if (!(camera = GLHCKRD()->camera)) { _glhckRenderDefaultProjection(width, height); glhckRenderViewporti(0, 0, width, height); } else { /* update camera */ GLHCKRD()->camera = NULL; camera->view.update = 1; glhckCameraUpdate(camera); } }
/* \brief get current renderer name */ GLHCKAPI const char* glhckRenderName(void) { GLHCK_INITIALIZED(); TRACE(0); RET(0, "%s", GLHCKR()->name); return GLHCKR()->name; }
/* \brief return detected driver type */ GLHCKAPI glhckDriverType glhckRenderGetDriver(void) { GLHCK_INITIALIZED(); TRACE(0); RET(0, "%u", GLHCKR()->driver); return GLHCKR()->driver; }
/* \brief close the virutal display */ GLHCKAPI void glhckDisplayClose(void) { GLHCK_INITIALIZED(); TRACE(0); if (!_glhckRenderInitialized()) return; memset(&GLHCKR()->features, 0, sizeof(glhckRenderFeatures)); GLHCKRA()->terminate(); GLHCKR()->type = GLHCK_RENDER_AUTO; }
/* \brief reset camera to default state */ GLHCKAPI void glhckCameraReset(glhckCamera *object) { CALL(0, "%p", object); assert(object); object->view.update = 1; kmVec3Fill(&object->view.upVector, 0, 1, 0); kmVec3Fill(&object->object->view.rotation, 0, 0, 0); kmVec3Fill(&object->object->view.target, 0, 0, 0); kmVec3Fill(&object->object->view.translation, 0, 0, 1); memset(&object->view.viewport, 0, sizeof(glhckRect)); object->view.viewport.w = GLHCKR()->width; object->view.viewport.h = GLHCKR()->height; _glhckCameraProjectionMatrix(object); }
/* \brief push current render state to stack */ GLHCKAPI void glhckRenderStatePush(void) { __GLHCKrenderState *state; GLHCK_INITIALIZED(); TRACE(2); if (!(state = _glhckMalloc(sizeof(__GLHCKrenderState)))) return; memcpy(&state->pass, &GLHCKR()->pass, sizeof(__GLHCKrenderPass)); memcpy(&state->view, &GLHCKRD()->view, sizeof(__GLHCKrenderView)); state->width = GLHCKR()->width; state->height = GLHCKR()->height; state->next = GLHCKR()->stack; GLHCKR()->stack = state; }
/* \brief resize render viewport internally */ GLHCKAPI void glhckRenderResize(int width, int height) { GLHCK_INITIALIZED(); CALL(1, "%d, %d", width, height); assert(width > 0 && height > 0); if (!_glhckRenderInitialized()) return; /* nothing to resize */ if (GLHCKR()->width == width && GLHCKR()->height == height) return; /* update all cameras */ _glhckCameraWorldUpdate(width, height); /* update on library last, so functions know the old values */ GLHCKR()->width = width; GLHCKR()->height = height; }
/* \brief pop render state from stack */ GLHCKAPI void glhckRenderStatePop(void) { __GLHCKrenderState *state, *newState; if (!(state = GLHCKR()->stack)) return; glhckRenderResize(state->width, state->height); memcpy(&GLHCKR()->pass, &state->pass, sizeof(__GLHCKrenderPass)); glhckRenderClearColor(&state->pass.clearColor); glhckRenderViewport(&state->pass.viewport); glhckRenderProjection(&state->view.projection); glhckRenderView(&state->view.view); GLHCKRA()->setOrthographic(&state->view.orthographic); memcpy(&GLHCKRD()->view.orthographic, &state->view.orthographic, sizeof(kmMat4)); glhckRenderFlip(state->view.flippedProjection); newState = (state?state->next:NULL); IFDO(_glhckFree, state); GLHCKR()->stack = newState; }
/* \brief creates virtual display and inits renderer */ GLHCKAPI int glhckDisplayCreate(int width, int height, glhckRenderType renderType) { GLHCK_INITIALIZED(); CALL(0, "%d, %d, %d", width, height, renderType); if (width <= 0 && height <= 0) goto fail; /* close display if created already */ if (GLHCKR()->type == renderType && renderType != GLHCK_RENDER_AUTO) goto success; else glhckDisplayClose(); /* init renderer */ switch (renderType) { case GLHCK_RENDER_AUTO: #ifdef GLHCK_HAS_OPENGL _glhckRenderOpenGL(); if (_glhckRenderInitialized()) break; #endif #ifdef GLHCK_HAS_OPENGL_FIXED_PIPELINE _glhckRenderOpenGLFixedPipeline(); if (_glhckRenderInitialized()) break; #endif _glhckRenderStub(); break; case GLHCK_RENDER_OPENGL: case GLHCK_RENDER_GLES2: #ifdef GLHCK_HAS_OPENGL _glhckRenderOpenGL(); #else DEBUG(GLHCK_DBG_ERROR, "OpenGL support was not compiled in!"); #endif break; case GLHCK_RENDER_OPENGL_FIXED_PIPELINE: case GLHCK_RENDER_GLES1: #ifdef GLHCK_HAS_OPENGL_FIXED_PIPELINE _glhckRenderOpenGLFixedPipeline(); #else DEBUG(GLHCK_DBG_ERROR, "OpenGL Fixed Pipeline support was not compiled in!"); #endif break; case GLHCK_RENDER_STUB: default: _glhckRenderStub(); break; } /* check that initialization was success */ if (!_glhckRenderInitialized()) goto fail; /* check render api and output warnings, * if any function is missing */ _glhckRenderCheckApi(); GLHCKR()->type = renderType; /* default render pass bits */ glhckRenderPass(glhckRenderPassDefaults()); /* default cull face */ glhckRenderCullFace(GLHCK_BACK); /* counter-clockwise are front face by default */ glhckRenderFrontFace(GLHCK_CCW); /* resize display */ glhckDisplayResize(width, height); success: RET(0, "%d", RETURN_OK); return RETURN_OK; fail: RET(0, "%d", RETURN_FAIL); return RETURN_FAIL; }
/* \brief is renderer initialized? */ int _glhckRenderInitialized(void) { return (GLHCKR()->name?1:0); }