void GLHelper::InitGL() { if (false) LOGD("----INITGL----"); // Create display _eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglInitialize(_eglDisplay, 0, 0); // Get suitable configs for this device SetEGLConfigs(); // Create context _eglPBufferContext = eglCreateContext(_eglDisplay, _eglPBufferConfig, EGL_NO_CONTEXT, _contextAttribs); if (_eglPBufferContext == EGL_NO_CONTEXT) XLI_THROW("Unable to create EGL PBuffer Context"); if (false) LOGD("pbufferContext=%d", _eglPBufferContext); // Create surface context: uses the config for rendering (so no buffer bit) _eglSurfaceContext = eglCreateContext(_eglDisplay, _eglRenderConfig, _eglPBufferContext, _contextAttribs); if (_eglSurfaceContext == EGL_NO_CONTEXT) XLI_THROW("Unable to create EGL Surface Context"); if (false) LOGD("surfaceContext=%d", _eglSurfaceContext); // Create worker-thread context: uses the config for rendering (so no buffer bit) _eglWorkerThreadContext = eglCreateContext(_eglDisplay, _eglRenderConfig, _eglPBufferContext, _contextAttribs); if (_eglWorkerThreadContext == EGL_NO_CONTEXT) XLI_THROW("Unable to create EGL Surface Context"); if (false) LOGD("workerThreadContext=%d", _eglWorkerThreadContext); // Create the surface CreatePBufferSurfaceAndMakeCurrent(); // DummySurface is a hack, but for now we need it. Will be removed after cleanup GLHelper::CreateDummySurface(); if (false) LOGD("---~INITGL~---"); }
void UnixFileSystemBase::CopyFile(const String& sourcePath, const String& destinationPath, bool overwrite) { int source; int destination; int createFlags = O_WRONLY | O_CREAT; if (!overwrite) createFlags |=O_EXCL; struct stat stat_buf; size_t size = 0; char buf[BUFSIZ]; source = open(sourcePath.Ptr(), O_RDONLY); if (source == -1) { XLI_THROW("Unable to copy file '" + sourcePath + "'"); } fstat(source, &stat_buf); destination = open(destinationPath.Ptr(), createFlags, stat_buf.st_mode); if (destination == -1) { XLI_THROW("Unable to copy to '" + destinationPath + "'"); } while ((size = read(source, buf, BUFSIZ)) > 0) { write(destination, buf, size); } close (source); close (destination); }
SampleReader::SampleReader(AudioStream* stream, bool forceStereo) { this->stream = stream; if (stream->GetChannelCount() > 2) XLI_THROW("Sample reader stream can only have one or two channels"); if (stream->GetDataType() != Xli::DataTypeInt16) XLI_THROW("Sample reader can only read Int16 streams"); this->forceStereo = forceStereo; this->internalBufferSize = 512; this->internalBuffer = new Int16[this->internalBufferSize]; }
// This is the first point we have in the app lifecycle when we are in control // At this point Xli has been loaded by the Activity.java file and, as specified by // the JNI spec, when a library is loaded, if there is a JNI_OnLoad method, it will // be called. // We use this point to grab the activity class and attach all the lifecycle callbacks jint JNI_OnLoad(JavaVM* vm, void* reserved) { if (false) { LOGD ("----------"); LOGD ("Jni_OnLoad"); } // vm & activityClass JNIEnv* env; if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { LOGD ("&&&&&&& GetEnv failed &&&&&&"); return -1; } jclass activityClass = env->FindClass("com/InfoMedic/InfoMedic"); jclass entryPointsClass = env->FindClass("com/InfoMedic/ActivityNativeEntryPoints"); jclass displayClass = env->FindClass("com/InfoMedic/Display"); jclass nativeExternClass = env->FindClass("com/Bindings/ExternedBlockHost"); if (!activityClass) { LOGD("COULD NOT FIND ACTIVITY CLASS"); XLI_THROW("COULD NOT FIND ACTIVITY CLASS"); } if (!displayClass) { LOGD("COULD NOT FIND DISPLAY CLASS"); XLI_THROW("COULD NOT FIND DISPLAY CLASS"); } if (!entryPointsClass) { LOGD("COULD NOT FIND ENTRYPOINTS CLASS"); XLI_THROW("COULD NOT FIND ENTRYPOINTS CLASS"); } if (!nativeExternClass) { LOGD("COULD NOT FIND NATIVEEXTERNCLASS CLASS"); XLI_THROW("COULD NOT FIND NATIVEEXTERNCLASS CLASS"); } // systems JniHelper::Init(vm, env, activityClass, displayClass, nativeExternClass); Xli::CoreLib::Init(); Xli::PlatformSpecific::Android::PostInit(); AApplication::Init(); // threading pthread_mutex_init(&EntryPoints::mutex, NULL); pthread_cond_init(&EntryPoints::cond, NULL); // java callbacks AttachNativeCallbacks(env, entryPointsClass); // uno uInitRuntime(); if (false) LOGD ("----------"); return JNI_VERSION_1_6; }
void AttachNativeCallbacks(JNIEnv* jni, jclass entryPointClass) { if (false) LOGD("Registering native functions"); static JNINativeMethod native_activity_funcs[] = { {(char* const)"cppOnCreate", (char* const)"(Z)V", (void *)&cppOnCreate}, {(char* const)"cppOnDestroy", (char* const)"()V", (void *)&cppOnDestroy}, {(char* const)"cppOnPause", (char* const)"()V", (void *)&cppOnPause}, {(char* const)"cppOnResume", (char* const)"()V", (void *)&cppOnResume}, {(char* const)"cppOnRestart", (char* const)"()V", (void *)&cppOnRestart}, {(char* const)"cppOnStart", (char* const)"()V", (void *)&cppOnStart}, {(char* const)"cppOnStop", (char* const)"()V", (void *)&cppOnStop}, {(char* const)"cppOnSaveInstanceState", (char* const)"(Landroid/os/Bundle;)V", (void *)&cppOnSaveInstanceState}, {(char* const)"cppOnConfigChanged", (char* const)"()V", (void *)&cppOnConfigChanged}, {(char* const)"cppOnLowMemory", (char* const)"()V", (void *)&cppOnLowMemory}, {(char* const)"cppOnWindowFocusChanged", (char* const)"(Z)V", (void *)&cppOnWindowFocusChanged}, {(char* const)"cppOnStartMainLoop", (char* const)"(ZZZ)V", (void *)&cppOnStartMainLoop}, {(char* const)"cppForceRedraw", (char* const)"(I)V", (void *)&cppForceRedraw}, {(char* const)"cppForceRedrawUnsafe", (char* const)"()V", (void *)&cppForceRedrawUnsafe}, {(char* const)"cppJavaThrowError", (char* const)"(ILjava/lang/String;)V", (void *)&cppJavaThrowError}, {(char* const)"cppOnReceiveURI", (char* const)"(Ljava/lang/String;)V", (void *)&cppOnReceiveURI}, {(char* const)"cppTimerCallback", (char* const)"(I)V", (void *)&cppTimerCallback}, {(char* const)"cppOnKeyboardResized", (char* const)"(I)V", (void *)&cppOnKeyboardResized}, {(char* const)"cppOnTopFrameChanged", (char* const)"(I)V", (void *)&cppOnTopFrameChanged}, {(char* const)"cppOnKeyUp", (char* const)"(I)V", (void *)&cppOnKeyUp}, {(char* const)"cppOnKeyDown", (char* const)"(I)V", (void *)&cppOnKeyDown}, }; // the last argument is the number of native functions int attached = (int)jni->RegisterNatives(entryPointClass, native_activity_funcs, 21); if (attached < 0) { LOGD("COULD NOT REGISTER NATIVE ACTIVITY FUNCTIONS"); XLI_THROW("COULD NOT REGISTER NATIVE ACTIVITY FUNCTIONS"); } else { if (false) LOGD("Native functions activity registered"); } }
void GLHelper::CreateEGLSurfaceFromANativeWindow(ANativeWindow* nativeWindow, EGLConfig config, EGLSurface& newSurface) { EGLint format; eglGetConfigAttrib(GLHelper::_eglDisplay, config, EGL_NATIVE_VISUAL_ID, &format); ANativeWindow_setBuffersGeometry(nativeWindow, 0, 0, format); newSurface = eglCreateWindowSurface(GLHelper::_eglDisplay, config, nativeWindow, NULL); if (newSurface == EGL_NO_SURFACE) XLI_THROW("Unable to create EGL Surface"); }
static Texture::Cube2DMode DetectCubeFrom2DMode(int w, int h) { if (w / 6 == h) return Texture::Cube2DMode6x1; if (2 * w / 3 == h) return Texture::Cube2DMode3x2; if (h / 6 == w) return Texture::Cube2DMode1x6; if (2 * h / 3 == w) return Texture::Cube2DMode2x3; XLI_THROW("Unable to create cube map: Invalid image dimension"); }
void UnixFileSystemBase::SetCurrentDirectory(const String& path) { if (!path.Length()) return; if (chdir(path.Ptr()) != 0) XLI_THROW("Unable to change directory to '" + path + "'"); }
void GLHelper::MakeCurrent(EGLContext context, EGLSurface surface) { if (eglMakeCurrent(GLHelper::_eglDisplay, surface, surface, context) == EGL_FALSE) { Xli::Error->WriteLine((Xli::String)"GLHelper::MakeCurrent: Unable to make EGL context current:" + (Xli::String)eglGetError()); XLI_THROW("Unable to make EGL context current"); } }
virtual void MakeCurrent(Window* wnd) { if (wnd) window = wnd; if (wnd && (NATIVE_HANDLE)wnd->GetNativeHandle() != handle) { #ifdef XLI_PLATFORM_ANDROID if (wnd->GetImplementation() == WindowImplementationAndroid) { EGLint format; eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format); ANativeWindow_setBuffersGeometry((ANativeWindow*)wnd->GetNativeHandle(), 0, 0, format); } #endif if (surface != EGL_NO_SURFACE) eglDestroySurface(display, surface); surface = eglCreateWindowSurface(display, config, (NATIVE_HANDLE)wnd->GetNativeHandle(), NULL); if (surface == EGL_NO_SURFACE) XLI_THROW("Unable to create EGL Surface"); if (context == EGL_NO_CONTEXT) { const EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribs); if (context == EGL_NO_CONTEXT) XLI_THROW("Unable to create EGL Context"); } } if (eglMakeCurrent(display, surface, surface, wnd != 0 ? context : 0) == EGL_FALSE) XLI_THROW("Unable to make EGL context current"); }
AAssetStream(String filename, FileMode mode) { if (mode != FileModeRead && mode != FileModeReadRandom) XLI_THROW("Unsupported asset file mode: " + FileModeInfo::ToString(mode)); AJniHelper jni; asset = AAssetManager_open(jni.GetAssetManager(), filename.Ptr(), ((mode & FileModeRandom) != 0) ? AASSET_MODE_RANDOM : AASSET_MODE_STREAMING); if (asset == 0) XLI_THROW_CANT_OPEN_FILE(filename); }
void Thread::Start(Managed<ThreadTask> task) { if (task.IsNull()) XLI_THROW_NULL_POINTER; if (_handle) XLI_THROW("Thread is already started"); _task = task; _state = ThreadStateRunning; _handle = CreateThread(thread_func, (void*)this); }
// private static extern void RegisterFunctions() [static] :15 void ExternBlockHost::RegisterFunctions() { uStackFrame __("Uno.Compiler.ExportTargetInterop.Foreign.Android.ExternBlockHost", "RegisterFunctions()"); JniHelper jni; static JNINativeMethod native_activity_funcs[] = { }; int funcCount = 0; if ((int)jni->RegisterNatives(JniHelper::GetNativeExternClass(), native_activity_funcs, funcCount)<0) { LOGD("COULD NOT REGISTER NATIVE EXTERN FUNCTIONS"); XLI_THROW("COULD NOT REGISTER NATIVE EXTERN FUNCTIONS"); } }
void GLHelper::CreatePBufferSurfaceAndMakeCurrent() { // create pbuffer surface, this allows us to upload resources and then switch to an // eglwindowsurface when the java Surface is ready EGLint pbufferAttribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE }; _eglPBufferSurface = eglCreatePbufferSurface(_eglDisplay, _eglPBufferConfig, pbufferAttribs); if (_eglPBufferSurface == EGL_FALSE) { Xli::Error->WriteLine((Xli::String)"Unable to make EGL pbuffer surface"); XLI_THROW("Unable to make EGL pbuffer surface"); } MakeCurrent(_eglPBufferContext, _eglPBufferSurface); }
Xli::Texture* uLoadXliTexture(const Xli::String& filename, Xli::Stream* stream) { Xli::String fnUpper = filename.ToUpper(); Xli::Managed<Xli::ImageReader> ir; if (fnUpper.EndsWith(".PNG")) ir = Xli::Png::CreateReader(stream); else if (fnUpper.EndsWith(".JPG") || fnUpper.EndsWith(".JPEG")) ir = Xli::Jpeg::CreateReader(stream); else XLI_THROW("Unsupported texture extension '" + Xli::Path::GetExtension(filename) + "'"); Xli::Managed<Xli::Bitmap> bmp = ir->ReadBitmap(); return Xli::Texture::Create(bmp); }
void UnixFileSystemBase::CreateDirectory(const String& path) { struct stat st; if (!path.Length() || path == "~" || stat(path.Ptr(), &st) == 0) return; if (mkdir(path.Ptr(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) { if (errno == EEXIST) return; XLI_THROW("Unable to create directory '" + path + "'"); } }
Win32Window::Win32Window(int width, int height, const Xli::String& title, int flags) { this->ownsHwnd = true; this->closed = false; this->fullscreen = false; this->eventHandler = eventHandler; if (flags & WindowFlagsFullscreen) { flags &= ~WindowFlagsFullscreen; fullscreen = true; } rect.top = 0; rect.left = 0; rect.bottom = height; rect.right = width; dwStyle = StyleFromXliWindowFlags(flags); AdjustWindowRect(&rect, dwStyle, 0); Utf16String titleW = Unicode::Utf8To16(title); hWnd = CreateWindowW(WindowClassName, titleW.Ptr(), dwStyle, CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, 0, 0, HInstance, 0); if (!hWnd) XLI_THROW("Failed to create window: " + Win32::GetLastErrorString()); if (!MainWindow) MainWindow = this; SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); ShowWindow(hWnd, SW_NORMAL); SetForegroundWindow(hWnd); SetFocus(hWnd); if (fullscreen) { fullscreen = false; SetFullscreen(true); } }
File::File(const String& filename, FileMode mode) { const char* m = "rb"; switch (mode) { case FileModeRead: m = "rb"; break; case FileModeWrite: m = "wb"; break; case FileModeAppend: m = "ab"; break; case FileModeReadWrite: m = "r+b"; break; case FileModeReadWriteNew: m = "w+b"; break; case FileModeReadAppend: m = "a+b"; break; default: XLI_THROW("Invalid file mode: " + FileModeInfo::ToString(mode)); } #ifdef XLI_COMPILER_MSVC fp = 0; Utf16String filenameW = Unicode::Utf8To16(filename); Utf16String mW = Unicode::Utf8To16(m); if (_wfopen_s(&fp, filenameW.Ptr(), mW.Ptr()) != 0) XLI_THROW_CANT_OPEN_FILE(filename); #else fp = fopen(filename.Ptr(), m); if (!fp) XLI_THROW_CANT_OPEN_FILE(filename); #endif this->flags = FileFlagsCanClose | FileFlagsCanSeek; if (mode & FileModeRead) this->flags |= FileFlagsCanRead; if ((mode & FileModeWrite) || (mode & FileModeAppend)) this->flags |= FileFlagsCanWrite; }
void InitWindow() { HInstance = GetModuleHandle(0); WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = PlatformSpecific::Win32Window::WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = HInstance; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hIcon = LoadIcon(HInstance, IDI_APPLICATION); wcex.hIconSm = LoadIcon(HInstance, IDI_APPLICATION); wcex.hbrBackground = NULL; wcex.lpszMenuName = NULL; wcex.lpszClassName = WindowClassName; if (!RegisterClassEx(&wcex)) XLI_THROW("Failed to register window class"); InitDisplay(); }
void AApplication::cppJavaThrowError (Xli::String message) { XLI_THROW(message.Ptr()); }
void GLHelper::_setEGLConfig(bool forPBuffer) { // Find suitable attribs for this device EGLConfig configs[128]; EGLint numConfigs; bool foundSuitableAttribs = false; EGLint _configAttribsPrimary[] = { EGL_SURFACE_TYPE, (forPBuffer ? EGL_PBUFFER_BIT : EGL_WINDOW_BIT), EGL_RED_SIZE, 5, EGL_GREEN_SIZE, 6, EGL_BLUE_SIZE, 5, EGL_ALPHA_SIZE, 0, EGL_DEPTH_SIZE, 16, EGL_STENCIL_SIZE, 0, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE, EGL_NONE }; EGLint _configAttribsFallback[] = { EGL_SURFACE_TYPE, (forPBuffer ? EGL_PBUFFER_BIT : EGL_WINDOW_BIT), EGL_RED_SIZE, 5, EGL_GREEN_SIZE, 6, EGL_BLUE_SIZE, 5, EGL_ALPHA_SIZE, 0, EGL_DEPTH_SIZE, 16, EGL_STENCIL_SIZE, 0, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE }; if (!eglChooseConfig(_eglDisplay, _configAttribsPrimary, configs, 128, &numConfigs) || (numConfigs == 0)) { if (!eglChooseConfig(_eglDisplay, _configAttribsFallback, configs, 128, &numConfigs) || (numConfigs == 0)) XLI_THROW("Unable to choose suitable EGL attribs for config"); } EGLint cs = 0, cd = 0, cb = 0; int cc = 0; const Xli::Vector4i& colorBits = Xli::Vector4i(8, 8, 8, 8); int samples = 4; for (int i = 0; i < numConfigs; i++) { EGLint samples, depth, stencil, buffer, r, g, b, a, render; eglGetConfigAttrib(_eglDisplay, configs[i], EGL_RED_SIZE, &r); eglGetConfigAttrib(_eglDisplay, configs[i], EGL_GREEN_SIZE, &g); eglGetConfigAttrib(_eglDisplay, configs[i], EGL_BLUE_SIZE, &b); eglGetConfigAttrib(_eglDisplay, configs[i], EGL_ALPHA_SIZE, &a); eglGetConfigAttrib(_eglDisplay, configs[i], EGL_BUFFER_SIZE, &buffer); eglGetConfigAttrib(_eglDisplay, configs[i], EGL_DEPTH_SIZE, &depth); eglGetConfigAttrib(_eglDisplay, configs[i], EGL_STENCIL_SIZE, &stencil); eglGetConfigAttrib(_eglDisplay, configs[i], EGL_SAMPLES, &samples); if (false) Xli::Error->WriteLine(Xli::String::Format("DEBUG: EGLConfig[%d]: M %d D %d S %d B %d R %d G %d B %d A %d", i, samples, depth, stencil, buffer, r, g, b, a)); if (samples >= cs && depth >= cd && buffer >= cb && samples <= samples && r <= colorBits.R && g <= colorBits.G && b <= colorBits.B && a <= colorBits.A) { cs = samples; cd = depth; cb = buffer; cc = i; } } if (forPBuffer) { _eglPBufferConfig = configs[cc]; if (false) Xli::Error->WriteLine((Xli::String)"DEBUG: Selected PBuffer EGLConfig[" + (int)cc + "]"); } else { _eglRenderConfig = configs[cc]; if (false) Xli::Error->WriteLine((Xli::String)"DEBUG: Selected Render EGLConfig[" + (int)cc + "]"); } }
unsigned int uCreateGLTexture(Xli::Texture* texData, bool generateMips, uGLTextureInfo* outInfo) { GLuint texHandle; glGenTextures(1, &texHandle); int width = texData->Faces[0].MipLevels[0]->GetWidth(); int height = texData->Faces[0].MipLevels[0]->GetHeight(); int mipCount = texData->Faces[0].MipLevels.Length(); int depth = 1; GLenum texTarget = texData->Type == Xli::TextureTypeCube ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D; glBindTexture(texTarget, texHandle); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_PACK_ALIGNMENT, 1); bool compressed = false; for (int i = 0; i < texData->Faces.Length(); i++) { GLenum texFace = texTarget == GL_TEXTURE_CUBE_MAP ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + i : GL_TEXTURE_2D; for (int j = 0; j < texData->Faces[i].MipLevels.Length(); j++) { Xli::Image* mip = texData->Faces[i].MipLevels[j]; switch (mip->GetFormat()) { #ifdef GL_ETC1_RGB8_OES case Xli::FormatCompressedRGB_ETC1: glCompressedTexImage2D(texFace, j, GL_ETC1_RGB8_OES, mip->GetWidth(), mip->GetHeight(), 0, mip->GetSizeInBytes(), mip->GetPtr()); compressed = true; break; #endif #ifdef GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG case Xli::FormatCompressedRGB_PVRTC_4BPP: glCompressedTexImage2D(texFace, j, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, mip->GetWidth(), mip->GetHeight(), 0, mip->GetSizeInBytes(), mip->GetPtr()); compressed = true; break; #endif #ifdef GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG case Xli::FormatCompressedRGB_PVRTC_2BPP: glCompressedTexImage2D(texFace, j, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, mip->GetWidth(), mip->GetHeight(), 0, mip->GetSizeInBytes(), mip->GetPtr()); compressed = true; break; #endif #ifdef GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG case Xli::FormatCompressedRGBA_PVRTC_4BPP: glCompressedTexImage2D(texFace, j, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, mip->GetWidth(), mip->GetHeight(), 0, mip->GetSizeInBytes(), mip->GetPtr()); compressed = true; break; #endif #ifdef GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG case Xli::FormatCompressedRGBA_PVRTC_2BPP: glCompressedTexImage2D(texFace, j, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, mip->GetWidth(), mip->GetHeight(), 0, mip->GetSizeInBytes(), mip->GetPtr()); compressed = true; break; #endif default: { Xli::Managed<Xli::Bitmap> bmp = mip->ToBitmap(); GLenum glFormat, glType; if (!TryGetGLFormat(bmp->GetFormat(), glFormat, glType)) XLI_THROW("Unsupported texture format: " + Xli::FormatInfo::ToString(bmp->GetFormat())); glTexImage2D(texFace, j, glFormat, bmp->GetWidth(), bmp->GetHeight(), 0, glFormat, glType, bmp->GetPtr()); } break; // Silence 'switch has default but no cases' warning case Xli::FormatUnspecified: break; } } } if (generateMips && !compressed) { glGenerateMipmap(texTarget); GLenum err = glGetError(); if (err == GL_NO_ERROR) { int w = width, h = height; while (w > 1 || h > 1) { w /= 2; h /= 2; mipCount++; } } } if (outInfo) { outInfo->GLTarget = texTarget; outInfo->Width = width; outInfo->Height = height; outInfo->Depth = depth; outInfo->MipCount = mipCount; } //XLI_GL_CHECK_ERROR; return texHandle; }
void UnixFileSystemBase::DeleteDirectory(const String& path) { if (rmdir(path.Ptr()) != 0) XLI_THROW("Unable to delete directory '" + path + "'"); }
void UnixFileSystemBase::DeleteFile(const String& path) { if (unlink(path.Ptr()) != 0) XLI_THROW("Unable to delete file '" + path + "'"); }
EglContext(Window* wnd, const GLContextAttributes& attribs) { swapInterval = -1; handle = NULL; context = EGL_NO_CONTEXT; surface = EGL_NO_SURFACE; display = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglInitialize(display, 0, 0); const EGLint iattribs[] = { EGL_RED_SIZE, 5, EGL_GREEN_SIZE, 6, EGL_BLUE_SIZE, 5, EGL_ALPHA_SIZE, 0, EGL_DEPTH_SIZE, 16, EGL_STENCIL_SIZE, 0, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, //EGL_RENDER_BUFFER, attribs.Buffers <= 1 ? EGL_SINGLE_BUFFER : EGL_BACK_BUFFER, EGL_NONE }; EGLint numConfigs; EGLConfig configs[128]; if (!eglChooseConfig(display, iattribs, configs, 128, &numConfigs) || numConfigs == 0) XLI_THROW("Unable to choose EGL config"); EGLint cs = 0, cd = 0, cb = 0; int cc = 0; for (int i = 0; i < numConfigs; i++) { EGLint samples, depth, stencil, buffer, r, g, b, a, render; eglGetConfigAttrib(display, configs[i], EGL_RED_SIZE, &r); eglGetConfigAttrib(display, configs[i], EGL_GREEN_SIZE, &g); eglGetConfigAttrib(display, configs[i], EGL_BLUE_SIZE, &b); eglGetConfigAttrib(display, configs[i], EGL_ALPHA_SIZE, &a); eglGetConfigAttrib(display, configs[i], EGL_BUFFER_SIZE, &buffer); eglGetConfigAttrib(display, configs[i], EGL_DEPTH_SIZE, &depth); eglGetConfigAttrib(display, configs[i], EGL_STENCIL_SIZE, &stencil); eglGetConfigAttrib(display, configs[i], EGL_SAMPLES, &samples); #ifdef XLI_DEBUG Error->WriteLine(String::Format("DEBUG: EGLConfig[%d]: M %d D %d S %d B %d R %d G %d B %d A %d", i, samples, depth, stencil, buffer, r, g, b, a)); #endif if (samples >= cs && depth >= cd && buffer >= cb && samples <= attribs.Samples && r <= attribs.ColorBits.R && g <= attribs.ColorBits.G && b <= attribs.ColorBits.B && a <= attribs.ColorBits.A) { cs = samples; cd = depth; cb = buffer; cc = i; } } config = configs[cc]; #ifdef XLI_DEBUG Error->WriteLine((String)"DEBUG: Selected EGLConfig[" + (int)cc + "]"); #endif MakeCurrent(wnd); }
void UnixFileSystemBase::MoveFile(const String& oldPath, const String& newPath) { if (rename(oldPath.Ptr(), newPath.Ptr()) != 0) XLI_THROW("Unable to move file '" + oldPath + "' to '" + newPath + "'"); }