예제 #1
0
void Skybox::init() {

    std::string fragShaderSrcStr = stringFromFile("shaders/cubemap.fs", PathType::internal);
    std::string vertShaderSrcStr = stringFromFile("shaders/cubemap.vs", PathType::internal);

    m_shader = std::make_unique<ShaderProgram>();
    m_shader->setSourceStrings(fragShaderSrcStr, vertShaderSrcStr);

    m_texture = std::unique_ptr<Texture>(new TextureCube(m_file));
    auto layout = std::shared_ptr<VertexLayout>(new VertexLayout({
        {"a_position", 3, GL_FLOAT, false, 0},
    }));

    m_mesh = std::make_unique<Mesh<PosVertex>>(layout, GL_TRIANGLES, GL_STATIC_DRAW, true);
    m_mesh->compile({
        { 5, 1, 3, 3, 7, 5, // +x
          6, 2, 0, 0, 4, 6, // -x
          2, 6, 7, 7, 3, 2, // +y
          5, 4, 0, 0, 1, 5, // -y
          0, 2, 3, 3, 1, 0, // +z
          7, 6, 4, 4, 5, 7  // -z
        },
        {{ -1.0, -1.0,  1.0 },
         {  1.0, -1.0,  1.0 },
         { -1.0,  1.0,  1.0 },
         {  1.0,  1.0,  1.0 },
         { -1.0, -1.0, -1.0 },
         {  1.0, -1.0, -1.0 },
         { -1.0,  1.0, -1.0 },
         {  1.0,  1.0, -1.0 }}});
}
예제 #2
0
void PolygonStyle::constructShaderProgram() {

    std::string vertShaderSrcStr = stringFromFile("shaders/polygon.vs", PathType::internal);
    std::string fragShaderSrcStr = stringFromFile("shaders/polygon.fs", PathType::internal);

    m_shaderProgram->setSourceStrings(fragShaderSrcStr, vertShaderSrcStr);
}
void PolylineStyle::constructShaderProgram() {

    std::string vertShaderSrcStr = stringFromFile("shaders/polyline.vs", PathType::internal);
    std::string fragShaderSrcStr = stringFromFile("shaders/polyline.fs", PathType::internal);

    m_shaderProgram->setSourceStrings(fragShaderSrcStr, vertShaderSrcStr);

    if (m_texCoordsGeneration) {
        m_shaderProgram->addSourceBlock("defines", "#define TANGRAM_USE_TEX_COORDS\n");
    }
}
예제 #4
0
void PointStyle::constructShaderProgram() {

    std::string fragShaderSrcStr = stringFromFile("shaders/point.fs", PathType::internal);
    std::string vertShaderSrcStr = stringFromFile("shaders/point.vs", PathType::internal);

    m_shaderProgram->setSourceStrings(fragShaderSrcStr, vertShaderSrcStr);

    std::string defines;

    if (!m_spriteAtlas && !m_texture) {
        defines += "#define TANGRAM_POINT\n";
    }

    m_shaderProgram->addSourceBlock("defines", defines);
}
예제 #5
0
TEST(Stream, append)
{
    const std::wstring LOG_FILE_NAME(L"StreamTest.log");
    removeFile(LOG_FILE_NAME);
    auto output(std::make_unique<LogOutput>(LOG_FILE_NAME));
    auto prefix(std::make_unique<NothingPrefix>());
    unsigned char uc[] = "uc";
    void* pointer = reinterpret_cast<void*>(12345678U);
    LogStream logStream(std::move(output), std::move(prefix));
    logStream << bkzFlush;
    logStream << 1;
    logStream << 2U;
    logStream << 1L;
    logStream << 2LU;
    logStream << 4.4f;
    logStream << 3.3;
    logStream << "HELLO";
    logStream << uc;
    logStream << std::string("string");
    logStream << std::wstring(L"wstring");
    logStream << pointer;

    logStream << bkzEndl;

    const std::wstring actual = stringFromFile(LOG_FILE_NAME);
    EXPECT_EQ(L"12124.403.300HELLOucstringwstring12345678\n", actual);
}
예제 #6
0
void loadScene(const char* _scenePath, bool _setPositionFromScene) {
    LOG("Loading scene file: %s", _scenePath);

    auto sceneString = stringFromFile(setResourceRoot(_scenePath).c_str(), PathType::resource);

    bool setPositionFromCurrentView = bool(m_scene);

    auto scene = std::make_shared<Scene>();
    if (m_view) {
        scene->view() = std::make_shared<View>(*m_view);
    }
    if (SceneLoader::loadScene(sceneString, *scene)) {
        m_scene = scene;
        m_scene->fontContext()->addFont("firasans", "medium", "");
        if (setPositionFromCurrentView && !_setPositionFromScene) {
            m_scene->view()->setPosition(m_view->getPosition());
            m_scene->view()->setZoom(m_view->getZoom());
        }
        m_view = m_scene->view();
        m_inputHandler->setView(m_view);
        m_tileManager->setDataSources(scene->dataSources());
        setPixelScale(m_view->pixelScale());

        m_tileWorker->setScene(scene);
    }
}
예제 #7
0
void TextStyle::constructShaderProgram() {
    std::string frag = m_sdf ? "shaders/sdf.fs" : "shaders/text.fs";

    std::string vertShaderSrcStr = stringFromFile("shaders/point.vs", PathType::internal);
    std::string fragShaderSrcStr = stringFromFile(frag.c_str(), PathType::internal);

    m_shaderProgram->setSourceStrings(fragShaderSrcStr, vertShaderSrcStr);

    std::string defines;

    if (m_sdf && m_sdfMultisampling) {
        defines += "#define TANGRAM_SDF_MULTISAMPLING\n";
    }

    m_shaderProgram->addSourceBlock("defines", defines);
}
예제 #8
0
ClientGeoJsonSource::ClientGeoJsonSource(const std::string& _name, const std::string& _url)
    : DataSource(_name, _url) {

    if (!_url.empty()) {
        // Load from file
        const auto& string = stringFromFile(_url.c_str(), PathType::resource);
        addData(string);
    }
}
예제 #9
0
PrivateKey PrivateKey::fromPEMFile(const QString &fileName, const SecureArray &passphrase, ConvertResult *result, const QString &provider)
{
	QString pem;
	if(!stringFromFile(fileName, &pem))
	{
		if(result)
			*result = ErrorFile;
		return PrivateKey();
	}
	return get_privatekey_pem(pem, fileName, 0, passphrase, result, provider);
}
예제 #10
0
PublicKey PublicKey::fromPEMFile(const QString &fileName, ConvertResult *result, const QString &provider)
{
	QString pem;
	if(!stringFromFile(fileName, &pem))
	{
		if(result)
			*result = ErrorFile;
		return PublicKey();
	}
	return fromPEM(pem, result, provider);
}
예제 #11
0
void Light::assembleLights(std::map<std::string, std::vector<std::string>>& _sourceBlocks) {

    // Create strings to contain the assembled lighting source code
    std::stringstream lighting;

    // Concatenate all strings at the "__lighting" keys
    // (struct definitions and function definitions)
    for (const auto& string : _sourceBlocks["__lighting"]) {
        lighting << '\n';
        lighting << string;
    }

    // After lights definitions are all added, add the main lighting functions
    if (s_mainLightingBlock.empty()) {
        s_mainLightingBlock = stringFromFile("shaders/lights.glsl", PathType::internal);
    }
    std::string lightingBlock = s_mainLightingBlock;

    // The main lighting functions each contain a tag where all light instances should be computed;
    // Insert all of our "lights_to_compute" at this tag

    std::string tag = "#pragma tangram: lights_to_compute";
    std::stringstream lights;
    for (const auto& string : _sourceBlocks["__lights_to_compute"]) {
        lights << '\n';
        lights << string;
    }

    size_t pos = lightingBlock.find(tag) + tag.length();
    lightingBlock.insert(pos, lights.str());

    // Place our assembled lighting source code back into the map of "source blocks";
    // The assembled strings will then be injected into a shader at the "vertex_lighting"
    // and "fragment_lighting" tags
    _sourceBlocks["lighting"] = { lighting.str() + lightingBlock  };
}
예제 #12
0
파일: bsod.cpp 프로젝트: VytenisP/enigma2-1
void bsodFatal(const char *component)
{
	/* show no more than one bsod while shutting down/crashing */
	if (bsodhandled)
		return;
	bsodhandled = true;

	if (!component)
		component = "Enigma2";

	/* Retrieve current ringbuffer state */
	const char* logp1;
	unsigned int logs1;
	const char* logp2;
	unsigned int logs2;
	retrieveLogBuffer(&logp1, &logs1, &logp2, &logs2);

	FILE *f;
	std::string crashlog_name;
	std::ostringstream os;
	time_t t = time(0);
	struct tm tm;
	char tm_str[32];
	localtime_r(&t, &tm);
	strftime(tm_str, sizeof(tm_str), "%Y-%m-%d_%H-%M-%S", &tm);
	os << getConfigString("config.crash.debug_path", "/home/root/logs/");
	os << "enigma2_crash_";
	os << tm_str;
	os << ".log";
	crashlog_name = os.str();
	f = fopen(crashlog_name.c_str(), "wb");

	if (f == NULL)
	{
		/* No hardisk. If there is a crash log in /home/root, leave it
		 * alone because we may be in a crash loop and writing this file
		 * all night long may damage the flash. Also, usually the first
		 * crash log is the most interesting one. */
		crashlog_name = "/home/root/logs/enigma2_crash.log";
		if ((access(crashlog_name.c_str(), F_OK) == 0) ||
		    ((f = fopen(crashlog_name.c_str(), "wb")) == NULL))
		{
			/* Re-write the same file in /tmp/ because it's expected to
			 * be in RAM. So the first crash log will end up in /home
			 * and the last in /tmp */
			crashlog_name = "/tmp/enigma2_crash.log";
			f = fopen(crashlog_name.c_str(), "wb");
		}
	}

	if (f)
	{
		time_t t = time(0);
		struct tm tm;
		char tm_str[32];

		localtime_r(&t, &tm);
		strftime(tm_str, sizeof(tm_str), "%a %b %_d %T %Y", &tm);

		fprintf(f,
					"OpenBh Enigma2 Crashlog\n\n"
					"Crashdate = %s\n\n"
					"%s\n"
					"Compiled = %s\n"
					"Skin = %s\n"
					"Component = %s\n\n"
					"Kernel CMDline = %s\n"
					"Nim Sockets = %s\n",
					tm_str,
					stringFromFile("/etc/image-version").c_str(),
					__DATE__,
					getConfigString("config.skin.primary_skin", "Default Skin").c_str(),
					component,
					stringFromFile("/proc/cmdline").c_str(),
					stringFromFile("/proc/bus/nim_sockets").c_str()
				);

		/* dump the log ringbuffer */
		fprintf(f, "\n\n");
		if (logp1)
			fwrite(logp1, 1, logs1, f);
		if (logp2)
			fwrite(logp2, 1, logs2, f);

		fclose(f);
	}

	ePtr<gMainDC> my_dc;
	gMainDC::getInstance(my_dc);

	gPainter p(my_dc);
	p.resetOffset();
	p.resetClip(eRect(ePoint(0, 0), my_dc->size()));
	p.setBackgroundColor(gRGB(0x010000));
	p.setForegroundColor(gRGB(0xFFFFFF));

	int hd =  my_dc->size().width() == 1920;
	ePtr<gFont> font = new gFont("Regular", hd ? 30 : 20);
	p.setFont(font);
	p.clear();

	eRect usable_area = eRect(hd ? 30 : 100, hd ? 30 : 70, my_dc->size().width() - (hd ? 60 : 150), hd ? 150 : 100);

	os.str("");
	os.clear();
	os << "We are really sorry. Your receiver encountered "
		"a software problem, and needs to be restarted.\n"
		"Please upload the crash log " << crashlog_name << " to www.vuplus-community.net\n"
		"Your STB will restart in 10 seconds!\n"
		"Component: " << component;

	p.renderText(usable_area, os.str().c_str(), gPainter::RT_WRAP|gPainter::RT_HALIGN_LEFT);

	std::string logtail;
	int lines = 20;
	
	if (logp2)
	{
		unsigned int size = logs2;
		while (size) {
			const char* r = (const char*)memrchr(logp2, '\n', size);
			if (r) {
				size = r - logp2;
				--lines;
				if (!lines) {
					logtail = std::string(r, logs2 - size);
					break;
				} 
			}
			else {
				logtail = std::string(logp2, logs2);
				break;
			}
		}
	}

	if (lines && logp1)
	{
		unsigned int size = logs1;
		while (size) {
			const char* r = (const char*)memrchr(logp1, '\n', size);
			if (r) {
				--lines;
				size = r - logp1;
				if (!lines) {
					logtail += std::string(r, logs1 - size);
					break;
				} 
			}
			else {
				logtail += std::string(logp1, logs1);
				break;
			}
		}
	}

	if (!logtail.empty())
	{
		font = new gFont("Regular", hd ? 21 : 14);
		p.setFont(font);
		usable_area = eRect(hd ? 30 : 100, hd ? 180 : 170, my_dc->size().width() - (hd ? 60 : 180), my_dc->size().height() - (hd ? 30 : 20));
		p.renderText(usable_area, logtail, gPainter::RT_HALIGN_LEFT);
	}
	sleep(10);

	/*
	 * When 'component' is NULL, we are called because of a python exception.
	 * In that case, we'd prefer to to a clean shutdown of the C++ objects,
	 * and this should be safe, because the crash did not occur in the
	 * C++ part.
	 * However, when we got here for some other reason, a segfault probably,
	 * we prefer to stop immediately instead of performing a clean shutdown.
	 * We'd risk destroying things with every additional instruction we're
	 * executing here.
	 */
	if (component) raise(SIGKILL);
}
예제 #13
0
void PETables::buildThunks(FILE *f) {
   unsigned int import_rva, min_rva = 0xFFFFFFFF, max_rva = 0;
   unsigned int min_iat = 0xFFFFFFFF, max_iat = 0;
   _IMAGE_IMPORT_DESCRIPTOR desc;

   import_rva = nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
   if (import_rva) {
      msg("import_rva = %x, image_base = %x\n", import_rva, (unsigned int)nt->OptionalHeader.ImageBase);
      import_rva = rvaToFileOffset(import_rva);
      imports = NULL;

      while (1) {
//         msg("iat seeking to %x\n", import_rva);
         if (fseek(f, import_rva, SEEK_SET)) {
//            msg("Could not seek to import table: %x\n", import_rva);
            destroy();
            return;
         }
         if (fread(&desc, sizeof(desc), 1, f) != 1)  {
//            msg("Failed to read import table\n");
            destroy();
            return;
         }
         unsigned int iat_base = desc.FirstThunk;
//         msg("iat_base = %x\n", iat_base);
         if (iat_base == 0) break;   //end of import descriptor array
         unsigned int name_table = desc.OriginalFirstThunk;
         unsigned int name = desc.Name;  //rva of dll name string
         unsigned int iat = rvaToFileOffset(iat_base);
         if (name_table == 0) {
            name_table = iat;
         }
         else {
            name_table = rvaToFileOffset(name_table);
         }

         import_rva = ftell(f);
         name = rvaToFileOffset(name);
         thunk_rec *tr = (thunk_rec*)calloc(1, sizeof(thunk_rec));
         if (tr == NULL)  {
//            msg("Failed to alloc thunk record\n");
            destroy();
            return;
         }
         tr->iat_base = iat_base;
         if (iat_base < min_iat) min_iat = iat_base;
         
         tr->next = imports;
         imports = tr;
         if (fseek(f, name, SEEK_SET))  {
//            msg("Could not seek to name %x\n", name);
            destroy();
            return;
         }
         tr->dll_name = stringFromFile(f);
         if (tr->dll_name == NULL) {
//            msg("dll_name was null\n");
            destroy();
            return;
         }
//         msg("thunk dll: %s\n", tr->dll_name);
         if (fseek(f, name_table, SEEK_SET)) {
//         if (fseek(f, iat, SEEK_SET)) {
            msg("Could not seek to iat\n");
            destroy();
            return;
         }
         if (desc.Name < min_rva) min_rva = desc.Name;
         if (desc.Name > max_rva) max_rva = desc.Name + strlen(tr->dll_name) + 1;
         while (1) {
            tr->iat = (unsigned int*)realloc(tr->iat, (tr->iat_size + 1) * sizeof(unsigned int));
            if (tr->iat == NULL) {
               msg("failed to realloc iat\n");
               destroy();
               return;
            }
            if (fread(&tr->iat[tr->iat_size], sizeof(unsigned int), 1, f) != 1) {
               msg("Failed to read iat\n");
               destroy();
               return;
            }
            tr->iat_size++;
            if (tr->iat[tr->iat_size - 1] == 0) break;
         }
         unsigned int end_iat = iat_base + 4 * tr->iat_size;
         if (end_iat > max_iat) max_iat = end_iat;
         
//         tr->names = (char**)calloc(tr->iat_size, sizeof(char*));
         for (int i = 0; tr->iat[i]; i++) {
            unsigned int name_rva = tr->iat[i];
            if (name_rva & 0x80000000) continue;  //import by ordinal
            if (fseek(f, rvaToFileOffset(name_rva + 2), SEEK_SET)) {
               msg("Could not seek to name_rva (by ordinal)\n");
               destroy();
               return;
            }
//            tr->names[i] = stringFromFile(f);
            char *n = stringFromFile(f);
#ifdef DEBUG
            msg("read import name %s\n", n);
#endif
            if (name_rva < min_rva) min_rva = name_rva;
            if (name_rva > max_rva) max_rva = name_rva + strlen(n) + 1;
            free(n);
         }
      }
      if (isEnabled(base + min_rva) && isEnabled(base + max_rva - 1)) {
      }
      else {
         unsigned int sz = max_rva - min_rva + 2;
         unsigned char *strtable = (unsigned char *)malloc(sz);
         if (fseek(f, rvaToFileOffset(min_rva), SEEK_SET)) {
            free(strtable);
//            destroy();
            return;
         }
         if (fread(strtable, sz, 1, f) != 1)  {
            free(strtable);
//            destroy();
            return;
         }
         createSegment(base + min_rva, sz, strtable);
         free(strtable);
      }
      // Make sure there is a segment to hold the import table
      if (!isEnabled(base + min_iat) && !isEnabled(base + max_iat - 1)) {
         createSegment(base + min_iat, max_iat - min_iat, NULL);
      }
   }
}
예제 #14
0
// TODO(bill): Customize to be specific for shader files
// #include <> & #include ""
INTERNAL std::string stringFromFile(const std::string& filename)
{
	std::ifstream file;
	file.open(std::string{BaseDirectory::Shaders + filename.c_str()},
	          std::ios::in | std::ios::binary);

	std::string fileDirectory{FileSystem::getFileDirectory(filename) + "/"};

	std::string output;
	std::string line;

	if (!file.is_open())
	{
		panic(std::string("Failed to open file : ") + filename);
	}
	else
	{
		while (file.good())
		{
			std::getline(file, line);

			if (line.find("#include") == std::string::npos)
			{
				output.append(line + "\n");
			}
			else
			{
				std::string includeFilename{split(line, ' ')[1]};

				if (includeFilename[0] == '<') // Absolute Path (library path)
				{
					usize closingBracketPos{0};
					usize length{len(includeFilename)};
					for (usize i{1}; i < length; i++)
					{
						if (includeFilename[i] == '>')
						{
							closingBracketPos = i;
							break;
						}
					}

					if (closingBracketPos > 1)
					{
						includeFilename =
						    includeFilename.substr(1, closingBracketPos - 1);
					}
					else
					{
						includeFilename = "";
					}
				}
				else if (includeFilename[0] == '\"') // Relative Path (folder path)
				{
					usize closingSpeechMark{0};
					usize length{len(includeFilename)};
					for (usize i{1}; i < length; i++)
					{
						if (includeFilename[i] == '\"')
						{
							closingSpeechMark = i;
							break;
						}
					}

					if (closingSpeechMark > 1)
						includeFilename = includeFilename.substr(1, closingSpeechMark - 1);
					else
						includeFilename = "";
				}

				// std::cout << includeFilename << '\n';

				if (len(includeFilename) > 0)
					output.append(stringFromFile(includeFilename) + "\n");
			}
		}
	}

	file.close();
	return output;
}
예제 #15
0
bool ShaderProgram::attachShaderFromFile(ShaderType type,
                                         const std::string& filename)
{
	std::string source{stringFromFile(filename)};
	return attachShaderFromMemory(type, source);
}
예제 #16
0
std::string Importer::getSceneString(const std::string &scenePath) {
    return stringFromFile(scenePath.c_str());
}
예제 #17
0
GLuint createShaderProgram(
  const char *vertPath,
  const char *fragPath,
  const char *progName
) {
  int vertSourceSize, fragSourceSize, textBufSize = 1024;
  
  vertSourceSize = getFileSize(vertPath);
  if (!vertSourceSize) {
    printf("error: could not open file \"%s\"\n", vertPath);
    return 0;
  }
  if (vertSourceSize > textBufSize) textBufSize = vertSourceSize + 1;
  
  fragSourceSize = getFileSize(fragPath);
  if (!fragSourceSize) {
    printf("error: could not open file \"%s\"\n", fragPath);
    return 0;
  }
  if (fragSourceSize > textBufSize) textBufSize = fragSourceSize + 1;
  
  char *textBuf = malloc(textBufSize);
  GLint success;
  const char *compileErrorString = "error compiling shader \"%s\":\n%s\n";
  
  GLuint vertShader = glCreateShader(GL_VERTEX_SHADER);_glec
  stringFromFile(vertPath, textBuf, textBufSize);
  glShaderSource(vertShader, 1, (const GLchar**)&textBuf, NULL);_glec
  glCompileShader(vertShader);_glec
  glGetShaderiv(vertShader, GL_COMPILE_STATUS, &success);_glec
  if (!success) {
    glGetShaderInfoLog(vertShader, textBufSize, NULL, textBuf);_glec
    printf(compileErrorString, vertPath, textBuf);
    return 0;
  }
  
  GLuint fragShader = glCreateShader(GL_FRAGMENT_SHADER);_glec
  stringFromFile(fragPath, textBuf, textBufSize);
  glShaderSource(fragShader, 1, (const GLchar **)&textBuf, NULL);_glec
  glCompileShader(fragShader);_glec
  glGetShaderiv(fragShader, GL_COMPILE_STATUS, &success);_glec
  if (!success) {
    glGetShaderInfoLog(fragShader, textBufSize, NULL, textBuf);_glec
    printf(compileErrorString, fragPath, textBuf);
    return 0;
  }
  
  GLuint shaderProgram = glCreateProgram();_glec
  glAttachShader(shaderProgram, vertShader);_glec
  glAttachShader(shaderProgram, fragShader);_glec
  glLinkProgram(shaderProgram);_glec
  glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);_glec
  if (!success) {
    glGetShaderInfoLog(shaderProgram, textBufSize, NULL, textBuf);_glec
    printf("error linking shader program \"%s\":\n%s\n", progName, textBuf);
    return 0;
  }
  glValidateProgram(shaderProgram);_glec
  glGetProgramiv(shaderProgram, GL_VALIDATE_STATUS, &success);_glec
  if (!success) {
    glGetShaderInfoLog(shaderProgram, textBufSize, NULL, textBuf);_glec
    printf("error: invalid shader program \"%s\":\n%s\n", progName, textBuf);
    return 0;
  }
  
  free(textBuf);
  return shaderProgram;
}