VirtualBox

Ignore:
Timestamp:
Feb 19, 2016 3:11:35 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
105608
Message:

SVGA3d: Applied patch for supporting pretransformed vertices (SVGA3D_DECLUSAGE_POSITIONT) from trivirt.

Location:
trunk/src/VBox/Devices/Graphics/shaderlib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Graphics/shaderlib/glsl_shader.c

    r54765 r59741  
    42624262}
    42634263
     4264#ifdef VBOX_WITH_VMSVGA
     4265static GLhandleARB generate_passthrough_vshader(const struct wined3d_gl_info *gl_info)
     4266{
     4267    GLhandleARB ret = 0;
     4268    static const char *passthrough_vshader[] =
     4269    {
     4270        "#version 120\n"
     4271        "vec4 R0;\n"
     4272        "void main(void)\n"
     4273        "{\n"
     4274        "    R0   = gl_Vertex;\n"
     4275        "    R0.w = 1.0;\n"
     4276        "    R0.z = 0.0;\n"
     4277        "    gl_Position   = gl_ModelViewProjectionMatrix * R0;\n"
     4278        "}\n"
     4279    };
     4280
     4281    ret = GL_EXTCALL(glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB));
     4282    checkGLcall("glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB)");
     4283    GL_EXTCALL(glShaderSourceARB(ret, 1, passthrough_vshader, NULL));
     4284    checkGLcall("glShaderSourceARB(ret, 1, passthrough_vshader, NULL)");
     4285    GL_EXTCALL(glCompileShaderARB(ret));
     4286    checkGLcall("glCompileShaderARB(ret)");
     4287    shader_glsl_validate_compile_link(gl_info, ret, FALSE);
     4288
     4289    return ret;
     4290}
     4291
     4292#endif
     4293
    42644294/* GL locking is done by the caller */
    42654295static void hardcode_local_constants(IWineD3DBaseShaderImpl *shader, const struct wined3d_gl_info *gl_info,
     
    47104740        list_add_head(&((IWineD3DBaseShaderImpl *)vshader)->baseShader.linked_programs, &entry->vshader_entry);
    47114741    }
     4742#ifdef VBOX_WITH_VMSVGA
     4743    else
     4744    if (device->strided_streams.position_transformed)
     4745    {
     4746        GLhandleARB passthrough_vshader_id;
     4747
     4748        passthrough_vshader_id = generate_passthrough_vshader(gl_info);
     4749        TRACE("Attaching GLSL shader object %p to program %p\n", (void *)(uintptr_t)passthrough_vshader_id, (void *)(uintptr_t)programId);
     4750        GL_EXTCALL(glAttachObjectARB(programId, passthrough_vshader_id));
     4751        checkGLcall("glAttachObjectARB");
     4752        /* Flag the reorder function for deletion, then it will be freed automatically when the program
     4753         * is destroyed
     4754         */
     4755        GL_EXTCALL(glDeleteObjectARB(passthrough_vshader_id));
     4756    }
     4757#endif
     4758
    47124759
    47134760    /* Attach GLSL pshader */
  • trunk/src/VBox/Devices/Graphics/shaderlib/shaderapi.c

    r53755 r59741  
    1515 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    1616 */
    17 
    1817#include <iprt/err.h>
    1918#include <iprt/mem.h>
     
    626625}
    627626
     627SHADERDECL(int) ShaderSetPositionTransformed(void *pShaderContext, unsigned cxViewPort, unsigned cyViewPort, bool fPreTransformed)
     628{
     629    IWineD3DDeviceImpl *This;
     630    int rc;
     631
     632    SHADER_SET_CURRENT_CONTEXT(pShaderContext);
     633    This = g_pCurrentContext->pDeviceContext;
     634
     635    if (This->strided_streams.position_transformed == fPreTransformed)
     636        return VINF_SUCCESS;    /* no changes; nothing to do. */
     637
     638    Log(("ShaderSetPositionTransformed viewport (%d,%d) fPreTransformed=%d\n", cxViewPort, cyViewPort, fPreTransformed));
     639   
     640    if (fPreTransformed)
     641    {   /* In the pre-transformed vertex coordinate case we need to disable all transformations as we're already using screen coordinates. */
     642        /* Load the identity matrix for the model view */
     643        glMatrixMode(GL_MODELVIEW);
     644        glLoadIdentity();
     645
     646        /* Reset the projection matrix too */
     647        rc = ShaderTransformProjection(cxViewPort, cyViewPort, NULL, fPreTransformed);
     648        AssertRCReturn(rc, rc);
     649    }
     650
     651    This->strided_streams.position_transformed = fPreTransformed;
     652    ((IWineD3DVertexDeclarationImpl *)(This->stateBlock->vertexDecl))->position_transformed = fPreTransformed;
     653    return VINF_SUCCESS;
     654}
     655
    628656SHADERDECL(int) ShaderUpdateState(void *pShaderContext, uint32_t rtHeight)
    629657{
     
    668696}
    669697
    670 SHADERDECL(int) ShaderTransformProjection(unsigned cxViewPort, unsigned cyViewPort, float matrix[16])
     698SHADERDECL(int) ShaderTransformProjection(unsigned cxViewPort, unsigned cyViewPort, float matrix[16], bool fPretransformed)
    671699{
    672700#ifdef DEBUG
     
    723751
    724752    glTranslatef(xoffset, -yoffset, -1.0f);
    725     /* flip y coordinate origin too */
    726     glScalef(1.0f, -1.0f, 2.0f);
    727 
    728     glMultMatrixf(matrix);
    729 
     753
     754    if (fPretransformed)
     755    {
     756        /* One world coordinate equals one screen pixel; y-inversion no longer an issue */
     757        glOrtho(0, cxViewPort, 0, cyViewPort, -1, 1);
     758    }
     759    else
     760    {
     761        /* flip y coordinate origin too */
     762        glScalef(1.0f, -1.0f, 2.0f);
     763
     764        /* Apply the supplied projection matrix */
     765        glMultMatrixf(matrix);
     766    }
    730767#ifdef DEBUG
    731768    lastError = glGetError();                                     \
  • trunk/src/VBox/Devices/Graphics/shaderlib/shaderlib.h

    r53755 r59741  
    8787SHADERDECL(int) ShaderSetPixelShaderConstantF(void *pShaderContext, uint32_t reg, const float *pValues, uint32_t cRegisters);
    8888
     89SHADERDECL(int) ShaderSetPositionTransformed(void *pShaderContext, unsigned cxViewPort, unsigned cyViewPort, bool fPreTransformed);
     90
    8991SHADERDECL(int) ShaderUpdateState(void *pShaderContext, uint32_t rtHeight);
    9092
    91 SHADERDECL(int) ShaderTransformProjection(unsigned cxViewPort, unsigned cyViewPort, float matrix[16]);
     93SHADERDECL(int) ShaderTransformProjection(unsigned cxViewPort, unsigned cyViewPort, float matrix[16], bool fPretransformed);
    9294
    9395RT_C_DECLS_END
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette