コード例 #1
0
ファイル: fboblittest.cpp プロジェクト: akallabeth/glmemperf
void FBOBlitTest::prepare()
{
    BlitTest::prepare();

    glTexImage2D(GL_TEXTURE_2D, 0, m_format, m_width, m_height, 0, m_format, m_type, NULL);
    ASSERT_GL();

    glGenRenderbuffers(1, &m_depthbuffer);
    glBindRenderbuffer(GL_RENDERBUFFER, m_depthbuffer);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, m_width, m_height);
    ASSERT_GL();

    glGenFramebuffers(1, &m_framebuffer);
    glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture, 0);
    if (m_useDepth)
    {
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
                                  GL_RENDERBUFFER, m_depthbuffer);
    }
    ASSERT_GL();

    GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    ASSERT(status == GL_FRAMEBUFFER_COMPLETE);

    GLint viewport[4];
    glGetIntegerv(GL_VIEWPORT, viewport);
    glViewport(0, 0, m_width, m_height);
    fillTexture();
    glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    glBindRenderbuffer(GL_RENDERBUFFER, 0);
    ASSERT_GL();
}
コード例 #2
0
/* External functions
 */
Mesh* create_mesh(const Vertex* vertex_data, size_t vertex_data_size,
                  const uint32_t* index_data, size_t index_data_size,
                  int index_count)
{
    Mesh*   mesh = NULL;
    GLuint  vertex_buffer = 0;
    GLuint  index_buffer = 0;

    /* Create vertex buffer */
    ASSERT_GL(glGenBuffers(1, &vertex_buffer));
    ASSERT_GL(glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer));
    ASSERT_GL(glBufferData(GL_ARRAY_BUFFER, vertex_data_size, vertex_data, GL_STATIC_DRAW));
    ASSERT_GL(glBindBuffer(GL_ARRAY_BUFFER, 0));

    /* Create index buffer */
    ASSERT_GL(glGenBuffers(1, &index_buffer));
    ASSERT_GL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer));
    ASSERT_GL(glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_data_size, index_data, GL_STATIC_DRAW));
    ASSERT_GL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));

    /* Create mesh */
    mesh = (Mesh*)calloc(1, sizeof(Mesh));
    mesh->vertex_buffer = vertex_buffer;
    mesh->index_buffer = index_buffer;
    mesh->index_count = index_count;

    return mesh;
}
コード例 #3
0
ファイル: Material.cpp プロジェクト: artcom/mobile-spark
 void
 Material::loadShader(const matrix & theMatrix) {
     if (!shaderProgram_) {
         initShader();
     }
     glUseProgram(shaderProgram_);
     ASSERT_GL("glUseProgram", PLUS_FILE_LINE);
     glUniformMatrix4fv(mvpHandle_, 1, GL_FALSE, theMatrix.data());
     glUniform1f(alphaHandle_, alpha_);
     for (std::map<std::string, std::pair<GLuint, float> >::const_iterator it = customHandlesAndValues_.begin(); 
             it != customHandlesAndValues_.end(); ++it) {
         AC_TRACE << "set value in shader " << it->first << "  " << it->second.first << "  " << it->second.second;
         glUniform1f(it->second.first, it->second.second);
     }
     ASSERT_GL("Material::loadShader", PLUS_FILE_LINE);
 }
コード例 #4
0
ファイル: GLProgram.cpp プロジェクト: omochi/gluttest
	GLint GLProgram::getUniform(const GLchar *name){
		GLint ret;
		if(m_Id==0)FAIL("getUniform");
		ret = glGetUniformLocation(m_Id,name);
		ASSERT_GL();
		return ret;
	}
コード例 #5
0
ファイル: Material.cpp プロジェクト: artcom/mobile-spark
 void
 Material::deleteShader() {
     if (shaderProgram_) {
         glUseProgram(0);
         glDeleteProgram(shaderProgram_);
         shaderProgram_ = 0;
         ASSERT_GL("glDeleteProgram", PLUS_FILE_LINE);
     }
 }
コード例 #6
0
ファイル: Material.cpp プロジェクト: artcom/mobile-spark
 void
 UnlitTexturedMaterial::loadShader(const matrix & theMatrix) {
     Material::loadShader(theMatrix);
     AC_TRACE << "UnlitTexturedMaterial::loadShader " << (void*)this
              << " bindTexture: "<<textureUnit_->getTexture()
              << " " << textureUnit_->getTexture()->getAttributesAsString();
     glUniformMatrix4fv(textureMatrixHandle_, 1, GL_FALSE, textureUnit_->getRenderMatrix().data());
     glBindTexture(textureUnit_->getTexture()->_textureTarget, textureUnit_->getTexture()->_textureId);
     ASSERT_GL("UnlitTexturedMaterial::loadShader", PLUS_FILE_LINE);
 }
コード例 #7
0
void draw_mesh(const Mesh* M)
{
    float* ptr = 0;
    ASSERT_GL(glBindBuffer(GL_ARRAY_BUFFER, M->vertex_buffer));
    ASSERT_GL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, M->index_buffer));
    ASSERT_GL(glVertexAttribPointer(kPositionSlot,    3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(ptr+=0)));
    ASSERT_GL(glVertexAttribPointer(kNormalSlot,      3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(ptr+=3)));
    ASSERT_GL(glVertexAttribPointer(kTangentSlot,     3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(ptr+=3)));
    ASSERT_GL(glVertexAttribPointer(kBitangentSlot,   3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(ptr+=3)));
    ASSERT_GL(glVertexAttribPointer(kTexCoordSlot,    2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(ptr+=3)));
    ASSERT_GL(glDrawElements(GL_TRIANGLES, M->index_count, GL_UNSIGNED_INT, NULL));
}
コード例 #8
0
ファイル: runner_cli.cpp プロジェクト: akallabeth/glmemperf
int main(int argc, char** argv)
{
    std::list<std::string> args(argv, argv + argc);

    showIntro();
    parseArguments(args);
    findDataDirectory();

    const EGLint configAttrs[] =
    {
        EGL_BUFFER_SIZE, options.bitsPerPixel,
        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
        EGL_NONE
    };

    const EGLint configAttrs32[] =
    {
        EGL_BUFFER_SIZE, 32,
        EGL_NONE
    };

    const EGLint contextAttrs[] =
    {
        EGL_CONTEXT_CLIENT_VERSION, 2,
        EGL_NONE
    };
    int winWidth = 800;
    int winHeight = 480;
    const float w = winWidth, h = winHeight;
    EGLConfig config32 = 0;
    EGLint configCount = 0;

    bool result = nativeCreateDisplay(&ctx.nativeDisplay);
    ASSERT(result);

    nativeGetScreenSize(ctx.nativeDisplay, &winWidth, &winHeight);
    result = initializeEgl(winWidth, winHeight, configAttrs, contextAttrs);
    ASSERT(result);

    eglChooseConfig(ctx.dpy, configAttrs32, &config32, 1, &configCount);

    if (!configCount)
    {
        printf("32bpp config not found\n");
    }

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    ASSERT_GL();

#define ADD_TEST(TEST) runTest(*std::auto_ptr<Test>(new TEST));
#include "tests.inl"
#undef ADD_TEST

    terminateEgl();
}
コード例 #9
0
ファイル: Material.cpp プロジェクト: artcom/mobile-spark
 void
 Material::initShader() {
     AC_DEBUG << "Material initShader "<<(void*)this;
     if (vertexShader_.empty() || fragmentShader_.empty()) {
         setShader();
     }
     shaderProgram_ = createProgram(vertexShader_, fragmentShader_);
     if (!shaderProgram_) {
         AC_ERROR << "Could not create program.";
         throw ShaderCreationException("problems during shader program creation of " + vertexShader_ + " or/and " + fragmentShader_, PLUS_FILE_LINE);
     }
     bindAttributes();
     setHandles();
     glLinkProgram(shaderProgram_);
     ASSERT_GL("glLinkProgram", PLUS_FILE_LINE);
 }
コード例 #10
0
ファイル: util.cpp プロジェクト: akallabeth/glmemperf
bool loadCompressedTexture(GLenum target, int level, GLenum internalFormat, int width,
                           int height, const std::string& fileName)
{
#if defined(SUPPORT_ANDROID)
    AAsset* asset = AAssetManager_open(ctx.assetManager, fileName.c_str(), O_RDONLY);
    if (!asset)
    {
        LOGW("Unable to open asset %s", fileName.c_str());
        return false;
    }
    off_t size = AAsset_getLength(asset);
    void* pixels = malloc(size);
    AAsset_read(asset, pixels, size);
    AAsset_close(asset);
#else // !SUPPORT_ANDROID
    int fd = open(fileName.c_str(), O_RDONLY); 

    if (fd == -1)
    {
        perror("open");
        return false;
    }

    struct stat sb;
    if (fstat(fd, &sb) == -1)
    {
        perror("stat");
        return false;
    }
    off_t size = sb.st_size;
    void* pixels = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
#endif // !SUPPORT_ANDROID

    glCompressedTexImage2D(target, level, internalFormat, width, height, 0, size, pixels);

#if defined(SUPPORT_ANDROID)
    free(pixels);
#else
    munmap(pixels, sb.st_size);
    close(fd);
#endif

    ASSERT_GL();
    return true;
}
コード例 #11
0
ファイル: Material.cpp プロジェクト: artcom/mobile-spark
 void
 Material::bindAttributes() {
     AC_DEBUG << "Material::bindAttributes "<<(void*)this;
     glBindAttribLocation(shaderProgram_, VERTEX_POS_INDEX, "a_position");
     ASSERT_GL("glBindAttribLocation", PLUS_FILE_LINE);
 }
コード例 #12
0
ファイル: Material.cpp プロジェクト: artcom/mobile-spark
 void
 UnlitTexturedMaterial::bindAttributes() {
     Material::bindAttributes();
     glBindAttribLocation(shaderProgram_, VERTEX_TEXCOORD0_INDEX, "a_texCoord0");
     ASSERT_GL("UnlitTexturedMaterial::bindAttributes", PLUS_FILE_LINE);
 }
コード例 #13
0
ファイル: Material.cpp プロジェクト: artcom/mobile-spark
 void
 UnlitColoredMaterial::loadShader(const matrix & theMatrix) {
     Material::loadShader(theMatrix);
     glUniform4fv(colorHandle_, 1, &(diffuse_[0]));
     ASSERT_GL("UnlitColoredMaterial::loadShader", PLUS_FILE_LINE);
 }
コード例 #14
0
ファイル: runner_cli.cpp プロジェクト: akallabeth/glmemperf
void runTest(Test& test)
{
    int frames = 0;
    int frameLimit = 100;
    int warmup = 20;
    int64_t minTime = options.minTime * 1000 * 1000 * 1000LL;
    struct timespec res, start, end;

    if (options.listTests)
    {
        printf("%s\n", test.name().c_str());
        return;
    }

    if (!shouldRunTest(test.name()))
    {
        return;
    }

    clock_getres(CLOCK_REALTIME, &res);
    //printf("Timer resolution: %d.%09d s\n", res.tv_sec, res.tv_nsec);
    printf("%-40s", (test.name() + ":").c_str());
    fflush(stdout);

    try
    {
        test.prepare();
        ASSERT_GL();
        ASSERT_EGL();
    } catch (const std::exception& e)
    {
        printf("%s\n", e.what());
        return;
    }

    nativeVerifyWindow(ctx.nativeDisplay, ctx.win);

    while (warmup--)
    {
        test(0);
        swapBuffers();
    }

    ASSERT_GL();
    ASSERT_EGL();

#if defined(HAVE_LIBOSSO)
    if (ossoContext)
    {
        osso_display_blanking_pause(ossoContext);
    }
#endif

    clock_gettime(CLOCK_REALTIME, &start);
    while (frames < frameLimit)
    {
        test(frames);
        swapBuffers();
        clock_gettime(CLOCK_REALTIME, &end);
        frames++;
        if (frames >= frameLimit && timeDiff(start, end) < minTime)
        {
            frameLimit *= 2;
        }
    }

    ASSERT_GL();
    ASSERT_EGL();

    test.teardown();
    ASSERT_GL();
    ASSERT_EGL();

    int64_t diff = timeDiff(start, end);
    int fps = static_cast<int>((1000 * 1000 * 1000LL * frames) / diff);
    //printf("%d frames in %6.2f ms (%3d fps) ", frames, diff / (1000.0f * 1000.0f), fps);
    printf("%3d fps ", fps);

    while (fps > 0)
    {
        fputc('#', stdout);
        fps -= 3;
    }
    fputc('\n', stdout);
}
コード例 #15
0
ファイル: GLProgram.cpp プロジェクト: omochi/gluttest
	void GLProgram::bindAttrib(GLuint index,const GLchar *name){
		if(m_Id==0)FAIL("bindAttrib");
		glBindAttribLocation(m_Id,index,name);
		ASSERT_GL();
	}
コード例 #16
0
void destroy_mesh(Mesh* M)
{
    ASSERT_GL(glDeleteBuffers(1,&M->vertex_buffer));
    ASSERT_GL(glDeleteBuffers(1,&M->index_buffer));
    free(M);
}