예제 #1
0
/**
 * \brief Creates a new animated geometry
 */
SCE_SAnimatedGeometry* SCE_AnimGeom_Create (void)
{
    SCE_SAnimatedGeometry *ageom = NULL;
    if (!(ageom = SCE_malloc (sizeof *ageom)))
        SCEE_LogSrc ();
    else {
        SCE_AnimGeom_Init (ageom);
        if (!(ageom->geom = SCE_Geometry_Create ())) {
            SCE_free (ageom), ageom = NULL;
            SCEE_LogSrc ();
        }
    }
    return ageom;
}
예제 #2
0
SCE_RShaderGLSL* SCE_RCreateShaderGLSL (SCE_RShaderType type)
{
    SCE_RShaderGLSL *shader = NULL;

    shader = SCE_malloc (sizeof *shader);
    if (!shader) {
        SCEE_LogSrc ();
        return NULL;
    }

    shader->data = NULL;
    shader->compiled = SCE_FALSE;
    shader->type = type;
    shader->gltype = sce_gltype[type];

    shader->id = glCreateShader (shader->gltype);
    if (shader->id == 0) {
        SCEE_Log (SCE_ERROR);
        SCEE_LogMsg ("failed to create shader: %s", SCE_RGetError ());
        SCE_free (shader);
        return NULL;
    }

    return shader;
}
예제 #3
0
/**
 * \brief Specify which varying should be written to the feedback stream(s)
 * \param prog a shader
 * \param n number of varyings
 * \param varyings names of the varyings that will be written onto the buffers
 * \param mode storage mode
 */
int SCE_RSetProgramFeedbackVaryings (SCE_RProgram *prog, SCEuint n,
                                     const char **varyings,
                                     SCE_RFeedbackStorageMode mode)
{
    size_t i;

    if (n == 0) {
        prog->fb_enabled = SCE_FALSE;
        for (i = 0; i < prog->n_varyings; i++)
            SCE_free (prog->fb_varyings[i]);
        SCE_free (prog->fb_varyings);
    } else {
        prog->n_varyings = n;
        if (!(prog->fb_varyings = SCE_malloc (n * sizeof *prog->fb_varyings)))
            goto fail;
        for (i = 0; i < n; i++)
            prog->fb_varyings[i] = NULL;
        for (i = 0; i < prog->n_varyings; i++) {
            if (!(prog->fb_varyings[i] = SCE_String_Dup (varyings[i])))
                goto fail;
        }
        prog->fb_enabled = SCE_TRUE;
        prog->fb_mode = mode;
        prog->linked = SCE_FALSE; /* link will be needed */
    }

    return SCE_OK;
fail:
    SCEE_LogSrc ();
    return SCE_ERROR;
}
예제 #4
0
SCE_RProgram* SCE_RCreateProgram (void)
{
    int i;
    SCE_RProgram *prog = NULL;
    prog = SCE_malloc (sizeof *prog);
    if (!prog) {
        SCEE_LogSrc ();
        return NULL;
    }

    prog->id = glCreateProgram ();
    prog->linked = SCE_FALSE;
    SCE_RInitVertexAttributesMap (prog->map);
    prog->map_built = SCE_FALSE;
    prog->use_vmap = SCE_FALSE;
    for (i = 0; i < SCE_NUM_MATRICES; i++) {
        prog->funs[i] = SCE_RSetProgramNoneMatrix;
        prog->mat_map[i] = -1;
    }
    prog->use_mmap = SCE_FALSE;
    prog->use_tess = SCE_FALSE;
    prog->patch_vertices = 0;
    prog->fb_enabled = SCE_FALSE;
    prog->fb_mode = SCE_FEEDBACK_INTERLEAVED;
    prog->fb_varyings = NULL;
    prog->n_varyings = 0;
    for (i = 0; i < SCE_MAX_ATTACHMENT_BUFFERS; i++)
        memset (prog->outputs[i], 0, SCE_SHADER_OUTPUT_LENGTH);

    return prog;
}
예제 #5
0
/**
 * \brief Creates a skybox
 */
SCE_SSkybox* SCE_Skybox_Create (void)
{
    SCE_SSceneEntityProperties *props = NULL;
    SCE_SSkybox *skybox = NULL;
    if (!(skybox = SCE_malloc (sizeof *skybox)))
        goto fail;
    SCE_Skybox_Init (skybox);
    if (!(skybox->mesh = SCE_Mesh_Create ()))
        goto fail;
    if (!(skybox->entity = SCE_SceneEntity_Create ()))
        goto fail;
    if (!(skybox->instance = SCE_SceneEntity_CreateInstance ()))
        goto fail;
    SCE_SceneEntity_AddInstanceToEntity (skybox->entity, skybox->instance);
    props = SCE_SceneEntity_GetProperties (skybox->entity);
    props->cullface = SCE_FALSE;
    props->depthtest = SCE_FALSE;
    props->alphatest = SCE_FALSE;

    return skybox;
fail:
    SCE_Skybox_Delete (skybox);
    SCEE_LogSrc ();
    return NULL;
}
예제 #6
0
int SCE_RBuildShaderGLSL (SCE_RShaderGLSL *shader)
{
    int compile_status = GL_TRUE;
    int loginfo_size = 0;
    char *loginfo = NULL;

    glShaderSource (shader->id, 1, (const GLchar**)&shader->data, NULL);
    glCompileShader (shader->id);

    glGetShaderiv (shader->id, GL_COMPILE_STATUS, &compile_status);
    if (compile_status != GL_TRUE) {
        SCEE_Log (SCE_INVALID_OPERATION);
        glGetShaderiv (shader->id, GL_INFO_LOG_LENGTH, &loginfo_size);
        loginfo = SCE_malloc (loginfo_size + 1);
        if (!loginfo) {
            SCEE_LogSrc ();
            return SCE_ERROR;
        }

        memset (loginfo, '\0', loginfo_size + 1);
        glGetShaderInfoLog (shader->id, loginfo_size, &loginfo_size, loginfo);

        SCEE_LogMsg ("error while compiling GLSL %s shader :\n%s",
                     sce_typename[shader->type], loginfo);
        SCE_free (loginfo);
        return SCE_ERROR;
    }

    shader->compiled = SCE_TRUE;
    return SCE_OK;
}
예제 #7
0
/**
 * \brief Loads an animated geometry from a file
 * \param fmesh the file of the mesh
 * \param force force reload of the resource
 * \returns a new animated geometry based on the given files or NULL on error
 * \sa SCE_Resource_Load()
 */
SCE_SAnimatedGeometry* SCE_AnimGeom_Load (const char *fmesh, int force)
{
    SCE_SAnimatedGeometry *ageom = NULL;
    if (!(ageom = SCE_Resource_Load (resource_type, fmesh, force, NULL)))
        SCEE_LogSrc ();
    return ageom;
}
예제 #8
0
파일: SCECore.c 프로젝트: scengine/core
/**
 * \brief Initializes the core
 * \param outlog stream used to log informations and errors
 * \param flags currently unuset, set it to 0
 * \returns SCE_ERROR if any error has occured, SCE_OK otherwise
 */
int SCE_Init_Core (FILE *outlog, SCEbitfield flags)
{
    int ret = SCE_OK;
    if (pthread_mutex_lock (&init_mutex) != 0) {
        SCEE_Log (42);
        SCEE_LogMsg ("failed to lock initialisation mutex of interface");
        return SCE_ERROR;
    }
    init_n++;
    if (init_n == 1) {
        if (SCE_Init_Utils (outlog) < 0 ||
            SCE_Init_Noise () < 0 ||
            SCE_Init_Geometry () < 0 ||
            SCE_Init_Image () < 0 ||
            SCE_Init_BoxGeom () < 0 ||
            SCE_Init_OBJ () < 0 ||
            SCE_Init_AnimGeom () < 0 ||
            SCE_Init_Anim () < 0 ||
            SCE_Init_idTechMD5 () < 0) {
            ret = SCE_ERROR;
        }
    }
    pthread_mutex_unlock (&init_mutex);
    if (ret == SCE_ERROR) {
        SCE_Quit_Core ();
        SCEE_LogSrc ();
        SCEE_LogSrcMsg ("failed to initialize SCEngine interface");
    }
    return ret;
}
예제 #9
0
int SCE_RValidateProgram (SCE_RProgram *prog)
{
    int status = GL_TRUE;
    int loginfo_size = 0;
    char *loginfo = NULL;

    glValidateProgram (prog->id);
    glGetProgramiv (prog->id, GL_VALIDATE_STATUS, &status);
    if (status != GL_TRUE) {
        /* TODO: add program name */
        glGetProgramiv (prog->id, GL_INFO_LOG_LENGTH, &loginfo_size);
        loginfo = SCE_malloc (loginfo_size + 1);
        if (!loginfo) {
            SCEE_LogSrc ();
            return SCE_ERROR;
        }
        memset (loginfo, '\0', loginfo_size + 1);
        glGetProgramInfoLog (prog->id, loginfo_size, &loginfo_size, loginfo);

        SCEE_LogMsg ("can't validate program, reason: %s", loginfo);
        return SCE_ERROR;
    }

    return SCE_OK;
}
예제 #10
0
/**
 * \brief Allocates memory for the base vertices (4D vectors)
 * \param attrib vertex attribute of the vectors
 * \param local are the vectors in local position from their joints?
 * \returns SCE_ERROR on error, SCE_OK otherwise
 */
int SCE_AnimGeom_AllocateBaseVertices (SCE_SAnimatedGeometry *ageom,
                                       SCE_EVertexAttribute attrib,
                                       int local)
{
    float *data = NULL;
    size_t i, n, id;
    if (local)
        n = ageom->n_weights;
    else
        n = ageom->n_vertices;
#ifdef SCE_DEBUG
    if (ageom->n_vertices == 0) {
        SCEE_Log (SCE_INVALID_OPERATION);
        SCEE_LogMsg ("you must call SCE_AnimGeom_AllocateVertices() "
                     "before calling this function");
        return SCE_ERROR;
    } else if (n == 0) {
        SCEE_Log (SCE_INVALID_OPERATION);
        SCEE_LogMsg ("you must call SCE_AnimGeom_AllocateWeights() "
                     "before calling this function");
        return SCE_ERROR;
    }
#endif
    id = SCE_AnimGeom_GetVerticesID (attrib);
    if (!(data = SCE_malloc (n * 4 * sizeof *data))) {
        SCEE_LogSrc ();
        return SCE_ERROR;
    }
    ageom->output[id] = SCE_malloc (ageom->n_vertices * 3 * sizeof *data);
    if (!ageom->output[id]) {
        SCE_free (data);
        SCEE_LogSrc ();
        return SCE_ERROR;
    }
    for (i = 0; i < n; i++) {
        data[i]     = ageom->output[id][i]     = 0.0f;
        data[i + 1] = ageom->output[id][i + 1] = 0.0f;
        data[i + 2] = ageom->output[id][i + 2] = 0.0f;
        data[i + 3] = 0.0f;
    }
    SCE_free (ageom->base[id]);
    ageom->base[id] = data;
    ageom->local[id] = local;
    return SCE_OK;
}
예제 #11
0
SCE_RPointSprite* SCE_RCreatePointSprite (void)
{
    SCE_RPointSprite *point = NULL;
    if (!(point = SCE_malloc (sizeof *point)))
        SCEE_LogSrc ();
    else
        SCE_RInitPointSprite (point);
    return point;
}
예제 #12
0
SCE_SParticleEmitter* SCE_ParticleEmit_Create (void)
{
    SCE_SParticleEmitter *emit = NULL;
    if (!(emit = SCE_malloc (sizeof *emit)))
        SCEE_LogSrc ();
    else
        SCE_ParticleEmit_Init (emit);
    return emit;
}
예제 #13
0
파일: SCEVoxelStore.c 프로젝트: has70/core
SCE_SVoxelStorage* SCE_VStore_Create (void)
{
    SCE_SVoxelStorage *vs = NULL;
    if (!(vs = SCE_malloc (sizeof *vs)))
        SCEE_LogSrc ();
    else
        SCE_VStore_Init (vs);
    return vs;
}
예제 #14
0
SCE_RMaterial* SCE_RCreateMaterial (void)
{
    SCE_RMaterial *mat = SCE_malloc (sizeof *mat);
    if (!mat)
        SCEE_LogSrc ();
    else
        SCE_RInitMaterial (mat);
    return mat;
}
예제 #15
0
파일: SCEVoxelGrid.c 프로젝트: has70/core
SCE_SVoxelGrid* SCE_VGrid_Create (void)
{
    SCE_SVoxelGrid *vg = NULL;
    if (!(vg = SCE_malloc (sizeof *vg)))
        SCEE_LogSrc ();
    else
        SCE_VGrid_Init (vg);
    return vg;
}
예제 #16
0
파일: SCETextureData.c 프로젝트: has70/core
SCE_STexData* SCE_TexData_Create (void)
{
    SCE_STexData *d = NULL;
    if (!(d = SCE_malloc (sizeof *d)))
        SCEE_LogSrc ();
    else
        SCE_TexData_Init (d);
    return d;
}
예제 #17
0
SCE_RLight* SCE_RCreateLight (void)
{
    SCE_RLight *light = NULL;

    if (!(light = SCE_malloc (sizeof *light)))
        SCEE_LogSrc ();
    else
        SCE_RInitLight (light);
    return light;
}
예제 #18
0
int SCE_RBuildProgram (SCE_RProgram *prog)
{
    const int modes[2] = {GL_INTERLEAVED_ATTRIBS, GL_SEPARATE_ATTRIBS};
    int status = GL_TRUE;
    int loginfo_size = 0;
    char *loginfo = NULL;
    int i, j;

    if (prog->linked)
        return SCE_OK;

    /* setting transform feedback up */
    if (prog->fb_enabled) {
        glTransformFeedbackVaryings (prog->id, prog->n_varyings,
                                     (const GLchar**)prog->fb_varyings,
                                     modes[prog->fb_mode]);
    }

    /* TODO: follows the same pattern as SCE_RSetDrawBuffers */
    j = 0;
    for (i = 0; i < SCE_MAX_ATTACHMENT_BUFFERS; i++) {
        if (*prog->outputs[i])
            glBindFragDataLocation (prog->id, j++, prog->outputs[i]);
    }

    glLinkProgram (prog->id);

    glGetProgramiv (prog->id, GL_LINK_STATUS, &status);
    if (status != GL_TRUE) {
        SCEE_Log (SCE_INVALID_OPERATION);

        glGetProgramiv (prog->id, GL_INFO_LOG_LENGTH, &loginfo_size);
        loginfo = SCE_malloc (loginfo_size + 1);
        if (!loginfo) {
            SCEE_LogSrc ();
            return SCE_ERROR;
        }
        memset (loginfo, '\0', loginfo_size + 1);
        glGetProgramInfoLog (prog->id, loginfo_size, &loginfo_size, loginfo);

        /* TODO: add program name */
        SCEE_LogMsg ("can't link program, reason: %s", loginfo);

        SCE_free (loginfo);
        return SCE_ERROR;
    }

    prog->linked = SCE_TRUE;

    /* if the map was previously built, rebuild it */
    if (prog->map_built)
        SCE_RSetupProgramAttributesMapping (prog);

    return SCE_OK;
}
예제 #19
0
파일: SCETextureData.c 프로젝트: has70/core
SCE_STexData* SCE_TexData_CreateFromImage (SCE_SImage *img, int canfree)
{
    SCE_STexData *d = NULL;
    if (!(d = SCE_TexData_Create ())) goto fail;
    if (SCE_TexData_SetImage (d, img, canfree) < 0) goto fail;
    return d;
fail:
    SCE_TexData_Delete (d);
    SCEE_LogSrc ();
    return NULL;
}
예제 #20
0
파일: SCEVoxelGrid.c 프로젝트: has70/core
int SCE_VGrid_Build (SCE_SVoxelGrid *vg)
{
    size_t size;

    size = vg->n_cmp * SCE_VGrid_GetNumVoxels (vg);
    if (!(vg->data = SCE_malloc (size))) {
        SCEE_LogSrc ();
        return SCE_ERROR;
    }
    /* NOTE: fill the voxels with an empty pattern... ? */
    return SCE_OK;
}
예제 #21
0
/**
 * \brief Builds the internal SCE_SGeometry of an animated geometry
 * \sa SCE_AnimGeom_GetGeometry()
 */
int SCE_AnimGeom_BuildGeometry (SCE_SAnimatedGeometry *ageom)
{
    if (ageom->base[0]) {
        ageom->arrays[0] =
            SCE_Geometry_AddNewArray (ageom->geom, SCE_POSITION,
                                      SCE_VERTICES_TYPE, 0, 3,
                                      ageom->output[0], SCE_FALSE);
                                      
        if (!ageom->arrays[0])
            goto fail;
    }
    if (ageom->base[1]) {
        ageom->arrays[1] =
            SCE_Geometry_AddNewArray (ageom->geom, SCE_NORMAL,
                                      SCE_VERTICES_TYPE, 0, 3,
                                      ageom->output[1], SCE_FALSE);
        if (!ageom->arrays[1])
            goto fail;
    }
    if (ageom->base[2]) {
        ageom->arrays[2] =
            SCE_Geometry_AddNewArray (ageom->geom, SCE_TANGENT,
                                      SCE_VERTICES_TYPE, 0, 3,
                                      ageom->output[2], SCE_FALSE);
        if (!ageom->arrays[2])
            goto fail;
    }
    if (ageom->base[3]) {
        ageom->arrays[3] =
            SCE_Geometry_AddNewArray (ageom->geom, SCE_BINORMAL,
                                      SCE_VERTICES_TYPE, 0, 3,
                                      ageom->output[3], SCE_FALSE);
        if (!ageom->arrays[3])
            goto fail;
    }
    if (ageom->indices) {
        SCE_SGeometryArray array;
        SCE_Geometry_InitArray (&array);
        SCE_Geometry_SetArrayIndices (&array, SCE_INDICES_TYPE,
                                      ageom->indices, SCE_FALSE);
        if (SCE_Geometry_SetIndexArrayDup (ageom->geom, &array, SCE_FALSE) < 0)
            goto fail;
        SCE_Geometry_SetNumIndices (ageom->geom, ageom->n_indices);
    }
    SCE_Geometry_SetNumVertices (ageom->geom, ageom->n_vertices);
    SCE_Geometry_SetPrimitiveType (ageom->geom, SCE_TRIANGLES);

    return SCE_OK;
fail:
    SCEE_LogSrc ();
    return SCE_ERROR;
}
예제 #22
0
/**
 * \brief Allocates memory for vertex weights
 * \returns SCE_ERROR on error, SCE_OK otherwise
 * \sa SCE_AnimGeom_SetWeights(), SCE_AnimGeom_AllocateVertices()
 */
int SCE_AnimGeom_AllocateWeights (SCE_SAnimatedGeometry *ageom, size_t n)
{
    size_t i;
    SCE_free (ageom->weights);
    if (!(ageom->weights = SCE_malloc (n * sizeof *ageom->weights))) {
        SCEE_LogSrc ();
        return SCE_ERROR;
    }
    ageom->n_weights = n;
    for (i = 0; i < n; i++)
        SCE_AnimGeom_InitWeight (&ageom->weights[i]);
    return SCE_OK;
}
예제 #23
0
/**
 * \brief Allocates memory for vertices
 * \returns SCE_ERROR on error, SCE_OK otherwise
 * \sa SCE_AnimGeom_AllocateWeights()
 */
int SCE_AnimGeom_AllocateVertices (SCE_SAnimatedGeometry *ageom, size_t n)
{
    size_t i;
    SCE_free (ageom->vertices);
    if (!(ageom->vertices = SCE_malloc (n * sizeof *ageom->vertices))) {
        SCEE_LogSrc ();
        return SCE_ERROR;
    }
    ageom->n_vertices = n;
    for (i = 0; i < n; i++)
        SCE_AnimGeom_InitVertex (&ageom->vertices[i]);
    return SCE_OK;
}
예제 #24
0
/**
 * \internal
 * \brief Initializes the animated geometry manager
 */
int SCE_Init_AnimGeom (void)
{
    if (is_init)
        return SCE_OK;
    resource_type = SCE_Resource_RegisterType (SCE_TRUE, NULL, NULL);
    if (resource_type < 0)
        goto fail;
    is_init = SCE_TRUE;
    return SCE_OK;
fail:
    SCEE_LogSrc ();
    SCEE_LogSrcMsg ("failed to initialize animated geometry module");
    return SCE_ERROR;
}
예제 #25
0
파일: SCETextureData.c 프로젝트: has70/core
/**
 * \brief Duplicates a texture data
 * \param d the texture data to copy
 *
 * This function duplicates the data of the texture but not the image.
 * \returns the copy of \p d
 */
SCE_STexData* SCE_TexData_Dup (const SCE_STexData *d)
{
    SCE_STexData *data = NULL;

    if (!(data = SCE_TexData_Create ())) {
        SCEE_LogSrc ();
        return NULL;
    }

    SCE_TexData_Copy (data, d);
    data->data_user = SCE_FALSE;
    data->data = NULL;

    if (data->data_size > 0 && d->data) {
        if (!(data->data = SCE_malloc (data->data_size))) {
            SCE_TexData_Delete (data);
            SCEE_LogSrc ();
            return NULL;
        }
        memcpy (data->data, d->data, data->data_size);
    }
    return data;
}
예제 #26
0
int SCE_RReallocBufferPoolBuffer (SCE_RBufferPool *pool, SCE_RBuffer *buf,
                                  size_t size)
{
    long id;
    if (SCE_RSetBufferPoolBuffer (pool, buf->id) < 0)
        goto fail;
    if ((id = SCE_RGetBufferPoolBuffer (pool, size)) < 0)
        goto fail;
    buf->id = id;
    buf->size = SCE_Math_NextPowerOfTwo (size);
    return SCE_OK;
fail:
    SCEE_LogSrc ();
    return SCE_ERROR;
}
예제 #27
0
파일: SCEVoxelStore.c 프로젝트: has70/core
/* also vacuum in void, dog. */
int SCE_VStore_Build (SCE_SVoxelStorage *vs, const void *vacuum)
{
    SCEuint i;

    if (!(vs->vacuum = SCE_malloc (vs->data_size)))
        goto fail;
    memcpy (vs->vacuum, vacuum, vs->data_size);

    for (i = 0; i < vs->n_lod; i++) {
        if (SCE_VStore_BuildLevel (vs, i) < 0)
            goto fail;
    }

    return SCE_OK;
fail:
    SCEE_LogSrc ();
    return SCE_ERROR;
}
예제 #28
0
/**
 * \brief Defines the texture of a skybox
 * \param skybox a skybox
 * \param tex the texture to set
 * \param mode see SCE_BoxGeom_Generate()
 * \returns SCE_ERROR on error, SCE_OK otherwise
 * \sa SCE_Skybox_SetShader(), SCE_SceneEntity_AddTexture()
 */
int SCE_Skybox_SetTexture (SCE_SSkybox *skybox, SCE_STexture *tex,
                           SCE_EBoxGeomTexCoordMode mode)
{
    SCE_TVector3 center = {0.0f, 0.0f, 0.0f};
    SCE_SBox box;
    int type;
    SCE_SGeometry *geom = NULL;

    /* remove the previous one */
    if (skybox->tex)
        SCE_SceneEntity_RemoveTexture (skybox->entity, skybox->tex);
    SCE_SceneEntity_AddTexture (skybox->entity, tex);
    skybox->tex = tex;

    SCE_Box_Init (&box);
    SCE_Box_Set (&box, center, 1.0f, 1.0f, 1.0f);

    type = SCE_Texture_GetType (tex);
    if (type == SCE_TEX_CUBE) {
        geom = SCE_BoxGeom_Create (&box, SCE_TRIANGLES,SCE_BOX_CUBEMAP_TEXCOORD,
                                   SCE_BOX_NONE_NORMALS);
    } else {
        if (!mode)              /* he lies. */
            mode = SCE_BOX_INTERIOR_TEXCOORD;
        geom = SCE_BoxGeom_Create (&box, SCE_TRIANGLES, mode,
                                   SCE_BOX_NONE_NORMALS);
    }
    if (!geom)
        goto fail;
    SCE_Mesh_SetGeometry (skybox->mesh, geom, SCE_TRUE);
    geom = NULL;
    SCE_Mesh_Build (skybox->mesh, SCE_GLOBAL_VERTEX_BUFFER, NULL);
    SCE_SceneEntity_SetMesh (skybox->entity, skybox->mesh);
    skybox->mode = mode;
    skybox->textype = type;

    return SCE_OK;
fail:
    SCE_Geometry_Delete (geom);
    SCEE_LogSrc ();
    return SCE_ERROR;
}
예제 #29
0
int SCE_RFlushBufferPool (SCE_RBufferPool *pool, SCEuint max)
{
    size_t i, size;
    SCE_SArray *a = NULL;

    max *= sizeof (SCEuint);
    for (i = 0; i < 32; i++) {
        a = &pool->buffers[i];
        size = SCE_Array_GetSize (a);
        if (size > max) {
            SCEubyte *ptr = SCE_Array_Get (a);
            glDeleteBuffers ((size - max) / sizeof (SCEuint), &ptr[max]);
            if (SCE_Array_PopBack (a, size - max) < 0) {
                SCEE_LogSrc ();
                return SCE_ERROR;
            }
        }
    }

    return SCE_OK;
}
예제 #30
0
/**
 * \brief Retrieve a buffer from a pool
 * \param pool a pool
 * \param size size of the desired buffer
 * \return the identifier of a buffer of size at least \p size,
 * SCE_ERROR on error
 */
long SCE_RGetBufferPoolBuffer (SCE_RBufferPool *pool, size_t size)
{
    SCEuint id;
    SCEuint index = getindex (size);

    if (size == 0)
        return 0;

    if (!SCE_Array_GetSize (&pool->buffers[index])) {
        /* pool is empty */
        id = SCE_RNewBuffer (pool, 1 << index);
    } else {
        id = *((SCEuint*)SCE_Array_Get (&pool->buffers[index]));
        if (SCE_Array_PopFront (&pool->buffers[index], sizeof id) < 0) {
            SCEE_LogSrc ();
            return SCE_ERROR;
        }
    }

    return id;
}