Example #1
0
float4 __CGsampler_state::magnify(int ndx, float4 strq)
{
    switch (magFilter) {
    default:
        assert(!"unexpected magnification filter");
    case GL_NEAREST:
        return nearestFilter(trueBaseLevel, strq);
    case GL_LINEAR:
        return linearFilter(trueBaseLevel, strq);
    }
}
Example #2
0
float4 __CGsampler_state::minify(int ndx, float4 strq, float1 lod)
{
    assert(lod > 0);  // Otherwise should be in minify
    switch (minFilter) {
    default:
        assert(!"unexpected minification filter");
    case GL_NEAREST:
        return nearestFilter(trueBaseLevel, strq);
    case GL_NEAREST_MIPMAP_NEAREST:
        {
            int level = clamp(int1(trueBaseLevel + round(lod)), trueBaseLevel, effectiveMaxLevel);
            return nearestFilter(level, strq);
        }
    case GL_LINEAR_MIPMAP_NEAREST:
        {
            int level = clamp(int1(trueBaseLevel + round(lod)), trueBaseLevel, effectiveMaxLevel);
            return linearFilter(level, strq);
        }
    case GL_NEAREST_MIPMAP_LINEAR:
        {
            int level0 = max(trueBaseLevel + int(floor(lod)), effectiveMaxLevel);
            int level1 = max(level0 + 1, effectiveMaxLevel);
            float4 tex0 = nearestFilter(level0, strq);
            float4 tex1 = nearestFilter(level1, strq);
            return lerp(tex0, tex1, frac(lod));
        }
    case GL_LINEAR_MIPMAP_LINEAR:
        {
            int level0 = max(trueBaseLevel + int(floor(lod)), effectiveMaxLevel);
            int level1 = max(level0 + 1, effectiveMaxLevel);
            float4 tex0 = linearFilter(level0, strq);
            float4 tex1 = linearFilter(level1, strq);
            return lerp(tex0, tex1, frac(lod));
        }
    case GL_LINEAR:
        return linearFilter(trueBaseLevel, strq);
    }
}
Example #3
0
int main(int argc, char *argv[]) {
    MPI_Init(&argc, &argv);

    int rank = 0;
    int size = 0;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    SDLImage *image = nullptr;
    Pixel *pixels = nullptr;

    int pixelsNum = 0;
    int pixelsRows = 0;
    int pixelsCols = 0;

    if (rank == ROOT) {
        image = new SDLImage(IMAGE_PATH);

        pixelsRows = image->getHeight();
        pixelsCols = image->getWidth();
        pixelsNum = pixelsRows * pixelsCols;
        pixels = new Pixel[pixelsNum]();
        getPixels(image, pixels);
    }

    MPI_Bcast(&pixelsNum, 1, MPI_INT, ROOT, MPI_COMM_WORLD);
    MPI_Bcast(&pixelsRows, 1, MPI_INT, ROOT, MPI_COMM_WORLD);
    MPI_Bcast(&pixelsCols, 1, MPI_INT, ROOT, MPI_COMM_WORLD);

    MPI_Barrier(MPI_COMM_WORLD);

    int localPixelsNum = pixelsNum / size;

    Pixel *localPixels = new Pixel[localPixelsNum];
    Pixel *outLocalPixels = new Pixel[localPixelsNum];
    Pixel *outPixels = new Pixel[pixelsNum];

    MPI_Datatype MPI_PIXEL;
    MPI_Type_contiguous(sizeof(Pixel), MPI_BYTE, &MPI_PIXEL);
    MPI_Type_commit(&MPI_PIXEL);

    MPI_Scatter(pixels, localPixelsNum, MPI_PIXEL, localPixels, localPixelsNum, MPI_PIXEL, ROOT, MPI_COMM_WORLD);

    MPI_Barrier(MPI_COMM_WORLD);

    linearFilter(localPixels, pixelsRows / size, pixelsCols, outLocalPixels, 7);

    MPI_Barrier(MPI_COMM_WORLD);

    MPI_Gather(outLocalPixels, localPixelsNum, MPI_PIXEL, outPixels, localPixelsNum, MPI_PIXEL, ROOT, MPI_COMM_WORLD);

    MPI_Barrier(MPI_COMM_WORLD);

    if (rank == ROOT) {

        image->ShowImage();

        SDL_Event event;
        bool stop = false;

        while (!stop && SDL_WaitEvent(&event) != -1) {
            if (event.type == SDL_KEYDOWN) {
                switch (event.key.keysym.sym) {
                    case SDLK_RETURN:
                        setPixels(outPixels, image);
                        image->UpdateImage();
                        break;
                    case SDLK_ESCAPE:
                        stop = true;
                        break;
                }
            }
        }
    }

    if (rank == ROOT) {
        delete[](pixels);
    }
    delete[](localPixels);
    delete[](outLocalPixels);
    delete[](outPixels);

    MPI_Finalize();
    return 0;
}