init log before everything else, use WMI to read machine and system info, rtt fixed on Samsung A3, try to create different EGL context config

This commit is contained in:
2017-04-02 15:02:45 +01:00
parent 0dfb458c71
commit b6c9429b89
8 changed files with 241 additions and 24 deletions

View File

@@ -21,6 +21,8 @@
#include <jni.h>
#include <errno.h>
#include <cassert>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include "pch.h"
#include "app.h"
@@ -77,6 +79,7 @@ struct engine {
*/
static int engine_init_display(struct engine* engine) {
// initialize OpenGL ES and EGL
App::I.initLog();
/*
* Here specify the attributes of the desired configuration.
@@ -142,6 +145,57 @@ static int engine_init_display(struct engine* engine) {
context = eglCreateContext(display, config, EGL_NO_CONTEXT, attribs_test);
if (context == EGL_NO_CONTEXT)
{
LOG("EGL: debug and forward context failed");
const EGLint attribs_test[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR,
EGL_NONE
};
context = eglCreateContext(display, config, EGL_NO_CONTEXT, attribs_test);
if (context == EGL_NO_CONTEXT)
{
LOG("EGL: only forward context failed");
const EGLint attribs_test[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR,
//EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR,
EGL_NONE
};
context = eglCreateContext(display, config, EGL_NO_CONTEXT, attribs_test);
if (context == EGL_NO_CONTEXT)
{
LOG("EGL: only debug context failed");
const EGLint attribs_test[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
context = eglCreateContext(display, config, EGL_NO_CONTEXT, attribs_test);
if (context == EGL_NO_CONTEXT)
{
LOG("EGL: all the context creation failed");
}
else
{
LOG("EGL: created simple context");
}
}
else
{
LOG("EGL: created only debug context");
}
}
else
{
LOG("EGL: created only forward context");
}
}
else
{
LOG("EGL: created debug and forward context");
}
if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
LOG("Unable to eglMakeCurrent");
return -1;
@@ -164,25 +218,32 @@ static int engine_init_display(struct engine* engine) {
LOG("OpenGL Info: %s", info);
}
const char* ext = (const char*) glGetString(GL_EXTENSIONS);
int ext_len = strlen(ext);
GLint n_exts;
std::map<std::string, bool> ext_map;
static char ext_name[256];
int ext_name_i = 0;
for (int i = 0; i < ext_len; i++)
glGetIntegerv(GL_NUM_EXTENSIONS, &n_exts);
for (int i = 0; i < n_exts; i++)
{
char c = ext[i];
if (c == ' ')
{
ext_map.emplace(std::string(ext_name, ext_name_i), true);
ext_name_i = 0;
}
else
{
ext_name[ext_name_i++] = c;
}
ext_map.emplace(glGetStringi(GL_EXTENSIONS, i), true);
}
//const char* ext = (const char*) glGetString(GL_EXTENSIONS);
//int ext_len = strlen(ext);
//static char ext_name[256];
//int ext_name_i = 0;
//for (int i = 0; i < ext_len; i++)
//{
// char c = ext[i];
// if (c == ' ')
// {
// ext_map.emplace(std::string(ext_name, ext_name_i), true);
// ext_name_i = 0;
// }
// else
// {
// ext_name[ext_name_i++] = c;
// }
//}
if (ext_map.count("GL_KHR_debug"))
{
LOG("GL_KHR_debug supported");

View File

@@ -442,10 +442,12 @@ void App::initLayout()
LOG("initializing layout completed");
}
void App::init()
void App::initLog()
{
LogRemote::I.start();
}
void App::init()
{
#ifdef _WIN32
static CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
@@ -465,7 +467,7 @@ void App::init()
LOG("OPENGL: %.*s", length, message);
FlushConsoleInputBuffer(GetStdHandle(STD_OUTPUT_HANDLE));
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), info.wAttributes);
// __debugbreak();
__debugbreak();
}
}, nullptr);
glEnable(GL_DEBUG_OUTPUT);
@@ -482,6 +484,14 @@ void App::init()
LOG("GL version: %s", glGetString(GL_VERSION));
LOG("GL vendor: %s", glGetString(GL_VENDOR));
LOG("GL renderer: %s", glGetString(GL_RENDERER));
GLint n_exts;
glGetIntegerv(GL_NUM_EXTENSIONS, &n_exts);
for (int i = 0; i < n_exts; i++)
{
LOG("%s", glGetStringi(GL_EXTENSIONS, i));
}
LOG("Screen Resolution: %dx%d", (int)width, (int)height);
zoom = ceilf(width / 1000.f);

View File

@@ -38,6 +38,7 @@ public:
#else
float zoom = 1.0;
#endif // __ANDROID__
void initLog();
void init();
void initShaders();
void initAssets();

View File

@@ -62,6 +62,25 @@ void LogRemote::log(const char* format, ...)
va_end(arglist);
m_mq.Post(std::string(buffer, n));
}
void LogRemote::log(const wchar_t* format, ...)
{
static wchar_t buffer[4096];
va_list arglist;
va_start(arglist, format);
int n = _vsnwprintf(buffer, sizeof(buffer)/sizeof(wchar_t), format, arglist);
va_end(arglist);
std::wstring string_to_convert(buffer, n);
//setup converter
using convert_type = std::codecvt_utf8<wchar_t>;
std::wstring_convert<convert_type, wchar_t> converter;
//use converter (.to_bytes: wstr->str, .from_bytes: str->wstr)
//std::string converted_str = converter.to_bytes(string_to_convert);
m_mq.Post(converter.to_bytes(string_to_convert));
}
LogRemote::~LogRemote()
{
m_running = false;

View File

@@ -7,6 +7,7 @@
#define LOG(...) { ((void)__android_log_print(ANDROID_LOG_INFO, "native-engine", __VA_ARGS__)); LogRemote::I.log(__VA_ARGS__); }
#elif _WIN32
#define LOG(M,...) { printf(M"\n", ##__VA_ARGS__); LogRemote::I.log(M, ##__VA_ARGS__); }
#define LOGW(M,...) { wprintf(M"\n", ##__VA_ARGS__); LogRemote::I.log(M, ##__VA_ARGS__); }
#endif
class LogRemote
@@ -27,5 +28,6 @@ public:
std::string net_request(std::string cmd, std::string data = "");
void net_close();
void log(const char* format, ...);
void log(const wchar_t* format, ...);
~LogRemote();
};

View File

@@ -262,8 +262,8 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
}
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
auto& app = App::I;
app.create();
App::I.initLog();
App::I.create();
NSRect r = NSMakeRect(0, 0, app.width, app.height);
view = [[View alloc] initWithFrame:r];
@@ -308,6 +308,7 @@ int main(int argc, const char * argv[])
#pragma comment (lib, "opengl32.lib")
#pragma comment (lib, "glew32.lib")
#pragma comment(lib, "wbemuuid.lib")
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp);
HINSTANCE hInst;
@@ -317,11 +318,123 @@ HGLRC hRC;
wchar_t* className;
bool keys[256];
#include <WbemCli.h>
int read_WMI_info()
{
// see: http://win32easy.blogspot.co.uk/2011/03/wmi-in-c-query-everyting-from-your-os.html
HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (FAILED(hRes))
{
LOG("Unable to launch COM: %x", hRes);
return 1;
}
if ((FAILED(hRes = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_CONNECT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, 0))))
{
LOG("Unable to initialize security: %x", hRes);
return 1;
}
IWbemLocator* pLocator = NULL;
if (FAILED(hRes = CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_ALL, IID_PPV_ARGS(&pLocator))))
{
LOG("Unable to create a WbemLocator: %x", hRes);
return 1;
}
IWbemServices* pService = NULL;
if (FAILED(hRes = pLocator->ConnectServer(L"root\\CIMV2", NULL, NULL, NULL, WBEM_FLAG_CONNECT_USE_MAX_WAIT, NULL, NULL, &pService)))
{
pLocator->Release();
LOG("Unable to connect to \"CIMV2\": %x", hRes);
return 1;
}
auto log_field = [](const wchar_t* section, IWbemClassObject* clsObj, const wchar_t* field) {
VARIANT vRet;
VariantInit(&vRet);
if (SUCCEEDED(clsObj->Get(field, 0, &vRet, NULL, NULL)) && vRet.vt == VT_BSTR)
{
LOGW(L"%s %s: %s", section, field, vRet.bstrVal);
VariantClear(&vRet);
}
};
// GET DEVICE INFO
{
IEnumWbemClassObject* pEnumerator = NULL;
if (FAILED(hRes = pService->ExecQuery(L"WQL", L"SELECT * FROM Win32_ComputerSystem", WBEM_FLAG_FORWARD_ONLY, NULL, &pEnumerator)))
{
pLocator->Release();
pService->Release();
LOG("Unable to retrive desktop monitors: %x", hRes);
return 1;
}
IWbemClassObject* clsObj = NULL;
int numElems;
while ((hRes = pEnumerator->Next(WBEM_INFINITE, 1, &clsObj, (ULONG*)&numElems)) != WBEM_S_FALSE)
{
if (FAILED(hRes))
break;
log_field(L"Machine", clsObj, L"Name");
log_field(L"Machine", clsObj, L"Model");
log_field(L"Machine", clsObj, L"Manufacturer");
clsObj->Release();
}
pEnumerator->Release();
}
// GET OS INFO
{
IEnumWbemClassObject* pEnumerator = NULL;
if (FAILED(hRes = pService->ExecQuery(L"WQL", L"SELECT * FROM Win32_OperatingSystem", WBEM_FLAG_FORWARD_ONLY, NULL, &pEnumerator)))
{
pLocator->Release();
pService->Release();
LOG("Unable to retrive desktop monitors: %x", hRes);
return 1;
}
IWbemClassObject* clsObj = NULL;
int numElems;
while ((hRes = pEnumerator->Next(WBEM_INFINITE, 1, &clsObj, (ULONG*)&numElems)) != WBEM_S_FALSE)
{
if (FAILED(hRes))
break;
log_field(L"OS", clsObj, L"Name");
log_field(L"OS", clsObj, L"Version");
log_field(L"OS", clsObj, L"Locale");
log_field(L"OS", clsObj, L"OSProductSuite");
log_field(L"OS", clsObj, L"Manufacturer");
log_field(L"OS", clsObj, L"Description");
clsObj->Release();
}
pEnumerator->Release();
}
pService->Release();
pLocator->Release();
CoUninitialize();
return 0;
}
int main()
{
WNDCLASS wc;
PIXELFORMATDESCRIPTOR pfd;
App::I.initLog();
read_WMI_info();
App::I.create();
RECT clientRect = { 0, 0, (int)App::I.width, (int)App::I.height };

View File

@@ -46,6 +46,8 @@
#include <mutex>
#include <memory>
#include <string>
#include <locale>
#include <codecvt>
#include <vector>
#include <random>
#include <thread>

View File

@@ -55,15 +55,12 @@ bool RTT::create(int width, int height, int tex/* = -1*/)
}
glBindTexture(GL_TEXTURE_2D, texID);
if (tex == -1)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D, 0);
// Create a renderbuffer object to store depth info
@@ -82,10 +79,22 @@ bool RTT::create(int width, int height, int tex/* = -1*/)
// Attach the renderbuffer to depth attachment point
//glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboID);
auto err2str = [](GLenum err) {
switch (err)
{
case GL_FRAMEBUFFER_UNDEFINED: return "GL_FRAMEBUFFER_UNDEFINED";
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: return "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
case GL_FRAMEBUFFER_UNSUPPORTED: return "GL_FRAMEBUFFER_UNSUPPORTED";
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: return "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE";
default: return "UNKNOWN";
}
};
// Check FBO status
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE)
LOG("createColorBuffer failed");
LOG("createColorBuffer failed because: %s", err2str(status));
// Switch back to window-system-provided framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, 0);