Changeset 59741 in vbox
- Timestamp:
- Feb 19, 2016 3:11:35 PM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 105608
- Location:
- trunk/src/VBox/Devices/Graphics
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp
r58132 r59741 3662 3662 case SVGA3D_TRANSFORM_PROJECTION: 3663 3663 { 3664 int rc = ShaderTransformProjection(pContext->state.RectViewPort.w, pContext->state.RectViewPort.h, matrix );3664 int rc = ShaderTransformProjection(pContext->state.RectViewPort.w, pContext->state.RectViewPort.h, matrix, false /* fPretransformed */); 3665 3665 AssertRCReturn(rc, rc); 3666 3666 break; … … 5862 5862 } 5863 5863 5864 int vmsvga3dDrawPrimitivesProcessVertexDecls(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t iVertexDeclBase, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl) 5865 { 5864 int vmsvga3dResetTransformMatrices(PVGASTATE pThis, PVMSVGA3DCONTEXT pContext) 5865 { 5866 int rc; 5867 5868 /* Reset the view matrix (also takes the world matrix into account). */ 5869 if (pContext->state.aTransformState[SVGA3D_TRANSFORM_VIEW].fValid == true) 5870 { 5871 rc = vmsvga3dSetTransform(pThis, pContext->id, SVGA3D_TRANSFORM_VIEW, pContext->state.aTransformState[SVGA3D_TRANSFORM_VIEW].matrix); 5872 } 5873 else 5874 { 5875 float matrix[16]; 5876 5877 /* identity matrix if no matrix set. */ 5878 memset(matrix, 0, sizeof(matrix)); 5879 matrix[0] = 1.0; 5880 matrix[5] = 1.0; 5881 matrix[10] = 1.0; 5882 matrix[15] = 1.0; 5883 rc = vmsvga3dSetTransform(pThis, pContext->id, SVGA3D_TRANSFORM_VIEW, matrix); 5884 } 5885 5886 /* Reset the projection matrix. */ 5887 if (pContext->state.aTransformState[SVGA3D_TRANSFORM_PROJECTION].fValid == true) 5888 { 5889 rc = vmsvga3dSetTransform(pThis, pContext->id, SVGA3D_TRANSFORM_PROJECTION, pContext->state.aTransformState[SVGA3D_TRANSFORM_PROJECTION].matrix); 5890 } 5891 else 5892 { 5893 float matrix[16]; 5894 5895 /* identity matrix if no matrix set. */ 5896 memset(matrix, 0, sizeof(matrix)); 5897 matrix[0] = 1.0; 5898 matrix[5] = 1.0; 5899 matrix[10] = 1.0; 5900 matrix[15] = 1.0; 5901 rc = vmsvga3dSetTransform(pThis, pContext->id, SVGA3D_TRANSFORM_PROJECTION, matrix); 5902 } 5903 AssertRC(rc); 5904 return rc; 5905 } 5906 5907 int vmsvga3dDrawPrimitivesProcessVertexDecls(PVGASTATE pThis, PVMSVGA3DCONTEXT pContext, uint32_t iVertexDeclBase, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl) 5908 { 5909 PVMSVGA3DSTATE pState = pThis->svga.p3dState; 5866 5910 unsigned sidVertex = pVertexDecl[0].array.surfaceId; 5867 5911 PVMSVGA3DSURFACE pVertexSurface; … … 5936 5980 switch (pVertexDecl[iVertex].identity.usage) 5937 5981 { 5982 case SVGA3D_DECLUSAGE_POSITIONT: 5938 5983 case SVGA3D_DECLUSAGE_POSITION: 5984 { 5939 5985 glEnableClientState(GL_VERTEX_ARRAY); 5940 5986 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); … … 5943 5989 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); 5944 5990 break; 5991 } 5945 5992 case SVGA3D_DECLUSAGE_BLENDWEIGHT: 5946 5993 AssertFailed(); … … 5981 6028 AssertFailed(); 5982 6029 break; 5983 case SVGA3D_DECLUSAGE_POSITIONT:5984 AssertFailed(); /* see position_transformed in Wine */5985 break;5986 6030 case SVGA3D_DECLUSAGE_COLOR: /** @todo color component order not identical!! test GL_BGRA!! */ 5987 6031 glEnableClientState(GL_COLOR_ARRAY); … … 6017 6061 } 6018 6062 6019 int vmsvga3dDrawPrimitivesCleanupVertexDecls(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t iVertexDeclBase, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl) 6020 { 6021 /* Setup the vertex declarations. */ 6063 int vmsvga3dDrawPrimitivesCleanupVertexDecls(PVGASTATE pThis, PVMSVGA3DCONTEXT pContext, uint32_t iVertexDeclBase, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl) 6064 { 6065 PVMSVGA3DSTATE pState = pThis->svga.p3dState; 6066 6067 /* Clean up the vertex declarations. */ 6022 6068 for (unsigned iVertex = 0; iVertex < numVertexDecls; iVertex++) 6023 6069 { 6070 if (pVertexDecl[iVertex].identity.usage == SVGA3D_DECLUSAGE_POSITIONT) 6071 { 6072 /* Reset the transformation matrices in case of a switch back from pretransformed mode. */ 6073 Log(("vmsvga3dDrawPrimitivesCleanupVertexDecls: reset world and projection matrices after transformation reset (pre-transformed -> transformed)\n")); 6074 vmsvga3dResetTransformMatrices(pThis, pContext); 6075 } 6076 6024 6077 if (pContext->state.shidVertex != SVGA_ID_INVALID) 6025 6078 { … … 6034 6087 { 6035 6088 case SVGA3D_DECLUSAGE_POSITION: 6089 case SVGA3D_DECLUSAGE_POSITIONT: 6036 6090 glDisableClientState(GL_VERTEX_ARRAY); 6037 6091 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); … … 6063 6117 case SVGA3D_DECLUSAGE_TESSFACTOR: 6064 6118 break; 6065 case SVGA3D_DECLUSAGE_POSITIONT:6066 break;6067 6119 case SVGA3D_DECLUSAGE_COLOR: /** @todo color component order not identical!! */ 6068 6120 glDisableClientState(GL_COLOR_ARRAY); … … 6089 6141 int vmsvga3dDrawPrimitives(PVGASTATE pThis, uint32_t cid, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl, uint32_t numRanges, SVGA3dPrimitiveRange *pRange, uint32_t cVertexDivisor, SVGA3dVertexDivisor *pVertexDivisor) 6090 6142 { 6143 PVMSVGA3DSTATE pState = pThis->svga.p3dState; 6091 6144 PVMSVGA3DCONTEXT pContext; 6092 PVMSVGA3DSTATE pState = pThis->svga.p3dState;6093 6145 AssertReturn(pState, VERR_INTERNAL_ERROR); 6094 6146 int rc = VERR_NOT_IMPLEMENTED; … … 6112 6164 VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext); 6113 6165 6114 /* Flush any shader changes. */ 6166 /* Check for pretransformed vertex declarations. */ 6167 for (unsigned iVertex = 0; iVertex < numVertexDecls; iVertex++) 6168 { 6169 switch (pVertexDecl[iVertex].identity.usage) 6170 { 6171 case SVGA3D_DECLUSAGE_POSITIONT: 6172 Log(("ShaderSetPositionTransformed: (%d,%d)\n", pContext->state.RectViewPort.w, pContext->state.RectViewPort.h)); 6173 case SVGA3D_DECLUSAGE_POSITION: 6174 ShaderSetPositionTransformed(pContext->pShaderContext, pContext->state.RectViewPort.w, pContext->state.RectViewPort.h, 6175 pVertexDecl[iVertex].identity.usage == SVGA3D_DECLUSAGE_POSITIONT); 6176 break; 6177 } 6178 } 6179 6180 /* Flush any shader changes; after (!) checking the vertex declarations to deal with pre-transformed vertices. */ 6115 6181 if (pContext->pShaderContext) 6116 6182 { … … 6142 6208 } 6143 6209 6144 rc = vmsvga3dDrawPrimitivesProcessVertexDecls(p State, pContext, iCurrentVertex, iVertex - iCurrentVertex, &pVertexDecl[iCurrentVertex]);6210 rc = vmsvga3dDrawPrimitivesProcessVertexDecls(pThis, pContext, iCurrentVertex, iVertex - iCurrentVertex, &pVertexDecl[iCurrentVertex]); 6145 6211 AssertRCReturn(rc, rc); 6146 6212 … … 6223 6289 else 6224 6290 { 6291 GLenum indexType; 6292 6225 6293 Assert(pRange[iPrimitive].indexBias >= 0); /** @todo indexBias */ 6226 6294 Assert(pRange[iPrimitive].indexWidth == pRange[iPrimitive].indexArray.stride); 6295 6296 if (pRange[iPrimitive].indexWidth == sizeof(uint8_t)) 6297 { 6298 indexType = GL_UNSIGNED_BYTE; 6299 } 6300 else 6301 if (pRange[iPrimitive].indexWidth == sizeof(uint16_t)) 6302 { 6303 indexType = GL_UNSIGNED_SHORT; 6304 } 6305 else 6306 { 6307 Assert(pRange[iPrimitive].indexWidth == sizeof(uint32_t)); 6308 indexType = GL_UNSIGNED_INT; 6309 } 6227 6310 6228 6311 /* Render with an index buffer */ … … 6231 6314 glDrawElements(modeDraw, 6232 6315 cVertices, 6233 (pRange[iPrimitive].indexWidth == sizeof(uint16_t)) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT,6316 indexType, 6234 6317 (GLvoid *)(uintptr_t)pRange[iPrimitive].indexArray.offset); /* byte offset in indices buffer */ 6235 6318 else 6236 6319 pState->ext.glDrawElementsBaseVertex(modeDraw, 6237 6320 cVertices, 6238 (pRange[iPrimitive].indexWidth == sizeof(uint16_t)) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT,6321 indexType, 6239 6322 (GLvoid *)(uintptr_t)pRange[iPrimitive].indexArray.offset, /* byte offset in indices buffer */ 6240 6323 pRange[iPrimitive].indexBias); /* basevertex */ … … 6265 6348 } 6266 6349 6267 rc = vmsvga3dDrawPrimitivesCleanupVertexDecls(p State, pContext, iCurrentVertex, iVertex - iCurrentVertex, &pVertexDecl[iCurrentVertex]);6350 rc = vmsvga3dDrawPrimitivesCleanupVertexDecls(pThis, pContext, iCurrentVertex, iVertex - iCurrentVertex, &pVertexDecl[iCurrentVertex]); 6268 6351 AssertRCReturn(rc, rc); 6269 6352 … … 6308 6391 6309 6392 #ifdef DEBUG_GFX_WINDOW 6310 if (pContext-> aSidActiveTexture[0])6393 if (pContext->sidRenderTarget) 6311 6394 { 6312 6395 SVGA3dCopyRect rect; 6313 6396 6314 6397 rect.srcx = rect.srcy = rect.x = rect.y = 0; 6315 rect.w = 800;6316 rect.h = 600;6398 rect.w = pContext->state.RectViewPort.w; 6399 rect.h = pContext->state.RectViewPort.h; 6317 6400 vmsvga3dCommandPresent(pThis, pContext->sidRenderTarget, 0, NULL); 6318 6401 } 6319 6402 #endif 6403 6320 6404 return rc; 6321 6405 } -
trunk/src/VBox/Devices/Graphics/VBoxSVGA3D.def
r56333 r59741 36 36 ShaderUpdateState 37 37 ShaderTransformProjection 38 ShaderSetPositionTransformed 38 39 40 -
trunk/src/VBox/Devices/Graphics/shaderlib/glsl_shader.c
r54765 r59741 4262 4262 } 4263 4263 4264 #ifdef VBOX_WITH_VMSVGA 4265 static 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 4264 4294 /* GL locking is done by the caller */ 4265 4295 static void hardcode_local_constants(IWineD3DBaseShaderImpl *shader, const struct wined3d_gl_info *gl_info, … … 4710 4740 list_add_head(&((IWineD3DBaseShaderImpl *)vshader)->baseShader.linked_programs, &entry->vshader_entry); 4711 4741 } 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 4712 4759 4713 4760 /* Attach GLSL pshader */ -
trunk/src/VBox/Devices/Graphics/shaderlib/shaderapi.c
r53755 r59741 15 15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 16 16 */ 17 18 17 #include <iprt/err.h> 19 18 #include <iprt/mem.h> … … 626 625 } 627 626 627 SHADERDECL(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 628 656 SHADERDECL(int) ShaderUpdateState(void *pShaderContext, uint32_t rtHeight) 629 657 { … … 668 696 } 669 697 670 SHADERDECL(int) ShaderTransformProjection(unsigned cxViewPort, unsigned cyViewPort, float matrix[16] )698 SHADERDECL(int) ShaderTransformProjection(unsigned cxViewPort, unsigned cyViewPort, float matrix[16], bool fPretransformed) 671 699 { 672 700 #ifdef DEBUG … … 723 751 724 752 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 } 730 767 #ifdef DEBUG 731 768 lastError = glGetError(); \ -
trunk/src/VBox/Devices/Graphics/shaderlib/shaderlib.h
r53755 r59741 87 87 SHADERDECL(int) ShaderSetPixelShaderConstantF(void *pShaderContext, uint32_t reg, const float *pValues, uint32_t cRegisters); 88 88 89 SHADERDECL(int) ShaderSetPositionTransformed(void *pShaderContext, unsigned cxViewPort, unsigned cyViewPort, bool fPreTransformed); 90 89 91 SHADERDECL(int) ShaderUpdateState(void *pShaderContext, uint32_t rtHeight); 90 92 91 SHADERDECL(int) ShaderTransformProjection(unsigned cxViewPort, unsigned cyViewPort, float matrix[16] );93 SHADERDECL(int) ShaderTransformProjection(unsigned cxViewPort, unsigned cyViewPort, float matrix[16], bool fPretransformed); 92 94 93 95 RT_C_DECLS_END
Note:
See TracChangeset
for help on using the changeset viewer.